email/imum/Utils/Src/IMSFolderSubscription.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 *       folder subscription dialog
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <impicmds.h>
       
    22 #include <ImumUtils.rsg>
       
    23 #include <MTMStore.h>
       
    24 #include <msvuids.h>
       
    25 #include <mtudcbas.h>
       
    26 #include <mtmuibas.h>
       
    27 #include <miuthdr.h>
       
    28 #include <imapcmds.h>
       
    29 #include <gulicon.h>
       
    30 #include <gulutil.h>
       
    31 #include <eikclb.h>
       
    32 #include <eikclbd.h>
       
    33 #include <eiktxlbm.h>
       
    34 #include <aknlists.h>
       
    35 #include <AknIconArray.h>                   // CAknIconArray
       
    36 #include <StringLoader.h>
       
    37 #include <eikmenup.h>
       
    38 #include <hlplch.h>                         // For HlpLauncher
       
    39 #include <muiu.mbg>
       
    40 #include <coemain.h>
       
    41 #include <MuiuOperationWait.h>
       
    42 #include <AknQueryDialog.h>
       
    43 #include <akninputblock.h> 					// CAknInputBlock
       
    44 #include <AknsUtils.h>
       
    45 #include <AknsConstants.h>                  // Skinned icon ids
       
    46 #include <mtudcbas.h>
       
    47 #include "IMSFolderSubscription.h"
       
    48 #include "ImumPanic.h"
       
    49 #include "EmailUtils.H"
       
    50 #include "EmailFeatureUtils.h"
       
    51 #include "IMSSettingsDialog.h"              // EDialogLastFlag
       
    52 #include "ImumInternalApiImpl.h"
       
    53 #include "ImumInMailboxUtilitiesImpl.h"
       
    54 #include "ImumInSettingsDataCollection.h"
       
    55 #include "ImumInSettingsData.h"
       
    56 #include <data_caging_path_literals.hrh>
       
    57 #include "ImumUtilsLogging.h"
       
    58 #include <csxhelp/mbxs.hlp.hrh>
       
    59 
       
    60 #include <aknnavide.h>
       
    61 #include "ImumNaviPaneFolderIndicator.h"
       
    62 
       
    63 // CONSTANTS
       
    64 enum TIFSFlags
       
    65     {
       
    66     EIFSPreviousFolderOpenVisible = EDialogLastFlag,
       
    67     EIFSPreviousSubscriptionUndimmed,
       
    68     EIFSSubscriptionsChanged,
       
    69     EIFSLastFlag
       
    70     };
       
    71 
       
    72 // Correct path is added to literal when it is used.
       
    73 _LIT(KMuiuBitmapFile, "z:muiu.MBM");
       
    74 const TInt KImumFolderArrayVisibleItems = 5;
       
    75 const TInt KImumFolderIconArrayGranularity = 6;
       
    76 
       
    77 const TUint KImumUidValue = 0x100058EB;
       
    78 const TUid KImumUid = { KImumUidValue };
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CImapSubscriptionDialog::NewL
       
    82 // ----------------------------------------------------------------------------
       
    83 CImapSubscriptionDialog* CImapSubscriptionDialog::NewL(
       
    84     CMuiuFlags& aFlags,
       
    85     TMsvId aServiceId,
       
    86     TMsvId aMailboxId,
       
    87     TBool& aLoginChanged,
       
    88     const TDesC8& aUserName,
       
    89     const TDesC8& aPassword,
       
    90     CImumInternalApiImpl& aMailboxApi )
       
    91     {
       
    92     IMUM_STATIC_CONTEXT( CImapSubscriptionDialog::NewL, 0, utils, KLogUi );
       
    93 
       
    94     CImapSubscriptionDialog* self =
       
    95         new ( ELeave ) CImapSubscriptionDialog( aFlags, aServiceId, aMailboxId,
       
    96             aLoginChanged, aUserName, aPassword, aMailboxApi );
       
    97 
       
    98     CleanupStack::PushL(self);
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop();
       
   101     return self;
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CImapSubscriptionDialog::~CImapSubscriptionDialog
       
   106 // ----------------------------------------------------------------------------
       
   107 CImapSubscriptionDialog::~CImapSubscriptionDialog()
       
   108     {
       
   109     IMUM_CONTEXT( CImapSubscriptionDialog::~CImapSubscriptionDialog, 0, KLogUi );
       
   110 
       
   111     iMailboxApi.MsvSession().RemoveObserver(*this);
       
   112     if (iMtmStore)
       
   113         {
       
   114         iMtmStore->ReleaseMtmUi(KUidMsgTypeIMAP4);
       
   115         delete iMtmStore;
       
   116         }
       
   117     delete iContextEntry;
       
   118     delete iFolderListArray;
       
   119     delete iSoftkeys;
       
   120     iFolderIdArray.Reset();
       
   121     iSoftkeys = NULL;
       
   122     iUtils = NULL;
       
   123 
       
   124 
       
   125 	if( iNaviPane )
       
   126 		{
       
   127 		iNaviPane->Pop( iFolderIndicator );
       
   128 		}
       
   129     delete iFolderIndicator;
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // CImapSubscriptionDialog::CImapSubscriptionDialog
       
   134 // ----------------------------------------------------------------------------
       
   135 CImapSubscriptionDialog::CImapSubscriptionDialog(
       
   136     CMuiuFlags& aFlags,
       
   137     TMsvId aServiceId,
       
   138     TMsvId aMailboxId,
       
   139     TBool& aLoginChanged,
       
   140     const TDesC8& aUserName,
       
   141     const TDesC8& aPassword,
       
   142     CImumInternalApiImpl& aMailboxApi )
       
   143     :
       
   144     iMailboxApi( aMailboxApi ),
       
   145     iFlags( aFlags ),
       
   146     iServiceId( aServiceId ),
       
   147     iMailboxId( aMailboxId ),
       
   148     iLoginChanged( aLoginChanged ),
       
   149     iUserName( aUserName ),
       
   150     iPassword( aPassword )
       
   151     {
       
   152     IMUM_CONTEXT( CImapSubscriptionDialog::CImapSubscriptionDialog, 0, KLogUi );
       
   153 
       
   154     // If login info has not changed, it need not be saved before refreshing
       
   155     // folder list from server.
       
   156     iLoginSaved = !aLoginChanged;
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CImapSubscriptionDialog::ConstructL
       
   161 // ----------------------------------------------------------------------------
       
   162 void CImapSubscriptionDialog::ConstructL()
       
   163     {
       
   164     IMUM_CONTEXT( CImapSubscriptionDialog::ConstructL, 0, KLogUi );
       
   165 
       
   166     CAknDialog::ConstructL( R_IMAS_SETTINGS_SUBSCRIBE_MENU );
       
   167     iFlags.ClearFlag( EIFSSubscriptionsChanged );
       
   168 
       
   169     iMailboxApi.MsvSession().AddObserverL(*this);
       
   170     iMtmStore=CMtmStore::NewL(iMailboxApi.MsvSession());
       
   171 
       
   172     iMtmUiData=&(iMtmStore->MtmUiDataL(KUidMsgTypeIMAP4));
       
   173 
       
   174     iMtmUi=&(iMtmStore->ClaimMtmUiL(KUidMsgTypeIMAP4));
       
   175     iMtmUi->BaseMtm().SwitchCurrentEntryL(iServiceId);
       
   176 
       
   177     TMsvSelectionOrdering selectionOrdering(KMsvGroupByType, EMsvSortByDetails, ETrue);
       
   178     iContextEntry=CMsvEntry::NewL(iMailboxApi.MsvSession(), iServiceId, selectionOrdering);
       
   179     iFolderListArray = CImapFolderListArray::NewL( iMailboxApi.MsvSession(), iServiceId );
       
   180     iOpenedFolderId = iServiceId;
       
   181     iFolderIdArray.Append(iOpenedFolderId);
       
   182     iUtils = const_cast<MImumInMailboxUtilities*>(
       
   183         &iMailboxApi.MailboxUtilitiesL() );
       
   184 
       
   185     CEikStatusPane* sp = ( (CAknAppUi*)iEikonEnv->EikAppUi() )->StatusPane();
       
   186     iNaviPane = (CAknNavigationControlContainer *)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
       
   187 
       
   188     CImumNaviPaneFolderIndicator* folder =
       
   189         CImumNaviPaneFolderIndicator::NewL( ETrue, 1 );
       
   190 
       
   191     CAknNavigationDecorator* tmp = CAknNavigationDecorator::NewL(
       
   192         iNaviPane, folder, CAknNavigationDecorator::ENotSpecified );
       
   193 
       
   194     CleanupStack::PushL( tmp );
       
   195     tmp->SetContainerWindowL( *iNaviPane );
       
   196     CleanupStack::Pop( tmp );
       
   197     tmp->MakeScrollButtonVisible( EFalse );
       
   198     iFolderIndicator = tmp;
       
   199 
       
   200     // draw the folder icons on navi pane
       
   201     // iDepth is 0 at this point, so only
       
   202     // the root icon is displayed
       
   203     SetFolderDepthL( iDepth );
       
   204     }
       
   205 
       
   206 /******************************************************************************
       
   207 
       
   208     Init
       
   209 
       
   210 ******************************************************************************/
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CImapSubscriptionDialog::PreLayoutDynInitL
       
   214 // ----------------------------------------------------------------------------
       
   215 void CImapSubscriptionDialog::PreLayoutDynInitL()
       
   216     {
       
   217     IMUM_CONTEXT( CImapSubscriptionDialog::PreLayoutDynInitL, 0, KLogUi );
       
   218 
       
   219     CEikColumnListBox* listBox =
       
   220         static_cast< CEikColumnListBox* >( Control( EImasCIDFolderListBox ) );
       
   221 
       
   222     listBox->SetListBoxObserver( this );
       
   223 
       
   224     // Create scroll bar
       
   225     listBox->CreateScrollBarFrameL();
       
   226     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   227         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   228 
       
   229 
       
   230     CTextListBoxModel* model = listBox->Model();
       
   231     model->SetItemTextArray( iFolderListArray );
       
   232     listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   233 
       
   234     HBufC* emptyText =
       
   235         StringLoader::LoadLC( R_IMAS_SETTINGS_DIALOG_SUBS_EMPTY_TEXT );
       
   236 
       
   237     listBox->View()->SetListEmptyTextL( emptyText->Des() );
       
   238 
       
   239     CArrayPtrFlat<CGulIcon>* icons
       
   240         = new(ELeave) CAknIconArray( KImumFolderIconArrayGranularity );
       
   241 
       
   242     CleanupStack::PushL( icons );
       
   243 
       
   244     // create icon array
       
   245     TFileName fileName;
       
   246 
       
   247     TParse tp;
       
   248     tp.Set( KMuiuBitmapFile, &KDC_APP_BITMAP_DIR, NULL );
       
   249     fileName.Copy( tp.FullName() );
       
   250 
       
   251     AppendIconsL( fileName, icons );
       
   252 
       
   253     reinterpret_cast<CAknSingleGraphicStyleListBox*>( listBox )->
       
   254         ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   255 
       
   256 
       
   257     CleanupStack::Pop( ); // icons
       
   258     CleanupStack::PopAndDestroy();// emptyText
       
   259 
       
   260     }
       
   261 
       
   262 // ----------------------------------------------------------------------------
       
   263 // CImapSubscriptionDialog::PostLayoutDynInitL
       
   264 // ----------------------------------------------------------------------------
       
   265 void CImapSubscriptionDialog::PostLayoutDynInitL()
       
   266     {
       
   267     IMUM_CONTEXT( CImapSubscriptionDialog::PostLayoutDynInitL, 0, KLogUi );
       
   268 
       
   269     iSoftkeys = CIMSSoftkeyControl::NewL( ButtonGroupContainer() );
       
   270     iSoftkeys->SetMSKLabelling( ETrue );
       
   271     SetMskL();
       
   272     }
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 // CImapSubscriptionDialog::DynInitMenuPaneL
       
   276 // ----------------------------------------------------------------------------
       
   277 void CImapSubscriptionDialog::DynInitMenuPaneL(
       
   278     TInt aResourceId,
       
   279     CEikMenuPane* aMenuPane )
       
   280     {
       
   281     IMUM_CONTEXT( CImapSubscriptionDialog::DynInitMenuPaneL, 0, KLogUi );
       
   282 
       
   283     TMsvId folderId = CurrentFolderL();
       
   284     if ( folderId == KErrNotFound )
       
   285         {
       
   286         if ( aResourceId == R_IMAS_SETTINGS_SUBSCRIBE_MENUPANE )
       
   287             {
       
   288             aMenuPane->SetItemDimmed( EFolderOpenFolder, ETrue );
       
   289             aMenuPane->SetItemDimmed( EFolderSubscribe, ETrue );
       
   290             aMenuPane->SetItemDimmed( EFolderUnsubscribe, ETrue );
       
   291             }
       
   292         }
       
   293     else
       
   294         {
       
   295         TMsvId prevEntry = iContextEntry->Entry().Id();
       
   296         iContextEntry->SetEntryL( folderId );
       
   297         const TMsvEmailEntry emailEntry( iContextEntry->Entry() );
       
   298 
       
   299         if ( aResourceId == R_IMAS_SETTINGS_SUBSCRIBE_MENUPANE )
       
   300             {
       
   301             if ( !ContextHasChildFolders() )
       
   302                 {
       
   303                 aMenuPane->SetItemDimmed( EFolderOpenFolder, ETrue );
       
   304                 }
       
   305             if ( iUtils->IsInbox( emailEntry ) )
       
   306                 {
       
   307                 //inbox subscription cannot be changed
       
   308                 aMenuPane->SetItemDimmed( EFolderSubscribe, ETrue );
       
   309                 aMenuPane->SetItemDimmed( EFolderUnsubscribe, ETrue );
       
   310                 }
       
   311             else
       
   312                 {
       
   313                 aMenuPane->SetItemDimmed(
       
   314                     EFolderSubscribe, emailEntry.LocalSubscription() );
       
   315                 aMenuPane->SetItemDimmed(
       
   316                     EFolderUnsubscribe, !emailEntry.LocalSubscription() );
       
   317                 }
       
   318             aMenuPane->SetItemDimmed( EAknCmdHelp,
       
   319                 !iFlags.GF( EMailFeatureHelp ) );
       
   320             }
       
   321 
       
   322         iContextEntry->SetEntryL( prevEntry );
       
   323         }
       
   324 
       
   325     }
       
   326 
       
   327 /******************************************************************************
       
   328 
       
   329     Events
       
   330 
       
   331 ******************************************************************************/
       
   332 
       
   333 // ----------------------------------------------------------------------------
       
   334 // CImapSubscriptionDialog::HandleSessionEventL
       
   335 // ----------------------------------------------------------------------------
       
   336 void CImapSubscriptionDialog::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   337     {
       
   338     IMUM_CONTEXT( CImapSubscriptionDialog::HandleSessionEventL, 0, KLogUi );
       
   339 
       
   340     if(aEvent!=EMsvEntriesChanged)
       
   341         return;
       
   342 
       
   343     CMsvEntrySelection& sel=*static_cast<CMsvEntrySelection*>(aArg1);
       
   344     if(sel.Find(CurrentFolderL())!=KErrNotFound)
       
   345         {
       
   346         CEikColumnListBox* listBox = static_cast<CEikColumnListBox*>(Control(EImasCIDFolderListBox));
       
   347         listBox->DrawNow();
       
   348         }
       
   349     }
       
   350 
       
   351 // ----------------------------------------------------------------------------
       
   352 // CImapSubscriptionDialog::OkToExitL
       
   353 // ----------------------------------------------------------------------------
       
   354 TBool CImapSubscriptionDialog::OkToExitL(TInt aButtonId)
       
   355     {
       
   356     IMUM_CONTEXT( CImapSubscriptionDialog::OkToExitL, 0, KLogUi );
       
   357 
       
   358     TBool exit=EFalse;
       
   359     CEikColumnListBox* listBox = static_cast<CEikColumnListBox*>(Control(EImasCIDFolderListBox));
       
   360     const TInt oldCount = listBox->Model()->NumberOfItems();
       
   361     switch(aButtonId)
       
   362         {
       
   363         case EAknSoftkeyOptions:
       
   364             return CAknDialog::OkToExitL( EAknSoftkeyOptions );
       
   365 
       
   366         case EFolderSubscribe:
       
   367         case EFolderUnsubscribe:
       
   368             iFlags.SetFlag( EIFSSubscriptionsChanged );
       
   369             CreateOperationL( aButtonId );
       
   370             break;
       
   371 
       
   372         case EAknSoftkeyClose:
       
   373             exit = ETrue;
       
   374             break;
       
   375 
       
   376         case EFolderOpenFolder:
       
   377             // open folder which has subfolders...
       
   378             iContextEntry->SetEntryL( CurrentFolderL() );
       
   379 
       
   380             // set the folder depth to 1 more for the
       
   381             // navi pane folder icons
       
   382 			iDepth++;
       
   383             if ( ContextHasChildFolders() )
       
   384                 {
       
   385                 iOpenedFolderId = CurrentFolderL();
       
   386                 iFolderIdArray.Append(iOpenedFolderId);
       
   387                 iFolderListArray->ChangeFolderL( CurrentFolderL() );
       
   388                 if ( listBox->Model()->NumberOfItems() )
       
   389                     {
       
   390                     listBox->SetTopItemIndex( 0 );
       
   391                     listBox->SetCurrentItemIndex( 0 );
       
   392                     }
       
   393                 if ( oldCount > listBox->Model()->NumberOfItems() )
       
   394                     {
       
   395                     listBox->HandleItemRemovalL();
       
   396                     }
       
   397                 else
       
   398                     {
       
   399                     listBox->HandleItemAdditionL();
       
   400                     }
       
   401                 }
       
   402             break;
       
   403 
       
   404         case EAknSoftkeyBack:
       
   405             {
       
   406             // set the folder depth to 1 less for the
       
   407             // navi pane folder icons
       
   408 			iDepth--;
       
   409             if( iContextEntry->Entry().iType == KUidMsvServiceEntry )
       
   410                 {
       
   411                 //Only exit if current folder is service
       
   412                 exit = ETrue;
       
   413                 break;
       
   414                 }
       
   415 
       
   416             TMsvId folderToBeSelected = iOpenedFolderId;
       
   417             iContextEntry->SetEntryL( iOpenedFolderId );
       
   418 
       
   419             iOpenedFolderId = iContextEntry->Entry().Parent();
       
   420             iFolderIdArray.Remove(iFolderIdArray.Count()-1);
       
   421             iFolderListArray->ChangeFolderL( iOpenedFolderId );
       
   422             iContextEntry->SetEntryL( iOpenedFolderId );
       
   423 
       
   424             if ( oldCount > listBox->Model()->NumberOfItems() )
       
   425                 {
       
   426                 listBox->HandleItemRemovalL();
       
   427                 }
       
   428             else
       
   429                 {
       
   430                 listBox->HandleItemAdditionL();
       
   431                 }
       
   432 
       
   433             TInt loop;
       
   434             for ( loop = iContextEntry->Count()-1; loop >= 0; loop-- )
       
   435                 {
       
   436                 if ( folderToBeSelected == (*iContextEntry)[loop].Id() )
       
   437                     {
       
   438                     break;
       
   439                     }
       
   440                 }
       
   441             if ( loop < 0 )
       
   442                 {
       
   443                 loop = 0;
       
   444                 }
       
   445             listBox->SetTopItemIndex( ( loop > KImumFolderArrayVisibleItems ? loop - KImumFolderArrayVisibleItems : 0 ) );
       
   446             listBox->SetCurrentItemIndex( loop );
       
   447             }
       
   448             break;
       
   449 
       
   450         case EEikCmdExit:
       
   451             exit = ETrue;
       
   452             // Issue exit to the dialog
       
   453             iFlags.SetFlag( EImumSettingShouldExit );
       
   454             break;
       
   455 
       
   456     default:
       
   457         break;
       
   458         };
       
   459 
       
   460     // draw the folder icons to navi pane
       
   461     SetFolderDepthL( iDepth );
       
   462 
       
   463     listBox->DrawNow();
       
   464     return exit;
       
   465     }
       
   466 
       
   467 // ----------------------------------------------------------------------------
       
   468 // CImapSubscriptionDialog::SetFolderDepthL
       
   469 // ----------------------------------------------------------------------------
       
   470 void CImapSubscriptionDialog::SetFolderDepthL( TInt aDepth )
       
   471 	{
       
   472 	CImumNaviPaneFolderIndicator* findicator =
       
   473 		static_cast<CImumNaviPaneFolderIndicator*>( iFolderIndicator->DecoratedControl() );
       
   474 
       
   475 	findicator->SetFolderDepth( aDepth );
       
   476 	iNaviPane->PushL( *iFolderIndicator );
       
   477 	}
       
   478 
       
   479 
       
   480 // ----------------------------------------------------------------------------
       
   481 // CImapSubscriptionDialog::HandleListBoxEventL
       
   482 // ----------------------------------------------------------------------------
       
   483 void CImapSubscriptionDialog::HandleListBoxEventL(
       
   484     CEikListBox* /*aListBox*/,
       
   485     TListBoxEvent aEventType )
       
   486     {
       
   487     IMUM_CONTEXT( CImapSubscriptionDialog::HandleListBoxEventL, 0, KLogUi );
       
   488 
       
   489     switch ( aEventType )
       
   490         {
       
   491         case EEventEnterKeyPressed:
       
   492         case EEventItemDoubleClicked:
       
   493             {
       
   494             TMsvId prevEntry = iContextEntry->Entry().Id();
       
   495 
       
   496             CEikColumnListBox* listBox =
       
   497                 static_cast<CEikColumnListBox*>(
       
   498                     Control( EImasCIDFolderListBox ) );
       
   499             iContextEntry->SetEntryL( CurrentFolderL() );
       
   500 
       
   501             if ( listBox->Model()->NumberOfItems() &&
       
   502                  ContextHasChildFolders() )
       
   503                 {
       
   504                 //if has childs, open folder
       
   505                 OkToExitL( EFolderOpenFolder );
       
   506                 }
       
   507             else
       
   508                 {
       
   509                 //if not, change subs state of the folder
       
   510                 const TMsvEmailEntry emailEntry( iContextEntry->Entry() );
       
   511 
       
   512                 if ( iUtils->IsInbox( emailEntry ) )
       
   513                     {
       
   514                     //inbox cannot be changed
       
   515                     iContextEntry->SetEntryL( prevEntry );
       
   516                     return;
       
   517                     }
       
   518 
       
   519                 if ( emailEntry.LocalSubscription() )
       
   520                     {
       
   521                     iFlags.SetFlag( EIFSSubscriptionsChanged );
       
   522                     CreateOperationL( EFolderUnsubscribe );
       
   523                     }
       
   524                 else
       
   525                     {
       
   526                     iFlags.SetFlag( EIFSSubscriptionsChanged );
       
   527                     CreateOperationL( EFolderSubscribe );
       
   528                     }
       
   529                 listBox->DrawNow();
       
   530                 iContextEntry->SetEntryL( prevEntry );
       
   531                 }
       
   532             // Don't set prev entry here because we're opening it,
       
   533             // so it will be valid
       
   534             SetMskL();
       
   535             }
       
   536             break;
       
   537         case EEventItemClicked:
       
   538         case EEventItemDraggingActioned:
       
   539             SetMskL();
       
   540             break;
       
   541         default:
       
   542             break;
       
   543         }
       
   544     }
       
   545 
       
   546 
       
   547 // ----------------------------------------------------------------------------
       
   548 // CImapSubscriptionDialog::OfferKeyEventL
       
   549 // ----------------------------------------------------------------------------
       
   550 TKeyResponse CImapSubscriptionDialog::OfferKeyEventL(
       
   551     const TKeyEvent& aKeyEvent,
       
   552     TEventCode aType )
       
   553     {
       
   554     IMUM_CONTEXT( CImapSubscriptionDialog::OfferKeyEventL, 0, KLogUi );
       
   555 
       
   556     // For key up events, update the middle softkey label
       
   557     if ( aType == EEventKeyUp )
       
   558         {
       
   559         SetMskL();
       
   560         }
       
   561 
       
   562     return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   563     }
       
   564 
       
   565 // ----------------------------------------------------------------------------
       
   566 // CImapSubscriptionDialog::ProcessCommandL
       
   567 // ----------------------------------------------------------------------------
       
   568 void CImapSubscriptionDialog::ProcessCommandL( TInt aCommandId )
       
   569     {
       
   570     IMUM_CONTEXT( CImapSubscriptionDialog::ProcessCommandL, 0, KLogUi );
       
   571 
       
   572     if ( MenuShowing() )
       
   573         {
       
   574         HideMenu();
       
   575         }
       
   576 
       
   577     CAknDialog::ProcessCommandL(aCommandId);
       
   578     switch( aCommandId )
       
   579         {
       
   580         case EAknSoftkeyOk:
       
   581             HandleListBoxEventL( NULL, EEventEnterKeyPressed );
       
   582             break;
       
   583 
       
   584         case EFolderOpenFolder:
       
   585             OkToExitL( EFolderOpenFolder );
       
   586             break;
       
   587         case EFolderSubscribe:
       
   588         case EFolderUnsubscribe:
       
   589             {
       
   590             TMsvEntry tEntry;
       
   591             TMsvId service;
       
   592             iMailboxApi.MsvSession().GetEntry( CurrentFolderL(), service, tEntry );
       
   593             const TMsvEmailEntry emailEntry( tEntry );
       
   594 
       
   595 
       
   596             iFlags.SetFlag( EIFSSubscriptionsChanged );
       
   597             CreateOperationL( aCommandId );
       
   598 
       
   599             SetMskL();
       
   600             }
       
   601             break;
       
   602         case ERefreshFolderList:
       
   603             RefreshFolderListL();
       
   604             break;
       
   605 
       
   606         case EAknCmdHelp:
       
   607             {
       
   608             LaunchHelpL();
       
   609             break;
       
   610             }
       
   611 
       
   612         case EEikCmdExit:
       
   613             TryExitL( aCommandId );
       
   614             break;
       
   615         default:
       
   616             iEikonEnv->EikAppUi()->HandleCommandL(aCommandId);
       
   617             break;
       
   618         }
       
   619     }
       
   620 
       
   621 // ----------------------------------------------------------------------------
       
   622 // CImapSubscriptionDialog::ActivateL
       
   623 // ----------------------------------------------------------------------------
       
   624 void CImapSubscriptionDialog::ActivateL()
       
   625     {
       
   626     CAknDialog::ActivateL();
       
   627 
       
   628     // Query user if folder list should be updated from server when "subscribe
       
   629     // folders" setting item is opened.
       
   630     CAknQueryDialog* confDialog = CAknQueryDialog::NewL();
       
   631     if( confDialog->ExecuteLD( R_IMUM_CONNECT_FOR_UPDATE ) )
       
   632         {
       
   633         RefreshFolderListL();
       
   634         }
       
   635     }
       
   636 
       
   637 /******************************************************************************
       
   638 
       
   639     Tools
       
   640 
       
   641 ******************************************************************************/
       
   642 
       
   643 // ----------------------------------------------------------------------------
       
   644 // CImapSubscriptionDialog::SynchroniseFoldersL
       
   645 // ----------------------------------------------------------------------------
       
   646 void CImapSubscriptionDialog::SynchroniseFoldersL()
       
   647     {
       
   648     IMUM_CONTEXT( CImapSubscriptionDialog::SynchroniseFoldersL, 0, KLogUi );
       
   649 
       
   650     CreateOperationL(ERefreshFolderList);
       
   651     }
       
   652 
       
   653 // ----------------------------------------------------------------------------
       
   654 // CImapSubscriptionDialog::CreateOperationL
       
   655 // ----------------------------------------------------------------------------
       
   656 void CImapSubscriptionDialog::CreateOperationL(TInt aButtonId)
       
   657     {
       
   658     IMUM_CONTEXT( CImapSubscriptionDialog::CreateOperationL, 0, KLogUi );
       
   659 
       
   660     CMsvEntrySelection* mySelection=new (ELeave) CMsvEntrySelection;
       
   661     CleanupStack::PushL(mySelection);
       
   662     TBuf8<1> dummyParam;
       
   663 
       
   664     CMsvOperation* op = NULL;
       
   665     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   666 
       
   667     switch(aButtonId)
       
   668         {
       
   669     case EFolderSubscribe:
       
   670     case EFolderUnsubscribe:
       
   671         {
       
   672         //check for child / parent folders for question "want to subscribe/unsub whole tree branch?"
       
   673         //eat softkey commands. If user would leave while subscription process in progress, it will crash.
       
   674         //Only for subscribe operations. We need to be able to cancel folder list update operation
       
   675         CAknInputBlock::NewLC( );
       
   676 
       
   677         HandleSubscriptionL( aButtonId, *mySelection );
       
   678 
       
   679         TInt cnt = mySelection->Count();
       
   680         if( cnt > 1 )
       
   681             {
       
   682             //if more than one folder, we need to do a batch of subscribe commands
       
   683             op = iMtmUi->InvokeAsyncFunctionL( KIMAP4MTMStartBatch,
       
   684             *mySelection, wait->iStatus, dummyParam);
       
   685             wait->Start();
       
   686             delete op;
       
   687             op = NULL;
       
   688 
       
   689             TInt i;
       
   690             for( i=0; i<cnt; i++ )
       
   691                 {
       
   692                 op = iMtmUi->InvokeAsyncFunctionL(
       
   693                     (aButtonId==EFolderSubscribe?KIMAP4MTMLocalSubscribe:KIMAP4MTMLocalUnsubscribe),
       
   694                     *mySelection, wait->iStatus, dummyParam);
       
   695                 wait->Start();
       
   696                 delete op;
       
   697                 op = NULL;
       
   698 
       
   699 
       
   700                 if( mySelection->Count() > 1 )
       
   701                     {
       
   702                     //don't delete the last one, otherwise next invokeasyncfunction crashes, there has to
       
   703                     //be something in the passed entry selection.
       
   704                     mySelection->Delete(0);//always delete the first item, so next will be the first
       
   705                     }
       
   706 
       
   707                 }
       
   708             op = iMtmUi->InvokeAsyncFunctionL( KIMAP4MTMEndBatch,
       
   709             *mySelection, wait->iStatus, dummyParam);
       
   710             }//if
       
   711         else
       
   712             {
       
   713             //for only selected folder, no batch needed
       
   714             op = iMtmUi->InvokeAsyncFunctionL(
       
   715                 (aButtonId==EFolderSubscribe?KIMAP4MTMLocalSubscribe:KIMAP4MTMLocalUnsubscribe),
       
   716                 *mySelection, wait->iStatus, dummyParam);
       
   717             }
       
   718 
       
   719         }
       
   720         break;
       
   721 
       
   722     case ERefreshFolderList:
       
   723 
       
   724         mySelection->AppendL(iServiceId);
       
   725         op = iMtmUi->InvokeAsyncFunctionL(
       
   726             KImpiMTMRefreshFolderList, *mySelection, wait->iStatus ,dummyParam);
       
   727 
       
   728         break;
       
   729 
       
   730     default:
       
   731         break;
       
   732         };
       
   733 
       
   734     wait->Start();
       
   735     delete op;
       
   736     op = NULL;
       
   737 
       
   738 
       
   739     if( aButtonId == EFolderSubscribe || aButtonId == EFolderUnsubscribe )
       
   740         {
       
   741         CleanupStack::PopAndDestroy();//CAknInputBlock
       
   742         }
       
   743 
       
   744     CleanupStack::PopAndDestroy(2); // CSI: 47 # wait, mySelection
       
   745     }
       
   746 
       
   747 // ----------------------------------------------------------------------------
       
   748 // CImapSubscriptionDialog::ContextHasChildFolders
       
   749 // ----------------------------------------------------------------------------
       
   750 TBool CImapSubscriptionDialog::ContextHasChildFolders() const
       
   751     {
       
   752     IMUM_CONTEXT( CImapSubscriptionDialog::ContextHasChildFolders, 0, KLogUi );
       
   753 
       
   754     TInt index=iContextEntry->Count()-1;
       
   755     while (index>=0 && (*iContextEntry)[index].iType!=KUidMsvFolderEntry)
       
   756         index--;
       
   757 
       
   758     if(index!=-1)
       
   759         return ETrue;
       
   760 
       
   761     return EFalse;
       
   762     }
       
   763 
       
   764 // ----------------------------------------------------------------------------
       
   765 // CImapSubscriptionDialog::DisplayFinalProgressDialog
       
   766 // ----------------------------------------------------------------------------
       
   767 void CImapSubscriptionDialog::DisplayFinalProgressDialog(
       
   768     CMsvOperation& aCompletedOperation) const
       
   769     {
       
   770     IMUM_CONTEXT( CImapSubscriptionDialog::DisplayFinalProgressDialog, 0, KLogUi );
       
   771 
       
   772     __ASSERT_DEBUG( !aCompletedOperation.IsActive(),
       
   773         User::Panic( KImumMtmUiPanic, EIMAP4MtmUiOperationStillActive ) );
       
   774     iMtmUi->DisplayProgressSummary(aCompletedOperation.FinalProgress());
       
   775     }
       
   776 
       
   777 // ----------------------------------------------------------------------------
       
   778 // CImapSubscriptionDialog::AppendIconsL
       
   779 // ----------------------------------------------------------------------------
       
   780 void CImapSubscriptionDialog::AppendIconsL(
       
   781     TFileName& aFileName,
       
   782     CArrayPtrFlat<CGulIcon>* aIcons)
       
   783     {
       
   784     IMUM_CONTEXT( CImapSubscriptionDialog::AppendIconsL, 0, KLogUi );
       
   785 
       
   786 
       
   787     MAknsSkinInstance* skins = AknsUtils::SkinInstance();
       
   788     TAknsItemID id;
       
   789     CFbsBitmap* bitmap;
       
   790     CFbsBitmap* bitmapMask;
       
   791     TBool found = ETrue;
       
   792 
       
   793 
       
   794     for( TInt i=EMbmMuiuQgn_prop_folder_small; i<EMbmMuiuQgn_prop_folder_sub_unsubs_new+1; i++ )
       
   795         {
       
   796         CGulIcon* icon = NULL;
       
   797         found = ETrue;
       
   798         switch( i )
       
   799             {
       
   800             case EMbmMuiuQgn_prop_folder_small:
       
   801                 id.Set( KAknsIIDQgnPropFolderSmall );
       
   802                 break;
       
   803             case EMbmMuiuQgn_prop_folder_subs:
       
   804                 id.Set( KAknsIIDQgnPropFolderSubs );
       
   805                 break;
       
   806             case EMbmMuiuQgn_prop_folder_subs_new:
       
   807                 id.Set( KAknsIIDQgnPropFolderSubsNew );
       
   808                 break;
       
   809             case EMbmMuiuQgn_prop_folder_sub_small:
       
   810                 id.Set( KAknsIIDQgnPropFolderSubSmall );
       
   811                 break;
       
   812             case EMbmMuiuQgn_prop_folder_sub_subs:
       
   813                 id.Set( KAknsIIDQgnPropFolderSubSubs );
       
   814                 break;
       
   815             case EMbmMuiuQgn_prop_folder_sub_subs_new:
       
   816                 id.Set( KAknsIIDQgnPropFolderSubSubsNew );
       
   817                 break;
       
   818             case EMbmMuiuQgn_prop_folder_unsubs_new:
       
   819                 id.Set( KAknsIIDQgnPropFolderUnsubsNew );
       
   820                 break;
       
   821             case EMbmMuiuQgn_prop_folder_sub_unsubs_new:
       
   822                 id.Set( KAknsIIDQgnPropFolderSubUnsubsNew );
       
   823                 break;
       
   824             default:
       
   825                 found = EFalse;
       
   826                 break;
       
   827             }
       
   828 
       
   829 
       
   830         if( found )
       
   831             {
       
   832             AknsUtils::CreateIconL( skins, id, bitmap,
       
   833                 bitmapMask, aFileName, i, i + 1 );
       
   834 
       
   835             icon = CGulIcon::NewL( bitmap, bitmapMask );
       
   836 
       
   837             // ownership of bitmap and mask transfered to icon
       
   838             CleanupStack::PushL( icon );
       
   839             aIcons->AppendL( icon );
       
   840             CleanupStack::Pop( icon ); // icon
       
   841             }
       
   842         }
       
   843 
       
   844     }
       
   845 
       
   846 // ----------------------------------------------------------------------------
       
   847 // CImapSubscriptionDialog::CurrentFolderL
       
   848 // ----------------------------------------------------------------------------
       
   849 TMsvId CImapSubscriptionDialog::CurrentFolderL()
       
   850     {
       
   851     IMUM_CONTEXT( CImapSubscriptionDialog::CurrentFolderL, 0, KLogUi );
       
   852 
       
   853     CEikColumnListBox* listBox = static_cast<CEikColumnListBox*>(Control(EImasCIDFolderListBox));
       
   854     TInt curIndex = listBox->CurrentItemIndex();
       
   855 
       
   856     return ( curIndex == KErrNotFound ? curIndex : iFolderListArray->Id( curIndex ) );
       
   857     }
       
   858 
       
   859 // ----------------------------------------------------------------------------
       
   860 // CImapSubscriptionDialog::GetResourceForMiddlekeyL()
       
   861 // ----------------------------------------------------------------------------
       
   862 //
       
   863 TInt CImapSubscriptionDialog::GetResourceForMiddlekeyL()
       
   864     {
       
   865     IMUM_CONTEXT( CImapSubscriptionDialog::GetResourceForMiddlekeyL, 0, KLogUi );
       
   866 
       
   867     TInt resource = 0;
       
   868     TMsvId folderId = CurrentFolderL();
       
   869 
       
   870     if ( folderId == KErrNotFound )
       
   871         {
       
   872         resource = R_IMAS_MSK_EMPTY;
       
   873         }
       
   874     else
       
   875         {
       
   876         TMsvId prevEntry = iContextEntry->Entry().Id();
       
   877         iContextEntry->SetEntryL( folderId );
       
   878         const TMsvEmailEntry emailEntry( iContextEntry->Entry() );
       
   879 
       
   880         // First check for subfolders
       
   881         if ( ContextHasChildFolders() )
       
   882             {
       
   883             // Text "OPEN" when subfolders
       
   884             resource = R_IMAS_MSK_OPEN;
       
   885             }
       
   886         else if ( iUtils->IsInbox( emailEntry ) )
       
   887             {
       
   888             // No text for inbox
       
   889             resource = R_IMAS_MSK_EMPTY;
       
   890             }
       
   891         else if ( !emailEntry.LocalSubscription() )
       
   892             {
       
   893             resource = R_IMAS_MSK_MARK;
       
   894             }
       
   895         else
       
   896             {
       
   897             resource = R_IMAS_MSK_UNMARK;
       
   898             }
       
   899 
       
   900         iContextEntry->SetEntryL( prevEntry );
       
   901         }
       
   902 
       
   903     return resource;
       
   904     }
       
   905 
       
   906 // ----------------------------------------------------------------------------
       
   907 // CImapSubscriptionDialog::LaunchHelpL
       
   908 // Launch help using context
       
   909 //
       
   910 // ----------------------------------------------------------------------------
       
   911 void CImapSubscriptionDialog::LaunchHelpL()
       
   912     {
       
   913     IMUM_CONTEXT( CImapSubscriptionDialog::LaunchHelpL, 0, KLogUi );
       
   914 
       
   915     TCoeHelpContext context;
       
   916     context.iContext = KMCE_HLP_SETT_MAILFOLDER_UPD;
       
   917     context.iMajor = KImumUid;
       
   918     
       
   919     CArrayFixFlat<TCoeHelpContext>* array = new(ELeave) CArrayFixFlat<TCoeHelpContext>( 1 );
       
   920     CleanupStack::PushL ( array );
       
   921     array->AppendL( context );
       
   922     CleanupStack::Pop( array );
       
   923     HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), array );
       
   924        
       
   925     }
       
   926 
       
   927 // ----------------------------------------------------------------------------
       
   928 // CImapSubscriptionDialog::HandleSubscriptionL( TInt aSubType )
       
   929 // ----------------------------------------------------------------------------
       
   930 void CImapSubscriptionDialog::HandleSubscriptionL( TInt aSubType, CMsvEntrySelection& aSelection )
       
   931     {
       
   932     IMUM_CONTEXT( CImapSubscriptionDialog::HandleSubscriptionL, 0, KLogUi );
       
   933 
       
   934     TMsvId current = CurrentFolderL();
       
   935 
       
   936     if( iFolderListArray->ContextHasChildren( current ) )
       
   937         {
       
   938         TMsvSelectionOrdering selectionOrdering(KMsvGroupByType, EMsvSortByDetails, ETrue);
       
   939 
       
   940         //CMsvEntry is used this way because GetContextChildrenL is recursive. Otherwise
       
   941         //CMsvEntry objects would be created several times before the first one is deleted
       
   942         //which consumes lots of memory. Now we just set new CMsvEntry over this one several times.
       
   943         CMsvEntry* entry = CMsvEntry::NewL(iMailboxApi.MsvSession(), current, selectionOrdering);
       
   944         CleanupStack::PushL( entry );
       
   945         CMsvEntrySelection* sel = iFolderListArray->GetContextChildrenL( current, *entry );
       
   946         CleanupStack::PopAndDestroy();//entry
       
   947 
       
   948         CleanupStack::PushL( sel );
       
   949 
       
   950         TBool allFolders = CheckAreAllFoldersIncludedL( aSubType, sel );
       
   951 
       
   952         CAknQueryDialog* subsQuery = new(ELeave) CAknQueryDialog;
       
   953 
       
   954         switch( aSubType )
       
   955             {
       
   956             case EFolderSubscribe:
       
   957                 {
       
   958                 //subscribe also all sub folders?
       
   959                 subsQuery->PrepareLC( R_IMUM_DO_SUBS_FOR_SUBFOLDERS );
       
   960                 }
       
   961                 break;
       
   962             case EFolderUnsubscribe:
       
   963                 {
       
   964                 //unsubscribe also all sub folders?
       
   965                 subsQuery->PrepareLC( R_IMUM_DO_UNSUBS_FOR_SUBFOLDERS );
       
   966                 }
       
   967                 break;
       
   968             default:
       
   969                 User::Leave( KErrNotSupported );
       
   970                 break;
       
   971             }//switch
       
   972 
       
   973 
       
   974         TInt ret = 1;//by default do all subfolders
       
   975 
       
   976         //if all subfolders already subbed / unsubbed, no need for query
       
   977         if( !allFolders )
       
   978             {
       
   979             ret = subsQuery->RunLD();
       
   980             }
       
   981         else
       
   982             {
       
   983             CleanupStack::PopAndDestroy();//subsQuery
       
   984             }
       
   985 
       
   986         if( ret )
       
   987             {
       
   988             //append all sub folders
       
   989 
       
   990             TInt count = sel->Count();
       
   991 
       
   992             //first append current
       
   993             aSelection.AppendL( current );
       
   994 
       
   995             //then the children
       
   996             TInt i;
       
   997             for( i=0; i<count; i++ )
       
   998                 {
       
   999                 aSelection.AppendL( sel->At(i) );
       
  1000                 }
       
  1001             }
       
  1002         else
       
  1003             {
       
  1004             //only selected
       
  1005             aSelection.AppendL( current );
       
  1006             }
       
  1007 
       
  1008         CleanupStack::PopAndDestroy();//sel
       
  1009         }//if
       
  1010     else
       
  1011         {
       
  1012         //no children, append only current
       
  1013         aSelection.AppendL( current );
       
  1014         }
       
  1015     }
       
  1016 
       
  1017 // ----------------------------------------------------------------------------
       
  1018 // CImapSubscriptionDialog::CheckAreAllFoldersIncludedL
       
  1019 // ----------------------------------------------------------------------------
       
  1020 TBool CImapSubscriptionDialog::CheckAreAllFoldersIncludedL( TInt aSubType, CMsvEntrySelection* sel )
       
  1021     {
       
  1022     IMUM_CONTEXT( CImapSubscriptionDialog::CheckAreAllFoldersIncludedL, 0, KLogUi );
       
  1023 
       
  1024     TMsvEntry tEntry;
       
  1025     TMsvId service;
       
  1026 
       
  1027     TInt count = sel->Count();
       
  1028     TInt i;
       
  1029     TInt result = 0;
       
  1030 
       
  1031     for( i=0; i<count; i++ )
       
  1032         {
       
  1033         iMailboxApi.MsvSession().GetEntry( sel->At(i), service, tEntry );
       
  1034         TMsvEmailEntry emailEntry( tEntry );
       
  1035 
       
  1036         if( aSubType == EFolderSubscribe )
       
  1037             {
       
  1038             //count all subscribed entries
       
  1039             if( emailEntry.LocalSubscription() )
       
  1040                 {
       
  1041                 result++;
       
  1042                 }
       
  1043             }
       
  1044         else
       
  1045             {
       
  1046             //count all unsubscribed entries
       
  1047             if( !emailEntry.LocalSubscription() )
       
  1048                 {
       
  1049                 result++;
       
  1050                 }
       
  1051             }
       
  1052         }
       
  1053 
       
  1054     if( count == result )
       
  1055         {
       
  1056         return ETrue;
       
  1057         }
       
  1058 
       
  1059     return EFalse;
       
  1060 
       
  1061     }
       
  1062 
       
  1063 // ----------------------------------------------------------------------------
       
  1064 // CImapSubscriptionDialog::RefreshFolderListL
       
  1065 // ----------------------------------------------------------------------------
       
  1066 void CImapSubscriptionDialog::RefreshFolderListL()
       
  1067     {
       
  1068     IMUM_CONTEXT( CImapSubscriptionDialog::RefreshFolderListL, 0, KLogUi );
       
  1069 
       
  1070     // If user has modified username/password setting we need to save them
       
  1071     // before connecting into IMAP server.
       
  1072     if ( !iLoginSaved )
       
  1073         {
       
  1074         SetLoginInformationL();
       
  1075         iLoginSaved = ETrue;
       
  1076         }
       
  1077 
       
  1078     CEikColumnListBox* listBox =
       
  1079             static_cast<CEikColumnListBox*>( Control(EImasCIDFolderListBox) );
       
  1080     const TInt oldCount = listBox->Model()->NumberOfItems();
       
  1081 
       
  1082     //get new folder structure from server
       
  1083     SynchroniseFoldersL();
       
  1084 
       
  1085     // Login into IMAP server took place. Inform caller of this dialog that
       
  1086     // username/password may have changed.
       
  1087     iLoginChanged = ETrue;
       
  1088 
       
  1089     iFolderListArray->RefreshFolderListArrayL();
       
  1090 
       
  1091     iOpenedFolderId = iServiceId;
       
  1092     iContextEntry->SetEntryL( iOpenedFolderId );
       
  1093 
       
  1094     SetBackToOldFolderL();
       
  1095 
       
  1096 
       
  1097     //Refresh listBox
       
  1098     if ( listBox->Model()->NumberOfItems() )
       
  1099         {
       
  1100         listBox->SetTopItemIndex( 0 );
       
  1101         listBox->SetCurrentItemIndex( 0 );
       
  1102         }
       
  1103     if ( oldCount > listBox->Model()->NumberOfItems() )
       
  1104         {
       
  1105         listBox->HandleItemRemovalL();
       
  1106         }
       
  1107     else
       
  1108         {
       
  1109         listBox->HandleItemAdditionL();
       
  1110         }
       
  1111     SetMskL();
       
  1112     }
       
  1113 
       
  1114 
       
  1115 // ----------------------------------------------------------------------------
       
  1116 // CImapSubscriptionDialog::SetBackToOldFolderL
       
  1117 // ----------------------------------------------------------------------------
       
  1118 void CImapSubscriptionDialog::SetBackToOldFolderL()
       
  1119     {
       
  1120     IMUM_CONTEXT( CImapSubscriptionDialog::SetBackToOldFolderL, 0, KLogUi );
       
  1121 
       
  1122     CMsvEntrySelection* sel = NULL;
       
  1123 
       
  1124     //set nextFolder index to root
       
  1125     TInt nextFolder = 0;
       
  1126     //if count is greater than 1 user is in some subfolder
       
  1127     const TInt count = iFolderIdArray.Count();
       
  1128 
       
  1129     //found == true if first index in iFolderIdArray is new root folder
       
  1130     TBool found = iFolderIdArray[nextFolder] == iOpenedFolderId;
       
  1131 
       
  1132     //loop as long as we found iFolderIdArray indexes from new folder structure
       
  1133     //or loop go thru whole iFolderIdArray. ++nextFolder set index to subfolder
       
  1134     while ( found && ++nextFolder < count &&
       
  1135             iContextEntry->Count() > 0 )
       
  1136         {
       
  1137 
       
  1138         sel = iContextEntry->ChildrenL();
       
  1139 
       
  1140         //test that subfolder found from selection
       
  1141         found = sel->Find( iFolderIdArray[nextFolder] ) != KErrNotFound;
       
  1142 
       
  1143         if ( found )
       
  1144             {
       
  1145 
       
  1146             iContextEntry->SetEntryL( iFolderIdArray[nextFolder] );
       
  1147             iOpenedFolderId = iContextEntry->EntryId();
       
  1148             }
       
  1149 
       
  1150         delete sel;
       
  1151         sel = NULL;
       
  1152         }
       
  1153 
       
  1154 
       
  1155     // nextFolder is now index to first
       
  1156     // FolderId that not found in previous loop
       
  1157     if ( nextFolder > 0 )
       
  1158         {
       
  1159         //update iFolderListArray to new opened folder
       
  1160         iFolderListArray->ChangeFolderL( iOpenedFolderId );
       
  1161 
       
  1162         //remove indexes that are not valid anymore
       
  1163         for ( TInt i = count; --i >= nextFolder; )
       
  1164             {
       
  1165             iFolderIdArray.Remove(i);
       
  1166             }
       
  1167         }
       
  1168     // if we did not found any subfolder indexes,
       
  1169     //set context to root and clear the array
       
  1170     else
       
  1171         {
       
  1172         iFolderIdArray.Reset();
       
  1173         iFolderIdArray.AppendL( iOpenedFolderId );
       
  1174         }
       
  1175 
       
  1176     }
       
  1177 
       
  1178 // ----------------------------------------------------------------------------
       
  1179 // CImapSubscriptionDialog::SetLoginInformationL
       
  1180 // ----------------------------------------------------------------------------
       
  1181 void CImapSubscriptionDialog::SetLoginInformationL()
       
  1182     {
       
  1183     // Retrieve the settings of the mailbox
       
  1184     const MImumInMailboxUtilities& utils = iMailboxApi.MailboxUtilitiesL();
       
  1185     TMsvEntry entry = utils.GetMailboxEntryL( iMailboxId );
       
  1186 
       
  1187     CImumInSettingsData* accountsettings =
       
  1188         iMailboxApi.MailboxServicesL().LoadMailboxSettingsL( iMailboxId );
       
  1189     CleanupStack::PushL( accountsettings );
       
  1190     // Incoming settings
       
  1191     MImumInSettingsDataCollection* connection = &accountsettings->GetInSetL( 0 );
       
  1192 
       
  1193     // Set login data to settings
       
  1194     User::LeaveIfError( connection->SetAttr(
       
  1195         TImumDaSettings::EKeyUsername, iUserName ) );
       
  1196     User::LeaveIfError( connection->SetAttr(
       
  1197         TImumDaSettings::EKeyPassword, iPassword ) );
       
  1198     User::LeaveIfError( connection->SetAttr(
       
  1199         TImumInSettings::EKeyTemporaryUsername, EFalse ) );
       
  1200     User::LeaveIfError( connection->SetAttr(
       
  1201         TImumInSettings::EKeyTemporaryPassword, EFalse ) );
       
  1202 
       
  1203     // Save mailbox data
       
  1204     iMailboxApi.MailboxServicesL().SaveMailboxSettingsL( *accountsettings );
       
  1205     CleanupStack::PopAndDestroy( accountsettings );
       
  1206     }
       
  1207 
       
  1208 // ----------------------------------------------------------------------------
       
  1209 // CImapSubscriptionDialog::SetMskL
       
  1210 // ----------------------------------------------------------------------------
       
  1211 void CImapSubscriptionDialog::SetMskL()
       
  1212     {
       
  1213     iSoftkeys->UpdateMiddleSoftkeyLabelL( GetResourceForMiddlekeyL(),
       
  1214         EAknSoftkeyOk, this );
       
  1215     }
       
  1216 
       
  1217 // End of File