Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
[libcontacts] Defer fetching changed contacts when display is off
Browse files Browse the repository at this point in the history
Do not respond immediately to contact change notifications when the
display is turned off.  Instead, defer fetching until the display
is re-enabled.
  • Loading branch information
matthewvogt committed Dec 10, 2013
1 parent 9897220 commit 3e3fcdf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
1 change: 1 addition & 0 deletions rpm/libcontacts-qt5.spec
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions rpm/libcontacts.spec
Expand Up @@ -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
Expand Down
55 changes: 42 additions & 13 deletions src/seasidecache.cpp
Expand Up @@ -45,6 +45,7 @@
#else
#include <QDesktopServices>
#endif
#include <QDBusConnection>
#include <QDir>
#include <QEvent>
#include <QFile>
Expand Down Expand Up @@ -72,6 +73,9 @@

#include <mlocale.h>

#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#ifdef USING_QTPIM
QTVERSIT_USE_NAMESPACE
#endif
Expand Down Expand Up @@ -501,6 +505,7 @@ SeasideCache::SeasideCache()
, m_updatesPending(false)
, m_refreshRequired(false)
, m_contactsUpdated(false)
, m_displayOff(false)
, m_activeResolve(0)
{
Q_ASSERT(!instancePtr);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/seasidecache.h
Expand Up @@ -374,6 +374,7 @@ private slots:
void displayLabelOrderChanged();
void sortPropertyChanged();
void groupPropertyChanged();
void displayStatusChanged(const QString &);

private:
enum PopulateProgress {
Expand Down Expand Up @@ -492,6 +493,7 @@ private slots:
bool m_updatesPending;
bool m_refreshRequired;
bool m_contactsUpdated;
bool m_displayOff;
QSet<ContactIdType> m_constituentIds;
QSet<ContactIdType> m_candidateIds;

Expand Down
3 changes: 2 additions & 1 deletion src/src.pro
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 3e3fcdf

Please sign in to comment.