blob: 5f595b05039aa9e6e9e2b9a5b26dcc1f1d67cff5 [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 Yu42f66462013-10-31 17:38:22 -070029#include "chronos-invitation.h"
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070030#endif
Yingdi Yudef90612013-10-09 22:34:42 -070031
Yingdi Yu53eb8a72013-10-23 11:50:51 -070032
Yingdi Yudef90612013-10-09 22:34:42 -070033namespace Ui {
34class ContactPanel;
35}
36
37class ContactPanel : public QDialog
38{
Yingdi Yuc4d08d22013-10-23 23:07:29 -070039 Q_OBJECT
Yingdi Yudef90612013-10-09 22:34:42 -070040
41public:
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070042 explicit ContactPanel(ndn::Ptr<ContactManager> contactManager, QWidget *parent = 0);
Yingdi Yu53eb8a72013-10-23 11:50:51 -070043
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070044 ~ContactPanel();
Yingdi Yudef90612013-10-09 22:34:42 -070045
Yingdi Yu53eb8a72013-10-23 11:50:51 -070046private:
47 void
48 openDB();
49
50 void
51 setKeychain();
52
53 void
54 setLocalPrefix();
55
56 void
57 onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
58
59 void
60 onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest);
61
62 void
63 onUnverified(ndn::Ptr<ndn::Data> data);
64
65 void
66 onTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest);
67
68 void
69 setInvitationListener();
70
71 void
72 onInvitation(ndn::Ptr<ndn::Interest> interest);
73
74 void
75 onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
76 const ndn::Name& interestName,
77 int inviterIndex);
78
79 std::string
80 getRandomString();
81
82 void
Yingdi Yu42f66462013-10-31 17:38:22 -070083 popChatInvitation(ndn::Ptr<ChronosInvitation> invitation,
Yingdi Yu53eb8a72013-10-23 11:50:51 -070084 int inviterIndex,
85 const ndn::Name& inviterNameSpace,
86 ndn::Ptr<ndn::security::IdentityCertificate> certificate);
87
Yingdi Yuc4d08d22013-10-23 23:07:29 -070088signals:
89 void
90 newInvitationReady();
91
Yingdi Yu01a942b2013-10-10 15:00:58 -070092private slots:
93 void
94 updateSelection(const QItemSelection &selected,
95 const QItemSelection &deselected);
96
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070097 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -070098 updateDefaultIdentity(const QString& identity);
99
100 void
Yingdi Yu0a6b6c52013-10-15 17:54:00 -0700101 openProfileEditor();
102
Yingdi Yud59b5932013-10-16 13:16:49 -0700103 void
104 openAddContactPanel();
105
Yingdi Yu79c25a22013-10-21 13:38:38 -0700106 void
107 openSetAliasDialog();
Yingdi Yu100267f2013-10-21 15:01:40 -0700108
109 void
110 openStartChatDialog();
Yingdi Yu79c25a22013-10-21 13:38:38 -0700111
112 void
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700113 openSettingDialog();
114
115 void
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700116 openInvitationDialog();
117
118 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700119 refreshContactList();
120
121 void
122 showContextMenu(const QPoint& pos);
123
Yingdi Yu100267f2013-10-21 15:01:40 -0700124 void
125 startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer);
126
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700127 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700128 startChatroom2(const ChronosInvitation& invitation,
129 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700130
131 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700132 acceptInvitation(const ChronosInvitation& invitation,
133 const ndn::security::IdentityCertificate& identityCertificate);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700134
135 void
Yingdi Yu42f66462013-10-31 17:38:22 -0700136 rejectInvitation(const ChronosInvitation& invitation);
Yingdi Yu53eb8a72013-10-23 11:50:51 -0700137
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