blob: 48e59d648d4ef7342aaaa1e97f5f992175d28c4c [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Yingdi Yu348f5ea2014-03-01 14:47:25 -08004 * 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
Yingdi Yueb692ac2015-02-10 18:46:18 -080014namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070015
Yingdi Yu348f5ea2014-03-01 14:47:25 -080016AddContactPanel::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
40AddContactPanel::~AddContactPanel()
41{
42 delete m_typeHeader;
43 delete m_valueHeader;
44 delete m_endorseHeader;
45
46 delete ui;
47}
48
49void
50AddContactPanel::onCancelClicked()
51{
Yingdi Yufa0b6a02014-04-30 14:26:42 -070052 this->close();
Yingdi Yu348f5ea2014-03-01 14:47:25 -080053}
54
55void
56AddContactPanel::onSearchClicked()
57{
58 // ui->infoView->clear();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070059 for (int i = ui->infoView->rowCount() - 1; i >= 0 ; i--)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080060 ui->infoView->removeRow(i);
61
62 m_searchIdentity = ui->contactInput->text();
63 emit fetchInfo(m_searchIdentity);
64}
65
66void
67AddContactPanel::onAddClicked()
68{
69 emit addContact(m_searchIdentity);
70 this->close();
71}
72
73void
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080074AddContactPanel::onContactEndorseInfoReady(const EndorseInfo& endorseInfo)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080075{
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080076 std::vector<EndorseInfo::Endorsement> endorsements = endorseInfo.getEndorsements();
77 for (size_t rowCount = 0; rowCount < endorsements.size(); rowCount++) {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070078 ui->infoView->insertRow(rowCount);
79 QTableWidgetItem* type =
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080080 new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].type));
Yingdi Yu0b0a7362014-08-05 16:31:30 -070081 ui->infoView->setItem(rowCount, 0, type);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070082
Yingdi Yu0b0a7362014-08-05 16:31:30 -070083 QTableWidgetItem* value =
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080084 new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].value));
Yingdi Yu0b0a7362014-08-05 16:31:30 -070085 ui->infoView->setItem(rowCount, 1, value);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080086
Yingdi Yu0b0a7362014-08-05 16:31:30 -070087 QTableWidgetItem* endorse =
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080088 new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].count));
Yingdi Yu0b0a7362014-08-05 16:31:30 -070089 ui->infoView->setItem(rowCount, 2, endorse);
90 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -080091}
92
Yingdi Yueb692ac2015-02-10 18:46:18 -080093} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -070094
Yingdi Yu348f5ea2014-03-01 14:47:25 -080095
96#if WAF
97#include "add-contact-panel.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080098#endif