|
|
@ -46,9 +46,9 @@ RssFeed::RssFeed(RssFolder* parent, QString _url): parent(parent), alias(""), ic |
|
|
|
qDebug("Loading %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data()); |
|
|
|
qDebug("Loading %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data()); |
|
|
|
foreach(const QVariant &var_it, old_items) { |
|
|
|
foreach(const QVariant &var_it, old_items) { |
|
|
|
QHash<QString, QVariant> item = var_it.toHash(); |
|
|
|
QHash<QString, QVariant> item = var_it.toHash(); |
|
|
|
RssArticle *rss_item = hashToRssArticle(this, item); |
|
|
|
const RssArticle rss_item = hashToRssArticle(this, item); |
|
|
|
if(rss_item) { |
|
|
|
if(rss_item.isValid()) { |
|
|
|
insert(rss_item->guid(), rss_item); |
|
|
|
insert(rss_item.guid(), rss_item); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -58,16 +58,14 @@ RssFeed::~RssFeed(){ |
|
|
|
if(refreshed) { |
|
|
|
if(refreshed) { |
|
|
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); |
|
|
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); |
|
|
|
QVariantList old_items; |
|
|
|
QVariantList old_items; |
|
|
|
foreach(RssArticle *item, this->values()) { |
|
|
|
foreach(const RssArticle &item, this->values()) { |
|
|
|
old_items << item->toHash(); |
|
|
|
old_items << item.toHash(); |
|
|
|
} |
|
|
|
} |
|
|
|
qDebug("Saving %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data()); |
|
|
|
qDebug("Saving %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data()); |
|
|
|
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash(); |
|
|
|
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash(); |
|
|
|
all_old_items[url] = old_items; |
|
|
|
all_old_items[url] = old_items; |
|
|
|
qBTRSS.setValue("old_items", all_old_items); |
|
|
|
qBTRSS.setValue("old_items", all_old_items); |
|
|
|
} |
|
|
|
} |
|
|
|
qDebug("Removing all item from feed"); |
|
|
|
|
|
|
|
removeAllItems(); |
|
|
|
|
|
|
|
qDebug("All items were removed"); |
|
|
|
qDebug("All items were removed"); |
|
|
|
if(QFile::exists(filePath)) |
|
|
|
if(QFile::exists(filePath)) |
|
|
|
misc::safeRemove(filePath); |
|
|
|
misc::safeRemove(filePath); |
|
|
@ -83,12 +81,6 @@ void RssFeed::refresh() { |
|
|
|
parent->refreshStream(url); |
|
|
|
parent->refreshStream(url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// delete all the items saved
|
|
|
|
|
|
|
|
void RssFeed::removeAllItems() { |
|
|
|
|
|
|
|
qDeleteAll(this->values()); |
|
|
|
|
|
|
|
this->clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RssFeed::removeAllSettings() { |
|
|
|
void RssFeed::removeAllSettings() { |
|
|
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); |
|
|
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); |
|
|
|
QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash(); |
|
|
|
QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash(); |
|
|
@ -172,8 +164,8 @@ void RssFeed::setIconPath(QString path) { |
|
|
|
iconPath = path; |
|
|
|
iconPath = path; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RssArticle* RssFeed::getItem(QString id) const{ |
|
|
|
RssArticle& RssFeed::getItem(QString id) { |
|
|
|
return this->value(id); |
|
|
|
return (*this)[id]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int RssFeed::getNbNews() const{ |
|
|
|
unsigned int RssFeed::getNbNews() const{ |
|
|
@ -181,29 +173,30 @@ unsigned int RssFeed::getNbNews() const{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RssFeed::markAllAsRead() { |
|
|
|
void RssFeed::markAllAsRead() { |
|
|
|
foreach(RssArticle *item, this->values()){ |
|
|
|
QHash<QString, RssArticle>::iterator it; |
|
|
|
item->markAsRead(); |
|
|
|
for(it = this->begin(); it != this->end(); it++) { |
|
|
|
|
|
|
|
it.value().markAsRead(); |
|
|
|
} |
|
|
|
} |
|
|
|
RssManager::instance()->forwardFeedInfosChanged(url, getName(), 0); |
|
|
|
RssManager::instance()->forwardFeedInfosChanged(url, getName(), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int RssFeed::getNbUnRead() const{ |
|
|
|
unsigned int RssFeed::getNbUnRead() const{ |
|
|
|
unsigned int nbUnread=0; |
|
|
|
unsigned int nbUnread=0; |
|
|
|
foreach(RssArticle *item, this->values()) { |
|
|
|
foreach(const RssArticle &item, this->values()) { |
|
|
|
if(!item->isRead()) |
|
|
|
if(!item.isRead()) |
|
|
|
++nbUnread; |
|
|
|
++nbUnread; |
|
|
|
} |
|
|
|
} |
|
|
|
return nbUnread; |
|
|
|
return nbUnread; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<RssArticle*> RssFeed::getNewsList() const{ |
|
|
|
QList<RssArticle> RssFeed::getNewsList() const{ |
|
|
|
return this->values(); |
|
|
|
return this->values(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<RssArticle*> RssFeed::getUnreadNewsList() const { |
|
|
|
QList<RssArticle> RssFeed::getUnreadNewsList() const { |
|
|
|
QList<RssArticle*> unread_news; |
|
|
|
QList<RssArticle> unread_news; |
|
|
|
foreach(RssArticle *item, this->values()) { |
|
|
|
foreach(const RssArticle &item, this->values()) { |
|
|
|
if(!item->isRead()) |
|
|
|
if(!item.isRead()) |
|
|
|
unread_news << item; |
|
|
|
unread_news << item; |
|
|
|
} |
|
|
|
} |
|
|
|
return unread_news; |
|
|
|
return unread_news; |
|
|
@ -272,11 +265,9 @@ short RssFeed::readDoc(QIODevice* device) { |
|
|
|
image = xml.attributes().value("url").toString(); |
|
|
|
image = xml.attributes().value("url").toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(xml.name() == "item") { |
|
|
|
else if(xml.name() == "item") { |
|
|
|
RssArticle * item = new RssArticle(this, xml); |
|
|
|
RssArticle item(this, xml); |
|
|
|
if(item->isValid() && !itemAlreadyExists(item->guid())) { |
|
|
|
if(item.isValid() && !itemAlreadyExists(item.guid())) { |
|
|
|
this->insert(item->guid(), item); |
|
|
|
this->insert(item.guid(), item); |
|
|
|
} else { |
|
|
|
|
|
|
|
delete item; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -289,21 +280,23 @@ short RssFeed::readDoc(QIODevice* device) { |
|
|
|
|
|
|
|
|
|
|
|
// RSS Feed Downloader
|
|
|
|
// RSS Feed Downloader
|
|
|
|
if(RssSettings().isRssDownloadingEnabled()) { |
|
|
|
if(RssSettings().isRssDownloadingEnabled()) { |
|
|
|
foreach(RssArticle* item, values()) { |
|
|
|
QHash<QString, RssArticle>::iterator it; |
|
|
|
if(item->isRead()) continue; |
|
|
|
for(it = this->begin(); it != this->end(); it++) { |
|
|
|
|
|
|
|
RssArticle &item = it.value(); |
|
|
|
|
|
|
|
if(item.isRead()) continue; |
|
|
|
QString torrent_url; |
|
|
|
QString torrent_url; |
|
|
|
if(item->hasAttachment()) |
|
|
|
if(item.hasAttachment()) |
|
|
|
torrent_url = item->torrentUrl(); |
|
|
|
torrent_url = item.torrentUrl(); |
|
|
|
else |
|
|
|
else |
|
|
|
torrent_url = item->link(); |
|
|
|
torrent_url = item.link(); |
|
|
|
// Check if the item should be automatically downloaded
|
|
|
|
// Check if the item should be automatically downloaded
|
|
|
|
const RssDownloadRule matching_rule = RssDownloadRuleList::instance()->findMatchingRule(url, item->title()); |
|
|
|
const RssDownloadRule matching_rule = RssDownloadRuleList::instance()->findMatchingRule(url, item.title()); |
|
|
|
if(matching_rule.isValid()) { |
|
|
|
if(matching_rule.isValid()) { |
|
|
|
// Download the torrent
|
|
|
|
// Download the torrent
|
|
|
|
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->title()).arg(getName())); |
|
|
|
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item.title()).arg(getName())); |
|
|
|
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule.savePath(), matching_rule.label()); |
|
|
|
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule.savePath(), matching_rule.label()); |
|
|
|
// Item was downloaded, consider it as Read
|
|
|
|
// Item was downloaded, consider it as Read
|
|
|
|
item->markAsRead(); |
|
|
|
item.markAsRead(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -314,11 +307,10 @@ void RssFeed::resizeList() { |
|
|
|
const unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed(); |
|
|
|
const unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed(); |
|
|
|
const unsigned int nb_articles = this->size(); |
|
|
|
const unsigned int nb_articles = this->size(); |
|
|
|
if(nb_articles > max_articles) { |
|
|
|
if(nb_articles > max_articles) { |
|
|
|
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values()); |
|
|
|
const QList<RssArticle> listItem = RssManager::sortNewsList(this->values()); |
|
|
|
const int excess = nb_articles - max_articles; |
|
|
|
const int excess = nb_articles - max_articles; |
|
|
|
for(int i=0; i<excess; ++i){ |
|
|
|
for(uint i=nb_articles-excess; i<nb_articles; ++i){ |
|
|
|
RssArticle *lastItem = listItem.takeLast(); |
|
|
|
this->remove(listItem.at(i).guid()); |
|
|
|
delete this->take(lastItem->guid()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|