diff --git a/src/Icons/loading.gif b/src/Icons/loading.gif
new file mode 100644
index 000000000..dfbfc5707
Binary files /dev/null and b/src/Icons/loading.gif differ
diff --git a/src/Icons/loading.png b/src/Icons/loading.png
new file mode 100644
index 000000000..2b8e5b96b
Binary files /dev/null and b/src/Icons/loading.png differ
diff --git a/src/icons.qrc b/src/icons.qrc
index ee7c5a0b6..465c2f1dc 100644
--- a/src/icons.qrc
+++ b/src/icons.qrc
@@ -20,12 +20,13 @@
Icons/splash.png
Icons/home.png
Icons/uparrow.png
- Icons/rss.png
Icons/downarrow.png
Icons/connection.png
- Icons/add_file.png
Icons/refresh.png
+ Icons/rss.png
Icons/add_folder.png
+ Icons/add_file.png
+ Icons/loading.png
Icons/flags/portugal.png
Icons/flags/france.png
Icons/flags/ukraine.png
diff --git a/src/rss.h b/src/rss.h
index 0c8cbd599..05506fb18 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -29,6 +29,9 @@
// avoid crash if too many refresh
#define REFRESH_FREQ_MAX 5000
+#define ICON 0
+#define NEWS 1
+
#include
#include
#include
@@ -36,6 +39,7 @@
#include
#include
#include
+#include
#include "misc.h"
#include "downloadThread.h"
@@ -118,14 +122,15 @@ class RssStream : public QObject{
QString image;
QString url;
QString filePath;
+ QString iconPath;
QList listItem;
downloadThread* downloader;
QTime lastRefresh;
bool read;
signals:
- void refreshFinished(const QString& msg);
-
+ void refreshFinished(const QString& msg, const unsigned short& type);
+
public slots :
// read and store the downloaded rss' informations
void processDownloadedFile(const QString&, const QString& file_path, int return_code, const QString&) {
@@ -138,23 +143,43 @@ class RssStream : public QObject{
// Download failed
qDebug("(download failure) "+file_path.toUtf8());
if(QFile::exists(filePath)) {
- QFile::remove(file_path);
+ QFile::remove(filePath);
}
- emit refreshFinished(url);
+ emit refreshFinished(url, NEWS);
return;
}
openRss();
- emit refreshFinished(url);
+ emit refreshFinished(url, NEWS);
}
+ void displayIcon(const QString&, const QString& file_path, int return_code, const QString&) {
+ if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") {
+ QFile::remove(iconPath);
+ }
+ iconPath = file_path;
+ if(return_code){
+ // Download failed
+ qDebug("(download failure) "+iconPath.toUtf8());
+ if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") {
+ QFile::remove(iconPath);
+ }
+ iconPath = ":/Icons/rss.png";
+ emit refreshFinished(url, ICON);
+ return;
+ }
+ emit refreshFinished(url, ICON);
+ }
+
public:
RssStream(const QString& _url) {
url = _url;
alias = url;
read = true;
+ iconPath = ":/Icons/rss.png";
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);
+ getIcon();
lastRefresh.start();
}
@@ -163,6 +188,8 @@ class RssStream : public QObject{
delete downloader;
if(QFile::exists(filePath))
QFile::remove(filePath);
+ if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png")
+ QFile::remove(iconPath);
}
// delete all the items saved
@@ -212,6 +239,10 @@ class RssStream : public QObject{
return filePath;
}
+ QString getIconPath() const{
+ return filePath;
+ }
+
RssItem* getItem(unsigned int index) const{
return listItem.at(index);
}
@@ -236,6 +267,13 @@ class RssStream : public QObject{
read = true;
}
+ void getIcon() {
+ QUrl siteUrl(url);
+ QString iconUrl = "http://"+siteUrl.host()+"/favicon.ico";
+ connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(displayIcon(const QString&, const QString&, int, const QString&)));
+ downloader->downloadUrl(iconUrl);
+ }
+
private:
// read and create items from a rss document
short readDoc(const QDomDocument& doc) {
@@ -342,11 +380,11 @@ class RssManager : public QObject{
QStringList streamListUrl;
signals:
- void streamNeedRefresh(const unsigned short&);
+ void streamNeedRefresh(const unsigned short&, const unsigned short&);
public slots :
- void streamNeedRefresh(const QString& _url) {
- emit(streamNeedRefresh(hasStream(_url)));
+ void streamNeedRefresh(const QString& _url, const unsigned short& type) {
+ emit(streamNeedRefresh(hasStream(_url), type));
}
public :
@@ -380,7 +418,7 @@ class RssManager : public QObject{
RssStream *stream = new RssStream(streamListUrl.at(i));
stream->setAlias(streamListAlias.at(i));
streamList.append(stream);
- connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
+ connect(stream, SIGNAL(refreshFinished(const QString&, const unsigned short&)), this, SLOT(streamNeedRefresh(const QString&, const unsigned short&)));
}
}
@@ -404,7 +442,7 @@ class RssManager : public QObject{
if(hasStream(stream) < 0){
streamList.append(stream);
streamListUrl.append(stream->getUrl());
- connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
+ connect(stream, SIGNAL(refreshFinished(const QString&, const unsigned short&)), this, SLOT(streamNeedRefresh(const QString&, const unsigned short&)));
}else{
qDebug("Not adding the Rss stream because it is already in the list");
}
@@ -426,7 +464,7 @@ class RssManager : public QObject{
RssStream* stream = new RssStream(url);
streamList.append(stream);
streamListUrl.append(url);
- connect(stream, SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
+ connect(stream, SIGNAL(refreshFinished(const QString&, const unsigned short&)), this, SLOT(streamNeedRefresh(const QString&, const unsigned short&)));
}else {
qDebug("Not adding the Rss stream because it is already in the list");
}
@@ -458,7 +496,7 @@ class RssManager : public QObject{
unsigned int streamListUrlSize = streamListUrl.size();
for(unsigned int i=0; irefresh();
- connect(getStream(i), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
+ connect(getStream(i), SIGNAL(refreshFinished(const QString&, const unsigned short&)), this, SLOT(streamNeedRefresh(const QString&, const unsigned short&)));
}
}
@@ -466,7 +504,7 @@ class RssManager : public QObject{
if(index>=0 && indexgetLastRefreshElapsed()>REFRESH_FREQ_MAX) {
getStream(index)->refresh();
- connect(getStream(index), SIGNAL(refreshFinished(const QString&)), this, SLOT(streamNeedRefresh(const QString&)));
+ connect(getStream(index), SIGNAL(refreshFinished(const QString&, const unsigned short&)), this, SLOT(streamNeedRefresh(const QString&, const unsigned short&)));
}
}
}
diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp
index 3e77fd42a..6a6fe48d4 100644
--- a/src/rss_imp.cpp
+++ b/src/rss_imp.cpp
@@ -65,7 +65,6 @@
// display the news of a stream when click on it
void RSSImp::on_listStreams_clicked() {
rssmanager.getStream(listStreams->currentRow())->setRead();
- //streamNeedRefresh(listStreams->currentRow());
listStreams->item(listStreams->currentRow())->setData(Qt::BackgroundRole, QVariant(QColor("white")));
refreshNewsList();
}
@@ -109,7 +108,7 @@
QString newAlias = QInputDialog::getText(this, tr("Please choose a new name for this stream"), tr("New stream name:"), QLineEdit::Normal, rssmanager.getStream(index)->getAlias(), &ok);
if(ok) {
rssmanager.setAlias(index, newAlias);
- updateStreamName(index);
+ updateStreamName(index, NEWS);
}
}
@@ -121,7 +120,7 @@
if(rssmanager.getNbStream()>0) {
textBrowser->clear();
listNews->clear();
- listStreams->item(index)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/refresh.png")));
+ listStreams->item(index)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
rssmanager.refresh(index);
}
}
@@ -132,7 +131,7 @@
listNews->clear();
unsigned short nbstream = rssmanager.getNbStream();
for(unsigned short i=0; iitem(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/refresh.png")));
+ listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
rssmanager.refreshAll();
}
@@ -162,7 +161,6 @@
listNews->clear();
refreshNewsList();
}
- //updateAllStreamsName();
}
// fills the newsList
@@ -191,46 +189,28 @@
}
// show the number of news for a stream, his status and an icon
- void RSSImp::updateStreamName(const unsigned short& i) {
- unsigned short nbitem = rssmanager.getStream(i)->getListSize();
- listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias()+" ("+QString::number(nbitem,10).toUtf8()+")");
- if(nbitem==0)
- listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red")));
- else if(rssmanager.getStream(i)->getLastRefreshElapsed()>REFRESH_MAX_LATENCY)
- listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("orange")));
- else
- listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("green")));
- if(!rssmanager.getStream(i)->isRead())
- listStreams->item(i)->setData(Qt::BackgroundRole, QVariant(QColor(0, 255, 0, 20)));
- listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/rss.png")));
- if(listStreams->currentRow()==i) {
- listNews->clear();
- refreshNewsList();
+ void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) {
+ if(type == ICON) {
+ listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
}
- }
-
- // show the number of news for each stream
- /*void RSSImp::updateAllStreamsName() {
- unsigned short nbstream = rssmanager.getNbStream();
- for(unsigned short i=0; igetListSize();
- listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias()+" ("+QString::number(nbitem,10).toUtf8()+")");
+ listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias().toUtf8()+" "+rssmanager.getStream(i)->getIconPath().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
if(nbitem==0)
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red")));
else if(rssmanager.getStream(i)->getLastRefreshElapsed()>REFRESH_MAX_LATENCY)
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("orange")));
else
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("green")));
- if(!rssmanager.getStream(i)->isRead())
+ if(!rssmanager.getStream(i)->isRead())
listStreams->item(i)->setData(Qt::BackgroundRole, QVariant(QColor(0, 255, 0, 20)));
+ listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
+ if(listStreams->currentRow()==i) {
+ listNews->clear();
+ refreshNewsList();
+ }
}
- int currentStream = listStreams->currentRow();
- if(currentStream>=0 && currentStreamsetCurrentRow(currentStream);
- listNews->clear();
- refreshNewsList();
- }
- }*/
+ }
RSSImp::RSSImp() : QWidget(){
setupUi(this);
@@ -243,11 +223,14 @@
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream()));
connect(actionCreate, SIGNAL(triggered()), this, SLOT(createStream()));
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
- connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&)));
+ connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&)));
refreshStreamList();
+ unsigned short nbstream = rssmanager.getNbStream();
+ for(unsigned short i=0; iitem(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
+ listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red")));
+ }
refreshTextBrowser();
- // force the first alias-refresh
- //QTimer::singleShot(10000, this, SLOT(updateAllStreamsName()));
}
RSSImp::~RSSImp(){
diff --git a/src/rss_imp.h b/src/rss_imp.h
index f83e19553..7e0d77504 100644
--- a/src/rss_imp.h
+++ b/src/rss_imp.h
@@ -46,7 +46,7 @@ class RSSImp : public QWidget, public Ui::RSS{
void renameStream();
void refreshStream();
void createStream();
- void updateStreamName(const unsigned short&);
+ void updateStreamName(const unsigned short&, const unsigned short&);
//void updateAllStreamsName();
void refreshAllStreams();
void refreshStreamList();