Added configurable path to extra configuration file.
[openvpnui.git] / src / vpncontrol.h
1 #ifndef VPNCONTROL_H
2 #define VPNCONTROL_H
3
4 #include <QObject>
5 #include <QProcess>
6
7 enum VPNSTATUS {
8 VPNSTATUS_INVALID = -1,
9
10 VPNSTATUS_UNINITIALISED,
11 VPNSTATUS_INITIALISING,
12 VPNSTATUS_CONNECTING,
13 VPNSTATUS_CONNECTED,
14 VPNSTATUS_DISCONNECTING,
15
16 VPNSTATUS_NUM
17 };
18
19 class VPNControl : public QObject
20 {
21 Q_OBJECT
22
23 // General properties
24 Q_PROPERTY (QString logText READ getLogText WRITE setLogText NOTIFY logTextChanged)
25
26 // Configuration properties
27 Q_PROPERTY (QString server READ getServer WRITE setServer NOTIFY serverChanged)
28 Q_PROPERTY (unsigned int port READ getPort WRITE setPort NOTIFY portChanged)
29 Q_PROPERTY (bool compressed READ getCompressed WRITE setCompressed NOTIFY compressedChanged)
30 Q_PROPERTY (bool useTLS READ getUseTLS WRITE setUseTLS NOTIFY useTLSChanged)
31 Q_PROPERTY (int tlsDirection READ getTlsDirection WRITE setTlsDirection NOTIFY tlsDirectionChanged)
32 Q_PROPERTY (QString caCertFile READ getCaCertFile WRITE setCaCertFile NOTIFY caCertFileChanged)
33 Q_PROPERTY (QString clientCertFile READ getClientCertFile WRITE setClientCertFile NOTIFY clientCertFileChanged)
34 Q_PROPERTY (QString clientKeyFile READ getClientKeyFile WRITE setClientKeyFile NOTIFY clientKeyFileChanged)
35 Q_PROPERTY (QString tlsKeyFile READ getTlsKeyFile WRITE setTlsKeyFile NOTIFY tlsKeyFileChanged)
36 Q_PROPERTY (QString configFile READ getConfigFile WRITE setConfigFile NOTIFY configFileChanged)
37
38 private:
39 // General variables
40 QProcess * vpnProcess;
41 VPNSTATUS vpnStatus;
42 QStringList arguments;
43 QString logText;
44
45 // Configuration options
46 QString server;
47 unsigned int port;
48 bool compressed;
49 bool useTLS;
50 int tlsDirection;
51 QString caCertFile;
52 QString clientCertFile;
53 QString clientKeyFile;
54 QString tlsKeyFile;
55 QString configFile;
56
57 // Internal methods
58 void collectArguments ();
59 void setStatus (VPNSTATUS newStatus);
60 void addArgument (QString key, QString value);
61 void addArgument (QString key);
62 void addArgumentNonempty (QString key, QString value);
63 void addOption (QString key, bool add);
64 void addValue (QString key);
65 void settingsSetValue (QString key, QString value);
66 void settingsSetValue (QString key, int value);
67
68 public:
69 // General methods
70 explicit VPNControl(QObject *parent = 0);
71 void initialise();
72 QString getLogText() const;
73
74 // Configuration retreival methods
75 QString getServer() const;
76 unsigned int getPort() const;
77 bool getCompressed() const;
78 bool getUseTLS() const;
79 int getTlsDirection() const;
80 QString getCaCertFile () const;
81 QString getClientCertFile () const;
82 QString getClientKeyFile () const;
83 QString getTlsKeyFile () const;
84 QString getConfigFile () const;
85
86 signals:
87 // General signals
88 void statusChanged(int status);
89 void logTextChanged (QString &logText);
90
91 // Configuration change signals
92 void serverChanged(QString &server);
93 void portChanged(unsigned int port);
94 void compressedChanged(bool compressed);
95 void useTLSChanged(bool useTLS);
96 void tlsDirectionChanged(int direction);
97 void caCertFileChanged(QString &caCertFile);
98 void clientCertFileChanged(QString &clientCertFile);
99 void clientKeyFileChanged(QString &clientKeyFile);
100 void tlsKeyFileChanged(QString &tlsKeyFile);
101 void configFileChanged(QString &configFile);
102
103 public slots:
104 // General methods
105 void vpnConnect ();
106 void vpnDisconnect ();
107 void readData ();
108 void started ();
109 void finished (int code);
110 void readError (QProcess::ProcessError error);
111 void updateConfiguration ();
112 void setLogText(const QString &value);
113 void logAppend(const QString &text);
114
115 // Configuration setting
116 void setServer(const QString &value);
117 void setPort(unsigned int value);
118 void setCompressed(bool value);
119 void setUseTLS(bool value);
120 void setTlsDirection(int value);
121 void setCaCertFile(const QString &value);
122 void setClientCertFile(const QString &value);
123 void setClientKeyFile(const QString &value);
124 void setTlsKeyFile(const QString &value);
125 void setConfigFile(const QString &value);
126 };
127
128 #endif // VPNCONTROL_H