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