/*
============================================================================
Name : MidnightMonitorAppUi.cpp
Author : windcao
Copyright : 2008
Description : CMidnightMonitorAppUi implementation
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <f32file.h>
#include <s32file.h>
#include <hlplch.h>
#include <MidnightMonitor_0xED4BAA38.rsg>
#include "MidnightMonitor_0xED4BAA38.hlp.hrh"
#include "MidnightMonitor.hrh"
#include "MidnightMonitor.pan"
#include "MidnightMonitorApplication.h"
#include "MidnightMonitorAppUi.h"
#include "MidnightMonitorAppView.h"
#include <BACNTF.H>
#include <e32std.h>
_LIT(KFileName, "C:\\private\\ED4BAA38\\MidnightMonitor.txt");
_LIT(KText, "Hello World!");
// ============================ MEMBER FUNCTIONS ===============================
TInt CallBackFunction(TAny* aFunction)
{
return ((CMidnightMonitorAppUi*)aFunction)->ChangeL();
}
// -----------------------------------------------------------------------------
// CMidnightMonitorAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CMidnightMonitorAppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL(CAknAppUi::EAknEnableSkin);
// Create view object
iAppView = CMidnightMonitorAppView::NewL(ClientRect() );
// Create a file to write the text to
TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName);
if ( (KErrNone != err) && (KErrAlreadyExists != err))
{
return;
}
RFile file;
err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite);
CleanupClosePushL(file);
if (KErrNone != err)
{
CleanupStack::PopAndDestroy(1); // file
return;
}
RFileWriteStream outputFileStream(file);
CleanupClosePushL(outputFileStream);
outputFileStream << KText;
CleanupStack::PopAndDestroy(2); // outputFileStream, file
iCallBack = new (ELeave)TCallBack(CallBackFunction, this);
iChangeNotifier = CEnvironmentChangeNotifier::NewL(CActive::EPriorityHigh,
*iCallBack);
iChangeNotifier->Start();
}
// -----------------------------------------------------------------------------
// CMidnightMonitorAppUi::CMidnightMonitorAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CMidnightMonitorAppUi::CMidnightMonitorAppUi()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CMidnightMonitorAppUi::~CMidnightMonitorAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CMidnightMonitorAppUi::~CMidnightMonitorAppUi()
{
if (iAppView)
{
delete iAppView;
iAppView = NULL;
}
if (iChangeNotifier)
{
iChangeNotifier->Cancel();
delete iChangeNotifier;
}
delete iCallBack;
}
TInt CMidnightMonitorAppUi::ChangeL()
{
TInt change = iChangeNotifier->Change();
if (change==127)//当iChangeNotifier 启动的时候绘产生一次回掉此时change为127
{
return -1;
}
if (change & EChangesLocale)
{
// Locale change, do something
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( _L("Locale change"));
}
if (change & EChangesMidnightCrossover)
{
// Midnight crossover, do something
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( _L("Midnight"));
}
if (change & EChangesThreadDeath)
{
// Thread death, do something
// CAknInformationNote* informationNote;
// informationNote = new ( ELeave ) CAknInformationNote;
// // Show the information Note
// informationNote->ExecuteLD( _L("EChangesThreadDeath"));
}
if (change & EChangesPowerStatus)
{
// Power status change, do something
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( _L("EChangesPowerStatus"));
}
if (change & EChangesSystemTime)
{
// System status change, do something
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( _L("EChangesSystemTime"));
}
return 1;
}
// -----------------------------------------------------------------------------
// CMidnightMonitorAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CMidnightMonitorAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ECommand1:
{
}
break;
case ECommand2:
{
RFile rFile;
//Open file where the stream text is
User::LeaveIfError(rFile.Open(CCoeEnv::Static()->FsSession(), KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
CleanupClosePushL(rFile);
// copy stream from file to RFileStream object
RFileReadStream inputFileStream(rFile);
CleanupClosePushL(inputFileStream);
// HBufC descriptor is created from the RFileStream object.
HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( *fileData);
// Pop loaded resources from the cleanup stack
CleanupStack::PopAndDestroy(3); // filedata, inputFileStream, rFile
}
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(EMidnightMonitorUi);
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CMidnightMonitorAppUi::HandleStatusPaneSizeChange()
{
iAppView->SetRect(ClientRect() );
}
CArrayFix<TCoeHelpContext>* CMidnightMonitorAppUi::HelpContextL() const
{
#warning "Please see comment about help and UID3..."
// 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 that 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>* array = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
CleanupStack::PushL(array);
array->AppendL(TCoeHelpContext(KUidMidnightMonitorApp, KGeneral_Information));
CleanupStack::Pop(array);
return array;
}
// End of File
评论0