mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-30 08:24:22 +00:00
- 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
This commit is contained in:
parent
1f8b9378a3
commit
eebdc26e5a
2
TODO
2
TODO
@ -101,6 +101,8 @@ beta6->beta7 changelog:
|
|||||||
- FEATURE: Added "Mark all as read" function for RSS feeds
|
- FEATURE: Added "Mark all as read" function for RSS feeds
|
||||||
- FEATURE: Added some RSS settings in program preferences
|
- FEATURE: Added some RSS settings in program preferences
|
||||||
- FEATURE: Display RSS article date and author if available
|
- 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: In torrent content, it is now easier to filter all torrents using right click menu
|
||||||
- BUGFIX: Updated man page / README / INSTALL
|
- BUGFIX: Updated man page / README / INSTALL
|
||||||
- BUGFIX: Paused torrents could be displayed as connected for a sec after checking
|
- BUGFIX: Paused torrents could be displayed as connected for a sec after checking
|
||||||
|
66
src/rss.h
66
src/rss.h
@ -33,6 +33,7 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "downloadThread.h"
|
#include "downloadThread.h"
|
||||||
@ -79,6 +80,7 @@ class RssItem : public QObject {
|
|||||||
QString image;
|
QString image;
|
||||||
QString author;
|
QString author;
|
||||||
QDateTime date;
|
QDateTime date;
|
||||||
|
QString hash;
|
||||||
bool read;
|
bool read;
|
||||||
QString downloadLink;
|
QString downloadLink;
|
||||||
|
|
||||||
@ -233,6 +235,7 @@ class RssItem : public QObject {
|
|||||||
author = property.text();
|
author = property.text();
|
||||||
property = property.nextSibling().toElement();
|
property = property.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
|
hash = QCryptographicHash::hash(QByteArray(title.toUtf8())+QByteArray(description.toUtf8()), QCryptographicHash::Md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RssItem(){
|
~RssItem(){
|
||||||
@ -250,6 +253,10 @@ class RssItem : public QObject {
|
|||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getHash() const {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
QString getDescription() const{
|
QString getDescription() const{
|
||||||
if(description.isEmpty())
|
if(description.isEmpty())
|
||||||
return tr("No description available");
|
return tr("No description available");
|
||||||
@ -331,6 +338,14 @@ class RssStream : public QObject{
|
|||||||
listItem.clear();
|
listItem.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool itemAlreadyExists(QString hash) {
|
||||||
|
RssItem * item;
|
||||||
|
foreach(item, listItem) {
|
||||||
|
if(item->getHash() == hash) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void setLoading(bool val) {
|
void setLoading(bool val) {
|
||||||
currently_loading = val;
|
currently_loading = val;
|
||||||
}
|
}
|
||||||
@ -446,9 +461,6 @@ class RssStream : public QObject{
|
|||||||
// TODO: Read only news more recent than last refresh
|
// TODO: Read only news more recent than last refresh
|
||||||
// read and create items from a rss document
|
// read and create items from a rss document
|
||||||
short readDoc(const QDomDocument& doc) {
|
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 ?
|
// is it a rss file ?
|
||||||
QDomElement root = doc.documentElement();
|
QDomElement root = doc.documentElement();
|
||||||
if(root.tagName() == QString::fromUtf8("html")){
|
if(root.tagName() == QString::fromUtf8("html")){
|
||||||
@ -461,10 +473,6 @@ class RssStream : public QObject{
|
|||||||
}
|
}
|
||||||
QDomNode rss = root.firstChild();
|
QDomNode rss = root.firstChild();
|
||||||
QDomElement channel = root.firstChild().toElement();
|
QDomElement channel = root.firstChild().toElement();
|
||||||
// unsigned short listsize = getNbNews();
|
|
||||||
// for(unsigned short i=0; i<listsize; ++i) {
|
|
||||||
// listItem.removeLast();
|
|
||||||
// }
|
|
||||||
|
|
||||||
while(!channel.isNull()) {
|
while(!channel.isNull()) {
|
||||||
// we are reading the rss'main info
|
// we are reading the rss'main info
|
||||||
@ -483,36 +491,46 @@ class RssStream : public QObject{
|
|||||||
else if (property.tagName() == "image")
|
else if (property.tagName() == "image")
|
||||||
image = property.text();
|
image = property.text();
|
||||||
else if(property.tagName() == "item") {
|
else if(property.tagName() == "item") {
|
||||||
if(getNbNews() < max_articles) {
|
RssItem * item = new RssItem(property);
|
||||||
listItem.append(new RssItem(property));
|
if(!itemAlreadyExists(item->getHash()))
|
||||||
}
|
listItem.append(item);
|
||||||
}
|
}
|
||||||
property = property.nextSibling().toElement();
|
property = property.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channel = channel.nextSibling().toElement();
|
channel = channel.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
|
sortList();
|
||||||
|
resizeList();
|
||||||
return 0;
|
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<RssItem*> &list, RssItem *item) {
|
||||||
|
int i = 0;
|
||||||
|
while(i < list.size() && item->getDate() < list.at(i)->getDate()) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
list.insert(i, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sortList() {
|
||||||
|
QList<RssItem*> 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() {
|
void resizeList() {
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
unsigned int max_articles = settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt();
|
unsigned int max_articles = settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt();
|
||||||
unsigned short lastindex = 0;
|
int excess = listItem.size() - max_articles;
|
||||||
QString firstTitle = getItem(0)->getTitle();
|
if(excess <= 0) return;
|
||||||
unsigned short listsize = getNbNews();
|
for(int i=0; i<excess; ++i){
|
||||||
for(unsigned short i=0; i<listsize; ++i) {
|
listItem.removeLast();
|
||||||
if(getItem(i)->getTitle() == firstTitle)
|
|
||||||
lastindex = i;
|
|
||||||
}
|
}
|
||||||
for(unsigned short i=0; i<lastindex; ++i) {
|
|
||||||
listItem.removeFirst();
|
|
||||||
}
|
|
||||||
while(getNbNews() > max_articles) {
|
|
||||||
listItem.removeLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// existing and opening test after download
|
// existing and opening test after download
|
||||||
|
Loading…
x
Reference in New Issue
Block a user