diff --git a/CMakeLists.txt b/CMakeLists.txt
index a4052f0..6482168 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
)
diff --git a/src/extension/favorite/favorite-context-menu.cpp b/src/extension/favorite/favorite-context-menu.cpp
new file mode 100644
index 0000000..3a08bc7
--- /dev/null
+++ b/src/extension/favorite/favorite-context-menu.cpp
@@ -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 .
+ *
+ */
+
+#include "favorite-context-menu.h"
+#include "app-data-manager.h"
+#include "event-track.h"
+
+namespace UkuiMenu {
+
+int FavoriteContextMenu::index() const
+{
+ return 512;
+}
+
+QList
+FavoriteContextMenu::actions(const DataEntity &data, QMenu *parent, const MenuInfo::Location &location,
+ const QString &locationId)
+{
+ if (!parent) {
+ return {};
+ }
+
+ if (data.type() != DataType::Normal) {
+ return {};
+ }
+
+ QList 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
diff --git a/src/extension/favorite/favorite-context-menu.h b/src/extension/favorite/favorite-context-menu.h
new file mode 100644
index 0000000..7ae19fa
--- /dev/null
+++ b/src/extension/favorite/favorite-context-menu.h
@@ -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 .
+ *
+ */
+
+#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 actions(const DataEntity &data, QMenu *parent,
+ const MenuInfo::Location &location,
+ const QString &locationId) override;
+};
+
+} // UkuiMenu
+
+#endif //UKUI_MENU_FAVORITE_CONTEXT_MENU_H
diff --git a/src/extension/favorite/favorite-extension-plugin.cpp b/src/extension/favorite/favorite-extension-plugin.cpp
new file mode 100644
index 0000000..2c97083
--- /dev/null
+++ b/src/extension/favorite/favorite-extension-plugin.cpp
@@ -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 .
+ *
+ */
+
+#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
diff --git a/src/extension/favorite/favorite-extension-plugin.h b/src/extension/favorite/favorite-extension-plugin.h
new file mode 100644
index 0000000..2328f9c
--- /dev/null
+++ b/src/extension/favorite/favorite-extension-plugin.h
@@ -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 .
+ *
+ */
+
+#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
diff --git a/src/extension/favorite/favorite-widget.cpp b/src/extension/favorite/favorite-widget.cpp
new file mode 100644
index 0000000..98509e4
--- /dev/null
+++ b/src/extension/favorite/favorite-widget.cpp
@@ -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 .
+ *
+ */
+
+#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
diff --git a/src/extension/favorite/favorite-widget.h b/src/extension/favorite/favorite-widget.h
new file mode 100644
index 0000000..c5ff8ab
--- /dev/null
+++ b/src/extension/favorite/favorite-widget.h
@@ -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 .
+ *
+ */
+
+#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
diff --git a/src/extension/menu-extension-loader.cpp b/src/extension/menu-extension-loader.cpp
index 7b355b4..b8f01d7 100644
--- a/src/extension/menu-extension-loader.cpp
+++ b/src/extension/menu-extension-loader.cpp
@@ -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
#include
@@ -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();
});
}