diff --git a/dataengines/notifications/CMakeLists.txt b/dataengines/notifications/CMakeLists.txt --- a/dataengines/notifications/CMakeLists.txt +++ b/dataengines/notifications/CMakeLists.txt @@ -9,6 +9,11 @@ notificationsanitizer.cpp ) +ecm_qt_declare_logging_category(notifications_engine_SRCS HEADER debug.h + IDENTIFIER NOTIFICATIONS + CATEGORY_NAME kde.dataengine.notifications` + DEFAULT_SEVERITY Info) + qt5_add_dbus_adaptor( notifications_engine_SRCS org.freedesktop.Notifications.xml notificationsengine.h NotificationsEngine ) add_library(plasma_engine_notifications MODULE ${notifications_engine_SRCS}) @@ -32,7 +37,16 @@ #unit test +set(notifications_test_SRCS + notificationsanitizer.cpp + notifications_test.cpp +) + +ecm_qt_declare_logging_category(notifications_test_SRCS HEADER debug.h + IDENTIFIER NOTIFICATIONS + CATEGORY_NAME kde.dataengine.notifications` + DEFAULT_SEVERITY Info) -add_executable(notification_test notificationsanitizer.cpp notifications_test.cpp) +add_executable(notification_test ${notifications_test_SRCS}) target_link_libraries(notification_test Qt5::Test Qt5::Core) ecm_mark_as_test(notification_test) diff --git a/dataengines/notifications/notificationaction.cpp b/dataengines/notifications/notificationaction.cpp --- a/dataengines/notifications/notificationaction.cpp +++ b/dataengines/notifications/notificationaction.cpp @@ -21,13 +21,13 @@ #include -#include +#include "debug.h" void NotificationAction::start() { - //qDebug() << "Trying to perform the action " << operationName() << " on " << destination(); - //qDebug() << "actionId: " << parameters()["actionId"].toString(); - //qDebug() << "params: " << parameters(); + qCDebug(NOTIFICATIONS) << "Trying to perform the action " << operationName() << " on " << destination(); + qCDebug(NOTIFICATIONS) << "actionId: " << parameters()["actionId"].toString(); + qCDebug(NOTIFICATIONS) << "params: " << parameters(); if (!m_engine) { setErrorText(i18n("The notification dataEngine is not set.")); @@ -49,7 +49,7 @@ } if (operationName() == QLatin1String("invokeAction")) { - //qDebug() << "invoking action on " << id; + qCDebug(NOTIFICATIONS) << "invoking action on " << id; emit m_engine->ActionInvoked(id, parameters()[QStringLiteral("actionId")].toString()); } else if (operationName() == QLatin1String("userClosed")) { //userClosedNotification deletes the job, so we have to invoke it queued, in this case emitResult() can be called diff --git a/dataengines/notifications/notificationsanitizer.cpp b/dataengines/notifications/notificationsanitizer.cpp --- a/dataengines/notifications/notificationsanitizer.cpp +++ b/dataengines/notifications/notificationsanitizer.cpp @@ -22,9 +22,10 @@ #include #include #include -#include #include +#include "debug.h" + QString NotificationSanitizer::parse(const QString &text) { // replace all \ns with
@@ -92,7 +93,7 @@ out.writeEndDocument(); if (r.hasError()) { - qWarning() << "Notification to send to backend contains invalid XML: " + qCWarning(NOTIFICATIONS) << "Notification to send to backend contains invalid XML: " << r.errorString() << "line" << r.lineNumber() << "col" << r.columnNumber(); } diff --git a/dataengines/notifications/notificationsengine.cpp b/dataengines/notifications/notificationsengine.cpp --- a/dataengines/notifications/notificationsengine.cpp +++ b/dataengines/notifications/notificationsengine.cpp @@ -22,7 +22,6 @@ #include "notificationsadaptor.h" #include "notificationsanitizer.h" -#include #include #include #include @@ -43,6 +42,8 @@ // for ::kill #include +#include "debug.h" + NotificationsEngine::NotificationsEngine( QObject* parent, const QVariantList& args ) : Plasma::DataEngine( parent, args ), m_nextId( 1 ), m_alwaysReplaceAppsList({QStringLiteral("Clementine"), QStringLiteral("Spotify"), QStringLiteral("Amarok")}) { @@ -59,7 +60,7 @@ // It's not the same but check if it isn't plasma, // we don't want to kill Plasma if (pid != plasmaPidReply.value()) { - qDebug() << "Terminating current Notification service with pid" << pid; + qCDebug(NOTIFICATIONS) << "Terminating current Notification service with pid" << pid; // Now finally terminate the service and register our own ::kill(pid, SIGTERM); // Wait 3 seconds and then try registering it again @@ -72,7 +73,7 @@ const bool broadcastsEnabled = config.readEntry("ListenForBroadcasts", false); if (broadcastsEnabled) { - qDebug() << "Notifications engine is configured to listen for broadcasts"; + qCDebug(NOTIFICATIONS) << "Notifications engine is configured to listen for broadcasts"; QDBusConnection::systemBus().connect({}, {}, QStringLiteral("org.kde.BroadcastNotifications"), QStringLiteral("Notify"), this, SLOT(onBroadcastNotification(QMap))); } @@ -102,7 +103,7 @@ return true; } - qDebug() << "Failed to register Notifications service"; + qCInfo(NOTIFICATIONS) << "Failed to register Notifications service"; return false; } @@ -132,7 +133,6 @@ arg.beginStructure(); arg >> width >> height >> rowStride >> hasAlpha >> bitsPerSample >> channels >> pixels; arg.endStructure(); - //qDebug() << width << height << rowStride << hasAlpha << bitsPerSample << channels; #define SANITY_CHECK(condition) \ if (!(condition)) { \ @@ -195,7 +195,7 @@ { foreach(NotificationInhibiton *ni, m_inhibitions) { if (hints[ni->hint] == ni->value) { - qDebug() << "notification inhibited. Skipping"; + qCDebug(NOTIFICATIONS) << "notification inhibited. Skipping"; return -1; } } @@ -214,9 +214,9 @@ partOf = m_activeNotifications.key(app_name + summary).midRef(13).toUInt(); } - qDebug() << "Currrent active notifications:" << m_activeNotifications; - qDebug() << "Guessing partOf as:" << partOf; - qDebug() << " New Notification: " << summary << body << timeout << "& Part of:" << partOf; + qCDebug(NOTIFICATIONS) << "Currrent active notifications:" << m_activeNotifications; + qCDebug(NOTIFICATIONS) << "Guessing partOf as:" << partOf; + qCDebug(NOTIFICATIONS) << " New Notification: " << summary << body << timeout << "& Part of:" << partOf; QString bodyFinal = NotificationSanitizer::parse(body); QString summaryFinal = summary; @@ -434,7 +434,7 @@ void NotificationsEngine::onBroadcastNotification(const QMap &properties) { - qDebug() << "Received broadcast notification"; + qCDebug(NOTIFICATIONS) << "Received broadcast notification"; const auto currentUserId = KUserId::currentEffectiveUserId().nativeId(); @@ -448,7 +448,7 @@ }); if (it == userIds.constEnd()) { - qDebug() << "It is not meant for us, ignoring"; + qCDebug(NOTIFICATIONS) << "It is not meant for us, ignoring"; return; } }