1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 23:07:59 +00:00

- Support a lot more countries in GeoIP (flag display)

This commit is contained in:
Christophe Dumez 2009-11-15 20:27:36 +00:00
parent 9e9e6f028c
commit 3d790d131c
11 changed files with 102 additions and 83 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
src/Icons/flags/india.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@ -34,6 +34,7 @@
#include <libtorrent/session.hpp>
#include <QString>
#include <QDir>
#include <QIcon>
#include <QFile>
#include "misc.h"
@ -106,6 +107,97 @@ public:
qDebug("ERROR: Impossible to find local Geoip Database");
}
}
// 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] == 'U') return QIcon(":/Icons/flags/australia.png");
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");
if(iso[1] == 'N') return QIcon(":/Icons/flags/india.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 'M':
if(iso[1] == 'Y') return QIcon(":/Icons/flags/malaysia.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");
if(iso[1] == 'K') return QIcon(":/Icons/flags/pakistan.png");
if(iso[1] == 'H') return QIcon(":/Icons/flags/philippines.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");
if(iso[1] == 'H') return QIcon(":/Icons/flags/thailand.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;
case 'Z':
if(iso[1] == 'A') return QIcon(":/Icons/flags/south_africa.png");
break;
}
qDebug("Unrecognized country code: %s", iso);
return QIcon();
}
};
#endif // GEOIP_H

View File

@ -43,8 +43,11 @@
<file>Icons/flags/czech.png</file>
<file>Icons/flags/china.png</file>
<file>Icons/flags/norway.png</file>
<file>Icons/flags/india.png</file>
<file>Icons/flags/finland.png</file>
<file>Icons/flags/australia.png</file>
<file>Icons/flags/netherlands.png</file>
<file>Icons/flags/south_africa.png</file>
<file>Icons/flags/taiwan.png</file>
<file>Icons/flags/sweden.png</file>
<file>Icons/flags/spain_catalunya.png</file>
@ -60,6 +63,7 @@
<file>Icons/flags/portugal.png</file>
<file>Icons/flags/russia.png</file>
<file>Icons/flags/united_kingdom.png</file>
<file>Icons/flags/thailand.png</file>
<file>Icons/flags/poland.png</file>
<file>Icons/flags/germany.png</file>
<file>Icons/flags/bulgaria.png</file>
@ -67,9 +71,12 @@
<file>Icons/flags/brazil.png</file>
<file>Icons/flags/france.png</file>
<file>Icons/flags/slovakia.png</file>
<file>Icons/flags/pakistan.png</file>
<file>Icons/flags/italy.png</file>
<file>Icons/flags/south_korea.png</file>
<file>Icons/flags/japan.png</file>
<file>Icons/flags/malaysia.png</file>
<file>Icons/flags/philippines.png</file>
<file>Icons/oxygen/mail-queue.png</file>
<file>Icons/oxygen/view-refresh.png</file>
<file>Icons/oxygen/file.png</file>

View File

@ -41,7 +41,6 @@
#include <QList>
#include <QPair>
#include <QThread>
#include <QIcon>
#include <ctime>
#include <QDateTime>
#include <boost/date_time/posix_time/posix_time_types.hpp>
@ -319,86 +318,6 @@ 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) {

View File

@ -33,6 +33,7 @@
#include "reverseresolution.h"
#include "preferences.h"
#include "propertieswidget.h"
#include "geoip.h"
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include <QSet>
@ -174,7 +175,7 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
if(resolver)
resolver->resolve(peer.ip);
if(display_flags) {
QIcon ico = misc::CountryISOCodeToIcon(peer.country);
QIcon ico = GeoIP::CountryISOCodeToIcon(peer.country);
if(!ico.isNull()) {
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
} else {
@ -194,7 +195,7 @@ 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);
QIcon ico = GeoIP::CountryISOCodeToIcon(peer.country);
if(!ico.isNull()) {
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
missingFlags.remove(ip);