summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2010-11-04 15:49:00 +1000
committerChris Adams <christopher.adams@nokia.com>2010-11-04 16:11:42 +1000
commit45e23829dc8de7829886daf8fec2a24364949eb7 (patch)
treef7ccf221733917209b70a10a54eab9b5164350d3
parent591888d6ac38ae2b82319ecd4ca5270f69ec4376 (diff)
Fix signal emission in maemo5 organizer backend
Previously, no signals were emitted when database changes were detected in the database on disc. This commit fixes this issue, and updates the unit test to ensure that no regressions occur in the future. Relates to task: MOBILITY-1661 Reviewed by: Michael Goddard
-rw-r--r--plugins/organizer/maemo5/qorganizermaemo5.cpp20
-rw-r--r--plugins/organizer/maemo5/qorganizermaemo5_p.h2
-rw-r--r--tests/auto/qorganizermanager/tst_qorganizermanager.cpp15
3 files changed, 24 insertions, 13 deletions
diff --git a/plugins/organizer/maemo5/qorganizermaemo5.cpp b/plugins/organizer/maemo5/qorganizermaemo5.cpp
index b9875b6127..bcdc046776 100644
--- a/plugins/organizer/maemo5/qorganizermaemo5.cpp
+++ b/plugins/organizer/maemo5/qorganizermaemo5.cpp
@@ -251,7 +251,8 @@ QOrganizerItemMaemo5Engine::QOrganizerItemMaemo5Engine()
QString dbPath = QDir::homePath().append(CALENDAR).append(CALENDARDB);
QFileSystemWatcher *databaseMonitor = new QFileSystemWatcher(this);
databaseMonitor->addPath(dbPath);
- connect(databaseMonitor, SIGNAL(fileChanged(const QString &)), this, SLOT(dataChanged()));
+ connect(databaseMonitor, SIGNAL(fileChanged(QString)), this, SLOT(databaseChanged()));
+ connect(&m_waitTimer, SIGNAL(timeout()), this, SIGNAL(dataChanged()));
d->m_itemTransformer.setManagerUri(managerUri());
d->m_asynchProcess = new OrganizerAsynchProcess(this);
@@ -262,21 +263,22 @@ QOrganizerItemMaemo5Engine::QOrganizerItemMaemo5Engine()
bool dbOk = d->m_dbAccess->open(QDir::homePath().append(CALENDAR).append(CALENDARDB));
if (!dbOk) {
- qDebug() << "Database didn't open!";
- // TODO: Then what? Constructor has no error status. Throw an exception?
+ qWarning() << "QOrganizerItemMaemo5Engine: error: unable to open database; instance will be invalid.";
}
}
-void QOrganizerItemMaemo5Engine::dataChanged()
+void QOrganizerItemMaemo5Engine::databaseChanged()
{
// Timer prevents from sending multiple signals
// when database is changed during short period of time
- if (!m_waitTimer.isActive()) {
- m_waitTimer.setSingleShot(true);
- m_waitTimer.setInterval(50);
- m_waitTimer.start();
- emit dataChanged();
+ if (m_waitTimer.isActive()) {
+ // we need to reset the timer.
+ m_waitTimer.stop();
}
+
+ m_waitTimer.setSingleShot(true);
+ m_waitTimer.setInterval(50);
+ m_waitTimer.start();
}
QOrganizerItemMaemo5Engine::~QOrganizerItemMaemo5Engine()
diff --git a/plugins/organizer/maemo5/qorganizermaemo5_p.h b/plugins/organizer/maemo5/qorganizermaemo5_p.h
index cd7336d5d5..ca5f91bf3d 100644
--- a/plugins/organizer/maemo5/qorganizermaemo5_p.h
+++ b/plugins/organizer/maemo5/qorganizermaemo5_p.h
@@ -183,7 +183,7 @@ public:
bool waitForRequestFinished(QOrganizerAbstractRequest *req, int msecs);
public Q_SLOTS:
- void dataChanged();
+ void databaseChanged();
private:
QList<QOrganizerItem> internalItemOccurrences(const QOrganizerItem &parentItem, const QDateTime &periodStart, const QDateTime &periodEnd, int maxCount, QOrganizerManager::Error *error) const;
diff --git a/tests/auto/qorganizermanager/tst_qorganizermanager.cpp b/tests/auto/qorganizermanager/tst_qorganizermanager.cpp
index 9c68feb11e..1224221c09 100644
--- a/tests/auto/qorganizermanager/tst_qorganizermanager.cpp
+++ b/tests/auto/qorganizermanager/tst_qorganizermanager.cpp
@@ -2390,18 +2390,27 @@ void tst_QOrganizerManager::signalEmission()
/* Now some cross manager testing */
if (!m1->hasFeature(QOrganizerManager::Anonymous)) {
// verify that signals are emitted for modifications made to other managers (same id).
+ QSignalSpy spyDC(m1.data(), SIGNAL(dataChanged()));
+ spyDC.clear();
QOrganizerItemDisplayLabel ncs = todo.detail(QOrganizerItemDisplayLabel::DefinitionName);
ncs.setLabel("Test");
QVERIFY(todo.saveDetail(&ncs));
todo.setId(QOrganizerItemId()); // reset id so save can succeed.
QVERIFY(m2->saveItem(&todo));
+
+ // now modify and resave.
ncs.setLabel("Test2");
QVERIFY(todo.saveDetail(&ncs));
QVERIFY(m2->saveItem(&todo));
- QTRY_COMPARE(spyCA.count(), 1); // check that we received the update signals.
- QTRY_COMPARE(spyCM.count(), 1); // check that we received the update signals.
+
+ // we should have one addition and one modification (or at least a data changed signal).
+ QTRY_VERIFY(spyDC.count() || (spyCA.count() == 1)); // check that we received the update signals.
+ QTRY_VERIFY(spyDC.count() || (spyCM.count() == 1)); // check that we received the update signals.
+ todo = m2->item(todo.id()); // reload it.
+ QVERIFY(m1->item(todo.id()) == todo); // ensure we can read it from m1.
+ spyDC.clear();
m2->removeItem(todo.id());
- QTRY_COMPARE(spyCR.count(), 1); // check that we received the remove signal.
+ QTRY_VERIFY(spyDC.count() || (spyCR.count() == 1)); // check that we received the remove signal.
}
}