blob: 92bccf3930d104476d77dd249fc51f3644b8cfda [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 Yu8e135832013-11-09 20:12:31 -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
62 setLocalPrefix();
63
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,
69 ndn::Ptr<ndn::Interest> interest);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070070
71 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070072 setInvitationListener();
73
74 void
75 onInvitation(ndn::Ptr<ndn::Interest> interest);
76
77 void
Yingdi Yu46948282013-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 Yu978b3ae2013-10-23 11:50:51 -070085 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070086 ndn::Ptr<ChronosInvitation> invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070087
Yingdi Yub2e747d2013-11-05 23:06:43 -080088 void
Yingdi Yu46948282013-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 Yub2e747d2013-11-05 23:06:43 -080094 collectEndorsement();
95
96 void
Yingdi Yu46948282013-11-06 18:43:31 -080097 onDnsEndorseeVerified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -080098
99 void
Yingdi Yu46948282013-11-06 18:43:31 -0800100 onDnsEndorseeTimeout(ndn::Ptr<ndn::Closure> closure,
Yingdi Yu83eae842013-11-06 22:07:38 -0800101 ndn::Ptr<ndn::Interest> interest,
102 int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800103
104 void
Yingdi Yu46948282013-11-06 18:43:31 -0800105 onDnsEndorseeUnverified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800106
107 void
108 updateCollectStatus(int count);
109
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700110 std::string
111 getRandomString();
112
Yingdi Yueda39aa2013-10-23 23:07:29 -0700113signals:
114 void
115 newInvitationReady();
116
Yingdi Yuae8217c2013-11-09 00:03:26 -0800117 void
118 refreshCertDirectory();
119
Yingdi Yu40eca752013-10-10 15:00:58 -0700120private slots:
121 void
Yingdi Yu8e135832013-11-09 20:12:31 -0800122 showError(const QString& msg);
123
124 void
Yingdi Yu40eca752013-10-10 15:00:58 -0700125 updateSelection(const QItemSelection &selected,
126 const QItemSelection &deselected);
127
Yingdi Yu3b318c12013-10-15 17:54:00 -0700128 void
Yingdi Yu46948282013-11-06 18:43:31 -0800129 updateDefaultIdentity(const QString& identity,
130 const QString& nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700131
132 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700133 openProfileEditor();
134
Yingdi Yu0269c872013-10-16 13:16:49 -0700135 void
136 openAddContactPanel();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800137
138 void
139 openBrowseContactDialog();
Yingdi Yu0269c872013-10-16 13:16:49 -0700140
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700141 void
142 openSetAliasDialog();
Yingdi Yuae8217c2013-11-09 00:03:26 -0800143
144 void
145 removeContactButton();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700146
147 void
148 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700149
150 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700151 openSettingDialog();
152
153 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700154 openInvitationDialog();
155
156 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700157 refreshContactList();
158
159 void
160 showContextMenu(const QPoint& pos);
161
Yingdi Yu595aadc2013-10-21 15:01:40 -0700162 void
Yingdi Yu46948282013-11-06 18:43:31 -0800163 startChatroom(const QString& chatroom,
164 const QString& invitee,
165 bool isIntroducer);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700166
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700167 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700168 startChatroom2(const ChronosInvitation& invitation,
169 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700170
171 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700172 acceptInvitation(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 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700177
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800178 void
179 isIntroducerChanged(int state);
180
Yingdi Yub2e747d2013-11-05 23:06:43 -0800181 void
182 addScopeClicked();
183
184 void
185 deleteScopeClicked();
186
187 void
188 saveScopeClicked();
189
190 void
191 endorseButtonClicked();
Yingdi Yu46948282013-11-06 18:43:31 -0800192
193 void
194 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800195
196
197
Yingdi Yu847aa862013-10-09 16:35:53 -0700198private:
Yingdi Yu3b318c12013-10-15 17:54:00 -0700199 Ui::ContactPanel *ui;
Yingdi Yu8e135832013-11-09 20:12:31 -0800200 WarningDialog* m_warningDialog;
Yingdi Yu9236c432013-10-18 11:29:25 -0700201 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700202 QStringListModel* m_contactListModel;
203 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700204 AddContactPanel* m_addContactPanel;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800205 BrowseContactDialog* m_browseContactDialog;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700206 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700207 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700208 InvitationDialog* m_invitationDialog;
209 SettingDialog* m_settingDialog;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700210 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700211 QAction* m_menuInvite;
212 QAction* m_menuAlias;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700213 std::vector<ndn::Ptr<ContactItem> > m_contactList;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800214 ndn::Ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700215
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700216 ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700217 ndn::Ptr<ndn::security::Keychain> m_keychain;
218 ndn::Ptr<ndn::Wrapper> m_handler;
219
220 ndn::Name m_defaultIdentity;
Yingdi Yu46948282013-11-06 18:43:31 -0800221 std::string m_nickName;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700222 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700223 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700224
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800225 ndn::Ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800226 QSqlTableModel* m_trustScopeModel;
227 QSqlTableModel* m_endorseDataModel;
228 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu847aa862013-10-09 16:35:53 -0700229};
230
231#endif // CONTACTPANEL_H