blob: 44e48016e7d587290b8b894ddfe74c73f5d27ff8 [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"
Yingdi Yu2c9e7712014-10-20 11:55:05 -070030#include "invitation.hpp"
31#include "controller-backend.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080032#endif
33
34namespace chronos {
35
36class Controller : public QDialog
37{
38 Q_OBJECT
39
40public: // public methods
Yingdi Yu2c9e7712014-10-20 11:55:05 -070041 Controller(QWidget* parent = 0);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070042
Yingdi Yu348f5ea2014-03-01 14:47:25 -080043 virtual
44 ~Controller();
45
46private: // private methods
47 std::string
48 getDBName();
49
50 void
51 openDB();
52
53 void
54 initialize();
55
56 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080057 loadConf();
58
59 void
60 saveConf();
61
Yingdi Yufa0b6a02014-04-30 14:26:42 -070062 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080063 createActions();
64
65 void
66 createTrayIcon();
67
68 void
69 updateMenu();
70
Yingdi Yu348f5ea2014-03-01 14:47:25 -080071 std::string
72 getRandomString();
73
Yingdi Yu348f5ea2014-03-01 14:47:25 -080074 void
75 addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
76
Mengjin Yan391d7242014-08-28 20:51:55 -070077 void
78 updateDiscoveryList(const chronos::ChatroomInfo& chatroomName, bool isAdd);
79
Yingdi Yu348f5ea2014-03-01 14:47:25 -080080signals:
81 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070082 shutdownBackend();
83
84 void
85 updateLocalPrefix();
86
87 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080088 closeDBModule();
89
90 void
91 localPrefixUpdated(const QString& localPrefix);
92
93 void
Yingdi Yubaaaec02014-09-02 22:05:32 -070094 localPrefixConfigured(const QString& prefix);
95
96 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080097 identityUpdated(const QString& identity);
98
99 void
100 refreshBrowseContact();
101
Yingdi Yu233a9722014-03-07 15:47:09 -0800102 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700103 invitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
104 size_t routingPrefixOffset);
105
106 void
107 discoverChatroomChanged(const chronos::ChatroomInfo& chatroomInfo, bool isAdd);
Yingdi Yu233a9722014-03-07 15:47:09 -0800108
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700109 void
110 addChatroom(QString chatroomName);
111
112 void
113 removeChatroom(QString chatroomName);
114
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800115private slots:
116 void
117 onIdentityUpdated(const QString& identity);
118
119 void
120 onIdentityUpdatedContinued();
121
122 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800123 onNickUpdated(const QString& nick);
124
125 void
126 onLocalPrefixUpdated(const QString& localPrefix);
127
128 void
Yingdi Yubaaaec02014-09-02 22:05:32 -0700129 onLocalPrefixConfigured(const QString& prefix);
130
131 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800132 onStartChatAction();
133
134 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700135 onDiscoveryAction();
136
137 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800138 onSettingsAction();
139
140 void
141 onProfileEditorAction();
142
143 void
144 onAddContactAction();
145
146 void
147 onContactListAction();
148
149 void
150 onDirectAdd();
151
152 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800153 onMinimizeAction();
154
155 void
156 onQuitAction();
157
158 void
159 onStartChatroom(const QString& chatroom, bool secured);
160
161 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700162 onStartChatroom2(chronos::Invitation invitation, bool secured);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800163
164 void
165 onShowChatMessage(const QString& chatroomName, const QString& from, const QString& data);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700166
Yingdi Yu233a9722014-03-07 15:47:09 -0800167 void
168 onResetIcon();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800169
170 void
171 onRemoveChatDialog(const QString& chatroom);
172
173 void
174 onWarning(const QString& msg);
175
176 void
177 onError(const QString& msg);
178
Yingdi Yu233a9722014-03-07 15:47:09 -0800179 void
Mengjin Yan391d7242014-08-28 20:51:55 -0700180 onRosterChanged(const chronos::ChatroomInfo& info);
181
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800182private: // private member
183 typedef std::map<std::string, QAction*> ChatActionList;
184 typedef std::map<std::string, ChatDialog*> ChatDialogList;
185
186 // Communication
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700187 Name m_localPrefix;
Yingdi Yubaaaec02014-09-02 22:05:32 -0700188 bool m_localPrefixDetected;
Mengjin Yan391d7242014-08-28 20:51:55 -0700189
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800190 // Tray
191 QAction* m_startChatroom;
Mengjin Yan391d7242014-08-28 20:51:55 -0700192 QAction* m_discoveryAction;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800193 QAction* m_minimizeAction;
194 QAction* m_settingsAction;
195 QAction* m_editProfileAction;
196 QAction* m_contactListAction;
197 QAction* m_addContactAction;
198 QAction* m_updateLocalPrefixAction;
199 QAction* m_quitAction;
200 QMenu* m_trayIconMenu;
201 QMenu* m_closeMenu;
202 QSystemTrayIcon* m_trayIcon;
203 ChatActionList m_chatActionList;
204 ChatActionList m_closeActionList;
205
206 // Dialogs
207 SettingDialog* m_settingDialog;
208 StartChatDialog* m_startChatDialog;
209 ProfileEditor* m_profileEditor;
210 InvitationDialog* m_invitationDialog;
211 ContactPanel* m_contactPanel;
212 BrowseContactDialog* m_browseContactDialog;
213 AddContactPanel* m_addContactPanel;
214 ChatDialogList m_chatDialogList;
215
216 // Conf
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700217 Name m_identity;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800218 std::string m_nick;
219 QSqlDatabase m_db;
220
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700221 // Backend
222 ControllerBackend m_backend;
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800223};
224
225} // namespace chronos
226
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700227#endif //CHRONOS_CONTROLLER_HPP