os/ossrv/genericopenlibs/openenvcore/libc/src/localeinfo.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:  Contains the source for all locale related functionalities
sl@0
    15
 *     
sl@0
    16
 *
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#include <stdlib.h>
sl@0
    21
#include <f32file.h>
sl@0
    22
#include "localeinfo.h"
sl@0
    23
#include "sysif.h"
sl@0
    24
#include <e32std_private.h>
sl@0
    25
#include <e32ldr_private.h>
sl@0
    26
sl@0
    27
typedef void (*TLibFn)(TLocale*);
sl@0
    28
sl@0
    29
#if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
sl@0
    30
#include "libc_wsd_defs.h"
sl@0
    31
#include "localetlsinfo.h"
sl@0
    32
#else
sl@0
    33
sl@0
    34
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
    35
#define NEW_LANG_VARIANT_DLL_NAME 30
sl@0
    36
#endif
sl@0
    37
sl@0
    38
#endif
sl@0
    39
#define LC_TIME_MEMORY 1024
sl@0
    40
#define LC_MONETARY_MEMORY 50
sl@0
    41
#define LC_NUMERIC_MEMORY 20
sl@0
    42
#define MONTHS	12
sl@0
    43
#define WEEKDAYS 7
sl@0
    44
#define DECIMAL_THOUSAND_DATE_TIME_SEPARATOR 2
sl@0
    45
#define EURO_CURRENCY 4
sl@0
    46
#define LOCALE_LENGTH 50
sl@0
    47
#define CHARACTER_SET_NAME 32
sl@0
    48
#define TIME_FORMAT_LENGTH 32
sl@0
    49
#define NON_UNICODE_TEXT_BUFFER_LENGTH 256
sl@0
    50
#define LANG_VARIANT_DLL_NAME 10
sl@0
    51
sl@0
    52
#define MONTH_STR	"%m"
sl@0
    53
#define DAY_STR		"%d"
sl@0
    54
#define YEAR_STR 	"%Y"
sl@0
    55
#define TWELVE_HOUR_STR 	"%I"
sl@0
    56
#define TWENTY_FOUR_HOUR_STR	"%H"
sl@0
    57
#define MINUTE_STR	"%M"
sl@0
    58
#define SECOND_STR	"%S"
sl@0
    59
#define AMPM_SPACE	" %p"
sl@0
    60
#define AMPM_NO_SPACE	"%p"
sl@0
    61
sl@0
    62
sl@0
    63
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
    64
sl@0
    65
sl@0
    66
_LIT(KLanDllName, "elocl_lan.");
sl@0
    67
_LIT(KRegDllName, "elocl_reg.");
sl@0
    68
_LIT(KColDllName, "elocl_col.");
sl@0
    69
sl@0
    70
#endif
sl@0
    71
sl@0
    72
_LIT(KDllName, "elocl");
sl@0
    73
sl@0
    74
sl@0
    75
#ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
    76
_LIT(KEuro, "\x20AC");
sl@0
    77
#endif
sl@0
    78
sl@0
    79
_LIT8(KAMPMSpace12hr, "B");
sl@0
    80
_LIT8(KAMPMSpace, "A");
sl@0
    81
_LIT8(KAMPMNoSpace12hr, "*B");
sl@0
    82
_LIT8(KAMPMNoSpace, "*A");
sl@0
    83
sl@0
    84
#ifndef EMULATOR
sl@0
    85
sl@0
    86
CLocale* CLocale::iNewLocale = NULL;
sl@0
    87
lc_monetary_T* CLocale::iMonetary_locale = NULL;
sl@0
    88
lc_numeric_T* CLocale::iNumeric_locale =NULL;
sl@0
    89
lc_time_T* CLocale::iTime_locale = NULL;
sl@0
    90
sl@0
    91
TText8*  numericLocale =  NULL;
sl@0
    92
TText8* monetaryLocale = NULL;
sl@0
    93
TText8* timeLocale =  NULL;
sl@0
    94
sl@0
    95
static TBuf<LANG_VARIANT_DLL_NAME> DllName;
sl@0
    96
sl@0
    97
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
    98
static TBuf<NEW_LANG_VARIANT_DLL_NAME> ColDllName;
sl@0
    99
#endif
sl@0
   100
sl@0
   101
#else //EMULATOR
sl@0
   102
sl@0
   103
#define iNewLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNewLocale,s))
sl@0
   104
#define iMonetary_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iMonetary_locale,s))
sl@0
   105
#define iNumeric_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNumeric_locale,s))
sl@0
   106
#define iTime_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iTime_locale,s))
sl@0
   107
sl@0
   108
#define numericLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(numericLocale,s))
sl@0
   109
#define monetaryLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(monetaryLocale,s))
sl@0
   110
#define timeLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(timeLocale,s))
sl@0
   111
sl@0
   112
#define DllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(DllName,s))
sl@0
   113
sl@0
   114
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
   115
sl@0
   116
#define ColDllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(ColDllName,s))
sl@0
   117
#endif
sl@0
   118
sl@0
   119
#endif //EMULATOR
sl@0
   120
sl@0
   121
CLocale::CLocale()
sl@0
   122
	{
sl@0
   123
	iMonetary_locale = NULL;
sl@0
   124
	iNumeric_locale = NULL;
sl@0
   125
	iTime_locale = NULL;
sl@0
   126
sl@0
   127
	numericLocale =  NULL;
sl@0
   128
    monetaryLocale = NULL;
sl@0
   129
	timeLocale =  NULL;
sl@0
   130
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL    
sl@0
   131
     iOldDllPresent = 0;
sl@0
   132
#endif
sl@0
   133
	}
sl@0
   134
	
sl@0
   135
sl@0
   136
sl@0
   137
CLocale* CLocale::New()
sl@0
   138
	{
sl@0
   139
	CLocale* self = new CLocale();
sl@0
   140
	if(self)
sl@0
   141
		{
sl@0
   142
		TInt ret=KErrNone;
sl@0
   143
		TRAPD(result,ret = self->ConstructL());
sl@0
   144
		if(KErrNone != (result | ret))
sl@0
   145
			{
sl@0
   146
			delete self;
sl@0
   147
			self = NULL;
sl@0
   148
			}
sl@0
   149
		}
sl@0
   150
	return self;
sl@0
   151
	}
sl@0
   152
	
sl@0
   153
TInt CLocale::ConstructL()
sl@0
   154
	{
sl@0
   155
	iMonetary_locale = new  lc_monetary_T;
sl@0
   156
	if(!iMonetary_locale)
sl@0
   157
		{
sl@0
   158
		return KErrNoMemory;
sl@0
   159
		}
sl@0
   160
	iNumeric_locale = new lc_numeric_T;
sl@0
   161
	if(!iNumeric_locale)
sl@0
   162
		{
sl@0
   163
		return KErrNoMemory;
sl@0
   164
		}
sl@0
   165
	iTime_locale = new (ELeave) lc_time_T;
sl@0
   166
	if(!iTime_locale)
sl@0
   167
		{
sl@0
   168
		return KErrNoMemory;
sl@0
   169
		}
sl@0
   170
	
sl@0
   171
	for(TInt i =0 ; i < MONTHS; i++)
sl@0
   172
		{
sl@0
   173
		iTime_locale->mon[i] = NULL;
sl@0
   174
		iTime_locale->month[i] = NULL;
sl@0
   175
		iTime_locale->alt_month[i] = NULL;	
sl@0
   176
		}
sl@0
   177
	
sl@0
   178
sl@0
   179
	for(TInt i =0 ; i < WEEKDAYS; i++)
sl@0
   180
		{
sl@0
   181
		iTime_locale->wday[i] = NULL;
sl@0
   182
		iTime_locale->weekday[i] = NULL;	
sl@0
   183
		}
sl@0
   184
sl@0
   185
	iTime_locale->X_fmt = NULL;
sl@0
   186
	iTime_locale->x_fmt = NULL;
sl@0
   187
	iTime_locale->c_fmt = NULL;
sl@0
   188
	iTime_locale->am = NULL;
sl@0
   189
	iTime_locale->pm = NULL;
sl@0
   190
	iTime_locale->date_fmt = NULL;
sl@0
   191
	iTime_locale->md_order = NULL;
sl@0
   192
	iTime_locale->ampm_fmt = NULL;
sl@0
   193
	
sl@0
   194
	iMonetary_locale->int_curr_symbol = NULL;
sl@0
   195
	iMonetary_locale->currency_symbol  = NULL;
sl@0
   196
	iMonetary_locale->mon_decimal_point = NULL;
sl@0
   197
	iMonetary_locale->mon_thousands_sep = NULL;
sl@0
   198
	iMonetary_locale->mon_grouping = NULL;
sl@0
   199
	iMonetary_locale->positive_sign = NULL;
sl@0
   200
	iMonetary_locale->negative_sign = NULL;
sl@0
   201
	iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = NULL;
sl@0
   202
	iMonetary_locale->p_cs_precedes = iMonetary_locale->int_p_cs_precedes = NULL;
sl@0
   203
	iMonetary_locale->p_sep_by_space = iMonetary_locale->int_p_sep_by_space = NULL;
sl@0
   204
	iMonetary_locale->n_cs_precedes = iMonetary_locale->int_n_cs_precedes = NULL;
sl@0
   205
	iMonetary_locale->n_sep_by_space = iMonetary_locale->int_n_sep_by_space = NULL;
sl@0
   206
	iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = NULL;
sl@0
   207
	iMonetary_locale->n_sign_posn = iMonetary_locale->int_n_sign_posn = NULL;
sl@0
   208
sl@0
   209
	iNumeric_locale->decimal_point = NULL;
sl@0
   210
	iNumeric_locale->thousands_sep = NULL;
sl@0
   211
	iNumeric_locale->grouping = NULL;
sl@0
   212
	
sl@0
   213
	return KErrNone;
sl@0
   214
	}
sl@0
   215
sl@0
   216
