1 #ifndef USERLIST_H
2 #define USERLIST_H
3 
4 #include "pb/moderator_commands.pb.h"
5 #include "user_level.h"
6 
7 #include <QComboBox>
8 #include <QDialog>
9 #include <QGroupBox>
10 #include <QStyledItemDelegate>
11 #include <QTreeWidgetItem>
12 
13 class QTreeWidget;
14 class ServerInfo_User;
15 class AbstractClient;
16 class TabSupervisor;
17 class QLabel;
18 class QCheckBox;
19 class QSpinBox;
20 class QRadioButton;
21 class QPlainTextEdit;
22 class Response;
23 class CommandContainer;
24 class UserContextMenu;
25 
26 class BanDialog : public QDialog
27 {
28     Q_OBJECT
29 private:
30     QLabel *daysLabel, *hoursLabel, *minutesLabel;
31     QCheckBox *nameBanCheckBox, *ipBanCheckBox, *idBanCheckBox;
32     QLineEdit *nameBanEdit, *ipBanEdit, *idBanEdit;
33     QSpinBox *daysEdit, *hoursEdit, *minutesEdit;
34     QRadioButton *permanentRadio, *temporaryRadio;
35     QPlainTextEdit *reasonEdit, *visibleReasonEdit;
36 private slots:
37     void okClicked();
38     void enableTemporaryEdits(bool enabled);
39 
40 public:
41     BanDialog(const ServerInfo_User &info, QWidget *parent = nullptr);
42     QString getBanName() const;
43     QString getBanIP() const;
44     QString getBanId() const;
45     int getMinutes() const;
46     QString getReason() const;
47     QString getVisibleReason() const;
48 };
49 
50 class WarningDialog : public QDialog
51 {
52     Q_OBJECT
53 private:
54     QLabel *descriptionLabel;
55     QLineEdit *nameWarning;
56     QComboBox *warningOption;
57     QLineEdit *warnClientID;
58 private slots:
59     void okClicked();
60 
61 public:
62     WarningDialog(const QString userName, const QString clientID, QWidget *parent = nullptr);
63     QString getName() const;
64     QString getWarnID() const;
65     QString getReason() const;
66     void addWarningOption(const QString warning);
67 };
68 
69 class UserListItemDelegate : public QStyledItemDelegate
70 {
71 public:
72     UserListItemDelegate(QObject *const parent);
73     bool
74     editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
75 };
76 
77 class UserListTWI : public QTreeWidgetItem
78 {
79 private:
80     ServerInfo_User userInfo;
81 
82 public:
83     UserListTWI(const ServerInfo_User &_userInfo);
getUserInfo()84     const ServerInfo_User &getUserInfo() const
85     {
86         return userInfo;
87     }
88     void setUserInfo(const ServerInfo_User &_userInfo);
89     void setOnline(bool online);
90     bool operator<(const QTreeWidgetItem &other) const;
91 };
92 
93 class UserList : public QGroupBox
94 {
95     Q_OBJECT
96 public:
97     enum UserListType
98     {
99         AllUsersList,
100         RoomList,
101         BuddyList,
102         IgnoreList
103     };
104 
105 private:
106     QMap<QString, UserListTWI *> users;
107     TabSupervisor *tabSupervisor;
108     AbstractClient *client;
109     UserListType type;
110     QTreeWidget *userTree;
111     UserListItemDelegate *itemDelegate;
112     UserContextMenu *userContextMenu;
113     int onlineCount;
114     QString titleStr;
115     void updateCount();
116 private slots:
117     void userClicked(QTreeWidgetItem *item, int column);
118 signals:
119     void openMessageDialog(const QString &userName, bool focus);
120     void addBuddy(const QString &userName);
121     void removeBuddy(const QString &userName);
122     void addIgnore(const QString &userName);
123     void removeIgnore(const QString &userName);
124 
125 public:
126     UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserListType _type, QWidget *parent = nullptr);
127     void retranslateUi();
128     void processUserInfo(const ServerInfo_User &user, bool online);
129     bool deleteUser(const QString &userName);
130     void setUserOnline(const QString &userName, bool online);
getUsers()131     const QMap<QString, UserListTWI *> &getUsers() const
132     {
133         return users;
134     }
135     void showContextMenu(const QPoint &pos, const QModelIndex &index);
136     void sortItems();
137 };
138 
139 #endif
140