Browse Source

- Implemented flag display in peer list (has to be enabled in program preferences, connection section)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
c5c09b09ee
  1. BIN
      src/Icons/flags/argentina.png
  2. BIN
      src/Icons/flags/canada.png
  3. BIN
      src/Icons/flags/usa.png
  4. 1
      src/bittorrent.cpp
  5. 3
      src/icons.qrc
  6. 81
      src/misc.h
  7. 45
      src/peerlistwidget.cpp
  8. 6
      src/peerlistwidget.h
  9. 1
      src/propertieswidget.cpp

BIN
src/Icons/flags/argentina.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
src/Icons/flags/canada.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 B

BIN
src/Icons/flags/usa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

1
src/bittorrent.cpp

@ -842,6 +842,7 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
// Uploads limit per torrent // Uploads limit per torrent
h.set_max_uploads(maxUploadsPerTorrent); h.set_max_uploads(maxUploadsPerTorrent);
// Resolve countries // Resolve countries
qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries);
h.resolve_countries(resolve_countries); h.resolve_countries(resolve_countries);
// Load filtered files // Load filtered files
loadFilesPriorities(h); loadFilesPriorities(h);

3
src/icons.qrc

@ -48,12 +48,14 @@
<file>Icons/flags/taiwan.png</file> <file>Icons/flags/taiwan.png</file>
<file>Icons/flags/sweden.png</file> <file>Icons/flags/sweden.png</file>
<file>Icons/flags/spain_catalunya.png</file> <file>Icons/flags/spain_catalunya.png</file>
<file>Icons/flags/usa.png</file>
<file>Icons/flags/romania.png</file> <file>Icons/flags/romania.png</file>
<file>Icons/flags/denmark.png</file> <file>Icons/flags/denmark.png</file>
<file>Icons/flags/hungary.png</file> <file>Icons/flags/hungary.png</file>
<file>Icons/flags/ukraine.png</file> <file>Icons/flags/ukraine.png</file>
<file>Icons/flags/turkey.png</file> <file>Icons/flags/turkey.png</file>
<file>Icons/flags/greece.png</file> <file>Icons/flags/greece.png</file>
<file>Icons/flags/argentina.png</file>
<file>Icons/flags/spain.png</file> <file>Icons/flags/spain.png</file>
<file>Icons/flags/portugal.png</file> <file>Icons/flags/portugal.png</file>
<file>Icons/flags/russia.png</file> <file>Icons/flags/russia.png</file>
@ -61,6 +63,7 @@
<file>Icons/flags/poland.png</file> <file>Icons/flags/poland.png</file>
<file>Icons/flags/germany.png</file> <file>Icons/flags/germany.png</file>
<file>Icons/flags/bulgaria.png</file> <file>Icons/flags/bulgaria.png</file>
<file>Icons/flags/canada.png</file>
<file>Icons/flags/brazil.png</file> <file>Icons/flags/brazil.png</file>
<file>Icons/flags/france.png</file> <file>Icons/flags/france.png</file>
<file>Icons/flags/slovakia.png</file> <file>Icons/flags/slovakia.png</file>

81
src/misc.h

