File indexing completed on 2024-12-08 08:02:34
0001 /* 0002 SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "configuration.h" 0008 #include <KConfigGroup> 0009 #include <KSharedConfig> 0010 #include <KUser> 0011 #include <QMutexLocker> 0012 0013 static bool propManageVirtualConnectionsInitialized = false; 0014 static bool propManageVirtualConnections = false; 0015 QMutex Configuration::sMutex; 0016 0017 Configuration &Configuration::self() 0018 { 0019 static Configuration c; 0020 return c; 0021 } 0022 0023 bool Configuration::unlockModemOnDetection() const 0024 { 0025 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0026 KConfigGroup grp(config, QStringLiteral("General")); 0027 0028 if (grp.isValid()) { 0029 return grp.readEntry(QStringLiteral("UnlockModemOnDetection"), true); 0030 } 0031 0032 return true; 0033 } 0034 0035 void Configuration::setUnlockModemOnDetection(bool unlock) 0036 { 0037 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0038 KConfigGroup grp(config, QStringLiteral("General")); 0039 0040 if (grp.isValid()) { 0041 grp.writeEntry(QStringLiteral("UnlockModemOnDetection"), unlock); 0042 } 0043 } 0044 0045 bool Configuration::manageVirtualConnections() const 0046 { 0047 // Avoid reading from the config file over and over 0048 if (propManageVirtualConnectionsInitialized) { 0049 return propManageVirtualConnections; 0050 } 0051 0052 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0053 KConfigGroup grp(config, QStringLiteral("General")); 0054 0055 if (grp.isValid()) { 0056 QMutexLocker locker(&sMutex); 0057 propManageVirtualConnections = grp.readEntry(QStringLiteral("ManageVirtualConnections"), false); 0058 propManageVirtualConnectionsInitialized = true; 0059 0060 return propManageVirtualConnections; 0061 } 0062 0063 return true; 0064 } 0065 0066 void Configuration::setManageVirtualConnections(bool manage) 0067 { 0068 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0069 KConfigGroup grp(config, QStringLiteral("General")); 0070 0071 if (grp.isValid()) { 0072 { 0073 QMutexLocker locker(&sMutex); 0074 grp.writeEntry(QStringLiteral("ManageVirtualConnections"), manage); 0075 grp.sync(); 0076 propManageVirtualConnections = manage; 0077 } 0078 Q_EMIT manageVirtualConnectionsChanged(manage); 0079 } 0080 } 0081 0082 bool Configuration::airplaneModeEnabled() const 0083 { 0084 static KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0085 static KConfigGroup grp(config, QStringLiteral("General")); 0086 return grp.readEntry(QStringLiteral("AirplaneModeEnabled"), false); 0087 } 0088 0089 void Configuration::setAirplaneModeEnabled(bool enabled) 0090 { 0091 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0092 KConfigGroup grp(config, QStringLiteral("General")); 0093 0094 if (grp.isValid()) { 0095 grp.writeEntry(QStringLiteral("AirplaneModeEnabled"), enabled); 0096 grp.sync(); 0097 Q_EMIT airplaneModeEnabledChanged(); 0098 } 0099 } 0100 0101 QString Configuration::hotspotName() const 0102 { 0103 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0104 KConfigGroup grp(config, QStringLiteral("General")); 0105 KUser currentUser; 0106 0107 const QString defaultName = currentUser.loginName() + QLatin1String("-hotspot"); 0108 0109 if (grp.isValid()) { 0110 return grp.readEntry(QStringLiteral("HotspotName"), defaultName); 0111 } 0112 0113 return defaultName; 0114 } 0115 0116 void Configuration::setHotspotName(const QString &name) 0117 { 0118 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0119 KConfigGroup grp(config, QStringLiteral("General")); 0120 0121 if (grp.isValid()) { 0122 grp.writeEntry(QStringLiteral("HotspotName"), name); 0123 } 0124 } 0125 0126 QString Configuration::hotspotPassword() const 0127 { 0128 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0129 KConfigGroup grp(config, QStringLiteral("General")); 0130 0131 if (grp.isValid()) { 0132 return grp.readEntry(QStringLiteral("HotspotPassword"), QString()); 0133 } 0134 0135 return {}; 0136 } 0137 0138 void Configuration::setHotspotPassword(const QString &password) 0139 { 0140 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0141 KConfigGroup grp(config, QStringLiteral("General")); 0142 0143 if (grp.isValid()) { 0144 grp.writeEntry(QStringLiteral("HotspotPassword"), password); 0145 } 0146 } 0147 0148 QString Configuration::hotspotConnectionPath() const 0149 { 0150 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0151 KConfigGroup grp(config, QStringLiteral("General")); 0152 0153 if (grp.isValid()) { 0154 return grp.readEntry(QStringLiteral("HotspotConnectionPath"), QString()); 0155 } 0156 0157 return {}; 0158 } 0159 0160 void Configuration::setHotspotConnectionPath(const QString &path) 0161 { 0162 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0163 KConfigGroup grp(config, QStringLiteral("General")); 0164 0165 if (grp.isValid()) { 0166 grp.writeEntry(QStringLiteral("HotspotConnectionPath"), path); 0167 } 0168 } 0169 0170 bool Configuration::showPasswordDialog() const 0171 { 0172 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0173 KConfigGroup grp(config, QStringLiteral("General")); 0174 0175 if (grp.isValid()) { 0176 return grp.readEntry(QStringLiteral("ShowPasswordDialog"), true); 0177 } 0178 0179 return true; 0180 } 0181 0182 bool Configuration::systemConnectionsByDefault() const 0183 { 0184 KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("plasma-nm")); 0185 KConfigGroup grp(config, QStringLiteral("General")); 0186 return grp.readEntry(QStringLiteral("SystemConnectionsByDefault"), false); 0187 } 0188 0189 #include "moc_configuration.cpp"