blob: 439f52a318e31971adbb433c81aa5efd4e52300d [file] [log] [blame]
Yingdi Yu9e0dc292013-10-10 11:39:45 -07001/* -*- 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 Yudef90612013-10-09 22:34:42 -070011#ifndef CONTACTPANEL_H
12#define CONTACTPANEL_H
13
14#include <QDialog>
Yingdi Yu01a942b2013-10-10 15:00:58 -070015#include <QStringListModel>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070016#include <QtSql/QSqlDatabase>
Yingdi Yu79c25a22013-10-21 13:38:38 -070017#include <QMenu>
Yingdi Yub29f78c2013-11-09 20:12:31 -080018#include <QMessageBox>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070019
20#include "profileeditor.h"
Yingdi Yud59b5932013-10-16 13:16:49 -070021#include "addcontactpanel.h"
Yingdi Yu79c25a22013-10-21 13:38:38 -070022#include "setaliasdialog.h"
Yingdi Yu100267f2013-10-21 15:01:40 -070023#include "startchatdialog.h"
Yingdi Yu53eb8a72013-10-23 11:50:51 -070024#include "invitationdialog.h"
25#include "settingdialog.h"
Yingdi Yuc4d08d22013-10-23 23:07:29 -070026#include "chatdialog.h"
Yingdi Yu8dacdf22013-11-05 23:06:43 -080027#include "endorse-combobox-delegate.h"
Yingdi Yu908f8412013-11-09 00:03:26 -080028#include "browsecontactdialog.h"
Yingdi Yub29f78c2013-11-09 20:12:31 -080029#include "warningDialog.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070030
31#ifndef Q_MOC_RUN
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070032#include "contact-manager.h"
Yingdi Yu42f66462013-10-31 17:38:22 -070033#include "chronos-invitation.h"
Yingdi Yued8cfc42013-11-01 17:37:51 -070034#include "panel-policy-manager.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070035#endif
Yingdi Yudef90612013-10-09 22:34:42 -070036
Yingdi Yu53eb8a72013-10-23 11:50:51 -070037
Yingdi Yudef90612013-10-09 22:34:42 -070038namespace Ui {
39class ContactPanel;
40}
41
42class ContactPanel : public QDialog
43{
Yingdi Yuc4d08d22013-10-23 23:07:29 -070044 Q_OBJECT
Yingdi Yudef90612013-10-09 22:34:42 -070045
46public:
Yingdi Yub29f78c2013-11-09 20:12:31 -080047 explicit ContactPanel(QWidget *parent = 0);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070048
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070049 ~ContactPanel();
Yingdi Yudef90612013-10-09 22:34:42 -070050
Yingdi Yu53eb8a72013-10-23 11:50:51 -070051private:
52 void
Yingdi Yu42372442013-11-06 18:43:31 -080053 createAction();
54
55 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070056 openDB();
57
58 void
59 setKeychain();
60
61 void
62 setLocalPrefix();
63
64 void
65 onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
66
67 void
Yingdi Yu42372442013-11-06 18:43:31 -080068 onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure,
69 ndn::Ptr<ndn::Interest> interest);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070070
71 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070072 setInvitationListener();
73
74 void
75 onInvitation(ndn::Ptr<ndn::Interest> interest);
76
77 void
Yingdi Yu42372442013-11-06 18:43:31 -080078 onUnverified(ndn::Ptr<ndn::Data> data);
79
80 void
81 onTimeout(ndn::Ptr<ndn::Closure> closure,
82 ndn::Ptr<ndn::Interest> interest);
83
84 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070085 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
Yingdi Yued8cfc42013-11-01 17:37:51 -070086 ndn::Ptr<ChronosInvitation> invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070087
Yingdi Yu8dacdf22013-11-05 23:06:43 -080088 void
Yingdi Yu42372442013-11-06 18:43:31 -080089 popChatInvitation(ndn::Ptr<ChronosInvitation> invitation,
90 const ndn::Name& inviterNameSpace,
91 ndn::Ptr<ndn::security::IdentityCertificate> certificate);
92
93 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080094 collectEndorsement();
95
96 void
Yingdi Yu42372442013-11-06 18:43:31 -080097 onDnsEndorseeVerified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080098
99 void
Yingdi Yu42372442013-11-06 18:43:31 -0800100 onDnsEndorseeTimeout(ndn::Ptr<ndn::Closure> closure,
Yingdi Yua0594092013-11-06 22:07:38 -0800101 ndn::Ptr<ndn::Interest> interest,
102 int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800103
104 void
Yingdi Yu42372442013-11-06 18:43:31 -0800105 onDnsEndorseeUnverified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800106
107 void
108 updateCollectStatus(int count);
109
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700110 std::string
111 getRandomString();
112
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700113signals:
114 void
115 newInvitationReady();
116
Yingdi Yu908f8412013-11-09 00:03:26 -0800117 void
118 refreshCertDirectory();
119
Yingdi Yu01a942b2013-10-10 15:00:58 -0700120private slots:
121 void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800122 showError(const QString& msg);
123
124 void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800125 showWarning(const QString& msg);
126
127 void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700128 updateSelection(const QItemSelection &selected,
129 const QItemSelection &deselected);
130
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700131 void
Yingdi Yu42372442013-11-06 18:43:31 -0800132 updateDefaultIdentity(const QString& identity,
133 const QString& nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700134
135 void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700136 openProfileEditor();
137
Yingdi Yud59b5932013-10-16 13:16:49 -0700138 void
139 openAddContactPanel();
Yingdi Yu908f8412013-11-09 00:03:26 -0800140
141 void
142 openBrowseContactDialog();
Yingdi Yud59b5932013-10-16 13:16:49 -0700143
Yingdi Yu79c25a22013-10-21 13:38:38 -0700144 void
145 openSetAliasDialog();
Yingdi Yu908f8412013-11-09 00:03:26 -0800146
147 void
148 removeContactButton();
Yingdi Yu100267f2013-10-21 15:01:40 -0700149
150 void
151 openStartChatDialog();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700152
153 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700154 openSettingDialog();
155
156 void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700157 openInvitationDialog();
158
159 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700160 refreshContactList();
161
162 void
163 showContextMenu(const QPoint& pos);
164
Yingdi Yu100267f2013-10-21 15:01:40 -0700165 void
Yingdi Yu42372442013-11-06 18:43:31 -0800166 startChatroom(const QString& chatroom,
167 const QString& invitee,
168 bool isIntroducer);
Yingdi Yu100267f2013-10-21 15:01:40 -0700169
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700170 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700171 startChatroom2(const ChronosInvitation& invitation,
172 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700173
174 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700175 acceptInvitation(const ChronosInvitation& invitation,
176 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700177
178 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700179 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700180
Yingdi Yua50c3252013-11-03 15:05:26 -0800181 void
182 isIntroducerChanged(int state);
183
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800184 void
185 addScopeClicked();
186
187 void
188 deleteScopeClicked();
189
190 void
191 saveScopeClicked();
192
193 void
194 endorseButtonClicked();
Yingdi Yu42372442013-11-06 18:43:31 -0800195
196 void
197 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800198
199
200
Yingdi Yudef90612013-10-09 22:34:42 -0700201private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700202 Ui::ContactPanel *ui;
Yingdi Yub29f78c2013-11-09 20:12:31 -0800203 WarningDialog* m_warningDialog;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700204 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700205 QStringListModel* m_contactListModel;
206 ProfileEditor* m_profileEditor;
Yingdi Yud59b5932013-10-16 13:16:49 -0700207 AddContactPanel* m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800208 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700209 SetAliasDialog* m_setAliasDialog;
Yingdi Yu100267f2013-10-21 15:01:40 -0700210 StartChatDialog* m_startChatDialog;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700211 InvitationDialog* m_invitationDialog;
212 SettingDialog* m_settingDialog;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700213 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700214 QAction* m_menuInvite;
215 QAction* m_menuAlias;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700216 std::vector<ndn::Ptr<ContactItem> > m_contactList;
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800217 ndn::Ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700218
Yingdi Yued8cfc42013-11-01 17:37:51 -0700219 ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700220 ndn::Ptr<ndn::security::Keychain> m_keychain;
221 ndn::Ptr<ndn::Wrapper> m_handler;
222
223 ndn::Name m_defaultIdentity;
Yingdi Yu42372442013-11-06 18:43:31 -0800224 std::string m_nickName;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700225 ndn::Name m_localPrefix;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700226 ndn::Name m_inviteListenPrefix;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700227
Yingdi Yua50c3252013-11-03 15:05:26 -0800228 ndn::Ptr<ContactItem> m_currentSelectedContact;
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800229 QSqlTableModel* m_trustScopeModel;
230 QSqlTableModel* m_endorseDataModel;
231 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yudef90612013-10-09 22:34:42 -0700232};
233
234#endif // CONTACTPANEL_H