signedapp.cpp
来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 528 行 · 第 1/2 页
CPP
528 行
// Load the INI file - all our settings etc
// This code simply implements the framework for INI file loading.
// If the INI file does not exist or the specific stream is missing this code handles it by
// ignoring the 'error'. This is entirely reasonable since this may be the first time the app
// has ever been run.
//
{
TRAPD(err,
CEikApplication* app=(CEikApplication*)Document()->Application();
CDictionaryStore* iniFile=app->OpenIniFileLC(iEikonEnv->FsSession());
if (iniFile->IsPresentL(KUidIniFilePrefs))
{
RDictionaryReadStream readStream;
readStream.OpenLC(*iniFile,KUidIniFilePrefs);
TInt version=readStream.ReadUint8L();
LoadIniFilePreferencesL(version,readStream);
CleanupStack::PopAndDestroy(); // readStream
}
CleanupStack::PopAndDestroy(); // iniFile
);
}
void CAppSpecificUi::SaveIniFileL(const TInt aVersion)
//
// Save the INI file - all our settings etc. Notice we dont actually need to supply any file name
// location, the framework automatically determines that from our application name and private path.
//
{
CEikApplication* app=(CEikApplication*)Document()->Application();
CDictionaryStore* iniFile=app->OpenIniFileLC(iEikonEnv->FsSession());
RDictionaryWriteStream writeStream;
writeStream.AssignLC(*iniFile,KUidIniFilePrefs);
// version
writeStream.WriteUint8L(aVersion);
// now all the content
SaveIniFilePreferencesL(writeStream);
writeStream.CommitL();
CleanupStack::PopAndDestroy(); // writeStream
iniFile->CommitL();
CleanupStack::PopAndDestroy(iniFile);
}
void CAppSpecificUi::HandleCommandL(TInt aCommand)
//
// If we have commands common across all Views we can implement them here
//
{
switch (aCommand)
{
case EAppCmdAbout:
(new(ELeave)CAboutDialog)->ExecuteLD(R_ABOUT_DIALOG);
break;
case EAppCmdRegister:
{
TInt code;
if ((new(ELeave)CRegistrationDialog(code,iPhoneImei))->ExecuteLD(R_REGISTER_DIALOG)==EAppCmdContinue)
{
// our registration scheme for this app is very simple - the last 5 digits of the
// IMEI need to match the number entered by the user.
TBuf<32>bb;
bb.Num(code);
if (bb.Length()!=5 || bb!=iPhoneImei.Right(5))
iEikonEnv->InfoWinL(R_STR_REG_FAILED_TITLE,R_STR_REG_FAILED_INFO);
else
{ // save the number the user entered. Give some +ve feedback that the registration
// code is correct.
iRegistrationCode=code;
iEikonEnv->InfoMsg(R_STR_REGISTERED);
}
}
break;
}
// in debug modes we have an exit command so we can easily exit app
// on real devices we are sent EEikCmdExit when the Task Manager has been requested to
// end the running application.
// If we 'leave' when handling this command the Task Manager cannot 'End' this app
case EEikCmdExit:
// On emul this causes a spurious CBase 65 panic...
// It is recommended this is periodically disabled (comment out) to check that your
// app is not leaking resources (resulting in ALLOC heaven or perhaps CONE 8 panics)
// when the app is exited.
TRAPD(junk,SaveIniFileL(KIniFileStreamVersion));
Exit();
break;
default:
break;
}
}
void CAppSpecificUi::ConstructL()
//
// Normal primary entry point to a Symbian App
//
{
CQikAppUi::ConstructL();
#ifdef __WINS__
_LIT(KPhoneImei,"98765-12345");
iPhoneImei=KPhoneImei;
#else
// set up and start the active object that obtains the phones IMEI
CGetPhoneIMEI* imei=new(ELeave)CGetPhoneIMEI(*this);
CleanupStack::PushL(imei);
imei->ConstructL();
// the CGetPhoneIMEI object will delete itself when it completes (self-ownership !)
CleanupStack::Pop(imei);
#endif
// create and set-up our engine - typically responsble for supplying data the UI renders
iEngine=new(ELeave)CAppEngine(iEikonEnv->FsSession(),EQikCmdZoomLevel2);
iEngine->ConstructL();
// Setup the default category list
TBuf<KCategoryNameMaxLength> bb;
for (TInt i=0;i<EAppCategoryLastItem;i++)
{
iEikonEnv->ReadResourceL(bb,R_STR_CATEGORY_NAME_1+i);
iEngine->AddCategoryL(i,bb);
}
// Locate our private path - were our example files have been installed to
// Private Path is too stupid to report the drive were on... so we have to do that manually.
TFileName installedDrive(Application()->BitmapStoreName());
TFileName path;
iEikonEnv->FsSession().PrivatePath(path);
TParse parse;
parse.Set(path,&installedDrive,NULL);
#ifdef __WINS__
// not unreasonably the OS blocks us creating files in Rom filing system...
// however that is where it thinks we are currently running/installed to in the emulator
// so we need to fix that feature.
path=parse.FullName();
path[0]='C';
parse.Set(path,NULL,NULL);
#endif
// this is only here for the emulator - since it does not create our private data caged folder by default
// or put the example data files in that folder
TRAPD(err,iEngine->SetDefaultPathL(parse.DriveAndPath()));
if (err==KErrNotFound || err==KErrPathNotFound)
{
iEikonEnv->InfoWinL(R_STR_NO_EXAMPLE_FILES,R_STR_PLEASE_COPY_FILES);
}
User::LeaveIfError(err);
// override any default settings with those stored from the previous time we ran the application
LoadIniFile();
// now create our views on the engine data
CListView* list=new(ELeave)CListView(*this,iEngine);
CleanupStack::PushL(list);
list->ConstructL();
AddViewL(*list); // takes ownership
CleanupStack::Pop(list);
CDetailsView* details=new(ELeave)CDetailsView(*this,iEngine);
CleanupStack::PushL(details);
details->ConstructL();
AddViewL(*details); // takes ownership
CleanupStack::Pop(details);
CAudioRecordView* audioRecord=new(ELeave)CAudioRecordView(*this,iEngine);
CleanupStack::PushL(audioRecord);
audioRecord->ConstructL();
AddViewL(*audioRecord); // takes ownership
CleanupStack::Pop(audioRecord);
CImageConversionView* imageConv=new(ELeave)CImageConversionView(*this,iEngine);
CleanupStack::PushL(imageConv);
imageConv->ConstructL();
AddViewL(*imageConv); // takes ownership
CleanupStack::Pop(imageConv);
CVideoPlaybackView* videoPlayer=new(ELeave)CVideoPlaybackView(*this,iEngine);
CleanupStack::PushL(videoPlayer);
videoPlayer->ConstructL();
AddViewL(*videoPlayer); // takes ownership
CleanupStack::Pop(videoPlayer);
CCameraView* camera=new(ELeave)CCameraView(*this,iEngine);
CleanupStack::PushL(camera);
camera->ConstructL();
AddViewL(*camera); // takes ownership
CleanupStack::Pop(camera);
// Only required to be display on first time start up.
if (!iDisplayedPrivacyStatement)
{
new(ELeave)CSymbianSignedPrivacyDialogDisplayer; // takes ownership of itself
iDisplayedPrivacyStatement=TRUE;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificDocument : public CQikDocument
{
protected:
CQikAppUi* CreateAppUiL();
public:
CAppSpecificDocument(CQikApplication& aApp);
static CAppSpecificDocument* NewL(CQikApplication& aApp);
protected:
};
CAppSpecificDocument::CAppSpecificDocument(CQikApplication& aApp) :
CQikDocument(aApp)
{
__DECLARE_NAME(_S("CAppSpecificDocument"));
}
CAppSpecificDocument* CAppSpecificDocument::NewL(CQikApplication& aApp)
{
return(new(ELeave)CAppSpecificDocument(aApp));
}
CQikAppUi* CAppSpecificDocument::CreateAppUiL()
{
return(new(ELeave)CAppSpecificUi);
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificApplication : public CQikApplication
{
protected:
TUid AppDllUid() const;
CApaDocument* CreateDocumentL();
};
TUid CAppSpecificApplication::AppDllUid() const
{
return(KAppSpecificUid);
}
CApaDocument* CAppSpecificApplication::CreateDocumentL()
{
return(CAppSpecificDocument::NewL(*this));
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication()
{
return(new CAppSpecificApplication);
}
GLDEF_C TInt E32Main()
{
return(EikStart::RunApplication(NewApplication));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?