diff --git a/src/rss.h b/src/rss.h index d658c85ec..74364d827 100644 --- a/src/rss.h +++ b/src/rss.h @@ -142,7 +142,7 @@ class RssStream : public QObject{ return; } openRss(); - emit refreshFinished("plop"); + emit refreshFinished(url); } public: @@ -226,6 +226,7 @@ class RssStream : public QObject{ } private: + // read and create items from a rss document short read(const QDomDocument& doc) { // is it a rss file ? QDomElement root = doc.documentElement(); @@ -239,7 +240,11 @@ class RssStream : public QObject{ } QDomNode rss = root.firstChild(); QDomElement channel = root.firstChild().toElement(); - + unsigned short listsize = getListSize(); + for(unsigned short i=0; igetTitle(); @@ -285,7 +287,7 @@ class RssStream : public QObject{ listItem.removeFirst(); } while(getListSize()>STREAM_MAX_ITEM) { - listItem.removeLast(); + listItem.removeAt(STREAM_MAX_ITEM); } } @@ -329,13 +331,11 @@ class RssManager : public QObject{ QStringList streamListAlias; signals: - void streamNeedRefresh(); + void streamNeedRefresh(const int&); public slots : - // read and store the downloaded rss' informations - void refreshFinished(const QString&) { - - qDebug("*******************************************************"); + void streamNeedRefresh(const QString& _url) { + emit(streamNeedRefresh(hasStream(_url))); } public : @@ -365,7 +365,7 @@ class RssManager : public QObject{ RssStream *stream = new RssStream(streamListUrl.at(i)); stream->setAlias(streamListAlias.at(i)); 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); streamListUrl.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{ 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) { - streamList.append(new RssStream(url)); + RssStream* stream = new RssStream(url); + streamList.append(stream); streamListUrl.append(url); streamListAlias.append(url); + connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&))); }else { 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 void refreshAll(){ - QList newStreamList; - unsigned int streamListSize = streamList.size(); - for(unsigned int i=0; isetAlias(streamListAlias.at(i)); - streamList.append(stream); - connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh())); + getStream(i)->refresh(); + connect(getStream(i), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&))); } } void refresh(int index) { if(index>=0 && indexgetLastRefreshElapsed()>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(); - connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh())); + connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&))); } } } diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index f31740780..be0620a68 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -148,10 +148,14 @@ void RSSImp::refreshStreamList() { int currentStream = listStreams->currentRow(); listStreams->clear(); - for(int i=0; igetAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")", listStreams); } listStreams->setCurrentRow(currentStream); + if(currentStream>=0) { + listNews->clear(); + refreshNewsList(); + } } // fills the newsList @@ -176,9 +180,13 @@ } // show the number of news for each stream - void RSSImp::updateStreamsName() { - for(int i=0; iitem(i)->setText(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")"); + void RSSImp::updateStreamsName(const int& i) { + 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(actionCreate, SIGNAL(triggered()), this, SLOT(createStream())); connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams())); + connect(&rssmanager, SIGNAL(streamNeedRefresh(const int&)), this, SLOT(updateStreamsName(const int&))); refreshStreamList(); refreshTextBrowser(); - timer = new QTimer(this); - //connect(timer, SIGNAL(timeout()), this, SLOT(updateStreamsName())); - timer->start(5000); - //for(int i=0; i