Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 3 | * Copyright (c) 2020, Regents of the University of California |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 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 Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 12 | #ifndef CHRONOCHAT_CHAT_DIALOG_HPP |
| 13 | #define CHRONOCHAT_CHAT_DIALOG_HPP |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 14 | |
| 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 Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 23 | #include "invitation.hpp" |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 24 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 25 | #include "digest-tree-scene.hpp" |
| 26 | #include "trust-tree-scene.hpp" |
| 27 | #include "trust-tree-node.hpp" |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 28 | #include "chat-dialog-backend.hpp" |
| 29 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 30 | #include "chatroom-info.hpp" |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 31 | #endif |
| 32 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 33 | namespace Ui { |
| 34 | class ChatDialog; |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 35 | } // namespace Ui |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 36 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 37 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 38 | |
| 39 | class ChatDialog : public QDialog |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | public: |
| 44 | explicit |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 45 | ChatDialog(const Name& chatroomPrefix, |
| 46 | const Name& userChatPrefix, |
| 47 | const Name& routingPrefix, |
| 48 | const std::string& chatroomName, |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 49 | const std::string& nick, |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 50 | bool isSecured = false, |
Yingdi Yu | 45da92a | 2015-02-02 13:17:03 -0800 | [diff] [blame] | 51 | const Name& signingId = Name(), |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 52 | QWidget* parent = 0); |
| 53 | |
| 54 | ~ChatDialog(); |
| 55 | |
| 56 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 57 | 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 Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 68 | ChatDialogBackend* |
| 69 | getBackend() |
| 70 | { |
| 71 | return &m_backend; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | addSyncAnchor(const Invitation& invitation) |
| 76 | { |
| 77 | } |
| 78 | |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 79 | ChatroomInfo |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 80 | getChatroomInfo(); |
| 81 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 82 | private: |
| 83 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 84 | disableSyncTreeDisplay(); |
| 85 | |
| 86 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 87 | appendChatMessage(const QString& nick, const QString& text, time_t timestamp); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 88 | |
| 89 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 90 | appendControlMessage(const QString& nick, const QString& action, time_t timestamp); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 91 | |
| 92 | QString |
| 93 | formatTime(time_t timestamp); |
| 94 | |
| 95 | void |
| 96 | printTimeInCell(QTextTable* table, time_t timestamp); |
| 97 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 98 | void |
| 99 | showMessage(const QString&, const QString&); |
| 100 | |
| 101 | void |
| 102 | fitView(); |
| 103 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 104 | signals: |
| 105 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 106 | shutdownBackend(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 107 | |
| 108 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 109 | msgToSent(QString text, time_t timestamp); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 110 | |
| 111 | void |
| 112 | closeChatDialog(const QString& chatroomName); |
| 113 | |
| 114 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 115 | showChatMessage(const QString& chatroomName, const QString& from, const QString& data); |
| 116 | |
| 117 | void |
| 118 | resetIcon(); |
| 119 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 120 | public slots: |
| 121 | void |
Yingdi Yu | e8323b6 | 2014-09-02 17:24:15 -0700 | [diff] [blame] | 122 | onShow(); |
| 123 | |
| 124 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 125 | shutdown(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 126 | |
| 127 | private slots: |
| 128 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 129 | updateSyncTree(std::vector<chronochat::NodeInfo> updates, QString rootDigest); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 130 | |
| 131 | void |
| 132 | receiveChatMessage(QString nick, QString text, time_t timestamp); |
| 133 | |
| 134 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 135 | removeSession(QString sessionPrefix, QString nick, time_t timestamp); |
| 136 | |
| 137 | void |
Qiuhan Ding | 7a4e7ef | 2015-02-03 20:25:50 -0800 | [diff] [blame] | 138 | receiveMessage(QString sessionPrefix, QString nick, uint64_t seqNo, time_t timestamp, |
| 139 | bool addSession); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 140 | |
| 141 | void |
| 142 | updateLabels(ndn::Name newChatPrefix); |
| 143 | |
| 144 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 145 | onReturnPressed(); |
| 146 | |
| 147 | void |
| 148 | onSyncTreeButtonPressed(); |
| 149 | |
| 150 | void |
| 151 | onTrustTreeButtonPressed(); |
| 152 | |
| 153 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 154 | enableSyncTreeDisplay(); |
| 155 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 156 | private: |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 157 | Ui::ChatDialog* ui; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 158 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 159 | ChatDialogBackend m_backend; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 160 | |
| 161 | std::string m_chatroomName; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 162 | Name m_chatroomPrefix; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 163 | QString m_nick; |
| 164 | bool m_isSecured; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 165 | |
| 166 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 167 | DigestTreeScene* m_scene; |
| 168 | TrustTreeScene* m_trustScene; |
| 169 | QStringListModel* m_rosterModel; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 172 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 173 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 174 | #endif // CHRONOCHAT_CHAT_DIALOG_HPP |