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