CLocale* CLocale::GetInstance()
sl@0
   217
	{
sl@0
   218
	// Switch to the backend heap
sl@0
   219
	RHeap* oldheap = User::SwitchHeap(Backend()->Heap());
sl@0
   220
	
sl@0
   221
	if(NULL == iNewLocale)	
sl@0
   222
		{
sl@0
   223
		iNewLocale = New();
sl@0
   224
		}
sl@0
   225
		
sl@0
   226
	if(numericLocale == NULL )
sl@0
   227
		{
sl@0
   228
		numericLocale =  new TText8 [LC_NUMERIC_MEMORY];	
sl@0
   229
		}
sl@0
   230
	
sl@0
   231
	if(monetaryLocale == NULL)
sl@0
   232
		{
sl@0
   233
		monetaryLocale = new TText8[LC_MONETARY_MEMORY];
sl@0
   234
		}
sl@0
   235
	
sl@0
   236
	if(timeLocale == NULL)
sl@0
   237
		{
sl@0
   238
		timeLocale =  new TText8[LC_TIME_MEMORY];
sl@0
   239
		}
sl@0
   240
	
sl@0
   241
sl@0
   242
				
sl@0
   243
	//Set back the default user heap
sl@0
   244
	User::SwitchHeap(oldheap);
sl@0
   245
	return iNewLocale;	
sl@0
   246
	}
sl@0
   247
sl@0
   248
	
sl@0
   249
void CLocale::DeleteInstance()
sl@0
   250
	{
sl@0
   251
	// Switch to the backend heap so that deletes happen from there
sl@0
   252
	RHeap* oldheap = User::SwitchHeap(Backend()->Heap());
sl@0
   253
sl@0
   254
	delete [] timeLocale;
sl@0
   255
	timeLocale =NULL;
sl@0
   256
sl@0
   257
	delete []  numericLocale;
sl@0
   258
	numericLocale = NULL;
sl@0
   259
sl@0
   260
	delete [] monetaryLocale;
sl@0
   261
	monetaryLocale = NULL;
sl@0
   262
sl@0
   263
	delete  iMonetary_locale;
sl@0
   264
	iMonetary_locale = NULL;
sl@0
   265
sl@0
   266
	delete iNumeric_locale;
sl@0
   267
	iNumeric_locale = NULL;
sl@0
   268
sl@0
   269
	delete iTime_locale;
sl@0
   270
	iTime_locale = NULL;
sl@0
   271
	
sl@0
   272
	delete iNewLocale;
sl@0
   273
	iNewLocale = NULL;
sl@0
   274
	
sl@0
   275
sl@0
   276
	
sl@0
   277
	//Set back to the default user heap
sl@0
   278
	User::SwitchHeap(oldheap);
sl@0
   279
	}
sl@0
   280
		
sl@0
   281
sl@0
   282
TText* CLocale::SetLocale(TDesC& aLocale)	
sl@0
   283
	{
sl@0
   284
		//Check whether locale is supported
sl@0
   285
	
sl@0
   286
		TText* retVal = NULL;
sl@0
   287
		TInt r;
sl@0
   288
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL 
sl@0
   289
		
sl@0
   290
		// load the new locale dll if not present check for the old dll
sl@0
   291
		r = LoadNewLocaleDll( aLocale );
sl@0
   292
        if ( r  ==  KErrNone ) 
sl@0
   293
        {
sl@0
   294
            retVal = (TText*) aLocale.Ptr();
sl@0
   295
            iOldDllPresent = 0;
sl@0
   296
            return retVal;
sl@0
   297
        }
sl@0
   298
#endif
sl@0
   299
sl@0
   300
    if(!LoadLocale(aLocale))
sl@0
   301
    {
sl@0
   302
        return NULL;
sl@0
   303
    }
sl@0
   304
    RLoader loader;
sl@0
   305
    r = loader.Connect();
sl@0
   306
    if(KErrNone == r)
sl@0
   307
        {
sl@0
   308
            //Load the language variant DLL 
sl@0
   309
            TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
sl@0
   310
            TPtr8 functionListBuf((TUint8*) iData, size, size);
sl@0
   311
            r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&DllName, &functionListBuf) );
sl@0
   312
            if(KErrNone == r)
sl@0
   313
            {
sl@0
   314
                ((TLibFn)iData[FnLocaleData])(&iLocale);
sl@0
   315
                retVal = (TText*) aLocale.Ptr();
sl@0
   316
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL 
sl@0
   317
                iOldDllPresent = 1;
sl@0
   318
#endif
sl@0
   319
            }
sl@0
   320
            loader.Close();
sl@0
   321
        }
sl@0
   322
    return retVal;
sl@0
   323
}
sl@0
   324
sl@0
   325
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   326
sl@0
   327
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
   328
TInt  CLocale::GetSystemLocale(TDesC& aLanDllName,TDesC& aRegDllName)
sl@0
   329
    {
sl@0
   330
        RLoader loader;
sl@0
   331
        TInt retVal = -1;
sl@0
   332
        TInt r = loader.Connect();
sl@0
   333
        if(KErrNone == r)
sl@0
   334
            {
sl@0
   335
            TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
sl@0
   336
            TPtr8 functionListBuf1((TUint8*) iDataLanguage, size, size);
sl@0
   337
            r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aLanDllName, &functionListBuf1) );
sl@0
   338
            if(KErrNone != r)
sl@0
   339
                return retVal;
sl@0
   340
            TPtr8 functionListBuf2((TUint8*) iDataRegion, size, size);
sl@0
   341
            r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aRegDllName, &functionListBuf2) );
sl@0
   342
            ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale);
sl@0
   343
            if(KErrNone != r)
sl@0
   344
                return retVal;
sl@0
   345
            retVal = 0;
sl@0
   346
            loader.Close();
sl@0
   347
            }
sl@0
   348
        return retVal;
sl@0
   349
    
sl@0
   350
    }
sl@0
   351
#endif
sl@0
   352
//Load the system dll settings
sl@0
   353
TInt CLocale::GetSystemLocale(TDesC& aDllName)	
sl@0
   354
	{
sl@0
   355
		RLoader loader;
sl@0
   356
		TInt retVal = -1;
sl@0
   357
		TInt r = loader.Connect();
sl@0
   358
		if(KErrNone == r)
sl@0
   359
			{
sl@0
   360
			//Load the language variant DLL 
sl@0
   361
			TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
sl@0
   362
          	TPtr8 functionListBuf((TUint8*) iData, size, size);
sl@0
   363
          	r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aDllName, &functionListBuf) );
sl@0
   364
			if(KErrNone == r)
sl@0
   365
				{
sl@0
   366
            	((TLibFn)iData[FnLocaleData])(&iLocale);
sl@0
   367
            	retVal = 0;
sl@0
   368
				}
sl@0
   369
			loader.Close();
sl@0
   370
			}
sl@0
   371
		return retVal;
sl@0
   372
	}
sl@0
   373
sl@0
   374
#endif
sl@0
   375
sl@0
   376
sl@0
   377
TInt CLocale::MonetaryLoadLocaleL(const char* localeName)
sl@0
   378
{
sl@0
   379
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   380
        TInt charsetID=-1;
sl@0
   381
        if(localeName)
sl@0
   382
        {
sl@0
   383
            charsetID = GetCharcaterSetIDL(localeName);
sl@0
   384
            if(charsetID == -1)
sl@0
   385
            {
sl@0
   386
                return -1;
sl@0
   387
            }
sl@0
   388
        }
sl@0
   389
    #else
sl@0
   390
        TInt charsetID = GetCharcaterSetIDL(localeName);
sl@0
   391
        if(charsetID == -1)
sl@0
   392
        {
sl@0
   393
            return -1;
sl@0
   394
        }
sl@0
   395
    #endif
sl@0
   396
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   397
	    else
sl@0
   398
        {
sl@0
   399
        //update the iLocale with the system locale settings
sl@0
   400
            iLocale.Refresh();	
sl@0
   401
        }
sl@0
   402
    #endif
sl@0
   403
    #ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   404
        //Retreive monetary information from language variant DLL
sl@0
   405
        Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));	
sl@0
   406
    #endif
sl@0
   407
        TLocalePos aCurrencySymbolPosition = iLocale.CurrencySymbolPosition();
sl@0
   408
        TLocale::TNegativeCurrencyFormat aNegativeCurrencyFormat = iLocale.NegativeCurrencyFormat();
sl@0
   409
        TBool aCurrencySpaceBetween = iLocale.CurrencySpaceBetween();
sl@0
   410
        TBool aNegativeCurrencySymbolOpposite = iLocale.NegativeCurrencySymbolOpposite();
sl@0
   411
        TBool aNegativeLoseSpace = iLocale.NegativeLoseSpace();
sl@0
   412
        TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed();
sl@0
   413
        
sl@0
   414
        TInt currencyDecimalPlaces = iLocale.CurrencyDecimalPlaces();
sl@0
   415
        iThousandsSeparator= iLocale.ThousandsSeparator();
sl@0
   416
        iDecimalSeparator = iLocale.DecimalSeparator();
sl@0
   417
            
sl@0
   418
        TText8* temp = monetaryLocale;
sl@0
   419
        
sl@0
   420
        //Set the decimal separator
sl@0
   421
        const TText* dec_point = (const TText*) &iDecimalSeparator;
sl@0
   422
        if(dec_point)
sl@0
   423
        {
sl@0
   424
            const TPtrC dec(dec_point);
sl@0
   425
            TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> decimal;
sl@0
   426
            decimal.Copy(dec);
sl@0
   427
            strncpy((char*) monetaryLocale, (char*) decimal.Ptr(), decimal.Length());
sl@0
   428
            monetaryLocale[decimal.Length()] = '\0';
sl@0
   429
            iMonetary_locale->mon_decimal_point = (const char*) monetaryLocale;
sl@0
   430
            monetaryLocale += decimal.Length() + 1;
sl@0
   431
        }
sl@0
   432
        
sl@0
   433
        //Set thousand separator
sl@0
   434
        const TText* thous_sep = (const TText*) &iThousandsSeparator;
sl@0
   435
        if(thous_sep)
sl@0
   436
        {
sl@0
   437
            const TPtrC thousand(thous_sep);
sl@0
   438
            TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> thousand_sep;
sl@0
   439
            thousand_sep.Copy(thousand);
sl@0
   440
            strncpy((char*) monetaryLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length());
sl@0
   441
            monetaryLocale[thousand_sep.Length()] = '\0';
sl@0
   442
            iMonetary_locale->mon_thousands_sep = (const char*) monetaryLocale;
sl@0
   443
            monetaryLocale += thousand_sep.Length() + 1;
sl@0
   444
        }
