examples/Base/Locale/localeupdate/src/localeupdate.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // License: "Symbian Foundation License v1.0" to Symbian Foundation
00004 // members and "Symbian Foundation End User License Agreement v1.0"
00005 // to non-members at the URL
00006 // "http://www.symbianfoundation.org/legal/licencesv10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // Contains the definition of functions defined in the CLocaleSettings class.
00015 // It also contains the definition of the DoStartL()function.
00016 // This function displays a number of locale settings for a variety of locale DLLs.
00017 //
00018 
00019 
00020 
00024 #include "localeupdate.h"
00025 
00026 LOCAL_D CConsoleBase* console;
00027 
00028 LOCAL_C void DoStartL();
00029 
00030 LOCAL_C void CallExampleL();
00031 
00038 CLocaleSettings* CLocaleSettings::NewL(TDesC16& aLocaleDLLName, CConsoleBase* aConsole)
00039         {
00040         CLocaleSettings* self = new (ELeave) CLocaleSettings;
00041         CleanupStack::PushL(self);
00042         self->ConstructL(aLocaleDLLName, aConsole);
00043         CleanupStack::Pop(self);
00044         return self;
00045         }
00046 
00053 void CLocaleSettings::ConstructL(TDesC16& aLocaleDLLName, CConsoleBase* aConsole)
00054         {
00055         // Store the name of the locale DLL.
00056         iLocaleDLLName.Copy(aLocaleDLLName);
00057         iConsole = aConsole;
00058 
00059         // Load the locale DLL.
00060         User::LeaveIfError(iExtendedLocale.LoadLocale(iLocaleDLLName));
00061 
00062         // Get the TLocale object from TExtendedLocale.
00063         iLocale = iExtendedLocale.GetLocale();
00064 
00065         // Get the first day of the week.
00066         // Monday is enumerated to 0, Tuesday to 1 and so on.
00067         iStartOfWeek = iLocale->StartOfWeek();
00068 
00069         // Get the working days mask.
00070         // Least significant bit corresponds to Monday.
00071         // A bit is set if it is a working day.
00072         iWorkingDaysMask = iLocale->WorkDays();
00073 
00074         // Get the collation method for the locale.
00075         iCollationMethod = iExtendedLocale.GetPreferredCollationMethod();
00076 
00077         // Get the country code.
00078         iCountryCode = iLocale->CountryCode();
00079 
00080         // Get the date format.
00081         iDateFormat = iLocale->DateFormat();
00082 
00083         // Get the time format.
00084         iTimeFormat = iLocale->TimeFormat();
00085 
00086         // Get numeric value settings.
00087         iThousandsSeparator = iLocale->ThousandsSeparator();
00088         iDecimalSeparator = iLocale->DecimalSeparator();
00089 
00090         // Get the units of measurement.
00091         iUnitsFormat = iLocale->UnitsGeneral();
00092 
00093         // Get the time zone information.
00094         // A locale's time zone is defined as an offset from UTC.
00095         iUTCOffset = User::UTCOffset();
00096         }
00097 
00101 CLocaleSettings::CLocaleSettings()
00102         {
00103         }
00104 
00108 void CLocaleSettings::DisplayLocaleSettings()
00109         {
00110         // Print the name of the locale DLL.
00111         _LIT(KTextDLLName, "\r\nLocale Settings for the DLL:");
00112         console->Printf(KTextDLLName);
00113         console->Printf(iLocaleDLLName);
00114         console->Printf(KTextNewLine);
00115 
00116         // Print the calendar settings.
00117         _LIT(KTextCalenderSettings, "Calendar Settings:\r\n1. First day of the week: %d\r\n");
00118         iConsole->Printf(KTextCalenderSettings, iStartOfWeek);
00119 
00120         // Print the mask.
00121         _LIT(KTextWorkingDays, "2. Working days of the week [LSB - Monday]: %07b\r\n");
00122         iConsole->Printf(KTextWorkingDays, iWorkingDaysMask);
00123 
00124         // Print the collation method.
00125         _LIT(KTextCollationMethod, "Collation method:");
00126         iConsole->Printf(KTextCollationMethod);
00127         if(iCollationMethod.iFlags & TCollationMethod::EIgnoreNone)
00128                 {
00129                 _LIT(KTextIgnoreNone, "IgnoreNone\r\n");
00130                 iConsole->Printf(KTextIgnoreNone);
00131                 }
00132         else if(iCollationMethod.iFlags & TCollationMethod::ESwapCase)
00133                 {
00134                 _LIT(KTextSwapCase, "SwapCase\r\n");
00135                 iConsole->Printf(KTextSwapCase);
00136                 }
00137         else if(iCollationMethod.iFlags & TCollationMethod::EAccentsBackwards)
00138                 {
00139                 _LIT(KTextAccents, "AccentsBackwards\r\n");
00140                 iConsole->Printf(KTextAccents);
00141                 }
00142         else if(iCollationMethod.iFlags & TCollationMethod::ESwapKana)
00143                 {
00144                 _LIT(KTextSwapKana, "SwapKana\r\n");
00145                 iConsole->Printf(KTextSwapKana);
00146                 }
00147         else if(iCollationMethod.iFlags & TCollationMethod::EFoldCase)
00148                 {
00149                 _LIT(KTextFoldCase, "FoldCase\r\n");
00150                 iConsole->Printf(KTextFoldCase);
00151                 }
00152         else
00153                 {
00154                 _LIT(KTextStandard, "Standard\r\n");
00155                 iConsole->Printf(KTextStandard);
00156                 }
00157 
00158         // Print the country code.
00159         _LIT(KTextCountryCode, "Country code: %d\r\n");
00160         iConsole->Printf(KTextCountryCode, iCountryCode);
00161 
00162         // Get the currency format.
00163         TBuf<50> currency;
00164         // A value for the currency.
00165         TInt currencyValue = 10241024;
00166         iLocale->FormatCurrency(currency, currencyValue);
00167         // Print the currency format.
00168         _LIT(KTextCurrencyFormat, "Currency format of %d:");
00169         iConsole->Printf(KTextCurrencyFormat, currencyValue);
00170         iConsole->Printf(currency);
00171         iConsole->Printf(KTextNewLine);
00172 
00173         // Print the date format.
00174         _LIT(KTextDateFormat, "Date Format: ");
00175         iConsole->Printf(KTextDateFormat);
00176         switch(iDateFormat)
00177                 {
00178                 case EDateAmerican:
00179                         _LIT(KTextUSFormat, "US Format (mm/dd/yy)\r\n");
00180                         iConsole->Printf(KTextUSFormat);
00181                         break;
00182                 case EDateEuropean:
00183                         _LIT(KTextEuropeanFormat, "European format (dd/mm/yyyy)\r\n");
00184                         iConsole->Printf(KTextEuropeanFormat);
00185                         break;
00186                 case EDateJapanese:
00187                         _LIT(KTextJapFormat, "Japanese format (yyyy/mm/dd)\r\n");
00188                         iConsole->Printf(KTextJapFormat);
00189                         break;
00190                 }
00191 
00192         // Print the time format.
00193         _LIT(KTextTimeFormat, "Time Format: ");
00194         iConsole->Printf(KTextTimeFormat);
00195         if(iTimeFormat == ETime12)
00196                 {
00197                 _LIT(KText12Hour, "12 hour format\r\n");
00198                 iConsole->Printf(KText12Hour);
00199                 }
00200         else
00201                 {
00202                 _LIT(KText24Hour, "24 hour format\r\n");
00203                 iConsole->Printf(KText24Hour);
00204                 }
00205 
00206         // Print the numeric value settings.
00207         _LIT(KTextNumericValues, "Numeric Values: \r\n");
00208         iConsole->Printf(KTextNumericValues);
00209         _LIT(KTextThousandsSeparator, "\tThousands separator: %c\r\n");
00210         iConsole->Printf(KTextThousandsSeparator, TUint(iThousandsSeparator));
00211         _LIT(KTextDecimalSeparator, "\tDecimal separator: %c\r\n");
00212         iConsole->Printf(KTextDecimalSeparator, TUint(iDecimalSeparator));
00213 
00214         // Print the time zone information.
00215         _LIT(KTextTimeZone, "UTC Offset in seconds (Time Zone Information): %d\r\n");
00216         iConsole->Printf(KTextTimeZone, iUTCOffset.Int());
00217 
00218         // Print the units of measurement.
00219         _LIT(KTextUnitsOfMeasure, "Units of measurement: ");
00220         iConsole->Printf(KTextUnitsOfMeasure);
00221         if(iUnitsFormat == EUnitsImperial)
00222                 {
00223                 _LIT(KTextImperial, "Imperial\r\n");
00224                 iConsole->Printf(KTextImperial);
00225                 }
00226         else
00227                 {
00228                 _LIT(KTextMetric, "Metric\r\n");
00229                 iConsole->Printf(KTextMetric);
00230                 }
00231         }
00232 
00236 CLocaleSettings::~CLocaleSettings()
00237         {
00238         }
00239 
00240 LOCAL_C void DoStartL()
00241         {
00242         // UK English locale DLL.
00243         _LIT(KLocaleName1, "elocl.01");
00244         TBufC<KLength> localeName1(KLocaleName1);
00245         // Create a CLocaleSettings object for the locale DLL eloc1.01.
00246         CLocaleSettings* obj = CLocaleSettings::NewL(localeName1, console);
00247         CleanupStack::PushL(obj);
00248         // Display the locale settings for the locale DLL eloc1.01.
00249         obj->DisplayLocaleSettings();
00250         // Delete the CLocaleSettings object.
00251         CleanupStack::PopAndDestroy(obj);
00252         // Wait for a key press.
00253         console->Printf(KTextPressAnyKey);
00254         console->Getch();
00255 
00256         // American locale DLL.
00257         _LIT(KLocaleName2, "elocl.10");
00258         TBufC<KLength> localeName2(KLocaleName2);
00259         // Create a CLocaleSettings object for the locale DLL eloc1.10.
00260         obj = CLocaleSettings::NewL(localeName2, console);
00261         CleanupStack::PushL(obj);
00262         // Display the locale settings for the locale DLL eloc1.10.
00263         obj->DisplayLocaleSettings();
00264         // Delete the CLocaleSettings object.
00265         CleanupStack::PopAndDestroy(obj);
00266         // Wait for a key press.
00267         console->Printf(KTextPressAnyKey);
00268         console->Getch();
00269 
00270         // Taiwanese Chinese locale DLL.
00271         _LIT(KLocaleName3, "elocl.29");
00272         TBufC<KLength> localeName3(KLocaleName3);
00273         // Create a CLocaleSettings object for the locale DLL eloc1.29.
00274         obj = CLocaleSettings::NewL(localeName3, console);
00275         CleanupStack::PushL(obj);
00276         // Display the locale settings for the locale DLL eloc1.29.
00277         obj->DisplayLocaleSettings();
00278         // Delete the CLocaleSettings object.
00279         CleanupStack::PopAndDestroy(obj);
00280         // Wait for a key press.
00281         console->Printf(KTextPressAnyKey);
00282         console->Getch();
00283 
00284         // Japanese locale DLL.
00285         _LIT(KLocaleName4, "elocl.32");
00286         TBufC<KLength> localeName4(KLocaleName4);
00287         // Create a CLocaleSettings object for the locale DLL eloc1.32.
00288         obj = CLocaleSettings::NewL(localeName4, console);
00289         CleanupStack::PushL(obj);
00290         // Display the locale settings for the locale DLL eloc1.32.
00291         obj->DisplayLocaleSettings();
00292         // Delete the CLocaleSettings object.
00293         CleanupStack::PopAndDestroy(obj);
00294         }
00295 
00296 GLDEF_C TInt E32Main() // main function called by E32
00297     {
00298         __UHEAP_MARK;
00299         CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
00300         TRAPD(error, CallExampleL()); // more initialization, then do example
00301         delete cleanup; // destroy clean-up stack
00302         __ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32EX, error));
00303         __UHEAP_MARKEND;
00304         return 0; // and return
00305     }
00306 
00307 LOCAL_C void CallExampleL() // initialize and call example code under cleanup stack
00308     {
00309         console=Console::NewL(KTxtExampleCode, TSize(KConsFullScreen, KConsFullScreen));
00310         CleanupStack::PushL(console);
00311         TRAPD(error, DoStartL()); // perform example function
00312         if (error)
00313                 console->Printf(KFormatFailed, error);
00314         else
00315                 console->Printf(KTxtOK);
00316         console->Printf(KTextPressAnyKey);
00317         console->Getch(); // get and ignore character
00318         CleanupStack::PopAndDestroy(); // close console
00319     }

Generated by  doxygen 1.6.2