blob: 887c6649a9813d5312bb423f7111d28958aa66ff [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Yingdi Yu348f5ea2014-03-01 14:47:25 -08004 * 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
Yingdi Yu0b0a7362014-08-05 16:31:30 -070012#include "browse-contact-dialog.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080013#include "ui_browse-contact-dialog.h"
14
15#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070016#include "profile.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080017#endif
18
Yingdi Yu0b0a7362014-08-05 16:31:30 -070019
Yingdi Yueb692ac2015-02-10 18:46:18 -080020namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070021
Varun Patil3d850902020-11-23 12:19:14 +053022using ndn::security::Certificate;
Yingdi Yu348f5ea2014-03-01 14:47:25 -080023
Yingdi Yufa0b6a02014-04-30 14:26:42 -070024BrowseContactDialog::BrowseContactDialog(QWidget *parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080025 : QDialog(parent)
26 , ui(new Ui::BrowseContactDialog)
27 , m_contactListModel(new QStringListModel)
28{
29 ui->setupUi(this);
30
31 m_typeHeader = new QTableWidgetItem(QString("Type"));
32 m_valueHeader = new QTableWidgetItem(QString("Value"));
33 ui->InfoTable->setHorizontalHeaderItem(0, m_typeHeader);
34 ui->InfoTable->setHorizontalHeaderItem(1, m_valueHeader);
35
36 ui->ContactList->setModel(m_contactListModel);
37
Yingdi Yu0b0a7362014-08-05 16:31:30 -070038 connect(ui->ContactList->selectionModel(),
39 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
40 this,
41 SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080042 connect(ui->AddButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070043 this, SLOT(onAddClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080044 connect(ui->DirectAddButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070045 this, SLOT(onDirectAddClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080046}
47
48BrowseContactDialog::~BrowseContactDialog()
49{
50 delete m_typeHeader;
51 delete m_valueHeader;
52 delete ui;
53}
54
55void
56BrowseContactDialog::onSelectionChanged(const QItemSelection& selected,
57 const QItemSelection& deselected)
58{
59 QModelIndexList items = selected.indexes();
60 QString certName = m_contactCertNameList[items.first().row()];
61 emit fetchIdCert(certName);
62}
63
64void
65BrowseContactDialog::onAddClicked()
66{
67 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
68 QModelIndexList selectedList = selectionModel->selectedIndexes();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070069
70 for (QModelIndexList::iterator it = selectedList.begin(); it != selectedList.end(); it++)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080071 emit addContact(m_contactNameList[it->row()]);
72
73 this->close();
74}
75
76void
77BrowseContactDialog::onDirectAddClicked()
78{
79 emit directAddClicked();
80 this->close();
81}
82
83void
84BrowseContactDialog::closeEvent(QCloseEvent *e)
85{
86 ui->InfoTable->clear();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070087 for (int i = ui->InfoTable->rowCount() - 1; i >= 0 ; i--)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080088 ui->InfoTable->removeRow(i);
89 ui->InfoTable->horizontalHeader()->hide();
90
91 hide();
92 e->ignore();
93}
94
95void
96BrowseContactDialog::onIdCertNameListReady(const QStringList& qCertNameList)
97{
98 m_contactCertNameList = qCertNameList;
99}
100
101void
102BrowseContactDialog::onNameListReady(const QStringList& qNameList)
103{
104 m_contactNameList = qNameList;
105 m_contactListModel->setStringList(m_contactNameList);
106}
107
108void
Varun Patil3d850902020-11-23 12:19:14 +0530109BrowseContactDialog::onIdCertReady(const Certificate& idCert)
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800110{
111 Profile profile(idCert);
112
113 ui->InfoTable->clear();
114
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700115 for (int i = ui->InfoTable->rowCount() - 1; i >= 0 ; i--)
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800116 ui->InfoTable->removeRow(i);
117
118 ui->InfoTable->horizontalHeader()->show();
119 ui->InfoTable->setColumnCount(2);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700120
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700121
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800122 int rowCount = 0;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700123 for (Profile::const_iterator proIt = profile.begin();
124 proIt != profile.end(); proIt++, rowCount++) {
125 ui->InfoTable->insertRow(rowCount);
126 QTableWidgetItem* type = new QTableWidgetItem(QString::fromStdString(proIt->first));
127 ui->InfoTable->setItem(rowCount, 0, type);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800128
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700129 QTableWidgetItem* value = new QTableWidgetItem(QString::fromStdString(proIt->second));
130 ui->InfoTable->setItem(rowCount, 1, value);
131 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800132}
133
Yingdi Yueb692ac2015-02-10 18:46:18 -0800134} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700135
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800136#if WAF
137#include "browse-contact-dialog.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800138#endif