cleanup: Clean up BufferViewConfig
[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 #include <QTemporaryDir>
31
32 #include "abstractnotificationbackend.h"
33 #include "graphicalui.h"
34 #include "qtuistyle.h"
35
36 class MainWin;
37 class MessageModel;
38 class QtUiMessageProcessor;
39
40 //! This class encapsulates Quassel's Qt-based GUI.
41 /** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin
42  *  from both QMainWindow and AbstractUi (because of multiple inheritance of QObject).
43  */
44 class QtUi : public GraphicalUi
45 {
46     Q_OBJECT
47
48 public:
49     QtUi();
50     ~QtUi() override;
51
52     MessageModel* createMessageModel(QObject* parent) override;
53     AbstractMessageProcessor* createMessageProcessor(QObject* parent) override;
54
55     static QtUi* instance();
56     inline static QtUiStyle* style();
57     inline static MainWin* mainWindow();
58
59     QString debugLog() const;
60
61     static bool haveSystemTray();
62
63     /* Notifications */
64
65     static void registerNotificationBackend(AbstractNotificationBackend*);
66     static void unregisterNotificationBackend(AbstractNotificationBackend*);
67     static void unregisterAllNotificationBackends();
68     static const QList<AbstractNotificationBackend*>& notificationBackends();
69     static const QList<AbstractNotificationBackend::Notification>& activeNotifications();
70
71     /**
72      * Determine available fallback icon themes.
73      *
74      * @returns The list of supported fallback themes (Breeze (Dark), Oxygen) that are available on the system
75      */
76     std::vector<std::pair<QString, QString>> availableIconThemes() const;
77
78     /**
79      * Determine the system icon theme set when Quassel was started.
80      *
81      * This property stores the icon theme initially configured in Qt when starting up (may be empty on platforms
82      * not supporting system icon themes). If the --icontheme option is given, uses that.
83      *
84      * Since Qt does not support notifications on theme changes, this property will not be updated when the theme
85      * changes at runtime.
86      *
87      * @returns The system icon theme at startup time
88      */
89     QString systemIconTheme() const;
90
91 public slots:
92     void init() override;
93
94     uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString& sender, const QString& text);
95     void closeNotification(uint notificationId);
96     void closeNotifications(BufferId bufferId = BufferId());
97
98     /**
99      * Refresh the current icon theme.
100      *
101      * @note This will not detect changes in the system icon theme, so if that changes, a client restart
102      *       is required for icons to work correctly.
103      */
104     void refreshIconTheme();
105
106 signals:
107     void iconThemeRefreshed();
108
109 protected slots:
110     void connectedToCore() override;
111     void disconnectedFromCore() override;
112     void notificationActivated(uint notificationId);
113     void bufferMarkedAsRead(BufferId);
114
115 protected:
116     void minimizeRestore(bool show) override;
117     bool isHidingMainWidgetAllowed() const override;
118
119 private slots:
120     void useSystemTrayChanged(const QVariant&);
121
122 private:
123     /**
124      * Sets up icon theme handling.
125      */
126     void setupIconTheme();
127
128 private:
129     static QList<AbstractNotificationBackend*> _notificationBackends;
130     static QList<AbstractNotificationBackend::Notification> _notifications;
131
132     std::unique_ptr<MainWin> _mainWin;
133
134     QString _systemIconTheme;
135
136     std::unique_ptr<QTemporaryDir> _dummyThemeDir;
137
138     bool _useSystemTray;
139 };
140
141 QtUiStyle* QtUi::style()
142 {
143     return qobject_cast<QtUiStyle*>(uiStyle());
144 }
145
146 MainWin* QtUi::mainWindow()
147 {
148     return instance()->_mainWin.get();
149 }