实现简易的文件夹数据扩展插件

This commit is contained in:
hewenfei 2023-01-03 11:04:06 +08:00
parent 29a0046b44
commit 33e05ce03a
6 changed files with 193 additions and 0 deletions

View File

@ -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

View File

@ -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 <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
}
}
}
}
}
}

View File

@ -14,5 +14,6 @@
<file>AppControls2/StyleBackground.qml</file>
<file>AppControls2/StyleText.qml</file>
<file>AppControls2/IconLabel.qml</file>
<file>extensions/FolderExtension.qml</file>
</qresource>
</RCC>

View File

@ -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 <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 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

View File

@ -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 <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

View File

@ -17,6 +17,7 @@
*/
#include "menu-extension.h"
#include "extensions/folder-extension.h"
#include <utility>
#include <QDebug>
@ -36,6 +37,7 @@ MenuExtension::MenuExtension()
// TODO load extension from filesystem.
// register extension.
registerExtension(new FolderExtension(this));
initModel();
}