Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 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 | std::string |
| 77 | getRandomString(); |
| 78 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 79 | void |
| 80 | addChatDialog(const QString& chatroomName, ChatDialog* chatDialog); |
| 81 | |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 82 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 83 | updateDiscoveryList(const chronochat::ChatroomInfo& chatroomName, bool isAdd); |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 84 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 85 | signals: |
| 86 | void |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 87 | shutdownBackend(); |
| 88 | |
| 89 | void |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 90 | shutdownDiscoveryBackend(); |
| 91 | |
| 92 | void |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 93 | updateLocalPrefix(); |
| 94 | |
| 95 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 96 | closeDBModule(); |
| 97 | |
| 98 | void |
| 99 | localPrefixUpdated(const QString& localPrefix); |
| 100 | |
| 101 | void |
Yingdi Yu | baaaec0 | 2014-09-02 22:05:32 -0700 | [diff] [blame] | 102 | localPrefixConfigured(const QString& prefix); |
| 103 | |
| 104 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 105 | identityUpdated(const QString& identity); |
| 106 | |
| 107 | void |
| 108 | refreshBrowseContact(); |
| 109 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 110 | void |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 111 | invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 112 | size_t routingPrefixOffset); |
| 113 | |
| 114 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 115 | discoverChatroomChanged(const chronochat::ChatroomInfo& chatroomInfo, bool isAdd); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 116 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 117 | void |
| 118 | addChatroom(QString chatroomName); |
| 119 | |
| 120 | void |
| 121 | removeChatroom(QString chatroomName); |
| 122 | |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 123 | void |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame^] | 124 | respondChatroomInfoRequest(ChatroomInfo chatroomInfo, bool isManager); |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 125 | |
| 126 | void |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame^] | 127 | nfdReconnect(); |
| 128 | |
| 129 | void |
| 130 | shutdownNfdChecker(); |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 131 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 132 | private slots: |
| 133 | void |
| 134 | onIdentityUpdated(const QString& identity); |
| 135 | |
| 136 | void |
| 137 | onIdentityUpdatedContinued(); |
| 138 | |
| 139 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 140 | onNickUpdated(const QString& nick); |
| 141 | |
| 142 | void |
| 143 | onLocalPrefixUpdated(const QString& localPrefix); |
| 144 | |
| 145 | void |
Yingdi Yu | baaaec0 | 2014-09-02 22:05:32 -0700 | [diff] [blame] | 146 | onLocalPrefixConfigured(const QString& prefix); |
| 147 | |
| 148 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 149 | onStartChatAction(); |
| 150 | |
| 151 | void |
| 152 | onSettingsAction(); |
| 153 | |
| 154 | void |
| 155 | onProfileEditorAction(); |
| 156 | |
| 157 | void |
| 158 | onAddContactAction(); |
| 159 | |
| 160 | void |
| 161 | onContactListAction(); |
| 162 | |
| 163 | void |
| 164 | onDirectAdd(); |
| 165 | |
| 166 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 167 | onMinimizeAction(); |
| 168 | |
| 169 | void |
| 170 | onQuitAction(); |
| 171 | |
| 172 | void |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 173 | onChatroomDiscoveryAction(); |
| 174 | |
| 175 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 176 | onStartChatroom(const QString& chatroom, bool secured); |
| 177 | |
| 178 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 179 | onStartChatroom2(chronochat::Invitation invitation, bool secured); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 180 | |
| 181 | void |
| 182 | onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 183 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 184 | void |
| 185 | onResetIcon(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 186 | |
| 187 | void |
| 188 | onRemoveChatDialog(const QString& chatroom); |
| 189 | |
| 190 | void |
| 191 | onWarning(const QString& msg); |
| 192 | |
| 193 | void |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame^] | 194 | onNfdError(); |
| 195 | |
| 196 | void |
| 197 | onNfdReconnect(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 198 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 199 | void |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 200 | onChatroomInfoRequest(std::string chatroomName, bool isManager); |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 201 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 202 | private: // private member |
| 203 | typedef std::map<std::string, QAction*> ChatActionList; |
| 204 | typedef std::map<std::string, ChatDialog*> ChatDialogList; |
| 205 | |
| 206 | // Communication |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 207 | Name m_localPrefix; |
Yingdi Yu | baaaec0 | 2014-09-02 22:05:32 -0700 | [diff] [blame] | 208 | bool m_localPrefixDetected; |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame^] | 209 | bool m_isInConnectionDetection; |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 210 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 211 | // Tray |
| 212 | QAction* m_startChatroom; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 213 | //QAction* m_discoveryAction; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 214 | QAction* m_minimizeAction; |
| 215 | QAction* m_settingsAction; |
| 216 | QAction* m_editProfileAction; |
| 217 | QAction* m_contactListAction; |
| 218 | QAction* m_addContactAction; |
| 219 | QAction* m_updateLocalPrefixAction; |
| 220 | QAction* m_quitAction; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 221 | QAction* m_chatroomDiscoveryAction; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 222 | QMenu* m_trayIconMenu; |
| 223 | QMenu* m_closeMenu; |
| 224 | QSystemTrayIcon* m_trayIcon; |
| 225 | ChatActionList m_chatActionList; |
| 226 | ChatActionList m_closeActionList; |
| 227 | |
| 228 | // Dialogs |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 229 | SettingDialog* m_settingDialog; |
| 230 | StartChatDialog* m_startChatDialog; |
| 231 | ProfileEditor* m_profileEditor; |
| 232 | InvitationDialog* m_invitationDialog; |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 233 | InvitationRequestDialog* m_invitationRequestDialog; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 234 | ContactPanel* m_contactPanel; |
| 235 | BrowseContactDialog* m_browseContactDialog; |
| 236 | AddContactPanel* m_addContactPanel; |
| 237 | ChatDialogList m_chatDialogList; |
| 238 | DiscoveryPanel* m_discoveryPanel; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 239 | |
| 240 | // Conf |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 241 | Name m_identity; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 242 | std::string m_nick; |
| 243 | QSqlDatabase m_db; |
| 244 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 245 | // Backend |
Yingdi Yu | f340118 | 2015-02-02 20:21:07 -0800 | [diff] [blame^] | 246 | ControllerBackend m_backend; |
| 247 | ChatroomDiscoveryBackend* m_chatroomDiscoveryBackend; |
| 248 | NfdConnectionChecker* m_nfdConnectionChecker; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 249 | }; |
| 250 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 251 | } // namespace chronochat |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 252 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 253 | #endif // CHRONOCHAT_CONTROLLER_HPP |