EmailExampleWin.cpp
上传用户:sempras
上传日期:2007-03-04
资源大小:821k
文件大小:4k
- /*
- * ============================================================================
- * Name : CEmailExampleWin from EmailExampleWin.cpp
- * Part of : EmailExample
- * Created : 09/11/2003 by Forum Nokia
- * Implementation notes:
- *
- * Version : 1.0
- * Copyright: Nokia Corporation
- * ============================================================================
- */
- #include "EmailExampleWin.h"
- #include "EmailExampleVer.h"
- #include "EmailExampleAui.h"
- #include "EmailExampleViews.h"
- #include "EmailExampleEngine.h"
- #include <eikdialg.h>
- #include <s32crypt.h>
- #include "EmailExample.hrh"
- #include <EmailExample.rsg>
- #include <Eikon.rsg>
- #define KRemoteMailView 0
- CEmailMainWindow::CEmailMainWindow(CEmailExampleAppUi& aOwner)
- : iOwner(aOwner)
- {}
- CEmailMainWindow::~CEmailMainWindow()
- {
- iViews.ResetAndDestroy();
- delete iEngine;
- }
- void CEmailMainWindow::ConstructL()
- {
- iEngine=CEmailExampleEngine::NewL(*this);
- // create window but do not activate
- CreateWindowL();
- iViews.Append(CRemoteView::NewL(*this));
- iViews[KRemoteMailView]->SetFocus(ETrue,EDrawNow);
- iViews[KRemoteMailView]->MakeVisible(ETrue);
- }
- void CEmailMainWindow::HandleEngineChangedEventL(TEmailExampleEngineEvent aEvent)
- {
- switch(aEvent)
- {
- case ERemoteCountChanged:
- static_cast<CEmailView*>(iViews[KRemoteMailView])->MailCountChange();
- iViews[iCurrentView]->DrawDeferred();
- break;
- }
- }
- void CEmailMainWindow::Draw(const TRect& aRect) const
- {
- CWindowGc& gc=SystemGc();
- gc.Clear(aRect);
- }
- void CEmailMainWindow::SizeChanged()
- {
- TRect rect(Rect());
- for(TInt i=0;i<iViews.Count();i++)
- iViews[i]->SetRect(rect);
- }
- TKeyResponse CEmailMainWindow::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
- {
- return iViews[iCurrentView]->OfferKeyEventL(aKeyEvent,aType);
- }
- void CEmailMainWindow::HandleCommandL(TInt aCommand)
- {
- if( iEngine->HandleAccountNotDefined() )
- { //if email settings have not been defined notify user with dialog
- CEikDialog* dialog = new (ELeave) CEikDialog;
- CleanupStack::PushL(dialog);
- //ugly
- if( iEngine->iProtocolType == EProtocolImap4 )
- {
- dialog->ExecuteLD(R_EMAILEXAMPLEAPP_NOIMAP4_DIALOG);
- }
- else
- {
- dialog->ExecuteLD(R_EMAILEXAMPLEAPP_NOPOP3_DIALOG);
- }
- CleanupStack::Pop(dialog);
- }
- else
- {
- static_cast<CEmailView*>(iViews[iCurrentView])->HandleCommandL(aCommand);
- }
- }
- CCoeControl* CEmailMainWindow::ComponentControl(TInt aIndex) const
- {
- return iViews[aIndex];
- }
- TInt CEmailMainWindow::CountComponentControls() const
- {
- return iViews.Count();
- }
- void CEmailMainWindow::Reset()
- { // clear all data ready for a new file
- }
- void CEmailMainWindow::SaveFileL(CStreamStore& aStore,CStreamDictionary& aStreamDic,CSecurityBase& aSecurity) const
- { // save current data
- // create a stream in the store
- RStoreWriteStream writeStream;
- TStreamId id=writeStream.CreateL(aStore);
- // create a secure stream attached to the writeStream so our data gets encrypted
- REncryptStream encryptStream;
- encryptStream.AttachLC(writeStream,aSecurity,TPtrC8(securityCode,8));
- // externalize our data here into 'encryptStream'
- //
- encryptStream.CommitL();
- CleanupStack::PopAndDestroy(); // writeStream
- aStreamDic.AssignL(KUidEmailExample,id);
- }
- void CEmailMainWindow::LoadFileL(const CStreamStore& aStore,const CStreamDictionary& aStreamDic,CSecurityBase& aSecurity,TInt /*aFileVersion*/)
- { // load data. can use 'aFileVersion' to determine what is in the file if we change file format
- // open the secure stream
- TStreamId streamId=aStreamDic.At(KUidEmailExample);
- if(streamId==KNullStreamId)
- { // no data present in file
- }
- else
- {
- RStoreReadStream readStream;
- readStream.OpenLC(aStore,streamId);
- RDecryptStream decryptStream;
- decryptStream.AttachLC(readStream,aSecurity,TPtrC8(securityCode,8));
- // internalize our data here from 'decryptStream'
- //
- CleanupStack::PopAndDestroy(2); // decryptStream and readStream
- }
- }