sl@0
   445
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   446
        TBuf<KMaxCurrencySymbol> CurrencySymbol;
sl@0
   447
        if(localeName)
sl@0
   448
        {
sl@0
   449
#ifdef  SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
   450
        if( iOldDllPresent ) // old style dll is loaded
sl@0
   451
            {
sl@0
   452
                Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
sl@0
   453
            }
sl@0
   454
        else
sl@0
   455
            {
sl@0
   456
                Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iDataRegion[FnCurrencySymbolV2](), sizeof(TText) * (KMaxCurrencySymbol+1));
sl@0
   457
            }
sl@0
   458
#else
sl@0
   459
        Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
sl@0
   460
#endif
sl@0
   461
        //Set Currency information
sl@0
   462
        const TText16* cur = iLocaleSettings.iCurrencySymbol;
sl@0
   463
        const TPtrC currency(cur);
sl@0
   464
        CurrencySymbol.Copy(currency);
sl@0
   465
        }
sl@0
   466
        else
sl@0
   467
        {
sl@0
   468
        TCurrencySymbol cur;
sl@0
   469
        const TPtrC currency(cur);
sl@0
   470
        CurrencySymbol.Copy(currency);
sl@0
   471
        }
sl@0
   472
        strncpy((char*) monetaryLocale, (char*) CurrencySymbol.Ptr(), CurrencySymbol.Length());
sl@0
   473
        monetaryLocale[CurrencySymbol.Length()] = '\0';
sl@0
   474
            iMonetary_locale->currency_symbol = (const char*) monetaryLocale;
sl@0
   475
            monetaryLocale += strlen((char*) monetaryLocale) + 1;
sl@0
   476
    #else	
sl@0
   477
        //Set Currency information
sl@0
   478
        const TText16* currency = iLocaleSettings.iCurrencySymbol;
sl@0
   479
        if(currency)
sl@0
   480
        {
sl@0
   481
            TBuf<EURO_CURRENCY> euroSymbol(currency);
sl@0
   482
            char* temp = strchr(localeName, '.');
sl@0
   483
            temp = temp + 1;
sl@0
   484
            
sl@0
   485
            if(!euroSymbol.Compare(KEuro) && !strcmp(temp, "ISO-8859-1"))
sl@0
   486
            {
sl@0
   487
                strcpy((char*) monetaryLocale,"\x80");
sl@0
   488
                monetaryLocale[1] = '\0';					
sl@0
   489
            }
sl@0
   490
            else
sl@0
   491
            {
sl@0
   492
                ConvertToMultiByteL((TText8*)monetaryLocale, currency, charsetID);	
sl@0
   493
            }
sl@0
   494
            iMonetary_locale->currency_symbol = (const char*) monetaryLocale;
sl@0
   495
            monetaryLocale += strlen((char*) monetaryLocale) + 1;
sl@0
   496
        }
sl@0
   497
    #endif
sl@0
   498
        
sl@0
   499
        //Set grouping information
sl@0
   500
        strcpy((char*) monetaryLocale,(aCurrencyTriadsAllowed? "\003":""));
sl@0
   501
        monetaryLocale[strlen((char*) monetaryLocale)] = '\0';
sl@0
   502
        iMonetary_locale->mon_grouping = (const char*) monetaryLocale;
sl@0
   503
        monetaryLocale += strlen((char*) monetaryLocale) + 1;
sl@0
   504
        
sl@0
   505
        //Set currency decimal places
sl@0
   506
        iMonetary_locale->int_frac_digits =	iMonetary_locale->frac_digits = (const char*) monetaryLocale;
sl@0
   507
        *monetaryLocale++ = currencyDecimalPlaces;
sl@0
   508
        *monetaryLocale++ = '\0';
sl@0
   509
            
sl@0
   510
        //Set the currency symbol position for a monetary quantity with non-negative value 
sl@0
   511
        iMonetary_locale->p_cs_precedes = (const char*) monetaryLocale;
sl@0
   512
        iMonetary_locale->int_p_cs_precedes = iMonetary_locale->p_cs_precedes;
sl@0
   513
        *monetaryLocale++ = (ELocaleBefore == aCurrencySymbolPosition)?1:0;
sl@0
   514
        *monetaryLocale++ = '\0';
sl@0
   515
        
sl@0
   516
        //Set the currency symbol position for a monetary quantity with negative value		
sl@0
   517
        iMonetary_locale->n_cs_precedes = (const char*) monetaryLocale;
sl@0
   518
        iMonetary_locale->int_n_cs_precedes = iMonetary_locale->n_cs_precedes;
sl@0
   519
        *monetaryLocale++ = aNegativeCurrencySymbolOpposite?0:1;
sl@0
   520
        *monetaryLocale++ ='\0';
sl@0
   521
        
sl@0
   522
        //Set the currency symbol separated by space or not for a monetary quantity with non-negative value
sl@0
   523
        iMonetary_locale->p_sep_by_space = (const char*) monetaryLocale;
sl@0
   524
        iMonetary_locale->int_p_sep_by_space = iMonetary_locale->p_sep_by_space;
sl@0
   525
        *monetaryLocale++ = aCurrencySpaceBetween?1:0;	
sl@0
   526
        *monetaryLocale++ ='\0';
sl@0
   527
        
sl@0
   528
        //Set the currency symbol separated by space or not for a monetary quantity with negative value
sl@0
   529
        iMonetary_locale->n_sep_by_space = (const char*) monetaryLocale;
sl@0
   530
        iMonetary_locale->int_n_sep_by_space = iMonetary_locale->n_sep_by_space;
sl@0
   531
        *monetaryLocale++ = aNegativeLoseSpace?1:0;
sl@0
   532
        *monetaryLocale++ = '\0';
sl@0
   533
        
sl@0
   534
        //Set the positioning of the negative and positive for a monetary quantity 
sl@0
   535
        if(TLocale::ELeadingMinusSign == aNegativeCurrencyFormat)				
sl@0
   536
        {
sl@0
   537
            iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
sl@0
   538
            *monetaryLocale++ = 1;
sl@0
   539
            *monetaryLocale++ = '\0';
sl@0
   540
        }
sl@0
   541
        if(TLocale::EInBrackets == aNegativeCurrencyFormat)
sl@0
   542
        {
sl@0
   543
            iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
sl@0
   544
            *monetaryLocale++ = 0;
sl@0
   545
            *monetaryLocale++ = '\0';
sl@0
   546
        }
sl@0
   547
        
sl@0
   548
        if(TLocale::ETrailingMinusSign == aNegativeCurrencyFormat)
sl@0
   549
        {
sl@0
   550
            iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
sl@0
   551
            *monetaryLocale++ = 2;
sl@0
   552
            *monetaryLocale++ = '\0';
sl@0
   553
        }
sl@0
   554
        
sl@0
   555
        if(TLocale::EInterveningMinusSign == aNegativeCurrencyFormat)
sl@0
   556
        {
sl@0
   557
            iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
sl@0
   558
            *monetaryLocale++ = 3;
sl@0
   559
            *monetaryLocale++ = '\0';
sl@0
   560
        }
sl@0
   561
        
sl@0
   562
        iMonetary_locale->int_n_sign_posn = iMonetary_locale->n_sign_posn;
sl@0
   563
        iMonetary_locale->p_sign_posn = 	iMonetary_locale->int_p_sign_posn = 	iMonetary_locale->n_sign_posn;
sl@0
   564
        //Set the positive sign and negative sign for monetary quantity
sl@0
   565
        iMonetary_locale->positive_sign = iMonetary_locale->negative_sign = "";
sl@0
   566
        //Set the internationla currency symbol
sl@0
   567
        iMonetary_locale->int_curr_symbol = "";
sl@0
   568
        monetaryLocale = temp;
sl@0
   569
        return 0;
sl@0
   570
        
sl@0
   571
	
sl@0
   572
}
sl@0
   573
/* Forward declaration of ReadALine */
sl@0
   574
inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc);
sl@0
   575
extern void GetInstallationDataDir(TFileName& aPath);
sl@0
   576
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
   577
sl@0
   578
TInt CLocale::ParseNewLocaleFile( TDesC& aLocale )
sl@0
   579
{
sl@0
   580
// open and parse the file
sl@0
   581
    TPtrC src(aLocale);
sl@0
   582
    TBuf8<LOCALE_LENGTH> locale_name;
sl@0
   583
    locale_name.Copy(src);
sl@0
   584
    char locale[LOCALE_LENGTH];
sl@0
   585
    strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length());
sl@0
   586
    locale[locale_name.Length()] = '\0';
sl@0
   587
    
sl@0
   588
    if (NULL == strchr(locale, '.'))
sl@0
   589
        {
sl@0
   590
        return 0;
sl@0
   591
        }
sl@0
   592
    RFile newfile;
sl@0
   593
#ifndef __EPOC32__
sl@0
   594
    _LIT(localeFileNew,"\\resource\\openc\\locales_new.txt" );
sl@0
   595
#else
sl@0
   596
    TFileName localeFileNew;
sl@0
   597
    GetInstallationDataDir(localeFileNew);
sl@0
   598
    localeFileNew.Append(_L("locales_new.txt" ));
sl@0
   599
#endif
sl@0
   600
           
sl@0
   601
    int retValNew = newfile.Open(Backend()->FileSession(), localeFileNew, EFileRead);
sl@0
   602
    if( KErrNone != retValNew )
sl@0
   603
    {
sl@0
   604
        return 0;
sl@0
   605
    }
sl@0
   606
    int pos = 0;
sl@0
   607
    TBuf8<LOCALE_LENGTH> localeInfoNew;
sl@0
   608
    retValNew = ReadALine(newfile, pos, localeInfoNew);
sl@0
   609
    char* buffer = (char*) localeInfoNew.Ptr();
sl@0
   610
    int  i = 0;
sl@0
   611
    int  flag = 0;
sl@0
   612
    while( retValNew > 0)
sl@0
   613
    {
sl@0
   614
        char str1[LOCALE_LENGTH];
sl@0
   615
        while(buffer[i] != '=')
sl@0
   616
        {
sl@0
   617
            str1[i] = buffer[i];
sl@0
   618
            i++;
sl@0
   619
        }
sl@0
   620
        str1[i] = '\0';
sl@0
   621
        if(!strcmp(str1,locale))
sl@0
   622
        {
sl@0
   623
            flag = 1;
sl@0
   624
            break;
sl@0
   625
        }
sl@0
   626
        i = 0;
sl@0
   627
        retValNew = ReadALine(newfile, pos, localeInfoNew);
sl@0
   628
        buffer = (char*) localeInfoNew.Ptr();
sl@0
   629
    }
