mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-09 06:17:58 +00:00
rss : bugs fixes, better refresh
This commit is contained in:
parent
eb85389c0a
commit
66201a2853
52
src/rss.h
52
src/rss.h
@ -142,7 +142,7 @@ class RssStream : public QObject{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
openRss();
|
openRss();
|
||||||
emit refreshFinished("plop");
|
emit refreshFinished(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -226,6 +226,7 @@ class RssStream : public QObject{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// read and create items from a rss document
|
||||||
short read(const QDomDocument& doc) {
|
short read(const QDomDocument& doc) {
|
||||||
// is it a rss file ?
|
// is it a rss file ?
|
||||||
QDomElement root = doc.documentElement();
|
QDomElement root = doc.documentElement();
|
||||||
@ -239,7 +240,11 @@ 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 = getListSize();
|
||||||
|
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
|
||||||
if (channel.tagName() == "channel") {
|
if (channel.tagName() == "channel") {
|
||||||
@ -257,9 +262,7 @@ 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() < 3*STREAM_MAX_ITEM) {
|
if(getListSize() < STREAM_MAX_ITEM) {
|
||||||
//TODO: find a way to break here
|
|
||||||
//add it to a list
|
|
||||||
listItem.append(new RssItem(property));
|
listItem.append(new RssItem(property));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,11 +271,10 @@ class RssStream : public QObject{
|
|||||||
}
|
}
|
||||||
channel = channel.nextSibling().toElement();
|
channel = channel.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
// resize stream listItem
|
|
||||||
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
|
||||||
void resizeList() {
|
void resizeList() {
|
||||||
unsigned short lastindex = 0;
|
unsigned short lastindex = 0;
|
||||||
QString firstTitle = getItem(0)->getTitle();
|
QString firstTitle = getItem(0)->getTitle();
|
||||||
@ -285,7 +287,7 @@ class RssStream : public QObject{
|
|||||||
listItem.removeFirst();
|
listItem.removeFirst();
|
||||||
}
|
}
|
||||||
while(getListSize()>STREAM_MAX_ITEM) {
|
while(getListSize()>STREAM_MAX_ITEM) {
|
||||||
listItem.removeLast();
|
listItem.removeAt(STREAM_MAX_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -329,13 +331,11 @@ class RssManager : public QObject{
|
|||||||
QStringList streamListAlias;
|
QStringList streamListAlias;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void streamNeedRefresh();
|
void streamNeedRefresh(const int&);
|
||||||
|
|
||||||
public slots :
|
public slots :
|
||||||
// read and store the downloaded rss' informations
|
void streamNeedRefresh(const QString& _url) {
|
||||||
void refreshFinished(const QString&) {
|
emit(streamNeedRefresh(hasStream(_url)));
|
||||||
|
|
||||||
qDebug("*******************************************************");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public :
|
public :
|
||||||
@ -365,7 +365,7 @@ class RssManager : public QObject{
|
|||||||
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()));
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +384,7 @@ class RssManager : public QObject{
|
|||||||
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()));
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
|
||||||
}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");
|
||||||
}
|
}
|
||||||
@ -402,9 +402,11 @@ class RssManager : public QObject{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(hasStream(url) < 0) {
|
if(hasStream(url) < 0) {
|
||||||
streamList.append(new RssStream(url));
|
RssStream* stream = new RssStream(url);
|
||||||
|
streamList.append(stream);
|
||||||
streamListUrl.append(url);
|
streamListUrl.append(url);
|
||||||
streamListAlias.append(url);
|
streamListAlias.append(url);
|
||||||
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
|
||||||
}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");
|
||||||
}
|
}
|
||||||
@ -435,30 +437,18 @@ class RssManager : public QObject{
|
|||||||
|
|
||||||
// reload all the xml files from the web
|
// reload all the xml files from the web
|
||||||
void refreshAll(){
|
void refreshAll(){
|
||||||
QList<RssStream*> newStreamList;
|
|
||||||
unsigned int streamListSize = streamList.size();
|
|
||||||
for(unsigned int i=0; i<streamListSize; ++i){
|
|
||||||
delete getStream(i);
|
|
||||||
}
|
|
||||||
streamList = newStreamList;
|
|
||||||
unsigned int streamListUrlSize = streamListUrl.size();
|
unsigned int streamListUrlSize = streamListUrl.size();
|
||||||
for(unsigned int i=0; i<streamListUrlSize; ++i){
|
for(unsigned int i=0; i<streamListUrlSize; ++i){
|
||||||
RssStream *stream = new RssStream(streamListUrl.at(i));
|
getStream(i)->refresh();
|
||||||
stream->setAlias(streamListAlias.at(i));
|
connect(getStream(i), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
|
||||||
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()) {
|
||||||
if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) {
|
if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) {
|
||||||
//delete getStream(index);
|
|
||||||
//RssStream *stream = new RssStream(streamListUrl.at(index));
|
|
||||||
//stream->setAlias(streamListAlias.at(index));
|
|
||||||
//streamList.replace(index, stream);
|
|
||||||
getStream(index)->refresh();
|
getStream(index)->refresh();
|
||||||
connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh()));
|
connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,10 +148,14 @@
|
|||||||
void RSSImp::refreshStreamList() {
|
void RSSImp::refreshStreamList() {
|
||||||
int currentStream = listStreams->currentRow();
|
int currentStream = listStreams->currentRow();
|
||||||
listStreams->clear();
|
listStreams->clear();
|
||||||
for(int i=0; i<rssmanager.getNbStream(); i++) {
|
for(unsigned short i=0; i<rssmanager.getNbStream(); i++) {
|
||||||
new QListWidgetItem(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")", listStreams);
|
new QListWidgetItem(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")", listStreams);
|
||||||
}
|
}
|
||||||
listStreams->setCurrentRow(currentStream);
|
listStreams->setCurrentRow(currentStream);
|
||||||
|
if(currentStream>=0) {
|
||||||
|
listNews->clear();
|
||||||
|
refreshNewsList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fills the newsList
|
// fills the newsList
|
||||||
@ -176,9 +180,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// show the number of news for each stream
|
// show the number of news for each stream
|
||||||
void RSSImp::updateStreamsName() {
|
void RSSImp::updateStreamsName(const int& 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()+")");
|
int currentStream = listStreams->currentRow();
|
||||||
|
listStreams->setCurrentRow(currentStream);
|
||||||
|
if(currentStream>=0) {
|
||||||
|
listNews->clear();
|
||||||
|
refreshNewsList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,18 +201,14 @@
|
|||||||
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream()));
|
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream()));
|
||||||
connect(actionCreate, SIGNAL(triggered()), this, SLOT(createStream()));
|
connect(actionCreate, SIGNAL(triggered()), this, SLOT(createStream()));
|
||||||
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
|
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
|
||||||
|
connect(&rssmanager, SIGNAL(streamNeedRefresh(const int&)), this, SLOT(updateStreamsName(const int&)));
|
||||||
refreshStreamList();
|
refreshStreamList();
|
||||||
refreshTextBrowser();
|
refreshTextBrowser();
|
||||||
timer = new QTimer(this);
|
// force the first alias-refresh
|
||||||
//connect(timer, SIGNAL(timeout()), this, SLOT(updateStreamsName()));
|
QTimer::singleShot(10000, this, SLOT(updateStreamsName()));
|
||||||
timer->start(5000);
|
|
||||||
//for(int i=0; i<rssmanager.getNbStream(); i++) {
|
|
||||||
//connect(rssmanager, SIGNAL(streamNeedRefresh()), this, SLOT(updateStreamsName()));
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RSSImp::~RSSImp(){
|
RSSImp::~RSSImp(){
|
||||||
delete timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ class RSSImp : public QWidget, public Ui::RSS{
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
RssManager rssmanager;
|
RssManager rssmanager;
|
||||||
QTimer* timer;
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_addStream_button_clicked();
|
void on_addStream_button_clicked();
|
||||||
@ -45,7 +44,7 @@ class RSSImp : public QWidget, public Ui::RSS{
|
|||||||
void renameStream();
|
void renameStream();
|
||||||
void refreshStream();
|
void refreshStream();
|
||||||
void createStream();
|
void createStream();
|
||||||
void updateStreamsName();
|
void updateStreamsName(const int&);
|
||||||
void refreshAllStreams();
|
void refreshAllStreams();
|
||||||
void refreshStreamList();
|
void refreshStreamList();
|
||||||
void refreshNewsList();
|
void refreshNewsList();
|
||||||
|
Loading…
Reference in New Issue
Block a user