Browse Source

Clean up PeerListWidget

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
6778b7460a
  1. 4
      src/iconprovider.cpp
  2. 2
      src/iconprovider.h
  3. 281
      src/properties/peerlistwidget.cpp
  4. 33
      src/properties/peerlistwidget.h
  5. 14
      src/reverseresolution.h
  6. 4
      src/torrentcontentmodel.cpp

4
src/iconprovider.cpp

@ -77,7 +77,7 @@ void IconProvider::useSystemIconTheme(bool enable)
// It scales the icon from the theme if necessary // It scales the icon from the theme if necessary
// Otherwise, the UI looks broken if the icon is not available // Otherwise, the UI looks broken if the icon is not available
// in the correct size. // in the correct size.
QIcon IconProvider::generateDifferentSizes(const QIcon &icon) QIcon IconProvider::generateDifferentSizes(const QIcon& icon)
{ {
QIcon new_icon; QIcon new_icon;
QList<QSize> required_sizes; QList<QSize> required_sizes;
@ -100,7 +100,7 @@ QIcon IconProvider::generateDifferentSizes(const QIcon &icon)
} }
#endif #endif
QString IconProvider::getIconPath(const QString &iconId) QString IconProvider::getIconPath(const QString& iconId)
{ {
#if defined(Q_WS_X11) #if defined(Q_WS_X11)
if (m_useSystemTheme) { if (m_useSystemTheme) {

2
src/iconprovider.h

@ -46,7 +46,7 @@ public:
static IconProvider* instance(); static IconProvider* instance();
static void drop(); static void drop();
QIcon getIcon(const QString& iconId); QIcon getIcon(const QString& iconId);
QString getIconPath(const QString &iconId); QString getIconPath(const QString& iconId);
#if defined(Q_WS_X11) #if defined(Q_WS_X11)
public: public:

281
src/properties/peerlistwidget.cpp

@ -48,7 +48,9 @@
using namespace libtorrent; using namespace libtorrent;
PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), properties(parent), display_flags(false) { PeerListWidget::PeerListWidget(PropertiesWidget *parent):
QTreeView(parent), m_properties(parent), m_displayFlags(false)
{
// Load settings // Load settings
loadSettings(); loadSettings();
// Visual settings // Visual settings
@ -57,27 +59,27 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), pro
setAllColumnsShowFocus(true); setAllColumnsShowFocus(true);
setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionMode(QAbstractItemView::ExtendedSelection);
// List Model // List Model
listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT); m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT);
listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP")); m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP"));
listModel->setHeaderData(PeerListDelegate::CONNECTION, Qt::Horizontal, tr("Connection")); m_listModel->setHeaderData(PeerListDelegate::CONNECTION, Qt::Horizontal, tr("Connection"));
listModel->setHeaderData(PeerListDelegate::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application")); m_listModel->setHeaderData(PeerListDelegate::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application"));
listModel->setHeaderData(PeerListDelegate::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded")); m_listModel->setHeaderData(PeerListDelegate::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
listModel->setHeaderData(PeerListDelegate::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed")); m_listModel->setHeaderData(PeerListDelegate::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed")); m_listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
listModel->setHeaderData(PeerListDelegate::TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded")); m_listModel->setHeaderData(PeerListDelegate::TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded"));
listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded")); m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded"));
// Proxy model to support sorting without actually altering the underlying model // Proxy model to support sorting without actually altering the underlying model
proxyModel = new QSortFilterProxyModel(); m_proxyModel = new QSortFilterProxyModel();
proxyModel->setDynamicSortFilter(true); m_proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(listModel); m_proxyModel->setSourceModel(m_listModel);
setModel(proxyModel); setModel(m_proxyModel);
hideColumn(PeerListDelegate::IP_HIDDEN); hideColumn(PeerListDelegate::IP_HIDDEN);
// Context menu // Context menu
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showPeerListMenu(QPoint))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showPeerListMenu(QPoint)));
// List delegate // List delegate
listDelegate = new PeerListDelegate(this); m_listDelegate = new PeerListDelegate(this);
setItemDelegate(listDelegate); setItemDelegate(m_listDelegate);
// Enable sorting // Enable sorting
setSortingEnabled(true); setSortingEnabled(true);
// IP to Hostname resolver // IP to Hostname resolver
@ -87,50 +89,50 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), pro
handleSortColumnChanged(header()->sortIndicatorSection()); handleSortColumnChanged(header()->sortIndicatorSection());
} }
PeerListWidget::~PeerListWidget() { PeerListWidget::~PeerListWidget()
{
saveSettings(); saveSettings();
delete proxyModel; delete m_proxyModel;
delete listModel; delete m_listModel;
delete listDelegate; delete m_listDelegate;
if (resolver) if (m_resolver)
delete resolver; delete m_resolver;
} }
void PeerListWidget::updatePeerHostNameResolutionState() { void PeerListWidget::updatePeerHostNameResolutionState()
{
if (Preferences().resolvePeerHostNames()) { if (Preferences().resolvePeerHostNames()) {
if (!resolver) { if (!m_resolver) {
resolver = new ReverseResolution(this); m_resolver = new ReverseResolution(this);
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString))); connect(m_resolver, SIGNAL(ip_resolved(QString,QString)), SLOT(handleResolved(QString,QString)));
loadPeers(properties->getCurrentTorrent(), true); loadPeers(m_properties->getCurrentTorrent(), true);
} }
} else { } else {
if (resolver) { if (m_resolver)
delete resolver; delete m_resolver;
}
} }
} }
void PeerListWidget::updatePeerCountryResolutionState() { void PeerListWidget::updatePeerCountryResolutionState()
if (Preferences().resolvePeerCountries() != display_flags) { {
display_flags = !display_flags; if (Preferences().resolvePeerCountries() != m_displayFlags) {
if (display_flags) { m_displayFlags = !m_displayFlags;
const QTorrentHandle h = properties->getCurrentTorrent(); if (m_displayFlags)
if (!h.is_valid()) return; loadPeers(m_properties->getCurrentTorrent());
loadPeers(h);
}
} }
} }
void PeerListWidget::showPeerListMenu(QPoint) { void PeerListWidget::showPeerListMenu(const QPoint&)
{
QMenu menu; QMenu menu;
bool empty_menu = true; bool empty_menu = true;
QTorrentHandle h = properties->getCurrentTorrent(); QTorrentHandle h = m_properties->getCurrentTorrent();
if (!h.is_valid()) return; if (!h.is_valid()) return;
QModelIndexList selectedIndexes = selectionModel()->selectedRows(); QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeerIPs; QStringList selectedPeerIPs;
foreach (const QModelIndex &index, selectedIndexes) { foreach (const QModelIndex &index, selectedIndexes) {
int row = proxyModel->mapToSource(index).row(); int row = m_proxyModel->mapToSource(index).row();
QString myip = listModel->data(listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString(); QString myip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
selectedPeerIPs << myip; selectedPeerIPs << myip;
} }
// Add Peer Action // Add Peer Action
@ -157,8 +159,8 @@ void PeerListWidget::showPeerListMenu(QPoint) {
QAction *act = menu.exec(QCursor::pos()); QAction *act = menu.exec(QCursor::pos());
if (act == 0) return; if (act == 0) return;
if (act == addPeerAct) { if (act == addPeerAct) {
libtorrent::asio::ip::tcp::endpoint ep = PeerAdditionDlg::askForPeerEndpoint(); boost::asio::ip::tcp::endpoint ep = PeerAdditionDlg::askForPeerEndpoint();
if (ep != libtorrent::asio::ip::tcp::endpoint()) { if (ep != boost::asio::ip::tcp::endpoint()) {
try { try {
h.connect_peer(ep); h.connect_peer(ep);
QMessageBox::information(0, tr("Peer addition"), tr("The peer was added to this torrent.")); QMessageBox::information(0, tr("Peer addition"), tr("The peer was added to this torrent."));
@ -191,42 +193,54 @@ void PeerListWidget::showPeerListMenu(QPoint) {
} }
} }
void PeerListWidget::banSelectedPeers(QStringList peer_ips) { void PeerListWidget::banSelectedPeers(const QStringList& peer_ips)
{
// Confirm first // Confirm first
int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to ban permanently the selected peers?"), int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to ban permanently the selected peers?"),
tr("&Yes"), tr("&No"), tr("&Yes"), tr("&No"),
QString(), 0, 1); QString(), 0, 1);
if (ret) return; if (ret)
return;
foreach (const QString &ip, peer_ips) { foreach (const QString &ip, peer_ips) {
qDebug("Banning peer %s...", ip.toLocal8Bit().data()); qDebug("Banning peer %s...", ip.toLocal8Bit().data());
QBtSession::instance()->addConsoleMessage(tr("Manually banning peer %1...").arg(ip)); QBtSession::instance()->addConsoleMessage(tr("Manually banning peer %1...").arg(ip));
QBtSession::instance()->banIP(ip); QBtSession::instance()->banIP(ip);
} }
// Refresh list // Refresh list
loadPeers(properties->getCurrentTorrent()); loadPeers(m_properties->getCurrentTorrent());
} }
void PeerListWidget::limitUpRateSelectedPeers(QStringList peer_ips) { void PeerListWidget::limitUpRateSelectedPeers(const QStringList& peer_ips)
if (peer_ips.empty()) return; {
QTorrentHandle h = properties->getCurrentTorrent(); if (peer_ips.empty())
if (!h.is_valid()) return; return;
bool ok=false; QTorrentHandle h = m_properties->getCurrentTorrent();
if (!h.is_valid())
return;
bool ok = false;
int cur_limit = -1; int cur_limit = -1;
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
libtorrent::asio::ip::tcp::endpoint first_ep = peerEndpoints.value(peer_ips.first(), boost::asio::ip::tcp::endpoint first_ep = peerEndpoints.value(peer_ips.first(),
libtorrent::asio::ip::tcp::endpoint()); boost::asio::ip::tcp::endpoint());
if (first_ep != libtorrent::asio::ip::tcp::endpoint()) if (first_ep != boost::asio::ip::tcp::endpoint())
cur_limit = h.get_peer_upload_limit(first_ep); cur_limit = h.get_peer_upload_limit(first_ep);
#endif #endif
long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Upload rate limiting"), cur_limit, Preferences().getGlobalUploadLimit()*1024.); long limit = SpeedLimitDialog::askSpeedLimit(&ok,
if (!ok) return; tr("Upload rate limiting"),
cur_limit,
Preferences().getGlobalUploadLimit()*1024.);
if (!ok)
return;
foreach (const QString &ip, peer_ips) { foreach (const QString &ip, peer_ips) {
libtorrent::asio::ip::tcp::endpoint ep = peerEndpoints.value(ip, libtorrent::asio::ip::tcp::endpoint()); boost::asio::ip::tcp::endpoint ep = m_peerEndpoints.value(ip, boost::asio::ip::tcp::endpoint());
if (ep != libtorrent::asio::ip::tcp::endpoint()) { if (ep != boost::asio::ip::tcp::endpoint()) {
qDebug("Settings Upload limit of %.1f Kb/s to peer %s", limit/1024., ip.toLocal8Bit().data()); qDebug("Settings Upload limit of %.1f Kb/s to peer %s", limit/1024., ip.toLocal8Bit().data());
try { try {
h.set_peer_upload_limit(ep, limit); h.set_peer_upload_limit(ep, limit);
}catch(std::exception) { } catch(std::exception) {
std::cerr << "Impossible to apply upload limit to peer" << std::endl; std::cerr << "Impossible to apply upload limit to peer" << std::endl;
} }
} else { } else {
@ -235,22 +249,26 @@ void PeerListWidget::limitUpRateSelectedPeers(QStringList peer_ips) {
} }
} }
void PeerListWidget::limitDlRateSelectedPeers(QStringList peer_ips) { void PeerListWidget::limitDlRateSelectedPeers(const QStringList& peer_ips)
QTorrentHandle h = properties->getCurrentTorrent(); {
if (!h.is_valid()) return; QTorrentHandle h = m_properties->getCurrentTorrent();
bool ok=false; if (!h.is_valid())
return;
bool ok = false;
int cur_limit = -1; int cur_limit = -1;
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
libtorrent::asio::ip::tcp::endpoint first_ep = peerEndpoints.value(peer_ips.first(), boost::asio::ip::tcp::endpoint first_ep = peerEndpoints.value(peer_ips.first(),
libtorrent::asio::ip::tcp::endpoint()); boost::asio::ip::tcp::endpoint());
if (first_ep != libtorrent::asio::ip::tcp::endpoint()) if (first_ep != boost::asio::ip::tcp::endpoint())
cur_limit = h.get_peer_download_limit(first_ep); cur_limit = h.get_peer_download_limit(first_ep);
#endif #endif
long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Download rate limiting"), cur_limit, Preferences().getGlobalDownloadLimit()*1024.); long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Download rate limiting"), cur_limit, Preferences().getGlobalDownloadLimit()*1024.);
if (!ok) return; if (!ok)
return;
foreach (const QString &ip, peer_ips) { foreach (const QString &ip, peer_ips) {
libtorrent::asio::ip::tcp::endpoint ep = peerEndpoints.value(ip, libtorrent::asio::ip::tcp::endpoint()); boost::asio::ip::tcp::endpoint ep = m_peerEndpoints.value(ip, boost::asio::ip::tcp::endpoint());
if (ep != libtorrent::asio::ip::tcp::endpoint()) { if (ep != boost::asio::ip::tcp::endpoint()) {
qDebug("Settings Download limit of %.1f Kb/s to peer %s", limit/1024., ip.toLocal8Bit().data()); qDebug("Settings Download limit of %.1f Kb/s to peer %s", limit/1024., ip.toLocal8Bit().data());
try { try {
h.set_peer_download_limit(ep, limit); h.set_peer_download_limit(ep, limit);
@ -266,13 +284,13 @@ void PeerListWidget::limitDlRateSelectedPeers(QStringList peer_ips) {
void PeerListWidget::clear() { void PeerListWidget::clear() {
qDebug("clearing peer list"); qDebug("clearing peer list");
peerItems.clear(); m_peerItems.clear();
peerEndpoints.clear(); m_peerEndpoints.clear();
missingFlags.clear(); m_missingFlags.clear();
int nbrows = listModel->rowCount(); int nbrows = m_listModel->rowCount();
if (nbrows > 0) { if (nbrows > 0) {
qDebug("Cleared %d peers", nbrows); qDebug("Cleared %d peers", nbrows);
listModel->removeRows(0, nbrows); m_listModel->removeRows(0, nbrows);
} }
} }
@ -287,111 +305,96 @@ void PeerListWidget::saveSettings() const {
} }
void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) { void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) {
if (!h.is_valid()) return; if (!h.is_valid())
return;
boost::system::error_code ec; boost::system::error_code ec;
std::vector<peer_info> peers; std::vector<peer_info> peers;
h.get_peer_info(peers); h.get_peer_info(peers);
std::vector<peer_info>::iterator itr; std::vector<peer_info>::const_iterator itr;
QSet<QString> old_peers_set = peerItems.keys().toSet(); QSet<QString> old_peers_set = m_peerItems.keys().toSet();
for (itr = peers.begin(); itr != peers.end(); itr++) { for (itr = peers.begin(); itr != peers.end(); itr++) {
peer_info peer = *itr; peer_info peer = *itr;
QString peer_ip = misc::toQString(peer.ip.address().to_string(ec)); QString peer_ip = misc::toQString(peer.ip.address().to_string(ec));
if (ec) continue; if (ec) continue;
if (peerItems.contains(peer_ip)) { if (m_peerItems.contains(peer_ip)) {
// Update existing peer // Update existing peer
updatePeer(peer_ip, peer); updatePeer(peer_ip, peer);
old_peers_set.remove(peer_ip); old_peers_set.remove(peer_ip);
if (force_hostname_resolution) { if (force_hostname_resolution && m_resolver) {
if (resolver) { m_resolver->resolve(peer.ip);
const QString host = resolver->getHostFromCache(peer.ip);
if (host.isNull()) {
resolver->resolve(peer.ip);
} else {
qDebug("Got peer IP from cache");
handleResolved(peer_ip, host);
}
}
} }
} else { } else {
// Add new peer // Add new peer
peerItems[peer_ip] = addPeer(peer_ip, peer); m_peerItems[peer_ip] = addPeer(peer_ip, peer);
peerEndpoints[peer_ip] = peer.ip; m_peerEndpoints[peer_ip] = peer.ip;
} }
} }
// Delete peers that are gone // Delete peers that are gone
QSetIterator<QString> it(old_peers_set); QSetIterator<QString> it(old_peers_set);
while(it.hasNext()) { while(it.hasNext()) {
QString ip = it.next(); const QString& ip = it.next();
missingFlags.remove(ip); m_missingFlags.remove(ip);
peerEndpoints.remove(ip); m_peerEndpoints.remove(ip);
QStandardItem *item = peerItems.take(ip); QStandardItem *item = m_peerItems.take(ip);
listModel->removeRow(item->row()); m_listModel->removeRow(item->row());
} }
} }
QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) { QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer) {
int row = listModel->rowCount(); int row = m_listModel->rowCount();
// Adding Peer to peer list // Adding Peer to peer list
listModel->insertRow(row); m_listModel->insertRow(row);
QString host; m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ip);
if (resolver) { m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP_HIDDEN), ip);
host = resolver->getHostFromCache(peer.ip);
}
if (host.isNull())
listModel->setData(listModel->index(row, PeerListDelegate::IP), ip);
else
listModel->setData(listModel->index(row, PeerListDelegate::IP), host);
listModel->setData(listModel->index(row, PeerListDelegate::IP_HIDDEN), ip);
// Resolve peer host name is asked // Resolve peer host name is asked
if (resolver && host.isNull()) if (m_resolver)
resolver->resolve(peer.ip); m_resolver->resolve(peer.ip);
if (display_flags) { if (m_displayFlags) {
const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country); const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country);
if (!ico.isNull()) { if (!ico.isNull()) {
listModel->setData(listModel->index(row, PeerListDelegate::IP), ico, Qt::DecorationRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ico, Qt::DecorationRole);
const QString country_name = GeoIPManager::CountryISOCodeToName(peer.country); const QString country_name = GeoIPManager::CountryISOCodeToName(peer.country);
listModel->setData(listModel->index(row, PeerListDelegate::IP), country_name, Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), country_name, Qt::ToolTipRole);
} else { } else {
missingFlags.insert(ip); m_missingFlags.insert(ip);
} }
} }
listModel->setData(listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type));
listModel->setData(listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client));
listModel->setData(listModel->index(row, PeerListDelegate::PROGRESS), peer.progress); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress);
listModel->setData(listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed);
listModel->setData(listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed); m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
listModel->setData(listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download); m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
listModel->setData(listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload); m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
return listModel->item(row, PeerListDelegate::IP); return m_listModel->item(row, PeerListDelegate::IP);
} }
void PeerListWidget::updatePeer(QString ip, peer_info peer) { void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) {
QStandardItem *item = peerItems.value(ip); QStandardItem *item = m_peerItems.value(ip);
int row = item->row(); int row = item->row();
if (display_flags) { if (m_displayFlags) {
const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country); const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country);
if (!ico.isNull()) { if (!ico.isNull()) {
listModel->setData(listModel->index(row, PeerListDelegate::IP), ico, Qt::DecorationRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ico, Qt::DecorationRole);
const QString country_name = GeoIPManager::CountryISOCodeToName(peer.country); const QString country_name = GeoIPManager::CountryISOCodeToName(peer.country);
listModel->setData(listModel->index(row, PeerListDelegate::IP), country_name, Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), country_name, Qt::ToolTipRole);
missingFlags.remove(ip); m_missingFlags.remove(ip);
} }
} }
listModel->setData(listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type));
listModel->setData(listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client));
listModel->setData(listModel->index(row, PeerListDelegate::PROGRESS), peer.progress); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress);
listModel->setData(listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed);
listModel->setData(listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed); m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
listModel->setData(listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download); m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
listModel->setData(listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload); m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
} }
void PeerListWidget::handleResolved(const QString &ip, const QString &hostname) { void PeerListWidget::handleResolved(const QString &ip, const QString &hostname) {
QStandardItem *item = peerItems.value(ip, 0); QStandardItem *item = m_peerItems.value(ip, 0);
if (item) { if (item) {
qDebug("Resolved %s -> %s", qPrintable(ip), qPrintable(hostname)); qDebug("Resolved %s -> %s", qPrintable(ip), qPrintable(hostname));
item->setData(hostname, Qt::DisplayRole); item->setData(hostname, Qt::DisplayRole);
//listModel->setData(listModel->index(item->row(), IP), hostname, Qt::DisplayRole);
} }
} }
@ -399,9 +402,9 @@ void PeerListWidget::handleSortColumnChanged(int col)
{ {
if (col == 0) { if (col == 0) {
qDebug("Sorting by decoration"); qDebug("Sorting by decoration");
proxyModel->setSortRole(Qt::ToolTipRole); m_proxyModel->setSortRole(Qt::ToolTipRole);
} else { } else {
proxyModel->setSortRole(Qt::DisplayRole); m_proxyModel->setSortRole(Qt::DisplayRole);
} }
} }

