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 class KNotification; 17 18 struct ca_context; 19 20 class NotifyByAudio : public KNotificationPlugin 21 { 22 Q_OBJECT 23 24 public: 25 explicit NotifyByAudio(QObject *parent = nullptr); 26 ~NotifyByAudio() override; 27 optionName()28 QString optionName() override 29 { 30 return QStringLiteral("Sound"); 31 } 32 void notify(KNotification *notification, KNotifyConfig *config) override; 33 void close(KNotification *notification) override; 34 35 private Q_SLOTS: 36 void finishCallback(uint32_t id, int error_code); 37 38 private: 39 static void ca_finish_callback(ca_context *c, uint32_t id, int error_code, void *userdata); 40 41 void finishNotification(KNotification *notification, quint32 id); 42 43 bool playSound(quint32 id, const QUrl &url); 44 45 ca_context *m_context = nullptr; 46 quint32 m_currentId = 0; 47 QHash<quint32, KNotification *> m_notifications; 48 // in case we loop we store the URL for the notification to be able to replay it 49 QHash<quint32, QUrl> m_loopSoundUrls; 50 }; 51 52 #endif 53