blob: fdce4cdc800acbc99f4574c7d0b434aec7b0f3f3 [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"
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080023#include "invitation-request-dialog.hpp"
Yingdi Yu0b0a7362014-08-05 16:31:30 -070024#include "contact-panel.hpp"
25#include "browse-contact-dialog.hpp"
26#include "add-contact-panel.hpp"
27#include "chat-dialog.hpp"
Qiuhan Ding43c8e162015-02-02 15:16:48 -080028#include "chatroom-discovery-backend.hpp"
29#include "discovery-panel.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080030
31#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070032#include "common.hpp"
Yingdi Yu2c9e7712014-10-20 11:55:05 -070033#include "invitation.hpp"
34#include "controller-backend.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080035#endif
36
Yingdi Yueb692ac2015-02-10 18:46:18 -080037namespace chronochat {
Yingdi Yu348f5ea2014-03-01 14:47:25 -080038
39class Controller : public QDialog
40{
41 Q_OBJECT
42
43public: // public methods
Yingdi Yu2c9e7712014-10-20 11:55:05 -070044 Controller(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
Yingdi Yu348f5ea2014-03-01 14:47:25 -080060 loadConf();
61
62 void
63 saveConf();
64
Yingdi Yufa0b6a02014-04-30 14:26:42 -070065 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080066 createActions();
67
68 void
69 createTrayIcon();
70
71 void
72 updateMenu();
73
Yingdi Yu348f5ea2014-03-01 14:47:25 -080074 std::string
75 getRandomString();
76
Yingdi Yu348f5ea2014-03-01 14:47:25 -080077 void
78 addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
79
Mengjin Yan391d7242014-08-28 20:51:55 -070080 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080081 updateDiscoveryList(const chronochat::ChatroomInfo& chatroomName, bool isAdd);
Mengjin Yan391d7242014-08-28 20:51:55 -070082
Yingdi Yu348f5ea2014-03-01 14:47:25 -080083signals:
84 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070085 shutdownBackend();
86
87 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -080088 shutdownDiscoveryBackend();
89
90 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070091 updateLocalPrefix();
92
93 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080094 closeDBModule();
95
96 void
97 localPrefixUpdated(const QString& localPrefix);
98
99 void
Yingdi Yubaaaec02014-09-02 22:05:32 -0700100 localPrefixConfigured(const QString& prefix);
101
102 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800103 identityUpdated(const QString& identity);
104
105 void
106 refreshBrowseContact();
107
Yingdi Yu233a9722014-03-07 15:47:09 -0800108 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700109 invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
110 size_t routingPrefixOffset);
111
112 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800113 discoverChatroomChanged(const chronochat::ChatroomInfo& chatroomInfo, bool isAdd);
Yingdi Yu233a9722014-03-07 15:47:09 -0800114
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700115 void
116 addChatroom(QString chatroomName);
117
118 void
119 removeChatroom(QString chatroomName);
120
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800121 void
122 newChatroomForDiscovery(Name::Component chatroomName);
123
124 void
125 respondChatroomInfoRequest(ChatroomInfo chatroomInfo, bool isManager);
126
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800127private slots:
128 void
129 onIdentityUpdated(const QString& identity);
130
131 void
132 onIdentityUpdatedContinued();
133
134 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800135 onNickUpdated(const QString& nick);
136
137 void
138 onLocalPrefixUpdated(const QString& localPrefix);
139
140 void
Yingdi Yubaaaec02014-09-02 22:05:32 -0700141 onLocalPrefixConfigured(const QString& prefix);
142
143 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800144 onStartChatAction();
145
146 void
147 onSettingsAction();
148
149 void
150 onProfileEditorAction();
151
152 void
153 onAddContactAction();
154
155 void
156 onContactListAction();
157
158 void
159 onDirectAdd();
160
161 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800162 onMinimizeAction();
163
164 void
165 onQuitAction();
166
167 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800168 onChatroomDiscoveryAction();
169
170 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800171 onStartChatroom(const QString& chatroom, bool secured);
172
173 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800174 onStartChatroom2(chronochat::Invitation invitation, bool secured);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800175
176 void
177 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700178
Yingdi Yu233a9722014-03-07 15:47:09 -0800179 void
180 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800181
182 void
183 onRemoveChatDialog(const QString& chatroom);
184
185 void
186 onWarning(const QString& msg);
187
188 void
189 onError(const QString& msg);
190
Yingdi Yu233a9722014-03-07 15:47:09 -0800191 void
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800192 onChatroomInfoRequest(std::string chatroomName, bool isManager);
Mengjin Yan391d7242014-08-28 20:51:55 -0700193
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800194private: // private member
195 typedef std::map<std::string, QAction*> ChatActionList;
196 typedef std::map<std::string, ChatDialog*> ChatDialogList;
197
198 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700199 Name m_localPrefix;
Yingdi Yubaaaec02014-09-02 22:05:32 -0700200 bool m_localPrefixDetected;
Mengjin Yan391d7242014-08-28 20:51:55 -0700201
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800202 // Tray
203 QAction* m_startChatroom;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800204 //QAction* m_discoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800205 QAction* m_minimizeAction;
206 QAction* m_settingsAction;
207 QAction* m_editProfileAction;
208 QAction* m_contactListAction;
209 QAction* m_addContactAction;
210 QAction* m_updateLocalPrefixAction;
211 QAction* m_quitAction;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800212 QAction* m_chatroomDiscoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800213 QMenu* m_trayIconMenu;
214 QMenu* m_closeMenu;
215 QSystemTrayIcon* m_trayIcon;
216 ChatActionList m_chatActionList;
217 ChatActionList m_closeActionList;
218
219 // Dialogs
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800220 SettingDialog* m_settingDialog;
221 StartChatDialog* m_startChatDialog;
222 ProfileEditor* m_profileEditor;
223 InvitationDialog* m_invitationDialog;
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800224 InvitationRequestDialog* m_invitationRequestDialog;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800225 ContactPanel* m_contactPanel;
226 BrowseContactDialog* m_browseContactDialog;
227 AddContactPanel* m_addContactPanel;
228 ChatDialogList m_chatDialogList;
229 DiscoveryPanel* m_discoveryPanel;
230 ChatroomDiscoveryBackend* m_chatroomDiscoveryBackend;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800231
232 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700233 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800234 std::string m_nick;
235 QSqlDatabase m_db;
236
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700237 // Backend
238 ControllerBackend m_backend;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800239};
240
Yingdi Yueb692ac2015-02-10 18:46:18 -0800241} // namespace chronochat
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800242
Yingdi Yueb692ac2015-02-10 18:46:18 -0800243#endif // CHRONOCHAT_CONTROLLER_HPP