From 89b1302ca54bc14b96d620d1efa79ebf08fe93a1 Mon Sep 17 00:00:00 2001 From: Emanoil Kotsev Date: Sat, 5 Jun 2021 12:35:10 +0200 Subject: [PATCH] some improvments display icon instead of text if supplied Signed-off-by: Emanoil Kotsev --- README | 16 ++++++++++++++++ src/daemon/NotificationsService.cpp | 13 ++++++++----- src/daemon/NotifyWidget.cpp | 15 +++++++++++---- src/daemon/NotifyWidget.h | 3 ++- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/README b/README index d82dff2..37b9058 100644 --- a/README +++ b/README @@ -70,3 +70,19 @@ gdbus call \ "[]" \ "{}" \ "2000" + +To test hypertext + +gdbus call \ + --session \ + --dest org.freedesktop.Notifications \ + --object-path /org/freedesktop/Notifications \ + --method org.freedesktop.Notifications.Notify \ + "Identifier" \ + "5" \ + "/usr/share/icons/hicolor/72x72/mimetypes/virtualbox-vbox.png" \ + "Notification title" \ + "Notification:
Some Text here" \ + "[]" \ + "{}" \ + "2000" diff --git a/src/daemon/NotificationsService.cpp b/src/daemon/NotificationsService.cpp index 77e0962..cf3c8a4 100644 --- a/src/daemon/NotificationsService.cpp +++ b/src/daemon/NotificationsService.cpp @@ -69,7 +69,7 @@ TQString NotificationsService::objectPath() const { bool NotificationsService::GetCapabilities(TQStringList& return_caps, TQT_DBusError& error) { return_caps.clear(); - return_caps << "actions" << "body" << "body-hyperlinks" << "body-markup" << "icon-static"; + return_caps << "action-icons" << "actions" << "body" << "body-hyperlinks" << "body-markup" << "icon-static"; return true; } @@ -103,17 +103,20 @@ void NotificationsService::NotifyAsync( { notificationMap[id] = new NotifyWidget(0, app_name.ascii(), this, id ); + notificationMap[id]->setFrameStyle( TQFrame::NoFrame ); - notificationMap[id]->setIcon(icon); notificationMap[id]->setPaletteBackgroundColor(TQt::black); notificationMap[id]->setPaletteForegroundColor(TQt::white); - // TODO: handle hypertext in the body - notificationMap[id]->setText(app_name + ": " + summary + "\n" + body); + + if (icon.isEmpty() || ! notificationMap[id]->setIcon(icon)) { + notificationMap[id]->setTextFormat(TQt::RichText); + notificationMap[id]->setText(app_name + ":\n" + summary + "\n" + body); + } notificationMap[id]->setActions(actions); notificationMap[id]->setHints(hints); notificationMap[id]->setTimeout(timeout); - notificationMap[id]->show(); notificationMap[id]->raise(); + notificationMap[id]->show(); notificationMap[id]->setActiveWindow(); NotifyAsyncReply(asyncCallId, id); diff --git a/src/daemon/NotifyWidget.cpp b/src/daemon/NotifyWidget.cpp index a91768b..02b40dc 100644 --- a/src/daemon/NotifyWidget.cpp +++ b/src/daemon/NotifyWidget.cpp @@ -20,7 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include +#include #include "NotifyWidget.h" #include "NotificationsService.h" @@ -30,13 +32,11 @@ NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, NotificationsServ mName(TQString(name)), notificationService(ns), mId(id) { // TODO Auto-generated constructor stub - } NotifyWidget::~NotifyWidget() { // TODO Auto-generated destructor stub - } void NotifyWidget::mousePressEvent( TQMouseEvent *e ) @@ -62,9 +62,16 @@ void NotifyWidget::setAutoMask(bool b) TQWidget::setAutoMask(b); } -void NotifyWidget::setIcon(const TQString& icon) { +bool NotifyWidget::setIcon(const TQString& icon) { mIcon = icon; - // TODO handle icon + TQPixmap pixmap; + if ( pixmap.load(mIcon) ) { + this->setPixmap(pixmap); + } else { + tqDebug("Could not load notification icon"); + return false; + } + return true; } void NotifyWidget::setActions(const TQStringList& actions) { diff --git a/src/daemon/NotifyWidget.h b/src/daemon/NotifyWidget.h index 891d5aa..cee8d2e 100644 --- a/src/daemon/NotifyWidget.h +++ b/src/daemon/NotifyWidget.h @@ -24,6 +24,7 @@ #define SRC_DAEMON_NOTIFYWIDGET_H_ #include +#include #include class NotificationsService; @@ -38,7 +39,7 @@ public: void setAutoMask(bool b); - void setIcon(const TQString& icon); + bool setIcon(const TQString& icon); void setActions(const TQStringList& actions); void setHints(const TQMap< TQString, TQT_DBusVariant >& hints); void setTimeout(TQ_INT32 t);