将最近文件作为单独子项目管理
This commit is contained in:
parent
386bb7700b
commit
3022070ce1
|
@ -28,7 +28,7 @@ find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
set(UKUI_MENU_EXTERNAL_LIBS "")
|
set(UKUI_MENU_EXTERNAL_LIBS "")
|
||||||
# glib-2.0 gio-unix-2.0 gsettings-qt x11 kysdk-waylandhelper
|
# 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})
|
foreach(external_lib IN ITEMS ${UKUI_MENU_PC_PKGS})
|
||||||
pkg_check_modules(${external_lib} REQUIRED ${external_lib})
|
pkg_check_modules(${external_lib} REQUIRED ${external_lib})
|
||||||
|
@ -59,14 +59,17 @@ include_directories(src/utils)
|
||||||
# 用于Qt Creator识别自定义qml模块的导入路径
|
# 用于Qt Creator识别自定义qml模块的导入路径
|
||||||
list(APPEND QML_MODULE_DIRS "${PROJECT_SOURCE_DIR}/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)
|
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_DATA_DIR "/usr/share/ukui-menu")
|
||||||
set(UKUI_MENU_TRANSLATION_DIR "${UKUI_MENU_DATA_DIR}/translations")
|
set(UKUI_MENU_TRANSLATION_DIR "${UKUI_MENU_DATA_DIR}/translations")
|
||||||
set(UKUI_MENU_EXTENSION_DIR "${UKUI_MENU_DATA_DIR}/extensions")
|
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_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}"
|
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-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-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/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/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/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/app-page-header-utils.cpp src/utils/app-page-header-utils.h
|
||||||
src/utils/power-button.cpp src/utils/power-button.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
|
src/items/theme-icon.h src/items/theme-icon.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# library sources
|
||||||
|
set(LIBRARY_SOURCES src/extension/menu-extension-iface.h)
|
||||||
|
|
||||||
# qrc文件
|
# qrc文件
|
||||||
set(QRC_FILES qml/qml.qrc res/res.qrc)
|
set(QRC_FILES qml/qml.qrc res/res.qrc)
|
||||||
# desktop file
|
# 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)
|
set(DBUS_SERVICE_FILE data/org.ukui.menu.service)
|
||||||
# data files
|
# data files
|
||||||
#set(DATA_FILES data/xxx)
|
#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")
|
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(GEN_TS ALL DEPENDS ${TS_FILES})
|
||||||
# add_custom_target(generate_qm ALL DEPENDS ${QM_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(
|
add_executable(
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
${QRC_FILES}
|
${QRC_FILES}
|
||||||
|
@ -151,10 +156,12 @@ target_link_libraries(${PROJECT_NAME}
|
||||||
Qt5Xdg
|
Qt5Xdg
|
||||||
${SingleApplication}
|
${SingleApplication}
|
||||||
${UKUI_MENU_EXTERNAL_LIBS}
|
${UKUI_MENU_EXTERNAL_LIBS}
|
||||||
|
${UKUI_MENU_LIBRARY_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
# 安装ukui-menu
|
# 安装ukui-menu
|
||||||
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "/usr/bin")
|
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}")
|
install(FILES ${QM_FILES} DESTINATION "${UKUI_MENU_TRANSLATION_DIR}")
|
||||||
# 安装desktop文件
|
# 安装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 ${GSETTING_FILE} DESTINATION "/usr/share/glib-2.0/schemas")
|
||||||
install(FILES ${GLOBAL_CONFIG_FILE} DESTINATION "${UKUI_MENU_DATA_DIR}")
|
install(FILES ${GLOBAL_CONFIG_FILE} DESTINATION "${UKUI_MENU_DATA_DIR}")
|
||||||
install(FILES ${DBUS_SERVICE_FILE} DESTINATION "/usr/share/dbus-1/services/")
|
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")
|
||||||
|
|
|
@ -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}")
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"Type": "UKUI_MENU_EXTENSION",
|
||||||
|
"Version": "1.0.0"
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/extensions">
|
||||||
|
<file>RecentFileExtension.qml</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
|
@ -24,6 +24,9 @@
|
||||||
#include <gio/gdesktopappinfo.h>
|
#include <gio/gdesktopappinfo.h>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QTranslator>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include "recent-file-extension.h"
|
#include "recent-file-extension.h"
|
||||||
|
|
||||||
|
@ -219,6 +222,13 @@ GVFSRecentFileData::parseRecentFiles(GFileEnumerator *enumerator, GAsyncResult *
|
||||||
// RecentFileExtension
|
// RecentFileExtension
|
||||||
RecentFileExtension::RecentFileExtension(QObject *parent) : MenuExtensionIFace(parent)
|
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<UkuiMenu::RecentFilesModel*>("RecentFilesModel*");
|
qRegisterMetaType<UkuiMenu::RecentFilesModel*>("RecentFilesModel*");
|
||||||
qRegisterMetaType<QVector<RecentFile> >("QVector<RecentFile>");
|
qRegisterMetaType<QVector<RecentFile> >("QVector<RecentFile>");
|
||||||
|
|
||||||
|
@ -279,7 +289,7 @@ QString RecentFileExtension::name()
|
||||||
|
|
||||||
QUrl RecentFileExtension::url()
|
QUrl RecentFileExtension::url()
|
||||||
{
|
{
|
||||||
return {"qrc:///qml/extensions/RecentFileExtension.qml"};
|
return {"qrc:///extensions/RecentFileExtension.qml"};
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap RecentFileExtension::data()
|
QVariantMap RecentFileExtension::data()
|
|
@ -23,7 +23,7 @@
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#include "../menu-extension-iface.h"
|
#include "menu-extension-iface.h"
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
|
||||||
|
@ -86,9 +86,11 @@ Q_SIGNALS:
|
||||||
class RecentFileExtension : public MenuExtensionIFace
|
class RecentFileExtension : public MenuExtensionIFace
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PLUGIN_METADATA(IID UKUI_MENU_EXTENSION_IFACE_IID FILE "metadata.json")
|
||||||
|
Q_INTERFACES(UkuiMenu::MenuExtensionIFace)
|
||||||
public:
|
public:
|
||||||
explicit RecentFileExtension(QObject *parent = nullptr);
|
explicit RecentFileExtension(QObject *parent = nullptr);
|
||||||
~RecentFileExtension();
|
~RecentFileExtension() override;
|
||||||
int index() override;
|
int index() override;
|
||||||
QString name() override;
|
QString name() override;
|
||||||
QUrl url() override;
|
QUrl url() override;
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="zh_CN">
|
||||||
|
<context>
|
||||||
|
<name>UkuiMenu::RecentFileExtension</name>
|
||||||
|
<message>
|
||||||
|
<source>Recent Files</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Open</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Remove from list</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Clear list</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Open the directory where the file is located</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,8 +2,6 @@
|
||||||
<qresource prefix="/qml">
|
<qresource prefix="/qml">
|
||||||
<file>main.qml</file>
|
<file>main.qml</file>
|
||||||
<file>MenuMainWindow.qml</file>
|
<file>MenuMainWindow.qml</file>
|
||||||
<file>org/ukui/menu/extension/qmldir</file>
|
|
||||||
<file>org/ukui/menu/extension/UkuiMenuExtension.qml</file>
|
|
||||||
<file>AppUI/qmldir</file>
|
<file>AppUI/qmldir</file>
|
||||||
<file>AppUI/NormalUI.qml</file>
|
<file>AppUI/NormalUI.qml</file>
|
||||||
<file>AppUI/FullScreenUI.qml</file>
|
<file>AppUI/FullScreenUI.qml</file>
|
||||||
|
@ -25,8 +23,6 @@
|
||||||
<file>AppControls2/AppItem.qml</file>
|
<file>AppControls2/AppItem.qml</file>
|
||||||
<file>AppControls2/LabelItem.qml</file>
|
<file>AppControls2/LabelItem.qml</file>
|
||||||
<file>AppControls2/FolderItem.qml</file>
|
<file>AppControls2/FolderItem.qml</file>
|
||||||
<file>extensions/FolderExtension.qml</file>
|
|
||||||
<file>extensions/RecentFileExtension.qml</file>
|
|
||||||
<file>extensions/FavoriteExtension.qml</file>
|
<file>extensions/FavoriteExtension.qml</file>
|
||||||
<file>AppControls2/RoundButton.qml</file>
|
<file>AppControls2/RoundButton.qml</file>
|
||||||
<file>AppControls2/FolderIcon.qml</file>
|
<file>AppControls2/FolderIcon.qml</file>
|
||||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "folder-extension.h"
|
|
||||||
#include "app-folder-helper.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
namespace UkuiMenu {
|
|
||||||
|
|
||||||
FolderExtension::FolderExtension(QObject *parent) : MenuExtensionIFace(parent)
|
|
||||||
{
|
|
||||||
qRegisterMetaType<UkuiMenu::Folder>("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
|
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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
|
|
|
@ -19,15 +19,19 @@
|
||||||
#ifndef UKUI_MENU_MENU_EXTENSION_I_FACE_H
|
#ifndef UKUI_MENU_MENU_EXTENSION_I_FACE_H
|
||||||
#define 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 <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QtPlugin>
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
|
||||||
class MenuExtensionIFace : public QObject
|
class Q_DECL_EXPORT MenuExtensionIFace : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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
|
#endif //UKUI_MENU_MENU_EXTENSION_I_FACE_H
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "menu-extension.h"
|
#include "menu-extension.h"
|
||||||
#include "extensions/folder-extension.h"
|
|
||||||
#include "extensions/recent-file-extension.h"
|
|
||||||
#include "extensions/favorite-extension.h"
|
#include "extensions/favorite-extension.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QPluginLoader>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
@ -37,10 +37,8 @@ MenuExtension::MenuExtension()
|
||||||
qRegisterMetaType<ExtensionModel*>("ExtensionModel*");
|
qRegisterMetaType<ExtensionModel*>("ExtensionModel*");
|
||||||
|
|
||||||
// TODO load extension from filesystem.
|
// TODO load extension from filesystem.
|
||||||
|
loadExtensions();
|
||||||
// register extension.
|
// register extension.
|
||||||
// registerExtension(new FolderExtension(this));
|
|
||||||
registerExtension(new RecentFileExtension(this));
|
|
||||||
registerExtension(new FavoriteExtension(this));
|
registerExtension(new FavoriteExtension(this));
|
||||||
|
|
||||||
initModel();
|
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<MenuExtensionIFace*>(obj);
|
||||||
|
if (!plugin) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
registerExtension(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ExtensionModel::ExtensionModel(const QVector<MenuExtensionIFace*> &extensions, QObject *parent)
|
ExtensionModel::ExtensionModel(const QVector<MenuExtensionIFace*> &extensions, QObject *parent)
|
||||||
: QAbstractListModel(parent), m_extensions(extensions)
|
: QAbstractListModel(parent), m_extensions(extensions)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MenuExtension();
|
MenuExtension();
|
||||||
|
void loadExtensions();
|
||||||
void initModel();
|
void initModel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue