From 3e3fcdf1faa973c4158d488b8f102c45b1011ba3 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Sun, 8 Dec 2013 23:42:54 -0800 Subject: [PATCH] [libcontacts] Defer fetching changed contacts when display is off Do not respond immediately to contact change notifications when the display is turned off. Instead, defer fetching until the display is re-enabled. --- rpm/libcontacts-qt5.spec | 1 + rpm/libcontacts.spec | 1 + src/seasidecache.cpp | 55 ++++++++++++++++++++++++++++++---------- src/seasidecache.h | 2 ++ src/src.pro | 3 ++- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/rpm/libcontacts-qt5.spec b/rpm/libcontacts-qt5.spec index b5d196e..18f9072 100644 --- a/rpm/libcontacts-qt5.spec +++ b/rpm/libcontacts-qt5.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(Qt5Contacts) BuildRequires: pkgconfig(Qt5Versit) BuildRequires: pkgconfig(mlite5) BuildRequires: pkgconfig(mlocale5) +BuildRequires: pkgconfig(mce) BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) >= 0.1.35 %description diff --git a/rpm/libcontacts.spec b/rpm/libcontacts.spec index 31eafea..6a619bc 100644 --- a/rpm/libcontacts.spec +++ b/rpm/libcontacts.spec @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(QtCore) BuildRequires: pkgconfig(QtContacts) BuildRequires: pkgconfig(QtVersit) BuildRequires: pkgconfig(mlite) +BuildRequires: pkgconfig(mce) BuildRequires: pkgconfig(qtcontacts-sqlite-extensions) >= 0.1.35 %description diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index 1ee30b7..bc1f690 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -45,6 +45,7 @@ #else #include #endif +#include #include #include #include @@ -72,6 +73,9 @@ #include +#include +#include + #ifdef USING_QTPIM QTVERSIT_USE_NAMESPACE #endif @@ -501,6 +505,7 @@ SeasideCache::SeasideCache() , m_updatesPending(false) , m_refreshRequired(false) , m_contactsUpdated(false) + , m_displayOff(false) , m_activeResolve(0) { Q_ASSERT(!instancePtr); @@ -526,6 +531,11 @@ SeasideCache::SeasideCache() m_groupProperty = groupPropertyConf.toString(); #endif + if (!QDBusConnection::systemBus().connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, + MCE_DISPLAY_SIG, this, SLOT(displayStatusChanged(QString)))) { + qWarning() << "Unable to connect to MCE displayStatusChanged signal"; + } + QContactManager *mgr(manager()); // The contactsPresenceChanged signal is not exported by QContactManager, so we @@ -1486,7 +1496,7 @@ bool SeasideCache::event(QEvent *event) m_fetchProcessedCount = 0; m_fetchTypesChanged = false; m_populateProgress = RefetchFavorites; - } else if (!m_changedContacts.isEmpty() && !m_fetchRequest.isActive()) { + } else if (!m_changedContacts.isEmpty() && !m_fetchRequest.isActive() && !m_displayOff) { // If we request too many IDs we will exceed the SQLite bound variables limit // The actual limit is over 800, but we should reduce further to increase interactivity const int maxRequestIds = 200; @@ -1511,7 +1521,7 @@ bool SeasideCache::event(QEvent *event) m_fetchRequest.start(); m_fetchProcessedCount = 0; - } else if (!m_presenceChangedContacts.isEmpty() && !m_fetchRequest.isActive()) { + } else if (!m_presenceChangedContacts.isEmpty() && !m_fetchRequest.isActive() && !m_displayOff) { const int maxRequestIds = 200; #ifdef USING_QTPIM @@ -1619,7 +1629,10 @@ bool SeasideCache::event(QEvent *event) void SeasideCache::timerEvent(QTimerEvent *event) { if (event->timerId() == m_fetchTimer.timerId()) { - fetchContacts(); + // If the display is off, defer these fetches until they can be seen + if (!m_displayOff) { + fetchContacts(); + } } if (event->timerId() == m_expiryTimer.timerId()) { @@ -1756,17 +1769,20 @@ void SeasideCache::updateContacts(const QList &contactIds, QList< m_contactsUpdated = true; updateList->append(contactIds); - if (m_fetchPostponed.isValid()) { - // We are waiting to accumulate further changes - int remainder = MaxPostponementMs - m_fetchPostponed.elapsed(); - if (remainder > 0) { - // We can postpone further - m_fetchTimer.start(std::min(remainder, PostponementIntervalMs), this); + // If the display is off, defer fetching these changes + if (!m_displayOff) { + if (m_fetchPostponed.isValid()) { + // We are waiting to accumulate further changes + int remainder = MaxPostponementMs - m_fetchPostponed.elapsed(); + if (remainder > 0) { + // We can postpone further + m_fetchTimer.start(std::min(remainder, PostponementIntervalMs), this); + } + } else { + // Wait for further changes before we query for the ones we have now + m_fetchPostponed.restart(); + m_fetchTimer.start(PostponementIntervalMs, this); } - } else { - // Wait for further changes before we query for the ones we have now - m_fetchPostponed.restart(); - m_fetchTimer.start(PostponementIntervalMs, this); } } } @@ -2693,6 +2709,19 @@ void SeasideCache::groupPropertyChanged() #endif } +void SeasideCache::displayStatusChanged(const QString &status) +{ + const bool off = (status == QLatin1String(MCE_DISPLAY_OFF_STRING)); + if (m_displayOff != off) { + m_displayOff = off; + + if (!m_displayOff) { + // The display has been enabled; check for pending fetches + requestUpdate(); + } + } +} + int SeasideCache::importContacts(const QString &path) { QFile vcf(path); diff --git a/src/seasidecache.h b/src/seasidecache.h index 11b27e1..964e216 100644 --- a/src/seasidecache.h +++ b/src/seasidecache.h @@ -374,6 +374,7 @@ private slots: void displayLabelOrderChanged(); void sortPropertyChanged(); void groupPropertyChanged(); + void displayStatusChanged(const QString &); private: enum PopulateProgress { @@ -492,6 +493,7 @@ private slots: bool m_updatesPending; bool m_refreshRequired; bool m_contactsUpdated; + bool m_displayOff; QSet m_constituentIds; QSet m_candidateIds; diff --git a/src/src.pro b/src/src.pro index 36279da..0b0ab8d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -23,6 +23,7 @@ equals(QT_MAJOR_VERSION, 4) { } else { warning("mlite not available. Some functionality may not work as expected.") } + PKGCONFIG += mce } equals(QT_MAJOR_VERSION, 5) { packagesExist(mlite5) { @@ -31,7 +32,7 @@ equals(QT_MAJOR_VERSION, 5) { } else { warning("mlite not available. Some functionality may not work as expected.") } - PKGCONFIG += mlocale5 + PKGCONFIG += mlocale5 mce } DEFINES += CONTACTCACHE_BUILD