calendarui/regionalplugins/lunarchinese/src/CalenLunarChinesePlugin.cpp
changeset 23 fd30d51f876b
parent 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
--- a/calendarui/regionalplugins/lunarchinese/src/CalenLunarChinesePlugin.cpp	Fri Apr 16 14:57:40 2010 +0300
+++ b/calendarui/regionalplugins/lunarchinese/src/CalenLunarChinesePlugin.cpp	Mon May 03 12:30:32 2010 +0300
@@ -15,28 +15,19 @@
  *
 */
 
-#include <QtGui>
-
 
 #include <eikenv.h>
-#include <aknutils.h>
-#include <eiklabel.h>
-#include <avkon.hrh>
 #include <StringLoader.h>
 #include <data_caging_path_literals.hrh>
 #include <bautils.h>
-#include <aknbiditextutils.h>
 #include <CalenLunarChinesePluginData.rsg>
-#include <layoutmetadata.cdl.h>
 
-#include <hblabel.h>
-#include <hbwidget.h>
-#include <qstring.h>
-#include <hbaction.h>
-#include <hbtextedit.h>
-#include <hbmainwindow.h>
-#include <hbview.h>
-#include <hbmenu.h>
+#include <QString>
+#include <HbAction>
+#include <HbView>
+#include <HbMenu>
+#include <HbMessageBox>
+#include <HbLabel>
 
 #include "calendarui_debug.h" 
 #include "CalenLunarChinesePlugin.h"
@@ -67,9 +58,7 @@
 	 iLocInfo(NULL),
 	 iServices(aServices),
 	 iInfoBarText(NULL),
