1 /*
2     Copyright © 2015-2019 by The qTox Project Contributors
3 
4     This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6     qTox is libre software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     qTox is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with qTox.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CONTENTDIALOG_H
21 #define CONTENTDIALOG_H
22 
23 #include "src/core/groupid.h"
24 #include "src/core/toxpk.h"
25 #include "src/model/dialogs/idialogs.h"
26 #include "src/model/status.h"
27 #include "src/widget/genericchatitemlayout.h"
28 #include "src/widget/tool/activatedialog.h"
29 
30 #include <memory>
31 
32 template <typename K, typename V>
33 class QHash;
34 
35 class ContentLayout;
36 class Friend;
37 class FriendChatroom;
38 class FriendListLayout;
39 class FriendWidget;
40 class GenericChatForm;
41 class GenericChatroomWidget;
42 class Group;
43 class GroupChatroom;
44 class GroupWidget;
45 class QCloseEvent;
46 class QSplitter;
47 
48 class ContentDialog : public ActivateDialog, public IDialogs
49 {
50     Q_OBJECT
51 public:
52     explicit ContentDialog(QWidget* parent = nullptr);
53     ~ContentDialog() override;
54 
55     FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
56     GroupWidget* addGroup(std::shared_ptr<GroupChatroom> chatroom, GenericChatForm* form);
57     void removeFriend(const ToxPk& friendPk) override;
58     void removeGroup(const GroupId& groupId) override;
59     int chatroomCount() const override;
60     void ensureSplitterVisible();
61     void updateTitleAndStatusIcon();
62 
63     void cycleContacts(bool forward, bool loop = true);
64     void onVideoShow(QSize size);
65     void onVideoHide();
66 
67     void addFriendWidget(FriendWidget* widget, Status::Status status);
68     bool isActiveWidget(GenericChatroomWidget* widget);
69 
70     bool hasContact(const ContactId& contactId) const override;
71     bool isContactActive(const ContactId& contactId) const override;
72 
73     void focusContact(const ContactId& friendPk);
74     void updateFriendStatus(const ToxPk& friendPk, Status::Status status);
75     void updateContactStatusLight(const ContactId& contactId);
76 
77     void setStatusMessage(const ToxPk& friendPk, const QString& message);
78 
79 signals:
80     void friendDialogShown(const Friend* f);
81     void groupDialogShown(Group* g);
82     void addFriendDialog(Friend* frnd, ContentDialog* contentDialog);
83     void addGroupDialog(Group* group, ContentDialog* contentDialog);
84     void activated();
85     void willClose();
86     void connectFriendWidget(FriendWidget& friendWidget);
87 
88 public slots:
89     void reorderLayouts(bool newGroupOnTop);
90     void previousContact();
91     void nextContact();
92     void setUsername(const QString& newName);
93 
94 protected:
95     bool event(QEvent* event) final override;
96     void dragEnterEvent(QDragEnterEvent* event) final override;
97     void dropEvent(QDropEvent* event) final override;
98     void changeEvent(QEvent* event) override;
99     void resizeEvent(QResizeEvent* event) override;
100     void moveEvent(QMoveEvent* event) override;
101     void keyPressEvent(QKeyEvent* event) override;
102 
103 public slots:
104     void activate(GenericChatroomWidget* widget);
105 
106 private slots:
107     void updateFriendWidget(const ToxPk& friendPk, QString alias);
108     void onGroupchatPositionChanged(bool top);
109 
110 private:
111     void closeIfEmpty();
112     void closeEvent(QCloseEvent* event) override;
113 
114     void retranslateUi();
115     void saveDialogGeometry();
116     void saveSplitterState();
117     QLayout* nextLayout(QLayout* layout, bool forward) const;
118     int getCurrentLayout(QLayout*& layout);
119     void focusCommon(const ContactId& id, QHash<const ContactId&, GenericChatroomWidget*> list);
120 
121 private:
122     QList<QLayout*> layouts;
123     QSplitter* splitter;
124     FriendListLayout* friendLayout;
125     GenericChatItemLayout groupLayout;
126     ContentLayout* contentLayout;
127     GenericChatroomWidget* activeChatroomWidget;
128     QSize videoSurfaceSize;
129     int videoCount;
130 
131     QHash<const ContactId&, GenericChatroomWidget*> contactWidgets;
132     QHash<const ContactId&, GenericChatForm*> contactChatForms;
133 
134     QString username;
135 };
136 
137 #endif // CONTENTDIALOG_H
138