Configurable delay for feeds update after app start - fixes #193.

This commit is contained in:
Martin Rotter 2020-06-03 14:13:51 +02:00
parent db4947eb4b
commit 35f8936292
9 changed files with 148 additions and 39 deletions

View file

@ -52,7 +52,7 @@
#define MIN_CATEGORY_NAME_LENGTH 1 #define MIN_CATEGORY_NAME_LENGTH 1
#define DEFAULT_AUTO_UPDATE_INTERVAL 15 #define DEFAULT_AUTO_UPDATE_INTERVAL 15
#define AUTO_UPDATE_INTERVAL 60000 #define AUTO_UPDATE_INTERVAL 60000
#define STARTUP_UPDATE_DELAY 30000 #define STARTUP_UPDATE_DELAY 3.0 // In seconds.
#define TIMEZONE_OFFSET_LIMIT 6 #define TIMEZONE_OFFSET_LIMIT 6
#define CHANGE_EVENT_DELAY 250 #define CHANGE_EVENT_DELAY 250
#define FLAG_ICON_SUBFOLDER "flags" #define FLAG_ICON_SUBFOLDER "flags"

View file

@ -20,6 +20,8 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
: SettingsPanel(settings, parent), m_ui(new Ui::SettingsFeedsMessages) { : SettingsPanel(settings, parent), m_ui(new Ui::SettingsFeedsMessages) {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->m_spinStartupUpdateDelay->setMode(TimeSpinBox::Mode::MinutesSeconds);
initializeMessageDateFormats(); initializeMessageDateFormats();
GuiUtilities::setLabelAsNotice(*m_ui->label_9, false); GuiUtilities::setLabelAsNotice(*m_ui->label_9, false);
@ -44,6 +46,8 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
connect(m_ui->m_checkUpdateAllFeedsOnStartup, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings); connect(m_ui->m_checkUpdateAllFeedsOnStartup, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_spinAutoUpdateInterval, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), connect(m_ui->m_spinAutoUpdateInterval, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &SettingsFeedsMessages::dirtifySettings); this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_spinStartupUpdateDelay, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_spinHeightImageAttachments, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(m_ui->m_spinHeightImageAttachments, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &SettingsFeedsMessages::dirtifySettings); this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_spinHeightRowsMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(m_ui->m_spinHeightRowsMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
@ -51,6 +55,7 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
connect(m_ui->m_spinHeightRowsFeeds, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(m_ui->m_spinHeightRowsFeeds, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &SettingsFeedsMessages::dirtifySettings); this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_checkAutoUpdate, &QCheckBox::toggled, m_ui->m_spinAutoUpdateInterval, &TimeSpinBox::setEnabled); connect(m_ui->m_checkAutoUpdate, &QCheckBox::toggled, m_ui->m_spinAutoUpdateInterval, &TimeSpinBox::setEnabled);
connect(m_ui->m_checkUpdateAllFeedsOnStartup, &QCheckBox::toggled, m_ui->m_spinStartupUpdateDelay, &TimeSpinBox::setEnabled);
connect(m_ui->m_spinFeedUpdateTimeout, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, connect(m_ui->m_spinFeedUpdateTimeout, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&SettingsFeedsMessages::dirtifySettings); &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_cmbMessagesDateTimeFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, connect(m_ui->m_cmbMessagesDateTimeFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
@ -126,6 +131,10 @@ void SettingsFeedsMessages::loadSettings() {
m_ui->m_spinAutoUpdateInterval->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::AutoUpdateInterval)).toInt()); m_ui->m_spinAutoUpdateInterval->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::AutoUpdateInterval)).toInt());
m_ui->m_spinFeedUpdateTimeout->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt()); m_ui->m_spinFeedUpdateTimeout->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt());
m_ui->m_checkUpdateAllFeedsOnStartup->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateOnStartup)).toBool()); m_ui->m_checkUpdateAllFeedsOnStartup->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateOnStartup)).toBool());
auto aa = settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateStartupDelay)).toDouble();
m_ui->m_spinStartupUpdateDelay->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateStartupDelay)).toDouble());
m_ui->m_cmbCountsFeedList->addItems(QStringList() << "(%unread)" << "[%unread]" << "%unread/%all" << "%unread-%all" << "[%unread|%all]"); m_ui->m_cmbCountsFeedList->addItems(QStringList() << "(%unread)" << "[%unread]" << "%unread/%all" << "%unread-%all" << "[%unread|%all]");
m_ui->m_cmbCountsFeedList->setEditText(settings()->value(GROUP(Feeds), SETTING(Feeds::CountFormat)).toString()); m_ui->m_cmbCountsFeedList->setEditText(settings()->value(GROUP(Feeds), SETTING(Feeds::CountFormat)).toString());
m_ui->m_spinHeightImageAttachments->setValue(settings()->value(GROUP(Messages), SETTING(Messages::MessageHeadImageHeight)).toInt()); m_ui->m_spinHeightImageAttachments->setValue(settings()->value(GROUP(Messages), SETTING(Messages::MessageHeadImageHeight)).toInt());
@ -181,6 +190,7 @@ void SettingsFeedsMessages::saveSettings() {
settings()->setValue(GROUP(Feeds), Feeds::AutoUpdateInterval, m_ui->m_spinAutoUpdateInterval->value()); settings()->setValue(GROUP(Feeds), Feeds::AutoUpdateInterval, m_ui->m_spinAutoUpdateInterval->value());
settings()->setValue(GROUP(Feeds), Feeds::UpdateTimeout, m_ui->m_spinFeedUpdateTimeout->value()); settings()->setValue(GROUP(Feeds), Feeds::UpdateTimeout, m_ui->m_spinFeedUpdateTimeout->value());
settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateOnStartup, m_ui->m_checkUpdateAllFeedsOnStartup->isChecked()); settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateOnStartup, m_ui->m_checkUpdateAllFeedsOnStartup->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateStartupDelay, m_ui->m_spinStartupUpdateDelay->value());
settings()->setValue(GROUP(Feeds), Feeds::CountFormat, m_ui->m_cmbCountsFeedList->currentText()); settings()->setValue(GROUP(Feeds), Feeds::CountFormat, m_ui->m_cmbCountsFeedList->currentText());
settings()->setValue(GROUP(Messages), Messages::UseCustomDate, m_ui->m_checkMessagesDateTimeFormat->isChecked()); settings()->setValue(GROUP(Messages), Messages::UseCustomDate, m_ui->m_checkMessagesDateTimeFormat->isChecked());
settings()->setValue(GROUP(Messages), Messages::MessageHeadImageHeight, m_ui->m_spinHeightImageAttachments->value()); settings()->setValue(GROUP(Messages), Messages::MessageHeadImageHeight, m_ui->m_spinHeightImageAttachments->value());

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>651</width> <width>651</width>
<height>478</height> <height>497</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
@ -34,30 +34,16 @@
</attribute> </attribute>
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="m_checkUpdateAllFeedsOnStartup"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="text">
<string>Update all feed on application startup</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="m_checkAutoUpdateNotification">
<property name="text">
<string>Enable &quot;auto-update started&quot; notification</string>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
<widget class="QCheckBox" name="m_checkAutoUpdate"> <widget class="QCheckBox" name="m_checkUpdateAllFeedsOnStartup">
<property name="text"> <property name="text">
<string>Auto-update all feeds every</string> <string>Update all feed on application startup with initial delay of</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="TimeSpinBox" name="m_spinAutoUpdateInterval"> <widget class="TimeSpinBox" name="m_spinStartupUpdateDelay">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -77,6 +63,20 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0">
<widget class="QCheckBox" name="m_checkAutoUpdateNotification">
<property name="text">
<string>Enable &quot;auto-update started&quot; notification</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="m_checkAutoUpdateOnlyUnfocused">
<property name="text">
<string>Only auto-update when application is unfocused</string>
</property>
</widget>
</item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QGroupBox" name="groupBox_6"> <widget class="QGroupBox" name="groupBox_6">
<property name="title"> <property name="title">
@ -88,6 +88,9 @@
<property name="text"> <property name="text">
<string>Font preview</string> <string>Font preview</string>
</property> </property>
<property name="buddy">
<cstring>m_btnChangeFeedListFont</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -181,6 +184,36 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="m_checkAutoUpdate">
<property name="text">
<string>Auto-update all feeds every</string>
</property>
</widget>
</item>
<item>
<widget class="TimeSpinBox" name="m_spinAutoUpdateInterval">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="readOnly">
<bool>false</bool>
</property>
<property name="accelerated">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0" colspan="2"> <item row="8" column="0" colspan="2">
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="font"> <property name="font">
@ -199,12 +232,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkAutoUpdateOnlyUnfocused"> <spacer name="verticalSpacer">
<property name="text"> <property name="orientation">
<string>Only auto-update when application is unfocused</string> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -311,6 +350,9 @@
<property name="text"> <property name="text">
<string>Font preview</string> <string>Font preview</string>
</property> </property>
<property name="buddy">
<cstring>m_btnChangeMessageListFont</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -334,6 +376,9 @@
<property name="text"> <property name="text">
<string>Font preview</string> <string>Font preview</string>
</property> </property>
<property name="buddy">
<cstring>m_btnChangeMessagesFont</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -348,6 +393,19 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -364,9 +422,11 @@
<tabstops> <tabstops>
<tabstop>m_tabFeedsMessages</tabstop> <tabstop>m_tabFeedsMessages</tabstop>
<tabstop>m_checkUpdateAllFeedsOnStartup</tabstop> <tabstop>m_checkUpdateAllFeedsOnStartup</tabstop>
<tabstop>m_spinStartupUpdateDelay</tabstop>
<tabstop>m_checkAutoUpdateNotification</tabstop> <tabstop>m_checkAutoUpdateNotification</tabstop>
<tabstop>m_checkAutoUpdate</tabstop> <tabstop>m_checkAutoUpdate</tabstop>
<tabstop>m_spinAutoUpdateInterval</tabstop> <tabstop>m_spinAutoUpdateInterval</tabstop>
<tabstop>m_checkAutoUpdateOnlyUnfocused</tabstop>
<tabstop>m_btnChangeFeedListFont</tabstop> <tabstop>m_btnChangeFeedListFont</tabstop>
<tabstop>m_spinFeedUpdateTimeout</tabstop> <tabstop>m_spinFeedUpdateTimeout</tabstop>
<tabstop>m_spinHeightRowsFeeds</tabstop> <tabstop>m_spinHeightRowsFeeds</tabstop>

