From 3bb95408d4270a0432b7f07fa9f5b8dbd91c71de Mon Sep 17 00:00:00 2001 From: kate Date: Sun, 20 Feb 2022 16:05:32 +0800 Subject: [PATCH] fix: notification interface --- src/notifications.cpp | 20 +++++++++++++++----- src/notifications.h | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/notifications.cpp b/src/notifications.cpp index d8602ff..59b34bb 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -18,15 +18,19 @@ */ #include "notifications.h" -#include -#include -#include Notifications::Notifications(QObject *parent) : QObject(parent) + , m_iface("com.cutefish.Notification", + "/Notification", + "com.cutefish.Notification", QDBusConnection::sessionBus()) { - QSettings settings(QSettings::UserScope, "cutefishos", "notification"); - m_doNotDisturb = settings.value("DoNotDisturb", false).toBool(); + m_doNotDisturb = m_iface.property("doNotDisturb").toBool(); + + QDBusConnection::sessionBus().connect("com.cutefish.Notification", + "/Notification", + "com.cutefish.Notification", + "doNotDisturbChanged", this, SLOT(onDBusDoNotDisturbChanged())); } bool Notifications::doNotDisturb() const @@ -48,3 +52,9 @@ void Notifications::setDoNotDisturb(bool enabled) emit doNotDisturbChanged(); } + +void Notifications::onDBusDoNotDisturbChanged() +{ + m_doNotDisturb = m_iface.property("doNotDisturb").toBool(); + emit doNotDisturbChanged(); +} diff --git a/src/notifications.h b/src/notifications.h index c564354..9ea984f 100644 --- a/src/notifications.h +++ b/src/notifications.h @@ -21,6 +21,8 @@ #define NOTIFICATIONS_H #include +#include +#include class Notifications : public QObject { @@ -33,10 +35,14 @@ public: bool doNotDisturb() const; void setDoNotDisturb(bool enabled); +private slots: + void onDBusDoNotDisturbChanged(); + signals: void doNotDisturbChanged(); private: + QDBusInterface m_iface; bool m_doNotDisturb; };