signedapp.cpp
来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 528 行 · 第 1/2 页
CPP
528 行
//
// SignedApp.cpp - Phase 2 of a signed app
//
// Copyright (C) UIQ Technology AB, 2007
//
// This material is provided "as is" without any warranty to its performance or functionality.
// In no event shall UIQ Technology be liable for any damages whatsoever arising out of the
// use or inabilty to use this material.
//
#include "SignedApp.h"
#include "ListView.h"
#include "DetailsView.h"
#include "AudioRecordView.h"
#include "ImageConversionView.h"
#include "VideoView.h"
#include "CameraView.h"
#include "SignedAppUids.h"
#include "SignedApp.hrh"
#include <SignedApp_0x20000462.rsg>
#include <eikstart.h>
#include <eikdialg.h>
#include <eiklabel.h>
#include <eikedwin.h>
#include <QikCommand.h>
#include <QikNumberEditor.h>
#include <QikSimpleDialog.h>
#include <Etel3rdParty.h>
////////////////////////////////////////////////////////////////////////////////////////////
class CGetPhoneIMEI : public CActive
{
protected:
void RunL();
void DoCancel();
public:
~CGetPhoneIMEI();
CGetPhoneIMEI(CAppSpecificUi& aAppUi);
void ConstructL();
protected:
CAppSpecificUi& iAppUi;
CTelephony::TPhoneIdV1Pckg iBuf;
CTelephony::TPhoneIdV1 iData;
CTelephony* iTelephony;
};
CGetPhoneIMEI::~CGetPhoneIMEI()
{
Cancel();
delete(iTelephony);
}
CGetPhoneIMEI::CGetPhoneIMEI(CAppSpecificUi& aAppUi) :
CActive(CActive::EPriorityHigh),iAppUi(aAppUi),iBuf(iData)
{
CActiveScheduler::Add(this);
}
void CGetPhoneIMEI::ConstructL()
// Start the request to obtain the IMEI
{
iTelephony=CTelephony::NewL();
iTelephony->GetPhoneId(iStatus,iBuf);
SetActive();
}
void CGetPhoneIMEI::RunL()
{
// for debugging purposes we set up the supplied serial number with debug info. We can leave this
// in production code, this may help support people diagnose problems.
_LIT(KErrNo,"Err %d");
_LIT(KBlank,"Blank");
if (iStatus!=KErrNone)
iData.iSerialNumber.Format(KErrNo,iStatus.Int());
else if (iData.iSerialNumber.Length()==0)
iData.iSerialNumber=KBlank;
// tell the UI about the phones IMEI
iAppUi.SetIMEI(iData.iSerialNumber);
delete(this);
}
void CGetPhoneIMEI::DoCancel()
// If we are currently IsActive() then calling Cancel() will call this to perform the actual
// cancelling before it consumes the generated signal.
{
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
}
////////////////////////////////////////////////////////////////////////////////////////////
// Display the IMEI of the phone - can help support people when Unlock codes supplied by
// sites either go missing, are wrong or customer enters wrong IMEI.
class CRegistrationDialog : public CQikSimpleDialog
{
protected:
void PreLayoutDynInitL();
void HandleCommandL(CQikCommand& aCommand);
public:
CRegistrationDialog(TInt& aCode,const TDesC& aImei);
protected:
TInt& iCode;
TBuf<32> iImei;
};
CRegistrationDialog::CRegistrationDialog(TInt& aCode,const TDesC& aImei) :
iCode(aCode)
{
iImei=aImei;
}
void CRegistrationDialog::PreLayoutDynInitL()
{
// display the current device IMEI
CEikLabel* lbl=LocateControlByUniqueHandle<CEikLabel>(EAppLabel1);
lbl->SetTextL(iImei);
}
void CRegistrationDialog::HandleCommandL(CQikCommand& aCommand)
{
switch (aCommand.Id())
{
case EAppCmdContinue:
{
// obtain the content entered by the user
CQikNumberEditor* numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin1);
iCode=numEd->Value();
// this value returned as the result to ExecuteLD()..
CloseDialog(EAppCmdContinue);
break;
}
default:
CQikSimpleDialog::HandleCommandL(aCommand);
break;
}
}
//////////////////////////////////////////////////////////////////////////////////
class CAboutDialog : public CQikSimpleDialog
{
protected:
void PreLayoutDynInitL();
};
// These would normally be derived from your in-house version control, this example just
// defines them here to remove such complexity from the example.
// Note that the content of the pkg file must also be kept in sync with this version number
const TInt KAppMajorVersion=1;
const TInt KAppMinorVersion=0;
const TInt KAppBuild=3;
void CAboutDialog::PreLayoutDynInitL()
//
// Generate the version text - e.g. Version 1.00 (03) and set the label
//
{
TBuf<128>bb;
iEikonEnv->Format128(bb,R_STR_VERSION,KAppMajorVersion,KAppMinorVersion,KAppBuild);
CEikLabel* lbl=LocateControlByUniqueHandle<CEikLabel>(EAppLabel1);
lbl->SetTextL(bb);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Defer displaying the prvacy dialog until all other active events been processed, in particular this
// allows our primary list view to be displayed correctly before we display this dialog.
class CSymbianSignedPrivacyDialogDisplayer : public CActive
{
protected:
void DoCancel() {};
void RunL();
public:
CSymbianSignedPrivacyDialogDisplayer();
protected:
};
CSymbianSignedPrivacyDialogDisplayer::CSymbianSignedPrivacyDialogDisplayer() :
CActive(CActive::EPriorityIdle)
{
CActiveScheduler::Add(this);
TRequestStatus* q=(&iStatus);
User::RequestComplete(q,KErrNone);
SetActive();
}
void CSymbianSignedPrivacyDialogDisplayer::RunL()
{
CEikonEnv::Static()->InfoWinL(R_STR_PRIVACY_STATEMENT_TITLE,R_STR_PRIVACY_STATEMENT_INFO);
delete(this);
}
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
{
delete(iEngine);
}
TBool CAppSpecificUi::CheckRegistration() const
//
// Check to see if the registration code entered by the user is valid or not.
// Used to determine whether we are running is 'Trial' or 'Purchased' mode
//
{
TBuf<32>bb;
bb.Num(iRegistrationCode);
if (iPhoneImei.Length()<5 || bb.Length()!=5 || bb!=iPhoneImei.Right(5))
return(EFalse);
return(ETrue);
}
// It is good practice to prepend streams with a version number - that way if the content has to
// change in the future we can maintain backwards compatibility.
const TInt KIniFileStreamVersion_One=1; // as used in SignedAppPhase2 (or Localization)
// we have added content to the stream store for this 'upgraded' version. So make sure
// we can differentiate between previous and 'upgraded' versions
const TInt KIniFileStreamVersion=2;
const TUid KUidIniFilePrefs={0x00000001};
void CAppSpecificUi::LoadIniFilePreferencesL(
// Load the application specific preferences/settings
const TInt aVersion, // which version of the content we are loading
RReadStream& aStream) // where we are loading the content from
{
if (aVersion>=KIniFileStreamVersion_One)
{
iRegistrationCode=aStream.ReadInt32L();
// our 'engine' contains all the user configuration information. Due to the >> operator definition
// this calls the InternalizeL() method of our engine object.
aStream>>(*iEngine);
// example of using the stream version info to maintain backwards compatibility
// In this case with SignedAppPhase2 (or Localization) example apps
if (aVersion>=KIniFileStreamVersion)
{
iDisplayedPrivacyStatement=aStream.ReadInt32L();
}
else
{ // may have to manually setup the property if not done in a construct(or)
}
}
}
void CAppSpecificUi::SaveIniFilePreferencesL(RWriteStream& aStream) const
// Save the application specific preferences/settings
{
aStream.WriteInt32L(iRegistrationCode);
// our 'engine' contains all the user configuration information. Due to the >> operator definition
// this calls the ExternalizeL() method of our engine object.
aStream<<(*iEngine);
// additional items added in version 2 of the stream file
// these should be added to the stream at the end of other content so we can
// successfully load previous versions + new versions of the stream store content
aStream.WriteInt32L(iDisplayedPrivacyStatement);
}
void CAppSpecificUi::LoadIniFile()
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?