File indexing completed on 2024-12-08 08:02:35

0001 /*
0002     SPDX-FileCopyrightText: 2010-2012 Lamarque Souza <lamarque@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef PLASMA_NM_MOBILE_PROVIDERS_H
0008 #define PLASMA_NM_MOBILE_PROVIDERS_H
0009 
0010 #include "plasmanm_editor_export.h"
0011 
0012 #include <QDomDocument>
0013 #include <QHash>
0014 #include <QStringList>
0015 #include <QVariantMap>
0016 
0017 #include <NetworkManagerQt/ConnectionSettings>
0018 
0019 struct ProviderData {
0020     QStringList mccmncs;
0021     QString name;
0022 };
0023 
0024 class PLASMANM_EDITOR_EXPORT MobileProviders
0025 {
0026 public:
0027     static const QString ProvidersFile;
0028 
0029     enum ErrorCodes {
0030         Success,
0031         CountryCodesMissing,
0032         ProvidersMissing,
0033         ProvidersIsNull,
0034         ProvidersWrongFormat,
0035         ProvidersFormatNotSupported,
0036     };
0037 
0038     MobileProviders();
0039     ~MobileProviders();
0040 
0041     QStringList getCountryList() const;
0042     QString countryFromLocale() const;
0043     QString getCountryName(const QString &key) const
0044     {
0045         return mCountries.value(key);
0046     }
0047     QStringList getProvidersList(QString country, NetworkManager::ConnectionSettings::ConnectionType type);
0048     QStringList getApns(const QString &provider);
0049     QStringList getNetworkIds(const QString &provider);
0050     QVariantMap getApnInfo(const QString &apn);
0051     QVariantMap getCdmaInfo(const QString &provider);
0052     QStringList getProvidersFromMCCMNC(const QString &mccmnc);
0053     QString getGsmNumber() const
0054     {
0055         return QStringLiteral("*99#");
0056     }
0057     QString getCdmaNumber() const
0058     {
0059         return QStringLiteral("#777");
0060     }
0061     inline ErrorCodes getError()
0062     {
0063         return mError;
0064     }
0065 
0066 private:
0067     ProviderData parseProvider(const QDomNode &providerNode);
0068 
0069     QHash<QString, QString> mCountries;
0070     QHash<QString, QString> mMccMncToName;
0071     QMap<QString, QDomNode> mProvidersGsm;
0072     QMap<QString, QDomNode> mProvidersCdma;
0073     QMap<QString, QDomNode> mApns;
0074     QStringList mNetworkIds;
0075     QDomDocument mDocProviders;
0076     QDomElement docElement;
0077     ErrorCodes mError;
0078     QString getNameByLocale(const QMap<QString, QString> &names) const;
0079 };
0080 
0081 #endif // PLASMA_NM_MOBILE_PROVIDERS_H