blob: 40a481a7b131feaa06e43a3815b164945b0d88dc [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
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
35namespace chronos {
36
37class Controller : public QDialog
38{
39 Q_OBJECT
40
41public: // public methods
42 Controller(ndn::shared_ptr<ndn::Face> face,
43 QWidget* parent = 0);
44
45 virtual
46 ~Controller();
47
48private: // 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
Yingdi Yu233a9722014-03-07 15:47:09 -080083 onInvitationInterestWrapper(const ndn::Name& prefix, const ndn::Interest& interest, size_t routingPrefixOffset);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080084
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
103signals:
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
Yingdi Yu233a9722014-03-07 15:47:09 -0800116 void
117 invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, size_t routingPrefixOffset);
118
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800119private slots:
120 void
121 onIdentityUpdated(const QString& identity);
122
123 void
124 onIdentityUpdatedContinued();
125
126 void
127 onContactIdListReady(const QStringList& list);
128
129 void
130 onNickUpdated(const QString& nick);
131
132 void
133 onLocalPrefixUpdated(const QString& localPrefix);
134
135 void
136 onStartChatAction();
137
138 void
139 onSettingsAction();
140
141 void
142 onProfileEditorAction();
143
144 void
145 onAddContactAction();
146
147 void
148 onContactListAction();
149
150 void
151 onDirectAdd();
152
153 void
154 onUpdateLocalPrefixAction();
155
156 void
157 onMinimizeAction();
158
159 void
160 onQuitAction();
161
162 void
163 onStartChatroom(const QString& chatroom, bool secured);
164
165 void
166 onInvitationResponded(const ndn::Name& invitationName, bool accepted);
167
168 void
169 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yu233a9722014-03-07 15:47:09 -0800170
171 void
172 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800173
174 void
175 onRemoveChatDialog(const QString& chatroom);
176
177 void
178 onWarning(const QString& msg);
179
180 void
181 onError(const QString& msg);
182
Yingdi Yu233a9722014-03-07 15:47:09 -0800183 void
184 onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, size_t routingPrefixOffset);
185
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800186private: // private member
187 typedef std::map<std::string, QAction*> ChatActionList;
188 typedef std::map<std::string, ChatDialog*> ChatDialogList;
189
190 // Communication
191 ndn::shared_ptr<ndn::Face> m_face;
192 ndn::Name m_localPrefix;
193 const ndn::RegisteredPrefixId* m_invitationListenerId;
194
195 // Contact Manager
196 ContactManager m_contactManager;
197
198 // Tray
199 QAction* m_startChatroom;
200 QAction* m_minimizeAction;
201 QAction* m_settingsAction;
202 QAction* m_editProfileAction;
203 QAction* m_contactListAction;
204 QAction* m_addContactAction;
205 QAction* m_updateLocalPrefixAction;
206 QAction* m_quitAction;
207 QMenu* m_trayIconMenu;
208 QMenu* m_closeMenu;
209 QSystemTrayIcon* m_trayIcon;
210 ChatActionList m_chatActionList;
211 ChatActionList m_closeActionList;
212
213 // Dialogs
214 SettingDialog* m_settingDialog;
215 StartChatDialog* m_startChatDialog;
216 ProfileEditor* m_profileEditor;
217 InvitationDialog* m_invitationDialog;
218 ContactPanel* m_contactPanel;
219 BrowseContactDialog* m_browseContactDialog;
220 AddContactPanel* m_addContactPanel;
221 ChatDialogList m_chatDialogList;
222
223 // Conf
224 ndn::Name m_identity;
225 std::string m_nick;
226 QSqlDatabase m_db;
227
228 // Security related;
229 ndn::KeyChain m_keyChain;
230 chronos::ValidatorInvitation m_validator;
231};
232
233} // namespace chronos
234
235#endif //CHRONOS_CONTROLLER_H