Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame] | 3 | * Copyright (c) 2020, Regents of the University of California |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 9 | * Qiuhan Ding <qiuhanding@cs.ucla.edu> |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 12 | #ifndef CHRONOCHAT_CONTROLLER_HPP |
| 13 | #define CHRONOCHAT_CONTROLLER_HPP |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 14 | |
| 15 | #include <QDialog> |
| 16 | #include <QMenu> |
| 17 | #include <QSystemTrayIcon> |
| 18 | #include <QtSql/QSqlDatabase> |
| 19 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 20 | #include "setting-dialog.hpp" |
| 21 | #include "start-chat-dialog.hpp" |
| 22 | #include "profile-editor.hpp" |
| 23 | #include "invitation-dialog.hpp" |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 24 | #include "invitation-request-dialog.hpp" |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 25 | #include "contact-panel.hpp" |
| 26 | #include "browse-contact-dialog.hpp" |
| 27 | #include "add-contact-panel.hpp" |
| 28 | #include "chat-dialog.hpp" |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 29 | #include "chatroom-discovery-backend.hpp" |
| 30 | #include "discovery-panel.hpp" |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 31 | #include "nfd-connection-checker.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 32 | |
| 33 | #ifndef Q_MOC_RUN |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 34 | #include "common.hpp" |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 35 | #include "invitation.hpp" |
| 36 | #include "controller-backend.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 37 | #endif |
| 38 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 39 | namespace chronochat { |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 40 | |
| 41 | class Controller : public QDialog |
| 42 | { |
| 43 | Q_OBJECT |
| 44 | |
| 45 | public: // public methods |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 46 | Controller(QWidget* parent = nullptr); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 47 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 48 | virtual |
| 49 | ~Controller(); |
| 50 | |
| 51 | private: // private methods |
| 52 | std::string |
| 53 | getDBName(); |
| 54 | |
| 55 | void |
| 56 | openDB(); |
| 57 | |
| 58 | void |
| 59 | initialize(); |
| 60 | |
| 61 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 62 | loadConf(); |
| 63 | |
| 64 | void |
| 65 | saveConf(); |
| 66 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 67 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 68 | createActions(); |
| 69 | |
| 70 | void |
| 71 | createTrayIcon(); |
| 72 | |
| 73 | void |
| 74 | updateMenu(); |
| 75 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 76 | void |
| 77 | addChatDialog(const QString& chatroomName, ChatDialog* chatDialog); |
| 78 | |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 79 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 80 | updateDiscoveryList(const chronochat::ChatroomInfo& chatroomName, bool isAdd); |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 81 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 82 | signals: |
| 83 | void |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 84 | shutdownBackend(); |
| 85 | |
| 86 | void |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 87 | shutdownDiscoveryBackend(); |
| 88 | |
| 89 | void |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 90 | updateLocalPrefix(); |
| 91 | |
| 92 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 93 | closeDBModule(); |
| 94 | |
| 95 | void |
| 96 | localPrefixUpdated(const QString& localPrefix); |
| 97 | |
| 98 | void |
Yingdi Yu | baaaec0 | 2014-09-02 22:05:32 -0700 | [diff] [blame] | 99 | localPrefixConfigured(const QString& prefix); |
| 100 | |
| 101 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 102 | identityUpdated(const QString& identity); |
| 103 | |
| 104 | void |
| 105 | refreshBrowseContact(); |
| 106 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 107 | void |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 108 | invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 109 | size_t routingPrefixOffset); |
| 110 | |
| 111 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 112 | discoverChatroomChanged(const chronochat::ChatroomInfo& chatroomInfo, bool isAdd); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 113 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 114 | void |
| 115 | addChatroom(QString chatroomName); |
| 116 | |
| 117 | void |
| 118 | removeChatroom(QString chatroomName); |
| 119 | |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 120 | void |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 121 | respondChatroomInfoRequest(ChatroomInfo chatroomInfo, bool isManager); |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 122 | |
| 123 | void |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 124 | nfdReconnect(); |
| 125 | |
| 126 | void |
| 127 | shutdownNfdChecker(); |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 128 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 129 | private slots: |
| 130 | void |
| 131 | onIdentityUpdated(const QString& identity); |
| 132 | |
| 133 | void |
| 134 | onIdentityUpdatedContinued(); |
| 135 | |
| 136 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 137 | onNickUpdated(const QString& nick); |
| 138 | |
| 139 | void |
| 140 | onLocalPrefixUpdated(const QString& localPrefix); |
| 141 | |
| 142 | void |
Yingdi Yu | baaaec0 | 2014-09-02 22:05:32 -0700 | [diff] [blame] | 143 | onLocalPrefixConfigured(const QString& prefix); |
| 144 | |
| 145 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 146 | 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 Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 164 | onMinimizeAction(); |
| 165 | |
| 166 | void |
| 167 | onQuitAction(); |
| 168 | |
| 169 | void |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 170 | onChatroomDiscoveryAction(); |
| 171 | |
| 172 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 173 | onStartChatroom(const QString& chatroom, bool secured); |
| 174 | |
| 175 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 176 | onStartChatroom2(chronochat::Invitation invitation, bool secured); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 177 | |
| 178 | void |
| 179 | onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 180 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 181 | void |
| 182 | onResetIcon(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 183 | |
| 184 | void |
| 185 | onRemoveChatDialog(const QString& chatroom); |
| 186 | |
| 187 | void |
| 188 | onWarning(const QString& msg); |
| 189 | |
| 190 | void |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 191 | onNfdError(); |
| 192 | |
| 193 | void |
| 194 | onNfdReconnect(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 195 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 196 | void |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 197 | onChatroomInfoRequest(std::string chatroomName, bool isManager); |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 198 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 199 | private: // private member |
| 200 | typedef std::map<std::string, QAction*> ChatActionList; |
| 201 | typedef std::map<std::string, ChatDialog*> ChatDialogList; |
| 202 | |
| 203 | // Communication |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 204 | Name m_localPrefix; |
Yingdi Yu | baaaec0 | 2014-09-02 22:05:32 -0700 | [diff] [blame] | 205 | bool m_localPrefixDetected; |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 206 | bool m_isInConnectionDetection; |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 207 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 208 | // Tray |
| 209 | QAction* m_startChatroom; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 210 | //QAction* m_discoveryAction; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 211 | 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 Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 218 | QAction* m_chatroomDiscoveryAction; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 219 | QMenu* m_trayIconMenu; |
| 220 | QMenu* m_closeMenu; |
| 221 | QSystemTrayIcon* m_trayIcon; |
| 222 | ChatActionList m_chatActionList; |
| 223 | ChatActionList m_closeActionList; |
| 224 | |
| 225 | // Dialogs |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 226 | SettingDialog* m_settingDialog; |
| 227 | StartChatDialog* m_startChatDialog; |
| 228 | ProfileEditor* m_profileEditor; |
| 229 | InvitationDialog* m_invitationDialog; |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 230 | InvitationRequestDialog* m_invitationRequestDialog; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 231 | ContactPanel* m_contactPanel; |
| 232 | BrowseContactDialog* m_browseContactDialog; |
| 233 | AddContactPanel* m_addContactPanel; |
| 234 | ChatDialogList m_chatDialogList; |
| 235 | DiscoveryPanel* m_discoveryPanel; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 236 | |
| 237 | // Conf |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 238 | Name m_identity; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 239 | std::string m_nick; |
| 240 | QSqlDatabase m_db; |
| 241 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 242 | // Backend |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame] | 243 | ControllerBackend m_backend; |
| 244 | ChatroomDiscoveryBackend* m_chatroomDiscoveryBackend; |
| 245 | NfdConnectionChecker* m_nfdConnectionChecker; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 248 | } // namespace chronochat |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 249 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 250 | #endif // CHRONOCHAT_CONTROLLER_HPP |