File indexing completed on 2024-09-01 05:15:39
0001 // SPDX-FileCopyrightText: 2022 Devin Lin <espidev@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #include "profilesettings.h" 0005 0006 #include <KLocalizedString> 0007 0008 ProfileSettings::ProfileSettings(QObject *parent, 0009 const QString &name, 0010 const QString &apn, 0011 const QString &user, 0012 const QString &password, 0013 NetworkManager::GsmSetting::NetworkType networkType, 0014 const QString &connectionUni) 0015 : QObject{parent} 0016 , m_name(name) 0017 , m_apn(apn) 0018 , m_user(user) 0019 , m_password(password) 0020 , m_networkType(networkTypeStr(networkType)) 0021 , m_connectionUni(connectionUni) 0022 { 0023 setParent(parent); 0024 } 0025 0026 ProfileSettings::ProfileSettings(QObject *parent, NetworkManager::Setting::Ptr setting, NetworkManager::Connection::Ptr connection) 0027 : QObject{parent} 0028 , m_connectionUni(connection->uuid()) 0029 { 0030 NetworkManager::GsmSetting::Ptr gsmSetting = setting.staticCast<NetworkManager::GsmSetting>(); 0031 0032 m_name = connection->name(); 0033 m_apn = gsmSetting->apn(); 0034 m_user = gsmSetting->username(); 0035 m_password = gsmSetting->password(); 0036 m_networkType = networkTypeStr(gsmSetting->networkType()); 0037 } 0038 0039 QString ProfileSettings::name() const 0040 { 0041 return m_name; 0042 } 0043 0044 QString ProfileSettings::apn() const 0045 { 0046 return m_apn; 0047 } 0048 0049 void ProfileSettings::setApn(const QString &apn) 0050 { 0051 if (apn != m_apn) { 0052 m_apn = apn; 0053 Q_EMIT apnChanged(); 0054 } 0055 } 0056 0057 QString ProfileSettings::user() const 0058 { 0059 return m_user; 0060 } 0061 0062 void ProfileSettings::setUser(const QString &user) 0063 { 0064 if (user != m_user) { 0065 m_user = user; 0066 Q_EMIT userChanged(); 0067 } 0068 } 0069 0070 QString ProfileSettings::password() const 0071 { 0072 return m_password; 0073 } 0074 0075 void ProfileSettings::setPassword(const QString &password) 0076 { 0077 if (password != m_password) { 0078 m_password = password; 0079 Q_EMIT passwordChanged(); 0080 } 0081 } 0082 0083 QString ProfileSettings::networkType() const 0084 { 0085 return m_networkType; 0086 } 0087 0088 void ProfileSettings::setNetworkType(const QString &networkType) 0089 { 0090 if (networkType != m_networkType) { 0091 m_networkType = networkType; 0092 Q_EMIT networkTypeChanged(); 0093 } 0094 } 0095 0096 QString ProfileSettings::connectionUni() const 0097 { 0098 return m_connectionUni; 0099 } 0100 0101 QString ProfileSettings::networkTypeStr(NetworkManager::GsmSetting::NetworkType networkType) 0102 { 0103 if (networkType == NetworkManager::GsmSetting::NetworkType::Any) { 0104 return QStringLiteral("Any"); 0105 } else if (networkType == NetworkManager::GsmSetting::NetworkType::GprsEdgeOnly) { 0106 return QStringLiteral("Only 2G"); 0107 } else if (networkType == NetworkManager::GsmSetting::NetworkType::Only3G) { 0108 return QStringLiteral("Only 3G"); 0109 } else if (networkType == NetworkManager::GsmSetting::NetworkType::Only4GLte) { 0110 return QStringLiteral("Only 4G"); 0111 } else if (networkType == NetworkManager::GsmSetting::NetworkType::Prefer2G) { 0112 return QStringLiteral("2G"); 0113 } else if (networkType == NetworkManager::GsmSetting::NetworkType::Prefer3G) { 0114 return QStringLiteral("3G/2G"); 0115 } else if (networkType == NetworkManager::GsmSetting::NetworkType::Prefer4GLte) { 0116 return QStringLiteral("4G/3G/2G"); 0117 } 0118 return QStringLiteral("Any"); 0119 } 0120 0121 NetworkManager::GsmSetting::NetworkType ProfileSettings::networkTypeFlag(const QString &networkType) 0122 { 0123 if (networkType == QStringLiteral("Any")) { 0124 return NetworkManager::GsmSetting::NetworkType::Any; 0125 } else if (networkType == QStringLiteral("Only 2G")) { 0126 return NetworkManager::GsmSetting::NetworkType::GprsEdgeOnly; 0127 } else if (networkType == QStringLiteral("Only 3G")) { 0128 return NetworkManager::GsmSetting::NetworkType::Only3G; 0129 } else if (networkType == QStringLiteral("Only 4G")) { 0130 return NetworkManager::GsmSetting::NetworkType::Only4GLte; 0131 } else if (networkType == QStringLiteral("2G")) { 0132 return NetworkManager::GsmSetting::NetworkType::Prefer2G; 0133 } else if (networkType == QStringLiteral("3G/2G")) { 0134 return NetworkManager::GsmSetting::NetworkType::Prefer3G; 0135 } else if (networkType == QStringLiteral("4G/3G/2G")) { 0136 return NetworkManager::GsmSetting::NetworkType::Prefer4GLte; 0137 } 0138 return NetworkManager::GsmSetting::NetworkType::Any; 0139 }