Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-systemsettings] Add readonly autoConnect property to the Vpn mo…
…del. Contributes to JB#41419

The autoConnect property of VpnModel is true if there's at least one
vpn connection that has autoConnect true.
  • Loading branch information
rainemak committed Apr 9, 2019
1 parent d374ea0 commit bc32662
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/vpnmodel.cpp
Expand Up @@ -319,6 +319,7 @@ VpnModel::VpnModel(QObject *parent)
, credentials_(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/system/privileged/vpn-data"))
, provisioningOutputPath_(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/system/privileged/vpn-provisioning"))
, bestState_(VpnModel::Idle)
, autoConnect_(false)
{
qDBusRegisterMetaType<PathProperties>();
qDBusRegisterMetaType<PathPropertiesArray>();
Expand Down Expand Up @@ -390,6 +391,11 @@ int VpnModel::bestState() const
return static_cast<int>(bestState_);
}

bool VpnModel::autoConnect() const
{
return autoConnect_;
}

void VpnModel::createConnection(const QVariantMap &createProperties)
{
const QString path(createProperties.value(QString("path")).toString());
Expand Down Expand Up @@ -883,6 +889,16 @@ void VpnModel::updateConnection(VpnConnection *conn, const QVariantMap &updatePr
}
}
}

bool autoConnect = false;
for (int i = 0; i < count(); ++i) {
autoConnect = autoConnect || get<VpnConnection>(i)->autoConnect();
}

if (autoConnect_ != autoConnect) {
autoConnect_ = autoConnect;
autoConnectChanged();
}
}

QVariantMap VpnModel::processOpenVpnProvisioningFile(QFile &provisioningFile)
Expand Down
5 changes: 5 additions & 0 deletions src/vpnmodel.h
Expand Up @@ -51,6 +51,7 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
Q_OBJECT

Q_PROPERTY(int bestState READ bestState NOTIFY bestStateChanged)
Q_PROPERTY(bool autoConnect READ autoConnect NOTIFY autoConnectChanged)

public:
enum ConnectionState {
Expand All @@ -66,6 +67,7 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
virtual ~VpnModel();

int bestState() const;
bool autoConnect() const;

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

signals:
void bestStateChanged();
void autoConnectChanged();
void connectionStateChanged(const QString &path, int state);

private:
Expand Down Expand Up @@ -130,6 +133,8 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
CredentialsRepository credentials_;
QString provisioningOutputPath_;
ConnectionState bestState_;
// True if there's one VPN that has autoConnect true
bool autoConnect_;
};

class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
Expand Down

0 comments on commit bc32662

Please sign in to comment.