Browse Source

Code clean up

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
1788078594
  1. 43
      src/bittorrent.cpp
  2. 13
      src/eventmanager.cpp
  3. 108
      src/options_imp.cpp
  4. 2
      src/options_imp.h
  5. 68
      src/preferences.h
  6. 3
      src/src.pro
  7. 60
      src/webui/preferences_content.html

43
src/bittorrent.cpp

@ -95,25 +95,7 @@ Bittorrent::Bittorrent() @@ -95,25 +95,7 @@ Bittorrent::Bittorrent()
version << VERSION_MINOR;
version << VERSION_BUGFIX;
version << VERSION_TYPE;
#ifdef CLIENT_USURPATION
QString peer_id = Preferences::getPeerID();
if(peer_id.size() != 2) peer_id = "qB";
if(peer_id != "qB") {
QStringList peer_ver = Preferences::getClientVersion().split('.');
while(peer_ver.size() < 4) {
peer_ver << "0";
}
for(int i=0; i<peer_ver.size(); ++i) {
QString ver = peer_ver.at(i);
if(ver.size() != 1) {
ver.truncate(1);
}
version.replace(i, ver.toInt());
}
}
#else
const QString peer_id = "qB";
#endif
// Construct session
s = new session(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)), 0);
std::cout << "Peer ID: " << fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string() << std::endl;
@ -411,32 +393,7 @@ void Bittorrent::configureSession() { @@ -411,32 +393,7 @@ void Bittorrent::configureSession() {
}
// * Session settings
session_settings sessionSettings;
#ifdef CLIENT_USURPATION
QString peer_id = Preferences::getPeerID();
if(peer_id.size() != 2) peer_id = "qB";
if(peer_id == "UT") {
QString version = Preferences::getClientVersion().replace(".", "");
while(version.size() < 4)
version.append("0");
const QString build = Preferences::getClientBuild();
sessionSettings.user_agent = QString("uTorrent/"+version+"("+build+")").toStdString();
} else {
if(peer_id == "AZ") {
QStringList version = Preferences::getClientVersion().split(".");
while(version.size() < 4)
version << "0";
sessionSettings.user_agent = QString("Azureus "+version.join(".")).toStdString();
} else {
if(peer_id == "KT") {
sessionSettings.user_agent = QString("KTorrent/"+Preferences::getClientVersion()).toStdString();
} else {
sessionSettings.user_agent = "qBittorrent "VERSION;
}
}
}
#else
sessionSettings.user_agent = "qBittorrent "VERSION;
#endif
std::cout << "HTTP user agent is " << sessionSettings.user_agent << std::endl;
addConsoleMessage(tr("HTTP user agent is %1").arg(misc::toQString(sessionSettings.user_agent)));

13
src/eventmanager.cpp

@ -208,14 +208,6 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { @@ -208,14 +208,6 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
Preferences::setLSDEnabled(m["lsd"].toBool());
if(m.contains("encryption"))
Preferences::setEncryptionSetting(m["encryption"].toInt());
#ifdef CLIENT_USURPATION
if(m.contains("peer_id"))
Preferences::setPeerID(m["peer_id"].toString());
if(m.contains("peer_version"))
Preferences::setClientVersion(m["peer_version"].toString());
if(m.contains("peer_build"))
Preferences::setClientBuild(m["peer_build"].toString());
#endif
// Proxy
if(m.contains("proxy_type"))
Preferences::setPeerProxyType(m["proxy_type"].toInt());
@ -297,11 +289,6 @@ QVariantMap EventManager::getGlobalPreferences() const { @@ -297,11 +289,6 @@ QVariantMap EventManager::getGlobalPreferences() const {
data["pex"] = Preferences::isPeXEnabled();
data["lsd"] = Preferences::isLSDEnabled();
data["encryption"] = Preferences::getEncryptionSetting();
#ifdef CLIENT_USURPATION
data["peer_id"] = Preferences::getPeerID();
data["peer_version"] = Preferences::getClientVersion();
data["peer_build"] = Preferences::getClientBuild();
#endif
// Proxy
data["proxy_type"] = Preferences::getPeerProxyType();
data["proxy_ip"] = Preferences::getPeerProxyIp();

108
src/options_imp.cpp

@ -272,10 +272,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -272,10 +272,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
scrollArea_advanced->setLayout(adv_layout);
connect(advancedSettings, SIGNAL(settingsChanged()), this, SLOT(enableApplyButton()));
#ifndef CLIENT_USURPATION
groupBox_usurpation->setVisible(false);
#endif
// Adapt size
show();
loadWindowState();
@ -452,26 +448,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -452,26 +448,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
settings.setValue(QString::fromUtf8("sameDHTPortAsBT"), isDHTPortSameAsBT());
settings.setValue(QString::fromUtf8("DHTPort"), getDHTPort());
settings.setValue(QString::fromUtf8("LSD"), isLSDEnabled());
#ifndef CLIENT_USURPATION
// Peer ID usurpation
switch(comboPeerID->currentIndex()) {
case 3: // KTorrent
Preferences::setPeerID("KT");
Preferences::setClientVersion(client_version->text());
break;
case 2: // uTorrent
Preferences::setPeerID("UT");
Preferences::setClientVersion(client_version->text());
Preferences::setClientBuild(client_build->text());
break;
case 1: // Vuze
Preferences::setPeerID("AZ");
Preferences::setClientVersion(client_version->text());
break;
default: //qBittorrent
Preferences::setPeerID("qB");
}
#endif
settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting());
Preferences::setMaxRatio(getMaxRatio());
Preferences::setMaxRatioAction(comboRatioLimitAct->currentIndex());
@ -761,34 +737,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -761,34 +737,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
spinDHTPort->setValue(Preferences::getDHTPort());
checkPeX->setChecked(Preferences::isPeXEnabled());
checkLSD->setChecked(Preferences::isLSDEnabled());
// Peer ID usurpation
#ifdef CLIENT_USURPATION
QString peer_id = Preferences::getPeerID();
if(peer_id == "UT") {
// uTorrent
comboPeerID->setCurrentIndex(2);
enableSpoofingSettings(2);
client_version->setText(Preferences::getClientVersion());
client_build->setText(Preferences::getClientBuild());
} else {
if(peer_id == "AZ") {
// Vuze
comboPeerID->setCurrentIndex(1);
enableSpoofingSettings(1);
client_version->setText(Preferences::getClientVersion());
} else {
if(peer_id == "KT") {
comboPeerID->setCurrentIndex(3);
enableSpoofingSettings(3);
client_version->setText(Preferences::getClientVersion());
} else {
// qBittorrent
comboPeerID->setCurrentIndex(0);
enableSpoofingSettings(0);
}
}
}
#endif
comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting());
// Ratio limit
floatValue = Preferences::getMaxRatio();
@ -833,62 +781,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -833,62 +781,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
return spinPort->value();
}
void options_imp::enableSpoofingSettings(int index) {
switch(index) {
case 0: // qBittorrent
resetPeerVersion_button->setEnabled(false);
version_label->setEnabled(false);
client_version->setEnabled(false);
client_version->clear();
build_label->setEnabled(false);
client_build->setEnabled(false);
client_build->clear();
break;
case 1: // Vuze
resetPeerVersion_button->setEnabled(true);
version_label->setEnabled(true);
client_version->setEnabled(true);
client_version->setText(Preferences::getDefaultClientVersion("AZ"));
build_label->setEnabled(false);
client_build->setEnabled(false);
client_build->clear();
break;
case 2: // uTorrent
resetPeerVersion_button->setEnabled(true);
version_label->setEnabled(true);
client_version->setEnabled(true);
client_version->setText(Preferences::getDefaultClientVersion("UT"));
build_label->setEnabled(true);
client_build->setEnabled(true);
client_build->setText(Preferences::getDefaultClientBuild("UT"));
break;
case 3: // KTorrent
resetPeerVersion_button->setEnabled(true);
version_label->setEnabled(true);
client_version->setEnabled(true);
client_version->setText(Preferences::getDefaultClientVersion("KT"));
build_label->setEnabled(false);
client_build->setEnabled(false);
client_build->clear();
break;
}
}
void options_imp::on_resetPeerVersion_button_clicked() {
switch(comboPeerID->currentIndex()) {
case 1: // Vuze
client_version->setText(Preferences::getDefaultClientVersion("AZ"));
break;
case 3: // KTorrent
client_version->setText(Preferences::getDefaultClientVersion("KT"));
break;
case 2: // uTorrent
client_version->setText(Preferences::getDefaultClientVersion("UT"));
client_build->setText(Preferences::getDefaultClientBuild("UT"));
break;
}
}
void options_imp::on_randomButton_clicked() {
// Range [1024: 65535]
spinPort->setValue(rand() % 64512 + 1024);

2
src/options_imp.h

@ -136,7 +136,6 @@ protected slots: @@ -136,7 +136,6 @@ protected slots:
void enableMaxConnecsLimitPerTorrent(bool checked);
void enableMaxUploadsLimitPerTorrent(bool checked);
void enableMaxRatio(bool checked);
void enableSpoofingSettings(int index);
void setStyle(QString style);
void on_buttonBox_accepted();
void closeEvent(QCloseEvent *e);
@ -161,7 +160,6 @@ protected slots: @@ -161,7 +160,6 @@ protected slots:
public slots:
void setLocale(QString locale);
void useStyle();
void on_resetPeerVersion_button_clicked();
signals:
void status_changed() const;

68
src/preferences.h

@ -582,74 +582,6 @@ public: @@ -582,74 +582,6 @@ public:
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), val);
}
static QString getPeerID() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/PeerID"), "qB").toString();
}
static void setPeerID(QString peer_id) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/PeerID"), peer_id);
}
static QString getDefaultClientVersion(QString peer_id) {
if(peer_id == "UT") {
// uTorrent
return "1.8.5";
}
// Azureus
if(peer_id == "AZ") {
return "4.3.0.4";
}
// KTorrent
if(peer_id == "KT") {
return "3.3.2";
}
// qBittorrent
return QString(VERSION);
}
static QString getDefaultClientBuild(QString peer_id) {
if(peer_id == "UT") {
return "17414";
}
return "";
}
static QString getClientVersion() {
QIniSettings settings("qBittorrent", "qBittorrent");
QString peer_id = getPeerID();
if(peer_id == "qB")
return QString(VERSION);
QString version = settings.value(QString::fromUtf8("Preferences/Bittorrent/PeerVersion"), QString()).toString();
if(version.isEmpty()) {
version = getDefaultClientVersion(peer_id);
}
return version;
}
static void setClientVersion(QString version) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/PeerVersion"), version);
}
static QString getClientBuild() {
QIniSettings settings("qBittorrent", "qBittorrent");
QString peer_id = getPeerID();
if(peer_id != "UT")
return "";
QString build = settings.value(QString::fromUtf8("Preferences/Bittorrent/PeerBuild"), QString()).toString();
if(build.isEmpty()) {
build = getDefaultClientBuild(peer_id);
}
return build;
}
static void setClientBuild(QString build) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/PeerBuild"), build);
}
static bool isDHTEnabled() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool();

