Browse Source

Add support for RSS feeds using magnet links (Closes #1016379)

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
5a65580169
  1. 11
      src/mainwindow.cpp
  2. 1
      src/mainwindow.h
  3. 7
      src/qtlibtorrent/qbtsession.cpp
  4. 4
      src/qtlibtorrent/qbtsession.h
  5. 17
      src/rss/rss_imp.cpp
  6. 3
      src/rss/rssfeed.cpp

11
src/mainwindow.cpp

@ -145,6 +145,7 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa @@ -145,6 +145,7 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle)));
connect(QBtSession::instance(), SIGNAL(trackerAuthenticationRequired(QTorrentHandle)), this, SLOT(trackerAuthenticationRequired(QTorrentHandle)));
connect(QBtSession::instance(), SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString)));
connect(QBtSession::instance(), SIGNAL(newMagnetLink(QString)), this, SLOT(processNewMagnetLink(QString)));
connect(QBtSession::instance(), SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle)));
@ -979,6 +980,16 @@ void MainWindow::processDownloadedFiles(QString path, QString url) { @@ -979,6 +980,16 @@ void MainWindow::processDownloadedFiles(QString path, QString url) {
QBtSession::instance()->addTorrent(path, false, url);
}
void MainWindow::processNewMagnetLink(const QString& link)
{
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
if (useTorrentAdditionDialog)
AddNewTorrentDialog::showMagnet(link);
else
QBtSession::instance()->addMagnetUri(link);
}
void MainWindow::optionsSaved() {
loadPreferences();
}

1
src/mainwindow.h

@ -129,6 +129,7 @@ protected slots: @@ -129,6 +129,7 @@ protected slots:
void addTorrent(QString path);
void addUnauthenticatedTracker(const QPair<QTorrentHandle,QString> &tracker);
void processDownloadedFiles(QString path, QString url);
void processNewMagnetLink(const QString& link);
void finishedTorrent(const QTorrentHandle& h) const;
void askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h);
// Options slots

7
src/qtlibtorrent/qbtsession.cpp

@ -2642,7 +2642,12 @@ void QBtSession::downloadFromURLList(const QStringList& urls) { @@ -2642,7 +2642,12 @@ void QBtSession::downloadFromURLList(const QStringList& urls) {
}
}
void QBtSession::addMagnetSkipAddDlg(QString uri) {
void QBtSession::addMagnetInteractive(const QString& uri)
{
emit newMagnetLink(uri);
}
void QBtSession::addMagnetSkipAddDlg(const QString& uri) {
addMagnetUri(uri, false);
}

4
src/qtlibtorrent/qbtsession.h

@ -161,7 +161,8 @@ public slots: @@ -161,7 +161,8 @@ public slots:
#endif
void addPeerBanMessage(QString msg, bool from_ipfilter);
void processDownloadedFile(QString, QString);
void addMagnetSkipAddDlg(QString uri);
void addMagnetSkipAddDlg(const QString& uri);
void addMagnetInteractive(const QString& uri);
void downloadFromURLList(const QStringList& urls);
void configureSession();
void banIP(QString ip);
@ -202,6 +203,7 @@ signals: @@ -202,6 +203,7 @@ signals:
void trackerError(const QString &hash, QString time, QString msg);
void trackerAuthenticationRequired(const QTorrentHandle& h);
void newDownloadedTorrent(QString path, QString url);
void newMagnetLink(const QString& link);
void updateFileSize(const QString &hash);
void downloadFromUrlFailure(QString url, QString reason);
void torrentFinishedChecking(const QTorrentHandle& h);

17
src/rss/rss_imp.cpp

@ -326,6 +326,17 @@ void RSSImp::downloadTorrent() { @@ -326,6 +326,17 @@ void RSSImp::downloadTorrent() {
foreach (const QListWidgetItem* item, selected_items) {
RssArticlePtr article = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
->getItem(item->data(Article::IdRole).toString());
QString torrentLink;
if (article->hasAttachment())
torrentLink = article->torrentUrl();
else
torrentLink = article->link();
// Check if it is a magnet link
if (torrentLink.startsWith("magnet:", Qt::CaseInsensitive))
QBtSession::instance()->addMagnetInteractive(torrentLink);
else {
// Load possible cookies
QList<QNetworkCookie> cookies;
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
@ -339,10 +350,8 @@ void RSSImp::downloadTorrent() { @@ -339,10 +350,8 @@ void RSSImp::downloadTorrent() {
}
}
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
if (article->hasAttachment()) {
QBtSession::instance()->downloadFromUrl(article->torrentUrl(), cookies);
} else {
QBtSession::instance()->downloadFromUrl(article->link(), cookies);
QBtSession::instance()->downloadFromUrl(torrentLink, cookies);
}
}
}

3
src/rss/rssfeed.cpp

@ -295,6 +295,9 @@ void RssFeed::downloadMatchingArticleTorrents() { @@ -295,6 +295,9 @@ void RssFeed::downloadMatchingArticleTorrents() {
// Download the torrent
QString torrent_url = article->hasAttachment() ? article->torrentUrl() : article->link();
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(article->title()).arg(displayName()));
if (torrent_url.startsWith("magnet:", Qt::CaseInsensitive))
QBtSession::instance()->addMagnetSkipAddDlg(torrent_url);
else
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
}
}

Loading…
Cancel
Save