Browse Source

- Fix several bugs in RSS plugin

* RSS downloader takes into consideration maximum number of articles per feed
  * Fix possible issue with RSS folder deletion
  * Clear persistant data whenever a RSS feed is deleted
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
af1b06c5be
  1. 10
      src/feedList.h
  2. 50
      src/rss.cpp
  3. 16
      src/rss.h
  4. 2
      src/rss_imp.cpp

10
src/feedList.h

@ -47,10 +47,16 @@ public: @@ -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<RssStream*> feeds = ((RssFolder*)file)->getAllFeeds();
foreach(RssStream* feed, feeds) {
feeds_items.remove(feed->getID());
}
}
}
bool hasFeed(QString url) const {

50
src/rss.cpp

@ -90,8 +90,12 @@ void RssFolder::refreshAll(){ @@ -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() { @@ -427,6 +431,20 @@ void RssStream::removeAllItems() {
this->clear();
}
void RssStream::removeAllSettings() {
QSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash();
if(feeds_w_downloader.contains(url)) {
feeds_w_downloader.remove(url);
qBTRSS.setValue("downloader_on", feeds_w_downloader);
}
QHash<QString, QVariant> all_feeds_filters = qBTRSS.value("feed_filters", QHash<QString, QVariant>()).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,15 +597,26 @@ short RssStream::readDoc(const QDomDocument& doc) { @@ -579,15 +597,26 @@ short RssStream::readDoc(const QDomDocument& doc) {
(*this)[title] = item;
} else {
delete item;
item = this->value(title);
}
} else {
delete item;
}
}
property = property.nextSibling().toElement();
}
}
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
if(!already_exists || !(*this)[item->getTitle()]->isRead()) {
FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle());
if(matching_filter != 0) {
// Download the torrent
@ -603,22 +632,11 @@ short RssStream::readDoc(const QDomDocument& doc) { @@ -603,22 +632,11 @@ short RssStream::readDoc(const QDomDocument& doc) {
BTSession->downloadUrlAndSkipDialog(torrent_url);
}
// Item was downloaded, consider it as Read
(*this)[item->getTitle()]->setRead();
item->setRead();
// Clean up
delete matching_filter;
}
}
} else {
delete item;
}
}
property = property.nextSibling().toElement();
}
}
channel = channel.nextSibling().toElement();
}
resizeList();
return 0;
}

16
src/rss.h

@ -97,11 +97,13 @@ public: @@ -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<RssItem*> getNewsList() const = 0;
virtual QList<RssItem*> getUnreadNewsList() const = 0;
QStringList getPath() const {
@ -408,6 +410,7 @@ public: @@ -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: @@ -464,6 +467,19 @@ public:
bool hasChild(QString ID) { return this->contains(ID); }
QList<RssItem*> getNewsList() const;
QList<RssItem*> 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();

2
src/rss_imp.cpp

@ -219,7 +219,7 @@ void RSSImp::deleteSelectedItems() { @@ -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;

Loading…
Cancel
Save