screensaver/screensaverplugins/snsrbigclockscreensaverplugin/src/snsrbigclockscreensaver.cpp
changeset 62 341166945d65
child 69 87476091b3f5
equal deleted inserted replaced
57:2e2dc3d30ca8 62:341166945d65
       
     1 /*
       
     2 * Copyright (c) 2009 - 2010 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: Big clock Screensaver.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsrbigclockscreensaver.h"
       
    19 
       
    20 #ifdef Q_OS_SYMBIAN
       
    21 #include <e32std.h>
       
    22 #endif // Q_OS_SYMBIAN
       
    23 
       
    24 #include <QDebug>
       
    25 #include <QTime>
       
    26 #include <QTimer>
       
    27 
       
    28 #include <hbinstance.h>
       
    29 #include <hbmainwindow.h>
       
    30 
       
    31 #include "snsranalogclockcontainer.h"
       
    32 #include "snsrdigitalclockcontainer.h"
       
    33 #include "snsroledanalogclockcontainer.h"
       
    34 #include "snsroleddigitalclockcontainer.h"
       
    35 #include "snsrindicatormodel.h"
       
    36 
       
    37 /*!
       
    38     \class SnsrBigClockScreensaver
       
    39     \ingroup group_snsrbigclockscreensaverplugin
       
    40     \brief Screensaver with big digital clock.
       
    41  */
       
    42 
       
    43 const int gTimeInterval(100);
       
    44 
       
    45 /*!
       
    46     Constructs a new SnsrBigClockScreensaver.
       
    47  */
       
    48 SnsrBigClockScreensaver::SnsrBigClockScreensaver() :
       
    49     mMainWindow(0),
       
    50     mCurrentContainer(0),
       
    51     mIndicatorModel(0)
       
    52 {
       
    53     mMainWindow = HbInstance::instance()->allMainWindows().at(0);
       
    54     // for nice looking clock hand transformations
       
    55     mMainWindow->setRenderHint(QPainter::SmoothPixmapTransform);
       
    56     
       
    57     // This model holds indicator status information and must exist as
       
    58     // long as screensaver does.
       
    59     mIndicatorModel = new SnsrIndicatorModel(this);
       
    60 }
       
    61 
       
    62 /*!
       
    63     Destructs the class.
       
    64  */
       
    65 SnsrBigClockScreensaver::~SnsrBigClockScreensaver()
       
    66 {
       
    67     // mCurrentContainer, mIndicatorModel - deleted by the parent
       
    68 }
       
    69 
       
    70 /*!
       
    71     @copydoc Screensaver::onInitialize()
       
    72 */
       
    73 bool SnsrBigClockScreensaver::onInitialize()
       
    74 {
       
    75     qDebug() << "SnsrBigClockScreensaver::onInitialize()";
       
    76     return true;
       
    77 }
       
    78 
       
    79 /*!
       
    80     @copydoc Screensaver::onForeground()
       
    81  */
       
    82 bool SnsrBigClockScreensaver::onForeground()
       
    83 {
       
    84     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onForeground")
       
    85     qDebug() << "SnsrBigClockScreensaver::onForeground()";
       
    86 
       
    87     removeCurrentContainer();
       
    88 
       
    89     SnsrBigClockContainer* newContainer( 0 );
       
    90     if (clockFormat() == ClockFormatAnalog) {
       
    91         newContainer = new SnsrAnalogClockContainer();
       
    92     }
       
    93     else {
       
    94         newContainer = new SnsrDigitalClockContainer();
       
    95     }
       
    96 
       
    97     setCurrentContainer( newContainer );
       
    98 
       
    99     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onForeground")
       
   100     return true;
       
   101 }
       
   102 
       
   103 /*!
       
   104     @copydoc Screensaver::onPartialForeground()
       
   105  */
       
   106 bool SnsrBigClockScreensaver::onPartialForeground()
       
   107 {
       
   108     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPartialForeground")
       
   109     qDebug() << "SnsrBigClockScreensaver::onPartialForeground()";
       
   110 
       
   111     removeCurrentContainer();
       
   112     
       
   113     SnsrBigClockContainer* newContainer( 0 );
       
   114     if (clockFormat() == ClockFormatAnalog) {
       
   115         newContainer = new SnsrOledAnalogClockContainer();
       
   116     }
       
   117     else {
       
   118         newContainer = new SnsrOledDigitalClockContainer();
       
   119     }
       
   120 
       
   121     setCurrentContainer( newContainer );
       
   122 
       
   123     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPartialForeground")
       
   124     return true;
       
   125 }
       
   126 
       
   127 /*!
       
   128     @copydoc Screensaver::onBackground()
       
   129  */
       
   130 bool SnsrBigClockScreensaver::onBackground()
       
   131 {
       
   132     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onBackground")
       
   133     qDebug() << "SnsrBigClockScreensaver::onBackground()";
       
   134 
       
   135     removeCurrentContainer();
       
   136 
       
   137     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onBackground")
       
   138     return true;
       
   139 }
       
   140 
       
   141 /*!
       
   142     @copydoc Screensaver::onPowerSave()
       
   143  */
       
   144 bool SnsrBigClockScreensaver::onPowerSave()
       
   145 {
       
   146     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPowerSave")
       
   147     qDebug() << "SnsrBigClockScreensaver::onPowerSave()";
       
   148 
       
   149     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPowerSave")
       
   150     return false;
       
   151 }
       
   152 
       
   153 /*!
       
   154     @copydoc Screensaver::onClose()
       
   155  */
       
   156 bool SnsrBigClockScreensaver::onClose()
       
   157 {
       
   158     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onClose")
       
   159     qDebug() << "SnsrBigClockScreensaver::onClose()";
       
   160 
       
   161     bool ret(false);
       
   162     if (onBackground()) {
       
   163         delete mCurrentContainer;
       
   164         mCurrentContainer = 0;
       
   165         ret = true;
       
   166     }
       
   167 
       
   168     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onClose")
       
   169     return ret;
       
   170 }
       
   171 
       
   172 /*!
       
   173     @copydoc Screensaver::onHandleActiveIndicators
       
   174  */
       
   175 void SnsrBigClockScreensaver::onHandleActiveIndicators(
       
   176         const QList<HbIndicatorInterface*> &activeIndicators)
       
   177 {
       
   178     mIndicatorModel->handleActiveIndicators(activeIndicators);
       
   179 }
       
   180 
       
   181 /*!
       
   182     @copydoc Screensaver::onHandleActivatedIndicator
       
   183  */
       
   184 void SnsrBigClockScreensaver::onHandleActivatedIndicator(
       
   185         HbIndicatorInterface *activatedIndicator)
       
   186 {
       
   187     mIndicatorModel->handleActivatedIndicator(activatedIndicator);
       
   188 }
       
   189 
       
   190 /*!
       
   191     @copydoc Screensaver::onHandleDeactivatedIndicator
       
   192  */
       
   193 void SnsrBigClockScreensaver::onHandleDeactivatedIndicator(
       
   194         HbIndicatorInterface *deactivatedIndicator)
       
   195 {
       
   196     mIndicatorModel->handleDeactivatedIndicator(deactivatedIndicator);
       
   197 }
       
   198 
       
   199 
       
   200 /*!
       
   201     Determines the curent clock format settings.
       
   202     \retval ClockFormat.
       
   203  */
       
   204 SnsrBigClockScreensaver::ClockFormat SnsrBigClockScreensaver::clockFormat()
       
   205 {
       
   206 #ifdef Q_OS_SYMBIAN
       
   207     if (TLocale().ClockFormat() == EClockAnalog) {
       
   208         return ClockFormatAnalog;
       
   209     } else {
       
   210         return ClockFormatDigital;
       
   211     }
       
   212 #else
       
   213     // windows build - change the format every 30 seconds for testing purposes
       
   214     if (QTime::currentTime().second() < 30) {
       
   215         return ClockFormatAnalog;
       
   216     } else {
       
   217         return ClockFormatDigital;
       
   218     }
       
   219 #endif // Q_OS_SYMBIAN
       
   220 }
       
   221 
       
   222 void SnsrBigClockScreensaver::removeCurrentContainer()
       
   223 {
       
   224     if ( mCurrentContainer ) {
       
   225         disconnect(
       
   226             mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
       
   227             mCurrentContainer, SLOT(changeLayout(Qt::Orientation))
       
   228             );
       
   229         disconnect(
       
   230             &mTimer, SIGNAL(timeout()),
       
   231             mCurrentContainer, SLOT(update())
       
   232             );
       
   233         disconnect( 
       
   234             mCurrentContainer, SIGNAL(unlockRequested()), 
       
   235             this, SIGNAL(unlockRequested()) );
       
   236         mTimer.stop();
       
   237         emit viewChanged(0);
       
   238         
       
   239         delete mCurrentContainer;
       
   240         mCurrentContainer = 0;
       
   241     }
       
   242 }
       
   243 
       
   244 void SnsrBigClockScreensaver::setCurrentContainer( SnsrBigClockContainer* newContainer )
       
   245 {
       
   246     mCurrentContainer = newContainer;
       
   247     connect(
       
   248             mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
       
   249             mCurrentContainer, SLOT(changeLayout(Qt::Orientation))
       
   250         );
       
   251     connect( &mTimer, SIGNAL(timeout()), mCurrentContainer, SLOT(update()) );
       
   252     connect( mCurrentContainer, SIGNAL(unlockRequested()), SIGNAL(unlockRequested()) );
       
   253 
       
   254     mCurrentContainer->initIndicators(*mIndicatorModel);
       
   255     
       
   256     mCurrentContainer->changeLayout(mMainWindow->orientation());
       
   257     mTimer.start( mCurrentContainer->updateIntervalInMilliseconds() );
       
   258     emit viewChanged(mCurrentContainer);
       
   259 }
       
   260