diff --git a/libnotificationmanager/CMakeLists.txt b/libnotificationmanager/CMakeLists.txt index 3419c39de..4fe4ef4b9 100644 --- a/libnotificationmanager/CMakeLists.txt +++ b/libnotificationmanager/CMakeLists.txt @@ -1,123 +1,122 @@ add_definitions(-DTRANSLATION_DOMAIN=\"libnotificationmanager\") add_subdirectory(declarative) if(BUILD_TESTING) add_subdirectory(autotests) endif() set(notificationmanager_LIB_SRCS server.cpp server_p.cpp settings.cpp mirroredscreenstracker.cpp notifications.cpp notification.cpp notificationsmodel.cpp notificationfilterproxymodel.cpp notificationsortproxymodel.cpp notificationgroupingproxymodel.cpp notificationgroupcollapsingproxymodel.cpp jobsmodel.cpp jobsmodel_p.cpp job.cpp job_p.cpp limitedrowcountproxymodel.cpp utils.cpp ) ecm_qt_declare_logging_category(notificationmanager_LIB_SRCS HEADER debug.h IDENTIFIER NOTIFICATIONMANAGER CATEGORY_NAME org.kde.plasma.notifications) if (${ECM_VERSION} STRGREATER "5.58.0") install(FILES libnotificationmanager.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) else() install(FILES libnotificationmanager.categories DESTINATION ${KDE_INSTALL_CONFDIR}) endif() # Settings kconfig_add_kcfg_files(notificationmanager_LIB_SRCS kcfg/donotdisturbsettings.kcfgc) kconfig_add_kcfg_files(notificationmanager_LIB_SRCS kcfg/notificationsettings.kcfgc) kconfig_add_kcfg_files(notificationmanager_LIB_SRCS kcfg/jobsettings.kcfgc) kconfig_add_kcfg_files(notificationmanager_LIB_SRCS kcfg/badgesettings.kcfgc) # DBus # Notifications qt5_add_dbus_adaptor(notificationmanager_LIB_SRCS dbus/org.freedesktop.Notifications.xml server_p.h NotificationManager::ServerPrivate) # JobView qt5_add_dbus_adaptor(notificationmanager_LIB_SRCS dbus/org.kde.kuiserver.xml jobsmodel_p.h NotificationManager::JobsModelPrivate) qt5_add_dbus_adaptor(notificationmanager_LIB_SRCS dbus/org.kde.JobViewServer.xml jobsmodel_p.h NotificationManager::JobsModelPrivate) qt5_add_dbus_adaptor(notificationmanager_LIB_SRCS dbus/org.kde.JobViewServerV2.xml jobsmodel_p.h NotificationManager::JobsModelPrivate) qt5_add_dbus_adaptor(notificationmanager_LIB_SRCS dbus/org.kde.JobViewV2.xml job_p.h NotificationManager::JobPrivate) qt5_add_dbus_adaptor(notificationmanager_LIB_SRCS dbus/org.kde.JobViewV3.xml job_p.h NotificationManager::JobPrivate) add_library(notificationmanager ${notificationmanager_LIB_SRCS}) add_library(PW::LibNotificationManager ALIAS notificationmanager) target_compile_definitions(notificationmanager PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") generate_export_header(notificationmanager) target_include_directories(notificationmanager PUBLIC "$" "$") target_link_libraries(notificationmanager PUBLIC Qt5::Core Qt5::Gui Qt5::Quick KF5::ConfigCore KF5::ItemModels PRIVATE Qt5::DBus KF5::ConfigGui KF5::I18n KF5::IconThemes KF5::KIOFileWidgets KF5::Plasma - KF5::ProcessCore KF5::Screen KF5::Service ) set_target_properties(notificationmanager PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1 EXPORT_NAME LibNotificationManager) install(TARGETS notificationmanager EXPORT notificationmanagerLibraryTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) install(FILES server.h notifications.h notification.h jobsmodel.h job.h settings.h ${CMAKE_CURRENT_BINARY_DIR}/notificationmanager_export.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/notificationmanager COMPONENT Devel ) write_basic_config_version_file(${CMAKE_CURRENT_BINARY_DIR}/LibNotificationManagerConfigVersion.cmake VERSION "${PROJECT_VERSION}" COMPATIBILITY AnyNewerVersion) set(CMAKECONFIG_INSTALL_DIR ${KDE_INSTALL_LIBDIR}/cmake/LibNotificationManager) configure_package_config_file(LibNotificationManagerConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/LibNotificationManagerConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LibNotificationManagerConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/LibNotificationManagerConfigVersion.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR}) install(EXPORT notificationmanagerLibraryTargets NAMESPACE PW:: DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE LibNotificationManagerLibraryTargets.cmake ) install(FILES plasmanotifyrc DESTINATION ${KDE_INSTALL_CONFDIR}) diff --git a/libnotificationmanager/utils.cpp b/libnotificationmanager/utils.cpp index ef811f881..6d6280cf5 100644 --- a/libnotificationmanager/utils.cpp +++ b/libnotificationmanager/utils.cpp @@ -1,101 +1,97 @@ /* * Copyright 2019 Kai Uwe Broulik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "utils_p.h" #include #include #include #include #include #include #include #include -#include -#include +#include using namespace NotificationManager; QString Utils::processNameFromPid(uint pid) { - KSysGuard::Processes procs; - procs.updateOrAddProcess(pid); + auto processInfo = KProcessList::processInfo(pid); - KSysGuard::Process *proc = procs.getProcess(pid); - - if (!proc) { + if (!processInfo.isValid()) { return QString(); } - return proc->name(); + return processInfo.name(); } QString Utils::desktopEntryFromPid(uint pid) { QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid))); if (!environFile.open(QIODevice::ReadOnly | QIODevice::Text)) { return QString(); } const QByteArray bamfDesktopFileHint = QByteArrayLiteral("BAMF_DESKTOP_FILE_HINT"); const auto lines = environFile.readAll().split('\0'); for (const QByteArray &line : lines) { const int equalsIdx = line.indexOf('='); if (equalsIdx <= 0) { continue; } const QByteArray key = line.left(equalsIdx); const QByteArray value = line.mid(equalsIdx + 1); if (key == bamfDesktopFileHint) { return value; } } return QString(); } QModelIndex Utils::mapToModel(const QModelIndex &idx, const QAbstractItemModel *sourceModel) { // KModelIndexProxyMapper can only map diferent indices to a single source // but we have the other way round, a single index that splits into different source models QModelIndex resolvedIdx = idx; while (resolvedIdx.isValid() && resolvedIdx.model() != sourceModel) { if (auto *proxyModel = qobject_cast(resolvedIdx.model())) { resolvedIdx = proxyModel->mapToSource(resolvedIdx); // KConcatenateRowsProxyModel isn't a "real" proxy model, so we need to special case for it :( } else if (auto *concatenateModel = qobject_cast(resolvedIdx.model())) { resolvedIdx = concatenateModel->mapToSource(resolvedIdx); } else { if (resolvedIdx.model() != sourceModel) { resolvedIdx = QModelIndex(); // give up } } } return resolvedIdx; } bool Utils::isDBusMaster() { return qApp->property("_plasma_dbus_master").toBool(); }