Browse Source

- Added download from url handling in GUI (still missing: search plugin update and rss)

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
1fb848e9ed
  1. 1
      TODO
  2. 6
      src/GUI.cpp
  3. 1
      src/GUI.h
  4. 11
      src/bittorrent.cpp
  5. 3
      src/bittorrent.h
  6. 30
      src/downloadThread.h

1
TODO

@ -28,6 +28,7 @@ @@ -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

6
src/GUI.cpp

@ -152,6 +152,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ @@ -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(){ @@ -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());

1
src/GUI.h

@ -153,6 +153,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -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();

11
src/bittorrent.cpp

@ -51,6 +51,7 @@ bittorrent::bittorrent(){ @@ -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){ @@ -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<torrent_handle> handles = s->get_torrents();
for(unsigned int i=0; i<handles.size(); ++i){
@ -1014,12 +1019,6 @@ void bittorrent::downloadFromUrl(const QString& url){ @@ -1014,12 +1019,6 @@ void bittorrent::downloadFromUrl(const QString& url){
// Add to bittorrent session the downloaded torrent file
void bittorrent::processDownloadedFile(const QString& url, const QString& file_path){
// if(return_code){
// // Download failed
// emit downloadFromUrlFailure(url, errorBuffer);
// QFile::remove(file_path);
// return;
// }
// Add file to torrent download list
emit newDownloadedTorrent(file_path, url);
}

3
src/bittorrent.h

@ -117,6 +117,7 @@ class bittorrent : public QObject{ @@ -117,6 +117,7 @@ class bittorrent : public QObject{
void loadTorrentSpeedLimits(QString hash);
void saveDownloadUploadForTorrent(QString hash);
void loadDownloadUploadForTorrent(QString hash);
void HandleDownloadFailure(const QString& url, const QString& reason);
// Session configuration - Setters
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
void setMaxConnections(int maxConnec);
@ -150,13 +151,13 @@ class bittorrent : public QObject{ @@ -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);
};

30
src/downloadThread.h

@ -49,6 +49,7 @@ class downloadThread : public QThread { @@ -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 { @@ -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 { @@ -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());

Loading…
Cancel
Save