-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'pr1/dbus-notif' into dev
- Loading branch information
Showing
5 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
# PowerKit <https://github.com/rodlie/powerkit> | ||
# Copyright (c) 2018-2022 Ole-André Rodlie <[email protected]> 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<QVariant> args; | ||
QVariantMap hintsMap; | ||
int timeout = 5000; | ||
|
||
if (critical) { | ||
hintsMap.insert("urgency", QVariant::fromValue(uchar(2))); | ||
timeout = 0; | ||
} | ||
|
||
args << (qAppName()) // appname | ||
<< static_cast<unsigned int>(0) // id | ||
<< DEFAULT_NOTIFY_ICON // icon | ||
<< title // summary | ||
<< text // body | ||
<< QStringList() // actions | ||
<< hintsMap // hints | ||
<< timeout; // timeout | ||
dbus->callWithArgumentList( QDBus::AutoDetect, QString("Notify"), args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
# PowerKit <https://github.com/rodlie/powerkit> | ||
# Copyright (c) 2018-2022 Ole-André Rodlie <[email protected]> All rights reserved. | ||
# | ||
# Available under the 3-clause BSD license | ||
# See the LICENSE file for full details | ||
*/ | ||
|
||
#ifndef NOTIFY_H | ||
#define NOTIFY_H | ||
|
||
#include <QObject> | ||
#include <QApplication> | ||
#include <QDBusConnection> | ||
#include <QDBusInterface> | ||
#include <QVariant> | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters