blob: c4894707c50444c3c059c8cef7f43d1b1b190309 [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- 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 Yu0b0a7362014-08-05 16:31:30 -070011#ifndef CHRONOS_CONTROLLER_HPP
12#define CHRONOS_CONTROLLER_HPP
Yingdi Yu348f5ea2014-03-01 14:47:25 -080013
14#include <QDialog>
15#include <QMenu>
16#include <QSystemTrayIcon>
17#include <QtSql/QSqlDatabase>
18
Yingdi Yu0b0a7362014-08-05 16:31:30 -070019#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 Yan391d7242014-08-28 20:51:55 -070027#include "chatroom-discovery-dialog.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080028
29#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070030#include "common.hpp"
31#include "contact-manager.hpp"
Mengjin Yan391d7242014-08-28 20:51:55 -070032#include "chatroom-discovery-logic.hpp"
Yingdi Yu0b0a7362014-08-05 16:31:30 -070033#include "validator-invitation.hpp"
Yingdi Yufa0b6a02014-04-30 14:26:42 -070034#include <ndn-cxx/security/key-chain.hpp>
Yingdi Yu348f5ea2014-03-01 14:47:25 -080035#endif
36
37namespace chronos {
38
39class Controller : public QDialog
40{
41 Q_OBJECT
42
43public: // public methods
Yingdi Yu0b0a7362014-08-05 16:31:30 -070044 Controller(shared_ptr<ndn::Face> face, QWidget* parent = 0);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070045
Yingdi Yu348f5ea2014-03-01 14:47:25 -080046 virtual
47 ~Controller();
48
49private: // 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 Yufa0b6a02014-04-30 14:26:42 -070068 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080069 createActions();
70
71 void
72 createTrayIcon();
73
74 void
75 updateMenu();
76
77 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070078 onLocalPrefix(const Interest& interest, Data& data);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080079
80 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070081 onLocalPrefixTimeout(const Interest& interest);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080082
83 void
Mengjin Yanaec70742014-08-25 10:37:45 -070084 onInvitationInterestWrapper(const ndn::Name& prefix, const ndn::Interest& interest,
Yingdi Yu0b0a7362014-08-05 16:31:30 -070085 size_t routingPrefixOffset);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070086
Yingdi Yu348f5ea2014-03-01 14:47:25 -080087 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070088 onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080089
90 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070091 onInvitationValidated(const shared_ptr<const Interest>& interest);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080092
93 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070094 onInvitationValidationFailed(const shared_ptr<const Interest>& interest,
95 std::string failureInfo);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080096
97 std::string
98 getRandomString();
99
100 ndn::Name
101 getInvitationRoutingPrefix();
102
103 void
104 addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
105
Mengjin Yan391d7242014-08-28 20:51:55 -0700106 void
107 updateDiscoveryList(const chronos::ChatroomInfo& chatroomName, bool isAdd);
108
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800109signals:
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 Yu233a9722014-03-07 15:47:09 -0800122 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700123 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 Yu233a9722014-03-07 15:47:09 -0800128
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800129private 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 Yan391d7242014-08-28 20:51:55 -0700149 onDiscoveryAction();
150
151 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800152 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 Yan391d7242014-08-28 20:51:55 -0700179 onInvitationResponded(const ndn::Name& invitationName, bool accepted);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800180
181 void
182 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700183
Yingdi Yu233a9722014-03-07 15:47:09 -0800184 void
185 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800186
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 Yu233a9722014-03-07 15:47:09 -0800196 void
Mengjin Yanaec70742014-08-25 10:37:45 -0700197 onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
198 size_t routingPrefixOffset);
Yingdi Yu233a9722014-03-07 15:47:09 -0800199
Mengjin Yan391d7242014-08-28 20:51:55 -0700200 void
201 onRosterChanged(const chronos::ChatroomInfo& info);
202
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800203private: // private member
204 typedef std::map<std::string, QAction*> ChatActionList;
205 typedef std::map<std::string, ChatDialog*> ChatDialogList;
206
207 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700208 shared_ptr<ndn::Face> m_face;
209 Name m_localPrefix;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800210 const ndn::RegisteredPrefixId* m_invitationListenerId;
211
212 // Contact Manager
213 ContactManager m_contactManager;
214
Mengjin Yan391d7242014-08-28 20:51:55 -0700215 // Chatroom discovery
216 ChatroomDiscoveryLogic m_discoveryLogic;
217
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800218 // Tray
219 QAction* m_startChatroom;
Mengjin Yan391d7242014-08-28 20:51:55 -0700220 QAction* m_discoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800221 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 Yan391d7242014-08-28 20:51:55 -0700243 ChatroomDiscoveryDialog* m_chatroomDiscoveryDialog;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800244
245 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700246 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800247 std::string m_nick;
248 QSqlDatabase m_db;
249
250 // Security related;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700251 ndn::KeyChain m_keyChain;
252 ValidatorInvitation m_validator;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800253};
254
255} // namespace chronos
256
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700257#endif //CHRONOS_CONTROLLER_HPP