screensaver/screensaverplugins/snsrbigclockscreensaverplugin/src/snsrbigclockscreensaver.cpp
changeset 97 66b5fe3c07fd
parent 95 32e56106abf2
child 98 e6f74eb7f69f
equal deleted inserted replaced
95:32e56106abf2 97:66b5fe3c07fd
     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 #include <XQSettingsManager> 
       
    28 #include <HbInstance>
       
    29 #include <HbMainWindow>
       
    30 
       
    31 #include <screensaverdomaincrkeys.h>
       
    32 #include "snsranalogclockcontainer.h"
       
    33 #include "snsrdigitalclockcontainer.h"
       
    34 #include "snsroledanalogclockcontainer.h"
       
    35 #include "snsroleddigitalclockcontainer.h"
       
    36 #include "snsrblankcontainer.h"
       
    37 #include "snsrindicatormodel.h"
       
    38 
       
    39 /*!
       
    40     \class SnsrBigClockScreensaver
       
    41     \ingroup group_snsrbigclockscreensaverplugin
       
    42     \brief Screensaver with big digital clock.
       
    43  */
       
    44 
       
    45 /*!
       
    46     Constructs a new SnsrBigClockScreensaver.
       
    47  */
       
    48 SnsrBigClockScreensaver::SnsrBigClockScreensaver() :
       
    49     mMainWindow(0),
       
    50     mCurrentContainer(0),
       
    51     mIndicatorModel(0),
       
    52     m_setManager(0)
       
    53 {
       
    54     mMainWindow = HbInstance::instance()->allMainWindows().at(0);
       
    55     // for nice looking clock hand transformations
       
    56     mMainWindow->setRenderHint(QPainter::SmoothPixmapTransform);
       
    57     
       
    58     // This model holds indicator status information and must exist as
       
    59     // long as screensaver does.
       
    60     mIndicatorModel = new SnsrIndicatorModel(this);
       
    61 }
       
    62 
       
    63 /*!
       
    64     Destructs the class.
       
    65  */
       
    66 SnsrBigClockScreensaver::~SnsrBigClockScreensaver()
       
    67 {
       
    68     mMainWindow->unsetOrientation( /*animate*/false );
       
    69     // mCurrentContainer, mIndicatorModel - deleted by the parent
       
    70 }
       
    71 
       
    72 /*!
       
    73     @copydoc Screensaver::onInitialize()
       
    74 */
       
    75 bool SnsrBigClockScreensaver::onInitialize()
       
    76 {
       
    77     qDebug() << "SnsrBigClockScreensaver::onInitialize()";
       
    78     return true;
       
    79 }
       
    80 
       
    81 /*!
       
    82     @copydoc Screensaver::onForeground()
       
    83  */
       
    84 bool SnsrBigClockScreensaver::onForeground()
       
    85 {
       
    86     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onForeground")
       
    87     qDebug() << "SnsrBigClockScreensaver::onForeground()";
       
    88 
       
    89     removeCurrentContainer();
       
    90 
       
    91     SnsrBigClockContainer* newContainer( 0 );
       
    92     if (clockFormat() == ClockFormatAnalog) {
       
    93         newContainer = new SnsrAnalogClockContainer();
       
    94     }
       
    95     else {
       
    96         newContainer = new SnsrDigitalClockContainer();
       
    97     }
       
    98 
       
    99     setCurrentContainer( newContainer );
       
   100     
       
   101     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onForeground")
       
   102     return true;
       
   103 }
       
   104 
       
   105 /*!
       
   106     @copydoc Screensaver::onPartialForeground()
       
   107  */
       
   108 bool SnsrBigClockScreensaver::onPartialForeground()
       
   109 {
       
   110     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPartialForeground")
       
   111     qDebug() << "SnsrBigClockScreensaver::onPartialForeground()";
       
   112 
       
   113     removeCurrentContainer();
       
   114     
       
   115     SnsrBigClockContainer* newContainer( 0 );
       
   116         
       
   117     // Check ScreensaverStatus from repository
       
   118     XQSettingsManager::Error error;
       
   119     int screensaverOn = 1; 
       
   120     XQCentralRepositorySettingsKey settingsKey(
       
   121             KCRUidScreensaverSettings.iUid, KScreensaverStatus ); // TUid as same repository used in control panel via Symbian APIs 
       
   122     m_setManager = new XQSettingsManager(this);
       
   123     if (m_setManager) {
       
   124         screensaverOn = m_setManager->readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt();
       
   125         error = m_setManager->error();
       
   126         if (error != XQSettingsManager::NoError) {
       
   127             qDebug("Error reading value from XQSettingsManager.. error = %d", error);
       
   128         }
       
   129         delete m_setManager;
       
   130     }
       
   131     
       
   132     if (screensaverOn) {
       
   133         if (clockFormat() == ClockFormatAnalog) {
       
   134             newContainer = new SnsrOledAnalogClockContainer();
       
   135         }
       
   136         else {
       
   137             newContainer = new SnsrOledDigitalClockContainer();
       
   138         }
       
   139     }
       
   140     else {
       
   141         newContainer = new SnsrBlankContainer();
       
   142     }
       
   143     
       
   144     setCurrentContainer( newContainer );
       
   145 
       
   146     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPartialForeground")
       
   147     return true;
       
   148 }
       
   149 
       
   150 /*!
       
   151     @copydoc Screensaver::onBackground()
       
   152  */
       
   153 bool SnsrBigClockScreensaver::onBackground()
       
   154 {
       
   155     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onBackground")
       
   156     qDebug() << "SnsrBigClockScreensaver::onBackground()";
       
   157 
       
   158     removeCurrentContainer();
       
   159 
       
   160     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onBackground")
       
   161     return true;
       
   162 }
       
   163 
       
   164 /*!
       
   165     @copydoc Screensaver::onPowerSave()
       
   166  */
       
   167 bool SnsrBigClockScreensaver::onPowerSave()
       
   168 {
       
   169     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPowerSave")
       
   170     qDebug() << "SnsrBigClockScreensaver::onPowerSave()";
       
   171 
       
   172     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPowerSave")
       
   173     return false;
       
   174 }
       
   175 
       
   176 /*!
       
   177     @copydoc Screensaver::onClose()
       
   178  */
       
   179 bool SnsrBigClockScreensaver::onClose()
       
   180 {
       
   181     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onClose")
       
   182     qDebug() << "SnsrBigClockScreensaver::onClose()";
       
   183 
       
   184     bool ret(false);
       
   185     if (onBackground()) {
       
   186         delete mCurrentContainer;
       
   187         mCurrentContainer = 0;
       
   188         ret = true;
       
   189     }
       
   190 
       
   191     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onClose")
       
   192     return ret;
       
   193 }
       
   194 
       
   195 /*!
       
   196     @copydoc Screensaver::onHandleActiveIndicators
       
   197  */
       
   198 void SnsrBigClockScreensaver::onHandleActiveIndicators(
       
   199         const QList<HbIndicatorInterface*> &activeIndicators)
       
   200 {
       
   201     mIndicatorModel->handleActiveIndicators(activeIndicators);
       
   202 }
       
   203 
       
   204 /*!
       
   205     @copydoc Screensaver::onHandleActivatedIndicator
       
   206  */
       
   207 void SnsrBigClockScreensaver::onHandleActivatedIndicator(
       
   208         HbIndicatorInterface *activatedIndicator)
       
   209 {
       
   210     mIndicatorModel->handleActivatedIndicator(activatedIndicator);
       
   211 }
       
   212 
       
   213 /*!
       
   214     @copydoc Screensaver::onHandleDeactivatedIndicator
       
   215  */
       
   216 void SnsrBigClockScreensaver::onHandleDeactivatedIndicator(
       
   217         HbIndicatorInterface *deactivatedIndicator)
       
   218 {
       
   219     mIndicatorModel->handleDeactivatedIndicator(deactivatedIndicator);
       
   220 }
       
   221 
       
   222 /*!
       
   223     @copydoc Screensaver::currentPowerMode
       
   224  */
       
   225 Screensaver::ScreenPowerMode SnsrBigClockScreensaver::currentPowerMode()
       
   226 {
       
   227     Screensaver::ScreenPowerMode mode( Screensaver::ScreenModeFullPower );
       
   228     if ( mCurrentContainer ) {
       
   229         mode = mCurrentContainer->displayPowerMode();
       
   230     }
       
   231     else {
       
   232         qWarning() << "No current container when current power mode queried.";
       
   233     }
       
   234     return mode;
       
   235 }
       
   236 
       
   237 /*!
       
   238     @copydoc Screensaver::getActiveScreenRows
       
   239  */
       
   240 void SnsrBigClockScreensaver::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow)
       
   241 {
       
   242     if ( mCurrentContainer ) {
       
   243         mCurrentContainer->getActiveScreenRows( firstActiveRow, lastActiveRow );
       
   244     }
       
   245     else {
       
   246         qWarning() << "No current container when active rows queried.";
       
   247     }
       
   248 }
       
   249 
       
   250 /*!
       
   251     @copydoc Screensaver::updateLayout
       
   252  */
       
   253 void SnsrBigClockScreensaver::updateLayout()
       
   254 {
       
   255     if ( mCurrentContainer ) {
       
   256         if ( mCurrentContainer->isOrientationLocked() ) {
       
   257             mMainWindow->setOrientation( mMainWindow->orientation(), /*animate*/false );
       
   258         }
       
   259         else {
       
   260             mMainWindow->unsetOrientation( /*animate*/false );
       
   261         }
       
   262         mCurrentContainer->changeLayout( mMainWindow->orientation() );
       
   263     }
       
   264     else {
       
   265         qWarning() << "No current container when updateLayout called.";
       
   266     }
       
   267 }
       
   268 
       
   269 /*!
       
   270     Update clock time when timer is triggered
       
   271  */
       
   272 void SnsrBigClockScreensaver::updateTime()
       
   273 {
       
   274     if ( mCurrentContainer ) {
       
   275         mCurrentContainer->update();
       
   276         
       
   277         // Move the active area of display device if current container uses the power save mode.
       
   278         if ( mCurrentContainer->displayPowerMode() == Screensaver::ScreenModeLowPower ) {
       
   279             emit activeAreaMoved();
       
   280         }
       
   281     }
       
   282 }
       
   283 
       
   284 /*!
       
   285     Determines the curent clock format settings.
       
   286     \retval ClockFormat.
       
   287  */
       
   288 SnsrBigClockScreensaver::ClockFormat SnsrBigClockScreensaver::clockFormat()
       
   289 {
       
   290 #ifdef Q_OS_SYMBIAN
       
   291     if (TLocale().ClockFormat() == EClockAnalog) {
       
   292         return ClockFormatAnalog;
       
   293     } else {
       
   294         return ClockFormatDigital;
       
   295     }
       
   296 #else
       
   297     // windows build - change the format every 30 seconds for testing purposes
       
   298     if (QTime::currentTime().second() < 30) {
       
   299         return ClockFormatAnalog;
       
   300     } else {
       
   301         return ClockFormatDigital;
       
   302     }
       
   303 #endif // Q_OS_SYMBIAN
       
   304 }
       
   305 
       
   306 void SnsrBigClockScreensaver::removeCurrentContainer()
       
   307 {
       
   308     if ( mCurrentContainer ) {
       
   309         disconnect(
       
   310             &mTimer, SIGNAL(timeout()),
       
   311             this, SLOT(updateTime())
       
   312             );
       
   313         disconnect( 
       
   314             mCurrentContainer, SIGNAL(unlockRequested()), 
       
   315             this, SIGNAL(unlockRequested()) );
       
   316         if (mTimer.timerId()!= -1) {
       
   317             mTimer.stop();
       
   318         }
       
   319         emit viewChanged(0);
       
   320         
       
   321         delete mCurrentContainer;
       
   322         mCurrentContainer = 0;
       
   323     }
       
   324     
       
   325     mMainWindow->unsetOrientation( /*animate*/false );
       
   326 }
       
   327 
       
   328 void SnsrBigClockScreensaver::setCurrentContainer( SnsrBigClockContainer* newContainer )
       
   329 {
       
   330     mCurrentContainer = newContainer;
       
   331     mCurrentContainer->setParent(this);
       
   332     connect( &mTimer, SIGNAL(timeout()), SLOT(updateTime()) );
       
   333     connect( mCurrentContainer, SIGNAL(unlockRequested()), SIGNAL(unlockRequested()) );
       
   334     
       
   335     mCurrentContainer->setIndicatorModel(*mIndicatorModel);
       
   336 
       
   337     int updateInterval = mCurrentContainer->updateIntervalInMilliseconds(); 
       
   338     // blankcontainer is empty one, don't start timer with -1 return value
       
   339     if ( updateInterval != -1) {
       
   340         mTimer.start(updateInterval);
       
   341     }
       
   342     
       
   343     emit viewChanged(mCurrentContainer);
       
   344 }
       
   345