sl@0
   630
    if(flag)
sl@0
   631
    {
sl@0
   632
        
sl@0
   633
        iLanDllName.Copy(KLanDllName);
sl@0
   634
        iRegDllName.Copy(KRegDllName);
sl@0
   635
        ColDllName.Copy(KColDllName);
sl@0
   636
        i++;
sl@0
   637
        int len = localeInfoNew.Length();
sl@0
   638
        TBuf<50> localeids;
sl@0
   639
        while(i < len )
sl@0
   640
        {
sl@0
   641
        localeids.Append(buffer[i]);  
sl@0
   642
        i++;
sl@0
   643
        }
sl@0
   644
        TLex lex( localeids );
sl@0
   645
        TChar ch;
sl@0
   646
        TInt k = 0;
sl@0
   647
        TBuf<10> token[3];
sl@0
   648
        while((ch = lex.Get()) != 0 )
sl@0
   649
        {
sl@0
   650
        while (ch != ',' && ch != 0 && ch != '\t' && ch != '\n' && ch != '\r') 
sl@0
   651
           {
sl@0
   652
           lex.Inc();
sl@0
   653
           ch = lex.Peek();
sl@0
   654
           }
sl@0
   655
        token[k].Copy(lex.MarkedToken());
sl@0
   656
        k++;
sl@0
   657
        lex.Inc();
sl@0
   658
        lex.Mark();
sl@0
   659
        }
sl@0
   660
        iLanDllName.Append(token[0]);
sl@0
   661
        iRegDllName.Append(token[1]);
sl@0
   662
        ColDllName.Append(token[2]);
sl@0
   663
        newfile.Close();
sl@0
   664
        return 1;
sl@0
   665
       
sl@0
   666
     }
sl@0
   667
    newfile.Close();
sl@0
   668
    return 0;
sl@0
   669
}
sl@0
   670
sl@0
   671
TInt CLocale::LoadNewLocaleDll( TDesC& aLocale  )
sl@0
   672
    {
sl@0
   673
    
sl@0
   674
    if(!ParseNewLocaleFile( aLocale ))
sl@0
   675
        {
sl@0
   676
            return -1;
sl@0
   677
        }
sl@0
   678
    RLoader loader;
sl@0
   679
    TInt r = loader.Connect();
sl@0
   680
    if( KErrNone != r)
sl@0
   681
       return -1;
sl@0
   682
    TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
sl@0
   683
    TPtr8 functionListBuf((TUint8*) iDataRegion, size, size );
sl@0
   684
    r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iRegDllName, &functionListBuf) );
sl@0
   685
    if( KErrNone != r)
sl@0
   686
       return -1;
sl@0
   687
    ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale);
sl@0
   688
    // language dll loading
sl@0
   689
    TPtr8 functionListBuf_lan((TUint8*) iDataLanguage, size, size);
sl@0
   690
    r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iLanDllName, &functionListBuf_lan) );
sl@0
   691
    if( KErrNone != r)
sl@0
   692
       return -1;
sl@0
   693
   
sl@0
   694
    return r;
sl@0
   695
    
sl@0
   696
    }
sl@0
   697
sl@0
   698
#endif
sl@0
   699
sl@0
   700
sl@0
   701
sl@0
   702
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   703
TInt CLocale::NumericLoadLocale(const char* localeName)
sl@0
   704
#else
sl@0
   705
TInt CLocale::NumericLoadLocale(const char* /*localeName*/)
sl@0
   706
#endif
sl@0
   707
{
sl@0
   708
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   709
        if(!localeName)
sl@0
   710
        {
sl@0
   711
            //update the iLocale with the system settings
sl@0
   712
            iLocale.Refresh();
sl@0
   713
            
sl@0
   714
        }
sl@0
   715
    #endif
sl@0
   716
        //Retrive numeric information from language variant DLL
sl@0
   717
        TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed();
sl@0
   718
        iThousandsSeparator= iLocale.ThousandsSeparator();
sl@0
   719
        iDecimalSeparator = iLocale.DecimalSeparator();
sl@0
   720
        
sl@0
   721
        TText8* temp = numericLocale;
sl@0
   722
        //Set the decimal separator
sl@0
   723
        const TText* dec_point = (const TText*) &iDecimalSeparator;
sl@0
   724
        if(dec_point)
sl@0
   725
        {
sl@0
   726
            const TPtrC dec(dec_point);
sl@0
   727
            TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> decimal;
sl@0
   728
            decimal.Copy(dec);
sl@0
   729
            strncpy((char*) numericLocale, (char*) decimal.Ptr(), decimal.Length());
sl@0
   730
            numericLocale[decimal.Length()] ='\0';
sl@0
   731
            iNumeric_locale->decimal_point = (const char*) numericLocale;
sl@0
   732
            numericLocale += decimal.Length() + 1;
sl@0
   733
        }
sl@0
   734
        
sl@0
   735
        //Set thousand separator
sl@0
   736
        const TText* thous_sep = (const TText*) &iThousandsSeparator;
sl@0
   737
        if(thous_sep)
sl@0
   738
        {
sl@0
   739
            const TPtrC thousand(thous_sep);
sl@0
   740
            TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> thousand_sep;
sl@0
   741
            thousand_sep.Copy(thousand);
sl@0
   742
            strncpy((char*) numericLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length());
sl@0
   743
            numericLocale[thousand_sep.Length()] = '\0';
sl@0
   744
            iNumeric_locale->thousands_sep = (const char*) numericLocale;
sl@0
   745
            numericLocale += thousand_sep.Length() + 1;
sl@0
   746
        }
sl@0
   747
        
sl@0
   748
        //Set grouping information
sl@0
   749
        strcpy((char*) numericLocale,(aCurrencyTriadsAllowed? "\003":""));
sl@0
   750
        numericLocale[strlen((char*) numericLocale)] = '\0';
sl@0
   751
        iNumeric_locale->grouping = (const char*) numericLocale;
sl@0
   752
        numericLocale += strlen((char*) numericLocale) + 1;
sl@0
   753
                
sl@0
   754
        numericLocale = temp;
sl@0
   755
        return 0;
sl@0
   756
	
sl@0
   757
}
sl@0
   758
sl@0
   759
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
   760
sl@0
   761
sl@0
   762
TInt CLocale::TimeLoadNewLocaleL( const char* localeName )
sl@0
   763
{
sl@0
   764
    TInt charsetID = -1;
sl@0
   765
    if( localeName )
sl@0
   766
    {
sl@0
   767
        charsetID = GetCharcaterSetIDL(localeName);
sl@0
   768
        if(charsetID == -1)
sl@0
   769
        {
sl@0
   770
            return -1;
sl@0
   771
        }
sl@0
   772
    }
sl@0
   773
    else
sl@0
   774
    {
sl@0
   775
    //update the iLocale with the system locale settings
sl@0
   776
        iLocale.Refresh();
sl@0
   777
    }
sl@0
   778
    TText8* startAddress =  timeLocale;
sl@0
   779
    //Set month and abbreviated month name information
sl@0
   780
    for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++)
sl@0
   781
    {
sl@0
   782
sl@0
   783
        const TText16* month = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnMonthTableV2]()))[aMonth]);
sl@0
   784
        if(month)
sl@0
   785
        {
sl@0
   786
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   787
            if(!localeName)
sl@0
   788
            {
sl@0
   789
                ConvertToMultiByteCustom((TUint8*)timeLocale,  month);  
sl@0
   790
            }
sl@0
   791
            else    
sl@0
   792
            {
sl@0
   793
#endif
sl@0
   794
            ConvertToMultiByteL((TUint8*)timeLocale,  month, charsetID);
sl@0
   795
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   796
            }
sl@0
   797
#endif
sl@0
   798
            iTime_locale->month[aMonth] = (const char*)  timeLocale;
sl@0
   799
            iTime_locale->alt_month[aMonth] = (const char*)  timeLocale;
sl@0
   800
            timeLocale += strlen((char*) timeLocale) + 1;
sl@0
   801
        }
sl@0
   802
        const TText16* abbMonth = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnMonthAbbTableV2]()))[aMonth]);
sl@0
   803
        if(abbMonth)
sl@0
   804
        {
sl@0
   805
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   806
            if(!localeName)
sl@0
   807
            {
sl@0
   808
                ConvertToMultiByteCustom((TUint8*)timeLocale,  abbMonth);   
sl@0
   809
            }
sl@0
   810
            else    
sl@0
   811
            {
sl@0
   812
#endif
sl@0
   813
            ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID);
sl@0
   814
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   815
            }
sl@0
   816
#endif
sl@0
   817
            iTime_locale->mon[aMonth] = (const char*)  timeLocale;
sl@0
   818
            timeLocale += strlen((char*) timeLocale) + 1;               
sl@0
   819
        }
sl@0
   820
                    
sl@0
   821
    }
sl@0
   822
    
sl@0
   823
    //Set day and abbreviated day name information
sl@0
   824
    const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayTableV2]()))[6]);
sl@0
   825
    if(day)
sl@0
   826
    {
sl@0
   827
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   828
        if(!localeName)
sl@0
   829
        {
sl@0
   830
            ConvertToMultiByteCustom((TUint8*)timeLocale,  day);    
sl@0
   831
        }
sl@0
   832
        else    
sl@0
   833
        {
sl@0
   834
#endif
sl@0
   835
        ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
sl@0
   836
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   837
        }
sl@0
   838
#endif
sl@0
   839
        iTime_locale->weekday[0] = (const char*)  timeLocale;
sl@0
   840
        timeLocale += strlen((char*) timeLocale) + 1;               
sl@0
   841
    }
sl@0
   842
    const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayAbbTableV2]()))[6]);
sl@0
   843
    if(abbDay)
