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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ option(BUILD_EXAMPLE "Build example programs" OFF)
set(DDE-Network-Core_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src-old")
set(DDE-Network-Core_LIBRARIES dde-network-core)

find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH})
find_package(WaylandProtocols REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LibNM REQUIRED IMPORTED_TARGET libnm)
include_directories(${LibNM_INCLUDE_DIRS})
Expand Down
7 changes: 6 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ Priority: optional
Maintainer: donghualin <donghualin@uniontech.com>
Build-Depends: debhelper-compat (= 12),
cmake,
extra-cmake-modules,
libglib2.0-dev (>= 2.32),
pkg-config,
libgtest-dev,
dde-control-center-dev (>= 6.1.71),
dde-tray-loader-dev,
dde-session-shell-dev,
libudev-dev,
libudev-dev,
qt6-base-dev,
qt6-declarative-dev,
qt6-tools-dev,
qt6-wayland-dev,
qt6-base-private-dev,
qt6-wayland-private-dev,
wayland-protocols,
libdtk6core-dev,
libdtk6widget-dev,
libgsettings-qt6-dev,
Expand Down
13 changes: 11 additions & 2 deletions dock-network-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

Expand All @@ -14,6 +14,7 @@ set(CMAKE_AUTOMOC ON)
# 启用 qrc 资源文件的支持
set(CMAKE_AUTORCC ON)


file(GLOB_RECURSE SRCS
"networkplugin.h"
"networkplugin.cpp"
Expand All @@ -26,14 +27,16 @@ file(GLOB_RECURSE SRCS
"widget/jumpsettingbutton.cpp"
"widget/commoniconbutton.h"
"widget/commoniconbutton.cpp"
"xdgactivation.h"
"xdgactivation.cpp"
)

set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_PTHREADS_INIT 1)
set(CMAKE_PREFER_PTHREAD_FLAG ON)

find_package(${QT_NS} COMPONENTS Core Widgets DBus Network LinguistTools REQUIRED)
find_package(${QT_NS} COMPONENTS Core Widgets DBus Network WaylandClient LinguistTools REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(${DTK_NS} REQUIRED COMPONENTS Widget)
find_package(KF6NetworkManagerQt REQUIRED)
Expand All @@ -46,6 +49,10 @@ find_package(DdeDock REQUIRED)

add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} ../net-view/window/qrc/network.qrc)

qt_generate_wayland_protocol_client_sources(${PLUGIN_NAME} FILES
${WaylandProtocols_DATADIR}/staging/xdg-activation/xdg-activation-v1.xml
)
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../../dde-dock)

