From 53340d9340bc2539e2fc131d2289eac737648e08 Mon Sep 17 00:00:00 2001 From: YeShanShan Date: Thu, 19 Oct 2023 20:02:45 +0800 Subject: [PATCH] feat: add dde-shell's plugin dde-shell loads org.deepin.ds.launchpad. Issue: https://github.com/linuxdeepin/developer-center/issues/5810 --- .reuse/dep5 | 4 ++ CMakeLists.txt | 4 +- dde-shell-wrapper/main.cpp | 90 +++++++++++++++++++++++++ dde-shell-wrapper/package/main.qml | 9 +++ dde-shell-wrapper/package/metadata.json | 8 +++ dde-shell-wrapper/src.cmake | 36 ++++++++++ 6 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 dde-shell-wrapper/main.cpp create mode 100644 dde-shell-wrapper/package/main.qml create mode 100644 dde-shell-wrapper/package/metadata.json create mode 100644 dde-shell-wrapper/src.cmake diff --git a/.reuse/dep5 b/.reuse/dep5 index 47588b3a..3d4ea4da 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -44,3 +44,7 @@ Copyright: 2010, Marco Martin 2019, David Edmundson License: LGPL-2.0-or-later +# package metadata +Files: */metadata.json +Copyright: None +License: CC0-1.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index c5292e26..c9ab0d84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ add_subdirectory(src/ddeintegration) add_subdirectory(src/models) set(SOURCE_FILES - main.cpp desktopintegration.cpp desktopintegration.h launchercontroller.cpp launchercontroller.h debughelper.cpp debughelper.h @@ -83,6 +82,7 @@ qt_add_dbus_adaptor(DBUS_ADAPTER_FILES dbus/org.deepin.dde.Launcher1.xml launche qtquick_compiler_add_resources(RESOURCES qml.qrc) add_executable(${BIN_NAME} + main.cpp ${SOURCE_FILES} ${DBUS_ADAPTER_FILES} ${RESOURCES} @@ -114,3 +114,5 @@ install( FILES dist/org.deepin.dde.launchpad.appdata.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo" ) + +include(dde-shell-wrapper/src.cmake) diff --git a/dde-shell-wrapper/main.cpp b/dde-shell-wrapper/main.cpp new file mode 100644 index 00000000..182d700f --- /dev/null +++ b/dde-shell-wrapper/main.cpp @@ -0,0 +1,90 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "appsmodel.h" +#include "desktopintegration.h" +#include "favoritedproxymodel.h" +#include "searchfilterproxymodel.h" +#include "categorizedsortproxymodel.h" +#include "multipageproxymodel.h" +#include "launchercontroller.h" +#include "debughelper.h" + +#include "corona.h" +#include "qmlengine.h" +#include "pluginfactory.h" +DS_USE_NAMESPACE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DCORE_USE_NAMESPACE +DGUI_USE_NAMESPACE + +// we should wait for dtkgui to have a "proper" loadTranslation() to use. +QStringList translationDir() { + QList translateDirs; + QString appName{"dde-launchpad"}; + //("/home/user/.local/share", "/usr/local/share", "/usr/share") + const QStringList dataDirs(DStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)); + for (const auto &path : dataDirs) { + DPathBuf DPathBuf(path); + translateDirs << (DPathBuf / appName / "translations").toString(); + } + return translateDirs; +} + +class LanchpadCorona : public DCorona +{ + Q_OBJECT +public: + LanchpadCorona(QObject *parent) + : DCorona(parent) + { + } + virtual void init() override + { + DGuiApplicationHelper::loadTranslator(QStringLiteral("dde-launchpad"), translationDir(), { QLocale() }); + + QDBusConnection connection = QDBusConnection::sessionBus(); + if (!connection.registerService(QStringLiteral("org.deepin.dde.Launcher1")) || + !connection.registerObject(QStringLiteral("/org/deepin/dde/Launcher1"), &LauncherController::instance())) { + qWarning() << "register dbus service failed"; + } + + qmlRegisterType("org.deepin.vendored", 1, 0, "KSortFilterProxyModel"); + qmlRegisterUncreatableType("org.deepin.launchpad", 1, 0, "AppItem", "AppItem should only be created from C++ side"); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "AppsModel", &AppsModel::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "FavoritedProxyModel", &FavoritedProxyModel::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "SearchFilterProxyModel", &SearchFilterProxyModel::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "CategorizedSortProxyModel", &CategorizedSortProxyModel::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "MultipageProxyModel", &MultipageProxyModel::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "DesktopIntegration", &DesktopIntegration::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "LauncherController", &LauncherController::instance()); + qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "DebugHelper", &DebugHelper::instance()); + + CategorizedSortProxyModel::instance().setCategoryType(CategorizedSortProxyModel::Alphabetary); + + auto &engine = *DQmlEngine().engine(); + + engine.addImageProvider(QLatin1String("app-icon"), new LauncherAppIconProvider); + engine.addImageProvider(QLatin1String("blurhash"), new BlurhashImageProvider); + + DCorona::init(); + } +}; + +D_APPLET_CLASS(LanchpadCorona) + +#include "main.moc" diff --git a/dde-shell-wrapper/package/main.qml b/dde-shell-wrapper/package/main.qml new file mode 100644 index 00000000..d5f3c5d4 --- /dev/null +++ b/dde-shell-wrapper/package/main.qml @@ -0,0 +1,9 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +import "qrc:/qml" as Impl + +Impl.Main { + +} \ No newline at end of file diff --git a/dde-shell-wrapper/package/metadata.json b/dde-shell-wrapper/package/metadata.json new file mode 100644 index 00000000..2d952069 --- /dev/null +++ b/dde-shell-wrapper/package/metadata.json @@ -0,0 +1,8 @@ +{ + "Plugin": { + "Version": "1.0", + "Id": "org.deepin.ds.launchpad", + "Url": "main.qml", + "ContainmentType": "Panel" + } +} diff --git a/dde-shell-wrapper/src.cmake b/dde-shell-wrapper/src.cmake new file mode 100644 index 00000000..0ad20f45 --- /dev/null +++ b/dde-shell-wrapper/src.cmake @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: CC0-1.0 + +find_package(DDEShell) +if (DDEShell_FOUND) + + add_library(ds-launchpad-wrapper SHARED + ${CMAKE_CURRENT_LIST_DIR}/main.cpp + ${SOURCE_FILES} + ${DBUS_ADAPTER_FILES} + ${RESOURCES} + ${TRANSLATED_FILES} + ) + target_compile_definitions(ds-launchpad-wrapper + PRIVATE + DDE_LAUNCHPAD_VERSION=${CMAKE_PROJECT_VERSION} + ) + target_link_libraries(ds-launchpad-wrapper PRIVATE + DDEShell + + Dtk::Core + Dtk::Gui + Qt${QT_MAJOR_VERSION}::Qml + Qt${QT_MAJOR_VERSION}::Quick + Qt${QT_MAJOR_VERSION}::QuickControls2 + + gio-utils + launcher-utils + launcher-qml-utils + launcher-models + dde-integration-dbus + ) + ds_install_package(PACKAGE org.deepin.ds.launchpad TARGET ds-launchpad-wrapper PACKAGE_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/package) + +endif() \ No newline at end of file