File indexing completed on 2024-04-28 15:29:12

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef NOTIFYBYAUDIO_H
0009 #define NOTIFYBYAUDIO_H
0010 
0011 #include "knotificationplugin.h"
0012 
0013 #include <QHash>
0014 #include <QUrl>
0015 
0016 class KNotification;
0017 
0018 struct ca_context;
0019 
0020 class NotifyByAudio : public KNotificationPlugin
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     explicit NotifyByAudio(QObject *parent = nullptr);
0026     ~NotifyByAudio() override;
0027 
0028     QString optionName() override
0029     {
0030         return QStringLiteral("Sound");
0031     }
0032     void notify(KNotification *notification, KNotifyConfig *config) override;
0033     void close(KNotification *notification) override;
0034 
0035 private Q_SLOTS:
0036     void finishCallback(uint32_t id, int error_code);
0037 
0038 private:
0039     static void ca_finish_callback(ca_context *c, uint32_t id, int error_code, void *userdata);
0040 
0041     void finishNotification(KNotification *notification, quint32 id);
0042 
0043     bool playSound(quint32 id, const QUrl &url);
0044 
0045     ca_context *m_context = nullptr;
0046     quint32 m_currentId = 0;
0047     QHash<quint32, KNotification *> m_notifications;
0048     // in case we loop we store the URL for the notification to be able to replay it
0049     QHash<quint32, QUrl> m_loopSoundUrls;
0050 };
0051 
0052 #endif