3
src/src.pro

@ -421,7 +421,4 @@ SOURCES += main.cpp \ @@ -421,7 +421,4 @@ SOURCES += main.cpp \
}
}
# NO CLIENT USURPATION
# DEFINES += CLIENT_USURPATION
DESTDIR = .

60
src/webui/preferences_content.html

@ -75,23 +75,6 @@ @@ -75,23 +75,6 @@
</select><br/>
</div>
</fieldset>
<!--
<fieldset>
<legend><b>_(Client whitelisting workaround)</b></legend>
_(Identify as:)
<select id="peer_id_select" onchange="updateSpoofingSettings();">
<option value="qB">_(qBittorrent)</option>
<option value="AZ">_(Vuze)</option>
<option value="UT">_(µTorrent)</option>
<option value="KT">_(KTorrent)</option>
</select>
&nbsp;&nbsp;
_(Version:) <input type="text" id="peer_version_text" style="width: 7em;" />
&nbsp;&nbsp;
_(Build:) <input type="text" id="peer_build_text" style="width: 5em;" />
<br/>
</fieldset>
-->
</div>
<div id="DownloadsTab" class="PrefTab invisible">
@ -350,9 +333,6 @@ @@ -350,9 +333,6 @@
var lsd = 0;
if($defined($('lsd_checkbox').get('checked')) && $('lsd_checkbox').get('checked'))
lsd = 1;
//var peer_id = $('peer_id_select').get('value');
//var peer_version = $('peer_version_text').get('value');
//var peer_build = $('peer_build_text').get('value');
// Downloads
var save_path = $("savepath_text").get('value');
var temp_path_enabled = 0
@ -476,9 +456,6 @@ @@ -476,9 +456,6 @@
dict.set('pex', pex);
dict.set('lsd', lsd);
dict.set('encryption', $('encryption_select').get('value'));
//dict.set('peer_id', peer_id);
//dict.set('peer_version', peer_version);
//dict.set('peer_build', peer_build);
// Downloads
dict.set('save_path', save_path);
dict.set('temp_path_enabled', temp_path_enabled);
@ -549,39 +526,6 @@ updateUpLimitEnabled = function() { @@ -549,39 +526,6 @@ updateUpLimitEnabled = function() {
}
}
updateSpoofingSettings = function() {
var peer_id = $('peer_id_select').get('value');
if(peer_id == "UT") {
// uTorrent
$('peer_version_text').removeProperty('disabled');
$('peer_version_text').set('value', '1.8.5');
$('peer_build_text').removeProperty('disabled');
$('peer_build_text').set('value', '17414');
} else {
if(peer_id == "AZ") {
// Vuze
$('peer_version_text').removeProperty('disabled');
$('peer_version_text').set('value', '4.3.0.4');
$('peer_build_text').set('disabled', 'true');
$('peer_build_text').set('value', '');
} else {
if(peer_id == "KT") {
// KTorrent
$('peer_version_text').removeProperty('disabled');
$('peer_version_text').set('value', '3.3.2');
$('peer_build_text').set('disabled', 'true');
$('peer_build_text').set('value', '');
} else {
// qBittorrent
$('peer_version_text').set('disabled', 'true');
$('peer_version_text').set('value', '');
$('peer_build_text').set('disabled', 'true');
$('peer_build_text').set('value', '');
}
}
}
}
updateMaxConnecEnabled = function() {
if($defined($('max_connec_checkbox').get('checked')) && $('max_connec_checkbox').get('checked')) {
$('max_connec_value').removeProperty('disabled');
@ -852,10 +796,6 @@ loadPreferences = function() { @@ -852,10 +796,6 @@ loadPreferences = function() {
}
var encryption = pref.encryption.toInt();
$('encryption_select').getChildren('option')[encryption].setAttribute('selected', '');
//$('peer_id_select').set('value', pref.peer_id);
//updateSpoofingSettings();
//$('peer_version_text').set('value', pref.peer_version);
//$('peer_build_text').set('value', pref.peer_build);
// Downloads
var save_path = pref.save_path;
$("savepath_text").set('value', save_path);

Loading…
Cancel
Save