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{ @@ -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,21 +162,27 @@ class RssStream : public QObject{ @@ -157,21 +162,27 @@ class RssStream : public QObject{
}
~RssStream(){
for(int i=0; i<listItem.size(); i++){
delete getItem(i);
}
removeAllItem();
delete downloader;
if(QFile::exists(filePath))
QFile::remove(filePath);
}
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&)));
downloader->downloadUrl(url);
return 1;
}
// delete all the items saved
void removeAllItem() {
int i=0;
while(i<listItem.size()) {
delete getItem(i);
i++;
}
}
QString getTitle() const{
return this->title;
}
@ -258,9 +269,11 @@ class RssStream : public QObject{ @@ -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()<STREAM_MAX_ITEM) {
RssItem* item = new RssItem(property, this);
//add it to a list
this->listItem.append(item);
}
}
property = property.nextSibling().toElement();
}
@ -276,21 +289,27 @@ class RssStream : public QObject{ @@ -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{ @@ -409,6 +428,24 @@ class RssManager{
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
short hasStream(RssStream* stream) const{
QString url = stream->getUrl();
@ -427,24 +464,6 @@ class RssManager{ @@ -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; 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(){
for(unsigned short i=0; i<streamList.size(); i++){
getStream(i)->displayStream();
@ -455,6 +474,10 @@ class RssManager{ @@ -455,6 +474,10 @@ class RssManager{
}
}
int getNbStream() {
return streamList.size();
}
};
#endif

59
src/rss.ui

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>811</width>
<height>453</height>
<height>447</height>
</rect>
</property>
<property name="windowTitle" >
@ -178,7 +178,62 @@ @@ -178,7 +178,62 @@
</widget>
</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>
</layout>
</item>

24
src/rss_imp.h

@ -27,15 +27,23 @@ @@ -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();
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

1
src/src.pro

@ -128,6 +128,7 @@ SOURCES += GUI.cpp \ @@ -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)

Loading…
Cancel
Save