From 3d790d131c85db405646597378546ec6cf49f9f8 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 15 Nov 2009 20:27:36 +0000 Subject: [PATCH] - Support a lot more countries in GeoIP (flag display) --- src/Icons/flags/australia.png | Bin 0 -> 1153 bytes src/Icons/flags/india.png | Bin 0 -> 400 bytes src/Icons/flags/malaysia.png | Bin 0 -> 643 bytes src/Icons/flags/pakistan.png | Bin 0 -> 833 bytes src/Icons/flags/philippines.png | Bin 0 -> 680 bytes src/Icons/flags/south_africa.png | Bin 0 -> 773 bytes src/Icons/flags/thailand.png | Bin 0 -> 198 bytes src/geoip.h | 92 +++++++++++++++++++++++++++++++ src/icons.qrc | 7 +++ src/misc.h | 81 --------------------------- src/peerlistwidget.cpp | 5 +- 11 files changed, 102 insertions(+), 83 deletions(-) create mode 100644 src/Icons/flags/australia.png create mode 100644 src/Icons/flags/india.png create mode 100644 src/Icons/flags/malaysia.png create mode 100644 src/Icons/flags/pakistan.png create mode 100644 src/Icons/flags/philippines.png create mode 100644 src/Icons/flags/south_africa.png create mode 100644 src/Icons/flags/thailand.png diff --git a/src/Icons/flags/australia.png b/src/Icons/flags/australia.png new file mode 100644 index 0000000000000000000000000000000000000000..033dd21bdc961b9c5813ae005b4a38b7b2b29de7 GIT binary patch literal 1153 zcmV-{1b+L8P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L004LZ004La>hfy#00007bV*G`2iXe` z6a^*w3hk}{00aR^L_t(I%Z-#>XdG1-hMzMtyOU{V+-#Dr-6p+gveq>Hw+(^PO5Ka9 zZN-9=pn_5gK@dgoB7$HpiWRS_*!lxPsZ>NS1S?3b*4Cd8sbJHzU`^7dn{;cF>^8}6 zva>%k=XkN}CR(Y!aBj|b&iTIg``-76;g@@4(-V*J=I3J^{p2#K6$|izB47d;-1*fLNJh{c8H*VpqTg$OjGjAQgzg#I(iKYpRcb5D>PBUrzrNkfoSt6_YF=un6hOc4fOKezo9i@DxE?#D9 zVv3!G44;OV^2S61y72LpC?`WOJL{52+$NVR0wAS_nC@6DbJ-lXW<5No4#%CQ29H!S zO^t04ZdpNUVwQYS5~{aZ9V+tnR0}U9)?$b}o)U{#2u#zUP$*S*jQ3if#=f_K)|Cxx zsw+^Fy-iw~SVs>N*xZ5Wex6kmql{b_VZgOHr`K|}{{|$INDQC^2!t?D%BN7s0|v{M z)w6HkX0&7DVWuLjbna-!%Vc@?e4Z2OD9e_InRk}bbK0eE>1LWAXrsNQj&Fus&W;oS zg;bKQTib}o*PxUK=m=o}lEy}xc)Sh$aL*ze;oD)DX6A@JvIJTfur> zcz=j5z8u7eMA+2g&^dR7^lX7kw+euuyZb?6u?T0*45DcPl#+nLb$tc~#?klQx25;| zz)fB`d7GcFdw|3W1aRtVIiGd-{>mJM+!W`2%`li!L|dYa-^_4vd>(<$^o+~kV3Ntn zEJ~HN-_+EI=SdQY1j6Q7IY$uCD<;taiD3lrJXtZ12Dm_wKq!oso2O8!NR?v62PRO~ z{$FV9b6kq@~fIul0-TTYY5-E#hG8yvu0zzoj z$ln~fetk3XcpF_^TW}n+lHhJAGZ8{V*MmS1&`^qhCQv{CP18uF<`^AK5eh9~p@nyY zM=Tbhr{@tuA*(WvGUr9m07+lp2>bUR$M+@4is_f07IlN Tn_BlC00000NkvXXu0mjf#VjJ9 literal 0 HcmV?d00001 diff --git a/src/Icons/flags/india.png b/src/Icons/flags/india.png new file mode 100644 index 0000000000000000000000000000000000000000..8ba6383beb300046054ca004ccccdc6c4549fa9d GIT binary patch literal 400 zcmeAS@N?(olHy`uVBq!ia0vp^l0YoT!3HEXcCqsTDVAa<&kznEsNqQI0P;BtJR*yM zbT9}retemf1!PE;xJHx&=ckpFCl;kLl$V$5W#(lUCnpx9>g5-u&wghk1ysZXQWTO| zl9S4ykeQc~nP{->gCbB|93<{oT9T1p#Nd-yT9jF=;GI~IlbKhXo#`Z%R1Q>f$jG^{jNA#lx&*EyTf_T)8qa6er?TsFOP1We0=k@u3KB{?r*+R6ZAi} z;}6^U$&5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/philippines.png b/src/Icons/flags/philippines.png new file mode 100644 index 0000000000000000000000000000000000000000..d33c19c3b5bf6b39fd24ee96c0c85134a2f2d98a GIT binary patch literal 680 zcmV;Z0$2TsP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L002_}002_~@#$h}00007bV*G`2iXe` z6c8oMzYDqm00JmUL_t(I%dM2lOO#<0#((ekePdahZfLoQ7SW~xyR4)ds9n2)puZr9 zsEvzsC?PVF32ISx#l*shf(n|2g_MPqLg^?L1yh-3%``fW=3KtZds@sa3IlCs-sQV^ zp7Z=T&ry#$zsQmL9!5uhfuSh%Q*I_MvolE=uTF5TC5-kosL~l3-t;;NDb8E#rv=-cT&Ek8EeHhlwswuWf>ZdQ`bC9=;_FU zu_;e`l8v-tkKD%@@62&4TSnQsgIJY*7Og!1K=#vZB=s3{{c%FIZS>uEf-()%JSO=B zHg2?=RJZ{*{u<6gXu8@z-h6DZ6DiO*S6u@ht>?JVAK7-jenPotl`#HnpShu@+o zD@_joWNaMgL=$dXM}F4AdSD^KpG}rb2Dkk#Zha#%@e_qv+%0lqFGvra0zmf@D2$Ehwa59REb5AHTvm7C^p_qcBP;4)7Z{DG+P*O1aAb O0000Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L004FX004FYPJ1Q@00007bV*G`2iXe` z6cQRp??eRv00MC}4 zLF2wGmpiV>6%-wvUbMH(b3qUYA)x^T)?Akel!S%zWf-|pNwt*|sY;zwmjTMP;igCca6P!-XArvwku);O zeGg90X*GWKyUUdj4Z;M3Aj$F}E-wT#IBN?q5LnbASwsZzj|X~7zyr!7_aKxMU6IQj zSLF)Y*)i{JYj@2H0zyiWD2Y&;Z=!p5AvNY(vj*RLVhcf7pcxnp@p@-VNv$(CdZV_i zY~0(_G`j@=4OO!LcJdKJ(d6^uT5oTUC#KXiCfV(O(pKt)cy4-wvvDS=0N~P+Bymw% zcipZ_BPY`Lr_|I;DOFWJvH?ip7%eu=ChZC82DT|N)7f|QzQZ-8Ny*=CbD7QVZ2%4b zH(ksRhe$==#jPhT!^fVou9qq?qz}cJ&7RyyE(d_WIfYDcvA%~e00000NkvXXu0mjf D{i#zY literal 0 HcmV?d00001 diff --git a/src/Icons/flags/thailand.png b/src/Icons/flags/thailand.png new file mode 100644 index 0000000000000000000000000000000000000000..68e9dee4d61d4156f5d6f6387d944538ff16d07c GIT binary patch literal 198 zcmeAS@N?(olHy`uVBq!ia0vp^5*h@TpUDEZ0+4!4-|6qba4!^IGtQ` z?!brnjcpB`jmH{VU1R4i6Epbt|9^c4`^B!_@=R$Lo=cnC$^?3&94sbH&)@O6-emE^ kuLrYBOK-7VoS?ssG4ZBomwlw4KF~x4Pgg&ebxsLQ0NId2{{R30 literal 0 HcmV?d00001 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);