KUnitConversion
currency.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2009 Petri Damstén <damu@iki.fi> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "currency.h" 00021 00022 #include "config-kunitconversion.h" 00023 00024 #include "converter.h" 00025 #include <QtCore/QFileInfo> 00026 #include <QtCore/QDateTime> 00027 #include <QtCore/QMutex> 00028 #include <QtXml/QDomDocument> 00029 #include <kdebug.h> 00030 #include <klocale.h> 00031 #include <kprocess.h> 00032 #include <kstandarddirs.h> 00033 00034 #ifndef KUNITCONVERSION_NO_SOLID 00035 #include <solid/networking.h> 00036 #endif 00037 00038 #ifdef KUNITCONVERSION_NO_KIO 00039 #include <QtNetwork/QNetworkAccessManager> 00040 #include <QtNetwork/QNetworkReply> 00041 #include <QtNetwork/QNetworkRequest> 00042 #endif 00043 00044 #include <kcurrencycode.h> 00045 00046 using namespace KUnitConversion; 00047 00048 static const char URL[] = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; 00049 00050 Currency::Currency() : UnitCategory(CurrencyCategory) 00051 { 00052 setName(i18n("Currency")); 00053 setDescription(i18n("From ECB")); 00054 setUrl(KUrl("http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html")); 00055 setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (currency)", "%1 %2")); 00056 00057 // Static rates 00058 setDefaultUnit(UP(Eur, 1, 00059 "EUR", 00060 KCurrencyCode::currencyCodeToName("EUR"), 00061 i18nc("EUR Euro - unit synonyms for matching user input", "euro;euros") + 00062 ";EUR;" + QString::fromUtf8("€") + ';' + KCurrencyCode::currencyCodeToName("EUR"), 00063 ki18nc("amount in units (real)", "%1 euros"), 00064 ki18ncp("amount in units (integer)", "%1 euro", "%1 euros") 00065 )); 00066 U(Ats, 0.0726728, 00067 "ATS", 00068 KCurrencyCode::currencyCodeToName("ATS"), 00069 i18nc("ATS Austrian Schilling - unit synonyms for matching user input", 00070 "schilling;schillings") + ";ATS;" + KGlobal::locale()->countryCodeToName("at") +';' + 00071 KCurrencyCode::currencyCodeToName("ATS"), 00072 ki18nc("amount in units (real)", "%1 schillings"), 00073 ki18ncp("amount in units (integer)", "%1 schilling", "%1 schillings") 00074 ); 00075 U(Bef, 0.0247894, 00076 "BEF", 00077 KCurrencyCode::currencyCodeToName("BEF"), 00078 i18nc("BEF Belgian Franc - unit synonyms for matching user input", "franc;francs") + 00079 ";BEF;" + KGlobal::locale()->countryCodeToName("be") + ';' + 00080 KCurrencyCode::currencyCodeToName("BEF"), 00081 ki18nc("amount in units (real)", "%1 Belgian francs"), 00082 ki18ncp("amount in units (integer)", "%1 Belgian franc", "%1 Belgian francs") 00083 ); 00084 U(Nlg, 0.45378, 00085 "NLG", 00086 KCurrencyCode::currencyCodeToName("NLG"), 00087 i18nc("NLG Netherlands Guilder - unit synonyms for matching user input", "guilder;guilders") + 00088 ";NLG;" + KGlobal::locale()->countryCodeToName("nl") + ';' + 00089 KCurrencyCode::currencyCodeToName("NLG"), 00090 ki18nc("amount in units (real)", "%1 guilders"), 00091 ki18ncp("amount in units (integer)", "%1 guilder", "%1 guilders") 00092 ); 00093 U(Fim, 0.168188, 00094 "FIM", 00095 KCurrencyCode::currencyCodeToName("FIM"), 00096 i18nc("FIM Finnish Markka - unit synonyms for matching user input", 00097 "markka;markkas;markkaa") + ";FIM;" + 00098 KGlobal::locale()->countryCodeToName("fi") + ';' + 00099 KCurrencyCode::currencyCodeToName("FIM"), 00100 ki18nc("amount in units (real)", "%1 markkas"), 00101 ki18ncp("amount in units (integer)", "%1 markka", "%1 markkas") // Alternative = markkaa 00102 ); 00103 U(Frf, 0.152449, 00104 "FRF", 00105 KCurrencyCode::currencyCodeToName("FRF"), 00106 i18nc("FRF French Franc - unit synonyms for matching user input", "franc;francs") + ";FRF;" + 00107 KGlobal::locale()->countryCodeToName("fr") + ';' + 00108 KCurrencyCode::currencyCodeToName("FRF"), 00109 ki18nc("amount in units (real)", "%1 French francs"), 00110 ki18ncp("amount in units (integer)", "%1 French franc", "%1 French francs") 00111 ); 00112 U(Dem, 0.511292, 00113 "DEM", 00114 KCurrencyCode::currencyCodeToName("DEM"), 00115 i18nc("DEM German Mark - unit synonyms for matching user input", "mark;marks") + ";DEM;" + 00116 KGlobal::locale()->countryCodeToName("de") + ';' + 00117 KCurrencyCode::currencyCodeToName("DEM"), 00118 ki18nc("amount in units (real)", "%1 marks"), 00119 ki18ncp("amount in units (integer)", "%1 mark", "%1 marks") 00120 ); 00121 U(Iep, 1.26974, 00122 "IEP", 00123 KCurrencyCode::currencyCodeToName("IEP"), 00124 i18nc("IEP Irish Pound - unit synonyms for matching user input", "Irish pound;Irish pounds") + 00125 ";IEP;" + KGlobal::locale()->countryCodeToName("ie") + ';' + 00126 KCurrencyCode::currencyCodeToName("IEP"), 00127 ki18nc("amount in units (real)", "%1 Irish pounds"), 00128 ki18ncp("amount in units (integer)", "%1 Irish pound", "%1 Irish pounds") 00129 ); 00130 U(Itl, 0.000516457, 00131 "ITL", 00132 KCurrencyCode::currencyCodeToName("ITL"), 00133 i18nc("ITL Italian Lira - unit synonyms for matching user input", "lira;liras") + ";ITL;" + 00134 KGlobal::locale()->countryCodeToName("it") + ';' + 00135 KCurrencyCode::currencyCodeToName("ITL"), 00136 ki18nc("amount in units (real)", "%1 Italian lira"), 00137 ki18ncp("amount in units (integer)", "%1 Italian lira", "%1 Italian lira") 00138 ); 00139 U(Luf, 0.0247894, 00140 "LUF", 00141 KCurrencyCode::currencyCodeToName("LUF"), 00142 i18nc("LUF Luxembourgish Franc - unit synonyms for matching user input", "franc;francs") + 00143 ";LUF;" + KGlobal::locale()->countryCodeToName("lu") + ';' + 00144 KCurrencyCode::currencyCodeToName("LUF"), 00145 ki18nc("amount in units (real)", "%1 Luxembourgish francs"), 00146 ki18ncp("amount in units (integer)", "%1 Luxembourgish franc", "%1 Luxembourgish francs") 00147 ); 00148 U(Pte, 0.00498798, 00149 "PTE", 00150 KCurrencyCode::currencyCodeToName("PTE"), 00151 i18nc("PTE Portugeuse Escudo - unit synonyms for matching user input", "escudo;escudos") + 00152 ";PTE;" + KGlobal::locale()->countryCodeToName("pt") + ';' + 00153 KCurrencyCode::currencyCodeToName("PTE"), 00154 ki18nc("amount in units (real)", "%1 escudos"), 00155 ki18ncp("amount in units (integer)", "%1 escudo", "%1 escudos") 00156 ); 00157 U(Esp, 0.00601012, 00158 "ESP", 00159 KCurrencyCode::currencyCodeToName("ESP"), 00160 i18nc("ESP Spanish Pesetas - unit synonyms for matching user input", "peseta;pesetas") + 00161 ";ESP;" + KGlobal::locale()->countryCodeToName("es") + ';' + 00162 KCurrencyCode::currencyCodeToName("ESP"), 00163 ki18nc("amount in units (real)", "%1 pesetas"), 00164 ki18ncp("amount in units (integer)", "%1 peseta", "%1 pesetas") 00165 ); 00166 U(Grd, 0.0029347, 00167 "GRD", 00168 KCurrencyCode::currencyCodeToName("GRD"), 00169 i18nc("GRD Greek Drachma - unit synonyms for matching user input", "drachma;drachmas") + 00170 ";GRD;" + KGlobal::locale()->countryCodeToName("gr") + ';' + 00171 KCurrencyCode::currencyCodeToName("GRD"), 00172 ki18nc("amount in units (real)", "%1 drachmas"), 00173 ki18ncp("amount in units (integer)", "%1 drachma", "%1 drachmas") 00174 ); 00175 U(Sit, 0.00417293, 00176 "SIT", 00177 KCurrencyCode::currencyCodeToName("SIT"), 00178 i18nc("SIT Slovenian Tolar - unit synonyms for matching user input", "tolar;tolars;tolarjev") + ";SIT;" + 00179 KGlobal::locale()->countryCodeToName("si") + ';' + KCurrencyCode::currencyCodeToName("SIT"), 00180 ki18nc("amount in units (real)", "%1 tolars"), 00181 ki18ncp("amount in units (integer)", "%1 tolar", "%1 tolars") //Alt: tolarjev/tolarja/tolarji 00182 ); 00183 U(Cyp, 1.7086, 00184 "CYP", 00185 KCurrencyCode::currencyCodeToName("CYP"), 00186 i18nc("CYP Cypriot Pound - unit synonyms for matching user input", 00187 "Cypriot pound;Cypriot pounds") + ";CYP;" + 00188 KGlobal::locale()->countryCodeToName("cy") + ';' + 00189 KCurrencyCode::currencyCodeToName("CYP"), 00190 ki18nc("amount in units (real)", "%1 Cypriot pounds"), 00191 ki18ncp("amount in units (integer)", "%1 Cypriot pound", "%1 Cypriot pounds") 00192 ); 00193 U(Mtl, 2.32937, 00194 "MTL", 00195 KCurrencyCode::currencyCodeToName("MTL"), 00196 i18nc("MTL Maltese Lira - unit synonyms for matching user input", "Maltese lira") + ";MTL;" + 00197 KGlobal::locale()->countryCodeToName("mt") + ';' + KCurrencyCode::currencyCodeToName("MTL"), 00198 ki18nc("amount in units (real)", "%1 Maltese lira"), 00199 ki18ncp("amount in units (integer)", "%1 Maltese lira", "%1 Maltese lira") 00200 ); 00201 U(Skk, 0.0331939, 00202 "SKK", 00203 KCurrencyCode::currencyCodeToName("SKK"), 00204 i18nc("SKK Slovak Koruna - unit synonyms for matching user input", 00205 "koruna;korunas;koruny;korun") + ";SKK;" + 00206 KGlobal::locale()->countryCodeToName("sk") + ';' + 00207 KCurrencyCode::currencyCodeToName("SKK"), 00208 ki18nc("amount in units (real)", "%1 Slovak korunas"), 00209 ki18ncp("amount in units (integer)", "%1 Slovak koruna", "%1 Slovak korunas") // Alt: koruny, korun 00210 ); 00211 00212 // From ECB 00213 U(Usd, 1e+99, 00214 "USD", 00215 KCurrencyCode::currencyCodeToName("USD"), 00216 i18nc("USD United States Dollars - unit synonyms for matching user input", "dollar;dollars") + 00217 ";USD;$;" + KGlobal::locale()->countryCodeToName("us") + ';' + 00218 KCurrencyCode::currencyCodeToName("USD"), 00219 ki18nc("amount in units (real)", "%1 United States dollars"), 00220 ki18ncp("amount in units (integer)", "%1 United States dollar", "%1 United States dollars") 00221 ); 00222 U(Jpy, 1e+99, 00223 "JPY", 00224 KCurrencyCode::currencyCodeToName("JPY"), 00225 i18nc("JPY Japanese Yen - unit synonyms for matching user input", "yen") + 00226 ";JPY;" + QString::fromUtf8("¥") + ';' + 00227 KGlobal::locale()->countryCodeToName("jp") + ';' + KCurrencyCode::currencyCodeToName("JPY"), 00228 ki18nc("amount in units (real)", "%1 yen"), 00229 ki18ncp("amount in units (integer)", "%1 yen", "%1 yen") 00230 ); 00231 U(Bgn, 1e+99, 00232 "BGN", 00233 KCurrencyCode::currencyCodeToName("BGN"), 00234 i18nc("BGN Bulgarian Lev - unit synonyms for matching user input", "lev;leva") + ";BGN;" + 00235 KGlobal::locale()->countryCodeToName("bg") + ';' + KCurrencyCode::currencyCodeToName("BGN"), 00236 ki18nc("amount in units (real)", "%1 leva"), 00237 ki18ncp("amount in units (integer)", "%1 lev", "%1 leva") 00238 ); 00239 U(Czk, 1e+99, 00240 "CZK", 00241 KCurrencyCode::currencyCodeToName("CZK"), 00242 i18nc("CZK Czech Koruna - unit synonyms for matching user input", "koruna;korunas") + 00243 ";CZK;" + KGlobal::locale()->countryCodeToName("cz") + ';' + 00244 KCurrencyCode::currencyCodeToName("CZK"), 00245 ki18nc("amount in units (real)", "%1 Czech korunas"), 00246 // Alt: koruny, korun 00247 ki18ncp("amount in units (integer)", "%1 Czech koruna", "%1 Czech korunas") 00248 ); 00249 U(Dkk, 1e+99, 00250 "DKK", 00251 KCurrencyCode::currencyCodeToName("DKK"), 00252 i18nc("DKK Danish Krone - unit synonyms for matching user input", 00253 "Danish krone;Danish kroner") + ";DKK;" + 00254 KGlobal::locale()->countryCodeToName("dk") + ';' + 00255 KCurrencyCode::currencyCodeToName("DKK"), 00256 ki18nc("amount in units (real)", "%1 Danish kroner"), 00257 ki18ncp("amount in units (integer)", "%1 Danish krone", "%1 Danish kroner") 00258 ); 00259 U(Eek, 1e+99, 00260 "EEK", 00261 KCurrencyCode::currencyCodeToName("EEK"), 00262 i18nc("EEK Estonian Kroon - unit synonyms for matching user input", "kroon;kroons;krooni") + 00263 ";EEK;" + KGlobal::locale()->countryCodeToName("ee") + ';' + 00264 KCurrencyCode::currencyCodeToName("EEK"), 00265 ki18nc("amount in units (real)", "%1 kroons"), 00266 ki18ncp("amount in units (integer)", "%1 kroon", "%1 kroons") // Alt: krooni 00267 ); 00268 U(Gbp, 1e+99, 00269 "GBP", 00270 KCurrencyCode::currencyCodeToName("GBP"), 00271 i18nc("GBP British Pound - unit synonyms for matching user input", 00272 "pound;pounds;pound sterling;pounds sterling") + 00273 ";GBP;" + QString::fromUtf8("£") + ';' + 00274 KGlobal::locale()->countryCodeToName("gb") + ';' + 00275 KCurrencyCode::currencyCodeToName("GBP"), 00276 ki18nc("amount in units (real)", "%1 pounds sterling"), 00277 ki18ncp("amount in units (integer)", "%1 pound sterling", "%1 pounds sterling") 00278 ); 00279 U(Huf, 1e+99, 00280 "HUF", 00281 KCurrencyCode::currencyCodeToName("HUF"), 00282 i18nc("HUF hungarian Forint - unit synonyms for matching user input", "forint") + ";HUF;" + 00283 KGlobal::locale()->countryCodeToName("hu") + ';' + 00284 KCurrencyCode::currencyCodeToName("HUF"), 00285 ki18nc("amount in units (real)", "%1 forint"), 00286 ki18ncp("amount in units (integer)", "%1 forint", "%1 forint") 00287 ); 00288 U(Ltl, 1e+99, 00289 "LTL", 00290 KCurrencyCode::currencyCodeToName("LTL"), 00291 i18nc("LTL Lithuanian Litas - unit synonyms for matching user input", "litas;litai;litu") + 00292 ";LTL;" + KGlobal::locale()->countryCodeToName("lt") + ';' + 00293 KCurrencyCode::currencyCodeToName("LTL"), 00294 ki18nc("amount in units (real)", "%1 litas"), 00295 ki18ncp("amount in units (integer)", "%1 litas", "%1 litai") // Alt: litu 00296 ); 00297 U(Lvl, 1e+99, 00298 "LVL", 00299 KCurrencyCode::currencyCodeToName("LVL"), 00300 i18nc("LVL Latvian Lats - unit synonyms for matching user input", "lats;lati") + ";LVL;" + 00301 KGlobal::locale()->countryCodeToName("lv") + ';' + KCurrencyCode::currencyCodeToName("LVL"), 00302 ki18nc("amount in units (real)", "%1 lati"), 00303 ki18ncp("amount in units (integer)", "%1 lats", "%1 lati") 00304 ); 00305 U(Pln, 1e+99, 00306 "PLN", 00307 KCurrencyCode::currencyCodeToName("PLN"), 00308 i18nc("PLN Polish Zloty - unit synonyms for matching user input", "zloty;zlotys;zloties") + 00309 ";PLN;" + KGlobal::locale()->countryCodeToName("pl") + ';' + 00310 KCurrencyCode::currencyCodeToName("PLN"), 00311 ki18nc("amount in units (real)", "%1 zlotys"), 00312 ki18ncp("amount in units (integer)", "%1 zloty", "%1 zlotys") // Alt: zloty, zlote, zlotych 00313 ); 00314 U(Ron, 1e+99, 00315 "RON", 00316 KCurrencyCode::currencyCodeToName("RON"), 00317 i18nc("RON Roumanian Leu - unit synonyms for matching user input", "leu;lei") + ";RON;" + 00318 KGlobal::locale()->countryCodeToName("ro") + ';' + 00319 KCurrencyCode::currencyCodeToName("RON"), 00320 ki18nc("amount in units (real)", "%1 lei"), 00321 ki18ncp("amount in units (integer)", "%1 leu", "%1 lei") 00322 ); 00323 U(Sek, 1e+99, 00324 "SEK", 00325 KCurrencyCode::currencyCodeToName("SEK"), 00326 i18nc("SEK Swedish Krona - unit synonyms for matching user input", "krona;kronor") + ";SEK;" + 00327 KGlobal::locale()->countryCodeToName("se") + ';' + 00328 KCurrencyCode::currencyCodeToName("SEK"), 00329 ki18nc("amount in units (real)", "%1 kronor"), 00330 ki18ncp("amount in units (integer)", "%1 krona", "%1 kronor") 00331 ); 00332 U(Chf, 1e+99, 00333 "CHF", 00334 KCurrencyCode::currencyCodeToName("CHF"), 00335 i18nc("CHF Swiss Francs - unit synonyms for matching user input", "franc;francs") + ";CHF;" + 00336 KGlobal::locale()->countryCodeToName("ch") + ';' + 00337 KCurrencyCode::currencyCodeToName("CHF"), 00338 ki18nc("amount in units (real)", "%1 Swiss francs"), 00339 ki18ncp("amount in units (integer)", "%1 Swiss franc", "%1 Swiss francs") 00340 ); 00341 U(Nok, 1e+99, 00342 "NOK", 00343 KCurrencyCode::currencyCodeToName("NOK"), 00344 i18nc("Norwegian Krone - unit synonyms for matching user input", 00345 "Norwegian krone;Norwegian kroner") + ";NOK;" + 00346 KGlobal::locale()->countryCodeToName("no") + ';' + 00347 KCurrencyCode::currencyCodeToName("NOK"), 00348 ki18nc("amount in units (real)", "%1 Norwegian kroner"), 00349 ki18ncp("amount in units (integer)", "%1 Norwegian krone", "%1 Norwegian kroner") 00350 ); 00351 U(Hrk, 1e+99, 00352 "HRK", 00353 KCurrencyCode::currencyCodeToName("HRK"), 00354 i18nc("HRK Croatian Kuna - unit synonyms for matching user input", "kuna;kune") + ";HRK;" + 00355 KGlobal::locale()->countryCodeToName("hr") + ';' + 00356 KCurrencyCode::currencyCodeToName("HRK"), 00357 ki18nc("amount in units (real)", "%1 kune"), 00358 ki18ncp("amount in units (integer)", "%1 kuna", "%1 kune") 00359 ); 00360 U(Rub, 1e+99, 00361 "RUB", 00362 KCurrencyCode::currencyCodeToName("RUB"), 00363 i18nc("RUB Russsian Ruble - unit synonyms for matching user input", 00364 "ruble;rubles;rouble;roubles") + ";RUB;" + 00365 KGlobal::locale()->countryCodeToName("ru") + ';' + 00366 KCurrencyCode::currencyCodeToName("RUB"), 00367 ki18nc("amount in units (real)", "%1 rubles"), 00368 ki18ncp("amount in units (integer)", "%1 ruble", "%1 rubles") //Alt: rouble/roubles 00369 ); 00370 U(Try, 1e+99, 00371 "TRY", 00372 KCurrencyCode::currencyCodeToName("TRY"), 00373 i18nc("TRY Turkish Lira - unit synonyms for matching user input", "lira") + ";TRY;" + 00374 KGlobal::locale()->countryCodeToName("tr") + ';' + 00375 KCurrencyCode::currencyCodeToName("TRY"), 00376 ki18nc("amount in units (real)", "%1 Turkish lira"), 00377 ki18ncp("amount in units (integer)", "%1 Turkish lira", "%1 Turkish lira") 00378 ); 00379 U(Aud, 1e+99, 00380 "AUD", 00381 KCurrencyCode::currencyCodeToName("AUD"), 00382 i18nc("AUD Australian Dollar - unit synonyms for matching user input", 00383 "Australian dollar;Australian dollars") + ";AUD;" + 00384 KGlobal::locale()->countryCodeToName("au") + ';' + 00385 KCurrencyCode::currencyCodeToName("AUD"), 00386 ki18nc("amount in units (real)", "%1 Australian dollars"), 00387 ki18ncp("amount in units (integer)", "%1 Australian dollar", "%1 Australian dollars") 00388 ); 00389 U(Brl, 1e+99, 00390 "BRL", 00391 KCurrencyCode::currencyCodeToName("BRL"), 00392 i18nc("BRL Brazillian Real - unit synonyms for matching user input", "real;reais") + 00393 ";BRL;" + KGlobal::locale()->countryCodeToName("br") + ';' + 00394 KCurrencyCode::currencyCodeToName("BRL"), 00395 ki18nc("amount in units (real)", "%1 reais"), 00396 ki18ncp("amount in units (integer)", "%1 real", "%1 reais") 00397 ); 00398 U(Cad, 1e+99, 00399 "CAD", 00400 KCurrencyCode::currencyCodeToName("CAD"), 00401 i18nc("Canadian Dollar - unit synonyms for matching user input", 00402 "Canadian dollar;Canadian dollars") + ";CAD;" + 00403 KGlobal::locale()->countryCodeToName("ca") + ';' + 00404 KCurrencyCode::currencyCodeToName("CAD"), 00405 ki18nc("amount in units (real)", "%1 Canadian dollars"), 00406 ki18ncp("amount in units (integer)", "%1 Canadian dollar", "%1 Canadian dollars") 00407 ); 00408 U(Cny, 1e+99, 00409 "CNY", 00410 KCurrencyCode::currencyCodeToName("CNY"), 00411 i18nc("Chinese Yuan - unit synonyms for matching user input", "yuan") + ";CNY;" + 00412 KGlobal::locale()->countryCodeToName("cn") + ';' + 00413 KCurrencyCode::currencyCodeToName("CNY"), 00414 ki18nc("amount in units (real)", "%1 yuan"), 00415 ki18ncp("amount in units (integer)", "%1 yuan", "%1 yuan") 00416 ); 00417 U(Hkd, 1e+99, 00418 "HKD", 00419 KCurrencyCode::currencyCodeToName("HKD"), 00420 i18nc("Hong Kong Dollar - unit synonyms for matching user input", 00421 "Hong Kong dollar;Hong Kong dollars") + ";HKD;" + 00422 KGlobal::locale()->countryCodeToName("hk") + ';' + 00423 KCurrencyCode::currencyCodeToName("HKD"), 00424 ki18nc("amount in units (real)", "%1 Hong Kong dollars"), 00425 ki18ncp("amount in units (integer)", "%1 Hong Kong dollar", "%1 Hong Kong dollars") 00426 ); 00427 U(Idr, 1e+99, 00428 "IDR", 00429 KCurrencyCode::currencyCodeToName("IDR"), 00430 i18nc("IDR Indonesian Rupiah - unit synonyms for matching user input", "rupiah;rupiahs") + 00431 ";IDR;" + KGlobal::locale()->countryCodeToName("id") + ';' + 00432 KCurrencyCode::currencyCodeToName("IDR"), 00433 ki18nc("amount in units (real)", "%1 rupiahs"), 00434 ki18ncp("amount in units (integer)", "%1 rupiah", "%1 rupiahs") // Alt: rupiah 00435 ); 00436 U(Inr, 1e+99, 00437 "INR", 00438 KCurrencyCode::currencyCodeToName("INR"), 00439 i18nc("INR Indian Rupee - unit synonyms for matching user input", "rupee;rupees") + ";INR;" + 00440 KGlobal::locale()->countryCodeToName("in") + ';' + 00441 KCurrencyCode::currencyCodeToName("INR"), 00442 ki18nc("amount in units (real)", "%1 rupees"), 00443 ki18ncp("amount in units (integer)", "%1 rupee", "%1 rupees") // Alt: rupee 00444 ); 00445 U(Krw, 1e+99, 00446 "KRW", 00447 KCurrencyCode::currencyCodeToName("KRW"), 00448 i18nc("KRW Korean Won - unit synonyms for matching user input", "won") + ";KRW;" + 00449 KGlobal::locale()->countryCodeToName("kr") + ';' + 00450 KCurrencyCode::currencyCodeToName("KRW"), 00451 ki18nc("amount in units (real)", "%1 won"), 00452 ki18ncp("amount in units (integer)", "%1 won", "%1 won") 00453 ); 00454 U(Mxn, 1e+99, 00455 "MXN", 00456 KCurrencyCode::currencyCodeToName("MXN"), 00457 i18nc("MXN Mexican Peso - unit synonyms for matching user input", 00458 "Mexican peso;Mexican pesos") + ";MXN;" + 00459 KGlobal::locale()->countryCodeToName("mx") + ';' + 00460 KCurrencyCode::currencyCodeToName("MXN"), 00461 ki18nc("amount in units (real)", "%1 Mexican pesos"), 00462 ki18ncp("amount in units (integer)", "%1 Mexican peso", "%1 Mexican pesos") 00463 ); 00464 U(Myr, 1e+99, 00465 "MYR", 00466 KCurrencyCode::currencyCodeToName("MYR"), 00467 i18nc("MYR Malasian Ringgit - unit synonyms for matching user input", "ringgit;ringgits") + 00468 ";MYR;" + KGlobal::locale()->countryCodeToName("my") + ';' + 00469 KCurrencyCode::currencyCodeToName("MYR"), 00470 ki18nc("amount in units (real)", "%1 ringgit"), 00471 ki18ncp("amount in units (integer)", "%1 ringgit", "%1 ringgit") // Alt: ringgits 00472 ); 00473 U(Nzd, 1e+99, 00474 "NZD", 00475 KCurrencyCode::currencyCodeToName("NZD"), 00476 i18nc("NZD New Zealand Dollar - unit synonyms for matching user input", 00477 "New Zealand dollar;New Zealand dollars") + ";NZD;" + 00478 KGlobal::locale()->countryCodeToName("nz") + ';' + 00479 KCurrencyCode::currencyCodeToName("NZD"), 00480 ki18nc("amount in units (real)", "%1 New Zealand dollars"), 00481 ki18ncp("amount in units (integer)", "%1 New Zealand dollar", "%1 New Zealand dollars") 00482 ); 00483 U(Php, 1e+99, 00484 "PHP", 00485 KCurrencyCode::currencyCodeToName("PHP"), 00486 i18nc("PHP Philippine Peso - unit synonyms for matching user input", 00487 "Philippine peso;Philippine pesos") + ";PHP;" + 00488 KGlobal::locale()->countryCodeToName("ph") + ';' + 00489 KCurrencyCode::currencyCodeToName("PHP"), 00490 ki18nc("amount in units (real)", "%1 Philippine pesos"), 00491 ki18ncp("amount in units (integer)", "%1 Philippine peso", "%1 Philippine pesos") 00492 ); 00493 U(Sgd, 1e+99, 00494 "SGD", 00495 KCurrencyCode::currencyCodeToName("SGD"), 00496 i18nc("SGD Singapore Dollar - unit synonyms for matching user input", 00497 "Singapore dollar;Singapore dollars") + ";SGD;" + 00498 KGlobal::locale()->countryCodeToName("sg") + ';' + 00499 KCurrencyCode::currencyCodeToName("SGD"), 00500 ki18nc("amount in units (real)", "%1 Singapore dollars"), 00501 ki18ncp("amount in units (integer)", "%1 Singapore dollar", "%1 Singapore dollars") 00502 ); 00503 U(Thb, 1e+99, 00504 "THB", 00505 KCurrencyCode::currencyCodeToName("THB"), 00506 i18nc("THB Thai Baht - unit synonyms for matching user input", "baht") + ";THB;" + 00507 KGlobal::locale()->countryCodeToName("th") + ';' + 00508 KCurrencyCode::currencyCodeToName("THB"), 00509 ki18nc("amount in units (real)", "%1 baht"), 00510 ki18ncp("amount in units (integer)", "%1 baht", "%1 baht") 00511 ); 00512 U(Zar, 1e+99, 00513 "ZAR", 00514 KCurrencyCode::currencyCodeToName("ZAR"), 00515 i18nc("South African Rand - unit synonyms for matching user input", "rand") + ";ZAR;" + 00516 KGlobal::locale()->countryCodeToName("za") + ';' + 00517 KCurrencyCode::currencyCodeToName("ZAR"), 00518 ki18nc("amount in units (real)", "%1 rand"), 00519 ki18ncp("amount in units (integer)", "%1 rand", "%1 rand") 00520 ); 00521 00522 setMostCommonUnits(QList<int>() << Eur << Usd << Jpy << Gbp << Cad); 00523 00524 m_cache = KStandardDirs::locateLocal("data", "libkunitconversion/currency.xml"); 00525 m_update = true; 00526 } 00527 00528 Value Currency::convert(const Value& value, UnitPtr to) 00529 { 00530 static QMutex mutex; 00531 00532 mutex.lock(); 00533 QFileInfo info(m_cache); 00534 if (!info.exists() || info.lastModified().secsTo(QDateTime::currentDateTime()) > 86400) { 00535 #ifndef KUNITCONVERSION_NO_SOLID 00536 Solid::Networking::Status status = Solid::Networking::status(); 00537 if (status == Solid::Networking::Connected || status == Solid::Networking::Unknown ) { 00538 #else 00539 { 00540 #endif 00541 kDebug() << "Getting currency info from net:" << URL; 00542 // TODO: This crashes in runner. Threading issues?? 00543 /* 00544 KIO::Job* job = KIO::file_copy(KUrl(URL), KUrl(m_cache), -1, 00545 KIO::Overwrite | KIO::HideProgressInfo); 00546 job->setUiDelegate(0); 00547 if (KIO::NetAccess::synchronousRun(job, 0)) { 00548 m_update = true; 00549 } 00550 */ 00551 kDebug() << "Removed previous cache:" << QFile::remove(m_cache); 00552 #ifndef KUNITCONVERSION_NO_KIO 00553 if (KProcess::execute(QStringList() << "kioclient" << "copy" << "--noninteractive" << URL << m_cache) == 0) { 00554 m_update = true; 00555 } 00556 #else 00557 QNetworkAccessManager manager; 00558 QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(URL))); 00559 QFile cacheFile(m_cache); 00560 cacheFile.open(QFile::WriteOnly); 00561 while (!reply->error() && !reply->atEnd()) { 00562 if (reply->bytesAvailable()>0 00563 || reply->waitForReadyRead(500)) { 00564 cacheFile.write(reply->readAll()); 00565 } 00566 } 00567 cacheFile.close(); 00568 #endif 00569 } 00570 } 00571 mutex.unlock(); 00572 00573 if (m_update) { 00574 QFile file(m_cache); 00575 if (file.open(QIODevice::ReadOnly)) { 00576 QDomDocument doc; 00577 if (doc.setContent(&file, false) ) { 00578 QDomNodeList list = doc.elementsByTagName("Cube"); 00579 for (int i = 0; i < list.count(); ++i) { 00580 const QDomElement e = list.item(i).toElement(); 00581 if (e.hasAttribute("currency")) { 00582 UnitPtr u = unit(e.attribute("currency")); 00583 if (u) { 00584 u->setMultiplier(1.0 / e.attribute("rate").toDouble()); 00585 } 00586 } 00587 } 00588 m_update = false; 00589 } 00590 } 00591 } 00592 Value v = UnitCategory::convert(value, to); 00593 return v; 00594 }
KDE 4.6 API Reference