From 9a14c4c5992840349a71fa487e72a100a4e26905 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 25 Aug 2009 09:19:02 +0000 Subject: [PATCH] - FEATURE: A random listening port can be chosen automatically --- Changelog | 1 + src/GUI.cpp | 2 +- src/bittorrent.cpp | 3 +- src/bittorrent.h | 2 +- src/downloadingTorrents.cpp | 4 +- src/options.ui | 51 +++++++++----------------- src/options_imp.cpp | 36 ++++++++---------- src/options_imp.h | 4 +- src/search_engine/engines/piratebay.py | 8 ++-- src/search_engine/engines/versions.txt | 2 +- 10 files changed, 47 insertions(+), 66 deletions(-) diff --git a/Changelog b/Changelog index 2c2c717ca..d9c81fcc2 100644 --- a/Changelog +++ b/Changelog @@ -10,6 +10,7 @@ - FEATURE: RSS feeds can now be grouped into folders - FEATURE: Added "Unread" item to RSS feed list to display all unread news - FEATURE: If a torrent contains a torrent file, process downloaded torrent file too + - FEATURE: A random listening port can be chosen automatically - BUGFIX: torrent resume code rewrited - COSMETIC: Redesigned search tab to improve usability - COSMETIC: Redesigned RSS tab to improve usability diff --git a/src/GUI.cpp b/src/GUI.cpp index 4a7a3b0c7..6e92915b3 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -1027,7 +1027,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis // Connection // * Ports binding unsigned short old_listenPort = BTSession->getListenPort(); - BTSession->setListeningPortsRange(options->getPorts()); + BTSession->setListeningPort(options->getPort()); unsigned short new_listenPort = BTSession->getListenPort(); if(new_listenPort != old_listenPort) { BTSession->addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg( misc::toQString(new_listenPort))); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index ff72b6999..3d0d95126 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1084,7 +1084,8 @@ void bittorrent::disableDirectoryScanning() { // Set the ports range in which is chosen the port the bittorrent // session will listen to -void bittorrent::setListeningPortsRange(std::pair ports) { +void bittorrent::setListeningPort(int port) { + std::pair ports(port, port); s->listen_on(ports); } diff --git a/src/bittorrent.h b/src/bittorrent.h index 0fcc99248..fb60900d2 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -141,7 +141,7 @@ class bittorrent : public QObject { void decreaseDlTorrentPriority(QString hash); void downloadUrlAndSkipDialog(QString url, QString save_path=QString::null); // Session configuration - Setters - void setListeningPortsRange(std::pair ports); + void setListeningPort(int port); void setMaxConnections(int maxConnec); void setMaxConnectionsPerTorrent(int max); void setMaxUploadsPerTorrent(int max); diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index 66d565f8c..1f6b31ec2 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -64,10 +64,10 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded")); DLListModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("DL Speed", "i.e: Download speed")); DLListModel->setHeaderData(UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed")); - DLListModel->setHeaderData(SEEDSLEECH, Qt::Horizontal, tr("Seeds/Leechs", "i.e: full/partial sources")); + DLListModel->setHeaderData(SEEDSLEECH, Qt::Horizontal, tr("Seeds/Leechers", "i.e: full/partial sources")); DLListModel->setHeaderData(RATIO, Qt::Horizontal, tr("Ratio")); DLListModel->setHeaderData(ETA, Qt::Horizontal, tr("ETA", "i.e: Estimated Time of Arrival / Time left")); - DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Priority")); + DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, "#"); downloadList->setModel(DLListModel); downloadList->setRootIsDecorated(false); downloadList->setAllColumnsShowFocus(true); diff --git a/src/options.ui b/src/options.ui index 41a940ec8..0f4ab4531 100644 --- a/src/options.ui +++ b/src/options.ui @@ -122,7 +122,7 @@ - Network + Connection AlignHCenter|AlignVCenter|AlignCenter @@ -465,7 +465,7 @@ - Transfer lists double-click action + Action for double click @@ -490,17 +490,17 @@ - Pause/Start torrent + Start/Stop - Open destination folder + Open folder - Display torrent properties + Show properties @@ -533,17 +533,17 @@ - Pause/Start torrent + Start/Stop - Open destination folder + Open folder - Display torrent properties + Show properties @@ -1052,17 +1052,17 @@ - Port range: + Port used for incoming connections: - + 1000 - 65525 + 65535 6881 @@ -1070,25 +1070,9 @@ - + - to - - - Qt::AlignCenter - - - - - - - 1000 - - - 65525 - - - 6889 + Random @@ -1783,7 +1767,7 @@ false - 65525 + 65535 8080 @@ -1978,7 +1962,7 @@ false - 65525 + 65535 8080 @@ -2315,7 +2299,7 @@ true - 65525 + 65535 80 @@ -2659,8 +2643,7 @@ checkStartPaused checkScanDir browseScanDirButton - spinPortMin - spinPortMax + spinPort checkUPnP checkNATPMP checkDHT diff --git a/src/options_imp.cpp b/src/options_imp.cpp index 388a1262a..1b536432b 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -49,6 +49,9 @@ #include #endif +#include +#include + #include "options_imp.h" #include "misc.h" @@ -187,8 +190,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(checkScanDir, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(textScanDir, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); // Connection tab - connect(spinPortMin, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); - connect(spinPortMax, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); + connect(spinPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkUPnP, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkNATPMP, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkUploadLimit, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); @@ -319,8 +321,6 @@ void options_imp::saveOptions(){ QSettings settings("qBittorrent", "qBittorrent"); // Apply style useStyle(); - // Check if min port < max port - checkPortsLogic(); settings.beginGroup("Preferences"); // General preferences settings.beginGroup("General"); @@ -352,8 +352,7 @@ void options_imp::saveOptions(){ settings.endGroup(); // Connection preferences settings.beginGroup("Connection"); - settings.setValue(QString::fromUtf8("PortRangeMin"), getPorts().first); - settings.setValue(QString::fromUtf8("PortRangeMax"), getPorts().second); + settings.setValue(QString::fromUtf8("PortRangeMin"), getPort()); settings.setValue(QString::fromUtf8("UPnP"), isUPnPEnabled()); settings.setValue(QString::fromUtf8("NAT-PMP"), isNATPMPEnabled()); settings.setValue(QString::fromUtf8("GlobalDLLimit"), getGlobalBandwidthLimits().first); @@ -578,10 +577,7 @@ void options_imp::loadOptions(){ settings.endGroup(); // Connection preferences settings.beginGroup("Connection"); - spinPortMin->setValue(settings.value(QString::fromUtf8("PortRangeMin"), 6881).toInt()); - spinPortMax->setValue(settings.value(QString::fromUtf8("PortRangeMax"), 6889).toInt()); - // Check if min port < max port - checkPortsLogic(); + spinPort->setValue(settings.value(QString::fromUtf8("PortRangeMin"), 6881).toInt()); checkUPnP->setChecked(settings.value(QString::fromUtf8("UPnP"), true).toBool()); checkNATPMP->setChecked(settings.value(QString::fromUtf8("NAT-PMP"), true).toBool()); intValue = settings.value(QString::fromUtf8("GlobalDLLimit"), -1).toInt(); @@ -777,12 +773,19 @@ void options_imp::loadOptions(){ textWebUiPassword->setText(settings.value("Password", "").toString()); // End Web UI settings.endGroup(); + // Random stuff + srand(time(0)); } // return min & max ports // [min, max] -std::pair options_imp::getPorts() const{ - return std::make_pair(spinPortMin->value(), spinPortMax->value()); +int options_imp::getPort() const{ + return spinPort->value(); +} + +void options_imp::on_randomButton_clicked() { + // Range [1024: 65535] + spinPort->setValue(rand() % 64512 + 1024); } int options_imp::getEncryptionSetting() const{ @@ -1317,15 +1320,6 @@ void options_imp::setLocale(QString locale){ } } -// Is called before saving to check if minPort < maxPort -void options_imp::checkPortsLogic(){ - int maxValue = spinPortMax->value(); - if(spinPortMin->value() > spinPortMax->value()){ - spinPortMax->setValue(spinPortMin->value()); - spinPortMin->setValue(maxValue); - } -} - // Return scan dir set in options QString options_imp::getScanDir() const { if(checkScanDir->isChecked()){ diff --git a/src/options_imp.h b/src/options_imp.h index 313a8f079..537a8845e 100644 --- a/src/options_imp.h +++ b/src/options_imp.h @@ -88,7 +88,7 @@ class options_imp : public QDialog, private Ui::Dialog { int getActionOnDblClOnTorrentDl() const; int getActionOnDblClOnTorrentFn() const; // Connection options - std::pair getPorts() const; + int getPort() const; bool isUPnPEnabled() const; bool isNATPMPEnabled() const; QPair getGlobalBandwidthLimits() const; @@ -165,13 +165,13 @@ class options_imp : public QDialog, private Ui::Dialog { void on_browseFilterButton_clicked(); void on_browseSaveDirButton_clicked(); void enableApplyButton(); - void checkPortsLogic(); void enableSystrayOptions(); void disableSystrayOptions(); void setSystrayOptionsState(int checkBoxValue); void enableWebUi(bool checkBoxValue); void changePage(QListWidgetItem*, QListWidgetItem*); void adaptToScreenSize(); + void on_randomButton_clicked(); public slots: void setLocale(QString locale); diff --git a/src/search_engine/engines/piratebay.py b/src/search_engine/engines/piratebay.py index baa47a02c..0d6d70194 100644 --- a/src/search_engine/engines/piratebay.py +++ b/src/search_engine/engines/piratebay.py @@ -1,5 +1,6 @@ -#VERSION: 1.11 +#VERSION: 1.20 #AUTHORS: Fabien Devaux (fab@gnux.info) +#CONTRIBUTORS: Christophe Dumez (chris@qbittorrent.org) # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -32,7 +33,8 @@ from helpers import retrieve_url, download_file class piratebay(object): url = 'http://thepiratebay.org' name = 'The Pirate Bay' - + supported_categories = {'all': '', 'movies': '', 'music': '', 'games': '', 'software': ''} + def __init__(self): self.results = [] self.parser = self.SimpleSGMLParser(self.results, self.url) @@ -92,7 +94,7 @@ class piratebay(object): self.current_item['leech'] = 0 prettyPrinter(self.current_item) self.results.append('a') - def search(self, what): + def search(self, what, cat='all'): ret = [] i = 0 order = 'se' diff --git a/src/search_engine/engines/versions.txt b/src/search_engine/engines/versions.txt index 284c36b5a..25db9442b 100644 --- a/src/search_engine/engines/versions.txt +++ b/src/search_engine/engines/versions.txt @@ -1,5 +1,5 @@ isohunt: 1.30 -torrentreactor: 1.11 +torrentreactor: 1.20 btjunkie: 2.21 mininova: 1.31 piratebay: 1.11