sl@0
   844
    {
sl@0
   845
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   846
        if(!localeName)
sl@0
   847
        {
sl@0
   848
            ConvertToMultiByteCustom((TUint8*)timeLocale,  abbDay); 
sl@0
   849
        }
sl@0
   850
        else
sl@0
   851
        {
sl@0
   852
#endif
sl@0
   853
        ConvertToMultiByteL((TUint8*)timeLocale,  abbDay, charsetID);
sl@0
   854
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   855
        }
sl@0
   856
#endif
sl@0
   857
        iTime_locale->wday[0] = (const char*)  timeLocale;              
sl@0
   858
        timeLocale += strlen((char*) timeLocale) + 1;
sl@0
   859
    }
sl@0
   860
    
sl@0
   861
    for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++)
sl@0
   862
    {
sl@0
   863
        const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayTableV2]()))[aDay]);
sl@0
   864
        if(day)
sl@0
   865
        {
sl@0
   866
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   867
            if(!localeName)
sl@0
   868
            {
sl@0
   869
                ConvertToMultiByteCustom((TUint8*)timeLocale,  day);    
sl@0
   870
            }
sl@0
   871
            else    
sl@0
   872
            {
sl@0
   873
#endif
sl@0
   874
            ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
sl@0
   875
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   876
            }
sl@0
   877
#endif
sl@0
   878
            iTime_locale->weekday[aDay + 1] = (const char*)  timeLocale;
sl@0
   879
            timeLocale += strlen((char*) timeLocale) + 1;               
sl@0
   880
        }
sl@0
   881
        const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayAbbTableV2]()))[aDay]);
sl@0
   882
        if(abbDay)
sl@0
   883
        {
sl@0
   884
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   885
            if(!localeName)
sl@0
   886
            {
sl@0
   887
                ConvertToMultiByteCustom((TUint8*)timeLocale,  abbDay); 
sl@0
   888
            }
sl@0
   889
            else    
sl@0
   890
            {
sl@0
   891
#endif
sl@0
   892
            ConvertToMultiByteL((TUint8*)timeLocale,  abbDay, charsetID);
sl@0
   893
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   894
            }  
sl@0
   895
#endif
sl@0
   896
            iTime_locale->wday[aDay + 1] = (const char*)  timeLocale;               
sl@0
   897
            timeLocale += strlen((char*) timeLocale) + 1;
sl@0
   898
        }
sl@0
   899
                    
sl@0
   900
    }
sl@0
   901
    const TText16* am = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnAmPmTableV2]()))[0]);
sl@0
   902
    if(am)
sl@0
   903
    {
sl@0
   904
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   905
        if(!localeName)
sl@0
   906
        {
sl@0
   907
            ConvertToMultiByteCustom((TUint8*)timeLocale,  am); 
sl@0
   908
        }
sl@0
   909
        else    
sl@0
   910
        {
sl@0
   911
#endif
sl@0
   912
        ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID);
sl@0
   913
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   914
        } 
sl@0
   915
#endif
sl@0
   916
        iTime_locale->am = (const char*)  timeLocale;                   
sl@0
   917
        timeLocale += strlen((char*) timeLocale) + 1;
sl@0
   918
    }
sl@0
   919
    const TText16* pm = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnAmPmTableV2]()))[1]);
sl@0
   920
    if(pm)
sl@0
   921
    {
sl@0
   922
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   923
        if(!localeName)
sl@0
   924
        {
sl@0
   925
            ConvertToMultiByteCustom((TUint8*)timeLocale,  pm); 
sl@0
   926
        }
sl@0
   927
        else    
sl@0
   928
        {
sl@0
   929
#endif
sl@0
   930
        ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID);
sl@0
   931
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
   932
        }  
sl@0
   933
#endif
sl@0
   934
        iTime_locale->pm = (const char*)  timeLocale;                   
sl@0
   935
        timeLocale += strlen((char*) timeLocale) + 1;
sl@0
   936
    }
sl@0
   937
            
sl@0
   938
    Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iDataRegion[FnTimeFormatSpecV2](), sizeof(TText) * (KMaxTimeFormatSpec+1));
sl@0
   939
    TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec;
sl@0
   940
    
sl@0
   941
    //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string
sl@0
   942
    if(timeForm)
sl@0
   943
    {
sl@0
   944
        const TPtrC time(timeForm);
sl@0
   945
        TBuf8<TIME_FORMAT_LENGTH> timeFormat;
sl@0
   946
        timeFormat.Copy(time);
sl@0
   947
        
sl@0
   948
        TChar timeSeparator = iLocale.TimeSeparator(1);
sl@0
   949
        TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator1;
sl@0
   950
        timeSeparator1.Append(timeSeparator);
sl@0
   951
        
sl@0
   952
        timeSeparator = iLocale.TimeSeparator(2);
sl@0
   953
        TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator2;
sl@0
   954
        timeSeparator2.Append(timeSeparator);
sl@0
   955
        
sl@0
   956
        TTimeFormat time12hror24hr = iLocale.TimeFormat();
sl@0
   957
        
sl@0
   958
        if(KErrNotFound != timeFormat.Locate('J'))
sl@0
   959
        {
sl@0
   960
            //Check for time format(12/24 hour format)
sl@0
   961
            if(time12hror24hr == ETime12)
sl@0
   962
            {
sl@0
   963
                strcpy((char*) timeLocale,TWELVE_HOUR_STR);
sl@0
   964
            }
sl@0
   965
            else
sl@0
   966
            {
sl@0
   967
                strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
sl@0
   968
            }
sl@0
   969
        }
sl@0
   970
        
sl@0
   971
        else if(KErrNotFound != timeFormat.Locate('I'))
sl@0
   972
        {
sl@0
   973
            strcpy((char*) timeLocale,TWELVE_HOUR_STR);
sl@0
   974
        }   
sl@0
   975
        
sl@0
   976
        else if(KErrNotFound != timeFormat.Locate('H'))
sl@0
   977
        {
sl@0
   978
            strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
sl@0
   979
        }   
sl@0
   980
    
sl@0
   981
        strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length());
sl@0
   982
        strcat((char*) timeLocale, MINUTE_STR);
sl@0
   983
        strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length());
sl@0
   984
        strcat((char*) timeLocale, SECOND_STR);
sl@0
   985
        
sl@0
   986
        if(time12hror24hr == ETime12)
sl@0
   987
        {
sl@0
   988
sl@0
   989
            if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) )
sl@0
   990
            {
sl@0
   991
                if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace)))
sl@0
   992
                {
sl@0
   993
                    strcat((char*) timeLocale, AMPM_NO_SPACE);
sl@0
   994
                }
sl@0
   995
                else
sl@0
   996
                {
sl@0
   997
                    strcat((char*) timeLocale, AMPM_SPACE);
sl@0
   998
                }
sl@0
   999
            }   
sl@0
  1000
        }
sl@0
  1001
                    
sl@0
  1002
        iTime_locale->ampm_fmt =  (const char*)  timeLocale;
sl@0
  1003
        iTime_locale->X_fmt = iTime_locale->ampm_fmt;
sl@0
  1004
        timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1005
    }
sl@0
  1006
    
sl@0
  1007
    TDateFormat aDateFormat = iLocale.DateFormat();
sl@0
  1008
    //Set date fromat string(D_FMT) 
sl@0
  1009
    TChar dateSeparator = iLocale.DateSeparator(1);
sl@0
  1010
    TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator1;
sl@0
  1011
    dateSeparator1.Append(dateSeparator);
sl@0
  1012
    
sl@0
  1013
    TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator2;
sl@0
  1014
    dateSeparator = iLocale.DateSeparator(2);
sl@0
  1015
    dateSeparator2.Append(dateSeparator);
sl@0
  1016
sl@0
  1017
    //Americal date formt(mm/dd/YYYY)
sl@0
  1018
    if(EDateAmerican == aDateFormat)
sl@0
  1019
    {
sl@0
  1020
        strcpy((char*) timeLocale, MONTH_STR);
sl@0
  1021
        strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
sl@0
  1022
        strcat((char*) timeLocale, DAY_STR);
sl@0
  1023
        strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
sl@0
  1024
        strcat((char*) timeLocale, YEAR_STR);
sl@0
  1025
        iTime_locale->x_fmt = (const char*)  timeLocale;
sl@0
  1026
    }
sl@0
  1027
    
sl@0
  1028
    //European date format(dd/mm/YYYY)
sl@0
  1029
    if(EDateEuropean == aDateFormat)
sl@0
  1030
    {
sl@0
  1031
        strcpy((char*) timeLocale, DAY_STR);
sl@0
  1032
        strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
sl@0
  1033
        strcat((char*) timeLocale, MONTH_STR);
sl@0
  1034
        strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
sl@0
  1035
        strcat((char*) timeLocale, YEAR_STR);
sl@0
  1036
        iTime_locale->x_fmt = (const char*)  timeLocale;
sl@0
  1037
    }
sl@0
  1038
    
sl@0
  1039
    //Japanese date format(YYYY/mm/dd)
sl@0
  1040
    if(EDateJapanese == aDateFormat)
sl@0
  1041
    {
sl@0
  1042
        strcpy((char*) timeLocale, YEAR_STR);
sl@0
  1043
        strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
sl@0
  1044
        strcat((char*) timeLocale, MONTH_STR);
sl@0
  1045
        strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
sl@0
  1046
        strcat((char*) timeLocale, DAY_STR);
sl@0
  1047
        iTime_locale->x_fmt = (const char*)  timeLocale;
sl@0
  1048
    }
sl@0
  1049
    
sl@0
  1050
    iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L"";
sl@0
  1051
            ;
sl@0
  1052
    timeLocale = startAddress;
sl@0
  1053
sl@0
  1054
sl@0
  1055
sl@0
  1056
return 0;
sl@0
  1057
}
sl@0
  1058
#endif
sl@0
  1059
