blob: 0158496a9766982019a67d1c7e79f73661a7cbb2 [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>)
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -080023Q_DECLARE_METATYPE(uint64_t)
Yingdi Yu0b0a7362014-08-05 16:31:30 -070024
Yingdi Yueb692ac2015-02-10 18:46:18 -080025namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070026
Yingdi Yud45777b2014-10-16 23:54:11 -070027static const Name PRIVATE_PREFIX("/private/local");
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080028static const ndn::Name::Component ROUTING_HINT_SEPARATOR =
29 ndn::name::Component::fromEscapedString("%F0%2E");
Yingdi Yu0b0a7362014-08-05 16:31:30 -070030
Yingdi Yud45777b2014-10-16 23:54:11 -070031ChatDialog::ChatDialog(const Name& chatroomPrefix,
32 const Name& userChatPrefix,
33 const Name& routingPrefix,
34 const std::string& chatroomName,
Yingdi Yu17032f82014-03-25 15:48:23 -070035 const std::string& nick,
Yingdi Yud45777b2014-10-16 23:54:11 -070036 bool isSecured,
Yingdi Yu45da92a2015-02-02 13:17:03 -080037 const Name& signingId,
Yingdi Yufa0b6a02014-04-30 14:26:42 -070038 QWidget* parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080039 : QDialog(parent)
40 , ui(new Ui::ChatDialog)
Yingdi Yu45da92a2015-02-02 13:17:03 -080041 , m_backend(chatroomPrefix, userChatPrefix, routingPrefix, chatroomName, nick, signingId)
Yingdi Yud45777b2014-10-16 23:54:11 -070042 , m_chatroomName(chatroomName)
Qiuhan Ding43c8e162015-02-02 15:16:48 -080043 , m_chatroomPrefix(chatroomPrefix)
Yingdi Yud45777b2014-10-16 23:54:11 -070044 , m_nick(nick.c_str())
45 , m_isSecured(isSecured)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080046{
Yingdi Yud45777b2014-10-16 23:54:11 -070047 qRegisterMetaType<ndn::Name>("ndn::Name");
48 qRegisterMetaType<time_t>("time_t");
Yingdi Yueb692ac2015-02-10 18:46:18 -080049 qRegisterMetaType<std::vector<chronochat::NodeInfo> >("std::vector<chronochat::NodeInfo>");
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -080050 qRegisterMetaType<uint64_t>("uint64_t");
Yingdi Yu348f5ea2014-03-01 14:47:25 -080051
52 m_scene = new DigestTreeScene(this);
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070053 m_trustScene = new TrustTreeScene(this);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080054 m_rosterModel = new QStringListModel(this);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080055
56 ui->setupUi(this);
Yingdi Yud45777b2014-10-16 23:54:11 -070057
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070058 ui->syncTreeViewer->setScene(m_scene);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080059 m_scene->setSceneRect(m_scene->itemsBoundingRect());
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070060 ui->syncTreeViewer->hide();
Yingdi Yud45777b2014-10-16 23:54:11 -070061
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070062 ui->trustTreeViewer->setScene(m_trustScene);
63 m_trustScene->setSceneRect(m_trustScene->itemsBoundingRect());
64 ui->trustTreeViewer->hide();
Yingdi Yud45777b2014-10-16 23:54:11 -070065
Yingdi Yu348f5ea2014-03-01 14:47:25 -080066 ui->listView->setModel(m_rosterModel);
67
Yingdi Yud45777b2014-10-16 23:54:11 -070068 Name routablePrefix;
Yingdi Yud85e29f2014-09-09 17:20:04 -070069
Yingdi Yud45777b2014-10-16 23:54:11 -070070 if (routingPrefix.isPrefixOf(userChatPrefix))
71 routablePrefix = userChatPrefix;
72 else
73 routablePrefix.append(routingPrefix)
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080074 .append(ROUTING_HINT_SEPARATOR)
Yingdi Yud45777b2014-10-16 23:54:11 -070075 .append(userChatPrefix);
Yingdi Yud85e29f2014-09-09 17:20:04 -070076
Yingdi Yud45777b2014-10-16 23:54:11 -070077 updateLabels(routablePrefix);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080078
Yingdi Yud45777b2014-10-16 23:54:11 -070079 QStringList roster;
80 roster << "- " + m_nick;
81 m_rosterModel->setStringList(roster);
82
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -080083 ui->syncTreeButton->setText("Hide ChronoSync Tree");
84
Yingdi Yud45777b2014-10-16 23:54:11 -070085 // When backend receives a sync update, notify frontend to update sync tree
Yingdi Yueb692ac2015-02-10 18:46:18 -080086 connect(&m_backend, SIGNAL(syncTreeUpdated(std::vector<chronochat::NodeInfo>, QString)),
87 this, SLOT(updateSyncTree(std::vector<chronochat::NodeInfo>, QString)));
Yingdi Yud45777b2014-10-16 23:54:11 -070088
89 // When backend receives a new chat message, notify frontent to print it out.
90 connect(&m_backend, SIGNAL(chatMessageReceived(QString, QString, time_t)),
91 this, SLOT(receiveChatMessage(QString, QString, time_t)));
92
Yingdi Yud45777b2014-10-16 23:54:11 -070093 // 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
Yingdi Yud45777b2014-10-16 23:54:11 -070097 // When backend receives a new message, notify frontend to print notification
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -080098 connect(&m_backend, SIGNAL(messageReceived(QString, QString, uint64_t, time_t, bool)),
99 this, SLOT(receiveMessage(QString, QString, uint64_t, time_t, bool)));
Yingdi Yud45777b2014-10-16 23:54:11 -0700100
101 // When backend updates prefix, notify frontend to update labels.
102 connect(&m_backend, SIGNAL(chatPrefixChanged(ndn::Name)),
103 this, SLOT(updateLabels(ndn::Name)));
104
Yingdi Yuf3401182015-02-02 20:21:07 -0800105 connect(&m_backend, SIGNAL(refreshChatDialog(ndn::Name)),
106 this, SLOT(updateLabels(ndn::Name)));
107
Yingdi Yud45777b2014-10-16 23:54:11 -0700108 // 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{
Qiuhan Ding4b8cfaa2015-03-10 17:03:48 -0700265 struct tm* localTime = localtime(&timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800266
Qiuhan Ding4b8cfaa2015-03-10 17:03:48 -0700267 return QString("%1:%2:%3")
268 .arg(localTime->tm_hour, 2, 10, QChar('0'))
269 .arg(localTime->tm_min, 2, 10, QChar('0'))
270 .arg(localTime->tm_sec, 2, 10, QChar('0'));
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800271}
272
273void
274ChatDialog::printTimeInCell(QTextTable *table, time_t timestamp)
275{
276 QTextCharFormat timeFormat;
277 timeFormat.setForeground(Qt::gray);
278 timeFormat.setFontUnderline(true);
279 timeFormat.setUnderlineColor(Qt::gray);
280 QTextTableCell timeCell = table->cellAt(0, 1);
281 timeCell.setFormat(timeFormat);
282 timeCell.firstCursorPosition().insertText(formatTime(timestamp));
283}
284
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800285void
286ChatDialog::showMessage(const QString& from, const QString& data)
287{
288 if (!isActiveWindow())
289 emit showChatMessage(QString::fromStdString(m_chatroomName),
290 from, data);
291}
292
293void
294ChatDialog::fitView()
295{
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800296 QRectF rect = m_scene->itemsBoundingRect();
297 m_scene->setSceneRect(rect);
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700298 ui->syncTreeViewer->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio);
299
300 QRectF trustRect = m_trustScene->itemsBoundingRect();
301 m_trustScene->setSceneRect(trustRect);
302 ui->trustTreeViewer->fitInView(m_trustScene->itemsBoundingRect(), Qt::KeepAspectRatio);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800303}
304
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800305// public slots:
306void
Yingdi Yue8323b62014-09-02 17:24:15 -0700307ChatDialog::onShow()
308{
309 this->show();
310 this->raise();
311 this->activateWindow();
312}
313
314void
Yingdi Yud45777b2014-10-16 23:54:11 -0700315ChatDialog::shutdown()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800316{
Yingdi Yud45777b2014-10-16 23:54:11 -0700317 if (m_backend.isRunning()) {
318 emit shutdownBackend();
319 m_backend.wait();
320 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800321 hide();
322 emit closeChatDialog(QString::fromStdString(m_chatroomName));
323}
324
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800325// private slots:
326void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800327ChatDialog::updateSyncTree(std::vector<chronochat::NodeInfo> updates, QString rootDigest)
Yingdi Yud45777b2014-10-16 23:54:11 -0700328{
329 m_scene->processSyncUpdate(updates, rootDigest);
330}
331
332void
333ChatDialog::receiveChatMessage(QString nick, QString text, time_t timestamp)
334{
335 appendChatMessage(nick, text, timestamp);
336}
337
338void
Yingdi Yud45777b2014-10-16 23:54:11 -0700339ChatDialog::removeSession(QString sessionPrefix, QString nick, time_t timestamp)
340{
341 appendControlMessage(nick, "leaves room", timestamp);
342 m_scene->removeNode(sessionPrefix);
343 m_rosterModel->setStringList(m_scene->getRosterList());
Qiuhan Ding112ee482015-03-11 11:54:11 -0700344 fitView();
Yingdi Yud45777b2014-10-16 23:54:11 -0700345}
346
347void
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -0800348ChatDialog::receiveMessage(QString sessionPrefix, QString nick, uint64_t seqNo, time_t timestamp,
349 bool addSession)
Yingdi Yud45777b2014-10-16 23:54:11 -0700350{
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -0800351 m_scene->updateNode(sessionPrefix, nick, seqNo);
Yingdi Yud45777b2014-10-16 23:54:11 -0700352 m_scene->messageReceived(sessionPrefix);
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -0800353 if (addSession) {
354 appendControlMessage(nick, "enters room", timestamp);
355 m_rosterModel->setStringList(m_scene->getRosterList());
356 }
Yingdi Yuf3401182015-02-02 20:21:07 -0800357 fitView();
Yingdi Yud45777b2014-10-16 23:54:11 -0700358}
359
360void
361ChatDialog::updateLabels(Name newChatPrefix)
362{
363 // Reset DigestTree
364 m_scene->clearAll();
365 m_scene->plot("Empty");
366
367 // Display chatroom name
368 QString chatroomName = QString("Chatroom: %1").arg(QString::fromStdString(m_chatroomName));
369 ui->infoLabel->setStyleSheet("QLabel {color: #630; font-size: 16px; font: bold \"Verdana\";}");
370 ui->infoLabel->setText(chatroomName);
371
372 // Display chat message prefix
373 QString chatPrefix;
374 if (PRIVATE_PREFIX.isPrefixOf(newChatPrefix)) {
375 chatPrefix =
376 QString("<Warning: no connection to hub or hub does not support prefix autoconfig.>\n"
377 "<Prefix = %1>")
378 .arg(QString::fromStdString(newChatPrefix.toUri()));
379 ui->prefixLabel->setStyleSheet(
380 "QLabel {color: red; font-size: 12px; font: bold \"Verdana\";}");
381 }
382 else {
383 chatPrefix = QString("<Prefix = %1>")
384 .arg(QString::fromStdString(newChatPrefix.toUri()));
385 ui->prefixLabel->setStyleSheet(
386 "QLabel {color: Green; font-size: 12px; font: bold \"Verdana\";}");
387 }
388 ui->prefixLabel->setText(chatPrefix);
Qiuhan Ding112ee482015-03-11 11:54:11 -0700389 fitView();
Yingdi Yud45777b2014-10-16 23:54:11 -0700390}
391
392void
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800393ChatDialog::onReturnPressed()
394{
395 QString text = ui->lineEdit->text();
Yingdi Yud45777b2014-10-16 23:54:11 -0700396
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800397 if (text.isEmpty())
398 return;
399
400 ui->lineEdit->clear();
401
Yingdi Yud45777b2014-10-16 23:54:11 -0700402 time_t timestamp =
403 static_cast<time_t>(time::toUnixTimestamp(time::system_clock::now()).count() / 1000);
404 // appendChatMessage(m_nick, text, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800405
Yingdi Yud45777b2014-10-16 23:54:11 -0700406 emit msgToSent(text, timestamp);
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800407
408 fitView();
409}
410
Yingdi Yufa0b6a02014-04-30 14:26:42 -0700411void
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700412ChatDialog::onSyncTreeButtonPressed()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800413{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700414 if (ui->syncTreeViewer->isVisible()) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700415 ui->syncTreeViewer->hide();
416 ui->syncTreeButton->setText("Show ChronoSync Tree");
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800417 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700418 else {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700419 ui->syncTreeViewer->show();
420 ui->syncTreeButton->setText("Hide ChronoSync Tree");
421 }
422
423 fitView();
424}
425
426void
427ChatDialog::onTrustTreeButtonPressed()
428{
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700429 if (ui->trustTreeViewer->isVisible()) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700430 ui->trustTreeViewer->hide();
431 ui->trustTreeButton->setText("Show Trust Tree");
432 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700433 else {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700434 ui->trustTreeViewer->show();
435 ui->trustTreeButton->setText("Hide Trust Tree");
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800436 }
437
438 fitView();
439}
440
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700441void ChatDialog::enableSyncTreeDisplay()
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800442{
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700443 ui->syncTreeButton->setEnabled(true);
Yingdi Yud45777b2014-10-16 23:54:11 -0700444 ui->syncTreeViewer->show();
445 fitView();
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800446}
447
Yingdi Yueb692ac2015-02-10 18:46:18 -0800448} // namespace chronochat
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800449
Mengjin Yanaec70742014-08-25 10:37:45 -0700450
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800451#if WAF
452#include "chat-dialog.moc"
Yingdi Yu42125862014-08-07 17:04:28 -0700453// #include "chat-dialog.cpp.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800454#endif