blob: 74dd76d8de365d10c56bb0f77d97907ee21f2db7 [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
79 shared_ptr<ChatroomInfo>
80 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
120 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800121 rosterChanged(const chronochat::ChatroomInfo& info);
Mengjin Yanaec70742014-08-25 10:37:45 -0700122
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700123public slots:
124 void
Yingdi Yue8323b62014-09-02 17:24:15 -0700125 onShow();
126
127 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700128 shutdown();
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700129
130private slots:
131 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800132 updateSyncTree(std::vector<chronochat::NodeInfo> updates, QString rootDigest);
Yingdi Yud45777b2014-10-16 23:54:11 -0700133
134 void
135 receiveChatMessage(QString nick, QString text, time_t timestamp);
136
137 void
138 addSession(QString sessionPrefix, QString nick, time_t timestamp);
139
140 void
141 removeSession(QString sessionPrefix, QString nick, time_t timestamp);
142
143 void
144 updateNick(QString sessionPrefix, QString nick);
145
146 void
147 receiveMessage(QString sessionPrefix);
148
149 void
150 updateLabels(ndn::Name newChatPrefix);
151
152 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700153 onReturnPressed();
154
155 void
156 onSyncTreeButtonPressed();
157
158 void
159 onTrustTreeButtonPressed();
160
161 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700162 enableSyncTreeDisplay();
163
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700164private:
Yingdi Yud45777b2014-10-16 23:54:11 -0700165 Ui::ChatDialog* ui;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700166
Yingdi Yud45777b2014-10-16 23:54:11 -0700167 ChatDialogBackend m_backend;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700168
169 std::string m_chatroomName;
Yingdi Yud45777b2014-10-16 23:54:11 -0700170 QString m_nick;
171 bool m_isSecured;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700172
173
Yingdi Yud45777b2014-10-16 23:54:11 -0700174 DigestTreeScene* m_scene;
175 TrustTreeScene* m_trustScene;
176 QStringListModel* m_rosterModel;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700177};
178
Yingdi Yueb692ac2015-02-10 18:46:18 -0800179} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700180
Mengjin Yanaec70742014-08-25 10:37:45 -0700181#endif // CHRONOCHAT_CHAT_DIALOG_HPP