View file

@ -5,10 +5,10 @@
#include <QStringList> #include <QStringList>
TimeSpinBox::TimeSpinBox(QWidget* parent) : QDoubleSpinBox(parent) { TimeSpinBox::TimeSpinBox(QWidget* parent) : QDoubleSpinBox(parent) {
setMinimum(3.0);
setAccelerated(true); setAccelerated(true);
setDecimals(0); setMinimum(3.0);
setMaximum(10000000.0); setMaximum(10000000.0);
setMode(TimeSpinBox::Mode::HoursMinutes);
} }
double TimeSpinBox::valueFromText(const QString& text) const { double TimeSpinBox::valueFromText(const QString& text) const {
@ -44,13 +44,26 @@ double TimeSpinBox::valueFromText(const QString& text) const {
} }
QString TimeSpinBox::textFromValue(double val) const { QString TimeSpinBox::textFromValue(double val) const {
int minutes_total = int(val); if (mode() == TimeSpinBox::Mode::HoursMinutes) {
int minutes_val = minutes_total % 60; // "val" is number of minutes.
int hours_val = (minutes_total - minutes_val) / 60; int minutes_total = int(val);
QString hours = tr("%n hour(s)", "", hours_val); int minutes_val = minutes_total % 60;
QString minutes = tr("%n minute(s)", "", minutes_val); int hours_val = (minutes_total - minutes_val) / 60;
QString hours = tr("%n hour(s)", "", hours_val);
QString minutes = tr("%n minute(s)", "", minutes_val);
return hours + tr(" and ") + minutes; return hours + tr(" and ") + minutes;
}
else {
// "val" is number of seconds.
int seconds_val = int(val);
int minutes_total = seconds_val / 60;
int seconds_total = seconds_val - (minutes_total * 60);
QString seconds = tr("%n seconds(s)", "", seconds_total);
QString minutes = tr("%n minute(s)", "", minutes_total);
return minutes + tr(" and ") + seconds;
}
} }
void TimeSpinBox::fixup(QString& input) const { void TimeSpinBox::fixup(QString& input) const {
@ -66,3 +79,13 @@ QValidator::State TimeSpinBox::validate(QString& input, int& pos) const {
Q_UNUSED(pos) Q_UNUSED(pos)
return (valueFromText(input) != -1.0) ? QValidator::Acceptable : QValidator::Intermediate; return (valueFromText(input) != -1.0) ? QValidator::Acceptable : QValidator::Intermediate;
} }
TimeSpinBox::Mode TimeSpinBox::mode() const {
return m_mode;
}
void TimeSpinBox::setMode(const TimeSpinBox::Mode& mode) {
m_mode = mode;
setValue(value());
}

View file

@ -9,12 +9,23 @@ class TimeSpinBox : public QDoubleSpinBox {
Q_OBJECT Q_OBJECT
public: public:
enum class Mode {
HoursMinutes,
MinutesSeconds
};
explicit TimeSpinBox(QWidget* parent = nullptr); explicit TimeSpinBox(QWidget* parent = nullptr);
double valueFromText(const QString& text) const; double valueFromText(const QString& text) const;
QString textFromValue(double val) const; QString textFromValue(double val) const;
void fixup(QString& input) const; void fixup(QString& input) const;
QValidator::State validate(QString& input, int& pos) const; QValidator::State validate(QString& input, int& pos) const;
Mode mode() const;
void setMode(const TimeSpinBox::Mode& mode);
private:
Mode m_mode;
}; };
#endif // TIMESPINBOX_H #endif // TIMESPINBOX_H

View file

@ -35,7 +35,9 @@ FeedReader::FeedReader(QObject* parent)
if (qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateOnStartup)).toBool()) { if (qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateOnStartup)).toBool()) {
qDebug("Requesting update for all feeds on application startup."); qDebug("Requesting update for all feeds on application startup.");
QTimer::singleShot(STARTUP_UPDATE_DELAY, this, SLOT(updateAllFeeds())); QTimer::singleShot(qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateStartupDelay)).toDouble() * 1000,
this,
&FeedReader::updateAllFeeds);
} }
} }

