client: Port old HighlightRule to ExpressionMatch
[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     ~QtUi();
54
55     MessageModel *createMessageModel(QObject *parent) override;
56     AbstractMessageProcessor *createMessageProcessor(QObject *parent) override;
57
58     inline static QtUi *instance();
59     inline static QtUiStyle *style();
60     inline static MainWin *mainWindow();
61
62     QString debugLog() const;
63
64     static bool haveSystemTray();
65
66     /* Notifications */
67
68     static void registerNotificationBackend(AbstractNotificationBackend *);
69     static void unregisterNotificationBackend(AbstractNotificationBackend *);
70     static void unregisterAllNotificationBackends();
71     static const QList<AbstractNotificationBackend *> &notificationBackends();
72     static const QList<AbstractNotificationBackend::Notification> &activeNotifications();
73
74     /**
75      * Determine available fallback icon themes.
76      *
77      * @returns The list of supported fallback themes (Breeze (Dark), Oxygen) that are available on the system
78      */
79     std::vector<std::pair<QString, QString>> availableIconThemes() const;
80
81     /**
82      * Determine the system icon theme set when Quassel was started.
83      *
84      * This property stores the icon theme initially configured in Qt when starting up (may be empty on platforms
85      * not supporting system icon themes). If the --icontheme option is given, uses that.
86      *
87      * Since Qt does not support notifications on theme changes, this property will not be updated when the theme
88      * changes at runtime.
89      *
90      * @returns The system icon theme at startup time
91      */
92     QString systemIconTheme() const;
93
94 public slots:
95     void init() override;
96
97     uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text);
98     void closeNotification(uint notificationId);
99     void closeNotifications(BufferId bufferId = BufferId());
100
101     /**
102      * Refresh the current icon theme.
103      *
104      * @note This will not detect changes in the system icon theme, so if that changes, a client restart
105      *       is required for icons to work correctly.
106      */
107     void refreshIconTheme();
108
109 signals:
110     void iconThemeRefreshed();
111
112 protected slots:
113     void connectedToCore() override;
114     void disconnectedFromCore() override;
115     void notificationActivated(uint notificationId);
116     void bufferMarkedAsRead(BufferId);
117
118 protected:
119     void minimizeRestore(bool show) override;
120     bool isHidingMainWidgetAllowed() const override;
121
122 private slots:
123     void useSystemTrayChanged(const QVariant &);
124
125 private:
126     /**
127      * Sets up icon theme handling.
128      */
129     void setupIconTheme();
130
131 private:
132     static QtUi *_instance;
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
147 QtUi *QtUi::instance() { return _instance ? _instance : new QtUi(); }
148 QtUiStyle *QtUi::style() { return qobject_cast<QtUiStyle *>(uiStyle()); }
149 MainWin *QtUi::mainWindow() { return _mainWin; }