TicTacToeAppUi.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:5k
源码类别:

Symbian

开发平台:

C/C++

  1. /*
  2. * ==============================================================================
  3. *  Name        : TicTacToeAppUi.cpp
  4. *  Part of     : TicTacToe
  5. *  Description : 
  6. *  Version     : 
  7. *
  8. *  Copyright (c) 2005 Nokia Corporation.
  9. * ==============================================================================
  10. */
  11. // INCLUDE FILES
  12. #include "TicTacToeAppUi.h"
  13. #include "TicTacToeAppView.h"
  14. #include "TicTacToe.hrh"
  15. #include <f32file.h>
  16. #include <s32file.h>
  17. // CONSTANTS
  18. _LIT(KTttSettingsFile, "C:\private\E02753ED\TicTacToe.ini");
  19. // ============================ MEMBER FUNCTIONS ===============================
  20. // -----------------------------------------------------------------------------
  21. // CTicTacToeAppUi::ConstructL
  22. // Perform the second phase construction. This needs to be public due
  23. // to the way the framework constructs the AppUi.
  24. // -----------------------------------------------------------------------------
  25. //
  26. void CTicTacToeAppUi::ConstructL()
  27.     {
  28.     BaseConstructL(EAknEnableSkin);
  29.     
  30.     TRAPD(error, LoadSettingsL());
  31.     if ( KErrNone != error )
  32.         {
  33.         iGraphicsSet = 0;
  34.         }
  35.     iAppView = CTicTacToeAppView::NewL(ClientRect(), iGraphicsSet);
  36.     AddToStackL(iAppView);
  37.     }
  38. // -----------------------------------------------------------------------------
  39. // CTicTacToeAppUi::CTicTacToeAppUi
  40. // Perform the first phase of two phase construction. This needs to be
  41. // public due to the way the framework constructs the AppUi.
  42. // -----------------------------------------------------------------------------
  43. //
  44. CTicTacToeAppUi::CTicTacToeAppUi()
  45.     {
  46.     // No implementation required
  47.     }
  48. // -----------------------------------------------------------------------------
  49. // CTicTacToeAppUi::~CTicTacToeAppUi
  50. // Destroy the object.
  51. // -----------------------------------------------------------------------------
  52. //
  53. CTicTacToeAppUi::~CTicTacToeAppUi()
  54.     {
  55.     if ( iAppView )
  56.         {
  57.         iEikonEnv->RemoveFromStack(iAppView);
  58.         delete iAppView;
  59.         iAppView = NULL;
  60.         }
  61.     }
  62. // -----------------------------------------------------------------------------
  63. // CTicTacToeAppUi::HandleCommandL
  64. // Handle user menu selections.
  65. // -----------------------------------------------------------------------------
  66. //
  67. void CTicTacToeAppUi::HandleCommandL(TInt aCommand)
  68.     {
  69.     switch(aCommand)
  70.         {
  71. case ETicTacToeNewGame:
  72. iAppView->NewGame();
  73. break;
  74. case ETicTacToeGraphics1:
  75. SetGraphicsL(0);
  76. break;
  77. case ETicTacToeGraphics2:
  78. SetGraphicsL(1);
  79. break;
  80. case EEikCmdExit:
  81.         case EAknSoftkeyExit:
  82.             SaveSettingsL();
  83.             Exit();
  84.             break;
  85.         default:
  86.             break;
  87.         }
  88.     }
  89. // -----------------------------------------------------------------------------
  90. // CTicTacToeAppUi::HandleScreenDeviceChangedL
  91. // Handle change in screen resolution.
  92. // -----------------------------------------------------------------------------
  93. //
  94. void CTicTacToeAppUi::HandleScreenDeviceChangedL()
  95.     {
  96.     CAknAppUi::HandleScreenDeviceChangedL();
  97.     // Reposition the view
  98.     if ( iAppView )
  99.         {
  100.         iAppView->SetRect(ClientRect());
  101.         }
  102.     }
  103. // -----------------------------------------------------------------------------
  104. // CTicTacToeAppUi::SetGraphicsL
  105. // Change the currently selected graphics set.
  106. // -----------------------------------------------------------------------------
  107. //
  108. void CTicTacToeAppUi::SetGraphicsL(TInt aGraphicsSet)
  109.     {
  110.     if ( iGraphicsSet != aGraphicsSet )
  111.         {
  112.         iGraphicsSet = aGraphicsSet;
  113.         iAppView->LoadIconsL(aGraphicsSet);
  114.         }
  115.     }
  116. // -----------------------------------------------------------------------------
  117. // CTicTacToeAppUi::LoadSettingsL
  118. // Load settings from the config file.
  119. // -----------------------------------------------------------------------------
  120. //
  121. void CTicTacToeAppUi::LoadSettingsL()
  122.     {
  123.     RFileReadStream stream;
  124.     CleanupClosePushL(stream);
  125.     User::LeaveIfError(stream.Open(iCoeEnv->FsSession(),
  126.                                     KTttSettingsFile, EFileRead));
  127.     iGraphicsSet = stream.ReadInt32L();
  128.     CleanupStack::PopAndDestroy(&stream);
  129.     }
  130. // -----------------------------------------------------------------------------
  131. // CTicTacToeAppUi::SaveSettingsL
  132. // Save settings to the config file.
  133. // -----------------------------------------------------------------------------
  134. //
  135. void CTicTacToeAppUi::SaveSettingsL()
  136.     {
  137.     RFileWriteStream stream;
  138.     CleanupClosePushL(stream);
  139.     iCoeEnv->FsSession().MkDirAll(KTttSettingsFile);
  140.     User::LeaveIfError(stream.Replace(iCoeEnv->FsSession(),
  141.                                     KTttSettingsFile, EFileWrite));
  142.     stream.WriteInt32L(iGraphicsSet);
  143.     CleanupStack::PopAndDestroy(&stream);
  144.     }
  145. //  End of File