From 33e05ce03a3d1b3a89c40391456d5222398b372c Mon Sep 17 00:00:00 2001 From: hewenfei Date: Tue, 3 Jan 2023 11:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=AE=80=E6=98=93=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E6=95=B0=E6=8D=AE=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + qml/extensions/FolderExtension.qml | 76 +++++++++++++++++++ qml/qml.qrc | 1 + src/extension/extensions/folder-extension.cpp | 69 +++++++++++++++++ src/extension/extensions/folder-extension.h | 44 +++++++++++ src/extension/menu-extension.cpp | 2 + 6 files changed, 193 insertions(+) create mode 100644 qml/extensions/FolderExtension.qml create mode 100644 src/extension/extensions/folder-extension.cpp create mode 100644 src/extension/extensions/folder-extension.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 98ed6d4..a29fa18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ set(SOURCE_FILES src/extension/menu-extension.cpp src/extension/menu-extension.h src/extension/menu-extension-iface.h src/appdata/data-provider-plugin-iface.h + src/extension/extensions/folder-extension.cpp src/extension/extensions/folder-extension.h ) # qrc文件 diff --git a/qml/extensions/FolderExtension.qml b/qml/extensions/FolderExtension.qml new file mode 100644 index 0000000..1958f7b --- /dev/null +++ b/qml/extensions/FolderExtension.qml @@ -0,0 +1,76 @@ +/* + * 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 efc3fb5..49f290d 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -14,5 +14,6 @@ AppControls2/StyleBackground.qml AppControls2/StyleText.qml AppControls2/IconLabel.qml + extensions/FolderExtension.qml diff --git a/src/extension/extensions/folder-extension.cpp b/src/extension/extensions/folder-extension.cpp new file mode 100644 index 0000000..f2c34d0 --- /dev/null +++ b/src/extension/extensions/folder-extension.cpp @@ -0,0 +1,69 @@ +/* + * 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 0; +} + +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 new file mode 100644 index 0000000..7a54ee2 --- /dev/null +++ b/src/extension/extensions/folder-extension.h @@ -0,0 +1,44 @@ +/* + * 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.cpp b/src/extension/menu-extension.cpp index a0cc168..25c4ab6 100644 --- a/src/extension/menu-extension.cpp +++ b/src/extension/menu-extension.cpp @@ -17,6 +17,7 @@ */ #include "menu-extension.h" +#include "extensions/folder-extension.h" #include #include @@ -36,6 +37,7 @@ MenuExtension::MenuExtension() // TODO load extension from filesystem. // register extension. + registerExtension(new FolderExtension(this)); initModel(); }