Browse Source

more clean up for feature selecting a random port when starts up

adaptive-webui-19844
tungnian lee 12 years ago committed by sledgehammer999
parent
commit
2de8b9112d
  1. 7
      src/preferences/options_imp.cpp
  2. 10
      src/preferences/preferences.h
  3. 27
      src/qtlibtorrent/qbtsession.cpp
  4. 4
      src/qtlibtorrent/qbtsession.h

7
src/preferences/options_imp.cpp

@ -138,7 +138,7 @@ options_imp::options_imp(QWidget *parent):
// General tab // General tab
connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkAltRowColors, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkAltRowColors, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
//add checkbox for random port // add checkbox for random port
connect(checkRandomPort, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkRandomPort, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkShowSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkShowSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
@ -369,7 +369,7 @@ void options_imp::saveOptions() {
// General preferences // General preferences
pref.setLocale(locale); pref.setLocale(locale);
pref.setAlternatingRowColors(checkAltRowColors->isChecked()); pref.setAlternatingRowColors(checkAltRowColors->isChecked());
//set random port // set random port
pref.setRandomPort(checkRandomPort->isChecked()); pref.setRandomPort(checkRandomPort->isChecked());
pref.setSystrayIntegration(systrayIntegration()); pref.setSystrayIntegration(systrayIntegration());
pref.setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex())); pref.setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex()));
@ -544,7 +544,7 @@ void options_imp::loadOptions() {
const Preferences pref; const Preferences pref;
setLocale(pref.getLocale()); setLocale(pref.getLocale());
checkAltRowColors->setChecked(pref.useAlternatingRowColors()); checkAltRowColors->setChecked(pref.useAlternatingRowColors());
//get random port // get random port
checkRandomPort->setChecked(pref.useRandomPort()); checkRandomPort->setChecked(pref.useRandomPort());
checkShowSystray->setChecked(pref.systrayIntegration()); checkShowSystray->setChecked(pref.systrayIntegration());
checkShowSplash->setChecked(!pref.isSlashScreenDisabled()); checkShowSplash->setChecked(!pref.isSlashScreenDisabled());
@ -798,7 +798,6 @@ void options_imp::on_randomButton_clicked() {
spinPort->setValue(rand() % 64512 + 1024); spinPort->setValue(rand() % 64512 + 1024);
} }
int options_imp::getEncryptionSetting() const { int options_imp::getEncryptionSetting() const {
return comboEncryption->currentIndex(); return comboEncryption->currentIndex();
} }

10
src/preferences/preferences.h

@ -77,8 +77,7 @@ public:
QIniSettings::sync(); QIniSettings::sync();
} }
// General options // General options
QString getLocale() const { QString getLocale() const {
return value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString(); return value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString();
} }
@ -86,7 +85,7 @@ public:
void setLocale(const QString &locale) { void setLocale(const QString &locale) {
setValue(QString::fromUtf8("Preferences/General/Locale"), locale); setValue(QString::fromUtf8("Preferences/General/Locale"), locale);
} }
bool useProgramNotification() const { bool useProgramNotification() const {
return value(QString::fromUtf8("Preferences/General/ProgramNotification"), true).toBool(); return value(QString::fromUtf8("Preferences/General/ProgramNotification"), true).toBool();
} }
@ -128,11 +127,11 @@ public:
} }
bool useRandomPort() const { bool useRandomPort() const {
return value(QString::fromUtf8("Preferences/General/RandomPort"), true).toBool(); return value(QString::fromUtf8("Preferences/General/UseRandomPort"), false).toBool();
} }
void setRandomPort(bool b) { void setRandomPort(bool b) {
setValue("Preferences/General/RandomPort", b); setValue("Preferences/General/UseRandomPort", b);
} }
bool systrayIntegration() const { bool systrayIntegration() const {
@ -1050,6 +1049,7 @@ public:
setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value); setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value);
} }
void setNetworkInterface(const QString& iface) { void setNetworkInterface(const QString& iface) {
setValue(QString::fromUtf8("Preferences/Connection/Interface"), iface); setValue(QString::fromUtf8("Preferences/Connection/Interface"), iface);
} }

27
src/qtlibtorrent/qbtsession.cpp

@ -113,9 +113,9 @@ QBtSession::QBtSession()
, geoipDBLoaded(false), resolve_countries(false) , geoipDBLoaded(false), resolve_countries(false)
#endif #endif
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN), , m_tracker(0), m_shutdownAct(NO_SHUTDOWN),
m_upnp(0), m_natpmp(0), m_dynDNSUpdater(0) m_upnp(0), m_natpmp(0), m_dynDNSUpdater(0),
m_randomPortEnabled(false)
{ {
setRandomPortset(false);
BigRatioTimer = new QTimer(this); BigRatioTimer = new QTimer(this);
BigRatioTimer->setInterval(10000); BigRatioTimer->setInterval(10000);
connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios())); connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios()));
@ -282,27 +282,24 @@ void QBtSession::setQueueingEnabled(bool enable) {
} }
} }
void QBtSession::setRandomPortset(bool set) {
randomPortSet = set;
}
// Set BT session configuration // Set BT session configuration
void QBtSession::configureSession() { void QBtSession::configureSession() {
qDebug("Configuring session"); qDebug("Configuring session");
//removed the constant modifier for Preferences
Preferences pref; Preferences pref;
const unsigned short old_listenPort = getListenPort(); const unsigned short old_listenPort = getListenPort();
const unsigned short new_listenPort = pref.getSessionPort(); const unsigned short new_listenPort = pref.getSessionPort();
if(pref.useRandomPort() && !isRandomPortset()) { // to check if the randomPort checkbox is selected if (pref.useRandomPort()) { // to check if the randomPort checkbox is selected
setRandomPortset(true); if (!m_randomPortEnabled) {
srand(time(0)); m_randomPortEnabled = true;
const unsigned short randomPort = rand() % USHRT_MAX + 1025; srand(time(0));
setListeningPort(randomPort); const unsigned short randomPort = rand() % USHRT_MAX + 1025;
addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort()))); setListeningPort(randomPort);
pref.setSessionPort(randomPort); addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort())));
pref.setSessionPort(randomPort);
}
} else { } else {
// * Ports binding // * Ports binding
m_randomPortEnabled = false;
if (old_listenPort != new_listenPort) { if (old_listenPort != new_listenPort) {
qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort); qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort);
setListeningPort(new_listenPort); setListeningPort(new_listenPort);

4
src/qtlibtorrent/qbtsession.h

@ -107,8 +107,6 @@ public:
inline bool isLSDEnabled() const { return LSDEnabled; } inline bool isLSDEnabled() const { return LSDEnabled; }
inline bool isPexEnabled() const { return PeXEnabled; } inline bool isPexEnabled() const { return PeXEnabled; }
inline bool isQueueingEnabled() const { return queueingEnabled; } inline bool isQueueingEnabled() const { return queueingEnabled; }
bool isRandomPortset() { return randomPortSet; };
void setRandomPortset(bool set);
public slots: public slots:
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
@ -259,7 +257,7 @@ private:
bool m_torrentExportEnabled; bool m_torrentExportEnabled;
bool m_finishedTorrentExportEnabled; bool m_finishedTorrentExportEnabled;
bool appendqBExtension; bool appendqBExtension;
bool randomPortSet; bool m_randomPortEnabled;
QString defaultSavePath; QString defaultSavePath;
QString defaultTempPath; QString defaultTempPath;
// IP filtering // IP filtering

Loading…
Cancel
Save