-	 iResourceFileOffset( NULL ),
-	 iLabelControl(NULL)
-	 
+	 iResourceFileOffset( NULL )
 	{
 	TRACE_ENTRY_POINT;
 	
@@ -80,11 +69,12 @@
 // CCalenLunarChinesePlugin::CreateChinesePluginL
 // -----------------------------------------------------------------------------
 //
-CCalenLunarChinesePlugin* CCalenLunarChinesePlugin::NewL( MCalenServices* aServices )
+CCalenLunarChinesePlugin* CCalenLunarChinesePlugin::NewL( 
+													MCalenServices* aServices )
 	{
 	TRACE_ENTRY_POINT;
 	CCalenLunarChinesePlugin* self = new( ELeave ) 
-											CCalenLunarChinesePlugin( aServices);
+										CCalenLunarChinesePlugin( aServices);
 	CleanupStack::PushL( self );
 	self->ConstructL();
     CleanupStack::Pop(self);
@@ -100,8 +90,6 @@
 	{
 	TRACE_ENTRY_POINT;
 	
- 	delete iLabelControl;
- 	iLabelControl = NULL;
 	
 	//Deregister services
 	if ( iServices )
@@ -142,81 +130,35 @@
     resourceFilename.Append(dllName.Mid(0,2));
     resourceFilename.Append(KResourcePath);
     resourceFilename.Append(KResourceChinesePluginFile);
-    BaflUtils::NearestLanguageFile( CEikonEnv::Static()->FsSession(), resourceFilename );
+    BaflUtils::NearestLanguageFile( CEikonEnv::Static()->FsSession(), 
+															resourceFilename );
     // Add the resource file.
-    iResourceFileOffset = CEikonEnv::Static()->AddResourceFileL( resourceFilename );
+    iResourceFileOffset = CEikonEnv::Static()->AddResourceFileL( 
+															resourceFilename );
 	
     iServices->RegisterForNotificationsL( this, ECalenNotifyContextChanged );
 	iServices->GetCommandRange( iStart, iEnd );
 	
 	iLocalizer = CCalenLunarLocalizer::NewL();
 	
-	iInfoProvider = CCalenLunarInfoProvider::NewL(CEikonEnv::Static()->FsSession());
+	iInfoProvider = CCalenLunarInfoProvider::NewL( 
+											CEikonEnv::Static()->FsSession() );
 	
-	iLabelControl = new CalenPluginLabel(*this);
-    
     TRACE_EXIT_POINT;	
 	}
-	
 
 // -----------------------------------------------------------------------------
-// CCalenLunarChinesePlugin::SetLabelContentL
-// -----------------------------------------------------------------------------
-//
-void CCalenLunarChinesePlugin::SetLabelContentL( HbLabel& aLabel) 
-    {
-    TRACE_ENTRY_POINT;
-    
-    FormatExtraRowStringL( aLabel, EFalse );
-    //aLabel.UseLogicalToVisualConversion(ETrue);
-    //aLabel.SetLabelAlignment(ELayoutAlignCenter);
-    //aLabel.setPlainText(  iExtraRowText );
-    
-    QString text = QString::fromUtf16(iExtraRowText.Ptr(),iExtraRowText.Length());
-    aLabel.setPlainText(text);
-    
-    TRACE_EXIT_POINT;
-    }    
-    
-// -----------------------------------------------------------------------------
 // CCalenLunarChinesePlugin::FormatExtraRowStringL
 // -----------------------------------------------------------------------------
 //	
-void CCalenLunarChinesePlugin::FormatExtraRowStringL( HbLabel& aLabel,TBool aTwoLines)
+void CCalenLunarChinesePlugin::FormatExtraRowStringL()
 
     {
     TRACE_ENTRY_POINT;
     
-    Q_UNUSED(aLabel);
-    const CFont*  labelFont = NULL;
-    
-    if( aTwoLines ) 
-    	{
-    	labelFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont,NULL);
-    	} 
-    else
-    	{
-    	labelFont = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont,NULL);	
-    	}
-    
-    //aLabel.SetFont( labelFont );
-    TInt maxWidth = 0;
-    if(iRect.IsEmpty())
-    	{
-    	maxWidth = 450; //For hitch we take max value
-    	}
-    else 
-    	{
-    	maxWidth = iRect.Size().iWidth;
-    	}
-    
-    if ( labelFont && iLocInfo )
+    if ( iLocInfo )
         {
-        iExtraRowText.Set( iLocalizer->GetExtraRowTextL( *iLocInfo, 
-                                                         maxWidth, 
-                                                         *labelFont,
-                                                         aTwoLines ) 
-                                                        );
+        iExtraRowText.Set( iLocalizer->GetExtraRowTextL( *iLocInfo) );
         }
     else 
         {
@@ -233,14 +175,8 @@
 HbWidget* CCalenLunarChinesePlugin::InfobarL( )
 	{
 	TRACE_ENTRY_POINT;
-
-	UpdateLocalizerInfoL();
-    
-	SetLabelContentL(*iLabelControl);
-		 
-	return iLabelControl;
-	
-    TRACE_EXIT_POINT;	
+	TRACE_EXIT_POINT;
+	return NULL;
 	}
 
 // ----------------------------------------------------------------------------
@@ -251,8 +187,6 @@
 QString* CCalenLunarChinesePlugin::InfobarTextL( )
     {
     TRACE_ENTRY_POINT;
-    TRect nullRect(0,0,0,0);
-    iRect = nullRect;
     if(iInfoBarText)
         {
         delete iInfoBarText;
@@ -261,7 +195,7 @@
     //Update the local information based on current context
     //from framework.
     UpdateLocalizerInfoL();  
-    SetLabelContentL(*iLabelControl);    
+    FormatExtraRowStringL();
     iInfoBarText = iExtraRowText.AllocLC();
     CleanupStack::Pop();
     
@@ -282,7 +216,6 @@
     TInt count = actionList.count() - 1;  
     if(count >= 0)
     aHbMenu->insertAction(actionList[count], lunarAction);
-    QObject::connect(lunarAction, SIGNAL(triggered()), iLabelControl, SLOT(showLunarData()));
     }
 
 // -----------------------------------------------------------------------------
@@ -294,7 +227,7 @@
 	TRACE_ENTRY_POINT;
 	
 	const TInt commandId = aCommand.Command();
-	if(iStart == commandId)
+	if(ECalenRegionalPluginTapEvent == commandId)
 		{
 		ShowDetailsL();	
 		}
@@ -307,7 +240,8 @@
 //
 // ----------------------------------------------------------------------------
 //
-TAny* CCalenLunarChinesePlugin::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ )
+TAny* CCalenLunarChinesePlugin::CalenCommandHandlerExtensionL( 
+														TUid /*aExtensionUid*/ )
     {
     TRACE_ENTRY_POINT;
     TRACE_EXIT_POINT;
@@ -324,7 +258,7 @@
 	
 	MCalenCommandHandler*  commandHandler = NULL;	
 		
-	if(iStart == aCommand)
+	if(ECalenRegionalPluginTapEvent == aCommand)
 		{
 		commandHandler = this;	
 		}
@@ -340,7 +274,13 @@
 void CCalenLunarChinesePlugin::UpdateLocalizerInfoL()
 	{
 	TRACE_ENTRY_POINT;
-	TTime focusTime = iServices->Context().FocusDateAndTimeL().TimeLocalL();
+	QDateTime focusDateTime= iServices->Context().focusDateAndTimeL();
+	TDateTime tempDateTime(
+					focusDateTime.date().year(),
+					static_cast<TMonth>(focusDateTime.date().month() - 1),
+					focusDateTime.date().day() - 1, focusDateTime.time().hour(),
+					focusDateTime.time().minute(), 0, 0);
+	TTime focusTime(tempDateTime);
     TCalenLunarInfo lunarInfo = iInfoProvider->GetLunarInfoL( focusTime );
     delete iLocInfo;
 	iLocInfo = NULL;
@@ -355,7 +295,8 @@
 // CCalenLunarChinesePlugin::HandleNotification
 // -----------------------------------------------------------------------------
 //	
-void CCalenLunarChinesePlugin::HandleNotification(const TCalenNotification aNotification)
+void CCalenLunarChinesePlugin::HandleNotification( 
+										const TCalenNotification aNotification )
 	{
 	TRACE_ENTRY_POINT;
 	if (aNotification == ECalenNotifyContextChanged)
@@ -435,84 +376,23 @@
 	QString text = QString::fromUtf16(aMsgText.Ptr(),aMsgText.Length());
 	
     // Instantiate a popup
-    HbPopup popup;
+	HbMessageBox popup;
+	popup.setDismissPolicy(HbDialog::NoDismiss);
+	popup.setTimeout(HbDialog::NoTimeout);
+	popup.setIconVisible(false);
 
-    // Set dismiss policy that determines what tap events will cause the popup
-    // to be dismissed
-    popup.setDismissPolicy(HbPopup::NoDismiss);
-    popup.setTimeout(HbPopup::NoTimeout);
-    
-    // Set the label as heading widget    
     popup.setHeadingWidget(new HbLabel("Lunar Calendar"));
-    HbTextEdit* contentWidget = new HbTextEdit (text);
-    contentWidget->setReadOnly(true);
-    //contentWidget->setCursorHidden(true);
-    QSizeF size = contentWidget->maximumSize();
-    contentWidget->setMinimumSize(200,250);    
-    popup.setContentWidget(contentWidget);
+    popup.setText(text);
     
     // Sets the primary action
-    popup.setPrimaryAction(new HbAction("Ok",&popup));  
+    popup.setPrimaryAction(new HbAction(hbTrId("txt_calendar_button_cancel"),
+                                        &popup));
 
     // Launch popup syncronously
     popup.exec();
    	TRACE_EXIT_POINT;
 	}
 
-
-CalenPluginLabel::CalenPluginLabel(CCalenLunarChinesePlugin& aPlugin , QGraphicsItem* parent)
-    :HbLabel(parent),iPlugin(aPlugin)
-    {
-	TRACE_ENTRY_POINT;
-	
-    setAlignment(Qt::AlignHCenter);
-    setTextColor(Qt::blue);    
-    QFont font("Times", 9, QFont::Bold);    
-    setFont(font);
-    setTextWrapping(Hb::TextWrapping);
-    setOpacity(12);
-    
-    TRACE_EXIT_POINT;    
-    }
-
-CalenPluginLabel::~CalenPluginLabel()
-    {
-    TRACE_ENTRY_POINT;
-    TRACE_EXIT_POINT;
-    }
-
-void CalenPluginLabel::showLunarData()
-    {
-    TRACE_ENTRY_POINT;
-    iPlugin.ShowDetailsL(); 
-    TRACE_EXIT_POINT;
-    }
-void CalenPluginLabel::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
-    {
-	TRACE_ENTRY_POINT;
-   
-    HbLabel::paint(painter,option,widget);
-    QPen pen;//
-    pen.setStyle(Qt::SolidLine);
-    pen.setWidth(1);
-    pen.setBrush(Qt::gray);
-    painter->setPen(pen);
-    QRectF rect = this->rect();
-    painter->eraseRect(rect);
-    painter->drawRect(rect);
-    painter->fillRect(rect,Qt::gray);
-    
-    TRACE_EXIT_POINT;    
-    }
-	
-void CalenPluginLabel::mousePressEvent(QGraphicsSceneMouseEvent* event)
-    {
-	TRACE_ENTRY_POINT;
-	Q_UNUSED(event);
-	iPlugin.ShowDetailsL();	
-	TRACE_EXIT_POINT;    
-    }	
-	
 //EOF