blob: 7f1a7261bd226a571fa19acaba5ed6d0cec192c1 [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
37namespace chronos {
38
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 Yu0b0a7362014-08-05 16:31:30 -070051 QWidget* parent = 0);
52
53 ~ChatDialog();
54
55 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070056 closeEvent(QCloseEvent* e);
57
58 void
59 changeEvent(QEvent* e);
60
61 void
62 resizeEvent(QResizeEvent* e);
63
64 void
65 showEvent(QShowEvent* e);
66
Yingdi Yud45777b2014-10-16 23:54:11 -070067 ChatDialogBackend*
68 getBackend()
69 {
70 return &m_backend;
71 }
72
73 void
74 addSyncAnchor(const Invitation& invitation)
75 {
76 }
77
78 shared_ptr<ChatroomInfo>
79 getChatroomInfo();
80
Yingdi Yu0b0a7362014-08-05 16:31:30 -070081private:
82 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070083 disableSyncTreeDisplay();
84
85 void
Yingdi Yud45777b2014-10-16 23:54:11 -070086 appendChatMessage(const QString& nick, const QString& text, time_t timestamp);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070087
88 void
Yingdi Yud45777b2014-10-16 23:54:11 -070089 appendControlMessage(const QString& nick, const QString& action, time_t timestamp);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070090
91 QString
92 formatTime(time_t timestamp);
93
94 void
95 printTimeInCell(QTextTable* table, time_t timestamp);
96
Yingdi Yu0b0a7362014-08-05 16:31:30 -070097 void
98 showMessage(const QString&, const QString&);
99
100 void
101 fitView();
102
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700103signals:
104 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700105 shutdownBackend();
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700106
107 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700108 msgToSent(QString text, time_t timestamp);
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700109
110 void
111 closeChatDialog(const QString& chatroomName);
112
113 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700114 showChatMessage(const QString& chatroomName, const QString& from, const QString& data);
115
116 void
117 resetIcon();
118
119 void
Mengjin Yanaec70742014-08-25 10:37:45 -0700120 rosterChanged(const chronos::ChatroomInfo& info);
121
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700122public slots:
123 void
Yingdi Yue8323b62014-09-02 17:24:15 -0700124 onShow();
125
126 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700127 shutdown();
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700128
129private slots:
130 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700131 updateSyncTree(std::vector<chronos::NodeInfo> updates, QString rootDigest);
132
133 void
134 receiveChatMessage(QString nick, QString text, time_t timestamp);
135
136 void
137 addSession(QString sessionPrefix, QString nick, time_t timestamp);
138
139 void
140 removeSession(QString sessionPrefix, QString nick, time_t timestamp);
141
142 void
143 updateNick(QString sessionPrefix, QString nick);
144
145 void
146 receiveMessage(QString sessionPrefix);
147
148 void
149 updateLabels(ndn::Name newChatPrefix);
150
151 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700152 onReturnPressed();
153
154 void
155 onSyncTreeButtonPressed();
156
157 void
158 onTrustTreeButtonPressed();
159
160 void
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700161 enableSyncTreeDisplay();
162
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700163private:
Yingdi Yud45777b2014-10-16 23:54:11 -0700164 Ui::ChatDialog* ui;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700165
Yingdi Yud45777b2014-10-16 23:54:11 -0700166 ChatDialogBackend m_backend;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700167
168 std::string m_chatroomName;
Yingdi Yud45777b2014-10-16 23:54:11 -0700169 QString m_nick;
170 bool m_isSecured;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700171
172
Yingdi Yud45777b2014-10-16 23:54:11 -0700173 DigestTreeScene* m_scene;
174 TrustTreeScene* m_trustScene;
175 QStringListModel* m_rosterModel;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700176};
177
178} // namespace chronos
179
Mengjin Yanaec70742014-08-25 10:37:45 -0700180#endif // CHRONOCHAT_CHAT_DIALOG_HPP