screensaver/snsrplugins/snsrbigclockscreensaverplugin/src/snsrbigclockscreensaver.cpp
author hgs
Wed, 06 Oct 2010 16:06:24 +0300
changeset 97 66b5fe3c07fd
child 98 e6f74eb7f69f
permissions -rw-r--r--
201039_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
97
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     1
/*
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     3
* All rights reserved.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     8
*
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
     9
* Initial Contributors:
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    11
*
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    12
* Contributors:
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    13
*
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    14
* Description: Big clock Screensaver.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    15
*
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    16
*/
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    17
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    18
#include "snsrbigclockscreensaver.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    19
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    20
#ifdef Q_OS_SYMBIAN
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    21
#include <e32std.h>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    22
#include <XQSettingsManager> 
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    23
#include <screensaverdomaincrkeys.h>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    24
#endif // Q_OS_SYMBIAN
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    25
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    26
#include <QDebug>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    27
#include <QTime>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    28
#include <QTimer>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    29
#include <HbInstance>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    30
#include <HbMainWindow>
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    31
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    32
#include "snsranalogclockcontainer.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    33
#include "snsrdigitalclockcontainer.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    34
#include "snsroledanalogclockcontainer.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    35
#include "snsroleddigitalclockcontainer.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    36
#include "snsrblankcontainer.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    37
#include "snsrindicatormodel.h"
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    38
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    39
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    40
    \class SnsrBigClockScreensaver
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    41
    \ingroup group_snsrbigclockscreensaverplugin
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    42
    \brief Screensaver with big digital clock.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    43
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    44
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    45
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    46
    Constructs a new SnsrBigClockScreensaver.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    47
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    48
SnsrBigClockScreensaver::SnsrBigClockScreensaver() :
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    49
    mMainWindow(0),
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    50
    mCurrentContainer(0),
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    51
    mIndicatorModel(0)
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    52
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    53
    mMainWindow = HbInstance::instance()->allMainWindows().at(0);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    54
    // for nice looking clock hand transformations
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    55
    mMainWindow->setRenderHint(QPainter::SmoothPixmapTransform);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    56
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    57
    // This model holds indicator status information and must exist as
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    58
    // long as screensaver does.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    59
    mIndicatorModel = new SnsrIndicatorModel(this);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    60
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    61
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    62
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    63
    Destructs the class.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    64
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    65
SnsrBigClockScreensaver::~SnsrBigClockScreensaver()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    66
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    67
    // TODO: unlock orientation once the locking mechanism is available and used
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    68
    // mCurrentContainer, mIndicatorModel - deleted by the parent
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    69
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    70
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    71
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    72
    @copydoc Screensaver::onInitialize()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    73
*/
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    74
bool SnsrBigClockScreensaver::onInitialize()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    75
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    76
    qDebug() << "SnsrBigClockScreensaver::onInitialize()";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    77
    return true;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    78
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    79
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    80
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    81
    @copydoc Screensaver::onForeground()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    82
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    83
bool SnsrBigClockScreensaver::onForeground()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    84
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    85
    SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onForeground")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    86
    qDebug() << "SnsrBigClockScreensaver::onForeground()";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    87
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    88
    removeCurrentContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    89
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    90
    SnsrBigClockContainer* newContainer( 0 );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    91
    if (clockFormat() == ClockFormatAnalog) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    92
        newContainer = new SnsrAnalogClockContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    93
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    94
    else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    95
        newContainer = new SnsrDigitalClockContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    96
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    97
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    98
    setCurrentContainer( newContainer );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
    99
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   100
    SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onForeground")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   101
    return true;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   102
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   103
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   104
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   105
    @copydoc Screensaver::onPartialForeground()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   106
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   107
bool SnsrBigClockScreensaver::onPartialForeground()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   108
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   109
    SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPartialForeground")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   110
    qDebug() << "SnsrBigClockScreensaver::onPartialForeground()";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   111
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   112
    removeCurrentContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   113
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   114
    SnsrBigClockContainer* newContainer( 0 );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   115
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   116
#ifdef Q_OS_SYMBIAN  
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   117
    // Check ScreensaverStatus from repository
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   118
    XQSettingsManager::Error error;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   119
    XQCentralRepositorySettingsKey settingsKey(
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   120
            KCRUidScreensaverSettings.iUid, KScreensaverStatus ); // TUid as same repository used in control panel via Symbian APIs 
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   121
    XQSettingsManager setManager;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   122
    int screensaverOn = setManager.readItemValue(settingsKey, XQSettingsManager::TypeInt).toInt();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   123
    error = setManager.error();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   124
    if (error != XQSettingsManager::NoError) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   125
        qDebug("Error reading value from XQSettingsManager.. error = %d", error);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   126
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   127
#else
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   128
    int screensaverOn = 1;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   129
