mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
rss : bug fixes and refresh algorithm improved and better use of
signals&memory
This commit is contained in:
parent
cf2bc1e980
commit
77b998c438
3 changed files with 81 additions and 54 deletions
100
src/rss.h
100
src/rss.h
|
@ -22,9 +22,12 @@
|
||||||
#ifndef RSS_H
|
#ifndef RSS_H
|
||||||
#define RSS_H
|
#define RSS_H
|
||||||
|
|
||||||
#define STREAM_MAX_ITEM 15
|
// MAX ITEM A STREAM
|
||||||
|
#define STREAM_MAX_ITEM 18
|
||||||
// FIXME: not used yet
|
// FIXME: not used yet
|
||||||
#define GLOBAL_MAX_ITEM 150
|
#define GLOBAL_MAX_ITEM 150
|
||||||
|
// avoid crash if too many refresh
|
||||||
|
#define REFRESH_FREQ_MAX 5000
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
@ -32,11 +35,14 @@
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
|
#include <QTime>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "downloadThread.h"
|
#include "downloadThread.h"
|
||||||
|
|
||||||
|
class RssManager;
|
||||||
class RssStream;
|
class RssStream;
|
||||||
|
class RssItem;
|
||||||
|
|
||||||
// Item of a rss stream, single information
|
// Item of a rss stream, single information
|
||||||
class RssItem{
|
class RssItem{
|
||||||
|
@ -47,14 +53,12 @@ class RssItem{
|
||||||
QString description;
|
QString description;
|
||||||
QString image;
|
QString image;
|
||||||
bool read;
|
bool read;
|
||||||
RssStream* parent;
|
|
||||||
QString downloadLink;
|
QString downloadLink;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// public constructor
|
// public constructor
|
||||||
RssItem(const QDomElement& properties, RssStream* _parent){
|
RssItem(const QDomElement& properties){
|
||||||
read = false;
|
read = false;
|
||||||
parent = _parent;
|
|
||||||
downloadLink = "none";
|
downloadLink = "none";
|
||||||
QDomElement property = properties.firstChild().toElement();
|
QDomElement property = properties.firstChild().toElement();
|
||||||
while(!property.isNull()) {
|
while(!property.isNull()) {
|
||||||
|
@ -68,7 +72,6 @@ class RssItem{
|
||||||
image = property.text();
|
image = property.text();
|
||||||
property = property.nextSibling().toElement();
|
property = property.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
//displayItem();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~RssItem(){
|
~RssItem(){
|
||||||
|
@ -101,14 +104,6 @@ class RssItem{
|
||||||
void setRead(){
|
void setRead(){
|
||||||
read = true;
|
read = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RssStream* getParent() const{
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void displayItem(){
|
|
||||||
qDebug(" - "+title.toUtf8()+" - "+link.toUtf8());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Rss stream, loaded form an xml file
|
// Rss stream, loaded form an xml file
|
||||||
|
@ -125,6 +120,10 @@ class RssStream : public QObject{
|
||||||
QString filePath;
|
QString filePath;
|
||||||
QList<RssItem*> listItem;
|
QList<RssItem*> listItem;
|
||||||
downloadThread* downloader;
|
downloadThread* downloader;
|
||||||
|
QTime lastRefresh;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void refreshFinished(const QString& msg);
|
||||||
|
|
||||||
public slots :
|
public slots :
|
||||||
// read and store the downloaded rss' informations
|
// read and store the downloaded rss' informations
|
||||||
|
@ -143,6 +142,7 @@ class RssStream : public QObject{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
openRss();
|
openRss();
|
||||||
|
emit refreshFinished("plop");
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -152,6 +152,7 @@ class RssStream : public QObject{
|
||||||
downloader = new downloadThread(this);
|
downloader = new downloadThread(this);
|
||||||
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
|
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
|
||||||
downloader->downloadUrl(url);
|
downloader->downloadUrl(url);
|
||||||
|
lastRefresh.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
~RssStream(){
|
~RssStream(){
|
||||||
|
@ -169,6 +170,12 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
|
||||||
|
downloader->downloadUrl(url);
|
||||||
|
lastRefresh.start();
|
||||||
|
}
|
||||||
|
|
||||||
QString getTitle() const{
|
QString getTitle() const{
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
@ -214,12 +221,8 @@ class RssStream : public QObject{
|
||||||
return listItem;
|
return listItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayStream(){
|
int getLastRefreshElapsed() const{
|
||||||
qDebug(" # "+getTitle().toUtf8()+" - "+getUrl().toUtf8()+" - "+getAlias().toUtf8());
|
return lastRefresh.elapsed();
|
||||||
unsigned int listItemSize = listItem.size();
|
|
||||||
for(unsigned int i=0; i<listItemSize; ++i){
|
|
||||||
getItem(i)->displayItem();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -236,6 +239,7 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
QDomNode rss = root.firstChild();
|
QDomNode rss = root.firstChild();
|
||||||
QDomElement channel = root.firstChild().toElement();
|
QDomElement channel = root.firstChild().toElement();
|
||||||
|
|
||||||
while(!channel.isNull()) {
|
while(!channel.isNull()) {
|
||||||
// we are reading the rss'main info
|
// we are reading the rss'main info
|
||||||
if (channel.tagName() == "channel") {
|
if (channel.tagName() == "channel") {
|
||||||
|
@ -253,10 +257,10 @@ 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(getListSize() < STREAM_MAX_ITEM) {
|
if(getListSize() < 3*STREAM_MAX_ITEM) {
|
||||||
//TODO: find a way to break here
|
//TODO: find a way to break here
|
||||||
//add it to a list
|
//add it to a list
|
||||||
listItem.append(new RssItem(property, this));
|
listItem.append(new RssItem(property));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property = property.nextSibling().toElement();
|
property = property.nextSibling().toElement();
|
||||||
|
@ -264,9 +268,28 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
channel = channel.nextSibling().toElement();
|
channel = channel.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
|
// resize stream listItem
|
||||||
|
resizeList();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resizeList() {
|
||||||
|
unsigned short lastindex = 0;
|
||||||
|
QString firstTitle = getItem(0)->getTitle();
|
||||||
|
unsigned short listsize = getListSize();
|
||||||
|
for(unsigned short i=0; i<listsize; i++) {
|
||||||
|
if(getItem(i)->getTitle() == firstTitle)
|
||||||
|
lastindex = i;
|
||||||
|
}
|
||||||
|
for(unsigned short i=0; i<lastindex; i++) {
|
||||||
|
listItem.removeFirst();
|
||||||
|
}
|
||||||
|
while(getListSize()>STREAM_MAX_ITEM) {
|
||||||
|
listItem.removeLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// existing and opening test after download
|
// existing and opening test after download
|
||||||
short openRss(){
|
short openRss(){
|
||||||
QDomDocument doc("Rss Seed");
|
QDomDocument doc("Rss Seed");
|
||||||
|
@ -297,13 +320,24 @@ class RssStream : public QObject{
|
||||||
};
|
};
|
||||||
|
|
||||||
// global class, manage the whole rss stream
|
// global class, manage the whole rss stream
|
||||||
class RssManager{
|
class RssManager : public QObject{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
private :
|
private :
|
||||||
QList<RssStream*> streamList;
|
QList<RssStream*> streamList;
|
||||||
QStringList streamListUrl;
|
QStringList streamListUrl;
|
||||||
QStringList streamListAlias;
|
QStringList streamListAlias;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void streamNeedRefresh();
|
||||||
|
|
||||||
|
public slots :
|
||||||
|
// read and store the downloaded rss' informations
|
||||||
|
void refreshFinished(const QString&) {
|
||||||
|
|
||||||
|
qDebug("*******************************************************");
|
||||||
|
}
|
||||||
|
|
||||||
public :
|
public :
|
||||||
RssManager(){
|
RssManager(){
|
||||||
loadStreamList();
|
loadStreamList();
|
||||||
|
@ -331,6 +365,7 @@ class RssManager{
|
||||||
RssStream *stream = new RssStream(streamListUrl.at(i));
|
RssStream *stream = new RssStream(streamListUrl.at(i));
|
||||||
stream->setAlias(streamListAlias.at(i));
|
stream->setAlias(streamListAlias.at(i));
|
||||||
streamList.append(stream);
|
streamList.append(stream);
|
||||||
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +384,7 @@ class RssManager{
|
||||||
streamList.append(stream);
|
streamList.append(stream);
|
||||||
streamListUrl.append(stream->getUrl());
|
streamListUrl.append(stream->getUrl());
|
||||||
streamListAlias.append(stream->getUrl());
|
streamListAlias.append(stream->getUrl());
|
||||||
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh()));
|
||||||
}else{
|
}else{
|
||||||
qDebug("Not adding the Rss stream because it is already in the list");
|
qDebug("Not adding the Rss stream because it is already in the list");
|
||||||
}
|
}
|
||||||
|
@ -410,15 +446,20 @@ class RssManager{
|
||||||
RssStream *stream = new RssStream(streamListUrl.at(i));
|
RssStream *stream = new RssStream(streamListUrl.at(i));
|
||||||
stream->setAlias(streamListAlias.at(i));
|
stream->setAlias(streamListAlias.at(i));
|
||||||
streamList.append(stream);
|
streamList.append(stream);
|
||||||
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh(int index) {
|
void refresh(int index) {
|
||||||
if(index>=0 && index<getNbStream()) {
|
if(index>=0 && index<getNbStream()) {
|
||||||
delete getStream(index);
|
if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) {
|
||||||
RssStream *stream = new RssStream(streamListUrl.at(index));
|
//delete getStream(index);
|
||||||
stream->setAlias(streamListAlias.at(index));
|
//RssStream *stream = new RssStream(streamListUrl.at(index));
|
||||||
streamList.replace(index, stream);
|
//stream->setAlias(streamListAlias.at(index));
|
||||||
|
//streamList.replace(index, stream);
|
||||||
|
getStream(index)->refresh();
|
||||||
|
connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,13 +476,6 @@ class RssManager{
|
||||||
return streamList.at(index);
|
return streamList.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayManager(){
|
|
||||||
unsigned int streamListSize = streamList.size();
|
|
||||||
for(unsigned int i=0; i<streamListSize; ++i){
|
|
||||||
getStream(i)->displayStream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int getNbStream() {
|
int getNbStream() {
|
||||||
return streamList.size();
|
return streamList.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,25 +114,21 @@
|
||||||
|
|
||||||
//right-clik on stream : refresh it
|
//right-clik on stream : refresh it
|
||||||
void RSSImp::refreshStream() {
|
void RSSImp::refreshStream() {
|
||||||
if(rssmanager.getNbStream()>0 && lastRefresh.elapsed()>REFRESH_FREQ_MAX) {
|
|
||||||
int index = listStreams->currentRow();
|
int index = listStreams->currentRow();
|
||||||
|
if(rssmanager.getNbStream()>0) {
|
||||||
textBrowser->clear();
|
textBrowser->clear();
|
||||||
listNews->clear();
|
listNews->clear();
|
||||||
rssmanager.refresh(index);
|
rssmanager.refresh(index);
|
||||||
refreshStreamList();
|
refreshStreamList();
|
||||||
lastRefresh.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//right-click somewhere, refresh all the streams
|
//right-click somewhere, refresh all the streams
|
||||||
void RSSImp::refreshAllStreams() {
|
void RSSImp::refreshAllStreams() {
|
||||||
if(lastRefresh.elapsed()>REFRESH_FREQ_MAX) {
|
|
||||||
textBrowser->clear();
|
textBrowser->clear();
|
||||||
listNews->clear();
|
listNews->clear();
|
||||||
rssmanager.refreshAll();
|
rssmanager.refreshAll();
|
||||||
refreshStreamList();
|
refreshStreamList();
|
||||||
lastRefresh.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//right-click, register a new stream
|
//right-click, register a new stream
|
||||||
|
@ -180,7 +176,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the number of news for each stream
|
// show the number of news for each stream
|
||||||
void RSSImp::updateStreamNbNews() {
|
void RSSImp::updateStreamsName() {
|
||||||
for(int i=0; i<rssmanager.getNbStream(); i++) {
|
for(int i=0; i<rssmanager.getNbStream(); i++) {
|
||||||
listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")");
|
listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")");
|
||||||
}
|
}
|
||||||
|
@ -200,9 +196,11 @@
|
||||||
refreshStreamList();
|
refreshStreamList();
|
||||||
refreshTextBrowser();
|
refreshTextBrowser();
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(updateStreamNbNews()));
|
//connect(timer, SIGNAL(timeout()), this, SLOT(updateStreamsName()));
|
||||||
timer->start(5000);
|
timer->start(5000);
|
||||||
lastRefresh.start();
|
//for(int i=0; i<rssmanager.getNbStream(); i++) {
|
||||||
|
//connect(rssmanager, SIGNAL(streamNeedRefresh()), this, SLOT(updateStreamsName()));
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
RSSImp::~RSSImp(){
|
RSSImp::~RSSImp(){
|
||||||
|
|
|
@ -21,11 +21,7 @@
|
||||||
#ifndef __RSS_IMP_H__
|
#ifndef __RSS_IMP_H__
|
||||||
#define __RSS_IMP_H__
|
#define __RSS_IMP_H__
|
||||||
|
|
||||||
// avoid crash if too many refresh
|
|
||||||
#define REFRESH_FREQ_MAX 5000
|
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTime>
|
|
||||||
#include "ui_rss.h"
|
#include "ui_rss.h"
|
||||||
#include "rss.h"
|
#include "rss.h"
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
@ -36,7 +32,6 @@ class RSSImp : public QWidget, public Ui::RSS{
|
||||||
private:
|
private:
|
||||||
RssManager rssmanager;
|
RssManager rssmanager;
|
||||||
QTimer* timer;
|
QTimer* timer;
|
||||||
QTime lastRefresh;
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_addStream_button_clicked();
|
void on_addStream_button_clicked();
|
||||||
|
@ -50,7 +45,7 @@ class RSSImp : public QWidget, public Ui::RSS{
|
||||||
void renameStream();
|
void renameStream();
|
||||||
void refreshStream();
|
void refreshStream();
|
||||||
void createStream();
|
void createStream();
|
||||||
void updateStreamNbNews();
|
void updateStreamsName();
|
||||||
void refreshAllStreams();
|
void refreshAllStreams();
|
||||||
void refreshStreamList();
|
void refreshStreamList();
|
||||||
void refreshNewsList();
|
void refreshNewsList();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue