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

May be related to #116.
This commit is contained in:
Christophe Dumez 2012-09-23 10:25:25 +03:00
parent 7e57a63ec5
commit 819dcacae0
8 changed files with 51 additions and 20 deletions

View File

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

View File

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

View File

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

View File

@ -313,6 +313,34 @@ void RssFeed::handleFeedTitle(const QString& feedUrl, const QString& title)
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)
{
if (feedUrl != m_url)
@ -329,20 +357,8 @@ void RssFeed::handleNewArticle(const QString& feedUrl, const QVariantHash& artic
addArticle(article);
// Download torrent if necessary.
if (RssSettings().isRssDownloadingEnabled()) {
RssDownloadRulePtr matching_rule = m_manager->downloadRules()->findMatchingRule(m_url, article->title());
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());
}
}
if (RssSettings().isRssDownloadingEnabled())
downloadArticleTorrentIfMatching(m_manager->downloadRules(), article);
m_manager->forwardFeedInfosChanged(m_url, displayName(), m_unreadCount);
// FIXME: We should forward the information here but this would seriously decrease

View File

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

View File

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

View File

@ -251,3 +251,12 @@ RssFilePtr RssFolder::takeChild(const QString &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();
}
}

View File

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