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