diff --git a/src/Icons/flags/argentina.png b/src/Icons/flags/argentina.png
new file mode 100644
index 000000000..65a769ccf
Binary files /dev/null and b/src/Icons/flags/argentina.png differ
diff --git a/src/Icons/flags/canada.png b/src/Icons/flags/canada.png
new file mode 100644
index 000000000..a6e35bcca
Binary files /dev/null and b/src/Icons/flags/canada.png differ
diff --git a/src/Icons/flags/usa.png b/src/Icons/flags/usa.png
new file mode 100644
index 000000000..93dec6428
Binary files /dev/null and b/src/Icons/flags/usa.png differ
diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp
index 159a55c19..6b432336a 100644
--- a/src/bittorrent.cpp
+++ b/src/bittorrent.cpp
@@ -842,6 +842,7 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
// Uploads limit per torrent
h.set_max_uploads(maxUploadsPerTorrent);
// Resolve countries
+ qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries);
h.resolve_countries(resolve_countries);
// Load filtered files
loadFilesPriorities(h);
diff --git a/src/icons.qrc b/src/icons.qrc
index e70126d52..49db953d6 100644
--- a/src/icons.qrc
+++ b/src/icons.qrc
@@ -48,12 +48,14 @@
Icons/flags/taiwan.png
Icons/flags/sweden.png
Icons/flags/spain_catalunya.png
+ Icons/flags/usa.png
Icons/flags/romania.png
Icons/flags/denmark.png
Icons/flags/hungary.png
Icons/flags/ukraine.png
Icons/flags/turkey.png
Icons/flags/greece.png
+ Icons/flags/argentina.png
Icons/flags/spain.png
Icons/flags/portugal.png
Icons/flags/russia.png
@@ -61,6 +63,7 @@
Icons/flags/poland.png
Icons/flags/germany.png
Icons/flags/bulgaria.png
+ Icons/flags/canada.png
Icons/flags/brazil.png
Icons/flags/france.png
Icons/flags/slovakia.png
diff --git a/src/misc.h b/src/misc.h
index 2b8d86ceb..f40c8e45f 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -41,6 +41,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -48,13 +49,13 @@
#ifndef Q_WS_WIN
#ifdef Q_WS_MAC
- #include
- #include
+#include
+#include
#else
- #include
+#include
#endif
#else
- #include
+#include
#endif
#include
@@ -143,7 +144,7 @@ public:
unsigned long long *ret;
if (pGetDiskFreeSpaceEx((LPCTSTR)path.ucs2(), &bytesFree, &bytesTotal, NULL)) {
tmp = (unsigned long long*)&bytesFree
- return ret;
+ return ret;
} else {
return -1;
}
@@ -318,6 +319,86 @@ public:
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
// time duration like "1d 2h 10m".
static QString userFriendlyDuration(qlonglong seconds) {
diff --git a/src/peerlistwidget.cpp b/src/peerlistwidget.cpp
index 8794ac1d5..7e025fd87 100644
--- a/src/peerlistwidget.cpp
+++ b/src/peerlistwidget.cpp
@@ -39,7 +39,7 @@
#include
#include
-PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent) {
+PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) {
// Visual settings
setRootIsDecorated(false);
setItemsExpandable(false);
@@ -84,8 +84,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() {
resolver = new ReverseResolution(this);
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString)));
resolver->start();
- clear();
- loadPeers(properties->getCurrentTorrent());
+ loadPeers(properties->getCurrentTorrent(), true);
}
} else {
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() {
qDebug("clearing peer list");
peerItems.clear();
+ missingFlags.clear();
int nbrows = listModel->rowCount();
if(nbrows > 0) {
qDebug("Cleared %d peers", nbrows);
@@ -122,7 +133,7 @@ void PeerListWidget::saveSettings() const {
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;
std::vector peers;
h.get_peer_info(peers);
@@ -135,6 +146,10 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h) {
// Update existing peer
updatePeer(peer_ip, peer);
old_peers_set.remove(peer_ip);
+ if(force_hostname_resolution) {
+ if(resolver)
+ resolver->resolve(peer.ip);
+ }
} else {
// Add new peer
peerItems[peer_ip] = addPeer(peer_ip, peer);
@@ -143,7 +158,9 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h) {
// Delete peers that are gone
QSetIterator it(old_peers_set);
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());
}
}
@@ -156,6 +173,14 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
// Resolve peer host name is asked
if(resolver)
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, PROGRESS), peer.progress);
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) {
QStandardItem *item = peerItems.value(ip);
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, PROGRESS), peer.progress);
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) {
- qDebug("%s was resolved to %s", ip.toLocal8Bit().data(), hostname.toLocal8Bit().data());
QStandardItem *item = peerItems.value(ip, 0);
if(item) {
- qDebug("item was updated");
- //item->setData(hostname);
listModel->setData(listModel->indexFromItem(item), hostname);
}
}
diff --git a/src/peerlistwidget.h b/src/peerlistwidget.h
index e6841cb51..4f8f6e7ec 100644
--- a/src/peerlistwidget.h
+++ b/src/peerlistwidget.h
@@ -34,6 +34,7 @@
#include
#include
#include
+#include
#include "qtorrenthandle.h"
#include "misc.h"
@@ -52,19 +53,22 @@ private:
PeerListDelegate *listDelegate;
QSortFilterProxyModel * proxyModel;
QHash peerItems;
+ QSet missingFlags;
QPointer resolver;
PropertiesWidget* properties;
+ bool display_flags;
public:
PeerListWidget(PropertiesWidget *parent);
~PeerListWidget();
public slots:
- void loadPeers(const QTorrentHandle &h);
+ void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution=false);
QStandardItem* addPeer(QString ip, peer_info peer);
void updatePeer(QString ip, peer_info peer);
void handleResolved(QString ip, QString hostname);
void updatePeerHostNameResolutionState();
+ void updatePeerCountryResolutionState();
void clear();
protected slots:
diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp
index ebf2b5918..b06d3cdd5 100644
--- a/src/propertieswidget.cpp
+++ b/src/propertieswidget.cpp
@@ -267,6 +267,7 @@ void PropertiesWidget::saveSettings() {
void PropertiesWidget::reloadPreferences() {
// Take program preferences into consideration
peersList->updatePeerHostNameResolutionState();
+ peersList->updatePeerCountryResolutionState();
}
void PropertiesWidget::loadDynamicData() {