Browse Source

rss : download icon fix, don't work so i commented it

adaptive-webui-19844
Arnaud Demaiziere 18 years ago
parent
commit
1a553b00b0
  1. 1
      src/downloadThread.h
  2. 79
      src/rss.h
  3. 38
      src/rss_imp.cpp

1
src/downloadThread.h

@ -156,7 +156,6 @@ class downloadThread : public QThread {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
// Close tmp file // Close tmp file
fclose(file); fclose(file);
qDebug("##### chemin "+filePath.toUtf8());
emit downloadFinished(url, filePath, return_code, QString(errorBuffer)); emit downloadFinished(url, filePath, return_code, QString(errorBuffer));
qDebug("In Download thread RUN, signal emitted, ErrorBuffer: %s", errorBuffer); qDebug("In Download thread RUN, signal emitted, ErrorBuffer: %s", errorBuffer);
}else{ }else{

79
src/rss.h

@ -29,10 +29,13 @@
// avoid crash if too many refresh // avoid crash if too many refresh
#define REFRESH_FREQ_MAX 5000 #define REFRESH_FREQ_MAX 5000
// type of refresh
#define ICON 0 #define ICON 0
#define NEWS 1 #define NEWS 1
#define LATENCY 2
#include <QFile> #include <QFile>
#include <QImage>
#include <QList> #include <QList>
#include <curl/curl.h> #include <curl/curl.h>
#include <QTemporaryFile> #include <QTemporaryFile>
@ -124,7 +127,8 @@ class RssStream : public QObject{
QString filePath; QString filePath;
QString iconPath; QString iconPath;
QList<RssItem*> listItem; QList<RssItem*> listItem;
downloadThread* downloader; downloadThread* downloaderRss;
downloadThread* downloaderIcon;
QTime lastRefresh; QTime lastRefresh;
bool read; bool read;
@ -153,10 +157,16 @@ class RssStream : public QObject{
} }
void displayIcon(const QString&, const QString& file_path, int return_code, const QString&) { void displayIcon(const QString&, const QString& file_path, int return_code, const QString&) {
if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") { /*if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") {
QFile::remove(iconPath); QFile::remove(iconPath);
} }
iconPath = file_path; iconPath = file_path;
// XXX : remove it when we manage to dl the iconPath
//iconPath = ":/Icons/rss.png";
//iconPath = "/tmp/favicon.gif";
if(return_code){ if(return_code){
// Download failed // Download failed
qDebug("(download failure) "+iconPath.toUtf8()); qDebug("(download failure) "+iconPath.toUtf8());
@ -167,7 +177,9 @@ class RssStream : public QObject{
emit refreshFinished(url, ICON); emit refreshFinished(url, ICON);
return; return;
} }
emit refreshFinished(url, ICON); openIcon();
emit refreshFinished(url, ICON);*/
qDebug("******************Icone downloaded"+file_path.toUtf8());
} }
public: public:
@ -175,21 +187,24 @@ class RssStream : public QObject{
url = _url; url = _url;
alias = url; alias = url;
read = true; read = true;
iconPath = ":/Icons/rss.png"; downloaderRss = new downloadThread(this);
downloader = new downloadThread(this); downloaderIcon = 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(downloaderRss, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
downloader->downloadUrl(url); downloaderRss->downloadUrl(url);
getIcon(); // XXX: remove it when gif can be displayed
iconPath = ":/Icons/rss.png";
//getIcon();
lastRefresh.start(); lastRefresh.start();
} }
~RssStream(){ ~RssStream(){
removeAllItem(); removeAllItem();
delete downloader; delete downloaderRss;
delete downloaderIcon;
if(QFile::exists(filePath)) if(QFile::exists(filePath))
QFile::remove(filePath); QFile::remove(filePath);
if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png")
QFile::remove(iconPath); QFile::remove(iconPath);
} }
// delete all the items saved // delete all the items saved
@ -201,8 +216,8 @@ class RssStream : public QObject{
} }
void refresh() { void refresh() {
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&))); connect(downloaderRss, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
downloader->downloadUrl(url); downloaderRss->downloadUrl(url);
lastRefresh.start(); lastRefresh.start();
} }
@ -240,7 +255,7 @@ class RssStream : public QObject{
} }
QString getIconPath() const{ QString getIconPath() const{
return filePath; return iconPath;
} }
RssItem* getItem(unsigned int index) const{ RssItem* getItem(unsigned int index) const{
@ -267,11 +282,13 @@ class RssStream : public QObject{
read = true; read = true;
} }
// FIXME : always return an empty file
void getIcon() { void getIcon() {
QUrl siteUrl(url); QUrl siteUrl(url);
QString iconUrl = "http://"+siteUrl.host()+"/favicon.ico"; 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&))); connect(downloaderIcon, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(displayIcon(const QString&, const QString&, int, const QString&)));
downloader->downloadUrl(iconUrl); downloaderIcon->downloadUrl(iconUrl);
qDebug("******************Icone "+iconUrl.toUtf8());
} }
private: private:
@ -369,6 +386,26 @@ class RssStream : public QObject{
} }
return return_lecture; return return_lecture;
} }
void openIcon() {
QImage fileIcon(iconPath,0);
// if(!fileIcon.open(QIODevice::ReadOnly)) {
// qDebug("error : icon open failed, no file or locked, "+iconPath.toUtf8());
// if(QFile::exists(iconPath)) {
// fileIcon.remove();
// iconPath = ":/Icons/rss.png";
// }
// return;
// }
if(fileIcon.isNull()) {
qDebug("error : icon open failed, file empty, "+iconPath.toUtf8());
if(QFile::exists(iconPath)) {
//QFile::remove(iconPath);
//iconPath = ":/Icons/rss.png";
}
return;
}
}
}; };
// global class, manage the whole rss stream // global class, manage the whole rss stream
@ -450,16 +487,6 @@ class RssManager : public QObject{
// add a stream to the manager // add a stream to the manager
void addStream(QString url){ void addStream(QString url){
// XXX : is it useful ?
// completion of the address
/*if(!url.endsWith(".xml")) {
if(url.endsWith("/")) {
url.append("rss.xml");
} else {
url.append("/rss.xml");
}
}*/
if(hasStream(url) < 0) { if(hasStream(url) < 0) {
RssStream* stream = new RssStream(url); RssStream* stream = new RssStream(url);
streamList.append(stream); streamList.append(stream);

38
src/rss_imp.cpp

@ -66,6 +66,8 @@
void RSSImp::on_listStreams_clicked() { void RSSImp::on_listStreams_clicked() {
rssmanager.getStream(listStreams->currentRow())->setRead(); rssmanager.getStream(listStreams->currentRow())->setRead();
listStreams->item(listStreams->currentRow())->setData(Qt::BackgroundRole, QVariant(QColor("white"))); listStreams->item(listStreams->currentRow())->setData(Qt::BackgroundRole, QVariant(QColor("white")));
// update the color of the stream, is it old ?
updateStreamName(listStreams->currentRow(), LATENCY);
refreshNewsList(); refreshNewsList();
} }
@ -150,17 +152,18 @@
// fills the streamList // fills the streamList
void RSSImp::refreshStreamList() { void RSSImp::refreshStreamList() {
short currentStream = listStreams->currentRow(); //short currentStream = listStreams->currentRow();
unsigned short nbstream = rssmanager.getNbStream(); unsigned short nbstream = rssmanager.getNbStream();
listStreams->clear(); listStreams->clear();
for(unsigned short i=0; i<nbstream; i++) { for(unsigned short i=0; i<nbstream; i++) {
new QListWidgetItem(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")", listStreams); new QListWidgetItem(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")", listStreams);
updateStreamName(i, NEWS);
} }
if(currentStream>=0 && currentStream<nbstream) { /*if(currentStream>=0 && currentStream<nbstream) {
listStreams->setCurrentRow(currentStream); listStreams->setCurrentRow(currentStream);
listNews->clear(); listNews->clear();
refreshNewsList(); refreshNewsList();
} }*/
} }
// fills the newsList // fills the newsList
@ -190,25 +193,41 @@
// show the number of news for a stream, his status and an icon // show the number of news for a stream, his status and an icon
void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) { void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) {
// icon has just been download
if(type == ICON) { if(type == ICON) {
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath()))); //qDebug("###################"+rssmanager.getStream(i)->getIconPath().toUtf8());
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
}
// on click, show the age of the stream
if(type == LATENCY) {
unsigned short nbitem = rssmanager.getStream(i)->getListSize();
listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias().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")));
} }
else if(type == NEWS) { // when news are refreshed, update all informations
if(type == NEWS) {
//qDebug("###################"+rssmanager.getStream(i)->getIconPath().toUtf8());
unsigned short nbitem = rssmanager.getStream(i)->getListSize(); unsigned short nbitem = rssmanager.getStream(i)->getListSize();
listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias().toUtf8()+" "+rssmanager.getStream(i)->getIconPath().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")"); listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
if(nbitem==0) if(nbitem==0)
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red"))); listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red")));
else if(rssmanager.getStream(i)->getLastRefreshElapsed()>REFRESH_MAX_LATENCY) else if(rssmanager.getStream(i)->getLastRefreshElapsed()>REFRESH_MAX_LATENCY)
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("orange"))); listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("orange")));
else else
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("green"))); 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::BackgroundRole, QVariant(QColor(0, 255, 0, 20)));
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
if(listStreams->currentRow()==i) { if(listStreams->currentRow()==i) {
listNews->clear(); listNews->clear();
refreshNewsList(); refreshNewsList();
} }
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
} }
} }
@ -225,11 +244,6 @@
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams())); connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&))); connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&)));
refreshStreamList(); refreshStreamList();
unsigned short nbstream = rssmanager.getNbStream();
for(unsigned short i=0; i<nbstream; i++) {
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red")));
}
refreshTextBrowser(); refreshTextBrowser();
} }

Loading…
Cancel
Save