Browse Source

Support overriding global "Add paused" option in RSS on per rule basis

adaptive-webui-19844
Nick Tiskov 10 years ago
parent
commit
ef14b83134
  1. 78
      src/qtlibtorrent/qbtsession.cpp
  2. 21
      src/qtlibtorrent/qbtsession.h
  3. 3
      src/rss/automatedrssdownloader.cpp
  4. 36
      src/rss/automatedrssdownloader.ui
  5. 2
      src/rss/rssdownloadrule.cpp
  6. 9
      src/rss/rssdownloadrule.h
  7. 4
      src/rss/rssfeed.cpp

78
src/qtlibtorrent/qbtsession.cpp

@ -272,6 +272,9 @@ void QBtSession::handleDownloadFailure(QString url, QString reason) {
const QUrl qurl = QUrl::fromEncoded(url.toUtf8()); const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
url_skippingDlg.removeOne(qurl); url_skippingDlg.removeOne(qurl);
savepathLabel_fromurl.remove(qurl); savepathLabel_fromurl.remove(qurl);
#ifndef DISABLE_GUI
addpaused_fromurl.remove(qurl);
#endif
} }
void QBtSession::handleMagnetRedirect(const QString &url_new, const QString &url_old) { 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); url_skippingDlg.removeOne(url_old);
QPair<QString, QString> savePath_label; QPair<QString, QString> savePath_label;
if (savepathLabel_fromurl.contains(url_old)) { if (savepathLabel_fromurl.contains(url_old)) {
savePath_label = savepathLabel_fromurl.take(QUrl::fromEncoded(url_old.toUtf8())); savePath_label = savepathLabel_fromurl.take(url_old);
savepathLabel_fromurl.remove(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 else
addMagnetInteractive(url_new); addMagnetInteractive(url_new);
@ -2914,18 +2926,49 @@ void QBtSession::addMagnetInteractive(const QString& uri)
emit newMagnetLink(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()) if (!save_path.isEmpty() || !label.isEmpty())
savepathLabel_fromurl[uri] = qMakePair(fsutils::fromNativePath(save_path), label); 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); addMagnetUri(uri, false);
emit newDownloadedTorrentFromRss(uri_old.isEmpty() ? uri : uri_old); 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); //emit aboutToDownloadFromUrl(url);
const QUrl qurl = QUrl::fromEncoded(url.toUtf8()); const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
if (!save_path.isEmpty() || !label.isEmpty()) if (!save_path.isEmpty() || !label.isEmpty())
savepathLabel_fromurl[qurl] = qMakePair(fsutils::fromNativePath(save_path), label); 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; url_skippingDlg << qurl;
// Launch downloader thread // Launch downloader thread
downloader->downloadTorrentUrl(url, cookies); downloader->downloadTorrentUrl(url, cookies);
@ -2953,6 +2996,31 @@ void QBtSession::processDownloadedFile(QString url, QString file_path) {
emit newDownloadedTorrent(file_path, url); emit newDownloadedTorrent(file_path, url);
} else { } else {
url_skippingDlg.removeAt(index); 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); addTorrent(file_path, false, url, false);
emit newDownloadedTorrentFromRss(url); emit newDownloadedTorrentFromRss(url);
} }

21
src/qtlibtorrent/qbtsession.h

@ -50,6 +50,10 @@
#include "trackerinfos.h" #include "trackerinfos.h"
#include "misc.h" #include "misc.h"
#ifndef DISABLE_GUI
#include "rssdownloadrule.h"
#endif
namespace libtorrent { namespace libtorrent {
struct add_torrent_params; struct add_torrent_params;
struct pe_settings; struct pe_settings;
@ -175,7 +179,14 @@ public slots:
void setQueueingEnabled(bool enable); void setQueueingEnabled(bool enable);
void handleDownloadFailure(QString url, QString reason); void handleDownloadFailure(QString url, QString reason);
void handleMagnetRedirect(const QString &url_new, const QString &url_old); 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 // Session configuration - Setters
void setListeningPort(int port); void setListeningPort(int port);
void setMaxConnectionsPerTorrent(int max); void setMaxConnectionsPerTorrent(int max);
@ -212,7 +223,12 @@ public slots:
void clearConsoleMessages() { consoleMessages.clear(); } void clearConsoleMessages() { consoleMessages.clear(); }
void clearPeerBanMessages() { peerBanMessages.clear(); } void clearPeerBanMessages() { peerBanMessages.clear(); }
void processDownloadedFile(QString, QString); void processDownloadedFile(QString, 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()); 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 addMagnetInteractive(const QString& uri);
void downloadFromURLList(const QStringList& urls); void downloadFromURLList(const QStringList& urls);
void configureSession(); void configureSession();
@ -305,6 +321,9 @@ private:
libtorrent::session *s; libtorrent::session *s;
QPointer<BandwidthScheduler> bd_scheduler; QPointer<BandwidthScheduler> bd_scheduler;
QMap<QUrl, QPair<QString, QString> > savepathLabel_fromurl; // Use QMap for compatibility with Qt < 4.7: qHash(QUrl) 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, QHash<QString, TrackerInfos> > trackersInfos;
QHash<QString, QString> savePathsToRemove; QHash<QString, QString> savePathsToRemove;
QStringList torrentsToPausedAfterChecking; QStringList torrentsToPausedAfterChecking;

3
src/rss/automatedrssdownloader.cpp

@ -255,6 +255,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
} else { } else {
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule->label())); ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule->label()));
} }
ui->comboAddPaused->setCurrentIndex(rule->addPaused());
ui->spinIgnorePeriod->setValue(rule->ignoreDays()); ui->spinIgnorePeriod->setValue(rule->ignoreDays());
QDateTime dateTime = rule->lastMatch(); QDateTime dateTime = rule->lastMatch();
QString lMatch = tr("Last match: "); QString lMatch = tr("Last match: ");
@ -269,6 +270,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
// New rule // New rule
clearRuleDefinitionBox(); clearRuleDefinitionBox();
ui->lineContains->setText(selection.first()->text()); ui->lineContains->setText(selection.first()->text());
ui->comboAddPaused->setCurrentIndex(0);
} }
updateFieldsToolTips(ui->checkRegex->isChecked()); updateFieldsToolTips(ui->checkRegex->isChecked());
// Enable // Enable
@ -339,6 +341,7 @@ void AutomatedRssDownloader::saveEditedRule()
else else
rule->setSavePath(""); rule->setSavePath("");
rule->setLabel(ui->comboLabel->currentText()); rule->setLabel(ui->comboLabel->currentText());
rule->setAddPaused(RssDownloadRule::AddPausedState(ui->comboAddPaused->currentIndex()));
// Save new label // Save new label
if (!rule->label().isEmpty()) if (!rule->label().isEmpty())
Preferences::instance()->addTorrentLabel(rule->label()); Preferences::instance()->addTorrentLabel(rule->label());