#endif // Q_OS_SYMBIAN
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   130
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   131
    if (screensaverOn) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   132
        if (clockFormat() == ClockFormatAnalog) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   133
            newContainer = new SnsrOledAnalogClockContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   134
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   135
        else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   136
            newContainer = new SnsrOledDigitalClockContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   137
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   138
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   139
    else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   140
        newContainer = new SnsrBlankContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   141
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   142
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   143
    setCurrentContainer( newContainer );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   144
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   145
    SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPartialForeground")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   146
    return true;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   147
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   148
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   149
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   150
    @copydoc Screensaver::onBackground()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   151
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   152
bool SnsrBigClockScreensaver::onBackground()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   153
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   154
    SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onBackground")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   155
    qDebug() << "SnsrBigClockScreensaver::onBackground()";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   156
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   157
    removeCurrentContainer();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   158
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   159
    SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onBackground")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   160
    return true;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   161
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   162
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   163
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   164
    @copydoc Screensaver::onPowerSave()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   165
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   166
bool SnsrBigClockScreensaver::onPowerSave()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   167
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   168
    SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onPowerSave")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   169
    qDebug() << "SnsrBigClockScreensaver::onPowerSave()";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   170
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   171
    SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onPowerSave")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   172
    return false;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   173
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   174
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   175
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   176
    @copydoc Screensaver::onClose()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   177
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   178
bool SnsrBigClockScreensaver::onClose()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   179
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   180
    SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockScreensaver::onClose")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   181
    qDebug() << "SnsrBigClockScreensaver::onClose()";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   182
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   183
    bool ret(false);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   184
    if (onBackground()) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   185
        delete mCurrentContainer;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   186
        mCurrentContainer = 0;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   187
        ret = true;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   188
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   189
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   190
    SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockScreensaver::onClose")
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   191
    return ret;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   192
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   193
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   194
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   195
    @copydoc Screensaver::onHandleActiveIndicators
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   196
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   197
void SnsrBigClockScreensaver::onHandleActiveIndicators(
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   198
        const QList<HbIndicatorInterface*> &activeIndicators)
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   199
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   200
    mIndicatorModel->handleActiveIndicators(activeIndicators);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   201
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   202
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   203
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   204
    @copydoc Screensaver::onHandleActivatedIndicator
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   205
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   206
void SnsrBigClockScreensaver::onHandleActivatedIndicator(
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   207
        HbIndicatorInterface *activatedIndicator)
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   208
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   209
    mIndicatorModel->handleActivatedIndicator(activatedIndicator);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   210
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   211
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   212
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   213
    @copydoc Screensaver::onHandleDeactivatedIndicator
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   214
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   215
void SnsrBigClockScreensaver::onHandleDeactivatedIndicator(
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   216
        HbIndicatorInterface *deactivatedIndicator)
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   217
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   218
    mIndicatorModel->handleDeactivatedIndicator(deactivatedIndicator);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   219
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   220
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   221
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   222
    @copydoc Screensaver::currentPowerMode
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   223
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   224
Screensaver::ScreenPowerMode SnsrBigClockScreensaver::currentPowerMode()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   225
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   226
    Screensaver::ScreenPowerMode mode( Screensaver::ScreenModeFullPower );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   227
    if ( mCurrentContainer ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   228
        mode = mCurrentContainer->displayPowerMode();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   229
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   230
    else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   231
        qWarning() << "No current container when current power mode queried.";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   232
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   233
    return mode;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   234
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   235
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   236
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   237
    @copydoc Screensaver::getActiveScreenRows
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   238
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   239
void SnsrBigClockScreensaver::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow)
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   240
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   241
    if ( mCurrentContainer ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   242
        mCurrentContainer->getActiveScreenRows( firstActiveRow, lastActiveRow );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   243
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   244
    else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   245
        qWarning() << "No current container when active rows queried.";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   246
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   247
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   248
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   249
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   250
    @copydoc Screensaver::updateLayout
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   251
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   252
void SnsrBigClockScreensaver::updateLayout()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   253
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   254
    if ( mCurrentContainer ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   255
        if ( mCurrentContainer->isOrientationLocked() ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   256
            // TODO: There is currently no way for device dialog to lock the display orientation.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   257
            // Orbit team has a backlog item about "global orientation lock" which could be
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   258
            // used here when it is available.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   259
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   260
        else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   261
            // TODO: There is currently no way for device dialog to lock the display orientation.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   262
            // Orbit team has a backlog item about "global orientation lock" which could be
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   263
            // used here when it is available.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   264
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   265
        mCurrentContainer->changeLayout( mMainWindow->orientation() );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   266
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   267
    else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   268
        qWarning() << "No current container when updateLayout called.";
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   269
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   270
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   271
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   272
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   273
    Update clock time when timer is triggered
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   274
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   275
void SnsrBigClockScreensaver::updateTime()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   276
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   277
    if ( mCurrentContainer ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   278
        mCurrentContainer->update();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   279
        
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   280
        // Move the active area of display device if current container uses the power save mode.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   281
        if ( mCurrentContainer->displayPowerMode() == Screensaver::ScreenModeLowPower ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   282
            emit activeAreaMoved();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   283
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   284
        
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   285
        // Ensure correct update interval is used. First timed update may be done
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   286
        // with timeout differing from the normal update rate.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   287
        int updateInterval = mCurrentContainer->updateIntervalInMilliseconds();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   288
        if ( updateInterval > 0 ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   289
            mTimer.setInterval( updateInterval );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   290
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   291
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   292
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   293
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   294
/*!
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   295
    Determines the curent clock format settings.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   296
    \retval ClockFormat.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   297
 */
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   298
SnsrBigClockScreensaver::ClockFormat SnsrBigClockScreensaver::clockFormat()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   299
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   300
#ifdef Q_OS_SYMBIAN
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   301
    if (TLocale().ClockFormat() == EClockAnalog) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   302
        return ClockFormatAnalog;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   303
    } else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   304
        return ClockFormatDigital;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   305
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   306
#else
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   307
    // windows build - change the format every 30 seconds for testing purposes
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   308
    if (QTime::currentTime().second() < 30) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   309
        return ClockFormatAnalog;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   310
    } else {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   311
        return ClockFormatDigital;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   312
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   313
#endif // Q_OS_SYMBIAN
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   314
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   315
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   316
void SnsrBigClockScreensaver::removeCurrentContainer()
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   317
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   318
    if ( mCurrentContainer ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   319
        disconnect(
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   320
            &mTimer, SIGNAL(timeout()),
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   321
            this, SLOT(updateTime())
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   322
            );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   323
        disconnect( 
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   324
            mCurrentContainer, SIGNAL(unlockRequested()), 
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   325
            this, SIGNAL(unlockRequested()) );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   326
        if (mTimer.timerId()!= -1) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   327
            mTimer.stop();
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   328
        }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   329
        emit viewChanged(0);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   330
        
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   331
        delete mCurrentContainer;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   332
        mCurrentContainer = 0;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   333
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   334
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   335
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   336
void SnsrBigClockScreensaver::setCurrentContainer( SnsrBigClockContainer* newContainer )
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   337
{
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   338
    mCurrentContainer = newContainer;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   339
    mCurrentContainer->setParent(this);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   340
    connect( &mTimer, SIGNAL(timeout()), SLOT(updateTime()) );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   341
    connect( mCurrentContainer, SIGNAL(unlockRequested()), SIGNAL(unlockRequested()) );
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   342
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   343
    mCurrentContainer->setIndicatorModel(*mIndicatorModel);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   344
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   345
    int updateInterval = mCurrentContainer->updateIntervalInMilliseconds(); 
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   346
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   347
    // In case the container needs an update seldomly (at maximum once per minute),
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   348
    // align these updates with the even minutes by doing the first update on the
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   349
    // next even minute.
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   350
    const int minute = 60*1000;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   351
    if ( updateInterval >= minute ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   352
        updateInterval = minute - QTime::currentTime().second()*1000;
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   353
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   354
    // container can use negative updateInteval value to indicate that no recurring
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   355
    // updates are needed
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   356
    if ( updateInterval > 0 ) {
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   357
        mTimer.start(updateInterval);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   358
    }
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   359
    
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   360
    emit viewChanged(mCurrentContainer);
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   361
}
66b5fe3c07fd 201039_01
hgs
parents:
diff changeset
   362