emailservices/emailserver/cmailhandlerplugin/src/fsnotificationhandlernotifierinitiator.cpp
branchRCL_3
changeset 25 3533d4323edc
parent 0 8466d47a6819
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: This file implements class CFSNotificationHandlerNotifierInitiator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail>
       
    20 //#include <eikenv.h>
       
    21 //#include <aknappui.h>
       
    22 //#include <aknmessagequerydialog.h>
       
    23 //#include <eiksrvui.h>   // CEikServAppUi
       
    24 //</cmail>
       
    25 
       
    26 #include "emailtrace.h"
       
    27 #include <fsmailserver.rsg>
       
    28 //<cmail>
       
    29 #include "fsmailserverconst.h"
       
    30 //</cmail>
       
    31 
       
    32 #include "fsnotificationhandlernotifierinitiator.h"
       
    33 #include "fsnotificationhandlermgr.h"
       
    34 #include "fsmailoutofmemoryhandler.h"
       
    35 //<cmail>
       
    36 //#include "FsEmailGlobalDialogsAppUi.h"
       
    37 //</cmail>
       
    38 #include "FsEmailAuthenticationDialog.h"
       
    39 #include "FsEmailMessageQueryDialog.h"
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 CFSNotificationHandlerNotifierInitiator::CFSNotificationHandlerNotifierInitiator(
       
    44     MFSNotificationHandlerNotifierInitiatorObserver& aOwner,
       
    45     MFSNotificationHandlerMgr& aNotificationHandlerMgr ) :
       
    46     CActive( EPriorityStandard ),
       
    47     iOwner( aOwner ),
       
    48     iNotificationHandlerMgr( aNotificationHandlerMgr ),
       
    49     iMailBoxId(),
       
    50     iCallback( NULL )
       
    51     {
       
    52     FUNC_LOG;
       
    53     iMessageType = static_cast<TFsEmailNotifierSystemMessageType>( -1 );
       
    54     }
       
    55 
       
    56 void CFSNotificationHandlerNotifierInitiator::ConstructL()
       
    57     {
       
    58     FUNC_LOG;
       
    59     CActiveScheduler::Add( this );
       
    60     User::LeaveIfError( iNotifier.Connect() );
       
    61     }
       
    62 
       
    63 CFSNotificationHandlerNotifierInitiator* CFSNotificationHandlerNotifierInitiator::NewL(
       
    64     MFSNotificationHandlerNotifierInitiatorObserver& aOwner,
       
    65     MFSNotificationHandlerMgr& aNotificationHandlerMgr )
       
    66     {
       
    67     FUNC_LOG;
       
    68     CFSNotificationHandlerNotifierInitiator* self = CFSNotificationHandlerNotifierInitiator::NewLC(
       
    69         aOwner, aNotificationHandlerMgr );
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73 
       
    74 CFSNotificationHandlerNotifierInitiator* CFSNotificationHandlerNotifierInitiator::NewLC(
       
    75     MFSNotificationHandlerNotifierInitiatorObserver& aOwner,
       
    76     MFSNotificationHandlerMgr& aNotificationHandlerMgr )
       
    77     {
       
    78     FUNC_LOG;
       
    79     CFSNotificationHandlerNotifierInitiator* self = new( ELeave ) CFSNotificationHandlerNotifierInitiator(
       
    80             aOwner, aNotificationHandlerMgr );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     return self;
       
    84     }
       
    85 
       
    86 
       
    87 void CFSNotificationHandlerNotifierInitiator::SetMailBoxId(
       
    88     TFSMailMsgId aNewMailBoxId )
       
    89     {
       
    90     FUNC_LOG;
       
    91     iMailBoxId.SetPluginId( aNewMailBoxId.PluginId() );
       
    92     iMailBoxId.SetId( aNewMailBoxId.Id() );
       
    93     }
       
    94 
       
    95 TFSMailMsgId CFSNotificationHandlerNotifierInitiator::MailBoxId() const
       
    96     {
       
    97     FUNC_LOG;
       
    98     return iMailBoxId;
       
    99     }
       
   100 
       
   101 void CFSNotificationHandlerNotifierInitiator::SetMessageType(
       
   102         TFsEmailNotifierSystemMessageType aMessageType )
       
   103     {
       
   104     FUNC_LOG;
       
   105     iMessageType = aMessageType;
       
   106     }
       
   107 
       
   108 TFsEmailNotifierSystemMessageType CFSNotificationHandlerNotifierInitiator::MessageType() const
       
   109     {
       
   110     FUNC_LOG;
       
   111     return iMessageType;
       
   112     }
       
   113 
       
   114 void CFSNotificationHandlerNotifierInitiator::SetCallback(
       
   115         MFSMailExceptionEventCallback* aCallback )
       
   116     {
       
   117     FUNC_LOG;
       
   118     iCallback = aCallback;
       
   119     }
       
   120 
       
   121 MFSMailExceptionEventCallback* CFSNotificationHandlerNotifierInitiator::Callback() const
       
   122     {
       
   123     FUNC_LOG;
       
   124     return iCallback;
       
   125     }
       
   126 
       
   127 
       
   128 CFSNotificationHandlerNotifierInitiator::
       
   129     ~CFSNotificationHandlerNotifierInitiator()
       
   130     {
       
   131     Cancel();
       
   132     iNotifier.Close();
       
   133     }
       
   134 
       
   135 void CFSNotificationHandlerNotifierInitiator::BeforeDialog()
       
   136     {
       
   137     FUNC_LOG;
       
   138     iLogin = EFalse;
       
   139     iNotificationHandlerMgr.IncreaseDialogCount();
       
   140     //<cmail>
       
   141     //iNotificationHandlerMgr.AppUi().BringToForeground();
       
   142     iNotificationHandlerMgr.BringAppUiToForeground();
       
   143     //</cmail>
       
   144     }
       
   145 
       
   146 void CFSNotificationHandlerNotifierInitiator::AfterDialog()
       
   147     {
       
   148     FUNC_LOG;
       
   149     // Decrease the dialog count and send mail server to background
       
   150     // if this was last active dialog.
       
   151     iNotificationHandlerMgr.DecreaseDialogCount();
       
   152     if( iNotificationHandlerMgr.GetDialogCount() <= 0 )
       
   153         {
       
   154         //<cmail>
       
   155         //iNotificationHandlerMgr.AppUi().SendToBackground();
       
   156         iNotificationHandlerMgr.SendAppUiToBackground();
       
   157         //</cmail>
       
   158         }
       
   159     }
       
   160 
       
   161 void CFSNotificationHandlerNotifierInitiator::RequestMessageQueryL(
       
   162     TDesC& aMailboxName,
       
   163     TFsEmailNotifierSystemMessageType aMessageType,
       
   164     const TDesC& aCustomMessageText )
       
   165     {
       
   166     FUNC_LOG;
       
   167     Cancel();
       
   168 
       
   169     // <cmail>
       
   170     BeforeDialog();
       
   171     TRAPD( err, iNotificationHandlerMgr.MessageQueryL( aMailboxName, iStatus, aCustomMessageText, aMessageType ) );
       
   172     // </cmail>
       
   173 
       
   174     if( KErrNone != err )
       
   175         {
       
   176         AfterDialog();
       
   177         User::Leave( err );
       
   178         }
       
   179     SetActive();
       
   180     }
       
   181 
       
   182 void CFSNotificationHandlerNotifierInitiator::RequestAuthenticationL(
       
   183     TDesC& aMailboxName )
       
   184     {
       
   185     FUNC_LOG;
       
   186 
       
   187     Cancel();
       
   188     iPassword.Zero();
       
   189     //<cmail>
       
   190     BeforeDialog();
       
   191 
       
   192     TInt err( iNotificationHandlerMgr.AuthenticateL( iPassword, aMailboxName, iStatus ) );
       
   193     //</cmail>
       
   194 
       
   195     if( err != KErrNone )
       
   196         {
       
   197         AfterDialog();
       
   198         User::Leave( err );
       
   199         }
       
   200 
       
   201     SetActive();
       
   202     }
       
   203 
       
   204 void CFSNotificationHandlerNotifierInitiator::GetLastAuthenticationOutput(
       
   205     TBuf<KFsEmailNotifierPasswordMaxLength>& aPassword ) const
       
   206     {
       
   207     FUNC_LOG;
       
   208     aPassword = iPassword;
       
   209     }
       
   210 
       
   211 TBool CFSNotificationHandlerNotifierInitiator::GetLastResponse() const
       
   212     {
       
   213     FUNC_LOG;
       
   214     return iLogin;
       
   215     }
       
   216 
       
   217 void CFSNotificationHandlerNotifierInitiator::DoCancel()
       
   218     {
       
   219     FUNC_LOG;
       
   220     // Let's cancel the notification if showing of it is still
       
   221     // pending.
       
   222     AfterDialog();
       
   223     }
       
   224 
       
   225 void CFSNotificationHandlerNotifierInitiator::RunL()
       
   226     {
       
   227     FUNC_LOG;
       
   228     // Notification showing is complete. We don't check the outcome
       
   229     // because we have no use for it anymore. There is no way
       
   230     // to communicate a possible error to the object that has
       
   231     // requested of the notification originally.
       
   232     AfterDialog();
       
   233     if( iStatus == KErrNone )
       
   234         {
       
   235         iLogin = ETrue;
       
   236         }
       
   237     else
       
   238         {
       
   239         iLogin = EFalse;
       
   240         }
       
   241 
       
   242     // Delete this. No member variable usage after this!
       
   243     iOwner.NotifierInitiatorDoneL( this );
       
   244     }
       
   245