From 3022070ce18bdd417abb77c77abe96aab54a18c1 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Sun, 9 Apr 2023 11:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=9C=80=E8=BF=91=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E5=8D=95=E7=8B=AC=E5=AD=90=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 25 +++--- extension/recent-file/CMakeLists.txt | 49 ++++++++++++ extension/recent-file/metadata.json | 4 + .../recent-file/qml}/RecentFileExtension.qml | 0 extension/recent-file/qml/qml.qrc | 5 ++ .../recent-file}/recent-file-extension.cpp | 12 ++- .../recent-file}/recent-file-extension.h | 6 +- .../recent-file-extension_zh_CN.ts | 27 +++++++ qml/extensions/FolderExtension.qml | 76 ------------------- qml/qml.qrc | 4 - src/extension/extensions/folder-extension.cpp | 69 ----------------- src/extension/extensions/folder-extension.h | 44 ----------- src/extension/menu-extension-iface.h | 8 +- src/extension/menu-extension.cpp | 40 ++++++++-- src/extension/menu-extension.h | 1 + 15 files changed, 159 insertions(+), 211 deletions(-) create mode 100644 extension/recent-file/CMakeLists.txt create mode 100644 extension/recent-file/metadata.json rename {qml/extensions => extension/recent-file/qml}/RecentFileExtension.qml (100%) create mode 100644 extension/recent-file/qml/qml.qrc rename {src/extension/extensions => extension/recent-file}/recent-file-extension.cpp (97%) rename {src/extension/extensions => extension/recent-file}/recent-file-extension.h (93%) create mode 100644 extension/recent-file/translations/recent-file-extension_zh_CN.ts delete mode 100644 qml/extensions/FolderExtension.qml delete mode 100644 src/extension/extensions/folder-extension.cpp delete mode 100644 src/extension/extensions/folder-extension.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e6bfa9..1e82d4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ find_package(PkgConfig REQUIRED) set(UKUI_MENU_EXTERNAL_LIBS "") # glib-2.0 gio-unix-2.0 gsettings-qt x11 kysdk-waylandhelper -set(UKUI_MENU_PC_PKGS glib-2.0 gio-unix-2.0 gsettings-qt x11 kysdk-waylandhelper ukui-search) +set(UKUI_MENU_PC_PKGS glib-2.0 gsettings-qt x11 kysdk-waylandhelper ukui-search) foreach(external_lib IN ITEMS ${UKUI_MENU_PC_PKGS}) pkg_check_modules(${external_lib} REQUIRED ${external_lib}) @@ -59,14 +59,17 @@ include_directories(src/utils) # 用于Qt Creator识别自定义qml模块的导入路径 list(APPEND QML_MODULE_DIRS "${PROJECT_SOURCE_DIR}/qml") set(QML_IMPORT_PATH "${QML_MODULE_DIRS}" CACHE STRING "Qt Creator extra qml import paths." FORCE) -message(STATUS "QML_IMPORT_PATH: ${QML_IMPORT_PATH}") +#message(STATUS "QML_IMPORT_PATH: ${QML_IMPORT_PATH}") # 基础设置 set(UKUI_MENU_DATA_DIR "/usr/share/ukui-menu") set(UKUI_MENU_TRANSLATION_DIR "${UKUI_MENU_DATA_DIR}/translations") set(UKUI_MENU_EXTENSION_DIR "${UKUI_MENU_DATA_DIR}/extensions") set(UKUI_MENU_GLOBAL_CONFIG_FILE "${UKUI_MENU_DATA_DIR}/ukui-menu-global-config.conf") -#set(UKUI_MENU_EXTENSION_IFACE_QML_DIR "/usr/lib/x86_64-linux-gnu/qt5/qml/org/ukui/menu/extension") +set(UKUI_MENU_LIBRARY_NAME "ukui-menu-extension") + +# 子项目 +add_subdirectory(extension/recent-file) # 宏定义 add_compile_definitions(UKUI_MENU_TRANSLATION_DIR="${UKUI_MENU_TRANSLATION_DIR}" @@ -99,10 +102,7 @@ set(SOURCE_FILES src/appdata/plugin/app-search-plugin.cpp src/appdata/plugin/app-search-plugin.h src/appdata/plugin/app-category-plugin.cpp src/appdata/plugin/app-category-plugin.h src/appdata/plugin/app-letter-sort-plugin.cpp src/appdata/plugin/app-letter-sort-plugin.h - src/extension/menu-extension-iface.h src/extension/menu-extension.cpp src/extension/menu-extension.h - src/extension/extensions/folder-extension.cpp src/extension/extensions/folder-extension.h - src/extension/extensions/recent-file-extension.cpp src/extension/extensions/recent-file-extension.h src/extension/extensions/favorite-extension.cpp src/extension/extensions/favorite-extension.h src/utils/app-page-header-utils.cpp src/utils/app-page-header-utils.h src/utils/power-button.cpp src/utils/power-button.h @@ -111,6 +111,9 @@ set(SOURCE_FILES src/items/theme-icon.h src/items/theme-icon.cpp ) +# library sources +set(LIBRARY_SOURCES src/extension/menu-extension-iface.h) + # qrc文件 set(QRC_FILES qml/qml.qrc res/res.qrc) # desktop file @@ -120,8 +123,6 @@ set(GLOBAL_CONFIG_FILE data/ukui-menu-global-config.conf) set(DBUS_SERVICE_FILE data/org.ukui.menu.service) # data files #set(DATA_FILES data/xxx) -# extension -#file(GLOB EXTENSION_IFACE_QML_FILES "qml/org/ukui/menu/extension/*") # 翻译文件 file(GLOB TS_FILES "${PROJECT_SOURCE_DIR}/translations/*.ts") @@ -131,6 +132,10 @@ qt5_create_translation(QM_FILES ${PROJECT_SOURCE_DIR} ${TS_FILES}) # add_custom_target(GEN_TS ALL DEPENDS ${TS_FILES}) # add_custom_target(generate_qm ALL DEPENDS ${QM_FILES}) +add_library(${UKUI_MENU_LIBRARY_NAME} SHARED ${LIBRARY_SOURCES}) +SET_TARGET_PROPERTIES(${UKUI_MENU_LIBRARY_NAME} PROPERTIES VERSION 1.0.0 SOVERSION 0) +target_link_libraries(${UKUI_MENU_LIBRARY_NAME} PRIVATE Qt5::Core) + add_executable( ${PROJECT_NAME} ${QRC_FILES} @@ -151,10 +156,12 @@ target_link_libraries(${PROJECT_NAME} Qt5Xdg ${SingleApplication} ${UKUI_MENU_EXTERNAL_LIBS} + ${UKUI_MENU_LIBRARY_NAME} ) # 安装ukui-menu install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "/usr/bin") +install(TARGETS ${UKUI_MENU_LIBRARY_NAME} LIBRARY DESTINATION "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}") # 安装翻译文件 install(FILES ${QM_FILES} DESTINATION "${UKUI_MENU_TRANSLATION_DIR}") # 安装desktop文件 @@ -162,4 +169,4 @@ install(FILES ${DESKTOP_FILE} DESTINATION "/etc/xdg/autostart") install(FILES ${GSETTING_FILE} DESTINATION "/usr/share/glib-2.0/schemas") install(FILES ${GLOBAL_CONFIG_FILE} DESTINATION "${UKUI_MENU_DATA_DIR}") install(FILES ${DBUS_SERVICE_FILE} DESTINATION "/usr/share/dbus-1/services/") -#install(FILES ${EXTENSION_IFACE_QML_FILES} DESTINATION "${UKUI_MENU_EXTENSION_IFACE_QML_DIR}") +install(DIRECTORY "qml/org" DESTINATION "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/qt5/qml") diff --git a/extension/recent-file/CMakeLists.txt b/extension/recent-file/CMakeLists.txt new file mode 100644 index 0000000..6742391 --- /dev/null +++ b/extension/recent-file/CMakeLists.txt @@ -0,0 +1,49 @@ +project(recent-file-extension LANGUAGES CXX) + +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +find_package(Qt5 COMPONENTS + Core Gui Widgets Quick LinguistTools DBus + REQUIRED) + +include_directories(../../src/extension) +set(SOURCE recent-file-extension.cpp recent-file-extension.h) + +find_package(PkgConfig REQUIRED) +set(EXTERNAL_LIBS "") +set(PC_PKGS glib-2.0 gio-unix-2.0) + +foreach(lib IN ITEMS ${PC_PKGS}) + pkg_check_modules(${lib} REQUIRED ${lib}) + if(${${lib}_FOUND}) + include_directories(${${lib}_INCLUDE_DIRS}) + link_directories(${${lib}_LIBRARY_DIRS}) + list(APPEND EXTERNAL_LIBS ${${lib}_LIBRARIES}) + endif() +endforeach() + +set(QRC_FILES qml/qml.qrc) +# 翻译文件 +file(GLOB TS_FILES "translations/*.ts") +# 更新翻译并创建.qm文件 +qt5_create_translation(QM_FILES ${PROJECT_SOURCE_DIR} ${TS_FILES}) + +set(RECENT_FILE_TRANSLATION_DIR "${UKUI_MENU_EXTENSION_DIR}/${PROJECT_NAME}") +add_compile_definitions(RECENT_FILE_TRANSLATION_DIR="${RECENT_FILE_TRANSLATION_DIR}") + +add_library(${PROJECT_NAME} SHARED ${SOURCE} ${QM_FILES} ${QRC_FILES}) +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Quick Qt5::DBus + ${EXTERNAL_LIBS} + ${UKUI_MENU_LIBRARY_NAME} +) + +install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION "${UKUI_MENU_EXTENSION_DIR}") +install(FILES ${QM_FILES} DESTINATION "${RECENT_FILE_TRANSLATION_DIR}") diff --git a/extension/recent-file/metadata.json b/extension/recent-file/metadata.json new file mode 100644 index 0000000..9079b7e --- /dev/null +++ b/extension/recent-file/metadata.json @@ -0,0 +1,4 @@ +{ + "Type": "UKUI_MENU_EXTENSION", + "Version": "1.0.0" +} diff --git a/qml/extensions/RecentFileExtension.qml b/extension/recent-file/qml/RecentFileExtension.qml similarity index 100% rename from qml/extensions/RecentFileExtension.qml rename to extension/recent-file/qml/RecentFileExtension.qml diff --git a/extension/recent-file/qml/qml.qrc b/extension/recent-file/qml/qml.qrc new file mode 100644 index 0000000..b2a10ac --- /dev/null +++ b/extension/recent-file/qml/qml.qrc @@ -0,0 +1,5 @@ + + + RecentFileExtension.qml + + diff --git a/src/extension/extensions/recent-file-extension.cpp b/extension/recent-file/recent-file-extension.cpp similarity index 97% rename from src/extension/extensions/recent-file-extension.cpp rename to extension/recent-file/recent-file-extension.cpp index 48d5563..280a60d 100644 --- a/src/extension/extensions/recent-file-extension.cpp +++ b/extension/recent-file/recent-file-extension.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include "recent-file-extension.h" @@ -219,6 +222,13 @@ GVFSRecentFileData::parseRecentFiles(GFileEnumerator *enumerator, GAsyncResult * // RecentFileExtension RecentFileExtension::RecentFileExtension(QObject *parent) : MenuExtensionIFace(parent) { + QString translationFile(QString(RECENT_FILE_TRANSLATION_DIR) + "/recent-file-extension_" + QLocale::system().name() + ".qm"); + if (QFile::exists(translationFile)) { + QTranslator *translator = new QTranslator(this); + translator->load(translationFile); + QCoreApplication::installTranslator(translator); + } + qRegisterMetaType("RecentFilesModel*"); qRegisterMetaType >("QVector"); @@ -279,7 +289,7 @@ QString RecentFileExtension::name() QUrl RecentFileExtension::url() { - return {"qrc:///qml/extensions/RecentFileExtension.qml"}; + return {"qrc:///extensions/RecentFileExtension.qml"}; } QVariantMap RecentFileExtension::data() diff --git a/src/extension/extensions/recent-file-extension.h b/extension/recent-file/recent-file-extension.h similarity index 93% rename from src/extension/extensions/recent-file-extension.h rename to extension/recent-file/recent-file-extension.h index d8d6152..e3d4eba 100644 --- a/src/extension/extensions/recent-file-extension.h +++ b/extension/recent-file/recent-file-extension.h @@ -23,7 +23,7 @@ #include #include -#include "../menu-extension-iface.h" +#include "menu-extension-iface.h" namespace UkuiMenu { @@ -86,9 +86,11 @@ Q_SIGNALS: class RecentFileExtension : public MenuExtensionIFace { Q_OBJECT + Q_PLUGIN_METADATA(IID UKUI_MENU_EXTENSION_IFACE_IID FILE "metadata.json") + Q_INTERFACES(UkuiMenu::MenuExtensionIFace) public: explicit RecentFileExtension(QObject *parent = nullptr); - ~RecentFileExtension(); + ~RecentFileExtension() override; int index() override; QString name() override; QUrl url() override; diff --git a/extension/recent-file/translations/recent-file-extension_zh_CN.ts b/extension/recent-file/translations/recent-file-extension_zh_CN.ts new file mode 100644 index 0000000..e17d0fe --- /dev/null +++ b/extension/recent-file/translations/recent-file-extension_zh_CN.ts @@ -0,0 +1,27 @@ + + + + + UkuiMenu::RecentFileExtension + + Recent Files + + + + Open + + + + Remove from list + + + + Clear list + + + + Open the directory where the file is located + + + + diff --git a/qml/extensions/FolderExtension.qml b/qml/extensions/FolderExtension.qml deleted file mode 100644 index 1958f7b..0000000 --- a/qml/extensions/FolderExtension.qml +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2022, KylinSoft Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -import QtQuick 2.0 -import org.ukui.menu.extension 1.0 - -UkuiMenuExtension { - onExtensionDataChanged: { - folderView.model = extensionData.folders - } - - Component.onCompleted: { - folderView.model = extensionData.folders - } - - Rectangle { - anchors.fill: parent; - color: "green" - - ListView { - id: folderView - anchors.fill: parent - delegate: Item { - width: ListView.view.width - height: 150 - - Column { - anchors.fill: parent - Row { - width: parent.width; - height: 50 - Text { - width: 100 - height: parent.height - text: "index: " + index - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - } - - Text { - width: 200 - height: parent.height - text: "name: " + modelData.name - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - } - } - - Text { - width: parent.width; - height: 100 - text: "name: " + modelData.apps - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignLeft - wrapMode: Text.WordWrap - } - } - } - } - } -} diff --git a/qml/qml.qrc b/qml/qml.qrc index 2c19037..5210279 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -2,8 +2,6 @@ main.qml MenuMainWindow.qml - org/ukui/menu/extension/qmldir - org/ukui/menu/extension/UkuiMenuExtension.qml AppUI/qmldir AppUI/NormalUI.qml AppUI/FullScreenUI.qml @@ -25,8 +23,6 @@ AppControls2/AppItem.qml AppControls2/LabelItem.qml AppControls2/FolderItem.qml - extensions/FolderExtension.qml - extensions/RecentFileExtension.qml extensions/FavoriteExtension.qml AppControls2/RoundButton.qml AppControls2/FolderIcon.qml diff --git a/src/extension/extensions/folder-extension.cpp b/src/extension/extensions/folder-extension.cpp deleted file mode 100644 index f4a48e5..0000000 --- a/src/extension/extensions/folder-extension.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2022, KylinSoft Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "folder-extension.h" -#include "app-folder-helper.h" - -#include - -namespace UkuiMenu { - -FolderExtension::FolderExtension(QObject *parent) : MenuExtensionIFace(parent) -{ - qRegisterMetaType("Folder"); - m_data.insert("name", "old name: hxf"); - - QVariantList folders; - for (const auto &item: AppFolderHelper::instance()->folderData()) { - folders.append(QVariant::fromValue(item)); - } - - m_data.insert("folders", folders); -} - -int FolderExtension::index() -{ - return 2; -} - -QString FolderExtension::name() -{ - return "Folder"; -} - -QUrl FolderExtension::url() -{ - return {"qrc:///qml/extensions/FolderExtension.qml"}; -} - -QVariantMap FolderExtension::data() -{ - return m_data; -} - -void FolderExtension::receive(QVariantMap data) -{ - for (const auto &item: data) { - qDebug() << "receive item:" << item.toString(); - } - - m_data.insert("name", "new name: hxf"); - Q_EMIT dataUpdated(); -} - -} // UkuiMenu diff --git a/src/extension/extensions/folder-extension.h b/src/extension/extensions/folder-extension.h deleted file mode 100644 index 7a54ee2..0000000 --- a/src/extension/extensions/folder-extension.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2022, KylinSoft Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef UKUI_MENU_FOLDER_EXTENSION_H -#define UKUI_MENU_FOLDER_EXTENSION_H - -#include "../menu-extension-iface.h" - -namespace UkuiMenu { - -class FolderExtension : public MenuExtensionIFace -{ - Q_OBJECT -public: - explicit FolderExtension(QObject *parent = nullptr); - - int index() override; - QString name() override; - QUrl url() override; - QVariantMap data() override; - void receive(QVariantMap data) override; - -private: - QVariantMap m_data; -}; - -} // UkuiMenu - -#endif //UKUI_MENU_FOLDER_EXTENSION_H diff --git a/src/extension/menu-extension-iface.h b/src/extension/menu-extension-iface.h index 3df7903..9ea2fbb 100644 --- a/src/extension/menu-extension-iface.h +++ b/src/extension/menu-extension-iface.h @@ -19,15 +19,19 @@ #ifndef UKUI_MENU_MENU_EXTENSION_I_FACE_H #define UKUI_MENU_MENU_EXTENSION_I_FACE_H +#define UKUI_MENU_EXTENSION_TYPE "UKUI_MENU_EXTENSION" +#define UKUI_MENU_EXTENSION_IFACE_IID "org.ukui.menu.extension" +#define UKUI_MENU_EXTENSION_IFACE_VERSION "1.0.0" #include #include #include #include +#include namespace UkuiMenu { -class MenuExtensionIFace : public QObject +class Q_DECL_EXPORT MenuExtensionIFace : public QObject { Q_OBJECT public: @@ -44,4 +48,6 @@ Q_SIGNALS: } +Q_DECLARE_INTERFACE(UkuiMenu::MenuExtensionIFace, UKUI_MENU_EXTENSION_IFACE_IID) + #endif //UKUI_MENU_MENU_EXTENSION_I_FACE_H diff --git a/src/extension/menu-extension.cpp b/src/extension/menu-extension.cpp index 6453b42..e915f66 100644 --- a/src/extension/menu-extension.cpp +++ b/src/extension/menu-extension.cpp @@ -17,11 +17,11 @@ */ #include "menu-extension.h" -#include "extensions/folder-extension.h" -#include "extensions/recent-file-extension.h" #include "extensions/favorite-extension.h" #include +#include +#include #include namespace UkuiMenu { @@ -37,10 +37,8 @@ MenuExtension::MenuExtension() qRegisterMetaType("ExtensionModel*"); // TODO load extension from filesystem. - + loadExtensions(); // register extension. -// registerExtension(new FolderExtension(this)); - registerExtension(new RecentFileExtension(this)); registerExtension(new FavoriteExtension(this)); initModel(); @@ -85,6 +83,38 @@ void MenuExtension::initModel() } } +void MenuExtension::loadExtensions() +{ + QDir pluginsDir(UKUI_MENU_EXTENSION_DIR); + pluginsDir.setFilter(QDir::Files); + for(const QString& fileName : pluginsDir.entryList(QDir::Files)) { + QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); + QJsonObject metaData = pluginLoader.metaData().value("MetaData").toObject(); + QString type = metaData.value("Type").toString(); + QString version = metaData.value("Version").toString(); + if(type != UKUI_MENU_EXTENSION_TYPE) { + continue; + } + + if(version != UKUI_MENU_EXTENSION_IFACE_VERSION) { + qWarning() << "UKUI_MENU_EXTENSION version check failed:" << fileName << "version:" << version << "iface version : " << UKUI_MENU_EXTENSION_IFACE_VERSION; + continue; + } + + QObject *obj = pluginLoader.instance(); + if (!obj) { + continue; + } + + MenuExtensionIFace *plugin = qobject_cast(obj); + if (!plugin) { + continue; + } + + registerExtension(plugin); + } +} + ExtensionModel::ExtensionModel(const QVector &extensions, QObject *parent) : QAbstractListModel(parent), m_extensions(extensions) { diff --git a/src/extension/menu-extension.h b/src/extension/menu-extension.h index 4e2c779..fb7e882 100644 --- a/src/extension/menu-extension.h +++ b/src/extension/menu-extension.h @@ -42,6 +42,7 @@ public: private: MenuExtension(); + void loadExtensions(); void initModel(); private: