messagingappbase/mce/src/MceMainViewListItemArray.cpp
changeset 0 72b543305e3a
child 2 0bf1d54f37d9
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 *     Item array for the message items to be displayed by mce.
       
    16 *     Main view items are kept in memory (CArrayFixFlat<TMceListItem>) when created but
       
    17 *     Message view list items are fetched from the msgs when needed in MdcaPoint function
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 
       
    25 #include <AknUtils.h>       // AknTextUtils
       
    26 #include <mtudcbas.h>
       
    27 #include <msvids.h>
       
    28 #include <NpdApi.h>         // CNotepadApi
       
    29 //#include "MtmRegistryObserver.h" // MMtmUiDataRegistryObserver
       
    30 #include <StringLoader.h>   // StringLoader
       
    31 #include <mce.rsg>
       
    32 #include <SenduiMtmUids.h>  // mtm uids
       
    33 #include <eikenv.h>
       
    34 #include <centralrepository.h>
       
    35 #include <messaginginternalcrkeys.h>
       
    36 
       
    37 
       
    38 #include <MTMStore.h>
       
    39 #include <commonphoneparser.h>
       
    40 
       
    41 #include <aknappui.h>
       
    42 #include <akncontext.h>
       
    43 #include <aknconsts.h>
       
    44 #include <e32math.h>
       
    45 
       
    46 #include <bldvariant.hrh>
       
    47 #include <featmgr.h>
       
    48 #include <NumberGrouping.h>
       
    49 #include <mmsconst.h>
       
    50 #include <mmsgenutils.h>
       
    51 #include <mmsclient.h>
       
    52 #include <mtclreg.h>
       
    53 #include <muiu.mbg>
       
    54 #include <mtudreg.h>        // CMtmUiDataRegistry
       
    55 
       
    56 // security data caging
       
    57 #include <data_caging_path_literals.hrh>
       
    58 #include <miutset.h>
       
    59 #include <msvapi.h>
       
    60 
       
    61 #include <ImumInternalApi.h>            // CImumInternalApi
       
    62 #include <ImumInSettingsData.h>         // CImumInSettingsData
       
    63 
       
    64 #include <muiuflags.h>
       
    65 
       
    66 #include "MceMainViewListItemArrayIncludes.h"
       
    67 #include <mceextraitems.rsg>
       
    68 //FS Email stuff
       
    69 #include <ImumInHealthServices.h>
       
    70 #include <muiumsvuiserviceutilitiesinternal.h>
       
    71 #include <MessagingDomainCRKeys.h>
       
    72 #include <bautils.h>
       
    73 
       
    74 // CONSTANTS
       
    75 
       
    76 // LOCAL CONSTANTS AND MACROS
       
    77 enum
       
    78     {
       
    79     KMceListArrayDocAmount = 0x0,
       
    80     KMceListArrayDocAmountMany,
       
    81     KMceListArrayDocAmountTemp,
       
    82     KMceListArrayDocAmountTemps,
       
    83     KMceListArrayDocNoMessages,
       
    84     KMceListArrayNumberOneMessage,
       
    85     KMceListArrayNumberOfMsgs, 
       
    86     KMceListArrayTimeFormatBuffer,
       
    87     KMceListArrayDateFormatBuffer
       
    88     };
       
    89 
       
    90 //cmail update
       
    91 #define KUidMsgTypeFsMtmVal               0x2001F406
       
    92 
       
    93 //cmail update
       
    94 
       
    95 // ================= MEMBER FUNCTIONS =======================
       
    96 
       
    97 // C++ default constructor can NOT contain any code that
       
    98 // might leave.
       
    99 //
       
   100 CMceMainViewListItemArray::CMceMainViewListItemArray(
       
   101     CMsvSessionPtr aSession,
       
   102     TMsvId /*aFolderId*/,
       
   103     TMceListType /*aListType*/,
       
   104     CMceBitmapResolver& aBitmapResolver ) :
       
   105     CArrayFixFlat<TMceListItem>( KMceListGranuality ),
       
   106     iSession( aSession ),
       
   107 //    KMsvRootIndexEntryId( aFolderId ),
       
   108 //    iListType( aListType ),
       
   109     iBitmapResolver( aBitmapResolver )
       
   110     {
       
   111     iMailboxArray.Reset();
       
   112     iDescriptionLength = iBitmapResolver.DescriptionLength();
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------
       
   116 // CMceMainViewListItemArray::ConstructL
       
   117 // Symbian OS default constructor can leave.
       
   118 // ----------------------------------------------------
       
   119 void CMceMainViewListItemArray::ConstructL()
       
   120     {
       
   121     FeatureManager::InitializeLibL();
       
   122     if ( FeatureManager::FeatureSupported( KFeatureIdSelectableEmail ) )
       
   123         {
       
   124         iSelectableEmail = ETrue;
       
   125         }
       
   126     if ( FeatureManager::FeatureSupported( KFeatureIdFfEmailFramework ) )
       
   127         {
       
   128         iEmailFramework = ETrue;
       
   129         }
       
   130     FeatureManager::UnInitializeLib();
       
   131     iCoeEnv = CEikonEnv::Static();
       
   132     iUiRegistry = CMtmUiDataRegistry::NewL(*iSession); 
       
   133     ReadMainViewItemsFromRepositoryL();
       
   134     ReadExtraItemsResourceL();
       
   135     
       
   136     // read phone number grouping feature flag
       
   137     // sort by details sorts remote mailboxes alphabetical order
       
   138     iFolderEntry = CMsvEntry::NewL(
       
   139         *iSession,
       
   140         KMsvRootIndexEntryId,
       
   141         TMsvSelectionOrdering(
       
   142             KMsvGroupByStandardFolders, EMsvSortByDetails ));
       
   143     
       
   144     iEmailApi = CreateEmailApiL( &*iSession );
       
   145     Reset();
       
   146     AddFoldersL();
       
   147     iIdleLoader = CMceUtilsIdleClass::NewL( *this );
       
   148     iIdleLoader->StartL();
       
   149     iNumberOfMessagesStrings = new(ELeave)CDesCArrayFlat( KMceListGranuality );
       
   150     TBuf<KMcePrintableTextLength> tempString;
       
   151     StringLoader::Load( tempString, R_MCE_DOC_AMOUNT, iCoeEnv );
       
   152     iNumberOfMessagesStrings->AppendL( tempString );
       
   153     StringLoader::Load( tempString, R_MCE_DOC_AMOUNT_MANY, iCoeEnv );
       
   154     iNumberOfMessagesStrings->AppendL( tempString );
       
   155     StringLoader::Load( tempString, R_MCE_DOC_AMOUNT_TEMP, iCoeEnv );
       
   156     iNumberOfMessagesStrings->AppendL( tempString );
       
   157     StringLoader::Load( tempString, R_MCE_DOC_AMOUNT_TEMPS, iCoeEnv );
       
   158     iNumberOfMessagesStrings->AppendL( tempString );
       
   159     StringLoader::Load( tempString, R_MCE_DOC_NO_MESSAGES, iCoeEnv);
       
   160     iNumberOfMessagesStrings->AppendL( tempString );
       
   161     StringLoader::Load( tempString, R_MCE_NUMBER_ONE_MESSAGE, iCoeEnv);
       
   162     iNumberOfMessagesStrings->AppendL( tempString );
       
   163     StringLoader::Load( tempString, R_MCE_NUMBER_OF_MSGS, iCoeEnv);
       
   164     iNumberOfMessagesStrings->AppendL( tempString );
       
   165 
       
   166     HBufC* timeFormat = iCoeEnv->
       
   167         AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   168     iNumberOfMessagesStrings->AppendL( *timeFormat );
       
   169     CleanupStack::PopAndDestroy();
       
   170     
       
   171     HBufC* dateFormat = iCoeEnv->
       
   172             AllocReadResourceLC( R_QTN_DATE_WITHOUT_YEAR_WITH_ZERO );
       
   173     iNumberOfMessagesStrings->AppendL( *dateFormat );
       
   174     CleanupStack::PopAndDestroy();
       
   175     
       
   176     
       
   177     // todo
       
   178     iListBoxText = HBufC::NewL( iDescriptionLength*3 ); 
       
   179     }
       
   180 
       
   181 // Two-phased constructor.
       
   182 CMceMainViewListItemArray* CMceMainViewListItemArray::NewL(
       
   183     CMsvSessionPtr aSession,
       
   184     TMsvId aFolderId,
       
   185     TMceListType aListType,
       
   186     CMceBitmapResolver& aBitmapResolver )
       
   187     {
       
   188     CMceMainViewListItemArray* self = new (ELeave) CMceMainViewListItemArray(
       
   189         aSession, aFolderId, aListType, aBitmapResolver );
       
   190     CleanupStack::PushL(self);
       
   191     self->ConstructL();
       
   192     CleanupStack::Pop(); // self
       
   193     return self;
       
   194     }
       
   195 
       
   196 
       
   197 // Destructor
       
   198 CMceMainViewListItemArray::~CMceMainViewListItemArray( )
       
   199     {
       
   200     delete iExtraItemsArray;
       
   201     delete iMainViewItems;
       
   202     delete iFolderEntry;
       
   203     delete iListBoxText;
       
   204     delete iNumberOfMessagesStrings;
       
   205 //    delete iUiRegistry;
       
   206     delete iEmailApi;
       
   207     iMailboxArray.Reset();
       
   208     delete iIdleLoader;
       
   209     delete iUiRegistry;
       
   210     // iSession deleted elsewhere
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CMceMainViewListItemArray::MakeItemL()
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CMceMainViewListItemArray::MakeItemL( 
       
   218     TMceListItem& aListItem,
       
   219     const TMsvEntry& aEntry ) const
       
   220     {
       
   221     aListItem.iPrintableText.Zero();
       
   222 
       
   223     const TMsvId id=aEntry.Id();
       
   224     StripAndAppendString( 
       
   225         aListItem.iPrintableText,
       
   226         aEntry.iDetails );
       
   227 
       
   228     aListItem.iMsvId = id;
       
   229     aListItem.iExtraItem = EFalse;
       
   230     aListItem.iIconIndex = KErrNotFound;    
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CMceMainViewListItemArray::InsertItemL()
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CMceMainViewListItemArray::InsertItemL( 
       
   238     const TMsvEntry& aEntry, 
       
   239     const TInt aIndex )
       
   240     {
       
   241     TMceListItem tempItem;
       
   242     MakeItemL( tempItem, aEntry );
       
   243     InsertL( aIndex, tempItem );
       
   244     }
       
   245 
       
   246 
       
   247 // ----------------------------------------------------
       
   248 // CMceMainViewListItemArray::AddItemL
       
   249 // ----------------------------------------------------
       
   250 void CMceMainViewListItemArray::AddItemL( const TMsvEntry& aEntry )
       
   251     {
       
   252     TMceListItem tempItem;
       
   253     MakeItemL( tempItem, aEntry );
       
   254     AppendL( tempItem );
       
   255     }
       
   256 
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // CMceListItemArray::AddFolderItemL()
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CMceMainViewListItemArray::AddFolderItemL( TMsvId aEntryId )
       
   263     {
       
   264     TMsvId service = KMsvLocalServiceIndexEntryId;
       
   265     TMsvEntry entry;
       
   266     if ( iSession->GetEntry(aEntryId,service,entry) == KErrNone )
       
   267     	{
       
   268     	AddItemL( entry );
       
   269     	}
       
   270     }
       
   271 
       
   272 // ----------------------------------------------------
       
   273 // CMceMainViewListItemArray::ItemIndex
       
   274 // ----------------------------------------------------
       
   275 TInt CMceMainViewListItemArray::ItemIndex(TMsvId aItemId) const
       
   276     {
       
   277     TInt foundItem = KErrNotFound;
       
   278     const TInt count = Count();
       
   279 
       
   280     for( TInt loop = 0; loop < count && foundItem == KErrNotFound ; loop++)
       
   281         {
       
   282         if ( !At(loop).iExtraItem && At(loop).iMsvId == aItemId )
       
   283             {
       
   284             foundItem = loop;
       
   285             }
       
   286         }
       
   287     return foundItem;
       
   288     }
       
   289 
       
   290 // ----------------------------------------------------
       
   291 // CMceMainViewListItemArray::ExtraItemIndex
       
   292 // ----------------------------------------------------
       
   293 TInt CMceMainViewListItemArray::ExtraItemIndex( TInt aItemId ) const
       
   294     {
       
   295     TInt foundItem = KErrNotFound;
       
   296     const TInt count = Count();
       
   297 
       
   298     for( TInt loop = 0; loop < count && foundItem == KErrNotFound ; loop++)
       
   299         {
       
   300         if ( At(loop).iExtraItem && At(loop).iMsvId == aItemId )
       
   301             {
       
   302             foundItem = loop;
       
   303             }
       
   304         }
       
   305     return foundItem;
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------
       
   309 // CMceListItemArray::ItemId
       
   310 // ----------------------------------------------------
       
   311 TMsvId CMceMainViewListItemArray::ItemId( TInt aIndex ) const
       
   312     {
       
   313     TMsvId id = KErrNotFound;
       
   314     if ( aIndex >= 0 && aIndex < Count() )
       
   315         {
       
   316         if ( !At(aIndex).iExtraItem )
       
   317             {
       
   318             id = At(aIndex).iMsvId;
       
   319             }
       
   320         }
       
   321     return id;
       
   322     }
       
   323 
       
   324 // ----------------------------------------------------
       
   325 // CMceMainViewListItemArray::Item
       
   326 // ----------------------------------------------------
       
   327 const TMceListItem CMceMainViewListItemArray::Item( TInt aIndex ) const
       
   328     {
       
   329     TMceListItem tempItem;
       
   330     tempItem.iMsvId = At(aIndex).iMsvId;
       
   331     tempItem.iExtraItem = At(aIndex).iExtraItem;
       
   332     return tempItem;
       
   333     }
       
   334 
       
   335 // ----------------------------------------------------
       
   336 // CMceMainViewListItemArray::AddExtraItemL
       
   337 // ----------------------------------------------------
       
   338 void CMceMainViewListItemArray::AddExtraItemL( TMceListItem& aNewItem, TInt aIndex )
       
   339     {
       
   340     TMcePrintableText tempText = aNewItem.iPrintableText; // let's save string
       
   341 
       
   342     aNewItem.iExtraItem = ETrue;
       
   343     // make sure it will not be mixed with items in msgs
       
   344     TMceBitmapListItem bitmapItem;
       
   345     bitmapItem.iExtraItem = ETrue;
       
   346     bitmapItem.iMtm.iUid = KUidMsvLocalServiceMtmValue;
       
   347     bitmapItem.iType.iUid = KUidMsvFolderEntryValue;
       
   348     bitmapItem.iId = aNewItem.iMsvId;
       
   349     const TInt index = iBitmapResolver.BitmapIndex( bitmapItem );
       
   350     aNewItem.iPrintableText.Zero();
       
   351     aNewItem.iPrintableText.AppendNum( index );
       
   352     aNewItem.iPrintableText.Append( KColumnListSeparator );
       
   353     aNewItem.iPrintableText.Append( tempText );
       
   354 
       
   355     InsertL( aIndex, aNewItem );
       
   356     }
       
   357 
       
   358 
       
   359 // ----------------------------------------------------
       
   360 // CMceMainViewListItemArray::AddExtraItemWithIconL
       
   361 // ----------------------------------------------------
       
   362 void CMceMainViewListItemArray::AddExtraItemWithIconL( 
       
   363     TMceListItem& aNewItem, 
       
   364     TInt aIndex, 
       
   365     TInt aIconIndex,
       
   366     TUid aApplicationUid )
       
   367     {
       
   368     TMcePrintableText tempText = aNewItem.iPrintableText; // let's save string
       
   369 
       
   370     aNewItem.iExtraItem = ETrue;
       
   371     // make sure it will not be mixed with items in msgs
       
   372     TMceBitmapListItem bitmapItem;
       
   373     bitmapItem.iExtraItem = ETrue;
       
   374     bitmapItem.iMtm = aApplicationUid ; //KUidMsvLocalServiceMtmValue;
       
   375     bitmapItem.iType = aApplicationUid; //KUidMsvFolderEntryValue;
       
   376     bitmapItem.iId = aNewItem.iMsvId;
       
   377     // here to add loading of the icon...
       
   378     _LIT( KMceExtraIconsDirAndFile,"MceExtraIcons.mbm" );
       
   379     TParse fp;
       
   380     fp.Set( KMceExtraIconsDirAndFile, &KDC_APP_BITMAP_DIR , NULL );
       
   381     // trap this and if fails, set index = Unknown.
       
   382     TInt error = KErrNone;
       
   383     
       
   384     // Add the bitmap
       
   385     TRAP( error, iBitmapResolver.CreateAndAppendIconL( \
       
   386         KAknsIIDDefault,\
       
   387         fp.FullName(),\
       
   388         aIconIndex,\
       
   389         &bitmapItem ) );
       
   390     
       
   391     // Handle the error
       
   392     TInt index;
       
   393     if ( error == KErrNone )
       
   394     	{
       
   395     	index = iBitmapResolver.BitmapIndex( bitmapItem );
       
   396     	}
       
   397     else
       
   398     	{
       
   399     	index = EMceBitmapIndexUnknown;
       
   400     	}
       
   401     
       
   402     aNewItem.iPrintableText.Zero();
       
   403     aNewItem.iPrintableText.AppendNum( index );
       
   404     aNewItem.iPrintableText.Append( KColumnListSeparator );
       
   405     aNewItem.iPrintableText.Append( tempText );
       
   406 
       
   407     InsertL( aIndex, aNewItem );
       
   408     }
       
   409 
       
   410 // ----------------------------------------------------
       
   411 // CMceMainViewListItemArray::MdcaCount
       
   412 // ----------------------------------------------------
       
   413 TInt CMceMainViewListItemArray::MdcaCount() const
       
   414     {
       
   415     return Count();
       
   416     }
       
   417 
       
   418 // ----------------------------------------------------
       
   419 // CMceMainViewListItemArray::MdcaPoint
       
   420 // ----------------------------------------------------
       
   421 TPtrC CMceMainViewListItemArray::MdcaPoint( TInt aIndex ) const
       
   422     {
       
   423     const TMceListItem& item = At( aIndex );
       
   424     if ( item.iExtraItem )
       
   425         {
       
   426         if ( item.iMsvId == KMceDeliveryReportsId )
       
   427             {
       
   428             TPtr tempText = iListBoxText->Des();
       
   429             tempText.Copy( item.iPrintableText );
       
   430             return tempText;
       
   431             }
       
   432         else
       
   433             {
       
   434             return item.iPrintableText;
       
   435             }
       
   436         }
       
   437     else
       
   438         {
       
   439         return MakeStringForMainView( aIndex );
       
   440         }
       
   441     }
       
   442 
       
   443 // ----------------------------------------------------
       
   444 // CMceMainViewListItemArray::MakeStringForMainView
       
   445 // ----------------------------------------------------
       
   446 TPtrC CMceMainViewListItemArray::MakeStringForMainView( TInt aIndex ) const
       
   447     {
       
   448     TPtr tempText = iListBoxText->Des();
       
   449     tempText.Zero();
       
   450     TMsvEntry entry;
       
   451     TMsvId serviceId;
       
   452     TInt  visiblecount=0;
       
   453     const TMceListItem& item = At( aIndex );
       
   454     if ( iSession->GetEntry( item.iMsvId, serviceId, entry ) == KErrNone )
       
   455         {
       
   456         if ( item.iIconIndex <= KErrNone || item.iIconIndex >= iBitmapResolver.MtmIconIndex() )
       
   457             {
       
   458             TInt messageCount = 0;
       
   459             CONST_CAST( TMceListItem*, &item)->iIconIndex = iBitmapResolver.BitmapIndex( entry, messageCount );
       
   460             CONST_CAST( TMceListItem*, &item)->iMessageCount = messageCount;
       
   461             }
       
   462         tempText.AppendNum( item.iIconIndex );
       
   463         tempText.Append( KColumnListSeparator );
       
   464         tempText.Append( item.iPrintableText );
       
   465         if((iSelectableEmail)||(iEmailFramework))
       
   466             {
       
   467          if( item.iMsvId == KMsvDraftEntryId || 
       
   468                 item.iMsvId == KMsvSentEntryId || 
       
   469                 item.iMsvId == KMsvDeletedEntryFolderEntryId || 
       
   470                 item.iMsvId == KMsvGlobalInBoxIndexEntryId || item.iMsvId == KMsvGlobalOutBoxIndexEntryId )
       
   471                {
       
   472          TRAP_IGNORE( visiblecount = FindVisibleCountL(item.iMsvId) );
       
   473         AppendMessageCountString( tempText, visiblecount );
       
   474                }
       
   475 			 else
       
   476 			 {
       
   477 			 AppendMessageCountString( tempText, item.iMessageCount );
       
   478 			 }
       
   479          }
       
   480         else
       
   481         {
       
   482             AppendMessageCountString( tempText, item.iMessageCount );
       
   483         }
       
   484         if ( entry.Connected() )
       
   485             {
       
   486             if ( iRoaming )
       
   487                 {
       
   488                 tempText.Append( KColumnListSeparator );
       
   489                 tempText.AppendNum( (TInt) EMceBitmapIndexAlwaysRoaming );
       
   490                 }
       
   491             else
       
   492                 {
       
   493                 tempText.Append( KColumnListSeparator );
       
   494                 tempText.AppendNum( (TInt) EMceBitmapIndexMailboxConnectionOn );
       
   495                 }
       
   496             }
       
   497         else if (  iAlwaysOnline && ( entry.iMtm == KSenduiMtmImap4Uid || 
       
   498             entry.iMtm == KSenduiMtmPop3Uid ) )
       
   499             {
       
   500             TBool dateTime = EFalse;
       
   501             TBool aoAccount = EFalse;
       
   502             TRAP_IGNORE( dateTime = AlwaysOnlineDateTimeValidL( serviceId, aoAccount ) );
       
   503             if ( dateTime )
       
   504                 {
       
   505                 // within the update interval
       
   506                 tempText.Append( KColumnListSeparator );
       
   507                 if ( iRoaming )
       
   508                     {
       
   509                     tempText.AppendNum( (TInt) EMceBitmapIndexAlwaysRoaming );
       
   510                     }
       
   511                 else
       
   512                     { 
       
   513                     tempText.AppendNum( (TInt) EMceBitmapIndexAlwaysAdd );
       
   514                     }
       
   515                 }
       
   516             else if ( aoAccount )
       
   517                 {
       
   518                 // outside the interval
       
   519                 tempText.Append( KColumnListSeparator );
       
   520                 if ( iRoaming )
       
   521                     {
       
   522                     tempText.AppendNum( (TInt) EMceBitmapIndexAlwaysRoaming );
       
   523                     }
       
   524                 else
       
   525                     {
       
   526                     tempText.AppendNum( (TInt) EMceBitmapIndexInactiveAdd );
       
   527                     }
       
   528                 }
       
   529 
       
   530             }
       
   531         }
       
   532     else
       
   533         {
       
   534         // this should never happend
       
   535         __ASSERT_DEBUG( 0, Panic(EMceListItemArrayEntryNotFound ) );
       
   536         tempText.AppendNum( (TInt)EMceBitmapIndexUnknown );
       
   537         tempText.Append( KColumnListSeparator );
       
   538         tempText.Append( item.iPrintableText );
       
   539         }
       
   540     return tempText;
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CMceMainViewListItemArray::ShouldAddToListL()
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 TBool CMceMainViewListItemArray::ShouldAddToListL( 
       
   548     const TMsvEntry& aEntry,
       
   549     const TMsvId aId )
       
   550     {
       
   551     TBool add =
       
   552         // Is it a folder
       
   553         ( aEntry.iType == KUidMsvFolderEntry ) ||
       
   554         // Is it a local service id
       
   555         ( aId == KMsvLocalServiceIndexEntryId ) ||
       
   556         // Is it service but not local one?
       
   557         ( ( aEntry.iType == KUidMsvServiceEntry && 
       
   558             aEntry.Id() != KMsvLocalServiceIndexEntryId ) );
       
   559 
       
   560     // Mailboxes are added later, so ignore them here            
       
   561     return add ? !iEmailApi->MailboxUtilitiesL().IsMailMtm( aEntry.iMtm, ETrue ) : EFalse;        
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // CMceMainViewListItemArray::CollectServicesL()
       
   566 // ---------------------------------------------------------------------------
       
   567 //
       
   568 TInt CMceMainViewListItemArray::CollectServicesL( const TMsvId aId )
       
   569     {    
       
   570     const TMsvEntry* tEntry;
       
   571     const TInt count = iFolderEntry->Count();
       
   572     for (TInt cc = 0; cc < count; cc++)
       
   573         {
       
   574         tEntry = &( *iFolderEntry )[cc];
       
   575         if ( ShouldAddToListL( *tEntry, aId ) )
       
   576             {
       
   577             AddItemL( *tEntry );            
       
   578             }
       
   579         }
       
   580         
       
   581     return Count();
       
   582     }
       
   583 
       
   584 // ---------------------------------------------------------------------------
       
   585 // CMceMainViewListItemArray::AddMailboxesL()
       
   586 // ---------------------------------------------------------------------------
       
   587 void CMceMainViewListItemArray::AddMailboxesL( const TInt /*aMailboxIndex*/ )
       
   588     {
       
   589     // add mailboxes only if smtp mtm is installed
       
   590     if ( iUiRegistry->IsPresent( KSenduiMtmSmtpUid ) )
       
   591         {
       
   592         // Get the list of valid IMAP4, POP3, and SyncML mailboxes
       
   593         TInt err  = MceUtils::GetHealthyMailboxListL( 
       
   594             iEmailApi->HealthServicesL(),
       
   595             iMailboxArray,
       
   596             ETrue,
       
   597             ETrue,
       
   598             ETrue,
       
   599             ETrue );
       
   600 
       
   601     // for use of CMceMainViewListView::AddExtraItemsL() so that 
       
   602     // MceUtils::GetHealthyMailboxListL won't be called twice
       
   603         iErrGetHealthyMailBoxList = err;
       
   604         iMaiboxArrayCount = iMailboxArray.Count(); 
       
   605 //        MCELOGGER_WRITE_FORMAT("AddMailboxesL: iMaiboxArrayCount: %d", iMaiboxArrayCount );
       
   606         
       
   607         if ( iMaiboxArrayCount )
       
   608             {
       
   609             // Add the items to main view array in alphabetical order        
       
   610             for ( TInt mbox = 0; mbox < iMaiboxArrayCount; mbox++)
       
   611                 {   
       
   612                 // cmail update
       
   613                 if(iEmailFramework)
       
   614                     {                   
       
   615                     //IF mtm UID matches with uidMsgTypeFsMtmVal, skip the entry
       
   616                     //cmail should not be visible in MCE main view
       
   617                     TMsvId service;
       
   618                     TMsvEntry entry;
       
   619                     User::LeaveIfError( iSession->GetEntry( iMailboxArray[mbox], service, entry ) );
       
   620                     if(entry.iMtm.iUid == KUidMsgTypeFsMtmVal)
       
   621                         {
       
   622                         continue;
       
   623                         }
       
   624                     }
       
   625                 //cmail update
       
   626                 AddItemL( iFolderEntry->ChildDataL( iMailboxArray[mbox] ) );
       
   627                 }            
       
   628             }
       
   629         else
       
   630             {
       
   631             //Cmail update
       
   632             // If iEmailFramework is true , donot show "MailBox"
       
   633             // even if selectable email is true.
       
   634             if(!iEmailFramework)
       
   635                 {
       
   636                 if ( !iSelectableEmail  || ( iSelectableEmail && 
       
   637                         !MsvUiServiceUtilitiesInternal::OtherEmailMTMExistL( *iSession ) ) )
       
   638                     {
       
   639                     // add special mailbox entry
       
   640                     AddExtraItemFromResourceL( R_MCE_MAIN_VIEW_NO_MAILBOXES, KMceNoMailboxesListId );
       
   641                     }
       
   642                 }
       
   643             }
       
   644         }
       
   645         
       
   646     }
       
   647 
       
   648 // ---------------------------------------------------------------------------
       
   649 // CMceMainViewListItemArray::AddExtraItemFromResourceL()
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 void CMceMainViewListItemArray::AddExtraItemFromResourceL( TInt aResourceId, TInt aCommandId )
       
   653     {
       
   654     TMceListItem tempItem;
       
   655     tempItem.iExtraItem = ETrue;
       
   656     tempItem.iMsvId = aCommandId;
       
   657     StringLoader::Load( tempItem.iPrintableText, aResourceId, iCoeEnv );
       
   658 
       
   659     HBufC* line2text = NULL;
       
   660     switch ( aResourceId )
       
   661         {
       
   662         case R_MCE_MAIN_VIEW_DELIVERY_REPORTS:
       
   663             line2text = StringLoader::LoadL( R_MCE_MAIN_VIEW_DELIVERY_INFORMATION, iEikonEnv );
       
   664         break;
       
   665         case R_MCE_MAIN_VIEW_NO_MAILBOXES:
       
   666             line2text = StringLoader::LoadL( R_MCE_MAIN_VIEW_NO_MAILBOXES_DEFINED, iEikonEnv );
       
   667         break;
       
   668         default:
       
   669             // others does not have line2...
       
   670         break;
       
   671         }
       
   672     
       
   673     if ( line2text )
       
   674         {
       
   675         tempItem.iPrintableText.Append( KColumnListSeparator );
       
   676         tempItem.iPrintableText.Append( *line2text );
       
   677         delete line2text;
       
   678         line2text = NULL;
       
   679         }
       
   680     
       
   681     // always add at the end
       
   682     AddExtraItemL( tempItem, Count() );
       
   683     }
       
   684 
       
   685 // ----------------------------------------------------
       
   686 // CMceMainViewListItemArray::AddFoldersL
       
   687 // Adds the children of TMsvId aId to the listbox
       
   688 // ----------------------------------------------------
       
   689 void CMceMainViewListItemArray::AddFoldersL( )
       
   690     {
       
   691     Reset();
       
   692     TInt count = iMainViewItems->Count();
       
   693     TInt extraItemCommandCount = 0;
       
   694     
       
   695     for ( TInt i=0; i<count; i++ )
       
   696         {
       
   697         TMsvId folderId = (*iMainViewItems)[i];
       
   698         switch ( folderId )
       
   699             {
       
   700             case KMceWriteMessageListIdValue:
       
   701                 AddExtraItemFromResourceL( R_MCE_MAIN_VIEW_WRITE_MESSAGE, folderId );
       
   702             break;
       
   703             case KMceNoMailboxesListIdValue:
       
   704                 AddMailboxesL( KErrNotFound );
       
   705                 //AddExtraItemFromResourceL();
       
   706             break;
       
   707             case KMceDeliveryReportsListIdValue:
       
   708                 AddExtraItemFromResourceL( R_MCE_MAIN_VIEW_DELIVERY_REPORTS, folderId );
       
   709             break;
       
   710             default:
       
   711             if ( folderId > KMsvRootIndexEntryIdValue )
       
   712                 {
       
   713                 AddFolderItemL( folderId );
       
   714                 }
       
   715              else if ( folderId == KMceExtraItemPlaceHolderValue )
       
   716                 {
       
   717                 AddExtraItemCommandL( extraItemCommandCount );
       
   718                 extraItemCommandCount++;
       
   719                 }
       
   720             break;
       
   721             }
       
   722         }
       
   723     }
       
   724     
       
   725 // ----------------------------------------------------
       
   726 // CMceMainViewListItemArray::AddInboxDocumentsL
       
   727 // ----------------------------------------------------
       
   728 void CMceMainViewListItemArray::AddInboxDocumentsL( )
       
   729     {
       
   730     iFolderEntry->SetEntryL( KMsvLocalServiceIndexEntryId );
       
   731     AddItemL( iFolderEntry->
       
   732         ChildDataL( KMsvGlobalInBoxIndexEntryId ) );
       
   733     AddItemL( iFolderEntry->ChildDataL( KMceDocumentsEntryId ) );
       
   734     }
       
   735 
       
   736 // ----------------------------------------------------
       
   737 // CMceMainViewListItemArray::AddDraftSentOutboxL
       
   738 // ----------------------------------------------------
       
   739 void CMceMainViewListItemArray::AddDraftSentOutboxL( )
       
   740     {
       
   741     iFolderEntry->SetEntryL( KMsvLocalServiceIndexEntryId );
       
   742     AddItemL( iFolderEntry->ChildDataL( KMsvDraftEntryId ) );
       
   743     AddItemL( iFolderEntry->ChildDataL( KMsvSentEntryId ) );
       
   744     AddItemL( iFolderEntry->
       
   745     ChildDataL( KMsvGlobalOutBoxIndexEntryId ) );
       
   746     }
       
   747 
       
   748 // ----------------------------------------------------
       
   749 // CMceMainViewListItemArray::HandleSessionEventL
       
   750 // ----------------------------------------------------
       
   751 void CMceMainViewListItemArray::HandleSessionEventL(
       
   752     TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   753     {
       
   754     switch (aEvent)
       
   755         {
       
   756     case EMsvEntriesCreated:
       
   757     case EMsvEntriesChanged:
       
   758     case EMsvEntriesDeleted:
       
   759     case EMsvMediaChanged:
       
   760     case EMsvMediaUnavailable:
       
   761     case EMsvMediaAvailable:
       
   762         Reset();
       
   763         AddFoldersL();
       
   764         break;
       
   765 
       
   766     case EMsvCloseSession:        
       
   767         break;
       
   768 
       
   769     default:
       
   770         break;
       
   771         }
       
   772     }
       
   773 
       
   774 // ----------------------------------------------------
       
   775 // CMceMainViewListItemArray::StripAndAppendString
       
   776 // ----------------------------------------------------
       
   777 void CMceMainViewListItemArray::StripAndAppendString(TDes& aTargetString, const TDesC& aSourceString) const
       
   778     {
       
   779     TRAP_IGNORE( MceUtils::StripAndAppendStringL(
       
   780         aTargetString,
       
   781         aSourceString,
       
   782         iDescriptionLength ) );
       
   783     }
       
   784 
       
   785 // ----------------------------------------------------
       
   786 // CMceMainViewListItemArray::IsFolderRemote
       
   787 // return ETrue, if remote folder
       
   788 //
       
   789 // ----------------------------------------------------
       
   790 TBool CMceMainViewListItemArray::IsFolderRemote() const
       
   791     {
       
   792     TMsvId service = KMsvLocalServiceIndexEntryId;
       
   793     TMsvEntry entry;
       
   794     if ( iSession->GetEntry(KMsvRootIndexEntryId,service,entry) == KErrNone )
       
   795     	{
       
   796     	return KMsvLocalServiceIndexEntryId != service;
       
   797     	}
       
   798     else
       
   799     	{
       
   800     	return EFalse;
       
   801     	}
       
   802     }
       
   803 
       
   804 // ----------------------------------------------------
       
   805 // CMceMainViewListItemArray::ConstructMainViewL
       
   806 // add folders in main view
       
   807 //
       
   808 // ----------------------------------------------------
       
   809 
       
   810 void CMceMainViewListItemArray::ConstructMainViewL()
       
   811     {
       
   812     delete iFolderEntry;
       
   813     iFolderEntry = NULL;
       
   814     iFolderEntry = CMsvEntry::NewL(
       
   815         *iSession,
       
   816         KMsvRootIndexEntryId,
       
   817         TMsvSelectionOrdering(
       
   818             KMsvGroupByStandardFolders, EMsvSortByDetails ) );
       
   819     AddFoldersL();
       
   820     }
       
   821 
       
   822 // ----------------------------------------------------
       
   823 // CMceMainViewListItemArray::FolderId
       
   824 // return folder id
       
   825 //
       
   826 // ----------------------------------------------------
       
   827 TMsvId CMceMainViewListItemArray::FolderId() const
       
   828     {
       
   829     return KMsvRootIndexEntryId;
       
   830     }
       
   831 
       
   832 
       
   833 // ----------------------------------------------------
       
   834 // CMceMainViewListItemArray::IsConnected
       
   835 // return ETrue, if account is connected
       
   836 //
       
   837 // ----------------------------------------------------
       
   838 TBool CMceMainViewListItemArray::IsConnected() const
       
   839     {
       
   840     TMsvEntry entry;
       
   841     entry = iFolderEntry->Entry();
       
   842 
       
   843     TMsvEntry serviceEntry;
       
   844     TMsvId serviceId;
       
   845     if ( iSession->GetEntry(entry.iServiceId,serviceId,serviceEntry) == KErrNone )
       
   846     	{
       
   847     	return serviceEntry.Connected();
       
   848     	}
       
   849     else
       
   850     	{
       
   851     	return EFalse;
       
   852     	}
       
   853     }
       
   854 
       
   855 
       
   856 // ----------------------------------------------------
       
   857 // CMceMainViewListItemArray::AlwaysOnlineDateTimeValidL
       
   858 // 
       
   859 //
       
   860 // ----------------------------------------------------
       
   861 TBool CMceMainViewListItemArray::AlwaysOnlineDateTimeValidL( const TMsvId aAccount, TBool &aoDefined ) const
       
   862     {
       
   863     // Check if the always online is turned on
       
   864     TInt64 flags = 0;    
       
   865     iEmailApi->MailboxUtilitiesL().QueryAlwaysOnlineStateL( 
       
   866         aAccount, flags );
       
   867                     
       
   868     aoDefined = 
       
   869         ( flags & MImumInMailboxUtilities::EFlagTurnedOn ) ? ETrue : EFalse;            
       
   870     return ( flags & MImumInMailboxUtilities::EFlagWaitingToConnect ) ? 
       
   871         ETrue : EFalse;
       
   872     }
       
   873 
       
   874 // ----------------------------------------------------
       
   875 // CMceMainViewListItemArray::AlwaysOnlineAccountL
       
   876 //
       
   877 // ----------------------------------------------------
       
   878 TBool CMceMainViewListItemArray::AlwaysOnlineAccountL( 
       
   879 	const TMsvId /*aAccount*/, 
       
   880     const CImumInSettingsData& aSettingsData ) const
       
   881     {
       
   882     TInt online = 0;
       
   883     aSettingsData.GetAttr( TImumDaSettings::EKeyAutoRetrieval, online );
       
   884     return online != TImumDaSettings::EValueAutoOff;
       
   885     }
       
   886 
       
   887 // ----------------------------------------------------
       
   888 // CMceMainViewListItemArray::SetRoaming
       
   889 // sets roaming flag
       
   890 //
       
   891 // ----------------------------------------------------
       
   892 void CMceMainViewListItemArray::SetRoaming( TBool aRoaming )
       
   893     {
       
   894     iRoaming = aRoaming;
       
   895     }
       
   896 
       
   897 // ----------------------------------------------------
       
   898 // CMceMainViewListItemArray::Roaming
       
   899 // gets roaming flag
       
   900 //
       
   901 // ----------------------------------------------------
       
   902 TBool CMceMainViewListItemArray::Roaming() const
       
   903     {
       
   904     return iRoaming;
       
   905     }
       
   906 
       
   907 // ----------------------------------------------------
       
   908 // CMceMainViewListItemArray::SetAlwaysOnline
       
   909 // sets always online flag
       
   910 //
       
   911 // ----------------------------------------------------
       
   912 void CMceMainViewListItemArray::SetAlwaysOnline( TBool aAlwaysOnline )
       
   913     {
       
   914     iAlwaysOnline = aAlwaysOnline;
       
   915     }
       
   916 
       
   917 // ----------------------------------------------------
       
   918 // CMceMainViewListItemArray::GetEmailApi
       
   919 // Returns the reference to the email API
       
   920 // ----------------------------------------------------
       
   921 CImumInternalApi* CMceMainViewListItemArray::GetEmailApi()
       
   922     {
       
   923     return iEmailApi;
       
   924     }
       
   925 
       
   926 // ----------------------------------------------------
       
   927 // CMceMainViewListItemArray::
       
   928 // ----------------------------------------------------
       
   929 void CMceMainViewListItemArray::AppendMessageCountString( TDes& aBuffer, TInt aMessageCount ) const
       
   930     {
       
   931     aBuffer.Append( KColumnListSeparator );
       
   932     if ( aMessageCount == 0)
       
   933         {
       
   934         aBuffer.Append( (*iNumberOfMessagesStrings)[
       
   935             KMceListArrayDocNoMessages] );
       
   936         }
       
   937     else if ( aMessageCount == 1 )
       
   938         {
       
   939         TBuf<KMcePrintableTextLength> tempString;
       
   940         tempString.Append((*iNumberOfMessagesStrings)[
       
   941             KMceListArrayNumberOneMessage] );
       
   942         AknTextUtils::LanguageSpecificNumberConversion( tempString );
       
   943         aBuffer.Append( tempString );
       
   944         }
       
   945     else
       
   946         {
       
   947         TBuf<KMcePrintableTextLength> tempString;
       
   948         StringLoader::Format( tempString,
       
   949             (*iNumberOfMessagesStrings)[KMceListArrayNumberOfMsgs],
       
   950             -1, // no index in the key string
       
   951             aMessageCount );
       
   952         AknTextUtils::LanguageSpecificNumberConversion( tempString );
       
   953         aBuffer.Append( tempString );
       
   954         }
       
   955     }
       
   956     
       
   957 
       
   958 // ----------------------------------------------------
       
   959 // CMceMainViewListItemArray::GetHealthyMailboxListResult( TInt& aCount )
       
   960 // ----------------------------------------------------    
       
   961 TInt CMceMainViewListItemArray::GetHealthyMailboxListResult( TInt& aCount )
       
   962     {
       
   963     aCount = iMaiboxArrayCount;
       
   964     return iErrGetHealthyMailBoxList;
       
   965     }  
       
   966 
       
   967 // ----------------------------------------------------
       
   968 // CMceMainViewListItemArray::
       
   969 // ----------------------------------------------------
       
   970 void CMceMainViewListItemArray::StartListUpdateL()
       
   971     {
       
   972     const TInt count = Count();
       
   973     TInt i = 0;
       
   974     for ( i = 0; i < count; i++ )
       
   975         {
       
   976         At( i ).iIconIndex = KErrNotFound;
       
   977         }
       
   978     iIdleCounter = 0; // update only item which icon index is not valid
       
   979     if ( iIdleLoader )
       
   980         {
       
   981         iIdleLoader->StartL();
       
   982         }
       
   983     }
       
   984 
       
   985 // ----------------------------------------------------
       
   986 // CMceMainViewListItemArray::
       
   987 // ----------------------------------------------------
       
   988 void CMceMainViewListItemArray::ResetIconIndexL( TInt aIndex )
       
   989     {
       
   990     iIdleCounter = 0;
       
   991     At( aIndex ).iIconIndex = KErrNotFound;
       
   992     if ( iIdleLoader )
       
   993         {
       
   994         iIdleLoader->StartL();
       
   995         }
       
   996     }
       
   997 
       
   998 // ----------------------------------------------------
       
   999 // CMceMainViewListItemArray::
       
  1000 // ----------------------------------------------------
       
  1001 TBool CMceMainViewListItemArray::MMceUtilsIdleClassStepL( )
       
  1002     {
       
  1003     const TInt count = Count();
       
  1004     // iIdleCounter set to 0 in functions StartListUpdateL and ResetIconIndexL
       
  1005     for ( ; iIdleCounter < count; iIdleCounter++ )
       
  1006         {
       
  1007         TMceListItem& item = At( iIdleCounter );
       
  1008         if ( !item.iExtraItem && ( item.iIconIndex <= KErrNone || item.iIconIndex > iBitmapResolver.MtmIconIndex() ) )
       
  1009             {
       
  1010             TMsvEntry entry;
       
  1011             TMsvId serviceId;
       
  1012             if ( iSession->GetEntry( item.iMsvId, serviceId, entry ) == KErrNone )
       
  1013                 {
       
  1014                 TInt messageCount = 0;
       
  1015                 item.iIconIndex = iBitmapResolver.BitmapIndex( entry, messageCount );
       
  1016                 item.iMessageCount = messageCount;
       
  1017 //                        item.iUnreadMessageCount = unreadMessageCount;
       
  1018                 if ( iListItemArrayObserver )
       
  1019                     {
       
  1020                     iListItemArrayObserver->MceListItemArrayChangedL();
       
  1021                     }
       
  1022 //                    iIdleCounter++;
       
  1023                 break;
       
  1024                 }
       
  1025             }
       
  1026         }
       
  1027     return iIdleCounter < count;
       
  1028     }
       
  1029 
       
  1030 // ----------------------------------------------------
       
  1031 // CMceMainViewListItemArray::
       
  1032 // ----------------------------------------------------
       
  1033 void CMceMainViewListItemArray::SetListItemArrayObserver( MMceMainViewListItemArrayObserver* aObserver )
       
  1034     {
       
  1035     iListItemArrayObserver = aObserver;
       
  1036     }
       
  1037 
       
  1038 // ----------------------------------------------------
       
  1039 // CMceMainViewListView::ReadExtraItemsResourceL
       
  1040 // ----------------------------------------------------
       
  1041 void CMceMainViewListItemArray::ReadExtraItemsResourceL()
       
  1042     {
       
  1043     if ( !iExtraItemsArray )
       
  1044         {
       
  1045         iExtraItemsArray = new( ELeave ) CMceMainViewExtraItemArray( KMceListGranuality );
       
  1046         }
       
  1047     else
       
  1048         {
       
  1049         iExtraItemsArray->Reset();
       
  1050         }
       
  1051     
       
  1052     _LIT(KDirAndMceExtraItemsResFileName,"mceextraitems.rsc");
       
  1053             TFileName fileName; 
       
  1054             TFindFile finder( iCoeEnv->FsSession() );
       
  1055             //Search Y->A then Z:
       
  1056             TInt err = finder.FindByDir( KDirAndMceExtraItemsResFileName, KDC_APP_RESOURCE_DIR );
       
  1057             if(err == KErrNone)
       
  1058                 {
       
  1059                 fileName = finder.File();
       
  1060                 BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(),fileName);
       
  1061                 RConeResourceLoader resources( *iCoeEnv );
       
  1062 
       
  1063                 TInt err = KErrNone;
       
  1064                 TRAP( err, resources.OpenL(fileName) );
       
  1065 
       
  1066                 if ( err == KErrNone )
       
  1067                     {
       
  1068                     TResourceReader reader;
       
  1069                     iEikonEnv->CreateResourceReaderLC( reader, R_MCE_EXTRA_ITEMS );
       
  1070 
       
  1071                     const TInt count = reader.ReadInt16();
       
  1072                     TMceMainViewExtraItem extraItem;
       
  1073                     extraItem.iCommandId = KMceFirstExtraItemId;
       
  1074                     for ( TInt loop = 0; loop < count; loop++ )
       
  1075                         {
       
  1076                         HBufC* txt = reader.ReadHBufCL();   // message text
       
  1077                         extraItem.iPrintableText.Copy( *txt );
       
  1078                         delete txt;
       
  1079                         txt = NULL;
       
  1080                         txt = reader.ReadHBufCL();   // message text
       
  1081                         extraItem.iCommandText.Copy( *txt );
       
  1082                         delete txt;
       
  1083 
       
  1084                         TInt depricatedResource = reader.ReadInt16(); // this is not used anymore, but left in resource so no DC break.
       
  1085                         extraItem.iIconIndex = reader.ReadInt16();
       
  1086                         TUid applicationUid;
       
  1087                         applicationUid.iUid = reader.ReadUint32();
       
  1088                         extraItem.iApplicationUid = applicationUid.iUid;
       
  1089 
       
  1090                         iExtraItemsArray->AppendL( extraItem );
       
  1091                         extraItem.iCommandId++;
       
  1092                         }
       
  1093                     CleanupStack::PopAndDestroy(); // reader
       
  1094                     resources.Close();
       
  1095                     }
       
  1096                 }
       
  1097             }
       
  1098 
       
  1099 
       
  1100 // ----------------------------------------------------
       
  1101 // CMceMainViewListView::ExtraItemCommandLC
       
  1102 // ----------------------------------------------------
       
  1103 HBufC* CMceMainViewListItemArray::ExtraItemCommandLC( TInt aCommandId )
       
  1104     {
       
  1105     HBufC* commandText = HBufC::NewLC( KMcePrintableTextLength );
       
  1106     TPtr tempText = commandText->Des();
       
  1107     
       
  1108     const TInt count = iExtraItemsArray->Count();
       
  1109     for (TInt i=0; i<count; i++ )
       
  1110         {
       
  1111         if ( aCommandId == (*iExtraItemsArray)[i].iCommandId )
       
  1112             {
       
  1113             tempText.Copy( (*iExtraItemsArray)[i].iCommandText );
       
  1114             i=count;
       
  1115             }
       
  1116         }
       
  1117     
       
  1118     return commandText;    
       
  1119     }
       
  1120     
       
  1121 // ----------------------------------------------------
       
  1122 // CMceMainViewListView::AddExtraItemCommandL
       
  1123 // ----------------------------------------------------
       
  1124 void CMceMainViewListItemArray::AddExtraItemCommandL( TInt aIndex )
       
  1125     {
       
  1126     if ( aIndex < iExtraItemsArray->Count() )
       
  1127         {
       
  1128         const TMceMainViewExtraItem& extraItem = (*iExtraItemsArray)[aIndex];
       
  1129         TMceListItem tempItem;
       
  1130         tempItem.iExtraItem = ETrue;
       
  1131         tempItem.iMsvId = extraItem.iCommandId;
       
  1132        	tempItem.iPrintableText.Copy( extraItem.iPrintableText );
       
  1133        	TUid appUid;
       
  1134        	appUid.iUid = extraItem.iApplicationUid;
       
  1135        	AddExtraItemWithIconL( tempItem, Count(), extraItem.iIconIndex, appUid );
       
  1136         }
       
  1137     }
       
  1138 
       
  1139 // ----------------------------------------------------
       
  1140 // CMceMainViewListView::ReadMainViewItemsFromRepositoryL
       
  1141 // ----------------------------------------------------
       
  1142 void CMceMainViewListItemArray::ReadMainViewItemsFromRepositoryL()
       
  1143     {
       
  1144     if ( !iMainViewItems )
       
  1145         {
       
  1146         iMainViewItems = new( ELeave ) CMsvEntrySelection();
       
  1147         }
       
  1148     else
       
  1149         {
       
  1150         iMainViewItems->Reset();        
       
  1151         }
       
  1152     CRepository* repository = CRepository::NewLC(KCRUidMuiuSettings);
       
  1153     for ( TInt i = KMuiuMceMainViewRow1; i<=KMuiuMceMainViewRow16; i++ )
       
  1154         {
       
  1155         TInt value = 0;
       
  1156         if ( repository->Get( i, value ) == KErrNone && value > KErrNotFound )
       
  1157             {
       
  1158             iMainViewItems->AppendL( value );
       
  1159             }
       
  1160         }
       
  1161     CleanupStack::PopAndDestroy( repository );
       
  1162     }
       
  1163 
       
  1164 // ----------------------------------------------------
       
  1165 // CMceMainViewListItemArray::FindVisibleCountL()
       
  1166 // ----------------------------------------------------
       
  1167 TInt CMceMainViewListItemArray::FindVisibleCountL(TMsvId serviceId ) const
       
  1168     {
       
  1169     TInt visiblecount=0;
       
  1170     TInt emailcount=0;
       
  1171     TInt itemcount;
       
  1172     CMsvEntry* entry = iSession->GetEntryL( serviceId );
       
  1173     itemcount=entry->Count();
       
  1174       
       
  1175     //Find email messages 
       
  1176     CMsvEntrySelection *smtpselection = entry->ChildrenWithMtmL( KUidMsgTypeSMTP );
       
  1177     CleanupStack::PushL( smtpselection );
       
  1178 
       
  1179     CMsvEntrySelection *pop3selection = NULL;
       
  1180     CMsvEntrySelection *imapselection = NULL ;
       
  1181     CMsvEntrySelection *cmailselection = NULL ;
       
  1182     
       
  1183     if(!iEmailFramework)
       
  1184         {
       
  1185         pop3selection = entry->ChildrenWithMtmL( KUidMsgTypePOP3 );
       
  1186         CleanupStack::PushL( pop3selection );
       
  1187         imapselection = entry->ChildrenWithMtmL( KUidMsgTypeIMAP4 );
       
  1188         CleanupStack::PushL( imapselection );
       
  1189         }
       
  1190     else
       
  1191         {
       
  1192         cmailselection = entry->ChildrenWithMtmL( 
       
  1193                 TUid::Uid(KUidMsgTypeFsMtmVal));
       
  1194         CleanupStack::PushL( cmailselection );
       
  1195         }
       
  1196 
       
  1197     if ( smtpselection!=0 && smtpselection->Count()>0 )
       
  1198         {
       
  1199         emailcount=emailcount+smtpselection->Count();
       
  1200         }
       
  1201 
       
  1202     if(!iEmailFramework)
       
  1203         {
       
  1204         if ( pop3selection!=0 && pop3selection->Count()>0 )
       
  1205             {
       
  1206             emailcount=emailcount+pop3selection->Count();
       
  1207             }
       
  1208         if ( imapselection!=0 && imapselection->Count()>0 )
       
  1209             {
       
  1210             emailcount=emailcount+imapselection->Count();
       
  1211             }        
       
  1212         }
       
  1213     else
       
  1214         {
       
  1215         if ( cmailselection!=0 && cmailselection->Count()>0 )
       
  1216             {
       
  1217             emailcount=emailcount+cmailselection->Count();
       
  1218             }
       
  1219         }
       
  1220 
       
  1221     visiblecount = itemcount - emailcount;
       
  1222 
       
  1223     if(iEmailFramework)
       
  1224         {
       
  1225         CleanupStack::PopAndDestroy( cmailselection );       
       
  1226         }
       
  1227     else
       
  1228         {
       
  1229         CleanupStack::PopAndDestroy(imapselection);
       
  1230         CleanupStack::PopAndDestroy( pop3selection );
       
  1231         }
       
  1232     CleanupStack::PopAndDestroy( smtpselection );
       
  1233 
       
  1234     return visiblecount; 
       
  1235     }
       
  1236 //  End of File