📄 ldk008appui.cpp
字号:
/*
============================================================================
Name : LDK008AppUi.cpp
Author :
Version :
Copyright : Your copyright notice
Description : Main application UI class (controller)
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <LDK008.rsg>
#include <f32file.h>
#include <s32file.h>
#include <bautils.h>
#include <charconv.h>
#include <hlplch.h>
#include <ldk008.mbg>
#include "LDK008.pan"
#include "LDK008Application.h"
#include "LDK008AppUi.h"
#include "LDK008.hrh"
#include "worldview.h"
#include "HelloView.h"
#include "LDK008_0xe1b6e4d3.hlp.hrh"
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CLDK008AppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CLDK008AppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL(EAknEnableSkin);
iWorldView = CWorldView::NewL();
AddViewL(iWorldView);
// Create view object
iHelloView = CHelloView::NewL();
AddViewL(iHelloView);
PrivacyStatementL();
}
// -----------------------------------------------------------------------------
// CLDK008AppUi::CLDK008AppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CLDK008AppUi::CLDK008AppUi()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CLDK008AppUi::~CLDK008AppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CLDK008AppUi::~CLDK008AppUi()
{
}
// -----------------------------------------------------------------------------
// CLDK008AppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CLDK008AppUi::HandleCommandL( TInt aCommand )
{
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ELDK008Command1:
{
// Load a string from the resource file and display it
HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT );
// Show the information Note with
// textResource loaded with StringLoader.
CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD( *textResource );
// Pop HBuf from CleanUpStack and Destroy it.
CleanupStack::PopAndDestroy( textResource );
}
break;
case EHelp:
{
CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
}
break;
case EAbout:
{
CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
dlg->QueryHeading()->SetTextL(*title);
CleanupStack::PopAndDestroy(); //title
HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
dlg->SetMessageTextL(*msg);
CleanupStack::PopAndDestroy(); //msg
dlg->RunLD();
}
break;
default:
Panic( ELDK008Ui );
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CLDK008AppUi::HandleStatusPaneSizeChange()
{
// iAppView->SetRect( ClientRect() );
}
CArrayFix<TCoeHelpContext>* CLDK008AppUi::HelpContextL() const
{
// Note: help will not work if the application uid3 is not in the
// protected range. The default uid3 range for projects created
// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so they
// can be self signed and installed on the device during testing.
// Once you get your official uid3 from Symbian Ltd. and find/replace
// all occurrences of uid3 in your project, the context help will
// work.
CArrayFixFlat<TCoeHelpContext>* ctxs = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
CleanupStack::PushL(ctxs);
ctxs->AppendL(TCoeHelpContext(KUidLDK008App, KGeneral_Information));
CleanupStack::Pop(ctxs);
return ctxs;
}
void CLDK008AppUi::PrivacyStatementL()
{
// Note: to see privacy statement in emulator, copy
// PrivacyStatement.txt from group/ directory to
// %EPOCROOT%\Epoc32\release\winscw\udeb\z\private\e1b6e4d3\
// Also note that on emulator you can't modify files on Z: drive,
// so even if you answer Yes to privacy statement, it will popup
// dialog every time you launch application. But on device it will work
// as expected.
HBufC * fileName = StringLoader::LoadLC(R_PRIVACY_STATEMENT_FILENAME);
RFs &fs= iCoeEnv->FsSession();
// Make full path to privacy statement
TFileName fullFileName;
TFileName privatePath;
fs.PrivatePath(privatePath);
TParse parser;
TFileName processFileName(RProcess().FileName());
User::LeaveIfError(parser.Set(*fileName, &privatePath, &processFileName));
fullFileName = parser.FullName();
CleanupStack::PopAndDestroy(fileName);
if(BaflUtils::FileExists(fs, fullFileName))
{
RBuf text(CLDK008AppUi::ReadUnicodeFileL(fs, fullFileName));
CleanupClosePushL(text);
CAknMessageQueryDialog *dialog = CAknMessageQueryDialog::NewL(text);
if(dialog->ExecuteLD(R_PRIVSTMT_DIALOG) == EAknSoftkeyYes)
{
BaflUtils::DeleteFile(fs, fullFileName);
}
CleanupStack::PopAndDestroy(&text);
}
}
HBufC * CLDK008AppUi::ReadUnicodeFileL(RFs& aFs, const TDesC& aFileName)
{
RFile file;
User::LeaveIfError(file.Open(aFs, aFileName, EFileShareReadersOnly | EFileStreamText | EFileRead));
CleanupClosePushL(file);
TInt size;
User::LeaveIfError(file.Size(size));
RBuf8 tmp;
tmp.CreateL(size);
CleanupClosePushL(tmp);
User::LeaveIfError(file.Read(tmp));
CCnvCharacterSetConverter * converter = CCnvCharacterSetConverter::NewLC();
converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, aFs);
HBufC *text = HBufC::NewL(size);
TInt state = CCnvCharacterSetConverter::KStateDefault;
TPtrC8 remainderOfForeignText(tmp);
for(;;)
{
TPtr textPtr(text->Des());
TInt retValue = converter->ConvertToUnicode(textPtr, remainderOfForeignText, state);
if(retValue == CCnvCharacterSetConverter::EErrorIllFormedInput)
User::Leave(KErrCorrupt);
else if(retValue < 0)
User::Leave(KErrGeneral);
if(retValue == 0)
break;
remainderOfForeignText.Set(remainderOfForeignText.Right(retValue));
}
CleanupStack::PopAndDestroy(converter);
CleanupStack::PopAndDestroy(2);
return text;
}
// End of File
void CLDK008AppUi::GetPath(TDes& aPath)
{
TFileName appFullName;
appFullName = Application()->AppFullName();
TParsePtr parse(appFullName);
aPath.Copy(parse.DriveAndPath().Mid(0,2));
aPath.Append(_L("\\resource\\apps\\"));
}
CGulIcon* CLDK008AppUi::LoadGraphicsL(TInt aType)
{
TBuf<KMaxPath> pathMbm;
GetPath(pathMbm);
pathMbm.Append(_L("LDK008.mbm"));
switch(aType)
{
case 0:
return iEikonEnv->CreateIconL(pathMbm, EMbmLdk008Grid1_48x48, EMbmLdk008Grid1_48x48_m);
case 1:
return iEikonEnv->CreateIconL(pathMbm, EMbmLdk008Grid2_48x48, EMbmLdk008Grid2_48x48_m);
default:
return NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -