mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
RSS optimization
This commit is contained in:
parent
86b4db75be
commit
954e010493
11 changed files with 131 additions and 145 deletions
|
@ -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());
|
||||
foreach(const QVariant &var_it, old_items) {
|
||||
QHash<QString, QVariant> item = var_it.toHash();
|
||||
RssArticle *rss_item = hashToRssArticle(this, item);
|
||||
if(rss_item) {
|
||||
insert(rss_item->guid(), rss_item);
|
||||
const RssArticle rss_item = hashToRssArticle(this, item);
|
||||
if(rss_item.isValid()) {
|
||||
insert(rss_item.guid(), rss_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,16 +58,14 @@ RssFeed::~RssFeed(){
|
|||
if(refreshed) {
|
||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
||||
QVariantList old_items;
|
||||
foreach(RssArticle *item, this->values()) {
|
||||
old_items << item->toHash();
|
||||
foreach(const RssArticle &item, this->values()) {
|
||||
old_items << item.toHash();
|
||||
}
|
||||
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();
|
||||
all_old_items[url] = old_items;
|
||||
qBTRSS.setValue("old_items", all_old_items);
|
||||
}
|
||||
qDebug("Removing all item from feed");
|
||||
removeAllItems();
|
||||
qDebug("All items were removed");
|
||||
if(QFile::exists(filePath))
|
||||
misc::safeRemove(filePath);
|
||||
|
@ -83,12 +81,6 @@ void RssFeed::refresh() {
|
|||
parent->refreshStream(url);
|
||||
}
|
||||
|
||||
// delete all the items saved
|
||||
void RssFeed::removeAllItems() {
|
||||
qDeleteAll(this->values());
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void RssFeed::removeAllSettings() {
|
||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
||||
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;
|
||||
}
|
||||
|
||||
RssArticle* RssFeed::getItem(QString id) const{
|
||||
return this->value(id);
|
||||
RssArticle& RssFeed::getItem(QString id) {
|
||||
return (*this)[id];
|
||||
}
|
||||
|
||||
unsigned int RssFeed::getNbNews() const{
|
||||
|
@ -181,29 +173,30 @@ unsigned int RssFeed::getNbNews() const{
|
|||
}
|
||||
|
||||
void RssFeed::markAllAsRead() {
|
||||
foreach(RssArticle *item, this->values()){
|
||||
item->markAsRead();
|
||||
QHash<QString, RssArticle>::iterator it;
|
||||
for(it = this->begin(); it != this->end(); it++) {
|
||||
it.value().markAsRead();
|
||||
}
|
||||
RssManager::instance()->forwardFeedInfosChanged(url, getName(), 0);
|
||||
}
|
||||
|
||||
unsigned int RssFeed::getNbUnRead() const{
|
||||
unsigned int nbUnread=0;
|
||||
foreach(RssArticle *item, this->values()) {
|
||||
if(!item->isRead())
|
||||
foreach(const RssArticle &item, this->values()) {
|
||||
if(!item.isRead())
|
||||
++nbUnread;
|
||||
}
|
||||
return nbUnread;
|
||||
}
|
||||
|
||||
QList<RssArticle*> RssFeed::getNewsList() const{
|
||||
QList<RssArticle> RssFeed::getNewsList() const{
|
||||
return this->values();
|
||||
}
|
||||
|
||||
QList<RssArticle*> RssFeed::getUnreadNewsList() const {
|
||||
QList<RssArticle*> unread_news;
|
||||
foreach(RssArticle *item, this->values()) {
|
||||
if(!item->isRead())
|
||||
QList<RssArticle> RssFeed::getUnreadNewsList() const {
|
||||
QList<RssArticle> unread_news;
|
||||
foreach(const RssArticle &item, this->values()) {
|
||||
if(!item.isRead())
|
||||
unread_news << item;
|
||||
}
|
||||
return unread_news;
|
||||
|
@ -272,11 +265,9 @@ short RssFeed::readDoc(QIODevice* device) {
|
|||
image = xml.attributes().value("url").toString();
|
||||
}
|
||||
else if(xml.name() == "item") {
|
||||
RssArticle * item = new RssArticle(this, xml);
|
||||
if(item->isValid() && !itemAlreadyExists(item->guid())) {
|
||||
this->insert(item->guid(), item);
|
||||
} else {
|
||||
delete item;
|
||||
RssArticle item(this, xml);
|
||||
if(item.isValid() && !itemAlreadyExists(item.guid())) {
|
||||
this->insert(item.guid(), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -289,21 +280,23 @@ short RssFeed::readDoc(QIODevice* device) {
|
|||
|
||||
// RSS Feed Downloader
|
||||
if(RssSettings().isRssDownloadingEnabled()) {
|
||||
foreach(RssArticle* item, values()) {
|
||||
if(item->isRead()) continue;
|
||||
QHash<QString, RssArticle>::iterator it;
|
||||
for(it = this->begin(); it != this->end(); it++) {
|
||||
RssArticle &item = it.value();
|
||||
if(item.isRead()) continue;
|
||||
QString torrent_url;
|
||||
if(item->hasAttachment())
|
||||
torrent_url = item->torrentUrl();
|
||||
if(item.hasAttachment())
|
||||
torrent_url = item.torrentUrl();
|
||||
else
|
||||
torrent_url = item->link();
|
||||
torrent_url = item.link();
|
||||
// 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()) {
|
||||
// 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());
|
||||
// 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 nb_articles = this->size();
|
||||
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;
|
||||
for(int i=0; i<excess; ++i){
|
||||
RssArticle *lastItem = listItem.takeLast();
|
||||
delete this->take(lastItem->guid());
|
||||
for(uint i=nb_articles-excess; i<nb_articles; ++i){
|
||||
this->remove(listItem.at(i).guid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue