f85d225249173c2fc9d736326461e40c6c4efc28
[quassel.git] / src / qtui / qtui.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <memory>
24 #include <tuple>
25 #include <vector>
26
27 #include <QList>
28 #include <QObject>
29 #include <QString>
30
31 #if QT_VERSION >= 0x050000
32 #  include <QTemporaryDir>
33 #endif
34
35 #include "abstractnotificationbackend.h"
36 #include "graphicalui.h"
37 #include "qtuistyle.h"
38
39 class MainWin;
40 class MessageModel;
41 class QtUiMessageProcessor;
42
43 //! This class encapsulates Quassel's Qt-based GUI.
44 /** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin
45  *  from both QMainWindow and AbstractUi (because of multiple inheritance of QObject).
46  */
47 class QtUi : public GraphicalUi
48 {
49     Q_OBJECT
50
51 public:
52     ~QtUi();
53
54     MessageModel *createMessageModel(QObject *parent) override;
55     AbstractMessageProcessor *createMessageProcessor(QObject *parent) override;
56
57     static QtUi *instance();
58     inline static QtUiStyle *style();
59     inline static MainWin *mainWindow();
60
61     QString debugLog() const;
62
63     static bool haveSystemTray();
64
65     /* Notifications */
66
67     static void registerNotificationBackend(AbstractNotificationBackend *);
68     static void unregisterNotificationBackend(AbstractNotificationBackend *);
69     static void unregisterAllNotificationBackends();
70     static const QList<AbstractNotificationBackend *> &notificationBackends();
71     static const QList<AbstractNotificationBackend::Notification> &activeNotifications();
72
73     /**
74      * Determine available fallback icon themes.
75      *
76      * @returns The list of supported fallback themes (Breeze (Dark), Oxygen) that are available on the system
77      */
78     std::vector<std::pair<QString, QString>> availableIconThemes() const;
79
80     /**
81      * Determine the system icon theme set when Quassel was started.
82      *
83      * This property stores the icon theme initially configured in Qt when starting up (may be empty on platforms
84      * not supporting system icon themes). If the --icontheme option is given, uses that.
85      *
86      * Since Qt does not support notifications on theme changes, this property will not be updated when the theme
87      * changes at runtime.
88      *
89      * @returns The system icon theme at startup time
90      */
91     QString systemIconTheme() const;
92
93 public slots:
94     void init() override;
95
96     uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text);
97     void closeNotification(uint notificationId);
98     void closeNotifications(BufferId bufferId = BufferId());
99
100     /**
101      * Refresh the current icon theme.
102      *
103      * @note This will not detect changes in the system icon theme, so if that changes, a client restart
104      *       is required for icons to work correctly.
105      */
106     void refreshIconTheme();
107
108 signals:
109     void iconThemeRefreshed();
110
111 protected slots:
112     void connectedToCore() override;
113     void disconnectedFromCore() override;
114     void notificationActivated(uint notificationId);
115     void bufferMarkedAsRead(BufferId);
116
117 protected:
118     void minimizeRestore(bool show) override;
119     bool isHidingMainWidgetAllowed() const override;
120
121 private slots:
122     void useSystemTrayChanged(const QVariant &);
123
124 private:
125     QtUi();
126
127     /**
128      * Sets up icon theme handling.
129      */
130     void setupIconTheme();
131
132 private:
133     static MainWin *_mainWin;
134     static QList<AbstractNotificationBackend *> _notificationBackends;
135     static QList<AbstractNotificationBackend::Notification> _notifications;
136
137     QString _systemIconTheme;
138
139 #if QT_VERSION >= 0x050000
140     std::unique_ptr<QTemporaryDir> _dummyThemeDir;
141 #endif
142
143     bool _useSystemTray;
144 };
145
146 QtUiStyle *QtUi::style() { return qobject_cast<QtUiStyle *>(uiStyle()); }
147 MainWin *QtUi::mainWindow() { return _mainWin; }