TInt CLocale::TimeLoadLocaleL(const char* localeName)
sl@0
  1060
{
sl@0
  1061
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
  1062
sl@0
  1063
    if( ! iOldDllPresent)
sl@0
  1064
        {
sl@0
  1065
           TInt ret = TimeLoadNewLocaleL( localeName ); // option 2 to load language and region dll both
sl@0
  1066
           if( ret == -1 )
sl@0
  1067
               return -1;
sl@0
  1068
           return ret;
sl@0
  1069
        }
sl@0
  1070
#endif
sl@0
  1071
    TText8* startAddress =  timeLocale;
sl@0
  1072
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1073
            TInt charsetID = -1;
sl@0
  1074
            if(localeName)
sl@0
  1075
            {
sl@0
  1076
                charsetID = GetCharcaterSetIDL(localeName);
sl@0
  1077
                if(charsetID == -1)
sl@0
  1078
                    {
sl@0
  1079
                        return -1;
sl@0
  1080
                    }
sl@0
  1081
            }
sl@0
  1082
    #else
sl@0
  1083
            TInt charsetID = GetCharcaterSetIDL(localeName);
sl@0
  1084
            if(charsetID == -1)
sl@0
  1085
            {
sl@0
  1086
                return -1;
sl@0
  1087
            }
sl@0
  1088
    #endif
sl@0
  1089
		
sl@0
  1090
sl@0
  1091
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1092
            else
sl@0
  1093
            {
sl@0
  1094
                iLocale.Refresh();
sl@0
  1095
            }
sl@0
  1096
    #endif
sl@0
  1097
            //Set month and abbreviated month name information
sl@0
  1098
            for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++)
sl@0
  1099
            {
sl@0
  1100
   
sl@0
  1101
                const TText16* month = ((reinterpret_cast<TText*const*>((const TText*) iData[FnMonthTable]()))[aMonth]);
sl@0
  1102
                if(month)
sl@0
  1103
                {
sl@0
  1104
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1105
                    if(!localeName)
sl@0
  1106
                    {
sl@0
  1107
                        ConvertToMultiByteCustom((TUint8*)timeLocale,  month);	
sl@0
  1108
                    }
sl@0
  1109
                    else	
sl@0
  1110
                    {
sl@0
  1111
    #endif
sl@0
  1112
                    ConvertToMultiByteL((TUint8*)timeLocale,  month, charsetID);
sl@0
  1113
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1114
                    }
sl@0
  1115
    #endif
sl@0
  1116
                    iTime_locale->month[aMonth] = (const char*)  timeLocale;
sl@0
  1117
                    iTime_locale->alt_month[aMonth] = (const char*)  timeLocale;
sl@0
  1118
                    timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1119
                }
sl@0
  1120
    
sl@0
  1121
                const TText16* abbMonth = ((reinterpret_cast<TText*const*>((const TText*) iData[FnMonthAbbTable]()))[aMonth]);
sl@0
  1122
                if(abbMonth)
sl@0
  1123
                {
sl@0
  1124
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1125
                    if(!localeName)
sl@0
  1126
                    {
sl@0
  1127
                        ConvertToMultiByteCustom((TUint8*)timeLocale,  abbMonth);	
sl@0
  1128
                    }
sl@0
  1129
                    else	
sl@0
  1130
                    {
sl@0
  1131
    #endif
sl@0
  1132
                    ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID);	
sl@0
  1133
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1134
                    }
sl@0
  1135
    #endif
sl@0
  1136
                    iTime_locale->mon[aMonth] = (const char*)  timeLocale;
sl@0
  1137
                    timeLocale += strlen((char*) timeLocale) + 1;				
sl@0
  1138
                }
sl@0
  1139
                            
sl@0
  1140
            }
sl@0
  1141
            
sl@0
  1142
            //Set day and abbreviated day name information
sl@0
  1143
    
sl@0
  1144
            const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayTable]()))[6]);
sl@0
  1145
            if(day)
sl@0
  1146
            {
sl@0
  1147
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1148
                if(!localeName)
sl@0
  1149
                {
sl@0
  1150
                    ConvertToMultiByteCustom((TUint8*)timeLocale,  day);	
sl@0
  1151
                }
sl@0
  1152
                else	
sl@0
  1153
                {
sl@0
  1154
    #endif
sl@0
  1155
                ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
sl@0
  1156
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1157
                }
sl@0
  1158
    #endif
sl@0
  1159
                iTime_locale->weekday[0] = (const char*)  timeLocale;
sl@0
  1160
                timeLocale += strlen((char*) timeLocale) + 1;				
sl@0
  1161
            }
sl@0
  1162
            
sl@0
  1163
    
sl@0
  1164
            const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayAbbTable]()))[6]);
sl@0
  1165
            if(abbDay)
sl@0
  1166
            {
sl@0
  1167
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1168
                if(!localeName)
sl@0
  1169
                {
sl@0
  1170
                    ConvertToMultiByteCustom((TUint8*)timeLocale,  abbDay);	
sl@0
  1171
                }
sl@0
  1172
                else
sl@0
  1173
                {
sl@0
  1174
    #endif
sl@0
  1175
                
sl@0
  1176
                ConvertToMultiByteL((TUint8*)timeLocale,  abbDay, charsetID);
sl@0
  1177
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1178
                }
sl@0
  1179
    #endif
sl@0
  1180
                iTime_locale->wday[0] = (const char*)  timeLocale;				
sl@0
  1181
                timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1182
            }
sl@0
  1183
            
sl@0
  1184
            for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++)
sl@0
  1185
            {
sl@0
  1186
    
sl@0
  1187
                const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayTable]()))[aDay]);
sl@0
  1188
                if(day)
sl@0
  1189
                {
sl@0
  1190
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1191
                    if(!localeName)
sl@0
  1192
                    {
sl@0
  1193
                        ConvertToMultiByteCustom((TUint8*)timeLocale,  day);	
sl@0
  1194
                    }
sl@0
  1195
                    else	
sl@0
  1196
                    {
sl@0
  1197
    #endif
sl@0
  1198
                    ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
sl@0
  1199
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1200
                    }
sl@0
  1201
    #endif
sl@0
  1202
                    iTime_locale->weekday[aDay + 1] = (const char*)  timeLocale;
sl@0
  1203
                    timeLocale += strlen((char*) timeLocale) + 1;				
sl@0
  1204
                }
sl@0
  1205
                
sl@0
  1206
    
sl@0
  1207
                const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayAbbTable]()))[aDay]);
sl@0
  1208
                if(abbDay)
sl@0
  1209
                {
sl@0
  1210
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1211
                    if(!localeName)
sl@0
  1212
                    {
sl@0
  1213
                        ConvertToMultiByteCustom((TUint8*)timeLocale,  abbDay);	
sl@0
  1214
                    }
sl@0
  1215
                    else	
sl@0
  1216
                    {
sl@0
  1217
    #endif
sl@0
  1218
                    ConvertToMultiByteL((TUint8*)timeLocale,  abbDay, charsetID);
sl@0
  1219
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1220
                    }  
sl@0
  1221
    #endif
sl@0
  1222
                    iTime_locale->wday[aDay + 1] = (const char*)  timeLocale;				
sl@0
  1223
                    timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1224
                }
sl@0
  1225
                            
sl@0
  1226
            }
sl@0
  1227
            
sl@0
  1228
            //Set AM string
sl@0
  1229
    
sl@0
  1230
            const TText16* am = ((reinterpret_cast<TText*const*>((const TText*) iData[FnAmPmTable]()))[0]);
sl@0
  1231
            if(am)
sl@0
  1232
            {
sl@0
  1233
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1234
                if(!localeName)
sl@0
  1235
                {
sl@0
  1236
                    ConvertToMultiByteCustom((TUint8*)timeLocale,  am);	
sl@0
  1237
                }
sl@0
  1238
                else	
sl@0
  1239
                {
sl@0
  1240
    #endif
sl@0
  1241
                ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID);
sl@0
  1242
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1243
                }  
sl@0
  1244
    #endif
sl@0
  1245
                iTime_locale->am = (const char*)  timeLocale;					
sl@0
  1246
                timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1247
            }
sl@0
  1248
            
sl@0
  1249
            //Set PM string
sl@0
  1250
    
sl@0
  1251
            const TText16* pm = ((reinterpret_cast<TText*const*>((const TText*) iData[FnAmPmTable]()))[1]);
sl@0
  1252
            if(pm)
sl@0
  1253
            {
sl@0
  1254
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1255
                if(!localeName)
sl@0
  1256
                {
sl@0
  1257
                    ConvertToMultiByteCustom((TUint8*)timeLocale,  pm);	
sl@0
  1258
                }
sl@0
  1259
                else	
sl@0
  1260
                {
sl@0
  1261
    #endif
sl@0
  1262
                ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID);
sl@0
  1263
    #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1264
                }  
sl@0
  1265
    #endif
sl@0
  1266
                iTime_locale->pm = (const char*)  timeLocale;					
sl@0
  1267
                timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1268
            }
sl@0
  1269
                    
sl@0
  1270
    
sl@0
  1271
            Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iData[FnTimeFormatSpec](), sizeof(TText) * (KMaxTimeFormatSpec+1));
sl@0
  1272
            TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec;
sl@0
  1273
            
sl@0
  1274
            //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string
sl@0
  1275
            if(timeForm)
sl@0
  1276
            {
sl@0
  1277
                const TPtrC time(timeForm);
sl@0
  1278
                TBuf8<TIME_FORMAT_LENGTH> timeFormat;
sl@0
  1279
                timeFormat.Copy(time);
sl@0
  1280
                
sl@0
  1281
                TChar timeSeparator = iLocale.TimeSeparator(1);
sl@0
  1282
                TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator1;
sl@0
  1283
                timeSeparator1.Append(timeSeparator);
sl@0
  1284
                
sl@0
  1285
                timeSeparator = iLocale.TimeSeparator(2);
sl@0
  1286
                TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator2;
sl@0
  1287
                timeSeparator2.Append(timeSeparator);
sl@0
  1288
                
sl@0
  1289
                TTimeFormat time12hror24hr = iLocale.TimeFormat();
sl@0
  1290
                
sl@0
  1291
                if(KErrNotFound != timeFormat.Locate('J'))
sl@0
  1292
                {
sl@0
  1293
                    //Check for time format(12/24 hour format)
sl@0
  1294
                    if(time12hror24hr == ETime12)
sl@0
  1295
                    {
sl@0
  1296
                        strcpy((char*) timeLocale,TWELVE_HOUR_STR);
sl@0
  1297
                    }
sl@0
  1298
                    else
sl@0
  1299
                    {
sl@0
  1300
                        strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
sl@0
  1301
                    }
sl@0
  1302
                }
sl@0
  1303
                
sl@0
  1304
                else if(KErrNotFound != timeFormat.Locate('I'))
sl@0
  1305
                {
sl@0
  1306
                    strcpy((char*) timeLocale,TWELVE_HOUR_STR);
sl@0
  1307
                }	
sl@0
  1308
                
sl@0
  1309
                else if(KErrNotFound != timeFormat.Locate('H'))
sl@0
  1310
                {
sl@0
  1311
                    strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
sl@0
  1312
                }	
sl@0
  1313
            
sl@0
  1314
                strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length());
