From c7fc015f278533220039163f7b536d0689441071 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Mon, 11 Dec 2023 10:43:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=BA=93so=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=A7=E7=89=88=E6=9C=AC=E8=8F=9C=E5=8D=95=E6=89=A9=E5=B1=95?= =?UTF-8?q?,=E9=87=8D=E6=96=B0=E5=AE=9E=E7=8E=B0=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E8=8F=9C=E5=8D=95=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 34 +- ...fig.cmake.in => ukui-menu-config.cmake.in} | 0 ...i-menu-interface.pc.in => ukui-menu.pc.in} | 0 src/appdata/app-folder-helper.cpp | 239 +++++++------ src/extension/context-menu-manager.cpp | 113 ++++++ .../context-menu-manager.h} | 26 +- src/extension/menu-extension-iface.h | 60 ---- src/extension/menu-extension.cpp | 190 ---------- src/extension/menu-extension.h | 82 ----- src/extension/menu/app-menu-plugin.cpp | 184 ++++++++++ src/extension/menu/app-menu-plugin.h | 37 ++ src/menu/menu-manager.cpp | 325 ------------------ src/menu/menu-provider.h | 62 ---- src/model/app-model.cpp | 4 +- src/model/app-model.h | 2 +- src/ukui-menu-application.cpp | 6 +- src/windows/menu-main-window.cpp | 6 +- 17 files changed, 490 insertions(+), 880 deletions(-) rename cmake/{ukui-menu-interface-config.cmake.in => ukui-menu-config.cmake.in} (100%) rename cmake/{ukui-menu-interface.pc.in => ukui-menu.pc.in} (100%) create mode 100755 src/extension/context-menu-manager.cpp rename src/{menu/menu-manager.h => extension/context-menu-manager.h} (60%) delete mode 100644 src/extension/menu-extension-iface.h delete mode 100644 src/extension/menu-extension.cpp delete mode 100644 src/extension/menu-extension.h create mode 100644 src/extension/menu/app-menu-plugin.cpp create mode 100644 src/extension/menu/app-menu-plugin.h delete mode 100755 src/menu/menu-manager.cpp delete mode 100644 src/menu/menu-provider.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b5368c9..a4052f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,12 +49,12 @@ set(SingleApplication "qtsingleapplication") # include文件夹 include_directories(src) -include_directories(src/menu) include_directories(src/model) include_directories(src/appdata) include_directories(src/settings) include_directories(src/uiconfig) include_directories(src/windows) +include_directories(src/extension) include_directories(src/utils) include_directories(3rd-parties/qtsingleapplication/src) @@ -75,7 +75,8 @@ set(UKUI_MENU_CONTEXT_MENU_DIR "${UKUI_MENU_SO_DIR}/context-menu") set(UKUI_MENU_LIBRARY_VERSION 1.0.0) set(UKUI_MENU_LIBRARY_API_VERSION 1) #set(UKUI_MENU_LIBRARY_NAME "ukui-menu${UKUI_MENU_LIBRARY_API_VERSION}") -set(UKUI_MENU_LIBRARY_NAME "ukui-menu-interface") +set(UKUI_MENU_LIBRARY_NAME "ukui-menu") +set(UKUI_MENU_LIBRARY_TARGET "libukui-menu") set(PC_INSTALL_DIR "/usr/lib/pkgconfig") set(CMAKE_CONFIG_INSTALL_DIR "/usr/share/cmake/${UKUI_MENU_LIBRARY_NAME}") @@ -110,23 +111,21 @@ set(SOURCE_FILES 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-letter-sort-plugin.cpp src/appdata/plugin/app-letter-sort-plugin.h - src/extension/menu-extension.cpp src/extension/menu-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/power-button.cpp src/utils/power-button.h src/utils/app-manager.cpp src/utils/app-manager.h src/utils/event-track.cpp src/utils/event-track.h src/utils/sidebar-button-utils.cpp src/utils/sidebar-button-utils.h - src/menu/menu-provider.h - src/menu/menu-manager.cpp src/menu/menu-manager.h src/items/theme-icon.h src/items/theme-icon.cpp src/settings/user-config.cpp src/settings/user-config.h + src/extension/menu-extension-plugin.cpp src/extension/menu-extension-plugin.h + src/extension/menu-extension-loader.cpp src/extension/menu-extension-loader.h src/extension/widget-extension.cpp src/extension/widget-extension.h src/extension/context-menu-extension.cpp src/extension/context-menu-extension.h - src/extension/menu-extension-loader.cpp src/extension/menu-extension-loader.h - src/extension/menu-extension-plugin.cpp src/extension/menu-extension-plugin.h + src/extension/context-menu-manager.cpp src/extension/context-menu-manager.h 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 ) @@ -139,14 +138,14 @@ endif() # library sources set(LIBRARY_SOURCES src/data-entity.cpp - src/extension/menu-extension-iface.h - ) + src/extension/menu-extension-plugin.cpp + src/extension/widget-extension.cpp + src/extension/context-menu-extension.cpp +) set(LIBRARY_HEADERS_DIR "/usr/include/${UKUI_MENU_LIBRARY_NAME}") set(LIBRARY_HEADERS src/data-entity.h - src/menu/menu-provider.h - src/extension/menu-extension-iface.h src/extension/menu-extension-plugin.h src/extension/widget-extension.h src/extension/context-menu-extension.h @@ -170,12 +169,13 @@ qt5_create_translation(QM_FILES ${PROJECT_SOURCE_DIR} ${TS_FILES}) # add_custom_target(GEN_TS ALL DEPENDS ${TS_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 +add_library(${UKUI_MENU_LIBRARY_TARGET} SHARED ${LIBRARY_SOURCES}) +set_target_properties(${UKUI_MENU_LIBRARY_TARGET} PROPERTIES VERSION ${UKUI_MENU_LIBRARY_VERSION} SOVERSION ${UKUI_MENU_LIBRARY_API_VERSION} + OUTPUT_NAME "ukui-menu" ) -target_link_libraries(${UKUI_MENU_LIBRARY_NAME} PRIVATE Qt5::Core) +target_link_libraries(${UKUI_MENU_LIBRARY_TARGET} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets) add_executable( ${PROJECT_NAME} @@ -198,12 +198,12 @@ target_link_libraries(${PROJECT_NAME} Qt5Xdg ${SingleApplication} ${UKUI_MENU_EXTERNAL_LIBS} - ${UKUI_MENU_LIBRARY_NAME} + ${UKUI_MENU_LIBRARY_TARGET} ) # 安装ukui-menu install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "/usr/bin") -install(TARGETS ${UKUI_MENU_LIBRARY_NAME} +install(TARGETS ${UKUI_MENU_LIBRARY_TARGET} EXPORT ${UKUI_MENU_LIBRARY_NAME} PUBLIC_HEADER DESTINATION ${LIBRARY_HEADERS_DIR} LIBRARY DESTINATION "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}" diff --git a/cmake/ukui-menu-interface-config.cmake.in b/cmake/ukui-menu-config.cmake.in similarity index 100% rename from cmake/ukui-menu-interface-config.cmake.in rename to cmake/ukui-menu-config.cmake.in diff --git a/cmake/ukui-menu-interface.pc.in b/cmake/ukui-menu.pc.in similarity index 100% rename from cmake/ukui-menu-interface.pc.in rename to cmake/ukui-menu.pc.in diff --git a/src/appdata/app-folder-helper.cpp b/src/appdata/app-folder-helper.cpp index 7227600..9d03fa0 100644 --- a/src/appdata/app-folder-helper.cpp +++ b/src/appdata/app-folder-helper.cpp @@ -17,7 +17,7 @@ */ #include "app-folder-helper.h" -#include "menu-manager.h" +#include "context-menu-manager.h" #include "app-data-manager.h" #include "model-manager.h" #include "app-model.h" @@ -36,125 +36,125 @@ namespace UkuiMenu { -class FolderMenuProvider : public MenuProvider -{ -public: - FolderMenuProvider(); - int index() override { return 256; } - bool isSupport(const RequestType &type) override; - QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override; -private: - static void folderMenuForNormal(QObject *parent, const QString &appId, QList &list); - static void dissolveFolder(QObject *parent, const QString &folderId, QList &list); - static void renameFolder(QObject *parent, const QString &folderId, QList &list); -}; +//class FolderMenuProvider : public MenuProvider +//{ +//public: +// FolderMenuProvider(); +// int index() override { return 256; } +// bool isSupport(const RequestType &type) override; +// QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override; +//private: +// static void folderMenuForNormal(QObject *parent, const QString &appId, QList &list); +// static void dissolveFolder(QObject *parent, const QString &folderId, QList &list); +// static void renameFolder(QObject *parent, const QString &folderId, QList &list); +//}; -FolderMenuProvider::FolderMenuProvider() -{ - -} - -bool FolderMenuProvider::isSupport(const MenuProvider::RequestType &type) -{ - return type == DataType; -} - -QList -FolderMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, - const QString &locationId) -{ - if (!parent) { - return {}; - } - - DataEntity app = data.value(); - QList list; - - switch (location) { - case MenuInfo::FullScreen: { - if (app.type() == DataType::Folder) { - dissolveFolder(parent, app.id(), list); - break; - } - } - case MenuInfo::AppList: { - if (app.type() == DataType::Folder) { - renameFolder(parent, app.id(), list); - dissolveFolder(parent, app.id(), list); - break; - } - - if (app.type() != DataType::Normal || locationId != "all") { - break; - } - } - case MenuInfo::FullScreenFolder: - case MenuInfo::FolderPage: { - if (app.type() == DataType::Normal) { - folderMenuForNormal(parent, app.id(), list); - } - break; - } - case MenuInfo::Extension: - default: - break; - } - - return list; -} - -void FolderMenuProvider::folderMenuForNormal(QObject *parent, const QString &appId, QList &list) -{ - Folder folder; - if (AppFolderHelper::instance()->searchFolderByAppName(appId, folder)) { - //从当前文件夹移除 - list << new QAction(QObject::tr("Remove from folder"), parent); - QObject::connect(list.last(), &QAction::triggered, parent, [appId, folder] { - AppFolderHelper::instance()->removeAppFromFolder(appId, folder.getId()); - AppFolderHelper::instance()->forceSync(); - }); - return; - } - - QMenu *menu = static_cast(parent); - //添加到应用组 - QMenu *subMenu = new QMenu(QObject::tr("Add to folder"), menu); - - QAction* newAct = new QAction(QObject::tr("Add to new folder"), subMenu); - QObject::connect(newAct, &QAction::triggered, parent, [appId] { - AppFolderHelper::instance()->addAppToNewFolder(appId, ""); - AppFolderHelper::instance()->forceSync(); - }); - subMenu->addAction(newAct); - - QList folders = AppFolderHelper::instance()->folderData(); - for (const Folder &f : folders) { - QString name = QObject::tr("Add to \"%1\"").arg(f.getName()); - QAction* act = new QAction(name, subMenu); - QObject::connect(act, &QAction::triggered, parent, [appId, f] { - AppFolderHelper::instance()->addAppToFolder(appId, f.getId()); - }); - subMenu->addAction(act); - } - menu->addMenu(subMenu); -} - -void FolderMenuProvider::dissolveFolder(QObject *parent, const QString &folderId, QList &list) -{ - list << new QAction(QObject::tr("Dissolve folder"), parent); - QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { - AppFolderHelper::instance()->deleteFolder(folderId.toInt()); - AppFolderHelper::instance()->forceSync(); - }); -} - -void FolderMenuProvider::renameFolder(QObject *parent, const QString &folderId, QList &list) -{ - list << new QAction(QObject::tr("Rename"), parent); - QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { - ModelManager::instance()->getAppModel()->toRenameFolder(folderId); - }); -} +//FolderMenuProvider::FolderMenuProvider() +//{ +// +//} +// +//bool FolderMenuProvider::isSupport(const MenuProvider::RequestType &type) +//{ +// return type == DataType; +//} +// +//QList +//FolderMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, +// const QString &locationId) +//{ +// if (!parent) { +// return {}; +// } +// +// DataEntity app = data.value(); +// QList list; +// +// switch (location) { +// case MenuInfo::FullScreen: { +// if (app.type() == DataType::Folder) { +// dissolveFolder(parent, app.id(), list); +// break; +// } +// } +// case MenuInfo::AppList: { +// if (app.type() == DataType::Folder) { +// renameFolder(parent, app.id(), list); +// dissolveFolder(parent, app.id(), list); +// break; +// } +// +// if (app.type() != DataType::Normal || locationId != "all") { +// break; +// } +// } +// case MenuInfo::FullScreenFolder: +// case MenuInfo::FolderPage: { +// if (app.type() == DataType::Normal) { +// folderMenuForNormal(parent, app.id(), list); +// } +// break; +// } +// case MenuInfo::Extension: +// default: +// break; +// } +// +// return list; +//} +// +//void FolderMenuProvider::folderMenuForNormal(QObject *parent, const QString &appId, QList &list) +//{ +// Folder folder; +// if (AppFolderHelper::instance()->searchFolderByAppName(appId, folder)) { +// //从当前文件夹移除 +// list << new QAction(QObject::tr("Remove from folder"), parent); +// QObject::connect(list.last(), &QAction::triggered, parent, [appId, folder] { +// AppFolderHelper::instance()->removeAppFromFolder(appId, folder.getId()); +// AppFolderHelper::instance()->forceSync(); +// }); +// return; +// } +// +// QMenu *menu = static_cast(parent); +// //添加到应用组 +// QMenu *subMenu = new QMenu(QObject::tr("Add to folder"), menu); +// +// QAction* newAct = new QAction(QObject::tr("Add to new folder"), subMenu); +// QObject::connect(newAct, &QAction::triggered, parent, [appId] { +// AppFolderHelper::instance()->addAppToNewFolder(appId, ""); +// AppFolderHelper::instance()->forceSync(); +// }); +// subMenu->addAction(newAct); +// +// QList folders = AppFolderHelper::instance()->folderData(); +// for (const Folder &f : folders) { +// QString name = QObject::tr("Add to \"%1\"").arg(f.getName()); +// QAction* act = new QAction(name, subMenu); +// QObject::connect(act, &QAction::triggered, parent, [appId, f] { +// AppFolderHelper::instance()->addAppToFolder(appId, f.getId()); +// }); +// subMenu->addAction(act); +// } +// menu->addMenu(subMenu); +//} +// +//void FolderMenuProvider::dissolveFolder(QObject *parent, const QString &folderId, QList &list) +//{ +// list << new QAction(QObject::tr("Dissolve folder"), parent); +// QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { +// AppFolderHelper::instance()->deleteFolder(folderId.toInt()); +// AppFolderHelper::instance()->forceSync(); +// }); +//} +// +//void FolderMenuProvider::renameFolder(QObject *parent, const QString &folderId, QList &list) +//{ +// list << new QAction(QObject::tr("Rename"), parent); +// QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { +// ModelManager::instance()->getAppModel()->toRenameFolder(folderId); +// }); +//} QString AppFolderHelper::s_folderConfigFile = QDir::homePath() + "/" + FOLDER_FILE_PATH + FOLDER_FILE_NAME; @@ -167,7 +167,6 @@ AppFolderHelper *AppFolderHelper::instance() AppFolderHelper::AppFolderHelper() { qRegisterMetaType("Folder"); - MenuManager::instance()->registerMenuProvider(new FolderMenuProvider); if (!QFile::exists(s_folderConfigFile)) { QDir dir; diff --git a/src/extension/context-menu-manager.cpp b/src/extension/context-menu-manager.cpp new file mode 100755 index 0000000..bb264e2 --- /dev/null +++ b/src/extension/context-menu-manager.cpp @@ -0,0 +1,113 @@ +/* + * 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 "context-menu-manager.h" +#include "app-data-manager.h" +#include "menu-extension-loader.h" + +#include +#include +#include +#include + +using namespace UkuiMenu; + +ContextMenuManager *ContextMenuManager::instance() +{ + static ContextMenuManager manager; + return &manager; +} + +class MenuManagerPrivate +{ +public: + QPointer contextMenu; + QWindow *mainWindow {nullptr}; + QList extensions; +}; + +ContextMenuManager::ContextMenuManager() : d(new MenuManagerPrivate) +{ + d->extensions = MenuExtensionLoader::instance()->menus(); +} + +ContextMenuManager::~ContextMenuManager() +{ + for (auto &provider : d->extensions) { + delete provider; + provider = nullptr; + } +} + +void ContextMenuManager::showMenu(const QString &appid, const MenuInfo::Location location, const QString &lid, const QPoint &point) +{ + DataEntity app; + if (AppDataManager::instance()->getApp(appid, app)) { + showMenu(app, location, lid, point); + } +} + +void ContextMenuManager::showMenu(const DataEntity &data, MenuInfo::Location location, const QString &lid, const QPoint &point) +{ + if (closeMenu()) { + return; + } + + auto menu = new QMenu; + QList actions; + for (const auto &extension : d->extensions) { + actions.append(extension->actions(data, menu, location, lid)); + } + + if (actions.isEmpty() && menu->isEmpty()) { + delete menu; + return; + } + + d->contextMenu = menu; + menu->setAttribute(Qt::WA_DeleteOnClose); + if (menu->winId()) { + menu->windowHandle()->setTransientParent(d->mainWindow); + } + + menu->addActions(actions); + menu->popup(checkPoint(point)); +} + +void ContextMenuManager::setMainWindow(QWindow *mainWindow) +{ + d->mainWindow = mainWindow; +} + +bool ContextMenuManager::closeMenu() +{ + if (d->contextMenu) { + d->contextMenu.data()->close(); + return true; + } + + return false; +} + +inline QPoint ContextMenuManager::checkPoint(const QPoint &rawPoint) +{ + if (rawPoint.isNull()) { + return QCursor::pos(); + } + return rawPoint; +} diff --git a/src/menu/menu-manager.h b/src/extension/context-menu-manager.h similarity index 60% rename from src/menu/menu-manager.h rename to src/extension/context-menu-manager.h index cdf2e58..6159cc4 100644 --- a/src/menu/menu-manager.h +++ b/src/extension/context-menu-manager.h @@ -16,36 +16,34 @@ * */ -#ifndef UKUI_MENU_MENU_MANAGER_H -#define UKUI_MENU_MENU_MANAGER_H +#ifndef UKUI_MENU_CONTEXT_MENU_MANAGER_H +#define UKUI_MENU_CONTEXT_MENU_MANAGER_H #include #include -#include "data-entity.h" -#include "menu-provider.h" +#include "context-menu-extension.h" class QWindow; class MenuManagerPrivate; namespace UkuiMenu { -class MenuManager : public QObject +class ContextMenuManager : public QObject { Q_OBJECT public: - static MenuManager *instance(); - ~MenuManager() override; - void registerMenuProvider(MenuProvider *provider); - Q_INVOKABLE void showMenu(const QString &appid, MenuInfo::Location, const QString& lid = QString(), const QPoint &point = QPoint()); - void showMenu(const DataEntity &entity, MenuInfo::Location location, const QString& lid = QString(), const QPoint &point = QPoint()); - void showMenu(const MenuProvider::RequestType &type, QVariant data, MenuInfo::Location location, const QString& lid = QString(), const QPoint &point = QPoint()); + static ContextMenuManager *instance(); + ~ContextMenuManager() override; + + Q_INVOKABLE void showMenu(const QString &appid, MenuInfo::Location location, const QString& lid = QString(), const QPoint &point = QPoint()); + void showMenu(const DataEntity &data, MenuInfo::Location location, const QString& lid = QString(), const QPoint &point = QPoint()); + void setMainWindow(QWindow *mainWindow); bool closeMenu(); private: - MenuManager(); - void loadMenus(); + ContextMenuManager(); inline QPoint checkPoint(const QPoint &rawPoint); private: @@ -54,4 +52,4 @@ private: } // UkuiMenu -#endif //UKUI_MENU_MENU_MANAGER_H +#endif //UKUI_MENU_CONTEXT_MENU_MANAGER_H diff --git a/src/extension/menu-extension-iface.h b/src/extension/menu-extension-iface.h deleted file mode 100644 index 818df9e..0000000 --- a/src/extension/menu-extension-iface.h +++ /dev/null @@ -1,60 +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 . - * - */ - -#ifndef 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.1" - -#include -#include -#include -#include -#include - -namespace UkuiMenu { - -class Q_DECL_EXPORT MenuExtensionIFace : public QObject -{ - Q_OBJECT -public: - enum Option { - HideBottomBar, - HideFullScreenButton - }; - Q_ENUM(Option) - - explicit MenuExtensionIFace(QObject *parent = nullptr) : QObject(parent) {}; - virtual int index() = 0; - virtual QString name() = 0; - virtual QUrl url() = 0; - virtual QVariantMap data() = 0; - virtual QVariantList options() { return {}; }; - virtual void receive(QVariantMap data) = 0; - -Q_SIGNALS: - void dataUpdated(); -}; - -} - -Q_DECLARE_INTERFACE(UkuiMenu::MenuExtensionIFace, UKUI_MENU_EXTENSION_IFACE_IID) - -#endif //UKUI_MENU_MENU_EXTENSION_I_FACE_H diff --git a/src/extension/menu-extension.cpp b/src/extension/menu-extension.cpp deleted file mode 100644 index 0b5d9cb..0000000 --- a/src/extension/menu-extension.cpp +++ /dev/null @@ -1,190 +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 . - * - */ - -#include "menu-extension.h" -#include "extensions/favorite-extension.h" - -#include -#include -#include -#include -#include - -namespace UkuiMenu { - -MenuExtension *MenuExtension::instance() -{ - static MenuExtension menuExtension; - return &menuExtension; -} - -MenuExtension::MenuExtension() -{ - qRegisterMetaType("ExtensionModel*"); - qmlRegisterUncreatableType("org.ukui.menu.extension", 1, 0, "MenuExtension", ""); - - // TODO load extension from filesystem. - loadExtensions(); - // register extension. - registerExtension(new FavoriteExtension(this)); - - initModel(); -} - -void MenuExtension::registerExtension(MenuExtensionIFace *extension) -{ - if (!extension) { - return; - } - - extension->setParent(this); - if (m_extensions.contains(extension->name())) { - return; - } - - m_extensions.insert(extension->name(), extension); -} - -ExtensionModel *MenuExtension::extensionModel() -{ - return m_model; -} - -void MenuExtension::initModel() -{ - QVector data; - - QMap::const_iterator iterator = m_extensions.constBegin(); - for (; iterator != m_extensions.constEnd(); ++iterator) { - MenuExtensionIFace* extension = iterator.value(); - data.append(extension); - } - - std::sort(data.begin(), data.end(), [](MenuExtensionIFace* a, MenuExtensionIFace* b) { - return a->index() <= b->index(); - }); - - m_model = new ExtensionModel(data, this); - if (!m_model) { - qWarning() << "MenuExtension: unable to init the model of menu-extension."; - } -} - -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(obj); - if (!plugin) { - continue; - } - - registerExtension(plugin); - } -} - -ExtensionModel::ExtensionModel(const QVector &extensions, QObject *parent) - : QAbstractListModel(parent), m_extensions(extensions) -{ - m_roleNames.insert(Name, "name"); - m_roleNames.insert(Url, "url"); - m_roleNames.insert(Data, "data"); - m_roleNames.insert(Options, "options"); - - for (int i = 0; i < m_extensions.size(); ++i) { - connect(m_extensions.at(i), &MenuExtensionIFace::dataUpdated, this, [this, i] { - extensionDataChanged(i); - }); - } -} - -int ExtensionModel::rowCount(const QModelIndex &parent) const -{ - return m_extensions.size(); -} - -QVariant ExtensionModel::data(const QModelIndex &index, int role) const -{ - int row = index.row(); - - if (row < 0 || row >= m_extensions.size()) { - return {}; - } - - switch (role) { - case Name: - return m_extensions.at(row)->name(); - case Url: - return m_extensions.at(row)->url(); - case Data: { - return m_extensions.at(row)->data(); - } - case Options: - return m_extensions.at(row)->options(); - default: - break; - } - - return {}; -} - -QHash ExtensionModel::roleNames() const -{ - return m_roleNames; -} - -void ExtensionModel::send(int index, QVariantMap data) -{ - if (index < 0 || index >= m_extensions.size()) { - return; - } - - m_extensions.at(index)->receive(std::move(data)); -} - -void ExtensionModel::extensionDataChanged(int index) -{ - if (index < 0 || index >= m_extensions.size()) { - return; - } - - QVector roles(1, Data); - QModelIndex modelIndex = createIndex(index, 0); - Q_EMIT dataChanged(modelIndex, modelIndex, roles); -} - -} // UkuiMenu diff --git a/src/extension/menu-extension.h b/src/extension/menu-extension.h deleted file mode 100644 index 4de4a2e..0000000 --- a/src/extension/menu-extension.h +++ /dev/null @@ -1,82 +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 . - * - */ - -#ifndef UKUI_MENU_MENU_EXTENSION_H -#define UKUI_MENU_MENU_EXTENSION_H - -#include -#include -#include -#include -#include -#include - -#include "menu-extension-iface.h" - -namespace UkuiMenu { - -class ExtensionModel; - -class MenuExtension : public QObject -{ - Q_OBJECT -public: - static MenuExtension *instance(); - void registerExtension(MenuExtensionIFace *extension); - Q_INVOKABLE ExtensionModel *extensionModel(); - -private: - MenuExtension(); - void loadExtensions(); - void initModel(); - -private: - ExtensionModel *m_model{nullptr}; - QMap m_extensions; -}; - -class ExtensionModel : public QAbstractListModel -{ - Q_OBJECT -public: - enum Name { - Name, - Url, - Data, - Options - }; - - explicit ExtensionModel(const QVector &extensions, QObject *parent = nullptr); - - int rowCount(const QModelIndex &parent) const override; - QVariant data(const QModelIndex &index, int role) const override; - QHash roleNames() const override; - - Q_INVOKABLE void send(int index, QVariantMap data); - -private: - void extensionDataChanged(int index); - -private: - QHash m_roleNames; - QVector m_extensions; -}; - -} // UkuiMenu - -#endif //UKUI_MENU_MENU_EXTENSION_H diff --git a/src/extension/menu/app-menu-plugin.cpp b/src/extension/menu/app-menu-plugin.cpp new file mode 100644 index 0000000..6cee589 --- /dev/null +++ b/src/extension/menu/app-menu-plugin.cpp @@ -0,0 +1,184 @@ +/* + * 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 "app-menu-plugin.h" +#include "app-data-manager.h" +#include "settings.h" +#include "app-manager.h" +#include "../context-menu-extension.h" + +#include +#include +#include +#include +#include +#include + +namespace UkuiMenu { + +class AppContentMenu : public ContextMenuExtension +{ +public: + int index() const override; + QList actions(const DataEntity &data, QMenu *parent, const MenuInfo::Location &location, + const QString &locationId) override; + +private: + static void addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list); + static void addToPanelAction(QObject *parent, const QString &appId, QList &list); + static void addToDesktopAction(QObject *parent, const QString &appId, QList &list); + static void addUninstall(QObject *parent, const QString &appId, QList &list); +}; + +int AppContentMenu::index() const +{ + return ContextMenuExtension::index(); +} + +QList AppContentMenu::actions(const DataEntity &data, QMenu *parent, const MenuInfo::Location &location, + const QString &locationId) +{ + if (!parent || (data.type() != DataType::Normal)) { + return {}; + } + + QList list; + QString appId = data.id(); + int appTop = data.top(); + + switch (location) { + case MenuInfo::AppList: { + //置顶 + if (locationId == "all") { + addToTop(parent, appId, appTop, list); + } + } + case MenuInfo::Extension: + case MenuInfo::FolderPage: + case MenuInfo::FullScreen: + case MenuInfo::FullScreenFolder: + // 卸载 + addToPanelAction(parent, appId, list); + // 添加到任务栏 + addUninstall(parent, appId, list); + //添加到桌面快捷方式 + addToDesktopAction(parent, appId, list); + break; + default: + break; + } + + return list; +} + +void AppContentMenu::addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list) +{ + QString actionName = (appTop == 0) ? QObject::tr("Fixed to all applications") : QObject::tr("Unfixed from all applications"); + list << new QAction(actionName, parent); + QObject::connect(list.last(), &QAction::triggered, parent, [appId, appTop] { + AppDataManager::instance()->fixToTop(appId, appTop); + }); +} + +void AppContentMenu::addToPanelAction(QObject *parent, const QString &appId, QList &list) +{ + QDBusInterface iface("com.ukui.panel.desktop", "/", "com.ukui.panel.desktop", QDBusConnection::sessionBus()); + + if (!iface.isValid()) { + qWarning() << "Panel desktop dbusinterface error"; + return; + } + + iface.setTimeout(1); + QDBusReply isFixedOnTaskBar = iface.call("CheckIfExist", appId); + + if (!isFixedOnTaskBar.isValid()) { + qWarning() << "Panel desktop dbusinterface call CheckIfExist timeout"; + return; + } + + QString actionName = isFixedOnTaskBar ? QObject::tr("Remove from taskbar") : QObject::tr("Add to taskbar"); + QString functionName = isFixedOnTaskBar ? "RemoveFromTaskbar" : "AddToTaskbar"; + list << new QAction(actionName, parent); + + QObject::connect(list.last(), &QAction::triggered, parent, [appId, functionName] { + QDBusInterface iface("com.ukui.panel.desktop", "/", "com.ukui.panel.desktop", QDBusConnection::sessionBus()); + + if (!iface.isValid()) { + qWarning() << "Panel desktop dbusinterface error"; + return; + } + + iface.setTimeout(1); + QDBusReply ret = iface.call(functionName, appId); + + if (!ret.isValid() || !ret) { + qWarning() << "Add/Remove from taskbar error"; + } + }); +} + +void AppContentMenu::addToDesktopAction(QObject *parent, const QString &appId, QList &list) +{ + list << new QAction(QObject::tr("Add to desktop shortcuts"), parent); + + QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + QString path = QString(desktopPath + "/" + QFileInfo(appId).fileName()); + + if (QFile::exists(path)) { + list.last()->setEnabled(false); + return; + } + + QObject::connect(list.last(), &QAction::triggered, parent, [appId, path] { + QFile file(appId); + bool ret = file.copy(path); + if (ret) { + QProcess::startDetached("chmod a+x ", {path}); + } + }); +} + +void AppContentMenu::addUninstall(QObject *parent, const QString &appId, QList &list) +{ + bool isSystemApp = GlobalSetting::instance()->isSystemApp(appId); + if (!isSystemApp) { + list << new QAction(QObject::tr("Uninstall"), parent); //QIcon::fromTheme("edit-delete-symbolic") + QObject::connect(list.last(), &QAction::triggered, parent, [appId] { + AppManager::instance()->launchBinaryApp("kylin-uninstaller", appId); + }); + } +} + +// ====== AppMenuPlugin ====== // +QString AppMenuPlugin::id() +{ + return QStringLiteral("app-menu"); +} + +WidgetExtension *AppMenuPlugin::createWidgetExtension() +{ + return nullptr; +} + +ContextMenuExtension *AppMenuPlugin::createContextMenuExtension() +{ + return new AppContentMenu; +} + +} // UkuiMenu diff --git a/src/extension/menu/app-menu-plugin.h b/src/extension/menu/app-menu-plugin.h new file mode 100644 index 0000000..211c3a5 --- /dev/null +++ b/src/extension/menu/app-menu-plugin.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_APP_MENU_PLUGIN_H +#define UKUI_MENU_APP_MENU_PLUGIN_H + +#include "../menu-extension-plugin.h" + +namespace UkuiMenu { + +class AppMenuPlugin : public MenuExtensionPlugin +{ + Q_OBJECT +public: + QString id() override; + WidgetExtension *createWidgetExtension() override; + ContextMenuExtension *createContextMenuExtension() override; +}; + +} // UkuiMenu + +#endif //UKUI_MENU_APP_MENU_PLUGIN_H diff --git a/src/menu/menu-manager.cpp b/src/menu/menu-manager.cpp deleted file mode 100755 index 31e6123..0000000 --- a/src/menu/menu-manager.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/* - * 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 "menu-manager.h" -#include "app-manager.h" -#include "app-data-manager.h" -#include "settings.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace UkuiMenu; - -class AppMenuProvider : public MenuProvider -{ -public: - AppMenuProvider(); - int index() override { return 1024; } - bool isSupport(const RequestType &type) override; - QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override; - -private: - void addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list); - void addToPanelAction(QObject *parent, const QString &appId, QList &list); - void addToDesktopAction(QObject *parent, const QString &appId, QList &list); - void addUninstall(QObject *parent, const QString &appId, QList &list); -}; - -AppMenuProvider::AppMenuProvider() -{ - -} - -bool AppMenuProvider::isSupport(const MenuProvider::RequestType &type) -{ - return type == DataType; -} - -QList -AppMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, - const QString &locationId) -{ - if (!parent) { - return {}; - } - - DataEntity app = data.value(); - if (app.type() != DataType::Normal) { - return {}; - } - - QList list; - QString appId = app.id(); - int appTop = app.top(); - - switch (location) { - case MenuInfo::AppList: { - //置顶 - if (locationId == "all") { - addToTop(parent, appId, appTop, list); - } - } - case MenuInfo::Extension: - case MenuInfo::FolderPage: - case MenuInfo::FullScreen: - case MenuInfo::FullScreenFolder: - // 卸载 - addToPanelAction(parent, appId, list); - // 添加到任务栏 - addUninstall(parent, appId, list); - //添加到桌面快捷方式 - addToDesktopAction(parent, appId, list); - break; - default: - break; - } - - return list; -} - -void AppMenuProvider::addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list) -{ - QString actionName = (appTop == 0) ? QObject::tr("Fixed to all applications") : QObject::tr("Unfixed from all applications"); - list << new QAction(actionName, parent); - QObject::connect(list.last(), &QAction::triggered, parent, [appId, appTop] { - AppDataManager::instance()->fixToTop(appId, appTop); - }); -} - -void AppMenuProvider::addToPanelAction(QObject *parent, const QString &appId, QList &list) -{ - QDBusInterface iface("com.ukui.panel.desktop", "/", "com.ukui.panel.desktop", QDBusConnection::sessionBus()); - - if (!iface.isValid()) { - qWarning() << "Panel desktop dbusinterface error"; - return; - } - - iface.setTimeout(1); - QDBusReply isFixedOnTaskBar = iface.call("CheckIfExist", appId); - - if (!isFixedOnTaskBar.isValid()) { - qWarning() << "Panel desktop dbusinterface call CheckIfExist timeout"; - return; - } - - QString actionName = isFixedOnTaskBar ? QObject::tr("Remove from taskbar") : QObject::tr("Add to taskbar"); - QString functionName = isFixedOnTaskBar ? "RemoveFromTaskbar" : "AddToTaskbar"; - list << new QAction(actionName, parent); - - QObject::connect(list.last(), &QAction::triggered, parent, [appId, functionName] { - QDBusInterface iface("com.ukui.panel.desktop", "/", "com.ukui.panel.desktop", QDBusConnection::sessionBus()); - - if (!iface.isValid()) { - qWarning() << "Panel desktop dbusinterface error"; - return; - } - - iface.setTimeout(1); - QDBusReply ret = iface.call(functionName, appId); - - if (!ret.isValid() || !ret) { - qWarning() << "Add/Remove from taskbar error"; - } - }); -} - -void AppMenuProvider::addToDesktopAction(QObject *parent, const QString &appId, QList &list) -{ - list << new QAction(QObject::tr("Add to desktop shortcuts"), parent); - - QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - QString path = QString(desktopPath + "/" + QFileInfo(appId).fileName()); - - if (QFile::exists(path)) { - list.last()->setEnabled(false); - return; - } - - QObject::connect(list.last(), &QAction::triggered, parent, [appId, path] { - QFile file(appId); - bool ret = file.copy(path); - if (ret) { - QProcess::startDetached("chmod a+x " + path); - } - }); -} - -void AppMenuProvider::addUninstall(QObject *parent, const QString &appId, QList &list) -{ - bool isSystemApp = GlobalSetting::instance()->isSystemApp(appId); - if (!isSystemApp) { - list << new QAction(QObject::tr("Uninstall"), parent); //QIcon::fromTheme("edit-delete-symbolic") - QObject::connect(list.last(), &QAction::triggered, parent, [appId] { - AppManager::instance()->launchBinaryApp("kylin-uninstaller", appId); - }); - } -} - -MenuManager *MenuManager::instance() -{ - static MenuManager manager; - return &manager; -} - -class MenuManagerPrivate -{ -public: - QPointer contextMenu; - QWindow *mainWindow {nullptr}; - QList providers; -}; - -MenuManager::MenuManager() : d(new MenuManagerPrivate) -{ - registerMenuProvider(new AppMenuProvider); - loadMenus(); -} - -MenuManager::~MenuManager() -{ - for (auto &provider : d->providers) { - delete provider; - provider = nullptr; - } -} - -void MenuManager::registerMenuProvider(MenuProvider *provider) -{ - if (!provider) { - return; - } - - d->providers.append(provider); - - std::sort(d->providers.begin(), d->providers.end(), [=] (MenuProvider *a, MenuProvider *b) { - return a->index() < b->index(); - }); -} - -void MenuManager::showMenu(const QString &appid, const MenuInfo::Location location, const QString &lid, const QPoint &point) -{ - DataEntity app; - if (AppDataManager::instance()->getApp(appid, app)) { - showMenu(MenuProvider::DataType, QVariant::fromValue(app), location, lid, point); - } -} - -void MenuManager::showMenu(const DataEntity &entity, const MenuInfo::Location location, const QString &lid, - const QPoint &point) -{ - showMenu(MenuProvider::DataType, QVariant::fromValue(entity), location, lid, point); -} - -void MenuManager::showMenu(const MenuProvider::RequestType &type, QVariant data, const MenuInfo::Location location, const QString &lid, const QPoint &point) -{ - if (closeMenu()) { - return; - } - - QMenu *menu = new QMenu; - QList actions; - for (const auto &provider : d->providers) { - if (provider->isSupport(type)) { - actions.append(provider->generateActions(menu, data, location, lid)); - } - } - - if (actions.isEmpty() && menu->isEmpty()) { - delete menu; - return; - } - - d->contextMenu = menu; - menu->setAttribute(Qt::WA_DeleteOnClose); - if (menu->winId()) { - menu->windowHandle()->setTransientParent(d->mainWindow); - } - - menu->addActions(actions); - menu->popup(checkPoint(point)); -} - -void MenuManager::setMainWindow(QWindow *mainWindow) -{ - d->mainWindow = mainWindow; -} - -bool MenuManager::closeMenu() -{ - if (d->contextMenu) { - d->contextMenu.data()->close(); - return true; - } - - return false; -} - -inline QPoint MenuManager::checkPoint(const QPoint &rawPoint) -{ - if (rawPoint.isNull()) { - return QCursor::pos(); - } - return rawPoint; -} - -void MenuManager::loadMenus() -{ - QDir pluginsDir(UKUI_MENU_CONTEXT_MENU_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_CONTEXTMENU_TYPE) { - continue; - } - - if(version != UKUI_MENU_CONTEXTMENU_IFACE_VERSION) { - qWarning() << "UKUI_MENU_CONTEXTMENU version check failed:" << fileName << "version:" << version << "iface version : " << UKUI_MENU_CONTEXTMENU_IFACE_VERSION; - continue; - } - - QObject *obj = pluginLoader.instance(); - if (!obj) { - continue; - } - - MenuProvider *provider = qobject_cast(obj); - if (!provider) { - continue; - } - - registerMenuProvider(provider); - } -} diff --git a/src/menu/menu-provider.h b/src/menu/menu-provider.h deleted file mode 100644 index 45273a9..0000000 --- a/src/menu/menu-provider.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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_MENU_PROVIDER_H -#define UKUI_MENU_MENU_PROVIDER_H - -#include -#include - -#define UKUI_MENU_CONTEXTMENU_TYPE "UKUI_MENU_CONTEXTMENU" -#define UKUI_MENU_CONTEXTMENU_IFACE_IID "org.ukui.menu.contextMenu" -#define UKUI_MENU_CONTEXTMENU_IFACE_VERSION "1.0.0" - -namespace UkuiMenu { - -class MenuInfo -{ - Q_GADGET -public: - enum Location { - AppList = 0, - Extension, - FolderPage, - FullScreen, - FullScreenFolder, - }; - Q_ENUM(Location) -}; - -class MenuProvider -{ -public: - enum RequestType { - DataType = 0, - Custom, - }; - virtual ~MenuProvider() = default; - virtual int index() = 0; - virtual bool isSupport(const RequestType &type) = 0; - virtual QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) = 0; -}; - -} // UkuiMenu - -Q_DECLARE_INTERFACE(UkuiMenu::MenuProvider, UKUI_MENU_CONTEXTMENU_IFACE_IID) - -#endif //UKUI_MENU_MENU_PROVIDER_H diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index 0219e5f..5a98bec 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -18,7 +18,7 @@ #include "app-model.h" #include "app-manager.h" -#include "menu-manager.h" +#include "context-menu-manager.h" #include "app-folder-helper.h" #include "settings.h" @@ -212,7 +212,7 @@ void AppModel::openMenu(const int &index, MenuInfo::Location location) return; } - MenuManager::instance()->showMenu(m_apps.at(index), location, DataProviderManager::instance()->activatedProvider()); + ContextMenuManager::instance()->showMenu(m_apps.at(index), location, DataProviderManager::instance()->activatedProvider()); } void AppModel::renameFolder(const QString &index, const QString &folderName) diff --git a/src/model/app-model.h b/src/model/app-model.h index 25760ce..0faf549 100644 --- a/src/model/app-model.h +++ b/src/model/app-model.h @@ -24,8 +24,8 @@ #include "commons.h" #include "data-provider-manager.h" -#include "menu-provider.h" #include "settings.h" +#include "context-menu-extension.h" namespace UkuiMenu { diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index 9182a9e..a227b6b 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -24,12 +24,11 @@ #include "theme-palette.h" #include "app-icon-provider.h" #include "menu-main-window.h" -#include "extension/menu-extension.h" #include "app-page-header-utils.h" #include "power-button.h" #include "items/theme-icon.h" #include "app-manager.h" -#include "menu-manager.h" +#include "context-menu-manager.h" #include "data-provider-manager.h" #include "event-track.h" #include "sidebar-button-utils.h" @@ -97,9 +96,8 @@ void UkuiMenuApplication::initQmlEngine() context->setContextProperty("themePalette", ThemePalette::getInstance()); context->setContextProperty("menuSetting", MenuSetting::instance()); context->setContextProperty("modelManager", ModelManager::instance()); - context->setContextProperty("extensionManager", MenuExtension::instance()); context->setContextProperty("appPageHeaderUtils", new AppPageHeaderUtils(this)); - context->setContextProperty("menuManager", MenuManager::instance()); + context->setContextProperty("menuManager", ContextMenuManager::instance()); context->setContextProperty("appManager", AppManager::instance()); // MenuMainWindow diff --git a/src/windows/menu-main-window.cpp b/src/windows/menu-main-window.cpp index 478aa66..bba2b34 100644 --- a/src/windows/menu-main-window.cpp +++ b/src/windows/menu-main-window.cpp @@ -18,7 +18,7 @@ #include "menu-main-window.h" #include "settings.h" -#include "menu-manager.h" +#include "context-menu-manager.h" #include #include @@ -421,7 +421,7 @@ void MenuWindow::init() updateGeometry(); - MenuManager::instance()->setMainWindow(this); + ContextMenuManager::instance()->setMainWindow(this); } void MenuWindow::updateGeometry() @@ -520,7 +520,7 @@ bool MenuWindow::event(QEvent *event) WindowHelper::removeHeaderBar(this); } if (event->type() == QEvent::MouseButtonPress) { - MenuManager::instance()->closeMenu(); + ContextMenuManager::instance()->closeMenu(); } return QQuickView::event(event);