blob: 222bf0b8908507275d712a6f6284cb28fba80df2 [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 Yu3b318c12013-10-15 17:54:00 -070018
19#include "profileeditor.h"
Yingdi Yu0269c872013-10-16 13:16:49 -070020#include "addcontactpanel.h"
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070021#include "setaliasdialog.h"
Yingdi Yu595aadc2013-10-21 15:01:40 -070022#include "startchatdialog.h"
Yingdi Yu978b3ae2013-10-23 11:50:51 -070023#include "invitationdialog.h"
24#include "settingdialog.h"
Yingdi Yueda39aa2013-10-23 23:07:29 -070025#include "chatdialog.h"
Yingdi Yub2e747d2013-11-05 23:06:43 -080026#include "endorse-combobox-delegate.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070027
28#ifndef Q_MOC_RUN
Yingdi Yu9236c432013-10-18 11:29:25 -070029#include "contact-manager.h"
Yingdi Yu7989eb22013-10-31 17:38:22 -070030#include "chronos-invitation.h"
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070031#include "panel-policy-manager.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070032#endif
Yingdi Yu847aa862013-10-09 16:35:53 -070033
Yingdi Yu978b3ae2013-10-23 11:50:51 -070034
Yingdi Yu847aa862013-10-09 16:35:53 -070035namespace Ui {
36class ContactPanel;
37}
38
39class ContactPanel : public QDialog
40{
Yingdi Yueda39aa2013-10-23 23:07:29 -070041 Q_OBJECT
Yingdi Yu847aa862013-10-09 16:35:53 -070042
43public:
Yingdi Yu9236c432013-10-18 11:29:25 -070044 explicit ContactPanel(ndn::Ptr<ContactManager> contactManager, QWidget *parent = 0);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070045
Yingdi Yu3b318c12013-10-15 17:54:00 -070046 ~ContactPanel();
Yingdi Yu847aa862013-10-09 16:35:53 -070047
Yingdi Yu978b3ae2013-10-23 11:50:51 -070048private:
49 void
50 openDB();
51
52 void
53 setKeychain();
54
55 void
56 setLocalPrefix();
57
58 void
59 onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
60
61 void
62 onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest);
63
64 void
65 onUnverified(ndn::Ptr<ndn::Data> data);
66
67 void
68 onTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest);
69
70 void
71 setInvitationListener();
72
73 void
74 onInvitation(ndn::Ptr<ndn::Interest> interest);
75
76 void
77 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070078 ndn::Ptr<ChronosInvitation> invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070079
Yingdi Yub2e747d2013-11-05 23:06:43 -080080 void
81 collectEndorsement();
82
83 void
84 onDnsEndoreeVerified(ndn::Ptr<ndn::Data> data, int count);
85
86 void
87 onDnsEndoreeTimeout(ndn::Ptr<ndn::Closure> closure,
88 ndn::Ptr<ndn::Interest> interest,
89 int count);
90
91 void
92 onDnsEndoreeUnverified(ndn::Ptr<ndn::Data> data, int count);
93
94 void
95 updateCollectStatus(int count);
96
Yingdi Yu978b3ae2013-10-23 11:50:51 -070097 std::string
98 getRandomString();
99
100 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700101 popChatInvitation(ndn::Ptr<ChronosInvitation> invitation,
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700102 const ndn::Name& inviterNameSpace,
103 ndn::Ptr<ndn::security::IdentityCertificate> certificate);
104
Yingdi Yueda39aa2013-10-23 23:07:29 -0700105signals:
106 void
107 newInvitationReady();
108
Yingdi Yu40eca752013-10-10 15:00:58 -0700109private slots:
110 void
111 updateSelection(const QItemSelection &selected,
112 const QItemSelection &deselected);
113
Yingdi Yu3b318c12013-10-15 17:54:00 -0700114 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700115 updateDefaultIdentity(const QString& identity);
116
117 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700118 openProfileEditor();
119
Yingdi Yu0269c872013-10-16 13:16:49 -0700120 void
121 openAddContactPanel();
122
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700123 void
124 openSetAliasDialog();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700125
126 void
127 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700128
129 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700130 openSettingDialog();
131
132 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700133 openInvitationDialog();
134
135 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700136 refreshContactList();
137
138 void
139 showContextMenu(const QPoint& pos);
140
Yingdi Yu595aadc2013-10-21 15:01:40 -0700141 void
142 startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer);
143
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700144 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700145 startChatroom2(const ChronosInvitation& invitation,
146 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700147
148 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700149 acceptInvitation(const ChronosInvitation& invitation,
150 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700151
152 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700153 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700154
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800155 void
156 isIntroducerChanged(int state);
157
Yingdi Yub2e747d2013-11-05 23:06:43 -0800158 void
159 addScopeClicked();
160
161 void
162 deleteScopeClicked();
163
164 void
165 saveScopeClicked();
166
167 void
168 endorseButtonClicked();
169
170
171
Yingdi Yu847aa862013-10-09 16:35:53 -0700172private:
Yingdi Yu3b318c12013-10-15 17:54:00 -0700173 Ui::ContactPanel *ui;
Yingdi Yu9236c432013-10-18 11:29:25 -0700174 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700175 QStringListModel* m_contactListModel;
176 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700177 AddContactPanel* m_addContactPanel;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700178 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700179 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700180 InvitationDialog* m_invitationDialog;
181 SettingDialog* m_settingDialog;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700182 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700183 QAction* m_menuInvite;
184 QAction* m_menuAlias;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700185 std::vector<ndn::Ptr<ContactItem> > m_contactList;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800186 ndn::Ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700187
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700188 ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700189 ndn::Ptr<ndn::security::Keychain> m_keychain;
190 ndn::Ptr<ndn::Wrapper> m_handler;
191
192 ndn::Name m_defaultIdentity;
193 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700194 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700195
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800196 // std::string m_currentSelectedContactAlias;
197 // std::string m_currentSelectedContactNamespace;
198 ndn::Ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800199 QSqlTableModel* m_trustScopeModel;
200 QSqlTableModel* m_endorseDataModel;
201 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700202
203
Yingdi Yu847aa862013-10-09 16:35:53 -0700204};
205
206#endif // CONTACTPANEL_H