Improved auto-update feature.

This commit is contained in:
Martin Rotter 2014-02-04 18:55:37 +01:00
parent 4efdcd6262
commit 57427f7d5d
5 changed files with 48 additions and 27 deletions

View File

@ -389,7 +389,7 @@ bool FeedsModel::editStandardFeed(FeedsModelStandardFeed *original_feed,
return true; return true;
} }
QList<FeedsModelFeed*> FeedsModel::feedsForScheduledUpdate(int global_auto_update_minutes_remaining) { QList<FeedsModelFeed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<FeedsModelFeed*> feeds_for_update; QList<FeedsModelFeed*> feeds_for_update;
foreach (FeedsModelFeed *feed, allFeeds()) { foreach (FeedsModelFeed *feed, allFeeds()) {
@ -401,7 +401,7 @@ QList<FeedsModelFeed*> FeedsModel::feedsForScheduledUpdate(int global_auto_updat
continue; continue;
case FeedsModelStandardFeed::DefaultAutoUpdate: case FeedsModelStandardFeed::DefaultAutoUpdate:
if (global_auto_update_minutes_remaining == 0) { if (auto_update_now) {
feeds_for_update.append(feed); feeds_for_update.append(feed);
} }

View File

@ -68,7 +68,7 @@ class FeedsModel : public QAbstractItemModel {
// Returns the list of updates which should be updated // Returns the list of updates which should be updated
// according to auto-update schedule. // according to auto-update schedule.
QList<FeedsModelFeed*> feedsForScheduledUpdate(int global_auto_update_minutes_remaining); QList<FeedsModelFeed*> feedsForScheduledUpdate(bool auto_update_now);
// Returns (undeleted) messages for given feeds. // Returns (undeleted) messages for given feeds.
QList<Message> messagesForFeeds(const QList<FeedsModelFeed*> &feeds); QList<Message> messagesForFeeds(const QList<FeedsModelFeed*> &feeds);

View File

@ -78,15 +78,37 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const {
case Qt::ToolTipRole: case Qt::ToolTipRole:
if (column == FDS_MODEL_TITLE_INDEX) { if (column == FDS_MODEL_TITLE_INDEX) {
QString auto_update_string;
switch (m_autoUpdateType) {
case DontAutoUpdate:
auto_update_string = QObject::tr("does not use auto-update");
break;
case DefaultAutoUpdate:
auto_update_string = QObject::tr("uses global settings");
break;
case SpecificAutoUpdate:
default:
auto_update_string = QObject::tr("uses specific settings "
"(%n minute(s) to next auto-update)",
0,
m_autoUpdateRemainingInterval);
break;
}
return QObject::tr("%1 (%2)\n" return QObject::tr("%1 (%2)\n"
"%3\n\n" "%3\n\n"
"Encoding: %4").arg(m_title, "Encoding: %4\n"
FeedsModelFeed::typeToString(m_type), "Auto-update status: %5").arg(m_title,
m_description, FeedsModelFeed::typeToString(m_type),
m_encoding); m_description,
m_encoding,
auto_update_string);
} }
else if (column == FDS_MODEL_COUNTS_INDEX) { else if (column == FDS_MODEL_COUNTS_INDEX) {
return QObject::tr("%n unread message(s).", "", countOfUnreadMessages()); return QObject::tr("%n unread message(s).", 0, countOfUnreadMessages());
} }
else { else {
return QVariant(); return QVariant();

View File

@ -54,25 +54,21 @@ void FeedsView::quit() {
} }
void FeedsView::updateAutoUpdateStatus() { void FeedsView::updateAutoUpdateStatus() {
// Update intervals. // Restore global intervals.
// NOTE: Specific per-feed interval are left intact.
m_globalAutoUpdateInitialInterval = Settings::instance()->value(APP_CFG_FEEDS, "auto_update_interval", DEFAULT_AUTO_UPDATE_INTERVAL).toInt(); m_globalAutoUpdateInitialInterval = Settings::instance()->value(APP_CFG_FEEDS, "auto_update_interval", DEFAULT_AUTO_UPDATE_INTERVAL).toInt();
m_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval; m_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval;
m_globalAutoUpdateEnabled = Settings::instance()->value(APP_CFG_FEEDS, "auto_update_enabled", false).toBool();
// Start/stop the timer as needed. // Start global auto-update timer if it is not running yet.
if (Settings::instance()->value(APP_CFG_FEEDS, "auto_update_enabled", false).toBool()) { // NOTE: The timer must run even if global auto-update
if (!m_autoUpdateTimer->isActive()) { // is not enabled because user can still enable auto-update
m_autoUpdateTimer->setInterval(AUTO_UPDATE_INTERVAL); // for individual feeds.
m_autoUpdateTimer->start(); if (!m_autoUpdateTimer->isActive()) {
m_autoUpdateTimer->setInterval(AUTO_UPDATE_INTERVAL);
m_autoUpdateTimer->start();
qDebug("Auto-update timer started with interval %d.", m_autoUpdateTimer->interval()); qDebug("Auto-update timer started with interval %d.", m_autoUpdateTimer->interval());
}
}
else {
if (m_autoUpdateTimer->isActive()) {
m_autoUpdateTimer->stop();
qDebug("Auto-update timer stopped.");
}
} }
} }
@ -151,9 +147,11 @@ void FeedsView::executeNextAutoUpdate() {
return; return;
} }
// If this reaches less than zero, then feeds with global auto-update interval should // If global auto-update is enabled
// be updated. // and its interval counter reached zero,
if (--m_globalAutoUpdateRemainingInterval < 0) { // then we need to restore it.
if (m_globalAutoUpdateEnabled &&
--m_globalAutoUpdateRemainingInterval < 0) {
// We should start next auto-update interval. // We should start next auto-update interval.
m_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval; m_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval;
} }
@ -163,7 +161,7 @@ void FeedsView::executeNextAutoUpdate() {
// Pass needed interval data and lets the model decide which feeds // Pass needed interval data and lets the model decide which feeds
// should be updated in this pass. // should be updated in this pass.
QList<FeedsModelFeed*> feeds_for_update = m_sourceModel->feedsForScheduledUpdate(m_globalAutoUpdateRemainingInterval); QList<FeedsModelFeed*> feeds_for_update = m_sourceModel->feedsForScheduledUpdate(m_globalAutoUpdateRemainingInterval == 0);
if (feeds_for_update.isEmpty()) { if (feeds_for_update.isEmpty()) {
// No feeds are scheduled for update now, unlock the master lock. // No feeds are scheduled for update now, unlock the master lock.

View File

@ -144,6 +144,7 @@ class FeedsView : public QTreeView {
// Auto-update stuff. // Auto-update stuff.
QTimer *m_autoUpdateTimer; QTimer *m_autoUpdateTimer;
bool m_globalAutoUpdateEnabled;
int m_globalAutoUpdateInitialInterval; int m_globalAutoUpdateInitialInterval;
int m_globalAutoUpdateRemainingInterval; int m_globalAutoUpdateRemainingInterval;
}; };