1 /*
2  * barrier -- mouse and keyboard sharing utility
3  * Copyright (C) 2012-2016 Symless Ltd.
4  * Copyright (C) 2008 Volker Lanz (vl@fidra.de)
5  *
6  * This package is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * found in the file LICENSE that should have accompanied this file.
9  *
10  * This package is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #if !defined(MAINWINDOW__H)
20 
21 #define MAINWINDOW__H
22 
23 #include <QMainWindow>
24 #include <QSystemTrayIcon>
25 #include <QSettings>
26 #include <QProcess>
27 #include <QThread>
28 
29 #include "ui_MainWindowBase.h"
30 
31 #include "ServerConfig.h"
32 #include "AppConfig.h"
33 #include "VersionChecker.h"
34 #include "IpcClient.h"
35 #include "Ipc.h"
36 #include "LogWindow.h"
37 
38 #include <QMutex>
39 
40 class QAction;
41 class QMenu;
42 class QLineEdit;
43 class QGroupBox;
44 class QPushButton;
45 class QTextEdit;
46 class QComboBox;
47 class QTabWidget;
48 class QCheckBox;
49 class QRadioButton;
50 class QTemporaryFile;
51 class QMessageBox;
52 class QAbstractButton;
53 
54 class LogDialog;
55 class QBarrierApplication;
56 class SetupWizard;
57 class ZeroconfService;
58 class DataDownloader;
59 class CommandProcess;
60 class SslCertificate;
61 
62 class MainWindow : public QMainWindow, public Ui::MainWindowBase
63 {
64     Q_OBJECT
65 
66     friend class QBarrierApplication;
67     friend class SetupWizard;
68     friend class SettingsDialog;
69 
70     public:
71         enum qBarrierState
72         {
73             barrierDisconnected,
74             barrierConnecting,
75             barrierConnected,
76             barrierTransfering
77         };
78 
79         enum qBarrierType
80         {
81             barrierClient,
82             barrierServer
83         };
84 
85         enum qLevel {
86             Error,
87             Info
88         };
89 
90         enum qRuningState {
91             kStarted,
92             kStopped
93         };
94 
95     public:
96         MainWindow(QSettings& settings, AppConfig& appConfig);
97         ~MainWindow();
98 
99     public:
100         void setVisible(bool visible);
barrierType()101         int barrierType() const { return m_pGroupClient->isChecked() ? barrierClient : barrierServer; }
barrierState()102         int barrierState() const { return m_BarrierState; }
hostname()103         QString hostname() const { return m_pLineEditHostname->text(); }
104         QString configFilename();
105         QString address();
106         QString appPath(const QString& name);
107         void open();
versionChecker()108         VersionChecker& versionChecker() { return m_VersionChecker; }
109         QString getScreenName();
serverConfig()110         ServerConfig& serverConfig() { return m_ServerConfig; }
111         void showConfigureServer(const QString& message);
showConfigureServer()112         void showConfigureServer() { showConfigureServer(""); }
113         void autoAddScreen(const QString name);
114         void updateZeroconfService();
115         void serverDetected(const QString name);
116 
117 public slots:
118         void appendLogRaw(const QString& text);
119         void appendLogInfo(const QString& text);
120         void appendLogDebug(const QString& text);
121         void appendLogError(const QString& text);
122         void startBarrier();
123 
124     protected slots:
125         void on_m_pGroupClient_toggled(bool on);
126         void on_m_pGroupServer_toggled(bool on);
127         bool on_m_pButtonBrowseConfigFile_clicked();
128         void on_m_pButtonConfigureServer_clicked();
129         bool on_m_pActionSave_triggered();
130         void on_m_pActionAbout_triggered();
131         void on_m_pActionSettings_triggered();
132         void barrierFinished(int exitCode, QProcess::ExitStatus);
133         void trayActivated(QSystemTrayIcon::ActivationReason reason);
134         void stopBarrier();
135         void logOutput();
136         void logError();
137         void bonjourInstallFinished();
138         void showLogWindow();
139 
140     protected:
settings()141         QSettings& settings() { return m_Settings; }
appConfig()142         AppConfig& appConfig() { return *m_AppConfig; }
barrierProcess()143         QProcess* barrierProcess() { return m_pBarrier; }
setBarrierProcess(QProcess * p)144         void setBarrierProcess(QProcess* p) { m_pBarrier = p; }
145         void initConnections();
146         void createMenuBar();
147         void createTrayIcon();
148         void loadSettings();
149         void saveSettings();
150         void setIcon(qBarrierState state);
151         void setBarrierState(qBarrierState state);
152         bool clientArgs(QStringList& args, QString& app);
153         bool serverArgs(QStringList& args, QString& app);
154         void setStatus(const QString& status);
155         void updateFromLogLine(const QString& line);
156         QString getIPAddresses();
157         void stopService();
158         void stopDesktop();
159         void changeEvent(QEvent* event);
160         void retranslateMenuBar();
161 #if defined(Q_OS_WIN)
162         bool isServiceRunning(QString name);
163 #else
164         bool isServiceRunning();
165 #endif
166         bool isBonjourRunning();
167         void downloadBonjour();
168         void promptAutoConfig();
169         void checkConnected(const QString& line);
170         void checkFingerprint(const QString& line);
171         void restartBarrier();
172         void proofreadInfo();
173         void windowStateChanged();
174         void updateSSLFingerprint();
175 
176     private:
177         QSettings& m_Settings;
178         AppConfig* m_AppConfig;
179         QProcess* m_pBarrier;
180         int m_BarrierState;
181         ServerConfig m_ServerConfig;
182         QTemporaryFile* m_pTempConfigFile;
183         QSystemTrayIcon* m_pTrayIcon;
184         QMenu* m_pTrayIconMenu;
185         bool m_AlreadyHidden;
186         VersionChecker m_VersionChecker;
187         IpcClient m_IpcClient;
188         QMenuBar* m_pMenuBar;
189         QMenu* m_pMenuBarrier;
190         QMenu* m_pMenuHelp;
191         ZeroconfService* m_pZeroconfService;
192         DataDownloader* m_pDataDownloader;
193         QMessageBox* m_DownloadMessageBox;
194         QAbstractButton* m_pCancelButton;
195         QMutex m_UpdateZeroconfMutex;
196         bool m_SuppressAutoConfigWarning;
197         CommandProcess* m_BonjourInstall;
198         bool m_SuppressEmptyServerWarning;
199         qRuningState m_ExpectedRunningState;
200         QMutex m_StopDesktopMutex;
201         SslCertificate* m_pSslCertificate;
202         QStringList m_PendingClientNames;
203         LogWindow *m_pLogWindow;
204 
205 private slots:
206     void on_m_pCheckBoxAutoConfig_toggled(bool checked);
207     void on_m_pComboServerList_currentIndexChanged(QString );
208     void on_m_pButtonReload_clicked();
209     void installBonjour();
210 
211 };
212 
213 #endif
214 
215