2022-12-08 14:37:02 +08:00
|
|
|
|
/*
|
|
|
|
|
* 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 "ukui-menu-application.h"
|
2023-04-11 15:29:05 +08:00
|
|
|
|
#include "menu-dbus-service.h"
|
2022-12-09 15:01:14 +08:00
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "commons.h"
|
2022-12-23 11:08:16 +08:00
|
|
|
|
#include "menu-main-window.h"
|
2023-02-14 09:58:57 +08:00
|
|
|
|
#include "power-button.h"
|
2023-03-31 16:20:05 +08:00
|
|
|
|
#include "app-manager.h"
|
2023-12-11 10:43:25 +08:00
|
|
|
|
#include "context-menu-manager.h"
|
2023-11-07 16:35:46 +08:00
|
|
|
|
#include "event-track.h"
|
2023-11-30 14:01:43 +08:00
|
|
|
|
#include "sidebar-button-utils.h"
|
2024-01-18 03:24:01 +08:00
|
|
|
|
#include "widget-model.h"
|
2024-01-09 10:08:53 +08:00
|
|
|
|
#include "app-page-backend.h"
|
2024-01-15 07:16:59 +08:00
|
|
|
|
#include "app-group-model.h"
|
2024-02-01 18:55:21 +08:00
|
|
|
|
#include "favorite/favorites-model.h"
|
|
|
|
|
#include "favorite/folder-model.h"
|
2022-12-08 14:37:02 +08:00
|
|
|
|
|
2023-09-12 10:24:28 +08:00
|
|
|
|
#include <QGuiApplication>
|
2022-12-08 14:37:02 +08:00
|
|
|
|
#include <QCommandLineParser>
|
2022-12-09 15:01:14 +08:00
|
|
|
|
#include <QQmlContext>
|
2023-04-11 15:29:05 +08:00
|
|
|
|
#include <QQmlEngine>
|
2022-12-08 14:37:02 +08:00
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
using namespace UkuiMenu;
|
|
|
|
|
|
|
|
|
|
UkuiMenuApplication::UkuiMenuApplication(MenuMessageProcessor *processor) : QObject(nullptr)
|
|
|
|
|
{
|
|
|
|
|
registerQmlTypes();
|
|
|
|
|
startUkuiMenu();
|
2022-12-12 10:02:44 +08:00
|
|
|
|
initDbusService();
|
2022-12-12 15:16:45 +08:00
|
|
|
|
connect(processor, &MenuMessageProcessor::request, this, &UkuiMenuApplication::execCommand);
|
2022-12-08 14:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UkuiMenuApplication::startUkuiMenu()
|
|
|
|
|
{
|
|
|
|
|
initQmlEngine();
|
2023-02-08 10:58:51 +08:00
|
|
|
|
loadMenuUI();
|
2022-12-08 14:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UkuiMenuApplication::registerQmlTypes()
|
|
|
|
|
{
|
2022-12-09 15:01:14 +08:00
|
|
|
|
const char *uri = "org.ukui.menu.core";
|
|
|
|
|
int versionMajor = 1, versionMinor = 0;
|
2022-12-13 09:08:51 +08:00
|
|
|
|
SettingModule::defineModule(uri, versionMajor, versionMinor);
|
2022-12-23 11:08:16 +08:00
|
|
|
|
WindowModule::defineModule(uri, versionMajor, versionMinor);
|
2023-02-13 09:31:11 +08:00
|
|
|
|
PowerButton::defineModule(uri, versionMajor, versionMinor);
|
2023-11-30 14:01:43 +08:00
|
|
|
|
SidebarButtonUtils::defineModule(uri, versionMajor, versionMinor);
|
2022-12-13 09:08:51 +08:00
|
|
|
|
|
2023-12-11 10:38:02 +08:00
|
|
|
|
qmlRegisterType<WidgetModel>(uri, versionMajor, versionMinor, "WidgetModel");
|
2024-01-15 07:16:59 +08:00
|
|
|
|
qmlRegisterType<AppGroupModel>(uri, versionMajor, versionMinor, "AppGroupModel");
|
2024-01-18 03:24:01 +08:00
|
|
|
|
//qmlRegisterType<AppPageBackend>(uri, versionMajor, versionMinor, "AppPageBackend");
|
|
|
|
|
qmlRegisterSingletonInstance(uri, versionMajor, versionMinor, "AppPageBackend", AppPageBackend::instance());
|
2024-01-09 10:08:53 +08:00
|
|
|
|
qmlRegisterUncreatableType<AppListPluginGroup>(uri, versionMajor, versionMinor, "PluginGroup", "Use enums only.");
|
2023-12-11 10:38:02 +08:00
|
|
|
|
|
2023-04-09 19:38:27 +08:00
|
|
|
|
// commons
|
|
|
|
|
qRegisterMetaType<UkuiMenu::DataType::Type>("DataType::Type");
|
|
|
|
|
qRegisterMetaType<UkuiMenu::DataEntity>("DataEntity");
|
2023-05-06 09:20:34 +08:00
|
|
|
|
qRegisterMetaType<UkuiMenu::MenuInfo::Location>("MenuInfo::Location");
|
2023-04-09 19:38:27 +08:00
|
|
|
|
qmlRegisterUncreatableType<Display>(uri, versionMajor, versionMinor, "Display", "Use enums only.");
|
|
|
|
|
qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only");
|
2023-05-06 09:20:34 +08:00
|
|
|
|
qmlRegisterUncreatableType<UkuiMenu::MenuInfo>(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only.");
|
2024-01-22 16:03:53 +08:00
|
|
|
|
qmlRegisterUncreatableType<UkuiMenu::LabelItem>(uri, versionMajor, versionMinor, "LabelItem", "Use enums only.");
|
2024-01-24 10:16:54 +08:00
|
|
|
|
qmlRegisterUncreatableType<UkuiMenu::WidgetMetadata>(uri, versionMajor, versionMinor, "WidgetMetadata", "Use enums only.");
|
2023-04-09 19:38:27 +08:00
|
|
|
|
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");
|
|
|
|
|
|
2023-11-07 16:35:46 +08:00
|
|
|
|
qmlRegisterUncreatableType<EventTrack>(uri, versionMajor, versionMinor, "EventTrack", "Attached only.");
|
2022-12-08 14:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UkuiMenuApplication::initQmlEngine()
|
|
|
|
|
{
|
2023-02-08 10:58:51 +08:00
|
|
|
|
m_engine = new QQmlEngine(this);
|
|
|
|
|
m_engine->addImportPath("qrc:/qml");
|
|
|
|
|
|
|
|
|
|
QQmlContext *context = m_engine->rootContext();
|
|
|
|
|
context->setContextProperty("menuSetting", MenuSetting::instance());
|
2023-12-11 10:43:25 +08:00
|
|
|
|
context->setContextProperty("menuManager", ContextMenuManager::instance());
|
2023-03-31 16:20:05 +08:00
|
|
|
|
context->setContextProperty("appManager", AppManager::instance());
|
2023-02-08 10:58:51 +08:00
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
|
context->setContextProperty("favoriteModel", &FavoritesModel::instance());
|
|
|
|
|
context->setContextProperty("FolderModel", &FolderModel::instance());
|
2023-02-08 10:58:51 +08:00
|
|
|
|
// MenuMainWindow
|
|
|
|
|
// const QUrl url(QStringLiteral("qrc:/qml/MenuMainWindow.qml"));
|
|
|
|
|
// QQmlApplicationEngine *m_applicationEngine{nullptr};
|
|
|
|
|
// m_applicationEngine = new QQmlApplicationEngine(this);
|
|
|
|
|
// QObject::connect(m_applicationEngine, &QQmlApplicationEngine::objectCreated,
|
|
|
|
|
// this, [url](QObject *obj, const QUrl &objUrl) {
|
|
|
|
|
// if (!obj && url == objUrl)
|
|
|
|
|
// QCoreApplication::exit(-1);
|
|
|
|
|
// }, Qt::QueuedConnection);
|
|
|
|
|
//
|
|
|
|
|
// m_applicationEngine->load(url);
|
2023-04-28 17:37:39 +08:00
|
|
|
|
|
|
|
|
|
connect(AppManager::instance(), &AppManager::request, this, &UkuiMenuApplication::execCommand);
|
2023-02-08 10:58:51 +08:00
|
|
|
|
}
|
2022-12-08 14:37:02 +08:00
|
|
|
|
|
2023-02-08 10:58:51 +08:00
|
|
|
|
void UkuiMenuApplication::loadMenuUI()
|
|
|
|
|
{
|
|
|
|
|
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
|
|
|
|
|
m_mainWindow = new MenuWindow(m_engine, nullptr);
|
|
|
|
|
m_mainWindow->setSource(url);
|
2023-06-08 17:11:06 +08:00
|
|
|
|
connect(m_mainWindow, &QQuickView::activeFocusItemChanged, m_mainWindow, [this] {
|
|
|
|
|
if (m_mainWindow->activeFocusItem()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
execCommand(Hide);
|
|
|
|
|
});
|
2022-12-08 14:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 10:02:44 +08:00
|
|
|
|
void UkuiMenuApplication::initDbusService()
|
|
|
|
|
{
|
2023-09-12 10:24:28 +08:00
|
|
|
|
m_menuDbusService = new MenuDbusService(QGuiApplication::instance()->property("display").toString(), this);
|
2022-12-12 15:16:45 +08:00
|
|
|
|
if (m_menuDbusService) {
|
|
|
|
|
connect(m_menuDbusService, &MenuDbusService::menuActive, this, [this] {
|
|
|
|
|
execCommand(Active);
|
|
|
|
|
});
|
|
|
|
|
// connect(m_menuDbusService, &MenuDbusService::reloadConfigSignal, this, [this] {
|
|
|
|
|
//// reload ...
|
|
|
|
|
// });
|
|
|
|
|
}
|
2022-12-12 10:02:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 15:16:45 +08:00
|
|
|
|
void UkuiMenuApplication::execCommand(Command command)
|
2022-12-08 14:37:02 +08:00
|
|
|
|
{
|
|
|
|
|
switch (command) {
|
2023-02-08 10:58:51 +08:00
|
|
|
|
case Active: {
|
|
|
|
|
if (m_mainWindow) {
|
2024-04-07 09:38:21 +08:00
|
|
|
|
m_mainWindow->activeMenuWindow(!m_mainWindow->isVisible());
|
2023-02-08 10:58:51 +08:00
|
|
|
|
}
|
2022-12-12 15:16:45 +08:00
|
|
|
|
break;
|
2023-02-08 10:58:51 +08:00
|
|
|
|
}
|
|
|
|
|
case Show: {
|
|
|
|
|
if (m_mainWindow) {
|
2024-04-07 09:38:21 +08:00
|
|
|
|
m_mainWindow->activeMenuWindow(true);
|
2023-02-08 10:58:51 +08:00
|
|
|
|
}
|
2022-12-08 14:37:02 +08:00
|
|
|
|
break;
|
2023-02-08 10:58:51 +08:00
|
|
|
|
}
|
|
|
|
|
case Quit: {
|
|
|
|
|
if (m_mainWindow) {
|
2024-04-07 09:38:21 +08:00
|
|
|
|
m_mainWindow->activeMenuWindow(false);
|
2023-02-08 10:58:51 +08:00
|
|
|
|
m_engine->quit();
|
|
|
|
|
}
|
2022-12-12 15:16:45 +08:00
|
|
|
|
QCoreApplication::quit();
|
2022-12-08 14:37:02 +08:00
|
|
|
|
break;
|
2023-02-08 10:58:51 +08:00
|
|
|
|
}
|
2023-04-28 17:37:39 +08:00
|
|
|
|
case Hide: {
|
|
|
|
|
if (m_mainWindow) {
|
2024-04-07 09:38:21 +08:00
|
|
|
|
m_mainWindow->activeMenuWindow(false);
|
2023-04-28 17:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-12-08 14:37:02 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-01-18 03:24:01 +08:00
|
|
|
|
|
|
|
|
|
// TODO: 发送窗口显示隐藏信号到插件
|
2022-12-08 14:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 10:58:51 +08:00
|
|
|
|
UkuiMenuApplication::~UkuiMenuApplication()
|
|
|
|
|
{
|
|
|
|
|
if (m_mainWindow) {
|
|
|
|
|
m_mainWindow->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 15:16:45 +08:00
|
|
|
|
// == MenuMessageProcessor == //
|
2023-04-10 18:01:18 +08:00
|
|
|
|
|
|
|
|
|
QCommandLineOption MenuMessageProcessor::showUkuiMenu({"s", "show"}, QObject::tr("Show ukui-menu."));
|
|
|
|
|
QCommandLineOption MenuMessageProcessor::quitUkuiMenu({"q", "quit"}, QObject::tr("Quit ukui-menu."));
|
|
|
|
|
|
2022-12-08 14:37:02 +08:00
|
|
|
|
MenuMessageProcessor::MenuMessageProcessor() : QObject(nullptr) {}
|
|
|
|
|
|
2023-04-10 18:01:18 +08:00
|
|
|
|
void MenuMessageProcessor::processMessage(const QString &message)
|
2022-12-08 14:37:02 +08:00
|
|
|
|
{
|
|
|
|
|
QStringList options = QString(message).split(' ');
|
|
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
2023-04-10 18:01:18 +08:00
|
|
|
|
parser.addOption(MenuMessageProcessor::showUkuiMenu);
|
|
|
|
|
parser.addOption(MenuMessageProcessor::quitUkuiMenu);
|
2022-12-08 14:37:02 +08:00
|
|
|
|
|
|
|
|
|
parser.parse(options);
|
|
|
|
|
|
2023-04-10 18:01:18 +08:00
|
|
|
|
if (parser.isSet(MenuMessageProcessor::showUkuiMenu)) {
|
2022-12-12 15:16:45 +08:00
|
|
|
|
Q_EMIT request(UkuiMenuApplication::Show);
|
2022-12-08 14:37:02 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 18:01:18 +08:00
|
|
|
|
if (parser.isSet(MenuMessageProcessor::quitUkuiMenu)) {
|
2022-12-12 15:16:45 +08:00
|
|
|
|
Q_EMIT request(UkuiMenuApplication::Quit);
|
2022-12-08 14:37:02 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 已知问题,使用命令quit时,会出现 QFileSystemWatcher::removePaths: list is empty
|
|
|
|
|
* 可见该bug: https://bugreports.qt.io/browse/QTBUG-68607
|
|
|
|
|
* @param message
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
bool MenuMessageProcessor::preprocessMessage(const QStringList& message)
|
|
|
|
|
{
|
2023-04-10 18:01:18 +08:00
|
|
|
|
qDebug() << "Hey, there.";
|
2022-12-08 14:37:02 +08:00
|
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
QCommandLineOption helpOption = parser.addHelpOption();
|
|
|
|
|
QCommandLineOption versionOption = parser.addVersionOption();
|
|
|
|
|
|
2023-04-10 18:01:18 +08:00
|
|
|
|
parser.addOption(MenuMessageProcessor::showUkuiMenu);
|
|
|
|
|
parser.addOption(MenuMessageProcessor::quitUkuiMenu);
|
2022-12-08 14:37:02 +08:00
|
|
|
|
|
|
|
|
|
parser.parse(message);
|
|
|
|
|
|
|
|
|
|
if (message.size() <= 1 || parser.isSet(helpOption) || !parser.unknownOptionNames().isEmpty()) {
|
|
|
|
|
if (!parser.unknownOptionNames().isEmpty()) {
|
|
|
|
|
qDebug() << "Unknown options:" << parser.unknownOptionNames();
|
|
|
|
|
}
|
|
|
|
|
parser.showHelp();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser.isSet(versionOption)) {
|
|
|
|
|
parser.showVersion();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 18:01:18 +08:00
|
|
|
|
return parser.isSet(MenuMessageProcessor::showUkuiMenu) || parser.isSet(MenuMessageProcessor::quitUkuiMenu);
|
2022-12-08 14:37:02 +08:00
|
|
|
|
}
|