blob: c12d0407eaa560f154acf97dbcfe1335dd0f718d [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -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#include "browse-contact-dialog.h"
13#include "ui_browse-contact-dialog.h"
14
15#ifndef Q_MOC_RUN
16#include "profile.h"
17#endif
18
Yingdi Yu348f5ea2014-03-01 14:47:25 -080019using namespace ndn;
20using namespace chronos;
21
Yingdi Yufa0b6a02014-04-30 14:26:42 -070022BrowseContactDialog::BrowseContactDialog(QWidget *parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080023 : QDialog(parent)
24 , ui(new Ui::BrowseContactDialog)
25 , m_contactListModel(new QStringListModel)
26{
27 ui->setupUi(this);
28
29 m_typeHeader = new QTableWidgetItem(QString("Type"));
30 m_valueHeader = new QTableWidgetItem(QString("Value"));
31 ui->InfoTable->setHorizontalHeaderItem(0, m_typeHeader);
32 ui->InfoTable->setHorizontalHeaderItem(1, m_valueHeader);
33
34 ui->ContactList->setModel(m_contactListModel);
35
36 connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
37 this, SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
38 connect(ui->AddButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070039 this, SLOT(onAddClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080040 connect(ui->DirectAddButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070041 this, SLOT(onDirectAddClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080042}
43
44BrowseContactDialog::~BrowseContactDialog()
45{
46 delete m_typeHeader;
47 delete m_valueHeader;
48 delete ui;
49}
50
51void
52BrowseContactDialog::onSelectionChanged(const QItemSelection& selected,
53 const QItemSelection& deselected)
54{
55 QModelIndexList items = selected.indexes();
56 QString certName = m_contactCertNameList[items.first().row()];
57 emit fetchIdCert(certName);
58}
59
60void
61BrowseContactDialog::onAddClicked()
62{
63 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
64 QModelIndexList selectedList = selectionModel->selectedIndexes();
65 QModelIndexList::iterator it = selectedList.begin();
66 for(; it != selectedList.end(); it++)
67 emit addContact(m_contactNameList[it->row()]);
68
69 this->close();
70}
71
72void
73BrowseContactDialog::onDirectAddClicked()
74{
75 emit directAddClicked();
76 this->close();
77}
78
79void
80BrowseContactDialog::closeEvent(QCloseEvent *e)
81{
82 ui->InfoTable->clear();
83 for(int i = ui->InfoTable->rowCount() - 1; i >= 0 ; i--)
84 ui->InfoTable->removeRow(i);
85 ui->InfoTable->horizontalHeader()->hide();
86
87 hide();
88 e->ignore();
89}
90
91void
92BrowseContactDialog::onIdCertNameListReady(const QStringList& qCertNameList)
93{
94 m_contactCertNameList = qCertNameList;
95}
96
97void
98BrowseContactDialog::onNameListReady(const QStringList& qNameList)
99{
100 m_contactNameList = qNameList;
101 m_contactListModel->setStringList(m_contactNameList);
102}
103
104void
105BrowseContactDialog::onIdCertReady(const IdentityCertificate& idCert)
106{
107 Profile profile(idCert);
108
109 ui->InfoTable->clear();
110
111 for(int i = ui->InfoTable->rowCount() - 1; i >= 0 ; i--)
112 ui->InfoTable->removeRow(i);
113
114 ui->InfoTable->horizontalHeader()->show();
115 ui->InfoTable->setColumnCount(2);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700116
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800117 Profile::const_iterator proIt = profile.begin();
118 Profile::const_iterator proEnd = profile.end();
119 int rowCount = 0;
120
121 for(; proIt != proEnd; proIt++, rowCount++)
122 {
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700123 ui->InfoTable->insertRow(rowCount);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800124 QTableWidgetItem* type = new QTableWidgetItem(QString::fromStdString(proIt->first));
125 ui->InfoTable->setItem(rowCount, 0, type);
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700126
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800127 QTableWidgetItem* value = new QTableWidgetItem(QString::fromStdString(proIt->second));
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700128 ui->InfoTable->setItem(rowCount, 1, value);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800129 }
130}
131
132#if WAF
133#include "browse-contact-dialog.moc"
134#include "browse-contact-dialog.cpp.moc"
135#endif