File: ConnectionManager.h

package info (click to toggle)
l2tp-ipsec-vpn 1.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,396 kB
  • sloc: cpp: 9,952; xml: 400; makefile: 139; sh: 78
file content (111 lines) | stat: -rw-r--r-- 3,641 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * $Id: ConnectionManager.h 115 2012-01-24 23:58:29Z werner $
 *
 * File:   ConnectionManager.h
 * Author: Werner Jaeger
 *
 * Created on July 7, 2010, 5:44 PM
 *
 * Copyright 2010 Werner Jaeger.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _CONNECTIONMANAGER_H
#define	_CONNECTIONMANAGER_H

#include <QObject>
#include <QSystemTrayIcon>
#include <QPair>

#include "util/NetworkInterface.h"

class QSystemTrayIcon;
class ConnectionState;
class VPNControlTask;
class ConnectionInformationDialog;
class QAction;
class QTimer;
class L2tpIPsecVpnApplication;

class ConnectionManager : public QObject
{
   Q_OBJECT

public:
   explicit ConnectionManager(L2tpIPsecVpnApplication& application, QObject* pParent = 0);
   virtual ~ConnectionManager();

   int exec();

private slots:
   void vpnConnect(QAction* pAction);
   void vpnDisconnect(bool fDontChangeStatus = false);
   void editConnections() const;
   void showConnectionInformation() const;
   void about() const;
   void iconActivated(QSystemTrayIcon::ActivationReason reason);
   void showMessage();
   void messageClicked();
   void detectConnectionState();
   void onVpnTaskOutput(const QString& strOutputLine);
   void onVpnTaskReadyReadLog();
   void onVpnTaskErrorMsg(int iErrorCode);
   void onVpnTaskTimeout();
   void onVpnTaskFinished();
   void onConnectionAdded(const QString& strName);
   void onConnectionRemoved(const QString& strName);
   void onRouteAdded(NetworkInterface interface, unsigned int iPriority);
   void onRouteDeleted(NetworkInterface interface, unsigned int iPriority);
   void onPtpInterfaceIsUpAnRunning(NetworkInterface interface);
   void onPtpInterfaceIsGoingDown(NetworkInterface interface);
   void onCheckPtpInterfaceIsUp();
   void onCheckPtpInterfaceIsDown();

private:
   typedef QList<QAction*> ActionList;
   typedef QPair<const QString, const NetworkInterface> ConnectionInfo;
   typedef enum { DISC, EDIT, INFO, ABOUT, QUIT } ActionType;

   ConnectionManager(const ConnectionManager& orig);
   ConnectionManager& operator=(const ConnectionManager& orig);

   void createActions();
   void createTrayIcon();
   void updateContextMenu(bool fStatusChanged);
   void vpnConnect(const QString& strConnectionName);
   void enableAllConnections(bool fEnable) const;
   void connected(const QString& strConnectionName, const NetworkInterface& ptpInterface);
   void disConnected();
   void error(int iErrorCode);
   ConnectionInfo connectionNameOfUpAndRunningPtpInterface() const;

   QAction* action(ActionType type) const;

   static QString connectionName(const NetworkInterface& interface, int iRetry = 1);

   ConnectionInformationDialog* const m_pConnectionInformation;
   QTimer* const m_pTimeout;
   ActionList* const m_pActions;
   L2tpIPsecVpnApplication& m_Application;

   ConnectionState* m_pState;
   QSystemTrayIcon* m_pTrayIcon;
   QMenu* m_pTrayIconMenu;
   VPNControlTask* m_pVPNControlTask;
   volatile bool m_fIsExecuting;
   volatile bool m_fRoutePriorityIsChanging;
};

#endif	/* _CONNECTIONMANAGER_H */