mobilemessaging/postcard/postcardsrc/PostcardCenRep.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:  
       
    15 *           Postcard application's interface central repository
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // Include files
       
    22 
       
    23 #include <centralrepository.h>
       
    24 #include <messaginginternalcrkeys.h>
       
    25 
       
    26 #include "PostcardCenRep.h"
       
    27 #include "PostcardPanic.h"
       
    28 
       
    29 // Static constant data
       
    30 
       
    31 // True if corresponding key refers to string data
       
    32 const TInt8 CPostcardCenRep::iIsStringType[KPocaKeyCount] = 
       
    33     {
       
    34     ETrue,  // KPocaKeyServiceProvider
       
    35     EFalse, // KPocaKeyMandatoryFields
       
    36     EFalse, // KPocaKeyMaxGreetingLength
       
    37     EFalse, // KPocaKeyMaxNameLength
       
    38     EFalse, // KPocaKeyMaxInfoLength
       
    39     EFalse, // KPocaKeyMaxStreetLength
       
    40     EFalse, // KPocaKeyMaxZipLength
       
    41     EFalse, // KPocaKeyMaxCityLength
       
    42     EFalse, // KPocaKeyMaxStateLength
       
    43     EFalse, // KPocaKeyMaxCountryLength
       
    44     ETrue,  // KPocaKeyServiceSpecialFormat
       
    45     ETrue,  // KPocaKeyServiceSeparator
       
    46     ETrue   // KPocaKeyServiceReplaceString
       
    47     };
       
    48 
       
    49 // Member functions
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 //  Two-phased constructor
       
    53 // ---------------------------------------------------------
       
    54 CPostcardCenRep* CPostcardCenRep::NewL()
       
    55     {
       
    56     CPostcardCenRep* self = new (ELeave) CPostcardCenRep();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 //  Default destructor
       
    65 // ---------------------------------------------------------
       
    66 CPostcardCenRep::~CPostcardCenRep()
       
    67     {
       
    68     for(TInt i = 0; i < KPocaKeyCount; i++)
       
    69         {
       
    70         if (iIsStringType[i])
       
    71             {
       
    72             delete iData[i].asString;
       
    73             }
       
    74         }
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CPostcardCenRep
       
    79 // ---------------------------------------------------------
       
    80 CPostcardCenRep::CPostcardCenRep()
       
    81     {
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // ConstructL
       
    86 // ---------------------------------------------------------
       
    87 void CPostcardCenRep::ConstructL()
       
    88     {
       
    89     // Read data from Postcard repository
       
    90     CRepository* cenrep = CRepository::NewLC(KCRUidPostcard);
       
    91 
       
    92     for(TInt i = 0; i < KPocaKeyCount; i++)
       
    93         {
       
    94         TUint32 key = KPocaKeyServiceProvider + i;
       
    95         if (iIsStringType[i])
       
    96             {
       
    97             HBufC* buf = iData[i].asString = HBufC::NewL(KCRPocaMaxString);
       
    98             TPtr des = buf->Des();
       
    99             User::LeaveIfError(cenrep->Get(key, des));
       
   100             iData[i].asString = buf->ReAllocL(buf->Length());
       
   101             }
       
   102         else
       
   103             {
       
   104             User::LeaveIfError(cenrep->Get(key, iData[i].asInt));
       
   105             }
       
   106         }
       
   107     CleanupStack::PopAndDestroy( cenrep); // cenrep
       
   108 
       
   109     // Read data from Muiu variation repository
       
   110     cenrep = CRepository::NewLC(KCRUidMuiuVariation);
       
   111     User::LeaveIfError(cenrep->Get(KMuiuPostcardFeatures, iFeatureBits));
       
   112     CleanupStack::PopAndDestroy( cenrep ); // cenrep
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // Get
       
   118 // ---------------------------------------------------------
       
   119 TInt CPostcardCenRep::Get(TUint32 aKey) const
       
   120     {
       
   121     TInt i = aKey - KPocaKeyServiceProvider;
       
   122     __ASSERT_DEBUG(i >= 0 && i < KPocaKeyCount, Panic(EPostcardPanicCoding));
       
   123     __ASSERT_DEBUG(!iIsStringType[i], Panic(EPostcardPanicCoding));
       
   124     return iData[i].asInt;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // GetString
       
   129 // ---------------------------------------------------------
       
   130 const TDesC& CPostcardCenRep::GetString(TUint32 aKey) const
       
   131     {
       
   132     TInt i = aKey - KPocaKeyServiceProvider;
       
   133     __ASSERT_DEBUG(i >= 0 && i < KPocaKeyCount, Panic(EPostcardPanicCoding));
       
   134     __ASSERT_DEBUG(iIsStringType[i], Panic(EPostcardPanicCoding));
       
   135     return *iData[i].asString;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // FeatureBits
       
   140 // ---------------------------------------------------------
       
   141 TInt CPostcardCenRep::FeatureBits() const
       
   142     {
       
   143     return iFeatureBits;
       
   144     }