File indexing completed on 2024-04-28 03:56:32

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 #include <KConfigWatcher>
0017 
0018 class KNotification;
0019 
0020 struct ca_context;
0021 
0022 class NotifyByAudio : public KNotificationPlugin
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit NotifyByAudio(QObject *parent = nullptr);
0028     ~NotifyByAudio() override;
0029 
0030     QString optionName() override
0031     {
0032         return QStringLiteral("Sound");
0033     }
0034     void notify(KNotification *notification, const KNotifyConfig &notifyConfig) override;
0035     void close(KNotification *notification) override;
0036 
0037 private Q_SLOTS:
0038     void finishCallback(uint32_t id, int error_code);
0039 
0040 private:
0041     static void ca_finish_callback(ca_context *c, uint32_t id, int error_code, void *userdata);
0042 
0043     ca_context *context();
0044     void finishNotification(KNotification *notification, quint32 id);
0045 
0046     bool playSound(quint32 id, const QString &eventName, const QUrl &fallbackUrl);
0047 
0048     ca_context *m_context = nullptr;
0049     quint32 m_currentId = 0;
0050     QHash<quint32, KNotification *> m_notifications;
0051     // in case we loop we store the URL for the notification to be able to replay it
0052     QHash<quint32, std::pair<QString, QUrl>> m_loopSoundUrls;
0053 
0054     KConfigWatcher::Ptr m_settingsWatcher;
0055     QString m_soundTheme;
0056     bool m_enabled = true;
0057 };
0058 
0059 #endif