Browse Source

rss : bugs fixes, better refresh

adaptive-webui-19844
Arnaud Demaiziere 18 years ago
parent
commit
66201a2853
  1. 50
      src/rss.h
  2. 26
      src/rss_imp.cpp
  3. 3
      src/rss_imp.h

50
src/rss.h

@ -142,7 +142,7 @@ class RssStream : public QObject{ @@ -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{ @@ -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,6 +240,10 @@ class RssStream : public QObject{ @@ -239,6 +240,10 @@ class RssStream : public QObject{
}
QDomNode rss = root.firstChild();
QDomElement channel = root.firstChild().toElement();
unsigned short listsize = getListSize();
for(unsigned short i=0; i<listsize; i++) {
listItem.removeLast();
}
while(!channel.isNull()) {
// we are reading the rss'main info
@ -257,9 +262,7 @@ class RssStream : public QObject{ @@ -257,9 +262,7 @@ class RssStream : public QObject{
else if (property.tagName() == "image")
image = property.text();
else if(property.tagName() == "item") {
if(getListSize() < 3*STREAM_MAX_ITEM) {
//TODO: find a way to break here
//add it to a list
if(getListSize() < STREAM_MAX_ITEM) {
listItem.append(new RssItem(property));
}
}
@ -268,11 +271,10 @@ class RssStream : public QObject{ @@ -268,11 +271,10 @@ class RssStream : public QObject{
}
channel = channel.nextSibling().toElement();
}
// resize stream listItem
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
void resizeList() {
unsigned short lastindex = 0;
QString firstTitle = getItem(0)->getTitle();
@ -285,7 +287,7 @@ class RssStream : public QObject{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -435,30 +437,18 @@ class RssManager : public QObject{
// reload all the xml files from the web
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();
for(unsigned int i=0; i<streamListUrlSize; ++i){
RssStream *stream = new RssStream(streamListUrl.at(i));
stream->setAlias(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 && index<getNbStream()) {
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();
connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh()));
connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
}
}
}

26
src/rss_imp.cpp

@ -148,10 +148,14 @@ @@ -148,10 +148,14 @@
void RSSImp::refreshStreamList() {
int currentStream = listStreams->currentRow();
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);
}
listStreams->setCurrentRow(currentStream);
if(currentStream>=0) {
listNews->clear();
refreshNewsList();
}
}
// fills the newsList
@ -176,9 +180,13 @@ @@ -176,9 +180,13 @@
}
// show the number of news for each stream
void RSSImp::updateStreamsName() {
for(int i=0; i<rssmanager.getNbStream(); i++) {
listStreams->item(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 @@ @@ -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<rssmanager.getNbStream(); i++) {
//connect(rssmanager, SIGNAL(streamNeedRefresh()), this, SLOT(updateStreamsName()));
//}
// force the first alias-refresh
QTimer::singleShot(10000, this, SLOT(updateStreamsName()));
}
RSSImp::~RSSImp(){
delete timer;
}

3
src/rss_imp.h

@ -31,7 +31,6 @@ class RSSImp : public QWidget, public Ui::RSS{ @@ -31,7 +31,6 @@ class RSSImp : public QWidget, public Ui::RSS{
private:
RssManager rssmanager;
QTimer* timer;
protected slots:
void on_addStream_button_clicked();
@ -45,7 +44,7 @@ class RSSImp : public QWidget, public Ui::RSS{ @@ -45,7 +44,7 @@ class RSSImp : public QWidget, public Ui::RSS{
void renameStream();
void refreshStream();
void createStream();
void updateStreamsName();
void updateStreamsName(const int&);
void refreshAllStreams();
void refreshStreamList();
void refreshNewsList();

Loading…
Cancel
Save