blob: 639c113bd884dd6928b627674d48d2718cb9674f [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- 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
17AddContactPanel::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
41AddContactPanel::~AddContactPanel()
42{
43 delete m_typeHeader;
44 delete m_valueHeader;
45 delete m_endorseHeader;
46
47 delete ui;
48}
49
50void
51AddContactPanel::onCancelClicked()
52{
Yingdi Yufa0b6a02014-04-30 14:26:42 -070053 this->close();
Yingdi Yu348f5ea2014-03-01 14:47:25 -080054}
55
56void
57AddContactPanel::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
67void
68AddContactPanel::onAddClicked()
69{
70 emit addContact(m_searchIdentity);
71 this->close();
72}
73
74void
75AddContactPanel::onContactEndorseInfoReady(const chronos::EndorseInfo& endorseInfo)
76{
77 int entrySize = endorseInfo.endorsement_size();
78
79 for(int rowCount = 0; rowCount < entrySize; rowCount++)
80 {
Yingdi Yufa0b6a02014-04-30 14:26:42 -070081 ui->infoView->insertRow(rowCount);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080082 QTableWidgetItem* type = new QTableWidgetItem(QString::fromStdString(endorseInfo.endorsement(rowCount).type()));
83 ui->infoView->setItem(rowCount, 0, type);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070084
Yingdi Yu348f5ea2014-03-01 14:47:25 -080085 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