1 | /* |
2 | * Copyright (C) 2009 Petri Damstén <damu@iki.fi> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU Library General Public License as |
6 | * published by the Free Software Foundation; either version 2, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "currency.h" |
21 | |
22 | #include "config-kunitconversion.h" |
23 | |
24 | #include "converter.h" |
25 | #include <QtCore/QFileInfo> |
26 | #include <QtCore/QDateTime> |
27 | #include <QtCore/QMutex> |
28 | #include <QtXml/QDomDocument> |
29 | #include <kdebug.h> |
30 | #include <klocale.h> |
31 | #include <kprocess.h> |
32 | #include <kstandarddirs.h> |
33 | |
34 | #ifndef KUNITCONVERSION_NO_SOLID |
35 | #include <solid/networking.h> |
36 | #endif |
37 | |
38 | #ifdef KUNITCONVERSION_NO_KIO |
39 | #include <QtNetwork/QNetworkAccessManager> |
40 | #include <QtNetwork/QNetworkReply> |
41 | #include <QtNetwork/QNetworkRequest> |
42 | #endif |
43 | |
44 | #include <kcurrencycode.h> |
45 | |
46 | using namespace KUnitConversion; |
47 | |
48 | static const char URL[] = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml" ; |
49 | |
50 | Currency::Currency() : UnitCategory(CurrencyCategory) |
51 | { |
52 | setName(i18n("Currency" )); |
53 | setDescription(i18n("From ECB" )); |
54 | setUrl(KUrl("http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html" )); |
55 | setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (currency)" , "%1 %2" )); |
56 | |
57 | // Static rates |
58 | setDefaultUnit(UP(Eur, 1, |
59 | "EUR" , |
60 | KCurrencyCode::currencyCodeToName("EUR" ), |
61 | i18nc("EUR Euro - unit synonyms for matching user input" , "euro;euros" ) + |
62 | ";EUR;" + QString::fromUtf8("€" ) + ';' + KCurrencyCode::currencyCodeToName("EUR" ), |
63 | ki18nc("amount in units (real)" , "%1 euros" ), |
64 | ki18ncp("amount in units (integer)" , "%1 euro" , "%1 euros" ) |
65 | )); |
66 | U(Ats, 0.0726728, |
67 | "ATS" , |
68 | KCurrencyCode::currencyCodeToName("ATS" ), |
69 | i18nc("ATS Austrian Schilling - unit synonyms for matching user input" , |
70 | "schilling;schillings" ) + ";ATS;" + KGlobal::locale()->countryCodeToName("at" ) +';' + |
71 | KCurrencyCode::currencyCodeToName("ATS" ), |
72 | ki18nc("amount in units (real)" , "%1 schillings" ), |
73 | ki18ncp("amount in units (integer)" , "%1 schilling" , "%1 schillings" ) |
74 | ); |
75 | U(Bef, 0.0247894, |
76 | "BEF" , |
77 | KCurrencyCode::currencyCodeToName("BEF" ), |
78 | i18nc("BEF Belgian Franc - unit synonyms for matching user input" , "franc;francs" ) + |
79 | ";BEF;" + KGlobal::locale()->countryCodeToName("be" ) + ';' + |
80 | KCurrencyCode::currencyCodeToName("BEF" ), |
81 | ki18nc("amount in units (real)" , "%1 Belgian francs" ), |
82 | ki18ncp("amount in units (integer)" , "%1 Belgian franc" , "%1 Belgian francs" ) |
83 | ); |
84 | U(Nlg, 0.45378, |
85 | "NLG" , |
86 | KCurrencyCode::currencyCodeToName("NLG" ), |
87 | i18nc("NLG Netherlands Guilder - unit synonyms for matching user input" , "guilder;guilders" ) + |
88 | ";NLG;" + KGlobal::locale()->countryCodeToName("nl" ) + ';' + |
89 | KCurrencyCode::currencyCodeToName("NLG" ), |
90 | ki18nc("amount in units (real)" , "%1 guilders" ), |
91 | ki18ncp("amount in units (integer)" , "%1 guilder" , "%1 guilders" ) |
92 | ); |
93 | U(Fim, 0.168188, |
94 | "FIM" , |
95 | KCurrencyCode::currencyCodeToName("FIM" ), |
96 | i18nc("FIM Finnish Markka - unit synonyms for matching user input" , |
97 | "markka;markkas;markkaa" ) + ";FIM;" + |
98 | KGlobal::locale()->countryCodeToName("fi" ) + ';' + |
99 | KCurrencyCode::currencyCodeToName("FIM" ), |
100 | ki18nc("amount in units (real)" , "%1 markkas" ), |
101 | ki18ncp("amount in units (integer)" , "%1 markka" , "%1 markkas" ) // Alternative = markkaa |
102 | ); |
103 | U(Frf, 0.152449, |
104 | "FRF" , |
105 | KCurrencyCode::currencyCodeToName("FRF" ), |
106 | i18nc("FRF French Franc - unit synonyms for matching user input" , "franc;francs" ) + ";FRF;" + |
107 | KGlobal::locale()->countryCodeToName("fr" ) + ';' + |
108 | KCurrencyCode::currencyCodeToName("FRF" ), |
109 | ki18nc("amount in units (real)" , "%1 French francs" ), |
110 | ki18ncp("amount in units (integer)" , "%1 French franc" , "%1 French francs" ) |
111 | ); |
112 | U(Dem, 0.511292, |
113 | "DEM" , |
114 | KCurrencyCode::currencyCodeToName("DEM" ), |
115 | i18nc("DEM German Mark - unit synonyms for matching user input" , "mark;marks" ) + ";DEM;" + |
116 | KGlobal::locale()->countryCodeToName("de" ) + ';' + |
117 | KCurrencyCode::currencyCodeToName("DEM" ), |
118 | ki18nc("amount in units (real)" , "%1 marks" ), |
119 | ki18ncp("amount in units (integer)" , "%1 mark" , "%1 marks" ) |
120 | ); |
121 | U(Iep, 1.26974, |
122 | "IEP" , |
123 | KCurrencyCode::currencyCodeToName("IEP" ), |
124 | i18nc("IEP Irish Pound - unit synonyms for matching user input" , "Irish pound;Irish pounds" ) + |
125 | ";IEP;" + KGlobal::locale()->countryCodeToName("ie" ) + ';' + |
126 | KCurrencyCode::currencyCodeToName("IEP" ), |
127 | ki18nc("amount in units (real)" , "%1 Irish pounds" ), |
128 | ki18ncp("amount in units (integer)" , "%1 Irish pound" , "%1 Irish pounds" ) |
129 | ); |
130 | U(Itl, 0.000516457, |
131 | "ITL" , |
132 | KCurrencyCode::currencyCodeToName("ITL" ), |
133 | i18nc("ITL Italian Lira - unit synonyms for matching user input" , "lira;liras" ) + ";ITL;" + |
134 | KGlobal::locale()->countryCodeToName("it" ) + ';' + |
135 | KCurrencyCode::currencyCodeToName("ITL" ), |
136 | ki18nc("amount in units (real)" , "%1 Italian lira" ), |
137 | ki18ncp("amount in units (integer)" , "%1 Italian lira" , "%1 Italian lira" ) |
138 | ); |
139 | U(Luf, 0.0247894, |
140 | "LUF" , |
141 | KCurrencyCode::currencyCodeToName("LUF" ), |
142 | i18nc("LUF Luxembourgish Franc - unit synonyms for matching user input" , "franc;francs" ) + |
143 | ";LUF;" + KGlobal::locale()->countryCodeToName("lu" ) + ';' + |
144 | KCurrencyCode::currencyCodeToName("LUF" ), |
145 | ki18nc("amount in units (real)" , "%1 Luxembourgish francs" ), |
146 | ki18ncp("amount in units (integer)" , "%1 Luxembourgish franc" , "%1 Luxembourgish francs" ) |
147 | ); |
148 | U(Pte, 0.00498798, |
149 | "PTE" , |
150 | KCurrencyCode::currencyCodeToName("PTE" ), |
151 | i18nc("PTE Portugeuse Escudo - unit synonyms for matching user input" , "escudo;escudos" ) + |
152 | ";PTE;" + KGlobal::locale()->countryCodeToName("pt" ) + ';' + |
153 | KCurrencyCode::currencyCodeToName("PTE" ), |
154 | ki18nc("amount in units (real)" , "%1 escudos" ), |
155 | ki18ncp("amount in units (integer)" , "%1 escudo" , "%1 escudos" ) |
156 | ); |
157 | U(Esp, 0.00601012, |
158 | "ESP" , |
159 | KCurrencyCode::currencyCodeToName("ESP" ), |
160 | i18nc("ESP Spanish Pesetas - unit synonyms for matching user input" , "peseta;pesetas" ) + |
161 | ";ESP;" + KGlobal::locale()->countryCodeToName("es" ) + ';' + |
162 | KCurrencyCode::currencyCodeToName("ESP" ), |
163 | ki18nc("amount in units (real)" , "%1 pesetas" ), |
164 | ki18ncp("amount in units (integer)" , "%1 peseta" , "%1 pesetas" ) |
165 | ); |
166 | U(Grd, 0.0029347, |
167 | "GRD" , |
168 | KCurrencyCode::currencyCodeToName("GRD" ), |
169 | i18nc("GRD Greek Drachma - unit synonyms for matching user input" , "drachma;drachmas" ) + |
170 | ";GRD;" + KGlobal::locale()->countryCodeToName("gr" ) + ';' + |
171 | KCurrencyCode::currencyCodeToName("GRD" ), |
172 | ki18nc("amount in units (real)" , "%1 drachmas" ), |
173 | ki18ncp("amount in units (integer)" , "%1 drachma" , "%1 drachmas" ) |
174 | ); |
175 | U(Sit, 0.00417293, |
176 | "SIT" , |
177 | KCurrencyCode::currencyCodeToName("SIT" ), |
178 | i18nc("SIT Slovenian Tolar - unit synonyms for matching user input" , "tolar;tolars;tolarjev" ) + ";SIT;" + |
179 | KGlobal::locale()->countryCodeToName("si" ) + ';' + KCurrencyCode::currencyCodeToName("SIT" ), |
180 | ki18nc("amount in units (real)" , "%1 tolars" ), |
181 | ki18ncp("amount in units (integer)" , "%1 tolar" , "%1 tolars" ) //Alt: tolarjev/tolarja/tolarji |
182 | ); |
183 | U(Cyp, 1.7086, |
184 | "CYP" , |
185 | KCurrencyCode::currencyCodeToName("CYP" ), |
186 | i18nc("CYP Cypriot Pound - unit synonyms for matching user input" , |
187 | "Cypriot pound;Cypriot pounds" ) + ";CYP;" + |
188 | KGlobal::locale()->countryCodeToName("cy" ) + ';' + |
189 | KCurrencyCode::currencyCodeToName("CYP" ), |
190 | ki18nc("amount in units (real)" , "%1 Cypriot pounds" ), |
191 | ki18ncp("amount in units (integer)" , "%1 Cypriot pound" , "%1 Cypriot pounds" ) |
192 | ); |
193 | U(Mtl, 2.32937, |
194 | "MTL" , |
195 | KCurrencyCode::currencyCodeToName("MTL" ), |
196 | i18nc("MTL Maltese Lira - unit synonyms for matching user input" , "Maltese lira" ) + ";MTL;" + |
197 | KGlobal::locale()->countryCodeToName("mt" ) + ';' + KCurrencyCode::currencyCodeToName("MTL" ), |
198 | ki18nc("amount in units (real)" , "%1 Maltese lira" ), |
199 | ki18ncp("amount in units (integer)" , "%1 Maltese lira" , "%1 Maltese lira" ) |
200 | ); |
201 | U(Skk, 0.0331939, |
202 | "SKK" , |
203 | KCurrencyCode::currencyCodeToName("SKK" ), |
204 | i18nc("SKK Slovak Koruna - unit synonyms for matching user input" , |
205 | "koruna;korunas;koruny;korun" ) + ";SKK;" + |
206 | KGlobal::locale()->countryCodeToName("sk" ) + ';' + |
207 | KCurrencyCode::currencyCodeToName("SKK" ), |
208 | ki18nc("amount in units (real)" , "%1 Slovak korunas" ), |
209 | ki18ncp("amount in units (integer)" , "%1 Slovak koruna" , "%1 Slovak korunas" ) // Alt: koruny, korun |
210 | ); |
211 | |
212 | // From ECB |
213 | U(Usd, 1e+99, |
214 | "USD" , |
215 | KCurrencyCode::currencyCodeToName("USD" ), |
216 | i18nc("USD United States Dollars - unit synonyms for matching user input" , "dollar;dollars" ) + |
217 | ";USD;$;" + KGlobal::locale()->countryCodeToName("us" ) + ';' + |
218 | KCurrencyCode::currencyCodeToName("USD" ), |
219 | ki18nc("amount in units (real)" , "%1 United States dollars" ), |
220 | ki18ncp("amount in units (integer)" , "%1 United States dollar" , "%1 United States dollars" ) |
221 | ); |
222 | U(Jpy, 1e+99, |
223 | "JPY" , |
224 | KCurrencyCode::currencyCodeToName("JPY" ), |
225 | i18nc("JPY Japanese Yen - unit synonyms for matching user input" , "yen" ) + |
226 | ";JPY;" + QString::fromUtf8("¥" ) + ';' + |
227 | KGlobal::locale()->countryCodeToName("jp" ) + ';' + KCurrencyCode::currencyCodeToName("JPY" ), |
228 | ki18nc("amount in units (real)" , "%1 yen" ), |
229 | ki18ncp("amount in units (integer)" , "%1 yen" , "%1 yen" ) |
230 | ); |
231 | U(Bgn, 1e+99, |
232 | "BGN" , |
233 | KCurrencyCode::currencyCodeToName("BGN" ), |
234 | i18nc("BGN Bulgarian Lev - unit synonyms for matching user input" , "lev;leva" ) + ";BGN;" + |
235 | KGlobal::locale()->countryCodeToName("bg" ) + ';' + KCurrencyCode::currencyCodeToName("BGN" ), |
236 | ki18nc("amount in units (real)" , "%1 leva" ), |
237 | ki18ncp("amount in units (integer)" , "%1 lev" , "%1 leva" ) |
238 | ); |
239 | U(Czk, 1e+99, |
240 | "CZK" , |
241 | KCurrencyCode::currencyCodeToName("CZK" ), |
242 | i18nc("CZK Czech Koruna - unit synonyms for matching user input" , "koruna;korunas" ) + |
243 | ";CZK;" + KGlobal::locale()->countryCodeToName("cz" ) + ';' + |
244 | KCurrencyCode::currencyCodeToName("CZK" ), |
245 | ki18nc("amount in units (real)" , "%1 Czech korunas" ), |
246 | // Alt: koruny, korun |
247 | ki18ncp("amount in units (integer)" , "%1 Czech koruna" , "%1 Czech korunas" ) |
248 | ); |
249 | U(Dkk, 1e+99, |
250 | "DKK" , |
251 | KCurrencyCode::currencyCodeToName("DKK" ), |
252 | i18nc("DKK Danish Krone - unit synonyms for matching user input" , |
253 | "Danish krone;Danish kroner" ) + ";DKK;" + |
254 | KGlobal::locale()->countryCodeToName("dk" ) + ';' + |
255 | KCurrencyCode::currencyCodeToName("DKK" ), |
256 | ki18nc("amount in units (real)" , "%1 Danish kroner" ), |
257 | ki18ncp("amount in units (integer)" , "%1 Danish krone" , "%1 Danish kroner" ) |
258 | ); |
259 | U(Eek, 1e+99, |
260 | "EEK" , |
261 | KCurrencyCode::currencyCodeToName("EEK" ), |
262 | i18nc("EEK Estonian Kroon - unit synonyms for matching user input" , "kroon;kroons;krooni" ) + |
263 | ";EEK;" + KGlobal::locale()->countryCodeToName("ee" ) + ';' + |
264 | KCurrencyCode::currencyCodeToName("EEK" ), |
265 | ki18nc("amount in units (real)" , "%1 kroons" ), |
266 | ki18ncp("amount in units (integer)" , "%1 kroon" , "%1 kroons" ) // Alt: krooni |
267 | ); |
268 | U(Gbp, 1e+99, |
269 | "GBP" , |
270 | KCurrencyCode::currencyCodeToName("GBP" ), |
271 | i18nc("GBP British Pound - unit synonyms for matching user input" , |
272 | "pound;pounds;pound sterling;pounds sterling" ) + |
273 | ";GBP;" + QString::fromUtf8("£" ) + ';' + |
274 | KGlobal::locale()->countryCodeToName("gb" ) + ';' + |
275 | KCurrencyCode::currencyCodeToName("GBP" ), |
276 | ki18nc("amount in units (real)" , "%1 pounds sterling" ), |
277 | ki18ncp("amount in units (integer)" , "%1 pound sterling" , "%1 pounds sterling" ) |
278 | ); |
279 | U(Huf, 1e+99, |
280 | "HUF" , |
281 | KCurrencyCode::currencyCodeToName("HUF" ), |
282 | i18nc("HUF hungarian Forint - unit synonyms for matching user input" , "forint" ) + ";HUF;" + |
283 | KGlobal::locale()->countryCodeToName("hu" ) + ';' + |
284 | KCurrencyCode::currencyCodeToName("HUF" ), |
285 | ki18nc("amount in units (real)" , "%1 forint" ), |
286 | ki18ncp("amount in units (integer)" , "%1 forint" , "%1 forint" ) |
287 | ); |
288 | U(Ltl, 1e+99, |
289 | "LTL" , |
290 | KCurrencyCode::currencyCodeToName("LTL" ), |
291 | i18nc("LTL Lithuanian Litas - unit synonyms for matching user input" , "litas;litai;litu" ) + |
292 | ";LTL;" + KGlobal::locale()->countryCodeToName("lt" ) + ';' + |
293 | KCurrencyCode::currencyCodeToName("LTL" ), |
294 | ki18nc("amount in units (real)" , "%1 litas" ), |
295 | ki18ncp("amount in units (integer)" , "%1 litas" , "%1 litai" ) // Alt: litu |
296 | ); |
297 | U(Lvl, 1e+99, |
298 | "LVL" , |
299 | KCurrencyCode::currencyCodeToName("LVL" ), |
300 | i18nc("LVL Latvian Lats - unit synonyms for matching user input" , "lats;lati" ) + ";LVL;" + |
301 | KGlobal::locale()->countryCodeToName("lv" ) + ';' + KCurrencyCode::currencyCodeToName("LVL" ), |
302 | ki18nc("amount in units (real)" , "%1 lati" ), |
303 | ki18ncp("amount in units (integer)" , "%1 lats" , "%1 lati" ) |
304 | ); |
305 | U(Pln, 1e+99, |
306 | "PLN" , |
307 | KCurrencyCode::currencyCodeToName("PLN" ), |
308 | i18nc("PLN Polish Zloty - unit synonyms for matching user input" , "zloty;zlotys;zloties" ) + |
309 | ";PLN;" + KGlobal::locale()->countryCodeToName("pl" ) + ';' + |
310 | KCurrencyCode::currencyCodeToName("PLN" ), |
311 | ki18nc("amount in units (real)" , "%1 zlotys" ), |
312 | ki18ncp("amount in units (integer)" , "%1 zloty" , "%1 zlotys" ) // Alt: zloty, zlote, zlotych |
313 | ); |
314 | U(Ron, 1e+99, |
315 | "RON" , |
316 | KCurrencyCode::currencyCodeToName("RON" ), |
317 | i18nc("RON Roumanian Leu - unit synonyms for matching user input" , "leu;lei" ) + ";RON;" + |
318 | KGlobal::locale()->countryCodeToName("ro" ) + ';' + |
319 | KCurrencyCode::currencyCodeToName("RON" ), |
320 | ki18nc("amount in units (real)" , "%1 lei" ), |
321 | ki18ncp("amount in units (integer)" , "%1 leu" , "%1 lei" ) |
322 | ); |
323 | U(Sek, 1e+99, |
324 | "SEK" , |
325 | KCurrencyCode::currencyCodeToName("SEK" ), |
326 | i18nc("SEK Swedish Krona - unit synonyms for matching user input" , "krona;kronor" ) + ";SEK;" + |
327 | KGlobal::locale()->countryCodeToName("se" ) + ';' + |
328 | KCurrencyCode::currencyCodeToName("SEK" ), |
329 | ki18nc("amount in units (real)" , "%1 kronor" ), |
330 | ki18ncp("amount in units (integer)" , "%1 krona" , "%1 kronor" ) |
331 | ); |
332 | U(Chf, 1e+99, |
333 | "CHF" , |
334 | KCurrencyCode::currencyCodeToName("CHF" ), |
335 | i18nc("CHF Swiss Francs - unit synonyms for matching user input" , "franc;francs" ) + ";CHF;" + |
336 | KGlobal::locale()->countryCodeToName("ch" ) + ';' + |
337 | KCurrencyCode::currencyCodeToName("CHF" ), |
338 | ki18nc("amount in units (real)" , "%1 Swiss francs" ), |
339 | ki18ncp("amount in units (integer)" , "%1 Swiss franc" , "%1 Swiss francs" ) |
340 | ); |
341 | U(Nok, 1e+99, |
342 | "NOK" , |
343 | KCurrencyCode::currencyCodeToName("NOK" ), |
344 | i18nc("Norwegian Krone - unit synonyms for matching user input" , |
345 | "Norwegian krone;Norwegian kroner" ) + ";NOK;" + |
346 | KGlobal::locale()->countryCodeToName("no" ) + ';' + |
347 | KCurrencyCode::currencyCodeToName("NOK" ), |
348 | ki18nc("amount in units (real)" , "%1 Norwegian kroner" ), |
349 | ki18ncp("amount in units (integer)" , "%1 Norwegian krone" , "%1 Norwegian kroner" ) |
350 | ); |
351 | U(Hrk, 1e+99, |
352 | "HRK" , |
353 | KCurrencyCode::currencyCodeToName("HRK" ), |
354 | i18nc("HRK Croatian Kuna - unit synonyms for matching user input" , "kuna;kune" ) + ";HRK;" + |
355 | KGlobal::locale()->countryCodeToName("hr" ) + ';' + |
356 | KCurrencyCode::currencyCodeToName("HRK" ), |
357 | ki18nc("amount in units (real)" , "%1 kune" ), |
358 | ki18ncp("amount in units (integer)" , "%1 kuna" , "%1 kune" ) |
359 | ); |
360 | U(Rub, 1e+99, |
361 | "RUB" , |
362 | KCurrencyCode::currencyCodeToName("RUB" ), |
363 | i18nc("RUB Russsian Ruble - unit synonyms for matching user input" , |
364 | "ruble;rubles;rouble;roubles" ) + ";RUB;" + |
365 | KGlobal::locale()->countryCodeToName("ru" ) + ';' + |
366 | KCurrencyCode::currencyCodeToName("RUB" ), |
367 | ki18nc("amount in units (real)" , "%1 rubles" ), |
368 | ki18ncp("amount in units (integer)" , "%1 ruble" , "%1 rubles" ) //Alt: rouble/roubles |
369 | ); |
370 | U(Try, 1e+99, |
371 | "TRY" , |
372 | KCurrencyCode::currencyCodeToName("TRY" ), |
373 | i18nc("TRY Turkish Lira - unit synonyms for matching user input" , "lira" ) + ";TRY;" + |
374 | KGlobal::locale()->countryCodeToName("tr" ) + ';' + |
375 | KCurrencyCode::currencyCodeToName("TRY" ), |
376 | ki18nc("amount in units (real)" , "%1 Turkish lira" ), |
377 | ki18ncp("amount in units (integer)" , "%1 Turkish lira" , "%1 Turkish lira" ) |
378 | ); |
379 | U(Aud, 1e+99, |
380 | "AUD" , |
381 | KCurrencyCode::currencyCodeToName("AUD" ), |
382 | i18nc("AUD Australian Dollar - unit synonyms for matching user input" , |
383 | "Australian dollar;Australian dollars" ) + ";AUD;" + |
384 | KGlobal::locale()->countryCodeToName("au" ) + ';' + |
385 | KCurrencyCode::currencyCodeToName("AUD" ), |
386 | ki18nc("amount in units (real)" , "%1 Australian dollars" ), |
387 | ki18ncp("amount in units (integer)" , "%1 Australian dollar" , "%1 Australian dollars" ) |
388 | ); |
389 | U(Brl, 1e+99, |
390 | "BRL" , |
391 | KCurrencyCode::currencyCodeToName("BRL" ), |
392 | i18nc("BRL Brazillian Real - unit synonyms for matching user input" , "real;reais" ) + |
393 | ";BRL;" + KGlobal::locale()->countryCodeToName("br" ) + ';' + |
394 | KCurrencyCode::currencyCodeToName("BRL" ), |
395 | ki18nc("amount in units (real)" , "%1 reais" ), |
396 | ki18ncp("amount in units (integer)" , "%1 real" , "%1 reais" ) |
397 | ); |
398 | U(Cad, 1e+99, |
399 | "CAD" , |
400 | KCurrencyCode::currencyCodeToName("CAD" ), |
401 | i18nc("Canadian Dollar - unit synonyms for matching user input" , |
402 | "Canadian dollar;Canadian dollars" ) + ";CAD;" + |
403 | KGlobal::locale()->countryCodeToName("ca" ) + ';' + |
404 | KCurrencyCode::currencyCodeToName("CAD" ), |
405 | ki18nc("amount in units (real)" , "%1 Canadian dollars" ), |
406 | ki18ncp("amount in units (integer)" , "%1 Canadian dollar" , "%1 Canadian dollars" ) |
407 | ); |
408 | U(Cny, 1e+99, |
409 | "CNY" , |
410 | KCurrencyCode::currencyCodeToName("CNY" ), |
411 | i18nc("Chinese Yuan - unit synonyms for matching user input" , "yuan" ) + ";CNY;" + |
412 | KGlobal::locale()->countryCodeToName("cn" ) + ';' + |
413 | KCurrencyCode::currencyCodeToName("CNY" ), |
414 | ki18nc("amount in units (real)" , "%1 yuan" ), |
415 | ki18ncp("amount in units (integer)" , "%1 yuan" , "%1 yuan" ) |
416 | ); |
417 | U(Hkd, 1e+99, |
418 | "HKD" , |
419 | KCurrencyCode::currencyCodeToName("HKD" ), |
420 | i18nc("Hong Kong Dollar - unit synonyms for matching user input" , |
421 | "Hong Kong dollar;Hong Kong dollars" ) + ";HKD;" + |
422 | KGlobal::locale()->countryCodeToName("hk" ) + ';' + |
423 | KCurrencyCode::currencyCodeToName("HKD" ), |
424 | ki18nc("amount in units (real)" , "%1 Hong Kong dollars" ), |
425 | ki18ncp("amount in units (integer)" , "%1 Hong Kong dollar" , "%1 Hong Kong dollars" ) |
426 | ); |
427 | U(Idr, 1e+99, |
428 | "IDR" , |
429 | KCurrencyCode::currencyCodeToName("IDR" ), |
430 | i18nc("IDR Indonesian Rupiah - unit synonyms for matching user input" , "rupiah;rupiahs" ) + |
431 | ";IDR;" + KGlobal::locale()->countryCodeToName("id" ) + ';' + |
432 | KCurrencyCode::currencyCodeToName("IDR" ), |
433 | ki18nc("amount in units (real)" , "%1 rupiahs" ), |
434 | ki18ncp("amount in units (integer)" , "%1 rupiah" , "%1 rupiahs" ) // Alt: rupiah |
435 | ); |
436 | U(Inr, 1e+99, |
437 | "INR" , |
438 | KCurrencyCode::currencyCodeToName("INR" ), |
439 | i18nc("INR Indian Rupee - unit synonyms for matching user input" , "rupee;rupees" ) + ";INR;" + |
440 | KGlobal::locale()->countryCodeToName("in" ) + ';' + |
441 | KCurrencyCode::currencyCodeToName("INR" ), |
442 | ki18nc("amount in units (real)" , "%1 rupees" ), |
443 | ki18ncp("amount in units (integer)" , "%1 rupee" , "%1 rupees" ) // Alt: rupee |
444 | ); |
445 | U(Krw, 1e+99, |
446 | "KRW" , |
447 | KCurrencyCode::currencyCodeToName("KRW" ), |
448 | i18nc("KRW Korean Won - unit synonyms for matching user input" , "won" ) + ";KRW;" + |
449 | KGlobal::locale()->countryCodeToName("kr" ) + ';' + |
450 | KCurrencyCode::currencyCodeToName("KRW" ), |
451 | ki18nc("amount in units (real)" , "%1 won" ), |
452 | ki18ncp("amount in units (integer)" , "%1 won" , "%1 won" ) |
453 | ); |
454 | U(Mxn, 1e+99, |
455 | "MXN" , |
456 | KCurrencyCode::currencyCodeToName("MXN" ), |
457 | i18nc("MXN Mexican Peso - unit synonyms for matching user input" , |
458 | "Mexican peso;Mexican pesos" ) + ";MXN;" + |
459 | KGlobal::locale()->countryCodeToName("mx" ) + ';' + |
460 | KCurrencyCode::currencyCodeToName("MXN" ), |
461 | ki18nc("amount in units (real)" , "%1 Mexican pesos" ), |
462 | ki18ncp("amount in units (integer)" , "%1 Mexican peso" , "%1 Mexican pesos" ) |
463 | ); |
464 | U(Myr, 1e+99, |
465 | "MYR" , |
466 | KCurrencyCode::currencyCodeToName("MYR" ), |
467 | i18nc("MYR Malasian Ringgit - unit synonyms for matching user input" , "ringgit;ringgits" ) + |
468 | ";MYR;" + KGlobal::locale()->countryCodeToName("my" ) + ';' + |
469 | KCurrencyCode::currencyCodeToName("MYR" ), |
470 | ki18nc("amount in units (real)" , "%1 ringgit" ), |
471 | ki18ncp("amount in units (integer)" , "%1 ringgit" , "%1 ringgit" ) // Alt: ringgits |
472 | ); |
473 | U(Nzd, 1e+99, |
474 | "NZD" , |
475 | KCurrencyCode::currencyCodeToName("NZD" ), |
476 | i18nc("NZD New Zealand Dollar - unit synonyms for matching user input" , |
477 | "New Zealand dollar;New Zealand dollars" ) + ";NZD;" + |
478 | KGlobal::locale()->countryCodeToName("nz" ) + ';' + |
479 | KCurrencyCode::currencyCodeToName("NZD" ), |
480 | ki18nc("amount in units (real)" , "%1 New Zealand dollars" ), |
481 | ki18ncp("amount in units (integer)" , "%1 New Zealand dollar" , "%1 New Zealand dollars" ) |
482 | ); |
483 | U(Php, 1e+99, |
484 | "PHP" , |
485 | KCurrencyCode::currencyCodeToName("PHP" ), |
486 | i18nc("PHP Philippine Peso - unit synonyms for matching user input" , |
487 | "Philippine peso;Philippine pesos" ) + ";PHP;" + |
488 | KGlobal::locale()->countryCodeToName("ph" ) + ';' + |
489 | KCurrencyCode::currencyCodeToName("PHP" ), |
490 | ki18nc("amount in units (real)" , "%1 Philippine pesos" ), |
491 | ki18ncp("amount in units (integer)" , "%1 Philippine peso" , "%1 Philippine pesos" ) |
492 | ); |
493 | U(Sgd, 1e+99, |
494 | "SGD" , |
495 | KCurrencyCode::currencyCodeToName("SGD" ), |
496 | i18nc("SGD Singapore Dollar - unit synonyms for matching user input" , |
497 | "Singapore dollar;Singapore dollars" ) + ";SGD;" + |
498 | KGlobal::locale()->countryCodeToName("sg" ) + ';' + |
499 | KCurrencyCode::currencyCodeToName("SGD" ), |
500 | ki18nc("amount in units (real)" , "%1 Singapore dollars" ), |
501 | ki18ncp("amount in units (integer)" , "%1 Singapore dollar" , "%1 Singapore dollars" ) |
502 | ); |
503 | U(Thb, 1e+99, |
504 | "THB" , |
505 | KCurrencyCode::currencyCodeToName("THB" ), |
506 | i18nc("THB Thai Baht - unit synonyms for matching user input" , "baht" ) + ";THB;" + |
507 | KGlobal::locale()->countryCodeToName("th" ) + ';' + |
508 | KCurrencyCode::currencyCodeToName("THB" ), |
509 | ki18nc("amount in units (real)" , "%1 baht" ), |
510 | ki18ncp("amount in units (integer)" , "%1 baht" , "%1 baht" ) |
511 | ); |
512 | U(Zar, 1e+99, |
513 | "ZAR" , |
514 | KCurrencyCode::currencyCodeToName("ZAR" ), |
515 | i18nc("South African Rand - unit synonyms for matching user input" , "rand" ) + ";ZAR;" + |
516 | KGlobal::locale()->countryCodeToName("za" ) + ';' + |
517 | KCurrencyCode::currencyCodeToName("ZAR" ), |
518 | ki18nc("amount in units (real)" , "%1 rand" ), |
519 | ki18ncp("amount in units (integer)" , "%1 rand" , "%1 rand" ) |
520 | ); |
521 | |
522 | setMostCommonUnits(QList<int>() << Eur << Usd << Jpy << Gbp << Cad); |
523 | |
524 | m_cache = KStandardDirs::locateLocal("data" , "libkunitconversion/currency.xml" ); |
525 | m_update = true; |
526 | } |
527 | |
528 | Value Currency::convert(const Value& value, UnitPtr to) |
529 | { |
530 | static QMutex mutex; |
531 | |
532 | mutex.lock(); |
533 | QFileInfo info(m_cache); |
534 | if (!info.exists() || info.lastModified().secsTo(QDateTime::currentDateTime()) > 86400) { |
535 | #ifndef KUNITCONVERSION_NO_SOLID |
536 | Solid::Networking::Status status = Solid::Networking::status(); |
537 | if (status == Solid::Networking::Connected || status == Solid::Networking::Unknown ) { |
538 | #else |
539 | { |
540 | #endif |
541 | kDebug() << "Getting currency info from net:" << URL; |
542 | // TODO: This crashes in runner. Threading issues?? |
543 | /* |
544 | KIO::Job* job = KIO::file_copy(KUrl(URL), KUrl(m_cache), -1, |
545 | KIO::Overwrite | KIO::HideProgressInfo); |
546 | job->setUiDelegate(0); |
547 | if (KIO::NetAccess::synchronousRun(job, 0)) { |
548 | m_update = true; |
549 | } |
550 | */ |
551 | kDebug() << "Removed previous cache:" << QFile::remove(m_cache); |
552 | #ifndef KUNITCONVERSION_NO_KIO |
553 | if (KProcess::execute(QStringList() << "kioclient" << "copy" << "--noninteractive" << URL << m_cache) == 0) { |
554 | m_update = true; |
555 | } |
556 | #else |
557 | QNetworkAccessManager manager; |
558 | QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(URL))); |
559 | QFile cacheFile(m_cache); |
560 | cacheFile.open(QFile::WriteOnly); |
561 | while (!reply->error() && !reply->atEnd()) { |
562 | if (reply->bytesAvailable()>0 |
563 | || reply->waitForReadyRead(500)) { |
564 | cacheFile.write(reply->readAll()); |
565 | } |
566 | } |
567 | cacheFile.close(); |
568 | #endif |
569 | } |
570 | } |
571 | mutex.unlock(); |
572 | |
573 | if (m_update) { |
574 | QFile file(m_cache); |
575 | if (file.open(QIODevice::ReadOnly)) { |
576 | QDomDocument doc; |
577 | if (doc.setContent(&file, false) ) { |
578 | QDomNodeList list = doc.elementsByTagName("Cube" ); |
579 | for (int i = 0; i < list.count(); ++i) { |
580 | const QDomElement e = list.item(i).toElement(); |
581 | if (e.hasAttribute("currency" )) { |
582 | UnitPtr u = unit(e.attribute("currency" )); |
583 | if (u) { |
584 | u->setMultiplier(1.0 / e.attribute("rate" ).toDouble()); |
585 | } |
586 | } |
587 | } |
588 | m_update = false; |
589 | } |
590 | } |
591 | } |
592 | Value v = UnitCategory::convert(value, to); |
593 | return v; |
594 | } |
595 | |