diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index cb2485f55..ed4c253ff 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -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 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); + } +#ifndef DISABLE_GUI + RssDownloadRule::AddPausedState state = RssDownloadRule::USE_GLOBAL; + if (addpaused_fromurl.contains(url_old)) { + state = addpaused_fromurl.take(url_old); } - addMagnetSkipAddDlg(url_new, savePath_label.first, savePath_label.second, 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& cookies) { +#ifndef DISABLE_GUI + void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label, + const QList& cookies, const RssDownloadRule::AddPausedState &aps) { +#else + void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label, const QList& 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); } diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index de45f9f41..bfb112e87 100755 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -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& cookies = QList()); +#ifndef DISABLE_GUI + void downloadUrlAndSkipDialog(QString url, QString save_path=QString(), QString label=QString(), + const QList& cookies = QList(), + const RssDownloadRule::AddPausedState &aps = RssDownloadRule::USE_GLOBAL); +#else + void downloadUrlAndSkipDialog(QString url, QString save_path=QString(), QString label=QString(), + const QList& cookies = QList()); +#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 bd_scheduler; QMap > savepathLabel_fromurl; // Use QMap for compatibility with Qt < 4.7: qHash(QUrl) +#ifndef DISABLE_GUI + QMap addpaused_fromurl; +#endif QHash > trackersInfos; QHash savePathsToRemove; QStringList torrentsToPausedAfterChecking; diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index 9edc05745..977d07a0b 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -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()); diff --git a/src/rss/automatedrssdownloader.ui b/src/rss/automatedrssdownloader.ui index 827e039f9..4a10460de 100644 --- a/src/rss/automatedrssdownloader.ui +++ b/src/rss/automatedrssdownloader.ui @@ -394,6 +394,42 @@ + + + + + + Add Paused: + + + + + + + + 0 + 0 + + + + + Use global setting + + + + + Always add paused + + + + + Never add paused + + + + + + diff --git a/src/rss/rssdownloadrule.cpp b/src/rss/rssdownloadrule.cpp index 2af77c1b9..439949aac 100644 --- a/src/rss/rssdownloadrule.cpp +++ b/src/rss/rssdownloadrule.cpp @@ -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; diff --git a/src/rss/rssdownloadrule.h b/src/rss/rssdownloadrule.h index 0d9624ccd..c76bd3187 100644 --- a/src/rss/rssdownloadrule.h +++ b/src/rss/rssdownloadrule.h @@ -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; }; diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index d3ad039bd..a1aadf433 100644 --- a/src/rss/rssfeed.cpp +++ b/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(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()