file(GLOB TS_FILES "translations/*.ts")
Expand All @@ -67,12 +74,14 @@ target_include_directories(${PLUGIN_NAME} PUBLIC
"../net-view/operation"
"../net-view/window"
"../src"
${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(${PLUGIN_NAME} PRIVATE
${QT_NS}::Widgets
${QT_NS}::DBus
${QT_NS}::Network
${QT_NS}::WaylandClientPrivate
${DTK_NS}::Widget
KF6::NetworkManagerQt
dde-network-core6
Expand Down
11 changes: 10 additions & 1 deletion dock-network-plugin/dockcontentwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#ifndef DOCKCONTENTWIDGET_H
#define DOCKCONTENTWIDGET_H

#include "netmanager.h"

Check warning on line 8 in dock-network-plugin/dockcontentwidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "netmanager.h" not found.
#include "netview.h"

Check warning on line 9 in dock-network-plugin/dockcontentwidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "netview.h" not found.
#include "widget/jumpsettingbutton.h"
#include "xdgactivation.h"
#include "constants.h"

Check warning on line 12 in dock-network-plugin/dockcontentwidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "constants.h" not found.

#include <QDebug>

Check warning on line 14 in dock-network-plugin/dockcontentwidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QEvent>
#include <QStyleOption>
#include <QStylePainter>
Expand Down Expand Up @@ -45,7 +46,15 @@
m_netSetBtn = new JumpSettingButton(this);
m_netSetBtn->setIcon(QIcon::fromTheme("network-setting"));
m_netSetBtn->setDescription(tr("Network settings"));
connect(m_netSetBtn, &JumpSettingButton::clicked, netManager, &NetManager::gotoControlCenter);
connect(m_netSetBtn, &JumpSettingButton::clicked, this, [this, netManager]() {
auto *activation = new XdgActivation(this);
Comment thread
18202781743 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有重复代码,建议在NetworkPlugin里加个函数,DockContentWidget里加个信号,NetworkPlugin里调用函数

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不加函数吧,本身也是简单的组合,它跟NetworkPlugin也没有公共的东西,

connect(activation, &XdgActivation::tokenReady, this,
[netManager, activation](const QString &token) {
netManager->gotoControlCenter(token);
activation->deleteLater();
}, Qt::SingleShotConnection);
activation->requestToken();
});

m_netCheckBtn = new JumpSettingButton(this);
m_netCheckBtn->setIcon(QIcon::fromTheme("network-check"));
Expand Down
24 changes: 17 additions & 7 deletions dock-network-plugin/networkplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#include "netview.h"
#include "quickpanelwidget.h"

#include <DGuiApplicationHelper>

Check warning on line 13 in dock-network-plugin/networkplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include "xdgactivation.h"

#include <QDBusConnection>

Check warning on line 17 in dock-network-plugin/networkplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 18 in dock-network-plugin/networkplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 19 in dock-network-plugin/networkplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <unistd.h>
Expand Down Expand Up @@ -164,11 +166,7 @@
{
Q_UNUSED(itemKey)
if (m_netStatus->needShowControlCenter()) {
return QString("dbus-send --print-reply "
"--dest=org.deepin.dde.ControlCenter1 "
"/org/deepin/dde/ControlCenter1 "
"org.deepin.dde.ControlCenter1.ShowModule "
"string:network");
return QString("dde-am --by-user org.deepin.dde.control-center -- -p network");
}

return QString();
Expand Down Expand Up @@ -350,7 +348,13 @@
void NetworkPlugin::onQuickIconClicked()
{
if (m_netStatus->needShowControlCenter()) {
m_manager->gotoControlCenter();
auto *activation = new XdgActivation(this);
connect(activation, &XdgActivation::tokenReady, this,
[this, activation](const QString &token) {
m_manager->gotoControlCenter(token);
activation->deleteLater();
}, Qt::SingleShotConnection);
activation->requestToken();
} else {
m_netStatus->toggleNetworkActive();
}
Expand All @@ -359,7 +363,13 @@
void NetworkPlugin::onQuickPanelClicked()
{
if (m_netStatus->needShowControlCenter()) {
m_manager->gotoControlCenter();
auto *activation = new XdgActivation(this);
connect(activation, &XdgActivation::tokenReady, this,
[this, activation](const QString &token) {
m_manager->gotoControlCenter(token);
activation->deleteLater();
}, Qt::SingleShotConnection);
activation->requestToken();
} else {
showNetworkDialog();
}
Expand Down
27 changes: 17 additions & 10 deletions dock-network-plugin/widget/jumpsettingbutton.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "jumpsettingbutton.h"
#include "../xdgactivation.h"

#include <QHBoxLayout>

Check warning on line 8 in dock-network-plugin/widget/jumpsettingbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in dock-network-plugin/widget/jumpsettingbutton.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 <DFontSizeManager>
#include <DGuiApplicationHelper>
#include <DPlatformTheme>
#include <DDBusSender>
#include <DPaletteHelper>

DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -119,14 +120,20 @@
if (underMouse()) {
Q_EMIT clicked();
if (m_autoShowPage && !m_fistPage.isEmpty()) {
DDBusSender()
.service("org.deepin.dde.ControlCenter1")
.path("/org/deepin/dde/ControlCenter1")
.interface("org.deepin.dde.ControlCenter1")
.method(QString("ShowPage"))
.arg(QString(m_fistPage))
.arg(QString(m_secondPage))
.call();
auto *activation = new dde::network::XdgActivation(this);
QString page = m_fistPage;
if (!m_secondPage.isEmpty())
page += "/" + m_secondPage;
connect(activation, &dde::network::XdgActivation::tokenReady, this,
[activation, page](const QString &token) {
QStringList args { "--by-user", "org.deepin.dde.control-center" };
if (!token.isEmpty())
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
args << "--" << "-p" << page;
QProcess::startDetached("dde-am", args);
activation->deleteLater();
}, Qt::SingleShotConnection);
activation->requestToken();
Q_EMIT showPageRequestWasSended();
}
return;
Expand Down
180 changes: 180 additions & 0 deletions dock-network-plugin/xdgactivation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "xdgactivation.h"

#include <DSGApplication>
#include <QGuiApplication>
#include <QLoggingCategory>
#include <QMetaObject>
#include <QtWaylandClient/QWaylandClientExtension>

#include "qwayland-xdg-activation-v1.h"

#include <private/qwaylanddisplay_p.h>
#include <private/qwaylandinputdevice_p.h>
#include <private/qwaylandwindow_p.h>

Q_LOGGING_CATEGORY(trayXdgActivation, "dde.network.xdgactivation")

namespace dde {
namespace network {

// ---------------------------------------------------------------------------
// XdgActivationTokenV1
// ---------------------------------------------------------------------------

class XdgActivationTokenV1 : public QObject, public QtWayland::xdg_activation_token_v1
{
Q_OBJECT
public:
~XdgActivationTokenV1() override
{
destroy();
}

Q_SIGNALS:
void done(const QString &token);

protected:
void xdg_activation_token_v1_done(const QString &token) override
{
Q_EMIT done(token);
}
};

// ---------------------------------------------------------------------------
// XdgActivationV1 (singleton extension)
// ---------------------------------------------------------------------------

namespace {

class XdgActivationV1 : public QWaylandClientExtensionTemplate<XdgActivationV1>,
public QtWayland::xdg_activation_v1
{
public:
XdgActivationV1()
: QWaylandClientExtensionTemplate<XdgActivationV1>(1)
{
qCDebug(trayXdgActivation) << "Initializing xdg_activation_v1 extension, version:";
initialize();
qCDebug(trayXdgActivation) << "xdg_activation_v1 initialized, isActive:" << isActive();
}

~XdgActivationV1() override
{
if (isInitialized())
destroy();
}

XdgActivationTokenV1 *createTokenProvider(QWindow *window, const QString &appId)
{
qCDebug(trayXdgActivation) << "Creating token provider, window:" << window << "appId:" << appId;
auto *provider = new XdgActivationTokenV1;
provider->init(get_activation_token());

if (window) {
if (auto *waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle())) {
if (auto *surface = waylandWindow->wlSurface()) {
qCDebug(trayXdgActivation) << "Setting surface for token request";
provider->set_surface(surface);
} else {
qCWarning(trayXdgActivation) << "WaylandWindow has no wlSurface";
}
if (auto *inputDevice = waylandWindow->display()->lastInputDevice()) {
qCDebug(trayXdgActivation) << "Setting serial:" << inputDevice->serial() << "seat:" << inputDevice->wl_seat();
provider->set_serial(inputDevice->serial(), inputDevice->wl_seat());
} else {
qCWarning(trayXdgActivation) << "No lastInputDevice available";
}
} else {
qCWarning(trayXdgActivation) << "Window handle is not a QWaylandWindow";
}
} else {
qCWarning(trayXdgActivation) << "No window provided for token request";
}

if (!appId.isEmpty())
provider->set_app_id(appId);

provider->commit();
qCDebug(trayXdgActivation) << "Token provider committed";
return provider;
}
};

XdgActivationV1 *activationV1()
{
static QPointer<XdgActivationV1> activation;
if (activation)
return activation;

activation = new XdgActivationV1;
activation->setParent(qApp);
return activation;
}

} // anonymous namespace

// ---------------------------------------------------------------------------
// XdgActivation
// ---------------------------------------------------------------------------

XdgActivation::XdgActivation(QObject *parent)
: QObject(parent)
{
}

XdgActivation::~XdgActivation() = default;

bool XdgActivation::isActive() const
{
auto *activation = activationV1();
const bool active = activation && activation->isActive();
qCDebug(trayXdgActivation) << "isActive:" << active;
return active;
}

void XdgActivation::requestToken(QWindow *window, const QString &appId)
{
qCDebug(trayXdgActivation) << "requestToken called, window:" << window << "appId:" << appId;

if (m_provider) {
qCWarning(trayXdgActivation) << "XDG activation token request already started, ignoring";
return;
}

if (!isActive()) {
qCDebug(trayXdgActivation) << "xdg_activation_v1 is not active; token request skipped";
Q_EMIT tokenReady({});
return;
}

const QString effectiveAppId = appId.isEmpty() ? QString::fromUtf8(DTK_CORE_NAMESPACE::DSGApplication::id()) : appId;
qCDebug(trayXdgActivation) << "effectiveAppId:" << effectiveAppId;

if (effectiveAppId.isEmpty())
qCWarning(trayXdgActivation) << "XDG activation request has empty app id";

auto effectiveWindow = window ? window : QGuiApplication::focusWindow();
qCDebug(trayXdgActivation) << "effectiveWindow:" << effectiveWindow;
auto *provider = activationV1()->createTokenProvider(effectiveWindow, effectiveAppId);
provider->setParent(this);
m_provider = provider;

connect(provider, &XdgActivationTokenV1::done, this, [this, provider, effectiveAppId](const QString &token) {
m_provider = nullptr;
if (token.isEmpty())
qCWarning(trayXdgActivation) << "XDG activation token missing for app:" << effectiveAppId;
else
qCDebug(trayXdgActivation) << "XDG activation token received for app:" << effectiveAppId << "token length:" << token.length();
provider->deleteLater();
Q_EMIT tokenReady(token);
}, Qt::SingleShotConnection);
}

} // namespace network
} // namespace dde

#include "xdgactivation.moc"
Loading
Loading