Skip to content

Commit

Permalink
[qmf] Use periodic keepalive instead of a long running one(IMAP IDLE).
Browse files Browse the repository at this point in the history
This is a partial revert of d45bc6c
where a long running keepalive has introduced, but periodic is proven
to cause less battery comsumption in the long run.
  • Loading branch information
Valerio Valerio committed Feb 4, 2015
1 parent 91efba9 commit 19dd294
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 2 additions & 3 deletions qmf/src/plugins/messageservices/imap/imapclient.cpp
Expand Up @@ -2026,7 +2026,7 @@ bool ImapClient::pushEnabled()

void ImapClient::setPushEnabled(bool state)
{
if (_pushEnabled != state) {
if (pushEnabled() != state) {
qMailLog(Messaging) << Q_FUNC_INFO << "Setting push enabled state to " << state;
_pushEnabled = state;
}
Expand Down Expand Up @@ -2088,8 +2088,7 @@ void ImapClient::onSsoSessionResponse(const QMap<QString,QList<QByteArray> > &ss
}
if (_sendLogin) {
_protocol.sendLogin(_config, _ssoLogin);
}
if (_waitingForIdle) {
} else if (_waitingForIdle) {
monitor(_waitingForIdleFolderIds);
}
}
Expand Down
20 changes: 18 additions & 2 deletions qmf/src/plugins/messageservices/imap/imapservice.cpp
Expand Up @@ -1529,8 +1529,10 @@ ImapService::ImapService(const QMailAccountId &accountId)
connect(_initiatePushEmailTimer, SIGNAL(timeout()), this, SLOT(initiatePushEmail()));

#ifdef USE_KEEPALIVE
_idling = false;
_backgroundActivity = new BackgroundActivity(this);
_backgroundActivity->setWakeupFrequency(BackgroundActivity::ThirtySeconds);
connect(_backgroundActivity, SIGNAL(running()), this, SLOT(onUpdateLastSyncTime()));

// Connect to dbus signals emitted by buteo notifying schedule changes
QDBusConnection m_dBusConnection(QDBusConnection::sessionBus());
Expand Down Expand Up @@ -1634,6 +1636,7 @@ void ImapService::disable()
_restartPushEmailTimer->stop();
_initiatePushEmailTimer->stop();
#ifdef USE_KEEPALIVE
_idling = false;
_backgroundActivity->stop();
#endif
_source->setIntervalTimer(0);
Expand Down Expand Up @@ -1771,6 +1774,7 @@ void ImapService::initiatePushEmail()
_restartPushEmailTimer->stop();
_initiatePushEmailTimer->stop();
#ifdef USE_KEEPALIVE
_idling = false;
if (_backgroundActivity->isRunning()) {
_backgroundActivity->stop();
qMailLog(Messaging) << Q_FUNC_INFO << "Stopping keepalive";
Expand All @@ -1787,7 +1791,8 @@ void ImapService::initiatePushEmail()
_establishingPushEmail = true;
#ifdef USE_KEEPALIVE
qMailLog(Messaging) << Q_FUNC_INFO << "Starting keepalive";
_backgroundActivity->run();
_idling = true;
_backgroundActivity->wait();
#endif
QMailAccount account(_accountId);
const bool hasPersistentConnection = (account.status() & QMailAccount::HasPersistentConnection);
Expand Down Expand Up @@ -1848,11 +1853,22 @@ void ImapService::updateStatus(const QString &text)
}

#ifdef USE_KEEPALIVE
void ImapService::onUpdateLastSyncTime()
{
// start timer again if still in idle mode
if (_idling) {
_backgroundActivity->wait();
} else if (_backgroundActivity->isRunning()){
qMailLog(Messaging) << Q_FUNC_INFO << "Stopping keepalive";
_backgroundActivity->stop();
}
}

void ImapService::stopPushEmail()
{
qMailLog(Messaging) << "Stopping push email for account" << _accountId
<< QMailAccount(_accountId).name();

_idling = false;
QMailAccount account(_accountId);
const bool hasPersistentConnection = (account.status() & QMailAccount::HasPersistentConnection);
if (hasPersistentConnection) {
Expand Down
2 changes: 2 additions & 0 deletions qmf/src/plugins/messageservices/imap/imapservice.h
Expand Up @@ -79,6 +79,7 @@ protected slots:
void updateStatus(const QString& text);

#ifdef USE_KEEPALIVE
void onUpdateLastSyncTime();
void stopPushEmail();
void pushEnabledStatus(uint accountId, const QString &profileType, bool state);
#endif
Expand All @@ -102,6 +103,7 @@ protected slots:
QTimer *_initiatePushEmailTimer;
#ifdef USE_KEEPALIVE
BackgroundActivity* _backgroundActivity;
bool _idling;
bool _accountPushEnabled;
bool _buteoReplyReceived;
#endif
Expand Down

0 comments on commit 19dd294

Please sign in to comment.