/* * * Notification DBus Service implementation * * Copyright (C) 2021 Emanoil Kotsev * * * This file is part of kdbusnotification. * * kdbusnotification is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * kdbusnotification is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with kdbusnotification; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "NotificationsService.h" #define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications" #define IMAGE_SIZE 48 #define SRV_VERSION "1.1" #define SPEC_VERSION "1.1" NotificationsService::NotificationsService(TQT_DBusConnection &conn) : org::freedesktop::NotificationsInterface(), mConnection(&conn) { // TODO Auto-generated constructor stub } NotificationsService::~NotificationsService() { // TODO Auto-generated destructor stub } void NotificationsService::closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason) { if (notificationMap[id]) { notificationMap[id]->close(); delete notificationMap[id]; notificationMap.remove(id); } if ( !emitNotificationClosed(id, reason) ) { tqWarning("Failed to emit DBus signal NotificationClosed"); } } bool NotificationsService::handleSignalSend(const TQT_DBusMessage& reply) { mConnection->send(reply); return true; } TQString NotificationsService::objectPath() const { return TQString(NOTIFICATIONS_DBUS_PATH); } bool NotificationsService::GetCapabilities(TQStringList& return_caps, TQT_DBusError& error) { return_caps.clear(); return_caps << "action-icons" << "actions" << "body" << "body-hyperlinks" << "body-markup" << "icon-static"; return true; } void NotificationsService::CloseNotificationAsync(int asyncCallId, TQ_UINT32 id) { closeNotifyWidget(id, 3); // The notification was closed by a call to CloseNotification. CloseNotificationAsyncReply(asyncCallId); } bool NotificationsService::ReloadSettings(TQT_DBusError& error) { // Do nothing return true; } bool NotificationsService::GetServerInformation(TQString& return_name, TQString& return_vendor, TQString& return_version, TQString& return_spec_version, TQT_DBusError& error) { return_name = TQString("Notification Daemon"); return_vendor = TQString("Trinity Desktop Project"); return_version = TQString(SRV_VERSION); return_spec_version = TQString(SPEC_VERSION); return true; } void NotificationsService::NotifyAsync( int asyncCallId, const TQString& app_name, TQ_UINT32 id, const TQString& icon, const TQString& summary, const TQString& body, const TQStringList& actions, const TQMap& hints, TQ_INT32 timeout) { if (notificationMap.contains(id)) { NotifyAsyncError(asyncCallId, TQT_DBusError::stdFailed("Requested id already displayed")); tqDebug("Requested id %i already in use", id); return; } notificationMap[id] = new NotifyWidget(0, app_name.ascii(), this, id ); notificationMap[id]->setFrameStyle( TQFrame::NoFrame ); notificationMap[id]->setPaletteBackgroundColor(TQt::black); notificationMap[id]->setPaletteForegroundColor(TQt::white); 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]->adjustSize(); notificationMap[id]->raise(); notificationMap[id]->show(); notificationMap[id]->setActiveWindow(); NotifyAsyncReply(asyncCallId, id); } void NotificationsService::handleMethodReply(const TQT_DBusMessage& reply) { mConnection->send(reply); }