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