feat: 修改收藏夹插件实现方式
This commit is contained in:
parent
c7fc015f27
commit
4e5afd2e67
|
@ -126,6 +126,9 @@ set(SOURCE_FILES
|
|||
src/extension/widget-extension-model.cpp src/extension/widget-extension-model.h
|
||||
src/extension/widget-model.cpp src/extension/widget-model.h
|
||||
src/extension/menu/app-menu-plugin.cpp src/extension/menu/app-menu-plugin.h
|
||||
src/extension/favorite/favorite-extension-plugin.cpp src/extension/favorite/favorite-extension-plugin.h
|
||||
src/extension/favorite/favorite-context-menu.cpp src/extension/favorite/favorite-context-menu.h
|
||||
src/extension/favorite/favorite-widget.cpp src/extension/favorite/favorite-widget.h
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2023, 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 "favorite-context-menu.h"
|
||||
#include "app-data-manager.h"
|
||||
#include "event-track.h"
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
int FavoriteContextMenu::index() const
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
|
||||
QList<QAction *>
|
||||
FavoriteContextMenu::actions(const DataEntity &data, QMenu *parent, const MenuInfo::Location &location,
|
||||
const QString &locationId)
|
||||
{
|
||||
if (!parent) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (data.type() != DataType::Normal) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QList<QAction *> list;
|
||||
|
||||
switch (location) {
|
||||
case MenuInfo::AppList:
|
||||
case MenuInfo::FolderPage:
|
||||
case MenuInfo::Extension: {
|
||||
if (data.favorite() == 0) {
|
||||
list << new QAction(QObject::tr("Fix to favorite"), parent);
|
||||
QObject::connect(list.last(), &QAction::triggered, parent, [data] {
|
||||
Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(data.id(), 1);
|
||||
EventTrack::instance()->sendDefaultEvent("fix_to_favorite", "Right-click Menu");
|
||||
});
|
||||
} else if (locationId == "favorite") {
|
||||
list << new QAction(QObject::tr("Remove from favorite"), parent);
|
||||
QObject::connect(list.last(), &QAction::triggered, parent, [data] {
|
||||
Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(data.id(), 0);
|
||||
EventTrack::instance()->sendDefaultEvent("remove_from_favorite", "Right-click Menu");
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MenuInfo::FullScreen:
|
||||
case MenuInfo::FullScreenFolder:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
} // UkuiMenu
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2023, 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_FAVORITE_CONTEXT_MENU_H
|
||||
#define UKUI_MENU_FAVORITE_CONTEXT_MENU_H
|
||||
|
||||
#include "../context-menu-extension.h"
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
class FavoriteContextMenu : public ContextMenuExtension
|
||||
{
|
||||
public:
|
||||
int index() const override;
|
||||
QList<QAction *> actions(const DataEntity &data, QMenu *parent,
|
||||
const MenuInfo::Location &location,
|
||||
const QString &locationId) override;
|
||||
};
|
||||
|
||||
} // UkuiMenu
|
||||
|
||||
#endif //UKUI_MENU_FAVORITE_CONTEXT_MENU_H
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2023, 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 "favorite-extension-plugin.h"
|
||||
#include "favorite-widget.h"
|
||||
#include "favorite-context-menu.h"
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
QString FavoriteExtensionPlugin::id()
|
||||
{
|
||||
return "favorite";
|
||||
}
|
||||
|
||||
WidgetExtension *FavoriteExtensionPlugin::createWidgetExtension()
|
||||
{
|
||||
return new FavoriteWidget;
|
||||
}
|
||||
|
||||
ContextMenuExtension *FavoriteExtensionPlugin::createContextMenuExtension()
|
||||
{
|
||||
return new FavoriteContextMenu;
|
||||
}
|
||||
|
||||
} // UkuiMenu
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2023, 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_FAVORITE_EXTENSION_PLUGIN_H
|
||||
#define UKUI_MENU_FAVORITE_EXTENSION_PLUGIN_H
|
||||
|
||||
#include "../menu-extension-plugin.h"
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
class FavoriteExtensionPlugin : public MenuExtensionPlugin
|
||||
{
|
||||
public:
|
||||
QString id() override;
|
||||
WidgetExtension *createWidgetExtension() override;
|
||||
ContextMenuExtension *createContextMenuExtension() override;
|
||||
};
|
||||
|
||||
} // UkuiMenu
|
||||
|
||||
#endif //UKUI_MENU_FAVORITE_EXTENSION_PLUGIN_H
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2023, 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 "favorite-widget.h"
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
FavoriteWidget::FavoriteWidget(QObject *parent) : WidgetExtension(parent)
|
||||
{
|
||||
m_metadata.insert(WidgetMetadata::Id, "favorite");
|
||||
m_metadata.insert(WidgetMetadata::Icon, "");
|
||||
m_metadata.insert(WidgetMetadata::Name, tr("Favorite"));
|
||||
m_metadata.insert(WidgetMetadata::Tooltip, tr("favorite"));
|
||||
m_metadata.insert(WidgetMetadata::Version, "1.0.0");
|
||||
m_metadata.insert(WidgetMetadata::Description, "favorite");
|
||||
m_metadata.insert(WidgetMetadata::Main, "qrc:///qml/extensions/FavoriteExtension.qml");
|
||||
m_metadata.insert(WidgetMetadata::Type, WidgetMetadata::Widget);
|
||||
m_metadata.insert(WidgetMetadata::Flag, WidgetMetadata::Normal);
|
||||
}
|
||||
|
||||
int FavoriteWidget::index() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MetadataMap FavoriteWidget::metadata() const
|
||||
{
|
||||
return m_metadata;
|
||||
}
|
||||
|
||||
QVariantMap FavoriteWidget::data()
|
||||
{
|
||||
return WidgetExtension::data();
|
||||
}
|
||||
|
||||
void FavoriteWidget::receive(const QVariantMap &data)
|
||||
{
|
||||
WidgetExtension::receive(data);
|
||||
}
|
||||
|
||||
} // UkuiMenu
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2023, 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_FAVORITE_WIDGET_H
|
||||
#define UKUI_MENU_FAVORITE_WIDGET_H
|
||||
|
||||
#include "../widget-extension.h"
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
class FavoriteWidget : public WidgetExtension
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FavoriteWidget(QObject *parent = nullptr);
|
||||
|
||||
int index() const override;
|
||||
MetadataMap metadata() const override;
|
||||
QVariantMap data() override;
|
||||
void receive(const QVariantMap &data) override;
|
||||
|
||||
private:
|
||||
MetadataMap m_metadata;
|
||||
};
|
||||
|
||||
} // UkuiMenu
|
||||
|
||||
#endif //UKUI_MENU_FAVORITE_WIDGET_H
|
|
@ -19,6 +19,9 @@
|
|||
#include "menu-extension-loader.h"
|
||||
#include "menu-extension-plugin.h"
|
||||
|
||||
#include "menu/app-menu-plugin.h"
|
||||
#include "favorite/favorite-extension-plugin.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QPluginLoader>
|
||||
|
||||
|
@ -48,7 +51,8 @@ void MenuExtensionLoader::load()
|
|||
|
||||
void MenuExtensionLoader::loadInternalExtension()
|
||||
{
|
||||
|
||||
registerExtension(new FavoriteExtensionPlugin);
|
||||
registerExtension(new AppMenuPlugin);
|
||||
}
|
||||
|
||||
void MenuExtensionLoader::loadExtensionFromDisk()
|
||||
|
@ -100,10 +104,20 @@ void MenuExtensionLoader::expand()
|
|||
}
|
||||
|
||||
std::sort(m_widgets.begin(), m_widgets.end(), [] (const WidgetExtension *a, const WidgetExtension *b) {
|
||||
if (a->index() < 0) {
|
||||
return false;
|
||||
} else if (b->index() < 0) {
|
||||
return true;
|
||||
}
|
||||
return a->index() <= b->index();
|
||||
});
|
||||
|
||||
std::sort(m_menus.begin(), m_menus.end(), [] (const ContextMenuExtension *a, const ContextMenuExtension *b) {
|
||||
if (a->index() < 0) {
|
||||
return false;
|
||||
} else if (b->index() < 0) {
|
||||
return true;
|
||||
}
|
||||
return a->index() <= b->index();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue