e54fb244d9ab5dd8f3d1682190b7ebf85393db95
[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 public slots:
78     void init() override;
79
80     uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text);
81     void closeNotification(uint notificationId);
82     void closeNotifications(BufferId bufferId = BufferId());
83
84     /**
85      * Refresh the current icon theme.
86      *
87      * @note This will not detect changes in the system icon theme, so if that changes, a client restart
88      *       is required for icons to work correctly.
89      */
90     void refreshIconTheme();
91
92 signals:
93     void iconThemeRefreshed();
94
95 protected slots:
96     void connectedToCore() override;
97     void disconnectedFromCore() override;
98     void notificationActivated(uint notificationId);
99     void bufferMarkedAsRead(BufferId);
100
101 protected:
102     void minimizeRestore(bool show) override;
103     bool isHidingMainWidgetAllowed() const override;
104
105 private slots:
106     void useSystemTrayChanged(const QVariant &);
107
108 private:
109     /**
110      * Sets up icon theme handling.
111      */
112     void setupIconTheme();
113
114 private:
115     static QtUi *_instance;
116     static MainWin *_mainWin;
117     static QList<AbstractNotificationBackend *> _notificationBackends;
118     static QList<AbstractNotificationBackend::Notification> _notifications;
119
120     QString _systemIconTheme;
121
122 #if QT_VERSION >= 0x050000
123     std::unique_ptr<QTemporaryDir> _dummyThemeDir;
124 #endif
125
126     bool _useSystemTray;
127 };
128
129
130 QtUi *QtUi::instance() { return _instance ? _instance : new QtUi(); }
131 QtUiStyle *QtUi::style() { return qobject_cast<QtUiStyle *>(uiStyle()); }
132 MainWin *QtUi::mainWindow() { return _mainWin; }