From c1031746096ac20d45f2444b27b6f8dbda482f16 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 14 Feb 2020 23:04:10 +0100 Subject: [PATCH] Make desktop files for Plasma integration from template * Avoid redundant meta-data * Take target suffix into account --- CMakeLists.txt | 1 + fileitemactionplugin/CMakeLists.txt | 10 ++-- .../syncthingfileitemaction.desktop.in | 15 ++++++ .../syncthingfileitemaction.desktop | 10 ---- plasmoid/CMakeLists.txt | 54 +++++++++++++++++-- .../templates/metadata.desktop.in} | 14 ++--- plasmoid/lib/CMakeLists.txt | 36 ++++--------- plasmoid/package/.gitignore | 2 + plasmoid/scripts/inittesting.sh | 17 +++++- testhelper/CMakeLists.txt | 3 ++ 10 files changed, 107 insertions(+), 55 deletions(-) create mode 100644 fileitemactionplugin/cmake/templates/syncthingfileitemaction.desktop.in delete mode 100644 fileitemactionplugin/syncthingfileitemaction.desktop rename plasmoid/{package/metadata.desktop => cmake/templates/metadata.desktop.in} (52%) create mode 100644 plasmoid/package/.gitignore diff --git a/CMakeLists.txt b/CMakeLists.txt index b246997..b5d76ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) set(META_PROJECT_NAME syncthingtray) set(META_PROJECT_TYPE application) set(META_APP_AUTHOR "Martchus") +set(META_APP_AUTHOR_MAIL "martchus@gmx.net") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "Tray application for Syncthing") set(META_APP_CATEGORIES "Network;FileTransfer") diff --git a/fileitemactionplugin/CMakeLists.txt b/fileitemactionplugin/CMakeLists.txt index 4662140..53a8cc2 100644 --- a/fileitemactionplugin/CMakeLists.txt +++ b/fileitemactionplugin/CMakeLists.txt @@ -41,7 +41,9 @@ include(WindowsResources) include(LibraryTarget) include(ConfigHeader) -install( - FILES ${META_PROJECT_NAME}.desktop - DESTINATION "share/kservices5" - COMPONENT desktop) +# configure and install desktop file +include(TemplateFinder) +find_template_file("${META_PROJECT_NAME}.desktop" "${META_PROJECT_NAME}" DESKTOP_TEMPLATE_FILE) +set(DESKTOP_TARGET_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}.desktop") +configure_file("${DESKTOP_TEMPLATE_FILE}" "${DESKTOP_TARGET_FILE}") +install(FILES "${DESKTOP_TARGET_FILE}" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/kservices5" COMPONENT desktop) diff --git a/fileitemactionplugin/cmake/templates/syncthingfileitemaction.desktop.in b/fileitemactionplugin/cmake/templates/syncthingfileitemaction.desktop.in new file mode 100644 index 0000000..e420730 --- /dev/null +++ b/fileitemactionplugin/cmake/templates/syncthingfileitemaction.desktop.in @@ -0,0 +1,15 @@ +[Desktop Entry] +Type=Service +Name=Trigger Syncthing scan +Name[de]="Syncthing-Rescan" im Servicemenü +X-KDE-PluginInfo-Author=@META_APP_AUTHOR@ +X-KDE-PluginInfo-Email=@META_APP_AUTHOR_MAIL@ +X-KDE-PluginInfo-License=@META_PROJECT_LICENSE@ +X-KDE-PluginInfo-Name=@META_ID@ +X-KDE-PluginInfo-Version=@META_VERSION_MAJOR@.@META_VERSION_MINOR@.@META_VERSION_PATCH@ +X-KDE-Library=@META_TARGET_NAME@ +X-KDE-Submenu=Syncthing + +Icon=syncthingtray +ServiceTypes=KFileItemAction/Plugin +MimeType=application/octet-stream;inode/directory diff --git a/fileitemactionplugin/syncthingfileitemaction.desktop b/fileitemactionplugin/syncthingfileitemaction.desktop deleted file mode 100644 index 950eb3e..0000000 --- a/fileitemactionplugin/syncthingfileitemaction.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Type=Service -Name=Trigger Syncthing scan -Name[de]="Syncthing-Rescan" im Servicemenü -X-KDE-Library=syncthingfileitemaction -X-KDE-Submenu=Syncthing - -Icon=syncthingtray -ServiceTypes=KFileItemAction/Plugin -MimeType=application/octet-stream;inode/directory diff --git a/plasmoid/CMakeLists.txt b/plasmoid/CMakeLists.txt index 6442a48..1e27747 100644 --- a/plasmoid/CMakeLists.txt +++ b/plasmoid/CMakeLists.txt @@ -3,27 +3,71 @@ cmake_minimum_required(VERSION 2.8.12) # meta data set(META_PROJECT_NAME syncthingplasmoid) set(META_APP_NAME "Syncthing Plasmoid") -set(META_APP_AUTHOR "Martchus") set(META_APP_DESCRIPTION "Plasmoid to interact with Syncthing") set(META_PROJECT_TYPE qtplugin) set(META_PLUGIN_CATEGORY plasma/applets) -set(META_ID "martchus.${META_PROJECT_NAME}") set(META_QT5_VERSION 5.8) +# source files +set(PLASMOID_FILES + package/contents/ui/CompactRepresentation.qml + package/contents/ui/FullRepresentation.qml + package/contents/ui/DirectoriesPage.qml + package/contents/ui/DevicesPage.qml + package/contents/ui/DownloadsPage.qml + package/contents/ui/RecentChangesPage.qml + package/contents/ui/TopLevelView.qml + package/contents/ui/TopLevelItem.qml + package/contents/ui/DetailView.qml + package/contents/ui/DetailItem.qml + package/contents/ui/ToolTipTrigger.qml + package/contents/ui/ToolTipView.qml + package/contents/ui/TinyButton.qml + package/contents/ui/TinyButtonStyle.qml + package/contents/ui/ButtonShadow.qml + package/contents/ui/IconLabel.qml + package/contents/ui/StatisticsView.qml + package/contents/ui/main.qml) + # find ECM (required by KF5Plasma) find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_MODULE_PATH}) + # find KF5Plasma find_package(KF5Plasma REQUIRED) -# add subdirs +# find c++utilities +find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS}) + +# prepare plasmoid package/configuration +set(PLASMOID_PACKAGE_DIR "${CMAKE_CURRENT_BINARY_DIR}/package") +file(MAKE_DIRECTORY "${PLASMOID_PACKAGE_DIR}") +set(PLASMOID_CONFIG_TARGET_FILE "${PLASMOID_PACKAGE_DIR}/metadata.desktop") + +# make plugin library add_subdirectory(lib) -plasma_install_package(package ${META_ID}) +# make plasmoid configuration +include(TemplateFinder) +find_template_file("metadata.desktop" "${META_PROJECT_NAME}" PLASMOID_CONFIG_TEMPLATE_FILE) +get_filename_component(PLASMOID_CONFIG_TARGET_FILE_ABSOLUTE_PATH "${PLASMOID_CONFIG_TARGET_FILE}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +configure_file("${PLASMOID_CONFIG_TEMPLATE_FILE}" "${PLASMOID_CONFIG_TARGET_FILE}") +# make plasmoid package folder +foreach (PLASMOID_FILE ${PLASMOID_FILES}) + get_filename_component(PLASMOID_FILE_DIR "${PLASMOID_FILE}" DIRECTORY) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PLASMOID_FILE_DIR}") + file(COPY "${PLASMOID_FILE}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${PLASMOID_FILE_DIR}") +endforeach () + +# install plasmoid files +plasma_install_package("${PLASMOID_PACKAGE_DIR}" "${META_ID}") + +# add target to ease testing the plasmoid (see testing.md) set(PLASMOID_TESTDIR "${CMAKE_CURRENT_BINARY_DIR}/testdir" CACHE STRING "specifies the Plasmoid test directory") file(MAKE_DIRECTORY "${PLASMOID_TESTDIR}") add_custom_target(init_plasmoid_testing - COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/inittesting.sh" + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/inittesting.sh" "${PLASMOID_CONFIG_TARGET_FILE_ABSOLUTE_PATH}" WORKING_DIRECTORY "${PLASMOID_TESTDIR}" ) diff --git a/plasmoid/package/metadata.desktop b/plasmoid/cmake/templates/metadata.desktop.in similarity index 52% rename from plasmoid/package/metadata.desktop rename to plasmoid/cmake/templates/metadata.desktop.in index ffbb480..a6929d5 100644 --- a/plasmoid/package/metadata.desktop +++ b/plasmoid/cmake/templates/metadata.desktop.in @@ -5,12 +5,12 @@ Icon=syncthingtray Type=Service Keywords=syncthing;sync; X-KDE-ParentApp= -X-KDE-PluginInfo-Author=Martchus -X-KDE-PluginInfo-Email=martchus@gmx.net -X-KDE-PluginInfo-License=GPLv2 -X-KDE-PluginInfo-Name=martchus.syncthingplasmoid -X-KDE-PluginInfo-Version=0.1 -X-KDE-PluginInfo-Website=https://github.com/martchus/syncthingtray +X-KDE-PluginInfo-Author=@META_APP_AUTHOR@ +X-KDE-PluginInfo-Email=@META_APP_AUTHOR_MAIL@ +X-KDE-PluginInfo-License=@META_PROJECT_LICENSE@ +X-KDE-PluginInfo-Name=@META_ID@ +X-KDE-PluginInfo-Version=@META_VERSION_MAJOR@.@META_VERSION_MINOR@.@META_VERSION_PATCH@ +X-KDE-PluginInfo-Website=@META_APP_URL@ X-KDE-ServiceTypes=Plasma/Applet X-Plasma-NotificationArea=true X-Plasma-API=declarativeappletscript @@ -18,4 +18,4 @@ X-Plasma-MainScript=ui/main.qml X-Plasma-RemoteLocation= X-KDE-PluginInfo-EnabledByDefault=true X-KDE-PluginInfo-Category=System Information -X-KDE-Library=syncthingplasmoid +X-KDE-Library=@META_TARGET_NAME@ diff --git a/plasmoid/lib/CMakeLists.txt b/plasmoid/lib/CMakeLists.txt index ad4d09c..9fa0e8e 100644 --- a/plasmoid/lib/CMakeLists.txt +++ b/plasmoid/lib/CMakeLists.txt @@ -2,34 +2,11 @@ set(HEADER_FILES syncthingapplet.h settingsdialog.h) set(SRC_FILES syncthingapplet.cpp settingsdialog.cpp) set(WIDGETS_UI_FILES appearanceoptionpage.ui) -set(PLASMOID_FILES - ../package/metadata.desktop - ../package/contents/ui/CompactRepresentation.qml - ../package/contents/ui/FullRepresentation.qml - ../package/contents/ui/DirectoriesPage.qml - ../package/contents/ui/DevicesPage.qml - ../package/contents/ui/DownloadsPage.qml - ../package/contents/ui/RecentChangesPage.qml - ../package/contents/ui/TopLevelView.qml - ../package/contents/ui/TopLevelItem.qml - ../package/contents/ui/DetailView.qml - ../package/contents/ui/DetailItem.qml - ../package/contents/ui/ToolTipTrigger.qml - ../package/contents/ui/ToolTipView.qml - ../package/contents/ui/TinyButton.qml - ../package/contents/ui/TinyButtonStyle.qml - ../package/contents/ui/ButtonShadow.qml - ../package/contents/ui/IconLabel.qml - ../package/contents/ui/StatisticsView.qml - ../package/contents/ui/main.qml) -list(APPEND QML_SRC_FILES ${PLASMOID_FILES}) - +foreach (PLASMOID_FILE ${PLASMOID_FILES}) + list(APPEND QML_SRC_FILES "../${PLASMOID_FILE}") +endforeach () set(TS_FILES ../translations/${META_PROJECT_NAME}_de_DE.ts ../translations/${META_PROJECT_NAME}_en_US.ts) -# find c++utilities -find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED) -list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS}) - # find qtutilities find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX} 6.0.0 REQUIRED) use_qt_utilities() @@ -62,5 +39,10 @@ include(WindowsResources) include(LibraryTarget) include(ConfigHeader) +# export some variable for further use in the overall plasmoid build script +set(META_TARGET_NAME "${META_TARGET_NAME}" PARENT_SCOPE) +set(META_ID "martchus.${META_TARGET_NAME}" PARENT_SCOPE) +set(META_PROJECT_LICENSE "${META_PROJECT_LICENSE}" PARENT_SCOPE) + # what ever this does, it is done -kcoreaddons_desktop_to_json("${META_PROJECT_NAME}" ../package/metadata.desktop) +kcoreaddons_desktop_to_json("${META_TARGET_NAME}" "${PLASMOID_CONFIG_TARGET_FILE}" DESKTOP_TO_JSON_OUTPUT_DIR "${PLASMOID_PACKAGE_DIR}") diff --git a/plasmoid/package/.gitignore b/plasmoid/package/.gitignore new file mode 100644 index 0000000..078e450 --- /dev/null +++ b/plasmoid/package/.gitignore @@ -0,0 +1,2 @@ +# the generated desktop file is required by inittesting.sh +metadata.desktop diff --git a/plasmoid/scripts/inittesting.sh b/plasmoid/scripts/inittesting.sh index 75feabe..d4f4535 100755 --- a/plasmoid/scripts/inittesting.sh +++ b/plasmoid/scripts/inittesting.sh @@ -1,4 +1,17 @@ -#!/bin/sh +#!/bin/bash +set -e + +# use the package dir within the source-tree so one does not need to run CMake again for updating +# build-tree copy all the time +package_dir=$(dirname $0)/../package + +# copy the generated desktop file back into the source-tree package dir so it can actually be used +meta_data_file=$1 +cp --target-directory="$package_dir" "$meta_data_file" + +# install or update the package into the working directory export HOME="$PWD" -plasmapkg2 --install $(dirname $0)/../package || plasmapkg2 --upgrade $(dirname $0)/../package +if ! plasmapkg2 --install "$package_dir"; then + plasmapkg2 --upgrade "$package_dir" +fi exit $? diff --git a/testhelper/CMakeLists.txt b/testhelper/CMakeLists.txt index 8d388a3..c4a5a7b 100644 --- a/testhelper/CMakeLists.txt +++ b/testhelper/CMakeLists.txt @@ -20,6 +20,9 @@ set(TEST_SRC_FILES tests/manualtesting.cpp) set(TS_FILES) +# don't allow adding a target suffix to the test library +set(SYNCTHINGTESTHELPER_CONFIGURATION_TARGET_SUFFIX none) + # find c++utilities find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED) use_cpp_utilities()