blob: ad04d09d479d0127c858472049c9ae547efc23db [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: Zhenkai Zhu <zhenkai@cs.ucla.edu>
9 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
10 * Yingdi Yu <yingdi@cs.ucla.edu>
11 */
12
Yingdi Yu0b0a7362014-08-05 16:31:30 -070013#include "chat-dialog.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080014#include "ui_chat-dialog.h"
15
16#include <QScrollBar>
17#include <QMessageBox>
18#include <QCloseEvent>
19
Yingdi Yud45777b2014-10-16 23:54:11 -070020Q_DECLARE_METATYPE(ndn::Name)
21Q_DECLARE_METATYPE(time_t)
Yingdi Yueb692ac2015-02-10 18:46:18 -080022Q_DECLARE_METATYPE(std::vector<chronochat::NodeInfo>)
Yingdi Yu0b0a7362014-08-05 16:31:30 -070023
Yingdi Yueb692ac2015-02-10 18:46:18 -080024namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070025
Yingdi Yud45777b2014-10-16 23:54:11 -070026static const Name PRIVATE_PREFIX("/private/local");
27static const uint8_t ROUTING_HINT_SEPARATOR[2] = {0xF0, 0x2E}; // %F0.
Yingdi Yu0b0a7362014-08-05 16:31:30 -070028
Yingdi Yud45777b2014-10-16 23:54:11 -070029ChatDialog::ChatDialog(const Name& chatroomPrefix,
30 const Name& userChatPrefix,
31 const Name& routingPrefix,
32 const std::string& chatroomName,
Yingdi Yu17032f82014-03-25 15:48:23 -070033 const std::string& nick,
Yingdi Yud45777b2014-10-16 23:54:11 -070034 bool isSecured,
Yingdi Yu45da92a2015-02-02 13:17:03 -080035 const Name& signingId,
Yingdi Yufa0b6a02014-04-30 14:26:42 -070036 QWidget* parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080037 : QDialog(parent)
38 , ui(new Ui::ChatDialog)
Yingdi Yu45da92a2015-02-02 13:17:03 -080039 , m_backend(chatroomPrefix, userChatPrefix, routingPrefix, chatroomName, nick, signingId)
Yingdi Yud45777b2014-10-16 23:54:11 -070040 , m_chatroomName(chatroomName)
Qiuhan Ding43c8e162015-02-02 15:16:48 -080041 , m_chatroomPrefix(chatroomPrefix)
Yingdi Yud45777b2014-10-16 23:54:11 -070042 , m_nick(nick.c_str())
43 , m_isSecured(isSecured)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080044{
Yingdi Yud45777b2014-10-16 23:54:11 -070045 qRegisterMetaType<ndn::Name>("ndn::Name");
46 qRegisterMetaType<time_t>("time_t");
Yingdi Yueb692ac2015-02-10 18:46:18 -080047 qRegisterMetaType<std::vector<chronochat::NodeInfo> >("std::vector<chronochat::NodeInfo>");
Yingdi Yu348f5ea2014-03-01 14:47:25 -080048
49 m_scene = new DigestTreeScene(this);
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070050 m_trustScene = new TrustTreeScene(this);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080051 m_rosterModel = new QStringListModel(this);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080052
53 ui->setupUi(this);
Yingdi Yud45777b2014-10-16 23:54:11 -070054
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070055 ui->syncTreeViewer->setScene(m_scene);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080056 m_scene->setSceneRect(m_scene->itemsBoundingRect());
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070057 ui->syncTreeViewer->hide();
Yingdi Yud45777b2014-10-16 23:54:11 -070058
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070059 ui->trustTreeViewer->setScene(m_trustScene);
60 m_trustScene->setSceneRect(m_trustScene->itemsBoundingRect());
61 ui->trustTreeViewer->hide();
Yingdi Yud45777b2014-10-16 23:54:11 -070062
Yingdi Yu348f5ea2014-03-01 14:47:25 -080063 ui->listView->setModel(m_rosterModel);
64
Yingdi Yud45777b2014-10-16 23:54:11 -070065 Name routablePrefix;
Yingdi Yud85e29f2014-09-09 17:20:04 -070066
Yingdi Yud45777b2014-10-16 23:54:11 -070067 if (routingPrefix.isPrefixOf(userChatPrefix))
68 routablePrefix = userChatPrefix;
69 else
70 routablePrefix.append(routingPrefix)
71 .append(ROUTING_HINT_SEPARATOR, 2)
72 .append(userChatPrefix);
Yingdi Yud85e29f2014-09-09 17:20:04 -070073
Yingdi Yud45777b2014-10-16 23:54:11 -070074 updateLabels(routablePrefix);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080075
Yingdi Yud45777b2014-10-16 23:54:11 -070076 QStringList roster;
77 roster << "- " + m_nick;
78 m_rosterModel->setStringList(roster);
79
80 // When backend receives a sync update, notify frontend to update sync tree
Yingdi Yueb692ac2015-02-10 18:46:18 -080081 connect(&m_backend, SIGNAL(syncTreeUpdated(std::vector<chronochat::NodeInfo>, QString)),
82 this, SLOT(updateSyncTree(std::vector<chronochat::NodeInfo>, QString)));
Yingdi Yud45777b2014-10-16 23:54:11 -070083
84 // When backend receives a new chat message, notify frontent to print it out.
85 connect(&m_backend, SIGNAL(chatMessageReceived(QString, QString, time_t)),
86 this, SLOT(receiveChatMessage(QString, QString, time_t)));
87
88 // When backend detects a new session, notify frontend to print the message.
89 connect(&m_backend, SIGNAL(sessionAdded(QString, QString, time_t)),
90 this, SLOT(addSession(QString, QString, time_t)));
91
92 // When backend detects a deleted session, notify frontend to print the message.
93 connect(&m_backend, SIGNAL(sessionRemoved(QString, QString, time_t)),
94 this, SLOT(removeSession(QString, QString, time_t)));
95
96 // When backend detects nick changed, notify frontend to print the new nick
97 connect(&m_backend, SIGNAL(nickUpdated(QString, QString)),
98 this, SLOT(updateNick(QString, QString)));
99
100 // When backend receives a new message, notify frontend to print notification
101 connect(&m_backend, SIGNAL(messageReceived(QString)),
102 this, SLOT(receiveMessage(QString)));
103
104 // When backend updates prefix, notify frontend to update labels.
105 connect(&m_backend, SIGNAL(chatPrefixChanged(ndn::Name)),
106 this, SLOT(updateLabels(ndn::Name)));
107
108 // When frontend gets a message to send, notify backend.
109 connect(this, SIGNAL(msgToSent(QString, time_t)),
110 &m_backend, SLOT(sendChatMessage(QString, time_t)));
111
112 // When frontend gets a shutdown command, notify backend.
113 connect(this, SIGNAL(shutdownBackend()),
114 &m_backend, SLOT(shutdown()));
115
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800116 m_scene->plot("Empty");
117
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700118 connect(ui->lineEdit, SIGNAL(returnPressed()),
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800119 this, SLOT(onReturnPressed()));
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700120 connect(ui->syncTreeButton, SIGNAL(pressed()),
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700121 this, SLOT(onSyncTreeButtonPressed()));
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700122 connect(ui->trustTreeButton, SIGNAL(pressed()),
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700123 this, SLOT(onTrustTreeButtonPressed()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800124
Yingdi Yud45777b2014-10-16 23:54:11 -0700125 disableSyncTreeDisplay();
126 QTimer::singleShot(2200, this, SLOT(enableSyncTreeDisplay()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800127
Yingdi Yud45777b2014-10-16 23:54:11 -0700128 m_backend.start();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800129}
130
131
132ChatDialog::~ChatDialog()
133{
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800134}
135
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800136void
137ChatDialog::closeEvent(QCloseEvent *e)
138{
Yingdi Yud45777b2014-10-16 23:54:11 -0700139 // When close button is clicked, do not close the dialog immediately.
140
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800141 QMessageBox::information(this, tr("ChronoChat"),
142 tr("The chatroom will keep running in the "
143 "system tray. To close the chatroom, "
144 "choose <b>Close chatroom</b> in the "
145 "context memu of the system tray entry."));
Yingdi Yue8323b62014-09-02 17:24:15 -0700146 hide();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800147 e->ignore();
148}
149
150void
Yingdi Yu233a9722014-03-07 15:47:09 -0800151ChatDialog::changeEvent(QEvent *e)
152{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700153 switch(e->type()) {
Yingdi Yu233a9722014-03-07 15:47:09 -0800154 case QEvent::ActivationChange:
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700155 if (isActiveWindow()) {
Yingdi Yu233a9722014-03-07 15:47:09 -0800156 emit resetIcon();
157 }
158 break;
159 default:
160 break;
161 }
162}
163
164void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800165ChatDialog::resizeEvent(QResizeEvent *e)
166{
167 fitView();
168}
169
170void
171ChatDialog::showEvent(QShowEvent *e)
172{
173 fitView();
174}
175
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800176ChatroomInfo
Yingdi Yud45777b2014-10-16 23:54:11 -0700177ChatDialog::getChatroomInfo()
178{
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800179 ChatroomInfo chatroomInfo;
180 chatroomInfo.setName(Name::Component(m_chatroomName));
Yingdi Yud45777b2014-10-16 23:54:11 -0700181 QStringList prefixList = m_scene->getRosterPrefixList();
182 for(QStringList::iterator it = prefixList.begin();
183 it != prefixList.end(); ++it ) {
184 Name participant = Name(it->toStdString()).getPrefix(-3);
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800185 chatroomInfo.addParticipant(participant);
Yingdi Yud45777b2014-10-16 23:54:11 -0700186 }
187
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800188 chatroomInfo.setSyncPrefix(m_chatroomPrefix);
Yingdi Yud45777b2014-10-16 23:54:11 -0700189 if (m_isSecured)
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800190 chatroomInfo.setTrustModel(ChatroomInfo::TRUST_MODEL_HIERARCHICAL);
Yingdi Yud45777b2014-10-16 23:54:11 -0700191 else
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800192 chatroomInfo.setTrustModel(ChatroomInfo::TRUST_MODEL_NONE);
Yingdi Yud45777b2014-10-16 23:54:11 -0700193 return chatroomInfo;
194}
195
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800196// private methods:
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700197void ChatDialog::disableSyncTreeDisplay()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800198{
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700199 ui->syncTreeButton->setEnabled(false);
200 ui->syncTreeViewer->hide();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800201 fitView();
202}
203
204void
Yingdi Yud45777b2014-10-16 23:54:11 -0700205ChatDialog::appendChatMessage(const QString& nick, const QString& text, time_t timestamp)
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800206{
Yingdi Yud45777b2014-10-16 23:54:11 -0700207 QTextCharFormat nickFormat;
208 nickFormat.setForeground(Qt::darkGreen);
209 nickFormat.setFontWeight(QFont::Bold);
210 nickFormat.setFontUnderline(true);
211 nickFormat.setUnderlineColor(Qt::gray);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800212
Yingdi Yud45777b2014-10-16 23:54:11 -0700213 // Print who & when
214 QTextCursor cursor(ui->textEdit->textCursor());
215 cursor.movePosition(QTextCursor::End);
216 QTextTableFormat tableFormat;
217 tableFormat.setBorder(0);
218 QTextTable *table = cursor.insertTable(1, 2, tableFormat);
219 QString from = QString("%1 ").arg(nick);
220 QTextTableCell fromCell = table->cellAt(0, 0);
221 fromCell.setFormat(nickFormat);
222 fromCell.firstCursorPosition().insertText(from);
223 printTimeInCell(table, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800224
Yingdi Yud45777b2014-10-16 23:54:11 -0700225 // Print what
226 QTextCursor nextCursor(ui->textEdit->textCursor());
227 nextCursor.movePosition(QTextCursor::End);
228 table = nextCursor.insertTable(1, 1, tableFormat);
229 table->cellAt(0, 0).firstCursorPosition().insertText(text);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800230
Yingdi Yud45777b2014-10-16 23:54:11 -0700231 // Popup notification
232 showMessage(from, text);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800233
234 QScrollBar *bar = ui->textEdit->verticalScrollBar();
235 bar->setValue(bar->maximum());
236}
237
238void
Yingdi Yud45777b2014-10-16 23:54:11 -0700239ChatDialog::appendControlMessage(const QString& nick,
240 const QString& action,
241 time_t timestamp)
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800242{
Yingdi Yud45777b2014-10-16 23:54:11 -0700243 QTextCharFormat nickFormat;
244 nickFormat.setForeground(Qt::gray);
245 nickFormat.setFontWeight(QFont::Bold);
246 nickFormat.setFontUnderline(true);
247 nickFormat.setUnderlineColor(Qt::gray);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800248
Yingdi Yud45777b2014-10-16 23:54:11 -0700249 QTextCursor cursor(ui->textEdit->textCursor());
250 cursor.movePosition(QTextCursor::End);
251 QTextTableFormat tableFormat;
252 tableFormat.setBorder(0);
253 QTextTable *table = cursor.insertTable(1, 2, tableFormat);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800254
Yingdi Yud45777b2014-10-16 23:54:11 -0700255 QString controlMsg = QString("%1 %2 ").arg(nick).arg(action);
256 QTextTableCell fromCell = table->cellAt(0, 0);
257 fromCell.setFormat(nickFormat);
258 fromCell.firstCursorPosition().insertText(controlMsg);
259 printTimeInCell(table, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800260}
261
262QString
263ChatDialog::formatTime(time_t timestamp)
264{
265 struct tm *tm_time = localtime(&timestamp);
266 int hour = tm_time->tm_hour;
267 QString amOrPM;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700268 if (hour > 12) {
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800269 hour -= 12;
270 amOrPM = "PM";
271 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700272 else {
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800273 amOrPM = "AM";
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700274 if (hour == 0) {
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800275 hour = 12;
276 }
277 }
278
279 char textTime[12];
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700280 sprintf(textTime, "%d:%02d:%02d %s",
281 hour, tm_time->tm_min, tm_time->tm_sec, amOrPM.toStdString().c_str());
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800282 return QString(textTime);
283}
284
285void
286ChatDialog::printTimeInCell(QTextTable *table, time_t timestamp)
287{
288 QTextCharFormat timeFormat;
289 timeFormat.setForeground(Qt::gray);
290 timeFormat.setFontUnderline(true);
291 timeFormat.setUnderlineColor(Qt::gray);
292 QTextTableCell timeCell = table->cellAt(0, 1);
293 timeCell.setFormat(timeFormat);
294 timeCell.firstCursorPosition().insertText(formatTime(timestamp));
295}
296
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800297void
298ChatDialog::showMessage(const QString& from, const QString& data)
299{
300 if (!isActiveWindow())
301 emit showChatMessage(QString::fromStdString(m_chatroomName),
302 from, data);
303}
304
305void
306ChatDialog::fitView()
307{
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800308 QRectF rect = m_scene->itemsBoundingRect();
309 m_scene->setSceneRect(rect);
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700310 ui->syncTreeViewer->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio);
311
312 QRectF trustRect = m_trustScene->itemsBoundingRect();
313 m_trustScene->setSceneRect(trustRect);
314 ui->trustTreeViewer->fitInView(m_trustScene->itemsBoundingRect(), Qt::KeepAspectRatio);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800315}
316
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800317// public slots:
318void
Yingdi Yue8323b62014-09-02 17:24:15 -0700319ChatDialog::onShow()
320{
321 this->show();
322 this->raise();
323 this->activateWindow();
324}
325
326void
Yingdi Yud45777b2014-10-16 23:54:11 -0700327ChatDialog::shutdown()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800328{
Yingdi Yud45777b2014-10-16 23:54:11 -0700329 if (m_backend.isRunning()) {
330 emit shutdownBackend();
331 m_backend.wait();
332 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800333 hide();
334 emit closeChatDialog(QString::fromStdString(m_chatroomName));
335}
336
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800337// private slots:
338void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800339ChatDialog::updateSyncTree(std::vector<chronochat::NodeInfo> updates, QString rootDigest)
Yingdi Yud45777b2014-10-16 23:54:11 -0700340{
341 m_scene->processSyncUpdate(updates, rootDigest);
342}
343
344void
345ChatDialog::receiveChatMessage(QString nick, QString text, time_t timestamp)
346{
347 appendChatMessage(nick, text, timestamp);
348}
349
350void
351ChatDialog::addSession(QString sessionPrefix, QString nick, time_t timestamp)
352{
353 appendControlMessage(nick, "enters room", timestamp);
354 m_scene->updateNick(sessionPrefix, nick);
355 m_rosterModel->setStringList(m_scene->getRosterList());
356}
357
358void
359ChatDialog::removeSession(QString sessionPrefix, QString nick, time_t timestamp)
360{
361 appendControlMessage(nick, "leaves room", timestamp);
362 m_scene->removeNode(sessionPrefix);
363 m_rosterModel->setStringList(m_scene->getRosterList());
364}
365
366void
367ChatDialog::updateNick(QString sessionPrefix, QString nick)
368{
369 m_scene->updateNick(sessionPrefix, nick);
370 m_rosterModel->setStringList(m_scene->getRosterList());
371}
372
373void
374ChatDialog::receiveMessage(QString sessionPrefix)
375{
376 m_scene->messageReceived(sessionPrefix);
377}
378
379void
380ChatDialog::updateLabels(Name newChatPrefix)
381{
382 // Reset DigestTree
383 m_scene->clearAll();
384 m_scene->plot("Empty");
385
386 // Display chatroom name
387 QString chatroomName = QString("Chatroom: %1").arg(QString::fromStdString(m_chatroomName));
388 ui->infoLabel->setStyleSheet("QLabel {color: #630; font-size: 16px; font: bold \"Verdana\";}");
389 ui->infoLabel->setText(chatroomName);
390
391 // Display chat message prefix
392 QString chatPrefix;
393 if (PRIVATE_PREFIX.isPrefixOf(newChatPrefix)) {
394 chatPrefix =
395 QString("<Warning: no connection to hub or hub does not support prefix autoconfig.>\n"
396 "<Prefix = %1>")
397 .arg(QString::fromStdString(newChatPrefix.toUri()));
398 ui->prefixLabel->setStyleSheet(
399 "QLabel {color: red; font-size: 12px; font: bold \"Verdana\";}");
400 }
401 else {
402 chatPrefix = QString("<Prefix = %1>")
403 .arg(QString::fromStdString(newChatPrefix.toUri()));
404 ui->prefixLabel->setStyleSheet(
405 "QLabel {color: Green; font-size: 12px; font: bold \"Verdana\";}");
406 }
407 ui->prefixLabel->setText(chatPrefix);
408}
409
410void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800411ChatDialog::onReturnPressed()
412{
413 QString text = ui->lineEdit->text();
Yingdi Yud45777b2014-10-16 23:54:11 -0700414
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800415 if (text.isEmpty())
416 return;
417
418 ui->lineEdit->clear();
419
Yingdi Yud45777b2014-10-16 23:54:11 -0700420 time_t timestamp =
421 static_cast<time_t>(time::toUnixTimestamp(time::system_clock::now()).count() / 1000);
422 // appendChatMessage(m_nick, text, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800423
Yingdi Yud45777b2014-10-16 23:54:11 -0700424 emit msgToSent(text, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800425
426 fitView();
427}
428
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700429void
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700430ChatDialog::onSyncTreeButtonPressed()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800431{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700432 if (ui->syncTreeViewer->isVisible()) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700433 ui->syncTreeViewer->hide();
434 ui->syncTreeButton->setText("Show ChronoSync Tree");
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800435 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700436 else {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700437 ui->syncTreeViewer->show();
438 ui->syncTreeButton->setText("Hide ChronoSync Tree");
439 }
440
441 fitView();
442}
443
444void
445ChatDialog::onTrustTreeButtonPressed()
446{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700447 if (ui->trustTreeViewer->isVisible()) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700448 ui->trustTreeViewer->hide();
449 ui->trustTreeButton->setText("Show Trust Tree");
450 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700451 else {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700452 ui->trustTreeViewer->show();
453 ui->trustTreeButton->setText("Hide Trust Tree");
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800454 }
455
456 fitView();
457}
458
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700459void ChatDialog::enableSyncTreeDisplay()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800460{
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700461 ui->syncTreeButton->setEnabled(true);
Yingdi Yud45777b2014-10-16 23:54:11 -0700462 ui->syncTreeViewer->show();
463 fitView();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800464}
465
Yingdi Yueb692ac2015-02-10 18:46:18 -0800466} // namespace chronochat
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800467
Mengjin Yanaec70742014-08-25 10:37:45 -0700468
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800469#if WAF
470#include "chat-dialog.moc"
Yingdi Yu42125862014-08-07 17:04:28 -0700471// #include "chat-dialog.cpp.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800472#endif