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

7
src/preferences/options_imp.cpp

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

9
src/preferences/preferences.h

@ -78,6 +78,7 @@ public: @@ -78,6 +78,7 @@ public:
}
// General options
QString getLocale() const {
return value(QString::fromUtf8("Preferences/General/Locale"), "en_GB").toString();
}
@ -126,6 +127,14 @@ public: @@ -126,6 +127,14 @@ public:
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 {
#ifdef Q_WS_MAC
return false;

30
src/qtlibtorrent/qbtsession.cpp

@ -115,6 +115,7 @@ QBtSession::QBtSession() @@ -115,6 +115,7 @@ QBtSession::QBtSession()
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN),
m_upnp(0), m_natpmp(0), m_dynDNSUpdater(0)
{
setRandomPortset(false);
BigRatioTimer = new QTimer(this);
BigRatioTimer->setInterval(10000);
connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios()));
@ -281,17 +282,32 @@ void QBtSession::setQueueingEnabled(bool enable) { @@ -281,17 +282,32 @@ void QBtSession::setQueueingEnabled(bool enable) {
}
}
void QBtSession::setRandomPortset(bool set) {
randomPortSet = set;
}
// Set BT session configuration
void QBtSession::configureSession() {
qDebug("Configuring session");
const Preferences pref;
// * Ports binding
//removed the constant modifier for Preferences
Preferences pref;
const unsigned short old_listenPort = getListenPort();
const unsigned short new_listenPort = pref.getSessionPort();
if (old_listenPort != new_listenPort) {
qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort);
setListeningPort(new_listenPort);
if(pref.useRandomPort() && !isRandomPortset()) { // to check if the randomPort checkbox is selected
setRandomPortset(true);
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())));
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
@ -1519,7 +1535,7 @@ void QBtSession::loadSessionState() { @@ -1519,7 +1535,7 @@ void QBtSession::loadSessionState() {
// bdecode
lazy_entry e;
#if LIBTORRENT_VERSION_NUM >= 001600
libtorrent::error_code ec;
error_code ec;
lazy_bdecode(&in[0], &in[0] + in.size(), e, ec);
if (!ec) {
#else
@ -1903,7 +1919,7 @@ void QBtSession::setListeningPort(int port) { @@ -1903,7 +1919,7 @@ void QBtSession::setListeningPort(int port) {
Preferences pref;
std::pair<int,int> ports(port, port);
#if LIBTORRENT_VERSION_NUM >= 001600
libtorrent::error_code ec;
error_code ec;
#endif
const QString iface_name = pref.getNetworkInterface();
if (iface_name.isEmpty()) {

3
src/qtlibtorrent/qbtsession.h

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

Loading…
Cancel
Save