2022-09-06 11:36:55 +08:00
|
|
|
|
// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd.
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2016-10-14 15:47:43 +08:00
|
|
|
|
|
|
|
|
|
#include "dbusdockadaptors.h"
|
2021-09-22 10:17:16 +08:00
|
|
|
|
#include "utils.h"
|
|
|
|
|
#include "dockitemmanager.h"
|
|
|
|
|
|
2016-10-14 15:47:43 +08:00
|
|
|
|
#include <QScreen>
|
2018-05-11 20:29:44 +08:00
|
|
|
|
#include <QDebug>
|
2021-09-22 10:17:16 +08:00
|
|
|
|
#include <QGSettings>
|
2016-10-14 15:47:43 +08:00
|
|
|
|
|
2021-09-22 10:17:16 +08:00
|
|
|
|
DBusDockAdaptors::DBusDockAdaptors(MainWindow* parent)
|
|
|
|
|
: QDBusAbstractAdaptor(parent)
|
|
|
|
|
, m_gsettings(Utils::SettingsPtr("com.deepin.dde.dock.mainwindow", QByteArray(), this))
|
2016-10-14 15:47:43 +08:00
|
|
|
|
{
|
2018-05-11 20:29:44 +08:00
|
|
|
|
connect(parent, &MainWindow::panelGeometryChanged, this, [=] {
|
2016-10-14 15:47:43 +08:00
|
|
|
|
emit DBusDockAdaptors::geometryChanged(geometry());
|
|
|
|
|
});
|
2021-09-22 10:17:16 +08:00
|
|
|
|
|
|
|
|
|
if (m_gsettings) {
|
|
|
|
|
connect(m_gsettings, &QGSettings::changed, this, [ = ] (const QString &key) {
|
|
|
|
|
if (key == "onlyShowPrimary") {
|
|
|
|
|
Q_EMIT showInPrimaryChanged(m_gsettings->get(key).toBool());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(DockItemManager::instance(), &DockItemManager::itemInserted, this, [ = ] (const int index, DockItem *item) {
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
if (item->itemType() == DockItem::Plugins
|
|
|
|
|
|| item->itemType() == DockItem::FixedPlugin) {
|
|
|
|
|
PluginsItem *pluginItem = static_cast<PluginsItem *>(item);
|
|
|
|
|
for (auto *p : DockItemManager::instance()->pluginList()) {
|
|
|
|
|
if (p->pluginName() == pluginItem->pluginName()) {
|
|
|
|
|
Q_EMIT pluginVisibleChanged(p->pluginDisplayName(), getPluginVisible(p->pluginDisplayName()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(DockItemManager::instance(), &DockItemManager::itemRemoved, this, [ = ] (DockItem *item) {
|
|
|
|
|
if (item->itemType() == DockItem::Plugins
|
|
|
|
|
|| item->itemType() == DockItem::FixedPlugin) {
|
|
|
|
|
PluginsItem *pluginItem = static_cast<PluginsItem *>(item);
|
|
|
|
|
for (auto *p : DockItemManager::instance()->pluginList()) {
|
|
|
|
|
if (p->pluginName() == pluginItem->pluginName()) {
|
|
|
|
|
Q_EMIT pluginVisibleChanged(p->pluginDisplayName(), getPluginVisible(p->pluginDisplayName()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-14 15:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBusDockAdaptors::~DBusDockAdaptors()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow *DBusDockAdaptors::parent() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<MainWindow *>(QObject::parent());
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-13 15:35:11 +08:00
|
|
|
|
void DBusDockAdaptors::callShow()
|
|
|
|
|
{
|
|
|
|
|
return parent()->callShow();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 15:31:25 +08:00
|
|
|
|
void DBusDockAdaptors::ReloadPlugins()
|
|
|
|
|
{
|
|
|
|
|
return parent()->relaodPlugins();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 10:17:16 +08:00
|
|
|
|
QStringList DBusDockAdaptors::GetLoadedPlugins()
|
|
|
|
|
{
|
|
|
|
|
auto pluginList = DockItemManager::instance()->pluginList();
|
|
|
|
|
QStringList nameList;
|
|
|
|
|
QMap<QString, QString> map;
|
|
|
|
|
for (auto plugin : pluginList) {
|
|
|
|
|
// 托盘本身也是一个插件,这里去除掉这个特殊的插件,还有一些没有实际名字的插件
|
|
|
|
|
if (plugin->pluginName() == "tray"
|
|
|
|
|
|| plugin->pluginDisplayName().isEmpty()
|
|
|
|
|
|| !isPluginValid(plugin->pluginName()))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
nameList << plugin->pluginName();
|
|
|
|
|
map.insert(plugin->pluginName(), plugin->pluginDisplayName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 排序,保持和原先任务栏右键菜单中的插件列表顺序一致
|
|
|
|
|
qSort(nameList.begin(), nameList.end(), [ = ] (const QString &name1, const QString &name2) {
|
|
|
|
|
return name1 > name2;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QStringList newList;
|
|
|
|
|
for (auto name : nameList) {
|
|
|
|
|
newList.push_back(map[name]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newList;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 13:10:09 +08:00
|
|
|
|
void DBusDockAdaptors::resizeDock(int offset, bool dragging)
|
2021-10-13 11:27:50 +08:00
|
|
|
|
{
|
2021-11-05 13:10:09 +08:00
|
|
|
|
parent()->resizeDock(offset, dragging);
|
2021-10-13 11:27:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 11:14:40 +08:00
|
|
|
|
// 返回每个插件的识别Key(所以此值应始终不变),供个性化插件根据key去匹配每个插件对应的图标
|
|
|
|
|
QString DBusDockAdaptors::getPluginKey(const QString &pluginName)
|
|
|
|
|
{
|
|
|
|
|
for (auto plugin : DockItemManager::instance()->pluginList()) {
|
|
|
|
|
if (plugin->pluginDisplayName() == pluginName)
|
|
|
|
|
return plugin->pluginName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 10:17:16 +08:00
|
|
|
|
bool DBusDockAdaptors::getPluginVisible(const QString &pluginName)
|
|
|
|
|
{
|
|
|
|
|
for (auto *p : DockItemManager::instance()->pluginList()) {
|
|
|
|
|
if (!p->pluginIsAllowDisable())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const QString &display = p->pluginDisplayName();
|
|
|
|
|
if (display != pluginName)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const QString &name = p->pluginName();
|
|
|
|
|
if (!isPluginValid(name))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return !p->pluginIsDisable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qInfo() << "Unable to get information about this plugin";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DBusDockAdaptors::setPluginVisible(const QString &pluginName, bool visible)
|
|
|
|
|
{
|
|
|
|
|
for (auto *p : DockItemManager::instance()->pluginList()) {
|
|
|
|
|
if (!p->pluginIsAllowDisable())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const QString &display = p->pluginDisplayName();
|
|
|
|
|
if (display != pluginName)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const QString &name = p->pluginName();
|
|
|
|
|
if (!isPluginValid(name))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (p->pluginIsDisable() == visible) {
|
|
|
|
|
p->pluginStateSwitched();
|
|
|
|
|
Q_EMIT pluginVisibleChanged(pluginName, visible);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qInfo() << "Unable to set information for this plugin";
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 15:47:43 +08:00
|
|
|
|
QRect DBusDockAdaptors::geometry() const
|
|
|
|
|
{
|
2018-05-15 20:02:37 +08:00
|
|
|
|
return parent()->geometry();
|
2016-10-14 15:47:43 +08:00
|
|
|
|
}
|
2021-09-22 10:17:16 +08:00
|
|
|
|
|
|
|
|
|
bool DBusDockAdaptors::showInPrimary() const
|
|
|
|
|
{
|
|
|
|
|
return Utils::SettingValue("com.deepin.dde.dock.mainwindow", QByteArray(), "onlyShowPrimary", false).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DBusDockAdaptors::setShowInPrimary(bool showInPrimary)
|
|
|
|
|
{
|
|
|
|
|
if (this->showInPrimary() == showInPrimary)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (Utils::SettingSaveValue("com.deepin.dde.dock.mainwindow", QByteArray(), "onlyShowPrimary", showInPrimary)) {
|
|
|
|
|
Q_EMIT showInPrimaryChanged(showInPrimary);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DBusDockAdaptors::isPluginValid(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
// 插件被全局禁用时,理应获取不到此插件的任何信息
|
2021-12-15 15:41:35 +08:00
|
|
|
|
if (!Utils::SettingValue("com.deepin.dde.dock.module." + name, QByteArray(), "enable", true).toBool())
|
2021-09-22 10:17:16 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2022-04-18 10:17:38 +08:00
|
|
|
|
// 在非wayland环境下,未开启窗口特效时,不显示多任务视图插件
|
|
|
|
|
if (name == "multitasking" && !DWindowManagerHelper::instance()->hasComposite() && !Utils::IS_WAYLAND_DISPLAY)
|
2021-10-11 11:14:40 +08:00
|
|
|
|
return false;
|
2021-09-22 10:17:16 +08:00
|
|
|
|
|
|
|
|
|
// 录屏插件不显示,插件名如果有变化,建议发需求,避免任务栏反复适配
|
|
|
|
|
if (name == "deepin-screen-recorder-plugin")
|
2021-10-11 11:14:40 +08:00
|
|
|
|
return false;
|
2021-09-22 10:17:16 +08:00
|
|
|
|
|
2022-07-06 13:44:41 +08:00
|
|
|
|
// 远程助手只有在启动时才会加载在任务栏,不需要在控制中心加载
|
|
|
|
|
if (name == "uos-remote-assistance")
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-22 10:17:16 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|