Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 3 | * Copyright (c) 2020, Regents of the University of California |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 11 | #include "add-contact-panel.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 12 | #include "ui_add-contact-panel.h" |
| 13 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 14 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 15 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 16 | AddContactPanel::AddContactPanel(QWidget *parent) |
| 17 | : QDialog(parent) |
| 18 | , ui(new Ui::AddContactPanel) |
| 19 | { |
| 20 | ui->setupUi(this); |
| 21 | |
| 22 | connect(ui->cancelButton, SIGNAL(clicked()), |
| 23 | this, SLOT(onCancelClicked())); |
| 24 | connect(ui->searchButton, SIGNAL(clicked()), |
| 25 | this, SLOT(onSearchClicked())); |
| 26 | connect(ui->addButton, SIGNAL(clicked()), |
| 27 | this, SLOT(onAddClicked())); |
| 28 | |
| 29 | ui->infoView->setColumnCount(3); |
| 30 | |
| 31 | m_typeHeader = new QTableWidgetItem(QString("Type")); |
| 32 | ui->infoView->setHorizontalHeaderItem(0, m_typeHeader); |
| 33 | m_valueHeader = new QTableWidgetItem(QString("Value")); |
| 34 | ui->infoView->setHorizontalHeaderItem(1, m_valueHeader); |
| 35 | m_endorseHeader = new QTableWidgetItem(QString("Endorse")); |
| 36 | ui->infoView->setHorizontalHeaderItem(2, m_endorseHeader); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | AddContactPanel::~AddContactPanel() |
| 41 | { |
| 42 | delete m_typeHeader; |
| 43 | delete m_valueHeader; |
| 44 | delete m_endorseHeader; |
| 45 | |
| 46 | delete ui; |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | AddContactPanel::onCancelClicked() |
| 51 | { |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 52 | this->close(); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void |
| 56 | AddContactPanel::onSearchClicked() |
| 57 | { |
| 58 | // ui->infoView->clear(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 59 | for (int i = ui->infoView->rowCount() - 1; i >= 0 ; i--) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 60 | ui->infoView->removeRow(i); |
| 61 | |
| 62 | m_searchIdentity = ui->contactInput->text(); |
| 63 | emit fetchInfo(m_searchIdentity); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | AddContactPanel::onAddClicked() |
| 68 | { |
| 69 | emit addContact(m_searchIdentity); |
| 70 | this->close(); |
| 71 | } |
| 72 | |
| 73 | void |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 74 | AddContactPanel::onContactEndorseInfoReady(const EndorseInfo& endorseInfo) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 75 | { |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 76 | std::vector<EndorseInfo::Endorsement> endorsements = endorseInfo.getEndorsements(); |
| 77 | for (size_t rowCount = 0; rowCount < endorsements.size(); rowCount++) { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 78 | ui->infoView->insertRow(rowCount); |
| 79 | QTableWidgetItem* type = |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 80 | new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].type)); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 81 | ui->infoView->setItem(rowCount, 0, type); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 82 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 83 | QTableWidgetItem* value = |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 84 | new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].value)); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 85 | ui->infoView->setItem(rowCount, 1, value); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 86 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 87 | QTableWidgetItem* endorse = |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 88 | new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].count)); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 89 | ui->infoView->setItem(rowCount, 2, endorse); |
| 90 | } |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 93 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 94 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 95 | |
| 96 | #if WAF |
| 97 | #include "add-contact-panel.moc" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 98 | #endif |