blob: b171e54f7c54498a39ca278582cfd316c0f0235d [file] [log] [blame]
Yingdi Yu847aa862013-10-09 16:35:53 -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
11#ifndef CONTACTPANEL_H
12#define CONTACTPANEL_H
13
14#include <QDialog>
Yingdi Yu40eca752013-10-10 15:00:58 -070015#include <QStringListModel>
Yingdi Yu3b318c12013-10-15 17:54:00 -070016#include <QtSql/QSqlDatabase>
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070017#include <QMenu>
Yingdi Yu8e135832013-11-09 20:12:31 -080018#include <QMessageBox>
Yingdi Yu3b318c12013-10-15 17:54:00 -070019
20#include "profileeditor.h"
Yingdi Yu0269c872013-10-16 13:16:49 -070021#include "addcontactpanel.h"
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070022#include "setaliasdialog.h"
Yingdi Yu595aadc2013-10-21 15:01:40 -070023#include "startchatdialog.h"
Yingdi Yu978b3ae2013-10-23 11:50:51 -070024#include "invitationdialog.h"
25#include "settingdialog.h"
Yingdi Yueda39aa2013-10-23 23:07:29 -070026#include "chatdialog.h"
Yingdi Yub2e747d2013-11-05 23:06:43 -080027#include "endorse-combobox-delegate.h"
Yingdi Yuae8217c2013-11-09 00:03:26 -080028#include "browsecontactdialog.h"
Yingdi Yub5a0fd32013-11-10 16:26:52 -080029#include "warningdialog.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070030
31#ifndef Q_MOC_RUN
Yingdi Yu9236c432013-10-18 11:29:25 -070032#include "contact-manager.h"
Yingdi Yu7989eb22013-10-31 17:38:22 -070033#include "chronos-invitation.h"
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070034#include "panel-policy-manager.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070035#endif
Yingdi Yu847aa862013-10-09 16:35:53 -070036
Yingdi Yu978b3ae2013-10-23 11:50:51 -070037
Yingdi Yu847aa862013-10-09 16:35:53 -070038namespace Ui {
39class ContactPanel;
40}
41
42class ContactPanel : public QDialog
43{
Yingdi Yueda39aa2013-10-23 23:07:29 -070044 Q_OBJECT
Yingdi Yu847aa862013-10-09 16:35:53 -070045
46public:
Yingdi Yu8e135832013-11-09 20:12:31 -080047 explicit ContactPanel(QWidget *parent = 0);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070048
Yingdi Yu3b318c12013-10-15 17:54:00 -070049 ~ContactPanel();
Yingdi Yu847aa862013-10-09 16:35:53 -070050
Yingdi Yu978b3ae2013-10-23 11:50:51 -070051private:
52 void
Yingdi Yu46948282013-11-06 18:43:31 -080053 createAction();
54
55 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070056 openDB();
57
58 void
59 setKeychain();
60
61 void
Yingdi Yufdb8ab82013-11-10 01:38:21 -080062 setLocalPrefix(int retry = 10);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070063
64 void
65 onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
66
67 void
Yingdi Yu46948282013-11-06 18:43:31 -080068 onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure,
Yingdi Yufdb8ab82013-11-10 01:38:21 -080069 ndn::Ptr<ndn::Interest> interest,
70 int retry);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070071
72 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070073 setInvitationListener();
74
75 void
76 onInvitation(ndn::Ptr<ndn::Interest> interest);
77
78 void
Yingdi Yu46948282013-11-06 18:43:31 -080079 onUnverified(ndn::Ptr<ndn::Data> data);
80
81 void
82 onTimeout(ndn::Ptr<ndn::Closure> closure,
83 ndn::Ptr<ndn::Interest> interest);
84
85 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070086 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070087 ndn::Ptr<ChronosInvitation> invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070088
Yingdi Yub2e747d2013-11-05 23:06:43 -080089 void
Yingdi Yu46948282013-11-06 18:43:31 -080090 popChatInvitation(ndn::Ptr<ChronosInvitation> invitation,
91 const ndn::Name& inviterNameSpace,
92 ndn::Ptr<ndn::security::IdentityCertificate> certificate);
93
94 void
Yingdi Yub2e747d2013-11-05 23:06:43 -080095 collectEndorsement();
96
97 void
Yingdi Yu46948282013-11-06 18:43:31 -080098 onDnsEndorseeVerified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -080099
100 void
Yingdi Yu46948282013-11-06 18:43:31 -0800101 onDnsEndorseeTimeout(ndn::Ptr<ndn::Closure> closure,
Yingdi Yu83eae842013-11-06 22:07:38 -0800102 ndn::Ptr<ndn::Interest> interest,
103 int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800104
105 void
Yingdi Yu46948282013-11-06 18:43:31 -0800106 onDnsEndorseeUnverified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800107
108 void
109 updateCollectStatus(int count);
110
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700111 std::string
112 getRandomString();
113
Yingdi Yueda39aa2013-10-23 23:07:29 -0700114signals:
115 void
116 newInvitationReady();
117
Yingdi Yuae8217c2013-11-09 00:03:26 -0800118 void
119 refreshCertDirectory();
120
Yingdi Yu40eca752013-10-10 15:00:58 -0700121private slots:
122 void
Yingdi Yu8e135832013-11-09 20:12:31 -0800123 showError(const QString& msg);
124
125 void
Yingdi Yue433a502013-11-10 01:34:57 -0800126 showWarning(const QString& msg);
127
128 void
Yingdi Yu40eca752013-10-10 15:00:58 -0700129 updateSelection(const QItemSelection &selected,
130 const QItemSelection &deselected);
131
Yingdi Yu3b318c12013-10-15 17:54:00 -0700132 void
Yingdi Yu46948282013-11-06 18:43:31 -0800133 updateDefaultIdentity(const QString& identity,
134 const QString& nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700135
136 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700137 openProfileEditor();
138
Yingdi Yu0269c872013-10-16 13:16:49 -0700139 void
140 openAddContactPanel();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800141
142 void
143 openBrowseContactDialog();
Yingdi Yu0269c872013-10-16 13:16:49 -0700144
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700145 void
146 openSetAliasDialog();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800147
148 void
149 removeContactButton();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700150
151 void
152 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700153
154 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700155 openSettingDialog();
156
157 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700158 openInvitationDialog();
159
160 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700161 refreshContactList();
162
163 void
164 showContextMenu(const QPoint& pos);
165
Yingdi Yu595aadc2013-10-21 15:01:40 -0700166 void
Yingdi Yu46948282013-11-06 18:43:31 -0800167 startChatroom(const QString& chatroom,
168 const QString& invitee,
169 bool isIntroducer);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700170
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700171 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700172 startChatroom2(const ChronosInvitation& invitation,
173 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700174
175 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700176 acceptInvitation(const ChronosInvitation& invitation,
177 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700178
179 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700180 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700181
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800182 void
183 isIntroducerChanged(int state);
184
Yingdi Yub2e747d2013-11-05 23:06:43 -0800185 void
186 addScopeClicked();
187
188 void
189 deleteScopeClicked();
190
191 void
192 saveScopeClicked();
193
194 void
195 endorseButtonClicked();
Yingdi Yu46948282013-11-06 18:43:31 -0800196
197 void
198 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800199
Yingdi Yu72232692013-11-12 17:50:21 -0800200 void
201 addContactIntoPanelPolicy(const ndn::Name& nameSpace);
202
203 void
204 removeContactFromPanelPolicy(const ndn::Name& keyName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800205
206
Yingdi Yu847aa862013-10-09 16:35:53 -0700207private:
Yingdi Yu3b318c12013-10-15 17:54:00 -0700208 Ui::ContactPanel *ui;
Yingdi Yu8e135832013-11-09 20:12:31 -0800209 WarningDialog* m_warningDialog;
Yingdi Yu9236c432013-10-18 11:29:25 -0700210 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700211 QStringListModel* m_contactListModel;
212 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700213 AddContactPanel* m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800214 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700215 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700216 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700217 InvitationDialog* m_invitationDialog;
218 SettingDialog* m_settingDialog;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700219 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700220 QAction* m_menuInvite;
221 QAction* m_menuAlias;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700222 std::vector<ndn::Ptr<ContactItem> > m_contactList;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800223 ndn::Ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700224
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700225 ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700226 ndn::Ptr<ndn::security::Keychain> m_keychain;
227 ndn::Ptr<ndn::Wrapper> m_handler;
228
229 ndn::Name m_defaultIdentity;
Yingdi Yu46948282013-11-06 18:43:31 -0800230 std::string m_nickName;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700231 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700232 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700233
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800234 ndn::Ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800235 QSqlTableModel* m_trustScopeModel;
236 QSqlTableModel* m_endorseDataModel;
237 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu847aa862013-10-09 16:35:53 -0700238};
239
240#endif // CONTACTPANEL_H