blob: 2b80932fc924f0a8780a2f2d8b4f8912d96f1205 [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 Yueb692ac2015-02-10 18:46:18 -080011#ifndef CHRONOCHAT_CONTROLLER_HPP
12#define CHRONOCHAT_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"
Qiuhan Ding43c8e162015-02-02 15:16:48 -080027#include "chatroom-discovery-backend.hpp"
28#include "discovery-panel.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080029
30#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070031#include "common.hpp"
Yingdi Yu2c9e7712014-10-20 11:55:05 -070032#include "invitation.hpp"
33#include "controller-backend.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080034#endif
35
Yingdi Yueb692ac2015-02-10 18:46:18 -080036namespace chronochat {
Yingdi Yu348f5ea2014-03-01 14:47:25 -080037
38class Controller : public QDialog
39{
40 Q_OBJECT
41
42public: // public methods
Yingdi Yu2c9e7712014-10-20 11:55:05 -070043 Controller(QWidget* parent = 0);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070044
Yingdi Yu348f5ea2014-03-01 14:47:25 -080045 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
Yingdi Yu348f5ea2014-03-01 14:47:25 -080059 loadConf();
60
61 void
62 saveConf();
63
Yingdi Yufa0b6a02014-04-30 14:26:42 -070064 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080065 createActions();
66
67 void
68 createTrayIcon();
69
70 void
71 updateMenu();
72
Yingdi Yu348f5ea2014-03-01 14:47:25 -080073 std::string
74 getRandomString();
75
Yingdi Yu348f5ea2014-03-01 14:47:25 -080076 void
77 addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
78
Mengjin Yan391d7242014-08-28 20:51:55 -070079 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080080 updateDiscoveryList(const chronochat::ChatroomInfo& chatroomName, bool isAdd);
Mengjin Yan391d7242014-08-28 20:51:55 -070081
Yingdi Yu348f5ea2014-03-01 14:47:25 -080082signals:
83 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070084 shutdownBackend();
85
86 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -080087 shutdownDiscoveryBackend();
88
89 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070090 updateLocalPrefix();
91
92 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080093 closeDBModule();
94
95 void
96 localPrefixUpdated(const QString& localPrefix);
97
98 void
Yingdi Yubaaaec02014-09-02 22:05:32 -070099 localPrefixConfigured(const QString& prefix);
100
101 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800102 identityUpdated(const QString& identity);
103
104 void
105 refreshBrowseContact();
106
Yingdi Yu233a9722014-03-07 15:47:09 -0800107 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700108 invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
109 size_t routingPrefixOffset);
110
111 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800112 discoverChatroomChanged(const chronochat::ChatroomInfo& chatroomInfo, bool isAdd);
Yingdi Yu233a9722014-03-07 15:47:09 -0800113
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700114 void
115 addChatroom(QString chatroomName);
116
117 void
118 removeChatroom(QString chatroomName);
119
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800120 void
121 newChatroomForDiscovery(Name::Component chatroomName);
122
123 void
124 respondChatroomInfoRequest(ChatroomInfo chatroomInfo, bool isManager);
125
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800126private slots:
127 void
128 onIdentityUpdated(const QString& identity);
129
130 void
131 onIdentityUpdatedContinued();
132
133 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800134 onNickUpdated(const QString& nick);
135
136 void
137 onLocalPrefixUpdated(const QString& localPrefix);
138
139 void
Yingdi Yubaaaec02014-09-02 22:05:32 -0700140 onLocalPrefixConfigured(const QString& prefix);
141
142 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800143 onStartChatAction();
144
145 void
146 onSettingsAction();
147
148 void
149 onProfileEditorAction();
150
151 void
152 onAddContactAction();
153
154 void
155 onContactListAction();
156
157 void
158 onDirectAdd();
159
160 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800161 onMinimizeAction();
162
163 void
164 onQuitAction();
165
166 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800167 onChatroomDiscoveryAction();
168
169 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800170 onStartChatroom(const QString& chatroom, bool secured);
171
172 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800173 onStartChatroom2(chronochat::Invitation invitation, bool secured);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800174
175 void
176 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700177
Yingdi Yu233a9722014-03-07 15:47:09 -0800178 void
179 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800180
181 void
182 onRemoveChatDialog(const QString& chatroom);
183
184 void
185 onWarning(const QString& msg);
186
187 void
188 onError(const QString& msg);
189
Yingdi Yu233a9722014-03-07 15:47:09 -0800190 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800191 onChatroomInfoRequest(std::string chatroomName, bool isManager);
Mengjin Yan391d7242014-08-28 20:51:55 -0700192
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800193private: // private member
194 typedef std::map<std::string, QAction*> ChatActionList;
195 typedef std::map<std::string, ChatDialog*> ChatDialogList;
196
197 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700198 Name m_localPrefix;
Yingdi Yubaaaec02014-09-02 22:05:32 -0700199 bool m_localPrefixDetected;
Mengjin Yan391d7242014-08-28 20:51:55 -0700200
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800201 // Tray
202 QAction* m_startChatroom;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800203 //QAction* m_discoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800204 QAction* m_minimizeAction;
205 QAction* m_settingsAction;
206 QAction* m_editProfileAction;
207 QAction* m_contactListAction;
208 QAction* m_addContactAction;
209 QAction* m_updateLocalPrefixAction;
210 QAction* m_quitAction;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800211 QAction* m_chatroomDiscoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800212 QMenu* m_trayIconMenu;
213 QMenu* m_closeMenu;
214 QSystemTrayIcon* m_trayIcon;
215 ChatActionList m_chatActionList;
216 ChatActionList m_closeActionList;
217
218 // Dialogs
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800219 SettingDialog* m_settingDialog;
220 StartChatDialog* m_startChatDialog;
221 ProfileEditor* m_profileEditor;
222 InvitationDialog* m_invitationDialog;
223 ContactPanel* m_contactPanel;
224 BrowseContactDialog* m_browseContactDialog;
225 AddContactPanel* m_addContactPanel;
226 ChatDialogList m_chatDialogList;
227 DiscoveryPanel* m_discoveryPanel;
228 ChatroomDiscoveryBackend* m_chatroomDiscoveryBackend;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800229
230 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700231 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800232 std::string m_nick;
233 QSqlDatabase m_db;
234
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700235 // Backend
236 ControllerBackend m_backend;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800237};
238
Yingdi Yueb692ac2015-02-10 18:46:18 -0800239} // namespace chronochat
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800240
Yingdi Yueb692ac2015-02-10 18:46:18 -0800241#endif // CHRONOCHAT_CONTROLLER_HPP