sl@0
  1315
                strcat((char*) timeLocale, MINUTE_STR);
sl@0
  1316
                strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length());
sl@0
  1317
                strcat((char*) timeLocale, SECOND_STR);
sl@0
  1318
                
sl@0
  1319
                if(time12hror24hr == ETime12)
sl@0
  1320
                {
sl@0
  1321
    
sl@0
  1322
                    if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) )
sl@0
  1323
                    {
sl@0
  1324
                        if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace)))
sl@0
  1325
                        {
sl@0
  1326
                            strcat((char*) timeLocale, AMPM_NO_SPACE);
sl@0
  1327
                        }
sl@0
  1328
                        else
sl@0
  1329
                        {
sl@0
  1330
                            strcat((char*) timeLocale, AMPM_SPACE);
sl@0
  1331
                        }
sl@0
  1332
                    }	
sl@0
  1333
                }
sl@0
  1334
                            
sl@0
  1335
                iTime_locale->ampm_fmt =  (const char*)  timeLocale;
sl@0
  1336
                iTime_locale->X_fmt = iTime_locale->ampm_fmt;
sl@0
  1337
                timeLocale += strlen((char*) timeLocale) + 1;
sl@0
  1338
            }
sl@0
  1339
            
sl@0
  1340
            TDateFormat aDateFormat = iLocale.DateFormat();
sl@0
  1341
            //Set date fromat string(D_FMT)	
sl@0
  1342
            TChar dateSeparator = iLocale.DateSeparator(1);
sl@0
  1343
            TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator1;
sl@0
  1344
            dateSeparator1.Append(dateSeparator);
sl@0
  1345
            
sl@0
  1346
            TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator2;
sl@0
  1347
            dateSeparator = iLocale.DateSeparator(2);
sl@0
  1348
            dateSeparator2.Append(dateSeparator);
sl@0
  1349
    
sl@0
  1350
            //Americal date formt(mm/dd/YYYY)
sl@0
  1351
            if(EDateAmerican == aDateFormat)
sl@0
  1352
            {
sl@0
  1353
                strcpy((char*) timeLocale, MONTH_STR);
sl@0
  1354
                strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
sl@0
  1355
                strcat((char*) timeLocale, DAY_STR);
sl@0
  1356
                strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
sl@0
  1357
                strcat((char*) timeLocale, YEAR_STR);
sl@0
  1358
                iTime_locale->x_fmt = (const char*)  timeLocale;
sl@0
  1359
            }
sl@0
  1360
            
sl@0
  1361
            //European date format(dd/mm/YYYY)
sl@0
  1362
            if(EDateEuropean == aDateFormat)
sl@0
  1363
            {
sl@0
  1364
                strcpy((char*) timeLocale, DAY_STR);
sl@0
  1365
                strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
sl@0
  1366
                strcat((char*) timeLocale, MONTH_STR);
sl@0
  1367
                strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
sl@0
  1368
                strcat((char*) timeLocale, YEAR_STR);
sl@0
  1369
                iTime_locale->x_fmt = (const char*)  timeLocale;
sl@0
  1370
            }
sl@0
  1371
            
sl@0
  1372
            //Japanese date format(YYYY/mm/dd)
sl@0
  1373
            if(EDateJapanese == aDateFormat)
sl@0
  1374
            {
sl@0
  1375
                strcpy((char*) timeLocale, YEAR_STR);
sl@0
  1376
                strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
sl@0
  1377
                strcat((char*) timeLocale, MONTH_STR);
sl@0
  1378
                strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
sl@0
  1379
                strcat((char*) timeLocale, DAY_STR);
sl@0
  1380
                iTime_locale->x_fmt = (const char*)  timeLocale;
sl@0
  1381
            }
sl@0
  1382
            
sl@0
  1383
            iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L"";
sl@0
  1384
                    ;
sl@0
  1385
            timeLocale = startAddress;
sl@0
  1386
            return 0;	
sl@0
  1387
		
sl@0
  1388
}
sl@0
  1389
sl@0
  1390
struct lc_numeric_T* CLocale::GetCurrentNumericLocale(void)
sl@0
  1391
{
sl@0
  1392
sl@0
  1393
	if(NULL != iNumeric_locale)
sl@0
  1394
	{
sl@0
  1395
		return iNumeric_locale;	
sl@0
  1396
	}
sl@0
  1397
	return NULL;
sl@0
  1398
	
sl@0
  1399
}
sl@0
  1400
sl@0
  1401
struct lc_monetary_T* CLocale::GetCurrentMonetaryLocale(void)
sl@0
  1402
{
sl@0
  1403
	if(NULL != iMonetary_locale)
sl@0
  1404
	{
sl@0
  1405
		return iMonetary_locale;	
sl@0
  1406
	}
sl@0
  1407
	return NULL;
sl@0
  1408
}
sl@0
  1409
sl@0
  1410
struct lc_time_T* CLocale::GetCurrentTimeLocale(void)
sl@0
  1411
{
sl@0
  1412
	if(NULL != iTime_locale)
sl@0
  1413
	{
sl@0
  1414
		return iTime_locale;
sl@0
  1415
	}
sl@0
  1416
	
sl@0
  1417
	return NULL;
sl@0
  1418
}
sl@0
  1419
sl@0
  1420
sl@0
  1421
TInt CLocale::LoadLocale(TDesC& aLocale)
sl@0
  1422
{
sl@0
  1423
    TPtrC src(aLocale);
sl@0
  1424
    TBuf8<LOCALE_LENGTH> locale_name;
sl@0
  1425
    locale_name.Copy(src);
sl@0
  1426
    char locale[LOCALE_LENGTH];
sl@0
  1427
    strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length());
sl@0
  1428
    locale[locale_name.Length()] = '\0';
sl@0
  1429
    
sl@0
  1430
    if (NULL == strchr(locale, '.'))
sl@0
  1431
        {
sl@0
  1432
        return 0;
sl@0
  1433
        }
sl@0
  1434
sl@0
  1435
    // Open the file locale mapping(mapping of POSIX locale string to language variant DLL number) file
sl@0
  1436
    RFile file;
sl@0
  1437
    
sl@0
  1438
#ifndef __EPOC32__
sl@0
  1439
    _LIT(localeFile, "\\resource\\openc\\locales.txt");
sl@0
  1440
#else
sl@0
  1441
    TFileName localeFile;
sl@0
  1442
    GetInstallationDataDir(localeFile);
sl@0
  1443
    localeFile.Append(_L("locales.txt"));
sl@0
  1444
#endif //__EPOC32__
sl@0
  1445
    
sl@0
  1446
    int retVal = file.Open(Backend()->FileSession(), localeFile, EFileRead);
sl@0
  1447
    if(KErrNone != retVal)
sl@0
  1448
        {
sl@0
  1449
        return 0;
sl@0
  1450
        }
sl@0
  1451
    
sl@0
  1452
    int pos = 0;
sl@0
  1453
    TBuf8<LOCALE_LENGTH> localeInfo;
sl@0
  1454
    retVal = ReadALine(file, pos, localeInfo);
sl@0
  1455
    char* buffer = (char*) localeInfo.Ptr();
sl@0
  1456
        
sl@0
  1457
    //Check whether locale is supported or not
sl@0
  1458
    int i = 0;
sl@0
  1459
    int flag = 0;
sl@0
  1460
    while( retVal > 0)
sl@0
  1461
    {
sl@0
  1462
        char str[LOCALE_LENGTH];
sl@0
  1463
        while(buffer[i] != '=')
sl@0
  1464
        {
sl@0
  1465
            str[i] = buffer[i];
sl@0
  1466
            i++;
sl@0
  1467
        }
sl@0
  1468
        str[i] = '\0';
sl@0
  1469
        if(!strcmp(str,locale))
sl@0
  1470
        {
sl@0
  1471
            flag = 1;
sl@0
  1472
            break;
sl@0
  1473
        }
sl@0
  1474
        i = 0;
sl@0
  1475
        retVal = ReadALine(file, pos, localeInfo);
sl@0
  1476
        buffer = (char*) localeInfo.Ptr();
sl@0
  1477
    }
sl@0
  1478
    if(flag)
sl@0
  1479
    {
sl@0
  1480
        DllName.Copy(KDllName);
sl@0
  1481
        DllName.Append('.');
sl@0
  1482
        i++;
sl@0
  1483
        int len = localeInfo.Length();
sl@0
  1484
        while(i < len)
sl@0
  1485
            {
sl@0
  1486
            DllName.Append(buffer[i]);  
sl@0
  1487
            i++;
sl@0
  1488
            }
sl@0
  1489
        file.Close();
sl@0
  1490
        return 1;   
sl@0
  1491
            }
sl@0
  1492
        
sl@0
  1493
        file.Close();
sl@0
  1494
        return 0;
sl@0
  1495
sl@0
  1496
}
sl@0
  1497
sl@0
  1498
sl@0
  1499
