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

79
src/rss.h

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

38
src/rss_imp.cpp

@ -66,6 +66,8 @@ @@ -66,6 +66,8 @@
void RSSImp::on_listStreams_clicked() {
rssmanager.getStream(listStreams->currentRow())->setRead();
listStreams->item(listStreams->currentRow())->setData(Qt::BackgroundRole, QVariant(QColor("white")));
// update the color of the stream, is it old ?
updateStreamName(listStreams->currentRow(), LATENCY);
refreshNewsList();
}
@ -150,17 +152,18 @@ @@ -150,17 +152,18 @@
// fills the streamList
void RSSImp::refreshStreamList() {
short currentStream = listStreams->currentRow();
//short currentStream = listStreams->currentRow();
unsigned short nbstream = rssmanager.getNbStream();
listStreams->clear();
for(unsigned short i=0; i<nbstream; i++) {
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);
listNews->clear();
refreshNewsList();
}
}*/
}
// fills the newsList
@ -190,25 +193,41 @@ @@ -190,25 +193,41 @@
// show the number of news for a stream, his status and an icon
void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) {
// icon has just been download
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();
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)
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(rssmanager.getStream(i)->getIconPath())));
if(listStreams->currentRow()==i) {
listNews->clear();
refreshNewsList();
}
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
}
}
@ -225,11 +244,6 @@ @@ -225,11 +244,6 @@
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&)));
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();
}

Loading…
Cancel
Save