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