Browse Source

Made changes for clean up and fix the problem that a new ramdon port is set every time a setting is saved.

adaptive-webui-19844
tungnian lee 12 years ago committed by sledgehammer999
parent
commit
75e28bb3e6
  1. 63
      src/preferences/options.ui
  2. 7
      src/preferences/options_imp.cpp
  3. 11
      src/preferences/preferences.h
  4. 30
      src/qtlibtorrent/qbtsession.cpp
  5. 3
      src/qtlibtorrent/qbtsession.h

63
src/preferences/options.ui

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>789</width> <width>779</width>
<height>591</height> <height>591</height>
</rect> </rect>
</property> </property>
@ -177,8 +177,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>-161</y> <y>-161</y>
<width>486</width> <width>484</width>
<height>638</height> <height>693</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
@ -262,6 +262,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkRandomPort">
<property name="text">
<string>Use random port to communicate</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox_7"> <widget class="QGroupBox" name="groupBox_7">
<property name="font"> <property name="font">
@ -516,8 +526,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>482</width> <width>501</width>
<height>1025</height> <height>930</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -735,6 +745,15 @@
<attribute name="verticalHeaderVisible"> <attribute name="verticalHeaderVisible">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>80</number>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -1022,8 +1041,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>474</width> <width>451</width>
<height>577</height> <height>524</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_20"> <layout class="QVBoxLayout" name="verticalLayout_20">
@ -1466,8 +1485,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>359</width> <width>398</width>
<height>480</height> <height>458</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_33"> <layout class="QVBoxLayout" name="verticalLayout_33">
@ -1741,6 +1760,12 @@
</item> </item>
<item> <item>
<widget class="QTimeEdit" name="schedule_from"> <widget class="QTimeEdit" name="schedule_from">
<property name="displayFormat">
<string notr="true">hh:mm</string>
</property>
<property name="calendarPopup">
<bool>false</bool>
</property>
<property name="time"> <property name="time">
<time> <time>
<hour>8</hour> <hour>8</hour>
@ -1748,12 +1773,6 @@
<second>0</second> <second>0</second>
</time> </time>
</property> </property>
<property name="displayFormat">
<string notr="true">hh:mm</string>
</property>
<property name="calendarPopup">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -1768,6 +1787,9 @@
</item> </item>
<item> <item>
<widget class="QTimeEdit" name="schedule_to"> <widget class="QTimeEdit" name="schedule_to">
<property name="displayFormat">
<string notr="true">hh:mm</string>
</property>
<property name="time"> <property name="time">
<time> <time>
<hour>20</hour> <hour>20</hour>
@ -1775,9 +1797,6 @@
<second>0</second> <second>0</second>
</time> </time>
</property> </property>
<property name="displayFormat">
<string notr="true">hh:mm</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -1878,8 +1897,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>557</width> <width>546</width>
<height>555</height> <height>524</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_7">
@ -2292,8 +2311,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>426</width> <width>436</width>
<height>611</height> <height>553</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_23"> <layout class="QVBoxLayout" name="verticalLayout_23">

7
src/preferences/options_imp.cpp

@ -138,6 +138,8 @@ 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
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()));
connect(checkMinimizeToSysTray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkMinimizeToSysTray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
@ -367,6 +369,8 @@ 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
pref.setRandomPort(checkRandomPort->isChecked());
pref.setSystrayIntegration(systrayIntegration()); pref.setSystrayIntegration(systrayIntegration());
pref.setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex())); pref.setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex()));
pref.setCloseToTray(closeToTray()); pref.setCloseToTray(closeToTray());
@ -540,6 +544,8 @@ 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
checkRandomPort->setChecked(pref.useRandomPort());
checkShowSystray->setChecked(pref.systrayIntegration()); checkShowSystray->setChecked(pref.systrayIntegration());
checkShowSplash->setChecked(!pref.isSlashScreenDisabled()); checkShowSplash->setChecked(!pref.isSlashScreenDisabled());
if (checkShowSystray->isChecked()) { if (checkShowSystray->isChecked()) {
@ -792,6 +798,7 @@ 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();
} }

11
src/preferences/preferences.h

@ -78,6 +78,7 @@ public:
} }
// 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();
} }
@ -85,7 +86,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();
} }
@ -126,6 +127,14 @@ public:
setValue("Preferences/General/AlternatingRowColors", b); setValue("Preferences/General/AlternatingRowColors", b);
} }
bool useRandomPort() const {
return value(QString::fromUtf8("Preferences/General/RandomPort"), true).toBool();
}
void setRandomPort(bool b) {
setValue("Preferences/General/RandomPort", b);
}
bool systrayIntegration() const { bool systrayIntegration() const {
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
return false; return false;

30
src/qtlibtorrent/qbtsession.cpp

@ -115,6 +115,7 @@ QBtSession::QBtSession()
, 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)
{ {
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()));
@ -281,17 +282,32 @@ 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");
const Preferences pref; //removed the constant modifier for Preferences
// * Ports binding 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 (old_listenPort != new_listenPort) { if(pref.useRandomPort() && !isRandomPortset()) { // to check if the randomPort checkbox is selected
qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort); setRandomPortset(true);
setListeningPort(new_listenPort); srand(time(0));
const unsigned short randomPort = rand() % USHRT_MAX + 1025;
setListeningPort(randomPort);
addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort()))); 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 {
// * Ports binding
if (old_listenPort != new_listenPort) {
qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort);
setListeningPort(new_listenPort);
addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort())));
}
} }
// Downloads // Downloads
@ -1519,7 +1535,7 @@ void QBtSession::loadSessionState() {
// bdecode // bdecode
lazy_entry e; lazy_entry e;
#if LIBTORRENT_VERSION_NUM >= 001600 #if LIBTORRENT_VERSION_NUM >= 001600
libtorrent::error_code ec; error_code ec;
lazy_bdecode(&in[0], &in[0] + in.size(), e, ec); lazy_bdecode(&in[0], &in[0] + in.size(), e, ec);
if (!ec) { if (!ec) {
#else #else
@ -1903,7 +1919,7 @@ void QBtSession::setListeningPort(int port) {
Preferences pref; Preferences pref;
std::pair<int,int> ports(port, port); std::pair<int,int> ports(port, port);
#if LIBTORRENT_VERSION_NUM >= 001600 #if LIBTORRENT_VERSION_NUM >= 001600
libtorrent::error_code ec; error_code ec;
#endif #endif
const QString iface_name = pref.getNetworkInterface(); const QString iface_name = pref.getNetworkInterface();
if (iface_name.isEmpty()) { if (iface_name.isEmpty()) {

3
src/qtlibtorrent/qbtsession.h

@ -107,6 +107,8 @@ 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);
@ -257,6 +259,7 @@ private:
bool m_torrentExportEnabled; bool m_torrentExportEnabled;
bool m_finishedTorrentExportEnabled; bool m_finishedTorrentExportEnabled;
bool appendqBExtension; bool appendqBExtension;
bool randomPortSet;
QString defaultSavePath; QString defaultSavePath;
QString defaultTempPath; QString defaultTempPath;
// IP filtering // IP filtering

Loading…
Cancel
Save