Browse Source

some work on rss, refresh & autoopenbrowser

adaptive-webui-19844
Arnaud Demaiziere 18 years ago
parent
commit
eddee2a0d5
  1. 85
      src/rss.h
  2. 59
      src/rss.ui
  3. 24
      src/rss_imp.h
  4. 1
      src/src.pro

85
src/rss.h

@ -135,12 +135,17 @@ class RssStream : public QObject{
// read and store the downloaded rss' informations // read and store the downloaded rss' informations
void processDownloadedFile(const QString&, const QString& file_path, int return_code, const QString&){ 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; filePath = file_path;
if(return_code){ if(return_code){
// Download failed // Download failed
qDebug("(download failure) "+file_path.toUtf8()); qDebug("(download failure) "+file_path.toUtf8());
QFile::remove(file_path); if(QFile::exists(filePath)) {
QFile::remove(file_path);
}
return; return;
} }
this->openRss(); this->openRss();
@ -157,20 +162,26 @@ class RssStream : public QObject{
} }
~RssStream(){ ~RssStream(){
for(int i=0; i<listItem.size(); i++){ removeAllItem();
delete getItem(i);
}
delete downloader; delete downloader;
if(QFile::exists(filePath)) if(QFile::exists(filePath))
QFile::remove(filePath); QFile::remove(filePath);
} }
int refresh(){ int refresh(){
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);
return 1; return 1;
} }
// delete all the items saved
void removeAllItem() {
int i=0;
while(i<listItem.size()) {
delete getItem(i);
i++;
}
}
QString getTitle() const{ QString getTitle() const{
return this->title; return this->title;
@ -258,9 +269,11 @@ class RssStream : public QObject{
// build items // build items
else if(property.tagName() == "item") else if(property.tagName() == "item")
{ {
RssItem* item = new RssItem(property, this); if(getListSize()<STREAM_MAX_ITEM) {
//add it to a list RssItem* item = new RssItem(property, this);
this->listItem.append(item); //add it to a list
this->listItem.append(item);
}
} }
property = property.nextSibling().toElement(); property = property.nextSibling().toElement();
} }
@ -276,21 +289,27 @@ class RssStream : public QObject{
QFile fileRss(filePath); QFile fileRss(filePath);
if(!fileRss.open(QIODevice::ReadOnly | QIODevice::Text)) if(!fileRss.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
qDebug("error : open failed, no file or locked"); qDebug("error : open failed, no file or locked, "+filePath.toUtf8());
fileRss.remove(); if(QFile::exists(filePath)) {
fileRss.remove();
}
return -1; return -1;
} }
if(!doc.setContent(&fileRss)) if(!doc.setContent(&fileRss))
{ {
qDebug("can't read temp file, might be empty"); qDebug("can't read temp file, might be empty");
fileRss.close(); fileRss.close();
fileRss.remove(); if(QFile::exists(filePath)) {
fileRss.remove();
}
return -1; return -1;
} }
// start reading the xml // start reading the xml
short return_lecture = read(doc); short return_lecture = read(doc);
fileRss.close(); fileRss.close();
fileRss.remove(); if(QFile::exists(filePath)) {
fileRss.remove();
}
return return_lecture; return return_lecture;
} }
}; };
@ -409,6 +428,24 @@ class RssManager{
this->streamListAlias = newAliasList; this->streamListAlias = newAliasList;
} }
// reload all the xml files from the web
void refreshAll(){
QList<RssStream*> newIgnoredList, newStreamList;
for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i);
}
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
this->streamList = newStreamList;
this->ignoredStreamList = newIgnoredList;
for(unsigned short i=0; i<streamListUrl.size(); i++){
RssStream *stream = new RssStream(this->streamListUrl.at(i));
stream->setAlias(this->streamListAlias.at(i));
this->streamList.append(stream);
}
}
// return the position index of a stream, if the manager owns it // return the position index of a stream, if the manager owns it
short hasStream(RssStream* stream) const{ short hasStream(RssStream* stream) const{
QString url = stream->getUrl(); QString url = stream->getUrl();
@ -427,24 +464,6 @@ class RssManager{
return ignoredStreamList.at(index); return ignoredStreamList.at(index);
} }
// reload all the xml files from the web
void refreshAll(){
// first refresh the ignored ones
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
if(getIgnored(i)->refresh()==0){
this->streamList.append(getIgnored(i));
this->ignoredStreamList.removeAt(i);
}
}
// then refresh the active ones
for(unsigned short i=0; i<streamList.size(); i++){
if(getStream(i)->refresh()!=0){
this->ignoredStreamList.append(getStream(i));
this->streamList.removeAt(i);
}
}
}
void displayManager(){ void displayManager(){
for(unsigned short i=0; i<streamList.size(); i++){ for(unsigned short i=0; i<streamList.size(); i++){
getStream(i)->displayStream(); getStream(i)->displayStream();
@ -455,6 +474,10 @@ class RssManager{
} }
} }
int getNbStream() {
return streamList.size();
}
}; };
#endif #endif

59
src/rss.ui

@ -6,7 +6,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>811</width> <width>811</width>
<height>453</height> <height>447</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
@ -178,7 +178,62 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTextBrowser" name="contentBrowser" /> <widget class="QTextBrowser" name="textBrowser" />
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="viewStream_button" >
<property name="minimumSize" >
<size>
<width>80</width>
<height>22</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>80</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>

24
src/rss_imp.h

@ -27,15 +27,23 @@
class RSSImp : public QWidget, public Ui::RSS{ class RSSImp : public QWidget, public Ui::RSS{
Q_OBJECT Q_OBJECT
public: private:
RSSImp() : QWidget(){ RssManager rssmanager;
setupUi(this); void refreshStreamList();
addStream_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); void refreshNewsList();
delStream_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); void refreshTextBrowser();
refreshAll_button->setIcon(QIcon(QString::fromUtf8(":/Icons/refresh.png")));
} 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();
~RSSImp(){} public:
RSSImp();
~RSSImp();
}; };
#endif #endif

1
src/src.pro

@ -128,6 +128,7 @@ SOURCES += GUI.cpp \
createtorrent_imp.cpp \ createtorrent_imp.cpp \
bittorrent.cpp \ bittorrent.cpp \
searchEngine.cpp \ searchEngine.cpp \
rss_imp.cpp \
FinishedTorrents.cpp FinishedTorrents.cpp
!contains(DEFINES, NO_UPNP){ !contains(DEFINES, NO_UPNP){
message(UPnP Enabled) message(UPnP Enabled)

Loading…
Cancel
Save