From eddee2a0d5ac45154a8f8a958c627a9168e1d892 Mon Sep 17 00:00:00 2001 From: Arnaud Demaiziere Date: Thu, 5 Apr 2007 12:39:42 +0000 Subject: [PATCH] some work on rss, refresh & autoopenbrowser --- src/rss.h | 85 ++++++++++++++++++++++++++++++++------------------- src/rss.ui | 59 +++++++++++++++++++++++++++++++++-- src/rss_imp.h | 24 ++++++++++----- src/src.pro | 1 + 4 files changed, 128 insertions(+), 41 deletions(-) diff --git a/src/rss.h b/src/rss.h index d4d3e2f32..d1e8cc000 100644 --- a/src/rss.h +++ b/src/rss.h @@ -135,12 +135,17 @@ class RssStream : public QObject{ // read and store the downloaded rss' informations void processDownloadedFile(const QString&, const QString& file_path, int return_code, const QString&){ - QFile::remove(filePath); + // delete the former file + if(QFile::exists(filePath)) { + QFile::remove(filePath); + } filePath = file_path; if(return_code){ // Download failed qDebug("(download failure) "+file_path.toUtf8()); - QFile::remove(file_path); + if(QFile::exists(filePath)) { + QFile::remove(file_path); + } return; } this->openRss(); @@ -157,20 +162,26 @@ class RssStream : public QObject{ } ~RssStream(){ - for(int i=0; idownloadUrl(url); return 1; } + + // delete all the items saved + void removeAllItem() { + int i=0; + while(ititle; @@ -258,9 +269,11 @@ class RssStream : public QObject{ // build items else if(property.tagName() == "item") { - RssItem* item = new RssItem(property, this); - //add it to a list - this->listItem.append(item); + if(getListSize()listItem.append(item); + } } property = property.nextSibling().toElement(); } @@ -276,21 +289,27 @@ class RssStream : public QObject{ QFile fileRss(filePath); if(!fileRss.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug("error : open failed, no file or locked"); - fileRss.remove(); + qDebug("error : open failed, no file or locked, "+filePath.toUtf8()); + if(QFile::exists(filePath)) { + fileRss.remove(); + } return -1; } if(!doc.setContent(&fileRss)) { qDebug("can't read temp file, might be empty"); fileRss.close(); - fileRss.remove(); + if(QFile::exists(filePath)) { + fileRss.remove(); + } return -1; } // start reading the xml short return_lecture = read(doc); fileRss.close(); - fileRss.remove(); + if(QFile::exists(filePath)) { + fileRss.remove(); + } return return_lecture; } }; @@ -409,6 +428,24 @@ class RssManager{ this->streamListAlias = newAliasList; } + // reload all the xml files from the web + void refreshAll(){ + QList newIgnoredList, newStreamList; + for(unsigned short i=0; istreamList = newStreamList; + this->ignoredStreamList = newIgnoredList; + for(unsigned short i=0; istreamListUrl.at(i)); + stream->setAlias(this->streamListAlias.at(i)); + this->streamList.append(stream); + } + } + // return the position index of a stream, if the manager owns it short hasStream(RssStream* stream) const{ QString url = stream->getUrl(); @@ -427,24 +464,6 @@ class RssManager{ return ignoredStreamList.at(index); } - // reload all the xml files from the web - void refreshAll(){ - // first refresh the ignored ones - for(unsigned short i=0; irefresh()==0){ - this->streamList.append(getIgnored(i)); - this->ignoredStreamList.removeAt(i); - } - } - // then refresh the active ones - for(unsigned short i=0; irefresh()!=0){ - this->ignoredStreamList.append(getStream(i)); - this->streamList.removeAt(i); - } - } - } - void displayManager(){ for(unsigned short i=0; idisplayStream(); @@ -455,6 +474,10 @@ class RssManager{ } } + int getNbStream() { + return streamList.size(); + } + }; #endif diff --git a/src/rss.ui b/src/rss.ui index 0b776e97d..11a9ba8c2 100644 --- a/src/rss.ui +++ b/src/rss.ui @@ -6,7 +6,7 @@ 0 0 811 - 453 + 447 @@ -178,7 +178,62 @@ - + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 80 + 22 + + + + + 80 + 22 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + diff --git a/src/rss_imp.h b/src/rss_imp.h index 286922d2c..60ca4cebd 100644 --- a/src/rss_imp.h +++ b/src/rss_imp.h @@ -27,15 +27,23 @@ class RSSImp : public QWidget, public Ui::RSS{ Q_OBJECT - public: - RSSImp() : QWidget(){ - setupUi(this); - addStream_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); - delStream_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); - refreshAll_button->setIcon(QIcon(QString::fromUtf8(":/Icons/refresh.png"))); - } + private: + RssManager rssmanager; + void refreshStreamList(); + void refreshNewsList(); + void refreshTextBrowser(); - ~RSSImp(){} + protected slots: + void on_addStream_button_clicked(); + void on_delStream_button_clicked(); + void on_refreshAll_button_clicked(); + void on_listStreams_clicked(); + void on_listNews_clicked(); + void on_viewStream_button_clicked(); + + public: + RSSImp(); + ~RSSImp(); }; #endif diff --git a/src/src.pro b/src/src.pro index bcb4650ea..2057675c8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -128,6 +128,7 @@ SOURCES += GUI.cpp \ createtorrent_imp.cpp \ bittorrent.cpp \ searchEngine.cpp \ + rss_imp.cpp \ FinishedTorrents.cpp !contains(DEFINES, NO_UPNP){ message(UPnP Enabled)