@ -41,6 +41,7 @@
#include <QList> #include <QList>
#include <QPair> #include <QPair>
#include <QThread> #include <QThread>
#include <QIcon>
#include <ctime> #include <ctime>
#include <QDateTime> #include <QDateTime>
#include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp>
@ -318,6 +319,86 @@ public:
return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate); return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate);
} }
// TODO: Support more countries
// http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
static QIcon CountryISOCodeToIcon(char* iso) {
switch(iso[0]) {
case 0:
case '-':
case '!':
//qDebug("Not returning any icon because iso is invalid: %s", iso);
return QIcon();
case 'A':
if(iso[1] == 'R') return QIcon(":/Icons/flags/argentina.png");
break;
case 'B':
if(iso[1] == 'R') return QIcon(":/Icons/flags/brazil.png");
if(iso[1] == 'G') return QIcon(":/Icons/flags/bulgaria.png");
break;
case 'C':
if(iso[1] == 'A') return QIcon(":/Icons/flags/canada.png");
if(iso[1] == 'Z') return QIcon(":/Icons/flags/czech.png");
if(iso[1] == 'C') return QIcon(":/Icons/flags/china.png");
break;
case 'D':
if(iso[1] == 'E') return QIcon(":/Icons/flags/germany.png");
if(iso[1] == 'K') return QIcon(":/Icons/flags/denmark.png");
break;
case 'E':
if(iso[1] == 'S') return QIcon(":/Icons/flags/spain.png");
break;
case 'F':
if(iso[1] == 'I') return QIcon(":/Icons/flags/finland.png");
if(iso[1] == 'R') return QIcon(":/Icons/flags/france.png");
break;
case 'G':
if(iso[1] == 'B') return QIcon(":/Icons/flags/united_kingdom.png");
if(iso[1] == 'R') return QIcon(":/Icons/flags/greece.png");
break;
case 'H':
if(iso[1] == 'U') return QIcon(":/Icons/flags/hungary.png");
if(iso[1] == 'K') return QIcon(":/Icons/flags/china.png");
break;
case 'I':
if(iso[1] == 'T') return QIcon(":/Icons/flags/italy.png");
break;
case 'J':
if(iso[1] == 'P') return QIcon(":/Icons/flags/japan.png");
break;
case 'K':
if(iso[1] == 'R') return QIcon(":/Icons/flags/south_korea.png");
break;
case 'N':
if(iso[1] == 'L') return QIcon(":/Icons/flags/netherlands.png");
if(iso[1] == 'O') return QIcon(":/Icons/flags/norway.png");
break;
case 'P':
if(iso[1] == 'T') return QIcon(":/Icons/flags/portugal.png");
if(iso[1] == 'L') return QIcon(":/Icons/flags/poland.png");
break;
case 'R':
if(iso[1] == 'U') return QIcon(":/Icons/flags/russia.png");
if(iso[1] == 'O') return QIcon(":/Icons/flags/romania.png");
if(iso[1] == 'E') return QIcon(":/Icons/flags/france.png");
break;
case 'S':
if(iso[1] == 'E') return QIcon(":/Icons/flags/sweden.png");
if(iso[1] == 'K') return QIcon(":/Icons/flags/slovakia.png");
break;
case 'T':
if(iso[1] == 'W') return QIcon(":/Icons/flags/china.png");
if(iso[1] == 'R') return QIcon(":/Icons/flags/turkey.png");
break;
case 'U':
if(iso[1] == 'S') return QIcon(":/Icons/flags/usa.png");
if(iso[1] == 'M') return QIcon(":/Icons/flags/usa.png");
if(iso[1] == 'A') return QIcon(":/Icons/flags/ukraine.png");
break;
}
qDebug("Unrecognized country code: %s", iso);
return QIcon();
}
// Take a number of seconds and return an user-friendly // Take a number of seconds and return an user-friendly
// time duration like "1d 2h 10m". // time duration like "1d 2h 10m".
static QString userFriendlyDuration(qlonglong seconds) { static QString userFriendlyDuration(qlonglong seconds) {

45
src/peerlistwidget.cpp

@ -39,7 +39,7 @@
#include <QSettings> #include <QSettings>
#include <vector> #include <vector>
PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent) { PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) {
// Visual settings // Visual settings
setRootIsDecorated(false); setRootIsDecorated(false);
setItemsExpandable(false); setItemsExpandable(false);
@ -84,8 +84,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() {
resolver = new ReverseResolution(this); resolver = new ReverseResolution(this);
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString))); connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString)));
resolver->start(); resolver->start();
clear(); loadPeers(properties->getCurrentTorrent(), true);
loadPeers(properties->getCurrentTorrent());
} }
} else { } else {
if(resolver) if(resolver)
@ -93,9 +92,21 @@ void PeerListWidget::updatePeerHostNameResolutionState() {
} }
} }
void PeerListWidget::updatePeerCountryResolutionState() {
if(Preferences::resolvePeerCountries() != display_flags) {
display_flags = !display_flags;
if(display_flags) {
const QTorrentHandle &h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
loadPeers(h);
}
}
}
void PeerListWidget::clear() { void PeerListWidget::clear() {
qDebug("clearing peer list"); qDebug("clearing peer list");
peerItems.clear(); peerItems.clear();
missingFlags.clear();
int nbrows = listModel->rowCount(); int nbrows = listModel->rowCount();
if(nbrows > 0) { if(nbrows > 0) {
qDebug("Cleared %d peers", nbrows); qDebug("Cleared %d peers", nbrows);
@ -122,7 +133,7 @@ void PeerListWidget::saveSettings() const {
settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths); settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths);
} }
void PeerListWidget::loadPeers(const QTorrentHandle &h) { void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) {
if(!h.is_valid()) return; if(!h.is_valid()) return;
std::vector<peer_info> peers; std::vector<peer_info> peers;
h.get_peer_info(peers); h.get_peer_info(peers);
@ -135,6 +146,10 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h) {
// 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(resolver)
resolver->resolve(peer.ip);
}
} else { } else {
// Add new peer // Add new peer
peerItems[peer_ip] = addPeer(peer_ip, peer); peerItems[peer_ip] = addPeer(peer_ip, peer);
@ -143,7 +158,9 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h) {
// 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()) {
QStandardItem *item = peerItems.take(it.next()); QString ip = it.next();
missingFlags.remove(ip);
QStandardItem *item = peerItems.take(ip);
listModel->removeRow(item->row()); listModel->removeRow(item->row());
} }
} }
@ -156,6 +173,14 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
// Resolve peer host name is asked // Resolve peer host name is asked
if(resolver) if(resolver)
resolver->resolve(peer.ip); resolver->resolve(peer.ip);
if(display_flags) {
QIcon ico = misc::CountryISOCodeToIcon(peer.country);
if(!ico.isNull()) {
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
} else {
missingFlags.insert(ip);
}
}
listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client)); listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client));
listModel->setData(listModel->index(row, PROGRESS), peer.progress); listModel->setData(listModel->index(row, PROGRESS), peer.progress);
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed); listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);
@ -168,6 +193,13 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
void PeerListWidget::updatePeer(QString ip, peer_info peer) { void PeerListWidget::updatePeer(QString ip, peer_info peer) {
QStandardItem *item = peerItems.value(ip); QStandardItem *item = peerItems.value(ip);
int row = item->row(); int row = item->row();
if(display_flags) {
QIcon ico = misc::CountryISOCodeToIcon(peer.country);
if(!ico.isNull()) {
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
missingFlags.remove(ip);
}
}
listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client)); listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client));
listModel->setData(listModel->index(row, PROGRESS), peer.progress); listModel->setData(listModel->index(row, PROGRESS), peer.progress);
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed); listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);
@ -177,11 +209,8 @@ void PeerListWidget::updatePeer(QString ip, peer_info peer) {
} }
void PeerListWidget::handleResolved(QString ip, QString hostname) { void PeerListWidget::handleResolved(QString ip, QString hostname) {
qDebug("%s was resolved to %s", ip.toLocal8Bit().data(), hostname.toLocal8Bit().data());
QStandardItem *item = peerItems.value(ip, 0); QStandardItem *item = peerItems.value(ip, 0);
if(item) { if(item) {
qDebug("item was updated");
//item->setData(hostname);
listModel->setData(listModel->indexFromItem(item), hostname); listModel->setData(listModel->indexFromItem(item), hostname);
} }
} }

