Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [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 |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 4 | * |
| 5 | * BSD license, See the LICENSE file for more information |
| 6 | * |
| 7 | * Author: Qiuhan Ding <qiuhanding@cs.ucla.edu> |
| 8 | * Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #ifndef CHRONOCHAT_DISCOVERY_PANEL_HPP |
| 12 | #define CHRONOCHAT_DISCOVERY_PANEL_HPP |
| 13 | |
| 14 | #include <QDialog> |
| 15 | #include <QStringListModel> |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame] | 16 | #include <QItemSelection> |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 17 | |
| 18 | #ifndef Q_MOC_RUN |
| 19 | #include "chatroom-info.hpp" |
| 20 | #endif |
| 21 | |
| 22 | namespace Ui { |
| 23 | class DiscoveryPanel; |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 24 | } // namespace Ui |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 25 | |
| 26 | namespace chronochat { |
| 27 | |
| 28 | class DiscoveryPanel : public QDialog |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | |
| 32 | public: |
| 33 | explicit |
| 34 | DiscoveryPanel(QWidget* parent = 0); |
| 35 | |
| 36 | virtual |
| 37 | ~DiscoveryPanel(); |
| 38 | |
| 39 | private: |
| 40 | void |
| 41 | resetPanel(); |
| 42 | |
| 43 | void |
| 44 | refreshPanel(); |
| 45 | |
| 46 | signals: |
| 47 | /** |
| 48 | * @brief get chatroom info from discovery backend |
| 49 | * |
| 50 | * @param chatroomName the name of chatroom we want to get info from |
| 51 | */ |
| 52 | void |
| 53 | waitForChatroomInfo(const QString& chatroomName); |
| 54 | |
| 55 | /** |
| 56 | * @brief send warning if strange things happen |
| 57 | * |
| 58 | * @param msg the message that print in the warning |
| 59 | */ |
| 60 | void |
| 61 | warning(const QString& msg); |
| 62 | |
| 63 | /** |
| 64 | * @brief join the chatroom the user clicked |
| 65 | * |
| 66 | * This function will be called if the join button is clicked. The join button is enabled |
| 67 | * when there is no trust model for the chatroom. |
| 68 | * The user will join the chatroom he choose directly. |
| 69 | * |
| 70 | * @param chatroomName the chatroom to join |
| 71 | * @param secured if security is enabled in this chatroom |
| 72 | */ |
| 73 | void |
| 74 | startChatroom(const QString& chatroomName, bool secured); |
| 75 | |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 76 | /** |
| 77 | * @brief send request for invitation to a chatroom |
| 78 | * |
| 79 | * This function will be called if request invitation button is clicked. |
| 80 | * |
| 81 | * @param chatroomName the chatroom to join |
| 82 | * @param identity the person that the user send the request to |
| 83 | */ |
| 84 | void |
| 85 | sendInvitationRequest(const QString& chatroomName, const QString& identity); |
| 86 | |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 87 | public slots: |
| 88 | /** |
| 89 | * @brief reset the panel when identity is updated |
| 90 | * |
| 91 | */ |
| 92 | void |
| 93 | onIdentityUpdated(const QString& identity); |
| 94 | |
| 95 | /** |
| 96 | * @brief print the chatroom list on the panel |
| 97 | * |
| 98 | * @param list list of chatroom name get from discovery backend |
| 99 | */ |
| 100 | void |
| 101 | onChatroomListReady(const QStringList& list); |
| 102 | |
| 103 | /** |
| 104 | * @brief print the chatroom info on the panel |
| 105 | * |
| 106 | * @param info chatroom info get from discovery backend |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 107 | * @param isParticipant if the user is a participant of the chatroom |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 108 | */ |
| 109 | void |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 110 | onChatroomInfoReady(const ChatroomInfo& info, bool isParticipant); |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 111 | |
| 112 | private slots: |
| 113 | void |
| 114 | onSelectedChatroomChanged(const QItemSelection& selected, |
| 115 | const QItemSelection& deselected); |
| 116 | |
| 117 | void |
| 118 | onSelectedParticipantChanged(const QItemSelection& selected, |
| 119 | const QItemSelection& deselected); |
| 120 | |
| 121 | void |
| 122 | onJoinClicked(); |
| 123 | |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame] | 124 | void |
| 125 | onRequestInvitation(); |
| 126 | |
| 127 | void |
| 128 | onInvitationRequestResult(const std::string& message); |
| 129 | |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 130 | private: |
| 131 | Ui::DiscoveryPanel* ui; |
| 132 | |
| 133 | // Models. |
| 134 | QStringListModel* m_chatroomListModel; |
| 135 | QStringListModel* m_rosterListModel; |
| 136 | |
| 137 | // Internal data structure. |
| 138 | QStringList m_chatroomList; |
| 139 | QStringList m_rosterList; |
| 140 | QString m_chatroom; |
| 141 | QString m_participant; |
Qiuhan Ding | 0b21e29 | 2015-03-12 14:18:18 -0700 | [diff] [blame] | 142 | |
| 143 | bool m_isParticipant; |
Qiuhan Ding | 43c8e16 | 2015-02-02 15:16:48 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | } // namespace chronochat |
| 147 | |
| 148 | #endif // CHRONOCHAT_DISCOVERY_PANEL_HPP |