Skip to content

Commit

Permalink
Changes: Clock updates not in sync with iphb
Browse files Browse the repository at this point in the history
RevBy: Vesa Halttunen
  • Loading branch information
Pankaj Saharan committed Jul 18, 2011
1 parent d02f259 commit dedb758
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 11 deletions.
21 changes: 19 additions & 2 deletions src/systemui/statusarea/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
** of this file.
**
****************************************************************************/

#include "clock.h"
#include <MLocale>

Expand All @@ -26,11 +25,15 @@ Clock::Clock(QGraphicsItem *parent) :
#ifdef HAVE_QMSYSTEM
// Be interested in changes to system time
connect(&qmTime, SIGNAL(timeOrSettingsChanged(MeeGo::QmTime::WhatChanged)), this, SLOT(updateModelAndSetupTimer()));
#endif

// Configure the heartbeat
qmHeartbeat.open(MeeGo::QmHeartbeat::SignalNeeded);
connect(&qmHeartbeat, SIGNAL(wakeUp(QTime)), this, SLOT(updateModelAndSetupTimer()));
#else
// Configure the timer
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()), this, SLOT(updateModelAndSetupTimer()));
#endif

if (isOnDisplay()) {
// Start updating the time if the clock is already on display, otherwise start updating on the first enterDisplayEvent()
Expand All @@ -54,17 +57,31 @@ void Clock::updateModelAndSetupTimer()
time.setHMS(time.hour(), time.minute(), 0);
nextUpdateTime.setTime(time);

#ifdef HAVE_QMSYSTEM
qmHeartbeat.wait(currentTime.secsTo(nextUpdateTime) + 1,
currentTime.secsTo(nextUpdateTime) + 2,
MeeGo::QmHeartbeat::DoNotWaitHeartbeat);
#else
// Set the time of the next update and start the timer. The extra one second is used for rounding up to make sure that we always hit the next minute, not the current one.
timer.start((currentTime.secsTo(nextUpdateTime) + 1) * 1000);
#endif
}

void Clock::enterDisplayEvent()
{
#ifdef HAVE_QMSYSTEM
qmHeartbeat.IWokeUp();
#else
timer.stop();
#endif
updateModelAndSetupTimer();
}

void Clock::exitDisplayEvent()
{
#ifdef HAVE_QMSYSTEM
qmHeartbeat.IWokeUp();
#else
timer.stop();
#endif
}
11 changes: 7 additions & 4 deletions src/systemui/statusarea/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#ifdef HAVE_QMSYSTEM
#include <qmtime.h>
#include <qmheartbeat.h>
#endif

