calendarengines/agnversit2/src/AgnVersit2StringProvider.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 string loader for the X-tented iCal
       
    15 *                properties which has to be language sensitive.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // Class include.
       
    22 #include "AgnVersit2StringProvider.h"
       
    23 
       
    24 //debug
       
    25 #include "calendarengines_debug.h"
       
    26 
       
    27 // System includes.
       
    28 #include <barsc.h>              // RResourceFile
       
    29 #include <bautils.h>            // BaflUtils
       
    30 #include <data_caging_path_literals.hrh>
       
    31 
       
    32 // Resource include.
       
    33 #include <agnversit2strings.rsg>
       
    34 
       
    35 // Constants
       
    36 _LIT(KResourceFilename, "agnversit2strings.rsc");
       
    37 
       
    38 
       
    39 /**
       
    40 Creates a new CAgnVersit2StringProvider and returns it
       
    41 @return pointer to the new CAgnVersit2StringProvider
       
    42 @internalTechnology
       
    43 */
       
    44 CAgnVersit2StringProvider* CAgnVersit2StringProvider::NewL()
       
    45 	{
       
    46 	TRACE_ENTRY_POINT;
       
    47 	
       
    48 	CAgnVersit2StringProvider* self = new (ELeave) CAgnVersit2StringProvider;
       
    49 	CleanupStack::PushL(self);
       
    50 	self->ConstructL();
       
    51 	CleanupStack::Pop(self);
       
    52 	
       
    53 	TRACE_EXIT_POINT;
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 /**
       
    58 Destructor Delete all objects owned by the class. Note that iResourceBuffer is
       
    59 NOT deleted here, as it will be deleted during the call to
       
    60 iStringArray.ResetAndDestroy()
       
    61 @internalTechnology
       
    62 */
       
    63 CAgnVersit2StringProvider::~CAgnVersit2StringProvider()
       
    64 	{
       
    65 	TRACE_ENTRY_POINT;
       
    66 	
       
    67 	iStringArray.ResetAndDestroy();
       
    68 	iResourceFile.Close();
       
    69 	iFs.Close();
       
    70 	
       
    71 	TRACE_EXIT_POINT;
       
    72 	}
       
    73 
       
    74 /**
       
    75 Returns a string based on the TStringId parameter. If the array item at index
       
    76 aStringId is NULL, then that particular string has not been requested yet. If
       
    77 this is the case, then the string is retrieved from the resource file and set
       
    78 to aIndex in the string array.
       
    79 @param aStringId string index to return
       
    80 @return reference to a descriptor containing the string
       
    81 @internalTechnology
       
    82 */
       
    83 const TDesC& CAgnVersit2StringProvider::StringL(TStringId aStringId)
       
    84 	{
       
    85 	TRACE_ENTRY_POINT;
       
    86 	
       
    87 	ASSERT(iStringArray.Count() >= aStringId + 1);
       
    88 	if ( !iStringArray[aStringId] )
       
    89 		{
       
    90 		ReadStringFromResourceL(aStringId);	
       
    91 		}
       
    92 	
       
    93 	TRACE_EXIT_POINT;
       
    94 	return *iStringArray[aStringId];
       
    95 	}
       
    96 
       
    97 /**
       
    98 Default constructor
       
    99 @internalTechnology
       
   100 */
       
   101 CAgnVersit2StringProvider::CAgnVersit2StringProvider()
       
   102 	{
       
   103 	TRACE_ENTRY_POINT;
       
   104 	TRACE_EXIT_POINT; 
       
   105 	}
       
   106 	
       
   107 /**
       
   108 Second phase construction
       
   109 @leave
       
   110 @internalTechnology
       
   111 */
       
   112 void CAgnVersit2StringProvider::ConstructL()
       
   113 	{
       
   114 	TRACE_ENTRY_POINT;
       
   115 	
       
   116 	//Fill iStringArray with NULL pointers...
       
   117 	for (TInt x = 0; x < EICalNumberOfStrings; ++x)
       
   118 		{
       
   119 		User::LeaveIfError(iStringArray.Append(NULL));
       
   120 		}
       
   121 	User::LeaveIfError(iFs.Connect());
       
   122 	
       
   123 /* JH 16.9. quick fix for the resource loading problem */
       
   124    TFileName fileName;
       
   125 	// Get the complate path of the DLL from where it is currently loaded
       
   126 	Dll::FileName( fileName );
       
   127 	
       
   128 	TFileName resFile;
       
   129 	
       
   130 	// Append the Drive letters ex., Z: or C:
       
   131 	resFile.Append(fileName.Mid(0,2));
       
   132 	resFile.Append(KDC_RESOURCE_FILES_DIR);
       
   133     resFile.Append(KResourceFilename);
       
   134    
       
   135 	// Find a localised resource file if available -- if not, it will be left as .rsc
       
   136 	BaflUtils::NearestLanguageFile(iFs, resFile);
       
   137 	// Now we've got the full resource file name, so open it
       
   138 	iResourceFile.OpenL(iFs, resFile);
       
   139 	iResourceFile.ConfirmSignatureL(0);
       
   140 	
       
   141 	// Read all strings immediately in debug mode.
       
   142 	__DEBUG_ONLY(ReadAllStringsL());
       
   143 	
       
   144 	TRACE_EXIT_POINT;
       
   145 	}
       
   146 
       
   147 /**
       
   148 Reads a string from the resource file and adds it to the array of strings.
       
   149 @param aStringId string to add
       
   150 @internalTechnology
       
   151 */
       
   152 void CAgnVersit2StringProvider::ReadStringFromResourceL(TStringId aStringId)
       
   153 	{
       
   154 	TRACE_ENTRY_POINT;
       
   155 	
       
   156 	TInt offset = 0;
       
   157 	
       
   158 	switch (aStringId)
       
   159 		{
       
   160 		case EICalProdIdValue:
       
   161 			offset = R_ICAL_PRODID;
       
   162 			break;
       
   163 		case EICalTzidUtc:
       
   164 			offset = R_TZID_UTC;
       
   165 			break;
       
   166 		case EICalTzidPlus:
       
   167 			offset = R_TZID_PLUS;
       
   168 			break;
       
   169 		case EICalTzidMinus:
       
   170 			offset = R_TZID_MINUS;
       
   171 			break;
       
   172 		case EICalTzidSlash:
       
   173 			offset = R_TZID_SLASH;
       
   174 			break;
       
   175 		case EICalTzidStandard:
       
   176 			offset = R_TZID_STANDARD;
       
   177 			break;
       
   178 		case EICalTzidDaylight:
       
   179 			offset = R_TZID_DAYLIGHT;
       
   180 			break;
       
   181 		case EICalErrRruleNumRules:
       
   182 			offset = R_ERRIMPORT_NUMRULES;
       
   183 			break;
       
   184 		case EICalErrRruleNoFreq:
       
   185 			offset = R_ERRIMPORT_NOFREQ;
       
   186 			break;
       
   187 		case EICalErrRruleNotYearly:
       
   188 			offset = R_ERRIMPORT_NOTYEARLY;
       
   189 			break;
       
   190 		case EICalErrValarmNotAllowed:
       
   191 			offset = R_ERRIMPORT_NOTALLOWED;
       
   192 			break;
       
   193 		case EICalErrValarmNoTrigger:
       
   194 			offset = R_ERRIMPORT_NOTRIGGER;
       
   195 			break;
       
   196 		case EICalErrValarmNoStart:
       
   197 			offset = R_ERRIMPORT_NOSTART;
       
   198 			break;
       
   199 		case EICalErrAlarmAfterEvent:
       
   200 			offset = R_ERRIMPORT_AFTEREVENT;
       
   201 			break;
       
   202 		case EICalXParamType:
       
   203 			offset = R_XPARAM_TYPE;
       
   204 			break;
       
   205 		case EICalXParamAppointment:
       
   206 			offset = R_XPARAM_APPT;
       
   207 			break;
       
   208 		case EICalXParamTodo:
       
   209 			offset = R_XPARAM_TODO;
       
   210 			break;
       
   211 		case EICalXParamEvent:
       
   212 			offset = R_XPARAM_EVENT;
       
   213 			break;
       
   214 		case EICalXParamReminder:
       
   215 			offset = R_XPARAM_REMINDER;
       
   216 			break;
       
   217 		case EICalXParamAnniversary:
       
   218 			offset = R_XPARAM_ANNIVERSARY;
       
   219 			break;
       
   220 		case EICalAppointment:
       
   221 			offset = R_CAT_APPOINTMENT;
       
   222 			break;
       
   223 		case EICalBusiness:
       
   224 			offset = R_CAT_BUSINESS;
       
   225 			break;
       
   226 		case EICalEducation:
       
   227 			offset = R_CAT_EDUCATION;
       
   228 			break;
       
   229 		case EICalHoliday:
       
   230 			offset = R_CAT_HOLIDAY;
       
   231 			break;
       
   232 		case EICalMeeting:
       
   233 			offset = R_CAT_MEETING;
       
   234 			break;
       
   235 		case EICalMisc:
       
   236 			offset = R_CAT_MISC;
       
   237 			break;
       
   238 		case EICalPersonal:
       
   239 			offset = R_CAT_PERSONAL;
       
   240 			break;
       
   241 		case EICalPhoneCall:
       
   242 			offset = R_CAT_PHONECALL;
       
   243 			break;
       
   244 		case EICalSick:
       
   245 			offset = R_CAT_SICK;
       
   246 			break;
       
   247 		case EICalSpecial:
       
   248 			offset = R_CAT_SPECIAL;
       
   249 			break;
       
   250 		case EICalTravel:
       
   251 			offset = R_CAT_TRAVEL;
       
   252 		break;
       
   253 		case EICalVacation:
       
   254 			offset = R_CAT_VACATION;
       
   255 			break;
       
   256 		default:
       
   257 			User::Leave(KErrCorrupt);
       
   258 			break;
       
   259 		}
       
   260 	HBufC8* resourceData = iResourceFile.AllocReadLC(offset);
       
   261 	iResourceReader.SetBuffer(resourceData);
       
   262 	iResourceBuffer = iResourceReader.ReadTPtrC().AllocL();
       
   263 	iStringArray[aStringId] = iResourceBuffer;	// iStringArray takes ownership here.
       
   264 	iResourceBuffer = NULL;
       
   265 	
       
   266 	CleanupStack::PopAndDestroy(resourceData);
       
   267 	
       
   268 	TRACE_EXIT_POINT;
       
   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 CAgnVersit2StringProvider::ReadAllStringsL()
       
   278 	{
       
   279 	TRACE_ENTRY_POINT;
       
   280 	
       
   281 	for (TInt id = 0; id < EICalNumberOfStrings; ++id)
       
   282 		{
       
   283 		ReadStringFromResourceL(static_cast<TStringId>(id));
       
   284 		}
       
   285 	
       
   286 	TRACE_EXIT_POINT;
       
   287 	}
       
   288 	
       
   289 // End of file.