File indexing completed on 2024-05-19 05:37:51
0001 /* 0002 SPDX-FileCopyrightText: 2008 Rob Scheepmaker <r.scheepmaker@student.utwente.nl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "notificationaction.h" 0008 0009 #include "server.h" 0010 0011 #include <klocalizedstring.h> 0012 0013 #include "debug.h" 0014 0015 using namespace NotificationManager; 0016 0017 void NotificationAction::start() 0018 { 0019 qCDebug(NOTIFICATIONS) << "Trying to perform the action " << operationName() << " on " << destination(); 0020 qCDebug(NOTIFICATIONS) << "actionId: " << parameters()["actionId"].toString(); 0021 qCDebug(NOTIFICATIONS) << "params: " << parameters(); 0022 0023 if (!m_engine) { 0024 setErrorText(i18n("The notification dataEngine is not set.")); 0025 setError(-1); 0026 emitResult(); 0027 return; 0028 } 0029 0030 const QStringList dest = destination().split(' '); 0031 0032 uint id = 0; 0033 if (dest.count() > 1 && !dest[1].toInt()) { 0034 setErrorText(i18n("Invalid destination: %1", destination())); 0035 setError(-2); 0036 emitResult(); 0037 return; 0038 } else if (dest.count() > 1) { 0039 id = dest[1].toUInt(); 0040 } 0041 0042 if (operationName() == QLatin1String("invokeAction")) { 0043 qCDebug(NOTIFICATIONS) << "invoking action on " << id; 0044 Server::self().invokeAction(id, parameters()[QStringLiteral("actionId")].toString(), {}, Notifications::None, nullptr); 0045 } else if (operationName() == QLatin1String("userClosed")) { 0046 // userClosedNotification deletes the job, so we have to invoke it queued, in this case emitResult() can be called 0047 m_engine->metaObject()->invokeMethod(m_engine, "removeNotification", Qt::QueuedConnection, Q_ARG(uint, id), Q_ARG(uint, 2)); 0048 } else if (operationName() == QLatin1String("expireNotification")) { 0049 // expireNotification deletes the job, so we have to invoke it queued, in this case emitResult() can be called 0050 m_engine->metaObject()->invokeMethod(m_engine, "removeNotification", Qt::QueuedConnection, Q_ARG(uint, id), Q_ARG(uint, 1)); 0051 } else if (operationName() == QLatin1String("createNotification")) { 0052 int expireTimeout = parameters().value(QStringLiteral("expireTimeout")).toInt(); 0053 bool isPersistent = parameters().value(QStringLiteral("isPersistent")).toBool(); 0054 0055 QVariantMap hints; 0056 if (parameters().value(QStringLiteral("skipGrouping")).toBool()) { 0057 hints.insert(QStringLiteral("x-kde-skipGrouping"), true); 0058 } 0059 0060 int rv = m_engine->createNotification(parameters().value(QStringLiteral("appName")).toString(), 0061 parameters().value(QStringLiteral("appIcon")).toString(), 0062 parameters().value(QStringLiteral("summary")).toString(), 0063 parameters().value(QStringLiteral("body")).toString(), 0064 isPersistent ? 0 : expireTimeout, 0065 parameters().value(QStringLiteral("actions")).toStringList(), 0066 hints); 0067 setResult(rv); 0068 return; 0069 } else if (operationName() == QLatin1String("configureNotification")) { 0070 m_engine->configureNotification(parameters()[QStringLiteral("appRealName")].toString(), parameters()[QStringLiteral("eventId")].toString()); 0071 } else if (operationName() == QLatin1String("inhibit")) { 0072 const QString hint = parameters()[QStringLiteral("hint")].toString(); 0073 const QString value = parameters()[QStringLiteral("value")].toString(); 0074 auto t = m_engine->createInhibition(hint, value); 0075 setResult(QVariant::fromValue(t)); 0076 return; 0077 } 0078 0079 emitResult(); 0080 }