Changeset View
Changeset View
Standalone View
Standalone View
libs/editor/mobileproviders.cpp
Show All 17 Lines | 1 | /* | |||
---|---|---|---|---|---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "debug.h" | 21 | #include "debug.h" | ||
22 | #include "mobileproviders.h" | 22 | #include "mobileproviders.h" | ||
23 | 23 | | |||
24 | #include <QFile> | 24 | #include <QFile> | ||
25 | #include <QTextStream> | 25 | #include <QTextStream> | ||
26 | 26 | #include <QLocale> | |||
27 | #include <KLocale> | | |||
28 | 27 | | |||
29 | const QString MobileProviders::ProvidersFile = "/usr/share/mobile-broadband-provider-info/serviceproviders.xml"; | 28 | const QString MobileProviders::ProvidersFile = "/usr/share/mobile-broadband-provider-info/serviceproviders.xml"; | ||
30 | 29 | | |||
31 | bool localeAwareCompare(const QString & one, const QString & two) { | 30 | bool localeAwareCompare(const QString & one, const QString & two) { | ||
32 | return one.localeAwareCompare(two) < 0; | 31 | return one.localeAwareCompare(two) < 0; | ||
33 | } | 32 | } | ||
34 | 33 | | |||
35 | MobileProviders::MobileProviders() | 34 | MobileProviders::MobileProviders() | ||
36 | { | 35 | { | ||
37 | const QStringList allCountries = KLocale::global()->allCountriesList(); | 36 | for (int c = 1; c <= QLocale::LastCountry; c++) { | ||
38 | Q_FOREACH (const QString & cc, allCountries) { | 37 | const auto country = static_cast<QLocale::Country>(c); | ||
39 | // qCDebug(PLASMA_NM) << "Inserting" << cc.toUpper() << KLocale::global()->countryCodeToName(cc); | 38 | QLocale locale(QLocale::AnyLanguage, country); | ||
40 | mCountries.insert(cc.toUpper(), KLocale::global()->countryCodeToName(cc)); | 39 | if (locale.country() == country) { | ||
40 | const QString localeName = locale.name(); | ||||
41 | const auto idx = localeName.indexOf(QLatin1Char('_')); | ||||
42 | if (idx != -1) { | ||||
43 | const QString countryCode = localeName.mid(idx + 1); | ||||
44 | QString countryName = locale.nativeCountryName(); | ||||
45 | if (countryName.isEmpty()) { | ||||
46 | countryName = QLocale::countryToString(country); | ||||
47 | } | ||||
48 | mCountries.insert(countryCode, countryName); | ||||
49 | } | ||||
50 | } | ||||
41 | } | 51 | } | ||
42 | mError = Success; | 52 | mError = Success; | ||
43 | 53 | | |||
44 | QFile file2(ProvidersFile); | 54 | QFile file2(ProvidersFile); | ||
45 | 55 | | |||
46 | if (file2.open(QIODevice::ReadOnly)) { | 56 | if (file2.open(QIODevice::ReadOnly)) { | ||
47 | if (mDocProviders.setContent(&file2)) { | 57 | if (mDocProviders.setContent(&file2)) { | ||
48 | docElement = mDocProviders.documentElement(); | 58 | docElement = mDocProviders.documentElement(); | ||
Show All 31 Lines | |||||
80 | { | 90 | { | ||
81 | QStringList temp = mCountries.values(); | 91 | QStringList temp = mCountries.values(); | ||
82 | qSort(temp.begin(), temp.end(), localeAwareCompare); | 92 | qSort(temp.begin(), temp.end(), localeAwareCompare); | ||
83 | return temp; | 93 | return temp; | ||
84 | } | 94 | } | ||
85 | 95 | | |||
86 | QString MobileProviders::countryFromLocale() const | 96 | QString MobileProviders::countryFromLocale() const | ||
87 | { | 97 | { | ||
88 | return KLocale::global()->country().toUpper(); | 98 | const QString localeName = QLocale().name(); | ||
99 | const auto idx = localeName.indexOf(QLatin1Char('_')); | ||||
100 | if (idx != -1) { | ||||
101 | return localeName.mid(idx + 1); | ||||
102 | } | ||||
103 | return QString(); | ||||
89 | } | 104 | } | ||
90 | 105 | | |||
91 | QStringList MobileProviders::getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type) | 106 | QStringList MobileProviders::getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type) | ||
92 | { | 107 | { | ||
93 | mProvidersGsm.clear(); | 108 | mProvidersGsm.clear(); | ||
94 | mProvidersCdma.clear(); | 109 | mProvidersCdma.clear(); | ||
95 | QDomNode n = docElement.firstChild(); | 110 | QDomNode n = docElement.firstChild(); | ||
96 | 111 | | |||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 280 | { | |||
298 | temp.insert("number", getCdmaNumber()); | 313 | temp.insert("number", getCdmaNumber()); | ||
299 | temp.insert("sidList", sidList); | 314 | temp.insert("sidList", sidList); | ||
300 | return temp; | 315 | return temp; | ||
301 | } | 316 | } | ||
302 | 317 | | |||
303 | QString MobileProviders::getNameByLocale(const QMap<QString, QString> & localizedNames) const | 318 | QString MobileProviders::getNameByLocale(const QMap<QString, QString> & localizedNames) const | ||
304 | { | 319 | { | ||
305 | QString name; | 320 | QString name; | ||
306 | const QStringList locales = KLocale::global()->languageList(); | 321 | const QStringList locales = QLocale().uiLanguages(); | ||
307 | Q_FOREACH (const QString & locale, locales) { | 322 | Q_FOREACH (const QString & locale, locales) { | ||
308 | QString language, country, modifier, charset; | 323 | QString language = locale.split(QLatin1Char('-')).at(0); | ||
309 | KLocale::splitLocale(locale, language, country, modifier, charset); | | |||
310 | 324 | | |||
311 | if (localizedNames.contains(language)) { | 325 | if (localizedNames.contains(language)) { | ||
312 | return localizedNames[language]; | 326 | return localizedNames[language]; | ||
313 | } | 327 | } | ||
314 | } | 328 | } | ||
315 | 329 | | |||
316 | name = localizedNames["en"]; | 330 | name = localizedNames["en"]; | ||
317 | 331 | | |||
318 | // Use any language if no proper localized name were found. | 332 | // Use any language if no proper localized name were found. | ||
319 | if (name.isEmpty() && !localizedNames.isEmpty()) { | 333 | if (name.isEmpty() && !localizedNames.isEmpty()) { | ||
320 | name = localizedNames.constBegin().value(); | 334 | name = localizedNames.constBegin().value(); | ||
321 | } | 335 | } | ||
322 | return name; | 336 | return name; | ||
323 | } | 337 | } |