Commit 02d2f32f authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Implement PulseAudio for disabling notification sounds

And some minor cleanups
parent 2d1b66fb
......@@ -18,14 +18,6 @@ target_link_libraries(plasma_applet_notifications
KF5::KIOWidgets # for PreviewJob
)
set(HAVE_PULSEAUDIOQT ${KF5PulseAudioQt_FOUND})
if(KF5PulseAudioQt_FOUND)
target_link_libraries(plasma_applet_notifications KF5::PulseAudioQt)
endif()
# can't ECM do that for us these days?
configure_file(config-notificationsapplet.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-notificationsapplet.h )
install(TARGETS plasma_applet_notifications DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/applets)
plasma_install_package(package org.kde.plasma.notifications)
......@@ -34,11 +34,6 @@
#include "filemenu.h"
#include "thumbnailer.h"
#ifdef HAVE_PULSEAUDIOQT
#include <PulseAudioQt/Context>
#include <PulseAudioQt/StreamRestore>
#endif
NotificationApplet::NotificationApplet(QObject *parent, const QVariantList &data)
: Plasma::Applet(parent, data)
{
......@@ -50,15 +45,6 @@ NotificationApplet::NotificationApplet(QObject *parent, const QVariantList &data
qmlProtectModule(uri, 2);
s_typesRegistered = true;
}
// TODO PulseAudio stuff to mute notification sounds in do not disturb mode
/*PulseAudioQt::Context::instance()->streamRestores();
connect(PulseAudioQt::Context::instance(), &PulseAudioQt::Context::streamRestoreAdded, this, [this](PulseAudioQt::StreamRestore *restore) {
if (restore->name() == QLatin1String("sink-input-by-media-role:event")) {
}
});*/
}
NotificationApplet::~NotificationApplet() = default;
......
......@@ -98,23 +98,10 @@ MouseArea {
id: countLabel
anchors.centerIn: parent
font.pointSize: -1
font.pixelSize: Math.round(parent.height * 0.6)
text: count || "" // don't show number zero
property int count: 0
onCountChanged: countChangeAnimation.start();
ParallelAnimation {
id: countChangeAnimation
NumberAnimation {
target: countLabel
property: "scale"
from: 2
to: 1
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
// FIXME fontSizeMode is awful but FontMetrics also doesn't cut it
font.pixelSize: Math.round(parent.height * (0.3 + 0.3 * text.length))
// TODO add animation when it changes?
text: compactRoot.unreadCount || ""
}
PlasmaComponents.BusyIndicator {
......@@ -154,7 +141,7 @@ MouseArea {
}
PropertyChanges {
target: countLabel
count: compactRoot.jobsCount
text: compactRoot.jobsCount
}
PropertyChanges {
target: busyIndicator
......@@ -194,7 +181,7 @@ MouseArea {
}
PropertyChanges {
target: countLabel
count: compactRoot.unreadCount
text: compactRoot.unreadCount
}
}
]
......
......@@ -272,6 +272,8 @@ QtObject {
}
property QtObject notificationSettings: NotificationManager.Settings {
notificationSoundsInhibited: globals.inhibited
onNotificationsInhibitedUntilChanged: globals.checkInhibition()
}
......
......@@ -34,8 +34,6 @@ import "global"
Item {
id: root
Plasmoid.hideOnWindowDeactivate: false
Plasmoid.status: historyModel.activeJobsCount > 0
|| Globals.popupNotificationsModel.activeNotificationsCount > 0
|| Globals.inhibited ? PlasmaCore.Types.ActiveStatus
......
......@@ -23,6 +23,9 @@ set(notificationmanager_LIB_SRCS
limitedrowcountproxymodel.cpp
)
set(HAVE_PULSEAUDIOQT ${KF5PulseAudioQt_FOUND})
configure_file(config-notificationmanager.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-notificationmanager.h )
ecm_qt_declare_logging_category(notificationmanager_LIB_SRCS
HEADER debug.h
IDENTIFIER NOTIFICATIONMANAGER
......@@ -65,6 +68,10 @@ target_link_libraries(notificationmanager
KF5::Service
)
if(KF5PulseAudioQt_FOUND)
target_link_libraries(notificationmanager PRIVATE KF5::PulseAudioQt)
endif()
set_target_properties(notificationmanager PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
......
......@@ -9,5 +9,9 @@
<entry name="Until" type="DateTime">
<default></default>
</entry>
<entry name="NotificationSoundsMuted" type="Bool">
<default>false</default>
</entry>
</group>
</kcfg>
......@@ -20,6 +20,8 @@
#include "settings.h"
#include "config-notificationmanager.h"
#include <QDebug>
#include <KConfigWatcher>
......@@ -34,6 +36,15 @@
#include "jobsettings.h"
#include "badgesettings.h"
#ifdef HAVE_PULSEAUDIOQT
#include <PulseAudioQt/Context>
#include <PulseAudioQt/StreamRestore>
using namespace PulseAudioQt;
static const char *s_notificationStreamId = "sink-input-by-media-role:event";
#endif
using namespace NotificationManager;
class Q_DECL_HIDDEN Settings::Private
......@@ -61,12 +72,36 @@ public:
bool live = false; // set to true initially in constructor
bool dirty = false;
#ifdef HAVE_PULSEAUDIOQT
QPointer<StreamRestore> notificationSounds;
#endif
};
Settings::Private::Private(Settings *q)
: q(q)
{
#ifdef HAVE_PULSEAUDIOQT
// Can there be multiple?
const auto streamRestores = Context::instance()->streamRestores();
for (StreamRestore *restore : streamRestores) {
if (restore->name() == QLatin1String(s_notificationStreamId)) {
notificationSounds = restore;
connect(notificationSounds.data(), &StreamRestore::mutedChanged, q, &Settings::notificationSoundsMutedChanged);
break;
}
}
QObject::connect(Context::instance(), &Context::streamRestoreAdded, q, [this, q](StreamRestore *restore) {
if (restore->name() == QLatin1String(s_notificationStreamId)) {
notificationSounds = restore;
connect(notificationSounds.data(), &StreamRestore::mutedChanged, q, &Settings::notificationSoundsMutedChanged);
}
});
#endif
}
Settings::Private::~Private() = default;
......@@ -534,3 +569,57 @@ void Settings::revokeApplicationInhibitions()
{
Server::self().clearInhibitions();
}
bool Settings::notificationSoundsInhibited() const
{
#ifdef HAVE_PULSEAUDIOQT
return DoNotDisturbSettings::notificationSoundsMuted();
#else
return false;
#endif
}
bool Settings::notificationSoundsMuted() const
{
#ifdef HAVE_PULSEAUDIOQT
return !d->notificationSounds.isNull() & d->notificationSounds->isMuted();
#else
return false;
#endif
}
void Settings::setNotificationSoundsMuted(bool muted)
{
#ifdef HAVE_PULSEAUDIOQT
if (d->notificationSounds) {
d->notificationSounds->setMuted(muted);
}
#else
Q_UNUSED(muted);
#endif
}
void Settings::setNotificationSoundsInhibited(bool inhibited)
{
if (inhibited == notificationSoundsInhibited()) {
return;
}
#ifdef HAVE_PULSEAUDIOQT
if (!d->notificationSounds) {
qCInfo(NOTIFICATIONMANAGER) << "Cannot" << (inhibited ? "mute" : "unmute") << "notification sounds without appropriate stream restore";
return;
}
if (inhibited && d->notificationSounds->isMuted()) {
// Already muted, don't write soundsMuted=true to avoid us unmuting them later
qCDebug(NOTIFICATIONMANAGER) << "Not muting notification sounds as they already are";
return;
}
d->notificationSounds->setMuted(inhibited);
DoNotDisturbSettings::setNotificationSoundsMuted(inhibited);
d->setDirty(true);
#endif
}
......@@ -105,6 +105,29 @@ class NOTIFICATIONMANAGER_EXPORT Settings : public QObject
READ notificationInhibitionReasons
NOTIFY notificationInhibitionApplicationsChanged)
/**
* Whether notification sounds should be disabled
*
* This does not reflect the actual mute state of the Notification Sounds
* but only remembers what value was assigned to this property.
*
* When @c true the notification sound stream is muted.
* When @c false the notification sound stream is unmuted only if it was
* previously muted by having set this property @c true. This is to avoid
* unmuting notification sounds if the user themselves have already muted them.
*/
Q_PROPERTY(bool notificationSoundsInhibited
WRITE setNotificationSoundsInhibited
NOTIFY NotificationSoundsInhibitedChanged)
/**
* Whether the notification sound stream is actually muted
*/
Q_PROPERTY(bool notificationSoundsMuted
READ notificationSoundsMuted
WRITE setNotificationSoundsMuted
NOTIFY notificationSoundsMutedChanged)
/**
* Whether to update the properties immediately when they are changed on disk
*
......@@ -216,6 +239,12 @@ public:
QStringList notificationInhibitionApplications() const;
QStringList notificationInhibitionReasons() const;
bool notificationSoundsInhibited() const;
void setNotificationSoundsInhibited(bool inhibited);
bool notificationSoundsMuted() const;
void setNotificationSoundsMuted(bool muted);
Q_INVOKABLE void revokeApplicationInhibitions();
signals:
......@@ -228,6 +257,8 @@ signals:
void notificationsInhibitedByApplicationChanged(bool notificationsInhibitedByApplication);
void notificationInhibitionApplicationsChanged();
void notificationSoundsInhibitedChanged();
void notificationSoundsMutedChanged();
private:
class Private;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment