- /*
- * ==============================================================================
- * Name : TicTacToeAppUi.cpp
- * Part of : TicTacToe
- * Description :
- * Version :
- *
- * Copyright (c) 2005 Nokia Corporation.
- * ==============================================================================
- */
- // INCLUDE FILES
- #include "TicTacToeAppUi.h"
- #include "TicTacToeAppView.h"
- #include "TicTacToe.hrh"
- #include <f32file.h>
- #include <s32file.h>
- // CONSTANTS
- _LIT(KTttSettingsFile, "C:\private\102753ed\TicTacToe.ini");
- // ============================ MEMBER FUNCTIONS ===============================
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::ConstructL
- // Perform the second phase construction. This needs to be public due
- // to the way the framework constructs the AppUi.
- // -----------------------------------------------------------------------------
- //
- void CTicTacToeAppUi::ConstructL()
- {
- BaseConstructL(EAknEnableSkin);
- TRAPD(error, LoadSettingsL());
- if ( KErrNone != error )
- {
- iGraphicsSet = 0;
- }
- iAppView = CTicTacToeAppView::NewL(ClientRect(), iGraphicsSet);
- AddToStackL(iAppView);
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::CTicTacToeAppUi
- // Perform the first phase of two phase construction. This needs to be
- // public due to the way the framework constructs the AppUi.
- // -----------------------------------------------------------------------------
- //
- CTicTacToeAppUi::CTicTacToeAppUi()
- {
- // No implementation required
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::~CTicTacToeAppUi
- // Destroy the object.
- // -----------------------------------------------------------------------------
- //
- CTicTacToeAppUi::~CTicTacToeAppUi()
- {
- if ( iAppView )
- {
- iEikonEnv->RemoveFromStack(iAppView);
- delete iAppView;
- iAppView = NULL;
- }
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::HandleCommandL
- // Handle user menu selections.
- // -----------------------------------------------------------------------------
- //
- void CTicTacToeAppUi::HandleCommandL(TInt aCommand)
- {
- switch(aCommand)
- {
- case ETicTacToeNewGame:
- iAppView->NewGame();
- break;
- case ETicTacToeGraphics1:
- SetGraphicsL(0);
- break;
- case ETicTacToeGraphics2:
- SetGraphicsL(1);
- break;
- case EEikCmdExit:
- case EAknSoftkeyExit:
- SaveSettingsL();
- Exit();
- break;
- default:
- break;
- }
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::HandleScreenDeviceChangedL
- // Handle change in screen resolution.
- // -----------------------------------------------------------------------------
- //
- void CTicTacToeAppUi::HandleScreenDeviceChangedL()
- {
- CAknAppUi::HandleScreenDeviceChangedL();
- // Reposition the view
- if ( iAppView )
- {
- iAppView->SetRect(ClientRect());
- }
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::SetGraphicsL
- // Change the currently selected graphics set.
- // -----------------------------------------------------------------------------
- //
- void CTicTacToeAppUi::SetGraphicsL(TInt aGraphicsSet)
- {
- if ( iGraphicsSet != aGraphicsSet )
- {
- iGraphicsSet = aGraphicsSet;
- iAppView->LoadIconsL(aGraphicsSet);
- }
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::LoadSettingsL
- // Load settings from the config file.
- // -----------------------------------------------------------------------------
- //
- void CTicTacToeAppUi::LoadSettingsL()
- {
- RFileReadStream stream;
- CleanupClosePushL(stream);
- User::LeaveIfError(stream.Open(iCoeEnv->FsSession(),
- KTttSettingsFile, EFileRead));
- iGraphicsSet = stream.ReadInt32L();
- CleanupStack::PopAndDestroy(&stream);
- }
- // -----------------------------------------------------------------------------
- // CTicTacToeAppUi::SaveSettingsL
- // Save settings to the config file.
- // -----------------------------------------------------------------------------
- //
- void CTicTacToeAppUi::SaveSettingsL()
- {
- RFileWriteStream stream;
- CleanupClosePushL(stream);
- iCoeEnv->FsSession().MkDirAll(KTttSettingsFile);
- User::LeaveIfError(stream.Replace(iCoeEnv->FsSession(),
- KTttSettingsFile, EFileWrite));
- stream.WriteInt32L(iGraphicsSet);
- CleanupStack::PopAndDestroy(&stream);
- }
- // End of File