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

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008 � list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010 � this list of conditions and the following disclaimer in the documentation
00011 � and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013 � may be used to endorse or promote products derived from this software
00014 � without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:�
00028 Contains the definition of functions defined in the CLocaleSettings class.
00029 It also contains the definition of the DoStartL()function.
00030 This function displays a number of locale settings for a variety of locale DLLs. 
00031 */
00032 
00033 
00034 
00035 
00039 #include "localeupdate.h"
00040 
00041 LOCAL_D CConsoleBase* console;
00042 
00043 LOCAL_C void DoStartL();
00044 
00045 LOCAL_C void CallExampleL();
00046 
00053 CLocaleSettings* CLocaleSettings::NewL(TDesC16& aLocaleDLLName, CConsoleBase* aConsole)
00054         {
00055         CLocaleSettings* self = new (ELeave) CLocaleSettings;
00056         CleanupStack::PushL(self);
00057         self->ConstructL(aLocaleDLLName, aConsole);
00058         CleanupStack::Pop(self);
00059         return self;
00060         }
00061 
00068 void CLocaleSettings::ConstructL(TDesC16& aLocaleDLLName, CConsoleBase* aConsole)
00069         {
00070         // Store the name of the locale DLL.
00071         iLocaleDLLName.Copy(aLocaleDLLName);
00072         iConsole = aConsole;
00073 
00074         // Load the locale DLL.
00075         User::LeaveIfError(iExtendedLocale.LoadLocale(iLocaleDLLName));
00076 
00077         // Get the TLocale object from TExtendedLocale.
00078         iLocale = iExtendedLocale.GetLocale();
00079 
00080         // Get the first day of the week.
00081         // Monday is enumerated to 0, Tuesday to 1 and so on.
00082         iStartOfWeek = iLocale->StartOfWeek();
00083 
00084         // Get the working days mask.
00085         // Least significant bit corresponds to Monday.
00086         // A bit is set if it is a working day.
00087         iWorkingDaysMask = iLocale->WorkDays();
00088 
00089         // Get the collation method for the locale.
00090         iCollationMethod = iExtendedLocale.GetPreferredCollationMethod();
00091 
00092         // Get the country code.
00093         iCountryCode = iLocale->CountryCode();
00094 
00095         // Get the date format.
00096         iDateFormat = iLocale->DateFormat();
00097 
00098         // Get the time format.
00099         iTimeFormat = iLocale->TimeFormat();
00100 
00101         // Get numeric value settings.
00102         iThousandsSeparator = iLocale->ThousandsSeparator();
00103         iDecimalSeparator = iLocale->DecimalSeparator();
00104 
00105         // Get the units of measurement.
00106         iUnitsFormat = iLocale->UnitsGeneral();
00107 
00108         // Get the time zone information.
00109         // A locale's time zone is defined as an offset from UTC.
00110         iUTCOffset = User::UTCOffset();
00111         }
00112 
00116 CLocaleSettings::CLocaleSettings()
00117         {
00118         }
00119 
00123 void CLocaleSettings::DisplayLocaleSettings()
00124         {
00125         // Print the name of the locale DLL.
00126         _LIT(KTextDLLName, "\r\nLocale Settings for the DLL:");
00127         console->Printf(KTextDLLName);
00128         console->Printf(iLocaleDLLName);
00129         console->Printf(KTextNewLine);
00130 
00131         // Print the calendar settings.
00132         _LIT(KTextCalenderSettings, "Calendar Settings:\r\n1. First day of the week: %d\r\n");
00133         iConsole->Printf(KTextCalenderSettings, iStartOfWeek);
00134 
00135         // Print the mask.
00136         _LIT(KTextWorkingDays, "2. Working days of the week [LSB - Monday]: %07b\r\n");
00137         iConsole->Printf(KTextWorkingDays, iWorkingDaysMask);
00138 
00139         // Print the collation method.
00140         _LIT(KTextCollationMethod, "Collation method:");
00141         iConsole->Printf(KTextCollationMethod);
00142         if(iCollationMethod.iFlags & TCollationMethod::EIgnoreNone)
00143                 {
00144                 _LIT(KTextIgnoreNone, "IgnoreNone\r\n");
00145                 iConsole->Printf(KTextIgnoreNone);
00146                 }
00147         else if(iCollationMethod.iFlags & TCollationMethod::ESwapCase)
00148                 {
00149                 _LIT(KTextSwapCase, "SwapCase\r\n");
00150                 iConsole->Printf(KTextSwapCase);
00151                 }
00152         else if(iCollationMethod.iFlags & TCollationMethod::EAccentsBackwards)
00153                 {
00154                 _LIT(KTextAccents, "AccentsBackwards\r\n");
00155                 iConsole->Printf(KTextAccents);
00156                 }
00157         else if(iCollationMethod.iFlags & TCollationMethod::ESwapKana)
00158                 {
00159                 _LIT(KTextSwapKana, "SwapKana\r\n");
00160                 iConsole->Printf(KTextSwapKana);
00161                 }
00162         else if(iCollationMethod.iFlags & TCollationMethod::EFoldCase)
00163                 {
00164                 _LIT(KTextFoldCase, "FoldCase\r\n");
00165                 iConsole->Printf(KTextFoldCase);
00166                 }
00167         else
00168                 {
00169                 _LIT(KTextStandard, "Standard\r\n");
00170                 iConsole->Printf(KTextStandard);
00171                 }
00172 
00173         // Print the country code.
00174         _LIT(KTextCountryCode, "Country code: %d\r\n");
00175         iConsole->Printf(KTextCountryCode, iCountryCode);
00176 
00177         // Get the currency format.
00178         TBuf<50> currency;
00179         // A value for the currency.
00180         TInt currencyValue = 10241024;
00181         iLocale->FormatCurrency(currency, currencyValue);
00182         // Print the currency format.
00183         _LIT(KTextCurrencyFormat, "Currency format of %d:");
00184         iConsole->Printf(KTextCurrencyFormat, currencyValue);
00185         iConsole->Printf(currency);
00186         iConsole->Printf(KTextNewLine);
00187 
00188         // Print the date format.
00189         _LIT(KTextDateFormat, "Date Format: ");
00190         iConsole->Printf(KTextDateFormat);
00191         switch(iDateFormat)
00192                 {
00193                 case EDateAmerican:
00194                         _LIT(KTextUSFormat, "US Format (mm/dd/yy)\r\n");
00195                         iConsole->Printf(KTextUSFormat);
00196                         break;
00197                 case EDateEuropean:
00198                         _LIT(KTextEuropeanFormat, "European format (dd/mm/yyyy)\r\n");
00199                         iConsole->Printf(KTextEuropeanFormat);
00200                         break;
00201                 case EDateJapanese:
00202                         _LIT(KTextJapFormat, "Japanese format (yyyy/mm/dd)\r\n");
00203                         iConsole->Printf(KTextJapFormat);
00204                         break;
00205                 }
00206 
00207         // Print the time format.
00208         _LIT(KTextTimeFormat, "Time Format: ");
00209         iConsole->Printf(KTextTimeFormat);
00210         if(iTimeFormat == ETime12)
00211                 {
00212                 _LIT(KText12Hour, "12 hour format\r\n");
00213                 iConsole->Printf(KText12Hour);
00214                 }
00215         else
00216                 {
00217                 _LIT(KText24Hour, "24 hour format\r\n");
00218                 iConsole->Printf(KText24Hour);
00219                 }
00220 
00221         // Print the numeric value settings.
00222         _LIT(KTextNumericValues, "Numeric Values: \r\n");
00223         iConsole->Printf(KTextNumericValues);
00224         _LIT(KTextThousandsSeparator, "\tThousands separator: %c\r\n");
00225         iConsole->Printf(KTextThousandsSeparator, TUint(iThousandsSeparator));
00226         _LIT(KTextDecimalSeparator, "\tDecimal separator: %c\r\n");
00227         iConsole->Printf(KTextDecimalSeparator, TUint(iDecimalSeparator));
00228 
00229         // Print the time zone information.
00230         _LIT(KTextTimeZone, "UTC Offset in seconds (Time Zone Information): %d\r\n");
00231         iConsole->Printf(KTextTimeZone, iUTCOffset.Int());
00232 
00233         // Print the units of measurement.
00234         _LIT(KTextUnitsOfMeasure, "Units of measurement: ");
00235         iConsole->Printf(KTextUnitsOfMeasure);
00236         if(iUnitsFormat == EUnitsImperial)
00237                 {
00238                 _LIT(KTextImperial, "Imperial\r\n");
00239                 iConsole->Printf(KTextImperial);
00240                 }
00241         else
00242                 {
00243                 _LIT(KTextMetric, "Metric\r\n");
00244                 iConsole->Printf(KTextMetric);
00245                 }
00246         }
00247 
00251 CLocaleSettings::~CLocaleSettings()
00252         {
00253         }
00254 
00255 LOCAL_C void DoStartL()
00256         {
00257         // UK English locale DLL.
00258         _LIT(KLocaleName1, "elocl.01");
00259         TBufC<KLength> localeName1(KLocaleName1);
00260         // Create a CLocaleSettings object for the locale DLL eloc1.01.
00261         CLocaleSettings* obj = CLocaleSettings::NewL(localeName1, console);
00262         CleanupStack::PushL(obj);
00263         // Display the locale settings for the locale DLL eloc1.01.
00264         obj->DisplayLocaleSettings();
00265         // Delete the CLocaleSettings object.
00266         CleanupStack::PopAndDestroy(obj);
00267         // Wait for a key press.
00268         console->Printf(KTextPressAnyKey);
00269         console->Getch();
00270 
00271         // American locale DLL.
00272         _LIT(KLocaleName2, "elocl.10");
00273         TBufC<KLength> localeName2(KLocaleName2);
00274         // Create a CLocaleSettings object for the locale DLL eloc1.10.
00275         obj = CLocaleSettings::NewL(localeName2, console);
00276         CleanupStack::PushL(obj);
00277         // Display the locale settings for the locale DLL eloc1.10.
00278         obj->DisplayLocaleSettings();
00279         // Delete the CLocaleSettings object.
00280         CleanupStack::PopAndDestroy(obj);
00281         // Wait for a key press.
00282         console->Printf(KTextPressAnyKey);
00283         console->Getch();
00284 
00285         // Taiwanese Chinese locale DLL.
00286         _LIT(KLocaleName3, "elocl.29");
00287         TBufC<KLength> localeName3(KLocaleName3);
00288         // Create a CLocaleSettings object for the locale DLL eloc1.29.
00289         obj = CLocaleSettings::NewL(localeName3, console);
00290         CleanupStack::PushL(obj);
00291         // Display the locale settings for the locale DLL eloc1.29.
00292         obj->DisplayLocaleSettings();
00293         // Delete the CLocaleSettings object.
00294         CleanupStack::PopAndDestroy(obj);
00295         // Wait for a key press.
00296         console->Printf(KTextPressAnyKey);
00297         console->Getch();
00298 
00299         // Japanese locale DLL.
00300         _LIT(KLocaleName4, "elocl.32");
00301         TBufC<KLength> localeName4(KLocaleName4);
00302         // Create a CLocaleSettings object for the locale DLL eloc1.32.
00303         obj = CLocaleSettings::NewL(localeName4, console);
00304         CleanupStack::PushL(obj);
00305         // Display the locale settings for the locale DLL eloc1.32.
00306         obj->DisplayLocaleSettings();
00307         // Delete the CLocaleSettings object.
00308         CleanupStack::PopAndDestroy(obj);
00309         }
00310 
00311 GLDEF_C TInt E32Main() // main function called by E32
00312     {
00313         __UHEAP_MARK;
00314         CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
00315         TRAPD(error, CallExampleL()); // more initialization, then do example
00316         delete cleanup; // destroy clean-up stack
00317         __ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32EX, error));
00318         __UHEAP_MARKEND;
00319         return 0; // and return
00320     }
00321 
00322 LOCAL_C void CallExampleL() // initialize and call example code under cleanup stack
00323     {
00324         console=Console::NewL(KTxtExampleCode, TSize(KConsFullScreen, KConsFullScreen));
00325         CleanupStack::PushL(console);
00326         TRAPD(error, DoStartL()); // perform example function
00327         if (error)
00328                 console->Printf(KFormatFailed, error);
00329         else
00330                 console->Printf(KTxtOK);
00331         console->Printf(KTextPressAnyKey);
00332         console->Getch(); // get and ignore character
00333         CleanupStack::PopAndDestroy(); // close console
00334     }

Generated by  doxygen 1.6.2