View file

@ -57,15 +57,11 @@ class RSSGUARD_DLLSPEC FeedReader : public QObject {
int autoUpdateInitialInterval() const; int autoUpdateInitialInterval() const;
public slots: public slots:
// Schedules all feeds from all accounts for update.
void updateAllFeeds(); void updateAllFeeds();
void stopRunningFeedUpdate(); void stopRunningFeedUpdate();
void quit(); void quit();
private slots: private slots:
// Is executed when next auto-update round could be done.
void executeNextAutoUpdate(); void executeNextAutoUpdate();
void checkServicesForAsyncOperations(); void checkServicesForAsyncOperations();
void asyncCacheSaveFinished(); void asyncCacheSaveFinished();

View file

@ -55,6 +55,10 @@ DKEY Feeds::FeedsUpdateOnStartup = "feeds_update_on_startup";
DVALUE(bool) Feeds::FeedsUpdateOnStartupDef = false; DVALUE(bool) Feeds::FeedsUpdateOnStartupDef = false;
DKEY Feeds::FeedsUpdateStartupDelay = "feeds_update_on_startup_delay";
DVALUE(double) Feeds::FeedsUpdateStartupDelayDef = STARTUP_UPDATE_DELAY;
DKEY Feeds::ShowOnlyUnreadFeeds = "show_only_unread_feeds"; DKEY Feeds::ShowOnlyUnreadFeeds = "show_only_unread_feeds";
DVALUE(bool) Feeds::ShowOnlyUnreadFeedsDef = false; DVALUE(bool) Feeds::ShowOnlyUnreadFeedsDef = false;
@ -446,7 +450,6 @@ SettingsProperties Settings::determineProperties() {
// We will use PORTABLE settings only and only if it is available and NON-PORTABLE // We will use PORTABLE settings only and only if it is available and NON-PORTABLE
// settings was not initialized before. // settings was not initialized before.
#if defined (Q_OS_LINUX) || defined (Q_OS_ANDROID) || defined (Q_OS_MACOS) #if defined (Q_OS_LINUX) || defined (Q_OS_ANDROID) || defined (Q_OS_MACOS)
// DO NOT use portable settings for Linux, it is really not used on that platform. // DO NOT use portable settings for Linux, it is really not used on that platform.
const bool will_we_use_portable_settings = false; const bool will_we_use_portable_settings = false;
#else #else

View file

@ -76,6 +76,10 @@ namespace Feeds {
VALUE(bool) FeedsUpdateOnStartupDef; VALUE(bool) FeedsUpdateOnStartupDef;
KEY FeedsUpdateStartupDelay;
VALUE(double) FeedsUpdateStartupDelayDef;
KEY ShowOnlyUnreadFeeds; KEY ShowOnlyUnreadFeeds;
VALUE(bool) ShowOnlyUnreadFeedsDef; VALUE(bool) ShowOnlyUnreadFeedsDef;