mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-11 15:56:17 -07:00
parent
b28c229f85
commit
627d89813c
16 changed files with 405 additions and 99 deletions
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2024 Jonathan Ketchker
|
* Copyright (C) 2024 Jonathan Ketchker
|
||||||
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
|
|
||||||
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
||||||
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
||||||
*
|
*
|
||||||
|
@ -56,19 +56,22 @@
|
||||||
|
|
||||||
const QString KEY_UID = u"uid"_s;
|
const QString KEY_UID = u"uid"_s;
|
||||||
const QString KEY_URL = u"url"_s;
|
const QString KEY_URL = u"url"_s;
|
||||||
|
const QString KEY_REFRESHINTERVAL = u"refreshInterval"_s;
|
||||||
const QString KEY_TITLE = u"title"_s;
|
const QString KEY_TITLE = u"title"_s;
|
||||||
const QString KEY_LASTBUILDDATE = u"lastBuildDate"_s;
|
const QString KEY_LASTBUILDDATE = u"lastBuildDate"_s;
|
||||||
const QString KEY_ISLOADING = u"isLoading"_s;
|
const QString KEY_ISLOADING = u"isLoading"_s;
|
||||||
const QString KEY_HASERROR = u"hasError"_s;
|
const QString KEY_HASERROR = u"hasError"_s;
|
||||||
const QString KEY_ARTICLES = u"articles"_s;
|
const QString KEY_ARTICLES = u"articles"_s;
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
using namespace RSS;
|
using namespace RSS;
|
||||||
|
|
||||||
Feed::Feed(const QUuid &uid, const QString &url, const QString &path, Session *session)
|
Feed::Feed(Session *session, const QUuid &uid, const QString &url, const QString &path, const std::chrono::seconds refreshInterval)
|
||||||
: Item(path)
|
: Item(path)
|
||||||
, m_session(session)
|
, m_session {session}
|
||||||
, m_uid(uid)
|
, m_uid {uid}
|
||||||
, m_url(url)
|
, m_url {url}
|
||||||
|
, m_refreshInterval {refreshInterval}
|
||||||
{
|
{
|
||||||
const auto uidHex = QString::fromLatin1(m_uid.toRfc4122().toHex());
|
const auto uidHex = QString::fromLatin1(m_uid.toRfc4122().toHex());
|
||||||
m_dataFileName = Path(uidHex + u".json");
|
m_dataFileName = Path(uidHex + u".json");
|
||||||
|
@ -462,6 +465,20 @@ Path Feed::iconPath() const
|
||||||
return m_iconPath;
|
return m_iconPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::chrono::seconds Feed::refreshInterval() const
|
||||||
|
{
|
||||||
|
return m_refreshInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Feed::setRefreshInterval(const std::chrono::seconds refreshInterval)
|
||||||
|
{
|
||||||
|
if (refreshInterval == m_refreshInterval)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const std::chrono::seconds oldRefreshInterval = std::exchange(m_refreshInterval, refreshInterval);
|
||||||
|
emit refreshIntervalChanged(oldRefreshInterval);
|
||||||
|
}
|
||||||
|
|
||||||
void Feed::setURL(const QString &url)
|
void Feed::setURL(const QString &url)
|
||||||
{
|
{
|
||||||
const QString oldURL = m_url;
|
const QString oldURL = m_url;
|
||||||
|
@ -474,6 +491,8 @@ QJsonValue Feed::toJsonValue(const bool withData) const
|
||||||
QJsonObject jsonObj;
|
QJsonObject jsonObj;
|
||||||
jsonObj.insert(KEY_UID, uid().toString());
|
jsonObj.insert(KEY_UID, uid().toString());
|
||||||
jsonObj.insert(KEY_URL, url());
|
jsonObj.insert(KEY_URL, url());
|
||||||
|
if (refreshInterval() > 0s)
|
||||||
|
jsonObj.insert(KEY_REFRESHINTERVAL, static_cast<qint64>(refreshInterval().count()));
|
||||||
|
|
||||||
if (withData)
|
if (withData)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2024 Jonathan Ketchker
|
* Copyright (C) 2024 Jonathan Ketchker
|
||||||
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
|
|
||||||
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
||||||
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
||||||
*
|
*
|
||||||
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include <QtContainerFwd>
|
#include <QtContainerFwd>
|
||||||
#include <QBasicTimer>
|
#include <QBasicTimer>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
@ -68,7 +70,7 @@ namespace RSS
|
||||||
|
|
||||||
friend class Session;
|
friend class Session;
|
||||||
|
|
||||||
Feed(const QUuid &uid, const QString &url, const QString &path, Session *session);
|
Feed(Session *session, const QUuid &uid, const QString &url, const QString &path, std::chrono::seconds refreshInterval);
|
||||||
~Feed() override;
|
~Feed() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -87,6 +89,9 @@ namespace RSS
|
||||||
Article *articleByGUID(const QString &guid) const;
|
Article *articleByGUID(const QString &guid) const;
|
||||||
Path iconPath() const;
|
Path iconPath() const;
|
||||||
|
|
||||||
|
std::chrono::seconds refreshInterval() const;
|
||||||
|
void setRefreshInterval(std::chrono::seconds refreshInterval);
|
||||||
|
|
||||||
QJsonValue toJsonValue(bool withData = false) const override;
|
QJsonValue toJsonValue(bool withData = false) const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -94,6 +99,7 @@ namespace RSS
|
||||||
void titleChanged(Feed *feed = nullptr);
|
void titleChanged(Feed *feed = nullptr);
|
||||||
void stateChanged(Feed *feed = nullptr);
|
void stateChanged(Feed *feed = nullptr);
|
||||||
void urlChanged(const QString &oldURL);
|
void urlChanged(const QString &oldURL);
|
||||||
|
void refreshIntervalChanged(std::chrono::seconds oldRefreshInterval);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleSessionProcessingEnabledChanged(bool enabled);
|
void handleSessionProcessingEnabledChanged(bool enabled);
|
||||||
|
@ -123,6 +129,7 @@ namespace RSS
|
||||||
Private::FeedSerializer *m_serializer = nullptr;
|
Private::FeedSerializer *m_serializer = nullptr;
|
||||||
const QUuid m_uid;
|
const QUuid m_uid;
|
||||||
QString m_url;
|
QString m_url;
|
||||||
|
std::chrono::seconds m_refreshInterval;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_lastBuildDate;
|
QString m_lastBuildDate;
|
||||||
bool m_hasError = false;
|
bool m_hasError = false;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2015-2024 Vladimir Golovnev <glassez@yandex.ru>
|
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2015-2024 Vladimir Golovnev <glassez@yandex.ru>
|
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2017-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2024 Jonathan Ketchker
|
* Copyright (C) 2024 Jonathan Ketchker
|
||||||
* Copyright (C) 2017 Vladimir Golovnev <glassez@yandex.ru>
|
|
||||||
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
||||||
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
||||||
*
|
*
|
||||||
|
@ -56,6 +56,7 @@ const QString CONF_FOLDER_NAME = u"rss"_s;
|
||||||
const QString DATA_FOLDER_NAME = u"rss/articles"_s;
|
const QString DATA_FOLDER_NAME = u"rss/articles"_s;
|
||||||
const QString FEEDS_FILE_NAME = u"feeds.json"_s;
|
const QString FEEDS_FILE_NAME = u"feeds.json"_s;
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
using namespace RSS;
|
using namespace RSS;
|
||||||
|
|
||||||
QPointer<Session> Session::m_instance = nullptr;
|
QPointer<Session> Session::m_instance = nullptr;
|
||||||
|
@ -94,12 +95,10 @@ Session::Session()
|
||||||
m_workingThread->start();
|
m_workingThread->start();
|
||||||
load();
|
load();
|
||||||
|
|
||||||
|
m_refreshTimer.setSingleShot(true);
|
||||||
connect(&m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
|
connect(&m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
|
||||||
if (isProcessingEnabled())
|
if (isProcessingEnabled())
|
||||||
{
|
|
||||||
m_refreshTimer.start(std::chrono::minutes(refreshInterval()));
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
|
||||||
|
|
||||||
// Remove legacy/corrupted settings
|
// Remove legacy/corrupted settings
|
||||||
// (at least on Windows, QSettings is case-insensitive and it can get
|
// (at least on Windows, QSettings is case-insensitive and it can get
|
||||||
|
@ -138,19 +137,20 @@ Session *Session::instance()
|
||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
nonstd::expected<void, QString> Session::addFolder(const QString &path)
|
nonstd::expected<Folder *, QString> Session::addFolder(const QString &path)
|
||||||
{
|
{
|
||||||
const nonstd::expected<Folder *, QString> result = prepareItemDest(path);
|
const nonstd::expected<Folder *, QString> result = prepareItemDest(path);
|
||||||
if (!result)
|
if (!result)
|
||||||
return result.get_unexpected();
|
return result.get_unexpected();
|
||||||
|
|
||||||
auto *destFolder = result.value();
|
auto *destFolder = result.value();
|
||||||
addItem(new Folder(path), destFolder);
|
auto *folder = new Folder(path);
|
||||||
|
addItem(folder, destFolder);
|
||||||
store();
|
store();
|
||||||
return {};
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
nonstd::expected<void, QString> Session::addFeed(const QString &url, const QString &path)
|
nonstd::expected<Feed *, QString> Session::addFeed(const QString &url, const QString &path, const std::chrono::seconds refreshInterval)
|
||||||
{
|
{
|
||||||
if (m_feedsByURL.contains(url))
|
if (m_feedsByURL.contains(url))
|
||||||
return nonstd::make_unexpected(tr("RSS feed with given URL already exists: %1.").arg(url));
|
return nonstd::make_unexpected(tr("RSS feed with given URL already exists: %1.").arg(url));
|
||||||
|
@ -160,13 +160,13 @@ nonstd::expected<void, QString> Session::addFeed(const QString &url, const QStri
|
||||||
return result.get_unexpected();
|
return result.get_unexpected();
|
||||||
|
|
||||||
auto *destFolder = result.value();
|
auto *destFolder = result.value();
|
||||||
auto *feed = new Feed(generateUID(), url, path, this);
|
auto *feed = new Feed(this, generateUID(), url, path, refreshInterval);
|
||||||
addItem(feed, destFolder);
|
addItem(feed, destFolder);
|
||||||
store();
|
store();
|
||||||
if (isProcessingEnabled())
|
if (isProcessingEnabled())
|
||||||
feed->refresh();
|
refreshFeed(feed, std::chrono::system_clock::now());
|
||||||
|
|
||||||
return {};
|
return feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
nonstd::expected<void, QString> Session::setFeedURL(const QString &path, const QString &url)
|
nonstd::expected<void, QString> Session::setFeedURL(const QString &path, const QString &url)
|
||||||
|
@ -192,7 +192,7 @@ nonstd::expected<void, QString> Session::setFeedURL(Feed *feed, const QString &u
|
||||||
feed->setURL(url);
|
feed->setURL(url);
|
||||||
store();
|
store();
|
||||||
if (isProcessingEnabled())
|
if (isProcessingEnabled())
|
||||||
feed->refresh();
|
refreshFeed(feed, std::chrono::system_clock::now());
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ bool Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
|
||||||
QString url = val.toString();
|
QString url = val.toString();
|
||||||
if (url.isEmpty())
|
if (url.isEmpty())
|
||||||
url = key;
|
url = key;
|
||||||
addFeedToFolder(generateUID(), url, key, folder);
|
addFeedToFolder(generateUID(), url, key, folder, 0s);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
else if (val.isObject())
|
else if (val.isObject())
|
||||||
|
@ -354,7 +354,9 @@ bool Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addFeedToFolder(uid, valObj[u"url"].toString(), key, folder);
|
const auto refreshInterval = std::chrono::seconds(valObj[u"refreshInterval"].toInteger());
|
||||||
|
|
||||||
|
addFeedToFolder(uid, valObj[u"url"].toString(), key, folder, refreshInterval);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -410,7 +412,7 @@ void Session::loadLegacy()
|
||||||
void Session::store()
|
void Session::store()
|
||||||
{
|
{
|
||||||
m_confFileStorage->store(Path(FEEDS_FILE_NAME)
|
m_confFileStorage->store(Path(FEEDS_FILE_NAME)
|
||||||
, QJsonDocument(rootFolder()->toJsonValue().toObject()).toJson());
|
, QJsonDocument(rootFolder()->toJsonValue().toObject()).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
nonstd::expected<Folder *, QString> Session::prepareItemDest(const QString &path)
|
nonstd::expected<Folder *, QString> Session::prepareItemDest(const QString &path)
|
||||||
|
@ -436,9 +438,9 @@ Folder *Session::addSubfolder(const QString &name, Folder *parentFolder)
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed *Session::addFeedToFolder(const QUuid &uid, const QString &url, const QString &name, Folder *parentFolder)
|
Feed *Session::addFeedToFolder(const QUuid &uid, const QString &url, const QString &name, Folder *parentFolder, const std::chrono::seconds refreshInterval)
|
||||||
{
|
{
|
||||||
auto *feed = new Feed(uid, url, Item::joinPath(parentFolder->path(), name), this);
|
auto *feed = new Feed(this, uid, url, Item::joinPath(parentFolder->path(), name), refreshInterval);
|
||||||
addItem(feed, parentFolder);
|
addItem(feed, parentFolder);
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
|
@ -460,8 +462,25 @@ void Session::addItem(Item *item, Folder *destFolder)
|
||||||
|
|
||||||
emit feedURLChanged(feed, oldURL);
|
emit feedURLChanged(feed, oldURL);
|
||||||
});
|
});
|
||||||
|
connect(feed, &Feed::refreshIntervalChanged, this, [this, feed](const std::chrono::seconds oldRefreshInterval)
|
||||||
|
{
|
||||||
|
store();
|
||||||
|
|
||||||
|
std::chrono::system_clock::time_point &nextRefresh = m_refreshTimepoints[feed];
|
||||||
|
if (nextRefresh > std::chrono::system_clock::time_point())
|
||||||
|
nextRefresh += feed->refreshInterval() - oldRefreshInterval;
|
||||||
|
|
||||||
|
if (isProcessingEnabled())
|
||||||
|
{
|
||||||
|
const std::chrono::seconds oldEffectiveRefreshInterval = (oldRefreshInterval > 0s)
|
||||||
|
? oldRefreshInterval : std::chrono::minutes(refreshInterval());
|
||||||
|
if (feed->refreshInterval() < oldEffectiveRefreshInterval)
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
m_feedsByUID[feed->uid()] = feed;
|
m_feedsByUID[feed->uid()] = feed;
|
||||||
m_feedsByURL[feed->url()] = feed;
|
m_feedsByURL[feed->url()] = feed;
|
||||||
|
m_refreshTimepoints.emplace(feed, std::chrono::system_clock::time_point());
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(item, &Item::pathChanged, this, &Session::itemPathChanged);
|
connect(item, &Item::pathChanged, this, &Session::itemPathChanged);
|
||||||
|
@ -482,14 +501,9 @@ void Session::setProcessingEnabled(const bool enabled)
|
||||||
{
|
{
|
||||||
m_storeProcessingEnabled = enabled;
|
m_storeProcessingEnabled = enabled;
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
|
||||||
m_refreshTimer.start(std::chrono::minutes(refreshInterval()));
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
m_refreshTimer.stop();
|
m_refreshTimer.stop();
|
||||||
}
|
|
||||||
|
|
||||||
emit processingStateChanged(enabled);
|
emit processingStateChanged(enabled);
|
||||||
}
|
}
|
||||||
|
@ -560,6 +574,7 @@ void Session::handleItemAboutToBeDestroyed(Item *item)
|
||||||
{
|
{
|
||||||
m_feedsByUID.remove(feed->uid());
|
m_feedsByUID.remove(feed->uid());
|
||||||
m_feedsByURL.remove(feed->url());
|
m_feedsByURL.remove(feed->url());
|
||||||
|
m_refreshTimepoints.remove(feed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,6 +613,28 @@ void Session::setMaxArticlesPerFeed(const int n)
|
||||||
|
|
||||||
void Session::refresh()
|
void Session::refresh()
|
||||||
{
|
{
|
||||||
// NOTE: Should we allow manually refreshing for disabled session?
|
const auto currentTimepoint = std::chrono::system_clock::now();
|
||||||
rootFolder()->refresh();
|
std::chrono::seconds nextRefreshInterval = 0s;
|
||||||
|
for (auto it = m_refreshTimepoints.begin(); it != m_refreshTimepoints.end(); ++it)
|
||||||
|
{
|
||||||
|
Feed *feed = it.key();
|
||||||
|
std::chrono::system_clock::time_point &timepoint = it.value();
|
||||||
|
|
||||||
|
if (timepoint <= currentTimepoint)
|
||||||
|
timepoint = refreshFeed(feed, currentTimepoint);
|
||||||
|
|
||||||
|
const auto interval = std::chrono::duration_cast<std::chrono::seconds>(timepoint - currentTimepoint);
|
||||||
|
if ((interval < nextRefreshInterval) || (nextRefreshInterval == 0s))
|
||||||
|
nextRefreshInterval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_refreshTimer.start(nextRefreshInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::chrono::system_clock::time_point Session::refreshFeed(Feed *feed, const std::chrono::system_clock::time_point ¤tTimepoint)
|
||||||
|
{
|
||||||
|
feed->refresh();
|
||||||
|
const std::chrono::seconds feedRefreshInterval = feed->refreshInterval();
|
||||||
|
const std::chrono::seconds effectiveRefreshInterval = (feedRefreshInterval > 0s) ? feedRefreshInterval : std::chrono::minutes(refreshInterval());
|
||||||
|
return currentTimepoint + effectiveRefreshInterval;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2017-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2024 Jonathan Ketchker
|
* Copyright (C) 2024 Jonathan Ketchker
|
||||||
* Copyright (C) 2017 Vladimir Golovnev <glassez@yandex.ru>
|
|
||||||
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
||||||
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
* Copyright (C) 2010 Arnaud Demaiziere <arnaud@qbittorrent.org>
|
||||||
*
|
*
|
||||||
|
@ -35,26 +35,20 @@
|
||||||
* RSS Session configuration file format (JSON):
|
* RSS Session configuration file format (JSON):
|
||||||
*
|
*
|
||||||
* =============== BEGIN ===============
|
* =============== BEGIN ===============
|
||||||
*
|
* {
|
||||||
{
|
* "folder1": {
|
||||||
* "folder1":
|
* "subfolder1": {
|
||||||
{
|
* "Feed name 1 (Alias)": {
|
||||||
* "subfolder1":
|
|
||||||
{
|
|
||||||
* "Feed name 1 (Alias)":
|
|
||||||
{
|
|
||||||
* "uid": "feed unique identifier",
|
* "uid": "feed unique identifier",
|
||||||
* "url": "http://some-feed-url1"
|
* "url": "http://some-feed-url1"
|
||||||
* }
|
* }
|
||||||
* "Feed name 2 (Alias)":
|
* "Feed name 2 (Alias)": {
|
||||||
{
|
|
||||||
* "uid": "feed unique identifier",
|
* "uid": "feed unique identifier",
|
||||||
* "url": "http://some-feed-url2"
|
* "url": "http://some-feed-url2"
|
||||||
* }
|
* }
|
||||||
* },
|
* },
|
||||||
* "subfolder2": {},
|
* "subfolder2": {},
|
||||||
* "Feed name 3 (Alias)":
|
* "Feed name 3 (Alias)": {
|
||||||
{
|
|
||||||
* "uid": "feed unique identifier",
|
* "uid": "feed unique identifier",
|
||||||
* "url": "http://some-feed-url3"
|
* "url": "http://some-feed-url3"
|
||||||
* }
|
* }
|
||||||
|
@ -120,8 +114,8 @@ namespace RSS
|
||||||
std::chrono::seconds fetchDelay() const;
|
std::chrono::seconds fetchDelay() const;
|
||||||
void setFetchDelay(std::chrono::seconds delay);
|
void setFetchDelay(std::chrono::seconds delay);
|
||||||
|
|
||||||
nonstd::expected<void, QString> addFolder(const QString &path);
|
nonstd::expected<Folder *, QString> addFolder(const QString &path);
|
||||||
nonstd::expected<void, QString> addFeed(const QString &url, const QString &path);
|
nonstd::expected<Feed *, QString> addFeed(const QString &url, const QString &path, std::chrono::seconds refreshInterval = {});
|
||||||
nonstd::expected<void, QString> setFeedURL(const QString &path, const QString &url);
|
nonstd::expected<void, QString> setFeedURL(const QString &path, const QString &url);
|
||||||
nonstd::expected<void, QString> setFeedURL(Feed *feed, const QString &url);
|
nonstd::expected<void, QString> setFeedURL(Feed *feed, const QString &url);
|
||||||
nonstd::expected<void, QString> moveItem(const QString &itemPath, const QString &destPath);
|
nonstd::expected<void, QString> moveItem(const QString &itemPath, const QString &destPath);
|
||||||
|
@ -135,9 +129,6 @@ namespace RSS
|
||||||
|
|
||||||
Folder *rootFolder() const;
|
Folder *rootFolder() const;
|
||||||
|
|
||||||
public slots:
|
|
||||||
void refresh();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void processingStateChanged(bool enabled);
|
void processingStateChanged(bool enabled);
|
||||||
void maxArticlesPerFeedChanged(int n);
|
void maxArticlesPerFeedChanged(int n);
|
||||||
|
@ -160,8 +151,10 @@ namespace RSS
|
||||||
void store();
|
void store();
|
||||||
nonstd::expected<Folder *, QString> prepareItemDest(const QString &path);
|
nonstd::expected<Folder *, QString> prepareItemDest(const QString &path);
|
||||||
Folder *addSubfolder(const QString &name, Folder *parentFolder);
|
Folder *addSubfolder(const QString &name, Folder *parentFolder);
|
||||||
Feed *addFeedToFolder(const QUuid &uid, const QString &url, const QString &name, Folder *parentFolder);
|
Feed *addFeedToFolder(const QUuid &uid, const QString &url, const QString &name, Folder *parentFolder, std::chrono::seconds refreshInterval);
|
||||||
void addItem(Item *item, Folder *destFolder);
|
void addItem(Item *item, Folder *destFolder);
|
||||||
|
void refresh();
|
||||||
|
std::chrono::system_clock::time_point refreshFeed(Feed *feed, const std::chrono::system_clock::time_point ¤tTimepoint);
|
||||||
|
|
||||||
static QPointer<Session> m_instance;
|
static QPointer<Session> m_instance;
|
||||||
|
|
||||||
|
@ -176,5 +169,6 @@ namespace RSS
|
||||||
QHash<QString, Item *> m_itemsByPath;
|
QHash<QString, Item *> m_itemsByPath;
|
||||||
QHash<QUuid, Feed *> m_feedsByUID;
|
QHash<QUuid, Feed *> m_feedsByUID;
|
||||||
QHash<QString, Feed *> m_feedsByURL;
|
QHash<QString, Feed *> m_feedsByURL;
|
||||||
|
QHash<Feed *, std::chrono::system_clock::time_point> m_refreshTimepoints;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ qt_wrap_ui(UI_HEADERS
|
||||||
properties/peersadditiondialog.ui
|
properties/peersadditiondialog.ui
|
||||||
properties/propertieswidget.ui
|
properties/propertieswidget.ui
|
||||||
rss/automatedrssdownloader.ui
|
rss/automatedrssdownloader.ui
|
||||||
|
rss/rssfeeddialog.ui
|
||||||
rss/rsswidget.ui
|
rss/rsswidget.ui
|
||||||
search/pluginselectdialog.ui
|
search/pluginselectdialog.ui
|
||||||
search/pluginsourcedialog.ui
|
search/pluginsourcedialog.ui
|
||||||
|
@ -89,6 +90,7 @@ add_library(qbt_gui STATIC
|
||||||
rss/automatedrssdownloader.h
|
rss/automatedrssdownloader.h
|
||||||
rss/feedlistwidget.h
|
rss/feedlistwidget.h
|
||||||
rss/htmlbrowser.h
|
rss/htmlbrowser.h
|
||||||
|
rss/rssfeeddialog.h
|
||||||
rss/rsswidget.h
|
rss/rsswidget.h
|
||||||
search/pluginselectdialog.h
|
search/pluginselectdialog.h
|
||||||
search/pluginsourcedialog.h
|
search/pluginsourcedialog.h
|
||||||
|
@ -188,6 +190,7 @@ add_library(qbt_gui STATIC
|
||||||
rss/automatedrssdownloader.cpp
|
rss/automatedrssdownloader.cpp
|
||||||
rss/feedlistwidget.cpp
|
rss/feedlistwidget.cpp
|
||||||
rss/htmlbrowser.cpp
|
rss/htmlbrowser.cpp
|
||||||
|
rss/rssfeeddialog.cpp
|
||||||
rss/rsswidget.cpp
|
rss/rsswidget.cpp
|
||||||
search/pluginselectdialog.cpp
|
search/pluginselectdialog.cpp
|
||||||
search/pluginsourcedialog.cpp
|
search/pluginsourcedialog.cpp
|
||||||
|
|
82
src/gui/rss/rssfeeddialog.cpp
Normal file
82
src/gui/rss/rssfeeddialog.cpp
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rssfeeddialog.h"
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "ui_rssfeeddialog.h"
|
||||||
|
|
||||||
|
RSSFeedDialog::RSSFeedDialog(QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, m_ui {new Ui::RSSFeedDialog}
|
||||||
|
{
|
||||||
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
m_ui->spinRefreshInterval->setMaximum(std::numeric_limits<int>::max());
|
||||||
|
m_ui->spinRefreshInterval->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType);
|
||||||
|
m_ui->spinRefreshInterval->setSuffix(tr(" sec"));
|
||||||
|
m_ui->spinRefreshInterval->setSpecialValueText(tr("Default"));
|
||||||
|
|
||||||
|
// disable Ok button
|
||||||
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
|
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
|
connect(m_ui->textFeedURL, &QLineEdit::textChanged, this, &RSSFeedDialog::feedURLChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
RSSFeedDialog::~RSSFeedDialog()
|
||||||
|
{
|
||||||
|
delete m_ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RSSFeedDialog::feedURL() const
|
||||||
|
{
|
||||||
|
return m_ui->textFeedURL->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RSSFeedDialog::setFeedURL(const QString &feedURL)
|
||||||
|
{
|
||||||
|
m_ui->textFeedURL->setText(feedURL);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::chrono::seconds RSSFeedDialog::refreshInterval() const
|
||||||
|
{
|
||||||
|
return std::chrono::seconds(m_ui->spinRefreshInterval->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RSSFeedDialog::setRefreshInterval(const std::chrono::seconds refreshInterval)
|
||||||
|
{
|
||||||
|
m_ui->spinRefreshInterval->setValue(refreshInterval.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RSSFeedDialog::feedURLChanged(const QString &feedURL)
|
||||||
|
{
|
||||||
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!feedURL.isEmpty());
|
||||||
|
}
|
57
src/gui/rss/rssfeeddialog.h
Normal file
57
src/gui/rss/rssfeeddialog.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class RSSFeedDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RSSFeedDialog final : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_DISABLE_COPY_MOVE(RSSFeedDialog)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RSSFeedDialog(QWidget *parent = nullptr);
|
||||||
|
~RSSFeedDialog() override;
|
||||||
|
|
||||||
|
QString feedURL() const;
|
||||||
|
void setFeedURL(const QString &feedURL);
|
||||||
|
std::chrono::seconds refreshInterval() const;
|
||||||
|
void setRefreshInterval(std::chrono::seconds refreshInterval);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void feedURLChanged(const QString &feedURL);
|
||||||
|
|
||||||
|
Ui::RSSFeedDialog *m_ui = nullptr;
|
||||||
|
};
|
75
src/gui/rss/rssfeeddialog.ui
Normal file
75
src/gui/rss/rssfeeddialog.ui
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>RSSFeedDialog</class>
|
||||||
|
<widget class="QDialog" name="RSSFeedDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>555</width>
|
||||||
|
<height>106</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>RSS Feed Options</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="labelFeedURL">
|
||||||
|
<property name="text">
|
||||||
|
<string>URL:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="textFeedURL"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="labelRefreshInterval">
|
||||||
|
<property name="text">
|
||||||
|
<string>Refresh interval:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="spinRefreshInterval">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -52,6 +52,7 @@
|
||||||
#include "articlelistwidget.h"
|
#include "articlelistwidget.h"
|
||||||
#include "automatedrssdownloader.h"
|
#include "automatedrssdownloader.h"
|
||||||
#include "feedlistwidget.h"
|
#include "feedlistwidget.h"
|
||||||
|
#include "rssfeeddialog.h"
|
||||||
#include "ui_rsswidget.h"
|
#include "ui_rsswidget.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -112,7 +113,7 @@ RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent)
|
||||||
m_ui->actionCopyFeedURL->setIcon(UIThemeManager::instance()->getIcon(u"edit-copy"_s));
|
m_ui->actionCopyFeedURL->setIcon(UIThemeManager::instance()->getIcon(u"edit-copy"_s));
|
||||||
m_ui->actionDelete->setIcon(UIThemeManager::instance()->getIcon(u"edit-clear"_s));
|
m_ui->actionDelete->setIcon(UIThemeManager::instance()->getIcon(u"edit-clear"_s));
|
||||||
m_ui->actionDownloadTorrent->setIcon(UIThemeManager::instance()->getIcon(u"downloading"_s, u"download"_s));
|
m_ui->actionDownloadTorrent->setIcon(UIThemeManager::instance()->getIcon(u"downloading"_s, u"download"_s));
|
||||||
m_ui->actionEditFeedURL->setIcon(UIThemeManager::instance()->getIcon(u"edit-rename"_s));
|
m_ui->actionEditFeed->setIcon(UIThemeManager::instance()->getIcon(u"edit-rename"_s));
|
||||||
m_ui->actionMarkItemsRead->setIcon(UIThemeManager::instance()->getIcon(u"task-complete"_s, u"mail-mark-read"_s));
|
m_ui->actionMarkItemsRead->setIcon(UIThemeManager::instance()->getIcon(u"task-complete"_s, u"mail-mark-read"_s));
|
||||||
m_ui->actionNewFolder->setIcon(UIThemeManager::instance()->getIcon(u"folder-new"_s));
|
m_ui->actionNewFolder->setIcon(UIThemeManager::instance()->getIcon(u"folder-new"_s));
|
||||||
m_ui->actionNewSubscription->setIcon(UIThemeManager::instance()->getIcon(u"list-add"_s));
|
m_ui->actionNewSubscription->setIcon(UIThemeManager::instance()->getIcon(u"list-add"_s));
|
||||||
|
@ -145,7 +146,7 @@ RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent)
|
||||||
// Feeds list actions
|
// Feeds list actions
|
||||||
connect(m_ui->actionDelete, &QAction::triggered, this, &RSSWidget::deleteSelectedItems);
|
connect(m_ui->actionDelete, &QAction::triggered, this, &RSSWidget::deleteSelectedItems);
|
||||||
connect(m_ui->actionRename, &QAction::triggered, this, &RSSWidget::renameSelectedRSSItem);
|
connect(m_ui->actionRename, &QAction::triggered, this, &RSSWidget::renameSelectedRSSItem);
|
||||||
connect(m_ui->actionEditFeedURL, &QAction::triggered, this, &RSSWidget::editSelectedRSSFeedURL);
|
connect(m_ui->actionEditFeed, &QAction::triggered, this, &RSSWidget::editSelectedRSSFeed);
|
||||||
connect(m_ui->actionUpdate, &QAction::triggered, this, &RSSWidget::refreshSelectedItems);
|
connect(m_ui->actionUpdate, &QAction::triggered, this, &RSSWidget::refreshSelectedItems);
|
||||||
connect(m_ui->actionNewFolder, &QAction::triggered, this, &RSSWidget::askNewFolder);
|
connect(m_ui->actionNewFolder, &QAction::triggered, this, &RSSWidget::askNewFolder);
|
||||||
connect(m_ui->actionNewSubscription, &QAction::triggered, this, &RSSWidget::on_newFeedButton_clicked);
|
connect(m_ui->actionNewSubscription, &QAction::triggered, this, &RSSWidget::on_newFeedButton_clicked);
|
||||||
|
@ -209,7 +210,7 @@ void RSSWidget::displayRSSListMenu(const QPoint &pos)
|
||||||
{
|
{
|
||||||
menu->addAction(m_ui->actionRename);
|
menu->addAction(m_ui->actionRename);
|
||||||
if (m_ui->feedListWidget->isFeed(selectedItem))
|
if (m_ui->feedListWidget->isFeed(selectedItem))
|
||||||
menu->addAction(m_ui->actionEditFeedURL);
|
menu->addAction(m_ui->actionEditFeed);
|
||||||
menu->addAction(m_ui->actionDelete);
|
menu->addAction(m_ui->actionDelete);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
if (m_ui->feedListWidget->isFolder(selectedItem))
|
if (m_ui->feedListWidget->isFolder(selectedItem))
|
||||||
|
@ -292,36 +293,29 @@ void RSSWidget::askNewFolder()
|
||||||
}
|
}
|
||||||
// Consider the case where the user clicked on Unread item
|
// Consider the case where the user clicked on Unread item
|
||||||
RSS::Folder *rssDestFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
RSS::Folder *rssDestFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
||||||
? RSS::Session::instance()->rootFolder()
|
? RSS::Session::instance()->rootFolder()
|
||||||
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
||||||
|
|
||||||
const QString newFolderPath = RSS::Item::joinPath(rssDestFolder->path(), newName);
|
const QString newFolderPath = RSS::Item::joinPath(rssDestFolder->path(), newName);
|
||||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFolder(newFolderPath);
|
const nonstd::expected<RSS::Folder *, QString> result = RSS::Session::instance()->addFolder(newFolderPath);
|
||||||
if (!result)
|
if (!result)
|
||||||
|
{
|
||||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RSS::Folder *newFolder = result.value();
|
||||||
|
|
||||||
// Expand destination folder to display new feed
|
// Expand destination folder to display new feed
|
||||||
if (destItem && (destItem != m_ui->feedListWidget->stickyUnreadItem()))
|
if (destItem && (destItem != m_ui->feedListWidget->stickyUnreadItem()))
|
||||||
destItem->setExpanded(true);
|
destItem->setExpanded(true);
|
||||||
// As new RSS items are added synchronously, we can do the following here.
|
// As new RSS items are added synchronously, we can do the following here.
|
||||||
m_ui->feedListWidget->setCurrentItem(m_ui->feedListWidget->mapRSSItem(RSS::Session::instance()->itemByPath(newFolderPath)));
|
m_ui->feedListWidget->setCurrentItem(m_ui->feedListWidget->mapRSSItem(newFolder));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a stream by a button
|
// add a stream by a button
|
||||||
void RSSWidget::on_newFeedButton_clicked()
|
void RSSWidget::on_newFeedButton_clicked()
|
||||||
{
|
{
|
||||||
// Ask for feed URL
|
|
||||||
const QString clipText = qApp->clipboard()->text();
|
|
||||||
const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : u"http://"_s;
|
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
QString newURL = AutoExpandableDialog::getText(
|
|
||||||
this, tr("Please type a RSS feed URL"), tr("Feed URL:"), QLineEdit::Normal, defaultURL, &ok);
|
|
||||||
if (!ok) return;
|
|
||||||
|
|
||||||
newURL = newURL.trimmed();
|
|
||||||
if (newURL.isEmpty()) return;
|
|
||||||
|
|
||||||
// Determine destination folder for new item
|
// Determine destination folder for new item
|
||||||
QTreeWidgetItem *destItem = nullptr;
|
QTreeWidgetItem *destItem = nullptr;
|
||||||
QList<QTreeWidgetItem *> selectedItems = m_ui->feedListWidget->selectedItems();
|
QList<QTreeWidgetItem *> selectedItems = m_ui->feedListWidget->selectedItems();
|
||||||
|
@ -332,21 +326,38 @@ void RSSWidget::on_newFeedButton_clicked()
|
||||||
destItem = destItem->parent();
|
destItem = destItem->parent();
|
||||||
}
|
}
|
||||||
// Consider the case where the user clicked on Unread item
|
// Consider the case where the user clicked on Unread item
|
||||||
RSS::Folder *rssDestFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
RSS::Folder *destFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
||||||
? RSS::Session::instance()->rootFolder()
|
? RSS::Session::instance()->rootFolder()
|
||||||
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
||||||
|
|
||||||
// NOTE: We still add feed using legacy way (with URL as feed name)
|
// Ask for feed URL
|
||||||
const QString newFeedPath = RSS::Item::joinPath(rssDestFolder->path(), newURL);
|
const QString clipText = qApp->clipboard()->text();
|
||||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFeed(newURL, newFeedPath);
|
const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : u"http://"_s;
|
||||||
if (!result)
|
|
||||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
RSS::Feed *newFeed = nullptr;
|
||||||
|
RSSFeedDialog dialog {this};
|
||||||
|
dialog.setFeedURL(defaultURL);
|
||||||
|
while (!newFeed && (dialog.exec() == RSSFeedDialog::Accepted))
|
||||||
|
{
|
||||||
|
const QString feedURL = dialog.feedURL().trimmed();
|
||||||
|
const std::chrono::seconds refreshInterval = dialog.refreshInterval();
|
||||||
|
|
||||||
|
const QString feedPath = RSS::Item::joinPath(destFolder->path(), feedURL);
|
||||||
|
const nonstd::expected<RSS::Feed *, QString> result = RSS::Session::instance()->addFeed(feedURL, feedPath, refreshInterval);
|
||||||
|
if (result)
|
||||||
|
newFeed = result.value();
|
||||||
|
else
|
||||||
|
QMessageBox::warning(&dialog, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!newFeed)
|
||||||
|
return;
|
||||||
|
|
||||||
// Expand destination folder to display new feed
|
// Expand destination folder to display new feed
|
||||||
if (destItem && (destItem != m_ui->feedListWidget->stickyUnreadItem()))
|
if (destItem && (destItem != m_ui->feedListWidget->stickyUnreadItem()))
|
||||||
destItem->setExpanded(true);
|
destItem->setExpanded(true);
|
||||||
// As new RSS items are added synchronously, we can do the following here.
|
// As new RSS items are added synchronously, we can do the following here.
|
||||||
m_ui->feedListWidget->setCurrentItem(m_ui->feedListWidget->mapRSSItem(RSS::Session::instance()->itemByPath(newFeedPath)));
|
m_ui->feedListWidget->setCurrentItem(m_ui->feedListWidget->mapRSSItem(newFeed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSWidget::deleteSelectedItems()
|
void RSSWidget::deleteSelectedItems()
|
||||||
|
@ -401,7 +412,7 @@ void RSSWidget::saveFoldersOpenState()
|
||||||
|
|
||||||
void RSSWidget::refreshAllFeeds()
|
void RSSWidget::refreshAllFeeds()
|
||||||
{
|
{
|
||||||
RSS::Session::instance()->refresh();
|
RSS::Session::instance()->rootFolder()->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSWidget::downloadSelectedTorrents()
|
void RSSWidget::downloadSelectedTorrents()
|
||||||
|
@ -463,7 +474,7 @@ void RSSWidget::renameSelectedRSSItem()
|
||||||
} while (!ok);
|
} while (!ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSWidget::editSelectedRSSFeedURL()
|
void RSSWidget::editSelectedRSSFeed()
|
||||||
{
|
{
|
||||||
QList<QTreeWidgetItem *> selectedItems = m_ui->feedListWidget->selectedItems();
|
QList<QTreeWidgetItem *> selectedItems = m_ui->feedListWidget->selectedItems();
|
||||||
if (selectedItems.size() != 1)
|
if (selectedItems.size() != 1)
|
||||||
|
@ -475,15 +486,20 @@ void RSSWidget::editSelectedRSSFeedURL()
|
||||||
if (!rssFeed) [[unlikely]]
|
if (!rssFeed) [[unlikely]]
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool ok = false;
|
auto *dialog = new RSSFeedDialog(this);
|
||||||
QString newURL = AutoExpandableDialog::getText(this, tr("Please type a RSS feed URL")
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
, tr("Feed URL:"), QLineEdit::Normal, rssFeed->url(), &ok).trimmed();
|
dialog->setFeedURL(rssFeed->url());
|
||||||
if (!ok || newURL.isEmpty())
|
dialog->setRefreshInterval(rssFeed->refreshInterval());
|
||||||
return;
|
connect(dialog, &RSSFeedDialog::accepted, this, [this, dialog, rssFeed]
|
||||||
|
{
|
||||||
|
rssFeed->setRefreshInterval(dialog->refreshInterval());
|
||||||
|
|
||||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->setFeedURL(rssFeed, newURL);
|
const QString newURL = dialog->feedURL();
|
||||||
if (!result)
|
const nonstd::expected<void, QString> result = RSS::Session::instance()->setFeedURL(rssFeed, newURL);
|
||||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
if (!result)
|
||||||
|
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||||
|
});
|
||||||
|
dialog->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSWidget::refreshSelectedItems()
|
void RSSWidget::refreshSelectedItems()
|
||||||
|
|
|
@ -70,7 +70,7 @@ private slots:
|
||||||
void displayRSSListMenu(const QPoint &pos);
|
void displayRSSListMenu(const QPoint &pos);
|
||||||
void displayItemsListMenu();
|
void displayItemsListMenu();
|
||||||
void renameSelectedRSSItem();
|
void renameSelectedRSSItem();
|
||||||
void editSelectedRSSFeedURL();
|
void editSelectedRSSFeed();
|
||||||
void refreshSelectedItems();
|
void refreshSelectedItems();
|
||||||
void copySelectedFeedsURL();
|
void copySelectedFeedsURL();
|
||||||
void handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem);
|
void handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem);
|
||||||
|
|
|
@ -198,12 +198,9 @@
|
||||||
<string>New folder...</string>
|
<string>New folder...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditFeedURL">
|
<action name="actionEditFeed">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit feed URL...</string>
|
<string>Feed options...</string>
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Edit feed URL</string>
|
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -50,7 +50,7 @@ void RSSController::addFolderAction()
|
||||||
requireParams({u"path"_s});
|
requireParams({u"path"_s});
|
||||||
|
|
||||||
const QString path = params()[u"path"_s];
|
const QString path = params()[u"path"_s];
|
||||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFolder(path);
|
const nonstd::expected<RSS::Folder *, QString> result = RSS::Session::instance()->addFolder(path);
|
||||||
if (!result)
|
if (!result)
|
||||||
throw APIError(APIErrorType::Conflict, result.error());
|
throw APIError(APIErrorType::Conflict, result.error());
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,8 @@ void RSSController::addFeedAction()
|
||||||
|
|
||||||
const QString url = params()[u"url"_s];
|
const QString url = params()[u"url"_s];
|
||||||
const QString path = params()[u"path"_s];
|
const QString path = params()[u"path"_s];
|
||||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFeed(url, (path.isEmpty() ? url : path));
|
const auto refreshInterval = std::max<qint64>(params()[u"refreshInterval"_s].toLongLong(), 0);
|
||||||
|
const nonstd::expected<RSS::Feed *, QString> result = RSS::Session::instance()->addFeed(url, (path.isEmpty() ? url : path), std::chrono::seconds(refreshInterval));
|
||||||
if (!result)
|
if (!result)
|
||||||
throw APIError(APIErrorType::Conflict, result.error());
|
throw APIError(APIErrorType::Conflict, result.error());
|
||||||
}
|
}
|
||||||
|
@ -77,6 +78,23 @@ void RSSController::setFeedURLAction()
|
||||||
throw APIError(APIErrorType::Conflict, result.error());
|
throw APIError(APIErrorType::Conflict, result.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RSSController::setFeedRefreshIntervalAction()
|
||||||
|
{
|
||||||
|
requireParams({u"path"_s, u"refreshInterval"_s});
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
const auto refreshInterval = params()[u"refreshInterval"_s].toLongLong(&ok);
|
||||||
|
if (!ok || (refreshInterval < 0))
|
||||||
|
throw APIError(APIErrorType::BadParams, tr("Invalid 'refreshInterval' value"));
|
||||||
|
|
||||||
|
const QString path = params()[u"path"_s];
|
||||||
|
auto *feed = qobject_cast<RSS::Feed *>(RSS::Session::instance()->itemByPath(path));
|
||||||
|
if (!feed)
|
||||||
|
throw APIError(APIErrorType::Conflict, tr("Feed doesn't exist: %1.").arg(path));
|
||||||
|
|
||||||
|
feed->setRefreshInterval(std::chrono::seconds(refreshInterval));
|
||||||
|
}
|
||||||
|
|
||||||
void RSSController::removeItemAction()
|
void RSSController::removeItemAction()
|
||||||
{
|
{
|
||||||
requireParams({u"path"_s});
|
requireParams({u"path"_s});
|
||||||
|
|
|
@ -42,6 +42,7 @@ private slots:
|
||||||
void addFolderAction();
|
void addFolderAction();
|
||||||
void addFeedAction();
|
void addFeedAction();
|
||||||
void setFeedURLAction();
|
void setFeedURLAction();
|
||||||
|
void setFeedRefreshIntervalAction();
|
||||||
void removeItemAction();
|
void removeItemAction();
|
||||||
void moveItemAction();
|
void moveItemAction();
|
||||||
void itemsAction();
|
void itemsAction();
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
#include "base/utils/version.h"
|
#include "base/utils/version.h"
|
||||||
#include "api/isessionmanager.h"
|
#include "api/isessionmanager.h"
|
||||||
|
|
||||||
inline const Utils::Version<3, 2> API_VERSION {2, 11, 4};
|
inline const Utils::Version<3, 2> API_VERSION {2, 11, 5};
|
||||||
|
|
||||||
class APIController;
|
class APIController;
|
||||||
class AuthController;
|
class AuthController;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue