|
|
@ -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&){ |
|
|
|
|
|
|
|
// delete the former file
|
|
|
|
|
|
|
|
if(QFile::exists(filePath)) { |
|
|
|
QFile::remove(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()); |
|
|
|
|
|
|
|
if(QFile::exists(filePath)) { |
|
|
|
QFile::remove(file_path); |
|
|
|
QFile::remove(file_path); |
|
|
|
|
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this->openRss(); |
|
|
|
this->openRss(); |
|
|
@ -157,21 +162,27 @@ 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,10 +269,12 @@ class RssStream : public QObject{ |
|
|
|
// build items
|
|
|
|
// build items
|
|
|
|
else if(property.tagName() == "item") |
|
|
|
else if(property.tagName() == "item") |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if(getListSize()<STREAM_MAX_ITEM) { |
|
|
|
RssItem* item = new RssItem(property, this); |
|
|
|
RssItem* item = new RssItem(property, this); |
|
|
|
//add it to a list
|
|
|
|
//add it to a list
|
|
|
|
this->listItem.append(item); |
|
|
|
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()); |
|
|
|
|
|
|
|
if(QFile::exists(filePath)) { |
|
|
|
fileRss.remove(); |
|
|
|
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(); |
|
|
|
|
|
|
|
if(QFile::exists(filePath)) { |
|
|
|
fileRss.remove(); |
|
|
|
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(); |
|
|
|
|
|
|
|
if(QFile::exists(filePath)) { |
|
|
|
fileRss.remove(); |
|
|
|
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 |
|
|
|