blob: 3f6070e234df8944fff32e7f406b194fd10ad4c3 [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");
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080027static const ndn::Name::Component ROUTING_HINT_SEPARATOR =
28 ndn::name::Component::fromEscapedString("%F0%2E");
Yingdi Yu0b0a7362014-08-05 16:31:30 -070029
Yingdi Yud45777b2014-10-16 23:54:11 -070030ChatDialog::ChatDialog(const Name& chatroomPrefix,
31 const Name& userChatPrefix,
32 const Name& routingPrefix,
33 const std::string& chatroomName,
Yingdi Yu17032f82014-03-25 15:48:23 -070034 const std::string& nick,
Yingdi Yud45777b2014-10-16 23:54:11 -070035 bool isSecured,
Yingdi Yu45da92a2015-02-02 13:17:03 -080036 const Name& signingId,
Yingdi Yufa0b6a02014-04-30 14:26:42 -070037 QWidget* parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080038 : QDialog(parent)
39 , ui(new Ui::ChatDialog)
Yingdi Yu45da92a2015-02-02 13:17:03 -080040 , m_backend(chatroomPrefix, userChatPrefix, routingPrefix, chatroomName, nick, signingId)
Yingdi Yud45777b2014-10-16 23:54:11 -070041 , m_chatroomName(chatroomName)
Qiuhan Ding43c8e162015-02-02 15:16:48 -080042 , m_chatroomPrefix(chatroomPrefix)
Yingdi Yud45777b2014-10-16 23:54:11 -070043 , m_nick(nick.c_str())
44 , m_isSecured(isSecured)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080045{
Yingdi Yud45777b2014-10-16 23:54:11 -070046 qRegisterMetaType<ndn::Name>("ndn::Name");
47 qRegisterMetaType<time_t>("time_t");
Yingdi Yueb692ac2015-02-10 18:46:18 -080048 qRegisterMetaType<std::vector<chronochat::NodeInfo> >("std::vector<chronochat::NodeInfo>");
Yingdi Yu348f5ea2014-03-01 14:47:25 -080049
50 m_scene = new DigestTreeScene(this);
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070051 m_trustScene = new TrustTreeScene(this);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080052 m_rosterModel = new QStringListModel(this);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080053
54 ui->setupUi(this);
Yingdi Yud45777b2014-10-16 23:54:11 -070055
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070056 ui->syncTreeViewer->setScene(m_scene);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080057 m_scene->setSceneRect(m_scene->itemsBoundingRect());
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070058 ui->syncTreeViewer->hide();
Yingdi Yud45777b2014-10-16 23:54:11 -070059
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070060 ui->trustTreeViewer->setScene(m_trustScene);
61 m_trustScene->setSceneRect(m_trustScene->itemsBoundingRect());
62 ui->trustTreeViewer->hide();
Yingdi Yud45777b2014-10-16 23:54:11 -070063
Yingdi Yu348f5ea2014-03-01 14:47:25 -080064 ui->listView->setModel(m_rosterModel);
65
Yingdi Yud45777b2014-10-16 23:54:11 -070066 Name routablePrefix;
Yingdi Yud85e29f2014-09-09 17:20:04 -070067
Yingdi Yud45777b2014-10-16 23:54:11 -070068 if (routingPrefix.isPrefixOf(userChatPrefix))
69 routablePrefix = userChatPrefix;
70 else
71 routablePrefix.append(routingPrefix)
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080072 .append(ROUTING_HINT_SEPARATOR)
Yingdi Yud45777b2014-10-16 23:54:11 -070073 .append(userChatPrefix);
Yingdi Yud85e29f2014-09-09 17:20:04 -070074
Yingdi Yud45777b2014-10-16 23:54:11 -070075 updateLabels(routablePrefix);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080076
Yingdi Yud45777b2014-10-16 23:54:11 -070077 QStringList roster;
78 roster << "- " + m_nick;
79 m_rosterModel->setStringList(roster);
80
81 // When backend receives a sync update, notify frontend to update sync tree
Yingdi Yueb692ac2015-02-10 18:46:18 -080082 connect(&m_backend, SIGNAL(syncTreeUpdated(std::vector<chronochat::NodeInfo>, QString)),
83 this, SLOT(updateSyncTree(std::vector<chronochat::NodeInfo>, QString)));
Yingdi Yud45777b2014-10-16 23:54:11 -070084
85 // When backend receives a new chat message, notify frontent to print it out.
86 connect(&m_backend, SIGNAL(chatMessageReceived(QString, QString, time_t)),
87 this, SLOT(receiveChatMessage(QString, QString, time_t)));
88
89 // When backend detects a new session, notify frontend to print the message.
90 connect(&m_backend, SIGNAL(sessionAdded(QString, QString, time_t)),
91 this, SLOT(addSession(QString, QString, time_t)));
92
93 // When backend detects a deleted session, notify frontend to print the message.
94 connect(&m_backend, SIGNAL(sessionRemoved(QString, QString, time_t)),
95 this, SLOT(removeSession(QString, QString, time_t)));
96
97 // When backend detects nick changed, notify frontend to print the new nick
98 connect(&m_backend, SIGNAL(nickUpdated(QString, QString)),
99 this, SLOT(updateNick(QString, QString)));
100
101 // When backend receives a new message, notify frontend to print notification
102 connect(&m_backend, SIGNAL(messageReceived(QString)),
103 this, SLOT(receiveMessage(QString)));
104
105 // When backend updates prefix, notify frontend to update labels.
106 connect(&m_backend, SIGNAL(chatPrefixChanged(ndn::Name)),
107 this, SLOT(updateLabels(ndn::Name)));
108
109 // When frontend gets a message to send, notify backend.
110 connect(this, SIGNAL(msgToSent(QString, time_t)),
111 &m_backend, SLOT(sendChatMessage(QString, time_t)));
112
113 // When frontend gets a shutdown command, notify backend.
114 connect(this, SIGNAL(shutdownBackend()),
115 &m_backend, SLOT(shutdown()));
116
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800117 m_scene->plot("Empty");
118
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700119 connect(ui->lineEdit, SIGNAL(returnPressed()),
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800120 this, SLOT(onReturnPressed()));
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700121 connect(ui->syncTreeButton, SIGNAL(pressed()),
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700122 this, SLOT(onSyncTreeButtonPressed()));
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700123 connect(ui->trustTreeButton, SIGNAL(pressed()),
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700124 this, SLOT(onTrustTreeButtonPressed()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800125
Yingdi Yud45777b2014-10-16 23:54:11 -0700126 disableSyncTreeDisplay();
127 QTimer::singleShot(2200, this, SLOT(enableSyncTreeDisplay()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800128
Yingdi Yud45777b2014-10-16 23:54:11 -0700129 m_backend.start();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800130}
131
132
133ChatDialog::~ChatDialog()
134{
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800135}
136
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800137void
138ChatDialog::closeEvent(QCloseEvent *e)
139{
Yingdi Yud45777b2014-10-16 23:54:11 -0700140 // When close button is clicked, do not close the dialog immediately.
141
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800142 QMessageBox::information(this, tr("ChronoChat"),
143 tr("The chatroom will keep running in the "
144 "system tray. To close the chatroom, "
145 "choose <b>Close chatroom</b> in the "
146 "context memu of the system tray entry."));
Yingdi Yue8323b62014-09-02 17:24:15 -0700147 hide();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800148 e->ignore();
149}
150
151void
Yingdi Yu233a9722014-03-07 15:47:09 -0800152ChatDialog::changeEvent(QEvent *e)
153{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700154 switch(e->type()) {
Yingdi Yu233a9722014-03-07 15:47:09 -0800155 case QEvent::ActivationChange:
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700156 if (isActiveWindow()) {
Yingdi Yu233a9722014-03-07 15:47:09 -0800157 emit resetIcon();
158 }
159 break;
160 default:
161 break;
162 }
163}
164
165void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800166ChatDialog::resizeEvent(QResizeEvent *e)
167{
168 fitView();
169}
170
171void
172ChatDialog::showEvent(QShowEvent *e)
173{
174 fitView();
175}
176
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800177ChatroomInfo
Yingdi Yud45777b2014-10-16 23:54:11 -0700178ChatDialog::getChatroomInfo()
179{
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800180 ChatroomInfo chatroomInfo;
181 chatroomInfo.setName(Name::Component(m_chatroomName));
Yingdi Yud45777b2014-10-16 23:54:11 -0700182 QStringList prefixList = m_scene->getRosterPrefixList();
183 for(QStringList::iterator it = prefixList.begin();
184 it != prefixList.end(); ++it ) {
185 Name participant = Name(it->toStdString()).getPrefix(-3);
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800186 chatroomInfo.addParticipant(participant);
Yingdi Yud45777b2014-10-16 23:54:11 -0700187 }
188
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800189 chatroomInfo.setSyncPrefix(m_chatroomPrefix);
Yingdi Yud45777b2014-10-16 23:54:11 -0700190 if (m_isSecured)
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800191 chatroomInfo.setTrustModel(ChatroomInfo::TRUST_MODEL_HIERARCHICAL);
Yingdi Yud45777b2014-10-16 23:54:11 -0700192 else
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800193 chatroomInfo.setTrustModel(ChatroomInfo::TRUST_MODEL_NONE);
Yingdi Yud45777b2014-10-16 23:54:11 -0700194 return chatroomInfo;
195}
196
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800197// private methods:
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700198void ChatDialog::disableSyncTreeDisplay()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800199{
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700200 ui->syncTreeButton->setEnabled(false);
201 ui->syncTreeViewer->hide();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800202 fitView();
203}
204
205void
Yingdi Yud45777b2014-10-16 23:54:11 -0700206ChatDialog::appendChatMessage(const QString& nick, const QString& text, time_t timestamp)
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800207{
Yingdi Yud45777b2014-10-16 23:54:11 -0700208 QTextCharFormat nickFormat;
209 nickFormat.setForeground(Qt::darkGreen);
210 nickFormat.setFontWeight(QFont::Bold);
211 nickFormat.setFontUnderline(true);
212 nickFormat.setUnderlineColor(Qt::gray);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800213
Yingdi Yud45777b2014-10-16 23:54:11 -0700214 // Print who & when
215 QTextCursor cursor(ui->textEdit->textCursor());
216 cursor.movePosition(QTextCursor::End);
217 QTextTableFormat tableFormat;
218 tableFormat.setBorder(0);
219 QTextTable *table = cursor.insertTable(1, 2, tableFormat);
220 QString from = QString("%1 ").arg(nick);
221 QTextTableCell fromCell = table->cellAt(0, 0);
222 fromCell.setFormat(nickFormat);
223 fromCell.firstCursorPosition().insertText(from);
224 printTimeInCell(table, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800225
Yingdi Yud45777b2014-10-16 23:54:11 -0700226 // Print what
227 QTextCursor nextCursor(ui->textEdit->textCursor());
228 nextCursor.movePosition(QTextCursor::End);
229 table = nextCursor.insertTable(1, 1, tableFormat);
230 table->cellAt(0, 0).firstCursorPosition().insertText(text);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800231
Yingdi Yud45777b2014-10-16 23:54:11 -0700232 // Popup notification
233 showMessage(from, text);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800234
235 QScrollBar *bar = ui->textEdit->verticalScrollBar();
236 bar->setValue(bar->maximum());
237}
238
239void
Yingdi Yud45777b2014-10-16 23:54:11 -0700240ChatDialog::appendControlMessage(const QString& nick,
241 const QString& action,
242 time_t timestamp)
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800243{
Yingdi Yud45777b2014-10-16 23:54:11 -0700244 QTextCharFormat nickFormat;
245 nickFormat.setForeground(Qt::gray);
246 nickFormat.setFontWeight(QFont::Bold);
247 nickFormat.setFontUnderline(true);
248 nickFormat.setUnderlineColor(Qt::gray);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800249
Yingdi Yud45777b2014-10-16 23:54:11 -0700250 QTextCursor cursor(ui->textEdit->textCursor());
251 cursor.movePosition(QTextCursor::End);
252 QTextTableFormat tableFormat;
253 tableFormat.setBorder(0);
254 QTextTable *table = cursor.insertTable(1, 2, tableFormat);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800255
Yingdi Yud45777b2014-10-16 23:54:11 -0700256 QString controlMsg = QString("%1 %2 ").arg(nick).arg(action);
257 QTextTableCell fromCell = table->cellAt(0, 0);
258 fromCell.setFormat(nickFormat);
259 fromCell.firstCursorPosition().insertText(controlMsg);
260 printTimeInCell(table, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800261}
262
263QString
264ChatDialog::formatTime(time_t timestamp)
265{
Qiuhan Ding4b8cfaa2015-03-10 17:03:48 -0700266 struct tm* localTime = localtime(&timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800267
Qiuhan Ding4b8cfaa2015-03-10 17:03:48 -0700268 return QString("%1:%2:%3")
269 .arg(localTime->tm_hour, 2, 10, QChar('0'))
270 .arg(localTime->tm_min, 2, 10, QChar('0'))
271 .arg(localTime->tm_sec, 2, 10, QChar('0'));
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800272}
273
274void
275ChatDialog::printTimeInCell(QTextTable *table, time_t timestamp)
276{
277 QTextCharFormat timeFormat;
278 timeFormat.setForeground(Qt::gray);
279 timeFormat.setFontUnderline(true);
280 timeFormat.setUnderlineColor(Qt::gray);
281 QTextTableCell timeCell = table->cellAt(0, 1);
282 timeCell.setFormat(timeFormat);
283 timeCell.firstCursorPosition().insertText(formatTime(timestamp));
284}
285
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800286void
287ChatDialog::showMessage(const QString& from, const QString& data)
288{
289 if (!isActiveWindow())
290 emit showChatMessage(QString::fromStdString(m_chatroomName),
291 from, data);
292}
293
294void
295ChatDialog::fitView()
296{
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800297 QRectF rect = m_scene->itemsBoundingRect();
298 m_scene->setSceneRect(rect);
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700299 ui->syncTreeViewer->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio);
300
301 QRectF trustRect = m_trustScene->itemsBoundingRect();
302 m_trustScene->setSceneRect(trustRect);
303 ui->trustTreeViewer->fitInView(m_trustScene->itemsBoundingRect(), Qt::KeepAspectRatio);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800304}
305
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800306// public slots:
307void
Yingdi Yue8323b62014-09-02 17:24:15 -0700308ChatDialog::onShow()
309{
310 this->show();
311 this->raise();
312 this->activateWindow();
313}
314
315void
Yingdi Yud45777b2014-10-16 23:54:11 -0700316ChatDialog::shutdown()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800317{
Yingdi Yud45777b2014-10-16 23:54:11 -0700318 if (m_backend.isRunning()) {
319 emit shutdownBackend();
320 m_backend.wait();
321 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800322 hide();
323 emit closeChatDialog(QString::fromStdString(m_chatroomName));
324}
325
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800326// private slots:
327void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800328ChatDialog::updateSyncTree(std::vector<chronochat::NodeInfo> updates, QString rootDigest)
Yingdi Yud45777b2014-10-16 23:54:11 -0700329{
330 m_scene->processSyncUpdate(updates, rootDigest);
331}
332
333void
334ChatDialog::receiveChatMessage(QString nick, QString text, time_t timestamp)
335{
336 appendChatMessage(nick, text, timestamp);
337}
338
339void
340ChatDialog::addSession(QString sessionPrefix, QString nick, time_t timestamp)
341{
342 appendControlMessage(nick, "enters room", timestamp);
343 m_scene->updateNick(sessionPrefix, nick);
344 m_rosterModel->setStringList(m_scene->getRosterList());
Qiuhan Ding112ee482015-03-11 11:54:11 -0700345 fitView();
Yingdi Yud45777b2014-10-16 23:54:11 -0700346}
347
348void
349ChatDialog::removeSession(QString sessionPrefix, QString nick, time_t timestamp)
350{
351 appendControlMessage(nick, "leaves room", timestamp);
352 m_scene->removeNode(sessionPrefix);
353 m_rosterModel->setStringList(m_scene->getRosterList());
Qiuhan Ding112ee482015-03-11 11:54:11 -0700354 fitView();
Yingdi Yud45777b2014-10-16 23:54:11 -0700355}
356
357void
358ChatDialog::updateNick(QString sessionPrefix, QString nick)
359{
360 m_scene->updateNick(sessionPrefix, nick);
361 m_rosterModel->setStringList(m_scene->getRosterList());
362}
363
364void
365ChatDialog::receiveMessage(QString sessionPrefix)
366{
367 m_scene->messageReceived(sessionPrefix);
368}
369
370void
371ChatDialog::updateLabels(Name newChatPrefix)
372{
373 // Reset DigestTree
374 m_scene->clearAll();
375 m_scene->plot("Empty");
376
377 // Display chatroom name
378 QString chatroomName = QString("Chatroom: %1").arg(QString::fromStdString(m_chatroomName));
379 ui->infoLabel->setStyleSheet("QLabel {color: #630; font-size: 16px; font: bold \"Verdana\";}");
380 ui->infoLabel->setText(chatroomName);
381
382 // Display chat message prefix
383 QString chatPrefix;
384 if (PRIVATE_PREFIX.isPrefixOf(newChatPrefix)) {
385 chatPrefix =
386 QString("<Warning: no connection to hub or hub does not support prefix autoconfig.>\n"
387 "<Prefix = %1>")
388 .arg(QString::fromStdString(newChatPrefix.toUri()));
389 ui->prefixLabel->setStyleSheet(
390 "QLabel {color: red; font-size: 12px; font: bold \"Verdana\";}");
391 }
392 else {
393 chatPrefix = QString("<Prefix = %1>")
394 .arg(QString::fromStdString(newChatPrefix.toUri()));
395 ui->prefixLabel->setStyleSheet(
396 "QLabel {color: Green; font-size: 12px; font: bold \"Verdana\";}");
397 }
398 ui->prefixLabel->setText(chatPrefix);
Qiuhan Ding112ee482015-03-11 11:54:11 -0700399 fitView();
Yingdi Yud45777b2014-10-16 23:54:11 -0700400}
401
402void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800403ChatDialog::onReturnPressed()
404{
405 QString text = ui->lineEdit->text();
Yingdi Yud45777b2014-10-16 23:54:11 -0700406
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800407 if (text.isEmpty())
408 return;
409
410 ui->lineEdit->clear();
411
Yingdi Yud45777b2014-10-16 23:54:11 -0700412 time_t timestamp =
413 static_cast<time_t>(time::toUnixTimestamp(time::system_clock::now()).count() / 1000);
414 // appendChatMessage(m_nick, text, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800415
Yingdi Yud45777b2014-10-16 23:54:11 -0700416 emit msgToSent(text, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800417
418 fitView();
419}
420
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700421void
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700422ChatDialog::onSyncTreeButtonPressed()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800423{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700424 if (ui->syncTreeViewer->isVisible()) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700425 ui->syncTreeViewer->hide();
426 ui->syncTreeButton->setText("Show ChronoSync Tree");
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800427 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700428 else {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700429 ui->syncTreeViewer->show();
430 ui->syncTreeButton->setText("Hide ChronoSync Tree");
431 }
432
433 fitView();
434}
435
436void
437ChatDialog::onTrustTreeButtonPressed()
438{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700439 if (ui->trustTreeViewer->isVisible()) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700440 ui->trustTreeViewer->hide();
441 ui->trustTreeButton->setText("Show Trust Tree");
442 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700443 else {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700444 ui->trustTreeViewer->show();
445 ui->trustTreeButton->setText("Hide Trust Tree");
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800446 }
447
448 fitView();
449}
450
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700451void ChatDialog::enableSyncTreeDisplay()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800452{
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700453 ui->syncTreeButton->setEnabled(true);
Yingdi Yud45777b2014-10-16 23:54:11 -0700454 ui->syncTreeViewer->show();
455 fitView();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800456}
457
Yingdi Yueb692ac2015-02-10 18:46:18 -0800458} // namespace chronochat
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800459
Mengjin Yanaec70742014-08-25 10:37:45 -0700460
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800461#if WAF
462#include "chat-dialog.moc"
Yingdi Yu42125862014-08-07 17:04:28 -0700463// #include "chat-dialog.cpp.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800464#endif