demonsymappui.cpp
来自「symbian下的一个例子」· C++ 代码 · 共 281 行
CPP
281 行
/*
============================================================================
Name : CDemonsymAppUi from DemonsymAppui.cpp
Author : huhao
Version :
Copyright : baidu
Description : CDemonsymAppUi implementation
============================================================================
*/
// INCLUDE FILES
#include "DemonsymApplication.h"
#include "DemonsymAppui.h"
#include "DemonsymView.h"
#include "DemonsymView2.h"
#include <Demonsym.rsg>
#include "Demonsym.hrh"
#include <stringloader.h>
#include <f32file.h>
#include <bautils.h>
#include <charconv.h>
#include <hlplch.h>
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include "Demonsym_0xe615c43a.hlp.hrh"
// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CDemonsymAppUi::ConstructL()
//
// ----------------------------------------------------------
//
void CDemonsymAppUi::ConstructL()
{
BaseConstructL();
// Show tabs for main views from resources
CEikStatusPane* sp = StatusPane();
// Fetch pointer to the default navi pane control
iNaviPane = (CAknNavigationControlContainer*)sp->ControlL(
TUid::Uid(EEikStatusPaneUidNavi));
// Tabgroup has been read from resource and it were pushed to the navi pane.
// Get pointer to the navigation decorator with the ResourceDecorator() function.
// Application owns the decorator and it has responsibility to delete the object.
iDecoratedTabGroup = iNaviPane->ResourceDecorator();
if (iDecoratedTabGroup)
{
iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();
iTabGroup->SetObserver( this );
}
CDemonsymView* view1 = new (ELeave) CDemonsymView;
CleanupStack::PushL( view1 );
view1->ConstructL();
AddViewL( view1 ); // transfer ownership to CAknViewAppUi
CleanupStack::Pop(); // view1
CDemonsymView2* view2 = new (ELeave) CDemonsymView2;
CleanupStack::PushL( view2 );
view2->ConstructL();
AddViewL( view2 ); // transfer ownership to CAknViewAppUi
CleanupStack::Pop(); // view2
SetDefaultViewL(*view1);
PrivacyStatementL();
}
// ----------------------------------------------------
// CDemonsymAppUi::~CDemonsymAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CDemonsymAppUi::~CDemonsymAppUi()
{
delete iDecoratedTabGroup;
}
// ------------------------------------------------------------------------------
// CDemonsymAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
// This function is called by the EIKON framework just before it displays
// a menu pane. Its default implementation is empty, and by overriding it,
// the application can set the state of menu items dynamically according
// to the state of application data.
// ------------------------------------------------------------------------------
//
void CDemonsymAppUi::DynInitMenuPaneL(
TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
{
}
// ----------------------------------------------------
// CDemonsymAppUi::HandleKeyEventL(
// const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// takes care of key event handling
// ----------------------------------------------------
//
TKeyResponse CDemonsymAppUi::HandleKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType)
{
if ( iTabGroup == NULL )
{
return EKeyWasNotConsumed;
}
if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow )
{
return iTabGroup->OfferKeyEventL( aKeyEvent, aType );
}
else
{
return EKeyWasNotConsumed;
}
}
// ----------------------------------------------------
// CDemonsymAppUi::HandleCommandL(TInt aCommand)
// takes care of command handling
// ----------------------------------------------------
//
void CDemonsymAppUi::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EEikCmdExit:
{
Exit();
break;
}
case EDemonsymCmdAppTest:
{
iEikonEnv->InfoMsg(_L("test"));
break;
}
case EDemonsymCmdGotoBaidu:
{
_LIT(KPrompt, "EDemonsymCmdGotoBaidu command id = %d");
RDebug::Print(KPrompt, aCommand);
}
break;
case EDemonsymCmdGotoSina:
{
_LIT(KPrompt, "EDemonsymCmdGotoBaidu command id = %d");
RDebug::Print(KPrompt, aCommand);
}
break;
case EDemonsymCmdGotoElse:
{
_LIT(KPrompt, "EDemonsymCmdGotoBaidu command id = %d");
RDebug::Print(KPrompt, aCommand);
}
break;
case EExit:
{
_LIT(KPrompt, "EDemonsymCmdGotoBaidu command id = %d");
RDebug::Print(KPrompt, aCommand);
}
break;
// TODO: Add Your command handling code here
default:
break;
}
}
// ----------------------------------------------------
// CDemonsymAppUi::TabChangedL(TInt aIndex)
// This method gets called when CAknTabGroup active
// tab has changed.
// ----------------------------------------------------
//
void CDemonsymAppUi::TabChangedL(TInt aIndex)
{
ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(aIndex)));
}
CArrayFix<TCoeHelpContext>* CDemonsymAppUi::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(KUidDemonsymApp, KGeneral_Information));
CleanupStack::Pop(ctxs);
return ctxs;
}
void CDemonsymAppUi::PrivacyStatementL()
{
// Note: to see privacy statement in emulator, copy
// PrivacyStatement.txt from group/ directory to
// %EPOCROOT%\Epoc32\release\winscw\udeb\z\private\e615c43a\
// 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(CDemonsymAppUi::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 * CDemonsymAppUi::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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?