33
src/properties/peerlistwidget.h

@ -58,16 +58,15 @@ QT_END_NAMESPACE
class PeerListWidget : public QTreeView { class PeerListWidget : public QTreeView {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(PeerListWidget)
public: public:
PeerListWidget(PropertiesWidget *parent); PeerListWidget(PropertiesWidget *parent);
~PeerListWidget(); ~PeerListWidget();
public slots: public slots:
void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution=false); void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution = false);
QStandardItem* addPeer(QString ip, libtorrent::peer_info peer); QStandardItem* addPeer(const QString& ip, const libtorrent::peer_info& peer);
void updatePeer(QString ip, libtorrent::peer_info peer); void updatePeer(const QString& ip, const libtorrent::peer_info& peer);
void handleResolved(const QString &ip, const QString &hostname); void handleResolved(const QString &ip, const QString &hostname);
void updatePeerHostNameResolutionState(); void updatePeerHostNameResolutionState();
void updatePeerCountryResolutionState(); void updatePeerCountryResolutionState();
@ -76,25 +75,25 @@ public slots:
protected slots: protected slots:
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
void showPeerListMenu(QPoint); void showPeerListMenu(const QPoint&);
void limitUpRateSelectedPeers(QStringList peer_ips); void limitUpRateSelectedPeers(const QStringList& peer_ips);
void limitDlRateSelectedPeers(QStringList peer_ips); void limitDlRateSelectedPeers(const QStringList& peer_ips);
void banSelectedPeers(QStringList peer_ips); void banSelectedPeers(const QStringList& peer_ips);
void handleSortColumnChanged(int col); void handleSortColumnChanged(int col);
private: private:
static QString getConnectionString(int connection_type); static QString getConnectionString(int connection_type);
private: private:
QStandardItemModel *listModel; QStandardItemModel *m_listModel;
PeerListDelegate *listDelegate; PeerListDelegate *m_listDelegate;
QSortFilterProxyModel * proxyModel; QSortFilterProxyModel *m_proxyModel;
QHash<QString, QStandardItem*> peerItems; QHash<QString, QStandardItem*> m_peerItems;
QHash<QString, libtorrent::asio::ip::tcp::endpoint> peerEndpoints; QHash<QString, boost::asio::ip::tcp::endpoint> m_peerEndpoints;
QSet<QString> missingFlags; QSet<QString> m_missingFlags;
QPointer<ReverseResolution> resolver; QPointer<ReverseResolution> m_resolver;
PropertiesWidget* properties; PropertiesWidget *m_properties;
bool display_flags; bool m_displayFlags;
}; };
#endif // PEERLISTWIDGET_H #endif // PEERLISTWIDGET_H

