examples/ForumNokia/InternetEmail/src/InternetEmailAppUi.cpp

00001 /*
00002  * Copyright � 2008 Nokia Corporation.
00003  */
00004 
00005 
00006 // INCLUDE FILES
00007 #include "InternetEmailAppUi.h"
00008 #include "InternetEmailContainer.h"
00009 #include "InternetEmailDocument.h"
00010 #include "InternetEmailEngine.h"
00011 
00012 #include <eikmenup.h>        // for Menupanes
00013 #include <stringloader.h>    // for easy resource usage
00014 
00015 #include <InternetEmail.rsg>
00016 #include "internetemail.hrh"
00017 
00018 #include <avkon.hrh>
00019 
00020 // ================= MEMBER FUNCTIONS =======================
00021 //
00022 
00023 // ----------------------------------------------------------
00024 // CInternetEmailAppUi::ConstructL()
00025 //  EPOC two phased constructor
00026 // ----------------------------------------------------------
00027 //
00028 void CInternetEmailAppUi::ConstructL()
00029     {
00030 
00031     BaseConstructL(CAknAppUi::EAknEnableSkin);
00032 
00033     iModel = CInternetEmailEngine::NewL(*this); //Must be first in this solution
00034     iAppContainer = new (ELeave) CInternetEmailContainer;
00035     iAppContainer->SetMopParent(this);
00036     iAppContainer->ConstructL( ClientRect(), this );
00037     AddToStackL( iAppContainer );
00038     }
00039 
00040 // ----------------------------------------------------
00041 // CInternetEmailAppUi::~CInternetEmailAppUi()
00042 // ----------------------------------------------------
00043 //
00044 CInternetEmailAppUi::~CInternetEmailAppUi()
00045     {
00046     delete iModel;
00047     delete iWaitDialog;
00048 
00049     if (iAppContainer)
00050         {
00051         RemoveFromStack( iAppContainer );
00052         delete iAppContainer;
00053         }
00054    }
00055 
00056 // -------------------------------------------------------
00057 // CInternetEmailDocument* CInternetEmailAppUi::Document()
00058 // -------------------------------------------------------
00059 //
00060 CInternetEmailDocument* CInternetEmailAppUi::Document()
00061     {
00062     return static_cast<CInternetEmailDocument*>(iDocument);
00063     }
00064 
00065 // -------------------------------------------------------------------------------
00066 // CInternetEmailAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
00067 //  This function is called by the EIKON framework just before it displays
00068 //  a menu pane. Its default implementation is empty, and by overriding it,
00069 //  the application can set the state of menu items dynamically according
00070 //  to the state of application data.
00071 //
00072 //  Here we argue that user must first select one protocol to use before
00073 //  starting the application. We do this buy dimming the menupane choices
00074 //  that should not be possible in different states. We also dim the choices
00075 //  to fetch mail until MsvServer session is ready.
00076 // -------------------------------------------------------------------------------
00077 //
00078 void CInternetEmailAppUi::DynInitMenuPaneL(
00079     TInt aResourceId,CEikMenuPane* aMenuPane)
00080     {
00081     if (aResourceId == R_INTERNETEMAIL_MENU)
00082         {
00083         if (iModel->IsProtocolSet())
00084             {
00085             if( iModel->IsEngineReady() )
00086                 {
00087                 aMenuPane->SetItemDimmed(EInternetEmailCmdProtocol, ETrue);
00088                 aMenuPane->SetItemDimmed(EInternetEmailCmdFetch, EFalse);
00089                 }
00090             else //if MsvServer session is not ready but protocol is selected
00091                 {
00092                 aMenuPane->SetItemDimmed(EInternetEmailCmdProtocol, EFalse);
00093                 aMenuPane->SetItemDimmed(EInternetEmailCmdFetch, EFalse);
00094                 }
00095 
00096             }
00097         else //we dim all if user have not picked the protocol to use.
00098             {
00099             aMenuPane->SetItemDimmed(EInternetEmailCmdProtocol, EFalse);
00100             aMenuPane->SetItemDimmed(EInternetEmailCmdFetch, ETrue);
00101             }
00102         }
00103     }
00104 
00105 // ----------------------------------------------------
00106 // CInternetEmailAppUi::HandleKeyEventL(
00107 //   const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
00108 // ----------------------------------------------------
00109 //
00110 TKeyResponse CInternetEmailAppUi::HandleKeyEventL(
00111     const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
00112     {
00113     return EKeyWasNotConsumed;
00114     }
00115 
00116 // -----------------------------------------------------
00117 // CInternetEmailAppUi::HandleCommandL(TInt aCommand)
00118 //  Here we handle the commands user interface offers to
00119 //  user.
00120 // -----------------------------------------------------
00121 //
00122 void CInternetEmailAppUi::HandleCommandL(TInt aCommand)
00123     {
00124     switch ( aCommand )
00125         {
00126         case EAknSoftkeyExit:
00127         case EEikCmdExit:
00128             {
00129             Exit();
00130             }
00131             break;
00132 
00133         case EInternetEmailCmdFetch:
00134             {
00135             // 1. first we initiate asynchornous mailcommand
00136             iModel->RemoteFetchL();
00137 
00138             // 2. then we show modal wait dialog to user
00139             iWaitDialog = new (ELeave) CAknWaitDialog(
00140             reinterpret_cast<CEikDialog**> (&iWaitDialog));
00141             iWaitDialog->SetCallback(this);
00142             iWaitDialog->ExecuteLD( R_WAIT_NOTE ); //resource based dialog
00143             }
00144             break;
00145 
00146         case EInternetEmailCmdSetPop:
00147             {
00148             if( !iModel->CheckIfExistsL( EProtocolPop3 ) )
00149                 {
00150                 ShowNoteL(R_NO_POP3_DEFINED);
00151                 }
00152             else
00153                 {
00154                 iModel->SetProtocolL( EProtocolPop3 );
00155                 }
00156             }
00157             break;
00158 
00159         case EInternetEmailCmdSetImap:
00160             {
00161             if( !iModel->CheckIfExistsL( EProtocolImap4 ) )
00162                 {
00163                 ShowNoteL(R_NO_IMAP4_DEFINED);
00164                 }
00165             else
00166                 {
00167                 iModel->SetProtocolL( EProtocolImap4 );
00168                 }
00169             }
00170             break;
00171 
00172         default:
00173             break;
00174         }
00175     }
00176 
00177 // --------------------------------------------------
00178 // CInternetEmailEngine* CInternetEmailAppUi::Model()
00179 // --------------------------------------------------
00180 //
00181 CInternetEmailEngine* CInternetEmailAppUi::Model()
00182     {
00183     return iModel;
00184     }
00185 
00186 
00187 // -------------------------------------------------
00188 // void CInternetEmailAppUi::ShowNote( TInt aResId )
00189 //  helper method which creates CAknInformation note
00190 //  from localized resource files with given res.id.
00191 // -------------------------------------------------
00192 //
00193 void CInternetEmailAppUi::ShowNoteL( const TInt &aResId ) const
00194     {
00195         HBufC* textResource = StringLoader::LoadLC( aResId );
00196         CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
00197         informationNote->ExecuteLD(textResource->Des());
00198         CleanupStack::PopAndDestroy(textResource);
00199     }
00200 
00201 // --------------------------------------------------------------------------------
00202 // CInternetEmailAppUi::HandleEngineChangedEventL(TInternetEmailEngineEvent aEvent)
00203 //  From MInternetEmailEngineObserver.
00204 //  Callback which is called from CInternetEmailEngine when email view
00205 //  needs to be updated as model have changed. This event is also used to
00206 //  close wait dialog.
00207 // --------------------------------------------------------------------------------
00208 //
00209 void CInternetEmailAppUi::HandleEngineChangedEventL(TInternetEmailEngineEvent aEvent)
00210     {
00211     switch(aEvent)
00212         {
00213         case ERemoteCountChanged:
00214             {
00215             if( iWaitDialog ) //signal waitdialog to finish
00216                 {
00217                 iWaitDialog->ProcessFinishedL();
00218                 delete iWaitDialog;
00219                 iWaitDialog = NULL;
00220                 }
00221             iAppContainer->MailCountChange();
00222             iAppContainer->DrawDeferred();
00223             }
00224             break;
00225         }
00226     }
00227 
00228 // --------------------------------------------------------------
00229 // void CInternetEmailAppUi::DialogDismissedL(TInt /*aButtonId*/)
00230 //  From MProgressDialogCallback.
00231 //  Callback which is called from CAknWaitDialog if
00232 //  user has dismissed the wait note.
00233 // --------------------------------------------------------------
00234 //
00235 void CInternetEmailAppUi::DialogDismissedL(TInt /*aButtonId*/)
00236     {
00237     iModel->CancelOperation();
00238     }
00239 
00240 // End of File

Generated by  doxygen 1.6.2