blob: d36e547c796dcbdb7689654db1ae117fb5779d65 [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 Yu10436892013-11-10 16:26:52 -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
Yingdi Yu2ab22e72013-11-10 01:38:21 -080062 setLocalPrefix(int retry = 10);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070063
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,
Yingdi Yu2ab22e72013-11-10 01:38:21 -080069 ndn::Ptr<ndn::Interest> interest,
70 int retry);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070071
72 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070073 setInvitationListener();
74
75 void
76 onInvitation(ndn::Ptr<ndn::Interest> interest);
77
78 void
Yingdi Yu42372442013-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 Yu53eb8a72013-10-23 11:50:51 -070086 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
Yingdi Yued8cfc42013-11-01 17:37:51 -070087 ndn::Ptr<ChronosInvitation> invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070088
Yingdi Yu8dacdf22013-11-05 23:06:43 -080089 void
Yingdi Yu42372442013-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 Yu8dacdf22013-11-05 23:06:43 -080095 collectEndorsement();
96
97 void
Yingdi Yu42372442013-11-06 18:43:31 -080098 onDnsEndorseeVerified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080099
100 void
Yingdi Yu42372442013-11-06 18:43:31 -0800101 onDnsEndorseeTimeout(ndn::Ptr<ndn::Closure> closure,
Yingdi Yua0594092013-11-06 22:07:38 -0800102 ndn::Ptr<ndn::Interest> interest,
103 int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800104
105 void
Yingdi Yu42372442013-11-06 18:43:31 -0800106 onDnsEndorseeUnverified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800107
108 void
109 updateCollectStatus(int count);
110
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700111 std::string
112 getRandomString();
113
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700114signals:
115 void
116 newInvitationReady();
117
Yingdi Yu908f8412013-11-09 00:03:26 -0800118 void
119 refreshCertDirectory();
120
Yingdi Yu01a942b2013-10-10 15:00:58 -0700121private slots:
122 void
Yingdi Yub29f78c2013-11-09 20:12:31 -0800123 showError(const QString& msg);
124
125 void
Yingdi Yueb98f7d2013-11-10 01:34:57 -0800126 showWarning(const QString& msg);
127
128 void
Yingdi Yu01a942b2013-10-10 15:00:58 -0700129 updateSelection(const QItemSelection &selected,
130 const QItemSelection &deselected);
131
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700132 void
Yingdi Yu42372442013-11-06 18:43:31 -0800133 updateDefaultIdentity(const QString& identity,
134 const QString& nickName);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700135
136 void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700137 openProfileEditor();
138
Yingdi Yud59b5932013-10-16 13:16:49 -0700139 void
140 openAddContactPanel();
Yingdi Yu908f8412013-11-09 00:03:26 -0800141
142 void
143 openBrowseContactDialog();
Yingdi Yud59b5932013-10-16 13:16:49 -0700144
Yingdi Yu79c25a22013-10-21 13:38:38 -0700145 void
146 openSetAliasDialog();
Yingdi Yu908f8412013-11-09 00:03:26 -0800147
148 void
149 removeContactButton();
Yingdi Yu100267f2013-10-21 15:01:40 -0700150
151 void
152 openStartChatDialog();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700153
154 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700155 openSettingDialog();
156
157 void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700158 openInvitationDialog();
159
160 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700161 refreshContactList();
162
163 void
164 showContextMenu(const QPoint& pos);
165
Yingdi Yu100267f2013-10-21 15:01:40 -0700166 void
Yingdi Yu42372442013-11-06 18:43:31 -0800167 startChatroom(const QString& chatroom,
168 const QString& invitee,
169 bool isIntroducer);
Yingdi Yu100267f2013-10-21 15:01:40 -0700170
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700171 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700172 startChatroom2(const ChronosInvitation& invitation,
173 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700174
175 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700176 acceptInvitation(const ChronosInvitation& invitation,
177 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700178
179 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700180 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700181
Yingdi Yua50c3252013-11-03 15:05:26 -0800182 void
183 isIntroducerChanged(int state);
184
Yingdi Yu8dacdf22013-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 Yu42372442013-11-06 18:43:31 -0800196
197 void
198 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800199
200
201
Yingdi Yudef90612013-10-09 22:34:42 -0700202private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700203 Ui::ContactPanel *ui;
Yingdi Yub29f78c2013-11-09 20:12:31 -0800204 WarningDialog* m_warningDialog;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700205 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700206 QStringListModel* m_contactListModel;
207 ProfileEditor* m_profileEditor;
Yingdi Yud59b5932013-10-16 13:16:49 -0700208 AddContactPanel* m_addContactPanel;
Yingdi Yu908f8412013-11-09 00:03:26 -0800209 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700210 SetAliasDialog* m_setAliasDialog;
Yingdi Yu100267f2013-10-21 15:01:40 -0700211 StartChatDialog* m_startChatDialog;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700212 InvitationDialog* m_invitationDialog;
213 SettingDialog* m_settingDialog;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700214 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700215 QAction* m_menuInvite;
216 QAction* m_menuAlias;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700217 std::vector<ndn::Ptr<ContactItem> > m_contactList;
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800218 ndn::Ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700219
Yingdi Yued8cfc42013-11-01 17:37:51 -0700220 ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700221 ndn::Ptr<ndn::security::Keychain> m_keychain;
222 ndn::Ptr<ndn::Wrapper> m_handler;
223
224 ndn::Name m_defaultIdentity;
Yingdi Yu42372442013-11-06 18:43:31 -0800225 std::string m_nickName;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700226 ndn::Name m_localPrefix;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700227 ndn::Name m_inviteListenPrefix;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700228
Yingdi Yua50c3252013-11-03 15:05:26 -0800229 ndn::Ptr<ContactItem> m_currentSelectedContact;
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800230 QSqlTableModel* m_trustScopeModel;
231 QSqlTableModel* m_endorseDataModel;
232 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yudef90612013-10-09 22:34:42 -0700233};
234
235#endif // CONTACTPANEL_H