2023-02-16 13:51:55 +08:00
|
|
|
|
// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
2022-09-06 11:36:55 +08:00
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
|
|
|
|
#include "systemtrayscontroller.h"
|
|
|
|
|
#include "pluginsiteminterface.h"
|
2021-12-17 14:49:51 +08:00
|
|
|
|
#include "utils.h"
|
2022-06-10 16:18:15 +00:00
|
|
|
|
#include "proxyplugincontroller.h"
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
|
|
SystemTraysController::SystemTraysController(QObject *parent)
|
2019-01-07 20:33:15 +08:00
|
|
|
|
: AbstractPluginsController(parent)
|
2018-11-13 20:07:52 +08:00
|
|
|
|
{
|
2019-01-07 20:33:15 +08:00
|
|
|
|
setObjectName("SystemTray");
|
2022-06-10 16:18:15 +00:00
|
|
|
|
|
|
|
|
|
// 将当前对象添加进代理对象列表中,代理对象在加载插件成功后,会调用列表中所有对象的itemAdded方法来添加插件
|
|
|
|
|
ProxyPluginController::instance(PluginType::QuickPlugin)->addProxyInterface(this);
|
|
|
|
|
ProxyPluginController::instance(PluginType::SystemTrays)->addProxyInterface(this);
|
|
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(this, [ this ] {
|
|
|
|
|
// 在加载当前的tray插件之前,所有的插件已经加载,因此此处需要获取代理中已经加载过的插件来加载到当前布局中
|
|
|
|
|
loadPlugins(ProxyPluginController::instance(PluginType::QuickPlugin));
|
|
|
|
|
loadPlugins(ProxyPluginController::instance(PluginType::SystemTrays));
|
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SystemTraysController::~SystemTraysController()
|
|
|
|
|
{
|
|
|
|
|
ProxyPluginController::instance(PluginType::QuickPlugin)->removeProxyInterface(this);
|
|
|
|
|
ProxyPluginController::instance(PluginType::SystemTrays)->removeProxyInterface(this);
|
2018-11-13 20:07:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SystemTraysController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
|
|
|
|
{
|
2019-01-10 10:02:54 +08:00
|
|
|
|
QMap<PluginsItemInterface *, QMap<QString, QObject *>> &mPluginsMap = pluginsMap();
|
2019-01-07 20:33:15 +08:00
|
|
|
|
|
2018-11-13 20:07:52 +08:00
|
|
|
|
// check if same item added
|
2019-01-07 20:33:15 +08:00
|
|
|
|
if (mPluginsMap.contains(itemInter))
|
2022-02-15 10:19:12 +08:00
|
|
|
|
if (mPluginsMap[itemInter].contains(itemKey))
|
|
|
|
|
return;
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
2022-02-15 10:19:12 +08:00
|
|
|
|
SystemTrayItem *item = new SystemTrayItem(itemInter, itemKey);
|
2019-08-01 15:59:25 +08:00
|
|
|
|
connect(item, &SystemTrayItem::itemVisibleChanged, this, [=] (bool visible){
|
|
|
|
|
if (visible) {
|
|
|
|
|
emit pluginItemAdded(itemKey, item);
|
2022-06-10 16:18:15 +00:00
|
|
|
|
} else {
|
2019-08-01 15:59:25 +08:00
|
|
|
|
emit pluginItemRemoved(itemKey, item);
|
|
|
|
|
}
|
|
|
|
|
}, Qt::QueuedConnection);
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
2019-01-07 20:33:15 +08:00
|
|
|
|
mPluginsMap[itemInter][itemKey] = item;
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
2021-12-17 14:49:51 +08:00
|
|
|
|
// 隐藏的插件不加入到布局中
|
2022-02-15 10:19:12 +08:00
|
|
|
|
if (Utils::SettingValue(QString("com.deepin.dde.dock.module.") + itemInter->pluginName(), QByteArray(), "enable", true).toBool())
|
2021-12-17 14:49:51 +08:00
|
|
|
|
emit pluginItemAdded(itemKey, item);
|
2018-11-13 20:07:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SystemTraysController::itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey)
|
|
|
|
|
{
|
2019-01-07 20:33:15 +08:00
|
|
|
|
SystemTrayItem *item = static_cast<SystemTrayItem *>(pluginItemAt(itemInter, itemKey));
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
|
|
|
|
item->update();
|
|
|
|
|
|
2019-01-07 20:33:15 +08:00
|
|
|
|
emit pluginItemUpdated(itemKey, item);
|
2018-11-13 20:07:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SystemTraysController::itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey)
|
|
|
|
|
{
|
2019-01-07 20:33:15 +08:00
|
|
|
|
SystemTrayItem *item = static_cast<SystemTrayItem *>(pluginItemAt(itemInter, itemKey));
|
2018-11-13 20:07:52 +08:00
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
item->detachPluginWidget();
|
|
|
|
|
|
2019-01-07 20:33:15 +08:00
|
|
|
|
emit pluginItemRemoved(itemKey, item);
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
2019-01-10 10:02:54 +08:00
|
|
|
|
QMap<PluginsItemInterface *, QMap<QString, QObject *>> &mPluginsMap = pluginsMap();
|
2019-01-07 20:33:15 +08:00
|
|
|
|
mPluginsMap[itemInter].remove(itemKey);
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
|
|
|
|
// do not delete the itemWidget object(specified in the plugin interface)
|
|
|
|
|
item->centralWidget()->setParent(nullptr);
|
|
|
|
|
|
|
|
|
|
// just delete our wrapper object(PluginsItem)
|
|
|
|
|
item->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 14:38:09 +08:00
|
|
|
|
void SystemTraysController::requestWindowAutoHide(PluginsItemInterface * const itemInter, const QString &itemKey, const bool autoHide)
|
2018-11-13 20:07:52 +08:00
|
|
|
|
{
|
2019-01-07 20:33:15 +08:00
|
|
|
|
SystemTrayItem *item = static_cast<SystemTrayItem *>(pluginItemAt(itemInter, itemKey));
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
2018-11-13 20:07:52 +08:00
|
|
|
|
|
2018-12-17 14:38:09 +08:00
|
|
|
|
Q_EMIT item->requestWindowAutoHide(autoHide);
|
2018-12-03 18:16:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 14:38:09 +08:00
|
|
|
|
void SystemTraysController::requestRefreshWindowVisible(PluginsItemInterface * const itemInter, const QString &itemKey)
|
2018-12-03 18:16:39 +08:00
|
|
|
|
{
|
2019-01-07 20:33:15 +08:00
|
|
|
|
SystemTrayItem *item = static_cast<SystemTrayItem *>(pluginItemAt(itemInter, itemKey));
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
2018-12-03 18:16:39 +08:00
|
|
|
|
|
2018-12-17 14:38:09 +08:00
|
|
|
|
Q_EMIT item->requestRefershWindowVisible();
|
2018-12-03 18:16:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 14:38:09 +08:00
|
|
|
|
void SystemTraysController::requestSetAppletVisible(PluginsItemInterface * const itemInter, const QString &itemKey, const bool visible)
|
2018-12-03 18:16:39 +08:00
|
|
|
|
{
|
2019-01-07 20:33:15 +08:00
|
|
|
|
SystemTrayItem *item = static_cast<SystemTrayItem *>(pluginItemAt(itemInter, itemKey));
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
2018-12-03 18:16:39 +08:00
|
|
|
|
|
2018-12-17 14:38:09 +08:00
|
|
|
|
if (visible) {
|
|
|
|
|
item->showPopupApplet(itemInter->itemPopupApplet(itemKey));
|
|
|
|
|
} else {
|
|
|
|
|
item->hidePopup();
|
|
|
|
|
}
|
2018-11-13 20:07:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 17:14:07 +08:00
|
|
|
|
int SystemTraysController::systemTrayItemSortKey(const QString &itemKey)
|
|
|
|
|
{
|
|
|
|
|
auto inter = pluginInterAt(itemKey);
|
|
|
|
|
|
2022-06-10 16:18:15 +00:00
|
|
|
|
if (!inter)
|
2018-11-21 17:14:07 +08:00
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return inter->itemSortKey(itemKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SystemTraysController::setSystemTrayItemSortKey(const QString &itemKey, const int order)
|
|
|
|
|
{
|
|
|
|
|
auto inter = pluginInterAt(itemKey);
|
|
|
|
|
|
2022-06-10 16:18:15 +00:00
|
|
|
|
if (!inter)
|
2018-11-21 17:14:07 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
inter->setSortKey(itemKey, order);
|
|
|
|
|
}
|
2018-12-28 17:00:29 +08:00
|
|
|
|
|
|
|
|
|
const QVariant SystemTraysController::getValueSystemTrayItem(const QString &itemKey, const QString &key, const QVariant &fallback)
|
|
|
|
|
{
|
|
|
|
|
auto inter = pluginInterAt(itemKey);
|
|
|
|
|
|
2022-06-10 16:18:15 +00:00
|
|
|
|
if (!inter)
|
2018-12-28 17:00:29 +08:00
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
return getValue(inter, key, fallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SystemTraysController::saveValueSystemTrayItem(const QString &itemKey, const QString &key, const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
auto inter = pluginInterAt(itemKey);
|
|
|
|
|
|
2022-06-10 16:18:15 +00:00
|
|
|
|
if (!inter)
|
2018-12-28 17:00:29 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
saveValue(inter, key, value);
|
|
|
|
|
}
|
2019-01-07 20:33:15 +08:00
|
|
|
|
|
2022-06-10 16:18:15 +00:00
|
|
|
|
void SystemTraysController::loadPlugins(ProxyPluginController *proxyController)
|
2019-01-07 20:33:15 +08:00
|
|
|
|
{
|
2022-06-10 16:18:15 +00:00
|
|
|
|
// 加载已有插件,并将其添加到当前的插件中
|
|
|
|
|
const QList<PluginsItemInterface *> &pluginsItems = proxyController->pluginsItems();
|
|
|
|
|
for (PluginsItemInterface *itemInter : pluginsItems)
|
|
|
|
|
itemAdded(itemInter, proxyController->itemKey(itemInter));
|
2019-01-07 20:33:15 +08:00
|
|
|
|
}
|