File indexing completed on 2024-05-19 05:38:22

0001 /*
0002     SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
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 <KQuickManagedConfigModule>
0010 
0011 #include <QHash>
0012 #include <QKeySequence>
0013 
0014 #include "badgesettings.h"
0015 #include "donotdisturbsettings.h"
0016 #include "eventsproxymodel.h"
0017 #include "filterproxymodel.h"
0018 #include "jobsettings.h"
0019 #include "notificationsettings.h"
0020 #include "sourcesmodel.h"
0021 
0022 class QAction;
0023 
0024 class NotificationsData;
0025 class SoundThemeConfig;
0026 
0027 namespace NotificationManager
0028 {
0029 class BehaviorSettings;
0030 }
0031 
0032 struct ca_context;
0033 
0034 class KCMNotifications : public KQuickManagedConfigModule
0035 {
0036     Q_OBJECT
0037 
0038     Q_PROPERTY(SourcesModel *sourcesModel READ sourcesModel CONSTANT)
0039     Q_PROPERTY(FilterProxyModel *filteredModel READ filteredModel CONSTANT)
0040     Q_PROPERTY(EventsProxyModel *eventsModel READ eventsModel CONSTANT)
0041 
0042     Q_PROPERTY(NotificationManager::DoNotDisturbSettings *dndSettings READ dndSettings CONSTANT)
0043     Q_PROPERTY(NotificationManager::NotificationSettings *notificationSettings READ notificationSettings CONSTANT)
0044     Q_PROPERTY(NotificationManager::JobSettings *jobSettings READ jobSettings CONSTANT)
0045     Q_PROPERTY(NotificationManager::BadgeSettings *badgeSettings READ badgeSettings CONSTANT)
0046     Q_PROPERTY(bool isDefaultsBehaviorSettings READ isDefaultsBehaviorSettings NOTIFY isDefaultsBehaviorSettingsChanged)
0047 
0048     Q_PROPERTY(
0049         QKeySequence toggleDoNotDisturbShortcut READ toggleDoNotDisturbShortcut WRITE setToggleDoNotDisturbShortcut NOTIFY toggleDoNotDisturbShortcutChanged)
0050 
0051     // So it can show the respective settings module right away
0052     Q_PROPERTY(QString initialDesktopEntry READ initialDesktopEntry WRITE setInitialDesktopEntry NOTIFY initialDesktopEntryChanged)
0053     Q_PROPERTY(QString initialNotifyRcName READ initialNotifyRcName WRITE setInitialNotifyRcName NOTIFY initialNotifyRcNameChanged)
0054     Q_PROPERTY(QString initialEventId READ initialEventId WRITE setInitialEventId NOTIFY initialEventIdChanged)
0055 
0056 public:
0057     KCMNotifications(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
0058     ~KCMNotifications() override;
0059 
0060     SourcesModel *sourcesModel() const;
0061     FilterProxyModel *filteredModel() const;
0062     EventsProxyModel *eventsModel() const;
0063 
0064     NotificationManager::DoNotDisturbSettings *dndSettings() const;
0065     NotificationManager::NotificationSettings *notificationSettings() const;
0066     NotificationManager::JobSettings *jobSettings() const;
0067     NotificationManager::BadgeSettings *badgeSettings() const;
0068 
0069     QKeySequence toggleDoNotDisturbShortcut() const;
0070     void setToggleDoNotDisturbShortcut(const QKeySequence &shortcut);
0071     Q_SIGNAL void toggleDoNotDisturbShortcutChanged();
0072 
0073     QString initialDesktopEntry() const;
0074     void setInitialDesktopEntry(const QString &desktopEntry);
0075 
0076     QString initialNotifyRcName() const;
0077     void setInitialNotifyRcName(const QString &notifyRcName);
0078 
0079     QString initialEventId() const;
0080     void setInitialEventId(const QString &eventId);
0081 
0082     Q_INVOKABLE QUrl soundsLocation();
0083     Q_INVOKABLE void playSound(const QString &soundName);
0084 
0085     Q_INVOKABLE NotificationManager::BehaviorSettings *behaviorSettings(const QModelIndex &index);
0086 
0087     bool isDefaultsBehaviorSettings() const;
0088 
0089 public Q_SLOTS:
0090     void load() override;
0091     void save() override;
0092     void defaults() override;
0093 
0094 Q_SIGNALS:
0095     void initialDesktopEntryChanged();
0096     void initialNotifyRcNameChanged();
0097     void initialEventIdChanged();
0098     void firstLoadDone();
0099     void isDefaultsBehaviorSettingsChanged();
0100 
0101 private Q_SLOTS:
0102     void onDefaultsIndicatorsVisibleChanged();
0103     void updateModelIsDefaultStatus(const QModelIndex &index);
0104 
0105 private:
0106     bool isSaveNeeded() const override;
0107     bool isDefaults() const override;
0108     void createConnections(NotificationManager::BehaviorSettings *settings, const QModelIndex &index);
0109 
0110     SourcesModel *const m_sourcesModel;
0111     FilterProxyModel *const m_filteredModel;
0112     EventsProxyModel *const m_eventsModel;
0113 
0114     NotificationsData *const m_data;
0115 
0116     QAction *m_toggleDoNotDisturbAction;
0117     QKeySequence m_toggleDoNotDisturbShortcut;
0118     bool m_toggleDoNotDisturbShortcutDirty = false;
0119     bool m_firstLoad = true;
0120 
0121     QString m_initialDesktopEntry;
0122     QString m_initialNotifyRcName;
0123     QString m_initialEventId;
0124 
0125     ca_context *m_canberraContext = nullptr;
0126     SoundThemeConfig *m_soundThemeConfig = nullptr;
0127 };