TInt CLocale::ConvertToMultiByteL(TUint8* aNarrowCharString, const TText16* aWideCharString, TInt  aCharsetUID)
sl@0
  1500
{
sl@0
  1501
	//Create a handle to a file server session and connect to the file server. 
sl@0
  1502
	//Push it on to cleanup stack
sl@0
  1503
	RFs fileSession;
sl@0
  1504
	User::LeaveIfError(fileSession.Connect());
sl@0
  1505
	CleanupClosePushL(fileSession);
sl@0
  1506
	
sl@0
  1507
	//Allocate and constructs a CCnvCharacterSetConverter object
sl@0
  1508
	CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC();
sl@0
  1509
sl@0
  1510
	//Search the character set array  containing all of the character sets for which conversion is available
sl@0
  1511
	CCnvCharacterSetConverter::TAvailability  avail = conv->PrepareToConvertToOrFromL(aCharsetUID, fileSession);
sl@0
  1512
	if(CCnvCharacterSetConverter::ENotAvailable == avail)
sl@0
  1513
		{
sl@0
  1514
			CleanupStack::PopAndDestroy(2);
sl@0
  1515
			*aNarrowCharString = '\0';
sl@0
  1516
			return -1;	
sl@0
  1517
		}
sl@0
  1518
		
sl@0
  1519
	const TPtrC16 unicodeText(aWideCharString);
sl@0
  1520
	TBuf8<NON_UNICODE_TEXT_BUFFER_LENGTH> nativeText;
sl@0
  1521
	
sl@0
  1522
	TInt retVal = KErrNone;
sl@0
  1523
	TInt aNumberOfUnconvertibleCharacters = 0;
sl@0
  1524
	TInt aIndexOfFirstByteOfFirstUnconvertibleCharacter = 0;
sl@0
  1525
	
sl@0
  1526
	//Convert text encoded in the Unicode character set (UCS-2) into other character sets
sl@0
  1527
	retVal = conv->ConvertFromUnicode(nativeText,unicodeText, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
sl@0
  1528
	TInt returnCode = 0;
sl@0
  1529
	//Check for illegal characters in the input
sl@0
  1530
	if(retVal == CCnvCharacterSetConverter::EErrorIllFormedInput)
sl@0
  1531
	{
sl@0
  1532
		*aNarrowCharString = '\0';
sl@0
  1533
		returnCode = -1;
sl@0
  1534
	}
sl@0
  1535
	
sl@0
  1536
	//Check for incomplete characters in the input, set the errno accordingly
sl@0
  1537
	else if(aNumberOfUnconvertibleCharacters)
sl@0
  1538
	{
sl@0
  1539
		*aNarrowCharString = '\0';
sl@0
  1540
		returnCode = -1;
sl@0
  1541
	}
sl@0
  1542
	else
sl@0
  1543
	{
sl@0
  1544
	strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length());
sl@0
  1545
	aNarrowCharString[nativeText.Length()] = '\0';
sl@0
  1546
	returnCode = 0;
sl@0
  1547
	}
sl@0
  1548
	CleanupStack::PopAndDestroy(2); // conv, fileSession
sl@0
  1549
	return returnCode;
sl@0
  1550
	
sl@0
  1551
}
sl@0
  1552
sl@0
  1553
TInt CLocale::GetCharcaterSetIDL(const char* aLocaleName)
sl@0
  1554
{
sl@0
  1555
	//extract the charcate set name  from locale string
sl@0
  1556
	char* temp = strchr(aLocaleName, '.');
sl@0
  1557
	char locale[LOCALE_LENGTH];
sl@0
  1558
	if(NULL == temp)
sl@0
  1559
	{
sl@0
  1560
		return -1;
sl@0
  1561
	}
sl@0
  1562
	temp++;
sl@0
  1563
	int  j= 0;
sl@0
  1564
	while((*temp != '@') && *temp != '\0')
sl@0
  1565
	{
sl@0
  1566
		locale[j++]	 = *temp++;
sl@0
  1567
	}
sl@0
  1568
	locale[j++] = '\0';
sl@0
  1569
	
sl@0
  1570
	//Create a handle to a file server session and connect to the file server. 
sl@0
  1571
	//Push it on to cleanup stack
sl@0
  1572
	RFs fileSession;
sl@0
  1573
	User::LeaveIfError(fileSession.Connect());
sl@0
  1574
	CleanupClosePushL(fileSession);
sl@0
  1575
	
sl@0
  1576
	TInt characterSetUID = 0;
sl@0
  1577
	
sl@0
  1578
	//Allocate and constructs a CCnvCharacterSetConverter object
sl@0
  1579
	CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC() ;
sl@0
  1580
		
sl@0
  1581
	//Create an array identifying all the character sets for which conversion is available
sl@0
  1582
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet> *charSet = CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL(fileSession);
sl@0
  1583
	CleanupStack::PushL( charSet );
sl@0
  1584
	
sl@0
  1585
	TInt i = 0;
sl@0
  1586
	//Get the number of character sets for which conversion is available
sl@0
  1587
	TInt count = charSet->Count();
sl@0
  1588
	while(i < count)
sl@0
  1589
	{
sl@0
  1590
		CCnvCharacterSetConverter::SCharacterSet characterSet = charSet->At(i);	
sl@0
  1591
		i++;
sl@0
  1592
		//Get the UID of character set for which conversion is available
sl@0
  1593
		TUint charSetUID = characterSet.Identifier();
sl@0
  1594
				
sl@0
  1595
		const TBufC<CHARACTER_SET_NAME> charSetName = characterSet.NameIsFileName()?TParsePtrC(characterSet.Name()).Name():characterSet.Name();								
sl@0
  1596
		TBuf8<CHARACTER_SET_NAME> aCharSetname;
sl@0
  1597
		aCharSetname.Copy(charSetName);
sl@0
  1598
	
sl@0
  1599
		//Assign the character set UID
sl@0
  1600
		if(!aCharSetname.Compare(TPtrC8((const TText8*) locale)))
sl@0
  1601
		{
sl@0
  1602
			characterSetUID = charSetUID;
sl@0
  1603
			break;
sl@0
  1604
		}
sl@0
  1605
					
sl@0
  1606
		HBufC8*  stdInterName = conv->ConvertCharacterSetIdentifierToStandardNameL(charSetUID, fileSession);					
sl@0
  1607
		if(NULL != stdInterName)
sl@0
  1608
		{
sl@0
  1609
			if(!stdInterName->Compare(TPtrC8((const TText8*) locale)))
sl@0
  1610
			{
sl@0
  1611
				characterSetUID = charSetUID;
sl@0
  1612
				delete stdInterName;
sl@0
  1613
				stdInterName = NULL;		
sl@0
  1614
				break;
sl@0
  1615
			}
sl@0
  1616
			delete stdInterName;
sl@0
  1617
			stdInterName = NULL;			
sl@0
  1618
		}
sl@0
  1619
	}
sl@0
  1620
	
sl@0
  1621
	if(!characterSetUID)
sl@0
  1622
	{
sl@0
  1623
		characterSetUID =  -1;
sl@0
  1624
	}
sl@0
  1625
		
sl@0
  1626
	CleanupStack::PopAndDestroy(3); //charSet, conv, fileSession
sl@0
  1627
	return characterSetUID;
sl@0
  1628
}
sl@0
  1629
sl@0
  1630
/* ReadALine : Reads one line at a time from specified file */
sl@0
  1631
inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc)
sl@0
  1632
	{
sl@0
  1633
	TInt ret = aFile.Read(aPos, aDesc);
sl@0
  1634
	TChar delimOne = '\r';
sl@0
  1635
	TChar delimTwo = '\n';
sl@0
  1636
	
sl@0
  1637
	TInt len = aDesc.Length();
sl@0
  1638
	if(!ret && len)
sl@0
  1639
		{
sl@0
  1640
		//Always assumes that each line will end with "\r\n" except the last line
sl@0
  1641
		TInt pos = aDesc.Locate(delimOne);
sl@0
  1642
		pos = aDesc.Locate(delimTwo);
sl@0
  1643
			
sl@0
  1644
		if(KErrNotFound != pos)
sl@0
  1645
			{
sl@0
  1646
			aPos = aPos + pos + 1;
sl@0
  1647
			len = pos - 1;
sl@0
  1648
			aDesc.SetLength(len);
sl@0
  1649
			}
sl@0
  1650
		else
sl@0
  1651
			{
sl@0
  1652
			aPos = aPos + len;
sl@0
  1653
			}
sl@0
  1654
		}
sl@0
  1655
	return len;
sl@0
  1656
	}
sl@0
  1657
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1658
sl@0
  1659
void CLocale::ConvertToMultiByteCustom(TUint8* aNarrowCharString, const TText16* aWideCharString)
sl@0
  1660
	{
sl@0
  1661
	const TPtrC unicodeText(aWideCharString);
sl@0
  1662
	TBuf8<NON_UNICODE_TEXT_BUFFER_LENGTH> nativeText;
sl@0
  1663
    nativeText.Copy(unicodeText);
sl@0
  1664
    strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length());
sl@0
  1665
    aNarrowCharString[nativeText.Length()] = '\0';
sl@0
  1666
	}
sl@0
  1667
sl@0
  1668
TInt CLocale::SyncLocale(TLocaleAspect aspect)
sl@0
  1669
	{   
sl@0
  1670
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
  1671
	TBuf<NON_UNICODE_TEXT_BUFFER_LENGTH> reg_dllname;
sl@0
  1672
#endif
sl@0
  1673
	TBuf<NON_UNICODE_TEXT_BUFFER_LENGTH> Kdname;
sl@0
  1674
	TExtendedLocale locale;
sl@0
  1675
    locale.LoadSystemSettings();
sl@0
  1676
    locale.GetLocaleDllName(aspect,Kdname);
sl@0
  1677
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
  1678
    // check if the new  dlls is present then load it or go for old dll
sl@0
  1679
    if( Kdname.FindC(_L("elocl.")) == KErrNotFound ) 
sl@0
  1680
        {
sl@0
  1681
        iOldDllPresent = 0;
sl@0
  1682
        locale.GetLocaleDllName(ELocaleTimeDateSettings,reg_dllname);
sl@0
  1683
        return (GetSystemLocale(Kdname,reg_dllname ));
sl@0
  1684
        }
sl@0
  1685
    else
sl@0
  1686
        iOldDllPresent = 1;
sl@0
  1687
#endif
sl@0
  1688
    return (GetSystemLocale(Kdname));
sl@0
  1689
	}
sl@0
  1690
sl@0
  1691
const TText* CLocale::GetLocaleName(void)
sl@0
  1692
	{
sl@0
  1693
	TPtrC dllname(DllName);
sl@0
  1694
	return dllname.Ptr();
sl@0
  1695
	}
sl@0
  1696
sl@0
  1697
sl@0
  1698
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
sl@0
  1699
    
sl@0
  1700
const TText* CLocale::GetCollateLocaleName(void)
sl@0
  1701
    {
sl@0
  1702
        TPtrC dllname(ColDllName);
sl@0
  1703
        return dllname.Ptr(); 
sl@0
  1704
     }
sl@0
  1705
#endif
sl@0
  1706
sl@0
  1707
sl@0
  1708
#endif // SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
sl@0
  1709
sl@0
  1710
sl@0
  1711
sl@0
  1712