EmailExampleWin.cpp
上传用户:sempras
上传日期:2007-03-04
资源大小:821k
文件大小:4k
源码类别:

Symbian

开发平台:

C/C++

  1. /*
  2. * ============================================================================
  3. *  Name     : CEmailExampleWin from EmailExampleWin.cpp
  4. *  Part of  : EmailExample
  5. *  Created  : 09/11/2003 by Forum Nokia
  6. *  Implementation notes:
  7. *
  8. *  Version  : 1.0
  9. *  Copyright: Nokia Corporation
  10. * ============================================================================
  11. */
  12. #include "EmailExampleWin.h"
  13. #include "EmailExampleVer.h"
  14. #include "EmailExampleAui.h"
  15. #include "EmailExampleViews.h"
  16. #include "EmailExampleEngine.h"
  17. #include <eikdialg.h>
  18. #include <s32crypt.h>
  19. #include "EmailExample.hrh"
  20. #include <EmailExample.rsg>
  21. #include <Eikon.rsg>
  22. #define KRemoteMailView 0
  23. CEmailMainWindow::CEmailMainWindow(CEmailExampleAppUi& aOwner)
  24. : iOwner(aOwner)
  25. {}
  26. CEmailMainWindow::~CEmailMainWindow()
  27. {
  28. iViews.ResetAndDestroy();
  29. delete iEngine;
  30. }
  31. void CEmailMainWindow::ConstructL()
  32. {
  33. iEngine=CEmailExampleEngine::NewL(*this);
  34. // create window but do not activate
  35.     CreateWindowL();
  36. iViews.Append(CRemoteView::NewL(*this));
  37. iViews[KRemoteMailView]->SetFocus(ETrue,EDrawNow);
  38. iViews[KRemoteMailView]->MakeVisible(ETrue);
  39. }
  40. void CEmailMainWindow::HandleEngineChangedEventL(TEmailExampleEngineEvent aEvent)
  41. {
  42. switch(aEvent)
  43. {
  44. case ERemoteCountChanged:
  45. static_cast<CEmailView*>(iViews[KRemoteMailView])->MailCountChange();
  46. iViews[iCurrentView]->DrawDeferred();
  47. break;
  48. }
  49. }
  50. void CEmailMainWindow::Draw(const TRect& aRect) const
  51. {
  52. CWindowGc& gc=SystemGc();
  53. gc.Clear(aRect);
  54. }
  55. void CEmailMainWindow::SizeChanged()
  56. {
  57. TRect rect(Rect());
  58. for(TInt i=0;i<iViews.Count();i++)
  59. iViews[i]->SetRect(rect);
  60. }
  61. TKeyResponse CEmailMainWindow::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
  62. {
  63. return iViews[iCurrentView]->OfferKeyEventL(aKeyEvent,aType);
  64. }
  65. void CEmailMainWindow::HandleCommandL(TInt aCommand)
  66. {
  67.  if( iEngine->HandleAccountNotDefined() )
  68. { //if email settings have not been defined notify user with dialog
  69. CEikDialog* dialog = new (ELeave) CEikDialog;
  70. CleanupStack::PushL(dialog);
  71. //ugly
  72. if( iEngine->iProtocolType == EProtocolImap4 )
  73. {
  74. dialog->ExecuteLD(R_EMAILEXAMPLEAPP_NOIMAP4_DIALOG);
  75. }
  76. else
  77. {
  78. dialog->ExecuteLD(R_EMAILEXAMPLEAPP_NOPOP3_DIALOG);
  79. }
  80. CleanupStack::Pop(dialog);
  81. }
  82.  else
  83. {
  84. static_cast<CEmailView*>(iViews[iCurrentView])->HandleCommandL(aCommand);
  85. }
  86. }
  87. CCoeControl* CEmailMainWindow::ComponentControl(TInt aIndex) const
  88. {
  89. return iViews[aIndex];
  90. }
  91. TInt CEmailMainWindow::CountComponentControls() const
  92. {
  93.     return iViews.Count();
  94. }
  95. void CEmailMainWindow::Reset()
  96. { // clear all data ready for a new file
  97. }
  98. void CEmailMainWindow::SaveFileL(CStreamStore& aStore,CStreamDictionary& aStreamDic,CSecurityBase& aSecurity) const
  99. { // save current data
  100. // create a stream in the store
  101. RStoreWriteStream writeStream;
  102. TStreamId id=writeStream.CreateL(aStore);
  103. // create a secure stream attached to the writeStream so our data gets encrypted
  104. REncryptStream encryptStream;
  105. encryptStream.AttachLC(writeStream,aSecurity,TPtrC8(securityCode,8));
  106. // externalize our data here into 'encryptStream'
  107. //
  108. encryptStream.CommitL();
  109. CleanupStack::PopAndDestroy();  // writeStream
  110. aStreamDic.AssignL(KUidEmailExample,id);
  111. }
  112. void CEmailMainWindow::LoadFileL(const CStreamStore& aStore,const CStreamDictionary& aStreamDic,CSecurityBase& aSecurity,TInt /*aFileVersion*/)
  113. { // load data. can use 'aFileVersion' to determine what is in the file if we change file format
  114. // open the secure stream
  115. TStreamId streamId=aStreamDic.At(KUidEmailExample);
  116. if(streamId==KNullStreamId)
  117. { // no data present in file
  118. }
  119. else
  120. {
  121. RStoreReadStream readStream;
  122. readStream.OpenLC(aStore,streamId);
  123. RDecryptStream decryptStream;
  124. decryptStream.AttachLC(readStream,aSecurity,TPtrC8(securityCode,8));
  125. // internalize our data here from 'decryptStream'
  126. //
  127. CleanupStack::PopAndDestroy(2); // decryptStream and readStream
  128. }
  129. }