1 //////////////////////////////////////////////////////////////////////
2 //
3 // BeeBEEP Copyright (C) 2010-2021 Marco Mastroddi
4 //
5 // BeeBEEP is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published
7 // by the Free Software Foundation, either version 3 of the License,
8 // or (at your option) any later version.
9 //
10 // BeeBEEP 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 BeeBEEP. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Author: Marco Mastroddi <marco.mastroddi(AT)gmail.com>
19 //
20 // $Id: GuiMain.h 1471 2021-01-06 12:10:07Z mastroddi $
21 //
22 //////////////////////////////////////////////////////////////////////
23 
24 #ifndef BEEBEEP_GUIMAIN_H
25 #define BEEBEEP_GUIMAIN_H
26 
27 
28 #include "Config.h"
29 #include "FileTransferPeer.h"
30 #ifdef BEEBEEP_USE_QXT
31  #include "qxtglobalshortcut.h"
32 #endif
33 class Chat;
34 class ChatMessage;
35 class Group;
36 class GuiChat;
37 class GuiChatList;
38 class GuiFileSharing;
39 class GuiFloatingChat;
40 class GuiGroupList;
41 class GuiHome;
42 class GuiLog;
43 class GuiNetworkTest;
44 class GuiSavedChat;
45 class GuiSavedChatList;
46 class GuiScreenShot;
47 class GuiSystemTray;
48 class GuiFileTransfer;
49 class GuiUserList;
50 class User;
51 #ifdef BEEBEEP_USE_SHAREDESKTOP
52   class GuiShareDesktop;
53 #endif
54 #ifdef BEEBEEP_USE_WEBENGINE
55   class GuiWebView;
56 #endif
57 
58 
59 class GuiMain : public QMainWindow
60 {
61   Q_OBJECT
62 
63 public:
64   GuiMain( QWidget* parent = Q_NULLPTR );
65 
66 public slots:
67   void loadSession();
68   void checkWindowFlagsAndShow();
69   void startCore();
70   void stopCore();
71   void restartCore();
72   void forceShutdown();
73   void hideToTrayIcon();
74   void setInIdle();
75   void exitFromIdle();
76   void showMessage( const QString&, int );
77   void showUp();
78   void raiseOnTop();
79   void onTickEvent( int );
80   void saveSession( QSessionManager& );
81   void onWakeUpRequest();
82   void onSleepRequest();
83   void disconnectFromNetwork();
84   void loadStyle();
85 
86 private slots:
87   void onCoreConnected();
88   void onCoreDisconnected();
89   void showAbout();
90   void showLicense();
91   void showAboutQt();
92   void onUserChanged( const User& );
93   void showWritingUser( const User&, VNumber );
94   void onUserRemoved( const User& );
95   void onNewChatMessage( const Chat&, const ChatMessage& );
96   void onChatChanged( const Chat& );
97   void onChatRemoved( const Chat& );
98   void sendMessage( VNumber, const QString& );
99   void showTipOfTheDay();
100   void showFaq();
101   void showFactOfTheDay();
102   void searchUsers();
103   void settingsChanged();
104   void settingsChanged( QAction* );
105   void showNextChat();
106   void statusSelected();
107   void changeStatusDescription();
108   void sendFileFromChat( VNumber, const QString& );
109   void sendFilesFromChat( VNumber, const QStringList& );
110   void sendFile( VNumber );
111   void sendFile( const QString& );
112   void downloadFolder( const User&, const QString&, const QList<FileInfo>& );
113   void downloadFile( const User&, const FileInfo& );
114   void downloadSharedFile( VNumber, VNumber );
115   void downloadSharedFiles( const QList<SharedFileInfo>& );
116   void selectDownloadDirectory();
117   void changeVCard();
118   void showVCard( VNumber );
119   void changeUserColor( VNumber, const QString& );
120   void showPluginHelp();
121   void showPluginManager();
122   void showChat( VNumber );
123   bool showWizard();
124   void trayIconClicked( QSystemTrayIcon::ActivationReason );
125   void trayMessageClicked();
126   void addToShare( const QString& );
127   void removeFromShare( const QString& );
128   void openUrl( const QUrl& );
129   void openUrlFromChat( const QUrl&, VNumber );
130   void selectBeepFile();
131   void testBeepFile();
132   void playBeep();
133   void playBuzz();
134   void editGroupChat( VNumber );
135   void createGroupChat();
136   void showSavedChatSelected( const QString& );
137   void removeSavedChat( const QString& );
138   void linkSavedChat( const QString& );
139   void checkNewVersion();
140   void openWebSite();
141   void openDownloadPluginPage();
142   void openDonationPage();
143   void openDeveloperWebSite();
144   void openHelpPage();
145   void clearChat( VNumber );
146   void clearSystemMessagesInChat( VNumber );
147   void removeChat( VNumber );
148   void showSharesForUser( const User& );
149   void selectLanguage();
150   void showLocalUserVCard();
151   void showAddUser();
152   void showChatSettingsMenu();
153   void sendBroadcastMessage();
154   void enableBroadcastAction();
155   void checkUserSelected( VNumber );
156   void showConnectionStatusChanged( const User& );
157   void changeAvatarSizeInList();
158   void toggleUserFavorite( VNumber );
159   void removeUserFromList( VNumber );
160   void openDataFolder();
161   void openResourceFolder();
162   void openDownloadFolder();
163   void readAllMessagesInChat( VNumber );
164   void recentlyUsedUserStatusSelected();
165   void clearRecentlyUsedUserStatus();
166   void loadSavedChatsCompleted();
167   void editShortcuts();
168   void minimizeAllChats();
169   void showAllChats();
170   void selectDictionatyPath();
171   void onNetworkInterfaceDown();
172   void onNetworkInterfaceUp();
173   void onChatReadByUser( const Chat&, const User& );
174   void askSaveGeometryAndState();
175   void askResetGeometryAndState();
176   void onChangeSettingOnExistingFile( QAction* );
177 #ifdef BEEBEEP_USE_SHAREDESKTOP
178   void onShareDesktopImageAvailable( const User&, const QImage&, const QString&, QRgb );
179   void onShareDesktopCloseEvent( VNumber );
180   void onShareDesktopDeleteRequest( VNumber );
181   void onShareDesktopRequestFromChat( VNumber, bool );
182   void onShareDesktopUpdate( const User& );
183   void sendScreenshotToChat( VNumber );
184 #endif
185   void startExternalApplicationFromActionData();
186   void onFileTransferProgress( VNumber, const User&, const FileInfo&, FileSizeType, qint64 );
187   void onFileTransferMessage( VNumber, const User&, const FileInfo&, const QString&, FileTransferPeer::TransferState );
188   void sendBuzzToUser( VNumber );
189   void showBuzzFromUser( const User& );
190   void removeFloatingChatFromList( VNumber );
191   void showFileSharingWindow();
192   void onFileSharingWindowClosed();
193   void showScreenShotWindow();
194   void onScreenShotWindowClosed();
195   void showLogWindow();
196   void onLogWindowClosed();
197   void onMainTabChanged( int );
198   void showWorkgroups();
199   void showRefusedChats();
200   void updateLocalStatusMessage();
201   void onStatusBarMessageChanged( const QString& );
202   void selectIconSourcePath();
203   void selectEmoticonSourcePath();
204   void onNewsAvailable( const QString& );
205   void showDefaultServerPortInMenu();
206   void createMessage();
207   void updateChatFont();
208   void updateChatColors();
209   void resetAllColors();
210   void onHideEmptyChatsRequest();
211   void updateUser( const User& );
212   void onApplicationFocusChanged( QWidget*, QWidget* );
213 #ifdef BEEBEEP_USE_WEBENGINE
214   void showWebView();
215   void onNewsLoad( bool );
216 #endif
217   void showNetworkTest();
218   void onNetworkTestWindowClosed();
219 #ifdef BEEBEEP_USE_VOICE_CHAT
220   void sendVoiceMessageToChat( VNumber, const QString&, qint64 );
221   void showVoiceEncoderSettings();
222 #endif
223   void resumeFileTransfer( VNumber user_id, const FileInfo& );
224 
225 protected:
226   void keyPressEvent( QKeyEvent* );
227   void closeEvent( QCloseEvent* );
228   void changeEvent( QEvent* );
229   bool promptConnectionPassword();
230   bool checkAllChatMembersAreConnected( const QList<VNumber>& );
231   void showAlertForMessage( const Chat&, const ChatMessage& );
232   GuiFloatingChat* createFloatingChat( const Chat& );
233   void setFileTransferEnabled( bool );
234   void setFileSharingEnabled( bool );
235   void saveGeometryAndState();
236   void restoreGeometryAndState();
237   void resetGeometryAndState();
238   void setMinimumWidthForStyle();
239 
240 private:
241   void setupChatConnections( GuiChat* );
242   void createActions();
243   void createMenus();
244   void createToolAndMenuBars();
245   void createMainWidgets();
246   void updateWindowTitle();
247   void initGuiItems();
248   void updadePluginMenu();
249   void updateStatusIcon();
250   void sendFile( const User& );
251   bool askToDownloadFile( const User&, const FileInfo&, const QString&, bool );
252   void checkAutoStartOnBoot( bool );
253   void checkViewActions();
254   bool sendFile( const User&, const QString&, VNumber chat_id );
255   bool openWebUrl( const QString& );
256   QStringList checkFilePath( const QString& );
257   bool isAudioDeviceAvailable() const;
258   GuiFloatingChat* floatingChat( VNumber ) const;
259   QWidget* activeWindow();
260   void setChatMessagesToShowInAction( QAction* );
261   void setMaxInactivityDaysInAction( QAction* );
262   void setChatInactiveWindowOpacityLevelInAction( QAction* );
263   void loadUserStatusRecentlyUsed();
264   void setUserStatusSelected( int );
265   void initShortcuts();
266   void updateShortcuts();
267   void updateEmoticons();
268   void updateNewMessageAction();
269   void updateTabTitles();
270   QString tabToolTip( int );
271   void showRestartConnectionAlertMessage();
272   void showRestartApplicationAlertMessage();
273   void showCheckSaveChatMessages();
274   void setChatMaxLinesToSaveInAction( QAction* );
275   void setClearCacheAfterDaysInAction( QAction* );
276   void setClearPartiallyDownloadedFilesAfterDaysInAction( QAction* );
277   void setMaxQueuedDownloadsInAction( QAction* );
278   bool isFileTransferInProgress();
279 
280 private:
281   QTabWidget* mp_tabMain;
282   GuiFileTransfer* mp_fileTransfer;
283   GuiUserList* mp_userList;
284   GuiChatList* mp_chatList;
285   GuiSavedChatList* mp_savedChatList;
286   GuiGroupList* mp_groupList;
287   GuiScreenShot* mp_screenShot;
288   GuiLog* mp_log;
289   QList<GuiFloatingChat*> m_floatingChats;
290   GuiFileSharing* mp_fileSharing;
291   GuiHome* mp_home;
292 #ifdef BEEBEEP_USE_SHAREDESKTOP
293   QList<GuiShareDesktop*> m_desktops;
294 #endif
295   QMenu* mp_menuMain;
296   QMenu* mp_menuInfo;
297   QMenu* mp_menuChat;
298   QMenu* mp_menuSettings;
299   QMenu* mp_menuStatus;
300   QMenu* mp_menuPlugins;
301   QMenu* mp_menuTrayIcon;
302   QMenu* mp_menuUserList;
303   QMenu* mp_menuUserStatusList;
304   QMenu* mp_menuInterfaceSettings;
305   QMenu* mp_menuStartupSettings;
306   QMenu* mp_menuCloseSettings;
307   QMenu* mp_menuUsersSettings;
308   QMenu* mp_menuChatSettings;
309   QMenu* mp_menuFileTransferSettings;
310   QMenu* mp_menuNotificationSettings;
311   QMenu* mp_menuTrayIconSettings;
312   QMenu* mp_menuExistingFile;
313   QMenu* mp_menuConnectionSettings;
314   QMenu* mp_menuChatColorSettings;
315   QMenu* mp_menuChatSaveSettings;
316 
317   QToolBar* mp_barMain;
318 
319   QAction* mp_actConnect;
320   QAction* mp_actDisconnect;
321   QAction* mp_actConfigureNetwork;
322   QAction* mp_actBroadcast;
323   QAction* mp_actQuit;
324   QAction* mp_actVCard;
325   QAction* mp_actMainToolBar;
326   QAction* mp_actAbout;
327   QAction* mp_actViewFileTransfer;
328   QAction* mp_actViewNewMessage;
329   QAction* mp_actPromptPassword;
330   QAction* mp_actConfirmDownload;
331   QAction* mp_actViewFileSharing;
332   QAction* mp_actViewScreenShot;
333   QAction* mp_actViewLog;
334   QAction* mp_actAddUsers;
335   QAction* mp_actCreateGroupChat;
336   QAction* mp_actEnableFileSharing;
337   QAction* mp_actSelectDownloadFolder;
338   QAction* mp_actSaveWindowGeometry;
339   QActionGroup* mp_actGroupExistingFile;
340   QAction* mp_actResumeFileTransfer;
341   QAction* mp_actBeepOnNewMessage;
342   QActionGroup* mp_actGroupRecognizeUsers;
343   QAction* mp_actSelectEmoticonSourcePath;
344   QAction* mp_actRemoveInactiveUsers;
345   QAction* mp_actChangeStatusDescription;
346   QAction* mp_actCreateMessage;
347   QAction* mp_actSaveUserList;
348   QAction* mp_actSaveGroupList;
349   QAction* mp_actSaveFileTransferMessages;
350   QAction* mp_actSaveSystemMessages;
351   QAction* mp_actSetAutoAway;
352   QAction* mp_actEditWorkgroups;
353   QAction* mp_actEditAvatarIconSize;
354   QAction* mp_actShowOnlineUsersOnly;
355   QAction* mp_actShowUserFullName;
356   QAction* mp_actShowUserFirstNameFirstInFullName;
357   QActionGroup* mp_actGroupOnSendingMessage;
358 
359   QMenu* mp_menuNetworkStatus;
360   QAction* mp_actHostAddress;
361   QAction* mp_actPortBroadcast;
362   QAction* mp_actPortListener;
363   QAction* mp_actPortFileTransfer;
364 #ifdef BEEBEEP_USE_MULTICAST_DNS
365   QAction* mp_actMulticastDns;
366 #endif
367   QAction* mp_actMulticastGroupAddress;
368   QAction* mp_actEncryptedConnectionByDefault;
369   QAction* mp_actCompressedDataByDefault;
370 
371   QDockWidget* mp_dockFileTransfers;
372 
373   GuiSystemTray* mp_trayIcon;
374   int m_lastUserStatus;
375 
376   bool m_forceShutdown;
377   bool m_autoConnectOnInterfaceUp;
378 
379   QShortcut* mp_scMinimizeAllChats;
380   QShortcut* mp_scShowNextUnreadMessage;
381 #ifdef BEEBEEP_USE_QXT
382   QxtGlobalShortcut* mp_scShowAllChats;
383 #endif
384   QWidget* mp_lastActiveWindow;
385 
386   bool m_prevActivatedState;
387   int m_unreadActivities;
388   bool m_coreIsConnecting;
389   bool m_changeTabToUserListOnFirstConnected;
390 
391 #ifdef BEEBEEP_USE_WEBENGINE
392   GuiWebView* mp_webView;
393   QAction* mp_actWebView;
394 #endif
395 
396   GuiNetworkTest* mp_networkTest;
397 
398 #ifdef BEEBEEP_USE_VOICE_CHAT
399   QMenu* mp_menuVoiceMessage;
400 #endif
401 
402   bool m_useFusionStyle;
403 };
404 
405 #endif // BEEBEEP_GUIMAIN_H
406