2010-10-16 21:39:03 +04:00
/*
* Bittorrent Client using Qt4 and libtorrent .
* Copyright ( C ) 2010 Christophe Dumez , Arnaud Demaiziere
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* In addition , as a special exception , the copyright holders give permission to
* link this program with the OpenSSL project ' s " OpenSSL " library ( or with
* modified versions of it that use the same license as the " OpenSSL " library ) ,
* and distribute the linked executables . You must obey the GNU General Public
* License in all respects for all of the code used other than " OpenSSL " . If you
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
*
* Contact : chris @ qbittorrent . org , arnaud @ qbittorrent . org
*/
2011-01-29 14:57:52 +03:00
# include <QDebug>
2010-10-16 21:39:03 +04:00
# include "rssfeed.h"
# include "rssmanager.h"
2015-04-19 18:17:47 +03:00
# include "core/bittorrent/session.h"
2010-10-16 21:39:03 +04:00
# include "rssfolder.h"
2015-04-13 19:19:53 +03:00
# include "core/preferences.h"
# include "core/qinisettings.h"
2010-10-16 21:39:03 +04:00
# include "rssarticle.h"
2012-08-18 19:06:29 +04:00
# include "rssparser.h"
2015-05-06 14:53:27 +03:00
# include "core/utils/misc.h"
2010-10-31 15:35:07 +03:00
# include "rssdownloadrulelist.h"
2015-04-19 18:17:47 +03:00
# include "core/net/downloadmanager.h"
# include "core/net/downloadhandler.h"
2015-05-06 14:53:27 +03:00
# include "core/utils/fs.h"
2015-04-13 19:19:53 +03:00
# include "core/logger.h"
2010-10-16 21:39:03 +04:00
2012-08-19 12:46:50 +04:00
bool rssArticleDateRecentThan ( const RssArticlePtr & left , const RssArticlePtr & right )
{
return left - > date ( ) > right - > date ( ) ;
}
2012-08-19 18:22:30 +04:00
RssFeed : : RssFeed ( RssManager * manager , RssFolder * parent , const QString & url ) :
m_manager ( manager ) ,
m_parent ( parent ) ,
m_url ( QUrl : : fromEncoded ( url . toUtf8 ( ) ) . toString ( ) ) ,
2015-01-18 15:13:06 +03:00
m_icon ( " :/icons/oxygen/application-rss+xml.png " ) ,
2012-08-19 18:22:30 +04:00
m_unreadCount ( 0 ) ,
m_dirty ( false ) ,
m_inErrorState ( false ) ,
m_loading ( false )
{
qDebug ( ) < < Q_FUNC_INFO < < m_url ;
2011-01-27 20:18:56 +03:00
// Listen for new RSS downloads
2012-08-18 19:06:29 +04:00
connect ( manager - > rssParser ( ) , SIGNAL ( feedTitle ( QString , QString ) ) , SLOT ( handleFeedTitle ( QString , QString ) ) ) ;
connect ( manager - > rssParser ( ) , SIGNAL ( newArticle ( QString , QVariantHash ) ) , SLOT ( handleNewArticle ( QString , QVariantHash ) ) ) ;
connect ( manager - > rssParser ( ) , SIGNAL ( feedParsingFinished ( QString , QString ) ) , SLOT ( handleFeedParsingFinished ( QString , QString ) ) ) ;
2011-01-27 20:18:56 +03:00
// Download the RSS Feed icon
2015-06-03 11:49:39 +03:00
Net : : DownloadHandler * handler = Net : : DownloadManager : : instance ( ) - > downloadUrl ( iconUrl ( ) , true ) ;
2015-04-19 18:17:47 +03:00
connect ( handler , SIGNAL ( downloadFinished ( QString , QString ) ) , this , SLOT ( handleFinishedDownload ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFailed ( QString , QString ) ) , this , SLOT ( handleDownloadFailure ( QString , QString ) ) ) ;
m_iconUrl = handler - > url ( ) ;
2011-09-26 21:25:59 +04:00
// Load old RSS articles
loadItemsFromDisk ( ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
RssFeed : : ~ RssFeed ( )
{
2012-02-20 21:30:53 +04:00
if ( ! m_icon . startsWith ( " :/ " ) & & QFile : : exists ( m_icon ) )
2015-05-06 14:53:27 +03:00
Utils : : Fs : : forceRemove ( m_icon ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
void RssFeed : : saveItemsToDisk ( )
{
2012-02-19 22:36:01 +04:00
qDebug ( ) < < Q_FUNC_INFO < < m_url ;
2012-08-18 22:26:22 +04:00
if ( ! m_dirty )
2012-02-19 22:36:01 +04:00
return ;
2013-01-28 14:53:04 +04:00
markAsDirty ( false ) ;
2012-08-18 22:26:22 +04:00
2011-09-26 21:25:59 +04:00
QIniSettings qBTRSS ( " qBittorrent " , " qBittorrent-rss " ) ;
QVariantList old_items ;
2012-07-14 15:45:40 +04:00
2012-08-19 18:22:30 +04:00
RssArticleHash : : ConstIterator it = m_articles . begin ( ) ;
RssArticleHash : : ConstIterator itend = m_articles . end ( ) ;
2012-07-14 15:45:40 +04:00
for ( ; it ! = itend ; + + it ) {
2012-02-19 18:38:41 +04:00
old_items < < it . value ( ) - > toHash ( ) ;
2011-09-26 21:25:59 +04:00
}
2012-08-19 18:22:30 +04:00
qDebug ( " Saving %d old items for feed %s " , old_items . size ( ) , qPrintable ( displayName ( ) ) ) ;
2011-09-26 21:25:59 +04:00
QHash < QString , QVariant > all_old_items = qBTRSS . value ( " old_items " , QHash < QString , QVariant > ( ) ) . toHash ( ) ;
all_old_items [ m_url ] = old_items ;
qBTRSS . setValue ( " old_items " , all_old_items ) ;
}
2012-08-19 18:22:30 +04:00
void RssFeed : : loadItemsFromDisk ( )
{
2011-09-26 21:25:59 +04:00
QIniSettings qBTRSS ( " qBittorrent " , " qBittorrent-rss " ) ;
QHash < QString , QVariant > all_old_items = qBTRSS . value ( " old_items " , QHash < QString , QVariant > ( ) ) . toHash ( ) ;
const QVariantList old_items = all_old_items . value ( m_url , QVariantList ( ) ) . toList ( ) ;
2012-08-19 18:22:30 +04:00
qDebug ( " Loading %d old items for feed %s " , old_items . size ( ) , qPrintable ( displayName ( ) ) ) ;
2011-09-26 21:25:59 +04:00
2012-08-19 18:22:30 +04:00
foreach ( const QVariant & var_it , old_items ) {
QVariantHash item = var_it . toHash ( ) ;
2012-02-19 18:38:41 +04:00
RssArticlePtr rss_item = hashToRssArticle ( this , item ) ;
2012-08-19 12:46:50 +04:00
if ( rss_item )
addArticle ( rss_item ) ;
}
}
2013-07-09 17:33:00 +04:00
void RssFeed : : addArticle ( const RssArticlePtr & article ) {
2014-07-05 16:44:13 +04:00
int max_articles = Preferences : : instance ( ) - > getRSSMaxArticlesPerFeed ( ) ;
2013-07-09 17:33:00 +04:00
if ( ! m_articles . contains ( article - > guid ( ) ) ) {
markAsDirty ( ) ;
2012-08-19 12:46:50 +04:00
// Update unreadCount
2013-07-09 17:33:00 +04:00
if ( ! article - > isRead ( ) )
+ + m_unreadCount ;
// Insert in hash table
m_articles [ article - > guid ( ) ] = article ;
// Insertion sort
RssArticleList : : Iterator lowerBound = qLowerBound ( m_articlesByDate . begin ( ) , m_articlesByDate . end ( ) , article , rssArticleDateRecentThan ) ;
m_articlesByDate . insert ( lowerBound , article ) ;
2015-05-14 14:22:36 +03:00
int lbIndex = m_articlesByDate . indexOf ( article ) ;
2013-07-09 17:33:00 +04:00
if ( m_articlesByDate . size ( ) > max_articles ) {
RssArticlePtr oldestArticle = m_articlesByDate . takeLast ( ) ;
m_articles . remove ( oldestArticle - > guid ( ) ) ;
// Update unreadCount
if ( ! oldestArticle - > isRead ( ) )
- - m_unreadCount ;
}
// Check if article was inserted at the end of the list and will break max_articles limit
2014-07-05 16:44:13 +04:00
if ( Preferences : : instance ( ) - > isRssDownloadingEnabled ( ) ) {
2013-07-09 17:33:00 +04:00
if ( lbIndex < max_articles & & ! article - > isRead ( ) )
downloadArticleTorrentIfMatching ( m_manager - > downloadRules ( ) , article ) ;
}
2011-09-26 21:25:59 +04:00
}
2013-07-09 17:33:00 +04:00
else {
// m_articles.contains(article->guid())
// Try to download skipped articles
2014-07-05 16:44:13 +04:00
if ( Preferences : : instance ( ) - > isRssDownloadingEnabled ( ) ) {
2013-07-09 17:33:00 +04:00
RssArticlePtr skipped = m_articles . value ( article - > guid ( ) , RssArticlePtr ( ) ) ;
if ( skipped ) {
if ( ! skipped - > isRead ( ) )
downloadArticleTorrentIfMatching ( m_manager - > downloadRules ( ) , skipped ) ;
}
}
2013-05-28 21:16:08 +04:00
}
2011-09-26 21:25:59 +04:00
}
2012-08-19 18:22:30 +04:00
bool RssFeed : : refresh ( )
{
2012-02-20 21:30:53 +04:00
if ( m_loading ) {
2012-08-19 18:22:30 +04:00
qWarning ( ) < < Q_FUNC_INFO < < " Feed " < < displayName ( ) < < " is already being refreshed, ignoring request " ;
2012-08-19 16:12:08 +04:00
return false ;
2011-10-05 19:54:06 +04:00
}
2011-01-27 20:18:56 +03:00
m_loading = true ;
// Download the RSS again
2015-06-03 11:49:39 +03:00
Net : : DownloadHandler * handler = Net : : DownloadManager : : instance ( ) - > downloadUrl ( m_url , true ) ;
2015-04-19 18:17:47 +03:00
connect ( handler , SIGNAL ( downloadFinished ( QString , QString ) ) , this , SLOT ( handleFinishedDownload ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFailed ( QString , QString ) ) , this , SLOT ( handleDownloadFailure ( QString , QString ) ) ) ;
m_url = handler - > url ( ) ; // sync URL encoding
2012-08-19 16:12:08 +04:00
return true ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
void RssFeed : : removeAllSettings ( )
{
2012-02-19 22:36:01 +04:00
qDebug ( ) < < " Removing all settings / history for feed: " < < m_url ;
2010-10-16 21:39:03 +04:00
QIniSettings qBTRSS ( " qBittorrent " , " qBittorrent-rss " ) ;
2012-08-19 18:22:30 +04:00
QVariantHash feeds_w_downloader = qBTRSS . value ( " downloader_on " , QVariantHash ( ) ) . toHash ( ) ;
2011-09-26 21:35:50 +04:00
if ( feeds_w_downloader . contains ( m_url ) ) {
2011-01-27 20:18:56 +03:00
feeds_w_downloader . remove ( m_url ) ;
2010-10-16 21:39:03 +04:00
qBTRSS . setValue ( " downloader_on " , feeds_w_downloader ) ;
}
2012-08-19 18:22:30 +04:00
QVariantHash all_feeds_filters = qBTRSS . value ( " feed_filters " , QVariantHash ( ) ) . toHash ( ) ;
2011-09-26 21:35:50 +04:00
if ( all_feeds_filters . contains ( m_url ) ) {
2011-01-27 20:18:56 +03:00
all_feeds_filters . remove ( m_url ) ;
2010-10-16 21:39:03 +04:00
qBTRSS . setValue ( " feed_filters " , all_feeds_filters ) ;
}
2012-08-19 18:22:30 +04:00
QVariantHash all_old_items = qBTRSS . value ( " old_items " , QVariantHash ( ) ) . toHash ( ) ;
2011-09-26 21:35:50 +04:00
if ( all_old_items . contains ( m_url ) ) {
all_old_items . remove ( m_url ) ;
qBTRSS . setValue ( " old_items " , all_old_items ) ;
}
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
bool RssFeed : : isLoading ( ) const
{
2011-01-27 20:18:56 +03:00
return m_loading ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
QString RssFeed : : title ( ) const
{
2011-01-27 20:18:56 +03:00
return m_title ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
void RssFeed : : rename ( const QString & new_name )
{
2011-01-27 20:18:56 +03:00
qDebug ( ) < < " Renaming stream to " < < new_name ;
m_alias = new_name ;
2010-10-16 21:39:03 +04:00
}
// Return the alias if the stream has one, the url if it has no alias
2012-08-19 18:22:30 +04:00
QString RssFeed : : displayName ( ) const
{
2012-02-20 23:32:58 +04:00
if ( ! m_alias . isEmpty ( ) )
2011-01-27 20:18:56 +03:00
return m_alias ;
2012-02-20 23:32:58 +04:00
if ( ! m_title . isEmpty ( ) )
2011-01-27 20:18:56 +03:00
return m_title ;
return m_url ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
QString RssFeed : : url ( ) const
{
2011-01-27 20:18:56 +03:00
return m_url ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 16:48:28 +04:00
QIcon RssFeed : : icon ( ) const
{
2012-08-18 19:06:29 +04:00
if ( m_inErrorState )
2015-01-18 15:13:06 +03:00
return QIcon ( " :/icons/oxygen/unavailable.png " ) ;
2012-08-19 18:22:30 +04:00
2012-08-19 16:48:28 +04:00
return QIcon ( m_icon ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
bool RssFeed : : hasCustomIcon ( ) const
{
2011-01-27 20:18:56 +03:00
return ! m_icon . startsWith ( " :/ " ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
void RssFeed : : setIconPath ( const QString & path )
{
if ( path . isEmpty ( ) | | ! QFile : : exists ( path ) )
return ;
2011-01-27 20:18:56 +03:00
m_icon = path ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
RssArticlePtr RssFeed : : getItem ( const QString & guid ) const
{
2012-02-19 17:42:51 +04:00
return m_articles . value ( guid ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
uint RssFeed : : count ( ) const
{
2011-01-27 20:18:56 +03:00
return m_articles . size ( ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
void RssFeed : : markAsRead ( )
{
RssArticleHash : : ConstIterator it = m_articles . begin ( ) ;
RssArticleHash : : ConstIterator itend = m_articles . end ( ) ;
2012-07-14 15:45:40 +04:00
for ( ; it ! = itend ; + + it ) {
2012-02-19 18:38:41 +04:00
it . value ( ) - > markAsRead ( ) ;
2010-10-16 21:39:03 +04:00
}
2012-08-18 23:25:21 +04:00
m_unreadCount = 0 ;
2012-02-19 20:53:10 +04:00
m_manager - > forwardFeedInfosChanged ( m_url , displayName ( ) , 0 ) ;
2010-10-16 21:39:03 +04:00
}
2013-01-28 14:53:04 +04:00
void RssFeed : : markAsDirty ( bool dirty )
{
m_dirty = dirty ;
}
2012-08-18 23:25:21 +04:00
uint RssFeed : : unreadCount ( ) const
{
return m_unreadCount ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
RssArticleList RssFeed : : articleListByDateDesc ( ) const
{
2012-08-19 12:46:50 +04:00
return m_articlesByDate ;
2010-10-16 21:39:03 +04:00
}
2012-08-19 18:22:30 +04:00
RssArticleList RssFeed : : unreadArticleListByDateDesc ( ) const
{
2012-02-19 20:53:10 +04:00
RssArticleList unread_news ;
2012-07-14 15:45:40 +04:00
2012-08-19 12:46:50 +04:00
RssArticleList : : ConstIterator it = m_articlesByDate . begin ( ) ;
RssArticleList : : ConstIterator itend = m_articlesByDate . end ( ) ;
2012-07-14 15:45:40 +04:00
for ( ; it ! = itend ; + + it ) {
2012-08-19 12:46:50 +04:00
if ( ! ( * it ) - > isRead ( ) )
unread_news < < * it ;
2010-10-16 21:39:03 +04:00
}
return unread_news ;
}
2015-05-04 02:09:30 +03:00
// download the icon from the address
2012-08-19 18:22:30 +04:00
QString RssFeed : : iconUrl ( ) const
{
2011-01-27 20:18:56 +03:00
// XXX: This works for most sites but it is not perfect
2012-08-19 18:22:30 +04:00
return QString ( " http:// " ) + QUrl ( m_url ) . host ( ) + QString ( " /favicon.ico " ) ;
2010-10-16 21:39:03 +04:00
}
// read and store the downloaded rss' informations
2015-04-19 18:17:47 +03:00
void RssFeed : : handleFinishedDownload ( const QString & url , const QString & filePath )
2012-08-19 18:22:30 +04:00
{
2012-02-20 21:30:53 +04:00
if ( url = = m_url ) {
2012-02-20 23:46:02 +04:00
qDebug ( ) < < Q_FUNC_INFO < < " Successfully downloaded RSS feed at " < < url ;
2011-01-27 20:18:56 +03:00
// Parse the download RSS
2012-08-19 18:22:30 +04:00
m_manager - > rssParser ( ) - > parseRssFile ( m_url , filePath ) ;
} else if ( url = = m_iconUrl ) {
m_icon = filePath ;
2011-10-05 19:54:06 +04:00
qDebug ( ) < < Q_FUNC_INFO < < " icon path: " < < m_icon ;
2012-08-19 18:22:30 +04:00
m_manager - > forwardFeedIconChanged ( m_url , m_icon ) ;
2010-10-16 21:39:03 +04:00
}
}
2015-04-19 18:17:47 +03:00
void RssFeed : : handleDownloadFailure ( const QString & url , const QString & error )
2012-08-19 18:22:30 +04:00
{
2015-04-19 18:17:47 +03:00
if ( url ! = m_url ) return ;
2012-08-19 18:22:30 +04:00
2012-08-18 19:06:29 +04:00
m_inErrorState = true ;
2011-01-27 20:18:56 +03:00
m_loading = false ;
2012-08-19 18:22:30 +04:00
m_manager - > forwardFeedInfosChanged ( m_url , displayName ( ) , m_unreadCount ) ;
2011-10-05 19:54:06 +04:00
qWarning ( ) < < " Failed to download RSS feed at " < < url ;
qWarning ( ) < < " Reason: " < < error ;
2010-10-16 21:39:03 +04:00
}
2012-08-18 19:06:29 +04:00
void RssFeed : : handleFeedTitle ( const QString & feedUrl , const QString & title )
{
if ( feedUrl ! = m_url )
return ;
2012-08-18 23:25:21 +04:00
if ( m_title = = title )
return ;
2012-08-18 22:30:15 +04:00
m_title = title ;
2012-08-18 23:25:21 +04:00
// Notify that we now have something better than a URL to display
if ( m_alias . isEmpty ( ) )
m_manager - > forwardFeedInfosChanged ( feedUrl , title , m_unreadCount ) ;
2012-08-18 19:06:29 +04:00
}
2012-09-23 11:25:25 +04:00
void RssFeed : : downloadArticleTorrentIfMatching ( RssDownloadRuleList * rules , const RssArticlePtr & article )
{
2014-07-05 16:44:13 +04:00
Q_ASSERT ( Preferences : : instance ( ) - > isRssDownloadingEnabled ( ) ) ;
2012-09-23 11:25:25 +04:00
RssDownloadRulePtr matching_rule = rules - > findMatchingRule ( m_url , article - > title ( ) ) ;
if ( ! matching_rule )
return ;
2013-07-25 00:39:05 +04:00
if ( matching_rule - > ignoreDays ( ) > 0 ) {
QDateTime lastMatch = matching_rule - > lastMatch ( ) ;
if ( lastMatch . isValid ( ) ) {
if ( QDateTime : : currentDateTime ( ) < lastMatch . addDays ( matching_rule - > ignoreDays ( ) ) ) {
connect ( article . data ( ) , SIGNAL ( articleWasRead ( ) ) , SLOT ( handleArticleStateChanged ( ) ) , Qt : : UniqueConnection ) ;
article - > markAsRead ( ) ;
return ;
}
}
}
matching_rule - > setLastMatch ( QDateTime : : currentDateTime ( ) ) ;
rules - > saveRulesToStorage ( ) ;
2012-09-23 11:25:25 +04:00
// Download the torrent
const QString & torrent_url = article - > torrentUrl ( ) ;
2015-08-04 03:43:45 +03:00
if ( torrent_url . isEmpty ( ) ) {
2015-08-08 16:19:46 +03:00
Logger : : instance ( ) - > addMessage ( tr ( " Automatic download of '%1' from '%2' RSS feed failed because it doesn't contain a torrent or a magnet link... " ) . arg ( article - > title ( ) ) . arg ( displayName ( ) ) , Log : : WARNING ) ;
2015-08-04 03:43:45 +03:00
article - > markAsRead ( ) ;
return ;
}
2015-08-08 16:19:46 +03:00
Logger : : instance ( ) - > addMessage ( tr ( " Automatically downloading '%1' torrent from '%2' RSS feed... " ) . arg ( article - > title ( ) ) . arg ( displayName ( ) ) ) ;
2015-04-19 18:17:47 +03:00
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( downloadFromUrlFinished ( QString ) ) , article . data ( ) , SLOT ( handleTorrentDownloadSuccess ( const QString & ) ) , Qt : : UniqueConnection ) ;
2013-10-20 00:59:36 +04:00
connect ( article . data ( ) , SIGNAL ( articleWasRead ( ) ) , SLOT ( handleArticleStateChanged ( ) ) , Qt : : UniqueConnection ) ;
2015-04-19 18:17:47 +03:00
BitTorrent : : AddTorrentParams params ;
params . savePath = matching_rule - > savePath ( ) ;
params . label = matching_rule - > label ( ) ;
if ( matching_rule - > addPaused ( ) = = RssDownloadRule : : ALWAYS_PAUSED )
params . addPaused = TriStateBool : : True ;
else if ( matching_rule - > addPaused ( ) = = RssDownloadRule : : NEVER_PAUSED )
params . addPaused = TriStateBool : : False ;
BitTorrent : : Session : : instance ( ) - > addTorrent ( torrent_url , params ) ;
2012-09-23 11:25:25 +04:00
}
void RssFeed : : recheckRssItemsForDownload ( )
{
2014-07-05 16:44:13 +04:00
Q_ASSERT ( Preferences : : instance ( ) - > isRssDownloadingEnabled ( ) ) ;
2012-09-23 11:25:25 +04:00
RssDownloadRuleList * rules = m_manager - > downloadRules ( ) ;
foreach ( const RssArticlePtr & article , m_articlesByDate ) {
if ( ! article - > isRead ( ) )
downloadArticleTorrentIfMatching ( rules , article ) ;
}
}
2012-08-18 19:06:29 +04:00
void RssFeed : : handleNewArticle ( const QString & feedUrl , const QVariantHash & articleData )
{
if ( feedUrl ! = m_url )
return ;
RssArticlePtr article = hashToRssArticle ( this , articleData ) ;
2013-10-20 01:33:22 +04:00
if ( article . isNull ( ) ) {
qDebug ( ) < < " Article hash corrupted or guid is uncomputable; feed url: " < < feedUrl ;
return ;
}
2012-08-18 19:06:29 +04:00
Q_ASSERT ( article ) ;
2012-08-19 12:46:50 +04:00
addArticle ( article ) ;
2012-08-18 19:06:29 +04:00
2012-08-18 23:25:21 +04:00
m_manager - > forwardFeedInfosChanged ( m_url , displayName ( ) , m_unreadCount ) ;
2012-08-18 19:06:29 +04:00
// FIXME: We should forward the information here but this would seriously decrease
// performance with current design.
2012-08-18 23:25:21 +04:00
//m_manager->forwardFeedContentChanged(m_url);
2012-08-18 19:06:29 +04:00
}
void RssFeed : : handleFeedParsingFinished ( const QString & feedUrl , const QString & error )
{
if ( feedUrl ! = m_url )
return ;
2012-08-18 23:25:21 +04:00
if ( ! error . isEmpty ( ) ) {
qWarning ( ) < < " Failed to parse RSS feed at " < < feedUrl ;
qWarning ( ) < < " Reason: " < < error ;
}
2012-08-18 19:06:29 +04:00
m_loading = false ;
m_inErrorState = ! error . isEmpty ( ) ;
2012-08-18 23:25:21 +04:00
m_manager - > forwardFeedInfosChanged ( m_url , displayName ( ) , m_unreadCount ) ;
// XXX: Would not be needed if we did this in handleNewArticle() instead
m_manager - > forwardFeedContentChanged ( m_url ) ;
2012-08-18 19:06:29 +04:00
saveItemsToDisk ( ) ;
}
2012-08-18 23:25:21 +04:00
2015-04-19 18:17:47 +03:00
void RssFeed : : handleArticleStateChanged ( )
{
2013-07-09 17:33:00 +04:00
m_manager - > forwardFeedInfosChanged ( m_url , displayName ( ) , m_unreadCount ) ;
}
2012-08-18 23:25:21 +04:00
void RssFeed : : decrementUnreadCount ( )
{
- - m_unreadCount ;
}