mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-02 05:38:06 -06:00
committed by
GitHub
parent
b28c229f85
commit
627d89813c
@@ -18,6 +18,7 @@ qt_wrap_ui(UI_HEADERS
|
||||
properties/peersadditiondialog.ui
|
||||
properties/propertieswidget.ui
|
||||
rss/automatedrssdownloader.ui
|
||||
rss/rssfeeddialog.ui
|
||||
rss/rsswidget.ui
|
||||
search/pluginselectdialog.ui
|
||||
search/pluginsourcedialog.ui
|
||||
@@ -89,6 +90,7 @@ add_library(qbt_gui STATIC
|
||||
rss/automatedrssdownloader.h
|
||||
rss/feedlistwidget.h
|
||||
rss/htmlbrowser.h
|
||||
rss/rssfeeddialog.h
|
||||
rss/rsswidget.h
|
||||
search/pluginselectdialog.h
|
||||
search/pluginsourcedialog.h
|
||||
@@ -188,6 +190,7 @@ add_library(qbt_gui STATIC
|
||||
rss/automatedrssdownloader.cpp
|
||||
rss/feedlistwidget.cpp
|
||||
rss/htmlbrowser.cpp
|
||||
rss/rssfeeddialog.cpp
|
||||
rss/rsswidget.cpp
|
||||
search/pluginselectdialog.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 "automatedrssdownloader.h"
|
||||
#include "feedlistwidget.h"
|
||||
#include "rssfeeddialog.h"
|
||||
#include "ui_rsswidget.h"
|
||||
|
||||
namespace
|
||||
@@ -112,7 +113,7 @@ RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent)
|
||||
m_ui->actionCopyFeedURL->setIcon(UIThemeManager::instance()->getIcon(u"edit-copy"_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->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->actionNewFolder->setIcon(UIThemeManager::instance()->getIcon(u"folder-new"_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
|
||||
connect(m_ui->actionDelete, &QAction::triggered, this, &RSSWidget::deleteSelectedItems);
|
||||
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->actionNewFolder, &QAction::triggered, this, &RSSWidget::askNewFolder);
|
||||
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);
|
||||
if (m_ui->feedListWidget->isFeed(selectedItem))
|
||||
menu->addAction(m_ui->actionEditFeedURL);
|
||||
menu->addAction(m_ui->actionEditFeed);
|
||||
menu->addAction(m_ui->actionDelete);
|
||||
menu->addSeparator();
|
||||
if (m_ui->feedListWidget->isFolder(selectedItem))
|
||||
@@ -292,36 +293,29 @@ void RSSWidget::askNewFolder()
|
||||
}
|
||||
// Consider the case where the user clicked on Unread item
|
||||
RSS::Folder *rssDestFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
||||
? RSS::Session::instance()->rootFolder()
|
||||
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
||||
? RSS::Session::instance()->rootFolder()
|
||||
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
||||
|
||||
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)
|
||||
{
|
||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
RSS::Folder *newFolder = result.value();
|
||||
|
||||
// Expand destination folder to display new feed
|
||||
if (destItem && (destItem != m_ui->feedListWidget->stickyUnreadItem()))
|
||||
destItem->setExpanded(true);
|
||||
// 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
|
||||
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
|
||||
QTreeWidgetItem *destItem = nullptr;
|
||||
QList<QTreeWidgetItem *> selectedItems = m_ui->feedListWidget->selectedItems();
|
||||
@@ -332,21 +326,38 @@ void RSSWidget::on_newFeedButton_clicked()
|
||||
destItem = destItem->parent();
|
||||
}
|
||||
// Consider the case where the user clicked on Unread item
|
||||
RSS::Folder *rssDestFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
||||
? RSS::Session::instance()->rootFolder()
|
||||
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
||||
RSS::Folder *destFolder = ((!destItem || (destItem == m_ui->feedListWidget->stickyUnreadItem()))
|
||||
? RSS::Session::instance()->rootFolder()
|
||||
: qobject_cast<RSS::Folder *>(m_ui->feedListWidget->getRSSItem(destItem)));
|
||||
|
||||
// NOTE: We still add feed using legacy way (with URL as feed name)
|
||||
const QString newFeedPath = RSS::Item::joinPath(rssDestFolder->path(), newURL);
|
||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFeed(newURL, newFeedPath);
|
||||
if (!result)
|
||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||
// Ask for feed URL
|
||||
const QString clipText = qApp->clipboard()->text();
|
||||
const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : u"http://"_s;
|
||||
|
||||
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
|
||||
if (destItem && (destItem != m_ui->feedListWidget->stickyUnreadItem()))
|
||||
destItem->setExpanded(true);
|
||||
// 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()
|
||||
@@ -401,7 +412,7 @@ void RSSWidget::saveFoldersOpenState()
|
||||
|
||||
void RSSWidget::refreshAllFeeds()
|
||||
{
|
||||
RSS::Session::instance()->refresh();
|
||||
RSS::Session::instance()->rootFolder()->refresh();
|
||||
}
|
||||
|
||||
void RSSWidget::downloadSelectedTorrents()
|
||||
@@ -463,7 +474,7 @@ void RSSWidget::renameSelectedRSSItem()
|
||||
} while (!ok);
|
||||
}
|
||||
|
||||
void RSSWidget::editSelectedRSSFeedURL()
|
||||
void RSSWidget::editSelectedRSSFeed()
|
||||
{
|
||||
QList<QTreeWidgetItem *> selectedItems = m_ui->feedListWidget->selectedItems();
|
||||
if (selectedItems.size() != 1)
|
||||
@@ -475,15 +486,20 @@ void RSSWidget::editSelectedRSSFeedURL()
|
||||
if (!rssFeed) [[unlikely]]
|
||||
return;
|
||||
|
||||
bool ok = false;
|
||||
QString newURL = AutoExpandableDialog::getText(this, tr("Please type a RSS feed URL")
|
||||
, tr("Feed URL:"), QLineEdit::Normal, rssFeed->url(), &ok).trimmed();
|
||||
if (!ok || newURL.isEmpty())
|
||||
return;
|
||||
auto *dialog = new RSSFeedDialog(this);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->setFeedURL(rssFeed->url());
|
||||
dialog->setRefreshInterval(rssFeed->refreshInterval());
|
||||
connect(dialog, &RSSFeedDialog::accepted, this, [this, dialog, rssFeed]
|
||||
{
|
||||
rssFeed->setRefreshInterval(dialog->refreshInterval());
|
||||
|
||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->setFeedURL(rssFeed, newURL);
|
||||
if (!result)
|
||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||
const QString newURL = dialog->feedURL();
|
||||
const nonstd::expected<void, QString> result = RSS::Session::instance()->setFeedURL(rssFeed, newURL);
|
||||
if (!result)
|
||||
QMessageBox::warning(this, u"qBittorrent"_s, result.error(), QMessageBox::Ok);
|
||||
});
|
||||
dialog->open();
|
||||
}
|
||||
|
||||
void RSSWidget::refreshSelectedItems()
|
||||
|
||||
@@ -70,7 +70,7 @@ private slots:
|
||||
void displayRSSListMenu(const QPoint &pos);
|
||||
void displayItemsListMenu();
|
||||
void renameSelectedRSSItem();
|
||||
void editSelectedRSSFeedURL();
|
||||
void editSelectedRSSFeed();
|
||||
void refreshSelectedItems();
|
||||
void copySelectedFeedsURL();
|
||||
void handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem);
|
||||
|
||||
@@ -198,12 +198,9 @@
|
||||
<string>New folder...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditFeedURL">
|
||||
<action name="actionEditFeed">
|
||||
<property name="text">
|
||||
<string>Edit feed URL...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Edit feed URL</string>
|
||||
<string>Feed options...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
||||
Reference in New Issue
Block a user