From 1fb848e9edb540ce9feeb2dfa28e5b0e5bfdf3dc Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 20 Jul 2007 20:18:18 +0000 Subject: [PATCH] - Added download from url handling in GUI (still missing: search plugin update and rss) --- TODO | 1 + src/GUI.cpp | 6 ++++++ src/GUI.h | 1 + src/bittorrent.cpp | 11 +++++------ src/bittorrent.h | 3 ++- src/downloadThread.h | 30 +++++++++++++++++++++++++++++- 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index c917e564d..10b5d6033 100644 --- a/TODO +++ b/TODO @@ -28,6 +28,7 @@ // in v1.1.0 - Tabs support in search +- Have a look at libcommoncpp2 to see if it can be useful for other stuff than url downloading // in v1.0.0 (partial) - WIP - Check storage st creation + hasher in torrent creation diff --git a/src/GUI.cpp b/src/GUI.cpp index c82e5c634..a4a86c4bd 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -152,6 +152,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ connect(BTSession, SIGNAL(peerBlocked(const QString&)), this, SLOT(addLogPeerBlocked(const QString))); connect(BTSession, SIGNAL(scanDirFoundTorrents(const QStringList&)), this, SLOT(processScannedFiles(const QStringList&))); connect(BTSession, SIGNAL(newDownloadedTorrent(const QString&, const QString&)), this, SLOT(processDownloadedFiles(const QString&, const QString&))); + connect(BTSession, SIGNAL(downloadFromUrlFailure(const QString&, const QString&)), this, SLOT(handleDownloadFromUrlFailure(const QString&, const QString&))); connect(BTSession, SIGNAL(aboutToDownloadFromUrl(const QString&)), this, SLOT(displayDownloadingUrlInfos(const QString&))); // creating options options = new options_imp(this); @@ -394,6 +395,11 @@ void GUI::on_actionSet_upload_limit_triggered(){ new BandwidthAllocationDialog(this, true, BTSession, hashes); } +void GUI::handleDownloadFromUrlFailure(const QString& url, const QString& reason){ + // Display a message box + QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download url: %1, reason: %2.").arg(url).arg(reason)); +} + void GUI::on_actionSet_global_upload_limit_triggered(){ qDebug("actionSet_global_upload_limit_triggered"); new BandwidthAllocationDialog(this, true, BTSession, QStringList()); diff --git a/src/GUI.h b/src/GUI.h index a508878f2..2b0dc7217 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -153,6 +153,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void displayUpTab(); void displaySearchTab(); void displayRSSTab(); + void handleDownloadFromUrlFailure(const QString&, const QString&); // Torrent actions void showProperties(const QModelIndex &index); void on_actionTorrent_Properties_triggered(); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 825e2e3a7..482be307e 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -51,6 +51,7 @@ bittorrent::bittorrent(){ // To download from urls downloader = new downloadThread(this); connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&))); + connect(downloader, SIGNAL(downloadFailure(const QString&, const QString&)), this, SLOT(HandleDownloadFailure(const QString&, const QString&))); } // Main destructor @@ -78,6 +79,10 @@ void bittorrent::setUploadLimit(QString hash, int val){ saveTorrentSpeedLimits(hash); } +void bittorrent::HandleDownloadFailure(const QString& url, const QString& reason){ + emit downloadFromUrlFailure(url, reason); +} + void bittorrent::updateETAs(){ std::vector handles = s->get_torrents(); for(unsigned int i=0; i ports); void setMaxConnections(int maxConnec); @@ -150,13 +151,13 @@ class bittorrent : public QObject{ void trackerError(const QString& hash, const QString& time, const QString& msg); void portListeningFailure(); void trackerAuthenticationRequired(torrent_handle& h); - void downloadFromUrlFailure(const QString& url, const QString& error); void scanDirFoundTorrents(const QStringList& pathList); void newDownloadedTorrent(const QString& path, const QString& url); void aboutToDownloadFromUrl(const QString& url); void updateFileSize(QString hash); void allTorrentsFinishedChecking(); void peerBlocked(const QString&); + void downloadFromUrlFailure(const QString& url, const QString& reason); }; diff --git a/src/downloadThread.h b/src/downloadThread.h index 309a1fd80..c772ccc55 100644 --- a/src/downloadThread.h +++ b/src/downloadThread.h @@ -49,6 +49,7 @@ class downloadThread : public QThread { signals: void downloadFinished(const QString& url, const QString& file_path); + void downloadFailure(const QString& url, const QString& reason); public: downloadThread(QObject* parent) : QThread(parent){ @@ -78,6 +79,33 @@ 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{ @@ -104,10 +132,10 @@ class downloadThread : public QThread { URLStream::Error status = url_stream.get((const char*)url.toUtf8()); if(status){ // Failure - //TODO: handle this 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; } qDebug("Downloading %s...", (const char*)url.toUtf8());