|
|
|
@ -114,9 +114,13 @@ void RssFeed::loadItemsFromDisk()
@@ -114,9 +114,13 @@ void RssFeed::loadItemsFromDisk()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RssFeed::addArticle(const RssArticlePtr& article) |
|
|
|
|
{ |
|
|
|
|
Q_ASSERT(!m_articles.contains(article->guid())); |
|
|
|
|
void RssFeed::addArticle(const RssArticlePtr& article) { |
|
|
|
|
int lbIndex = -1; |
|
|
|
|
int max_articles = RssSettings().getRSSMaxArticlesPerFeed(); |
|
|
|
|
|
|
|
|
|
if (!m_articles.contains(article->guid())) { |
|
|
|
|
markAsDirty(); |
|
|
|
|
|
|
|
|
|
// Update unreadCount
|
|
|
|
|
if (!article->isRead()) |
|
|
|
|
++m_unreadCount; |
|
|
|
@ -125,9 +129,7 @@ void RssFeed::addArticle(const RssArticlePtr& article)
@@ -125,9 +129,7 @@ void RssFeed::addArticle(const RssArticlePtr& article)
|
|
|
|
|
// Insertion sort
|
|
|
|
|
RssArticleList::Iterator lowerBound = qLowerBound(m_articlesByDate.begin(), m_articlesByDate.end(), article, rssArticleDateRecentThan); |
|
|
|
|
m_articlesByDate.insert(lowerBound, article); |
|
|
|
|
const int lbIndex = m_articlesByDate.indexOf(article); |
|
|
|
|
// Restrict size
|
|
|
|
|
const int max_articles = RssSettings().getRSSMaxArticlesPerFeed(); |
|
|
|
|
lbIndex = m_articlesByDate.indexOf(article); |
|
|
|
|
if (m_articlesByDate.size() > max_articles) { |
|
|
|
|
RssArticlePtr oldestArticle = m_articlesByDate.takeLast(); |
|
|
|
|
m_articles.remove(oldestArticle->guid()); |
|
|
|
@ -142,6 +144,18 @@ void RssFeed::addArticle(const RssArticlePtr& article)
@@ -142,6 +144,18 @@ void RssFeed::addArticle(const RssArticlePtr& article)
|
|
|
|
|
downloadArticleTorrentIfMatching(m_manager->downloadRules(), article); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// m_articles.contains(article->guid())
|
|
|
|
|
// Try to download skipped articles
|
|
|
|
|
if (RssSettings().isRssDownloadingEnabled()) { |
|
|
|
|
RssArticlePtr skipped = m_articles.value(article->guid(), RssArticlePtr()); |
|
|
|
|
if (skipped) { |
|
|
|
|
if (!skipped->isRead()) |
|
|
|
|
downloadArticleTorrentIfMatching(m_manager->downloadRules(), skipped); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QList<QNetworkCookie> RssFeed::feedCookies() const |
|
|
|
|
{ |
|
|
|
@ -338,16 +352,17 @@ void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const
@@ -338,16 +352,17 @@ void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const
|
|
|
|
|
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 |
|
|
|
|
else { |
|
|
|
|
connect(QBtSession::instance(), SIGNAL(newDownloadedTorrentFromRss(QString)), article.data(), SLOT(handleTorrentDownloadSuccess(const QString&)), Qt::UniqueConnection); |
|
|
|
|
connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection); |
|
|
|
|
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label(), feedCookies()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RssFeed::recheckRssItemsForDownload() |
|
|
|
|
{ |
|
|
|
@ -364,12 +379,6 @@ void RssFeed::handleNewArticle(const QString& feedUrl, const QVariantHash& artic
@@ -364,12 +379,6 @@ void RssFeed::handleNewArticle(const QString& feedUrl, const QVariantHash& artic
|
|
|
|
|
if (feedUrl != m_url) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
const QString guid = articleData["id"].toString(); |
|
|
|
|
if (m_articles.contains(guid)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
markAsDirty(); |
|
|
|
|
|
|
|
|
|
RssArticlePtr article = hashToRssArticle(this, articleData); |
|
|
|
|
Q_ASSERT(article); |
|
|
|
|
addArticle(article); |
|
|
|
@ -400,6 +409,10 @@ void RssFeed::handleFeedParsingFinished(const QString& feedUrl, const QString& e
@@ -400,6 +409,10 @@ void RssFeed::handleFeedParsingFinished(const QString& feedUrl, const QString& e
|
|
|
|
|
saveItemsToDisk(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RssFeed::handleArticleStateChanged() { |
|
|
|
|
m_manager->forwardFeedInfosChanged(m_url, displayName(), m_unreadCount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RssFeed::decrementUnreadCount() |
|
|
|
|
{ |
|
|
|
|
--m_unreadCount; |
|
|
|
|