14
src/reverseresolution.h

@ -59,20 +59,6 @@ public:
qDebug("Deleting host name resolver..."); qDebug("Deleting host name resolver...");
} }
QString getHostFromCache(const libtorrent::asio::ip::tcp::endpoint &ip) {
boost::system::error_code ec;
const QString ip_str = misc::toQString(ip.address().to_string(ec));
if (ec) return QString();
QString ret;
if (m_cache.contains(ip_str)) {
qDebug("Got host name from cache");
ret = *m_cache.object(ip_str);
} else {
ret = QString::null;
}
return ret;
}
void resolve(const libtorrent::asio::ip::tcp::endpoint &ip) { void resolve(const libtorrent::asio::ip::tcp::endpoint &ip) {
boost::system::error_code ec; boost::system::error_code ec;
const QString ip_str = misc::toQString(ip.address().to_string(ec)); const QString ip_str = misc::toQString(ip.address().to_string(ec));

4
src/torrentcontentmodel.cpp

@ -35,7 +35,7 @@
#include <QDir> #include <QDir>
TorrentContentModel::TorrentContentModel(QObject *parent): TorrentContentModel::TorrentContentModel(QObject *parent):
QAbstractItemModel(parent), m_filesIndex(0), QAbstractItemModel(parent),
m_rootItem(new TorrentContentModelItem(QList<QVariant>() << tr("Name") << tr("Size") m_rootItem(new TorrentContentModelItem(QList<QVariant>() << tr("Name") << tr("Size")
<< tr("Progress") << tr("Priority"))) << tr("Progress") << tr("Priority")))
{ {
@ -50,7 +50,7 @@ TorrentContentModel::~TorrentContentModel()
void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size_type>& fp) void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size_type>& fp)
{ {
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
Q_ASSERT(m_filesIndex.size() == fp.size()); Q_ASSERT(m_filesIndex.size() == (int)fp.size());
for (uint i=0; i<fp.size(); ++i) { for (uint i=0; i<fp.size(); ++i) {
m_filesIndex[i]->setProgress(fp[i]); m_filesIndex[i]->setProgress(fp[i]);
} }

Loading…
Cancel
Save