calendarui/regionalplugins/KoreanLunar/src/CalenLunarLocalizer.cpp
branchRCL_3
changeset 31 97232defd20e
equal deleted inserted replaced
30:bd7edf625bdd 31:97232defd20e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 *  Description : Class looking after alarm fields for forms.
       
    15 *
       
    16 */
       
    17 
       
    18 //debug
       
    19 #include "calendarui_debug.h"
       
    20 #include "CalenLunarLocalizer.h"
       
    21 #include "CalenLunarInfo.h"
       
    22 #include "CalenLunarLocalizedInfo.h"
       
    23 #include "CalenExtraRowFormatter.h"
       
    24 #include <calenkoreanlunarplugindata.rsg>
       
    25 
       
    26 //system includes
       
    27 #include <aknbiditextutils.h>
       
    28 #include <avkon.rsg>
       
    29 #include <badesca.h>
       
    30 #include <eikenv.h>
       
    31 #include <StringLoader.h>
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CCalenLunarLocalizer::NewL()
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CCalenLunarLocalizer* CCalenLunarLocalizer::NewL()
       
    41     {
       
    42     TRACE_ENTRY_POINT;
       
    43 
       
    44     CCalenLunarLocalizer* self = new (ELeave) CCalenLunarLocalizer;
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop(self);
       
    48 
       
    49     TRACE_EXIT_POINT;
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CCalenLunarLocalizer::~CCalenLunarLocalizer()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CCalenLunarLocalizer::~CCalenLunarLocalizer()
       
    58     {
       
    59     TRACE_ENTRY_POINT;
       
    60 
       
    61     delete iLunarFestivalNames;
       
    62     delete iSolarFestivalNames;
       
    63     delete iSolarTermNames;
       
    64     delete iGregorianDateFormat;
       
    65     delete iRowFormatter;
       
    66 
       
    67     TRACE_EXIT_POINT;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CCalenLunarLocalizer::CCalenLunarLocalizer()
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CCalenLunarLocalizer::CCalenLunarLocalizer() : iEikEnv( CEikonEnv::Static() )
       
    75     {
       
    76     TRACE_ENTRY_POINT;
       
    77     TRACE_EXIT_POINT;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CCalenLunarLocalizer::ConstructL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CCalenLunarLocalizer::ConstructL()
       
    85     {
       
    86     TRACE_ENTRY_POINT;
       
    87 
       
    88     iRowFormatter = CCalenExtraRowFormatter::NewL();
       
    89 
       
    90     iLunarFestivalNames = iEikEnv->ReadDesCArrayResourceL(R_CALEN_KOR_FESTIVALS);
       
    91     iSolarFestivalNames = iEikEnv->ReadDesCArrayResourceL(R_CALEN_KOR_SOLAR_ANNIVERSARY_ITEMS);
       
    92     iSolarTermNames = iEikEnv->ReadDesCArrayResourceL(R_CALEN_KOR_SOLAR_ITEMS);
       
    93     iGregorianDateFormat = StringLoader::LoadL(R_QTN_DATE_USUAL_WITH_ZERO);
       
    94 
       
    95     TRACE_EXIT_POINT;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CCalenLunarLocalizer::LocalizeL()
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CCalenLunarLocalizedInfo* CCalenLunarLocalizer::LocalizeL( TCalenLunarInfo& aInfo )
       
   103     {
       
   104     TRACE_ENTRY_POINT;
       
   105 
       
   106     CCalenLunarLocalizedInfo* localized = CCalenLunarLocalizedInfo::NewL();
       
   107     CleanupStack::PushL( localized );
       
   108 
       
   109     if ( aInfo.HasLunarFestival() )
       
   110         {
       
   111         localized->iLunarFestival.Set( iLunarFestivalNames->MdcaPoint( aInfo.iLunarFestival ) );
       
   112         }
       
   113 
       
   114     if ( aInfo.HasSolarFestival() )
       
   115         {
       
   116         localized->iSolarFestival.Set( iSolarFestivalNames->MdcaPoint( aInfo.iSolarFestival ) );
       
   117         }
       
   118 
       
   119     if ( aInfo.HasSolarTerm() )
       
   120         {
       
   121         localized->iSolarTerm.Set( iSolarTermNames->MdcaPoint( aInfo.iSolarTerm ) );
       
   122         }
       
   123 
       
   124     LocalizeMonthAndDayL(localized, aInfo);
       
   125 
       
   126     aInfo.iGregorianDate.FormatL( localized->iGregorianDate,
       
   127                                  *iGregorianDateFormat );
       
   128     CleanupStack::Pop( localized );
       
   129 
       
   130     TRACE_EXIT_POINT;
       
   131     return localized;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CCalenLunarLocalizer::GetExtraRowTextL()
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 TPtrC CCalenLunarLocalizer::GetExtraRowTextL( CCalenLunarLocalizedInfo& aLocInfo, 
       
   139         TInt aMaxWidth, const CFont& aFont
       
   140 #ifdef RD_CALENDAR_PREVIEW
       
   141                                               , TBool aTwoLines
       
   142 #endif // RD_CALENDAR_PREVIEW
       
   143                                               )
       
   144     {
       
   145     TRACE_ENTRY_POINT;
       
   146 
       
   147     RArray<CCalenLunarLocalizedInfo::TField> fields;
       
   148     CleanupClosePushL( fields );
       
   149 
       
   150     fields.AppendL( CCalenLunarLocalizedInfo::ELunarMonthAndDay );  //1st priority
       
   151     fields.AppendL( CCalenLunarLocalizedInfo::ESolarFestival );     //2nd priority
       
   152     fields.AppendL( CCalenLunarLocalizedInfo::ELunarFestival );     //3rd priority
       
   153     fields.AppendL( CCalenLunarLocalizedInfo::ESolarTerm );         //4th priority
       
   154 
       
   155     TPtrC text = iRowFormatter->FormatExtraRowInformationL( aLocInfo, fields, aMaxWidth, aFont
       
   156 #ifdef RD_CALENDAR_PREVIEW
       
   157                                                             , aTwoLines
       
   158 #endif // RD_CALENDAR_PREVIEW
       
   159                                                             );
       
   160     CleanupStack::PopAndDestroy( &fields );
       
   161 
       
   162     TRACE_EXIT_POINT;
       
   163     return text;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CCalenLunarLocalizer::LocalizeMonthAndDayL()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CCalenLunarLocalizer::LocalizeMonthAndDayL( CCalenLunarLocalizedInfo* aLocInfo,
       
   171         TCalenLunarInfo& aInfo )
       
   172     {
       
   173     TRACE_ENTRY_POINT;
       
   174     
       
   175     TInt dateResource = R_CALE_KOR_LUNAR_DATE;    
       
   176     HBufC* lunar_indicator_year = StringLoader::LoadLC( R_CALE_KOR_LUNAR_INDICATOR );    
       
   177     HBufC* lunar_leap_year = StringLoader::LoadLC( R_CALE_KOR_LEAP_YEAR_INDICATOR );
       
   178 
       
   179     TBuf16<2> month;
       
   180     TBuf16<2> day;
       
   181     HBufC* lunar_indicator_buf = HBufC::NewLC(lunar_indicator_year->Length()+lunar_leap_year->Length());
       
   182     lunar_indicator_buf->Des().Append(*lunar_indicator_year);
       
   183     TPtr lunar_indicator = lunar_indicator_buf->Des(); 
       
   184         
       
   185     if ( aInfo.iLunarDate.iLeapMonth )
       
   186         {
       
   187         lunar_indicator.Append(*lunar_leap_year);
       
   188         }
       
   189 
       
   190     month.AppendNum( aInfo.iLunarDate.iMonth );
       
   191     day.AppendNum( aInfo.iLunarDate.iDay );
       
   192 
       
   193     CPtrCArray* monthAndDaySubs = new (ELeave) CPtrCArray(3);
       
   194     CleanupStack::PushL( monthAndDaySubs );
       
   195 
       
   196     monthAndDaySubs->AppendL( lunar_indicator );
       
   197     monthAndDaySubs->AppendL( month );
       
   198     monthAndDaySubs->AppendL( day );
       
   199 
       
   200     HBufC* tmp = StringLoader::LoadLC( dateResource, *monthAndDaySubs );
       
   201     aLocInfo->iLunarMonthAndDay = *tmp;
       
   202     CleanupStack::PopAndDestroy( tmp );
       
   203     CleanupStack::PopAndDestroy( monthAndDaySubs );
       
   204     
       
   205     CleanupStack::PopAndDestroy( lunar_indicator_buf );
       
   206     CleanupStack::PopAndDestroy( lunar_leap_year );
       
   207     CleanupStack::PopAndDestroy( lunar_indicator_year ); 
       
   208     
       
   209     TRACE_EXIT_POINT;
       
   210     }
       
   211 
       
   212 // End of file