Browse Source

- Fixed download from url function (should be a lot less buggy). It improves downloads from search engine since it uses this function

- Removed torrentReactor search engine (hopefully temporarilly) because I can't manage to download from their links using libcurl
- When HTTP response code is 500 (5xx in fact: too busy), downloader will retry 10 times every second.
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
a072247e70
  1. 2
      Changelog
  2. 1
      TODO
  3. 26
      src/GUI.cpp
  4. 7
      src/MainWindow.ui
  5. 26
      src/downloadThread.h

2
Changelog

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
- FEATURE: Rewritten parts of the download/search lists to improve performance
- FEATURE: Individual share ratio is now displayed in each torrent properties.
- FEATURE: Tuned default settings to improve download speed
- FEATURE: Downloading from an URL will retry 10 times if too many users.
- I18N: Added Norwegian translation
- BUGFIX: Fixed a memory leak when pressing OK in torrent properties
- BUGFIX: Improved code so that GUI never freeze during downloading from an url
@ -27,6 +28,7 @@ @@ -27,6 +28,7 @@
- BUGFIX: Fixed problems that could happen with delete selection action
- BUGFIX: Fixed an arithmetic exception that could happen in ETA calculation
- BUGFIX: Fixed Isohunt search engine
- BUGFIX: Fixed download from URL function (was buggy)
- COSMETIC: Now displaying the number of downloads in tab title
- COSMETIC: Redesigned download from url dialog
- COSMETIC: Added a message to warn user that we started download from an url

1
TODO

@ -34,5 +34,4 @@ @@ -34,5 +34,4 @@
// Before 0.7.0
- Test tracker authentication
- Wait for libtorrent v0.11rc release
- Fix curl downloader to work with TorrentReactor engine

26
src/GUI.cpp

@ -216,7 +216,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ @@ -216,7 +216,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
// Set search engines names
mininova->setText("Mininova");
piratebay->setText("ThePirateBay");
reactor->setText("TorrentReactor");
// reactor->setText("TorrentReactor");
isohunt->setText("Isohunt");
btjunkie->setText("BTJunkie");
meganova->setText("Meganova");
@ -224,7 +224,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ @@ -224,7 +224,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
loadCheckedSearchEngines();
connect(mininova, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
connect(piratebay, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
connect(reactor, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
// connect(reactor, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
connect(isohunt, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
connect(btjunkie, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
connect(meganova, SIGNAL(stateChanged(int)), this, SLOT(saveCheckedSearchEngines(int)));
@ -761,8 +761,8 @@ void GUI::saveCheckedSearchEngines(int) const{ @@ -761,8 +761,8 @@ void GUI::saveCheckedSearchEngines(int) const{
lastSearchEngines.write(QByteArray("mininova\n"));
if(piratebay->isChecked())
lastSearchEngines.write(QByteArray("piratebay\n"));
if(reactor->isChecked())
lastSearchEngines.write(QByteArray("reactor\n"));
// if(reactor->isChecked())
// lastSearchEngines.write(QByteArray("reactor\n"));
if(isohunt->isChecked())
lastSearchEngines.write(QByteArray("isohunt\n"));
if(btjunkie->isChecked())
@ -893,11 +893,11 @@ void GUI::loadCheckedSearchEngines(){ @@ -893,11 +893,11 @@ void GUI::loadCheckedSearchEngines(){
}else{
piratebay->setChecked(false);
}
if(searchEnginesList.indexOf("reactor\n") != -1){
reactor->setChecked(true);
}else{
reactor->setChecked(false);
}
// if(searchEnginesList.indexOf("reactor\n") != -1){
// reactor->setChecked(true);
// }else{
// reactor->setChecked(false);
// }
if(searchEnginesList.indexOf("isohunt\n") != -1){
isohunt->setChecked(true);
}else{
@ -1770,7 +1770,7 @@ void GUI::on_search_button_clicked(){ @@ -1770,7 +1770,7 @@ void GUI::on_search_button_clicked(){
return;
}
// Getting checked search engines
if(!mininova->isChecked() && ! piratebay->isChecked() && !reactor->isChecked() && !isohunt->isChecked() && !btjunkie->isChecked() && !meganova->isChecked()){
if(!mininova->isChecked() && ! piratebay->isChecked()/* && !reactor->isChecked()*/ && !isohunt->isChecked() && !btjunkie->isChecked() && !meganova->isChecked()){
QMessageBox::critical(0, tr("No seach engine selected"), tr("You must select at least one search engine."));
return;
}
@ -1784,9 +1784,9 @@ void GUI::on_search_button_clicked(){ @@ -1784,9 +1784,9 @@ void GUI::on_search_button_clicked(){
if(piratebay->isChecked()){
engineNames << "piratebay";
}
if(reactor->isChecked()){
engineNames << "reactor";
}
// if(reactor->isChecked()){
// engineNames << "reactor";
// }
if(isohunt->isChecked()){
engineNames << "isohunt";
}

7
src/MainWindow.ui

@ -404,13 +404,6 @@ @@ -404,13 +404,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="reactor" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="isohunt" >
<property name="text" >

26
src/downloadThread.h

@ -49,9 +49,12 @@ class downloadThread : public QThread { @@ -49,9 +49,12 @@ class downloadThread : public QThread {
void downloadUrl(const QString& url){
mutex.lock();
qDebug("In Download thread function, mutex locked");
url_list << url;
mutex.unlock();
qDebug("In Download thread function, mutex unlocked (url added)");
if(!isRunning()){
qDebug("In Download thread function, Launching thread (was stopped)");
start();
}
}
@ -59,12 +62,14 @@ class downloadThread : public QThread { @@ -59,12 +62,14 @@ class downloadThread : public QThread {
void run(){
forever{
mutex.lock();
qDebug("In Download thread RUN, mutex locked");
if(url_list.size() != 0){
QString url = url_list.takeFirst();
mutex.unlock();
qDebug("In Download thread RUN, mutex unlocked (got url)");
CURL *curl;
std::string filePath;
int return_code;
int return_code, response;
// XXX: Trick to get a unique filename
QTemporaryFile *tmpfile = new QTemporaryFile;
if (tmpfile->open()) {
@ -83,8 +88,10 @@ class downloadThread : public QThread { @@ -83,8 +88,10 @@ class downloadThread : public QThread {
fclose(file);
return;
}
std::string urlString = url.toStdString();
// Set url to download
curl_easy_setopt(curl, CURLOPT_URL, (void*) url.toStdString().c_str());
curl_easy_setopt(curl, CURLOPT_URL, urlString.c_str());
qDebug("Url: %s", urlString.c_str());
// 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
@ -104,6 +111,7 @@ class downloadThread : public QThread { @@ -104,6 +111,7 @@ class downloadThread : public QThread {
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::cout << "Error: failed to set error buffer in curl\n";
@ -111,15 +119,29 @@ class downloadThread : public QThread { @@ -111,15 +119,29 @@ class downloadThread : public QThread {
QFile::remove(filePath.c_str());
return;
}
int 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);
// Cleanup
curl_easy_cleanup(curl);
// Close tmp file
fclose(file);
emit downloadFinished(url, QString(filePath.c_str()), return_code, QString(errorBuffer));
qDebug("In Download thread RUN, signal emitted, ErrorBuffer: %s", errorBuffer);
}else{
mutex.unlock();
qDebug("In Download thread RUN, mutex unlocked (no urls) -> stopping");
break;
}
}

Loading…
Cancel
Save