Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plugin framework structure and example #1

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

set(DS_VERSION "1.0.0" CACHE STRING "Define project version")
project(DDEShell
VERSION "${DS_VERSION}"
DESCRIPTION "dde-shell"
HOMEPAGE_URL "https://github.com/linuxdeepin/dde-shell"
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 17)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
endif ()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(DS_BUILD_WITH_QT6 ON CACHE BOOL "Build dde-shell with Qt6")

if (DS_BUILD_WITH_QT6)
set(QT_VERSION_MAJOR 6)
set(DTK_VERSION_MAJOR 6)
else()
set(QT_VERSION_MAJOR 5)
set(DTK_VERSION_MAJOR "")
endif()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Library install path")
set(DDE_SHELL_PACKAGE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/dde-shell CACHE STRING "Package install path")
set(DDE_SHELL_PLUGIN_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/dde-shell CACHE STRING "Plugin install path")
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/dde-shell" CACHE STRING "Headers install path")
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/DDEShell" CACHE STRING "CMake config file install directory")
set(QML_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/qml" CACHE STRING "Qml plugin install directory")

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(DDEShellPackageMacros)

find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Concurrent Quick)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)

add_subdirectory(frame)
add_subdirectory(shell)
add_subdirectory(example)

configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/misc/DDEShellConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/DDEShellConfig.cmake"
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DDEShellConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)
# Install cmake config file
install(FILES "${PROJECT_SOURCE_DIR}/cmake/DDEShellPackageMacros.cmake" DESTINATION "${CONFIG_INSTALL_DIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DDEShellConfig.cmake" DESTINATION "${CONFIG_INSTALL_DIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DDEShellConfigVersion.cmake" DESTINATION "${CONFIG_INSTALL_DIR}")
156 changes: 156 additions & 0 deletions LICENSES/CC-BY-4.0.txt

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions cmake/DDEShellPackageMacros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include(CMakeParseArguments)

