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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 12 | #include "browse-contact-dialog.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 13 | #include "ui_browse-contact-dialog.h" |
| 14 | |
| 15 | #ifndef Q_MOC_RUN |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 16 | #include "profile.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 17 | #endif |
| 18 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 20 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 21 | |
| 22 | using ndn::IdentityCertificate; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 23 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 24 | BrowseContactDialog::BrowseContactDialog(QWidget *parent) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 25 | : 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 Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 38 | connect(ui->ContactList->selectionModel(), |
| 39 | SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
| 40 | this, |
| 41 | SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 42 | connect(ui->AddButton, SIGNAL(clicked()), |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 43 | this, SLOT(onAddClicked())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 44 | connect(ui->DirectAddButton, SIGNAL(clicked()), |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 45 | this, SLOT(onDirectAddClicked())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | BrowseContactDialog::~BrowseContactDialog() |
| 49 | { |
| 50 | delete m_typeHeader; |
| 51 | delete m_valueHeader; |
| 52 | delete ui; |
| 53 | } |
| 54 | |
| 55 | void |
| 56 | BrowseContactDialog::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 | |
| 64 | void |
| 65 | BrowseContactDialog::onAddClicked() |
| 66 | { |
| 67 | QItemSelectionModel* selectionModel = ui->ContactList->selectionModel(); |
| 68 | QModelIndexList selectedList = selectionModel->selectedIndexes(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 69 | |
| 70 | for (QModelIndexList::iterator it = selectedList.begin(); it != selectedList.end(); it++) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 71 | emit addContact(m_contactNameList[it->row()]); |
| 72 | |
| 73 | this->close(); |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | BrowseContactDialog::onDirectAddClicked() |
| 78 | { |
| 79 | emit directAddClicked(); |
| 80 | this->close(); |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | BrowseContactDialog::closeEvent(QCloseEvent *e) |
| 85 | { |
| 86 | ui->InfoTable->clear(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 87 | for (int i = ui->InfoTable->rowCount() - 1; i >= 0 ; i--) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 88 | ui->InfoTable->removeRow(i); |
| 89 | ui->InfoTable->horizontalHeader()->hide(); |
| 90 | |
| 91 | hide(); |
| 92 | e->ignore(); |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | BrowseContactDialog::onIdCertNameListReady(const QStringList& qCertNameList) |
| 97 | { |
| 98 | m_contactCertNameList = qCertNameList; |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | BrowseContactDialog::onNameListReady(const QStringList& qNameList) |
| 103 | { |
| 104 | m_contactNameList = qNameList; |
| 105 | m_contactListModel->setStringList(m_contactNameList); |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | BrowseContactDialog::onIdCertReady(const IdentityCertificate& idCert) |
| 110 | { |
| 111 | Profile profile(idCert); |
| 112 | |
| 113 | ui->InfoTable->clear(); |
| 114 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 115 | for (int i = ui->InfoTable->rowCount() - 1; i >= 0 ; i--) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 116 | ui->InfoTable->removeRow(i); |
| 117 | |
| 118 | ui->InfoTable->horizontalHeader()->show(); |
| 119 | ui->InfoTable->setColumnCount(2); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 120 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 121 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 122 | int rowCount = 0; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 123 | 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 Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 128 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 129 | QTableWidgetItem* value = new QTableWidgetItem(QString::fromStdString(proIt->second)); |
| 130 | ui->InfoTable->setItem(rowCount, 1, value); |
| 131 | } |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 134 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 135 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 136 | #if WAF |
| 137 | #include "browse-contact-dialog.moc" |
Yingdi Yu | 4212586 | 2014-08-07 17:04:28 -0700 | [diff] [blame] | 138 | // #include "browse-contact-dialog.cpp.moc" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 139 | #endif |