meetingrequest/mrmbutilsextension/src/cmrmbutilssettings.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2008 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: MBUtils settings implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // ----------------------------------------------------------------------------
       
    19 // INCLUDE FILES
       
    20 // ----------------------------------------------------------------------------
       
    21 //
       
    22 #include "cmrmbutilssettings.h"
       
    23 #include "mrmbutilsextensioncrkeys.h"
       
    24 #include "CFSMailBox.h"
       
    25 #include "CFSMailClient.h"
       
    26 #include "emailtrace.h"
       
    27 
       
    28 #include <e32std.h>
       
    29 #include <centralrepository.h>
       
    30 #include <ct/rcpointerarray.h>
       
    31 
       
    32 namespace {  // codescanner::namespace
       
    33 // Length for CRC buffer 
       
    34 const TInt KCRCBufferLen(32);
       
    35 }
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // MEMBER FUNCTIONS
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // CMRMBUtilsSettings::CMRUtilsSettingsMgr
       
    44 //
       
    45 // Constructor.
       
    46 // ----------------------------------------------------------------------------
       
    47 //
       
    48 CMRMBUtilsSettings::CMRMBUtilsSettings(
       
    49         CFSMailClient& aMailClient )
       
    50 :   iMailClient( aMailClient ) 
       
    51     {    
       
    52     // No implementation
       
    53     }
       
    54     
       
    55 // ----------------------------------------------------------------------------
       
    56 // CMRUtilsSettingsMgr::~CMRUtilsSettingsMgr
       
    57 //
       
    58 // Destructor.
       
    59 // ----------------------------------------------------------------------------
       
    60 //        
       
    61 CMRMBUtilsSettings::~CMRMBUtilsSettings()
       
    62     {   
       
    63     // No implementation
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CMRMBUtilsSettings::NewL
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 CMRMBUtilsSettings* CMRMBUtilsSettings::NewL(
       
    71         CFSMailClient& aMailClient )
       
    72     {
       
    73     FUNC_LOG;
       
    74     
       
    75     CMRMBUtilsSettings* self = 
       
    76             new( ELeave ) CMRMBUtilsSettings( aMailClient );
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82     
       
    83 // ----------------------------------------------------------------------------
       
    84 // CMRUtilsSettingsMgr::ConstructL
       
    85 // ----------------------------------------------------------------------------
       
    86 //    
       
    87 void CMRMBUtilsSettings::ConstructL()
       
    88     {
       
    89     FUNC_LOG;
       
    90     
       
    91     // Not yet implementation
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // CMRUtilsSettingsMgr::ConstructL
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 void CMRMBUtilsSettings::SetDefaultMailboxSettingL( 
       
    99         TInt aId )
       
   100     {
       
   101     FUNC_LOG;
       
   102     
       
   103     RCPointerArray<CFSMailBox> mailBoxes;
       
   104     CleanupClosePushL( mailBoxes );
       
   105         
       
   106     TFSMailMsgId msgId;
       
   107     iMailClient.ListMailBoxes( msgId, mailBoxes );
       
   108 
       
   109     TBool mailboxFound( EFalse );
       
   110     TInt mailboxCount( mailBoxes.Count() );
       
   111     for (TInt i(0); i < mailboxCount && !mailboxFound; ++i )
       
   112         {
       
   113         CFSMailBox* mailbox( mailBoxes[i] );
       
   114         TFSMailMsgId mailboxId( mailbox->GetId() );
       
   115         
       
   116         TBuf<KCRCBufferLen> crcBuffer;
       
   117         crcBuffer.AppendNum( mailboxId.PluginId().iUid );
       
   118         crcBuffer.AppendNum( mailboxId.Id() );
       
   119         
       
   120         TUint32 cmailMailboxCrc( 0 );
       
   121         Mem::Crc32( cmailMailboxCrc, 
       
   122                 crcBuffer.Ptr(), 
       
   123                 crcBuffer.Size() );
       
   124         
       
   125         if ( cmailMailboxCrc == aId )
       
   126             {
       
   127             SetDefaultCMailMRMailBoxL( 
       
   128                     aId,
       
   129                     mailboxId.PluginId(),
       
   130                     mailboxId.Id() );
       
   131             
       
   132             mailboxFound = ETrue;
       
   133             }
       
   134         }
       
   135     
       
   136     if ( !mailboxFound )
       
   137         {
       
   138         // CMAIL mailbox not found --> Reset the setting
       
   139         SetDefaultCMailMRMailBoxL( 
       
   140                 KMRUICMailInvalidIntValue,
       
   141                 TUid::Uid( KMRUICMailInvalidIntValue ),
       
   142                 KMRUICMailInvalidIntValue );
       
   143         }
       
   144     
       
   145     // mailBoxes
       
   146     CleanupStack::PopAndDestroy(); // codescanner::cleanup
       
   147     }
       
   148 
       
   149 // ----------------------------------------------------------------------------
       
   150 // CMRUtilsSettingsMgr::ConstructL
       
   151 // ----------------------------------------------------------------------------
       
   152 //
       
   153 void CMRMBUtilsSettings::GetDefaultMailboxSettingsL( TInt& aId )
       
   154     {
       
   155     FUNC_LOG;
       
   156     
       
   157     TUid mailboxUID;
       
   158     TInt mailboxId;
       
   159     
       
   160     GetDefaultCMailMRMailBoxL( 
       
   161             aId,
       
   162             mailboxUID,
       
   163             mailboxId );
       
   164     
       
   165     RCPointerArray<CFSMailBox> mailBoxes;
       
   166     CleanupClosePushL( mailBoxes );
       
   167         
       
   168     TFSMailMsgId msgId;
       
   169     iMailClient.ListMailBoxes( msgId, mailBoxes );
       
   170 
       
   171     TBool mailboxFound( EFalse );
       
   172     TInt mailboxCount( mailBoxes.Count() );
       
   173     for (TInt i(0); i < mailboxCount && !mailboxFound; ++i )
       
   174         {
       
   175         CFSMailBox* mailbox( mailBoxes[i] );
       
   176         TFSMailMsgId mailboxId( mailbox->GetId() );
       
   177         
       
   178         TBuf<KCRCBufferLen> crcBuffer;
       
   179         crcBuffer.AppendNum( mailboxId.PluginId().iUid );
       
   180         crcBuffer.AppendNum( mailboxId.Id() );
       
   181         
       
   182         TUint32 cmailMailboxCrc( 0 );
       
   183         Mem::Crc32( cmailMailboxCrc, 
       
   184                 crcBuffer.Ptr(), 
       
   185                 crcBuffer.Size() );
       
   186                 
       
   187         if ( cmailMailboxCrc == aId )
       
   188             {
       
   189             mailboxFound = ETrue;
       
   190             }
       
   191         }
       
   192     
       
   193     if ( !mailboxFound )
       
   194         {
       
   195         aId = KMRUICMailInvalidIntValue;
       
   196         }
       
   197     
       
   198     // mailBoxes
       
   199     CleanupStack::PopAndDestroy(); // codescanner::cleanup    
       
   200     }
       
   201 
       
   202 // ----------------------------------------------------------------------------
       
   203 // CMRUtilsSettingsMgr::GetDefaultCMailMRMailBoxL
       
   204 // ----------------------------------------------------------------------------
       
   205 //    
       
   206 TInt CMRMBUtilsSettings::GetDefaultCMailMRMailBoxL( 
       
   207         TInt& aDefaultBox,
       
   208         TUid& aMailboxPluginUID,
       
   209         TInt& aMailboxId )
       
   210     {
       
   211     FUNC_LOG;
       
   212     
       
   213     TInt retValue( KErrNotFound );
       
   214     
       
   215     TInt defaultBox( KMRUICMailInvalidIntValue );
       
   216     TInt mailboxPluginUID( KMRUICMailInvalidIntValue );
       
   217     TInt mailboxId( KMRUICMailInvalidIntValue );    
       
   218 
       
   219     aDefaultBox = defaultBox;
       
   220     aMailboxPluginUID = TUid::Uid( mailboxPluginUID );
       
   221     aMailboxId = mailboxId;
       
   222     
       
   223     // Create central repository
       
   224     CRepository* cenRep = 
       
   225             CRepository::NewLC( KCRUidMRDefaultCMailMRMailbox );
       
   226     
       
   227     // Get default meeting request mailbox id from CentRep
       
   228     TInt err = cenRep->Get( KMRUIS60DefMailbox, defaultBox ); 
       
   229     if ( KErrNone == err  )
       
   230         {
       
   231         err = cenRep->Get( KMRUICMailMailboxUID, mailboxPluginUID );         
       
   232         if ( KErrNone == err )
       
   233             {
       
   234             err = cenRep->Get( KMRUICMailMailboxID, mailboxId );
       
   235             }
       
   236         }
       
   237     
       
   238     // If some other error than KErrNotFound Leave
       
   239     if ( err != KErrNotFound )
       
   240         {
       
   241         // KErrNone won't leave
       
   242         User::LeaveIfError( err ); 
       
   243         }
       
   244     
       
   245     CleanupStack::PopAndDestroy( cenRep );
       
   246     
       
   247     if ( KErrNone == err )
       
   248         {
       
   249         aDefaultBox = defaultBox;
       
   250         aMailboxPluginUID = TUid::Uid( mailboxPluginUID );
       
   251         aMailboxId = mailboxId;        
       
   252         }
       
   253         
       
   254     return retValue;    
       
   255     }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CMRUtilsSettingsMgr::SetDefaultCMailMRMailBoxL
       
   259 // ----------------------------------------------------------------------------
       
   260 //                
       
   261 TInt CMRMBUtilsSettings::SetDefaultCMailMRMailBoxL( 
       
   262         TInt aDefaultBox,
       
   263         TUid aMailboxPluginUID,
       
   264         TInt aMailboxId )
       
   265     {
       
   266     FUNC_LOG;
       
   267     
       
   268     // Create central repository
       
   269     CRepository* cenRep = 
       
   270             CRepository::NewLC( KCRUidMRDefaultCMailMRMailbox );  
       
   271     
       
   272     TInt err = cenRep->Set( KMRUIS60DefMailbox, aDefaultBox ); 
       
   273     
       
   274     if ( err == KErrNone )
       
   275         {
       
   276         TInt uid( static_cast<TInt>(aMailboxPluginUID.iUid ) );
       
   277         err = cenRep->Set( KMRUICMailMailboxUID, uid ); 
       
   278         if ( err == KErrNone )
       
   279             {
       
   280             err = cenRep->Set( KMRUICMailMailboxID, aMailboxId ); 
       
   281             }
       
   282         }    
       
   283     
       
   284     CleanupStack::PopAndDestroy( cenRep ); 
       
   285     
       
   286     User::LeaveIfError( err );
       
   287     
       
   288     return err;   
       
   289     }
       
   290 
       
   291 // End of file