Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 1 | /* -*- 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 Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 19 | using namespace ndn; |
| 20 | using namespace chronos; |
| 21 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 22 | BrowseContactDialog::BrowseContactDialog(QWidget *parent) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 23 | : 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 Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 39 | this, SLOT(onAddClicked())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 40 | connect(ui->DirectAddButton, SIGNAL(clicked()), |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 41 | this, SLOT(onDirectAddClicked())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | BrowseContactDialog::~BrowseContactDialog() |
| 45 | { |
| 46 | delete m_typeHeader; |
| 47 | delete m_valueHeader; |
| 48 | delete ui; |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | BrowseContactDialog::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 | |
| 60 | void |
| 61 | BrowseContactDialog::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 | |
| 72 | void |
| 73 | BrowseContactDialog::onDirectAddClicked() |
| 74 | { |
| 75 | emit directAddClicked(); |
| 76 | this->close(); |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | BrowseContactDialog::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 | |
| 91 | void |
| 92 | BrowseContactDialog::onIdCertNameListReady(const QStringList& qCertNameList) |
| 93 | { |
| 94 | m_contactCertNameList = qCertNameList; |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | BrowseContactDialog::onNameListReady(const QStringList& qNameList) |
| 99 | { |
| 100 | m_contactNameList = qNameList; |
| 101 | m_contactListModel->setStringList(m_contactNameList); |
| 102 | } |
| 103 | |
| 104 | void |
| 105 | BrowseContactDialog::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 Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 116 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 117 | 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 Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 123 | ui->InfoTable->insertRow(rowCount); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 124 | QTableWidgetItem* type = new QTableWidgetItem(QString::fromStdString(proIt->first)); |
| 125 | ui->InfoTable->setItem(rowCount, 0, type); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 126 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 127 | QTableWidgetItem* value = new QTableWidgetItem(QString::fromStdString(proIt->second)); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 128 | ui->InfoTable->setItem(rowCount, 1, value); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | #if WAF |
| 133 | #include "browse-contact-dialog.moc" |
| 134 | #include "browse-contact-dialog.cpp.moc" |
| 135 | #endif |