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

View File

@ -68,7 +68,7 @@ class FeedsModel : public QAbstractItemModel {
// Returns the list of updates which should be updated
// 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.
QList<Message> messagesForFeeds(const QList<FeedsModelFeed*> &feeds);

View File

@ -78,15 +78,37 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const {
case Qt::ToolTipRole:
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"
"%3\n\n"
"Encoding: %4").arg(m_title,
"Encoding: %4\n"
"Auto-update status: %5").arg(m_title,
FeedsModelFeed::typeToString(m_type),
m_description,
m_encoding);
m_encoding,
auto_update_string);
}
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 {
return QVariant();

View File

@ -54,26 +54,22 @@ void FeedsView::quit() {
}
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_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval;
m_globalAutoUpdateEnabled = Settings::instance()->value(APP_CFG_FEEDS, "auto_update_enabled", false).toBool();
// Start/stop the timer as needed.
if (Settings::instance()->value(APP_CFG_FEEDS, "auto_update_enabled", false).toBool()) {
// Start global auto-update timer if it is not running yet.
// NOTE: The timer must run even if global auto-update
// is not enabled because user can still enable auto-update
// for individual feeds.
if (!m_autoUpdateTimer->isActive()) {
m_autoUpdateTimer->setInterval(AUTO_UPDATE_INTERVAL);
m_autoUpdateTimer->start();
qDebug("Auto-update timer started with interval %d.", m_autoUpdateTimer->interval());
}
}
else {
if (m_autoUpdateTimer->isActive()) {
m_autoUpdateTimer->stop();
qDebug("Auto-update timer stopped.");
}
}
}
void FeedsView::setSortingEnabled(bool enable) {
@ -151,9 +147,11 @@ void FeedsView::executeNextAutoUpdate() {
return;
}
// If this reaches less than zero, then feeds with global auto-update interval should
// be updated.
if (--m_globalAutoUpdateRemainingInterval < 0) {
// If global auto-update is enabled
// and its interval counter reached zero,
// then we need to restore it.
if (m_globalAutoUpdateEnabled &&
--m_globalAutoUpdateRemainingInterval < 0) {
// We should start next auto-update interval.
m_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval;
}
@ -163,7 +161,7 @@ void FeedsView::executeNextAutoUpdate() {
// Pass needed interval data and lets the model decide which feeds
// 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()) {
// No feeds are scheduled for update now, unlock the master lock.

View File

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