1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2009-07-07
7  * Description : country selector combo-box.
8  *
9  * Copyright (C) 2009-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "countryselector.h"
25 
26 // Qt includes
27 
28 #include <QMap>
29 
30 // KDE includes
31 
32 #include <klocalizedstring.h>
33 
34 // Local includes
35 
36 #include "digikam_debug.h"
37 
38 namespace Digikam
39 {
40 
41 class Q_DECL_HIDDEN CountrySelector::Private
42 {
43 public:
44 
Private()45     explicit Private()
46     {
47         /**
48          * NOTE: We cannot use KLocale::allCountriesList() here because KDE only
49          * support 2 characters country codes. XMP require 3 characters country
50          * following ISO 3166 (userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html)
51          */
52 
53         // Standard ISO 3166 country codes.
54 
55         countryCodeMap.insert( QLatin1String("AFG"), i18nc("@info: country code", "Afghanistan") );
56         countryCodeMap.insert( QLatin1String("ALB"), i18nc("@info: country code", "Albania") );
57         countryCodeMap.insert( QLatin1String("DZA"), i18nc("@info: country code", "Algeria") );
58         countryCodeMap.insert( QLatin1String("ASM"), i18nc("@info: country code", "American Samoa") );
59         countryCodeMap.insert( QLatin1String("AND"), i18nc("@info: country code", "Andorra") );
60         countryCodeMap.insert( QLatin1String("AGO"), i18nc("@info: country code", "Angola") );
61         countryCodeMap.insert( QLatin1String("AIA"), i18nc("@info: country code", "Anguilla") );
62         countryCodeMap.insert( QLatin1String("AGO"), i18nc("@info: country code", "Angola") );
63         countryCodeMap.insert( QLatin1String("ATA"), i18nc("@info: country code", "Antarctica") );
64         countryCodeMap.insert( QLatin1String("ATG"), i18nc("@info: country code", "Antigua and Barbuda") );
65         countryCodeMap.insert( QLatin1String("ARG"), i18nc("@info: country code", "Argentina") );
66         countryCodeMap.insert( QLatin1String("ARM"), i18nc("@info: country code", "Armenia") );
67         countryCodeMap.insert( QLatin1String("ABW"), i18nc("@info: country code", "Aruba") );
68         countryCodeMap.insert( QLatin1String("AUS"), i18nc("@info: country code", "Australia") );
69         countryCodeMap.insert( QLatin1String("AUT"), i18nc("@info: country code", "Austria") );
70         countryCodeMap.insert( QLatin1String("AZE"), i18nc("@info: country code", "Azerbaijan") );
71         countryCodeMap.insert( QLatin1String("BHS"), i18nc("@info: country code", "Bahamas") );
72         countryCodeMap.insert( QLatin1String("BHR"), i18nc("@info: country code", "Bahrain") );
73         countryCodeMap.insert( QLatin1String("BGD"), i18nc("@info: country code", "Bangladesh") );
74         countryCodeMap.insert( QLatin1String("BRB"), i18nc("@info: country code", "Barbados") );
75         countryCodeMap.insert( QLatin1String("BLR"), i18nc("@info: country code", "Belarus") );
76         countryCodeMap.insert( QLatin1String("BEL"), i18nc("@info: country code", "Belgium") );
77         countryCodeMap.insert( QLatin1String("BLZ"), i18nc("@info: country code", "Belize") );
78         countryCodeMap.insert( QLatin1String("BEN"), i18nc("@info: country code", "Benin") );
79         countryCodeMap.insert( QLatin1String("BMU"), i18nc("@info: country code", "Bermuda") );
80         countryCodeMap.insert( QLatin1String("BTN"), i18nc("@info: country code", "Bhutan") );
81         countryCodeMap.insert( QLatin1String("BOL"), i18nc("@info: country code", "Bolivia") );
82         countryCodeMap.insert( QLatin1String("BIH"), i18nc("@info: country code", "Bosnia and Herzegovina") );
83         countryCodeMap.insert( QLatin1String("BWA"), i18nc("@info: country code", "Botswana") );
84         countryCodeMap.insert( QLatin1String("BVT"), i18nc("@info: country code", "Bouvet Island") );
85         countryCodeMap.insert( QLatin1String("BRA"), i18nc("@info: country code", "Brazil") );
86         countryCodeMap.insert( QLatin1String("IOT"), i18nc("@info: country code", "British Indian Ocean Territory") );
87         countryCodeMap.insert( QLatin1String("VGB"), i18nc("@info: country code", "British Virgin Islands") );
88         countryCodeMap.insert( QLatin1String("BRN"), i18nc("@info: country code", "Brunei Darussalam") );
89         countryCodeMap.insert( QLatin1String("BGR"), i18nc("@info: country code", "Bulgaria") );
90         countryCodeMap.insert( QLatin1String("BFA"), i18nc("@info: country code", "Burkina Faso") );
91         countryCodeMap.insert( QLatin1String("BDI"), i18nc("@info: country code", "Burundi") );
92         countryCodeMap.insert( QLatin1String("KHM"), i18nc("@info: country code", "Cambodia") );
93         countryCodeMap.insert( QLatin1String("CMR"), i18nc("@info: country code", "Cameroon") );
94         countryCodeMap.insert( QLatin1String("CAN"), i18nc("@info: country code", "Canada") );
95         countryCodeMap.insert( QLatin1String("CPV"), i18nc("@info: country code", "Cape Verde") );
96         countryCodeMap.insert( QLatin1String("CYM"), i18nc("@info: country code", "Cayman Islands") );
97         countryCodeMap.insert( QLatin1String("CAF"), i18nc("@info: country code", "Central African Republic") );
98         countryCodeMap.insert( QLatin1String("TCD"), i18nc("@info: country code", "Chad") );
99         countryCodeMap.insert( QLatin1String("CHL"), i18nc("@info: country code", "Chile") );
100         countryCodeMap.insert( QLatin1String("CHN"), i18nc("@info: country code", "China") );
101         countryCodeMap.insert( QLatin1String("CXR"), i18nc("@info: country code", "Christmas Island ") );
102         countryCodeMap.insert( QLatin1String("CCK"), i18nc("@info: country code", "Cocos Islands") );
103         countryCodeMap.insert( QLatin1String("COL"), i18nc("@info: country code", "Colombia") );
104         countryCodeMap.insert( QLatin1String("COM"), i18nc("@info: country code", "Comoros") );
105         countryCodeMap.insert( QLatin1String("COD"), i18nc("@info: country code", "Zaire") );
106         countryCodeMap.insert( QLatin1String("COG"), i18nc("@info: country code", "Congo") );
107         countryCodeMap.insert( QLatin1String("COK"), i18nc("@info: country code", "Cook Islands") );
108         countryCodeMap.insert( QLatin1String("CRI"), i18nc("@info: country code", "Costa Rica") );
109         countryCodeMap.insert( QLatin1String("CIV"), i18nc("@info: country code", "Ivory Coast") );
110         countryCodeMap.insert( QLatin1String("CUB"), i18nc("@info: country code", "Cuba") );
111         countryCodeMap.insert( QLatin1String("CYP"), i18nc("@info: country code", "Cyprus") );
112         countryCodeMap.insert( QLatin1String("CZE"), i18nc("@info: country code", "Czechia") );
113         countryCodeMap.insert( QLatin1String("DNK"), i18nc("@info: country code", "Denmark") );
114         countryCodeMap.insert( QLatin1String("DJI"), i18nc("@info: country code", "Djibouti") );
115         countryCodeMap.insert( QLatin1String("DMA"), i18nc("@info: country code", "Dominica") );
116         countryCodeMap.insert( QLatin1String("DOM"), i18nc("@info: country code", "Dominican Republic") );
117         countryCodeMap.insert( QLatin1String("ECU"), i18nc("@info: country code", "Ecuador") );
118         countryCodeMap.insert( QLatin1String("EGY"), i18nc("@info: country code", "Egypt") );
119         countryCodeMap.insert( QLatin1String("SLV"), i18nc("@info: country code", "El Salvador") );
120         countryCodeMap.insert( QLatin1String("GNQ"), i18nc("@info: country code", "Equatorial Guinea") );
121         countryCodeMap.insert( QLatin1String("ERI"), i18nc("@info: country code", "Eritrea") );
122         countryCodeMap.insert( QLatin1String("EST"), i18nc("@info: country code", "Estonia") );
123         countryCodeMap.insert( QLatin1String("ETH"), i18nc("@info: country code", "Ethiopia") );
124         countryCodeMap.insert( QLatin1String("FRO"), i18nc("@info: country code", "Faeroe Islands") );
125         countryCodeMap.insert( QLatin1String("FLK"), i18nc("@info: country code", "Falkland Islands") );
126         countryCodeMap.insert( QLatin1String("FJI"), i18nc("@info: country code", "Fiji Islands") );
127         countryCodeMap.insert( QLatin1String("FIN"), i18nc("@info: country code", "Finland") );
128         countryCodeMap.insert( QLatin1String("FRA"), i18nc("@info: country code", "France") );
129         countryCodeMap.insert( QLatin1String("GUF"), i18nc("@info: country code", "French Guiana") );
130         countryCodeMap.insert( QLatin1String("PYF"), i18nc("@info: country code", "French Polynesia") );
131         countryCodeMap.insert( QLatin1String("ATF"), i18nc("@info: country code", "French Southern Territories") );
132         countryCodeMap.insert( QLatin1String("GAB"), i18nc("@info: country code", "Gabon") );
133         countryCodeMap.insert( QLatin1String("GMB"), i18nc("@info: country code", "Gambia") );
134         countryCodeMap.insert( QLatin1String("GEO"), i18nc("@info: country code", "Georgia") );
135         countryCodeMap.insert( QLatin1String("DEU"), i18nc("@info: country code", "Germany") );
136         countryCodeMap.insert( QLatin1String("GHA"), i18nc("@info: country code", "Ghana") );
137         countryCodeMap.insert( QLatin1String("GIB"), i18nc("@info: country code", "Gibraltar") );
138         countryCodeMap.insert( QLatin1String("GRC"), i18nc("@info: country code", "Greece") );
139         countryCodeMap.insert( QLatin1String("GRL"), i18nc("@info: country code", "Greenland") );
140         countryCodeMap.insert( QLatin1String("GRD"), i18nc("@info: country code", "Grenada") );
141         countryCodeMap.insert( QLatin1String("GLP"), i18nc("@info: country code", "Guadaloupe") );
142         countryCodeMap.insert( QLatin1String("GUM"), i18nc("@info: country code", "Guam") );
143         countryCodeMap.insert( QLatin1String("GTM"), i18nc("@info: country code", "Guatemala") );
144         countryCodeMap.insert( QLatin1String("GIN"), i18nc("@info: country code", "Guinea") );
145         countryCodeMap.insert( QLatin1String("GNB"), i18nc("@info: country code", "Guinea-Bissau") );
146         countryCodeMap.insert( QLatin1String("GUY"), i18nc("@info: country code", "Guyana") );
147         countryCodeMap.insert( QLatin1String("HTI"), i18nc("@info: country code", "Haiti") );
148         countryCodeMap.insert( QLatin1String("HMD"), i18nc("@info: country code", "Heard and McDonald Islands") );
149         countryCodeMap.insert( QLatin1String("VAT"), i18nc("@info: country code", "Vatican") );
150         countryCodeMap.insert( QLatin1String("HND"), i18nc("@info: country code", "Honduras") );
151         countryCodeMap.insert( QLatin1String("HKG"), i18nc("@info: country code", "Hong Kong") );
152         countryCodeMap.insert( QLatin1String("HRV"), i18nc("@info: country code", "Croatia") );
153         countryCodeMap.insert( QLatin1String("HUN"), i18nc("@info: country code", "Hungary") );
154         countryCodeMap.insert( QLatin1String("ISL"), i18nc("@info: country code", "Iceland") );
155         countryCodeMap.insert( QLatin1String("IND"), i18nc("@info: country code", "India") );
156         countryCodeMap.insert( QLatin1String("IDN"), i18nc("@info: country code", "Indonesia") );
157         countryCodeMap.insert( QLatin1String("IRN"), i18nc("@info: country code", "Iran") );
158         countryCodeMap.insert( QLatin1String("IRQ"), i18nc("@info: country code", "Iraq") );
159         countryCodeMap.insert( QLatin1String("IRL"), i18nc("@info: country code", "Ireland") );
160         countryCodeMap.insert( QLatin1String("ISR"), i18nc("@info: country code", "Israel") );
161         countryCodeMap.insert( QLatin1String("ITA"), i18nc("@info: country code", "Italy") );
162         countryCodeMap.insert( QLatin1String("JAM"), i18nc("@info: country code", "Jamaica") );
163         countryCodeMap.insert( QLatin1String("JPN"), i18nc("@info: country code", "Japan") );
164         countryCodeMap.insert( QLatin1String("JOR"), i18nc("@info: country code", "Jordan") );
165         countryCodeMap.insert( QLatin1String("KAZ"), i18nc("@info: country code", "Kazakhstan") );
166         countryCodeMap.insert( QLatin1String("KEN"), i18nc("@info: country code", "Kenya") );
167         countryCodeMap.insert( QLatin1String("KIR"), i18nc("@info: country code", "Kiribati") );
168         countryCodeMap.insert( QLatin1String("PRK"), i18nc("@info: country code", "North-Korea") );
169         countryCodeMap.insert( QLatin1String("KOR"), i18nc("@info: country code", "South-Korea") );
170         countryCodeMap.insert( QLatin1String("KWT"), i18nc("@info: country code", "Kuwait") );
171         countryCodeMap.insert( QLatin1String("KGZ"), i18nc("@info: country code", "Kyrgyz Republic") );
172         countryCodeMap.insert( QLatin1String("LAO"), i18nc("@info: country code", "Lao") );
173         countryCodeMap.insert( QLatin1String("LVA"), i18nc("@info: country code", "Latvia") );
174         countryCodeMap.insert( QLatin1String("LBN"), i18nc("@info: country code", "Lebanon") );
175         countryCodeMap.insert( QLatin1String("LSO"), i18nc("@info: country code", "Lesotho") );
176         countryCodeMap.insert( QLatin1String("LBR"), i18nc("@info: country code", "Liberia") );
177         countryCodeMap.insert( QLatin1String("LBY"), i18nc("@info: country code", "Libyan Arab Jamahiriya") );
178         countryCodeMap.insert( QLatin1String("LIE"), i18nc("@info: country code", "Liechtenstein") );
179         countryCodeMap.insert( QLatin1String("LTU"), i18nc("@info: country code", "Lithuania") );
180         countryCodeMap.insert( QLatin1String("LUX"), i18nc("@info: country code", "Luxembourg") );
181         countryCodeMap.insert( QLatin1String("MAC"), i18nc("@info: country code", "Macao") );
182         countryCodeMap.insert( QLatin1String("MKD"), i18nc("@info: country code", "Macedonia") );
183         countryCodeMap.insert( QLatin1String("MDG"), i18nc("@info: country code", "Madagascar") );
184         countryCodeMap.insert( QLatin1String("MWI"), i18nc("@info: country code", "Malawi") );
185         countryCodeMap.insert( QLatin1String("MYS"), i18nc("@info: country code", "Malaysia") );
186         countryCodeMap.insert( QLatin1String("MDV"), i18nc("@info: country code", "Maldives") );
187         countryCodeMap.insert( QLatin1String("MLI"), i18nc("@info: country code", "Mali") );
188         countryCodeMap.insert( QLatin1String("MLT"), i18nc("@info: country code", "Malta") );
189         countryCodeMap.insert( QLatin1String("MHL"), i18nc("@info: country code", "Marshall Islands") );
190         countryCodeMap.insert( QLatin1String("MTQ"), i18nc("@info: country code", "Martinique") );
191         countryCodeMap.insert( QLatin1String("MRT"), i18nc("@info: country code", "Mauritania") );
192         countryCodeMap.insert( QLatin1String("MUS"), i18nc("@info: country code", "Mauritius") );
193         countryCodeMap.insert( QLatin1String("MYT"), i18nc("@info: country code", "Mayotte") );
194         countryCodeMap.insert( QLatin1String("MEX"), i18nc("@info: country code", "Mexico") );
195         countryCodeMap.insert( QLatin1String("FSM"), i18nc("@info: country code", "Micronesia") );
196         countryCodeMap.insert( QLatin1String("MDA"), i18nc("@info: country code", "Moldova") );
197         countryCodeMap.insert( QLatin1String("MCO"), i18nc("@info: country code", "Monaco") );
198         countryCodeMap.insert( QLatin1String("MNG"), i18nc("@info: country code", "Mongolia") );
199         countryCodeMap.insert( QLatin1String("MSR"), i18nc("@info: country code", "Montserrat") );
200         countryCodeMap.insert( QLatin1String("MAR"), i18nc("@info: country code", "Morocco") );
201         countryCodeMap.insert( QLatin1String("MOZ"), i18nc("@info: country code", "Mozambique") );
202         countryCodeMap.insert( QLatin1String("MMR"), i18nc("@info: country code", "Myanmar") );
203         countryCodeMap.insert( QLatin1String("NAM"), i18nc("@info: country code", "Namibia") );
204         countryCodeMap.insert( QLatin1String("NRU"), i18nc("@info: country code", "Nauru") );
205         countryCodeMap.insert( QLatin1String("NPL"), i18nc("@info: country code", "Nepal") );
206         countryCodeMap.insert( QLatin1String("ANT"), i18nc("@info: country code", "Netherlands Antilles") );
207         countryCodeMap.insert( QLatin1String("NLD"), i18nc("@info: country code", "Netherlands") );
208         countryCodeMap.insert( QLatin1String("NCL"), i18nc("@info: country code", "New Caledonia") );
209         countryCodeMap.insert( QLatin1String("NZL"), i18nc("@info: country code", "New Zealand") );
210         countryCodeMap.insert( QLatin1String("NIC"), i18nc("@info: country code", "Nicaragua") );
211         countryCodeMap.insert( QLatin1String("NER"), i18nc("@info: country code", "Niger") );
212         countryCodeMap.insert( QLatin1String("NGA"), i18nc("@info: country code", "Nigeria") );
213         countryCodeMap.insert( QLatin1String("NIU"), i18nc("@info: country code", "Niue") );
214         countryCodeMap.insert( QLatin1String("NFK"), i18nc("@info: country code", "Norfolk Island") );
215         countryCodeMap.insert( QLatin1String("MNP"), i18nc("@info: country code", "Northern Mariana Islands") );
216         countryCodeMap.insert( QLatin1String("NOR"), i18nc("@info: country code", "Norway") );
217         countryCodeMap.insert( QLatin1String("OMN"), i18nc("@info: country code", "Oman") );
218         countryCodeMap.insert( QLatin1String("PAK"), i18nc("@info: country code", "Pakistan") );
219         countryCodeMap.insert( QLatin1String("PLW"), i18nc("@info: country code", "Palau") );
220         countryCodeMap.insert( QLatin1String("PSE"), i18nc("@info: country code", "Palestinian Territory") );
221         countryCodeMap.insert( QLatin1String("PAN"), i18nc("@info: country code", "Panama") );
222         countryCodeMap.insert( QLatin1String("PNG"), i18nc("@info: country code", "Papua New Guinea") );
223         countryCodeMap.insert( QLatin1String("PRY"), i18nc("@info: country code", "Paraguay") );
224         countryCodeMap.insert( QLatin1String("PER"), i18nc("@info: country code", "Peru") );
225         countryCodeMap.insert( QLatin1String("PHL"), i18nc("@info: country code", "Philippines") );
226         countryCodeMap.insert( QLatin1String("PCN"), i18nc("@info: country code", "Pitcairn Island") );
227         countryCodeMap.insert( QLatin1String("POL"), i18nc("@info: country code", "Poland") );
228         countryCodeMap.insert( QLatin1String("PRT"), i18nc("@info: country code", "Portugal") );
229         countryCodeMap.insert( QLatin1String("PRI"), i18nc("@info: country code", "Puerto Rico") );
230         countryCodeMap.insert( QLatin1String("QAT"), i18nc("@info: country code", "Qatar") );
231         countryCodeMap.insert( QLatin1String("REU"), i18nc("@info: country code", "Reunion") );
232         countryCodeMap.insert( QLatin1String("ROU"), i18nc("@info: country code", "Romania") );
233         countryCodeMap.insert( QLatin1String("RUS"), i18nc("@info: country code", "Russian Federation") );
234         countryCodeMap.insert( QLatin1String("RWA"), i18nc("@info: country code", "Rwanda") );
235         countryCodeMap.insert( QLatin1String("SHN"), i18nc("@info: country code", "St. Helena") );
236         countryCodeMap.insert( QLatin1String("KNA"), i18nc("@info: country code", "St. Kitts and Nevis") );
237         countryCodeMap.insert( QLatin1String("LCA"), i18nc("@info: country code", "St. Lucia") );
238         countryCodeMap.insert( QLatin1String("SPM"), i18nc("@info: country code", "St. Pierre and Miquelon") );
239         countryCodeMap.insert( QLatin1String("VCT"), i18nc("@info: country code", "St. Vincent and the Grenadines") );
240         countryCodeMap.insert( QLatin1String("WSM"), i18nc("@info: country code", "Samoa") );
241         countryCodeMap.insert( QLatin1String("SMR"), i18nc("@info: country code", "San Marino") );
242         countryCodeMap.insert( QLatin1String("STP"), i18nc("@info: country code", "Sao Tome and Principe") );
243         countryCodeMap.insert( QLatin1String("SAU"), i18nc("@info: country code", "Saudi Arabia") );
244         countryCodeMap.insert( QLatin1String("SEN"), i18nc("@info: country code", "Senegal") );
245         countryCodeMap.insert( QLatin1String("SCG"), i18nc("@info: country code", "Serbia") );
246         countryCodeMap.insert( QLatin1String("SYC"), i18nc("@info: country code", "Seychelles") );
247         countryCodeMap.insert( QLatin1String("SLE"), i18nc("@info: country code", "Sierra Leone") );
248         countryCodeMap.insert( QLatin1String("SGP"), i18nc("@info: country code", "Singapore") );
249         countryCodeMap.insert( QLatin1String("SVK"), i18nc("@info: country code", "Slovakia") );
250         countryCodeMap.insert( QLatin1String("SVN"), i18nc("@info: country code", "Slovenia") );
251         countryCodeMap.insert( QLatin1String("SLB"), i18nc("@info: country code", "Solomon Islands") );
252         countryCodeMap.insert( QLatin1String("SOM"), i18nc("@info: country code", "Somalia") );
253         countryCodeMap.insert( QLatin1String("ZAF"), i18nc("@info: country code", "South Africa") );
254         countryCodeMap.insert( QLatin1String("SGS"), i18nc("@info: country code", "South Georgia and the South Sandwich Islands") );
255         countryCodeMap.insert( QLatin1String("ESP"), i18nc("@info: country code", "Spain") );
256         countryCodeMap.insert( QLatin1String("LKA"), i18nc("@info: country code", "Sri Lanka") );
257         countryCodeMap.insert( QLatin1String("SDN"), i18nc("@info: country code", "Sudan") );
258         countryCodeMap.insert( QLatin1String("SUR"), i18nc("@info: country code", "Suriname") );
259         countryCodeMap.insert( QLatin1String("SJM"), i18nc("@info: country code", "Svalbard & Jan Mayen Islands") );
260         countryCodeMap.insert( QLatin1String("SWZ"), i18nc("@info: country code", "Swaziland") );
261         countryCodeMap.insert( QLatin1String("SWE"), i18nc("@info: country code", "Sweden") );
262         countryCodeMap.insert( QLatin1String("CHE"), i18nc("@info: country code", "Switzerland") );
263         countryCodeMap.insert( QLatin1String("SYR"), i18nc("@info: country code", "Syrian Arab Republic") );
264         countryCodeMap.insert( QLatin1String("TWN"), i18nc("@info: country code", "Taiwan") );
265         countryCodeMap.insert( QLatin1String("TJK"), i18nc("@info: country code", "Tajikistan") );
266         countryCodeMap.insert( QLatin1String("TZA"), i18nc("@info: country code", "Tanzania") );
267         countryCodeMap.insert( QLatin1String("THA"), i18nc("@info: country code", "Thailand") );
268         countryCodeMap.insert( QLatin1String("TLS"), i18nc("@info: country code", "Timor-Leste") );
269         countryCodeMap.insert( QLatin1String("TGO"), i18nc("@info: country code", "Togo") );
270         countryCodeMap.insert( QLatin1String("TKL"), i18nc("@info: country code", "Tokelau Islands") );
271         countryCodeMap.insert( QLatin1String("TON"), i18nc("@info: country code", "Tonga") );
272         countryCodeMap.insert( QLatin1String("TTO"), i18nc("@info: country code", "Trinidad and Tobago") );
273         countryCodeMap.insert( QLatin1String("TUN"), i18nc("@info: country code", "Tunisia") );
274         countryCodeMap.insert( QLatin1String("TUR"), i18nc("@info: country code", "Turkey") );
275         countryCodeMap.insert( QLatin1String("TKM"), i18nc("@info: country code", "Turkmenistan") );
276         countryCodeMap.insert( QLatin1String("TCA"), i18nc("@info: country code", "Turks and Caicos Islands") );
277         countryCodeMap.insert( QLatin1String("TUV"), i18nc("@info: country code", "Tuvalu") );
278         countryCodeMap.insert( QLatin1String("VIR"), i18nc("@info: country code", "US Virgin Islands") );
279         countryCodeMap.insert( QLatin1String("UGA"), i18nc("@info: country code", "Uganda") );
280         countryCodeMap.insert( QLatin1String("UKR"), i18nc("@info: country code", "Ukraine") );
281         countryCodeMap.insert( QLatin1String("ARE"), i18nc("@info: country code", "United Arab Emirates") );
282         countryCodeMap.insert( QLatin1String("GBR"), i18nc("@info: country code", "United Kingdom") );
283         countryCodeMap.insert( QLatin1String("UMI"), i18nc("@info: country code", "United States Minor Outlying Islands") );
284         countryCodeMap.insert( QLatin1String("USA"), i18nc("@info: country code", "United States of America") );
285         countryCodeMap.insert( QLatin1String("URY"), i18nc("@info: country code", "Uruguay, Eastern Republic of") );
286         countryCodeMap.insert( QLatin1String("UZB"), i18nc("@info: country code", "Uzbekistan") );
287         countryCodeMap.insert( QLatin1String("VUT"), i18nc("@info: country code", "Vanuatu") );
288         countryCodeMap.insert( QLatin1String("VEN"), i18nc("@info: country code", "Venezuela") );
289         countryCodeMap.insert( QLatin1String("VNM"), i18nc("@info: country code", "Viet Nam") );
290         countryCodeMap.insert( QLatin1String("WLF"), i18nc("@info: country code", "Wallis and Futuna Islands ") );
291         countryCodeMap.insert( QLatin1String("ESH"), i18nc("@info: country code", "Western Sahara") );
292         countryCodeMap.insert( QLatin1String("YEM"), i18nc("@info: country code", "Yemen") );
293         countryCodeMap.insert( QLatin1String("ZMB"), i18nc("@info: country code", "Zambia") );
294         countryCodeMap.insert( QLatin1String("ZWE"), i18nc("@info: country code", "Zimbabwe") );
295         // Supplemental IPTC/IIM country codes.
296         countryCodeMap.insert( QLatin1String("XUN"), i18nc("@info: country code", "United Nations") );
297         countryCodeMap.insert( QLatin1String("XEU"), i18nc("@info: country code", "European Union") );
298         countryCodeMap.insert( QLatin1String("XSP"), i18nc("@info: country code", "Space") );
299         countryCodeMap.insert( QLatin1String("XSE"), i18nc("@info: country code", "At Sea") );
300         countryCodeMap.insert( QLatin1String("XIF"), i18nc("@info: country code", "In Flight") );
301         countryCodeMap.insert( QLatin1String("XEN"), i18nc("@info: country code", "England") );
302         countryCodeMap.insert( QLatin1String("XSC"), i18nc("@info: country code", "Scotland") );
303         countryCodeMap.insert( QLatin1String("XNI"), i18nc("@info: country code", "Northern Ireland") );
304         countryCodeMap.insert( QLatin1String("XWA"), i18nc("@info: country code", "Wales") );
305         countryCodeMap.insert( QLatin1String("PSE"), i18nc("@info: country code", "Palestine") );
306         countryCodeMap.insert( QLatin1String("GZA"), i18nc("@info: country code", "Gaza") );
307         countryCodeMap.insert( QLatin1String("JRO"), i18nc("@info: country code", "Jericho") );
308     }
309 
310     typedef QMap<QString, QString> CountryCodeMap;
311 
312     CountryCodeMap                 countryCodeMap;
313 };
314 
CountrySelector(QWidget * const parent)315 CountrySelector::CountrySelector(QWidget* const parent)
316     : QComboBox(parent),
317       d        (new Private)
318 {
319     for (Private::CountryCodeMap::Iterator it = d->countryCodeMap.begin() ;
320          it != d->countryCodeMap.end() ; ++it)
321     {
322         addItem(QString::fromLatin1("%1 - %2").arg(it.key()).arg(it.value()));
323     }
324 
325     model()->sort(0);
326 
327     insertSeparator(count());
328     addItem(i18nc("@item: unknown country", "Unknown"));
329 }
330 
~CountrySelector()331 CountrySelector::~CountrySelector()
332 {
333     delete d;
334 }
335 
setCountry(const QString & countryCode)336 void CountrySelector::setCountry(const QString& countryCode)
337 {
338     // NOTE: if countryCode is empty or do not matches code map, unknow is selected from the list.
339 
340     int id = count()-1;
341 
342     for (int i = 0 ; i < d->countryCodeMap.count() ; ++i)
343     {
344         if (itemText(i).left(3) == countryCode)
345         {
346             id = i;
347             break;
348         }
349     }
350 
351     setCurrentIndex(id);
352 
353     qCDebug(DIGIKAM_WIDGETS_LOG) << count() << " :: " << id;
354 }
355 
country(QString & countryCode,QString & countryName) const356 bool CountrySelector::country(QString& countryCode, QString& countryName) const
357 {
358     // Unknow is selected ?
359 
360     if (currentIndex() == count()-1)
361     {
362         return false;
363     }
364 
365     countryName = currentText().mid(6);
366     countryCode = currentText().left(3);
367 
368     return true;
369 }
370 
countryForCode(const QString & countryCode)371 QString CountrySelector::countryForCode(const QString& countryCode)
372 {
373     Private priv;
374 
375     return (priv.countryCodeMap[countryCode]);
376 }
377 
378 } // namespace Digikam
379