6
src/peerlistwidget.h

@ -34,6 +34,7 @@
#include <QTreeView> #include <QTreeView>
#include <QHash> #include <QHash>
#include <QPointer> #include <QPointer>
#include <QSet>
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
#include "misc.h" #include "misc.h"
@ -52,19 +53,22 @@ private:
PeerListDelegate *listDelegate; PeerListDelegate *listDelegate;
QSortFilterProxyModel * proxyModel; QSortFilterProxyModel * proxyModel;
QHash<QString, QStandardItem*> peerItems; QHash<QString, QStandardItem*> peerItems;
QSet<QString> missingFlags;
QPointer<ReverseResolution> resolver; QPointer<ReverseResolution> resolver;
PropertiesWidget* properties; PropertiesWidget* properties;
bool display_flags;
public: public:
PeerListWidget(PropertiesWidget *parent); PeerListWidget(PropertiesWidget *parent);
~PeerListWidget(); ~PeerListWidget();
public slots: public slots:
void loadPeers(const QTorrentHandle &h); void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution=false);
QStandardItem* addPeer(QString ip, peer_info peer); QStandardItem* addPeer(QString ip, peer_info peer);
void updatePeer(QString ip, peer_info peer); void updatePeer(QString ip, peer_info peer);
void handleResolved(QString ip, QString hostname); void handleResolved(QString ip, QString hostname);
void updatePeerHostNameResolutionState(); void updatePeerHostNameResolutionState();
void updatePeerCountryResolutionState();
void clear(); void clear();
protected slots: protected slots:

1
src/propertieswidget.cpp

@ -267,6 +267,7 @@ void PropertiesWidget::saveSettings() {
void PropertiesWidget::reloadPreferences() { void PropertiesWidget::reloadPreferences() {
// Take program preferences into consideration // Take program preferences into consideration
peersList->updatePeerHostNameResolutionState(); peersList->updatePeerHostNameResolutionState();
peersList->updatePeerCountryResolutionState();
} }
void PropertiesWidget::loadDynamicData() { void PropertiesWidget::loadDynamicData() {

Loading…
Cancel
Save