blob: 1f74bc1686447f533454f63cae9c9008596ea8f7 [file] [log] [blame]
Yingdi Yuae8217c2013-11-09 00:03:26 -08001/* -*- 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
12#ifndef BROWSECONTACTDIALOG_H
13#define BROWSECONTACTDIALOG_H
14
15#include <QDialog>
16#include <QStringListModel>
Yingdi Yue433a502013-11-10 01:34:57 -080017#include <QCloseEvent>
Yingdi Yuae8217c2013-11-09 00:03:26 -080018#include "warningdialog.h"
19
20
21#ifndef Q_MOC_RUN
Yingdi Yu76dd8002013-12-24 11:16:32 +080022#include <ndn-cpp/security/certificate/identity-certificate.hpp>
Yingdi Yuae8217c2013-11-09 00:03:26 -080023#include <boost/thread/locks.hpp>
24#include <boost/thread/recursive_mutex.hpp>
25#include "profile.h"
26#include "contact-manager.h"
27#endif
28
29namespace Ui {
30class BrowseContactDialog;
31}
32
33class BrowseContactDialog : public QDialog
34{
35 Q_OBJECT
36
37public:
Yingdi Yu76dd8002013-12-24 11:16:32 +080038 explicit BrowseContactDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
Yingdi Yuae8217c2013-11-09 00:03:26 -080039 QWidget *parent = 0);
40
41 ~BrowseContactDialog();
42
43protected:
44 typedef boost::recursive_mutex RecLock;
45 typedef boost::unique_lock<RecLock> UniqueRecLock;
46
47private:
Alexander Afanasyeve5b55132013-11-09 23:07:48 -080048 void
49 getCertNames(std::vector<std::string> &names);
Yingdi Yuae8217c2013-11-09 00:03:26 -080050
51 void
52 updateCertificateMap(bool filter = false);
53
54 void
55 updateCertificateFetchingStatus(int count);
56
57 void
58 fetchCertificate();
59
Yingdi Yue433a502013-11-10 01:34:57 -080060protected:
61 void
62 closeEvent(QCloseEvent *e);
63
Yingdi Yuae8217c2013-11-09 00:03:26 -080064private slots:
65 void
66 updateSelection(const QItemSelection &selected,
67 const QItemSelection &deselected);
68
69 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080070 onCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yuae8217c2013-11-09 00:03:26 -080071
72 void
73 onCertificateFetchFailed(const ndn::Name& identity);
74
75 void
76 onWarning(QString msg);
77
78 void
79 onAddClicked();
80
81 void
Yingdi Yu9d7dfc22013-11-10 17:59:58 -080082 onDirectAddClicked();
Yingdi Yuae8217c2013-11-09 00:03:26 -080083
84public slots:
85 void
86 refreshList();
87
88signals:
89 void
90 newContactAdded();
91
Yingdi Yu9d7dfc22013-11-10 17:59:58 -080092 void
93 directAddClicked();
94
Yingdi Yuae8217c2013-11-09 00:03:26 -080095private:
96 Ui::BrowseContactDialog *ui;
97
Yingdi Yu76dd8002013-12-24 11:16:32 +080098 ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
Yingdi Yuae8217c2013-11-09 00:03:26 -080099
100 WarningDialog* m_warningDialog;
101 QStringListModel* m_contactListModel;
102
103 QStringList m_contactList;
104 std::vector<ndn::Name> m_contactNameList;
105 std::vector<ndn::Name> m_certificateNameList;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800106 std::map<ndn::Name, ndn::IdentityCertificate, ndn::Name::BreadthFirstLess> m_certificateMap;
107 std::map<ndn::Name, Profile, ndn::Name::BreadthFirstLess> m_profileMap;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800108
109 RecLock m_mutex;
110
111
112};
113
114#endif // BROWSECONTACTDIALOG_H