36
src/rss/automatedrssdownloader.ui

@ -394,6 +394,42 @@
</item> </item>
</layout> </layout>
</item> </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> </layout>
</widget> </widget>
</item> </item>

2
src/rss/rssdownloadrule.cpp

@ -148,6 +148,7 @@ RssDownloadRulePtr RssDownloadRule::fromVariantHash(const QVariantHash &rule_has
rule->setEnabled(rule_hash.value("enabled", false).toBool()); rule->setEnabled(rule_hash.value("enabled", false).toBool());
rule->setSavePath(rule_hash.value("save_path").toString()); rule->setSavePath(rule_hash.value("save_path").toString());
rule->setLabel(rule_hash.value("label_assigned").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->setLastMatch(rule_hash.value("last_match").toDateTime());
rule->setIgnoreDays(rule_hash.value("ignore_days").toInt()); rule->setIgnoreDays(rule_hash.value("ignore_days").toInt());
return rule; return rule;
@ -164,6 +165,7 @@ QVariantHash RssDownloadRule::toVariantHash() const
hash["enabled"] = m_enabled; hash["enabled"] = m_enabled;
hash["label_assigned"] = m_label; hash["label_assigned"] = m_label;
hash["use_regex"] = m_useRegex; hash["use_regex"] = m_useRegex;
hash["add_paused"] = m_apstate;
hash["episode_filter"] = m_episodeFilter; hash["episode_filter"] = m_episodeFilter;
hash["last_match"] = m_lastMatch; hash["last_match"] = m_lastMatch;
hash["ignore_days"] = m_ignoreDays; hash["ignore_days"] = m_ignoreDays;

9
src/rss/rssdownloadrule.h

@ -46,6 +46,12 @@ class RssDownloadRule
{ {
public: public:
enum AddPausedState {
USE_GLOBAL = 0,
ALWAYS_PAUSED,
NEVER_PAUSED
};
explicit RssDownloadRule(); explicit RssDownloadRule();
static RssDownloadRulePtr fromVariantHash(const QVariantHash &rule_hash); static RssDownloadRulePtr fromVariantHash(const QVariantHash &rule_hash);
QVariantHash toVariantHash() const; QVariantHash toVariantHash() const;
@ -58,6 +64,8 @@ public:
inline void setName(const QString &name) { m_name = name; } inline void setName(const QString &name) { m_name = name; }
inline QString savePath() const { return m_savePath; } inline QString savePath() const { return m_savePath; }
void setSavePath(const QString &save_path); 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 QString label() const { return m_label; }
inline void setLabel(const QString &_label) { m_label = _label; } inline void setLabel(const QString &_label) { m_label = _label; }
inline bool isEnabled() const { return m_enabled; } inline bool isEnabled() const { return m_enabled; }
@ -86,6 +94,7 @@ private:
bool m_enabled; bool m_enabled;
QStringList m_rssFeeds; QStringList m_rssFeeds;
bool m_useRegex; bool m_useRegex;
AddPausedState m_apstate;
QDateTime m_lastMatch; QDateTime m_lastMatch;
int m_ignoreDays; int m_ignoreDays;
}; };

4
src/rss/rssfeed.cpp

@ -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(QBtSession::instance(), SIGNAL(newDownloadedTorrentFromRss(QString)), article.data(), SLOT(handleTorrentDownloadSuccess(const QString&)), Qt::UniqueConnection);
connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection); connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection);
if (torrent_url.startsWith("magnet:", Qt::CaseInsensitive)) 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 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() void RssFeed::recheckRssItemsForDownload()

Loading…
Cancel
Save