From 3f65002dc9944851b11bdff8a8c388e82b669083 Mon Sep 17 00:00:00 2001 From: lidanger Date: Wed, 14 Oct 2020 20:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spark-store.pro | 2 +- widget.cpp | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/spark-store.pro b/spark-store.pro index ea7dcf9..686efe8 100644 --- a/spark-store.pro +++ b/spark-store.pro @@ -12,7 +12,7 @@ TRANSLATIONS = ./trans/spark-store_en.ts \ ./trans/spark-store_fr.ts\ CONFIG += link_pkgconfig -PKGCONFIG += dtkwidget +PKGCONFIG += dtkwidget glib-2.0 gdk-pixbuf-2.0 libnotify TARGET = spark-store TEMPLATE = app diff --git a/widget.cpp b/widget.cpp index 0729698..ccb1ca6 100644 --- a/widget.cpp +++ b/widget.cpp @@ -1,3 +1,4 @@ +#include #include "widget.h" #include "ui_widget.h" #include @@ -301,20 +302,32 @@ DTitlebar* Widget::getTitlebar() return ui->titlebar; } +static NotifyNotification *_notify = nullptr; + void Widget::sendNotification(const QString &message, const int msTimeout, const QString &icon) { - system((QString("notify-send --icon=%1 --expire-time=%2 --app-name=").arg(icon).arg(msTimeout) + - tr("Spark\\ Store") + - " '" + message + "'" - ).toUtf8()); + if(_notify == nullptr) + { + _notify = notify_notification_new(tr("Spark\\ Store").toLocal8Bit(), message.toLocal8Bit(), icon.toLocal8Bit()); + notify_notification_set_timeout(_notify, msTimeout); + } + else + notify_notification_update(_notify, tr("Spark\\ Store").toLocal8Bit(), message.toLocal8Bit(), icon.toLocal8Bit()); + + notify_notification_show(_notify, nullptr); } void Widget::sendNotification(const char *message, const int msTimeout, const QString &icon) { - system((QString("notify-send --icon=%1 --expire-time=%2 --app-name=").arg(icon).arg(msTimeout) + - tr("Spark\\ Store") + - " '" + message + "'" - ).toUtf8()); + if(_notify == nullptr) + { + _notify = notify_notification_new(tr("Spark\\ Store").toLocal8Bit(), message, icon.toLocal8Bit()); + notify_notification_set_timeout(_notify, msTimeout); + } + else + notify_notification_update(_notify, tr("Spark\\ Store").toLocal8Bit(), message, icon.toLocal8Bit()); + + notify_notification_show(_notify, nullptr); } void Widget::updateUI() -- Gitee