blob: d0635bb6b043245a8fd94091bfa653c25755f672 [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Davide Pesavento7676b562020-12-14 00:41:26 -05003 * Copyright (c) 2020, Regents of the University of California
Yingdi Yu348f5ea2014-03-01 14:47:25 -08004 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
Yingdi Yuf3401182015-02-02 20:21:07 -08009 * Qiuhan Ding <qiuhanding@cs.ucla.edu>
Yingdi Yu348f5ea2014-03-01 14:47:25 -080010 */
11
Yingdi Yueb692ac2015-02-10 18:46:18 -080012#ifndef CHRONOCHAT_CONTROLLER_HPP
13#define CHRONOCHAT_CONTROLLER_HPP
Yingdi Yu348f5ea2014-03-01 14:47:25 -080014
15#include <QDialog>
16#include <QMenu>
17#include <QSystemTrayIcon>
18#include <QtSql/QSqlDatabase>
19
Yingdi Yu0b0a7362014-08-05 16:31:30 -070020#include "setting-dialog.hpp"
21#include "start-chat-dialog.hpp"
22#include "profile-editor.hpp"
23#include "invitation-dialog.hpp"
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080024#include "invitation-request-dialog.hpp"
Yingdi Yu0b0a7362014-08-05 16:31:30 -070025#include "contact-panel.hpp"
26#include "browse-contact-dialog.hpp"
27#include "add-contact-panel.hpp"
28#include "chat-dialog.hpp"
Qiuhan Ding43c8e162015-02-02 15:16:48 -080029#include "chatroom-discovery-backend.hpp"
30#include "discovery-panel.hpp"
Yingdi Yuf3401182015-02-02 20:21:07 -080031#include "nfd-connection-checker.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080032
33#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070034#include "common.hpp"
Yingdi Yu2c9e7712014-10-20 11:55:05 -070035#include "invitation.hpp"
36#include "controller-backend.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080037#endif
38
Yingdi Yueb692ac2015-02-10 18:46:18 -080039namespace chronochat {
Yingdi Yu348f5ea2014-03-01 14:47:25 -080040
41class Controller : public QDialog
42{
43 Q_OBJECT
44
45public: // public methods
Yingdi Yuf3401182015-02-02 20:21:07 -080046 Controller(QWidget* parent = nullptr);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070047
Yingdi Yu348f5ea2014-03-01 14:47:25 -080048 virtual
49 ~Controller();
50
51private: // private methods
52 std::string
53 getDBName();
54
55 void
56 openDB();
57
58 void
59 initialize();
60
61 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080062 loadConf();
63
64 void
65 saveConf();
66
Yingdi Yufa0b6a02014-04-30 14:26:42 -070067 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080068 createActions();
69
70 void
71 createTrayIcon();
72
73 void
74 updateMenu();
75
Yingdi Yu348f5ea2014-03-01 14:47:25 -080076 void
77 addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
78
Mengjin Yan391d7242014-08-28 20:51:55 -070079 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080080 updateDiscoveryList(const chronochat::ChatroomInfo& chatroomName, bool isAdd);
Mengjin Yan391d7242014-08-28 20:51:55 -070081
Yingdi Yu348f5ea2014-03-01 14:47:25 -080082signals:
83 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070084 shutdownBackend();
85
86 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -080087 shutdownDiscoveryBackend();
88
89 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070090 updateLocalPrefix();
91
92 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080093 closeDBModule();
94
95 void
96 localPrefixUpdated(const QString& localPrefix);
97
98 void
Yingdi Yubaaaec02014-09-02 22:05:32 -070099 localPrefixConfigured(const QString& prefix);
100
101 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800102 identityUpdated(const QString& identity);
103
104 void
105 refreshBrowseContact();
106
Yingdi Yu233a9722014-03-07 15:47:09 -0800107 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700108 invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
109 size_t routingPrefixOffset);
110
111 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800112 discoverChatroomChanged(const chronochat::ChatroomInfo& chatroomInfo, bool isAdd);
Yingdi Yu233a9722014-03-07 15:47:09 -0800113
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700114 void
115 addChatroom(QString chatroomName);
116
117 void
118 removeChatroom(QString chatroomName);
119
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800120 void
Yingdi Yuf3401182015-02-02 20:21:07 -0800121 respondChatroomInfoRequest(ChatroomInfo chatroomInfo, bool isManager);
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800122
123 void
Yingdi Yuf3401182015-02-02 20:21:07 -0800124 nfdReconnect();
125
126 void
127 shutdownNfdChecker();
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800128
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800129private slots:
130 void
131 onIdentityUpdated(const QString& identity);
132
133 void
134 onIdentityUpdatedContinued();
135
136 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800137 onNickUpdated(const QString& nick);
138
139 void
140 onLocalPrefixUpdated(const QString& localPrefix);
141
142 void
Yingdi Yubaaaec02014-09-02 22:05:32 -0700143 onLocalPrefixConfigured(const QString& prefix);
144
145 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800146 onStartChatAction();
147
148 void
149 onSettingsAction();
150
151 void
152 onProfileEditorAction();
153
154 void
155 onAddContactAction();
156
157 void
158 onContactListAction();
159
160 void
161 onDirectAdd();
162
163 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800164 onMinimizeAction();
165
166 void
167 onQuitAction();
168
169 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800170 onChatroomDiscoveryAction();
171
172 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800173 onStartChatroom(const QString& chatroom, bool secured);
174
175 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800176 onStartChatroom2(chronochat::Invitation invitation, bool secured);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800177
178 void
179 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700180
Yingdi Yu233a9722014-03-07 15:47:09 -0800181 void
182 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800183
184 void
185 onRemoveChatDialog(const QString& chatroom);
186
187 void
188 onWarning(const QString& msg);
189
190 void
Yingdi Yuf3401182015-02-02 20:21:07 -0800191 onNfdError();
192
193 void
194 onNfdReconnect();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800195
Yingdi Yu233a9722014-03-07 15:47:09 -0800196 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800197 onChatroomInfoRequest(std::string chatroomName, bool isManager);
Mengjin Yan391d7242014-08-28 20:51:55 -0700198
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800199private: // private member
200 typedef std::map<std::string, QAction*> ChatActionList;
201 typedef std::map<std::string, ChatDialog*> ChatDialogList;
202
203 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700204 Name m_localPrefix;
Yingdi Yubaaaec02014-09-02 22:05:32 -0700205 bool m_localPrefixDetected;
Yingdi Yuf3401182015-02-02 20:21:07 -0800206 bool m_isInConnectionDetection;
Mengjin Yan391d7242014-08-28 20:51:55 -0700207
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800208 // Tray
209 QAction* m_startChatroom;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800210 //QAction* m_discoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800211 QAction* m_minimizeAction;
212 QAction* m_settingsAction;
213 QAction* m_editProfileAction;
214 QAction* m_contactListAction;
215 QAction* m_addContactAction;
216 QAction* m_updateLocalPrefixAction;
217 QAction* m_quitAction;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800218 QAction* m_chatroomDiscoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800219 QMenu* m_trayIconMenu;
220 QMenu* m_closeMenu;
221 QSystemTrayIcon* m_trayIcon;
222 ChatActionList m_chatActionList;
223 ChatActionList m_closeActionList;
224
225 // Dialogs
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800226 SettingDialog* m_settingDialog;
227 StartChatDialog* m_startChatDialog;
228 ProfileEditor* m_profileEditor;
229 InvitationDialog* m_invitationDialog;
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800230 InvitationRequestDialog* m_invitationRequestDialog;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800231 ContactPanel* m_contactPanel;
232 BrowseContactDialog* m_browseContactDialog;
233 AddContactPanel* m_addContactPanel;
234 ChatDialogList m_chatDialogList;
235 DiscoveryPanel* m_discoveryPanel;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800236
237 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700238 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800239 std::string m_nick;
240 QSqlDatabase m_db;
241
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700242 // Backend
Yingdi Yuf3401182015-02-02 20:21:07 -0800243 ControllerBackend m_backend;
244 ChatroomDiscoveryBackend* m_chatroomDiscoveryBackend;
245 NfdConnectionChecker* m_nfdConnectionChecker;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800246};
247
Yingdi Yueb692ac2015-02-10 18:46:18 -0800248} // namespace chronochat
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800249
Yingdi Yueb692ac2015-02-10 18:46:18 -0800250#endif // CHRONOCHAT_CONTROLLER_HPP