email/imum/Utils/Src/IMASCenRepControl.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  IMASCenRepControl.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <centralrepository.h>          // CRepository
       
    22 #include "MuiuDynamicHeader.h"
       
    23 
       
    24 #include "IMASCenRepControl.h"
       
    25 #include "ImumPanic.h"
       
    26 #include "ImumUtilsLogging.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 // CONSTANTS
       
    31 enum TICRCErrors
       
    32     {
       
    33     EICRCNoError = 0,
       
    34     EICRCNoCenRepSession
       
    35     };
       
    36 
       
    37 // MACROS
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 // MODULE DATA STRUCTURES
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CIMASCenRepControl::CIMASCenRepControl()
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 CIMASCenRepControl::CIMASCenRepControl()
       
    50     {
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CIMASCenRepControl::~CIMASCenRepControl()
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CIMASCenRepControl::~CIMASCenRepControl()
       
    58     {
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CIMASCenRepControl::ConstructL()
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 void CIMASCenRepControl::ConstructL()
       
    66     {
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CIMASCenRepControl::NewL()
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 CIMASCenRepControl* CIMASCenRepControl::NewL()
       
    74     {
       
    75     IMUM_STATIC_CONTEXT( CIMASCenRepControl::NewL, 0, utils, KLogData );
       
    76 
       
    77     CIMASCenRepControl* self = NewLC();
       
    78     CleanupStack::Pop( self );
       
    79 
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CIMASCenRepControl::NewLC()
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 CIMASCenRepControl* CIMASCenRepControl::NewLC()
       
    88     {
       
    89     IMUM_STATIC_CONTEXT( CIMASCenRepControl::NewLC, 0, utils, KLogData );
       
    90 
       
    91     CIMASCenRepControl* self = new ( ELeave ) CIMASCenRepControl();
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94 
       
    95     return self;
       
    96     }
       
    97 
       
    98 /******************************************************************************
       
    99 
       
   100     Storer Tools
       
   101 
       
   102 ******************************************************************************/
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CIMASCenRepControl::SetActiveCentralRepository()
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void CIMASCenRepControl::SetActiveCentralRepository(
       
   109     CRepository& aRepository )
       
   110     {
       
   111     iCenRep = &aRepository;
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CIMASCenRepControl::SetActiveBaseKey()
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 void CIMASCenRepControl::SetActiveBaseKey(
       
   119     const TUint32 aAccountId,
       
   120     const TUid& aProtocol )
       
   121     {
       
   122     iBaseKey = IMASAccountControl::CreateBaseKeyFromAccountId(
       
   123         aAccountId, aProtocol );
       
   124     }
       
   125 
       
   126 // ----------------------------------------------------------------------------
       
   127 // CIMASCenRepControl::SetActiveBaseKey()
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 void CIMASCenRepControl::SetActiveBaseKey(
       
   131     const TUint32 aExtendedAccountId )
       
   132     {
       
   133     iBaseKey = IMASAccountControl::CreateBaseKeyFromExtendedAccountId(
       
   134         aExtendedAccountId );
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // CIMASCenRepControl::CreateToAccountL()
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 void CIMASCenRepControl::CreateToAccountL(
       
   142     const TUint32 aSetting,
       
   143     const TInt aValue )
       
   144     {
       
   145     __ASSERT_DEBUG( iCenRep != NULL,
       
   146         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   147 
       
   148     // Determine the setting id and create the new key
       
   149     TUint32 settingId = iBaseKey + aSetting;
       
   150     TInt err = iCenRep->Create( settingId, aValue );
       
   151     // if the setting already exists, this means that there are some lingering
       
   152     // extended settings from a mailbox which was e.g. deleted using
       
   153     // CEmailAccounts. We can just overwrite the setting
       
   154     if( err == KErrAlreadyExists )
       
   155     	{
       
   156     	SetToAccountL( aSetting, aValue );
       
   157     	}
       
   158     else
       
   159     	{
       
   160     	User::LeaveIfError( err );
       
   161     	}
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // CIMASCenRepControl::CreateToAccountL()
       
   166 // ----------------------------------------------------------------------------
       
   167 //
       
   168 void CIMASCenRepControl::CreateToAccountL(
       
   169     const TUint32 aSetting,
       
   170     const TDesC& aString )
       
   171     {
       
   172     __ASSERT_DEBUG( iCenRep != NULL,
       
   173         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   174 
       
   175     // Determine the setting id and create the new key
       
   176     TUint32 settingId = iBaseKey + aSetting;
       
   177     TInt err = iCenRep->Create( settingId, aString );
       
   178     // if the setting already exists, this means that there are some lingering
       
   179     // extended settings from a mailbox which was e.g. deleted using
       
   180     // CEmailAccounts. We can just overwrite the setting
       
   181     if( err == KErrAlreadyExists )
       
   182     	{
       
   183     	SetToAccountL( aSetting, aString );
       
   184     	}
       
   185     else
       
   186     	{
       
   187     	User::LeaveIfError( err );
       
   188     	}
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CIMASCenRepControl::CreateToAccountL()
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 void CIMASCenRepControl::CreateToAccountL(
       
   196     const TInt aSettingHigh,
       
   197     const TInt aSettingLow,
       
   198     const TInt64 aValue )
       
   199     {
       
   200     // The high and low part has to be stored separately
       
   201     CreateToAccountL( aSettingHigh, I64HIGH( aValue ) );
       
   202     CreateToAccountL( aSettingLow, I64LOW( aValue ) );
       
   203     }
       
   204 
       
   205 // ----------------------------------------------------------------------------
       
   206 // CIMASCenRepControl::DeleteFromAccountL()
       
   207 // ----------------------------------------------------------------------------
       
   208 //
       
   209 void CIMASCenRepControl::DeleteFromAccountL(
       
   210     const TInt aSetting ) const
       
   211     {
       
   212     __ASSERT_DEBUG( iCenRep != NULL,
       
   213         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   214 
       
   215     // Load the values
       
   216     TUint32 settingId = iBaseKey + aSetting;
       
   217     User::LeaveIfError( iCenRep->Delete( settingId ) );
       
   218     }
       
   219 
       
   220 // ----------------------------------------------------------------------------
       
   221 // CIMASCenRepControl::DeleteFromAccountL()
       
   222 // ----------------------------------------------------------------------------
       
   223 //
       
   224 void CIMASCenRepControl::DeleteFromAccountL(
       
   225     const TInt aSettingHigh,
       
   226     const TInt aSettingLow ) const
       
   227     {
       
   228     // Load the values
       
   229     TUint32 settingId = iBaseKey + aSettingHigh;
       
   230     User::LeaveIfError( iCenRep->Delete( settingId ) );
       
   231 
       
   232     settingId = iBaseKey + aSettingLow;
       
   233     User::LeaveIfError( iCenRep->Delete( settingId ) );
       
   234     }
       
   235 
       
   236 // ----------------------------------------------------------------------------
       
   237 // CIMASCenRepControl::SetToAccountL()
       
   238 // ----------------------------------------------------------------------------
       
   239 //
       
   240 void CIMASCenRepControl::SetToAccountL(
       
   241     const TUint32 aSetting,
       
   242     const TInt aValue )
       
   243     {
       
   244     __ASSERT_DEBUG( iCenRep != NULL,
       
   245         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   246 
       
   247     // Determine the setting id and create the new key
       
   248     TUint32 settingId = iBaseKey + aSetting;
       
   249     User::LeaveIfError( iCenRep->Set( settingId, aValue ) );
       
   250     }
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // CIMASCenRepControl::SetToAccountL()
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 void CIMASCenRepControl::SetToAccountL(
       
   257     const TUint32 aSetting,
       
   258     const TDesC& aString )
       
   259     {
       
   260     __ASSERT_DEBUG( iCenRep != NULL,
       
   261         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   262 
       
   263     // Determine the setting id and create the new key
       
   264     TUint32 settingId = iBaseKey + aSetting;
       
   265     User::LeaveIfError( iCenRep->Set( settingId, aString ) );
       
   266     }
       
   267 
       
   268 // ----------------------------------------------------------------------------
       
   269 // CIMASCenRepControl::SetToAccountL()
       
   270 // ----------------------------------------------------------------------------
       
   271 //
       
   272 void CIMASCenRepControl::SetToAccountL(
       
   273     const TInt aSettingHigh,
       
   274     const TInt aSettingLow,
       
   275     const TInt64 aSetting )
       
   276     {
       
   277     // The high and low part has to be stored separately
       
   278     SetToAccountL( aSettingHigh, I64HIGH( aSetting ) );
       
   279     SetToAccountL( aSettingLow, I64LOW( aSetting ) );
       
   280     }
       
   281 
       
   282 // ----------------------------------------------------------------------------
       
   283 // CIMASCenRepControl::GetFromAccountL()
       
   284 // ----------------------------------------------------------------------------
       
   285 //
       
   286 TInt64 CIMASCenRepControl::GetFromAccountL(
       
   287     const TInt aSettingHigh,
       
   288     const TInt aSettingLow ) const
       
   289     {
       
   290     TInt64 value = KErrNone;
       
   291     User::LeaveIfError( GetFromAccount( aSettingHigh, aSettingLow, value ) );
       
   292 
       
   293     return value;
       
   294     }
       
   295 
       
   296 // ----------------------------------------------------------------------------
       
   297 // CIMASCenRepControl::GetFromAccountL()
       
   298 // ----------------------------------------------------------------------------
       
   299 //
       
   300 TInt CIMASCenRepControl::GetFromAccountL(
       
   301     const TInt aSetting ) const
       
   302     {
       
   303     TInt value = KErrNotFound;
       
   304     User::LeaveIfError( GetFromAccount( aSetting, value ) );
       
   305 
       
   306     return value;
       
   307     }
       
   308 
       
   309 // ----------------------------------------------------------------------------
       
   310 // CIMASCenRepControl::GetTextFromAccountL()
       
   311 // ----------------------------------------------------------------------------
       
   312 //
       
   313 void CIMASCenRepControl::GetTextFromAccountL(
       
   314     TDes& aText,
       
   315     const TInt aSetting ) const
       
   316     {
       
   317     User::LeaveIfError( GetTextFromAccount( aText,  aSetting ) );
       
   318     }
       
   319 
       
   320 // ----------------------------------------------------------------------------
       
   321 // CIMASCenRepControl::SetActiveDefaultDataKey()
       
   322 // ----------------------------------------------------------------------------
       
   323 //
       
   324 void CIMASCenRepControl::SetActiveDefaultDataKey()
       
   325     {
       
   326     iBaseKey = 0;
       
   327     }
       
   328 
       
   329 // ----------------------------------------------------------------------------
       
   330 // CIMASCenRepControl::GetFromAccount()
       
   331 // ----------------------------------------------------------------------------
       
   332 //
       
   333 TInt CIMASCenRepControl::GetFromAccount( const TInt aSettingHigh,
       
   334     const TInt aSettingLow,
       
   335     TInt64& aSettingValue ) const
       
   336     {
       
   337     __ASSERT_DEBUG( iCenRep != NULL,
       
   338         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   339 
       
   340     // Prepare the number
       
   341     TInt high = 0;
       
   342     TInt low = 0;
       
   343     TInt error = KErrNotFound;
       
   344 
       
   345     // Load the values
       
   346     TUint32 settingId = iBaseKey + aSettingHigh;
       
   347     error = iCenRep->Get( settingId, high );
       
   348 
       
   349     settingId = iBaseKey + aSettingLow;
       
   350 
       
   351     if ( error == KErrNone )
       
   352         {
       
   353         error = iCenRep->Get( settingId, low );
       
   354         }
       
   355     // Return the combined value
       
   356     if ( error == KErrNone )
       
   357         {
       
   358         aSettingValue = MAKE_TINT64( high, low );
       
   359         }
       
   360 
       
   361     return error;
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------------------------------
       
   365 // CIMASCenRepControl::GetFromAccount()
       
   366 // ----------------------------------------------------------------------------
       
   367 //
       
   368 TInt CIMASCenRepControl::GetFromAccount(
       
   369     const TInt aSetting, TInt& aSettingValue ) const
       
   370     {
       
   371     __ASSERT_DEBUG( iCenRep != NULL,
       
   372         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   373 
       
   374     // Load the values
       
   375     TUint32 settingId = iBaseKey + aSetting;
       
   376     return iCenRep->Get( settingId, aSettingValue );
       
   377     }
       
   378 
       
   379 // ----------------------------------------------------------------------------
       
   380 // CIMASCenRepControl::GetTextFromAccount()
       
   381 // ----------------------------------------------------------------------------
       
   382 //
       
   383 TInt CIMASCenRepControl::GetTextFromAccount(
       
   384     TDes& aText,
       
   385     const TInt aSetting ) const
       
   386     {
       
   387     __ASSERT_DEBUG( iCenRep != NULL,
       
   388         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   389 
       
   390     // Load the values
       
   391     TUint32 settingId = iBaseKey + aSetting;
       
   392     return iCenRep->Get( settingId, aText );
       
   393     }
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CIMASCenRepControl::GetTextFromAccount()
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 TInt CIMASCenRepControl::GetTextFromAccount(
       
   400     TDes8& aText,
       
   401     const TInt aSetting ) const
       
   402     {
       
   403     __ASSERT_DEBUG( iCenRep != NULL,
       
   404         User::Panic( KIMASCenRepCtrlPanic, EICRCNoCenRepSession ) );
       
   405 
       
   406     // Load the values
       
   407     TUint32 settingId = iBaseKey + aSetting;
       
   408     return iCenRep->Get( settingId, aText );
       
   409     }
       
   410 
       
   411 // ----------------------------------------------------------------------------
       
   412 // CIMASCenRepControl::GetFromAccountOrCreateL()
       
   413 // ----------------------------------------------------------------------------
       
   414 //
       
   415 TInt CIMASCenRepControl::GetFromAccountOrCreateL(
       
   416     const TUint32 aSetting, TInt aDefaultValue )
       
   417     {
       
   418     TInt value = aDefaultValue;
       
   419     TInt error = GetFromAccount( aSetting, value );
       
   420     
       
   421     if( error == KErrNotFound )
       
   422         {
       
   423         CreateToAccountL( aSetting, aDefaultValue );
       
   424         }
       
   425     else
       
   426         {
       
   427         User::LeaveIfError( error );
       
   428         }
       
   429 
       
   430     return value;
       
   431     }
       
   432 
       
   433 // ----------------------------------------------------------------------------
       
   434 // CIMASCenRepControl::GetFromAccountOrCreateL()
       
   435 // ----------------------------------------------------------------------------
       
   436 //
       
   437 TInt64 CIMASCenRepControl::GetFromAccountOrCreateL(
       
   438     const TUint32 aSettingHigh,
       
   439     const TUint32 aSettingLow,
       
   440     TInt64 aDefaultValue )
       
   441     {
       
   442     TInt64 value = aDefaultValue;
       
   443     TInt error = GetFromAccount( aSettingHigh, aSettingLow, value );
       
   444     
       
   445     if( error == KErrNotFound )
       
   446         {
       
   447         CreateToAccountL( aSettingHigh, aSettingLow, aDefaultValue );
       
   448         }
       
   449     else
       
   450         {
       
   451         User::LeaveIfError( error );
       
   452         }
       
   453 
       
   454     return value;
       
   455     }
       
   456 	
       
   457 // End of File