diff --git a/src/addTorrentDialog.ui b/src/addTorrentDialog.ui
index d4c0a77c5..b4e1a0986 100644
--- a/src/addTorrentDialog.ui
+++ b/src/addTorrentDialog.ui
@@ -13,21 +13,12 @@
Torrent addition dialog
+
+ 9
+
6
-
- 9
-
-
- 9
-
-
- 9
-
-
- 9
-
-
@@ -57,21 +48,12 @@
-
+
+ 0
+
6
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
@@ -126,21 +108,12 @@
-
+
+ 0
+
6
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
diff --git a/src/downloadThread.h b/src/downloadThread.h
index c772ccc55..4b0665087 100644
--- a/src/downloadThread.h
+++ b/src/downloadThread.h
@@ -28,14 +28,10 @@
#include
#include
#include
+#include
#include
-#include
-#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 {
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 {
}
}
- 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 {
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;
}
- dest_file.close();
- url_stream.close();
- emit downloadFinished(url, filePath);
- qDebug("In Download thread RUN, signal emitted");
+ 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);
+ }
+ }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);
diff --git a/src/properties.ui b/src/properties.ui
index 072a1b942..5152e9f6b 100644
--- a/src/properties.ui
+++ b/src/properties.ui
@@ -13,21 +13,12 @@
Torrent Properties
+
+ 9
+
6
-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 0
-
-
- 0
-
-
@@ -906,21 +759,12 @@
-
+
+ 0
+
6
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
@@ -983,21 +827,12 @@
Torrent content
+
+ 9
+
6
-
- 9
-
-
- 9
-
-
- 9
-
-
- 9
-
-
@@ -1071,21 +906,12 @@
-
+
+ 0
+
6
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
diff --git a/src/rss.h b/src/rss.h
index 15ddc2279..598792889 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -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{
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{
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{
return listItem.size();
}
+ unsigned short getNbNonRead() const{
+ int i=0, nbnonread=0;
+ for(i=0; iisRead())
+ nbnonread++;
+ }
+ return nbnonread;
+ }
+
QList getListItem() const{
return listItem;
}
@@ -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:
diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp
index 9b0efcdf6..1ac8c51dc 100644
--- a/src/rss_imp.cpp
+++ b/src/rss_imp.cpp
@@ -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")));