mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-25 02:36:10 +03:00
Support overriding global "Add paused" option in RSS on per rule basis
This commit is contained in:
parent
3b4548fe73
commit
ef14b83134
7 changed files with 146 additions and 9 deletions
|
@ -272,6 +272,9 @@ void QBtSession::handleDownloadFailure(QString url, QString reason) {
|
|||
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||
url_skippingDlg.removeOne(qurl);
|
||||
savepathLabel_fromurl.remove(qurl);
|
||||
#ifndef DISABLE_GUI
|
||||
addpaused_fromurl.remove(qurl);
|
||||
#endif
|
||||
}
|
||||
|
||||
void QBtSession::handleMagnetRedirect(const QString &url_new, const QString &url_old) {
|
||||
|
@ -279,10 +282,19 @@ void QBtSession::handleMagnetRedirect(const QString &url_new, const QString &url
|
|||
url_skippingDlg.removeOne(url_old);
|
||||
QPair<QString, QString> savePath_label;
|
||||
if (savepathLabel_fromurl.contains(url_old)) {
|
||||
savePath_label = savepathLabel_fromurl.take(QUrl::fromEncoded(url_old.toUtf8()));
|
||||
savepathLabel_fromurl.remove(url_old);
|
||||
savePath_label = savepathLabel_fromurl.take(url_old);
|
||||
}
|
||||
addMagnetSkipAddDlg(url_new, savePath_label.first, savePath_label.second, url_old);
|
||||
#ifndef DISABLE_GUI
|
||||
RssDownloadRule::AddPausedState state = RssDownloadRule::USE_GLOBAL;
|
||||
if (addpaused_fromurl.contains(url_old)) {
|
||||
state = addpaused_fromurl.take(url_old);
|
||||
}
|
||||
#endif
|
||||
addMagnetSkipAddDlg(url_new, savePath_label.first, savePath_label.second,
|
||||
#ifndef DISABLE_GUI
|
||||
state,
|
||||
#endif
|
||||
url_old);
|
||||
}
|
||||
else
|
||||
addMagnetInteractive(url_new);
|
||||
|
@ -2914,18 +2926,49 @@ void QBtSession::addMagnetInteractive(const QString& uri)
|
|||
emit newMagnetLink(uri);
|
||||
}
|
||||
|
||||
void QBtSession::addMagnetSkipAddDlg(const QString& uri, const QString& save_path, const QString& label, const QString &uri_old) {
|
||||
#ifndef DISABLE_GUI
|
||||
void QBtSession::addMagnetSkipAddDlg(const QString& uri, const QString& save_path, const QString& label,
|
||||
const RssDownloadRule::AddPausedState &aps, const QString &uri_old) {
|
||||
#else
|
||||
void QBtSession::addMagnetSkipAddDlg(const QString& uri, const QString& save_path, const QString& label, const QString &uri_old) {
|
||||
#endif
|
||||
if (!save_path.isEmpty() || !label.isEmpty())
|
||||
savepathLabel_fromurl[uri] = qMakePair(fsutils::fromNativePath(save_path), label);
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
QString hash = misc::magnetUriToHash(uri);
|
||||
switch (aps) {
|
||||
case RssDownloadRule::ALWAYS_PAUSED:
|
||||
TorrentTempData::setAddPaused(hash, true);
|
||||
break;
|
||||
case RssDownloadRule::NEVER_PAUSED:
|
||||
TorrentTempData::setAddPaused(hash, false);
|
||||
break;
|
||||
case RssDownloadRule::USE_GLOBAL:
|
||||
default:;
|
||||
// Use global preferences
|
||||
}
|
||||
#endif
|
||||
|
||||
addMagnetUri(uri, false);
|
||||
emit newDownloadedTorrentFromRss(uri_old.isEmpty() ? uri : uri_old);
|
||||
}
|
||||
|
||||
void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label, const QList<QNetworkCookie>& cookies) {
|
||||
#ifndef DISABLE_GUI
|
||||
void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label,
|
||||
const QList<QNetworkCookie>& cookies, const RssDownloadRule::AddPausedState &aps) {
|
||||
#else
|
||||
void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label, const QList<QNetworkCookie>& cookies) {
|
||||
#endif
|
||||
//emit aboutToDownloadFromUrl(url);
|
||||
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||
if (!save_path.isEmpty() || !label.isEmpty())
|
||||
savepathLabel_fromurl[qurl] = qMakePair(fsutils::fromNativePath(save_path), label);
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
if (aps != RssDownloadRule::USE_GLOBAL)
|
||||
addpaused_fromurl[qurl] = aps;
|
||||
#endif
|
||||
url_skippingDlg << qurl;
|
||||
// Launch downloader thread
|
||||
downloader->downloadTorrentUrl(url, cookies);
|
||||
|
@ -2953,6 +2996,31 @@ void QBtSession::processDownloadedFile(QString url, QString file_path) {
|
|||
emit newDownloadedTorrent(file_path, url);
|
||||
} else {
|
||||
url_skippingDlg.removeAt(index);
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
libtorrent::error_code ec;
|
||||
// Get hash
|
||||
libtorrent::torrent_info ti(file_path.toStdString(), ec);
|
||||
QString hash;
|
||||
|
||||
if (!ec) {
|
||||
hash = misc::toQString(ti.info_hash());
|
||||
RssDownloadRule::AddPausedState aps = addpaused_fromurl[url];
|
||||
addpaused_fromurl.remove(url);
|
||||
switch (aps) {
|
||||
case RssDownloadRule::ALWAYS_PAUSED:
|
||||
TorrentTempData::setAddPaused(hash, true);
|
||||
break;
|
||||
case RssDownloadRule::NEVER_PAUSED:
|
||||
TorrentTempData::setAddPaused(hash, false);
|
||||
break;
|
||||
case RssDownloadRule::USE_GLOBAL:
|
||||
default:;
|
||||
// Use global preferences
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
addTorrent(file_path, false, url, false);
|
||||
emit newDownloadedTorrentFromRss(url);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@
|
|||
#include "trackerinfos.h"
|
||||
#include "misc.h"
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
#include "rssdownloadrule.h"
|
||||
#endif
|
||||
|
||||
namespace libtorrent {
|
||||
struct add_torrent_params;
|
||||
struct pe_settings;
|
||||
|
@ -175,7 +179,14 @@ public slots:
|
|||
void setQueueingEnabled(bool enable);
|
||||
void handleDownloadFailure(QString url, QString reason);
|
||||
void handleMagnetRedirect(const QString &url_new, const QString &url_old);
|
||||
void downloadUrlAndSkipDialog(QString url, QString save_path=QString(), QString label=QString(), const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
|
||||
#ifndef DISABLE_GUI
|
||||
void downloadUrlAndSkipDialog(QString url, QString save_path=QString(), QString label=QString(),
|
||||
const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>(),
|
||||
const RssDownloadRule::AddPausedState &aps = RssDownloadRule::USE_GLOBAL);
|
||||
#else
|
||||
void downloadUrlAndSkipDialog(QString url, QString save_path=QString(), QString label=QString(),
|
||||
const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
|
||||
#endif
|
||||
// Session configuration - Setters
|
||||
void setListeningPort(int port);
|
||||
void setMaxConnectionsPerTorrent(int max);
|
||||
|
@ -212,7 +223,12 @@ public slots:
|
|||
void clearConsoleMessages() { consoleMessages.clear(); }
|
||||
void clearPeerBanMessages() { peerBanMessages.clear(); }
|
||||
void processDownloadedFile(QString, QString);
|
||||
void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString(), const QString &uri_old = QString());
|
||||
#ifndef DISABLE_GUI
|
||||
void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString(),
|
||||
const RssDownloadRule::AddPausedState &aps = RssDownloadRule::USE_GLOBAL, const QString &uri_old = QString());
|
||||
#else
|
||||
void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString(), const QString &uri_old = QString());
|
||||
#endif
|
||||
void addMagnetInteractive(const QString& uri);
|
||||
void downloadFromURLList(const QStringList& urls);
|
||||
void configureSession();
|
||||
|
@ -305,6 +321,9 @@ private:
|
|||
libtorrent::session *s;
|
||||
QPointer<BandwidthScheduler> bd_scheduler;
|
||||
QMap<QUrl, QPair<QString, QString> > savepathLabel_fromurl; // Use QMap for compatibility with Qt < 4.7: qHash(QUrl)
|
||||
#ifndef DISABLE_GUI
|
||||
QMap<QUrl, RssDownloadRule::AddPausedState> addpaused_fromurl;
|
||||
#endif
|
||||
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
|
||||
QHash<QString, QString> savePathsToRemove;
|
||||
QStringList torrentsToPausedAfterChecking;
|
||||
|
|
|
@ -255,6 +255,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
|
|||
} else {
|
||||
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule->label()));
|
||||
}
|
||||
ui->comboAddPaused->setCurrentIndex(rule->addPaused());
|
||||
ui->spinIgnorePeriod->setValue(rule->ignoreDays());
|
||||
QDateTime dateTime = rule->lastMatch();
|
||||
QString lMatch = tr("Last match: ");
|
||||
|
@ -269,6 +270,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
|
|||
// New rule
|
||||
clearRuleDefinitionBox();
|
||||
ui->lineContains->setText(selection.first()->text());
|
||||
ui->comboAddPaused->setCurrentIndex(0);
|
||||
}
|
||||
updateFieldsToolTips(ui->checkRegex->isChecked());
|
||||
// Enable
|
||||
|
@ -339,6 +341,7 @@ void AutomatedRssDownloader::saveEditedRule()
|
|||
else
|
||||
rule->setSavePath("");
|
||||
rule->setLabel(ui->comboLabel->currentText());
|
||||
rule->setAddPaused(RssDownloadRule::AddPausedState(ui->comboAddPaused->currentIndex()));
|
||||
// Save new label
|
||||
if (!rule->label().isEmpty())
|
||||
Preferences::instance()->addTorrentLabel(rule->label());
|
||||
|
|
|
@ -394,6 +394,42 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblAddPaused">
|
||||
<property name="text">
|
||||
<string>Add Paused:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboAddPaused">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Use global setting</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Always add paused</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Never add paused</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -148,6 +148,7 @@ RssDownloadRulePtr RssDownloadRule::fromVariantHash(const QVariantHash &rule_has
|
|||
rule->setEnabled(rule_hash.value("enabled", false).toBool());
|
||||
rule->setSavePath(rule_hash.value("save_path").toString());
|
||||
rule->setLabel(rule_hash.value("label_assigned").toString());
|
||||
rule->setAddPaused(AddPausedState(rule_hash.value("add_paused").toUInt()));
|
||||
rule->setLastMatch(rule_hash.value("last_match").toDateTime());
|
||||
rule->setIgnoreDays(rule_hash.value("ignore_days").toInt());
|
||||
return rule;
|
||||
|
@ -164,6 +165,7 @@ QVariantHash RssDownloadRule::toVariantHash() const
|
|||
hash["enabled"] = m_enabled;
|
||||
hash["label_assigned"] = m_label;
|
||||
hash["use_regex"] = m_useRegex;
|
||||
hash["add_paused"] = m_apstate;
|
||||
hash["episode_filter"] = m_episodeFilter;
|
||||
hash["last_match"] = m_lastMatch;
|
||||
hash["ignore_days"] = m_ignoreDays;
|
||||
|
|
|
@ -46,6 +46,12 @@ class RssDownloadRule
|
|||
{
|
||||
|
||||
public:
|
||||
enum AddPausedState {
|
||||
USE_GLOBAL = 0,
|
||||
ALWAYS_PAUSED,
|
||||
NEVER_PAUSED
|
||||
};
|
||||
|
||||
explicit RssDownloadRule();
|
||||
static RssDownloadRulePtr fromVariantHash(const QVariantHash &rule_hash);
|
||||
QVariantHash toVariantHash() const;
|
||||
|
@ -58,6 +64,8 @@ public:
|
|||
inline void setName(const QString &name) { m_name = name; }
|
||||
inline QString savePath() const { return m_savePath; }
|
||||
void setSavePath(const QString &save_path);
|
||||
inline AddPausedState addPaused() const { return m_apstate; }
|
||||
inline void setAddPaused(const AddPausedState &aps) { m_apstate = aps; }
|
||||
inline QString label() const { return m_label; }
|
||||
inline void setLabel(const QString &_label) { m_label = _label; }
|
||||
inline bool isEnabled() const { return m_enabled; }
|
||||
|
@ -86,6 +94,7 @@ private:
|
|||
bool m_enabled;
|
||||
QStringList m_rssFeeds;
|
||||
bool m_useRegex;
|
||||
AddPausedState m_apstate;
|
||||
QDateTime m_lastMatch;
|
||||
int m_ignoreDays;
|
||||
};
|
||||
|
|
|
@ -371,9 +371,9 @@ void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const
|
|||
connect(QBtSession::instance(), SIGNAL(newDownloadedTorrentFromRss(QString)), article.data(), SLOT(handleTorrentDownloadSuccess(const QString&)), Qt::UniqueConnection);
|
||||
connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection);
|
||||
if (torrent_url.startsWith("magnet:", Qt::CaseInsensitive))
|
||||
QBtSession::instance()->addMagnetSkipAddDlg(torrent_url, matching_rule->savePath(), matching_rule->label());
|
||||
QBtSession::instance()->addMagnetSkipAddDlg(torrent_url, matching_rule->savePath(), matching_rule->label(), matching_rule->addPaused());
|
||||
else
|
||||
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label(), feedCookies());
|
||||
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label(), feedCookies(), matching_rule->addPaused());
|
||||
}
|
||||
|
||||
void RssFeed::recheckRssItemsForDownload()
|
||||
|
|
Loading…
Reference in a new issue