meetingrequest/mragnversit2/src/cesmragnversit2stringprovider.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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: This file implements class CESMRAgnVersit2StringProvider.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Class include.
       
    20 #include "emailtrace.h"
       
    21 #include "cesmragnversit2stringprovider.h"
       
    22 #include "esmrhelper.h"
       
    23 
       
    24 //debug
       
    25 //<cmail>
       
    26 //</cmail>
       
    27 
       
    28 // System includes.
       
    29 #include <barsc.h>              // RResourceFile
       
    30 #include <bautils.h>            // BaflUtils
       
    31 #include <data_caging_path_literals.hrh>
       
    32 
       
    33 // Resource include.
       
    34 #include <esmragnversit2strings.rsg>
       
    35 
       
    36 // Constants
       
    37 namespace{//local namespace for constants
       
    38 
       
    39 // CESMRAgnVersit2StringProvider resource name
       
    40 _LIT( KESMRAgnVersit2ResourceFilename, "esmragnversit2strings.rsc");
       
    41 
       
    42 }//namespace
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CESMRAgnVersit2StringProvider::NewL
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CESMRAgnVersit2StringProvider* CESMRAgnVersit2StringProvider::NewL()
       
    51     {
       
    52     FUNC_LOG;
       
    53 
       
    54     CESMRAgnVersit2StringProvider* self = new (ELeave) CESMRAgnVersit2StringProvider;
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop(self);
       
    58 
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CESMRAgnVersit2StringProvider::~CESMRAgnVersit2StringProvider
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CESMRAgnVersit2StringProvider::~CESMRAgnVersit2StringProvider()
       
    67     {
       
    68     FUNC_LOG;
       
    69 
       
    70     iStringArray.ResetAndDestroy();
       
    71     iResourceFile.Close();
       
    72     iFs.Close();
       
    73 
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CESMRAgnVersit2StringProvider::StringL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 const TDesC& CESMRAgnVersit2StringProvider::StringL(TStringId aStringId)
       
    81     {
       
    82     FUNC_LOG;
       
    83 
       
    84     ASSERT(iStringArray.Count() >= aStringId + 1);
       
    85     if ( !iStringArray[aStringId] )
       
    86         {
       
    87         ReadStringFromResourceL(aStringId);
       
    88         }
       
    89 
       
    90     return *iStringArray[aStringId];
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CESMRAgnVersit2StringProvider::CESMRAgnVersit2StringProvider
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CESMRAgnVersit2StringProvider::CESMRAgnVersit2StringProvider()
       
    98     {
       
    99     FUNC_LOG;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CESMRAgnVersit2StringProvider::ConstructL
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CESMRAgnVersit2StringProvider::ConstructL()
       
   107     {
       
   108     FUNC_LOG;
       
   109 
       
   110     //Fill iStringArray with NULL pointers...
       
   111     for (TInt x = 0; x < EICalNumberOfStrings; ++x)
       
   112         {
       
   113         User::LeaveIfError(iStringArray.Append(NULL));
       
   114         }
       
   115     User::LeaveIfError(iFs.Connect());
       
   116 
       
   117     TFileName resource;
       
   118 
       
   119 
       
   120     User::LeaveIfError(
       
   121             ESMRHelper::LocateResourceFile(
       
   122                     KESMRAgnVersit2ResourceFilename,
       
   123                     KDC_RESOURCE_FILES_DIR,
       
   124                     resource,
       
   125                     &iFs ) );
       
   126 
       
   127     // Find a localised resource file if available -- if not, it will be left as .rsc
       
   128     BaflUtils::NearestLanguageFile(iFs, resource);
       
   129     // Now we've got the full resource file name, so open it
       
   130     iResourceFile.OpenL(iFs, resource);
       
   131     iResourceFile.ConfirmSignatureL(0);
       
   132 
       
   133     // Read all strings immediately in debug mode.
       
   134     __DEBUG_ONLY(ReadAllStringsL());
       
   135 
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CESMRAgnVersit2StringProvider::ReadStringFromResourceL
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 /**
       
   143  * Reads a string from the resource file and adds it to the array of strings.
       
   144  * @param aStringId string to add
       
   145  * @internalTechnology
       
   146  * */
       
   147 void CESMRAgnVersit2StringProvider::ReadStringFromResourceL(TStringId aStringId)
       
   148     {
       
   149     FUNC_LOG;
       
   150 
       
   151     TInt offset = 0;
       
   152 
       
   153     switch (aStringId)
       
   154         {
       
   155         case EICalProdIdValue:
       
   156             offset = R_ICAL_PRODID;
       
   157             break;
       
   158         case EICalTzidUtc:
       
   159             offset = R_TZID_UTC;
       
   160             break;
       
   161         case EICalTzidPlus:
       
   162             offset = R_TZID_PLUS;
       
   163             break;
       
   164         case EICalTzidMinus:
       
   165             offset = R_TZID_MINUS;
       
   166             break;
       
   167         case EICalTzidSlash:
       
   168             offset = R_TZID_SLASH;
       
   169             break;
       
   170         case EICalTzidStandard:
       
   171             offset = R_TZID_STANDARD;
       
   172             break;
       
   173         case EICalTzidDaylight:
       
   174             offset = R_TZID_DAYLIGHT;
       
   175             break;
       
   176         case EICalErrRruleNumRules:
       
   177             offset = R_ERRIMPORT_NUMRULES;
       
   178             break;
       
   179         case EICalErrRruleNoFreq:
       
   180             offset = R_ERRIMPORT_NOFREQ;
       
   181             break;
       
   182         case EICalErrRruleNotYearly:
       
   183             offset = R_ERRIMPORT_NOTYEARLY;
       
   184             break;
       
   185         case EICalErrValarmNotAllowed:
       
   186             offset = R_ERRIMPORT_NOTALLOWED;
       
   187             break;
       
   188         case EICalErrValarmNoTrigger:
       
   189             offset = R_ERRIMPORT_NOTRIGGER;
       
   190             break;
       
   191         case EICalErrValarmNoStart:
       
   192             offset = R_ERRIMPORT_NOSTART;
       
   193             break;
       
   194         case EICalErrAlarmAfterEvent:
       
   195             offset = R_ERRIMPORT_AFTEREVENT;
       
   196             break;
       
   197         case EICalXParamType:
       
   198             offset = R_XPARAM_TYPE;
       
   199             break;
       
   200         case EICalXParamAppointment:
       
   201             offset = R_XPARAM_APPT;
       
   202             break;
       
   203         case EICalXParamTodo:
       
   204             offset = R_XPARAM_TODO;
       
   205             break;
       
   206         case EICalXParamEvent:
       
   207             offset = R_XPARAM_EVENT;
       
   208             break;
       
   209         case EICalXParamReminder:
       
   210             offset = R_XPARAM_REMINDER;
       
   211             break;
       
   212         case EICalXParamAnniversary:
       
   213             offset = R_XPARAM_ANNIVERSARY;
       
   214             break;
       
   215         case EICalAppointment:
       
   216             offset = R_CAT_APPOINTMENT;
       
   217             break;
       
   218         case EICalBusiness:
       
   219             offset = R_CAT_BUSINESS;
       
   220             break;
       
   221         case EICalEducation:
       
   222             offset = R_CAT_EDUCATION;
       
   223             break;
       
   224         case EICalHoliday:
       
   225             offset = R_CAT_HOLIDAY;
       
   226             break;
       
   227         case EICalMeeting:
       
   228             offset = R_CAT_MEETING;
       
   229             break;
       
   230         case EICalMisc:
       
   231             offset = R_CAT_MISC;
       
   232             break;
       
   233         case EICalPersonal:
       
   234             offset = R_CAT_PERSONAL;
       
   235             break;
       
   236         case EICalPhoneCall:
       
   237             offset = R_CAT_PHONECALL;
       
   238             break;
       
   239         case EICalSick:
       
   240             offset = R_CAT_SICK;
       
   241             break;
       
   242         case EICalSpecial:
       
   243             offset = R_CAT_SPECIAL;
       
   244             break;
       
   245         case EICalTravel:
       
   246             offset = R_CAT_TRAVEL;
       
   247         break;
       
   248         case EICalVacation:
       
   249             offset = R_CAT_VACATION;
       
   250             break;
       
   251         default:
       
   252             User::Leave(KErrCorrupt);
       
   253             break;
       
   254         }
       
   255     HBufC8* resourceData = iResourceFile.AllocReadLC(offset);
       
   256     iResourceReader.SetBuffer(resourceData);
       
   257     iResourceBuffer = iResourceReader.ReadTPtrC().AllocL();
       
   258     
       
   259     iStringArray[aStringId] = iResourceBuffer;  // iStringArray takes ownership here.	
       
   260     
       
   261     iResourceBuffer = NULL;
       
   262 
       
   263     CleanupStack::PopAndDestroy(resourceData);
       
   264 
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CESMRAgnVersit2StringProvider::ReadAllStringsL
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 /**
       
   272  * Reads every string into the string array to prevent lazy initialisation from
       
   273  * confusing any OOM tests. If we don't do this, then the strings stored in the
       
   274  * array between one import and the next look like a memory leak.
       
   275  * @internalTechnology
       
   276  */
       
   277 void CESMRAgnVersit2StringProvider::ReadAllStringsL()
       
   278     {
       
   279     FUNC_LOG;
       
   280 
       
   281     for (TInt id = 0; id < EICalNumberOfStrings; ++id)
       
   282         {
       
   283         ReadStringFromResourceL(static_cast<TStringId>(id));
       
   284         }
       
   285 
       
   286     }
       
   287 
       
   288 // End of file.
       
   289