blob: 5b9a14f6b02285c22221ec964996e37e5f9e0e39 [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001/* -*- 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 Yu0b0a7362014-08-05 16:31:30 -07004 *
5 * BSD license, See the LICENSE file for more information
6 *
7 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
8 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9 * Yingdi Yu <yingdi@cs.ucla.edu>
10 */
11
Mengjin Yanaec70742014-08-25 10:37:45 -070012#ifndef CHRONOCHAT_CHAT_DIALOG_HPP
13#define CHRONOCHAT_CHAT_DIALOG_HPP
Yingdi Yu0b0a7362014-08-05 16:31:30 -070014
15#include <QDialog>
16#include <QTextTable>
17#include <QStringListModel>
18#include <QSystemTrayIcon>
19#include <QMenu>
20#include <QTimer>
21
22#ifndef Q_MOC_RUN
Yingdi Yu0b0a7362014-08-05 16:31:30 -070023#include "invitation.hpp"
Yingdi Yud45777b2014-10-16 23:54:11 -070024
Yingdi Yu0b0a7362014-08-05 16:31:30 -070025#include "digest-tree-scene.hpp"
26#include "trust-tree-scene.hpp"
27#include "trust-tree-node.hpp"
Yingdi Yud45777b2014-10-16 23:54:11 -070028#include "chat-dialog-backend.hpp"
29
Mengjin Yanaec70742014-08-25 10:37:45 -070030#include "chatroom-info.hpp"
Yingdi Yu0b0a7362014-08-05 16:31:30 -070031#endif
32
Yingdi Yu0b0a7362014-08-05 16:31:30 -070033namespace Ui {
34class ChatDialog;
Varun Patila24bd3e2020-11-24 10:08:33 +053035} // namespace Ui
Yingdi Yu0b0a7362014-08-05 16:31:30 -070036
Yingdi Yueb692ac2015-02-10 18:46:18 -080037namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070038
39class ChatDialog : public QDialog
40{
41 Q_OBJECT
42
43public:
44 explicit
Yingdi Yud45777b2014-10-16 23:54:11 -070045 ChatDialog(const Name& chatroomPrefix,
46 const Name& userChatPrefix,
47 const Name& routingPrefix,
48 const std::string& chatroomName,
Yingdi Yu0b0a7362014-08-05 16:31:30 -070049 const std::string& nick,
Yingdi Yud45777b2014-10-16 23:54:11 -070050 bool isSecured = false,
Yingdi Yu45da92a2015-02-02 13:17:03 -080051 const Name& signingId = Name(),
Yingdi Yu0b0a7362014-08-05 16:31:30 -070052 QWidget* parent = 0);
53
54 ~ChatDialog();
55
56 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070057 closeEvent(QCloseEvent* e);
58
59 void
60 changeEvent(QEvent* e);
61
62 void
63 resizeEvent(QResizeEvent* e);
64
65 void
66 showEvent(QShowEvent* e);
67
Yingdi Yud45777b2014-10-16 23:54:11 -070068 ChatDialogBackend*
69 getBackend()
70 {
71 return &m_backend;
72 }
73
74 void
75 addSyncAnchor(const Invitation& invitation)
76 {
77 }
78
Qiuhan Ding43c8e162015-02-02 15:16:48 -080079 ChatroomInfo
Yingdi Yud45777b2014-10-16 23:54:11 -070080 getChatroomInfo();
81
Yingdi Yu0b0a7362014-08-05 16:31:30 -070082private:
83 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070084 disableSyncTreeDisplay();
85
86 void
Yingdi Yud45777b2014-10-16 23:54:11 -070087 appendChatMessage(const QString& nick, const QString& text, time_t timestamp);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070088
89 void
Yingdi Yud45777b2014-10-16 23:54:11 -070090 appendControlMessage(const QString& nick, const QString& action, time_t timestamp);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070091
92 QString
93 formatTime(time_t timestamp);
94
95 void
96 printTimeInCell(QTextTable* table, time_t timestamp);
97
Yingdi Yu0b0a7362014-08-05 16:31:30 -070098 void
99 showMessage(const QString&, const QString&);
100
101 void
102 fitView();
103
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700104signals:
105 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700106 shutdownBackend();
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700107
108 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700109 msgToSent(QString text, time_t timestamp);
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700110
111 void
112 closeChatDialog(const QString& chatroomName);
113
114 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700115 showChatMessage(const QString& chatroomName, const QString& from, const QString& data);
116
117 void
118 resetIcon();
119
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700120public slots:
121 void
Yingdi Yue8323b62014-09-02 17:24:15 -0700122 onShow();
123
124 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700125 shutdown();
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700126
127private slots:
128 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800129 updateSyncTree(std::vector<chronochat::NodeInfo> updates, QString rootDigest);
Yingdi Yud45777b2014-10-16 23:54:11 -0700130
131 void
132 receiveChatMessage(QString nick, QString text, time_t timestamp);
133
134 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700135 removeSession(QString sessionPrefix, QString nick, time_t timestamp);
136
137 void
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -0800138 receiveMessage(QString sessionPrefix, QString nick, uint64_t seqNo, time_t timestamp,
139 bool addSession);
Yingdi Yud45777b2014-10-16 23:54:11 -0700140
141 void
142 updateLabels(ndn::Name newChatPrefix);
143
144 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700145 onReturnPressed();
146
147 void
148 onSyncTreeButtonPressed();
149
150 void
151 onTrustTreeButtonPressed();
152
153 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700154 enableSyncTreeDisplay();
155
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700156private:
Yingdi Yud45777b2014-10-16 23:54:11 -0700157 Ui::ChatDialog* ui;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700158
Yingdi Yud45777b2014-10-16 23:54:11 -0700159 ChatDialogBackend m_backend;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700160
161 std::string m_chatroomName;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800162 Name m_chatroomPrefix;
Yingdi Yud45777b2014-10-16 23:54:11 -0700163 QString m_nick;
164 bool m_isSecured;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700165
166
Yingdi Yud45777b2014-10-16 23:54:11 -0700167 DigestTreeScene* m_scene;
168 TrustTreeScene* m_trustScene;
169 QStringListModel* m_rosterModel;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700170};
171
Yingdi Yueb692ac2015-02-10 18:46:18 -0800172} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700173
Mengjin Yanaec70742014-08-25 10:37:45 -0700174#endif // CHRONOCHAT_CHAT_DIALOG_HPP