blob: 9e0db7404c7e8bf4e9535dc56ba22a1b77bd2741 [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
Yingdi Yu0b0a7362014-08-05 16:31:30 -070011#include "add-contact-panel.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080012#include "ui_add-contact-panel.h"
13
14#ifndef Q_MOC_RUN
15#endif
16
Yingdi Yu0b0a7362014-08-05 16:31:30 -070017namespace chronos {
18
Yingdi Yu348f5ea2014-03-01 14:47:25 -080019AddContactPanel::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
43AddContactPanel::~AddContactPanel()
44{
45 delete m_typeHeader;
46 delete m_valueHeader;
47 delete m_endorseHeader;
48
49 delete ui;
50}
51
52void
53AddContactPanel::onCancelClicked()
54{
Yingdi Yufa0b6a02014-04-30 14:26:42 -070055 this->close();
Yingdi Yu348f5ea2014-03-01 14:47:25 -080056}
57
58void
59AddContactPanel::onSearchClicked()
60{
61 // ui->infoView->clear();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070062 for (int i = ui->infoView->rowCount() - 1; i >= 0 ; i--)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080063 ui->infoView->removeRow(i);
64
65 m_searchIdentity = ui->contactInput->text();
66 emit fetchInfo(m_searchIdentity);
67}
68
69void
70AddContactPanel::onAddClicked()
71{
72 emit addContact(m_searchIdentity);
73 this->close();
74}
75
76void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070077AddContactPanel::onContactEndorseInfoReady(const Chronos::EndorseInfo& endorseInfo)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080078{
79 int entrySize = endorseInfo.endorsement_size();
80
Yingdi Yu0b0a7362014-08-05 16:31:30 -070081 for (int rowCount = 0; rowCount < entrySize; rowCount++) {
82 ui->infoView->insertRow(rowCount);
83 QTableWidgetItem* type =
84 new QTableWidgetItem(QString::fromStdString(endorseInfo.endorsement(rowCount).type()));
85 ui->infoView->setItem(rowCount, 0, type);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070086
Yingdi Yu0b0a7362014-08-05 16:31:30 -070087 QTableWidgetItem* value =
88 new QTableWidgetItem(QString::fromStdString(endorseInfo.endorsement(rowCount).value()));
89 ui->infoView->setItem(rowCount, 1, value);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080090
Yingdi Yu0b0a7362014-08-05 16:31:30 -070091 QTableWidgetItem* endorse =
92 new QTableWidgetItem(QString::fromStdString(endorseInfo.endorsement(rowCount).endorse()));
93 ui->infoView->setItem(rowCount, 2, endorse);
94 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -080095}
96
Yingdi Yu0b0a7362014-08-05 16:31:30 -070097} // namespace chronos
98
Yingdi Yu348f5ea2014-03-01 14:47:25 -080099
100#if WAF
101#include "add-contact-panel.moc"
102#include "add-contact-panel.cpp.moc"
103#endif