emailservices/emailserver/cmailhandlerplugin/src/cmailcpssettings.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 2 5253a20d2a1e
child 10 f5907b1a1053
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
     1 /*
     1 /*
     2 * Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2008 - 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 
    18 
    19 #include "emailtrace.h"
    19 #include "emailtrace.h"
    20 #include <e32base.h>
    20 #include <e32base.h>
    21 // CRepository
    21 // CRepository
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
       
    23 
    23 // Email Framework APIs
    24 // Email Framework APIs
    24 //<cmail>
    25 //<cmail>
    25 #include "CFSMailCommon.h"
    26 #include "cfsmailcommon.h"
    26 #include "CFSMailClient.h"
    27 #include "cfsmailclient.h"
    27 #include "CFSMailBox.h"
    28 #include "cfsmailbox.h"
    28 #include "CFSMailFolder.h"
    29 #include "cfsmailfolder.h"
    29 //</cmail>
    30 //</cmail>
    30 
    31 
    31 #include "cmailcpssettings.h"
    32 #include "cmailcpssettings.h"
    32 #include "cmailwidgetcenrepkeysinternal.h"
    33 #include "cmailwidgetcenrepkeysinternal.h"
    33 #include "cmailcpsifconsts.h"
    34 #include "cmailcpsifconsts.h"
       
    35 #include "cmailexternalaccount.h"
    34 
    36 
    35 // ======== MEMBER FUNCTIONS ========
    37 // ======== MEMBER FUNCTIONS ========
    36 
    38 
    37 // ---------------------------------------------------------------------------
    39 // ---------------------------------------------------------------------------
    38 // CMailCpsSettings::NewL
    40 // CMailCpsSettings::NewL
    94 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
    95 //
    97 //
    96 void CMailCpsSettings::RunL()
    98 void CMailCpsSettings::RunL()
    97     {
    99     {
    98     FUNC_LOG;
   100     FUNC_LOG;
       
   101     StartObservingL();
    99     LoadSettingsL(); // mailboxes etc. user changeable data
   102     LoadSettingsL(); // mailboxes etc. user changeable data
   100     LoadConfigurationL(); // internal configuration data
   103     LoadConfigurationL(); // internal configuration data
   101     iObserver->SettingsChangedCallback();
   104     iObserver->SettingsChangedCallback();
   102     StartObservingL();
       
   103     }
   105     }
   104 
   106 
   105 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
   106 // CMailCpsSettings::DoCancel
   108 // CMailCpsSettings::DoCancel
   107 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   190         User::Leave( ret );
   192         User::Leave( ret );
   191         }
   193         }
   192     }
   194     }
   193 
   195 
   194 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
       
   197 // CMailCpsSettings::GetMailboxNonZeroKeysL
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CMailCpsSettings::GetExtMailboxNonZeroKeysL( RArray<TUint32>& aKeys )
       
   201     {
       
   202     FUNC_LOG;
       
   203     TInt ret = iCenRep->FindNeqL( KCmailExtMailboxKeyRange, KCmailExtMailboxRangeMask, 0, aKeys );
       
   204     if ( ret != KErrNone && ret != KErrNotFound )
       
   205         {
       
   206         User::Leave( ret );
       
   207         }
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
   195 // CMailCpsSettings::ResolveMailbox
   211 // CMailCpsSettings::ResolveMailbox
   196 // ---------------------------------------------------------------------------
   212 // ---------------------------------------------------------------------------
   197 //
   213 //
   198 TInt CMailCpsSettings::ResolveMailbox( const TInt aMailboxId, TFSMailMsgId& aMsg )
   214 TInt CMailCpsSettings::ResolveMailbox( const TInt aMailboxId, TFSMailMsgId& aMsg )
   199     {
   215     {
   264 // CMailCpsSettings::Mailboxes
   280 // CMailCpsSettings::Mailboxes
   265 // ---------------------------------------------------------------------------
   281 // ---------------------------------------------------------------------------
   266 //
   282 //
   267 RArray<TFSMailMsgId>& CMailCpsSettings::Mailboxes()
   283 RArray<TFSMailMsgId>& CMailCpsSettings::Mailboxes()
   268     {
   284     {
       
   285     FUNC_LOG;
   269     return iMailboxArray;
   286     return iMailboxArray;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CMailCpsSettings::ExternalMailboxes
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CMailCpsSettings::GetExtMailboxesL( RPointerArray<CMailExternalAccount>& aAccounts )
       
   294     {
       
   295     FUNC_LOG;
       
   296     RArray<TUint32> keys;
       
   297     CleanupClosePushL( keys );
       
   298     GetExtMailboxNonZeroKeysL( keys );
       
   299 
       
   300     for ( TInt i = 0; i < keys.Count(); i++ )
       
   301         {
       
   302         CMailExternalAccount* account = GetExtMailboxL( keys[i] );
       
   303         CleanupStack::PushL( account );
       
   304         aAccounts.AppendL( account );
       
   305         CleanupStack::Pop( account );
       
   306         }
       
   307 
       
   308     CleanupStack::PopAndDestroy(); // keys
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CMailCpsSettings::GetExtMailboxL
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 CMailExternalAccount* CMailCpsSettings::GetExtMailboxL( TInt aKey )
       
   316     {
       
   317     FUNC_LOG;
       
   318     TInt mailboxId( 0 );
       
   319     TInt pluginId( 0 );
       
   320     HBufC* contentIdBuf = HBufC::NewL( KMaxDescLen );
       
   321     TPtr contentId = contentIdBuf->Des();
       
   322 
       
   323     User::LeaveIfError( iCenRep->Get( aKey, mailboxId ) );
       
   324     User::LeaveIfError( iCenRep->Get( aKey + KCMailExtPluginIdOffset, pluginId ) );
       
   325     User::LeaveIfError( iCenRep->Get( aKey + KCMailExtWidgetCidOffset, contentId ) );
       
   326 
       
   327     return CMailExternalAccount::NewL(
       
   328         mailboxId, pluginId, contentIdBuf );
   270     }
   329     }
   271 
   330 
   272 // ---------------------------------------------------------------------------
   331 // ---------------------------------------------------------------------------
   273 // CMailCpsSettings::AddMailboxL
   332 // CMailCpsSettings::AddMailboxL
   274 // ---------------------------------------------------------------------------
   333 // ---------------------------------------------------------------------------
   577     FUNC_LOG;
   636     FUNC_LOG;
   578     return iConfigData;
   637     return iConfigData;
   579     }
   638     }
   580 
   639 
   581 // ---------------------------------------------------------------------------
   640 // ---------------------------------------------------------------------------
   582 // CMailCpsSettings::GetTotalMailboxCount
   641 // CMailCpsSettings::TotalIntMailboxCount
   583 // ---------------------------------------------------------------------------
   642 // ---------------------------------------------------------------------------
   584 //
   643 //
   585 TInt CMailCpsSettings::GetTotalMailboxCount()
   644 TInt CMailCpsSettings::TotalIntMailboxCount()
   586     {
   645     {
   587     FUNC_LOG;
   646     FUNC_LOG;
   588     RPointerArray<CFSMailBox> mailboxarray;
   647     RPointerArray<CFSMailBox> mailboxarray;
   589     iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxarray );    
   648     iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxarray );    
   590     TInt ret = mailboxarray.Count(); 
   649     TInt ret = mailboxarray.Count(); 
   659         {
   718         {
   660         value.Delete(result, cid.Length());
   719         value.Delete(result, cid.Length());
   661         iCenRep->Set( key, value );        
   720         iCenRep->Set( key, value );        
   662         }
   721         }
   663     }
   722     }
       
   723 
       
   724 // -----------------------------------------------------------------------------
       
   725 // CMailCpsSettings::ToggleWidgetNewMailIconL
       
   726 // -----------------------------------------------------------------------------
       
   727 void CMailCpsSettings::ToggleWidgetNewMailIconL( TBool aIconOn, const TFSMailMsgId& aMailBox )
       
   728     {
       
   729     FUNC_LOG;
       
   730     TBuf<KMaxDescLen> mailbox;
       
   731     mailbox.Num(aMailBox.Id());
       
   732 
       
   733     TBuf<KMaxDescLen> str;
       
   734     str.Copy(KStartSeparator);    
       
   735     str.Append(mailbox);
       
   736     str.Append(KEndSeparator);    
       
   737 
       
   738     TBuf<KMaxDescLen> stored;
       
   739     TUint32 key(KCMailMailboxesWithNewMail);
       
   740     iCenRep->Get( key, stored );
       
   741     
       
   742     TInt result = stored.Find(str);
       
   743     
       
   744     if (aIconOn)
       
   745         {
       
   746         if (result < 0) // Not found
       
   747             {
       
   748             stored.Append(str);
       
   749             iCenRep->Set( key, stored );
       
   750             }
       
   751         }
       
   752     else
       
   753         {
       
   754         if (result >= 0)
       
   755             {
       
   756             stored.Delete(result, str.Length());
       
   757             iCenRep->Set( key, stored );
       
   758             }
       
   759         }
       
   760     }
       
   761 
       
   762 // -----------------------------------------------------------------------------
       
   763 // CMailCpsSettings::GetNewMailState
       
   764 // -----------------------------------------------------------------------------
       
   765 TBool CMailCpsSettings::GetNewMailState( const TFSMailMsgId& aMailBox )
       
   766     {
       
   767     FUNC_LOG;
       
   768     TBool ret(EFalse);
       
   769     TBuf<KMaxDescLen> mailbox;
       
   770     mailbox.Num(aMailBox.Id());
       
   771 
       
   772     TBuf<KMaxDescLen> str;
       
   773     str.Copy(KStartSeparator);    
       
   774     str.Append(mailbox);
       
   775     str.Append(KEndSeparator);    
       
   776 
       
   777     TBuf<KMaxDescLen> stored;
       
   778     TUint32 key(KCMailMailboxesWithNewMail);
       
   779     iCenRep->Get( key, stored );
       
   780     
       
   781     TInt result = stored.Find(str);
       
   782     if (result >= 0)
       
   783         {
       
   784         ret = ETrue;
       
   785         }
       
   786     return ret;
       
   787     }