|
|
@ -22,9 +22,12 @@ |
|
|
|
#ifndef RSS_H |
|
|
|
#ifndef RSS_H |
|
|
|
#define RSS_H |
|
|
|
#define RSS_H |
|
|
|
|
|
|
|
|
|
|
|
#define STREAM_MAX_ITEM 15 |
|
|
|
// MAX ITEM A STREAM
|
|
|
|
|
|
|
|
#define STREAM_MAX_ITEM 18 |
|
|
|
// FIXME: not used yet
|
|
|
|
// FIXME: not used yet
|
|
|
|
#define GLOBAL_MAX_ITEM 150 |
|
|
|
#define GLOBAL_MAX_ITEM 150 |
|
|
|
|
|
|
|
// avoid crash if too many refresh
|
|
|
|
|
|
|
|
#define REFRESH_FREQ_MAX 5000 |
|
|
|
|
|
|
|
|
|
|
|
#include <QFile> |
|
|
|
#include <QFile> |
|
|
|
#include <QList> |
|
|
|
#include <QList> |
|
|
@ -32,11 +35,14 @@ |
|
|
|
#include <QTemporaryFile> |
|
|
|
#include <QTemporaryFile> |
|
|
|
#include <QSettings> |
|
|
|
#include <QSettings> |
|
|
|
#include <QDomDocument> |
|
|
|
#include <QDomDocument> |
|
|
|
|
|
|
|
#include <QTime> |
|
|
|
|
|
|
|
|
|
|
|
#include "misc.h" |
|
|
|
#include "misc.h" |
|
|
|
#include "downloadThread.h" |
|
|
|
#include "downloadThread.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RssManager; |
|
|
|
class RssStream; |
|
|
|
class RssStream; |
|
|
|
|
|
|
|
class RssItem; |
|
|
|
|
|
|
|
|
|
|
|
// Item of a rss stream, single information
|
|
|
|
// Item of a rss stream, single information
|
|
|
|
class RssItem{ |
|
|
|
class RssItem{ |
|
|
@ -47,14 +53,12 @@ class RssItem{ |
|
|
|
QString description; |
|
|
|
QString description; |
|
|
|
QString image; |
|
|
|
QString image; |
|
|
|
bool read; |
|
|
|
bool read; |
|
|
|
RssStream* parent; |
|
|
|
|
|
|
|
QString downloadLink; |
|
|
|
QString downloadLink; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
// public constructor
|
|
|
|
// public constructor
|
|
|
|
RssItem(const QDomElement& properties, RssStream* _parent){ |
|
|
|
RssItem(const QDomElement& properties){ |
|
|
|
read = false; |
|
|
|
read = false; |
|
|
|
parent = _parent; |
|
|
|
|
|
|
|
downloadLink = "none"; |
|
|
|
downloadLink = "none"; |
|
|
|
QDomElement property = properties.firstChild().toElement(); |
|
|
|
QDomElement property = properties.firstChild().toElement(); |
|
|
|
while(!property.isNull()) { |
|
|
|
while(!property.isNull()) { |
|
|
@ -68,7 +72,6 @@ class RssItem{ |
|
|
|
image = property.text(); |
|
|
|
image = property.text(); |
|
|
|
property = property.nextSibling().toElement(); |
|
|
|
property = property.nextSibling().toElement(); |
|
|
|
} |
|
|
|
} |
|
|
|
//displayItem();
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~RssItem(){ |
|
|
|
~RssItem(){ |
|
|
@ -101,14 +104,6 @@ class RssItem{ |
|
|
|
void setRead(){ |
|
|
|
void setRead(){ |
|
|
|
read = true; |
|
|
|
read = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RssStream* getParent() const{ |
|
|
|
|
|
|
|
return parent; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void displayItem(){ |
|
|
|
|
|
|
|
qDebug(" - "+title.toUtf8()+" - "+link.toUtf8()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Rss stream, loaded form an xml file
|
|
|
|
// Rss stream, loaded form an xml file
|
|
|
@ -125,7 +120,11 @@ class RssStream : public QObject{ |
|
|
|
QString filePath; |
|
|
|
QString filePath; |
|
|
|
QList<RssItem*> listItem; |
|
|
|
QList<RssItem*> listItem; |
|
|
|
downloadThread* downloader; |
|
|
|
downloadThread* downloader; |
|
|
|
|
|
|
|
QTime lastRefresh; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signals: |
|
|
|
|
|
|
|
void refreshFinished(const QString& msg); |
|
|
|
|
|
|
|
|
|
|
|
public slots : |
|
|
|
public slots : |
|
|
|
// 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&) { |
|
|
@ -143,6 +142,7 @@ class RssStream : public QObject{ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
openRss(); |
|
|
|
openRss(); |
|
|
|
|
|
|
|
emit refreshFinished("plop"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
@ -152,6 +152,7 @@ class RssStream : public QObject{ |
|
|
|
downloader = new downloadThread(this); |
|
|
|
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); |
|
|
|
|
|
|
|
lastRefresh.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~RssStream(){ |
|
|
|
~RssStream(){ |
|
|
@ -169,6 +170,12 @@ class RssStream : public QObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void refresh() { |
|
|
|
|
|
|
|
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&))); |
|
|
|
|
|
|
|
downloader->downloadUrl(url); |
|
|
|
|
|
|
|
lastRefresh.start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString getTitle() const{ |
|
|
|
QString getTitle() const{ |
|
|
|
return title; |
|
|
|
return title; |
|
|
|
} |
|
|
|
} |
|
|
@ -214,13 +221,9 @@ class RssStream : public QObject{ |
|
|
|
return listItem; |
|
|
|
return listItem; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void displayStream(){ |
|
|
|
int getLastRefreshElapsed() const{ |
|
|
|
qDebug(" # "+getTitle().toUtf8()+" - "+getUrl().toUtf8()+" - "+getAlias().toUtf8()); |
|
|
|
return lastRefresh.elapsed(); |
|
|
|
unsigned int listItemSize = listItem.size(); |
|
|
|
} |
|
|
|
for(unsigned int i=0; i<listItemSize; ++i){ |
|
|
|
|
|
|
|
getItem(i)->displayItem(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
short read(const QDomDocument& doc) { |
|
|
|
short read(const QDomDocument& doc) { |
|
|
@ -236,6 +239,7 @@ class RssStream : public QObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
QDomNode rss = root.firstChild(); |
|
|
|
QDomNode rss = root.firstChild(); |
|
|
|
QDomElement channel = root.firstChild().toElement(); |
|
|
|
QDomElement channel = root.firstChild().toElement(); |
|
|
|
|
|
|
|
|
|
|
|
while(!channel.isNull()) { |
|
|
|
while(!channel.isNull()) { |
|
|
|
// we are reading the rss'main info
|
|
|
|
// we are reading the rss'main info
|
|
|
|
if (channel.tagName() == "channel") { |
|
|
|
if (channel.tagName() == "channel") { |
|
|
@ -253,10 +257,10 @@ class RssStream : public QObject{ |
|
|
|
else if (property.tagName() == "image") |
|
|
|
else if (property.tagName() == "image") |
|
|
|
image = property.text(); |
|
|
|
image = property.text(); |
|
|
|
else if(property.tagName() == "item") { |
|
|
|
else if(property.tagName() == "item") { |
|
|
|
if(getListSize() < STREAM_MAX_ITEM) { |
|
|
|
if(getListSize() < 3*STREAM_MAX_ITEM) { |
|
|
|
//TODO: find a way to break here
|
|
|
|
//TODO: find a way to break here
|
|
|
|
//add it to a list
|
|
|
|
//add it to a list
|
|
|
|
listItem.append(new RssItem(property, this)); |
|
|
|
listItem.append(new RssItem(property)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
property = property.nextSibling().toElement(); |
|
|
|
property = property.nextSibling().toElement(); |
|
|
@ -264,9 +268,28 @@ class RssStream : public QObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
channel = channel.nextSibling().toElement(); |
|
|
|
channel = channel.nextSibling().toElement(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// resize stream listItem
|
|
|
|
|
|
|
|
resizeList(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void resizeList() { |
|
|
|
|
|
|
|
unsigned short lastindex = 0; |
|
|
|
|
|
|
|
QString firstTitle = getItem(0)->getTitle(); |
|
|
|
|
|
|
|
unsigned short listsize = getListSize(); |
|
|
|
|
|
|
|
for(unsigned short i=0; i<listsize; i++) { |
|
|
|
|
|
|
|
if(getItem(i)->getTitle() == firstTitle) |
|
|
|
|
|
|
|
lastindex = i; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(unsigned short i=0; i<lastindex; i++) { |
|
|
|
|
|
|
|
listItem.removeFirst(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while(getListSize()>STREAM_MAX_ITEM) { |
|
|
|
|
|
|
|
listItem.removeLast(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// existing and opening test after download
|
|
|
|
// existing and opening test after download
|
|
|
|
short openRss(){ |
|
|
|
short openRss(){ |
|
|
|
QDomDocument doc("Rss Seed"); |
|
|
|
QDomDocument doc("Rss Seed"); |
|
|
@ -297,13 +320,24 @@ class RssStream : public QObject{ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// global class, manage the whole rss stream
|
|
|
|
// global class, manage the whole rss stream
|
|
|
|
class RssManager{ |
|
|
|
class RssManager : public QObject{ |
|
|
|
|
|
|
|
Q_OBJECT |
|
|
|
|
|
|
|
|
|
|
|
private : |
|
|
|
private : |
|
|
|
QList<RssStream*> streamList; |
|
|
|
QList<RssStream*> streamList; |
|
|
|
QStringList streamListUrl; |
|
|
|
QStringList streamListUrl; |
|
|
|
QStringList streamListAlias; |
|
|
|
QStringList streamListAlias; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signals: |
|
|
|
|
|
|
|
void streamNeedRefresh(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public slots : |
|
|
|
|
|
|
|
// read and store the downloaded rss' informations
|
|
|
|
|
|
|
|
void refreshFinished(const QString&) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug("*******************************************************"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public : |
|
|
|
public : |
|
|
|
RssManager(){ |
|
|
|
RssManager(){ |
|
|
|
loadStreamList(); |
|
|
|
loadStreamList(); |
|
|
@ -331,6 +365,7 @@ class RssManager{ |
|
|
|
RssStream *stream = new RssStream(streamListUrl.at(i)); |
|
|
|
RssStream *stream = new RssStream(streamListUrl.at(i)); |
|
|
|
stream->setAlias(streamListAlias.at(i)); |
|
|
|
stream->setAlias(streamListAlias.at(i)); |
|
|
|
streamList.append(stream); |
|
|
|
streamList.append(stream); |
|
|
|
|
|
|
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -349,6 +384,7 @@ class RssManager{ |
|
|
|
streamList.append(stream); |
|
|
|
streamList.append(stream); |
|
|
|
streamListUrl.append(stream->getUrl()); |
|
|
|
streamListUrl.append(stream->getUrl()); |
|
|
|
streamListAlias.append(stream->getUrl()); |
|
|
|
streamListAlias.append(stream->getUrl()); |
|
|
|
|
|
|
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh())); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
qDebug("Not adding the Rss stream because it is already in the list"); |
|
|
|
qDebug("Not adding the Rss stream because it is already in the list"); |
|
|
|
} |
|
|
|
} |
|
|
@ -410,15 +446,20 @@ class RssManager{ |
|
|
|
RssStream *stream = new RssStream(streamListUrl.at(i)); |
|
|
|
RssStream *stream = new RssStream(streamListUrl.at(i)); |
|
|
|
stream->setAlias(streamListAlias.at(i)); |
|
|
|
stream->setAlias(streamListAlias.at(i)); |
|
|
|
streamList.append(stream); |
|
|
|
streamList.append(stream); |
|
|
|
|
|
|
|
connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void refresh(int index) { |
|
|
|
void refresh(int index) { |
|
|
|
if(index>=0 && index<getNbStream()) { |
|
|
|
if(index>=0 && index<getNbStream()) { |
|
|
|
delete getStream(index); |
|
|
|
if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) { |
|
|
|
RssStream *stream = new RssStream(streamListUrl.at(index)); |
|
|
|
//delete getStream(index);
|
|
|
|
stream->setAlias(streamListAlias.at(index)); |
|
|
|
//RssStream *stream = new RssStream(streamListUrl.at(index));
|
|
|
|
streamList.replace(index, stream); |
|
|
|
//stream->setAlias(streamListAlias.at(index));
|
|
|
|
|
|
|
|
//streamList.replace(index, stream);
|
|
|
|
|
|
|
|
getStream(index)->refresh(); |
|
|
|
|
|
|
|
connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -435,13 +476,6 @@ class RssManager{ |
|
|
|
return streamList.at(index); |
|
|
|
return streamList.at(index); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void displayManager(){ |
|
|
|
|
|
|
|
unsigned int streamListSize = streamList.size(); |
|
|
|
|
|
|
|
for(unsigned int i=0; i<streamListSize; ++i){ |
|
|
|
|
|
|
|
getStream(i)->displayStream(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int getNbStream() { |
|
|
|
int getNbStream() { |
|
|
|
return streamList.size(); |
|
|
|
return streamList.size(); |
|
|
|
} |
|
|
|
} |
|
|
|