Commit 3e3fcdf1 authored by mvogt's avatar mvogt

[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.
parent 98972204
......@@ -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
......
......@@ -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
......
......@@ -45,6 +45,7 @@
#else
#include <QDesktopServices>
#endif
#include <QDBusConnection>
#include <QDir>
#include <QEvent>
#include <QFile>
......@@ -72,6 +73,9 @@
#include <mlocale.h>
#include <mce/dbus-names.h>
#include <mce/mode-names.h>
#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<ContactIdType> &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);
......
......@@ -374,6 +374,7 @@ private slots:
void displayLabelOrderChanged();
void sortPropertyChanged();
void groupPropertyChanged();
void displayStatusChanged(const QString &);
private:
enum PopulateProgress {
......@@ -492,6 +493,7 @@ private:
bool m_updatesPending;
bool m_refreshRequired;
bool m_contactsUpdated;
bool m_displayOff;
QSet<ContactIdType> m_constituentIds;
QSet<ContactIdType> m_candidateIds;
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment