- Added option to disable peer host name resolution (disabled as a default)

- Fix several other bugs related to properties and preferences
This commit is contained in:
Christophe Dumez 2009-11-15 10:00:07 +00:00
parent 3762c37517
commit 5962ef79cb
8 changed files with 81 additions and 15 deletions

View file

@ -760,6 +760,10 @@ void GUI::processDownloadedFiles(QString path, QString url) {
}
}
void GUI::optionsSaved() {
loadPreferences();
}
// Load program preferences
void GUI::loadPreferences(bool configure_session) {
BTSession->addConsoleMessage(tr("Options were saved successfully."));
@ -830,6 +834,9 @@ void GUI::loadPreferences(bool configure_session) {
displayRSSTab(false);
}
// Torrent properties
properties->reloadPreferences();
if(configure_session)
BTSession->configureSession();
@ -1001,7 +1008,7 @@ void GUI::createTrayIcon() {
// Display Program Options
void GUI::on_actionOptions_triggered() {
options = new options_imp(this);
connect(options, SIGNAL(status_changed()), this, SLOT(loadPreferences(bool)));
connect(options, SIGNAL(status_changed()), this, SLOT(optionsSaved()));
}
bool GUI::initWebUi(QString username, QString password, int port) {

View file

@ -156,6 +156,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void scrapeTrackers();
// Options slots
void on_actionOptions_triggered();
void optionsSaved();
// HTTP slots
void on_actionDownload_from_URL_triggered();

View file

@ -364,6 +364,8 @@ void options_imp::saveOptions(){
settings.setValue(QString::fromUtf8("NAT-PMP"), isNATPMPEnabled());
settings.setValue(QString::fromUtf8("GlobalDLLimit"), getGlobalBandwidthLimits().first);
settings.setValue(QString::fromUtf8("GlobalUPLimit"), getGlobalBandwidthLimits().second);
settings.setValue("ResolvePeerCountries", checkResolveCountries->isChecked());
settings.setValue("ResolvePeerHostNames", checkResolveHosts->isChecked());
settings.setValue(QString::fromUtf8("ProxyType"), getProxyType());
//if(isProxyEnabled()) {
settings.beginGroup("Proxy");
@ -604,6 +606,10 @@ void options_imp::loadOptions(){
checkUploadLimit->setChecked(false);
spinUploadLimit->setEnabled(false);
}
// Peer connections
checkResolveCountries->setChecked(Preferences::resolvePeerCountries());
checkResolveHosts->setChecked(Preferences::resolvePeerHostNames());
intValue = Preferences::getProxyType();
if(intValue <= 0) {
intValue = 0;

View file

@ -31,13 +31,15 @@
#include "peerlistwidget.h"
#include "peerlistdelegate.h"
#include "reverseresolution.h"
#include "preferences.h"
#include "propertieswidget.h"
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include <QSet>
#include <QSettings>
#include <vector>
PeerListWidget::PeerListWidget() {
PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent) {
// Visual settings
setRootIsDecorated(false);
setItemsExpandable(false);
@ -64,9 +66,7 @@ PeerListWidget::PeerListWidget() {
// Load settings
loadSettings();
// IP to Hostname resolver
resolver = new ReverseResolution(this);
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString)));
resolver->start();
updatePeerHostNameResolutionState();
}
PeerListWidget::~PeerListWidget() {
@ -74,7 +74,33 @@ PeerListWidget::~PeerListWidget() {
delete proxyModel;
delete listModel;
delete listDelegate;
delete resolver;
if(resolver)
delete resolver;
}
void PeerListWidget::updatePeerHostNameResolutionState() {
if(Preferences::resolvePeerHostNames()) {
if(!resolver) {
resolver = new ReverseResolution(this);
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString)));
resolver->start();
clear();
loadPeers(properties->getCurrentTorrent());
}
} else {
if(resolver)
delete resolver;
}
}
void PeerListWidget::clear() {
qDebug("clearing peer list");
peerItems.clear();
int nbrows = listModel->rowCount();
if(nbrows > 0) {
qDebug("Cleared %d peers", nbrows);
listModel->removeRows(0, nbrows);
}
}
void PeerListWidget::loadSettings() {
@ -96,7 +122,8 @@ void PeerListWidget::saveSettings() const {
settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths);
}
void PeerListWidget::loadPeers(QTorrentHandle &h) {
void PeerListWidget::loadPeers(const QTorrentHandle &h) {
if(!h.is_valid()) return;
std::vector<peer_info> peers;
h.get_peer_info(peers);
std::vector<peer_info>::iterator itr;
@ -126,7 +153,9 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
// Adding Peer to peer list
listModel->insertRow(row);
listModel->setData(listModel->index(row, IP), ip);
resolver->resolve(peer.ip);
// Resolve peer host name is asked
if(resolver)
resolver->resolve(peer.ip);
listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client));
listModel->setData(listModel->index(row, PROGRESS), peer.progress);
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);

