From d14fd7f434b90bd63aa98058696c14e78a5448c4 Mon Sep 17 00:00:00 2001 From: Prajwal S N Date: Wed, 18 Oct 2023 18:16:07 +0530 Subject: [PATCH 1/2] feat: use dbus for notifications Co-authored by: Tassos Manganaris Signed-off-by: Prajwal S N --- src/powerkit.h | 5 ++++- src/powerkit_notify.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ src/powerkit_notify.h | 36 ++++++++++++++++++++++++++++++ src/powerkit_systray.cpp | 20 +++++++++++------ 4 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 src/powerkit_notify.cpp create mode 100644 src/powerkit_notify.h diff --git a/src/powerkit.h b/src/powerkit.h index 49930e0..97c01fe 100644 --- a/src/powerkit.h +++ b/src/powerkit.h @@ -33,6 +33,9 @@ #define LOGIND_MANAGER "org.freedesktop.login1.Manager" #define LOGIND_DOCKED "Docked" +#define NOTIFY_SERVICE "org.freedesktop.Notifications" +#define NOTIFY_PATH "/org/freedesktop/Notifications" + #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_MANAGER "org.freedesktop.UPower" #define UPOWER_DEVICES "/org/freedesktop/UPower/devices/" @@ -183,7 +186,7 @@ private slots: quint32 cookie); void handleDelInhibitScreenSaver(quint32 cookie); void handleDelInhibitPowerManagement(quint32 cookie); - + bool registerSuspendLock(); void setWakeAlarmFromSettings(); diff --git a/src/powerkit_notify.cpp b/src/powerkit_notify.cpp new file mode 100644 index 0000000..52ebed1 --- /dev/null +++ b/src/powerkit_notify.cpp @@ -0,0 +1,47 @@ +/* +# PowerKit +# Copyright (c) 2018-2022 Ole-André Rodlie All rights reserved. +# +# Available under the 3-clause BSD license +# See the LICENSE file for full details +*/ + +#include "powerkit_notify.h" +#include "powerkit_def.h" +#include "powerkit.h" + +SystemNotification::SystemNotification(QObject* parent) + : QObject(parent) +{ + dbus = + new QDBusInterface(NOTIFY_SERVICE, + NOTIFY_PATH, + NOTIFY_SERVICE, + QDBusConnection::sessionBus(), + this); + valid = dbus->isValid(); +} + +void SystemNotification::sendMessage(const QString& text, + const QString& title, + const bool critical) +{ + QList args; + QVariantMap hintsMap; + int timeout = 5000; + + if (critical) { + hintsMap.insert("urgency", QVariant::fromValue(uchar(2))); + timeout = 0; + } + + args << (qAppName()) // appname + << static_cast(0) // id + << DEFAULT_NOTIFY_ICON // icon + << title // summary + << text // body + << QStringList() // actions + << hintsMap // hints + << timeout; // timeout + dbus->callWithArgumentList( QDBus::AutoDetect, QString("Notify"), args); +} diff --git a/src/powerkit_notify.h b/src/powerkit_notify.h new file mode 100644 index 0000000..e0eb964 --- /dev/null +++ b/src/powerkit_notify.h @@ -0,0 +1,36 @@ +/* +# PowerKit +# Copyright (c) 2018-2022 Ole-André Rodlie All rights reserved. +# +# Available under the 3-clause BSD license +# See the LICENSE file for full details +*/ + +#ifndef NOTIFY_H +#define NOTIFY_H + +#include +#include +#include +#include +#include + +class QDBusInterface; + +class SystemNotification : public QObject +{ + Q_OBJECT + +public: + explicit SystemNotification(QObject* parent = nullptr); + bool valid; + + void sendMessage(const QString& text, + const QString& title, + const bool critical); + +private: + QDBusInterface *dbus; +}; + +#endif // NOTIFY_H diff --git a/src/powerkit_systray.cpp b/src/powerkit_systray.cpp index 7a2dd97..80170f6 100644 --- a/src/powerkit_systray.cpp +++ b/src/powerkit_systray.cpp @@ -9,6 +9,7 @@ #include "powerkit_systray.h" #include "powerkit_def.h" #include "powerkit_theme.h" +#include "powerkit_notify.h" #include "powerkit_settings.h" #include "powerkit_backlight.h" #include "powerkit_cpu.h" @@ -898,13 +899,18 @@ void SysTray::showMessage(const QString &title, const QString &msg, bool critical) { - if (tray->isVisible() && showNotifications) { - if (critical) { - tray->showMessage(title, msg, - QSystemTrayIcon::Critical, - 900000); - } else { - tray->showMessage(title, msg); + if (showNotifications) { + SystemNotification notifier; + if (notifier.valid) { + notifier.sendMessage(title, msg, critical); + } else if (tray->isVisible()) { + if (critical) { + tray->showMessage(title, msg, + QSystemTrayIcon::Critical, + 900000); + } else { + tray->showMessage(title, msg); + } } } } From a8ddabd0757d596e04eacbff110c83655074ab2f Mon Sep 17 00:00:00 2001 From: Prajwal S N Date: Sat, 6 Jan 2024 14:01:55 +0530 Subject: [PATCH 2/2] fix(ci): use latest Ubuntu image Signed-off-by: Prajwal S N --- .github/workflows/c-cpp.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 77ed6e0..f6f85e3 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -5,12 +5,15 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Dependencies - run: sudo apt-get install tree cmake qt4-dev-tools qtbase5-dev libxss-dev libxrandr-dev + - uses: actions/checkout@v3 + - name: Install dependencies + run: | + sudo add-apt-repository -y ppa:ubuntuhandbook1/ppa + sudo apt-get update + sudo apt-get install -y tree cmake qt4-dev-tools qtbase5-dev libxss-dev libxrandr-dev - name: Build run: | export CWD=`pwd`