542ec95b250ff1a1d1514b2db77a4171306c7b6a
[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 Q_PROPERTY (QString server READ getServer WRITE setServer NOTIFY serverChanged)
24 Q_PROPERTY (unsigned int port READ getPort WRITE setPort NOTIFY portChanged)
25 Q_PROPERTY (bool compressed READ getCompressed WRITE setCompressed NOTIFY compressedChanged)
26 Q_PROPERTY (bool useTLS READ getUseTLS WRITE setUseTLS NOTIFY useTLSChanged)
27 Q_PROPERTY (int tlsDirection READ getTlsDirection WRITE setTlsDirection NOTIFY tlsDirectionChanged)
28
29 private:
30 QProcess * vpnProcess;
31 VPNSTATUS vpnStatus;
32 QStringList arguments;
33
34 // Configuration options
35 QString server;
36 unsigned int port;
37 bool compressed;
38 bool useTLS;
39 int tlsDirection;
40
41 void collectArguments ();
42 void setStatus (VPNSTATUS newStatus);
43 void addArgument (QString key, QString value);
44 void addArgument (QString key);
45 void addOption (QString key, bool add);
46 void addValue (QString key);
47 void settingsSetValue (QString key, QString value);
48 void settingsSetValue (QString key, int value);
49
50 public:
51 explicit VPNControl(QObject *parent = 0);
52 void initialise();
53 QString getServer() const;
54 unsigned int getPort() const;
55 bool getCompressed() const;
56 bool getUseTLS() const;
57 int getTlsDirection() const;
58
59 signals:
60 void statusChanged(int status);
61 void serverChanged(QString server);
62 void portChanged(unsigned int port);
63 void compressedChanged(bool compressed);
64 void useTLSChanged(bool useTLS);
65 void tlsDirectionChanged (int direction);
66
67 public slots:
68 void vpnConnect ();
69 void vpnDisconnect ();
70 void readData ();
71 void started ();
72 void finished (int code);
73 void readError (QProcess::ProcessError error);
74 void updateConfiguration ();
75 void setServer(const QString &value);
76 void setPort(unsigned int value);
77 void setCompressed(bool value);
78 void setUseTLS(bool value);
79 void setTlsDirection(int value);
80 };
81
82 #endif // VPNCONTROL_H