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