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