Browse Source

rss : show the number of NONREAD news (local test succeeded, need tests)

rss : clean the file rss.h
rss : display the site favicon (local test succeeded, need tests)

bug that i've noticed but not fixed :
_ something create qt_temp files without delete them
_ in dl list, columns disappear
adaptive-webui-19844
Arnaud Demaiziere 18 years ago
parent
commit
7edc89638f
  1. 45
      src/addTorrentDialog.ui
  2. 130
      src/downloadThread.h
  3. 312
      src/properties.ui
  4. 39
      src/rss.h
  5. 2
      src/rss_imp.cpp

45
src/addTorrentDialog.ui

@ -13,20 +13,11 @@ @@ -13,20 +13,11 @@
<string>Torrent addition dialog</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="fileNameLbl" >
@ -57,20 +48,11 @@ @@ -57,20 +48,11 @@
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLineEdit" name="savePathTxt" />
@ -126,20 +108,11 @@ @@ -126,20 +108,11 @@
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>

130
src/downloadThread.h

@ -28,14 +28,10 @@ @@ -28,14 +28,10 @@
#include <QMutex>
#include <QMutexLocker>
#include <QWaitCondition>
#include <curl/curl.h>
#include <iostream>
#include <cc++/common.h>
#include "misc.h"
#ifdef CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif
#include "misc.h"
class downloadThread : public QThread {
Q_OBJECT
@ -45,11 +41,9 @@ class downloadThread : public QThread { @@ -45,11 +41,9 @@ class downloadThread : public QThread {
QMutex mutex;
QWaitCondition condition;
bool abort;
URLStream url_stream;
signals:
void downloadFinished(const QString& url, const QString& file_path);
void downloadFailure(const QString& url, const QString& reason);
void downloadFinished(const QString& url, const QString& file_path, int return_code, const QString& errorBuffer);
public:
downloadThread(QObject* parent) : QThread(parent){
@ -79,33 +73,6 @@ class downloadThread : public QThread { @@ -79,33 +73,6 @@ class downloadThread : public QThread {
}
}
QString errorCodeToString(URLStream::Error status){
switch(status){
case URLStream::errUnreachable:
return tr("Host is unreachable");
case URLStream::errMissing:
return tr("File was not found (404)");
case URLStream::errDenied:
return tr("Connection was denied");
case URLStream::errInvalid:
return tr("Url is invalid");
case URLStream::errForbidden:
return tr("Connection forbidden (403)");
case URLStream::errUnauthorized:
return tr("Connection was not authorized (401)");
case URLStream::errRelocated:
return tr("Content has moved (301)");
case URLStream::errFailure:
return tr("Connection failure");
case URLStream::errTimeout:
return tr("Connection was timed out");
case URLStream::errInterface:
return tr("Incorrect network interface");
default:
return tr("Unknown error");
}
}
protected:
void run(){
forever{
@ -117,41 +84,80 @@ class downloadThread : public QThread { @@ -117,41 +84,80 @@ class downloadThread : public QThread {
QString url = url_list.takeFirst();
mutex.unlock();
qDebug("In Download thread RUN, mutex unlocked (got url)");
// XXX: Trick to get a unique filename
CURL *curl;
QString filePath;
QTemporaryFile *tmpfile = new QTemporaryFile();
int return_code, response;
// XXX: Trick to get a unique filename
QTemporaryFile *tmpfile = new QTemporaryFile;
if (tmpfile->open()) {
filePath = tmpfile->fileName();
}
delete tmpfile;
QFile dest_file(filePath);
if(!dest_file.open(QIODevice::WriteOnly | QIODevice::Text)){
std::cerr << "Error: could't create temporary file: " << (const char*)filePath.toUtf8() << '\n';
continue;
if(abort)
return;
FILE *file = fopen((const char*)filePath.toUtf8(), "w");
if(!file){
std::cerr << "Error: could not open temporary file...\n";
return;
}
URLStream::Error status = url_stream.get((const char*)url.toUtf8());
if(status){
// Failure
QString error_msg = QString(misc::toString(status).c_str());
qDebug("Download failed for %s, reason: %s", (const char*)url.toUtf8(), (const char*)error_msg.toUtf8());
url_stream.close();
emit downloadFailure(url, errorCodeToString(status));
continue;
// Initilization required by libcurl
curl = curl_easy_init();
if(!curl){
std::cerr << "Error: Failed to init curl...\n";
fclose(file);
return;
}
qDebug("Downloading %s...", (const char*)url.toUtf8());
char cbuf[1024];
int len;
while(!url_stream.eof()) {
url_stream.read(cbuf, sizeof(cbuf));
len = url_stream.gcount();
if(len > 0){
dest_file.write(cbuf, len);
// Set url to download
curl_easy_setopt(curl, CURLOPT_URL, url.toLocal8Bit().constData());
qDebug("Url: %s", url.toLocal8Bit().constData());
// Define our callback to get called when there's data to be written
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, misc::my_fwrite);
// Set destination file
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
// Some SSL mambo jambo
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
// Disable progress meter
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
// Any kind of authentication
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// Auto referrer
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1);
// Follow redirections
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
// Enable cookies
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
// We want error message:
char errorBuffer[CURL_ERROR_SIZE];
errorBuffer[0]=0; /* prevent junk from being output */
return_code = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
if(return_code){
std::cerr << "Error: failed to set error buffer in curl\n";
fclose(file);
QFile::remove(filePath);
return;
}
unsigned short retries = 0;
bool to_many_users = false;
do{
// Perform Download
return_code = curl_easy_perform(curl);
// We want HTTP response code
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
qDebug("HTTP response code: %d", response);
if(response/100 == 5){
to_many_users = true;
++retries;
SleeperThread::msleep(1000);
}
dest_file.close();
url_stream.close();
emit downloadFinished(url, filePath);
qDebug("In Download thread RUN, signal emitted");
}while(to_many_users && retries < 10 && response!=0);
// Cleanup
curl_easy_cleanup(curl);
// Close tmp file
fclose(file);
emit downloadFinished(url, filePath, return_code, QString(errorBuffer));
qDebug("In Download thread RUN, signal emitted, ErrorBuffer: %s", errorBuffer);
}else{
qDebug("In Download thread RUN, mutex still locked (no urls) -> sleeping");
condition.wait(&mutex);

312
src/properties.ui

@ -13,20 +13,11 @@ @@ -13,20 +13,11 @@
<string>Torrent Properties</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QTabWidget" name="torrentContent" >
@ -38,20 +29,11 @@ @@ -38,20 +29,11 @@
<string>Main infos</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="fileName" >
@ -99,54 +81,27 @@ @@ -99,54 +81,27 @@
<string>Torrent infos</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="savePath_lbl" >
@ -234,20 +189,11 @@ @@ -234,20 +189,11 @@
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="save_path" >
@ -330,7 +276,9 @@ @@ -330,7 +276,9 @@
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -356,54 +304,27 @@ @@ -356,54 +304,27 @@
<string>Current session</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_5" >
@ -481,20 +402,11 @@ @@ -481,20 +402,11 @@
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="upTotal" >
@ -569,25 +481,18 @@ @@ -569,25 +481,18 @@
<string>Trackers</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -613,37 +518,19 @@ @@ -613,37 +518,19 @@
<string>Tracker</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_9" >
@ -665,25 +552,18 @@ @@ -665,25 +552,18 @@
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QListWidget" name="trackersURLS" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -692,20 +572,11 @@ @@ -692,20 +572,11 @@
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
@ -777,20 +648,11 @@ @@ -777,20 +648,11 @@
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
@ -862,20 +724,11 @@ @@ -862,20 +724,11 @@
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_10" >
@ -906,20 +759,11 @@ @@ -906,20 +759,11 @@
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_2" >
@ -983,20 +827,11 @@ @@ -983,20 +827,11 @@
<string>Torrent content</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<property name="margin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_4" >
@ -1071,20 +906,11 @@ @@ -1071,20 +906,11 @@
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>

39
src/rss.h

@ -142,33 +142,15 @@ class RssStream : public QObject{ @@ -142,33 +142,15 @@ class RssStream : public QObject{
QFile::remove(filePath);
}
filePath = file_path;
// if(return_code){
// // Download failed
// qDebug("(download failure) "+file_path.toUtf8());
// if(QFile::exists(filePath)) {
// QFile::remove(filePath);
// }
// emit refreshFinished(url, NEWS);
// return;
// }
openRss();
emit refreshFinished(url, NEWS);
}
void displayIcon(const QString&, const QString& file_path, int, const QString&) {
/*if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") {
QFile::remove(iconPath);
}
// display the icon in the rss window
void displayIcon(const QString&, const QString& file_path, int return_code, const QString&) {
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());
if(QFile::exists(iconPath) && iconPath!=":/Icons/rss.png") {
QFile::remove(iconPath);
}
@ -177,8 +159,7 @@ class RssStream : public QObject{ @@ -177,8 +159,7 @@ class RssStream : public QObject{
return;
}
openIcon();
emit refreshFinished(url, ICON);*/
qDebug("******************Icone downloaded"+file_path.toUtf8());
emit refreshFinished(url, ICON);
}
public:
@ -193,7 +174,7 @@ class RssStream : public QObject{ @@ -193,7 +174,7 @@ class RssStream : public QObject{
downloaderRss->downloadUrl(url);
// XXX: remove it when gif can be displayed
iconPath = ":/Icons/rss.png";
//getIcon();
getIcon();
lastRefresh.start();
}
@ -265,6 +246,15 @@ class RssStream : public QObject{ @@ -265,6 +246,15 @@ class RssStream : public QObject{
return listItem.size();
}
unsigned short getNbNonRead() const{
int i=0, nbnonread=0;
for(i=0; i<listItem.size(); i++) {
if(!listItem.at(i)->isRead())
nbnonread++;
}
return nbnonread;
}
QList<RssItem*> getListItem() const{
return listItem;
}
@ -285,13 +275,12 @@ class RssStream : public QObject{ @@ -285,13 +275,12 @@ class RssStream : public QObject{
read = true;
}
// FIXME : always return an empty file
// download the icon from the adress
void getIcon() {
QUrl siteUrl(url);
QString iconUrl = "http://"+siteUrl.host()+"/favicon.ico";
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:

2
src/rss_imp.cpp

@ -239,7 +239,7 @@ @@ -239,7 +239,7 @@
}
// on click, show the age of the stream
if(type == LATENCY) {
unsigned short nbitem = rssmanager.getStream(i)->getListSize();
unsigned short nbitem = rssmanager.getStream(i)->getNbNonRead();
listStreams->topLevelItem(i)->setText(0,rssmanager.getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
if(nbitem==0)
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("red")));

Loading…
Cancel
Save