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" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 27 | |
| 28 | #ifndef Q_MOC_RUN |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 29 | #include "common.hpp" |
| 30 | #include "contact-manager.hpp" |
| 31 | #include "validator-invitation.hpp" |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 32 | #include <ndn-cxx/security/key-chain.hpp> |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | namespace chronos { |
| 36 | |
| 37 | class Controller : public QDialog |
| 38 | { |
| 39 | Q_OBJECT |
| 40 | |
| 41 | public: // public methods |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 42 | Controller(shared_ptr<ndn::Face> face, QWidget* parent = 0); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 43 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 44 | virtual |
| 45 | ~Controller(); |
| 46 | |
| 47 | private: // private methods |
| 48 | std::string |
| 49 | getDBName(); |
| 50 | |
| 51 | void |
| 52 | openDB(); |
| 53 | |
| 54 | void |
| 55 | initialize(); |
| 56 | |
| 57 | void |
| 58 | setInvitationListener(); |
| 59 | |
| 60 | void |
| 61 | loadConf(); |
| 62 | |
| 63 | void |
| 64 | saveConf(); |
| 65 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 66 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 67 | createActions(); |
| 68 | |
| 69 | void |
| 70 | createTrayIcon(); |
| 71 | |
| 72 | void |
| 73 | updateMenu(); |
| 74 | |
| 75 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 76 | onLocalPrefix(const Interest& interest, Data& data); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 77 | |
| 78 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 79 | onLocalPrefixTimeout(const Interest& interest); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 80 | |
| 81 | void |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame^] | 82 | onInvitationInterestWrapper(const ndn::Name& prefix, const ndn::Interest& interest, |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 83 | size_t routingPrefixOffset); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 84 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 85 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 86 | onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 87 | |
| 88 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 89 | onInvitationValidated(const shared_ptr<const Interest>& interest); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 90 | |
| 91 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 92 | onInvitationValidationFailed(const shared_ptr<const Interest>& interest, |
| 93 | std::string failureInfo); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 94 | |
| 95 | std::string |
| 96 | getRandomString(); |
| 97 | |
| 98 | ndn::Name |
| 99 | getInvitationRoutingPrefix(); |
| 100 | |
| 101 | void |
| 102 | addChatDialog(const QString& chatroomName, ChatDialog* chatDialog); |
| 103 | |
| 104 | signals: |
| 105 | void |
| 106 | closeDBModule(); |
| 107 | |
| 108 | void |
| 109 | localPrefixUpdated(const QString& localPrefix); |
| 110 | |
| 111 | void |
| 112 | identityUpdated(const QString& identity); |
| 113 | |
| 114 | void |
| 115 | refreshBrowseContact(); |
| 116 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 117 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 118 | invitationInterest(const Name& prefix, const Interest& interest, size_t routingPrefixOffset); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 119 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 120 | private slots: |
| 121 | void |
| 122 | onIdentityUpdated(const QString& identity); |
| 123 | |
| 124 | void |
| 125 | onIdentityUpdatedContinued(); |
| 126 | |
| 127 | void |
| 128 | onContactIdListReady(const QStringList& list); |
| 129 | |
| 130 | void |
| 131 | onNickUpdated(const QString& nick); |
| 132 | |
| 133 | void |
| 134 | onLocalPrefixUpdated(const QString& localPrefix); |
| 135 | |
| 136 | void |
| 137 | onStartChatAction(); |
| 138 | |
| 139 | void |
| 140 | onSettingsAction(); |
| 141 | |
| 142 | void |
| 143 | onProfileEditorAction(); |
| 144 | |
| 145 | void |
| 146 | onAddContactAction(); |
| 147 | |
| 148 | void |
| 149 | onContactListAction(); |
| 150 | |
| 151 | void |
| 152 | onDirectAdd(); |
| 153 | |
| 154 | void |
| 155 | onUpdateLocalPrefixAction(); |
| 156 | |
| 157 | void |
| 158 | onMinimizeAction(); |
| 159 | |
| 160 | void |
| 161 | onQuitAction(); |
| 162 | |
| 163 | void |
| 164 | onStartChatroom(const QString& chatroom, bool secured); |
| 165 | |
| 166 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 167 | onInvitationResponded(const Name& invitationName, bool accepted); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 168 | |
| 169 | void |
| 170 | onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 171 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 172 | void |
| 173 | onResetIcon(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 174 | |
| 175 | void |
| 176 | onRemoveChatDialog(const QString& chatroom); |
| 177 | |
| 178 | void |
| 179 | onWarning(const QString& msg); |
| 180 | |
| 181 | void |
| 182 | onError(const QString& msg); |
| 183 | |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 184 | void |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame^] | 185 | onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 186 | size_t routingPrefixOffset); |
Yingdi Yu | 233a972 | 2014-03-07 15:47:09 -0800 | [diff] [blame] | 187 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 188 | private: // private member |
| 189 | typedef std::map<std::string, QAction*> ChatActionList; |
| 190 | typedef std::map<std::string, ChatDialog*> ChatDialogList; |
| 191 | |
| 192 | // Communication |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 193 | shared_ptr<ndn::Face> m_face; |
| 194 | Name m_localPrefix; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 195 | const ndn::RegisteredPrefixId* m_invitationListenerId; |
| 196 | |
| 197 | // Contact Manager |
| 198 | ContactManager m_contactManager; |
| 199 | |
| 200 | // Tray |
| 201 | QAction* m_startChatroom; |
| 202 | QAction* m_minimizeAction; |
| 203 | QAction* m_settingsAction; |
| 204 | QAction* m_editProfileAction; |
| 205 | QAction* m_contactListAction; |
| 206 | QAction* m_addContactAction; |
| 207 | QAction* m_updateLocalPrefixAction; |
| 208 | QAction* m_quitAction; |
| 209 | QMenu* m_trayIconMenu; |
| 210 | QMenu* m_closeMenu; |
| 211 | QSystemTrayIcon* m_trayIcon; |
| 212 | ChatActionList m_chatActionList; |
| 213 | ChatActionList m_closeActionList; |
| 214 | |
| 215 | // Dialogs |
| 216 | SettingDialog* m_settingDialog; |
| 217 | StartChatDialog* m_startChatDialog; |
| 218 | ProfileEditor* m_profileEditor; |
| 219 | InvitationDialog* m_invitationDialog; |
| 220 | ContactPanel* m_contactPanel; |
| 221 | BrowseContactDialog* m_browseContactDialog; |
| 222 | AddContactPanel* m_addContactPanel; |
| 223 | ChatDialogList m_chatDialogList; |
| 224 | |
| 225 | // Conf |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 226 | Name m_identity; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 227 | std::string m_nick; |
| 228 | QSqlDatabase m_db; |
| 229 | |
| 230 | // Security related; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 231 | ndn::KeyChain m_keyChain; |
| 232 | ValidatorInvitation m_validator; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | } // namespace chronos |
| 236 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 237 | #endif //CHRONOS_CONTROLLER_HPP |