/*!
Expand Down Expand Up @@ -59,12 +60,14 @@ private slots:
virtual void exitDisplayEvent();
//! \reimp_end

//! Update timer
QTimer timer;

#ifdef HAVE_QMSYSTEM
//! QmTime object to get the time format is
//! QmHeartbeat object for time updates
MeeGo::QmHeartbeat qmHeartbeat;
//! QmTime object to get the time format
MeeGo::QmTime qmTime;
#else
//! Update timer
QTimer timer;
#endif

#ifdef UNIT_TEST
Expand Down
84 changes: 79 additions & 5 deletions tests/ut_clock/ut_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QtTest/QtTest>
#ifdef HAVE_QMSYSTEM
#include <qmtime.h>
#include <qmheartbeat.h>
#endif
#include "ut_clock.h"
#include "clock.h"
Expand Down Expand Up @@ -49,6 +50,31 @@ void QTimer::stop()
Ut_Clock::timerTimeout = -1;
}

#ifdef HAVE_QMSYSTEM
int gMintime, gMaxtime;
bool gHeartBeatServiceOpened = false;
MeeGo::QmHeartbeat::SignalNeed gSignalNeed;
bool MeeGo::QmHeartbeat::open(MeeGo::QmHeartbeat::SignalNeed signalNeed) {
gSignalNeed = signalNeed;
return gHeartBeatServiceOpened = true;
}

bool gWakeUp = false;
bool MeeGo::QmHeartbeat::IWokeUp(void)
{
return gWakeUp = true;
}

MeeGo::QmHeartbeat::WaitMode gWaitMode;
QTime MeeGo::QmHeartbeat::wait(unsigned short mintime, unsigned short maxtime, QmHeartbeat::WaitMode wait)
{
gMintime = mintime;
gMaxtime = maxtime;
gWaitMode = wait;
return QTime();
}
#endif

int Ut_Clock::timerTimeout = -1;
QDateTime Ut_Clock::expectedDateTime;

Expand All @@ -66,6 +92,14 @@ void Ut_Clock::cleanupTestCase()
// Called before each testfunction is executed
void Ut_Clock::init()
{
#ifdef HAVE_QMSYSTEM
gMintime = 0;
gMaxtime = 0;
gWakeUp = false;
gWaitMode = MeeGo::QmHeartbeat::WaitHeartbeat;
gSignalNeed = MeeGo::QmHeartbeat::NoSignalNeeded;
gHeartBeatServiceOpened = false;
#endif
m_subject = new Clock;
}

Expand Down Expand Up @@ -94,14 +128,28 @@ void Ut_Clock::testConstruction()
mWidgetIsOnDisplay = isOnDisplay;
m_subject = new Clock;

#ifdef HAVE_QMSYSTEM
QCOMPARE(gHeartBeatServiceOpened, true);
QCOMPARE(gSignalNeed, MeeGo::QmHeartbeat::SignalNeeded);
QVERIFY(disconnect(&m_subject->qmHeartbeat, SIGNAL(wakeUp(QTime)), m_subject, SLOT(updateModelAndSetupTimer())));
#else
QVERIFY(disconnect(&m_subject->timer, SIGNAL(timeout()), m_subject, SLOT(updateModelAndSetupTimer())));
QVERIFY(m_subject->timer.isSingleShot());
#endif

QDateTime nextUpdateTime = expectedDateTime.addSecs(60);
QTime time = nextUpdateTime.time();
time.setHMS(time.hour(), time.minute(), 0);
nextUpdateTime.setTime(time);

if (isOnDisplay) {
#ifdef HAVE_QMSYSTEM
QCOMPARE(gMintime, expectedDateTime.secsTo(nextUpdateTime) + 1);
QCOMPARE(gMaxtime, expectedDateTime.secsTo(nextUpdateTime) + 2);
QCOMPARE(gWaitMode, MeeGo::QmHeartbeat::DoNotWaitHeartbeat);
#else
QVERIFY(timerTimeout > expectedDateTime.msecsTo(nextUpdateTime));
#endif
} else {
QCOMPARE(timerTimeout, -1);
}
Expand All @@ -116,18 +164,44 @@ void Ut_Clock::testTimeUpdate()

void Ut_Clock::testModelUpdates()
{
// The timer should be running by default and the model should contain the current time
QVERIFY(timerTimeout >= 0);
#ifdef HAVE_QMSYSTEM
// qmHeartbeat.wait() is called with proper parameters
// Seconds to next update time should be 60
QCOMPARE(gMintime, 60 + 1);
QCOMPARE(gMaxtime, 60 + 2);
QCOMPARE(gWaitMode, MeeGo::QmHeartbeat::DoNotWaitHeartbeat);
#else
// Check if the timer is running
QVERIFY(timerTimeout >=0);
#endif
// The model should contain the current time
QCOMPARE(m_subject->model()->time(), expectedDateTime);

// When the application becomes invisible the timer should stop
// Check when the application becomes invisible
m_subject->exitDisplayEvent();
#ifdef HAVE_QMSYSTEM
// qmHeartbeat IWokeUp() is called
QCOMPARE(gWakeUp, true);
#else
// The timer should stop
QCOMPARE(timerTimeout, -1);
#endif

// When the application becomes visible the timer should start and the model should be updated to contain the current time
// Check when the application becomes visible
#ifdef HAVE_QMSYSTEM
gWakeUp = false;
#endif
expectedDateTime = QDateTime(QDate(2001, 1, 1));
m_subject->enterDisplayEvent();
QVERIFY(timerTimeout >= 0);

#ifdef HAVE_QMSYSTEM
// qmHeartbeat IWokeUp() is called
QCOMPARE(gWakeUp, true);
#else
// The timer should start
QVERIFY(timerTimeout >=0);
#endif
//The model should be updated to contain the current time
QCOMPARE(m_subject->model()->time(), expectedDateTime);
}

Expand Down

0 comments on commit dedb758

Please sign in to comment.