Debian Codegraph @

src/MainWindow.h

raw symbols SCIP
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #pragma once
6
7 #include <functional>
8
9 #include <QHash>
10 #include <QQuickView>
11 #include <QSharedPointer>
12 #include <QSystemTrayIcon>
13
14 #include "UserSettingsPage.h"
15 #include "dock/Dock.h"
16
17 class ChatPage;
18 class RegisterPage;
19 class WelcomePage;
20
21 class TrayIcon;
22 class UserSettings;
23 class MxcImageProvider;
24
25 namespace mtx {
26 namespace requests {
27 struct CreateRoom;
28 }
29 }
30
31 namespace dialogs {
32 class CreateRoom;
33 class InviteUsers;
34 class MemberList;
35 }
36
37 class NhekoFixupPaletteEventFilter final : public QObject
38 {
39 Q_OBJECT
40
41 public:
42 NhekoFixupPaletteEventFilter(QObject *parent)
43 : QObject(parent)
44 {
45 }
46
47 bool eventFilter(QObject *obj, QEvent *event) override;
48 };
49
50 class MainWindow : public QQuickView
51 {
52 Q_OBJECT
53 QML_ELEMENT
54 QML_SINGLETON
55
56 public:
57 explicit MainWindow(QWindow *parent);
58
59 static MainWindow *instance() { return instance_; }
60 static MainWindow *create(QQmlEngine *qmlEngine, QJSEngine *)
61 {
62 // The instance has to exist before it is used. We cannot replace it.
63 Q_ASSERT(instance_);
64
65 // The engine has to have the same thread affinity as the singleton.
66 Q_ASSERT(qmlEngine->thread() == instance_->thread());
67
68 // There can only be one engine accessing the singleton.
69 static QJSEngine *s_engine = nullptr;
70 if (s_engine)
71 Q_ASSERT(qmlEngine == s_engine);
72 else
73 s_engine = qmlEngine;
74
75 QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership);
76 return instance_;
77 }
78
79 void saveCurrentWindowSize();
80
81 void openJoinRoomDialog(std::function<void(const QString &room_id)> callback);
82
83 MxcImageProvider *imageProvider() { return imgProvider; }
84
85 //! Show the chat page and start communicating with the given access token.
86 void showChatPage();
87
88 #ifdef NHEKO_DBUS_SYS
89 bool dbusAvailable() const { return dbusAvailable_; }
90 #endif
91
92 Q_INVOKABLE void addPerRoomWindow(const QString &room, QWindow *window);
93 Q_INVOKABLE void removePerRoomWindow(const QString &room, QWindow *window);
94 QWindow *windowForRoom(const QString &room);
95 QString focusedRoom() const;
96
97 protected:
98 void closeEvent(QCloseEvent *event) override;
99 // HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu
100 void mousePressEvent(QMouseEvent *) override;
101
102 private slots:
103 //! Handle interaction with the tray icon.
104 void iconActivated(QSystemTrayIcon::ActivationReason reason);
105
106 virtual void setWindowTitle(int notificationCount);
107
108 signals:
109 // HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu
110 void hideMenu();
111 void reload();
112 void secretsChanged();
113
114 void showNotification(QString msg);
115
116 void switchToChatPage();
117 void switchToWelcomePage();
118 void switchToLoginPage(QString error);
119
120 private:
121 void showDialog(QWidget *dialog);
122 bool hasActiveUser();
123 void restoreWindowSize();
124 //! Check if the current page supports the "minimize to tray" functionality.
125 bool pageSupportsTray() const;
126
127 void registerQmlTypes();
128
129 static MainWindow *instance_;
130
131 //! The initial welcome screen.
132 WelcomePage *welcome_page_;
133 //! The register page.
134 RegisterPage *register_page_;
135 //! The main chat area.
136 ChatPage *chat_page_;
137 QSharedPointer<UserSettings> userSettings_;
138 //! Tray icon that shows the unread message count.
139 TrayIcon *trayIcon_;
140 Dock *dock_;
141
142 MxcImageProvider *imgProvider = nullptr;
143
144 QMultiHash<QString, QWindow *> roomWindows_;
145
146 #ifdef NHEKO_DBUS_SYS
147 bool dbusAvailable_{false};
148 #endif
149 };