Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
# SPDX-License-Identifier: CC0-1.0

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets LinguistTools)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widget)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widget Tools)

file(GLOB SRCS "*.h" "*.cpp" "../../interfaces/*.h" "utils/*.h" "utils/*.cpp")

file(GLOB TS_FILES "translations/*.ts")
qt_add_translation(QM_FILES ${TS_FILES})
add_custom_target(trayloader_translations ALL DEPENDS ${QM_FILES})

set(PLUGIN_INTERACTION_CONFIG_META_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/configs/org.deepin.dde.dock.plugin.interaction.json")
dtk_add_config_to_cpp(
PLUGIN_INTERACTION_CONFIG_HEADER
"${PLUGIN_INTERACTION_CONFIG_META_FILE}"
OUTPUT_FILE_NAME plugininteractionconfig.h
CLASS_NAME PluginInteractionConfig
)

add_executable(trayplugin-loader
main.cpp
dockdbusproxy.cpp
Expand All @@ -19,6 +28,7 @@ add_executable(trayplugin-loader
widgetplugin.cpp
pluginitem.h
pluginitem.cpp
"${PLUGIN_INTERACTION_CONFIG_HEADER}"
quickpluginitem.h
quickpluginitem.cpp
utils/setproctitle.h
Expand All @@ -43,6 +53,7 @@ target_link_libraries(trayplugin-loader PRIVATE
dockpluginmanager-interface
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Dtk${DTK_VERSION_MAJOR}::Core
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Gui
)
Expand All @@ -52,6 +63,7 @@ install(TARGETS trayplugin-loader DESTINATION ${CMAKE_INSTALL_LIBEXECDIR})
#dconfig
dtk_add_config_meta_files(APPID org.deepin.dde.dock FILES ./configs/org.deepin.dde.dock.plugin.common.json) # compat
dtk_add_config_meta_files(APPID org.deepin.dde.tray-loader FILES ./configs/org.deepin.dde.dock.plugin.common.json)
dtk_add_config_meta_files(APPID org.deepin.dde.tray-loader FILES "${PLUGIN_INTERACTION_CONFIG_META_FILE}")

# 安装 .qm 文件
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/trayplugin-loader/translations)
39 changes: 39 additions & 0 deletions src/loader/configs/org.deepin.dde.dock.plugin.interaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"itemActivationEnabled": {
"value": true,
"serial": 0,
"flags": [],
"name": "Enable plugin item activation",
"name[zh_CN]": "允许激活插件项",
"description": "Whether the tray loader may invoke itemCommand and itemPopupApplet for the taskbar items provided by this plugin.",
"description[zh_CN]": "是否允许任务栏加载器调用此插件在任务栏中各插件项的 itemCommand 和 itemPopupApplet 接口。",
"permissions": "readwrite",
"visibility": "private"
},
"itemContextMenuEnabled": {
"value": true,
"serial": 0,
"flags": [],
"name": "Enable plugin item context menu",
"name[zh_CN]": "允许插件项上下文菜单",
"description": "Whether the tray loader may invoke itemContextMenu and display framework-provided context menu actions for the taskbar items provided by this plugin.",
"description[zh_CN]": "是否允许任务栏加载器调用此插件在任务栏中各插件项的 itemContextMenu 接口,并显示任务栏提供的驻留或移除驻留菜单。",
"permissions": "readwrite",
"visibility": "private"
},
"itemTooltipEnabled": {
"value": true,
"serial": 0,
"flags": [],
"name": "Enable plugin item tooltip",
"name[zh_CN]": "允许插件项悬浮提示",
"description": "Whether the tray loader may invoke itemTipsWidget and display tooltips for the taskbar items provided by this plugin.",
"description[zh_CN]": "是否允许任务栏加载器调用此插件在任务栏中各插件项的 itemTipsWidget 接口并显示悬浮提示。",
"permissions": "readwrite",
"visibility": "private"
}
}
}
50 changes: 50 additions & 0 deletions src/loader/pluginitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@

#include "constants.h"
#include "pluginitem.h"
#include "plugin.h"

Check warning on line 7 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "plugin.h" not found.
#include "widgetplugin.h"
#include "dockcontextmenu.h"
#include "plugininteractionconfig.h"

Check warning on line 10 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "plugininteractionconfig.h" not found.

#include <xdgactivation.h>

Check warning on line 12 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <xdgactivation.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QHBoxLayout>
#include <QMouseEvent>
#include <QMenu>
#include <QPainter>

Check warning on line 17 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>

