blob: 770f039c973a452891ec811fc627e63ac3a14484 [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 Yueb692ac2015-02-10 18:46:18 -080017namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070018
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
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080077AddContactPanel::onContactEndorseInfoReady(const EndorseInfo& endorseInfo)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080078{
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080079 std::vector<EndorseInfo::Endorsement> endorsements = endorseInfo.getEndorsements();
80 for (size_t rowCount = 0; rowCount < endorsements.size(); rowCount++) {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070081 ui->infoView->insertRow(rowCount);
82 QTableWidgetItem* type =
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080083 new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].type));
Yingdi Yu0b0a7362014-08-05 16:31:30 -070084 ui->infoView->setItem(rowCount, 0, type);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070085
Yingdi Yu0b0a7362014-08-05 16:31:30 -070086 QTableWidgetItem* value =
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080087 new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].value));
Yingdi Yu0b0a7362014-08-05 16:31:30 -070088 ui->infoView->setItem(rowCount, 1, value);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080089
Yingdi Yu0b0a7362014-08-05 16:31:30 -070090 QTableWidgetItem* endorse =
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080091 new QTableWidgetItem(QString::fromStdString(endorsements[rowCount].count));
Yingdi Yu0b0a7362014-08-05 16:31:30 -070092 ui->infoView->setItem(rowCount, 2, endorse);
93 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -080094}
95
Yingdi Yueb692ac2015-02-10 18:46:18 -080096} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -070097
Yingdi Yu348f5ea2014-03-01 14:47:25 -080098
99#if WAF
100#include "add-contact-panel.moc"
Yingdi Yu42125862014-08-07 17:04:28 -0700101// #include "add-contact-panel.cpp.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800102#endif