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 | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 11 | #ifndef CHRONOS_CONTROLLER_HPP |
| 12 | #define CHRONOS_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" |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 27 | #include "chatroom-discovery-dialog.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 28 | |
| 29 | #ifndef Q_MOC_RUN |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 30 | #include "common.hpp" |
| 31 | #include "contact-manager.hpp" |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 32 | #include "chatroom-discovery-logic.hpp" |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 33 | #include "validator-invitation.hpp" |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/security/key-chain.hpp> |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 35 | #endif |
| 36 | |
| 37 | namespace chronos { |
| 38 | |
| 39 | class Controller : public QDialog |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | public: // public methods |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 44 | Controller(shared_ptr<ndn::Face> face, 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 |
| 60 | setInvitationListener(); |
| 61 | |
| 62 | void |
| 63 | loadConf(); |
| 64 | |
| 65 | void |
| 66 | saveConf(); |
| 67 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 68 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 69 | createActions(); |
| 70 | |
| 71 | void |
| 72 | createTrayIcon(); |
| 73 | |
| 74 | void |
| 75 | updateMenu(); |
| 76 | |
| 77 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 78 | onLocalPrefix(const Interest& interest, Data& data); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 79 | |
| 80 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 81 | onLocalPrefixTimeout(const Interest& interest); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 82 | |
| 83 | void |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 84 | onInvitationInterestWrapper(const ndn::Name& prefix, const ndn::Interest& interest, |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 85 | size_t routingPrefixOffset); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 86 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 87 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 88 | onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 89 | |
| 90 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 91 | onInvitationValidated(const shared_ptr<const Interest>& interest); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 92 | |
| 93 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 94 | onInvitationValidationFailed(const shared_ptr<const Interest>& interest, |
| 95 | std::string failureInfo); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 96 | |
| 97 | std::string |
| 98 | getRandomString(); |
| 99 | |
| 100 | ndn::Name |
| 101 | getInvitationRoutingPrefix(); |
| 102 | |
| 103 | void |
| 104 | addChatDialog(const QString& chatroomName, ChatDialog* chatDialog); |
| 105 | |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 106 | void |
| 107 | updateDiscoveryList(const chronos::ChatroomInfo& chatroomName, bool isAdd); |
| 108 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 109 | signals: |
| 110 | void |
| 111 | closeDBModule(); |
| 112 | |
| 113 | void |
| 114 | localPrefixUpdated(const QString& localPrefix); |
| 115 | |
| 116 | void |
| 117 | identityUpdated(const QString& identity); |
| 118 | |
| 119 | void |
| 120 | refreshBrowseContact(); |
| 121 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 122 | void |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 123 | invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 124 | size_t routingPrefixOffset); |
| 125 | |
| 126 | void |
| 127 | discoverChatroomChanged(const chronos::ChatroomInfo& chatroomInfo, bool isAdd); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -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 |
| 137 | onContactIdListReady(const QStringList& list); |
| 138 | |
| 139 | void |
| 140 | onNickUpdated(const QString& nick); |
| 141 | |
| 142 | void |
| 143 | onLocalPrefixUpdated(const QString& localPrefix); |
| 144 | |
| 145 | void |
| 146 | onStartChatAction(); |
| 147 | |
| 148 | void |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 149 | onDiscoveryAction(); |
| 150 | |
| 151 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 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 |
| 167 | onUpdateLocalPrefixAction(); |
| 168 | |
| 169 | void |
| 170 | onMinimizeAction(); |
| 171 | |
| 172 | void |
| 173 | onQuitAction(); |
| 174 | |
| 175 | void |
| 176 | onStartChatroom(const QString& chatroom, bool secured); |
| 177 | |
| 178 | void |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 179 | onInvitationResponded(const ndn::Name& invitationName, bool accepted); |
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 |
| 194 | onError(const QString& msg); |
| 195 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 196 | void |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 197 | onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 198 | size_t routingPrefixOffset); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 199 | |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 200 | void |
| 201 | onRosterChanged(const chronos::ChatroomInfo& info); |
| 202 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 203 | private: // private member |
| 204 | typedef std::map<std::string, QAction*> ChatActionList; |
| 205 | typedef std::map<std::string, ChatDialog*> ChatDialogList; |
| 206 | |
| 207 | // Communication |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 208 | shared_ptr<ndn::Face> m_face; |
| 209 | Name m_localPrefix; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 210 | const ndn::RegisteredPrefixId* m_invitationListenerId; |
| 211 | |
| 212 | // Contact Manager |
| 213 | ContactManager m_contactManager; |
| 214 | |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 215 | // Chatroom discovery |
| 216 | ChatroomDiscoveryLogic m_discoveryLogic; |
| 217 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 218 | // Tray |
| 219 | QAction* m_startChatroom; |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 220 | QAction* m_discoveryAction; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 221 | QAction* m_minimizeAction; |
| 222 | QAction* m_settingsAction; |
| 223 | QAction* m_editProfileAction; |
| 224 | QAction* m_contactListAction; |
| 225 | QAction* m_addContactAction; |
| 226 | QAction* m_updateLocalPrefixAction; |
| 227 | QAction* m_quitAction; |
| 228 | QMenu* m_trayIconMenu; |
| 229 | QMenu* m_closeMenu; |
| 230 | QSystemTrayIcon* m_trayIcon; |
| 231 | ChatActionList m_chatActionList; |
| 232 | ChatActionList m_closeActionList; |
| 233 | |
| 234 | // Dialogs |
| 235 | SettingDialog* m_settingDialog; |
| 236 | StartChatDialog* m_startChatDialog; |
| 237 | ProfileEditor* m_profileEditor; |
| 238 | InvitationDialog* m_invitationDialog; |
| 239 | ContactPanel* m_contactPanel; |
| 240 | BrowseContactDialog* m_browseContactDialog; |
| 241 | AddContactPanel* m_addContactPanel; |
| 242 | ChatDialogList m_chatDialogList; |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame^] | 243 | ChatroomDiscoveryDialog* m_chatroomDiscoveryDialog; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 244 | |
| 245 | // Conf |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 246 | Name m_identity; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 247 | std::string m_nick; |
| 248 | QSqlDatabase m_db; |
| 249 | |
| 250 | // Security related; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 251 | ndn::KeyChain m_keyChain; |
| 252 | ValidatorInvitation m_validator; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | } // namespace chronos |
| 256 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 257 | #endif //CHRONOS_CONTROLLER_HPP |