emailuis/widget/emailwidgetsettings/src/emailwidgetsettingslistviewcontainer.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 1 12c456ceeff2
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include <eikclbd.h>
    19 #include <eikclbd.h>
    20 #include <eikmop.h>
    20 #include <eikmop.h>
    21 #include <bacline.h>
    21 #include <bacline.h>
    22 #include <StringLoader.h>
    22 #include <StringLoader.h>
    23 #include <akniconarray.h>
    23 #include <AknIconArray.h>
    24 #include <emailwidgetsettings.rsg>
    24 #include <emailwidgetsettings.rsg>
    25 #include <emailwidgetsettings.mbg>
    25 #include <emailwidgetsettings.mbg>
       
    26 #include <emailobserverinterface.hrh>
       
    27 #include <memaildata.h>
    26 
    28 
    27 #include "emailtrace.h"
    29 #include "emailtrace.h"
    28 #include "emailwidgetsettingslistview.h"
    30 #include "emailwidgetsettingslistview.h"
    29 #include "cmailwidgetcenrepkeys.h"
    31 #include "cmailwidgetcenrepkeys.h"
    30 #include "CFSMailClient.h"
    32 #include "cfsmailclient.h"
    31 
    33 
    32 using namespace AknLayout;
    34 using namespace AknLayout;
       
    35 using namespace EmailInterface;
    33 
    36 
    34 const TInt KMaxMailboxCount = 18;
    37 const TInt KMaxMailboxCount = 18;
       
    38 const TInt KMaxExternalBoxCount = 10;
    35 _LIT( KDissociated,"0");
    39 _LIT( KDissociated,"0");
    36 const TInt KMaxDescLen = 256;
    40 const TInt KMaxDescLen = 256;
    37 const TUid KUidWizardApp = { 0x10281c96 };
    41 const TUid KUidWizardApp = { 0x10281c96 };
    38 const TUid KUidEmailWizardView = { 0x10281C9A };
    42 const TUid KUidEmailWizardView = { 0x10281C9A };
    39 _LIT( KMifPath, "z:\\resource\\apps\\emailwidgetsettings.mif");
    43 _LIT( KMifPath, "z:\\resource\\apps\\emailwidgetsettings.mif");
       
    44 _LIT( KMifPrefix, "mif(" );
    40 
    45 
    41 // ======== MEMBER FUNCTIONS ========
    46 // ======== MEMBER FUNCTIONS ========
    42 
    47 
    43 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    44 // 
    49 // CEmailWidgetSettingsListViewContainer::CEmailWidgetSettingsListViewContainer
    45 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    46 //
    51 //
    47 CEmailWidgetSettingsListViewContainer::CEmailWidgetSettingsListViewContainer()
    52 CEmailWidgetSettingsListViewContainer::CEmailWidgetSettingsListViewContainer()
    48     {
    53     {
    49     FUNC_LOG;        
    54     FUNC_LOG;        
    50     }
    55     }
    51 
    56 
    52 // ---------------------------------------------------------------------------
    57 // ---------------------------------------------------------------------------
    53 // 
    58 // CEmailWidgetSettingsListViewContainer::ConstructL
    54 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    55 //
    60 //
    56 void CEmailWidgetSettingsListViewContainer::ConstructL(CEmailWidgetSettingsListView* aView, 
    61 void CEmailWidgetSettingsListViewContainer::ConstructL(CEmailWidgetSettingsListView* aView, 
    57                                                        const TRect& aRect)
    62                                                        const TRect& aRect)
    58     {
    63     {
    67     SetRect(aRect);
    72     SetRect(aRect);
    68     ActivateL();
    73     ActivateL();
    69     }
    74     }
    70 
    75 
    71 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    72 // 
    77 // CEmailWidgetSettingsListViewContainer::CreateListBoxL 
    73 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    74 //
    79 //
    75 void CEmailWidgetSettingsListViewContainer::CreateListBoxL(MEikListBoxObserver* aObserver)
    80 void CEmailWidgetSettingsListViewContainer::CreateListBoxL(MEikListBoxObserver* aObserver)
    76     {
    81     {
    77     FUNC_LOG;        
    82     FUNC_LOG;      
    78     TInt count = iMailboxes->MailboxCount();
    83     
       
    84     
       
    85     TInt nativeMailboxCount = iMailboxes->MailboxCount();
    79 
    86 
    80     iListBox = new(ELeave) CAknSingleGraphicStyleListBox;
    87     iListBox = new(ELeave) CAknSingleGraphicStyleListBox;
    81     iListBox->SetContainerWindowL( *this);
    88     iListBox->SetContainerWindowL( *this);
    82     iListBox->ConstructL( this, EAknListBoxSelectionList );
    89     iListBox->ConstructL( this, EAknListBoxSelectionList );
    83     iAccountNames = new (ELeave) CDesCArrayFlat(count + 1);
    90     
    84     iDomains = new (ELeave) CDesCArrayFlat(count);
    91     iAccountNames = new (ELeave) CDesCArrayFlat(nativeMailboxCount + 1); // +1 for creating new mailbox
    85     if (count)
    92     iDomains = new (ELeave) CDesCArrayFlat(1);
    86         {
    93 	iAccountIds = new ( ELeave ) CArrayFixFlat<TFSMailMsgId>(1);
    87 		iAccountIds = new ( ELeave ) CArrayFixFlat<TFSMailMsgId>(count);
    94 	
    88 		}
    95     // First items on the selection list are native mailboxes.
    89     for (TInt i = 0; i < count; i++)
    96 	// Append name, domain and id information to the arrays.
       
    97 	for (TInt i = 0; i < nativeMailboxCount; i++)
    90         {
    98         {
    91         TBuf<KMaxDescLen> name;
    99         TBuf<KMaxDescLen> name;
    92         TBuf<KMaxDescLen> domain;        
   100         TBuf<KMaxDescLen> domain;        
    93         TFSMailMsgId id;
   101         TFSMailMsgId id;
    94         iMailboxes->GetMailboxNameL(i, name);
   102         iMailboxes->GetMailboxNameL(i, name);
    96         iMailboxes->GetMailboxIdL(i, id);
   104         iMailboxes->GetMailboxIdL(i, id);
    97         iAccountNames->AppendL(name);
   105         iAccountNames->AppendL(name);
    98         iDomains->AppendL(domain);
   106         iDomains->AppendL(domain);
    99         iAccountIds->AppendL(id);
   107         iAccountIds->AppendL(id);
   100         }
   108         }
       
   109     
       
   110     // Continue with external mailboxes.
       
   111 	// List plugins implementing the interface.
       
   112     TUid interfaceUid = TUid::Uid( KEmailObserverInterfaceUid );
       
   113     RImplInfoPtrArray pluginArray;
       
   114     REComSession::ListImplementationsL( interfaceUid, pluginArray);
       
   115    
       
   116     const TInt pluginCount = pluginArray.Count();
       
   117     INFO_1("***** NUMBER OF plugins == %d", pluginCount);
       
   118     for ( TInt ii = 0; ii < pluginCount; ii++ )
       
   119         {
       
   120         TUid implUid = pluginArray[ii]->ImplementationUid();
       
   121        
       
   122         // load external email client plugin
       
   123         INFO_1("***** BEFORE instantiating plugin %d", implUid.iUid);
       
   124         EmailInterface::CEmailObserverPlugin* plugin = EmailInterface::CEmailObserverPlugin::NewL( implUid, this );
       
   125         CleanupStack::PushL( plugin );
       
   126         INFO("***** AFTER instantiating plugin ");
       
   127         
       
   128         // list mailboxes of the plugin
       
   129         MEmailData& data( plugin->EmailDataL() );
       
   130         RPointerArray<MMailboxData> extMailboxes = data.MailboxesL();
       
   131         
       
   132         const TInt extMailboxCount = extMailboxes.Count();
       
   133         
       
   134         for ( TInt jj = 0; jj < extMailboxCount; jj++ )
       
   135             {
       
   136             // Append mailbox name using indexed format ( e.g. "1\tMailboxName\t\t" )
       
   137             TBuf<KMaxDescLen> name;
       
   138             name.AppendNum(nativeMailboxCount + 1 + jj);
       
   139             name.Append(_L("\t"));
       
   140             name.Append(extMailboxes[jj]->Name());
       
   141             name.Append(_L("\t\t"));
       
   142             iAccountNames->AppendL(name);
       
   143             
       
   144             // Instead of domain information, external mail clients are requested
       
   145             // to provide a string containing a mif file path and icon/mask numbers.
       
   146             // The provided string is stored to domain list.
       
   147             iDomains->AppendL( extMailboxes[jj]->BrandingIcon());
       
   148             
       
   149 
       
   150             // Combine plugin uid and mailbox id and add to the list.
       
   151             TFSMailMsgId uid( implUid, extMailboxes[jj]->MailboxId() );
       
   152             iAccountIds->AppendL( uid );
       
   153             }
       
   154         CleanupStack::PopAndDestroy(plugin);
       
   155         plugin = NULL;
       
   156         }
       
   157     pluginArray.ResetAndDestroy();
       
   158   
   101     HBufC* createNewMailbox = StringLoader::LoadLC(R_EMAILWIDGETSETTINGS_CREATE_NEW_MAILBOX);
   159     HBufC* createNewMailbox = StringLoader::LoadLC(R_EMAILWIDGETSETTINGS_CREATE_NEW_MAILBOX);
   102     iAccountNames->AppendL(createNewMailbox->Des());
   160     iAccountNames->AppendL(createNewMailbox->Des());
   103     CleanupStack::PopAndDestroy(createNewMailbox);
   161     CleanupStack::PopAndDestroy(createNewMailbox);
   104     iListBox->Model()->SetItemTextArray(iAccountNames);
   162     iListBox->Model()->SetItemTextArray(iAccountNames);
   105     
   163     
   108     iListBox->SetBorder(TGulBorder::ESingleBlack);
   166     iListBox->SetBorder(TGulBorder::ESingleBlack);
   109     iListBox->CreateScrollBarFrameL(ETrue);
   167     iListBox->CreateScrollBarFrameL(ETrue);
   110     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
   168     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
   111     iListBox->SetListBoxObserver(aObserver);
   169     iListBox->SetListBoxObserver(aObserver);
   112     
   170     
       
   171 
   113     SetupListIconsL();
   172     SetupListIconsL();
   114     }
   173 
   115 
   174     }
   116 // ---------------------------------------------------------------------------
   175 
   117 // 
   176 // ---------------------------------------------------------------------------
       
   177 // CEmailWidgetSettingsListViewContainer::SetupListIconsL
   118 // ---------------------------------------------------------------------------
   178 // ---------------------------------------------------------------------------
   119 //
   179 //
   120 void CEmailWidgetSettingsListViewContainer::SetupListIconsL()
   180 void CEmailWidgetSettingsListViewContainer::SetupListIconsL()
   121     {
   181     {
   122     FUNC_LOG;        
   182     FUNC_LOG;        
   123     CFSMailClient* mailClient = CFSMailClient::NewL();
   183     CFSMailClient* mailClient = CFSMailClient::NewL();
   124     CleanupClosePushL(*mailClient);
   184     CleanupClosePushL(*mailClient);
   125     MFSMailBrandManager& brandManager = mailClient->GetBrandManagerL();
   185     MFSMailBrandManager& brandManager = mailClient->GetBrandManagerL();
   126     
   186     
   127     TInt count = iMailboxes->MailboxCount();
   187     TInt count = iAccountIds->Count();
       
   188     
   128     CArrayPtr<CGulIcon>* icons = new(ELeave) CArrayPtrFlat<CGulIcon>( count + 1 );
   189     CArrayPtr<CGulIcon>* icons = new(ELeave) CArrayPtrFlat<CGulIcon>( count + 1 );
   129     CleanupStack::PushL( icons );
   190     CleanupStack::PushL( icons );
   130    
   191     
       
   192     // Add "new mailbox" icon to the list
   131     AppendIconL(icons, EMbmEmailwidgetsettingsQgn_prop_cmail_new_mailbox, 
   193     AppendIconL(icons, EMbmEmailwidgetsettingsQgn_prop_cmail_new_mailbox, 
   132                        EMbmEmailwidgetsettingsQgn_prop_cmail_new_mailbox_mask);
   194                        EMbmEmailwidgetsettingsQgn_prop_cmail_new_mailbox_mask);
   133 
   195 
   134     for (TInt i = 0; i < count; i++)
   196     for (TInt i = 0; i < count; i++)
   135         {
   197         {
   136         CGulIcon* brandIcon;
   198         CGulIcon* brandIcon;
   137         brandIcon = brandManager.GetGraphicL( EFSMailboxIcon, iDomains->MdcaPoint(i) );
   199         brandIcon = brandManager.GetGraphicL( EFSMailboxIcon, iDomains->MdcaPoint(i) );
   138         
   200         
   139         if (brandIcon)
   201         if (brandIcon)
   140             {
   202             {
       
   203             // Add branded mailbox icon to the list
   141             icons->AppendL(brandIcon);
   204             icons->AppendL(brandIcon);
   142             }
   205             }
   143         else
   206         else
   144             {
   207             {
   145             AppendIconL(icons, EMbmEmailwidgetsettingsQgn_indi_cmail_drop_email_account, 
   208             TInt err(KErrNotFound);
   146                                EMbmEmailwidgetsettingsQgn_indi_cmail_drop_email_account_mask);
   209             
   147             }
   210             // Check if domain list item contains mif file path (instead of domain)
   148         }
   211             // Path follows the format: "mif(z:\\resource\\apps\\myemailplugin.mif N1 N2)"    
   149 
   212         
       
   213             TBufC<KMaxDescLen> temp( iDomains->MdcaPoint(i) );
       
   214             if( temp.Find(KMifPrefix) == 0 )
       
   215                 {        
       
   216                 TInt p1 = KMifPrefix().Length();
       
   217                 TInt p2 = temp.Locate(' ') + 1;
       
   218                 TInt p3 = temp.LocateReverse(' ') + 1;
       
   219                 TInt end = temp.Length() - 1;
       
   220 
       
   221                 TInt p1Len = p2-p1-1;
       
   222                 TInt p2Len = p3-p2-1;
       
   223                 TInt p3Len = end-p3;
       
   224 
       
   225                 // negative lengths not allowed
       
   226                 if ( p1Len > 0 && p2Len > 0 && p3Len > 0 )
       
   227                     {
       
   228                     TBufC<KMaxDescLen>  mifPath(temp.Mid( p1, p1Len ));
       
   229                     TBufC<16>        iconString(temp.Mid( p2, p2Len ));
       
   230                     TBufC<16>        maskString(temp.Mid( p3, p3Len )); 
       
   231                     
       
   232                     TLex lexIcon(iconString);
       
   233                     TLex lexMask(maskString);
       
   234                     TInt icon(0), mask(0);     
       
   235                     lexIcon.Val(icon);
       
   236                     lexMask.Val(mask);
       
   237                     
       
   238                     // Add 3rd party mailbox icon to the list
       
   239                     err = AppendExternalIconL( icons, mifPath, icon, mask );
       
   240                     }
       
   241                 }   
       
   242             if ( err )
       
   243                 {
       
   244                 // Add default mailbox icon to the list
       
   245                 AppendIconL(icons, EMbmEmailwidgetsettingsQgn_indi_cmail_drop_email_account, 
       
   246                                    EMbmEmailwidgetsettingsQgn_indi_cmail_drop_email_account_mask);
       
   247                 }
       
   248             }
       
   249         }
       
   250     
   150     // clear any previous icon array
   251     // clear any previous icon array
   151     CAknIconArray* oldIconArray = static_cast<CAknIconArray*>(iListBox->ItemDrawer()->ColumnData()->IconArray());
   252     CAknIconArray* oldIconArray = static_cast<CAknIconArray*>(iListBox->ItemDrawer()->ColumnData()->IconArray());
   152     if (oldIconArray)
   253     if (oldIconArray)
   153         delete oldIconArray;
   254         delete oldIconArray;
   154     
   255     
   156     CleanupStack::Pop(icons);
   257     CleanupStack::Pop(icons);
   157     CleanupStack::PopAndDestroy( mailClient );
   258     CleanupStack::PopAndDestroy( mailClient );
   158     }
   259     }
   159 
   260 
   160 // -----------------------------------------------------------------------------
   261 // -----------------------------------------------------------------------------
   161 // CFeedsTopicContainer::AppendIconL
   262 // CEmailWidgetSettingsListViewContainer::AppendIconL
   162 //
   263 //
   163 // Loads and appends an icon to the icon array.
   264 // Loads and appends an icon to the icon array.
   164 // -----------------------------------------------------------------------------
   265 // -----------------------------------------------------------------------------
   165 //
   266 //
   166 
   267 
   182     CleanupStack::PushL(newIcon);
   283     CleanupStack::PushL(newIcon);
   183     aIcons->AppendL(newIcon);
   284     aIcons->AppendL(newIcon);
   184     CleanupStack::Pop(newIcon);
   285     CleanupStack::Pop(newIcon);
   185     }
   286     }
   186 
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CEmailWidgetSettingsListViewContainer::AppendExternalIconL
       
   290 //
       
   291 // Loads and appends an 3rd party icon to the icon array.
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 TInt CEmailWidgetSettingsListViewContainer::AppendExternalIconL(
       
   295         CArrayPtr<CGulIcon>* aIcons,
       
   296         const TDesC& aMifPath,
       
   297         const TInt aFileBitmapId, 
       
   298         const TInt aFileMaskId)
       
   299     {
       
   300     FUNC_LOG;
       
   301     CGulIcon*    newIcon;
       
   302     CFbsBitmap*  newIconBmp;
       
   303     CFbsBitmap*  newIconMaskBmp;
       
   304     // Trap when faulty mif path, missing graphic file, etc. 
       
   305     TRAPD( err, AknIconUtils::CreateIconL( newIconBmp, newIconMaskBmp, aMifPath,
       
   306                 aFileBitmapId,
       
   307                 aFileMaskId ) );
       
   308     if (!err)
       
   309         {
       
   310         CleanupStack::PushL(newIconBmp);
       
   311         CleanupStack::PushL(newIconMaskBmp);
       
   312         newIcon = CGulIcon::NewL(newIconBmp, newIconMaskBmp);
       
   313         CleanupStack::Pop(newIconMaskBmp);
       
   314         CleanupStack::Pop(newIconBmp);
       
   315         CleanupStack::PushL(newIcon);
       
   316         aIcons->AppendL(newIcon);
       
   317         CleanupStack::Pop(newIcon);
       
   318         }
       
   319     return err;
       
   320     }
       
   321 
   187 // ---------------------------------------------------------------------------
   322 // ---------------------------------------------------------------------------
   188 // CEmailWidgetSettingsListViewContainer::CreateCbaL
   323 // CEmailWidgetSettingsListViewContainer::CreateCbaL
   189 // ---------------------------------------------------------------------------
   324 // ---------------------------------------------------------------------------
   190 //
   325 //
   191 void CEmailWidgetSettingsListViewContainer::CreateCbaL( MEikCommandObserver* aObserver )
   326 void CEmailWidgetSettingsListViewContainer::CreateCbaL( MEikCommandObserver* aObserver )
   208     delete iPopoutCba;
   343     delete iPopoutCba;
   209     delete iListBox;
   344     delete iListBox;
   210     delete iAccountNames;
   345     delete iAccountNames;
   211     delete iDomains;
   346     delete iDomains;
   212     delete iAccountIds;
   347     delete iAccountIds;
       
   348     REComSession::FinalClose();
   213     }
   349     }
   214 
   350 
   215 // ---------------------------------------------------------------------------
   351 // ---------------------------------------------------------------------------
   216 // CEmailWidgetSettingsListViewContainer::SizeChanged
   352 // CEmailWidgetSettingsListViewContainer::SizeChanged
   217 // ---------------------------------------------------------------------------
   353 // ---------------------------------------------------------------------------
   218 //
   354 //
   219 void CEmailWidgetSettingsListViewContainer::SizeChanged()
   355 void CEmailWidgetSettingsListViewContainer::SizeChanged()
   220     {
   356     {
   221     FUNC_LOG;        
   357     FUNC_LOG;        
   222     TRect mainPaneRect;
   358     TRect mainPaneRect;
   223 		AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
   359     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
   224 		TRect listBoxRect(mainPaneRect.Size());
   360     TRect listBoxRect(mainPaneRect.Size());
   225 		iListBox->SetRect(listBoxRect);
   361     iListBox->SetRect(listBoxRect);
   226     }
   362     }
   227 
   363 
   228 // ---------------------------------------------------------------------------
   364 // ---------------------------------------------------------------------------
   229 // CEmailWidgetSettingsListViewContainer::CountComponentControls
   365 // CEmailWidgetSettingsListViewContainer::CountComponentControls
   230 // ---------------------------------------------------------------------------
   366 // ---------------------------------------------------------------------------
   289 // CEmailWidgetSettingsListViewContainer::SaveSelectedL
   425 // CEmailWidgetSettingsListViewContainer::SaveSelectedL
   290 // ---------------------------------------------------------------------------
   426 // ---------------------------------------------------------------------------
   291 //
   427 //
   292 void CEmailWidgetSettingsListViewContainer::SaveSelectedL()
   428 void CEmailWidgetSettingsListViewContainer::SaveSelectedL()
   293     {
   429     {
   294     FUNC_LOG;        
   430     FUNC_LOG;
       
   431 
   295     if (CurrentIndex() == iAccountNames->Count() - 1)
   432     if (CurrentIndex() == iAccountNames->Count() - 1)
   296         {
   433         {
   297         LaunchEmailWizardL();
   434         LaunchEmailWizardL();
   298         return;
   435         return;
   299         }
   436         }
   304         {
   441         {
   305         User::LeaveIfError(KErrNotFound);
   442         User::LeaveIfError(KErrNotFound);
   306         }  
   443         }  
   307     CRepository* cenRep = CRepository::NewL( KCRUidCmailWidget );
   444     CRepository* cenRep = CRepository::NewL( KCRUidCmailWidget );
   308 
   445 
       
   446     // Check whether selected box is native or external mailbox
       
   447     TInt index = CurrentIndex();
       
   448     TInt nativeBoxCount = iMailboxes->MailboxCount();
       
   449 
       
   450     TBool nativeBox(ETrue);
       
   451     if ( index >= nativeBoxCount )
       
   452         {
       
   453         nativeBox = EFalse;
       
   454         }
       
   455     
   309     if ( cenRep )
   456     if ( cenRep )
   310         {
   457         {
   311         TInt setId (GetSettingToAssociateL(args->Arg(1)));
   458         TInt setId ( GetSettingToAssociateL(args->Arg(1), nativeBox, cenRep) );
   312         if (setId >= 0)
   459         if (setId >= 0)
   313             {
   460             {
   314             TUint32 errorKey;
       
   315             TFSMailMsgId msgId = (*iAccountIds)[CurrentIndex()];
   461             TFSMailMsgId msgId = (*iAccountIds)[CurrentIndex()];
   316             TInt id = msgId.Id();
   462             TInt id = msgId.Id();
   317             TUid pluginId = msgId.PluginId();
   463             TUid pluginId = msgId.PluginId();
   318             TInt pId(pluginId.iUid);
   464             TInt pId(pluginId.iUid);
   319             cenRep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   465             TInt ret = cenRep->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   320             cenRep->Set( KCMailMailboxIdBase+setId, id );
   466 
   321             cenRep->Set( KCMailPluginIdBase+setId, pId );
   467             if ( nativeBox )
   322             cenRep->Set( KCMailWidgetContentIdBase+setId, args->Arg(1) );
   468                 {
       
   469                 ResetExtAccountWithSameId( args->Arg(1), cenRep );
       
   470             
       
   471                 ret = cenRep->Set( KCMailMailboxIdBase+setId, id );
       
   472                 ret = cenRep->Set( KCMailPluginIdBase+setId, pId );
       
   473                 ret = cenRep->Set( KCMailWidgetContentIdBase+setId, args->Arg(1) );
       
   474                 }
       
   475             else // external mailbox
       
   476                 {
       
   477                 ResetNatAccountWithSameId( args->Arg(1), cenRep );
       
   478             
       
   479                 ret = cenRep->Set( KCMailExtMailboxBase+setId, id );
       
   480                 ret = cenRep->Set( KCMailExtMailboxBase+KCMailExtPluginIdOffset+setId, pId );
       
   481                 ret = cenRep->Set( KCMailExtMailboxBase+KCMailExtWidgetCidOffset+setId, args->Arg(1) );          
       
   482                 }
       
   483             
       
   484             TUint32 errorKey( 0 );
   323             cenRep->CommitTransaction(errorKey);
   485             cenRep->CommitTransaction(errorKey);
       
   486             INFO_1("Errorkey == %d", errorKey);
   324             }
   487             }
   325         }
   488         }
   326     delete cenRep;
   489     delete cenRep;
   327     CleanupStack::PopAndDestroy(args);
   490     CleanupStack::PopAndDestroy(args);
   328     }
   491     }
   329 
   492 
   330 // ---------------------------------------------------------------------------
   493 // ---------------------------------------------------------------------------
       
   494 // CEmailWidgetSettingsListViewContainer::ResetExtAccountWithSameId
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CEmailWidgetSettingsListViewContainer::ResetExtAccountWithSameId( const TDesC& aContentId, CRepository* aCenRep )
       
   498     {
       
   499     FUNC_LOG;
       
   500     for ( TInt i = 0; i < KMaxExternalBoxCount; i++ )
       
   501         {
       
   502         TBuf<10> value;
       
   503         TInt ret = aCenRep->Get( KCMailExtMailboxBase+KCMailExtWidgetCidOffset+i, value );
       
   504         if ( !value.Compare( aContentId ) )
       
   505             {
       
   506             // found
       
   507             ret = aCenRep->Set(KCMailExtMailboxBase+i, 0);
       
   508             ret = aCenRep->Set(KCMailExtMailboxBase+KCMailExtPluginIdOffset+i, 0);
       
   509             ret = aCenRep->Set(KCMailExtMailboxBase+KCMailExtWidgetCidOffset+i, KDissociated);
       
   510             }
       
   511         }
       
   512     }
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // CEmailWidgetSettingsListViewContainer::ResetNatAccountWithSameId
       
   516 // ---------------------------------------------------------------------------
       
   517 void CEmailWidgetSettingsListViewContainer::ResetNatAccountWithSameId( const TDesC& aContentId, CRepository* aCenRep )
       
   518     {
       
   519     FUNC_LOG;
       
   520     for ( TInt i = 0; i < KMaxMailboxCount; i++ )
       
   521         {
       
   522         TBuf<10> value;
       
   523         TInt ret = aCenRep->Get( KCMailWidgetContentIdBase+i, value );
       
   524         if ( !value.Compare( aContentId ) )
       
   525             {
       
   526             // found
       
   527             ret = aCenRep->Set(KCMailMailboxIdBase+i, 0);
       
   528             ret = aCenRep->Set(KCMailPluginIdBase+i, 0);
       
   529             ret = aCenRep->Set(KCMailWidgetContentIdBase+i, KDissociated);
       
   530             }
       
   531         }
       
   532     }
       
   533 
       
   534 // ---------------------------------------------------------------------------
   331 // CEmailWidgetSettingsListViewContainer::GetSettingToAssociateL
   535 // CEmailWidgetSettingsListViewContainer::GetSettingToAssociateL
   332 // ---------------------------------------------------------------------------
   536 // ---------------------------------------------------------------------------
   333 //
   537 //
   334 TInt CEmailWidgetSettingsListViewContainer::GetSettingToAssociateL(const TDesC& aCid)
   538 TInt CEmailWidgetSettingsListViewContainer::GetSettingToAssociateL(const TDesC& aCid,
   335     {
   539                                                                    const TBool aNativeBox,
   336     FUNC_LOG;
   540                                                                    CRepository* aCenRep)
       
   541     {
       
   542     FUNC_LOG;
       
   543     TUint32 keyBase;
       
   544     TInt mailboxCount;
       
   545     if (aNativeBox)
       
   546         {
       
   547         keyBase = KCMailWidgetContentIdBase;
       
   548         mailboxCount = KMaxMailboxCount;
       
   549         }
       
   550     else // external mailbox
       
   551         {
       
   552         keyBase = KCMailExtMailboxBase + KCMailExtWidgetCidOffset;
       
   553         mailboxCount = KMaxExternalBoxCount;
       
   554         }
       
   555     
   337     TInt ret(KErrNotFound);
   556     TInt ret(KErrNotFound);
   338     CRepository* cenRep = CRepository::NewL( KCRUidCmailWidget );
   557 
   339     for (TInt i = 0; i < KMaxMailboxCount; i++)
   558     // Search selected widget content id from cenrep settings 
       
   559     for (TInt i = 0; i < mailboxCount; i++)
   340         {
   560         {
   341         TBuf<KMaxDescLen> value;
   561         TBuf<KMaxDescLen> value;
   342         TUint32 key(KCMailWidgetContentIdBase+i);
   562         aCenRep->Get( keyBase+i, value );
   343         cenRep->Get( key, value );
       
   344         TInt result = value.Compare(aCid);
   563         TInt result = value.Compare(aCid);
   345         if (!result)
   564         if (!result)
   346             {
   565             {
       
   566             // Content id found
   347             ret = i;
   567             ret = i;
   348             break;
   568             break;
   349             }
   569             }
   350         }
   570         }
   351     if (ret < 0 )
   571     if (ret < 0 )
   352         {
   572         {
   353         for (TInt i = 0; i < KMaxMailboxCount; i++)
   573         // Content id not found. Search first free space.
       
   574         for (TInt i = 0; i < mailboxCount; i++)
   354             {       
   575             {       
   355             TBuf<KMaxDescLen> value;
   576             TBuf<KMaxDescLen> value;
   356             TUint32 key(KCMailWidgetContentIdBase+i);
   577             aCenRep->Get( keyBase+i, value );
   357             cenRep->Get( key, value );
       
   358             TInt result = value.Compare(KDissociated);
   578             TInt result = value.Compare(KDissociated);
   359             if (!result)
   579             if (!result)
   360                 {
   580                 {
       
   581                 // Free space found
   361                 ret = i;
   582                 ret = i;
   362                 break;
   583                 break;
   363                 }
   584                 }
   364             }
   585             }
   365         }
   586         }
   366     delete cenRep;
       
   367     return ret;
   587     return ret;
   368     }
   588     }
   369 
   589 
   370 // -----------------------------------------------------------------------------
   590 // -----------------------------------------------------------------------------
   371 //  CEmailWidgetSettingsListViewContainer::LaunchEmailWizardL
   591 //  CEmailWidgetSettingsListViewContainer::LaunchEmailWizardL
   383             appui->ActivateViewL(TVwsViewId(KUidWizardApp, KUidEmailWizardView));
   603             appui->ActivateViewL(TVwsViewId(KUidWizardApp, KUidEmailWizardView));
   384             }
   604             }
   385         }
   605         }
   386     }
   606     }
   387 
   607 
       
   608 void CEmailWidgetSettingsListViewContainer::EmailObserverEvent(
       
   609     EmailInterface::MEmailData& /*aEmailData*/ )
       
   610     {
       
   611     FUNC_LOG;
       
   612     }
       
   613 
   388 // End of File
   614 // End of File