diff --git a/TODO b/TODO index 2fd5f1540..f917c2872 100644 --- a/TODO +++ b/TODO @@ -101,6 +101,8 @@ beta6->beta7 changelog: - FEATURE: Added "Mark all as read" function for RSS feeds - FEATURE: Added some RSS settings in program preferences - FEATURE: Display RSS article date and author if available +- FEATURE: Articles in a RSS feed are now ordered by date (newer at the top) +- FEATURE: Read articles in a feed are not resetted when the feed is refreshed anymore - BUGFIX: In torrent content, it is now easier to filter all torrents using right click menu - BUGFIX: Updated man page / README / INSTALL - BUGFIX: Paused torrents could be displayed as connected for a sec after checking diff --git a/src/rss.h b/src/rss.h index 452f1c5f5..b54e4531c 100644 --- a/src/rss.h +++ b/src/rss.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "misc.h" #include "downloadThread.h" @@ -79,6 +80,7 @@ class RssItem : public QObject { QString image; QString author; QDateTime date; + QString hash; bool read; QString downloadLink; @@ -233,6 +235,7 @@ class RssItem : public QObject { author = property.text(); property = property.nextSibling().toElement(); } + hash = QCryptographicHash::hash(QByteArray(title.toUtf8())+QByteArray(description.toUtf8()), QCryptographicHash::Md5); } ~RssItem(){ @@ -250,6 +253,10 @@ class RssItem : public QObject { return link; } + QString getHash() const { + return hash; + } + QString getDescription() const{ if(description.isEmpty()) return tr("No description available"); @@ -331,6 +338,14 @@ class RssStream : public QObject{ listItem.clear(); } + bool itemAlreadyExists(QString hash) { + RssItem * item; + foreach(item, listItem) { + if(item->getHash() == hash) return true; + } + return false; + } + void setLoading(bool val) { currently_loading = val; } @@ -446,9 +461,6 @@ class RssStream : public QObject{ // TODO: Read only news more recent than last refresh // read and create items from a rss document short readDoc(const QDomDocument& doc) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - unsigned int max_articles = settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt(); - qDebug("Reading %d articles max in xml file", max_articles); // is it a rss file ? QDomElement root = doc.documentElement(); if(root.tagName() == QString::fromUtf8("html")){ @@ -461,10 +473,6 @@ class RssStream : public QObject{ } QDomNode rss = root.firstChild(); QDomElement channel = root.firstChild().toElement(); -// unsigned short listsize = getNbNews(); -// for(unsigned short i=0; igetHash())) + listItem.append(item); } property = property.nextSibling().toElement(); } } channel = channel.nextSibling().toElement(); } + sortList(); + resizeList(); return 0; } - // not actually used, it is used to resize the list of item AFTER the update, instead of delete it BEFORE, some troubles + static void insertSortElem(QList &list, RssItem *item) { + int i = 0; + while(i < list.size() && item->getDate() < list.at(i)->getDate()) { + ++i; + } + list.insert(i, item); + } + + void sortList() { + QList new_list; + RssItem *item; + foreach(item, listItem) { + insertSortElem(new_list, item); + } + listItem = new_list; + } + + // not actually used, it is used to resize the list of item AFTER the update, instead of delete it BEFORE void resizeList() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); unsigned int max_articles = settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt(); - unsigned short lastindex = 0; - QString firstTitle = getItem(0)->getTitle(); - unsigned short listsize = getNbNews(); - for(unsigned short i=0; igetTitle() == firstTitle) - lastindex = i; + int excess = listItem.size() - max_articles; + if(excess <= 0) return; + for(int i=0; i max_articles) { - listItem.removeLast(); - } - } // existing and opening test after download