Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit bc32662

Browse files
committed
[nemo-systemsettings] Add readonly autoConnect property to the Vpn model. Contributes to JB#41419
The autoConnect property of VpnModel is true if there's at least one vpn connection that has autoConnect true.
1 parent d374ea0 commit bc32662

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/vpnmodel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ VpnModel::VpnModel(QObject *parent)
319319
, credentials_(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/system/privileged/vpn-data"))
320320
, provisioningOutputPath_(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/system/privileged/vpn-provisioning"))
321321
, bestState_(VpnModel::Idle)
322+
, autoConnect_(false)
322323
{
323324
qDBusRegisterMetaType<PathProperties>();
324325
qDBusRegisterMetaType<PathPropertiesArray>();
@@ -390,6 +391,11 @@ int VpnModel::bestState() const
390391
return static_cast<int>(bestState_);
391392
}
392393

394+
bool VpnModel::autoConnect() const
395+
{
396+
return autoConnect_;
397+
}
398+
393399
void VpnModel::createConnection(const QVariantMap &createProperties)
394400
{
395401
const QString path(createProperties.value(QString("path")).toString());
@@ -883,6 +889,16 @@ void VpnModel::updateConnection(VpnConnection *conn, const QVariantMap &updatePr
883889
}
884890
}
885891
}
892+
893+
bool autoConnect = false;
894+
for (int i = 0; i < count(); ++i) {
895+
autoConnect = autoConnect || get<VpnConnection>(i)->autoConnect();
896+
}
897+
898+
if (autoConnect_ != autoConnect) {
899+
autoConnect_ = autoConnect;
900+
autoConnectChanged();
901+
}
886902
}
887903

888904
QVariantMap VpnModel::processOpenVpnProvisioningFile(QFile &provisioningFile)

src/vpnmodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
5151
Q_OBJECT
5252

5353
Q_PROPERTY(int bestState READ bestState NOTIFY bestStateChanged)
54+
Q_PROPERTY(bool autoConnect READ autoConnect NOTIFY autoConnectChanged)
5455

5556
public:
5657
enum ConnectionState {
@@ -66,6 +67,7 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
6667
virtual ~VpnModel();
6768

6869
int bestState() const;
70+
bool autoConnect() const;
6971

7072
Q_INVOKABLE void createConnection(const QVariantMap &properties);
7173
Q_INVOKABLE void modifyConnection(const QString &path, const QVariantMap &properties);
@@ -88,6 +90,7 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
8890

8991
signals:
9092
void bestStateChanged();
93+
void autoConnectChanged();
9194
void connectionStateChanged(const QString &path, int state);
9295

9396
private:
@@ -130,6 +133,8 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
130133
CredentialsRepository credentials_;
131134
QString provisioningOutputPath_;
132135
ConnectionState bestState_;
136+
// True if there's one VPN that has autoConnect true
137+
bool autoConnect_;
133138
};
134139

135140
class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject

0 commit comments

Comments
 (0)