blob: 59c07b8cfd52c4aca3fd70883e35dce01aa79654 [file] [log] [blame]
Qiuhan Ding43c8e162015-02-02 15:16:48 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Qiuhan Ding43c8e162015-02-02 15:16:48 -08004 *
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 Patil3d850902020-11-23 12:19:14 +053016#include <QItemSelection>
Qiuhan Ding43c8e162015-02-02 15:16:48 -080017
18#ifndef Q_MOC_RUN
19#include "chatroom-info.hpp"
20#endif
21
22namespace Ui {
23class DiscoveryPanel;
Varun Patila24bd3e2020-11-24 10:08:33 +053024} // namespace Ui
Qiuhan Ding43c8e162015-02-02 15:16:48 -080025
26namespace chronochat {
27
28class DiscoveryPanel : public QDialog
29{
30 Q_OBJECT
31
32public:
33 explicit
34 DiscoveryPanel(QWidget* parent = 0);
35
36 virtual
37 ~DiscoveryPanel();
38
39private:
40 void
41 resetPanel();
42
43 void
44 refreshPanel();
45
46signals:
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 Dingba3e57a2015-01-08 19:07:39 -080076 /**
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 Ding43c8e162015-02-02 15:16:48 -080087public 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 Dingba3e57a2015-01-08 19:07:39 -0800107 * @param isParticipant if the user is a participant of the chatroom
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800108 */
109 void
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800110 onChatroomInfoReady(const ChatroomInfo& info, bool isParticipant);
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800111
112private 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 Dingba3e57a2015-01-08 19:07:39 -0800124 void
125 onRequestInvitation();
126
127 void
128 onInvitationRequestResult(const std::string& message);
129
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800130private:
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 Ding0b21e292015-03-12 14:18:18 -0700142
143 bool m_isParticipant;
Qiuhan Ding43c8e162015-02-02 15:16:48 -0800144};
145
146} // namespace chronochat
147
148#endif // CHRONOCHAT_DISCOVERY_PANEL_HPP