diff --git a/CMakeLists.txt b/CMakeLists.txt index 4020fffa..b727ec59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,100 +1,99 @@ cmake_minimum_required(VERSION 3.0) project(plasma-networkmanagement) set(PROJECT_VERSION "5.13.80") set(PROJECT_VERSION_MAJOR 5) set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.42.0") ################# set KDE specific information ################# find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core DBus Network Quick Widgets ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED I18n WindowSystem Service Completion WidgetsAddons KIO CoreAddons Wallet ConfigWidgets IconThemes Solid DBusAddons Notifications Plasma Declarative NetworkManagerQt - KDELibs4Support ) find_package(KF5ModemManagerQt ${KF5_MIN_VERSION}) set_package_properties(KF5ModemManagerQt PROPERTIES TYPE OPTIONAL) # Required only for getting information about NetworkManager version in CMake find_package(NetworkManager 1.0.0) set_package_properties(NetworkManager PROPERTIES TYPE REQUIRED) find_package(MobileBroadbandProviderInfo) set_package_properties(MobileBroadbandProviderInfo PROPERTIES DESCRIPTION "Database of mobile broadband service providers" URL "http://live.gnome.org/NetworkManager/MobileBroadband/ServiceProviders" TYPE OPTIONAL) find_package(Qca-qt5 2.1.0) set_package_properties(Qca-qt5 PROPERTIES DESCRIPTION "Support for encryption" URL "http://download.kde.org/stable/qca-qt5/" TYPE REQUIRED) if (DISABLE_MODEMMANAGER_SUPPORT) message(STATUS "Disabling ModemManager support") set(WITH_MODEMMANAGER_SUPPORT 0) else() if (KF5ModemManagerQt_FOUND) message(STATUS "Enabling ModemManager support") set(WITH_MODEMMANAGER_SUPPORT 1) else() message(STATUS "ModemManager or ModemManagerQt not found") set(WITH_MODEMMANAGER_SUPPORT 0) endif() endif() add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) add_definitions(-DQT_USE_FAST_OPERATOR_PLUS) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_BYTEARRAY) add_definitions(-DWITH_MODEMMANAGER_SUPPORT=${WITH_MODEMMANAGER_SUPPORT}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs ${CMAKE_CURRENT_SOURCE_DIR}/libs/editor/) add_subdirectory(applet) add_subdirectory(kded) add_subdirectory(kcm) add_subdirectory(libs) add_subdirectory(vpn) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/libs/editor/CMakeLists.txt b/libs/editor/CMakeLists.txt index bdeb2db4..c50a43ac 100644 --- a/libs/editor/CMakeLists.txt +++ b/libs/editor/CMakeLists.txt @@ -1,110 +1,109 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/widgets) set(plasmanm_editor_SRCS settings/bondwidget.cpp settings/bridgewidget.cpp settings/btwidget.cpp settings/cdmawidget.cpp settings/connectionwidget.cpp settings/gsmwidget.cpp settings/infinibandwidget.cpp settings/ipv4widget.cpp settings/ipv6widget.cpp settings/pppoewidget.cpp settings/pppwidget.cpp settings/security802-1x.cpp settings/teamwidget.cpp settings/vlanwidget.cpp settings/wificonnectionwidget.cpp settings/wifisecurity.cpp settings/wiredconnectionwidget.cpp settings/wiredsecurity.cpp widgets/advancedpermissionswidget.cpp widgets/bssidcombobox.cpp widgets/delegate.cpp widgets/editlistdialog.cpp widgets/hwaddrcombobox.cpp widgets/intdelegate.cpp widgets/ipv4delegate.cpp widgets/ipv4routeswidget.cpp widgets/ipv6delegate.cpp widgets/ipv6routeswidget.cpp widgets/passwordfield.cpp widgets/settingwidget.cpp widgets/ssidcombobox.cpp connectioneditorbase.cpp connectioneditordialog.cpp connectioneditortabwidget.cpp listvalidator.cpp simpleipv4addressvalidator.cpp simpleipv6addressvalidator.cpp vpnuiplugin.cpp ../configuration.cpp ../debug.cpp ../uiutils.cpp ) if (WITH_MODEMMANAGER_SUPPORT) set(plasmanm_editor_SRCS ${plasmanm_editor_SRCS} widgets/mobileconnectionwizard.cpp mobileproviders.cpp) endif() ki18n_wrap_ui(plasmanm_editor_SRCS settings/ui/802-1x.ui settings/ui/bond.ui settings/ui/bridge.ui settings/ui/bt.ui settings/ui/cdma.ui settings/ui/connectionwidget.ui settings/ui/gsm.ui settings/ui/infiniband.ui settings/ui/ipv4.ui settings/ui/ipv6.ui settings/ui/ppp.ui settings/ui/pppoe.ui settings/ui/team.ui settings/ui/vlan.ui settings/ui/team.ui settings/ui/wificonnectionwidget.ui settings/ui/wifisecurity.ui settings/ui/wiredconnectionwidget.ui settings/ui/wiredsecurity.ui widgets/ui/advancedpermissionswidget.ui widgets/ui/ipv4routes.ui widgets/ui/ipv6routes.ui connectioneditortabwidget.ui ) add_library(plasmanm_editor SHARED ${plasmanm_editor_SRCS}) target_link_libraries(plasmanm_editor PUBLIC KF5::NetworkManagerQt KF5::WidgetsAddons KF5::Completion Qt5::Widgets PRIVATE Qt5::Network Qt5::DBus qca-qt5 KF5::I18n KF5::KIOWidgets KF5::IconThemes KF5::Notifications KF5::Wallet KF5::Solid - KF5::KDELibs4Support # KLocale ) if (WITH_MODEMMANAGER_SUPPORT) target_link_libraries(plasmanm_editor PUBLIC KF5::ModemManagerQt) endif() install(TARGETS plasmanm_editor ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES plasma-networkmanagement-vpnuiplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR}) diff --git a/libs/editor/mobileproviders.cpp b/libs/editor/mobileproviders.cpp index 568cb349..113458ff 100644 --- a/libs/editor/mobileproviders.cpp +++ b/libs/editor/mobileproviders.cpp @@ -1,323 +1,337 @@ /* Copyright 2010-2012 Lamarque Souza This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "debug.h" #include "mobileproviders.h" #include #include - -#include +#include const QString MobileProviders::ProvidersFile = "/usr/share/mobile-broadband-provider-info/serviceproviders.xml"; bool localeAwareCompare(const QString & one, const QString & two) { return one.localeAwareCompare(two) < 0; } MobileProviders::MobileProviders() { - const QStringList allCountries = KLocale::global()->allCountriesList(); - Q_FOREACH (const QString & cc, allCountries) { - // qCDebug(PLASMA_NM) << "Inserting" << cc.toUpper() << KLocale::global()->countryCodeToName(cc); - mCountries.insert(cc.toUpper(), KLocale::global()->countryCodeToName(cc)); + for (int c = 1; c <= QLocale::LastCountry; c++) { + const auto country = static_cast(c); + QLocale locale(QLocale::AnyLanguage, country); + if (locale.country() == country) { + const QString localeName = locale.name(); + const auto idx = localeName.indexOf(QLatin1Char('_')); + if (idx != -1) { + const QString countryCode = localeName.mid(idx + 1); + QString countryName = locale.nativeCountryName(); + if (countryName.isEmpty()) { + countryName = QLocale::countryToString(country); + } + mCountries.insert(countryCode, countryName); + } + } } mError = Success; QFile file2(ProvidersFile); if (file2.open(QIODevice::ReadOnly)) { if (mDocProviders.setContent(&file2)) { docElement = mDocProviders.documentElement(); if (docElement.isNull()) { qCWarning(PLASMA_NM) << ProvidersFile << ": document is null"; mError = ProvidersIsNull; } else { if (docElement.isNull() || docElement.tagName() != "serviceproviders") { qCWarning(PLASMA_NM) << ProvidersFile << ": wrong format"; mError = ProvidersWrongFormat; } else { if (docElement.attribute("format") != "2.0") { qCWarning(PLASMA_NM) << ProvidersFile << ": mobile broadband provider database format '" << docElement.attribute("format") << "' not supported."; mError = ProvidersFormatNotSupported; } else { // qCDebug(PLASMA_NM) << "Everything is alright so far"; } } } } file2.close(); } else { qCWarning(PLASMA_NM) << "Error opening providers file" << ProvidersFile; mError = ProvidersMissing; } } MobileProviders::~MobileProviders() { } QStringList MobileProviders::getCountryList() const { QStringList temp = mCountries.values(); qSort(temp.begin(), temp.end(), localeAwareCompare); return temp; } QString MobileProviders::countryFromLocale() const { - return KLocale::global()->country().toUpper(); + const QString localeName = QLocale().name(); + const auto idx = localeName.indexOf(QLatin1Char('_')); + if (idx != -1) { + return localeName.mid(idx + 1); + } + return QString(); } QStringList MobileProviders::getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type) { mProvidersGsm.clear(); mProvidersCdma.clear(); QDomNode n = docElement.firstChild(); // country is a country name and we parse country codes. if (!mCountries.key(country).isNull()) { country = mCountries.key(country); } QMap sortedGsm; QMap sortedCdma; while (!n.isNull()) { QDomElement e = n.toElement(); // if (!e.isNull() && e.attribute("code").toUpper() == country) { QDomNode n2 = e.firstChild(); while (!n2.isNull()) { QDomElement e2 = n2.toElement(); // if (!e2.isNull() && e2.tagName().toLower() == "provider") { QDomNode n3 = e2.firstChild(); bool hasGsm = false; bool hasCdma = false; QMap localizedProviderNames; while (!n3.isNull()) { QDomElement e3 = n3.toElement(); // if (!e3.isNull()) { if (e3.tagName().toLower() == "gsm") { hasGsm = true; } else if (e3.tagName().toLower() == "cdma") { hasCdma = true; } else if (e3.tagName().toLower() == "name") { QString lang = e3.attribute("xml:lang"); if (lang.isEmpty()) { lang = "en"; // English is default } else { lang = lang.toLower(); lang.remove(QRegExp("\\-.*$")); // Remove everything after '-' in xml:lang attribute. } localizedProviderNames.insert(lang, e3.text()); } } n3 = n3.nextSibling(); } const QString name = getNameByLocale(localizedProviderNames); if (hasGsm) { mProvidersGsm.insert(name, e2.firstChild()); sortedGsm.insert(name.toLower(), name); } if (hasCdma) { mProvidersCdma.insert(name, e2.firstChild()); sortedCdma.insert(name.toLower(), name); } } n2 = n2.nextSibling(); } break; } n = n.nextSibling(); } if (type == NetworkManager::ConnectionSettings::Gsm) { return sortedGsm.values(); } return sortedCdma.values(); } QStringList MobileProviders::getApns(const QString & provider) { mApns.clear(); mNetworkIds.clear(); if (!mProvidersGsm.contains(provider)) { return QStringList(); } QDomNode n = mProvidersGsm[provider]; while (!n.isNull()) { QDomElement e = n.toElement(); // if (!e.isNull() && e.tagName().toLower() == "gsm") { QDomNode n2 = e.firstChild(); while (!n2.isNull()) { QDomElement e2 = n2.toElement(); // if (!e2.isNull() && e2.tagName().toLower() == "apn") { bool isInternet = true; QDomNode n3 = e2.firstChild(); while (!n3.isNull()) { QDomElement e3 = n3.toElement(); // if (!e3.isNull() && e3.tagName().toLower() == "usage" && !e3.attribute("type").isNull() && e3.attribute("type").toLower() != "internet") { // qCDebug(PLASMA_NM) << "apn" << e2.attribute("value") << "ignored because of usage" << e3.attribute("type"); isInternet = false; break; } n3 = n3.nextSibling(); } if (isInternet) { mApns.insert(e2.attribute("value"), e2.firstChild()); } } else if (!e2.isNull() && e2.tagName().toLower() == "network-id") { mNetworkIds.append(e2.attribute("mcc") + '-' + e2.attribute("mnc")); } n2 = n2.nextSibling(); } } n = n.nextSibling(); } QStringList temp = mApns.keys(); temp.sort(); return temp; } QStringList MobileProviders::getNetworkIds(const QString & provider) { if (mNetworkIds.isEmpty()) { getApns(provider); } return mNetworkIds; } QVariantMap MobileProviders::getApnInfo(const QString & apn) { QVariantMap temp; QDomNode n = mApns[apn]; QStringList dnsList; QMap localizedPlanNames; while (!n.isNull()) { QDomElement e = n.toElement(); // if (!e.isNull()) { if (e.tagName().toLower() == "name") { QString lang = e.attribute("xml:lang"); if (lang.isEmpty()) { lang = "en"; // English is default } else { lang = lang.toLower(); lang.remove(QRegExp("\\-.*$")); // Remove everything after '-' in xml:lang attribute. } localizedPlanNames.insert(lang, e.text()); } else if (e.tagName().toLower() == "username") { temp.insert("username", e.text()); } else if (e.tagName().toLower() == "password") { temp.insert("password", e.text()); } else if (e.tagName().toLower() == "dns") { dnsList.append(e.text()); } } n = n.nextSibling(); } QString name = getNameByLocale(localizedPlanNames); if (!name.isEmpty()) { temp.insert("name", QVariant::fromValue(name)); } temp.insert("number", getGsmNumber()); temp.insert("apn", apn); temp.insert("dnsList", dnsList); return temp; } QVariantMap MobileProviders::getCdmaInfo(const QString & provider) { if (!mProvidersCdma.contains(provider)) { return QVariantMap(); } QVariantMap temp; QDomNode n = mProvidersCdma[provider]; QStringList sidList; while (!n.isNull()) { QDomElement e = n.toElement(); // if (!e.isNull() && e.tagName().toLower() == "cdma") { QDomNode n2 = e.firstChild(); while (!n2.isNull()) { QDomElement e2 = n2.toElement(); // if (!e2.isNull()) { if (e2.tagName().toLower() == "username") { temp.insert("username", e2.text()); } else if (e2.tagName().toLower() == "password") { temp.insert("password", e2.text()); } else if (e2.tagName().toLower() == "sid") { sidList.append(e2.text()); } } n2 = n2.nextSibling(); } } n = n.nextSibling(); } temp.insert("number", getCdmaNumber()); temp.insert("sidList", sidList); return temp; } QString MobileProviders::getNameByLocale(const QMap & localizedNames) const { QString name; - const QStringList locales = KLocale::global()->languageList(); + const QStringList locales = QLocale().uiLanguages(); Q_FOREACH (const QString & locale, locales) { - QString language, country, modifier, charset; - KLocale::splitLocale(locale, language, country, modifier, charset); + QString language = locale.split(QLatin1Char('-')).at(0); if (localizedNames.contains(language)) { return localizedNames[language]; } } name = localizedNames["en"]; // Use any language if no proper localized name were found. if (name.isEmpty() && !localizedNames.isEmpty()) { name = localizedNames.constBegin().value(); } return name; }