1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #ifndef NOTIFYBYAUDIO_H |
9 | #define NOTIFYBYAUDIO_H |
10 | |
11 | #include "knotificationplugin.h" |
12 | |
13 | #include <QHash> |
14 | #include <QUrl> |
15 | |
16 | #include <KConfigWatcher> |
17 | |
18 | class KNotification; |
19 | |
20 | struct ca_context; |
21 | |
22 | class NotifyByAudio : public KNotificationPlugin |
23 | { |
24 | Q_OBJECT |
25 | |
26 | public: |
27 | explicit NotifyByAudio(QObject *parent = nullptr); |
28 | ~NotifyByAudio() override; |
29 | |
30 | QString optionName() override |
31 | { |
32 | return QStringLiteral("Sound" ); |
33 | } |
34 | void notify(KNotification *notification, const KNotifyConfig ¬ifyConfig) override; |
35 | void close(KNotification *notification) override; |
36 | |
37 | private Q_SLOTS: |
38 | void finishCallback(uint32_t id, int error_code); |
39 | |
40 | private: |
41 | static void ca_finish_callback(ca_context *c, uint32_t id, int error_code, void *userdata); |
42 | |
43 | ca_context *context(); |
44 | void finishNotification(KNotification *notification, quint32 id); |
45 | |
46 | bool playSound(quint32 id, const QString &eventName, const QUrl &fallbackUrl); |
47 | |
48 | ca_context *m_context = nullptr; |
49 | quint32 m_currentId = 0; |
50 | QHash<quint32, KNotification *> m_notifications; |
51 | // in case we loop we store the URL for the notification to be able to replay it |
52 | QHash<quint32, std::pair<QString, QUrl>> m_loopSoundUrls; |
53 | |
54 | KConfigWatcher::Ptr m_settingsWatcher; |
55 | QString m_soundTheme; |
56 | bool m_enabled = true; |
57 | }; |
58 | |
59 | #endif |
60 | |