blob: 2f33b4923d399fa8a1209e08f1728f6b482d2aaa [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 Yu0a6b6c52013-10-15 17:54:00 -070018
19#include "profileeditor.h"
Yingdi Yud59b5932013-10-16 13:16:49 -070020#include "addcontactpanel.h"
Yingdi Yu79c25a22013-10-21 13:38:38 -070021#include "setaliasdialog.h"
Yingdi Yu100267f2013-10-21 15:01:40 -070022#include "startchatdialog.h"
Yingdi Yu53eb8a72013-10-23 11:50:51 -070023#include "invitationdialog.h"
24#include "settingdialog.h"
Yingdi Yuc4d08d22013-10-23 23:07:29 -070025#include "chatdialog.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070026
27#ifndef Q_MOC_RUN
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070028#include "contact-manager.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070029#endif
Yingdi Yudef90612013-10-09 22:34:42 -070030
Yingdi Yu53eb8a72013-10-23 11:50:51 -070031
Yingdi Yudef90612013-10-09 22:34:42 -070032namespace Ui {
33class ContactPanel;
34}
35
36class ContactPanel : public QDialog
37{
Yingdi Yuc4d08d22013-10-23 23:07:29 -070038 Q_OBJECT
Yingdi Yudef90612013-10-09 22:34:42 -070039
40public:
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070041 explicit ContactPanel(ndn::Ptr<ContactManager> contactManager, QWidget *parent = 0);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070042
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070043 ~ContactPanel();
Yingdi Yudef90612013-10-09 22:34:42 -070044
Yingdi Yu53eb8a72013-10-23 11:50:51 -070045private:
46 void
47 openDB();
48
49 void
50 setKeychain();
51
52 void
53 setLocalPrefix();
54
55 void
56 onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
57
58 void
59 onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest);
60
61 void
62 onUnverified(ndn::Ptr<ndn::Data> data);
63
64 void
65 onTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest);
66
67 void
68 setInvitationListener();
69
70 void
71 onInvitation(ndn::Ptr<ndn::Interest> interest);
72
73 void
74 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
75 const ndn::Name& interestName,
76 int inviterIndex);
77
78 std::string
79 getRandomString();
80
81 void
82 popChatInvitation(const ndn::Name& interestName,
83 int inviterIndex,
84 const ndn::Name& inviterNameSpace,
85 ndn::Ptr<ndn::security::IdentityCertificate> certificate);
86
Yingdi Yuc4d08d22013-10-23 23:07:29 -070087signals:
88 void
89 newInvitationReady();
90
Yingdi Yu01a942b2013-10-10 15:00:58 -070091private slots:
92 void
93 updateSelection(const QItemSelection &selected,
94 const QItemSelection &deselected);
95
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070096 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070097 updateDefaultIdentity(const QString& identity);
98
99 void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700100 openProfileEditor();
101
Yingdi Yud59b5932013-10-16 13:16:49 -0700102 void
103 openAddContactPanel();
104
Yingdi Yu79c25a22013-10-21 13:38:38 -0700105 void
106 openSetAliasDialog();
Yingdi Yu100267f2013-10-21 15:01:40 -0700107
108 void
109 openStartChatDialog();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700110
111 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700112 openSettingDialog();
113
114 void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700115 openInvitationDialog();
116
117 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700118 refreshContactList();
119
120 void
121 showContextMenu(const QPoint& pos);
122
Yingdi Yu100267f2013-10-21 15:01:40 -0700123 void
124 startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer);
125
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700126 void
127 startChatroom2(const QString& chatroom, const QString& inviter);
128
129 void
130 acceptInvitation(const ndn::Name& interestName,
131 const ndn::security::IdentityCertificate& identityCertificate,
132 QString inviter,
133 QString chatroom);
134
135 void
136 rejectInvitation(const ndn::Name& interestName);
137
Yingdi Yudef90612013-10-09 22:34:42 -0700138private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700139 Ui::ContactPanel *ui;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700140 ndn::Ptr<ContactManager> m_contactManager;
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700141 QStringListModel* m_contactListModel;
142 ProfileEditor* m_profileEditor;
Yingdi Yud59b5932013-10-16 13:16:49 -0700143 AddContactPanel* m_addContactPanel;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700144 SetAliasDialog* m_setAliasDialog;
Yingdi Yu100267f2013-10-21 15:01:40 -0700145 StartChatDialog* m_startChatDialog;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700146 InvitationDialog* m_invitationDialog;
147 SettingDialog* m_settingDialog;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700148 std::map<ndn::Name, ChatDialog*> m_chatDialogs;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700149 QAction* m_menuInvite;
150 QAction* m_menuAlias;
Yingdi Yu79c25a22013-10-21 13:38:38 -0700151 std::vector<ndn::Ptr<ContactItem> > m_contactList;
152
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700153 ndn::Ptr<ndn::security::Keychain> m_keychain;
154 ndn::Ptr<ndn::Wrapper> m_handler;
155
156 ndn::Name m_defaultIdentity;
157 ndn::Name m_localPrefix;
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700158 ndn::Name m_inviteListenPrefix;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700159
Yingdi Yu100267f2013-10-21 15:01:40 -0700160 std::string m_currentSelectedContactAlias;
161 std::string m_currentSelectedContactNamespace;
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700162
163
Yingdi Yudef90612013-10-09 22:34:42 -0700164};
165
166#endif // CONTACTPANEL_H