mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
feat: 添加dbus接口提供数据
提供接口,后续做控制中心的任务栏配置插件需要用到 Log: Task: https://pms.uniontech.com/zentao/task-view-86357.html Change-Id: I82a3718c9cc0e4ae40095a05d6e2d551a2ec74ca
This commit is contained in:
parent
c33693ad6e
commit
b7b3451735
@ -20,14 +20,53 @@
|
||||
*/
|
||||
|
||||
#include "dbusdockadaptors.h"
|
||||
#include "utils.h"
|
||||
#include "dockitemmanager.h"
|
||||
|
||||
#include <QScreen>
|
||||
#include <QDebug>
|
||||
#include <QGSettings>
|
||||
|
||||
DBusDockAdaptors::DBusDockAdaptors(MainWindow* parent): QDBusAbstractAdaptor(parent)
|
||||
DBusDockAdaptors::DBusDockAdaptors(MainWindow* parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
, m_gsettings(Utils::SettingsPtr("com.deepin.dde.dock.mainwindow", QByteArray(), this))
|
||||
{
|
||||
connect(parent, &MainWindow::panelGeometryChanged, this, [=] {
|
||||
emit DBusDockAdaptors::geometryChanged(geometry());
|
||||
});
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
DBusDockAdaptors::~DBusDockAdaptors()
|
||||
@ -50,7 +89,113 @@ void DBusDockAdaptors::ReloadPlugins()
|
||||
return parent()->relaodPlugins();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
QRect DBusDockAdaptors::geometry() const
|
||||
{
|
||||
return parent()->geometry();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// 插件被全局禁用时,理应获取不到此插件的任何信息
|
||||
if (!Utils::SettingValue("com.deepin.dde.dock.module." + name, QByteArray(), "enable", false).toBool())
|
||||
return false;
|
||||
|
||||
// 未开启窗口特效时,不显示多任务视图插件
|
||||
if (name == "multitasking" && !DWindowManagerHelper::instance()->hasComposite())
|
||||
return false;
|
||||
|
||||
// 录屏插件不显示,插件名如果有变化,建议发需求,避免任务栏反复适配
|
||||
if (name == "deepin-screen-recorder-plugin")
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -23,11 +23,13 @@
|
||||
#define DBUSDOCKADAPTORS_H
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
/*
|
||||
* Adaptor class for interface com.deepin.dde.Dock
|
||||
*/
|
||||
class QGSettings;
|
||||
class DBusDockAdaptors: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -35,13 +37,28 @@ class DBusDockAdaptors: public QDBusAbstractAdaptor
|
||||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
" <interface name=\"com.deepin.dde.Dock\">\n"
|
||||
" <property access=\"read\" type=\"(iiii)\" name=\"geometry\"/>\n"
|
||||
" <property access=\"readwrite\" type=\"b\" name=\"showInPrimary\"/>\n"
|
||||
" <method name=\"callShow\"/>"
|
||||
" <method name=\"ReloadPlugins\"/>"
|
||||
" <signal name=\"geometryChanged\">"
|
||||
"<arg name=\"geometry\" type=\"(iiii)\"/>"
|
||||
"</signal>"
|
||||
" <method name=\"GetLoadedPlugins\">"
|
||||
" <arg name=\"list\" type=\"as\" direction=\"out\"/>"
|
||||
" </method>"
|
||||
" <method name=\"getPluginVisible\">"
|
||||
" <arg name=\"pluginName\" type=\"s\" direction=\"in\"/>"
|
||||
" <arg name=\"visible\" type=\"b\" direction=\"out\"/>"
|
||||
" </method>"
|
||||
" <method name=\"setPluginVisible\">"
|
||||
" <arg name=\"pluginName\" type=\"s\" direction=\"in\"/>"
|
||||
" <arg name=\"visible\" type=\"b\" direction=\"in\"/>"
|
||||
" </method>"
|
||||
" <signal name=\"pluginVisibleChanged\">"
|
||||
" <arg type=\"s\"/>"
|
||||
" <arg type=\"b\"/>"
|
||||
" </signal>"
|
||||
" </interface>\n"
|
||||
"")
|
||||
Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
|
||||
Q_PROPERTY(bool showInPrimary READ showInPrimary WRITE setShowInPrimary NOTIFY showInPrimaryChanged)
|
||||
|
||||
public:
|
||||
explicit DBusDockAdaptors(MainWindow *parent);
|
||||
@ -53,12 +70,27 @@ public Q_SLOTS: // METHODS
|
||||
void callShow();
|
||||
void ReloadPlugins();
|
||||
|
||||
QStringList GetLoadedPlugins();
|
||||
|
||||
bool getPluginVisible(const QString &pluginName);
|
||||
void setPluginVisible(const QString &pluginName, bool visible);
|
||||
|
||||
public: // PROPERTIES
|
||||
Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
|
||||
QRect geometry() const;
|
||||
|
||||
bool showInPrimary() const;
|
||||
void setShowInPrimary(bool showInPrimary);
|
||||
|
||||
signals:
|
||||
void geometryChanged(QRect geometry);
|
||||
void showInPrimaryChanged(bool);
|
||||
void pluginVisibleChanged(const QString &pluginName, bool visible);
|
||||
|
||||
private:
|
||||
bool isPluginValid(const QString &name);
|
||||
|
||||
private:
|
||||
QGSettings *m_gsettings;
|
||||
};
|
||||
|
||||
#endif //DBUSDOCKADAPTORS
|
||||
|
Loading…
x
Reference in New Issue
Block a user