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
connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle)));
connect(QBtSession::instance(), SIGNAL(trackerAuthenticationRequired(QTorrentHandle)), this, SLOT(trackerAuthenticationRequired(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(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(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool))); connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle)));
@ -979,6 +980,16 @@ void MainWindow::processDownloadedFiles(QString path, QString url) {
QBtSession::instance()->addTorrent(path, false, 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() { void MainWindow::optionsSaved() {
loadPreferences(); loadPreferences();
} }

1
src/mainwindow.h

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

7
src/qtlibtorrent/qbtsession.cpp

@ -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); addMagnetUri(uri, false);
} }

4
src/qtlibtorrent/qbtsession.h

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

17
src/rss/rss_imp.cpp

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

3
src/rss/rssfeed.cpp

@ -295,6 +295,9 @@ void RssFeed::downloadMatchingArticleTorrents() {
// Download the torrent // Download the torrent
QString torrent_url = article->hasAttachment() ? article->torrentUrl() : article->link(); 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())); 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()); QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
} }
} }

Loading…
Cancel
Save