Skip to content

Commit

Permalink
[vpn] Store VPN types in generic strings instead of hard-coded enums.…
Browse files Browse the repository at this point in the history
… Contributes to JB#40883
  • Loading branch information
Joona Petrell committed Jan 29, 2018
1 parent 813b0e9 commit d9a5317
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
14 changes: 3 additions & 11 deletions src/vpnmodel.cpp
Expand Up @@ -48,14 +48,6 @@ QHash<QString, QList<QPair<QVariant, QVariant> > > propertyConversions()
{
QHash<QString, QList<QPair<QVariant, QVariant> > > rv;

QList<QPair<QVariant, QVariant> > types;
types.push_back(qMakePair(QVariant::fromValue(QString("openvpn")), QVariant::fromValue(static_cast<int>(VpnModel::OpenVPN))));
types.push_back(qMakePair(QVariant::fromValue(QString("openconnect")), QVariant::fromValue(static_cast<int>(VpnModel::OpenConnect))));
types.push_back(qMakePair(QVariant::fromValue(QString("vpnc")), QVariant::fromValue(static_cast<int>(VpnModel::VPNC))));
types.push_back(qMakePair(QVariant::fromValue(QString("l2tp")), QVariant::fromValue(static_cast<int>(VpnModel::L2TP))));
types.push_back(qMakePair(QVariant::fromValue(QString("pptp")), QVariant::fromValue(static_cast<int>(VpnModel::PPTP))));
rv.insert(QString("type"), types);

QList<QPair<QVariant, QVariant> > states;
states.push_back(qMakePair(QVariant::fromValue(QString("idle")), QVariant::fromValue(static_cast<int>(VpnModel::Idle))));
states.push_back(qMakePair(QVariant::fromValue(QString("failure")), QVariant::fromValue(static_cast<int>(VpnModel::Failure))));
Expand Down Expand Up @@ -733,13 +725,13 @@ QVariantMap VpnModel::connectionSettings(const QString &path)
return rv;
}

QVariantMap VpnModel::processProvisioningFile(const QString &path, ConnectionType type)
QVariantMap VpnModel::processProvisioningFile(const QString &path, const QString &type)
{
QVariantMap rv;

QFile provisioningFile(path);
if (provisioningFile.open(QIODevice::ReadOnly)) {
if (type == OpenVPN) {
if (type == QString("openvpn")) {
rv = processOpenVpnProvisioningFile(provisioningFile);
} else {
qWarning() << "Provisioning not currently supported for VPN type:" << type;
Expand Down Expand Up @@ -1109,7 +1101,7 @@ VpnConnection::VpnConnection(const QString &path)
: QObject(0)
, path_(path)
, state_(static_cast<int>(VpnModel::Disconnect))
, type_(static_cast<int>(VpnModel::OpenVPN))
, type_("openvpn")
{
}

20 changes: 5 additions & 15 deletions src/vpnmodel.h
Expand Up @@ -50,7 +50,6 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
{
Q_OBJECT
Q_ENUMS(ConnectionState)
Q_ENUMS(ConnectionType)

Q_PROPERTY(int bestState READ bestState NOTIFY bestStateChanged)

Expand All @@ -63,14 +62,6 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
Disconnect,
};

enum ConnectionType {
OpenVPN,
OpenConnect,
VPNC,
L2TP,
PPTP,
};

explicit VpnModel(QObject *parent = 0);
virtual ~VpnModel();

Expand All @@ -93,7 +84,7 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel

Q_INVOKABLE QVariantMap connectionSettings(const QString &path);

Q_INVOKABLE QVariantMap processProvisioningFile(const QString &path, ConnectionType type);
Q_INVOKABLE QVariantMap processProvisioningFile(const QString &path, const QString &type);

VpnConnection *connection(const QString &path) const;

Expand Down Expand Up @@ -167,7 +158,7 @@ class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
Q_PROPERTY(bool automaticUpDown READ automaticUpDown WRITE setAutomaticUpDown NOTIFY automaticUpDownChanged)
Q_PROPERTY(bool storeCredentials READ storeCredentials WRITE setStoreCredentials NOTIFY storeCredentialsChanged)
Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(bool immutable READ immutable WRITE setImmutable NOTIFY immutableChanged)
Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged)
Q_PROPERTY(QVariantMap iPv4 READ iPv4 WRITE setIPv4 NOTIFY iPv4Changed)
Expand Down Expand Up @@ -203,8 +194,8 @@ class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
int state() const { return state_; }
void setState(int state) { updateMember(&VpnConnection::state_, state, &VpnConnection::stateChanged); }

int type() const { return type_; }
void setType(int type) { updateMember(&VpnConnection::type_, type, &VpnConnection::typeChanged); }
QString type() const { return type_; }
void setType(const QString &type) { updateMember(&VpnConnection::type_, type, &VpnConnection::typeChanged); }

bool immutable() const { return immutable_; }
void setImmutable(bool immutable) { updateMember(&VpnConnection::immutable_, immutable, &VpnConnection::immutableChanged); }
Expand Down Expand Up @@ -262,7 +253,7 @@ class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
QString path_;
QString name_;
int state_;
int type_;
QString type_;
QString host_;
QString domain_;
QString networks_;
Expand All @@ -279,6 +270,5 @@ class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
};

Q_DECLARE_METATYPE(VpnModel::ConnectionState)
Q_DECLARE_METATYPE(VpnModel::ConnectionType)

#endif

0 comments on commit d9a5317

Please sign in to comment.