Check warning on line 18 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcess> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcessEnvironment>

Check warning on line 19 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcessEnvironment> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QUrl>

Check warning on line 20 in src/loader/pluginitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QUrl> not found. Please note: Cppcheck does not need standard library headers to get proper results.

const static QString DockQuickPlugins = "Dock_Quick_Plugins";

namespace {
constexpr auto PluginInteractionConfigAppId = "org.deepin.dde.tray-loader";

QString pluginInteractionConfigSubpath(const QString &pluginId)
{
return QStringLiteral("/%1").arg(QString::fromLatin1(QUrl::toPercentEncoding(pluginId)));
}
}

PluginItem::PluginItem(PluginsItemInterface *pluginItemInterface, const QString &itemKey, QWidget *parent)
: QWidget(parent)
, m_itemKey(itemKey)
Expand Down Expand Up @@ -69,6 +80,9 @@

QWidget *PluginItem::itemPopupApplet()
{
if (m_interactionConfig && !m_interactionConfig->itemActivationEnabled())
return nullptr;

if (auto popup = m_pluginsItemInterface->itemPopupApplet(m_itemKey)) {
bool existed = panelPopupExisted();
bool embed = embedPanelPopupExisted();
Expand Down Expand Up @@ -101,6 +115,9 @@

QMenu *PluginItem::pluginContextMenu()
{
if (m_interactionConfig && !m_interactionConfig->itemContextMenuEnabled())
return nullptr;

if (!m_menu->actions().isEmpty()) {
m_menu->clear();
}
Expand Down Expand Up @@ -291,6 +308,27 @@

void PluginItem::init()
{
if (itemKey() != Dock::QUICK_ITEM_KEY && !m_interactionConfig) {
m_interactionConfig = PluginInteractionConfig::create(
QLatin1String(PluginInteractionConfigAppId),
pluginInteractionConfigSubpath(pluginId()),
this);
connect(m_interactionConfig,
&PluginInteractionConfig::itemContextMenuEnabledChanged,
this,
[this] {
if (!m_interactionConfig->itemContextMenuEnabled())
m_menu->close();
});
connect(m_interactionConfig,
&PluginInteractionConfig::itemTooltipEnabledChanged,
this,
[this] {
if (!m_interactionConfig->itemTooltipEnabled())
closeToolTip();
});
}

setAttribute(Qt::WA_TranslucentBackground);
winId();

Expand All @@ -305,6 +343,9 @@

void PluginItem::initPluginMenu()
{
if (m_interactionConfig && !m_interactionConfig->itemContextMenuEnabled())
return;

const QString menuJson = m_pluginsItemInterface->itemContextMenu(m_itemKey);
if (menuJson.isEmpty()) {
qWarning() << "itemContextMenu is empty!";
Expand Down Expand Up @@ -335,6 +376,9 @@

QWidget *PluginItem::pluginTooltip()
{
if (m_interactionConfig && !m_interactionConfig->itemTooltipEnabled())
return nullptr;

auto popup = m_pluginsItemInterface->itemPopupApplet(m_itemKey);
if (popup && popup->isVisible())
popup->windowHandle()->hide();
Expand All @@ -344,6 +388,9 @@

QWidget * PluginItem::itemTooltip(const QString &itemKey)
{
if (m_interactionConfig && !m_interactionConfig->itemTooltipEnabled())
return nullptr;

if (!m_tipsWidget) {
auto toolTip = m_pluginsItemInterface->itemTipsWidget(itemKey);
if (!toolTip) {
Expand Down Expand Up @@ -375,6 +422,9 @@

bool PluginItem::executeCommand()
{
if (m_interactionConfig && !m_interactionConfig->itemActivationEnabled())
return false;

const QString command = m_pluginsItemInterface->itemCommand(m_itemKey);
if (!command.isEmpty()) {
qInfo() << "command: " << command;
Expand Down
4 changes: 3 additions & 1 deletion src/loader/pluginitem.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -13,6 +13,7 @@
const int Attribute_ForceUnDock = 0x800000;

class DockContextMenu;
class PluginInteractionConfig;
class PluginItem : public QWidget
{
Q_OBJECT
Expand Down Expand Up @@ -76,6 +77,7 @@ class PluginItem : public QWidget
private:
QTimer* m_tooltipTimer;
QPointer<QWidget> m_tipsWidget;
PluginInteractionConfig *m_interactionConfig = nullptr;

QAction *m_unDockAction = nullptr;
int m_pluginFlags = 0;
Expand Down
Loading