blob: 919c511f134c04038a084d227d4fa68fe6561b0b [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 *
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;
35}
36
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
135 addSession(QString sessionPrefix, QString nick, time_t timestamp);
136
137 void
138 removeSession(QString sessionPrefix, QString nick, time_t timestamp);
139
140 void
141 updateNick(QString sessionPrefix, QString nick);
142
143 void
144 receiveMessage(QString sessionPrefix);
145
146 void
147 updateLabels(ndn::Name newChatPrefix);
148
149 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700150 onReturnPressed();
151
152 void
153 onSyncTreeButtonPressed();
154
155 void
156 onTrustTreeButtonPressed();
157
158 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700159 enableSyncTreeDisplay();
160
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700161private:
Yingdi Yud45777b2014-10-16 23:54:11 -0700162 Ui::ChatDialog* ui;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700163
Yingdi Yud45777b2014-10-16 23:54:11 -0700164 ChatDialogBackend m_backend;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700165
166 std::string m_chatroomName;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800167 Name m_chatroomPrefix;
Yingdi Yud45777b2014-10-16 23:54:11 -0700168 QString m_nick;
169 bool m_isSecured;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700170
171
Yingdi Yud45777b2014-10-16 23:54:11 -0700172 DigestTreeScene* m_scene;
173 TrustTreeScene* m_trustScene;
174 QStringListModel* m_rosterModel;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700175};
176
Yingdi Yueb692ac2015-02-10 18:46:18 -0800177} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700178
Mengjin Yanaec70742014-08-25 10:37:45 -0700179#endif // CHRONOCHAT_CHAT_DIALOG_HPP