diff --git a/src/Icons/flags/australia.png b/src/Icons/flags/australia.png new file mode 100644 index 000000000..033dd21bd Binary files /dev/null and b/src/Icons/flags/australia.png differ diff --git a/src/Icons/flags/india.png b/src/Icons/flags/india.png new file mode 100644 index 000000000..8ba6383be Binary files /dev/null and b/src/Icons/flags/india.png differ diff --git a/src/Icons/flags/malaysia.png b/src/Icons/flags/malaysia.png new file mode 100644 index 000000000..e78066ebc Binary files /dev/null and b/src/Icons/flags/malaysia.png differ diff --git a/src/Icons/flags/pakistan.png b/src/Icons/flags/pakistan.png new file mode 100644 index 000000000..16be3bd21 Binary files /dev/null and b/src/Icons/flags/pakistan.png differ diff --git a/src/Icons/flags/philippines.png b/src/Icons/flags/philippines.png new file mode 100644 index 000000000..d33c19c3b Binary files /dev/null and b/src/Icons/flags/philippines.png differ diff --git a/src/Icons/flags/south_africa.png b/src/Icons/flags/south_africa.png new file mode 100644 index 000000000..abc2c22b7 Binary files /dev/null and b/src/Icons/flags/south_africa.png differ diff --git a/src/Icons/flags/thailand.png b/src/Icons/flags/thailand.png new file mode 100644 index 000000000..68e9dee4d Binary files /dev/null and b/src/Icons/flags/thailand.png differ diff --git a/src/geoip.h b/src/geoip.h index 6da142615..e9334d076 100644 --- a/src/geoip.h +++ b/src/geoip.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #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 diff --git a/src/icons.qrc b/src/icons.qrc index 49db953d6..88923b143 100644 --- a/src/icons.qrc +++ b/src/icons.qrc @@ -43,8 +43,11 @@ Icons/flags/czech.png Icons/flags/china.png Icons/flags/norway.png + Icons/flags/india.png Icons/flags/finland.png + Icons/flags/australia.png Icons/flags/netherlands.png + Icons/flags/south_africa.png Icons/flags/taiwan.png Icons/flags/sweden.png Icons/flags/spain_catalunya.png @@ -60,6 +63,7 @@ Icons/flags/portugal.png Icons/flags/russia.png Icons/flags/united_kingdom.png + Icons/flags/thailand.png Icons/flags/poland.png Icons/flags/germany.png Icons/flags/bulgaria.png @@ -67,9 +71,12 @@ Icons/flags/brazil.png Icons/flags/france.png Icons/flags/slovakia.png + Icons/flags/pakistan.png Icons/flags/italy.png Icons/flags/south_korea.png Icons/flags/japan.png + Icons/flags/malaysia.png + Icons/flags/philippines.png Icons/oxygen/mail-queue.png Icons/oxygen/view-refresh.png Icons/oxygen/file.png diff --git a/src/misc.h b/src/misc.h index f40c8e45f..90daa9dea 100644 --- a/src/misc.h +++ b/src/misc.h @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -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) { diff --git a/src/peerlistwidget.cpp b/src/peerlistwidget.cpp index 7e025fd87..c8a0cb789 100644 --- a/src/peerlistwidget.cpp +++ b/src/peerlistwidget.cpp @@ -33,6 +33,7 @@ #include "reverseresolution.h" #include "preferences.h" #include "propertieswidget.h" +#include "geoip.h" #include #include #include @@ -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);