examples/ForumNokia/InternetEmail/src/InternetEmailAppUi.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 
00031 // INCLUDE FILES
00032 #include "InternetEmailAppUi.h"
00033 #include "InternetEmailContainer.h"
00034 #include "InternetEmailDocument.h"
00035 #include "InternetEmailEngine.h"
00036 
00037 #include <eikmenup.h>        // for Menupanes
00038 #include <stringloader.h>    // for easy resource usage
00039 
00040 #include <InternetEmail.rsg>
00041 #include "internetemail.hrh"
00042 
00043 #include <avkon.hrh>
00044 
00045 // ================= MEMBER FUNCTIONS =======================
00046 //
00047 
00048 // ----------------------------------------------------------
00049 // CInternetEmailAppUi::ConstructL()
00050 //  EPOC two phased constructor
00051 // ----------------------------------------------------------
00052 //
00053 void CInternetEmailAppUi::ConstructL()
00054     {
00055 
00056     BaseConstructL(CAknAppUi::EAknEnableSkin);
00057 
00058     iModel = CInternetEmailEngine::NewL(*this); //Must be first in this solution
00059     iAppContainer = new (ELeave) CInternetEmailContainer;
00060     iAppContainer->SetMopParent(this);
00061     iAppContainer->ConstructL( ClientRect(), this );
00062     AddToStackL( iAppContainer );
00063     }
00064 
00065 // ----------------------------------------------------
00066 // CInternetEmailAppUi::~CInternetEmailAppUi()
00067 // ----------------------------------------------------
00068 //
00069 CInternetEmailAppUi::~CInternetEmailAppUi()
00070     {
00071     delete iModel;
00072     delete iWaitDialog;
00073 
00074     if (iAppContainer)
00075         {
00076         RemoveFromStack( iAppContainer );
00077         delete iAppContainer;
00078         }
00079    }
00080 
00081 // -------------------------------------------------------
00082 // CInternetEmailDocument* CInternetEmailAppUi::Document()
00083 // -------------------------------------------------------
00084 //
00085 CInternetEmailDocument* CInternetEmailAppUi::Document()
00086     {
00087     return static_cast<CInternetEmailDocument*>(iDocument);
00088     }
00089 
00090 // -------------------------------------------------------------------------------
00091 // CInternetEmailAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
00092 //  This function is called by the EIKON framework just before it displays
00093 //  a menu pane. Its default implementation is empty, and by overriding it,
00094 //  the application can set the state of menu items dynamically according
00095 //  to the state of application data.
00096 //
00097 //  Here we argue that user must first select one protocol to use before
00098 //  starting the application. We do this buy dimming the menupane choices
00099 //  that should not be possible in different states. We also dim the choices
00100 //  to fetch mail until MsvServer session is ready.
00101 // -------------------------------------------------------------------------------
00102 //
00103 void CInternetEmailAppUi::DynInitMenuPaneL(
00104     TInt aResourceId,CEikMenuPane* aMenuPane)
00105     {
00106     if (aResourceId == R_INTERNETEMAIL_MENU)
00107         {
00108         if (iModel->IsProtocolSet())
00109             {
00110             if( iModel->IsEngineReady() )
00111                 {
00112                 aMenuPane->SetItemDimmed(EInternetEmailCmdProtocol, ETrue);
00113                 aMenuPane->SetItemDimmed(EInternetEmailCmdFetch, EFalse);
00114                 }
00115             else //if MsvServer session is not ready but protocol is selected
00116                 {
00117                 aMenuPane->SetItemDimmed(EInternetEmailCmdProtocol, EFalse);
00118                 aMenuPane->SetItemDimmed(EInternetEmailCmdFetch, EFalse);
00119                 }
00120 
00121             }
00122         else //we dim all if user have not picked the protocol to use.
00123             {
00124             aMenuPane->SetItemDimmed(EInternetEmailCmdProtocol, EFalse);
00125             aMenuPane->SetItemDimmed(EInternetEmailCmdFetch, ETrue);
00126             }
00127         }
00128     }
00129 
00130 // ----------------------------------------------------
00131 // CInternetEmailAppUi::HandleKeyEventL(
00132 //   const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
00133 // ----------------------------------------------------
00134 //
00135 TKeyResponse CInternetEmailAppUi::HandleKeyEventL(
00136     const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
00137     {
00138     return EKeyWasNotConsumed;
00139     }
00140 
00141 // -----------------------------------------------------
00142 // CInternetEmailAppUi::HandleCommandL(TInt aCommand)
00143 //  Here we handle the commands user interface offers to
00144 //  user.
00145 // -----------------------------------------------------
00146 //
00147 void CInternetEmailAppUi::HandleCommandL(TInt aCommand)
00148     {
00149     switch ( aCommand )
00150         {
00151         case EAknSoftkeyExit:
00152         case EEikCmdExit:
00153             {
00154             Exit();
00155             }
00156             break;
00157 
00158         case EInternetEmailCmdFetch:
00159             {
00160             // 1. first we initiate asynchornous mailcommand
00161             iModel->RemoteFetchL();
00162 
00163             // 2. then we show modal wait dialog to user
00164             iWaitDialog = new (ELeave) CAknWaitDialog(
00165             reinterpret_cast<CEikDialog**> (&iWaitDialog));
00166             iWaitDialog->SetCallback(this);
00167             iWaitDialog->ExecuteLD( R_WAIT_NOTE ); //resource based dialog
00168             }
00169             break;
00170 
00171         case EInternetEmailCmdSetPop:
00172             {
00173             if( !iModel->CheckIfExistsL( EProtocolPop3 ) )
00174                 {
00175                 ShowNoteL(R_NO_POP3_DEFINED);
00176                 }
00177             else
00178                 {
00179                 iModel->SetProtocolL( EProtocolPop3 );
00180                 }
00181             }
00182             break;
00183 
00184         case EInternetEmailCmdSetImap:
00185             {
00186             if( !iModel->CheckIfExistsL( EProtocolImap4 ) )
00187                 {
00188                 ShowNoteL(R_NO_IMAP4_DEFINED);
00189                 }
00190             else
00191                 {
00192                 iModel->SetProtocolL( EProtocolImap4 );
00193                 }
00194             }
00195             break;
00196 
00197         default:
00198             break;
00199         }
00200     }
00201 
00202 // --------------------------------------------------
00203 // CInternetEmailEngine* CInternetEmailAppUi::Model()
00204 // --------------------------------------------------
00205 //
00206 CInternetEmailEngine* CInternetEmailAppUi::Model()
00207     {
00208     return iModel;
00209     }
00210 
00211 
00212 // -------------------------------------------------
00213 // void CInternetEmailAppUi::ShowNote( TInt aResId )
00214 //  helper method which creates CAknInformation note
00215 //  from localized resource files with given res.id.
00216 // -------------------------------------------------
00217 //
00218 void CInternetEmailAppUi::ShowNoteL( const TInt &aResId ) const
00219     {
00220         HBufC* textResource = StringLoader::LoadLC( aResId );
00221         CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
00222         informationNote->ExecuteLD(textResource->Des());
00223         CleanupStack::PopAndDestroy(textResource);
00224     }
00225 
00226 // --------------------------------------------------------------------------------
00227 // CInternetEmailAppUi::HandleEngineChangedEventL(TInternetEmailEngineEvent aEvent)
00228 //  From MInternetEmailEngineObserver.
00229 //  Callback which is called from CInternetEmailEngine when email view
00230 //  needs to be updated as model have changed. This event is also used to
00231 //  close wait dialog.
00232 // --------------------------------------------------------------------------------
00233 //
00234 void CInternetEmailAppUi::HandleEngineChangedEventL(TInternetEmailEngineEvent aEvent)
00235     {
00236     switch(aEvent)
00237         {
00238         case ERemoteCountChanged:
00239             {
00240             if( iWaitDialog ) //signal waitdialog to finish
00241                 {
00242                 iWaitDialog->ProcessFinishedL();
00243                 delete iWaitDialog;
00244                 iWaitDialog = NULL;
00245                 }
00246             iAppContainer->MailCountChange();
00247             iAppContainer->DrawDeferred();
00248             }
00249             break;
00250         }
00251     }
00252 
00253 // --------------------------------------------------------------
00254 // void CInternetEmailAppUi::DialogDismissedL(TInt /*aButtonId*/)
00255 //  From MProgressDialogCallback.
00256 //  Callback which is called from CAknWaitDialog if
00257 //  user has dismissed the wait note.
00258 // --------------------------------------------------------------
00259 //
00260 void CInternetEmailAppUi::DialogDismissedL(TInt /*aButtonId*/)
00261     {
00262     iModel->CancelOperation();
00263     }
00264 
00265 // End of File

Generated by  doxygen 1.6.2