diff --git a/src/feedList.h b/src/feedList.h index 8e6daee89..bbb79677f 100644 --- a/src/feedList.h +++ b/src/feedList.h @@ -47,10 +47,16 @@ public: } } - void itemRemoved(QTreeWidgetItem *item) { + void itemAboutToBeRemoved(QTreeWidgetItem *item) { RssFile* file = mapping.take(item); - if(file->getType() == RssFile::STREAM) + if(file->getType() == RssFile::STREAM) { feeds_items.remove(file->getID()); + } else { + QList feeds = ((RssFolder*)file)->getAllFeeds(); + foreach(RssStream* feed, feeds) { + feeds_items.remove(feed->getID()); + } + } } bool hasFeed(QString url) const { diff --git a/src/rss.cpp b/src/rss.cpp index 9b2b6fd92..1817df79e 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -90,8 +90,12 @@ void RssFolder::refreshAll(){ } void RssFolder::removeFile(QString ID) { - if(this->contains(ID)) - delete this->take(ID); + if(this->contains(ID)) { + RssFile* child = this->take(ID); + child->removeAllSettings(); + child->removeAllItems(); + delete child; + } } RssFolder* RssFolder::addFolder(QString name) { @@ -427,6 +431,20 @@ void RssStream::removeAllItems() { this->clear(); } +void RssStream::removeAllSettings() { + QSettings qBTRSS("qBittorrent", "qBittorrent-rss"); + QHash feeds_w_downloader = qBTRSS.value("downloader_on", QHash()).toHash(); + if(feeds_w_downloader.contains(url)) { + feeds_w_downloader.remove(url); + qBTRSS.setValue("downloader_on", feeds_w_downloader); + } + QHash all_feeds_filters = qBTRSS.value("feed_filters", QHash()).toHash(); + if(all_feeds_filters.contains(url)) { + all_feeds_filters.remove(url); + qBTRSS.setValue("feed_filters", all_feeds_filters); + } +} + bool RssStream::itemAlreadyExists(QString name) { return this->contains(name); } @@ -579,36 +597,7 @@ short RssStream::readDoc(const QDomDocument& doc) { (*this)[title] = item; } else { delete item; - item = this->value(title); } - QString torrent_url; - if(item->has_attachment()) - torrent_url = item->getTorrentUrl(); - else - torrent_url = item->getLink(); - // Check if the item should be automatically downloaded - if(!already_exists || !(*this)[item->getTitle()]->isRead()) { - FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle()); - if(matching_filter != 0) { - // Download the torrent - BTSession->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->getTitle()).arg(getName())); - if(matching_filter->isValid()) { - QString save_path = matching_filter->getSavePath(); - if(save_path.isEmpty()) - BTSession->downloadUrlAndSkipDialog(torrent_url); - else - BTSession->downloadUrlAndSkipDialog(torrent_url, save_path); - } else { - // All torrents are downloaded from this feed - BTSession->downloadUrlAndSkipDialog(torrent_url); - } - // Item was downloaded, consider it as Read - (*this)[item->getTitle()]->setRead(); - // Clean up - delete matching_filter; - } - } - } else { delete item; } @@ -619,6 +608,35 @@ short RssStream::readDoc(const QDomDocument& doc) { channel = channel.nextSibling().toElement(); } resizeList(); + // RSS Feed Downloader + foreach(RssItem* item, values()) { + if(item->isRead()) continue; + QString torrent_url; + if(item->has_attachment()) + torrent_url = item->getTorrentUrl(); + else + torrent_url = item->getLink(); + // Check if the item should be automatically downloaded + FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle()); + if(matching_filter != 0) { + // Download the torrent + BTSession->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->getTitle()).arg(getName())); + if(matching_filter->isValid()) { + QString save_path = matching_filter->getSavePath(); + if(save_path.isEmpty()) + BTSession->downloadUrlAndSkipDialog(torrent_url); + else + BTSession->downloadUrlAndSkipDialog(torrent_url, save_path); + } else { + // All torrents are downloaded from this feed + BTSession->downloadUrlAndSkipDialog(torrent_url); + } + // Item was downloaded, consider it as Read + item->setRead(); + // Clean up + delete matching_filter; + } + } return 0; } diff --git a/src/rss.h b/src/rss.h index 4770f6049..163b7afc5 100644 --- a/src/rss.h +++ b/src/rss.h @@ -97,11 +97,13 @@ public: virtual FileType getType() const = 0; virtual QString getName() const = 0; virtual QString getID() const = 0; + virtual void removeAllItems() = 0; virtual void rename(QString new_name) = 0; virtual void markAllAsRead() = 0; virtual RssFolder* getParent() const = 0; virtual void setParent(RssFolder*) = 0; virtual void refresh() = 0; + virtual void removeAllSettings() = 0; virtual QList getNewsList() const = 0; virtual QList getUnreadNewsList() const = 0; QStringList getPath() const { @@ -225,11 +227,11 @@ protected: negOffset = true; // military zone: RFC 2822 treats as '-0000' else if (zone != "UT" && zone != "GMT") { // treated as '+0000' offset = (zone == "EDT") ? -4*3600 - : (zone == "EST" || zone == "CDT") ? -5*3600 - : (zone == "CST" || zone == "MDT") ? -6*3600 - : (zone == "MST" || zone == "PDT") ? -7*3600 - : (zone == "PST") ? -8*3600 - : 0; + : (zone == "EST" || zone == "CDT") ? -5*3600 + : (zone == "CST" || zone == "MDT") ? -6*3600 + : (zone == "MST" || zone == "PDT") ? -7*3600 + : (zone == "PST") ? -8*3600 + : 0; if (!offset) { // Check for any other alphabetic time zone bool nonalpha = false; @@ -408,6 +410,7 @@ public: void refresh(); QString getID() const { return url; } void removeAllItems(); + void removeAllSettings(); bool itemAlreadyExists(QString hash); void setLoading(bool val); bool isLoading(); @@ -464,6 +467,19 @@ public: bool hasChild(QString ID) { return this->contains(ID); } QList getNewsList() const; QList getUnreadNewsList() const; + void removeAllSettings() { + foreach(RssFile* child, values()) { + child->removeAllSettings(); + } + } + + void removeAllItems() { + foreach(RssFile* child, values()) { + child->removeAllItems(); + } + qDeleteAll(values()); + clear(); + } public slots: void refreshAll(); diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index c93fe010d..967ab6d28 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -219,7 +219,7 @@ void RSSImp::deleteSelectedItems() { } RssFile *rss_item = listStreams->getRSSItem(item); // Notify TreeWidget - listStreams->itemRemoved(item); + listStreams->itemAboutToBeRemoved(item); // Actually delete the item rss_item->getParent()->removeFile(rss_item->getID()); delete item;