diff --git a/korgac/CMakeLists.txt b/korgac/CMakeLists.txt --- a/korgac/CMakeLists.txt +++ b/korgac/CMakeLists.txt @@ -34,6 +34,8 @@ KOAlarmClient ) +qt5_add_dbus_interface(korgac_SRCS org.freedesktop.Notifications.xml notifications_interface) +qt5_add_dbus_interface(korgac_SRCS org.freedesktop.DBus.Properties.xml dbusproperties) file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/pixmaps/*-apps-korgac.png") ecm_add_app_icon(korgac_SRCS ICONS ${ICONS_SRCS}) diff --git a/korgac/alarmdialog.h b/korgac/alarmdialog.h --- a/korgac/alarmdialog.h +++ b/korgac/alarmdialog.h @@ -109,6 +109,12 @@ void closeEvent(QCloseEvent *) override; void showEvent(QShowEvent *event) override; +private Q_SLOTS: + void slotDBusNotificationsPropertiesChanged( + const QString& interface, + const QVariantMap& changedProperties, + const QStringList& invalidatedProperties); + private: void update(); void updateButtons(); diff --git a/korgac/alarmdialog.cpp b/korgac/alarmdialog.cpp --- a/korgac/alarmdialog.cpp +++ b/korgac/alarmdialog.cpp @@ -30,6 +30,9 @@ #include "mailclient.h" #include "koalarmclient_debug.h" +#include "notifications_interface.h" // DBUS-generated +#include "dbusproperties.h" // DBUS-generated + #include #include #include @@ -78,6 +81,9 @@ static int defSuspendVal = 5; static int defSuspendUnit = AlarmDialog::SuspendInMinutes; +static const char s_fdo_notifications_service[] = "org.freedesktop.Notifications"; +static const char s_fdo_notifications_path[] = "/org/freedesktop/Notifications"; + class ReminderTreeItem : public QTreeWidgetItem { public: @@ -332,6 +338,16 @@ connect(mUser3Button, &QPushButton::clicked, this, &AlarmDialog::slotUser3); mIdentityManager = new CalendarSupport::IdentityManager; + + QDBusConnection dbusConn = QDBusConnection::sessionBus(); + if (dbusConn.interface()->isServiceRegistered(QString::fromLatin1(s_fdo_notifications_service))) { + OrgFreedesktopDBusPropertiesInterface *propsIface = new OrgFreedesktopDBusPropertiesInterface( + QString::fromLatin1(s_fdo_notifications_service), + QString::fromLatin1(s_fdo_notifications_path), + dbusConn, this); + connect(propsIface, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, + this, &AlarmDialog::slotDBusNotificationsPropertiesChanged); + } } AlarmDialog::~AlarmDialog() @@ -769,6 +785,19 @@ void AlarmDialog::wakeUp() { + // Check if notifications are inhibited (e.x. plasma "do not disturb" mode. + // In that case, we'll wait until they are allowed again (see slotDBusNotificationsPropertiesChanged) + QDBusConnection dbusConn = QDBusConnection::sessionBus(); + if (dbusConn.interface()->isServiceRegistered(QString::fromLatin1(s_fdo_notifications_service))) { + OrgFreedesktopNotificationsInterface iface( + QString::fromLatin1(s_fdo_notifications_service), + QString::fromLatin1(s_fdo_notifications_path), + dbusConn); + if (iface.inhibited()) { + return; + } + } + bool activeReminders = false; QTreeWidgetItemIterator it(mIncidenceTree); QTreeWidgetItem *firstItem = nullptr; @@ -800,6 +829,24 @@ Q_EMIT reminderCount(activeCount()); } +void AlarmDialog::slotDBusNotificationsPropertiesChanged( + const QString& interface, + const QVariantMap& changedProperties, + const QStringList& invalidatedProperties) +{ + Q_UNUSED(interface); // always "org.freedesktop.Notifications" + Q_UNUSED(invalidatedProperties); + const auto it = changedProperties.find(QStringLiteral("Inhibited")); + if (it != changedProperties.end()) { + const bool inhibited = it.value().toBool(); + qCDebug(KOALARMCLIENT_LOG) << "Notifications inhibited:" << inhibited; + if (!inhibited) { + wakeUp(); + } + } +} + + void AlarmDialog::slotSave() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); diff --git a/korgac/org.freedesktop.DBus.Properties.xml b/korgac/org.freedesktop.DBus.Properties.xml new file mode 100644 --- /dev/null +++ b/korgac/org.freedesktop.DBus.Properties.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/korgac/org.freedesktop.Notifications.xml b/korgac/org.freedesktop.Notifications.xml new file mode 100644 --- /dev/null +++ b/korgac/org.freedesktop.Notifications.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/korgac/tests/CMakeLists.txt b/korgac/tests/CMakeLists.txt --- a/korgac/tests/CMakeLists.txt +++ b/korgac/tests/CMakeLists.txt @@ -9,12 +9,19 @@ ########### next target ############### -set(testalarmdlg_SRCS testalarmdlg.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../alarmdialog.cpp ../mailclient.cpp ${korganizer_BINARY_DIR}/korgac/koalarmclient_debug.cpp) +set(testalarmdlg_SRCS + testalarmdlg.cpp + ../alarmdialog.cpp + ../mailclient.cpp + ${korganizer_BINARY_DIR}/korgac/koalarmclient_debug.cpp) qt5_add_dbus_interface(testalarmdlg_SRCS ${korganizer_xml} korganizer_interface ) +qt5_add_dbus_interface(testalarmdlg_SRCS ../org.freedesktop.Notifications.xml notifications_interface) +qt5_add_dbus_interface(testalarmdlg_SRCS ../org.freedesktop.DBus.Properties.xml dbusproperties) + add_executable(testalarmdlg ${testalarmdlg_SRCS}) target_link_libraries(testalarmdlg