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 | mCountries.insert(countryCode, locale.nativeCountryName()); | ||||
45 | } | ||||
46 | } | ||||
41 | } | 47 | } | ||
42 | mError = Success; | 48 | mError = Success; | ||
43 | 49 | | |||
44 | QFile file2(ProvidersFile); | 50 | QFile file2(ProvidersFile); | ||
45 | 51 | | |||
46 | if (file2.open(QIODevice::ReadOnly)) { | 52 | if (file2.open(QIODevice::ReadOnly)) { | ||
47 | if (mDocProviders.setContent(&file2)) { | 53 | if (mDocProviders.setContent(&file2)) { | ||
48 | docElement = mDocProviders.documentElement(); | 54 | docElement = mDocProviders.documentElement(); | ||
Show All 31 Lines | |||||
80 | { | 86 | { | ||
81 | QStringList temp = mCountries.values(); | 87 | QStringList temp = mCountries.values(); | ||
82 | qSort(temp.begin(), temp.end(), localeAwareCompare); | 88 | qSort(temp.begin(), temp.end(), localeAwareCompare); | ||
83 | return temp; | 89 | return temp; | ||
84 | } | 90 | } | ||
85 | 91 | | |||
86 | QString MobileProviders::countryFromLocale() const | 92 | QString MobileProviders::countryFromLocale() const | ||
87 | { | 93 | { | ||
88 | return KLocale::global()->country().toUpper(); | 94 | const QString localeName = QLocale().name(); | ||
95 | const auto idx = localeName.indexOf(QLatin1Char('_')); | ||||
96 | if (idx != -1) { | ||||
97 | return localeName.mid(idx + 1); | ||||
98 | } | ||||
99 | return QString(); | ||||
89 | } | 100 | } | ||
90 | 101 | | |||
91 | QStringList MobileProviders::getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type) | 102 | QStringList MobileProviders::getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type) | ||
92 | { | 103 | { | ||
93 | mProvidersGsm.clear(); | 104 | mProvidersGsm.clear(); | ||
94 | mProvidersCdma.clear(); | 105 | mProvidersCdma.clear(); | ||
95 | QDomNode n = docElement.firstChild(); | 106 | QDomNode n = docElement.firstChild(); | ||
96 | 107 | | |||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 276 | { | |||
298 | temp.insert("number", getCdmaNumber()); | 309 | temp.insert("number", getCdmaNumber()); | ||
299 | temp.insert("sidList", sidList); | 310 | temp.insert("sidList", sidList); | ||
300 | return temp; | 311 | return temp; | ||
301 | } | 312 | } | ||
302 | 313 | | |||
303 | QString MobileProviders::getNameByLocale(const QMap<QString, QString> & localizedNames) const | 314 | QString MobileProviders::getNameByLocale(const QMap<QString, QString> & localizedNames) const | ||
304 | { | 315 | { | ||
305 | QString name; | 316 | QString name; | ||
306 | const QStringList locales = KLocale::global()->languageList(); | 317 | const QStringList locales = QLocale().uiLanguages(); | ||
307 | Q_FOREACH (const QString & locale, locales) { | 318 | Q_FOREACH (const QString & locale, locales) { | ||
308 | QString language, country, modifier, charset; | 319 | QString language = locale.split(QLatin1Char('-')).at(0); | ||
309 | KLocale::splitLocale(locale, language, country, modifier, charset); | | |||
310 | 320 | | |||
311 | if (localizedNames.contains(language)) { | 321 | if (localizedNames.contains(language)) { | ||
312 | return localizedNames[language]; | 322 | return localizedNames[language]; | ||
313 | } | 323 | } | ||
314 | } | 324 | } | ||
315 | 325 | | |||
316 | name = localizedNames["en"]; | 326 | name = localizedNames["en"]; | ||
317 | 327 | | |||
318 | // Use any language if no proper localized name were found. | 328 | // Use any language if no proper localized name were found. | ||
319 | if (name.isEmpty() && !localizedNames.isEmpty()) { | 329 | if (name.isEmpty() && !localizedNames.isEmpty()) { | ||
320 | name = localizedNames.constBegin().value(); | 330 | name = localizedNames.constBegin().value(); | ||
321 | } | 331 | } | ||
322 | return name; | 332 | return name; | ||
323 | } | 333 | } |