View file

@ -33,6 +33,7 @@
#include <QTreeView>
#include <QHash>
#include <QPointer>
#include "qtorrenthandle.h"
#include "misc.h"
@ -41,6 +42,7 @@ class QStandardItem;
class QSortFilterProxyModel;
class PeerListDelegate;
class ReverseResolution;
class PropertiesWidget;
class PeerListWidget : public QTreeView {
Q_OBJECT
@ -50,17 +52,20 @@ private:
PeerListDelegate *listDelegate;
QSortFilterProxyModel * proxyModel;
QHash<QString, QStandardItem*> peerItems;
ReverseResolution *resolver;
QPointer<ReverseResolution> resolver;
PropertiesWidget* properties;
public:
PeerListWidget();
PeerListWidget(PropertiesWidget *parent);
~PeerListWidget();
public slots:
void loadPeers(QTorrentHandle &h);
void loadPeers(const QTorrentHandle &h);
QStandardItem* addPeer(QString ip, peer_info peer);
void updatePeer(QString ip, peer_info peer);
void handleResolved(QString ip, QString hostname);
void updatePeerHostNameResolutionState();
void clear();
protected slots:
void loadSettings();

View file

@ -187,6 +187,16 @@ public:
return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimit"), -1).toInt();
}
static bool resolvePeerCountries() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerCountries"), false).toBool();
}
static bool resolvePeerHostNames() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), false).toBool();
}
// Proxy options
static bool isHTTPProxyEnabled() {
QSettings settings("qBittorrent", "qBittorrent");

View file

@ -92,7 +92,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, TransferListWidget *transfer
progressBar->setForegroundColor(Qt::blue);
ProgressHLayout->insertWidget(1, progressBar);
// Peers list
peersList = new PeerListWidget();
peersList = new PeerListWidget(this);
peerpage_layout->addWidget(peersList);
// Pointers init
progressBarUpdater = 0;
@ -144,6 +144,7 @@ void PropertiesWidget::slide() {
}
void PropertiesWidget::clear() {
qDebug("Clearing torrent properties");
save_path->clear();
lbl_creationDate->clear();
hash_lbl->clear();
@ -155,6 +156,7 @@ void PropertiesWidget::clear() {
wasted->clear();
upTotal->clear();
dlTotal->clear();
peersList->clear();
lbl_uplimit->clear();
lbl_dllimit->clear();
lbl_elapsed->clear();
@ -165,6 +167,10 @@ void PropertiesWidget::clear() {
setEnabled(false);
}
const QTorrentHandle& PropertiesWidget::getCurrentTorrent() const {
return h;
}
void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
h = _h;
if(!h.is_valid()) {
@ -258,8 +264,9 @@ void PropertiesWidget::saveSettings() {
}
}
void PropertiesWidget::loadPeers() {
// TODO
void PropertiesWidget::reloadPreferences() {
// Take program preferences into consideration
peersList->updatePeerHostNameResolutionState();
}
void PropertiesWidget::loadDynamicData() {

View file

@ -81,7 +81,6 @@ protected slots:
void setIncrementalDownload(int checkboxState);
void loadTrackers();
void loadUrlSeeds();
void loadPeers();
void on_main_infos_button_clicked();
void on_trackers_button_clicked();
void on_peers_button_clicked();
@ -108,10 +107,12 @@ public slots:
void clear();
void readSettings();
void saveSettings();
void reloadPreferences();
public:
PropertiesWidget(QWidget *parent, TransferListWidget *transferList, bittorrent* BTSession);
~PropertiesWidget();
const QTorrentHandle& getCurrentTorrent() const;
};
#endif // PROPERTIESWIDGET_H