blob: f6e794c947820600d2c93b1b4d36faddf68df06c [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 Yu46948282013-11-06 18:43:31 -080044 explicit ContactPanel(ndn::Ptr<ContactManager> contactManager,
45 QWidget *parent = 0);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070046
Yingdi Yu3b318c12013-10-15 17:54:00 -070047 ~ContactPanel();
Yingdi Yu847aa862013-10-09 16:35:53 -070048
Yingdi Yu978b3ae2013-10-23 11:50:51 -070049private:
50 void
Yingdi Yu46948282013-11-06 18:43:31 -080051 createAction();
52
53 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070054 openDB();
55
56 void
57 setKeychain();
58
59 void
60 setLocalPrefix();
61
62 void
63 onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
64
65 void
Yingdi Yu46948282013-11-06 18:43:31 -080066 onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure,
67 ndn::Ptr<ndn::Interest> interest);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070068
69 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070070 setInvitationListener();
71
72 void
73 onInvitation(ndn::Ptr<ndn::Interest> interest);
74
75 void
Yingdi Yu46948282013-11-06 18:43:31 -080076 onUnverified(ndn::Ptr<ndn::Data> data);
77
78 void
79 onTimeout(ndn::Ptr<ndn::Closure> closure,
80 ndn::Ptr<ndn::Interest> interest);
81
82 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070083 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070084 ndn::Ptr<ChronosInvitation> invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -070085
Yingdi Yub2e747d2013-11-05 23:06:43 -080086 void
Yingdi Yu46948282013-11-06 18:43:31 -080087 popChatInvitation(ndn::Ptr<ChronosInvitation> invitation,
88 const ndn::Name& inviterNameSpace,
89 ndn::Ptr<ndn::security::IdentityCertificate> certificate);
90
91 void
Yingdi Yub2e747d2013-11-05 23:06:43 -080092 collectEndorsement();
93
94 void
Yingdi Yu46948282013-11-06 18:43:31 -080095 onDnsEndorseeVerified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -080096
97 void
Yingdi Yu46948282013-11-06 18:43:31 -080098 onDnsEndorseeTimeout(ndn::Ptr<ndn::Closure> closure,
Yingdi Yu83eae842013-11-06 22:07:38 -080099 ndn::Ptr<ndn::Interest> interest,
100 int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800101
102 void
Yingdi Yu46948282013-11-06 18:43:31 -0800103 onDnsEndorseeUnverified(ndn::Ptr<ndn::Data> data, int count);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800104
105 void
106 updateCollectStatus(int count);
107
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700108 std::string
109 getRandomString();
110
Yingdi Yueda39aa2013-10-23 23:07:29 -0700111signals:
112 void
113 newInvitationReady();
114
Yingdi Yu40eca752013-10-10 15:00:58 -0700115private slots:
116 void
117 updateSelection(const QItemSelection &selected,
118 const QItemSelection &deselected);
119
Yingdi Yu3b318c12013-10-15 17:54:00 -0700120 void
Yingdi Yu46948282013-11-06 18:43:31 -0800121 updateDefaultIdentity(const QString& identity,
122 const QString& nickName);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700123
124 void
Yingdi Yu3b318c12013-10-15 17:54:00 -0700125 openProfileEditor();
126
Yingdi Yu0269c872013-10-16 13:16:49 -0700127 void
128 openAddContactPanel();
129
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700130 void
131 openSetAliasDialog();
Yingdi Yu595aadc2013-10-21 15:01:40 -0700132
133 void
134 openStartChatDialog();
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700135
136 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700137 openSettingDialog();
138
139 void
Yingdi Yueda39aa2013-10-23 23:07:29 -0700140 openInvitationDialog();
141
142 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700143 refreshContactList();
144
145 void
146 showContextMenu(const QPoint& pos);
147
Yingdi Yu595aadc2013-10-21 15:01:40 -0700148 void
Yingdi Yu46948282013-11-06 18:43:31 -0800149 startChatroom(const QString& chatroom,
150 const QString& invitee,
151 bool isIntroducer);
Yingdi Yu595aadc2013-10-21 15:01:40 -0700152
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700153 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700154 startChatroom2(const ChronosInvitation& invitation,
155 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700156
157 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700158 acceptInvitation(const ChronosInvitation& invitation,
159 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700160
161 void
Yingdi Yu7989eb22013-10-31 17:38:22 -0700162 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700163
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800164 void
165 isIntroducerChanged(int state);
166
Yingdi Yub2e747d2013-11-05 23:06:43 -0800167 void
168 addScopeClicked();
169
170 void
171 deleteScopeClicked();
172
173 void
174 saveScopeClicked();
175
176 void
177 endorseButtonClicked();
Yingdi Yu46948282013-11-06 18:43:31 -0800178
179 void
180 removeChatDialog(const ndn::Name& chatroomName);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800181
182
183
Yingdi Yu847aa862013-10-09 16:35:53 -0700184private:
Yingdi Yu3b318c12013-10-15 17:54:00 -0700185 Ui::ContactPanel *ui;
Yingdi Yu9236c432013-10-18 11:29:25 -0700186 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu3b318c12013-10-15 17:54:00 -0700187 QStringListModel* m_contactListModel;
188 ProfileEditor* m_profileEditor;
Yingdi Yu0269c872013-10-16 13:16:49 -0700189 AddContactPanel* m_addContactPanel;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700190 SetAliasDialog* m_setAliasDialog;
Yingdi Yu595aadc2013-10-21 15:01:40 -0700191 StartChatDialog* m_startChatDialog;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700192 InvitationDialog* m_invitationDialog;
193 SettingDialog* m_settingDialog;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700194 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700195 QAction* m_menuInvite;
196 QAction* m_menuAlias;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700197 std::vector<ndn::Ptr<ContactItem> > m_contactList;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800198 ndn::Ptr<std::vector<bool> > m_collectStatus;
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700199
Yingdi Yu9b34b1f2013-11-01 17:37:51 -0700200 ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700201 ndn::Ptr<ndn::security::Keychain> m_keychain;
202 ndn::Ptr<ndn::Wrapper> m_handler;
203
204 ndn::Name m_defaultIdentity;
Yingdi Yu46948282013-11-06 18:43:31 -0800205 std::string m_nickName;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700206 ndn::Name m_localPrefix;
Yingdi Yueda39aa2013-10-23 23:07:29 -0700207 ndn::Name m_inviteListenPrefix;
Yingdi Yu978b3ae2013-10-23 11:50:51 -0700208
Yingdi Yuec5e72a2013-11-03 15:05:26 -0800209 ndn::Ptr<ContactItem> m_currentSelectedContact;
Yingdi Yub2e747d2013-11-05 23:06:43 -0800210 QSqlTableModel* m_trustScopeModel;
211 QSqlTableModel* m_endorseDataModel;
212 EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
Yingdi Yu847aa862013-10-09 16:35:53 -0700213};
214
215#endif // CONTACTPANEL_H