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