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