File indexing completed on 2024-05-12 05:02:10

0001 /*
0002 
0003  * SPDX-FileCopyrightText: 2016 Riccardo Iaconelli <riccardo@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  *
0007  */
0008 
0009 #pragma once
0010 
0011 #include "libruqolacore_export.h"
0012 #include <KStatusNotifierItem>
0013 #include <QMap>
0014 
0015 class UnityServiceManager;
0016 class LIBRUQOLACORE_EXPORT Notification : public KStatusNotifierItem
0017 {
0018     Q_OBJECT
0019 public:
0020     explicit Notification(QObject *parent = nullptr);
0021     ~Notification() override;
0022 
0023     void roomNeedAttention();
0024     void updateNotification(bool hasAlert, int unreadNumber, const QString &account);
0025     void clearNotification(const QString &account);
0026 #ifdef UNITY_SUPPORT
0027     UnityServiceManager *unityServiceManager();
0028 #endif
0029 
0030 Q_SIGNALS:
0031     void alert();
0032 
0033 private:
0034     Q_DISABLE_COPY(Notification)
0035     struct TrayInfo {
0036         TrayInfo(int unread, bool alert)
0037             : unreadMessage(unread)
0038             , hasAlert(alert)
0039         {
0040         }
0041 
0042         [[nodiscard]] bool hasNotification() const
0043         {
0044             return (unreadMessage != 0) || hasAlert;
0045         }
0046 
0047         int unreadMessage = 0;
0048         bool hasAlert = false;
0049     };
0050     /**
0051      * @brief Creates tray icon consisting of actions
0052      */
0053     LIBRUQOLACORE_NO_EXPORT void createTrayIcon();
0054     LIBRUQOLACORE_NO_EXPORT void createToolTip();
0055     LIBRUQOLACORE_NO_EXPORT void updateUnityService(int unreadMessage);
0056 
0057     QMap<QString, TrayInfo> mListTrayIcon;
0058 #ifdef UNITY_SUPPORT
0059     UnityServiceManager *mUnityServiceManager = nullptr;
0060 #endif
0061 };