email/imum/Mtms/Src/SmtpCreateNewOp.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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: 
       
    15 *       SMTP Create New Email operation
       
    16 *
       
    17 */
       
    18 
       
    19 #include <eikenv.h>
       
    20 #include <miuthdr.h>
       
    21 #include <smtpset.h>
       
    22 #include <MTMStore.h>
       
    23 #include <muiumsvuiserviceutilitiesinternal.h>
       
    24 #include <MsvPrgReporter.h>
       
    25 #include <SendUiConsts.h>
       
    26 #include "ImumMtmLogging.h"
       
    27 #include "SmtpCreateNewOp.h"
       
    28 #include "SmtpTimerOp.h"
       
    29 #include "EmailPreCreation.h"
       
    30 #include "MsvConnectionValidation.h"
       
    31 #include "MsvEmailConnectionProgressProvider.h"
       
    32 #include "EmailUtils.H"
       
    33 
       
    34 
       
    35 const TInt KNewMsgOpPriority = CActive::EPriorityStandard;
       
    36 const TInt KIntervalAfterEditorLaunch = 100000; // 0.1 seconds
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // NewL
       
    40 // ----------------------------------------------------------------------------
       
    41 CSmtpCreateNewOp* CSmtpCreateNewOp::NewL(
       
    42     CImumInternalApi& aMailboxApi,
       
    43     TRequestStatus& aObserverRequestStatus,
       
    44     const TEditorParameters& aParams,
       
    45     const TDesC& aAppName,
       
    46     const TDesC8& aEditorProgress)
       
    47     {
       
    48     IMUM_STATIC_CONTEXT( CSmtpCreateNewOp::NewL, 0, mtm, KImumMtmLog );
       
    49     IMUM_IN();
       
    50     
       
    51     CSmtpCreateNewOp* op = new(ELeave) CSmtpCreateNewOp(
       
    52         aMailboxApi, aObserverRequestStatus, aParams, aAppName);
       
    53     CleanupStack::PushL(op);
       
    54     op->ConstructL(aEditorProgress);
       
    55     CleanupStack::Pop();
       
    56     IMUM_OUT();
       
    57     return op;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // ~CSmtpCreateNewOp
       
    62 // ----------------------------------------------------------------------------
       
    63 CSmtpCreateNewOp::~CSmtpCreateNewOp()
       
    64     {
       
    65     IMUM_CONTEXT( CSmtpCreateNewOp::~CSmtpCreateNewOp, 0, KImumMtmLog );
       
    66     IMUM_IN();
       
    67     
       
    68     delete iEditorProgress;
       
    69     IMUM_OUT();
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // RunL
       
    74 // ----------------------------------------------------------------------------
       
    75 void CSmtpCreateNewOp::RunL()
       
    76     {
       
    77     IMUM_CONTEXT( CSmtpCreateNewOp::RunL, 0, KImumMtmLog );
       
    78     IMUM_IN();
       
    79     
       
    80     DoRunL();
       
    81     
       
    82     IMUM_OUT();
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // RunL
       
    87 // ----------------------------------------------------------------------------
       
    88 TInt CSmtpCreateNewOp::RunError(TInt aError)
       
    89 	{
       
    90     IMUM_CONTEXT( CSmtpCreateNewOp::RunError, 0, KImumMtmLog );
       
    91     IMUM_IN();
       
    92 	
       
    93 	IMUM1( 0, "RunL leaved with error code %d", aError );
       
    94 	
       
    95     if( iState == EStateLaunch || iState == EStateDeleteAll || iState == EStateCreateNew )
       
    96         {
       
    97         iProgress().iError = aError;
       
    98         iProgress().iType = TMsvLocalOperationProgress::ELocalNew;
       
    99         iProgress().iTotalNumberOfEntries = 1;
       
   100         iProgress().iNumberFailed = 1;
       
   101         }
       
   102     iMtm = KUidMsvLocalServiceMtm;
       
   103     CompleteObserver();	
       
   104     
       
   105     IMUM_OUT();	
       
   106     
       
   107     return KErrNone;
       
   108 	}
       
   109  
       
   110 // ----------------------------------------------------------------------------
       
   111 // DoRunL
       
   112 // ----------------------------------------------------------------------------
       
   113 void CSmtpCreateNewOp::DoRunL()
       
   114     {
       
   115     IMUM_CONTEXT( CSmtpCreateNewOp::DoRunL, 0, KImumMtmLog );
       
   116     IMUM_IN();
       
   117     
       
   118     TInt err = KErrNone;
       
   119     TPckgBuf<TMsvId> idbuf;
       
   120     if(iStatus.Int() != KErrNone)
       
   121         {
       
   122         err = iStatus.Int();
       
   123         }
       
   124     else if(iOperation)
       
   125         {
       
   126         const TDesC8& prog = iOperation->ProgressL();
       
   127         if(prog.Length())
       
   128             {
       
   129             if(iState == EStateCreate || iState == EStateCreateNew)
       
   130                 {
       
   131                 idbuf.Copy(prog.Left(sizeof(TMsvId)));
       
   132                 if(idbuf() == KMsvNullIndexEntryId)
       
   133                     {
       
   134                     err = KErrGeneral;
       
   135                     }
       
   136                 }
       
   137             else
       
   138                 {
       
   139                 const TUid uid(iOperation->Mtm());
       
   140                 if(uid == KUidMsvLocalServiceMtm)
       
   141                     {
       
   142                     err = McliUtils::GetLocalProgressL(*iOperation).iError;
       
   143                     }
       
   144                 else
       
   145                     {
       
   146                     TBuf<CBaseMtmUi::EProgressStringMaxLen> retString;
       
   147                     TInt totalEntryCount = 0;
       
   148                     TInt entriesDone = 0;
       
   149                     TInt currentEntrySize = 0;
       
   150                     TInt currentBytesTrans = 0;
       
   151                     err = iMtmStore->ClaimMtmUiL(uid).GetProgress(
       
   152                         prog,
       
   153                         retString,
       
   154                         totalEntryCount,
       
   155                         entriesDone,
       
   156                         currentEntrySize,
       
   157                         currentBytesTrans);
       
   158                     iMtmStore->ReleaseMtmUi(uid);
       
   159                     }
       
   160                 }
       
   161             }
       
   162         }
       
   163     if(iOperation)
       
   164         {
       
   165         delete iOperation;
       
   166         iOperation = NULL;
       
   167         }
       
   168     User::LeaveIfError(err); // Caught in RunL()
       
   169 
       
   170     switch(iState)
       
   171         {
       
   172     case EStateIdle:
       
   173     case EStateCreateNew:
       
   174         LaunchEditorL();
       
   175         break;
       
   176     case EStateDeleteAll:
       
   177         CreateMessageL( ETrue );
       
   178         break;
       
   179     case EStateLaunch:
       
   180     case EStateWait:
       
   181         CreateMessageL();
       
   182         break;
       
   183     case EStateCreate:
       
   184         CompleteObserver();
       
   185         break;
       
   186     default:
       
   187         break;
       
   188         }
       
   189     iMtm = (iOperation) ? (iOperation->Mtm()) : (KUidMsvLocalServiceMtm);
       
   190     IMUM_OUT();
       
   191     }
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 // CSmtpCreateNewOp
       
   195 // ----------------------------------------------------------------------------
       
   196 CSmtpCreateNewOp::CSmtpCreateNewOp(
       
   197     CImumInternalApi& aMailboxApi,
       
   198     TRequestStatus& aObserverRequestStatus,
       
   199     const TEditorParameters& aParams,
       
   200     const TDesC& aAppName)
       
   201     :   
       
   202     CSmtpPreCreationOpBase(
       
   203         aMailboxApi.MsvSession(), KNewMsgOpPriority, aObserverRequestStatus ),    
       
   204     iParams(aParams),
       
   205     iAppName(aAppName)
       
   206     {
       
   207     IMUM_CONTEXT( CSmtpCreateNewOp::CSmtpCreateNewOp, 0, KImumMtmLog );
       
   208     IMUM_IN();
       
   209     IMUM_OUT();
       
   210     
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // ConstructL
       
   215 // ----------------------------------------------------------------------------
       
   216 void CSmtpCreateNewOp::ConstructL(const TDesC8& aEditorProgress)
       
   217     {
       
   218     IMUM_CONTEXT( CSmtpCreateNewOp::ConstructL, 0, KImumMtmLog );
       
   219     IMUM_IN();
       
   220     
       
   221     CSmtpPreCreationOpBase::ConstructL();
       
   222     iEditorProgress = aEditorProgress.AllocL();
       
   223     if(iParams.iFlags & EMsgCreateMessageToService)
       
   224         {
       
   225         // Context sensitive service.
       
   226         iService = iParams.iId;
       
   227         }
       
   228     else
       
   229         {
       
   230         iService = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
   231             iMsvSession, KUidMsgTypeSMTP, ETrue);
       
   232         }
       
   233     iStatus = KRequestPending;
       
   234     SetActive();
       
   235     CompleteThis();
       
   236     iState = EStateIdle;
       
   237     IMUM_OUT();
       
   238     }
       
   239 
       
   240 // ----------------------------------------------------------------------------
       
   241 // LaunchEditorL
       
   242 // ----------------------------------------------------------------------------
       
   243 void CSmtpCreateNewOp::LaunchEditorL()
       
   244     {
       
   245     IMUM_CONTEXT( CSmtpCreateNewOp::LaunchEditorL, 0, KImumMtmLog );
       
   246     IMUM_IN();
       
   247     
       
   248     TMsvId id = iPreCreate->FindPreCreatedEmailL(iService, KMsvNullIndexEntryId);
       
   249     if(id != KMsvNullIndexEntryId)
       
   250         {
       
   251         // Adjust editor parameters for editing existing message.
       
   252         iParams.iFlags &= ~(EMsgCreateNewMessage | EMsgCreateMessageToService);
       
   253         iParams.iFlags |= EMsgEditNewMessage;
       
   254         iParams.iId = id;
       
   255         }
       
   256     iStatus = KRequestPending;
       
   257     iOperation = NULL;
       
   258 
       
   259     TRAPD( error, iOperation = MsgEditorLauncher::LaunchEditorApplicationL(
       
   260         iMsvSession,
       
   261         TUid::Uid( KSenduiMtmSmtpUidValue ),
       
   262         iStatus,
       
   263         iParams,
       
   264         iAppName,
       
   265         *iEditorProgress) );
       
   266 
       
   267     if ( error == KErrNotFound && iState == EStateIdle )
       
   268         {
       
   269         // try to recover from the situation where precreated mail is corrupted.
       
   270         iOperation = iPreCreate->DeleteAllPreCreatedEmailsL( iService, iStatus );
       
   271         iState = EStateDeleteAll;
       
   272         }
       
   273     else
       
   274         {
       
   275         if ( error != KErrNone )
       
   276             {
       
   277             User::Leave( KErrCancel );    
       
   278             }
       
   279         iState = EStateLaunch;
       
   280         }
       
   281 
       
   282     SetActive();
       
   283     IMUM_OUT();
       
   284     }
       
   285 
       
   286 // ----------------------------------------------------------------------------
       
   287 // WaitL
       
   288 // ----------------------------------------------------------------------------
       
   289 void CSmtpCreateNewOp::WaitL()
       
   290     {
       
   291     IMUM_CONTEXT( CSmtpCreateNewOp::WaitL, 0, KImumMtmLog );
       
   292     IMUM_IN();
       
   293     
       
   294     iStatus = KRequestPending;
       
   295     CSmtpTimerOp* op = new(ELeave) CSmtpTimerOp(
       
   296         iMailboxApi->MsvSession(), CActive::EPriorityIdle, iStatus);
       
   297     CleanupStack::PushL(op);
       
   298     op->ConstructL();
       
   299     op->After(TTimeIntervalMicroSeconds32(KIntervalAfterEditorLaunch));
       
   300     CleanupStack::Pop(op);
       
   301     iOperation = op;
       
   302     SetActive();
       
   303     iState = EStateWait;
       
   304     IMUM_OUT();
       
   305     }
       
   306 
       
   307 // ----------------------------------------------------------------------------
       
   308 // CreateMessageL
       
   309 // ----------------------------------------------------------------------------
       
   310 void CSmtpCreateNewOp::CreateMessageL( TBool aLaunchEditorAfterCreate /*= EFalse*/ )
       
   311     {
       
   312     IMUM_CONTEXT( CSmtpCreateNewOp::CreateMessageL, 0, KImumMtmLog );
       
   313     IMUM_IN();
       
   314     
       
   315     // Only create if there isn't a message there already.
       
   316     iStatus = KRequestPending;
       
   317     if(iPreCreate->FindPreCreatedEmailL(iService, iParams.iId) == KMsvNullIndexEntryId)
       
   318         {
       
   319         iOperation = iPreCreate->PreCreateBlankEmailL(iService, iStatus);
       
   320         }
       
   321     else
       
   322         {
       
   323         CompleteThis();
       
   324         }
       
   325     SetActive();
       
   326     iState = aLaunchEditorAfterCreate ? EStateCreateNew: EStateCreate;
       
   327     IMUM_OUT();
       
   328     }
       
   329 
       
   330 // End of File