Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Set low urgency hint for notifications and send along desktop entry
Browse files Browse the repository at this point in the history
Allows the notification server to better identify where the notification comes from and that
it is a non-important notification that shouldn't e.g. clutter up the notification backlog.
Moreover, according to freedesktop Notifications spec the "appName" is a user-visible
name, so use applicationDisplayName for it.
  • Loading branch information
kbroulik committed Apr 17, 2019
1 parent c245985 commit ac8608a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 deletions dbus/notify.cpp
Expand Up @@ -25,7 +25,7 @@
#include "notificationsinterface.h"
#include <QDBusPendingReply>
#include <QDBusPendingCallWatcher>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QPixmap>
#include <QImage>

Expand Down Expand Up @@ -90,13 +90,19 @@ Notify::Notify(QObject *p)
"/org/freedesktop/Notifications", QDBusConnection::sessionBus());
}

void Notify::show(const QString &title, const QString &text, const QImage &img)
void Notify::show(const QString &title, const QString &text, const QImage &img, Notify::Urgency urgency)
{
QVariantMap hints;
if (!img.isNull()) {
hints["image_data"] = QVariant(img);
}

if (urgency != DefaultUrgency) {
hints["urgency"] = static_cast<int>(urgency);
}

hints["desktop-entry"] = QGuiApplication::desktopFileName();

int id = 0;
if (lastTime.secsTo(QDateTime::currentDateTime()) * 1000 < constTimeout) {
// Reuse the existing popup if it's still open. The reason we don't always
Expand All @@ -105,7 +111,7 @@ void Notify::show(const QString &title, const QString &text, const QImage &img)
id = lastId;
}

QDBusPendingReply<uint> reply = iface->Notify(QCoreApplication::applicationName(), id, "cantata",
QDBusPendingReply<uint> reply = iface->Notify(QGuiApplication::applicationDisplayName(), id, "cantata",
QString(title).replace(QLatin1String("&"), QLatin1String("&amp;")),
QString(text).replace(QLatin1String("&"), QLatin1String("&amp;")),
QStringList(), hints, constTimeout);
Expand Down
9 changes: 8 additions & 1 deletion dbus/notify.h
Expand Up @@ -43,7 +43,14 @@ class Notify : public QObject
Notify(QObject *p);
~Notify() override { }

void show(const QString &title, const QString &text, const QImage &img);
enum Urgency {
DefaultUrgency = -1,
LowUrgency,
NormalUrgency,
CriticalUrgency
};

void show(const QString &title, const QString &text, const QImage &img, Urgency urgency = DefaultUrgency);

private Q_SLOTS:
void callFinished(QDBusPendingCallWatcher *watcher);
Expand Down

0 comments on commit ac8608a

Please sign in to comment.