messagingappbase/mce/src/MceSendOperation.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Sends messages from Outbox when user selects "Start" in Outbox.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "MceSendOperation.h"   // header
       
    24 
       
    25 #include <SenduiMtmUids.h>	// mtm uids
       
    26 #include <MTMStore.h>		// CMtmStore
       
    27 #include <mtmuibas.h>		// CBaseMtmUi
       
    28 #include <muiumsvuiserviceutilitiesinternal.h>
       
    29 #include <msvstd.hrh>
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KSendPriority=1000;
       
    34 const TInt KSendSelectionGranularity=4;
       
    35 const TInt KSendServicesGranularity=4;
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // Two-phased constructor.
       
    40 CMceSendOperation* CMceSendOperation::NewL(
       
    41     CMsvSession& aMsvSession,
       
    42     TRequestStatus& aObserverRequestStatus,
       
    43     CMtmStore& aMtmStore,
       
    44     CMsvEntrySelection* aSel)
       
    45     {
       
    46     CMceSendOperation* self = new ( ELeave ) CMceSendOperation(aMsvSession, aObserverRequestStatus, aMtmStore);
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aSel );
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // C++ default constructor can NOT contain any code that
       
    54 // might leave.
       
    55 //
       
    56 CMceSendOperation::CMceSendOperation(
       
    57     CMsvSession& aMsvSession,
       
    58     TRequestStatus& aObserverRequestStatus,
       
    59     CMtmStore& aMtmStore)
       
    60     :
       
    61     CMsvOperation(aMsvSession, KSendPriority, aObserverRequestStatus),
       
    62     iMtmStore( aMtmStore ),
       
    63     iSelections( KSendSelectionGranularity ),
       
    64     iServices( KSendServicesGranularity ),
       
    65     iBlank(_L8(""))
       
    66     {
       
    67     CActiveScheduler::Add(this);
       
    68     }
       
    69 
       
    70 //destructor
       
    71 CMceSendOperation::~CMceSendOperation()
       
    72     {
       
    73     Cancel();
       
    74     delete iOperation;
       
    75     delete iCEntry;
       
    76     iSelections.ResetAndDestroy();
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------
       
    80 // CMceSendOperation::ConstructL
       
    81 // ----------------------------------------------------
       
    82 void CMceSendOperation::ConstructL(CMsvEntrySelection* aSelection)
       
    83     {
       
    84     //@what if service is defined, but has been deleted?
       
    85     //@assert aSelection->Count()>=1
       
    86     // split the selection up into separate selections for particular services (grouped by MTM)
       
    87     CleanupStack::PushL(aSelection);
       
    88     TUid   mtm;
       
    89     TMsvId service;
       
    90     TMsvId actualMessageService;
       
    91     
       
    92     CMsvEntry* rootEntry=iMsvSession.GetEntryL(KMsvRootIndexEntryIdValue);
       
    93     CleanupStack::PushL(rootEntry);
       
    94     rootEntry->SetSortTypeL(TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
       
    95 
       
    96     TInt index;
       
    97     CMsvEntrySelection* sel;
       
    98 
       
    99     iCEntry=iMsvSession.GetEntryL(aSelection->At(0));
       
   100 
       
   101     // nextIndexStart is used to keep the services of a particular MTM together
       
   102     TInt nextIndexStart = KErrNotFound;
       
   103     TMsvId id;
       
   104     TBool isDefaultForMTM = EFalse;
       
   105     TBool sendfirst = EFalse;
       
   106     while (aSelection->Count()>0)
       
   107         {
       
   108         index = (nextIndexStart>KErrNotFound) ? nextIndexStart:0;
       
   109         iCEntry->SetEntryL( aSelection->At(index) );
       
   110         mtm=iCEntry->Entry().iMtm;
       
   111         sendfirst = ( mtm==KSenduiMtmSmsUid );
       
   112         actualMessageService=iCEntry->Entry().iServiceId;
       
   113         service=actualMessageService;
       
   114         TInt serviceFoundErr = KErrNone;
       
   115         TRAP(serviceFoundErr, rootEntry->ChildDataL(service));
       
   116         
       
   117         // Use the default service if the actual message service is not available
       
   118         if ( service == KMsvUnkownServiceIndexEntryIdValue
       
   119             || service == KMsvLocalServiceIndexEntryIdValue
       
   120             || serviceFoundErr )
       
   121             {
       
   122             isDefaultForMTM = ETrue;
       
   123             service = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
   124                 iMsvSession,
       
   125                 mtm, 
       
   126                 ETrue );
       
   127             const TInt getDefaultErr = ( service != KMsvUnkownServiceIndexEntryIdValue &&
       
   128                 service != KMsvLocalServiceIndexEntryIdValue );
       
   129 
       
   130             TInt foundDefaultServiceErr = KErrNone;
       
   131             if ( getDefaultErr == KErrNone )
       
   132                 {
       
   133                 TRAP(foundDefaultServiceErr, rootEntry->ChildDataL(service));
       
   134                 }
       
   135             if (getDefaultErr || foundDefaultServiceErr)
       
   136                 {
       
   137                 CMsvEntrySelection* servs=rootEntry->ChildrenWithMtmL(mtm);
       
   138                 if (servs!=0 && servs->Count()>0)
       
   139                     {
       
   140                     service=servs->At(0);
       
   141                     }
       
   142                 delete servs;
       
   143                 }
       
   144             }
       
   145         else
       
   146             {
       
   147             isDefaultForMTM=EFalse;
       
   148             }
       
   149         sel=new(ELeave) CMsvEntrySelection;
       
   150         CleanupStack::PushL(sel);
       
   151         if (sendfirst)
       
   152             {
       
   153             iServices.InsertL(0,service);
       
   154             iSelections.InsertL(0,sel);
       
   155             }
       
   156         else
       
   157             {
       
   158             iServices.AppendL(service);
       
   159             iSelections.AppendL(sel);
       
   160             }
       
   161         CleanupStack::Pop( sel );
       
   162         nextIndexStart = KErrNotFound;
       
   163         
       
   164         // Entry IDs for this service
       
   165         while (index<aSelection->Count())
       
   166             {
       
   167             id=aSelection->At(index);
       
   168             iCEntry->SetEntryL(id);
       
   169             TBool entryIsForThisMTM = (iCEntry->Entry().iMtm==mtm );
       
   170             TMsvId thisServiceId=iCEntry->Entry().iServiceId;
       
   171             if (entryIsForThisMTM && (thisServiceId==service  || (actualMessageService==thisServiceId && serviceFoundErr) || ((thisServiceId==KMsvUnkownServiceIndexEntryIdValue || thisServiceId==KMsvLocalServiceIndexEntryIdValue) && isDefaultForMTM)))
       
   172                 {
       
   173                 sel->AppendL(id);
       
   174                 aSelection->Delete(index);
       
   175                 }
       
   176             else
       
   177                 {
       
   178                 if (nextIndexStart == KErrNotFound && entryIsForThisMTM)
       
   179                     {
       
   180                     nextIndexStart=index;
       
   181                     }
       
   182 
       
   183                 ++index;
       
   184                 }
       
   185             }
       
   186         }
       
   187 
       
   188     CleanupStack::PopAndDestroy(2, aSelection); // aSelection, rootEntry
       
   189 
       
   190     StartNextOperation();
       
   191     }
       
   192 
       
   193 
       
   194 // ----------------------------------------------------
       
   195 // CMceSendOperation::StartNextOperation
       
   196 // ----------------------------------------------------
       
   197 void CMceSendOperation::StartNextOperation()
       
   198     {
       
   199     if(iOperation)
       
   200         {
       
   201         delete iOperation;
       
   202         iOperation = NULL;
       
   203         }
       
   204     TRAPD(err, MakeNewOperationL());
       
   205 
       
   206     // whether error or not, remove the data for this operation
       
   207     iServices.Delete(0);
       
   208     delete iSelections[0];
       
   209     iSelections.Delete(0);
       
   210     // and set active
       
   211     iStatus=KRequestPending;
       
   212     SetActive();
       
   213     // if error, then complete this pass with the error code
       
   214     if (err)
       
   215         {
       
   216         TRequestStatus* status = &iStatus;
       
   217         User::RequestComplete(status, err);
       
   218         }
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------
       
   222 // CMceSendOperation::MakeNewOperationL
       
   223 // ----------------------------------------------------
       
   224 void CMceSendOperation::MakeNewOperationL()
       
   225     {
       
   226     // get the service entry
       
   227     iCEntry->SetEntryL(iServices[0]);
       
   228     // get the UI setting context to the service
       
   229     CBaseMtmUi& mtmui=iMtmStore.GetMtmUiAndSetContextLC(iCEntry->Entry());
       
   230     // set the new current selection
       
   231     iOperation=mtmui.CopyToL(*iSelections[0], iStatus);
       
   232     // set the current mtm
       
   233     iMtm=iCEntry->Entry().iMtm;
       
   234     CleanupStack::PopAndDestroy(); // release mtmUi
       
   235     }
       
   236 
       
   237 // ----------------------------------------------------
       
   238 // CMceSendOperation::DoCancel
       
   239 // ----------------------------------------------------
       
   240 void CMceSendOperation::DoCancel()
       
   241     {
       
   242     if (iOperation)
       
   243         {
       
   244         iOperation->Cancel();
       
   245         }
       
   246     TRequestStatus* status = &iObserverRequestStatus;
       
   247     User::RequestComplete(status, iStatus.Int());
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------
       
   251 // CMceSendOperation::RunL
       
   252 // ----------------------------------------------------
       
   253 void CMceSendOperation::RunL()
       
   254     {
       
   255     if (iSelections.Count()==0)
       
   256         {
       
   257         // nothing left to process, so complete the observer
       
   258         TRequestStatus* status = &iObserverRequestStatus;
       
   259         User::RequestComplete(status, iStatus.Int());
       
   260         }
       
   261     else
       
   262         {
       
   263         const TDesC8& progress=ProgressL();
       
   264         if (progress.Length()>0)
       
   265             {
       
   266             iMtmStore.GetMtmUiLC(iCEntry->Entry().iMtm).DisplayProgressSummary(progress);
       
   267             CleanupStack::PopAndDestroy(); // release mtmUi
       
   268             }
       
   269         // start the next pass
       
   270         StartNextOperation();
       
   271         }
       
   272     }
       
   273 
       
   274 // ----------------------------------------------------
       
   275 // CMceSendOperation::ProgressL
       
   276 // ----------------------------------------------------
       
   277 const TDesC8& CMceSendOperation::ProgressL()
       
   278     {
       
   279     if (iOperation)
       
   280         {
       
   281         return iOperation->ProgressL();
       
   282         }
       
   283     return iBlank;
       
   284     }
       
   285 
       
   286 // End of file