macro(ds_build_package)
set(oneValueArgs PACKAGE TARGET PACKAGE_ROOT_DIR)
cmake_parse_arguments(_config "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(package_root_dir ${CMAKE_CURRENT_SOURCE_DIR}/package)
if (DEFINED _config_PACKAGE_ROOT_DIR)
set(package_root_dir ${_config_PACKAGE_ROOT_DIR})
endif()
file(GLOB_RECURSE package_files ${package_root_dir}/*)
add_custom_target(${_config_PACKAGE}_package ALL
SOURCES ${package_files}
)
set(package_dirs ${PROJECT_BINARY_DIR}/packages/${_config_PACKAGE}/)
add_custom_command(TARGET ${_config_PACKAGE}_package
COMMAND ${CMAKE_COMMAND} -E copy_directory ${package_root_dir} ${package_dirs}
)

if (DEFINED _config_TARGET)
set_target_properties(${_config_TARGET} PROPERTIES
PREFIX ""
OUTPUT_NAME ${_config_PACKAGE}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/plugins/
)
endif()
endmacro()

function(ds_install_package)
ds_build_package(${ARGN})
install(DIRECTORY ${package_dirs} DESTINATION ${DDE_SHELL_PACKAGE_INSTALL_DIR}/${_config_PACKAGE})

if (DEFINED _config_TARGET)
install(TARGETS ${_config_TARGET} DESTINATION ${DDE_SHELL_PLUGIN_INSTALL_DIR}/)
endif()
endfunction()
43 changes: 43 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Source: dde-shell
Section: unknown
Priority: optional
Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends:
debhelper-compat ( =12),
cmake,
qt6-base-dev,
qt6-declarative-dev,
qt6-base-dev-tools,
qt6-tools-dev,
libdtk6gui-dev,
libdtk6core-dev,
libdtkcommon-dev,
Standards-Version: 3.9.8
Homepage: http://www.deepin.org

Package: libdde-shell
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends},
libdtkcore5
Multi-Arch: same
Description: DDE Shell library
DDE Shell is a plugin system that integrates plugins developed based on this plugin system into DDE.

Package: libdde-shell-dev
Architecture: any
Depends: ${misc:Depends}, libdde-shell( =${binary:Version})
Description: DDE Shell devel library
DDE Shell is a plugin system that integrates plugins developed based on this plugin system into DDE.

Package: dde-shell
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libdde-shell( =${binary:Version})
Multi-Arch: same
Description: An wrapper for developed based on dde-shell plugin system

Package: dde-shell-example
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libdde-shell( =${binary:Version})
Multi-Arch: same
Description: DDE Shell example
This package contains some plugins based on dde-shell plugin system.
2 changes: 2 additions & 0 deletions debian/dde-shell-example.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/lib/*/*dde-shell/*
usr/share/dde-shell/*
1 change: 1 addition & 0 deletions debian/dde-shell.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/bin/*
3 changes: 3 additions & 0 deletions debian/libdde-shell-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
usr/lib/*/lib*.so
usr/include
usr/lib/*/cmake/*/*.cmake
2 changes: 2 additions & 0 deletions debian/libdde-shell.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/lib/*/lib*.so.*
usr/lib/*/qt6/qml/org/deepin/ds/*
16 changes: 16 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/make -f
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

VERSION = $(DEB_VERSION_UPSTREAM)
PACK_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$1}')
# Fix: invalid digit "8" in octal constant. e.g. u008 ==> 008 ==> 8
BUILD_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$2}' | sed 's/[^0-9]//g' | awk '{print int($$1)}')

%:
dh $@

override_dh_auto_configure:
dh_auto_configure -- -DDS_VERSION=${PACK_VER}
10 changes: 10 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Quick)

add_subdirectory(applet-example)
add_subdirectory(applet-example-data)
add_subdirectory(containment-example)
add_subdirectory(corona-example)
14 changes: 14 additions & 0 deletions example/applet-example-data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

add_library(ds-example-applet-data SHARED
exampleapplet.h
exampleapplet.cpp
)

target_link_libraries(ds-example-applet-data PRIVATE
dde-shell-frame
)

ds_install_package(PACKAGE org.deepin.ds.applet-example-data TARGET ds-example-applet-data)
23 changes: 23 additions & 0 deletions example/applet-example-data/exampleapplet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "exampleapplet.h"

18202781743 marked this conversation as resolved.
Show resolved Hide resolved
#include "pluginfactory.h"

ExampleApplet::ExampleApplet(QObject *parent)
: DApplet(parent)
, m_mainText("Custom Applet")
{

}

QString ExampleApplet::mainText() const

Check warning on line 16 in example/applet-example-data/exampleapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'mainText' is never used.
{
return m_mainText;
}

D_APPLET_CLASS(ExampleApplet)

#include "exampleapplet.moc"
21 changes: 21 additions & 0 deletions example/applet-example-data/exampleapplet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "applet.h"

DS_USE_NAMESPACE

class Q_DECL_EXPORT ExampleApplet : public DApplet
{
Q_OBJECT
Q_PROPERTY(QString mainText READ mainText CONSTANT)
public:
ExampleApplet(QObject *parent = nullptr);

QString mainText() const;
private:
QString m_mainText;
};
22 changes: 22 additions & 0 deletions example/applet-example-data/package/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.11
import QtQuick.Controls 2.15

import org.deepin.ds 1.0

AppletItem {
objectName: "appplet data"
implicitWidth: 200
implicitHeight: 100
Rectangle {
anchors.fill: parent
color: "gray"
Text {
anchors.centerIn: parent
text: Applet.mainText
}
}
}
8 changes: 8 additions & 0 deletions example/applet-example-data/package/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Plugin": {
"Version": "1.0",
"Id": "org.deepin.ds.applet-example-data",
"Url": "main.qml",
"Parent": "org.deepin.ds.containment-example"
}
}
5 changes: 5 additions & 0 deletions example/applet-example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

ds_install_package(PACKAGE org.deepin.ds.applet-example)
10 changes: 10 additions & 0 deletions example/applet-example/package/control/TextEx.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.11
import QtQuick.Controls 2.4

Text {
color: "cyan"
}
23 changes: 23 additions & 0 deletions example/applet-example/package/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.11
import QtQuick.Controls 2.4

import org.deepin.ds 1.0
import "control"

AppletItem {
objectName: "appplet item"
implicitWidth: 100
implicitHeight: 100
Rectangle {
anchors.fill: parent
color: "green"
TextEx {
anchors.centerIn: parent
text: "Hello world"
}
}
}
8 changes: 8 additions & 0 deletions example/applet-example/package/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Plugin": {
"Version": "1.0",
"Id": "org.deepin.ds.applet-example",
"Url": "main.qml",
"Parent": "org.deepin.ds.containment-example"
}
}
5 changes: 5 additions & 0 deletions example/containment-example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

ds_install_package(PACKAGE org.deepin.ds.containment-example)
22 changes: 22 additions & 0 deletions example/containment-example/package/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.15
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11

import org.deepin.ds 1.0

ContainmentItem {
id: root
objectName: "containment item"
RowLayout {
Repeater {
model: Applet.appletItems
delegate: Control {
contentItem: modelData
}
}
}
}
9 changes: 9 additions & 0 deletions example/containment-example/package/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Plugin": {
"Version": "1.0",
"Id": "org.deepin.ds.containment-example",
"Url": "main.qml",
"Parent": "org.deepin.ds.corona-example",
"ContainmentType": "Containment"
}
}
14 changes: 14 additions & 0 deletions example/corona-example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

add_library(ds-corona-example SHARED
examplecorona.cpp
examplecorona.h
)

target_link_libraries(ds-corona-example PRIVATE
dde-shell-frame
)

ds_install_package(PACKAGE org.deepin.ds.corona-example TARGET ds-corona-example)
Loading