14 * Description: Calendar Lunar Plugin |
14 * Description: Calendar Lunar Plugin |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <eikenv.h> |
|
20 #include <StringLoader.h> |
|
21 #include <data_caging_path_literals.hrh> |
|
22 #include <bautils.h> |
|
23 #include <CalenLunarChinesePluginData.rsg> |
|
24 |
|
25 #include <QString> |
19 #include <QString> |
|
20 #include <QStringList> |
|
21 #include <QTranslator> |
26 #include <HbAction> |
22 #include <HbAction> |
27 #include <HbView> |
23 #include <HbView> |
28 #include <HbMenu> |
24 #include <HbMenu> |
29 #include <HbMessageBox> |
25 #include <HbMessageBox> |
30 #include <HbLabel> |
26 #include <HbLabel> |
|
27 #include <HbApplication> |
|
28 |
|
29 #include <eikenv.h> |
|
30 #include <data_caging_path_literals.hrh> |
|
31 #include <bautils.h> |
31 |
32 |
32 #include "calendarui_debug.h" |
33 #include "calendarui_debug.h" |
33 #include "CalenLunarChinesePlugin.h" |
34 #include "CalenLunarChinesePlugin.h" |
34 #include "CalenLunarPanic.h" |
35 #include "CalenLunarPanic.h" |
35 #include "CalenLunarLocalizedInfo.h" |
36 #include "CalenLunarLocalizedInfo.h" |
36 #include "CalenLunarLocalizer.h" |
37 #include "CalenLunarLocalizer.h" |
37 #include "CalenLunarInfoProvider.h" |
38 #include "CalenLunarInfoProvider.h" |
|
39 #include "CalendarPrivateCRKeys.h" |
38 #include "hb_calencommands.hrh" |
40 #include "hb_calencommands.hrh" |
39 |
41 |
40 //CONSTANTS |
42 //CONSTANTS |
41 _LIT( KFieldSeparator, "\n" ); |
43 static const QString fieldSeparator("\n"); |
42 _LIT( KHeaderSeparator, "\n "); |
44 static const QString headerSeparator("\n "); |
43 _LIT( KResourceChinesePluginFile, "calenlunarchineseplugindata.rsc" ); |
|
44 #define KResourcePath KDC_RESOURCE_FILES_DIR |
|
45 |
45 |
46 const TInt KFieldCount = 5; |
46 const TInt KFieldCount = 5; |
47 |
47 |
48 |
48 |
49 // ============================ MEMBER FUNCTIONS =============================== |
49 // ============================ MEMBER FUNCTIONS =============================== |
104 |
103 |
105 delete iInfoProvider; |
104 delete iInfoProvider; |
106 delete iLocalizer; |
105 delete iLocalizer; |
107 delete iLocInfo; |
106 delete iLocInfo; |
108 |
107 |
109 if( iResourceFileOffset ) |
108 // Remove the translator for plugin |
110 { |
109 HbApplication::instance()->removeTranslator(iTranslator); |
111 CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset ); |
110 if (iTranslator) { |
112 } |
111 delete iTranslator; |
|
112 iTranslator = 0; |
|
113 } |
113 TRACE_EXIT_POINT; |
114 TRACE_EXIT_POINT; |
114 } |
115 } |
115 |
116 |
116 // ----------------------------------------------------------------------------- |
117 // ----------------------------------------------------------------------------- |
117 // CCalenLunarChinesePlugin::ContructL |
118 // CCalenLunarChinesePlugin::ContructL |
118 // ----------------------------------------------------------------------------- |
119 // ----------------------------------------------------------------------------- |
119 // |
120 // |
120 void CCalenLunarChinesePlugin::ConstructL() |
121 void CCalenLunarChinesePlugin::ConstructL() |
121 { |
122 { |
122 TRACE_ENTRY_POINT; |
123 TRACE_ENTRY_POINT; |
123 |
|
124 TFileName dllName; |
|
125 // Get the complate path of the DLL from where it is currently loaded |
|
126 Dll::FileName( dllName ); |
|
127 |
|
128 TFileName resourceFilename; |
|
129 resourceFilename.Append(dllName.Mid(0,2)); |
|
130 resourceFilename.Append(KResourcePath); |
|
131 resourceFilename.Append(KResourceChinesePluginFile); |
|
132 BaflUtils::NearestLanguageFile( CEikonEnv::Static()->FsSession(), |
|
133 resourceFilename ); |
|
134 // Add the resource file. |
|
135 iResourceFileOffset = CEikonEnv::Static()->AddResourceFileL( |
|
136 resourceFilename ); |
|
137 |
|
138 iServices->RegisterForNotificationsL( this, ECalenNotifyContextChanged ); |
124 iServices->RegisterForNotificationsL( this, ECalenNotifyContextChanged ); |
139 iServices->GetCommandRange( iStart, iEnd ); |
125 iServices->GetCommandRange( iStart, iEnd ); |
140 |
126 |
|
127 // Install the translator before the CCalenLunarLocalizer is constructed |
|
128 iTranslator = new QTranslator; |
|
129 QString lang = QLocale::system().name(); |
|
130 QString path = "Z:/resource/qt/translations/"; |
|
131 bool loaded = iTranslator->load("calenregional_en_GB", ":/translations"); |
|
132 // TODO: Load the appropriate .qm file based on locale |
|
133 //bool loaded = iTranslator->load("calenregional_" + lang, path); |
|
134 HbApplication::instance()->installTranslator(iTranslator); |
|
135 |
141 iLocalizer = CCalenLunarLocalizer::NewL(); |
136 iLocalizer = CCalenLunarLocalizer::NewL(); |
142 |
137 |
143 iInfoProvider = CCalenLunarInfoProvider::NewL( |
138 iInfoProvider = CCalenLunarInfoProvider::NewL( |
144 CEikonEnv::Static()->FsSession() ); |
139 CEikonEnv::Static()->FsSession() ); |
|
140 |
145 |
141 |
146 TRACE_EXIT_POINT; |
142 TRACE_EXIT_POINT; |
147 } |
143 } |
148 |
144 |
149 // ----------------------------------------------------------------------------- |
145 // ----------------------------------------------------------------------------- |
309 // CCalenLunarChinesePlugin::ShowDetailsL |
305 // CCalenLunarChinesePlugin::ShowDetailsL |
310 // Message popup from menu |
306 // Message popup from menu |
311 // ----------------------------------------------------------------------------- |
307 // ----------------------------------------------------------------------------- |
312 // |
308 // |
313 void CCalenLunarChinesePlugin::ShowDetailsL( ) |
309 void CCalenLunarChinesePlugin::ShowDetailsL( ) |
314 { |
310 { |
315 TRACE_ENTRY_POINT; |
311 QString msgText; |
316 HBufC* msgText = HBufC::NewLC( 1000 ); |
312 if(iLocInfo) { |
317 if ( iLocInfo ) |
313 QStringList headerIds; |
318 { |
314 headerIds.append(hbTrId("txt_calendar_info_festival")); |
319 TInt headerIds[KFieldCount] = { |
315 headerIds.append(hbTrId("txt_calendar_solar_term")); |
320 R_CALENDAR_LUNAR_INFO_FESTIVAL, |
316 headerIds.append(hbTrId("txt_calendar_lunar_date")); |
321 R_CALENDAR_LUNAR_INFO_SOLAR, |
317 headerIds.append(hbTrId("txt_calendar_animal_year")); |
322 R_CALENDAR_LUNAR_INFO_DATE, |
318 headerIds.append(hbTrId("txt_calendar_gregorian_date")); |
323 R_CALENDAR_LUNAR_INFO_ANIMAL_YEAR, |
319 |
324 R_CALENDAR_LUNAR_INFO_WESTERN_DATE |
320 QStringList fieldInfo; |
325 }; |
321 QString data; |
326 |
322 |
327 RPointerArray<HBufC> headersArray; |
323 data = QString::fromUtf16(iLocInfo->Festival().Ptr(),iLocInfo->Festival().Length()); |
328 |
324 fieldInfo.append(data); |
329 for ( TInt i=0; i < KFieldCount; i++) |
325 data = QString::fromUtf16(iLocInfo->SolarTerm().Ptr(),iLocInfo->SolarTerm().Length()); |
330 { |
326 fieldInfo.append(data); |
331 headersArray.Append( StringLoader::LoadL( headerIds[i] ) ); |
327 data = QString::fromUtf16(iLocInfo->FullLunarDate().Ptr(),iLocInfo->FullLunarDate().Length()); |
332 } |
328 fieldInfo.append(data); |
333 |
329 data = QString::fromUtf16(iLocInfo->AnimalYear().Ptr(),iLocInfo->AnimalYear().Length()); |
334 CPtrCArray* fieldsArray = new (ELeave) CPtrCArray(5); |
330 fieldInfo.append(data); |
335 CleanupStack::PushL( fieldsArray ); |
331 data = QString::fromUtf16(iLocInfo->GregorianDate().Ptr(),iLocInfo->GregorianDate().Length()); |
336 fieldsArray->AppendL( iLocInfo->Festival() ); |
332 fieldInfo.append(data); |
337 fieldsArray->AppendL( iLocInfo->SolarTerm() ); |
333 // Append the data in the proper order |
338 fieldsArray->AppendL( iLocInfo->FullLunarDate() ); |
334 for (TInt i=0; i < KFieldCount; i++) { |
339 fieldsArray->AppendL( iLocInfo->AnimalYear() ); |
335 if(!fieldInfo.at(i).isEmpty()) { |
340 fieldsArray->AppendL( iLocInfo->GregorianDate() ); |
336 msgText.append(headerIds[i]); |
341 |
337 msgText.append(headerSeparator); |
342 for (TInt i=0; i < KFieldCount; i++) |
338 msgText.append(fieldInfo[i]); |
343 { |
339 if ( i < KFieldCount - 1 ) { |
344 TPtrC fieldPtrC = fieldsArray->At(i); |
340 // not last item |
345 if ( fieldPtrC != KNullDesC ) |
341 msgText.append(fieldSeparator); |
346 { |
342 } |
347 msgText->Des().Append( *(headersArray[i]) ); |
343 } |
348 msgText->Des().Append( KHeaderSeparator ); |
344 } |
349 msgText->Des().Append( fieldPtrC ); |
345 } |
350 if ( i < KFieldCount - 1 ) // not last |
346 ExecuteMessageDialogL(msgText); |
351 { |
347 } |
352 msgText->Des().Append( KFieldSeparator ); |
348 |
353 } |
349 // ----------------------------------------------------------------------------- |
354 } |
350 // CCalenLunarChinesePlugin::ExecuteMessageDialogL |
355 } |
351 // ----------------------------------------------------------------------------- |
356 CleanupStack::PopAndDestroy( fieldsArray ); |
352 // |
357 headersArray.ResetAndDestroy(); |
353 void CCalenLunarChinesePlugin::ExecuteMessageDialogL(QString aMsgText) |
358 } |
|
359 |
|
360 |
|
361 ExecuteMessageDialogL(*msgText); |
|
362 |
|
363 CleanupStack::PopAndDestroy( msgText ); |
|
364 |
|
365 TRACE_EXIT_POINT; |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CCalenLunarChinesePlugin::ShowMessageDialogL |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CCalenLunarChinesePlugin::ExecuteMessageDialogL(TDesC& aMsgText) |
|
373 { |
354 { |
374 TRACE_ENTRY_POINT; |
355 TRACE_ENTRY_POINT; |
375 QString text = QString::fromUtf16(aMsgText.Ptr(),aMsgText.Length()); |
|
376 |
|
377 // Instantiate a popup |
356 // Instantiate a popup |
378 HbMessageBox *popup = new HbMessageBox(); |
357 HbMessageBox *popup = new HbMessageBox(); |
379 popup->setDismissPolicy(HbDialog::NoDismiss); |
358 popup->setDismissPolicy(HbDialog::NoDismiss); |
380 popup->setTimeout(HbDialog::NoTimeout); |
359 popup->setTimeout(HbDialog::NoTimeout); |
381 popup->setIconVisible(false); |
360 popup->setIconVisible(false); |
382 popup->setAttribute( Qt::WA_DeleteOnClose, true ); |
361 popup->setAttribute( Qt::WA_DeleteOnClose, true ); |
383 |
362 |
384 popup->setHeadingWidget(new HbLabel("Lunar Calendar")); |
363 popup->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_lunar_calendar"))); |
385 popup->setText(text); |
364 popup->setText(aMsgText); |
386 |
365 |
387 // Remove the default actions |
366 // Remove the default actions |
388 QList<QAction*> list = popup->actions(); |
367 QList<QAction*> list = popup->actions(); |
389 for(int i=0; i < list.count(); i++) |
368 for(int i=0; i < list.count(); i++) |
390 { |
369 { |
391 popup->removeAction(list[i]); |
370 popup->removeAction(list[i]); |
392 } |
371 } |
393 // Sets the primary action |
372 // Sets the primary action |
394 popup->addAction(new HbAction(hbTrId("txt_calendar_button_cancel"), popup)); |
373 popup->addAction(new HbAction(hbTrId("txt_calendar_button_close"), popup)); |
395 |
374 |
396 // Launch popup |
375 // Launch popup |
397 popup->open(); |
376 popup->open(); |
398 TRACE_EXIT_POINT; |
377 TRACE_EXIT_POINT; |
399 } |
378 } |
400 |
|
401 //EOF |
379 //EOF |
402 |
380 |
403 |
381 |