Browse Source

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

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
3d790d131c
  1. BIN
      src/Icons/flags/australia.png
  2. BIN
      src/Icons/flags/india.png
  3. BIN
      src/Icons/flags/malaysia.png
  4. BIN
      src/Icons/flags/pakistan.png
  5. BIN
      src/Icons/flags/philippines.png
  6. BIN
      src/Icons/flags/south_africa.png
  7. BIN
      src/Icons/flags/thailand.png
  8. 92
      src/geoip.h
  9. 7
      src/icons.qrc
  10. 81
      src/misc.h
  11. 5
      src/peerlistwidget.cpp

BIN
src/Icons/flags/australia.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
src/Icons/flags/india.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

BIN
src/Icons/flags/malaysia.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

BIN
src/Icons/flags/pakistan.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 833 B

BIN
src/Icons/flags/philippines.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

BIN
src/Icons/flags/south_africa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

BIN
src/Icons/flags/thailand.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

92
src/geoip.h

@ -34,6 +34,7 @@
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <QString> #include <QString>
#include <QDir> #include <QDir>
#include <QIcon>
#include <QFile> #include <QFile>
#include "misc.h" #include "misc.h"
@ -106,6 +107,97 @@ public:
qDebug("ERROR: Impossible to find local Geoip Database"); 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 #endif // GEOIP_H

7
src/icons.qrc

@ -43,8 +43,11 @@
<file>Icons/flags/czech.png</file> <file>Icons/flags/czech.png</file>
<file>Icons/flags/china.png</file> <file>Icons/flags/china.png</file>
<file>Icons/flags/norway.png</file> <file>Icons/flags/norway.png</file>
<file>Icons/flags/india.png</file>
<file>Icons/flags/finland.png</file> <file>Icons/flags/finland.png</file>
<file>Icons/flags/australia.png</file>
<file>Icons/flags/netherlands.png</file> <file>Icons/flags/netherlands.png</file>
<file>Icons/flags/south_africa.png</file>
<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>
@ -60,6 +63,7 @@
<file>Icons/flags/portugal.png</file> <file>Icons/flags/portugal.png</file>
<file>Icons/flags/russia.png</file> <file>Icons/flags/russia.png</file>
<file>Icons/flags/united_kingdom.png</file> <file>Icons/flags/united_kingdom.png</file>
<file>Icons/flags/thailand.png</file>
<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>
@ -67,9 +71,12 @@
<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>
<file>Icons/flags/pakistan.png</file>
<file>Icons/flags/italy.png</file> <file>Icons/flags/italy.png</file>
<file>Icons/flags/south_korea.png</file> <file>Icons/flags/south_korea.png</file>
<file>Icons/flags/japan.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/mail-queue.png</file>
<file>Icons/oxygen/view-refresh.png</file> <file>Icons/oxygen/view-refresh.png</file>
<file>Icons/oxygen/file.png</file> <file>Icons/oxygen/file.png</file>

81
src/misc.h

@ -41,7 +41,6 @@
#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>
@ -319,86 +318,6 @@ 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) {

5
src/peerlistwidget.cpp

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

Loading…
Cancel
Save