homescreenapp/widgetplugins/hsclockwidgetplugin/src/hsclockwidget.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
    19 #include <QGraphicsWidget>
    19 #include <QGraphicsWidget>
    20 #include <QSizePolicy>
    20 #include <QSizePolicy>
    21 #include <QGraphicsLinearLayout>
    21 #include <QGraphicsLinearLayout>
    22 #include <hblabel.h>
    22 #include <hblabel.h>
    23 #include <hbextendedlocale.h>
    23 #include <hbextendedlocale.h>
       
    24 #include <hbdeviceprofile.h> // temp
    24 
    25 
    25 #include "hsclockwidget.h"
    26 #include "hsclockwidget.h"
    26 #include "hsanalogclockwidget.h"
    27 #include "hsanalogclockwidget.h"
    27 #include "hsdigitalclockwidget.h"
    28 #include "hsdigitalclockwidget.h"
    28 #include "hsclockwidgetdocumentloader.h"
       
    29 
    29 
    30 #ifdef Q_OS_SYMBIAN    
    30 #ifdef Q_OS_SYMBIAN    
    31 #include "hsclockwidgettype_symbian.h"
    31 #include "hsclockwidgettype_symbian.h"
    32 #endif
    32 #include <apgtask.h>
       
    33 #include <eikenv.h>
       
    34 #endif //Q_OS_SYMBIAN
    33 
    35 
    34 namespace
    36 namespace
    35 {
    37 {
    36     const char ANALOG[] = "analog";
    38     const char ANALOG[] = "analog";
    37     const char DIGITAL[] = "digital";
    39     const char DIGITAL[] = "digital";
    38 
    40 
    39     const char DIGITAL_CLOCK_DOCML[] = ":/xml/hsdigitalclockwidget.docml";
       
    40     const char ANALOG_CLOCK_DOCML[] = ":/xml/hsanalogclockwidget.docml";
       
    41 
       
    42     const char DIGITAL_CLOCK_WIDGET[] = "timeLabel";
       
    43     const char ANALOG_CLOCK_WIDGET[] = "analogClockWidget";
       
    44 
       
    45     const int clockUpdateInterval = 1000; // msec
    41     const int clockUpdateInterval = 1000; // msec
    46 }
    42 }
       
    43 
       
    44 #ifdef Q_OS_SYMBIAN
       
    45 #define KClockAppUid TUid::Uid(0x10005903)
       
    46 _LIT (KClockAppExe, "clock.exe");
       
    47 #endif //Q_OS_SYMBIAN
    47 
    48 
    48 /*!
    49 /*!
    49     \class HsClockWidget
    50     \class HsClockWidget
    50     \ingroup group_hsclockwidgetplugin
    51     \ingroup group_hsclockwidgetplugin
    51     \brief Implementation for the homescreen clock widget.
    52     \brief Implementation for the homescreen clock widget.
   199     show();
   200     show();
   200     updateTime();
   201     updateTime();
   201     update();
   202     update();
   202 
   203 
   203     mTimer->start(clockUpdateInterval);
   204     mTimer->start(clockUpdateInterval);
   204 #endif    
   205 #else //Q_OS_SYMBIAN
   205 }
   206     TApaTaskList taskList(CEikonEnv::Static()->WsSession());    
   206 
   207     TApaTask task = taskList.FindApp(KClockAppUid);    
       
   208     if (task.Exists()){
       
   209         task.BringToForeground();
       
   210     }    
       
   211     else {
       
   212         RProcess process;
       
   213         TInt error = process.Create(KClockAppExe, KNullDesC, EOwnerThread);
       
   214     
       
   215         if (error == KErrNone){
       
   216             // start the process running.
       
   217             process.Resume();
       
   218             process.Close();
       
   219         }
       
   220     }
       
   221 #endif //Q_OS_SYMBIAN   
       
   222 }
       
   223 
       
   224   
   207 /*!
   225 /*!
   208     Toggles the clock type.
   226     Toggles the clock type.
   209 */
   227 */
   210 void HsClockWidget::toggleClockType()
   228 void HsClockWidget::toggleClockType()
   211 {
   229 {
   221 */
   239 */
   222 HbWidget *HsClockWidget::loadClockWidget()
   240 HbWidget *HsClockWidget::loadClockWidget()
   223 {
   241 {
   224     HbWidget *clockWidget = 0;
   242     HbWidget *clockWidget = 0;
   225 
   243 
   226     QString docmlFile;
       
   227     if (mClockType == DIGITAL) {
   244     if (mClockType == DIGITAL) {
   228         docmlFile = DIGITAL_CLOCK_DOCML;
   245         clockWidget = new HsDigitalClockWidget();
   229     } else {
   246         clockWidget->setBackgroundItem(HbStyle::P_Fade_background);
   230         docmlFile = ANALOG_CLOCK_DOCML;
   247     } else {
   231     }
   248         clockWidget = new HsAnalogClockWidget();
   232 
   249     }
   233     HsClockWidgetDocumentLoader loader;
   250 
   234     bool loaded = false;
   251     qreal unit = HbDeviceProfile::current().unitValue(); 
   235     loader.load(docmlFile, &loaded);
   252     clockWidget->setPreferredSize(QSizeF(25 * unit, 25 * unit)); // TODO: temp workaround
   236 
       
   237     if (loaded) {
       
   238         if (mClockType == DIGITAL) {
       
   239             clockWidget = qobject_cast<HsDigitalClockWidget *>(loader.findWidget(DIGITAL_CLOCK_WIDGET));
       
   240             clockWidget->setBackgroundItem(HbStyle::P_Fade_background);
       
   241         } else {
       
   242             clockWidget = qobject_cast<HsAnalogClockWidget *>(loader.findWidget(ANALOG_CLOCK_WIDGET));
       
   243         }
       
   244 
       
   245     } else {
       
   246         qWarning() << "Unable to load clock widget from docml: " << docmlFile;
       
   247         // TODO: We must handle this error situation once error handling strategy is clear!
       
   248     }
       
   249 
   253 
   250     return clockWidget;
   254     return clockWidget;
   251 }
   255 }
   252 
   256 
   253 void HsClockWidget::onTypeChanged(QString type)
   257 void HsClockWidget::onTypeChanged(QString type)
   254 {
   258 {
       
   259   Q_UNUSED(type);
   255 #if 0
   260 #if 0
   256     if (mClockType != type) {
   261     if (mClockType != type) {
   257         mTimer->stop();
   262         mTimer->stop();
   258         mClockType = type;
   263         mClockType = type;
   259         emit setPreferences(QStringList() << "clockType");
   264         emit setPreferences(QStringList() << "clockType");