blob: d44517155add4c16089ef1c2953c08d84eedfa91 [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"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080027
28#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070029#include "common.hpp"
30#include "contact-manager.hpp"
31#include "validator-invitation.hpp"
Yingdi Yufa0b6a02014-04-30 14:26:42 -070032#include <ndn-cxx/security/key-chain.hpp>
Yingdi Yu348f5ea2014-03-01 14:47:25 -080033#endif
34
35namespace chronos {
36
37class Controller : public QDialog
38{
39 Q_OBJECT
40
41public: // public methods
Yingdi Yu0b0a7362014-08-05 16:31:30 -070042 Controller(shared_ptr<ndn::Face> face, QWidget* parent = 0);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070043
Yingdi Yu348f5ea2014-03-01 14:47:25 -080044 virtual
45 ~Controller();
46
47private: // 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 Yufa0b6a02014-04-30 14:26:42 -070066 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080067 createActions();
68
69 void
70 createTrayIcon();
71
72 void
73 updateMenu();
74
75 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070076 onLocalPrefix(const Interest& interest, Data& data);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080077
78 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070079 onLocalPrefixTimeout(const Interest& interest);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080080
81 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070082 onInvitationInterestWrapper(const Name& prefix, const Interest& interest,
83 size_t routingPrefixOffset);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070084
Yingdi Yu348f5ea2014-03-01 14:47:25 -080085 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070086 onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080087
88 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070089 onInvitationValidated(const shared_ptr<const Interest>& interest);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080090
91 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070092 onInvitationValidationFailed(const shared_ptr<const Interest>& interest,
93 std::string failureInfo);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080094
95 std::string
96 getRandomString();
97
98 ndn::Name
99 getInvitationRoutingPrefix();
100
101 void
102 addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
103
104signals:
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 Yu233a9722014-03-07 15:47:09 -0800117 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700118 invitationInterest(const Name& prefix, const Interest& interest, size_t routingPrefixOffset);
Yingdi Yu233a9722014-03-07 15:47:09 -0800119
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800120private 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 Yu0b0a7362014-08-05 16:31:30 -0700167 onInvitationResponded(const Name& invitationName, bool accepted);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800168
169 void
170 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700171
Yingdi Yu233a9722014-03-07 15:47:09 -0800172 void
173 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800174
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 Yu233a9722014-03-07 15:47:09 -0800184 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700185 onInvitationInterest(const Name& prefix, const Interest& interest, size_t routingPrefixOffset);
Yingdi Yu233a9722014-03-07 15:47:09 -0800186
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800187private: // private member
188 typedef std::map<std::string, QAction*> ChatActionList;
189 typedef std::map<std::string, ChatDialog*> ChatDialogList;
190
191 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700192 shared_ptr<ndn::Face> m_face;
193 Name m_localPrefix;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800194 const ndn::RegisteredPrefixId* m_invitationListenerId;
195
196 // Contact Manager
197 ContactManager m_contactManager;
198
199 // Tray
200 QAction* m_startChatroom;
201 QAction* m_minimizeAction;
202 QAction* m_settingsAction;
203 QAction* m_editProfileAction;
204 QAction* m_contactListAction;
205 QAction* m_addContactAction;
206 QAction* m_updateLocalPrefixAction;
207 QAction* m_quitAction;
208 QMenu* m_trayIconMenu;
209 QMenu* m_closeMenu;
210 QSystemTrayIcon* m_trayIcon;
211 ChatActionList m_chatActionList;
212 ChatActionList m_closeActionList;
213
214 // Dialogs
215 SettingDialog* m_settingDialog;
216 StartChatDialog* m_startChatDialog;
217 ProfileEditor* m_profileEditor;
218 InvitationDialog* m_invitationDialog;
219 ContactPanel* m_contactPanel;
220 BrowseContactDialog* m_browseContactDialog;
221 AddContactPanel* m_addContactPanel;
222 ChatDialogList m_chatDialogList;
223
224 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700225 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800226 std::string m_nick;
227 QSqlDatabase m_db;
228
229 // Security related;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700230 ndn::KeyChain m_keyChain;
231 ValidatorInvitation m_validator;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800232};
233
234} // namespace chronos
235
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700236#endif //CHRONOS_CONTROLLER_HPP