File indexing completed on 2025-01-05 04:29:55

0001 /**
0002  * SPDX-FileCopyrightText: 2023 Bart De Vries <bart@mogwai.be>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QQmlEngine>
0011 #ifndef Q_OS_ANDROID
0012 #include <QSystemTrayIcon>
0013 #endif
0014 
0015 class SystrayIcon
0016 #ifndef Q_OS_ANDROID
0017     : public QSystemTrayIcon
0018 #else
0019     : public QObject
0020 #endif
0021 {
0022     Q_OBJECT
0023     QML_ELEMENT
0024     QML_SINGLETON
0025 
0026 public:
0027     enum IconColor {
0028         Colorful,
0029         Light,
0030         Dark,
0031     };
0032     Q_ENUM(IconColor)
0033 
0034     Q_PROPERTY(bool available READ available CONSTANT)
0035 
0036     static SystrayIcon &instance()
0037     {
0038         static SystrayIcon _instance;
0039         return _instance;
0040     }
0041     static SystrayIcon *create(QQmlEngine *engine, QJSEngine *)
0042     {
0043         engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
0044         return &instance();
0045     }
0046 
0047     [[nodiscard]] bool available() const;
0048 
0049     void setIconColor(IconColor iconColor);
0050 
0051 Q_SIGNALS:
0052     void raiseWindow();
0053 
0054 private:
0055     explicit SystrayIcon(QObject *parent = nullptr);
0056     int iconColorEnumToInt(IconColor iconColor);
0057     IconColor intToIconColorEnum(int iconColorCode);
0058 };