blob: 81b05a9f097ca36d57777953f6afc359b76a2830 [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
Yingdi Yubaaaec02014-09-02 22:05:32 -0700117 localPrefixConfigured(const QString& prefix);
118
119 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800120 identityUpdated(const QString& identity);
121
122 void
123 refreshBrowseContact();
124
Yingdi Yu233a9722014-03-07 15:47:09 -0800125 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700126 invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
127 size_t routingPrefixOffset);
128
129 void
130 discoverChatroomChanged(const chronos::ChatroomInfo& chatroomInfo, bool isAdd);
Yingdi Yu233a9722014-03-07 15:47:09 -0800131
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800132private slots:
133 void
134 onIdentityUpdated(const QString& identity);
135
136 void
137 onIdentityUpdatedContinued();
138
139 void
140 onContactIdListReady(const QStringList& list);
141
142 void
143 onNickUpdated(const QString& nick);
144
145 void
146 onLocalPrefixUpdated(const QString& localPrefix);
147
148 void
Yingdi Yubaaaec02014-09-02 22:05:32 -0700149 onLocalPrefixConfigured(const QString& prefix);
150
151 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800152 onStartChatAction();
153
154 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700155 onDiscoveryAction();
156
157 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800158 onSettingsAction();
159
160 void
161 onProfileEditorAction();
162
163 void
164 onAddContactAction();
165
166 void
167 onContactListAction();
168
169 void
170 onDirectAdd();
171
172 void
173 onUpdateLocalPrefixAction();
174
175 void
176 onMinimizeAction();
177
178 void
179 onQuitAction();
180
181 void
182 onStartChatroom(const QString& chatroom, bool secured);
183
184 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700185 onInvitationResponded(const ndn::Name& invitationName, bool accepted);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800186
187 void
188 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700189
Yingdi Yu233a9722014-03-07 15:47:09 -0800190 void
191 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800192
193 void
194 onRemoveChatDialog(const QString& chatroom);
195
196 void
197 onWarning(const QString& msg);
198
199 void
200 onError(const QString& msg);
201
Yingdi Yu233a9722014-03-07 15:47:09 -0800202 void
Mengjin Yanaec70742014-08-25 10:37:45 -0700203 onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
204 size_t routingPrefixOffset);
Yingdi Yu233a9722014-03-07 15:47:09 -0800205
Mengjin Yan391d7242014-08-28 20:51:55 -0700206 void
207 onRosterChanged(const chronos::ChatroomInfo& info);
208
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800209private: // private member
210 typedef std::map<std::string, QAction*> ChatActionList;
211 typedef std::map<std::string, ChatDialog*> ChatDialogList;
212
213 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700214 shared_ptr<ndn::Face> m_face;
215 Name m_localPrefix;
Yingdi Yubaaaec02014-09-02 22:05:32 -0700216 bool m_localPrefixDetected;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800217 const ndn::RegisteredPrefixId* m_invitationListenerId;
218
219 // Contact Manager
220 ContactManager m_contactManager;
221
Mengjin Yan391d7242014-08-28 20:51:55 -0700222 // Chatroom discovery
223 ChatroomDiscoveryLogic m_discoveryLogic;
224
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800225 // Tray
226 QAction* m_startChatroom;
Mengjin Yan391d7242014-08-28 20:51:55 -0700227 QAction* m_discoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800228 QAction* m_minimizeAction;
229 QAction* m_settingsAction;
230 QAction* m_editProfileAction;
231 QAction* m_contactListAction;
232 QAction* m_addContactAction;
233 QAction* m_updateLocalPrefixAction;
234 QAction* m_quitAction;
235 QMenu* m_trayIconMenu;
236 QMenu* m_closeMenu;
237 QSystemTrayIcon* m_trayIcon;
238 ChatActionList m_chatActionList;
239 ChatActionList m_closeActionList;
240
241 // Dialogs
242 SettingDialog* m_settingDialog;
243 StartChatDialog* m_startChatDialog;
244 ProfileEditor* m_profileEditor;
245 InvitationDialog* m_invitationDialog;
246 ContactPanel* m_contactPanel;
247 BrowseContactDialog* m_browseContactDialog;
248 AddContactPanel* m_addContactPanel;
249 ChatDialogList m_chatDialogList;
Mengjin Yan391d7242014-08-28 20:51:55 -0700250 ChatroomDiscoveryDialog* m_chatroomDiscoveryDialog;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800251
252 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700253 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800254 std::string m_nick;
255 QSqlDatabase m_db;
256
257 // Security related;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700258 ndn::KeyChain m_keyChain;
259 ValidatorInvitation m_validator;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800260};
261
262} // namespace chronos
263
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700264#endif //CHRONOS_CONTROLLER_HPP