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

This commit is contained in:
Nick Tiskov
2014-08-18 23:58:40 +04:00
parent 3b4548fe73
commit ef14b83134
7 changed files with 146 additions and 9 deletions

View File

@@ -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);
}

View File

@@ -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;