Skip to content

Commit

Permalink
Use std::chrono::seconds for fetchDelay
Browse files Browse the repository at this point in the history
Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
  • Loading branch information
jNullj and Chocobo1 committed Dec 3, 2023
1 parent fad287c commit e1d5d28
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/base/rss/rss_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ const QString DATA_FOLDER_NAME = u"rss/articles"_s;
const QString FEEDS_FILE_NAME = u"feeds.json"_s;

using namespace RSS;
using namespace std::chrono_literals;

QPointer<Session> Session::m_instance = nullptr;

Session::Session()
: m_storeProcessingEnabled(u"RSS/Session/EnableProcessing"_s)
, m_storeRefreshInterval(u"RSS/Session/RefreshInterval"_s, 30)
, m_storeFetchDelay(u"RSS/Session/FetchDelay"_s, 2)
, m_storeFetchDelay(u"RSS/Session/FetchDelay"_s, 2s)
, m_storeMaxArticlesPerFeed(u"RSS/Session/MaxArticlesPerFeed"_s, 50)
, m_workingThread(new QThread)
{
Expand Down Expand Up @@ -526,15 +527,16 @@ void Session::setRefreshInterval(const int refreshInterval)
}
}

int Session::fetchDelay() const
std::chrono::seconds Session::fetchDelay() const
{
return m_storeFetchDelay;
}

void Session::setFetchDelay(const int fetchDelay)
void Session::setFetchDelay(const std::chrono::seconds delay)
{
if (m_storeFetchDelay == fetchDelay) { return; }
m_storeFetchDelay = fetchDelay;
if (delay == fetchDelay())
return;
m_storeFetchDelay = delay;
}

QThread *Session::workingThread() const
Expand Down
8 changes: 5 additions & 3 deletions src/base/rss/rss_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
* 3. Feed is JSON object (keys are property names, values are property values; 'uid' and 'url' are required)
*/

#include <chrono>

#include <QHash>
#include <QObject>
#include <QPointer>
Expand Down Expand Up @@ -114,8 +116,8 @@ namespace RSS
int refreshInterval() const;
void setRefreshInterval(int refreshInterval);

int fetchDelay() const;
void setFetchDelay(int fetchDelay);
std::chrono::seconds fetchDelay() const;
void setFetchDelay(std::chrono::seconds delay);

nonstd::expected<void, QString> addFolder(const QString &path);
nonstd::expected<void, QString> addFeed(const QString &url, const QString &path);
Expand Down Expand Up @@ -164,7 +166,7 @@ namespace RSS

CachedSettingValue<bool> m_storeProcessingEnabled;
CachedSettingValue<int> m_storeRefreshInterval;
CachedSettingValue<int> m_storeFetchDelay;
CachedSettingValue<std::chrono::seconds> m_storeFetchDelay;
CachedSettingValue<int> m_storeMaxArticlesPerFeed;
Utils::Thread::UniquePtr m_workingThread;
AsyncFileStorage *m_confFileStorage = nullptr;
Expand Down
9 changes: 9 additions & 0 deletions src/base/settingsstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@

#pragma once

#include <chrono>
#include <type_traits>

#include <QObject>
#include <QReadWriteLock>
#include <QTimer>
#include <qtypes.h>
#include <QVariant>
#include <QVariantHash>

Expand Down Expand Up @@ -84,6 +86,11 @@ class SettingsStorage final : public QObject
const typename T::Int value = loadValue(key, static_cast<typename T::Int>(defaultValue));
return T {value};
}
else if constexpr (std::same_as<T, std::chrono::seconds>)
{
const qlonglong value = loadValue(key, static_cast<qlonglong>(defaultValue.count()));
return std::chrono::seconds(value);
}
else
{
const QVariant value = loadValueImpl(key);
Expand All @@ -103,6 +110,8 @@ class SettingsStorage final : public QObject
storeValueImpl(key, Utils::String::fromEnum(value));
else if constexpr (IsQFlags<T>)
storeValueImpl(key, static_cast<typename T::Int>(value));
else if constexpr (std::same_as<T, std::chrono::seconds>)
storeValueImpl(key, static_cast<qlonglong>(value.count()));
else
storeValueImpl(key, QVariant::fromValue(value));
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "optionsdialog.h"

#include <chrono>
#include <cstdlib>
#include <limits>

Expand Down Expand Up @@ -1164,7 +1165,7 @@ void OptionsDialog::loadRSSTabOptions()

m_ui->checkRSSEnable->setChecked(rssSession->isProcessingEnabled());
m_ui->spinRSSRefreshInterval->setValue(rssSession->refreshInterval());
m_ui->spinRSSFetchDelay->setValue(rssSession->fetchDelay());
m_ui->spinRSSFetchDelay->setValue(rssSession->fetchDelay().count());
m_ui->spinRSSMaxArticlesPerFeed->setValue(rssSession->maxArticlesPerFeed());
m_ui->checkRSSAutoDownloaderEnable->setChecked(autoDownloader->isProcessingEnabled());
m_ui->textSmartEpisodeFilters->setPlainText(autoDownloader->smartEpisodeFilters().join(u'\n'));
Expand Down Expand Up @@ -1192,7 +1193,7 @@ void OptionsDialog::saveRSSTabOptions() const

rssSession->setProcessingEnabled(m_ui->checkRSSEnable->isChecked());
rssSession->setRefreshInterval(m_ui->spinRSSRefreshInterval->value());
rssSession->setFetchDelay(m_ui->spinRSSFetchDelay->value());
rssSession->setFetchDelay(std::chrono::seconds(m_ui->spinRSSFetchDelay->value()));
rssSession->setMaxArticlesPerFeed(m_ui->spinRSSMaxArticlesPerFeed->value());
autoDownloader->setProcessingEnabled(m_ui->checkRSSAutoDownloaderEnable->isChecked());
autoDownloader->setSmartEpisodeFilters(m_ui->textSmartEpisodeFilters->toPlainText().split(u'\n', Qt::SkipEmptyParts));
Expand Down
4 changes: 2 additions & 2 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void AppController::preferencesAction()

// RSS settings
data[u"rss_refresh_interval"_s] = RSS::Session::instance()->refreshInterval();
data[u"rss_fetch_delay"_s] = RSS::Session::instance()->fetchDelay();
data[u"rss_fetch_delay"_s] = static_cast<int>(RSS::Session::instance()->fetchDelay().count());
data[u"rss_max_articles_per_feed"_s] = RSS::Session::instance()->maxArticlesPerFeed();
data[u"rss_processing_enabled"_s] = RSS::Session::instance()->isProcessingEnabled();
data[u"rss_auto_downloading_enabled"_s] = RSS::AutoDownloader::instance()->isProcessingEnabled();
Expand Down Expand Up @@ -862,7 +862,7 @@ void AppController::setPreferencesAction()
if (hasKey(u"rss_refresh_interval"_s))
RSS::Session::instance()->setRefreshInterval(it.value().toInt());
if (hasKey(u"rss_fetch_delay"_s))
RSS::Session::instance()->setFetchDelay(it.value().toInt());
RSS::Session::instance()->setFetchDelay(std::chrono::seconds(it.value().toInt()));
if (hasKey(u"rss_max_articles_per_feed"_s))
RSS::Session::instance()->setMaxArticlesPerFeed(it.value().toInt());
if (hasKey(u"rss_processing_enabled"_s))
Expand Down

0 comments on commit e1d5d28

Please sign in to comment.