messagingappbase/mcesettings/src/MceSettingsSessionObserver.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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 *     Message centre's settings session observer
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <ErrorUI.h> // CErrorUI
       
    23 #include <aknappui.h> // iAvkonAppUi
       
    24 #include <avkon.mbg>
       
    25 
       
    26 #include <mtudreg.h>
       
    27 #include <MTMStore.h>
       
    28 #include <MsgArrays.h> // CUidNameArray
       
    29 #include <msvids.h>
       
    30 #include <msvuids.h>
       
    31 
       
    32 #include <MuiuMsvUiServiceUtilities.h> // MsvUiServiceUtilities
       
    33 #include <MuiuMsvProgressReporterOperation.h>
       
    34 #include <akninputblock.h> // CAknInputBlock
       
    35 #include <SenduiMtmUids.h>
       
    36 
       
    37 #include "MceSettingsSessionObserver.h"
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 const TInt KMceArrayGranularity = 4;
       
    42 const TInt KMceVisibleTextLength = KHumanReadableNameLength;
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 
       
    46 // ----------------------------------------------------
       
    47 // CMceSettingsSessionObserver::Constructor
       
    48 // ----------------------------------------------------
       
    49 CMceSettingsSessionObserver::CMceSettingsSessionObserver( CMsvSession* aSession )
       
    50     :
       
    51     iSession( aSession ),
       
    52     iDeleteSession( EFalse )
       
    53     {
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------
       
    57 // CMceSettingsSessionObserver::Constructor
       
    58 // ----------------------------------------------------
       
    59 void CMceSettingsSessionObserver::ConstructL()
       
    60     {
       
    61     if ( !iSession )
       
    62         {
       
    63         iSession = CMsvSession::OpenSyncL( *this );
       
    64         iDeleteSession = ETrue;
       
    65         }
       
    66     iUiRegistry = CMtmUiDataRegistry::NewL( *iSession );
       
    67     iMtmStore = CMtmStore::NewL( *iSession );
       
    68     iRootEntry=CMsvEntry::NewL(
       
    69         *iSession,
       
    70         KMsvRootIndexEntryId,
       
    71         TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) );
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------
       
    75 // CMceSettingsSessionObserver::Constructor
       
    76 // ----------------------------------------------------
       
    77 EXPORT_C CMceSettingsSessionObserver* CMceSettingsSessionObserver::NewL( CMsvSession* aSession )
       
    78     {
       
    79     CMceSettingsSessionObserver* self = new ( ELeave ) CMceSettingsSessionObserver( aSession );
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop( self );
       
    83     return self;    
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------
       
    87 // CMceSettingsSessionObserver::Destructor
       
    88 // ----------------------------------------------------
       
    89 EXPORT_C CMceSettingsSessionObserver::~CMceSettingsSessionObserver()
       
    90     {
       
    91     delete iRunningOperation;
       
    92     delete iUiRegistry;
       
    93     delete iMtmStore;
       
    94     delete iRootEntry;
       
    95     if ( iDeleteSession )
       
    96         {
       
    97         delete iSession;
       
    98         }
       
    99     }
       
   100 
       
   101 
       
   102 // ----------------------------------------------------
       
   103 // CMceSettingsSessionObserver::Session
       
   104 // ----------------------------------------------------
       
   105 EXPORT_C CMsvSession& CMceSettingsSessionObserver::Session()
       
   106     {
       
   107     return *iSession;
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------
       
   111 // CMceSettingsSessionObserver::UiRegistry
       
   112 // ----------------------------------------------------
       
   113 EXPORT_C CMtmUiDataRegistry* CMceSettingsSessionObserver::UiRegistry() const
       
   114     {
       
   115     return iUiRegistry;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------
       
   119 // CMceSettingsSessionObserver::MtmStore
       
   120 // ----------------------------------------------------
       
   121 EXPORT_C CMtmStore* CMceSettingsSessionObserver::MtmStore() const
       
   122     {
       
   123     return iMtmStore;
       
   124     }
       
   125 
       
   126 // ----------------------------------------------------
       
   127 // CMceSettingsSessionObserver::HandleSessionEventL
       
   128 // ----------------------------------------------------
       
   129 void CMceSettingsSessionObserver::HandleSessionEventL( TMsvSessionEvent /*aEvent*/, 
       
   130                                                                                           TAny* /*aArg1*/, 
       
   131                                                                                           TAny* /*aArg2*/, 
       
   132                                                                                           TAny* /*aArg3*/ )
       
   133     {
       
   134 
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------
       
   138 // CMceSettingsSessionObserver::OpCompleted
       
   139 // ----------------------------------------------------
       
   140 void CMceSettingsSessionObserver::OpCompleted( CMsvSingleOpWatcher& aOpWatcher, 
       
   141                                                                             TInt aCompletionCode )
       
   142     {
       
   143     CMsvOperation* op=&aOpWatcher.Operation();
       
   144     TRAP_IGNORE( DoOperationCompletedL( op, aCompletionCode ) );  
       
   145 
       
   146     if ( iRunningOperation->Operation().Id() == op->Id() )
       
   147         {
       
   148         delete iRunningOperation;
       
   149         iRunningOperation = NULL;
       
   150         }
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------
       
   154 // CMceSettingsSessionObserver::DoOperationCompletedL
       
   155 // ----------------------------------------------------
       
   156 void CMceSettingsSessionObserver::DoOperationCompletedL(
       
   157     CMsvOperation* aOperation, 
       
   158     TInt aCompletionCode )
       
   159     {
       
   160     if ( !aOperation )
       
   161         {
       
   162         return;
       
   163         }
       
   164 
       
   165     if ( aCompletionCode == EEikCmdExit )
       
   166         {
       
   167         iAvkonAppUi->ProcessCommandL( EAknCmdExit );
       
   168         return;
       
   169         }
       
   170 
       
   171     const TDesC8& progress = aOperation->ProgressL();
       
   172 
       
   173     if ( progress.Length() == 0 )
       
   174         {
       
   175         return;
       
   176         }
       
   177 
       
   178     if ( aOperation->Mtm() != KUidMsvLocalServiceMtm )
       
   179         {
       
   180         CAknInputBlock::NewLC();
       
   181         iMtmStore->GetMtmUiLC( aOperation->Mtm() ).DisplayProgressSummary( progress );            
       
   182         CleanupStack::PopAndDestroy( 2 );  // CAknInputBlock, release mtmUi      
       
   183         return;
       
   184         }
       
   185     
       
   186     TMsvLocalOperationProgress localprogress = 
       
   187         McliUtils::GetLocalProgressL( *aOperation );     
       
   188 
       
   189     if ( ( aCompletionCode==KErrNone || aCompletionCode==KErrCancel) &&
       
   190         ( localprogress.iError==KErrNone || localprogress.iError==KErrCancel ) )
       
   191         {
       
   192         return;
       
   193         }
       
   194 
       
   195     CErrorUI* errorUi = CErrorUI::NewL( *CCoeEnv::Static() );
       
   196     CleanupStack::PushL( errorUi );
       
   197     errorUi->ShowGlobalErrorNoteL( localprogress.iError?localprogress.iError:aCompletionCode );
       
   198     CleanupStack::PopAndDestroy( errorUi );
       
   199     }
       
   200 
       
   201 
       
   202 // ----------------------------------------------------
       
   203 // CMceSettingsSessionObserver::CanCreateNewAccountL
       
   204 // ----------------------------------------------------
       
   205 EXPORT_C TBool CMceSettingsSessionObserver::CanCreateNewAccountL( TUid aMtm )
       
   206     {
       
   207     TMsvEntry serviceEntry;
       
   208     serviceEntry.iType=KUidMsvServiceEntry;
       
   209     serviceEntry.iMtm=aMtm;
       
   210     TInt rid;
       
   211     CBaseMtmUiData& uiData = iMtmStore->MtmUiDataL( aMtm );
       
   212     return uiData.CanCreateEntryL( iRootEntry->Entry(), serviceEntry, rid );
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------
       
   216 // CMceSettingsSessionObserver::DeleteAccountL
       
   217 // ----------------------------------------------------
       
   218 EXPORT_C void CMceSettingsSessionObserver::DeleteAccountL( TMsvId aId )
       
   219     {
       
   220     User::LeaveIfError( iRunningOperation ? KErrInUse : KErrNone );
       
   221     TMsvEntry entry;
       
   222     TMsvId serviceId;
       
   223     User::LeaveIfError( iSession->GetEntry( aId, serviceId, entry ) );
       
   224     const TUid mtm = entry.iMtm;
       
   225     CBaseMtmUi* ui = &iMtmStore->ClaimMtmUiL( mtm );
       
   226     if ( ui )
       
   227         {
       
   228         CMtmStoreMtmReleaser::CleanupReleaseMtmUiLC( *iMtmStore, mtm );
       
   229         }
       
   230 
       
   231     CMsvOperation* op = NULL;    
       
   232 
       
   233 // Request free disk space to be implemented
       
   234     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
   235     CleanupStack::PushL( singleOpWatcher );
       
   236     if ( ui )
       
   237         {
       
   238         ui->BaseMtm().SetCurrentEntryL( iSession->GetEntryL( KMsvRootIndexEntryId ) );
       
   239         CAknInputBlock::NewLC();
       
   240         op = ui->DeleteServiceL( entry, singleOpWatcher->iStatus );
       
   241         CleanupStack::PopAndDestroy(); //CAknInputBlock
       
   242         CleanupStack::PushL( op );
       
   243         }
       
   244     else
       
   245         {
       
   246         // could not load mtm, so delete as normal local entry
       
   247         CMsvProgressReporterOperation* progOp = CMsvProgressReporterOperation::NewL(
       
   248             *iSession, singleOpWatcher->iStatus, EMbmAvkonQgn_note_erased );
       
   249         CleanupStack::PushL( progOp );
       
   250 
       
   251         CMsvEntrySelection* selection = new( ELeave ) CMsvEntrySelection();
       
   252         CleanupStack::PushL( selection );
       
   253         selection->AppendL( entry.Id() );
       
   254         CMsvOperation* subOp = iRootEntry->DeleteL( *selection, progOp->RequestStatus() );
       
   255         CleanupStack::PopAndDestroy( selection );
       
   256         progOp->SetOperationL( subOp ); // this takes ownership immediately, so no cleanupstack needed.
       
   257         op = progOp;
       
   258         CleanupStack::PushL( op );
       
   259         }
       
   260 
       
   261     CleanupStack::Pop( op );
       
   262     CleanupStack::Pop( singleOpWatcher );
       
   263     singleOpWatcher->SetOperation( op );
       
   264     iRunningOperation = singleOpWatcher;    
       
   265 
       
   266 // Cancel the free disk space request to be implemented
       
   267 
       
   268     if ( ui )
       
   269         {
       
   270         CleanupStack::PopAndDestroy();// release mtmUi
       
   271         }
       
   272     }
       
   273 
       
   274 // ----------------------------------------------------
       
   275 // CMceSettingsSessionObserver::CreateNewAccountL
       
   276 // ----------------------------------------------------
       
   277 EXPORT_C TBool CMceSettingsSessionObserver::CreateNewAccountL( TUid aMessageType, 
       
   278                                                                            TMsvId aOldServiceId /* = KMsvNullIndexEntryId */)
       
   279     {
       
   280     LeaveIfDiskSpaceUnderCriticalLevelL();
       
   281     User::LeaveIfError ( ( iRunningOperation ? KErrInUse : KErrNone ) );
       
   282 
       
   283     TMsvEntry nentry;
       
   284     nentry.iMtm = aMessageType;
       
   285     nentry.iType.iUid = KUidMsvServiceEntryValue;
       
   286     nentry.iDate.HomeTime();
       
   287     nentry.iServiceId = aOldServiceId;
       
   288 
       
   289     // --- Get the MTM UI relevant to the message type ---
       
   290     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiLC( nentry.iMtm );
       
   291     CMsvEntry* centry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
   292     CleanupStack::PushL( centry );
       
   293     CAknInputBlock::NewLC();
       
   294 
       
   295     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
   296     CleanupStack::PushL( singleOpWatcher );
       
   297 
       
   298     CMsvOperation* op=mtmUi.CreateL(
       
   299         nentry,
       
   300         *centry,
       
   301         singleOpWatcher->iStatus );
       
   302 
       
   303     CleanupStack::PushL( op );
       
   304     singleOpWatcher->SetOperation( op );
       
   305     iRunningOperation = singleOpWatcher;
       
   306     CleanupStack::Pop( op );
       
   307     CleanupStack::Pop( singleOpWatcher );
       
   308 
       
   309     TBool accountCreated = ( op->iStatus != KErrCancel );
       
   310     // if not created, imum returns completed operation with KErrCancel
       
   311 
       
   312     CleanupStack::PopAndDestroy(); // command absorb
       
   313     CleanupStack::PopAndDestroy( centry );
       
   314     CleanupStack::PopAndDestroy(); // mtm ui release
       
   315     return accountCreated;
       
   316     }
       
   317 
       
   318 
       
   319 // ----------------------------------------------------
       
   320 // CMceSettingsSessionObserver::EditAccountL
       
   321 // ----------------------------------------------------
       
   322 EXPORT_C void CMceSettingsSessionObserver::EditAccountL( TMsvId aId )
       
   323     {
       
   324     LeaveIfDiskSpaceUnderCriticalLevelL();
       
   325     User::LeaveIfError ( ( iRunningOperation ? KErrInUse : KErrNone ) );
       
   326 
       
   327     TMsvEntry entry;
       
   328     TMsvId serviceId;
       
   329     User::LeaveIfError( iSession->GetEntry( aId, serviceId, entry ) );
       
   330 
       
   331     if ( entry.iType == KUidMsvServiceEntry )
       
   332         {
       
   333         CBaseMtmUi& mtmUi=iMtmStore->GetMtmUiAndSetContextLC( entry );
       
   334         CAknInputBlock::NewLC();
       
   335         CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
   336         CleanupStack::PushL( singleOpWatcher );
       
   337         CMsvOperation* op=mtmUi.EditL( singleOpWatcher->iStatus );
       
   338         CleanupStack::PushL( op );
       
   339         singleOpWatcher->SetOperation( op );
       
   340         iRunningOperation = singleOpWatcher;
       
   341         CleanupStack::Pop( op ); 
       
   342         CleanupStack::Pop( singleOpWatcher );
       
   343         CleanupStack::PopAndDestroy( 2 ); // CAknInputBlock, release mtmUi
       
   344         }
       
   345     }
       
   346 
       
   347 // ----------------------------------------------------
       
   348 // CMceSettingsSessionObserver::MtmAccountsL
       
   349 // ----------------------------------------------------
       
   350 EXPORT_C CUidNameArray* CMceSettingsSessionObserver::MtmAccountsL( TUid aType )
       
   351     {
       
   352     CUidNameArray* accounts = new (ELeave) CUidNameArray(
       
   353         KMceArrayGranularity );
       
   354     CleanupStack::PushL( accounts );
       
   355 
       
   356     CMsvEntrySelection* sel = NULL;
       
   357 
       
   358     if ( aType == KSenduiMtmSmtpUid )
       
   359         {
       
   360         sel = MsvUiServiceUtilities::GetListOfAccountsL(
       
   361             *iSession,
       
   362             ETrue );
       
   363         }
       
   364     else
       
   365         {
       
   366         sel = MsvUiServiceUtilities::GetListOfAccountsWithMTML(
       
   367             *iSession,
       
   368             aType,
       
   369             ETrue );
       
   370         }
       
   371     CleanupStack::PushL( sel );
       
   372 
       
   373     CMsvEntry* rootEntry=CMsvEntry::NewL(
       
   374         *iSession,
       
   375         KMsvRootIndexEntryId,
       
   376         TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue ) );
       
   377     delete iRootEntry;
       
   378     iRootEntry = rootEntry;
       
   379 
       
   380     TUid uid;
       
   381     TUid techType=iUiRegistry->TechnologyTypeUid( aType );
       
   382     const TInt numAccounts=sel->Count();
       
   383     for (TInt cc=0; cc<numAccounts; cc++)
       
   384         {
       
   385         uid.iUid=sel->At(cc);
       
   386         TMsvEntry tentry;
       
   387         TRAPD( err, ( tentry = iRootEntry->ChildDataL( uid.iUid ) ) );
       
   388         if ( err == KErrNone &&
       
   389             iUiRegistry->IsPresent( tentry.iMtm ) && 
       
   390             iUiRegistry->TechnologyTypeUid( tentry.iMtm ) == techType )
       
   391             {
       
   392             const TInt count = accounts->Count();
       
   393             TBool foundService = EFalse;
       
   394             //check that related service is not already added to array
       
   395             for ( TInt loop = 0; loop < count; loop ++ )
       
   396                 {
       
   397                 if ( tentry.iRelatedId == ( *accounts )[loop].iUid.iUid )
       
   398                     {
       
   399                     foundService = ETrue;
       
   400                     break;
       
   401                     }
       
   402                 }
       
   403             if ( !foundService )
       
   404                 {
       
   405                 TUidNameInfo info( uid, tentry.iDetails.Left( KMceVisibleTextLength ) );
       
   406                 accounts->AppendL( info );
       
   407                 }
       
   408             }
       
   409         }
       
   410     CleanupStack::PopAndDestroy( sel );
       
   411     CleanupStack::Pop( accounts );
       
   412     return accounts;
       
   413     }
       
   414 
       
   415 // ----------------------------------------------------
       
   416 // CMceSettingsSessionObserver::IsPresent
       
   417 // ----------------------------------------------------
       
   418 EXPORT_C TBool CMceSettingsSessionObserver::IsPresent( TUid aMtm ) const
       
   419     {
       
   420     return iUiRegistry->IsPresent( aMtm );
       
   421     }
       
   422 
       
   423 // ----------------------------------------------------
       
   424 // CMceSettingsSessionObserver::LeaveIfDiskSpaceUnderCriticalLevelL
       
   425 // ----------------------------------------------------
       
   426 void CMceSettingsSessionObserver::LeaveIfDiskSpaceUnderCriticalLevelL( TInt aBytesToWrite ) const
       
   427     {
       
   428     if ( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( *iSession, aBytesToWrite) )
       
   429         {
       
   430         User::Leave( KErrDiskFull );
       
   431         }
       
   432     }
       
   433 
       
   434 // ----------------------------------------------------
       
   435 // CMceSettingsSessionObserver::CancelFreeDiskSpaceRequest
       
   436 // Static function.
       
   437 // ----------------------------------------------------
       
   438 void CMceSettingsSessionObserver::CancelFreeDiskSpaceRequest(TAny* /*aAny*/)
       
   439     {
       
   440     // Cancel free disk space request to be implemented
       
   441     }
       
   442 
       
   443 // ----------------------------------------------------
       
   444 // CMceSettingsSessionObserver::MtmName
       
   445 //
       
   446 // ----------------------------------------------------
       
   447 EXPORT_C THumanReadableName CMceSettingsSessionObserver::MtmName( TUid aMtm ) const
       
   448     {
       
   449     return iUiRegistry->RegisteredMtmDllInfo( aMtm ).HumanReadableName();
       
   450     }
       
   451     
       
   452 // ----------------------------------------------------
       
   453 // CMceSettingsSessionObserver::SetChangeMessageStore
       
   454 //
       
   455 // ----------------------------------------------------
       
   456 EXPORT_C void CMceSettingsSessionObserver::SetChangeMessageStore( TBool /*aChangeEnded*/ )
       
   457     {
       
   458     // do nothing...
       
   459     }