Browse Source

Make sure new RSS download rules apply to existing articles as well, not just new ones

May be related to #116.
adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
819dcacae0
  1. 4
      src/rss/rss_imp.cpp
  2. 7
      src/rss/rssarticle.cpp
  3. 2
      src/rss/rssarticle.h
  4. 44
      src/rss/rssfeed.cpp
  5. 3
      src/rss/rssfeed.h
  6. 1
      src/rss/rssfile.h
  7. 9
      src/rss/rssfolder.cpp
  8. 1
      src/rss/rssfolder.h

4
src/rss/rss_imp.cpp

@ -761,6 +761,8 @@ void RSSImp::on_rssDownloaderBtn_clicked()
{ {
AutomatedRssDownloader dlg(m_rssManager, this); AutomatedRssDownloader dlg(m_rssManager, this);
dlg.exec(); dlg.exec();
if (dlg.isRssDownloaderEnabled()) if (dlg.isRssDownloaderEnabled()) {
m_rssManager->recheckRssItemsForDownload();
refreshAllFeeds(); refreshAllFeeds();
}
} }

7
src/rss/rssarticle.cpp

@ -89,10 +89,9 @@ const QString& RssArticle::link() const {
return m_link; return m_link;
} }
const QString& RssArticle::description() const { QString RssArticle::description() const
if (m_description.isNull()) {
return ""; return m_description.isNull() ? "" : m_description;
return m_description;
} }
const QDateTime& RssArticle::date() const { const QDateTime& RssArticle::date() const {

2
src/rss/rssarticle.h

@ -54,7 +54,7 @@ public:
const QString& author() const; const QString& author() const;
const QString& torrentUrl() const; const QString& torrentUrl() const;
const QString& link() const; const QString& link() const;
const QString& description() const; QString description() const;
const QDateTime& date() const; const QDateTime& date() const;
bool isRead() const; bool isRead() const;
// Setters // Setters

44
src/rss/rssfeed.cpp

@ -313,6 +313,34 @@ void RssFeed::handleFeedTitle(const QString& feedUrl, const QString& title)
m_manager->forwardFeedInfosChanged(feedUrl, title, m_unreadCount); m_manager->forwardFeedInfosChanged(feedUrl, title, m_unreadCount);
} }
void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const RssArticlePtr& article)
{
Q_ASSERT(RssSettings().isRssDownloadingEnabled());
RssDownloadRulePtr matching_rule = rules->findMatchingRule(m_url, article->title());
if (!matching_rule)
return;
// Torrent was downloaded, consider article as read
article->markAsRead();
// Download the torrent
const QString& torrent_url = article->torrentUrl();
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, matching_rule->savePath(), matching_rule->label());
else
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
}
void RssFeed::recheckRssItemsForDownload()
{
Q_ASSERT(RssSettings().isRssDownloadingEnabled());
RssDownloadRuleList* rules = m_manager->downloadRules();
foreach (const RssArticlePtr& article, m_articlesByDate) {
if (!article->isRead())
downloadArticleTorrentIfMatching(rules, article);
}
}
void RssFeed::handleNewArticle(const QString& feedUrl, const QVariantHash& articleData) void RssFeed::handleNewArticle(const QString& feedUrl, const QVariantHash& articleData)
{ {
if (feedUrl != m_url) if (feedUrl != m_url)
@ -329,20 +357,8 @@ void RssFeed::handleNewArticle(const QString& feedUrl, const QVariantHash& artic
addArticle(article); addArticle(article);
// Download torrent if necessary. // Download torrent if necessary.
if (RssSettings().isRssDownloadingEnabled()) { if (RssSettings().isRssDownloadingEnabled())
RssDownloadRulePtr matching_rule = m_manager->downloadRules()->findMatchingRule(m_url, article->title()); downloadArticleTorrentIfMatching(m_manager->downloadRules(), article);
if (matching_rule) {
// Torrent was downloaded, consider article as read
article->markAsRead();
// Download the torrent
QString torrent_url = article->torrentUrl();
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, matching_rule->savePath(), matching_rule->label());
else
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
}
}
m_manager->forwardFeedInfosChanged(m_url, displayName(), m_unreadCount); m_manager->forwardFeedInfosChanged(m_url, displayName(), m_unreadCount);
// FIXME: We should forward the information here but this would seriously decrease // FIXME: We should forward the information here but this would seriously decrease

3
src/rss/rssfeed.h

@ -40,6 +40,7 @@
class RssFeed; class RssFeed;
class RssManager; class RssManager;
class RssDownloadRuleList;
typedef QHash<QString, RssArticlePtr> RssArticleHash; typedef QHash<QString, RssArticlePtr> RssArticleHash;
typedef QSharedPointer<RssFeed> RssFeedPtr; typedef QSharedPointer<RssFeed> RssFeedPtr;
@ -75,6 +76,7 @@ public:
const RssArticleHash& articleHash() const { return m_articles; } const RssArticleHash& articleHash() const { return m_articles; }
virtual RssArticleList unreadArticleListByDateDesc() const; virtual RssArticleList unreadArticleListByDateDesc() const;
void decrementUnreadCount(); void decrementUnreadCount();
void recheckRssItemsForDownload();
private slots: private slots:
void handleFinishedDownload(const QString& url, const QString &file_path); void handleFinishedDownload(const QString& url, const QString &file_path);
@ -87,6 +89,7 @@ private:
QString iconUrl() const; QString iconUrl() const;
void loadItemsFromDisk(); void loadItemsFromDisk();
void addArticle(const RssArticlePtr& article); void addArticle(const RssArticlePtr& article);
void downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const RssArticlePtr& article);
private: private:
RssManager* m_manager; RssManager* m_manager;

1
src/rss/rssfile.h

@ -65,6 +65,7 @@ public:
virtual RssArticleList unreadArticleListByDateDesc() const = 0; virtual RssArticleList unreadArticleListByDateDesc() const = 0;
virtual void removeAllSettings() = 0; virtual void removeAllSettings() = 0;
virtual void saveItemsToDisk() = 0; virtual void saveItemsToDisk() = 0;
virtual void recheckRssItemsForDownload() = 0;
QStringList pathHierarchy() const; QStringList pathHierarchy() const;
protected: protected:

9
src/rss/rssfolder.cpp

@ -251,3 +251,12 @@ RssFilePtr RssFolder::takeChild(const QString &childId)
{ {
return m_children.take(childId); return m_children.take(childId);
} }
void RssFolder::recheckRssItemsForDownload()
{
RssFileHash::ConstIterator it = m_children.begin();
RssFileHash::ConstIterator itend = m_children.end();
for ( ; it != itend; ++it) {
it.value()->recheckRssItemsForDownload();
}
}

1
src/rss/rssfolder.h

@ -70,6 +70,7 @@ public:
void removeAllItems(); void removeAllItems();
void renameChildFolder(const QString &old_name, const QString &new_name); void renameChildFolder(const QString &old_name, const QString &new_name);
RssFilePtr takeChild(const QString &childId); RssFilePtr takeChild(const QString &childId);
void recheckRssItemsForDownload();
public slots: public slots:
virtual bool refresh(); virtual bool refresh();

Loading…
Cancel
Save