Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 1 | /* -*- 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 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; |
| 35 | } |
| 36 | |
| 37 | namespace chronos { |
| 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 | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 51 | QWidget* parent = 0); |
| 52 | |
| 53 | ~ChatDialog(); |
| 54 | |
| 55 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 56 | 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 Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 67 | 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 Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 81 | private: |
| 82 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 83 | disableSyncTreeDisplay(); |
| 84 | |
| 85 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 86 | appendChatMessage(const QString& nick, const QString& text, time_t timestamp); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 87 | |
| 88 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 89 | appendControlMessage(const QString& nick, const QString& action, time_t timestamp); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 90 | |
| 91 | QString |
| 92 | formatTime(time_t timestamp); |
| 93 | |
| 94 | void |
| 95 | printTimeInCell(QTextTable* table, time_t timestamp); |
| 96 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 97 | void |
| 98 | showMessage(const QString&, const QString&); |
| 99 | |
| 100 | void |
| 101 | fitView(); |
| 102 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 103 | signals: |
| 104 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 105 | shutdownBackend(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 106 | |
| 107 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 108 | msgToSent(QString text, time_t timestamp); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 109 | |
| 110 | void |
| 111 | closeChatDialog(const QString& chatroomName); |
| 112 | |
| 113 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 114 | showChatMessage(const QString& chatroomName, const QString& from, const QString& data); |
| 115 | |
| 116 | void |
| 117 | resetIcon(); |
| 118 | |
| 119 | void |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 120 | rosterChanged(const chronos::ChatroomInfo& info); |
| 121 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 122 | public slots: |
| 123 | void |
Yingdi Yu | e8323b6 | 2014-09-02 17:24:15 -0700 | [diff] [blame] | 124 | onShow(); |
| 125 | |
| 126 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 127 | shutdown(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 128 | |
| 129 | private slots: |
| 130 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 131 | 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 Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 152 | onReturnPressed(); |
| 153 | |
| 154 | void |
| 155 | onSyncTreeButtonPressed(); |
| 156 | |
| 157 | void |
| 158 | onTrustTreeButtonPressed(); |
| 159 | |
| 160 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 161 | enableSyncTreeDisplay(); |
| 162 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 163 | private: |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 164 | Ui::ChatDialog* ui; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 165 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 166 | ChatDialogBackend m_backend; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 167 | |
| 168 | std::string m_chatroomName; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 169 | QString m_nick; |
| 170 | bool m_isSecured; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 171 | |
| 172 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame^] | 173 | DigestTreeScene* m_scene; |
| 174 | TrustTreeScene* m_trustScene; |
| 175 | QStringListModel* m_rosterModel; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | } // namespace chronos |
| 179 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 180 | #endif // CHRONOCHAT_CHAT_DIALOG_HPP |