diff --git a/archlinux/PKGBUILD b/archlinux/PKGBUILD index 42e0dfcc9..f05ff63bb 100644 --- a/archlinux/PKGBUILD +++ b/archlinux/PKGBUILD @@ -41,6 +41,7 @@ makedepends=('git' 'ninja' 'extra-cmake-modules' 'wayland-protocols' + 'networkmanager-qt' ) conflicts=('dde-shell') provides=('dde-shell') diff --git a/debian/control b/debian/control index 1c9bf8e05..ce911b8f0 100644 --- a/debian/control +++ b/debian/control @@ -42,6 +42,7 @@ Build-Depends: libxres-dev, libxtst-dev, libdframeworkdbus-dev, + libkf6networkmanagerqt-dev, Standards-Version: 3.9.8 Homepage: http://www.deepin.org diff --git a/debian/dde-shell.install b/debian/dde-shell.install index adec6b756..c42b6e4b0 100644 --- a/debian/dde-shell.install +++ b/debian/dde-shell.install @@ -8,6 +8,8 @@ usr/share/dde-shell/org.deepin.ds.dock*/ usr/lib/*/qt6/qml/org/deepin/ds/dock/* usr/lib/*/dde-shell/org.deepin.ds.notification* usr/share/dde-shell/org.deepin.ds.notification*/ +usr/lib/*/dde-shell/org.deepin.ds.dde-am* +usr/share/dde-shell/org.deepin.ds.dde-am*/ usr/libexec/dockplugin-loader usr/lib/*/qt5/plugins/wayland-shell-integration usr/lib/*/libdde-dockplugin-interface.so.* @@ -16,3 +18,4 @@ usr/lib/dde-dock/tmp/plugins usr/lib/dde-dock/tmp/plugins/quick-trays usr/share/dde-dock/tmp/translations usr/share/dde-shell/*/translations +usr/share/dock-network-plugin/tmp/translations diff --git a/panels/dock/tray/CMakeLists.txt b/panels/dock/tray/CMakeLists.txt index 660c789df..ed6da31c6 100644 --- a/panels/dock/tray/CMakeLists.txt +++ b/panels/dock/tray/CMakeLists.txt @@ -74,28 +74,6 @@ endfunction(generation_dbus_interface) file(GLOB INTERFACES "interfaces/*.h") add_definitions(-DCVERSION="${VERSION}") -#因为单元测试需要直接测试源代码,而主程序代码中include的单元使用了相对路径 -#单元测试的CMakeLists和主程序的CMakeLists路径不同,编译单元测试时会提示找不到文件 -#因此设置搜索路径 -include_directories( - frame/accessible - frame/controller - frame/dbus - frame/dbus/sni - frame/display - frame/item - frame/item/components - frame/item/resources - frame/model - frame/util - frame/window - frame/window/components - frame/window/tray - frame/window/tray/widgets - frame/xcb - ../widgets - ../interfaces - ) aux_source_directory(frame/accessible ACCESSIBLE) aux_source_directory(frame/controller CONTROLLER) aux_source_directory(frame/dbus DBUS) @@ -132,6 +110,30 @@ file(GLOB SRC_PATH add_subdirectory("frame") add_subdirectory("plugins") add_subdirectory("libdbusmenu-qt") + +#因为单元测试需要直接测试源代码,而主程序代码中include的单元使用了相对路径 +#单元测试的CMakeLists和主程序的CMakeLists路径不同,编译单元测试时会提示找不到文件 +#因此设置搜索路径 +# include_directories( +# frame/accessible +# frame/controller +# frame/dbus +# frame/dbus/sni +# frame/display +# frame/item +# frame/item/components +# frame/item/resources +# frame/model +# frame/util +# frame/window +# frame/window/components +# frame/window/tray +# frame/window/tray/widgets +# frame/xcb +# ../widgets +# ../interfaces +# ) + ## qm files file(GLOB QM_FILES "translations/*.qm") install(FILES ${QM_FILES} diff --git a/panels/dock/tray/frame/CMakeLists.txt b/panels/dock/tray/frame/CMakeLists.txt index 8f18c24d9..dd676e37d 100644 --- a/panels/dock/tray/frame/CMakeLists.txt +++ b/panels/dock/tray/frame/CMakeLists.txt @@ -53,6 +53,7 @@ target_include_directories(${BIN_NAME} PUBLIC accessible controller dbus + dbus/sni display item item/components diff --git a/panels/dock/tray/plugins/CMakeLists.txt b/panels/dock/tray/plugins/CMakeLists.txt index 609ab9ae4..12fdca71c 100644 --- a/panels/dock/tray/plugins/CMakeLists.txt +++ b/panels/dock/tray/plugins/CMakeLists.txt @@ -11,3 +11,4 @@ add_subdirectory("bluetooth") add_subdirectory("airplane-mode") add_subdirectory("notification") add_subdirectory("deepin-screen-recorder") +add_subdirectory("dde-network-core") diff --git a/panels/dock/tray/plugins/bluetooth/CMakeLists.txt b/panels/dock/tray/plugins/bluetooth/CMakeLists.txt index fc593036b..ac3e8d900 100644 --- a/panels/dock/tray/plugins/bluetooth/CMakeLists.txt +++ b/panels/dock/tray/plugins/bluetooth/CMakeLists.txt @@ -34,6 +34,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../quic target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ../../frame + ../../frame/util ../../frame/qtdbusextended ./dbusinterface/generation_dbus_interface componments) diff --git a/panels/dock/tray/plugins/dde-network-core/CMakeLists.txt b/panels/dock/tray/plugins/dde-network-core/CMakeLists.txt new file mode 100644 index 000000000..067ed9dce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.7) + +set(VERSION "2.0.18" CACHE STRING "define project version") +project(dde-network-core + VERSION ${VERSION} + DESCRIPTION "DDE Network Core" + HOMEPAGE_URL "https://github.com/linuxdeepin/dde-network-core" + LANGUAGES CXX C +) + +# 增加安全编译参数 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now -z noexecstack -pie") + +option(ENABLE_DEEPIN_NMQT "enable nmqt patch on deepin" OFF) + +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) +set(QT_MAJOR_VERSION 6) +find_package(Qt6 COMPONENTS Core Widgets DBus Network LinguistTools REQUIRED) +find_package(KF6NetworkManagerQt REQUIRED) + +if (ENABLE_DEEPIN_NMQT) + add_definitions(-DUSE_DEEPIN_NMQT) +endif() + +message(STATUS DEEPIN_NMQT_TEST ": ${DEEPIN_NMQT_TEST}") + +add_subdirectory("src") +add_subdirectory("dock-network-plugin") diff --git a/panels/dock/tray/plugins/dde-network-core/README.md b/panels/dock/tray/plugins/dde-network-core/README.md new file mode 100644 index 000000000..00c8fca23 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/README.md @@ -0,0 +1,58 @@ +## DDE Network Core + +DDE network library framework + +## Dependencies +You can also check the "Depends" provided in the debian/control file. + +### Build dependencies +You can also check the "Build-Depends" provided in the debian/control file. + +## Installation + +### Build from source code + +1. Make sure you have installed all dependencies. + +2. Build: +``` +$ cd dde-network-core +$ mkdir Build +$ cd Build +$ cmake .. +$ make +``` + +3. Install: +``` +$ sudo make install +``` + +The executable binary file could be found at `/usr/bin/dde-network-dialog` after the installation is finished, and plugins will be placed into related module plugin directory. + +## Usage + +Execute `dde-network-dialog -h` to get more details. + +## Getting help + +You can press `F1` to start [deepin-manual](https://github.com/linuxdeepin/deepin-manual) when you focus on DDE Control Center network module. + +You may also find these channels useful if you encounter any other issues: + +* [Gitter](https://gitter.im/orgs/linuxdeepin/rooms) +* [IRC Channel](https://webchat.freenode.net/?channels=deepin) +* [Official Forum](https://bbs.deepin.org/) +* [Wiki](https://wiki.deepin.org/) +* [Developer Center](https://github.com/linuxdeepin/dde-network-core) + +## Getting involved + +We encourage you to report issues and contribute changes + +* [Contribution guide for developers](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers-en). (English) +* [开发者代码贡献指南](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers) (中文) + +## License + +DDE Network Core is licensed under [LGPL-3.0-or-later](LICENSE). diff --git a/panels/dock/tray/plugins/dde-network-core/README.zh_CN.md b/panels/dock/tray/plugins/dde-network-core/README.zh_CN.md new file mode 100644 index 000000000..f2a15a64e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/README.zh_CN.md @@ -0,0 +1,57 @@ +## DDE网络核心框架 +DDE网络核心框架是UOS桌面环境的网络连接框架。 + +## 依赖 +请查看“debian/control”文件中提供的“Depends”。 + +### 编译依赖 +请查看“debian/control”文件中提供的“Build-Depends”。 + +## 安装 + +### 构建过程 + +1. 确保已经安装了所有的编译依赖 + +2. 构建 +``` +$ cd dde-network-core +$ mkdir Build +$ cd Build +$ cmake .. +$ make +``` + +3. 安装 +``` +$ sudo make install +``` + +安装完成后可执行二进制文件在/usr/bin/dde-network-dialog,插件会放在相关模块的插件目录下。 + +## 用法 + +执行 `dde-network-dialog -h` 以获取更多详细信息。 + +## 获得帮助 + +当你使用DDE控制中心,进入网络模块时,您可以按 `F1` 启动 [deepin-manual](https://github.com/linuxdeepin/deepin-manual)。 + +如果您遇到任何其他问题,您可能还会发现这些渠道很有用: + +* [Gitter](https://gitter.im/orgs/linuxdeepin/rooms) +* [IRC Channel](https://webchat.freenode.net/?channels=deepin) +* [官方论坛](https://bbs.deepin.org/) +* [Wiki](https://wiki.deepin.org/) +* [项目地址](https://github.com/linuxdeepin/dde-network-core) + +## 贡献指南 + +我们鼓励您报告问题并做出更改 + +* [Contribution guide for developers](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers-en). (English) +* [开发者代码贡献指南](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers) (中文) + +## License + +DDE网络核心框架在 [LGPL-3.0-or-later](LICENSE)下发布。 diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.cpp new file mode 100644 index 000000000..b0372108e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.cpp @@ -0,0 +1,444 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "devicestatushandler.h" + +#include +#include +#include + +DeviceStatusHandler::DeviceStatusHandler(QObject *parent) + : QObject(parent) +{ +} + +DeviceStatusHandler::~DeviceStatusHandler() +{ +} + +PluginState DeviceStatusHandler::pluginState() +{ + QList devices = NetworkController::instance()->devices(); + // 筛选出所有的有线和无线的状态 + QList wiredDevices; + QList wirelessDevice; + for (NetworkDeviceBase *deviceBase : devices) { + if (deviceBase->deviceType() == DeviceType::Wired) { + WiredDevice *device = static_cast(deviceBase); + wiredDevices << device; + } else if (deviceBase->deviceType() == DeviceType::Wireless) { + WirelessDevice *device = static_cast(deviceBase); + wirelessDevice << device; + } + } + + // 计算有线网络和无线网络的合并状态 + NetDeviceStatus wiredStat = wiredStatus(wiredDevices); + NetDeviceStatus wirelessStat = wirelessStatus(wirelessDevice); + return plugState(wiredStat, wirelessStat); +} + +NetDeviceStatus DeviceStatusHandler::wiredStatus(WiredDevice *device) +{ + // 如果当前网卡是禁用,直接返回禁用 + if (!device->isEnabled()) + return NetDeviceStatus::Disabled; + + // 网络是已连接,但是当前的连接状态不是Full,则认为网络连接成功,但是无法上网 + if (device->deviceStatus() == DeviceStatus::Activated + && NetworkController::instance()->connectivity() != Connectivity::Full) { + return NetDeviceStatus::ConnectNoInternet; + } + + // 获取IP地址失败 + if (!device->IPValid()) + return NetDeviceStatus::ObtainIpFailed; + + // 根据设备状态来直接获取返回值 + switch (device->deviceStatus()) { + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: return NetDeviceStatus::Nocable; + case DeviceStatus::Disconnected: return NetDeviceStatus::Disconnected; + case DeviceStatus::Prepare: + case DeviceStatus::Config: return NetDeviceStatus::Connecting; + case DeviceStatus::Needauth: return NetDeviceStatus::Authenticating; + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: + case DeviceStatus::Secondaries: return NetDeviceStatus::ObtainingIP; + case DeviceStatus::Activated: return NetDeviceStatus::Connected; + case DeviceStatus::Deactivation: + case DeviceStatus::Failed: return NetDeviceStatus::ConnectFailed; + case DeviceStatus::IpConfilct: return NetDeviceStatus::IpConflicted; + default: return NetDeviceStatus::Unknown; + } + + Q_UNREACHABLE(); + return NetDeviceStatus::Unknown; +} + +NetDeviceStatus DeviceStatusHandler::wiredStatus(const QList &devices) +{ + QList deviceStatus; + for (WiredDevice *device : devices) + deviceStatus << wiredStatus(device); + + // 显示的规则:从allDeviceStatus列表中按照顺序遍历所有的状态, + // 再遍历所有的设备的状态,只要其中一个设备的状态满足当前的状态,就返回当前状态 + static QList allDeviceStatus = + { NetDeviceStatus::Authenticating, NetDeviceStatus::ObtainingIP, NetDeviceStatus::IpConflicted, + NetDeviceStatus::Connected, NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::Connecting, + NetDeviceStatus::Disconnected, NetDeviceStatus::Disabled, NetDeviceStatus::Nocable, NetDeviceStatus::Unknown }; + for (int i = 0; i < allDeviceStatus.size(); i++) { + NetDeviceStatus status = allDeviceStatus[i]; + if (deviceStatus.contains(status)) + return status; + } + + return NetDeviceStatus::Unknown; +} + +NetDeviceStatus DeviceStatusHandler::wirelessStatus(WirelessDevice *device) +{ + if (!device->isEnabled()) + return NetDeviceStatus::Disabled; + + if (device->deviceStatus() == DeviceStatus::Activated + && device->connectivity() != Connectivity::Full) { + return NetDeviceStatus::ConnectNoInternet; + } + + if (!device->IPValid()) + return NetDeviceStatus::ObtainIpFailed; + + DeviceStatus status = device->deviceStatus(); + switch (status) { + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: + case DeviceStatus::Disconnected: return NetDeviceStatus::Disconnected; + case DeviceStatus::Prepare: + case DeviceStatus::Config: return NetDeviceStatus::Connecting; + case DeviceStatus::Needauth: return NetDeviceStatus::Authenticating; + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: + case DeviceStatus::Secondaries: return NetDeviceStatus::ObtainingIP; + case DeviceStatus::Activated: return NetDeviceStatus::Connected; + case DeviceStatus::Deactivation: + case DeviceStatus::Failed: return NetDeviceStatus::ConnectFailed; + case DeviceStatus::IpConfilct: return NetDeviceStatus::IpConflicted; + default: return NetDeviceStatus::Unknown; + } + + Q_UNREACHABLE(); + return NetDeviceStatus::Unknown; +} + +NetDeviceStatus DeviceStatusHandler::wirelessStatus(const QList &devices) +{ + // 所有设备状态叠加 + QList devStatus; + for (WirelessDevice *device : devices) + devStatus << wirelessStatus(device); + + static QList allDeviceStatus = + { NetDeviceStatus::Authenticating, NetDeviceStatus::ObtainingIP, NetDeviceStatus::IpConflicted, + NetDeviceStatus::Connected, NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::Connecting, + NetDeviceStatus::Disconnected, NetDeviceStatus::Disabled, NetDeviceStatus::Unknown}; + + for (int i = 0; i < allDeviceStatus.size(); i++) { + NetDeviceStatus status = allDeviceStatus[i]; + if (devStatus.contains(status)) + return status; + } + + return NetDeviceStatus::Unknown; +} + +PluginState DeviceStatusHandler::plugState(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + if (isUnknow(wiredStatus, wirelessStatus)) + return PluginState::Unknown; + + if (isDisabled(wiredStatus, wirelessStatus)) + return PluginState::Disabled; + + if (isWiredDisconnected(wiredStatus, wirelessStatus)) + return PluginState::WiredDisconnected; + + if (isWiredDisabled(wiredStatus, wirelessStatus)) + return PluginState::WiredDisabled; + + if (isWiredConnected(wiredStatus, wirelessStatus)) + return PluginState::WiredConnected; + + if (isWiredConnecting(wiredStatus, wirelessStatus)) + return PluginState::WiredConnecting; + + if (isWiredConnectNoInternet(wiredStatus, wirelessStatus)) + return PluginState::WiredConnectNoInternet; + + if (isNocable(wiredStatus, wirelessStatus)) + return PluginState::Nocable; + + if (isWiredFailed(wiredStatus, wirelessStatus)) + return PluginState::WiredFailed; + + if (isWirelessDisconnected(wiredStatus, wirelessStatus)) + return PluginState::WirelessDisconnected; + + if (isWirelessDisabled(wiredStatus, wirelessStatus)) + return PluginState::WirelessDisabled; + + if (isWirelessConnected(wiredStatus, wirelessStatus)) + return PluginState::WirelessConnected; + + if (isWirelessConnecting(wiredStatus, wirelessStatus)) + return PluginState::WirelessConnecting; + + if (isWirelessConnectNoInternet(wiredStatus, wirelessStatus)) + return PluginState::WirelessConnectNoInternet; + + if (isWirelessFailed(wiredStatus, wirelessStatus)) + return PluginState::WirelessFailed; + + if (isDisconnected(wiredStatus, wirelessStatus)) + return PluginState::Disconnected; + + if (wirelessStatus == NetDeviceStatus::IpConflicted) + return PluginState::WirelessIpConflicted; + + if (wiredStatus == NetDeviceStatus::IpConflicted) + return PluginState::WiredIpConflicted; + + if (isConnected(wiredStatus, wirelessStatus)) + return PluginState::Connected; + + if (isConnecting(wiredStatus, wirelessStatus)) + return PluginState::Connecting; + + if (isConnectNoInternet(wiredStatus, wirelessStatus)) + return PluginState::ConnectNoInternet; + + return PluginState::Failed; +} + +bool DeviceStatusHandler::isUnknow(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线和有线都是未知状态,则认为是未知状态(都没有网卡) + return (wiredStatus == NetDeviceStatus::Unknown + && wirelessStatus == NetDeviceStatus::Unknown); +} + +bool DeviceStatusHandler::isDisabled(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线无线都禁用,则认为是禁用状态 + return (wiredStatus == NetDeviceStatus::Disabled + && wirelessStatus == NetDeviceStatus::Disabled); +} + +bool DeviceStatusHandler::isWiredDisconnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 没有无线或者无线禁用的情况下, 有线设备开启、有线设备断开连接,有线设备获取IP失败,认为有线连接失败 + return ((wirelessStatus == NetDeviceStatus::Unknown && wiredStatus == NetDeviceStatus::Enabled) + || (wirelessStatus == NetDeviceStatus::Unknown && wiredStatus == NetDeviceStatus::Disconnected) + || (wirelessStatus == NetDeviceStatus::Unknown && wiredStatus == NetDeviceStatus::ObtainIpFailed) + || (wirelessStatus == NetDeviceStatus::Disabled && wiredStatus == NetDeviceStatus::Enabled) + || (wirelessStatus == NetDeviceStatus::Disabled && wiredStatus == NetDeviceStatus::Disconnected) + || (wirelessStatus == NetDeviceStatus::Disabled && wiredStatus == NetDeviceStatus::ObtainIpFailed)); +} + +bool DeviceStatusHandler::isWiredDisabled(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线禁用了,没有无线网卡 + return (wiredStatus == NetDeviceStatus::Disabled + && wirelessStatus == NetDeviceStatus::Unknown); +} + +bool DeviceStatusHandler::isWiredConnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 如果有线是连接状态,没有无线,无线启用,无线禁用,无线断开连接,无线获取IP失败,无线连接成功但是无网络 + // 无线连接失败,则认为是有线连接成功 + static QList wirelessFailuredStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectNoInternet + , NetDeviceStatus::ConnectFailed }; + + return ((wiredStatus == NetDeviceStatus::Connected) + && (wirelessFailuredStatus.contains(wirelessStatus))); +} + +bool DeviceStatusHandler::isWiredConnecting(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线正在连接,正在认证,正在获取IP + // 没有无线,无线开启和禁用、连接成功,断开连接,获取IP失败,连接但是没有网络,连接失败 + // 这种情况认为是有线正在连接 + static QList wiredConnectingStatus = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating, NetDeviceStatus::ObtainingIP }; + static QList wirelessConnecting = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Connected + , NetDeviceStatus::Disconnected, NetDeviceStatus::ObtainIpFailed + , NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::ConnectFailed }; + + return (wiredConnectingStatus.contains(wiredStatus) + && wirelessConnecting.contains(wirelessStatus)); +} + +bool DeviceStatusHandler::isWiredConnectNoInternet(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 没有无线,无线开启或禁用,无线断开连接,无线获取IP失败,无线连接失败 + // 有线连接但是没有网络 + // 这种情况认为是有线连接无网络 + static QList wirelessNoConnectStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectFailed }; + + return (wiredStatus == NetDeviceStatus::ConnectNoInternet + && wirelessNoConnectStatus.contains(wirelessStatus)); +} + +bool DeviceStatusHandler::isNocable(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线不可用,没有无线或无线禁用,这种情况认为是网络不可用 + return (wiredStatus == NetDeviceStatus::Nocable + && (wirelessStatus == NetDeviceStatus::Unknown + || wirelessStatus == NetDeviceStatus::Disabled )); +} + +bool DeviceStatusHandler::isWiredFailed(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线连接失败,没有无线或无线禁用,这种情况认为是有线不可用 + return (wiredStatus == NetDeviceStatus::ConnectFailed + && (wirelessStatus == NetDeviceStatus::Unknown + || wirelessStatus == NetDeviceStatus::Disabled )); +} + +bool DeviceStatusHandler::isWirelessDisconnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线启用,断开连接,获取IP失败 + // 没有有线,有线禁用,有线无效,有线失败 + // 这种情况认为是无线断开连接 + static QList wirelessStatusOfDis = + { NetDeviceStatus::Enabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed }; + static QList wiredStatusOfDis = + { NetDeviceStatus::Unknown, NetDeviceStatus::Disabled + , NetDeviceStatus::Nocable, NetDeviceStatus::ConnectFailed }; + + return ((wirelessStatusOfDis.contains(wirelessStatus) + && wiredStatusOfDis.contains(wiredStatus)) + || (wirelessStatus == NetDeviceStatus::ConnectFailed + && wiredStatus == NetDeviceStatus::Nocable)); +} + +bool DeviceStatusHandler::isWirelessDisabled(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线禁用,没有有线,这种情况认为是无线禁用 + return (wirelessStatus == NetDeviceStatus::Disabled + && wiredStatus == NetDeviceStatus::Unknown); +} + +bool DeviceStatusHandler::isWirelessConnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 没有有线网卡,有线启用禁用,断开连接,获取IP失败,已经连接网络但是无法上网,无效和失败 + // 无线网络已连接,这种情况认为是无线网络已连接 + static QList wiredFailusStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectNoInternet + , NetDeviceStatus::Nocable, NetDeviceStatus::ConnectFailed }; + + return (wiredFailusStatus.contains(wiredStatus) + && wirelessStatus == NetDeviceStatus::Connected); +} + +bool DeviceStatusHandler::isWirelessConnecting(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线状态:正在连接,正在认证, 正在获取IP + // 有线状态:没有有线,禁用,启用,连接成功,断开连接,获取IP失败,连接成功但是无法上网,无效,连接失败 + // 这种情况认为是无线正在连接 + static QList wirelessConnecting = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating + , NetDeviceStatus::ObtainingIP }; + + static QList wiredOfConnecting = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Connected + , NetDeviceStatus::Disconnected, NetDeviceStatus::ObtainIpFailed + , NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::Nocable + , NetDeviceStatus::ConnectFailed }; + + return (wirelessConnecting.contains(wirelessStatus) + && wiredOfConnecting.contains(wiredStatus)); +} + +bool DeviceStatusHandler::isWirelessConnectNoInternet(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线状态:没有无线,启用,禁用,断开连接,获取IP失败,无效,失败 + // 无线是已连接但是无法上网,这种情况认为是无线已连接但是无法上网 + static QList allWiredStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::Nocable + , NetDeviceStatus::ConnectFailed }; + + return (allWiredStatus.contains(wiredStatus) + && wirelessStatus == NetDeviceStatus::ConnectNoInternet); +} + +bool DeviceStatusHandler::isWirelessFailed(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线连接失败,在没有有线和有线禁用的情况下,认为无线连接失败 + return (wirelessStatus == NetDeviceStatus::ConnectFailed + && (wiredStatus == NetDeviceStatus::Unknown + || wiredStatus == NetDeviceStatus::Disabled)); +} + +bool DeviceStatusHandler::isDisconnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线启用,断开连接,获取IP失败,连接失败 + // 有线启用,断开连接,获取IP失败 + // 这种情况认为网络连接断开 + static QList disconectStatusWireless = + { NetDeviceStatus::Enabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectFailed }; + + static QList disconnectStatusWired = + { NetDeviceStatus::Enabled, NetDeviceStatus::Disconnected, NetDeviceStatus::ObtainIpFailed }; + + return (disconectStatusWireless.contains(wirelessStatus) + && disconnectStatusWired.contains(wiredStatus)); +} + +bool DeviceStatusHandler::isConnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线和无线都连接成功,这种情况认为连接成功 + return (wirelessStatus == NetDeviceStatus::Connected + && wiredStatus == NetDeviceStatus::Connected); +} + +bool DeviceStatusHandler::isConnecting(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线正在连接,正在认证,正在获取IP + // 无线正在连接,正在认证,正在获取IP + // 这种情况认为是正在连接 + static QList connectingWired = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating + , NetDeviceStatus::ObtainingIP }; + + static QList connectingWireless = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating + , NetDeviceStatus::ObtainingIP }; + + return (connectingWired.contains(wiredStatus) + && connectingWireless.contains(wirelessStatus)); +} + +bool DeviceStatusHandler::isConnectNoInternet(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线和无线都已经连接但是无法上网,这种情况认为是已连接但是无法上网 + return (wirelessStatus == NetDeviceStatus::ConnectNoInternet + && wiredStatus == NetDeviceStatus::ConnectNoInternet); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.h new file mode 100644 index 000000000..4dba551c9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.h @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEVICESTATUSHANDLER_H +#define DEVICESTATUSHANDLER_H + +#include + +namespace dde { + namespace network { + class WiredDevice; + class WirelessDevice; + } +} + +using namespace dde::network; + +enum class NetDeviceStatus { + Unknown = 0, + Enabled, + Disabled, + Connected, + Disconnected, + Connecting, + Authenticating, + ObtainingIP, + ObtainIpFailed, + ConnectNoInternet, + IpConflicted, + Nocable, + ConnectFailed +}; + +enum class PluginState +{ + Unknown = 0, + Disabled, + Connected, + Disconnected, + Connecting, + Failed, + ConnectNoInternet, + WirelessDisabled, + WiredDisabled, + WirelessConnected, + WiredConnected, + WirelessDisconnected, + WiredDisconnected, + WirelessConnecting, + WiredConnecting, + WirelessConnectNoInternet, + WiredConnectNoInternet, + WirelessFailed, + WiredFailed, + WiredIpConflicted, + WirelessIpConflicted, + Nocable +}; + +#define DECLARE_STATIC_CHECKSTATUS(method) static bool method(const NetDeviceStatus &, const NetDeviceStatus &); + +class DeviceStatusHandler : public QObject +{ + Q_OBJECT + +public: + // 获取当前所有的设备列表的状态 + static PluginState pluginState(); + + static NetDeviceStatus wiredStatus(WiredDevice * device); + static NetDeviceStatus wiredStatus(const QList &devices); + static NetDeviceStatus wirelessStatus(WirelessDevice *device); + static NetDeviceStatus wirelessStatus(const QList &devices); + static PluginState plugState(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus); + +private: + explicit DeviceStatusHandler(QObject *parent = Q_NULLPTR); + ~DeviceStatusHandler(); + +private: + DECLARE_STATIC_CHECKSTATUS(isUnknow) + DECLARE_STATIC_CHECKSTATUS(isDisabled) + DECLARE_STATIC_CHECKSTATUS(isWiredDisconnected) + DECLARE_STATIC_CHECKSTATUS(isWiredDisabled) + DECLARE_STATIC_CHECKSTATUS(isWiredConnected) + DECLARE_STATIC_CHECKSTATUS(isWiredConnecting) + DECLARE_STATIC_CHECKSTATUS(isWiredConnectNoInternet) + DECLARE_STATIC_CHECKSTATUS(isNocable) + DECLARE_STATIC_CHECKSTATUS(isWiredFailed) + DECLARE_STATIC_CHECKSTATUS(isWirelessDisconnected) + DECLARE_STATIC_CHECKSTATUS(isWirelessDisabled) + DECLARE_STATIC_CHECKSTATUS(isWirelessConnected) + DECLARE_STATIC_CHECKSTATUS(isWirelessConnecting) + DECLARE_STATIC_CHECKSTATUS(isWirelessConnectNoInternet) + DECLARE_STATIC_CHECKSTATUS(isWirelessFailed) + DECLARE_STATIC_CHECKSTATUS(isDisconnected) + DECLARE_STATIC_CHECKSTATUS(isConnected) + DECLARE_STATIC_CHECKSTATUS(isConnecting) + DECLARE_STATIC_CHECKSTATUS(isConnectNoInternet) +}; + +#endif // DEVICESTATUSHANDLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/network.qrc b/panels/dock/tray/plugins/dde-network-core/common-plugin/network.qrc new file mode 100644 index 000000000..55271263d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/network.qrc @@ -0,0 +1,80 @@ + + + resources/light/network-wired-symbolic-connecting1.svg + resources/light/network-wired-symbolic-connecting2.svg + resources/light/network-wired-symbolic-connecting3.svg + resources/light/network-wired-symbolic-connecting4.svg + resources/light/network-wired-symbolic-connecting5.svg + resources/light/network-disabled-symbolic.svg + resources/light/network-error-symbolic.svg + resources/light/network-online-symbolic.svg + resources/light/network-offline-symbolic.svg + resources/light/network-wired-symbolic.svg + resources/light/network-none-symbolic.svg + resources/light/network-warning-symbolic.svg + resources/light/wireless-background.svg + resources/light/wireless-disconnect.svg + resources/light/wireless-offline-symbolic.svg + resources/light/wireless-0-symbolic.svg + resources/light/wireless-20-symbolic.svg + resources/light/wireless-40-symbolic.svg + resources/light/wireless-60-symbolic.svg + resources/light/wireless-80-symbolic.svg + resources/light/wireless-disconnect-symbolic.svg + resources/light/security.svg + resources/light/select.svg + resources/light/disconnect.svg + resources/light/refresh.svg + resources/light/wireless-disabled-symbolic.svg + resources/light/wireless6-0-symbolic.svg + resources/light/wireless6-20-symbolic.svg + resources/light/wireless6-40-symbolic.svg + resources/light/wireless6-60-symbolic.svg + resources/light/wireless6-80-symbolic.svg + resources/light/wireless6-no-route-symbolic.svg + resources/light/wireless6-offline-symbolic.svg + resources/light/wireless6-warning-symbolic.svg + + + resources/dark/network-wired-symbolic-connecting1.svg + resources/dark/network-wired-symbolic-connecting2.svg + resources/dark/network-wired-symbolic-connecting3.svg + resources/dark/network-wired-symbolic-connecting4.svg + resources/dark/network-wired-symbolic-connecting5.svg + resources/dark/network-disabled-symbolic.svg + resources/dark/network-error-symbolic.svg + resources/dark/network-online-symbolic.svg + resources/dark/network-offline-symbolic.svg + resources/dark/network-wired-symbolic.svg + resources/dark/network-none-symbolic.svg + resources/dark/network-warning-symbolic.svg + resources/dark/wireless-background.svg + resources/dark/wireless-disconnect.svg + resources/dark/wireless-offline-symbolic.svg + resources/dark/wireless-0-symbolic.svg + resources/dark/wireless-20-symbolic.svg + resources/dark/wireless-40-symbolic.svg + resources/dark/wireless-60-symbolic.svg + resources/dark/wireless-80-symbolic.svg + resources/dark/wireless-disconnect-symbolic.svg + resources/dark/security.svg + resources/dark/select.svg + resources/dark/disconnect.svg + resources/dark/refresh.svg + resources/dark/wireless-disabled-symbolic.svg + resources/dark/wireless6-0-symbolic.svg + resources/dark/wireless6-20-symbolic.svg + resources/dark/wireless6-40-symbolic.svg + resources/dark/wireless6-60-symbolic.svg + resources/dark/wireless6-80-symbolic.svg + resources/dark/wireless6-no-route-symbolic.svg + resources/dark/wireless6-offline-symbolic.svg + resources/dark/wireless6-warning-symbolic.svg + + + resources/common/list_select.png + resources/common/list_select@2x.png + resources/common/notify_close_press.png + resources/common/notify_close_press@2x.png + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.cpp new file mode 100644 index 000000000..4f729fe63 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.cpp @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkdialog.h" +#include "networkdialog/networkpanel.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +NETWORKPLUGIN_USE_NAMESPACE + +static const QString NetworkDialogApp = "dde-network-dialog"; //网络列表执行文件 +static QMap s_FunMap = { + { "password", &NetworkDialog::sendPassword }, + { "connect", &NetworkDialog::connectNetwork }, +}; + +NetworkDialog::NetworkDialog(QObject *parent) + : QObject(parent) + , m_server(nullptr) + , m_panel(new NetworkPanel()) +{ + connect(m_panel, &NetworkPanel::passwordChanged, this, &NetworkDialog::changePassword); +} + +NetworkDialog::~NetworkDialog() +{ +} + +void NetworkDialog::setServerName(const QString &name) +{ + if (m_server) + return; + + m_serverName = name; + m_server = new QLocalServer(this); + connect(m_server, SIGNAL(newConnection()), this, SLOT(newConnectionHandler())); + m_server->setSocketOptions(QLocalServer::WorldAccessOption); + + m_server->listen(m_serverName); +} + +bool NetworkDialog::closeOnClear() const +{ + return m_panel->closeOnClear(); +} + +void NetworkDialog::setCloseOnClear(bool closeOnClear) +{ + m_panel->setCloseOnClear(closeOnClear); +} + +void NetworkDialog::clear() +{ + m_panel->clear(); +} + +QWidget *NetworkDialog::panel() +{ + return m_panel->itemApplet(); +} + +void NetworkDialog::setConnectWireless(const QString &dev, const QString &ssid, bool wait) +{ + m_connectDev = dev; + m_connectSsid = ssid; + Q_EMIT requestShow(); + // 先响应requestShow将界面显示后再显示密码输入框,否则输入框无焦点 + QTimer::singleShot(100, this, [ = ]{ + m_panel->passwordError(dev, ssid, wait); + }); +} + +void NetworkDialog::newConnectionHandler() +{ + QLocalSocket *socket = m_server->nextPendingConnection(); + connect(socket, SIGNAL(readyRead()), this, SLOT(readyReadHandler())); + connect(socket, SIGNAL(disconnected()), this, SLOT(disconnectedHandler())); + m_clients.append(socket); +} + +void NetworkDialog::disconnectedHandler() +{ + QLocalSocket *socket = static_cast(sender()); + if (socket) { + sendPassword(socket, "{}"); + m_clients.removeAll(socket); + socket->deleteLater(); + } +} + +void NetworkDialog::changePassword(const QString &key, const QString &password, bool input) +{ + QJsonObject json; + json.insert("key", key); + json.insert("password", password); + json.insert("input", input); + + QJsonDocument doc; + doc.setObject(json); + QByteArray data = doc.toJson(QJsonDocument::Compact); + + for (auto it = m_clients.begin(); it != m_clients.end(); it++) { + (*it)->write("\npassword:" + data + "\n"); + } + Q_EMIT inputPassword(key, password, input); +} + +void NetworkDialog::readyReadHandler() +{ + QLocalSocket *socket = static_cast(sender()); + if (socket) { + QByteArray allData = socket->readAll(); + allData = m_lastData + allData; + qDebug() << "Receive data from client: " << allData; + QList dataArray = allData.split('\n'); + m_lastData = dataArray.last(); + for (const QByteArray &data : dataArray) { + int keyIndex = data.indexOf(':'); + if (keyIndex != -1) { + QString key = data.left(keyIndex); + QByteArray value = data.mid(keyIndex + 1); + if (s_FunMap.contains(key)) { + (this->*s_FunMap.value(key))(socket, value); + } + } + } + } +} + +void NetworkDialog::connectNetwork(QLocalSocket *socket, const QByteArray &data) +{ + QJsonDocument doc = QJsonDocument::fromJson(data); + if (doc.isObject()) { + QJsonObject obj = doc.object(); + setConnectWireless(obj.value("dev").toString(), obj.value("ssid").toString()); + } + socket->write("\nreceive:" + data + "\n"); +} + +void NetworkDialog::sendPassword(QLocalSocket *socket, const QByteArray &data) +{ + Q_UNUSED(socket); + QByteArray sendData = "\npassword:" + data + "\n"; + for (auto it = m_clients.begin(); it != m_clients.end(); it++) { + (*it)->write(sendData); + } +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.h new file mode 100644 index 000000000..f28d10675 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.h @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDIALOG_H +#define NETWORKDIALOG_H + +#include "utils.h" + +class QWidget; +class QLocalServer; +class QLocalSocket; +class NetworkPanel; + +NETWORKPLUGIN_BEGIN_NAMESPACE + +class NetworkDialog : public QObject +{ + Q_OBJECT + +public: + explicit NetworkDialog(QObject *parent = Q_NULLPTR); + ~NetworkDialog() override; + +Q_SIGNALS: + void requestShow(); + void inputPassword(const QString &key, const QString &password, bool input); + +public: + QWidget *panel(); + void setConnectWireless(const QString &dev, const QString &ssid, bool wait = true); + void setServerName(const QString &name); + + bool closeOnClear() const; + void setCloseOnClear(bool closeOnClear); + void clear(); + +private Q_SLOTS: + void newConnectionHandler(); + void readyReadHandler(); + void disconnectedHandler(); + void changePassword(const QString &key, const QString &password, bool input); + +public: + void connectNetwork(QLocalSocket *socket, const QByteArray &data); + void sendPassword(QLocalSocket *socket, const QByteArray &data); + +private: + QString m_connectDev; + QString m_connectSsid; + QByteArray m_lastData; + + QLocalServer *m_server; + QList m_clients; + QString m_serverName; + + NetworkPanel *m_panel; +}; + +NETWORKPLUGIN_END_NAMESPACE +#endif // NETWORKDIALOG_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.cpp new file mode 100644 index 000000000..d21b72b43 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.cpp @@ -0,0 +1,701 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "netitem.h" +#include "wirelessconnect.h" +#include "../thememanager.h" +#include "../networkpanel.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define SWITCH_WIDTH 50 +#define SWITCH_HEIGHT 24 + +DWIDGET_USE_NAMESPACE + +#define MAXTEXTWIDTH 180 +/** + * 单个列表项的基类 + */ +NetItem::NetItem(QWidget *parent) + : QObject(parent) + , m_standardItem(new DStandardItem) + , m_parentWidget(parent) +{ + m_standardItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + m_standardItem->setData(NetConnectionType::UnConnected, ConnectionStatusRole); + m_standardItem->setBackground(Qt::transparent); + m_standardItem->setTextColorRole(DPalette::BrightText); +} + +NetItem::~NetItem() +{ +} + +DStandardItem *NetItem::standardItem() +{ + return m_standardItem; +} + +/** + * @brief baseControllItem::baseControllItem + * 总线控制器 + */ +DeviceControllItem::DeviceControllItem(const DeviceType &deviceType, QWidget *parent) + : NetItem(parent) + , m_deviceType(deviceType) +{ + initItemText(); +} + +DeviceControllItem::~DeviceControllItem() +{ +} + +void DeviceControllItem::setDevices(const QList &devices) +{ + m_devices.clear(); + for (NetworkDeviceBase *device : devices) { + if (m_deviceType == device->deviceType()) { + connect(device, &NetworkDeviceBase::destroyed, this, [ this, device ] { + m_devices.removeOne(device); + standardItem()->setData(QVariant::fromValue>(m_devices), DeviceDataRole); + }); + m_devices << device; + } + } + + updateView(); +} + +DeviceType DeviceControllItem::deviceType() +{ + return m_deviceType; +} + +void DeviceControllItem::updateView() +{ + // 更新状态显示 + standardItem()->setData(QVariant::fromValue>(m_devices), DeviceDataRole); +} + +NetItemType DeviceControllItem::itemType() +{ + return DeviceControllViewItem; +} + +void DeviceControllItem::initItemText() +{ + // 创建左侧的切换文本 + standardItem()->setSizeHint(QSize(-1, 46)); + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setData(NetItemType::DeviceControllViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(m_deviceType), NetItemRole::DeviceTypeRole); + standardItem()->setFontSize(DFontSizeManager::T4); + + if (m_deviceType == DeviceType::Wireless) + standardItem()->setText(tr("Wireless Network")); + else + standardItem()->setText(tr("Wired Network")); +} + +WiredControllItem::WiredControllItem(QWidget *parent, WiredDevice *device) + : NetItem(parent) + , m_device(device) +{ + standardItem()->setSizeHint(QSize(-1, 46)); + standardItem()->setText(device->deviceName()); + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setData(NetItemType::WiredControllViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wired), NetItemRole::DeviceTypeRole); + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setFontSize(DFontSizeManager::T5); + connect(m_device, &WiredDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +WiredControllItem::~WiredControllItem() +{ +} + +WiredDevice *WiredControllItem::device() +{ + return m_device; +} + +void WiredControllItem::updateView() +{ + standardItem()->setText(m_device->deviceName()); +} + +NetItemType WiredControllItem::itemType() +{ + return WiredControllViewItem; +} + +WirelessControllItem::WirelessControllItem(QWidget *parent, WirelessDevice *device) + : NetItem(parent) + , m_device(device) +{ + standardItem()->setSizeHint(QSize(-1, 46)); + standardItem()->setText(device->deviceName()); + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setData(NetItemType::WirelessControllViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wireless), NetItemRole::DeviceTypeRole); + standardItem()->setFontSize(DFontSizeManager::T5); + connect(m_device, &WirelessDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +WirelessControllItem::~WirelessControllItem() +{ +} + +WirelessDevice *WirelessControllItem::device() +{ + return m_device; +} + +void WirelessControllItem::updateView() +{ + standardItem()->setText(m_device->deviceName()); +} + +NetItemType WirelessControllItem::itemType() +{ + return WirelessControllViewItem; +} + +WiredItem::WiredItem(QWidget *parent, WiredDevice *device, WiredConnection *connection) + : NetItem(parent) + , m_connection(connection) + , m_device(device) +{ + initUi(); +} + +WiredItem::~WiredItem() +{ +} + +WiredConnection *WiredItem::connection() +{ + return m_connection; +} + +QString WiredItem::symbolicIcon(const bool &connected) const +{ + QString icon = connected ? QString("network-wired-symbolic") : QString("network-none-symbolic"); + return ThemeManager::ref().getIcon(icon); +} + +void WiredItem::updateView() +{ + // 更新显示的文本 + QFontMetrics ftm(standardItem()->font()); + QString displayText = ftm.elidedText(m_connection->connection()->id(), Qt::TextElideMode::ElideRight, MAXTEXTWIDTH); + standardItem()->setText(displayText); + // 更新当前的连接状态 + QString connectionIconFile; + switch (m_connection->status()) { + case ConnectionStatus::Activating: + standardItem()->setData(NetConnectionType::Connecting, ConnectionStatusRole); + connectionIconFile = symbolicIcon(false); + break; + case ConnectionStatus::Activated: + standardItem()->setData(NetConnectionType::Connected, ConnectionStatusRole); + connectionIconFile = symbolicIcon(true); + break; + default: + standardItem()->setData(NetConnectionType::UnConnected, ConnectionStatusRole); + connectionIconFile = symbolicIcon(false); + break; + } + + // 设置左侧的连接图标 + m_connectionIconAction->setIcon(QIcon(connectionIconFile)); +} + +NetItemType WiredItem::itemType() +{ + return WiredViewItem; +} + +void WiredItem::initUi() +{ + standardItem()->setSizeHint(QSize(-1, 36)); + + // 占位的 + DViewItemAction *emptyAction = new DViewItemAction(Qt::AlignLeft | Qt::AlignVCenter, + QSize(20, 20), QSize(20, 20), false); + + m_connectionIconAction = new DViewItemAction(Qt::AlignLeft | Qt::AlignVCenter, + QSize(20, 20), QSize(8, 20), false); + + standardItem()->setActionList(Qt::LeftEdge, { emptyAction, m_connectionIconAction }); + updateView(); + + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setFontSize(DFontSizeManager::T6); + standardItem()->setData(NetItemType::WiredViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setData(QVariant::fromValue(static_cast(m_connection)), NetItemRole::DataRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wired), NetItemRole::DeviceTypeRole); + connect(m_device, &WiredDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +void WiredItem::connectNetwork() +{ + if (m_connection && !m_connection->connected()) { + m_device->connectNetwork(m_connection); + } +} + +WirelessItem::WirelessItem(QWidget *parent, WirelessDevice *device, AccessPoints *ap, NetworkPanel *panel) + : NetItem(parent) + , m_accessPoint(ap) + , m_device(device) + , m_securityAction(nullptr) + , m_wifiLabel(nullptr) + , m_connectionAction(nullptr) + , m_loadingStat(nullptr) + , m_connectionWidget(nullptr) + , m_stackWidget(nullptr) + , m_expandItem(nullptr) + , m_topItem(nullptr) + , m_passwdEdit(nullptr) + , m_ssidEdit(nullptr) + , m_wirelessConnect(new WirelessConnect(this, device, ap)) + , m_connectButton(nullptr) + , m_panel(panel) +{ + initUi(parent); + initConnection(); + if (m_accessPoint) { + m_wirelessConnect->setSsid(ap->ssid()); + QFontMetrics ftm(standardItem()->font()); + QString displayText = ftm.elidedText(m_accessPoint->ssid(), Qt::TextElideMode::ElideRight, MAXTEXTWIDTH); + standardItem()->setText(displayText); + } else { + m_wifiLabel->setVisible(false); + m_securityAction->setVisible(false); + standardItem()->setText(tr("Connect to hidden network")); + } +} + +WirelessItem::~WirelessItem() +{ + m_stackWidget->setParent(nullptr); + m_stackWidget->deleteLater(); +} + +const AccessPoints *WirelessItem::accessPoint() +{ + return m_accessPoint; +} + +const WirelessDevice *WirelessItem::wirelessDevice() +{ + return m_device; +} + +void WirelessItem::updateView() +{ + updateSrcirityIcon(); + updateWifiIcon(); + updateConnectionStatus(); +} + +NetItemType WirelessItem::itemType() +{ + return WirelessViewItem; +} + +QString WirelessItem::getStrengthStateString(int strength) +{ + if (5 >= strength) + return "0"; + + if (30 >= strength) + return "20"; + + if (55 >= strength) + return "40"; + + if (65 >= strength) + return "60"; + + return "80"; +} + +void WirelessItem::initUi(QWidget *parent) +{ + m_expandItem = new DViewItemAction(Qt::AlignBottom, QSize(PANELWIDTH, 20), QSize(PANELWIDTH, 20), false); + m_stackWidget = new DStackedWidget(parent); + // 初始化展开输入控件 + initExpandUi(); + m_expandItem->setWidget(m_stackWidget); + standardItem()->setActionList(Qt::BottomEdge, { m_expandItem }); + m_expandItem->setVisible(false); + // 左侧的加密图标 + m_securityAction = new DViewItemAction(Qt::AlignLeft , QSize(20, 35), QSize(20, 35), false); + updateSrcirityIcon(); + // 绘制WiFi图标 + m_wifiLabel = new DViewItemAction(Qt::AlignLeft , QSize(20, 35), QSize(8, 35), false); + updateWifiIcon(); + + standardItem()->setSizeHint(QSize(-1, 36)); + standardItem()->setActionList(Qt::LeftEdge, { m_securityAction, m_wifiLabel }); + + m_topItem = new DViewItemAction(Qt::AlignTop, QSize(-1, 1), QSize(-1, 1), false); + standardItem()->setActionList(Qt::TopEdge, { m_topItem }); + m_topItem->setVisible(false); + // 绘制右侧的连接图标 + standardItem()->setFlags(Qt::ItemIsEnabled); + updateConnectionStatus(); + if (m_accessPoint) { + standardItem()->setData(NetItemType::WirelessViewItem, NetItemRole::TypeRole); + } else { + standardItem()->setData(NetItemType::WirelessHiddenViewItem, NetItemRole::TypeRole); + } + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wireless), NetItemRole::DeviceTypeRole); + standardItem()->setData(QVariant::fromValue(static_cast(m_accessPoint)), NetItemRole::DataRole); + standardItem()->setFontSize(DFontSizeManager::T6); + connect(m_device, &WirelessDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +void WirelessItem::initConnection() +{ + connect(m_wirelessConnect, &WirelessConnect::passwordError, this, &WirelessItem::onInputPassword, Qt::QueuedConnection); +} + +void WirelessItem::updateSrcirityIcon() +{ + if (m_accessPoint && m_accessPoint->secured()) { + QString srcirityIcon = ThemeManager::ref().getIcon("security"); + // 更新加密图标 + m_securityAction->setIcon(QIcon(srcirityIcon)); + } else { + m_securityAction->setIcon(QIcon()); + } +} + +void WirelessItem::updateWifiIcon() +{ + if (!m_accessPoint) + return; + + bool isWlan6 = (m_accessPoint->type() == AccessPoints::WlanType::wlan6); + QString strength = getStrengthStateString(m_accessPoint->strength()); + QString iconRes = QString(isWlan6 ? QString("wireless6-%1-symbolic") + : QString("wireless-%1-symbolic")).arg(strength); + QString icon = ThemeManager::ref().getIcon(iconRes); + m_wifiLabel->setIcon(QIcon(icon)); +} + +void WirelessItem::updateConnectionStatus() +{ + if (!m_accessPoint) + return; + + switch (m_accessPoint->status()) { + case ConnectionStatus::Activating: + standardItem()->setData(NetConnectionType::Connecting, ConnectionStatusRole); + break; + case ConnectionStatus::Activated: + standardItem()->setData(NetConnectionType::Connected, ConnectionStatusRole); + expandWidget(ExpandWidget::Hide); + break; + default: + standardItem()->setData(NetConnectionType::UnConnected, ConnectionStatusRole); + break; + } +} + +void WirelessItem::onConnection() +{ + if (m_device->activeAccessPoints() == m_accessPoint) + m_device->disconnectNetwork(); +} + +void WirelessItem::expandWidget(ExpandWidget type, bool autoDisconnect) +{ + switch (type) { + case ExpandWidget::Hide: + if(m_expandItem->isVisible()) { + m_expandItem->setVisible(false); + m_topItem->setVisible(false); + standardItem()->setSizeHint(QSize(-1, 36)); + if (m_accessPoint) { + m_panel->changePassword(m_accessPoint->ssid(), QString(), false); + if(autoDisconnect && m_accessPoint->status() == ConnectionStatus::Activating) { + m_device->disconnectNetwork(); + } + } + m_ssidEdit->lineEdit()->clear(); + m_passwdEdit->clear(); + } + break; + case ExpandWidget::ShowSSID: + m_expandItem->setVisible(true); + m_topItem->setVisible(true); + standardItem()->setSizeHint(QSize(-1, 130)); + m_stackWidget->setCurrentIndex(type); + m_ssidEdit->lineEdit()->setFocus(); + QTimer::singleShot(50, m_ssidEdit->lineEdit(), SLOT(setFocus())); + break; + case ExpandWidget::ShowPassword: + // 如果当前需要输入密码的ap不是处理正在连接状态,则隐藏起来,目的是为了处理在控制中心快速切换ap导致连接状态错误的问题 + const QString ssidWaitingForPassword = m_panel->ssidWaitingForPassword(); + if (m_accessPoint && ssidWaitingForPassword == m_accessPoint->ssid()) { + if (m_accessPoint->status() != ConnectionStatus::Activating) { + expandWidget(ExpandWidget::Hide); + break; + } + // 有时候显示密码输入框时, ap的status还没有来得变更,有可能会在几毫秒(不确定)后变更,需要绑定信号进行处理 + connect(m_accessPoint, &AccessPoints::connectionStatusChanged, this, &WirelessItem::onApConnectionStatusChanged, Qt::UniqueConnection); + } + m_expandItem->setVisible(true); + m_topItem->setVisible(true); + standardItem()->setSizeHint(QSize(-1, 130)); + m_stackWidget->setCurrentIndex(type); + m_passwdEdit->lineEdit()->setFocus(); + checkInputValid(); + m_passwdEdit->setAlert(!m_passwdEdit->text().isEmpty()); + QTimer::singleShot(50, m_passwdEdit->lineEdit(), SLOT(setFocus())); + break; + } + emit sizeChanged(); +} + +void WirelessItem::onApConnectionStatusChanged(ConnectionStatus status) +{ + if (status != ConnectionStatus::Activating && expandVisible()) { + expandWidget(ExpandWidget::Hide); + } +} + +void WirelessItem::createPasswordEdit() +{ + // 密码输入窗 + DWidget *passwdWidget = new DWidget(m_stackWidget); + m_passwdEdit = new DPasswordEdit(passwdWidget); + m_passwdEdit->lineEdit()->setPlaceholderText(tr("Password")); + m_passwdEdit->lineEdit()->setMaxLength(256); + m_passwdEdit->setContextMenuPolicy(Qt::NoContextMenu); + m_passwdEdit->setFixedHeight(36); + m_passwdEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + DPushButton *cancelButtion = new DPushButton(tr("Cancel", "button"), passwdWidget); // 取消 + m_connectButton = new DSuggestButton(tr("Connect", "button"), passwdWidget); // 连接 + cancelButtion->setFixedHeight(36); + cancelButtion->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_connectButton->setFixedHeight(36); + m_connectButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + QHBoxLayout *line2 = new QHBoxLayout; + line2->setContentsMargins(0, 0, 0, 0); + + QVBoxLayout *layout = new QVBoxLayout(passwdWidget); + layout->setContentsMargins(0, 0, 10, 10); + line2->addWidget(cancelButtion); + line2->addSpacing(3); + line2->addWidget(m_connectButton); + + layout->addWidget(m_passwdEdit); + layout->addSpacing(10); + layout->addLayout(line2); + layout->addSpacing(7); + + passwdWidget->setLayout(layout); + m_stackWidget->addWidget(passwdWidget); + + connect(cancelButtion, &DPushButton::clicked, this, &WirelessItem::onCancel); + connect(m_connectButton, &DPushButton::clicked, this, &WirelessItem::onConnectNetwork); + connect(m_passwdEdit->lineEdit(), &QLineEdit::returnPressed, this, &WirelessItem::onConnectNetwork); + connect(m_passwdEdit->lineEdit(), &QLineEdit::textChanged, this, &WirelessItem::checkInputValid); + ThemeManager::ref().updateInputStyle(m_passwdEdit); +} + +void WirelessItem::createSsidEdit() +{ + // ssid输入窗 + DWidget *ssidWidget = new DWidget(m_stackWidget); + m_ssidEdit = new DLineEdit(ssidWidget); + m_ssidEdit->setPlaceholderText(tr("Name (SSID)")); + m_ssidEdit->lineEdit()->setMaxLength(256); + m_ssidEdit->setContextMenuPolicy(Qt::NoContextMenu); + m_ssidEdit->setFixedHeight(36); + m_ssidEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + DPushButton *cancelButtion = new DPushButton(tr("Cancel", "button"), ssidWidget); // 取消 + DPushButton *connectButton = new DSuggestButton(tr("Connect", "button"), ssidWidget); // 连接 + cancelButtion->setFixedHeight(36); + cancelButtion->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + connectButton->setFixedHeight(36); + connectButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + QHBoxLayout *line2 = new QHBoxLayout; + line2->setContentsMargins(0, 0, 0, 0); + + QVBoxLayout *layout = new QVBoxLayout(ssidWidget); + layout->setContentsMargins(0, 0, 10, 10); + line2->addWidget(cancelButtion); + line2->addSpacing(3); + line2->addWidget(connectButton); + + layout->addWidget(m_ssidEdit); + layout->addSpacing(10); + layout->addLayout(line2); + layout->addSpacing(7); + + ssidWidget->setLayout(layout); + m_stackWidget->addWidget(ssidWidget); + + connect(cancelButtion, &DPushButton::clicked, this, &WirelessItem::onCancel); + connect(connectButton, &DPushButton::clicked, this, &WirelessItem::onConnectHidden); + connect(m_ssidEdit->lineEdit(), &QLineEdit::returnPressed, this, &WirelessItem::onConnectHidden); + ThemeManager::ref().updateInputStyle(m_ssidEdit); +} + +void WirelessItem::initExpandUi() +{ + createPasswordEdit(); + createSsidEdit(); + m_stackWidget->setContentsMargins(0, 0, 0, 0); + m_stackWidget->setFixedSize(PANELWIDTH - 10, 92); +} + +void WirelessItem::connectNetwork() +{ + if (NetConnectionType::UnConnected == standardItem()->data(ConnectionStatusRole)) { + // 密码框未显示前尝试直接连接 + if (!m_expandItem->isVisible()) { + if (m_accessPoint) { + m_wirelessConnect->connectNetwork(); + } else { + expandWidget(ExpandWidget::ShowSSID); + } + } + } +} + +void WirelessItem::onConnectNetwork() +{ + QString password = m_passwdEdit->text(); + // 输入无效在checkInputValid里已判断 + if (m_wirelessConnect->passwordIsValid(password)) { + if (m_accessPoint) { + if (m_panel->changePassword(m_accessPoint->ssid(), password, true)) { + expandWidget(ExpandWidget::Hide, false); + return; + } + } + m_wirelessConnect->connectNetworkPassword(m_passwdEdit->text()); + expandWidget(ExpandWidget::Hide, false); + } +} + +void WirelessItem::onInputPassword(const QString oldPassword) +{ + m_passwdEdit->setText(oldPassword); + expandWidget(ExpandWidget::ShowPassword); +} + +void WirelessItem::expandPasswordInput() +{ + m_wirelessConnect->getoldPassword(); +} + +void WirelessItem::onAirplaneModeChanged(bool airplaneModeEnabled) +{ + m_stackWidget->setDisabled(airplaneModeEnabled); +} + +void WirelessItem::onConnectHidden() +{ + QString ssid = m_ssidEdit->text(); + if (!ssid.isEmpty()) { + expandWidget(ExpandWidget::Hide, false); + m_wirelessConnect->setSsid(ssid); + m_wirelessConnect->connectNetwork(); + } +} + +void WirelessItem::checkInputValid() +{ + bool isValid = m_wirelessConnect->passwordIsValid(m_passwdEdit->text()); + + m_passwdEdit->setAlert(false); + m_connectButton->setEnabled(isValid); +} + +bool WirelessItem::expandVisible() +{ + return m_expandItem->isVisible(); +} + +const QDateTime WirelessItem::timeStamp(WirelessConnection *connection) const +{ + NetworkManager::Connection::Ptr connect(new NetworkManager::Connection(connection->connection()->path())); + return connect->settings()->timestamp(); +} + +void WirelessItem::onCancel() +{ + if (m_accessPoint && (m_accessPoint->status() == ConnectionStatus::Activating || m_accessPoint->ssid() == m_device->activeAp())) { + m_device->disconnectNetwork(); + QList connections = m_device->items(); + // 断开连接后,找到最后一次连接的热点 + WirelessConnection *lastConnection = nullptr; + for (WirelessConnection *conn : connections) { + if (conn->accessPoints() == m_accessPoint) + continue; + + QDateTime ts = timeStamp(conn); + if (!ts.isValid()) + continue; + + if (!lastConnection || timeStamp(lastConnection) < ts) + lastConnection = conn; + } + + if (lastConnection) + m_device->connectNetwork(lastConnection->accessPoints()); + + } + + this->expandWidget(ExpandWidget::Hide); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.h new file mode 100644 index 000000000..fb8176879 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.h @@ -0,0 +1,249 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETITEM_H +#define NETITEM_H + +#include + +#include +#include +#include +#include + +#include + +class NetworkDevice; +class NetItem; +class WirelessConnect; +class QLabel; +class QPushButton; +class NetworkPanel; + +namespace dde { + namespace network { + class NetworkDeviceBase; + class WiredDevice; + class WirelessDevice; + class AccessPoints; + class WiredConnection; + class WirelessConnection; + enum class DeviceType; + } // namespace network +} // namespace dde + +using namespace dde::network; +namespace Dtk { + namespace Widget { + class DListView; + class DViewItemAction; + class DLoadingIndicator; + class DSpinner; + class DPasswordEdit; + class DLineEdit; + class DStandardItem; + } // namespace Widget +} // namespace Dtk + +DWIDGET_USE_NAMESPACE + +enum NetItemRole { + TypeRole = Qt::UserRole + 100, + DeviceDataRole, + DataRole, + ConnectionStatusRole, + MouseInBoundingRole, + DeviceTypeRole, + sortRole +}; + +#define PANELWIDTH 300 + +enum NetItemType { + DeviceControllViewItem = 0, // 总控开关 + WirelessControllViewItem, // 无线网卡开关 + WirelessViewItem, // 无线列表 + WirelessHiddenViewItem, // 无线隐藏列表 + WiredControllViewItem, // 有线网卡开关 + WiredViewItem // 有线列表 +}; + +enum NetConnectionType { + UnConnected = 0, // 未连接 + Connecting, // 正在连接 + Connected // 已连接 +}; + +class NetItem : public QObject +{ + Q_OBJECT + +public: + NetItem(QWidget *parent); + virtual ~NetItem(); + + virtual DStandardItem *standardItem(); + virtual void updateView() {} + virtual NetItemType itemType() = 0; + +private: + DStandardItem *m_standardItem; + QWidget *m_parentWidget; +}; + +class DeviceControllItem : public NetItem +{ + Q_OBJECT + +public: + DeviceControllItem(const DeviceType &deviceType, QWidget *parent); + ~DeviceControllItem() Q_DECL_OVERRIDE; + + void setDevices(const QList &devices); + DeviceType deviceType(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + +private: + void initItemText(); + +private: + QList m_devices; + DeviceType m_deviceType; +}; + +class WiredControllItem : public NetItem +{ + Q_OBJECT + +public: + WiredControllItem(QWidget *parent, WiredDevice *device); + ~WiredControllItem() Q_DECL_OVERRIDE; + + WiredDevice *device(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + +private: + WiredDevice *m_device; +}; + +class WirelessControllItem : public NetItem +{ + Q_OBJECT + +public: + WirelessControllItem(QWidget *parent, WirelessDevice *device); + ~WirelessControllItem() Q_DECL_OVERRIDE; + + WirelessDevice *device(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + +private: + WirelessDevice *m_device; +}; + +class WiredItem : public NetItem +{ + Q_OBJECT + +public: + WiredItem(QWidget *parent, WiredDevice *device, WiredConnection *connection); + ~WiredItem() Q_DECL_OVERRIDE; + + WiredConnection *connection(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + void connectNetwork(); + +private: + void initUi(); + QString symbolicIcon(const bool &connected) const; + void initConnection(); + +private: + WiredConnection *m_connection; + WiredDevice *m_device; + DViewItemAction *m_connectionIconAction; +}; + +class WirelessItem : public NetItem +{ + Q_OBJECT + +Q_SIGNALS: + void sizeChanged(); + +public: + enum ExpandWidget { + Hide = -1, + ShowPassword, + ShowSSID, + }; + +public: + WirelessItem(QWidget *parent, WirelessDevice *device, AccessPoints *ap, NetworkPanel *panel); + ~WirelessItem() Q_DECL_OVERRIDE; + + const AccessPoints *accessPoint(); + const WirelessDevice *wirelessDevice(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + static QString getStrengthStateString(int strength); + void expandWidget(ExpandWidget type, bool autoDisconnect = true); + void connectNetwork(); + void expandPasswordInput(); + bool expandVisible(); + +public Q_SLOTS: + void onAirplaneModeChanged(bool airplaneModeEnabled); + void onCancel(); + +private: + void initUi(QWidget *parent); + void initConnection(); + void updateSrcirityIcon(); + void updateWifiIcon(); + void updateConnectionStatus(); + void createPasswordEdit(); + void createSsidEdit(); + void initExpandUi(); + const QDateTime timeStamp(WirelessConnection *connection) const; + +private Q_SLOTS: + void onConnection(); + void onConnectNetwork(); + void onInputPassword(const QString oldPassword); + void onConnectHidden(); + void checkInputValid(); + void onApConnectionStatusChanged(ConnectionStatus); + +private: + AccessPoints *m_accessPoint; + WirelessDevice *m_device; + DViewItemAction *m_securityAction; + DViewItemAction *m_wifiLabel; + DViewItemAction *m_connectionAction; + DSpinner *m_loadingStat; + + QWidget *m_connectionWidget; + + DStackedWidget *m_stackWidget; + DViewItemAction *m_expandItem; + DViewItemAction *m_topItem; // 占空间 + + DPasswordEdit *m_passwdEdit; + DLineEdit *m_ssidEdit; + + WirelessConnect *m_wirelessConnect; + DPushButton *m_connectButton; + NetworkPanel *m_panel; +}; + +Q_DECLARE_METATYPE(NetItemType) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(DeviceType) + +#endif // NETWORKAPPLETMODEL_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.cpp new file mode 100644 index 000000000..676c614b0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.cpp @@ -0,0 +1,276 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "wirelessconnect.h" + +#include "wirelessdevice.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace dde::network; +using namespace NetworkManager; + +WirelessConnect::WirelessConnect(QObject *parent, dde::network::WirelessDevice *device, dde::network::AccessPoints *ap) + : QObject(parent) + , m_device(device) + , m_accessPoint(ap) + , m_needUpdate(false) +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); +} + +WirelessConnect::~WirelessConnect() +{ +} + +void WirelessConnect::setSsid(const QString &ssid) +{ + m_ssid = ssid; + m_connectionSettings.clear(); +} + +bool WirelessConnect::passwordIsValid(const QString &password) +{ + WirelessSecuritySetting::KeyMgmt keyMgmt = WirelessSecuritySetting::WpaPsk; + if (m_connectionSettings) { + WirelessSecuritySetting::Ptr wsSetting = m_connectionSettings->setting(Setting::SettingType::WirelessSecurity).staticCast(); + keyMgmt = wsSetting->keyMgmt(); + } else { + keyMgmt = getKeyMgmtByAp(m_accessPoint); + } + if (keyMgmt == WirelessSecuritySetting::KeyMgmt::Wep) { + return wepKeyIsValid(password, WirelessSecuritySetting::WepKeyType::Passphrase); + } + return wpaPskIsValid(password); +} + +WirelessSecuritySetting::KeyMgmt WirelessConnect::getKeyMgmtByAp(dde::network::AccessPoints *ap) +{ + if (nullptr == ap) { + return WirelessSecuritySetting::WpaPsk; + } + AccessPoint::Ptr nmAp(new AccessPoint(ap->path())); + AccessPoint::Capabilities capabilities = nmAp->capabilities(); + AccessPoint::WpaFlags wpaFlags = nmAp->wpaFlags(); + AccessPoint::WpaFlags rsnFlags = nmAp->rsnFlags(); + + WirelessSecuritySetting::KeyMgmt keyMgmt = WirelessSecuritySetting::KeyMgmt::WpaNone; + + if (capabilities.testFlag(AccessPoint::Capability::Privacy) && !wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmtPsk) && !wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmt8021x)) { + keyMgmt = WirelessSecuritySetting::KeyMgmt::Wep; + } + + if (wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmtPsk) || rsnFlags.testFlag(AccessPoint::WpaFlag::KeyMgmtPsk)) { + keyMgmt = WirelessSecuritySetting::KeyMgmt::WpaPsk; + } + + // 判断是否是wpa3加密的,因为wpa3加密方式,实际上是wpa2的扩展,所以其中会包含KeyMgmtPsk枚举值 + if (wpaFlags.testFlag(NetworkManager::AccessPoint::WpaFlag::KeyMgmtSAE) || rsnFlags.testFlag(NetworkManager::AccessPoint::WpaFlag::KeyMgmtSAE)) { + keyMgmt = NetworkManager::WirelessSecuritySetting::KeyMgmt::SAE; + } + + if (wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmt8021x) || rsnFlags.testFlag(AccessPoint::WpaFlag::KeyMgmt8021x)) { + keyMgmt = WirelessSecuritySetting::KeyMgmt::WpaEap; + } + return keyMgmt; +} + +void WirelessConnect::initConnection() +{ + // 隐藏网络直接创建settings + if (m_accessPoint) { + NetworkManager::Connection::Ptr conn; + for (ActiveConnection::Ptr con : NetworkManager::activeConnections()) { + if (con->type() != ConnectionSettings::ConnectionType::Wireless || con->id() != m_ssid) + continue; + + NetworkManager::ConnectionSettings::Ptr connSettings = con->connection()->settings(); + NetworkManager::WirelessSetting::Ptr wSetting = connSettings->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + QString settingMacAddress = wSetting->macAddress().toHex().toUpper(); + QString deviceMacAddress = m_device->realHwAdr().remove(":"); + if (!settingMacAddress.isEmpty() && settingMacAddress != deviceMacAddress) + continue; + + conn = findConnectionByUuid(con->uuid()); + break; + } + + if (conn.isNull()) { + for (auto item : m_device->items()) { + if (item->connection()->ssid() != m_ssid) + continue; + + QString uuid = item->connection()->uuid(); + if (!uuid.isEmpty()) { + conn = findConnectionByUuid(uuid); + if (!conn.isNull() && conn->isValid()) { + break; + } + } + } + } + if (!conn.isNull() && conn->isValid()) { + m_connectionSettings = conn->settings(); + } + } + // 没连接过的需要新建连接 + if (m_connectionSettings.isNull()) { + m_connectionSettings = QSharedPointer(new ConnectionSettings(ConnectionSettings::ConnectionType::Wireless)); + // 创建uuid + QString uuid = m_connectionSettings->createNewUuid(); + while (findConnectionByUuid(uuid)) { + qint64 second = QDateTime::currentDateTime().toSecsSinceEpoch(); + uuid.replace(24, QString::number(second).length(), QString::number(second)); + } + m_connectionSettings->setUuid(uuid); + m_connectionSettings->setId(m_ssid); + if (!m_accessPoint) { + m_connectionSettings->setting(Setting::SettingType::Wireless).staticCast()->setHidden(true); + } + qInfo() << "create connect:" << m_ssid << uuid << m_accessPoint; + if (m_accessPoint) { + m_connectionSettings->setting(Setting::Security8021x).staticCast()->setPasswordFlags(Setting::AgentOwned); + WirelessSecuritySetting::Ptr wsSetting = m_connectionSettings->setting(Setting::WirelessSecurity).dynamicCast(); + WirelessSecuritySetting::KeyMgmt keyMgmt = getKeyMgmtByAp(m_accessPoint); + if (keyMgmt != WirelessSecuritySetting::KeyMgmt::WpaNone) { + wsSetting->setKeyMgmt(keyMgmt); + if (keyMgmt == WirelessSecuritySetting::KeyMgmt::Wep) { + wsSetting->setWepKeyFlags(Setting::None); + } else if (keyMgmt == WirelessSecuritySetting::KeyMgmt::WpaPsk || keyMgmt == WirelessSecuritySetting::KeyMgmt::SAE) { + wsSetting->setPskFlags(Setting::None); + } + wsSetting->setInitialized(true); + } + } + WirelessSetting::Ptr wirelessSetting = m_connectionSettings->setting(Setting::Wireless).dynamicCast(); + wirelessSetting->setSsid(m_ssid.toUtf8()); + wirelessSetting->setInitialized(true); + m_needUpdate = true; + } +} + +void WirelessConnect::setPassword(const QString &password) +{ + WirelessSecuritySetting::Ptr wsSetting = m_connectionSettings->setting(Setting::SettingType::WirelessSecurity).staticCast(); + bool isHidden = m_connectionSettings->setting(Setting::SettingType::Wireless).staticCast()->hidden(); + WirelessSecuritySetting::KeyMgmt keyMgmt = isHidden ? getKeyMgmtByAp(m_accessPoint) : wsSetting->keyMgmt(); + wsSetting->setKeyMgmt(keyMgmt); + if (keyMgmt == WirelessSecuritySetting::KeyMgmt::Wep) { + wsSetting->setWepKey0(password); + } else if (keyMgmt == WirelessSecuritySetting::KeyMgmt::WpaPsk || keyMgmt == WirelessSecuritySetting::KeyMgmt::SAE) { + + wsSetting->setPsk(password); + + if (isHidden && keyMgmt == WirelessSecuritySetting::KeyMgmt::WpaPsk) { + wsSetting->setAuthAlg(WirelessSecuritySetting::AuthAlg::Open); + } + } + wsSetting->setInitialized(true); + m_needUpdate = true; +} + +/** + * @brief WirelessConnect::hasPassword + * @return 是否需要密码 + */ +bool WirelessConnect::hasPassword() +{ + if (m_accessPoint && m_accessPoint->secured()) { + // 已有Connection则尝试直接连接 + NetworkManager::Connection::Ptr conn = findConnectionByUuid(m_connectionSettings->uuid()); + return conn.isNull(); + } + + return (!m_accessPoint || m_accessPoint->secured()); +} + +void WirelessConnect::connectNetwork() +{ + initConnection(); + // 隐藏网络先尝试无密码连接 + if (m_accessPoint) { + if ((hasPassword())) { + emit passwordError(QString()); + return; + } + } + activateConnection(); +} + +void WirelessConnect::connectNetworkPassword(const QString password) +{ + initConnection(); + setPassword(password); + activateConnection(); +} + +void WirelessConnect::activateConnection() +{ + m_device->disconnectNetwork(); + NetworkManager::Connection::Ptr conn; + QString id = m_connectionSettings->id(); + ConnectionSettings::ConnectionType type = m_connectionSettings->connectionType(); + for (auto it : NetworkManager::listConnections()) { + if (type != it->settings()->connectionType() || id != it->name()) + continue; + + NetworkManager::WirelessSetting::Ptr wSetting = it->settings()->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + const QString setingMacAddress = wSetting->macAddress().toHex().toUpper(); + const QString deviceMacAddress = m_device->realHwAdr().remove(":").toUpper(); + if (!setingMacAddress.isEmpty() && setingMacAddress != deviceMacAddress) + continue; + + m_connectionSettings->setUuid(it->uuid()); + conn = it; + break; + } + + QString accessPointPath; + if (m_accessPoint) { + accessPointPath = m_accessPoint->path(); + } + if (conn.isNull()) { + conn = findConnectionByUuid(m_connectionSettings->uuid()); + } + if (conn.isNull()) { + qInfo() << "addAndActivateConnection" << m_device->path() << accessPointPath; + addAndActivateConnection(m_connectionSettings->toMap(), m_device->path(), accessPointPath); + return; + } + // 隐藏网络或设置过密码的需要update + if (m_needUpdate) { + m_needUpdate = false; + QDBusPendingReply<> reply; + reply = conn->update(m_connectionSettings->toMap()); + reply.waitForFinished(); + if (reply.isError()) { + qInfo() << "error occurred while updating the connection" << reply.error(); + return; + } + } + qInfo() << "activateConnection" << conn->path() << m_device->path() << accessPointPath; + NetworkManager::activateConnection(conn->path(), m_device->path(), accessPointPath); +} + +void WirelessConnect::getoldPassword() +{ + // 旧密码不展示 + emit passwordError(QString()); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.h new file mode 100644 index 000000000..da4c5b865 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.h @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef WIRELESSCONNECT_H +#define WIRELESSCONNECT_H + +#include +#include +#include + +namespace dde { + namespace network { + class NetworkDeviceBase; + class WiredDevice; + class WirelessDevice; + class AccessPoints; + class WiredConnection; + enum class DeviceType; + } // namespace network +} // namespace dde + +class WirelessConnect : public QObject +{ + Q_OBJECT + +public: + explicit WirelessConnect(QObject *parent, dde::network::WirelessDevice *device, dde::network::AccessPoints *ap); + ~WirelessConnect() Q_DECL_OVERRIDE; + + void setSsid(const QString &ssid); + bool passwordIsValid(const QString &password); + void getoldPassword(); + +protected: + void setPassword(const QString &password); + bool hasPassword(); + void initConnection(); + void activateConnection(); + NetworkManager::WirelessSecuritySetting::KeyMgmt getKeyMgmtByAp(dde::network::AccessPoints *ap); + +public Q_SLOTS: + void connectNetwork(); + void connectNetworkPassword(const QString password); + +Q_SIGNALS: + void passwordError(const QString oldPassword); + +private: + dde::network::WirelessDevice *m_device; + dde::network::AccessPoints *m_accessPoint; + QString m_ssid; + bool m_needUpdate; + + NetworkManager::ConnectionSettings::Ptr m_connectionSettings; +}; + +#endif // WIRELESSCONNECT_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.cpp new file mode 100644 index 000000000..543f25472 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.cpp @@ -0,0 +1,1183 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkpanel.h" +#include "utils.h" +#include "item/netitem.h" +#include "item/devicestatushandler.h" +#include "thememanager.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define SWITCH_WIDTH 50 +#define SWITCH_HEIGHT 24 + +class ScrollArea : public QScrollArea +{ +public: + explicit ScrollArea(NetworkPanel *panel) + : QScrollArea(nullptr) + , m_panel(panel) + { + } + ~ScrollArea() override {} + + void setVisible(bool visible) override; + +private: + NetworkPanel *m_panel; +}; + +void ScrollArea::setVisible(bool visible) +{ + if (!visible && m_panel->closeOnClear()) { + m_panel->clear(); + } + QScrollArea::setVisible(visible); +} + +NetworkPanel::NetworkPanel(QObject *parent) + : QObject(parent) + , m_wirelessScanTimer(new QTimer(this)) + , m_closeOnClear(true) + , m_applet(new ScrollArea(this)) + , m_centerWidget(new QWidget(m_applet)) + , m_netListView(new DListView(m_centerWidget)) + , m_airplaneMode(new NetworkDBusProxy(this)) + , m_updateTimer(new QTimer(this)) +{ + initUi(); + if (NetworkController::instance()->devices().isEmpty()) { + // 当关闭网络后,不会收到activeConnectionChange信号,需要监听deviceAdded信号初始化连接 + connect(NetworkController::instance(), &NetworkController::deviceAdded, this, &NetworkPanel::initConnection); + } else { + initConnection(); + } +} + +NetworkPanel::~NetworkPanel() +{ + NetItem *oldSelectItem = selectItem(); + if (oldSelectItem) { + WirelessItem *item = static_cast(oldSelectItem); + if (item) { + const AccessPoints *ap = item->accessPoint(); + if (ap && ap->status() == ConnectionStatus::Activating) { + WirelessDevice *device = (const_cast(item->wirelessDevice())); + device->disconnectNetwork(); + } + } + } + + for (NetItem *item : m_items) + delete item; + + m_items.clear(); +} + +void NetworkPanel::initUi() +{ + m_netListView->setAccessibleName("list_network"); + m_netListView->setBackgroundType(DStyledItemDelegate::BackgroundType::ClipCornerBackground); + m_netListView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_netListView->setFrameShape(QFrame::NoFrame); + m_netListView->setViewportMargins(0, 0, 0, 0); + m_netListView->setItemSpacing(1); + m_netListView->setMouseTracking(true); + m_netListView->setItemMargins(QMargins(10, 0, 10, 0)); + m_netListView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + m_netListView->setItemRadius(0); + + NetworkDelegate *delegate = new NetworkDelegate(m_netListView); + delegate->setDBusAirplaneMode(m_airplaneMode); + delegate->setMargins(QMargins(10, 0, 6, 0)); + m_netListView->setItemDelegate(delegate); + connect(delegate, &NetworkDelegate::refreshClicked, this, &NetworkPanel::onRefreshClicked); + connect(delegate, &NetworkDelegate::enabledClicked, this, &NetworkPanel::onEnabledClicked); + connect(delegate, &NetworkDelegate::closeClicked, this, [] (const QModelIndex &index) { + // 获取该行数据对应的设备 + NetItemType type = index.data(NetItemRole::TypeRole).value(); + if (type == NetItemType::WiredViewItem) { + WiredDevice *device = index.data(NetItemRole::DeviceDataRole).value(); + WiredConnection *connection = static_cast(index.data(NetItemRole::DataRole).value()); + if (device && connection) { + if (connection->connected()) + device->disconnectNetwork(); + else + device->connectNetwork(connection); + } + } else if (type == NetItemType::WirelessViewItem || type == NetItemType::WirelessHiddenViewItem) { + WirelessDevice *device = index.data(NetItemRole::DeviceDataRole).value(); + AccessPoints *accessPoint = static_cast(index.data(NetItemRole::DataRole).value()); + if (device && accessPoint) { + if (device->activeAccessPoints() == accessPoint) + device->disconnectNetwork(); + } + } + }); + + m_model = new QStandardItemModel(this); + m_model->setSortRole(sortRole); + m_netListView->setModel(m_model); + + QVBoxLayout *centerLayout = new QVBoxLayout(m_centerWidget); + centerLayout->setContentsMargins(0, 0, 0, 0); + centerLayout->addWidget(m_netListView); + + m_applet->setFixedWidth(PANELWIDTH); + m_applet->setWidget(m_centerWidget); + m_applet->setFrameShape(QFrame::NoFrame); + m_applet->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_applet->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + m_centerWidget->setAutoFillBackground(false); + m_applet->viewport()->setAutoFillBackground(false); + m_applet->setVisible(false); + m_applet->installEventFilter(this); + m_applet->setFixedSize(PANELWIDTH, 0); + + setControlBackground(); + + // 支持在触摸屏上滚动 + QScroller::grabGesture(m_netListView->viewport(), QScroller::LeftMouseButtonGesture); + QScroller *scroller = QScroller::scroller(m_netListView->window()); + QScrollerProperties sp; + sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff); + scroller->setScrollerProperties(sp); +} + +void NetworkPanel::initConnection() +{ + static bool isConnectionInited = false; + if (isConnectionInited) { + return; + } + isConnectionInited = true; + // 主题发生变化触发的信号 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &NetworkPanel::onUpdatePlugView); + + // 连接信号 + disconnect(NetworkController::instance(), nullptr, this, nullptr); + NetworkController *networkController = NetworkController::instance(); + connect(networkController, &NetworkController::deviceAdded, this, &NetworkPanel::onDeviceAdded); + connect(networkController, &NetworkController::deviceRemoved, this, &NetworkPanel::onUpdatePlugView); + connect(networkController, &NetworkController::connectivityChanged, this, &NetworkPanel::onUpdatePlugView); + + // 点击列表的信号 + connect(m_netListView, &DListView::pressed, this, &NetworkPanel::onClickListView); + + int wirelessScanInterval = Utils::SettingValue("com.deepin.dde.dock", QByteArray(), "wireless-scan-interval", 10).toInt() * 1000; + m_wirelessScanTimer->setInterval(wirelessScanInterval); + // const QGSettings *gsetting = Utils::SettingsPtr("com.deepin.dde.dock", QByteArray(), this); + // if (gsetting) + // connect(gsetting, &QGSettings::changed, [ & ](const QString &key) { + // if (key == "wireless-scan-interval") { + // int interval = gsetting->get("wireless-scan-interval").toInt() * 1000; + // m_wirelessScanTimer->setInterval(interval); + // } + // }); + connect(m_wirelessScanTimer, &QTimer::timeout, [ & ] { + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *wirelessDevice = static_cast(device); + wirelessDevice->scanNetwork(); + } + } + }); + connect(m_updateTimer, &QTimer::timeout, this, &NetworkPanel::updateView); + m_updateTimer->setInterval(200); + m_updateTimer->setSingleShot(true); + + QTimer::singleShot(0, this, [ = ] { + onDeviceAdded(networkController->devices()); + updateView(); + }); +} + +void NetworkPanel::onEnabledClicked(const QModelIndex &index, const bool enabled) +{ + NetItemType itemType = index.data(TypeRole).value(); + switch (itemType) { + case NetItemType::DeviceControllViewItem: { + QList devices = index.data(DeviceDataRole).value>(); + for (NetworkDeviceBase *device : devices) { + if (device->isEnabled() != enabled) + device->setEnabled(enabled); + } + break; + } + case NetItemType::WiredControllViewItem: + case NetItemType::WirelessControllViewItem: { + NetworkDeviceBase *device = index.data(DeviceDataRole).value(); + if (device && device->isEnabled() != enabled) + device->setEnabled(enabled); + break; + } + default: + break; + } +} + +void NetworkPanel::onRefreshClicked(const QModelIndex &index) +{ + NetItemType itemType = index.data(TypeRole).value(); + if (itemType != NetItemType::WirelessControllViewItem) + return; + + WirelessDevice *device = index.data(DeviceDataRole).value(); + if (device) + device->scanNetwork(); +} + +void NetworkPanel::updateItems() +{ + auto findBaseController = [ this ] (DeviceType t)-> DeviceControllItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::DeviceControllViewItem) + continue; + + DeviceControllItem *pBaseCtrlItem = static_cast(item); + if (pBaseCtrlItem->deviceType() == t) + return pBaseCtrlItem; + } + + return Q_NULLPTR; + }; + + auto findWiredController = [ this ] (WiredDevice *device)-> WiredControllItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WiredControllViewItem) + continue; + + WiredControllItem *wiredCtrlItem = static_cast(item); + if (wiredCtrlItem->device() == device) + return wiredCtrlItem; + } + + return Q_NULLPTR; + }; + + auto findWiredItem = [ this ] (WiredConnection *conn)-> WiredItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WiredViewItem) + continue; + + WiredItem *wiredItem = static_cast(item); + if (wiredItem->connection() == conn) + return wiredItem; + } + + return Q_NULLPTR; + }; + + auto findWirelessController = [ this ] (WirelessDevice *device)-> WirelessControllItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WirelessControllViewItem) + continue; + + WirelessControllItem *wiredCtrlItem = static_cast(item); + if (wiredCtrlItem->device() == device) + return wiredCtrlItem; + } + + return Q_NULLPTR; + }; + + auto findWirelessItem = [ this ] (const AccessPoints *ap, const WirelessDevice *device)-> WirelessItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WirelessViewItem) + continue; + + WirelessItem *wirelessItem = static_cast(item); + const AccessPoints *apData = wirelessItem->accessPoint(); + const WirelessDevice *wirelessdevice = wirelessItem->wirelessDevice(); + if (apData == ap && wirelessdevice == device) + return wirelessItem; + } + + return Q_NULLPTR; + }; + + QList devices = NetworkController::instance()->devices(); + QList wiredDevices; + QList wirelessDevices; + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == DeviceType::Wired) { + WiredDevice *dev = static_cast(device); + wiredDevices << dev; + } else if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *dev = static_cast(device); + wirelessDevices << dev; + } + } + + // 存在多个无线设备的情况下,需要显示总开关 + int sortIndex = 0; + QList items; + if (wirelessDevices.size() > 1) { + DeviceControllItem *ctrl = findBaseController(DeviceType::Wireless); + if (!ctrl) + ctrl = new DeviceControllItem(DeviceType::Wireless, m_netListView->viewport()); + else + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + ctrl->setDevices(devices); + items << ctrl; + } + + // 遍历当前所有的无线网卡 + auto accessPoints = [] (WirelessDevice *device) { + if (device->isEnabled()) + return device->accessPointItems(); + + return QList(); + }; + + for (WirelessDevice *device : wirelessDevices) { + WirelessControllItem *ctrl = findWirelessController(device); + if (!ctrl) + ctrl = new WirelessControllItem(m_netListView->viewport(), static_cast(device)); + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + items << ctrl; + if (device->isEnabled() && !device->hotspotEnabled()) { + QList aps = accessPoints(device); + // 按连接状态、强度、名称排序 + std::sort(aps.begin(), aps.end(), [](AccessPoints *a, AccessPoints *b) { + int aStatus = static_cast(a->status()) & 3; + int bStatus = static_cast(b->status()) & 3; + if (aStatus ^ bStatus) + return aStatus != 0; + if (a->strength() == b->strength()) + return a->ssid() <= b->ssid(); + return a->strength() > b->strength(); + }); + for (AccessPoints *ap : aps) { + WirelessItem *apCtrl = findWirelessItem(ap, device); + if (!apCtrl) { + apCtrl = new WirelessItem(m_netListView->viewport(), device, ap, this); + connect(apCtrl, &WirelessItem::sizeChanged, this, &NetworkPanel::refreshItems); + connect(m_airplaneMode, &NetworkDBusProxy::EnabledChanged, apCtrl, &WirelessItem::onAirplaneModeChanged); + } + apCtrl->updateView(); + apCtrl->onAirplaneModeChanged(m_airplaneMode->enabled()); + + apCtrl->standardItem()->setData(sortIndex++, sortRole); + items << apCtrl; + } + if (!m_airplaneMode->enabled()) { + // 连接隐藏网络 + WirelessItem *apCtrl = findWirelessItem(nullptr, device); + if (!apCtrl) { + apCtrl = new WirelessItem(m_netListView->viewport(), device, nullptr, this); + connect(apCtrl, &WirelessItem::sizeChanged, this, &NetworkPanel::refreshItems); + } + apCtrl->updateView(); + + apCtrl->standardItem()->setData(sortIndex++, sortRole); + items << apCtrl; + } + } + } + + // 存在多个有线设备的情况下,需要显示总开关 + if (wiredDevices.size() > 1) { + DeviceControllItem *ctrl = findBaseController(DeviceType::Wired); + if (!ctrl) + ctrl = new DeviceControllItem(DeviceType::Wired, m_netListView->viewport()); + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + ctrl->setDevices(devices); + items << ctrl; + } + + auto wiredConnections = [ & ](WiredDevice *device) { + if (device->isEnabled()) + return device->items(); + + return QList(); + }; + + // 遍历当前所有的有线网卡 + for (WiredDevice *device : wiredDevices) { + WiredControllItem *ctrl = findWiredController(device); + if (!ctrl) + ctrl = new WiredControllItem(m_netListView->viewport(), device); + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + items << ctrl; + + QList connItems = wiredConnections(device); + for (WiredConnection *conn : connItems) { + WiredItem *connectionCtrl = findWiredItem(conn); + if (!connectionCtrl) + connectionCtrl = new WiredItem(m_netListView->viewport(), device, conn); + connectionCtrl->updateView(); + + connectionCtrl->standardItem()->setData(sortIndex++, sortRole); + items << connectionCtrl; + } + } + + // 把原来列表中不存在的项放到移除列表中 + for (NetItem *item : m_items) { + if (!items.contains(item)) + delete item; + } + + m_items = items; +} + +void NetworkPanel::updateView() +{ + updateItems(); + refreshItems(); + passwordError(QString(), QString()); + // 网络设备数量大于1时,需要延迟发送信号,确保数据初始化完成,避免网络面板闪烁,解决bug119717 + QTimer::singleShot(200, this, [ this ] { + if (m_model->rowCount() > 0) + Q_EMIT updateFinished(); + }); +} + +void NetworkPanel::refreshItems() +{ + QList items; + QList rmRows; + for (NetItem *item : m_items) + items << item->standardItem(); + + for (int i = 0; i < m_model->rowCount(); i++) { + DStandardItem *item = static_cast(m_model->item(i)); + if (!items.contains(item)) + rmRows << i; + } + // 将row按照从大到小的顺序排序,否则会出现删除错误的问题 + std::sort(rmRows.begin(), rmRows.end(), [](const int row1, const int row2) { return row1 > row2; }); + for (int row : rmRows) + m_model->removeRow(row); + + // 从缓存中查找出当前列表不存在的Item,并插入到列表中 + QList currentItems; + for (int i = 0; i < m_model->rowCount(); i++) + currentItems << m_model->item(i); + + QList newItems; + for (QStandardItem *item : items) { + if (!currentItems.contains(item)) + newItems << item; + } + + for (QStandardItem *item : newItems) + m_model->appendRow(item); + + // 对列表进行重新排序 + m_model->sort(0); + + // 设置高度 + int height = 0; + int totalHeight = 0; + for (int i = 0; i < m_model->rowCount(); i++) { + QStandardItem *item = m_model->item(i); + QSize size = item->sizeHint(); + if (i < 16) + height += size.height(); + + totalHeight += size.height(); + } + + m_netListView->setFixedSize(PANELWIDTH, totalHeight); + m_centerWidget->setFixedSize(PANELWIDTH, totalHeight); + m_applet->setFixedSize(PANELWIDTH, height); + + m_netListView->update(); +} + +bool NetworkPanel::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == m_applet) { + switch (event->type()) { + case QEvent::Show: { + if (!m_wirelessScanTimer->isActive()) + m_wirelessScanTimer->start(); + break; + } + case QEvent::Hide: { + if (m_wirelessScanTimer->isActive()) + m_wirelessScanTimer->stop(); + break; + } + default: + break; + } + } + + return QObject::eventFilter(obj, event); +} + +int NetworkPanel::deviceCount(const DeviceType &devType) +{ + // 获取指定的设备类型的设备数量 + int count = 0; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *dev : devices) + if (dev->deviceType() == static_cast(devType)) + count++; + + return count; +} + +void NetworkPanel::onDeviceAdded(QList devices) +{ + // 处理新增设备的信号 + for (NetworkDeviceBase *device : devices) { + // 当网卡连接状态发生变化的时候重新绘制任务栏的图标 + connect(device, &NetworkDeviceBase::deviceStatusChanged, this, &NetworkPanel::onUpdatePlugView); + connect(device, &NetworkDeviceBase::activeConnectionChanged, this, &NetworkPanel::onUpdatePlugView); + switch (device->deviceType()) { + case DeviceType::Wired: { + WiredDevice *wiredDevice = static_cast(device); + + connect(wiredDevice, &WiredDevice::connectionAdded, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionRemoved, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionPropertyChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::deviceStatusChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::enableChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::connectionChanged, this, &NetworkPanel::onUpdatePlugView); + } break; + case DeviceType::Wireless: { + WirelessDevice *wirelessDevice = static_cast(device); + + connect(wirelessDevice, &WirelessDevice::networkAdded, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::networkRemoved, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::accessPointInfoChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::enableChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::connectionChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::hotspotEnableChanged, this, &NetworkPanel::onUpdatePlugView); + + wirelessDevice->scanNetwork(); + } break; + default: + break; + } + } + + onUpdatePlugView(); +} + +bool NetworkPanel::deviceEnabled(const DeviceType &deviceType) const +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType && device->isEnabled()) + return true; + + return false; +} + +void NetworkPanel::setDeviceEnabled(const DeviceType &deviceType, bool enabeld) +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType) + device->setEnabled(enabeld); +} + +QWidget *NetworkPanel::itemApplet() +{ + return m_applet; +} + +void NetworkPanel::setControlBackground() +{ + QPalette backgroud = m_applet->palette(); + backgroud.setColor(QPalette::Window, ThemeManager::ref().backgroundColor()); + m_applet->setAutoFillBackground(true); + m_applet->setPalette(backgroud); +} + +void NetworkPanel::onUpdatePlugView() +{ + if (!m_updateTimer->isActive()) { + m_updateTimer->start(); + } +} + +void NetworkPanel::onClickListView(const QModelIndex &index) +{ + // 如果当前点击的是连接隐藏网络或者无线网络,且开启了飞行模式,则不让点击 + NetItemType type = index.data(NetItemRole::TypeRole).value(); + if ((type == WirelessHiddenViewItem || type == WirelessViewItem) && m_airplaneMode->enabled()) + return; + + NetItem *oldSelectItem = selectItem(); + NetItem *newSelectItem = m_items.at(index.row()); + if (newSelectItem != oldSelectItem && oldSelectItem) { + WirelessItem *item = static_cast(oldSelectItem); + item->expandWidget(WirelessItem::Hide, false); // 选择切换时隐藏输入框 + } + switch (type) { + case WirelessHiddenViewItem: + case WirelessViewItem: { + WirelessItem *item = static_cast(newSelectItem); + item->connectNetwork(); + break; + } + case WiredViewItem: { + WiredItem *item = static_cast(newSelectItem); + item->connectNetwork(); + break; + } + default: + break; + } +} + +int NetworkPanel::getStrongestAp() +{ + int retStrength = -1; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + WirelessDevice *dev = static_cast(device); + AccessPoints *ap = dev->activeAccessPoints(); + if (ap && retStrength < ap->strength()) + retStrength = ap->strength(); + } + + return retStrength; +} + +void NetworkPanel::passwordError(const QString &dev, const QString &ssid, bool wait) +{ + if (!ssid.isEmpty()) { + m_reconnectSsid = ssid; + m_reconnectDev = dev; + m_waitPassword = wait; + clear(); + } + if (!m_reconnectSsid.isEmpty()) { + QTimer::singleShot(0, this, &NetworkPanel::expandPasswordInput); + } +} + +bool NetworkPanel::changePassword(const QString &key, const QString &password, bool input) +{ + if (m_waitPassword) { + Q_EMIT passwordChanged(key, password, input); + m_waitPassword = false; + return true; + } + return false; +} + +QString NetworkPanel::ssidWaitingForPassword() const +{ + return m_reconnectSsid; +} + +bool NetworkPanel::closeOnClear() const +{ + return m_closeOnClear; +} + +void NetworkPanel::setCloseOnClear(bool closeOnClear) +{ + m_closeOnClear = closeOnClear; +} + +void NetworkPanel::clear() +{ + NetItem *oldSelectItem = selectItem(); + if (oldSelectItem) { + WirelessItem *selectItem = static_cast(oldSelectItem); + selectItem->expandWidget(WirelessItem::Hide); + } + m_applet->verticalScrollBar()->setValue(0); +} + +void NetworkPanel::expandPasswordInput() +{ + if (m_reconnectSsid.isEmpty()) { + return; + } + NetItem *oldSelectItem = selectItem(); + int y = 0; + for (NetItem *item : m_items) { + if (NetItemType::WirelessViewItem == item->itemType()) { + WirelessItem *wirelessItem = static_cast(item); + if (wirelessItem->accessPoint() + && (m_reconnectDev.isEmpty() || wirelessItem->wirelessDevice()->path() == m_reconnectDev) + && (wirelessItem->accessPoint()->ssid() == m_reconnectSsid)) { + if (item != oldSelectItem) { + if (oldSelectItem) { + WirelessItem *selectItem = static_cast(oldSelectItem); + selectItem->expandWidget(WirelessItem::Hide); // 选择切换时隐藏输入框 + } + wirelessItem->expandPasswordInput(); + int h = item->standardItem()->sizeHint().height() / 2; + m_applet->ensureVisible(0, y + h, 0, h); + } + m_reconnectSsid.clear(); + m_reconnectDev.clear(); + break; + } + } + y += item->standardItem()->sizeHint().height(); + } +} + +NetItem *NetworkPanel::selectItem() +{ + for (NetItem *item : m_items) { + if (NetItemType::WirelessViewItem == item->itemType() || NetItemType::WirelessHiddenViewItem == item->itemType()) { + WirelessItem *wirelessItem = static_cast(item); + if (wirelessItem->expandVisible()) { + return wirelessItem; + } + } + } + return nullptr; +} + +// 用于绘制分割线 +#define RIGHTMARGIN 13 +#define DIAMETER 16 + +NetworkDelegate::NetworkDelegate(QAbstractItemView *parent) + : DStyledItemDelegate(parent) + , m_parentWidget(parent) + , m_refreshIconTimer(new QTimer(this)) + , m_currentDegree(0) + , m_refreshTimer(new QTimer(this)) + , m_airplaneMode(nullptr) +{ + connect(m_refreshTimer, &QTimer::timeout, this, [this]() { + this->m_currentDegree += 14; + m_parentWidget->update(); + }); + + m_refreshIconTimer->setInterval(3); + connect(m_refreshIconTimer, &QTimer::timeout, this, [ this ] { + QList refreshIndexs = m_refreshAngle.keys(); + for (int i = refreshIndexs.size() - 1; i >= 0; i--) { + const QModelIndex &index = refreshIndexs[i]; + int angle = m_refreshAngle[index]; + if (angle >= 360) { + m_refreshAngle.remove(index); + } else { + angle += (angle <= 180 ? 5 : 8); + m_refreshAngle[index] = angle; + } + } + if (m_refreshAngle.size() == 0) { + if (m_refreshIconTimer->isActive()) + m_refreshIconTimer->stop(); + } + m_parentWidget->update(); + }); + + m_refreshTimer->setInterval(30); +} + +NetworkDelegate::~NetworkDelegate() +{ + if (m_refreshTimer->isActive()) + m_refreshTimer->stop(); +} + +void NetworkDelegate::setDBusAirplaneMode(NetworkDBusProxy *airplane) +{ + m_airplaneMode = airplane; +} + +void NetworkDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const +{ + option->state &= ~QStyle::State_MouseOver; + DStyledItemDelegate::initStyleOption(option, index); +} + +void NetworkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + bool drawLine = needDrawLine(index); + if (drawLine) { + // 绘制间隔线 + QRect rct = option.rect; + rct.setY(rct.top() + rct.height() - 2); + rct.setHeight(2); + painter->fillRect(rct, ThemeManager::ref().lineColor()); + } + // 鼠标移动的时候不 + bool isHoverItem = cantHover(index); + QRect rect = option.rect; + if (drawLine) + rect.setHeight(rect.height() - 2); + + if (!isHoverItem && (option.state & QStyle::State_MouseOver)) { + painter->fillRect(rect, ThemeManager::ref().itemBackgroundColor()); + } + + // 绘制无线网络左侧的刷新按钮 + if (index.data(TypeRole).value() == NetItemType::WirelessControllViewItem) + drawRefreshButton(painter, option, index); + + // 绘制开关按钮,因为如果直接在DStandardItem上使用DSwitchButton就会导致更新列表的时候引起错位,就使用绘制开关的方式来实现吧 + if (hasSwitchButton(index)) + drawSwitchButton(painter, option, index); + + // 绘制右侧的连接图标 + NetConnectionType connectionStatus = static_cast(index.data(NetItemRole::ConnectionStatusRole).toInt()); + if (connectionStatus == NetConnectionType::Connecting) { + if (!m_ConnectioningIndexs.contains(index)) + m_ConnectioningIndexs << index; + } else { + if (m_ConnectioningIndexs.contains(index)) + m_ConnectioningIndexs.removeOne(index); + } + + if (m_ConnectioningIndexs.size() > 0) { + if (!m_refreshTimer->isActive()) + m_refreshTimer->start(); + } else { + if (m_refreshTimer->isActive()) { + m_refreshTimer->stop(); + m_currentDegree = 0; + } + } + + switch (connectionStatus) { + case NetConnectionType::Connected: { + painter->setRenderHint(QPainter::Antialiasing, true); + + QRect rct = checkRect(option.rect); + painter->save(); + painter->setPen(QPen(Qt::NoPen)); + painter->setBrush(m_parentWidget->palette().color(QPalette::Highlight)); + + QPen pen(Qt::white, DIAMETER / 100.0 * 6.20, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); + if (index.data(NetItemRole::MouseInBoundingRole).toBool()) + drawFork(painter, rct, pen, DIAMETER); + else + drawCheck(painter, rct, pen, DIAMETER); + + painter->restore(); + break; + } + case NetConnectionType::Connecting: { + QRect rct = checkRect(option.rect); + drawLoading(painter, rct, DIAMETER); + break; + } + default: + break; + } + + DStyledItemDelegate::paint(painter, option, index); +} + +bool NetworkDelegate::needDrawLine(const QModelIndex &index) const +{ + // 如果是最后一行,则无需绘制线条 + QModelIndex siblingIndex = index.siblingAtRow(index.row() + 1); + if (!siblingIndex.isValid()) + return false; + + // 如果是总控开关,无线开关和有线开关,下面都要分割线 + NetItemType itemType = index.data(TypeRole).value(); + if (itemType == NetItemType::DeviceControllViewItem + || itemType == NetItemType::WirelessControllViewItem + || itemType == NetItemType::WiredControllViewItem) + return true; + + NetItemType nextItemType = siblingIndex.data(TypeRole).value(); + return itemType != nextItemType; +} + +bool NetworkDelegate::cantHover(const QModelIndex &index) const +{ + NetItemType itemType = index.data(TypeRole).value(); + // 如果是无线网络或者连接隐藏网络项,且当前开启了飞行模式,则当前行不让点击 + if (itemType == NetItemType::WirelessViewItem || itemType == NetItemType::WirelessHiddenViewItem) + return (m_airplaneMode && m_airplaneMode->enabled()); + + return (itemType == NetItemType::DeviceControllViewItem + || itemType == NetItemType::WirelessControllViewItem + || itemType == NetItemType::WiredControllViewItem); +} + +bool NetworkDelegate::hasSwitchButton(const QModelIndex &index) const +{ + NetItemType itemType = index.data(TypeRole).value(); + // 如果是总控、有线网卡、无线网卡开关,则需要显示开关 + return (itemType == NetItemType::DeviceControllViewItem + || itemType == NetItemType::WirelessControllViewItem + || itemType == NetItemType::WiredControllViewItem); +} + +void NetworkDelegate::drawCheck(QPainter *painter, QRect &rect, QPen &pen, int radius) const +{ + painter->drawPie(rect, 0, 360 * 16); + painter->setPen(pen); + + QPointF points[3] = { + QPointF(rect.left() + radius / 100.0 * 32, rect.top() + radius / 100.0 * 57), + QPointF(rect.left() + radius / 100.0 * 45, rect.top() + radius / 100.0 * 70), + QPointF(rect.left() + radius / 100.0 * 75, rect.top() + radius / 100.0 * 35) + }; + + painter->drawPolyline(points, 3); +} + +void NetworkDelegate::drawFork(QPainter *painter, QRect &rect, QPen &pen, int radius) const +{ + painter->drawPie(rect, 0, 360 * 16); + pen.setCapStyle(Qt::RoundCap); + painter->setPen(pen); + + QPointF pointsl[2] = { + QPointF(rect.left() + radius / 100.0 * 35, rect.top() + radius / 100.0 * 35), + QPointF(rect.left() + radius / 100.0 * 65, rect.top() + radius / 100.0 * 65) + }; + + painter->drawPolyline(pointsl, 2); + + QPointF pointsr[2] = { + QPointF(rect.left() + radius / 100.0 * 65, rect.top() + radius / 100.0 * 35), + QPointF(rect.left() + radius / 100.0 * 35, rect.top() + radius / 100.0 * 65) + }; + + painter->drawPolyline(pointsr, 2); +} + +void NetworkDelegate::drawLoading(QPainter *painter, QRect &rect, int diameter) const +{ + painter->setRenderHint(QPainter::Antialiasing, true); + QList> indicatorColors; + for (int i = 0; i < 3; i++) + indicatorColors << createDefaultIndicatorColorList(m_parentWidget->palette().highlight().color()); + + double radius = diameter * 0.66; + auto center = QRectF(rect).center(); + auto indicatorRadius = radius / 2 / 2 * 1.1; + auto indicatorDegreeDelta = 360 / indicatorColors.count(); + +#define INDICATOR_SHADOW_OFFSET 10 + + for (int i = 0; i < indicatorColors.count(); ++i) { + QList colors = indicatorColors.value(i); + for (int j = 0; j < colors.count(); ++j) { + double degreeCurrent = m_currentDegree - j * INDICATOR_SHADOW_OFFSET + indicatorDegreeDelta * i; + auto x = (radius - indicatorRadius) * qCos(qDegreesToRadians(degreeCurrent)); + auto y = (radius - indicatorRadius) * qSin(qDegreesToRadians(degreeCurrent)); + + x = center.x() + x; + y = center.y() + y; + auto tl = QPointF(x - 1 * indicatorRadius, y - 1 * indicatorRadius); + QRectF rf(tl.x(), tl.y(), indicatorRadius * 2, indicatorRadius * 2); + + QPainterPath path; + path.addEllipse(rf); + + painter->fillPath(path, colors.value(j)); + } + } +} + +bool NetworkDelegate::switchIsEnabled(const QModelIndex &index) const +{ + if (!index.isValid()) + return false; + + NetItemType itemType = index.data(TypeRole).value(); + switch (itemType) { + case NetItemType::DeviceControllViewItem: { + QList devices = index.data(NetItemRole::DeviceDataRole).value>(); + for (NetworkDeviceBase *device : devices) { + if (device->isEnabled()) + return true; + } + return false; + } + case NetItemType::WiredControllViewItem:{ + NetworkDeviceBase *device = index.data(NetItemRole::DeviceDataRole).value(); + if (device) + return device->isEnabled(); + break; + } + case NetItemType::WirelessControllViewItem: { + NetworkDeviceBase *device = index.data(NetItemRole::DeviceDataRole).value(); + if (device) + return device->isEnabled() && !m_airplaneMode->enabled(); + break; + } + default: + break; + } + return false; +} + +void NetworkDelegate::drawRefreshButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + // 如果当前开关为关闭状态,则不显示刷新按钮 + if (!switchIsEnabled(index)) + return; + + QRect rctIcon(option.rect.width() - SWITCH_WIDTH - 36, option.rect.top() + (option.rect.height() - 20) / 2, 20, 20); + QPixmap pixmap = DIcon::loadNxPixmap(ThemeManager::ref().getIcon("refresh")); + painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + if (m_refreshAngle.contains(index)) { + QPoint ptCenter(rctIcon.left() + rctIcon.width() / 2, rctIcon.top() + rctIcon.height() / 2); + painter->translate(ptCenter); + painter->rotate(m_refreshAngle[index]); + painter->drawPixmap(QRect(-10, -10, 20, 20), pixmap); + } else { + painter->drawPixmap(rctIcon, pixmap); + } + + painter->restore(); +} + +void NetworkDelegate::drawSwitchButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + QRect rctSwitch(option.rect.width() - SWITCH_WIDTH - 10, + option.rect.top() + (option.rect.height() - SWITCH_HEIGHT) / 2, + SWITCH_WIDTH, SWITCH_HEIGHT); + painter->setPen(Qt::NoPen); + DPalette palette = option.palette; + painter->setBrush(palette.color(DPalette::ColorRole::Button)); + painter->drawRoundedRect(rctSwitch, 8, 8); + bool isSwitchEnabled = switchIsEnabled(index); + NetItemType itemType = index.data(TypeRole).value(); + // 如果是总控、有线网卡、无线网卡开关,则需要显示开关 + QPalette::ColorRole colorRole = isSwitchEnabled ? QPalette::ColorRole::Highlight : DPalette::ColorRole::ButtonText; + if (m_airplaneMode->enabled() && itemType == NetItemType::WirelessControllViewItem) + painter->setBrush(palette.color(QPalette::ColorGroup::Disabled, colorRole)); + else + painter->setBrush(palette.color(colorRole)); + + isSwitchEnabled ? rctSwitch.setLeft(rctSwitch.left() + 20) : rctSwitch.setWidth(30); + painter->drawRoundedRect(rctSwitch, 8, 8); + + painter->restore(); +} + +bool NetworkDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + switch (event->type()) { + case QEvent::MouseMove: { + QMouseEvent *mouseEvent = static_cast(event); + QRect rct = checkRect(option.rect); + model->setData(index, rct.contains(mouseEvent->pos()), NetItemRole::MouseInBoundingRole); + m_parentWidget->update(); + break; + } + case QEvent::Leave: { + model->setData(index, false, NetItemRole::MouseInBoundingRole); + m_parentWidget->update(); + break; + } + case QEvent::MouseButtonPress: { + QMouseEvent *mouseEvent = static_cast(event); + if (index.data(TypeRole).value() == NetItemType::WirelessControllViewItem) { + if (!m_airplaneMode->enabled()) { + if (!m_refreshAngle.contains(index)) { + QRect rctSwitch(option.rect.width() - SWITCH_WIDTH - 36, option.rect.top() + (option.rect.height() - 20) / 2, 20, 20); + if (rctSwitch.contains(mouseEvent->pos())) { + Q_EMIT refreshClicked(index); + // 后面刷新图标是根据m_refreshAngle列表中是否存在来决定是否刷新的,因此,需要提前将m_refreshAngle填充数据 + m_refreshAngle[index] = 0; + if (!m_refreshIconTimer->isActive()) + m_refreshIconTimer->start(); + return true; + } + } + } + } + if (hasSwitchButton(index)) { + NetItemType itemType = index.data(TypeRole).value(); + // 以下三种情况可以点击按钮 + // 1: 飞行模式关闭 2: 当前是有线网卡 3: 当前是有线网卡总控 + if (!m_airplaneMode->enabled() || itemType == NetItemType::WiredControllViewItem + || (itemType == NetItemType::DeviceControllViewItem && index.data(NetItemRole::DeviceTypeRole).value() == DeviceType::Wired)) { + QRect rctSwitch(option.rect.width() - SWITCH_WIDTH - 10, + option.rect.top() + (option.rect.height() - SWITCH_HEIGHT) / 2, + SWITCH_WIDTH, SWITCH_HEIGHT); + if (rctSwitch.contains(mouseEvent->pos())) { + Q_EMIT enabledClicked(index, !switchIsEnabled(index)); + return true; + } + } + } else { + NetConnectionType connectionStatus = static_cast(index.data(NetItemRole::ConnectionStatusRole).toInt()); + QRect rct = checkRect(option.rect); + if (connectionStatus == NetConnectionType::Connected) { + if (rct.contains(mouseEvent->pos())) { + Q_EMIT closeClicked(index); + return true; + } + } + } + break; + } + default: + break; + } + + return DStyledItemDelegate::editorEvent(event, model, option, index); +} + +QRect NetworkDelegate::checkRect(const QRect &rct) const +{ + int left = rct.right() - RIGHTMARGIN - DIAMETER + 4; + int top = rct.top() + (DIAMETER / 2); // 连接图标绘制在顶端 + QRect rect; + rect.setLeft(left); + rect.setTop(top); + rect.setWidth(DIAMETER); + rect.setHeight(DIAMETER); + return rect; +} + +QList NetworkDelegate::createDefaultIndicatorColorList(QColor color) const +{ + QList colors; + QList opacitys; + opacitys << 100 << 30 << 15 << 10 << 5 << 4 << 3 << 2 << 1; + for (int i = 0; i < opacitys.count(); ++i) { + color.setAlpha(255 * opacitys.value(i) / 100); + colors << color; + } + return colors; +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.h new file mode 100644 index 000000000..3e48ebef1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.h @@ -0,0 +1,149 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPANEL_H +#define NETWORKPANEL_H + +#include "item/devicestatushandler.h" + +#include + +#include + +#include +#include + +namespace dde { + namespace network { + enum class DeviceType; + class NetworkDeviceBase; + class NetworkDBusProxy; + } +} + +class NetItem; +class QStandardItemModel; +class QTimer; +class QScrollArea; + +using namespace dde::network; + +DGUI_USE_NAMESPACE +DWIDGET_USE_NAMESPACE + +class NetworkPanel : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void updateFinished(); + void passwordChanged(const QString &key, const QString &password, bool input); + +public: + explicit NetworkPanel(QObject *parent = Q_NULLPTR); + ~NetworkPanel() override; + + QWidget *itemApplet(); + void passwordError(const QString &dev, const QString &ssid, bool wait = true); + + bool changePassword(const QString &key, const QString &password, bool input); + QString ssidWaitingForPassword() const; + bool closeOnClear() const; + void setCloseOnClear(bool closeOnClear); + void clear(); + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + +private: + void setControlBackground(); + void initUi(); + void updateItems(); + bool deviceEnabled(const DeviceType &deviceType) const; + void setDeviceEnabled(const DeviceType &deviceType, bool enabeld); + + int getStrongestAp(); + int deviceCount(const DeviceType &devType); + void expandPasswordInput(); + NetItem *selectItem(); + +private Q_SLOTS: + void initConnection(); + void onDeviceAdded(QList devices); + void onUpdatePlugView(); + void onEnabledClicked(const QModelIndex &index, const bool enabled); + void onRefreshClicked(const QModelIndex &index); + + void onClickListView(const QModelIndex &index); + void updateView(); // 更新网络列表内容大小 + void refreshItems(); + +private: + QTimer *m_wirelessScanTimer; + + bool m_closeOnClear; + + QStandardItemModel *m_model; + + QScrollArea *m_applet; + QWidget *m_centerWidget; + DListView *m_netListView; + + QList m_items; + // 记录无线设备Path,防止信号重复连接 + QSet m_wirelessDevicePath; + QString m_reconnectDev; + QString m_reconnectSsid; + bool m_waitPassword; + NetworkDBusProxy *m_airplaneMode; + QTimer *m_updateTimer; +}; + +class NetworkDelegate : public DStyledItemDelegate +{ + Q_OBJECT + +public: + explicit NetworkDelegate(QAbstractItemView *parent = Q_NULLPTR); + ~NetworkDelegate() Q_DECL_OVERRIDE; + void setDBusAirplaneMode(NetworkDBusProxy *airplane); + +Q_SIGNALS: + void refreshClicked(const QModelIndex &); + void closeClicked(const QModelIndex &); + void enabledClicked(const QModelIndex &, const bool); + +protected: + void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; + + bool needDrawLine(const QModelIndex &index) const; + bool cantHover(const QModelIndex &index) const; + bool hasSwitchButton(const QModelIndex &index) const; + + void drawCheck(QPainter *painter, QRect &rect, QPen &pen, int radius) const; + void drawFork(QPainter *painter, QRect &rect, QPen &pen, int radius) const; + void drawLoading(QPainter *painter, QRect &rect, int diameter) const; + void drawRefreshButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void drawSwitchButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; + + QRect checkRect(const QRect &rct) const; + + QList createDefaultIndicatorColorList(QColor color) const; + +private: + bool switchIsEnabled(const QModelIndex &index) const; + +private: + QAbstractItemView *m_parentWidget; + QTimer *m_refreshIconTimer; + mutable double m_currentDegree; + QTimer *m_refreshTimer; + NetworkDBusProxy *m_airplaneMode; + mutable QList m_ConnectioningIndexs; + mutable QMap m_refreshAngle; +}; + +#endif // NETWORKPANEL_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.cpp new file mode 100644 index 000000000..5c58107ab --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.cpp @@ -0,0 +1,133 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "thememanager.h" +#include "utils.h" + +#include +#include +#include + +DGUI_USE_NAMESPACE + +ThemeManager::ThemeManager(QObject *parent) + : QObject(parent) + , m_themeType(UnknownType) +{ + appThemeTypeChanged(Dtk::Gui::DGuiApplicationHelper::instance()->themeType()); + // 主题发生变化触发的信号 + connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged, this, &ThemeManager::appThemeTypeChanged); +} + +ThemeManager::~ThemeManager() +{ +} + +QString ThemeManager::getIcon(QString path) +{ + if (path.startsWith("common")) { + return ":/" + path; + } + switch (m_themeType) { + case GreeterType: + case LockType: + case DarkType: + return ":/dark/" + path; + default: + return ":/light/" + path; + } +} + +void ThemeManager::setThemeType(ThemeType type) +{ + if (type != m_themeType) { + m_themeType = type; + emit themeChanged(m_themeType); + } +} + +void ThemeManager::updateInputStyle(Dtk::Widget::DLineEdit *inputEdit) +{ + switch (m_themeType) { + case GreeterType: + case LockType: { + QPalette editPalette = inputEdit->palette(); + editPalette.setColor(QPalette::Button, QColor(255, 255, 255, static_cast(0.2 * 255))); + inputEdit->setPalette(editPalette); + } break; + case DarkType: { + QPalette editPalette = inputEdit->palette(); + editPalette.setColor(QPalette::Button, QColor(255, 255, 255, static_cast(0.2 * 255))); + inputEdit->setPalette(editPalette); + } break; + case LightType: { + QPalette editPalette = inputEdit->palette(); + editPalette.setColor(QPalette::Button, QColor(0, 0, 0, static_cast(0.2 * 255))); + inputEdit->setPalette(editPalette); + } break; + default: + break; + } +} + +void ThemeManager::appThemeTypeChanged(Dtk::Gui::DGuiApplicationHelper::ColorType themeType) +{ + if (m_themeType >= UnknownType) { + switch (themeType) { + case Dtk::Gui::DGuiApplicationHelper::ColorType::DarkType: + setThemeType(DarkType); + break; + case Dtk::Gui::DGuiApplicationHelper::ColorType::LightType: + setThemeType(LightType); + break; + default: + break; + } + } +} + +QColor ThemeManager::backgroundColor() +{ + int alpha = Utils::isWaylandEnvironment() ? static_cast(0.5 * 255) : static_cast(0.03 * 255); + switch (m_themeType) { + case DarkType: + return QColor(0, 0, 0, alpha); + case GreeterType: + case LockType: + return QColor(235, 235, 235, static_cast(0.05 * 255)); + default: + return QColor(255, 255, 255, alpha); + } + Q_UNREACHABLE(); + return QColor(255, 255, 255, alpha); +} + +QColor ThemeManager::lineColor() +{ + switch (m_themeType) { + case DarkType: + return QColor(255, 255, 255, static_cast(0.05 * 255)); + case LockType: + return QColor(0, 0, 0, static_cast(0.1 * 255)); + default: + return QColor(0, 0, 0, static_cast(0.1 * 255)); + } + Q_UNREACHABLE(); + return QColor(255, 255, 255, static_cast(0.03 * 255)); +} + +QColor ThemeManager::itemBackgroundColor() +{ + switch (m_themeType) { + case DarkType: + return QColor(255, 255, 255, static_cast(255 * 0.10)); + case GreeterType: + case LockType: + return QColor(255, 255, 255, static_cast(255 * 0.10)); + default: + return QColor(0, 0, 0, static_cast(255 * 0.10)); + } + Q_UNREACHABLE(); + return QColor(255, 255, 255, static_cast(0.03 * 255)); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.h new file mode 100644 index 000000000..e08bfecef --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.h @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef THEMEMANAGER_H +#define THEMEMANAGER_H + +#include +#include + +namespace Dtk { +namespace Widget { +class DLineEdit; +} +} + +class ThemeManager : public QObject, public Dtk::Core::DSingleton +{ + Q_OBJECT + + friend Dtk::Core::DSingleton; + +public: + enum ThemeType { + LockType, + GreeterType, + UnknownType, + LightType, + DarkType, + }; + +Q_SIGNALS: + void themeChanged(ThemeType type); + +public: + ~ThemeManager(); + QString getIcon(QString path); + QColor backgroundColor(); + QColor lineColor(); + QColor itemBackgroundColor(); + void setThemeType(ThemeType type); + void updateInputStyle(Dtk::Widget::DLineEdit *inputEdit); + +protected Q_SLOT: + void appThemeTypeChanged(Dtk::Gui::DGuiApplicationHelper::ColorType themeType); + +protected: + explicit ThemeManager(QObject *parent = nullptr); + +private: + ThemeType m_themeType; +}; + +#endif // THEMEMANAGER_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.cpp new file mode 100644 index 000000000..9714eee04 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.cpp @@ -0,0 +1,736 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkpluginhelper.h" +#include "widgets/tipswidget.h" +#include "utils.h" +#include "item/devicestatushandler.h" +#include "networkdialog.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "networkdbusproxy.h" + +NETWORKPLUGIN_USE_NAMESPACE + +NetworkPluginHelper::NetworkPluginHelper(NetworkDialog *networkDialog, QObject *parent) + : QObject(parent) + , m_pluginState(PluginState::Unknown) + , m_tipsWidget(new TipsWidget(nullptr)) + , m_switchWire(true) + , m_networkDialog(networkDialog) + , m_isDarkIcon(true) + , m_refreshIconTimer(new QTimer(this)) + , m_trayIcon(new QIcon(QIcon::fromTheme(":/light/wireless-disabled-symbolic"))) +{ + qDBusRegisterMetaType(); + initUi(); + initConnection(); +} + +NetworkPluginHelper::~NetworkPluginHelper() +{ + delete m_tipsWidget; + delete m_trayIcon; +} + +void NetworkPluginHelper::initUi() +{ + m_tipsWidget->setVisible(false); + m_tipsWidget->setSpliter(" : "); +} + +void NetworkPluginHelper::initConnection() +{ + // 主题发生变化触发的信号 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &NetworkPluginHelper::onUpdatePlugView); + + // 连接信号 + NetworkController *networkController = NetworkController::instance(); + connect(networkController, &NetworkController::deviceAdded, this, &NetworkPluginHelper::onDeviceAdded); + connect(networkController, &NetworkController::deviceRemoved, this, &NetworkPluginHelper::onUpdatePlugView); + connect(networkController, &NetworkController::connectivityChanged, this, &NetworkPluginHelper::onUpdatePlugView); + + m_refreshIconTimer->setInterval(200); + connect(m_refreshIconTimer, &QTimer::timeout, this, &NetworkPluginHelper::refreshIcon); + + refreshIcon(); + QTimer::singleShot(100, this, [ = ] { + onDeviceAdded(networkController->devices()); + refreshIcon(); + }); +} + +void NetworkPluginHelper::updatePluginState() +{ + m_pluginState = DeviceStatusHandler::pluginState(); +} + +PluginState NetworkPluginHelper::getPluginState() +{ + return m_pluginState; +} + +QList> NetworkPluginHelper::ipTipsMessage(const DeviceType &devType) +{ + DeviceType type = static_cast(devType); + QList> tipMessage; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != type) + continue; + + QStringList ipv4 = device->ipv4(); + if (ipv4.isEmpty() || ipv4[0].isEmpty()) + continue; + + QStringList ipv4Messages; + for (int i = 0; i < ipv4.size(); i++) { + ipv4Messages << (i < 3 ? ipv4[i] : "......"); + if (i >= 3) + break; + } + + tipMessage << QPair({ device->deviceName(), ipv4Messages }); + } + return tipMessage; +} + +void NetworkPluginHelper::updateTooltips() +{ + switch (m_pluginState) { + case PluginState::Connected: { + QList> textList; + textList << ipTipsMessage(DeviceType::Wireless) << ipTipsMessage(DeviceType::Wired); + m_tipsWidget->setContext(textList); + break; + } + case PluginState::WirelessConnected: + m_tipsWidget->setContext(ipTipsMessage(DeviceType::Wireless)); + break; + case PluginState::WiredConnected: + m_tipsWidget->setContext(ipTipsMessage(DeviceType::Wired)); + break; + case PluginState::Disabled: + case PluginState::WirelessDisabled: + case PluginState::WiredDisabled: { + QList> tips; + tips << QPair({ tr("Device disabled"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Unknown: + case PluginState::Nocable: { + QList> tips; + tips << QPair({ tr("Network cable unplugged"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Disconnected: + case PluginState::WirelessDisconnected: + case PluginState::WiredDisconnected: { + QList> tips; + tips << QPair({ tr("Not connected"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Connecting: + case PluginState::WirelessConnecting: + case PluginState::WiredConnecting: { + QList> tips; + tips << QPair({ tr("Connecting"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::ConnectNoInternet: + case PluginState::WirelessConnectNoInternet: + case PluginState::WiredConnectNoInternet: { + QList> tips; + tips << QPair({ tr("Connected but no Internet access"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Failed: + case PluginState::WirelessFailed: + case PluginState::WiredFailed: { + QList> tips; + tips << QPair({ tr("Connection failed"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::WiredIpConflicted: + case PluginState::WirelessIpConflicted: { + QList> tips; + tips << QPair({ tr("IP conflict"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + } +} + +QIcon *NetworkPluginHelper::trayIcon() const +{ + return m_trayIcon; +} + +QIcon NetworkPluginHelper::icon(int colorType) const +{ + return QIcon::fromTheme(iconPath(colorType)); +} + +QString NetworkPluginHelper::iconPath(int colorType) const +{ + QString stateString; + QString iconString; + QString localPath = (colorType == DGuiApplicationHelper::ColorType::DarkType ? ":/dark/" : ":/light/"); + + switch (m_pluginState) { + case PluginState::Disabled: + case PluginState::WirelessDisabled: + stateString = "disabled"; + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + case PluginState::WiredDisabled: + stateString = "disabled"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + case PluginState::Connected: + case PluginState::WirelessConnected: { + bool isWlan6 = false; + AccessPoints *activeAp = getStrongestAp(); + if (activeAp) { + isWlan6 = (activeAp->type() == AccessPoints::WlanType::wlan6); + } + + stateString = getStrengthStateString(activeAp ? activeAp->strength() : 0); + if (isWlan6) { + iconString = QString("wireless6-%1-symbolic").arg(stateString); + } else { + iconString = QString("wireless-%1-symbolic").arg(stateString); + } + } + break; + case PluginState::WiredConnected: + stateString = "online"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + case PluginState::Disconnected: + case PluginState::WirelessDisconnected: + stateString = "0"; + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + case PluginState::WiredDisconnected: + stateString = "none"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + case PluginState::Connecting: { + if (QTime::currentTime().second() & 2) { + stateString = getStrengthStateString(QTime::currentTime().msec() / 10 % 100); + iconString = QString("wireless-%1-symbolic").arg(stateString); + } else { + const int index = QTime::currentTime().msec() / 200 % 10; + const int num = index + 1; + iconString = QString("network-wired-symbolic-connecting%1").arg(num); + } + break; + } + case PluginState::WirelessConnecting: { + stateString = getStrengthStateString(QTime::currentTime().msec() / 10 % 100); + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + } + case PluginState::WiredConnecting: { + const int index = QTime::currentTime().msec() / 200 % 10; + const int num = index + 1; + iconString = QString("network-wired-symbolic-connecting%1").arg(num); + break; + } + case PluginState::ConnectNoInternet: + case PluginState::WirelessConnectNoInternet: { + // 无线已连接但无法访问互联网 offline + bool isWlan6 = false; + AccessPoints *connectedAp = getConnectedAp(); + if (connectedAp) { + isWlan6 = (connectedAp->type() == AccessPoints::WlanType::wlan6); + } + + stateString = "offline"; + if (isWlan6) { + iconString = QString("wireless6-%1-symbolic").arg(stateString); + } else { + iconString = QString("wireless-%1-symbolic").arg(stateString); + } + break; + } + case PluginState::WiredConnectNoInternet: { + stateString = "warning"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::WiredFailed: { + // 有线连接失败none变为offline + stateString = "offline"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::Unknown: + case PluginState::Nocable: { + stateString = "error"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::WirelessIpConflicted: { + stateString = "offline"; + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + } + case PluginState::WiredIpConflicted: { + stateString = "offline"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::WirelessFailed: + case PluginState::Failed: { + // 无线连接失败改为 disconnect + stateString = "disconnect"; + iconString = QString("wireless-%1").arg(stateString); + break; + } + } + return localPath + iconString; +} + +void NetworkPluginHelper::refreshIcon() +{ + int colorType = m_isDarkIcon ? DGuiApplicationHelper::ColorType::DarkType : DGuiApplicationHelper::ColorType::LightType; + (*m_trayIcon) = icon(colorType); + emit iconChanged(); +} + +void NetworkPluginHelper::setIconDark(bool isDark) +{ + m_isDarkIcon = isDark; +} + +int NetworkPluginHelper::deviceCount(const DeviceType &devType) const +{ + // 获取指定的设备类型的设备数量 + int count = 0; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *dev : devices) + if (dev->deviceType() == static_cast(devType)) + count++; + + return count; +} + +void NetworkPluginHelper::onDeviceAdded(QList devices) +{ + // 处理新增设备的信号 + for (NetworkDeviceBase *device : devices) { + // 当网卡连接状态发生变化的时候重新绘制任务栏的图标 + connect(device, &NetworkDeviceBase::deviceStatusChanged, this, &NetworkPluginHelper::onUpdatePlugView); + + emit addDevice(device->path()); + switch (device->deviceType()) { + case DeviceType::Wired: { + WiredDevice *wiredDevice = static_cast(device); + + connect(wiredDevice, &WiredDevice::connectionAdded, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionRemoved, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionPropertyChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::enableChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::connectionChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::activeConnectionChanged, this, &NetworkPluginHelper::onUpdatePlugView); + } break; + case DeviceType::Wireless: { + WirelessDevice *wirelessDevice = static_cast(device); + + connect(wirelessDevice, &WirelessDevice::networkAdded, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::networkAdded, this, &NetworkPluginHelper::onAccessPointsAdded); + connect(wirelessDevice, &WirelessDevice::networkRemoved, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::enableChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::connectionChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::hotspotEnableChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::activeConnectionChanged, this, &NetworkPluginHelper::onActiveConnectionChanged); + + wirelessDevice->scanNetwork(); + } break; + default: + break; + } + } + + onUpdatePlugView(); +} + +void NetworkPluginHelper::invokeMenuItem(const QString &menuId) +{ + switch (menuId.toInt()) { + case MenuItemKey::MenuEnable: + setDeviceEnabled(DeviceType::Wired, true); + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, true); + break; + case MenuItemKey::MenuDisable: + setDeviceEnabled(DeviceType::Wired, false); + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, false); + break; + case MenuItemKey::MenuWiredEnable: + setDeviceEnabled(DeviceType::Wired, true); + break; + case MenuItemKey::MenuWiredDisable: + setDeviceEnabled(DeviceType::Wired, false); + break; + case MenuItemKey::MenuWirelessEnable: + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, true); + break; + case MenuItemKey::MenuWirelessDisable: + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, false); + break; + case MenuItemKey::MenuSettings: + NetworkDBusProxy::ShowPage("network"); + break; + default: + break; + } +} + +bool NetworkPluginHelper::needShowControlCenter() +{ + QList devices = NetworkController::instance()->devices(); + // 如果没有网络设备,则直接唤起控制中心 + if (devices.size() == 0) + return true; + + for (NetworkDeviceBase *device : devices) { + if (!device->isEnabled()) + continue; + + if (device->deviceType() == DeviceType::Wired) { + WiredDevice *wiredDevice = static_cast(device); + // 只要有一个有线网卡存在连接列表,就让其弹出网络列表 + if (!wiredDevice->items().isEmpty()) + return false; + } else if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *wirelessDevice = static_cast(device); + if (!wirelessDevice->accessPointItems().isEmpty()) + return false; + } + } + + return true; +} + +bool NetworkPluginHelper::deviceEnabled(const DeviceType &deviceType) const +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType && device->isEnabled()) + return true; + + return false; +} + +void NetworkPluginHelper::setDeviceEnabled(const DeviceType &deviceType, bool enabeld) +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType) + device->setEnabled(enabeld); +} + +bool NetworkPluginHelper::wirelessIsActive() const +{ + dde::network::NetworkDBusProxy *networkInter = new dde::network::NetworkDBusProxy(); + networkInter->deleteLater(); + return !networkInter->enabled(); +} + +QString NetworkPluginHelper::getStrengthStateString(int strength) const +{ + if (5 >= strength) + return "0"; + + if (30 >= strength) + return "20"; + + if (55 >= strength) + return "40"; + + if (65 >= strength) + return "60"; + + return "80"; +} + +AccessPoints *NetworkPluginHelper::getStrongestAp() const +{ + AccessPoints *maxAps = nullptr; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + WirelessDevice *dev = static_cast(device); + AccessPoints *ap = dev->activeAccessPoints(); + if (ap && (!maxAps || maxAps->strength() < ap->strength())) + maxAps = ap; + } + + return maxAps; +} + +AccessPoints *NetworkPluginHelper::getConnectedAp() const +{ + AccessPoints *connectedAp = nullptr; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + WirelessDevice *dev = static_cast(device); + AccessPoints *ap = dev->activeAccessPoints(); + if (ap && ap->connected() && (!connectedAp || connectedAp->strength() < ap->strength())) + connectedAp = ap; + } + + return connectedAp; +} + +const QString NetworkPluginHelper::contextMenu(bool hasSetting) const +{ + int wiredCount = deviceCount(DeviceType::Wired); + int wirelessCount = deviceCount(DeviceType::Wireless); + bool wiredEnabled = deviceEnabled(DeviceType::Wired); + bool wirelessEnabeld = deviceEnabled(DeviceType::Wireless); + QList items; + if (wiredCount && wirelessCount) { + items.reserve(3); + QMap wireEnable; + if (wiredEnabled) { + wireEnable["itemId"] = QString::number(MenuWiredDisable); + wireEnable["itemText"] = tr("Disable wired connection"); + } else { + wireEnable["itemId"] = QString::number(MenuWiredEnable); + wireEnable["itemText"] = tr("Enable wired connection"); + } + + wireEnable["isActive"] = true; + items.push_back(wireEnable); + + QMap wirelessEnable; + if (wirelessEnabeld) { + wirelessEnable["itemText"] = tr("Disable wireless connection"); + wirelessEnable["itemId"] = QString::number(MenuWirelessDisable); + } else { + wirelessEnable["itemText"] = tr("Enable wireless connection"); + wirelessEnable["itemId"] = QString::number(MenuWirelessEnable); + } + + wirelessEnable["isActive"] = wirelessIsActive(); + items.push_back(wirelessEnable); + } else if (wiredCount || wirelessCount) { + items.reserve(2); + QMap enable; + if (wiredEnabled || wirelessEnabeld) { + enable["itemId"] = QString::number(MenuDisable); + enable["itemText"] = tr("Disable network"); + } else { + enable["itemId"] = QString::number(MenuEnable); + enable["itemText"] = tr("Enable network"); + } + + enable["isActive"] = (wirelessCount > 0 ? wirelessIsActive() : true); + items.push_back(enable); + } + if (hasSetting) { + QMap settings; + settings["itemId"] = QString::number(MenuSettings); + settings["itemText"] = tr("Network settings"); + settings["isActive"] = true; + items.push_back(settings); + } + QMap menu; + menu["items"] = items; + menu["checkableMenu"] = false; + menu["singleCheck"] = false; + + return QJsonDocument::fromVariant(menu).toJson(); +} + +QWidget *NetworkPluginHelper::itemTips() +{ + return m_tipsWidget->height() == 0 ? nullptr : m_tipsWidget; +} + +void NetworkPluginHelper::onUpdatePlugView() +{ + updatePluginState(); + updateTooltips(); + refreshIcon(); + emit viewUpdate(); +} + +void NetworkPluginHelper::onActiveConnectionChanged() +{ + WirelessDevice *wireless = static_cast(sender()); + DeviceStatus status = wireless->deviceStatus(); + if (status == DeviceStatus::Disconnected + || status == DeviceStatus::Deactivation) + return; + + QString wirelessPath = wireless->path(); + for (auto conn : NetworkManager::activeConnections()) { + if (!conn->id().isEmpty() && conn->devices().contains(wirelessPath)) { + NetworkManager::ConnectionSettings::Ptr connSettings = conn->connection()->settings(); + NetworkManager::WirelessSetting::Ptr wSetting = connSettings->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + const QString settingMacAddress = wSetting->macAddress().toHex().toUpper(); + const QString deviceMacAddress = wireless->realHwAdr().remove(":"); + if (!settingMacAddress.isEmpty() && settingMacAddress != deviceMacAddress) + continue; + + // 隐藏网络配置错误时提示重连 + if (wSetting && wSetting->hidden()) { + NetworkManager::WirelessSecuritySetting::Ptr wsSetting = connSettings->setting(NetworkManager::Setting::SettingType::WirelessSecurity).staticCast(); + if (wsSetting && NetworkManager::WirelessSecuritySetting::KeyMgmt::Unknown == wsSetting->keyMgmt()) { + for (auto ap : wireless->accessPointItems()) { + if (ap->ssid() == wSetting->ssid() && ap->secured() && ap->strength() > 0) { + // 隐藏网络逻辑是要输入密码重连,所以后端无等待,前端重连 + m_networkDialog->setConnectWireless(wireless->path(), ap->ssid(), false); + break; + } + } + } + } + } + } + + onUpdatePlugView(); +} + +bool NetworkPluginHelper::needSetPassword(AccessPoints *accessPoint) const +{ + // 如果当前热点不是隐藏热点,或者当前热点不是加密热点,则需要设置密码(因为这个函数只是处理隐藏且加密的热点) + if (!accessPoint->hidden() || !accessPoint->secured()) + return false; + + WirelessDevice *wirelessDevice = nullptr; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == DeviceType::Wireless && device->path() == accessPoint->devicePath()) { + wirelessDevice = static_cast(device); + break; + } + } + + // 如果连这个连接的设备都找不到,则无需设置密码 + if (!wirelessDevice) + return false; + + // 查找该热点对应的连接的UUID + NetworkManager::Connection::Ptr connection; + NetworkManager::WirelessDevice::Ptr device(new NetworkManager::WirelessDevice(wirelessDevice->path())); + NetworkManager::Connection::List connectionlist = device->availableConnections(); + for (NetworkManager::Connection::Ptr conn : connectionlist) { + NetworkManager::WirelessSetting::Ptr wSetting = conn->settings()->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + if (wSetting->ssid() != accessPoint->ssid()) + continue; + + connection = conn; + break; + } + + if (connection.isNull()) + return true; + + // 查找该连接对应的密码配置信息 + NetworkManager::ConnectionSettings::Ptr settings = connection->settings(); + if (settings.isNull()) + return true; + + NetworkManager::WirelessSecuritySetting::Ptr securitySetting = + settings->setting(NetworkManager::Setting::SettingType::WirelessSecurity).staticCast(); + + NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt = securitySetting->keyMgmt(); + if (keyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaNone || keyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::Unknown) + return true; + + NetworkManager::Setting::SettingType sType = NetworkManager::Setting::SettingType::WirelessSecurity; + if (keyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaEap) + sType = NetworkManager::Setting::SettingType::Security8021x; + + QDBusPendingReply reply; + reply = connection->secrets(settings->setting(sType)->name()); + + reply.waitForFinished(); + if (reply.isError() || !reply.isValid()) + return true; + + NMVariantMapMap sSecretsMapMap = reply.value(); + QSharedPointer setting = settings->setting(sType).staticCast(); + setting->secretsFromMap(sSecretsMapMap.value(setting->name())); + + if (securitySetting.isNull()) + return true; + + QString psk; + switch (keyMgmt) { + case NetworkManager::WirelessSecuritySetting::KeyMgmt::Wep: + psk = securitySetting->wepKey0(); + break; + case NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaPsk: + default: + psk = securitySetting->psk(); + break; + } + + // 如果该密码存在,则无需调用设置密码信息 + return psk.isEmpty(); +} + +void NetworkPluginHelper::handleAccessPointSecure(AccessPoints *accessPoint) +{ + if (needSetPassword(accessPoint)) + m_networkDialog->setConnectWireless(accessPoint->devicePath(), accessPoint->ssid()); +} + +void NetworkPluginHelper::onAccessPointsAdded(QList newAps) +{ + for (AccessPoints *newAp : newAps) { + connect(newAp, &AccessPoints::securedChanged, this, [ this, newAp ] { + handleAccessPointSecure(newAp); + }); + handleAccessPointSecure(newAp); + } +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.h new file mode 100644 index 000000000..86bd176e1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.h @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPLUGINHELPER_H +#define NETWORKPLUGINHELPER_H +#include "utils.h" +#include "item/devicestatushandler.h" + +#include + +#include + + +DGUI_USE_NAMESPACE + +namespace dde { +namespace network { +enum class DeviceType; +class NetworkDeviceBase; +class AccessPoints; +} // namespace network +} // namespace dde + +class QTimer; +class NetItem; + +namespace dde { +namespace networkplugin { + +class NetworkDialog; +class TipsWidget; + +class NetworkPluginHelper : public QObject +{ + Q_OBJECT + +public: + enum MenuItemKey : int { + MenuSettings = 1, + MenuEnable, + MenuDisable, + MenuWiredEnable, + MenuWiredDisable, + MenuWirelessEnable, + MenuWirelessDisable, + }; + +Q_SIGNALS: + void sendIpConflictDect(int); + void addDevice(const QString &devicePath); + void viewUpdate(); + void iconChanged(); + +public: + explicit NetworkPluginHelper(NetworkDialog *networkDialog, QObject *parent = Q_NULLPTR); + ~NetworkPluginHelper(); + + void invokeMenuItem(const QString &menuId); + bool needShowControlCenter(); + const QString contextMenu(bool hasSetting) const; + QWidget *itemTips(); + PluginState getPluginState(); + void updatePluginState(); + void updateTooltips(); // 更新提示的内容 + + QIcon *trayIcon() const; + QIcon icon(int colorType) const; + QString iconPath(int colorType) const; + void refreshIcon(); + void setIconDark(bool isDark); + +private: + void initUi(); + void initConnection(); + bool deviceEnabled(const DeviceType &deviceType) const; + void setDeviceEnabled(const DeviceType &deviceType, bool enabeld); + bool wirelessIsActive() const; + QString getStrengthStateString(int strength) const; + dde::network::AccessPoints *getStrongestAp() const; + dde::network::AccessPoints *getConnectedAp() const; + + void handleAccessPointSecure(AccessPoints *accessPoint); + + int deviceCount(const DeviceType &devType) const; + QList> ipTipsMessage(const DeviceType &devType); + bool needSetPassword(AccessPoints *accessPoint) const; + +private Q_SLOTS: + void onDeviceAdded(QList devices); + void onUpdatePlugView(); + void onActiveConnectionChanged(); + + void onAccessPointsAdded(QList newAps); + +private: + PluginState m_pluginState; + + TipsWidget *m_tipsWidget; + bool m_switchWire; + QPixmap m_iconPixmap; + + QSet m_devicePaths; // 记录无线设备Path,防止信号重复连接 + QString m_lastActiveWirelessDevicePath; + NetworkDialog *m_networkDialog; + QIcon *m_trayIcon; + QTimer *m_refreshIconTimer; + bool m_isDarkIcon; // 是深色主题 +}; +} +} + +#endif // NETWORKPLUGINHELPER_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/plugin_global.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/plugin_global.h new file mode 100644 index 000000000..c04199596 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/plugin_global.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef PLUGIN_GLOBAL_H +#define PLUGIN_GLOBAL_H + +#define NETWORKPLUGIN_BEGIN_NAMESPACE namespace dde { namespace networkplugin { +#define NETWORKPLUGIN_END_NAMESPACE }} +#define NETWORKPLUGIN_USE_NAMESPACE using namespace dde::networkplugin; +#define NETWORKPLUGIN_NAMESPACE dde::networkplugin + + +#endif diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select.png new file mode 100644 index 000000000..886736105 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select@2x.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select@2x.png new file mode 100644 index 000000000..a04e6e4d5 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select@2x.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press.png new file mode 100644 index 000000000..d6dbc2124 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press@2x.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press@2x.png new file mode 100644 index 000000000..7d67765b4 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press@2x.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/disconnect.svg new file mode 100644 index 000000000..f18f360a1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/disconnect.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-disabled-symbolic.svg new file mode 100644 index 000000000..0588d0f06 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-disabled-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-error-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-error-symbolic.svg new file mode 100644 index 000000000..0e5ec862f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-error-symbolic.svg @@ -0,0 +1,8 @@ + + + network-error-unknown + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-none-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-none-symbolic.svg new file mode 100644 index 000000000..2f0b286bc --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-none-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-offline-symbolic.svg new file mode 100644 index 000000000..6e9cd759c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-online-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-online-symbolic.svg new file mode 100644 index 000000000..b014c7e22 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-online-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-warning-symbolic.svg new file mode 100644 index 000000000..258a63b6f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-warning-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting1.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting1.svg new file mode 100644 index 000000000..4df47e0d9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting1.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting1 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting2.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting2.svg new file mode 100644 index 000000000..0dc1af6f3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting2.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting2 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting3.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting3.svg new file mode 100644 index 000000000..4c6ce3716 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting3.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting3 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting4.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting4.svg new file mode 100644 index 000000000..487a15eb7 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting4.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting4 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting5.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting5.svg new file mode 100644 index 000000000..1f76ba5ce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting5.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting5 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic.svg new file mode 100644 index 000000000..b014c7e22 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/refresh.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/refresh.svg new file mode 100644 index 000000000..5ef071ada --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/refresh.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/security.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/security.svg new file mode 100644 index 000000000..b126160dc --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/security.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/select.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/select.svg new file mode 100644 index 000000000..e1c2b319c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/select.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-0-symbolic.svg new file mode 100644 index 000000000..e6bebf631 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-0-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-20-symbolic.svg new file mode 100644 index 000000000..3d4a6e780 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-20-symbolic.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-40-symbolic.svg new file mode 100644 index 000000000..30669f645 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-40-symbolic.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-60-symbolic.svg new file mode 100644 index 000000000..0985e6a04 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-60-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-80-symbolic.svg new file mode 100644 index 000000000..137e21c9f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-80-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-background.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-background.svg new file mode 100644 index 000000000..ba17ed434 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-background.svg @@ -0,0 +1,18 @@ + + + + wireless-background-48px + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disabled-symbolic.svg new file mode 100644 index 000000000..670c64c78 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disabled-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect-symbolic.svg new file mode 100644 index 000000000..5a5a0ff5f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect-symbolic.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect.svg new file mode 100644 index 000000000..724b3902a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect.svg @@ -0,0 +1,14 @@ + + + + wireless-disconnect + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-offline-symbolic.svg new file mode 100644 index 000000000..fbbdf9422 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-0-symbolic.svg new file mode 100644 index 000000000..d0adcf653 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-0-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-none-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-20-symbolic.svg new file mode 100644 index 000000000..fb967806d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-20-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-low-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-40-symbolic.svg new file mode 100644 index 000000000..cabd8198f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-40-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-medium-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-60-symbolic.svg new file mode 100644 index 000000000..71c88c81a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-60-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-high-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-80-symbolic.svg new file mode 100644 index 000000000..3a6fa4a68 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-80-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-full-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-no-route-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-no-route-symbolic.svg new file mode 100644 index 000000000..db5f2b951 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-no-route-symbolic.svg @@ -0,0 +1,8 @@ + + + network-wirelss-6-no-route-symbolic + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-offline-symbolic.svg new file mode 100644 index 000000000..3e6526b35 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-offline-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-offline-symbolic + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-warning-symbolic.svg new file mode 100644 index 000000000..7945aceec --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-warning-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-warning-symbolic + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/disconnect.svg new file mode 100644 index 000000000..cf2971327 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/disconnect.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-disabled-symbolic.svg new file mode 100644 index 000000000..d6d5fc20d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-disabled-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-error-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-error-symbolic.svg new file mode 100644 index 000000000..aa96bd677 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-error-symbolic.svg @@ -0,0 +1,8 @@ + + + network-error-unknown-dark + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-none-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-none-symbolic.svg new file mode 100644 index 000000000..9e0bc5e31 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-none-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-offline-symbolic.svg new file mode 100644 index 000000000..f0fd47362 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-online-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-online-symbolic.svg new file mode 100644 index 000000000..50d901c62 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-online-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-warning-symbolic.svg new file mode 100644 index 000000000..ebd1e11d3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-warning-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting1.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting1.svg new file mode 100644 index 000000000..e3127d2fd --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting1.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting2.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting2.svg new file mode 100644 index 000000000..46534627a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting2.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting3.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting3.svg new file mode 100644 index 000000000..5efbbc6d9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting3.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting4.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting4.svg new file mode 100644 index 000000000..a1d03e412 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting4.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting5.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting5.svg new file mode 100644 index 000000000..9247612c1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting5.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic.svg new file mode 100644 index 000000000..50d901c62 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/refresh.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/refresh.svg new file mode 100644 index 000000000..dc2950711 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/refresh.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/security.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/security.svg new file mode 100644 index 000000000..6301d47de --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/security.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/select.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/select.svg new file mode 100644 index 000000000..4071c706a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/select.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-0-symbolic.svg new file mode 100644 index 000000000..d5babcbee --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-0-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-20-symbolic.svg new file mode 100644 index 000000000..5ffe56aab --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-20-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-40-symbolic.svg new file mode 100644 index 000000000..d6f6c012e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-40-symbolic.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-60-symbolic.svg new file mode 100644 index 000000000..2b3dc7c92 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-60-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-80-symbolic.svg new file mode 100644 index 000000000..20bcbc2fc --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-80-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-background.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-background.svg new file mode 100644 index 000000000..ba17ed434 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-background.svg @@ -0,0 +1,18 @@ + + + + wireless-background-48px + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disabled-symbolic.svg new file mode 100644 index 000000000..cf5fdd82a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disabled-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect-symbolic.svg new file mode 100644 index 000000000..ec80d3197 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect-symbolic.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect.svg new file mode 100644 index 000000000..ac0e27b67 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect.svg @@ -0,0 +1,14 @@ + + + + wireless-disconnect + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-offline-symbolic.svg new file mode 100644 index 000000000..3c35a9ae9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-0-symbolic.svg new file mode 100644 index 000000000..43f6b9aff --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-0-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-none-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-20-symbolic.svg new file mode 100644 index 000000000..c097f8882 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-20-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-low-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-40-symbolic.svg new file mode 100644 index 000000000..fde3f1e27 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-40-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-medium-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-60-symbolic.svg new file mode 100644 index 000000000..0a0c0a251 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-60-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-high-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-80-symbolic.svg new file mode 100644 index 000000000..3eae7b0a9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-80-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-full-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-no-route-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-no-route-symbolic.svg new file mode 100644 index 000000000..f1e5dbc03 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-no-route-symbolic.svg @@ -0,0 +1,8 @@ + + + network-wirelss-6-no-route-symbolic-dark + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-offline-symbolic.svg new file mode 100644 index 000000000..ac90da349 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-offline-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-offline-symbolic-dark + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-warning-symbolic.svg new file mode 100644 index 000000000..7173ff96e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-warning-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-warning-symbolic-dark + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.cpp new file mode 100644 index 000000000..575fdc457 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.cpp @@ -0,0 +1,330 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "secretagent.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_PRINT qDebug() << __FILE__ << "line:" << __LINE__ << "function:" << __FUNCTION__ << "Message:" + +NETWORKPLUGIN_USE_NAMESPACE + +SecretAgent::SecretAgent(bool greeter, QObject *parent) + : NetworkManager::SecretAgent(QStringLiteral("com.deepin.system.network.SecretAgent"), parent) +{ + m_greeter = greeter; + qInfo() << "register secret agent: com.deepin.system.network.SecretAgent mode: " << (m_greeter ? "greeter" : "lock"); + + qDBusRegisterMetaType(); +} + +SecretAgent::~SecretAgent() = default; + +NMVariantMapMap SecretAgent::GetSecrets(const NMVariantMapMap &connection, + const QDBusObjectPath &connection_path, + const QString &setting_name, + const QStringList &hints, + uint flags) +{ + DEBUG_PRINT << "Path:" << connection_path.path(); + DEBUG_PRINT << "Setting name:" << setting_name; + DEBUG_PRINT << "Hints:" << hints; + DEBUG_PRINT << "Flags:" << flags; + + const QString callId = connection_path.path() % setting_name; + for (const SecretsRequest &request : m_calls) { + if (request == callId) { + qWarning() << "GetSecrets was called again! This should not happen, cancelling first call" << connection_path.path() + << setting_name; + CancelGetSecrets(connection_path, setting_name); + break; + } + } + + setDelayedReply(true); + SecretsRequest request(SecretsRequest::GetSecrets); + request.callId = callId; + request.connection = connection; + request.connection_path = connection_path; + request.flags = static_cast(flags); + request.hints = hints; + request.setting_name = setting_name; + request.message = message(); + m_calls << request; + + processNext(); + + return {}; +} + +void SecretAgent::SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) +{ + setDelayedReply(true); + SecretsRequest::Type type; + if (hasSecrets(connection)) { + type = SecretsRequest::SaveSecrets; + } else { + type = SecretsRequest::DeleteSecrets; + } + SecretsRequest request(type); + request.connection = connection; + request.connection_path = connection_path; + request.message = message(); + m_calls << request; + + processNext(); +} + +void SecretAgent::DeleteSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) +{ + setDelayedReply(true); + SecretsRequest request(SecretsRequest::DeleteSecrets); + request.connection = connection; + request.connection_path = connection_path; + request.message = message(); + m_calls << request; + + processNext(); +} + +void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connection_path, const QString &setting_name) +{ + QString callId = connection_path.path() % setting_name; + for (int i = 0; i < m_calls.size(); ++i) { + SecretsRequest request = m_calls.at(i); + if (request.type == SecretsRequest::GetSecrets && callId == request.callId) { + if (m_ssid == request.ssid) { + DEBUG_PRINT << "process finished (agent canceled)"; + m_ssid.clear(); + } + sendError(SecretAgent::AgentCanceled, QStringLiteral("Agent canceled the password dialog"), request.message); + m_calls.removeAt(i); + break; + } + } + + processNext(); +} + +void SecretAgent::onInputPassword(const QString &key, const QString &password, bool input) +{ + for (int i = 0; i < m_calls.size(); ++i) { + SecretsRequest &request = m_calls[i]; + if (request.type == SecretsRequest::GetSecrets && request.ssid == key) { + if (input) { + QJsonObject resultJsonObj; + QJsonArray secretsJsonArray; + secretsJsonArray.append(password); + resultJsonObj.insert("secrets", secretsJsonArray); + + NetworkManager::ConnectionSettings::Ptr connectionSettings = + NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); + NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); + auto needSecrets = setting->needSecrets(request.flags & RequestNew); + if (!password.isEmpty() && !needSecrets.isEmpty()) { + QVariantMap result; + result.insert(needSecrets.first(), password); + request.connection[request.setting_name] = result; + sendSecrets(request.connection, request.message); + } + } else { + sendError(SecretAgent::UserCanceled, QStringLiteral("user canceled"), request.message); + } + } + } +} + +void SecretAgent::processNext() +{ + int i = 0; + while (i < m_calls.size()) { + SecretsRequest &request = m_calls[i]; + switch (request.type) { + case SecretsRequest::GetSecrets: + if (processGetSecrets(request)) { + m_calls.removeAt(i); + continue; + } + break; + case SecretsRequest::SaveSecrets: + if (processSaveSecrets(request)) { + m_calls.removeAt(i); + continue; + } + break; + case SecretsRequest::DeleteSecrets: + if (processDeleteSecrets(request)) { + m_calls.removeAt(i); + continue; + } + break; + } + ++i; + } +} + +bool SecretAgent::processGetSecrets(SecretsRequest &request) +{ + if (!m_ssid.isEmpty()) { + return false; + } + + NetworkManager::ConnectionSettings::Ptr connectionSettings = + NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); + NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); + + const bool requestNew = request.flags & RequestNew; + const bool userRequested = request.flags & UserRequested; + const bool allowInteraction = request.flags & AllowInteraction; + const bool isVpn = (setting->type() == NetworkManager::Setting::Vpn); + + if (isVpn) { + NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); + if (vpnSetting->serviceType() == QLatin1String("org.freedesktop.NetworkManager.ssh") && vpnSetting->data()["auth-type"] == QLatin1String("ssh-agent")) { + QString authSock = qgetenv("SSH_AUTH_SOCK"); + qDebug() << Q_FUNC_INFO << "Sending SSH auth socket" << authSock; + + if (authSock.isEmpty()) { + sendError(SecretAgent::NoSecrets, QStringLiteral("SSH_AUTH_SOCK not present"), request.message); + } else { + NMStringMap secrets; + secrets.insert(QStringLiteral("ssh-auth-sock"), authSock); + + QVariantMap secretData; + secretData.insert(QStringLiteral("secrets"), QVariant::fromValue(secrets)); + request.connection[request.setting_name] = secretData; + sendSecrets(request.connection, request.message); + } + return true; + } + } + + if (!m_greeter) { + if (!requestNew) { + // 需要去解锁密码环,取密码 + return false; + } + + NMStringMap secretsMap; + setting->secretsFromStringMap(secretsMap); + if (!(isVpn) && setting->needSecrets(requestNew).isEmpty()) { + // Enough secrets were retrieved from storage + request.connection[request.setting_name] = setting->secretsToMap(); + sendSecrets(request.connection, request.message); + return true; + } + } + + if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) + || (isVpn && allowInteraction)) { + DEBUG_PRINT << "process request secrets"; + + // 只处理无线的 + if (connectionSettings->connectionType() != NetworkManager::ConnectionSettings::Wireless) { + sendError(SecretAgent::InternalError, QStringLiteral("dss can only handle wireless"), request.message); + return true; + } + + if (!userRequested) { + sendError(SecretAgent::AgentCanceled, QStringLiteral("dss only support user quest"), request.message); + return true; + } + + QString devPath; + NetworkManager::ActiveConnection::List actives = NetworkManager::activeConnections(); + for (auto it = actives.begin(); it != actives.end(); ++it) { + if ((*it)->connection()->path() == request.connection_path.path()) { + devPath = (*it)->devices().first(); + break; + } + } + m_ssid = connectionSettings->id(); + request.ssid = m_ssid; + DEBUG_PRINT << "requestPassword" << devPath << connectionSettings->id(); + Q_EMIT requestPassword(devPath, connectionSettings->id(), true); + return false; + } else if (isVpn && userRequested) { // just return what we have + NMVariantMapMap result; + NetworkManager::VpnSetting::Ptr vpnSetting; + vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); + // FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it + // won't ask for additional secrets with AllowInteraction flag which would display the authentication dialog + if (vpnSetting->secretsToMap().isEmpty()) { + // Insert an empty secrets map as it was before I fixed it in NetworkManagerQt to make sure NM will ask again + // with flags we need + QVariantMap secretsMap; + secretsMap.insert(QStringLiteral("secrets"), QVariant::fromValue(NMStringMap())); + result.insert(QStringLiteral("vpn"), secretsMap); + } else { + result.insert(QStringLiteral("vpn"), vpnSetting->secretsToMap()); + } + sendSecrets(result, request.message); + return true; + } else if (setting->needSecrets().isEmpty()) { + NMVariantMapMap result; + result.insert(setting->name(), setting->secretsToMap()); + sendSecrets(result, request.message); + return true; + } else { + sendError(SecretAgent::InternalError, QStringLiteral("dss did not know how to handle the request"), request.message); + return true; + } +} + +bool SecretAgent::processSaveSecrets(SecretsRequest &request) const +{ + if (!request.saveSecretsWithoutReply) { + QDBusMessage reply = request.message.createReply(); + if (!QDBusConnection::systemBus().send(reply)) { + qWarning() << "Failed put save secrets reply into the queue"; + } + } + + return true; +} + +bool SecretAgent::processDeleteSecrets(SecretsRequest &request) const +{ + QDBusMessage reply = request.message.createReply(); + if (!QDBusConnection::systemBus().send(reply)) { + qWarning() << "Failed put delete secrets reply into the queue"; + } + + return true; +} + +bool SecretAgent::hasSecrets(const NMVariantMapMap &connection) const +{ + NetworkManager::ConnectionSettings connectionSettings(connection); + for (const NetworkManager::Setting::Ptr &setting : connectionSettings.settings()) { + if (!setting->secretsToMap().isEmpty()) { + return true; + } + } + + return false; +} + +void SecretAgent::sendSecrets(const NMVariantMapMap &secrets, const QDBusMessage &message) const +{ + QDBusMessage reply; + reply = message.createReply(QVariant::fromValue(secrets)); + if (!QDBusConnection::systemBus().send(reply)) { + qWarning() << "Failed put the secret into the queue"; + } +} + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.h new file mode 100644 index 000000000..53bde3f9f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.h @@ -0,0 +1,100 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef SECRETAGENT_H +#define SECRETAGENT_H + +#include "utils.h" + +#include + +NETWORKPLUGIN_BEGIN_NAMESPACE + +class SecretsRequest +{ +public: + enum Type { + GetSecrets, + SaveSecrets, + DeleteSecrets, + }; + explicit SecretsRequest(Type _type) + : type(_type) + , flags(NetworkManager::SecretAgent::None) + , saveSecretsWithoutReply(false) + { + } + inline bool operator==(const QString &other) const + { + return callId == other; + } + Type type; + QString callId; + NMVariantMapMap connection; + QDBusObjectPath connection_path; + QString setting_name; + QStringList hints; + NetworkManager::SecretAgent::GetSecretsFlags flags; + /** + * When a user connection is called on GetSecrets, + * the secret agent is supposed to save the secrets + * typed by user, when true proccessSaveSecrets + * should skip the DBus reply. + */ + bool saveSecretsWithoutReply; + QDBusMessage message; + QString ssid; +}; + +class Q_DECL_EXPORT SecretAgent : public NetworkManager::SecretAgent +{ + Q_OBJECT + +public: + explicit SecretAgent(bool greeter = false, QObject *parent = nullptr); + + ~SecretAgent() override; + +Q_SIGNALS: + void secretsError(const QString &connectionPath, const QString &message) const; + void requestPassword(const QString &dev, const QString &ssid, bool wait); + +public Q_SLOTS: + NMVariantMapMap GetSecrets(const NMVariantMapMap &, const QDBusObjectPath &, const QString &, const QStringList &, uint) override; + void SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) override; + void DeleteSecrets(const NMVariantMapMap &, const QDBusObjectPath &) override; + void CancelGetSecrets(const QDBusObjectPath &, const QString &) override; + + void onInputPassword(const QString &key, const QString &password, bool input); + +private: + void processNext(); + /** + * @brief processGetSecrets requests + * @param request the request we are processing + * @param ignoreWallet true if the code should avoid Wallet + * normally if it failed to open + * @return true if the item was processed + */ + bool processGetSecrets(SecretsRequest &request); + bool processSaveSecrets(SecretsRequest &request) const; + bool processDeleteSecrets(SecretsRequest &request) const; + + /** + * @brief hasSecrets verifies if the desired connection has secrets to store + * @param connection map with or without secrets + * @return true if the connection has secrets, false otherwise + */ + bool hasSecrets(const NMVariantMapMap &connection) const; + void sendSecrets(const NMVariantMapMap &secrets, const QDBusMessage &message) const; + bool needConnectNetwork(const NMVariantMapMap &connectionMap) const; + + QString m_ssid; + QList m_calls; + bool m_greeter; +}; + +NETWORKPLUGIN_END_NAMESPACE + +#endif // SECRETAGENT_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/utils.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/utils.h new file mode 100644 index 000000000..ed2682402 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/utils.h @@ -0,0 +1,199 @@ +// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef UTILS +#define UTILS +#include +#include +#include +#include +#include + +#include "plugin_global.h" + +namespace Utils { + +#define ICBC_CONF_FILE "/etc/deepin/icbc.conf" + +// /** +// * @brief SettingsPtr 根据给定信息返回一个QGSettings指针 +// * @param schema_id The id of the schema +// * @param path If non-empty, specifies the path for a relocatable schema +// * @param parent 创建指针的付对象 +// * @return +// */ +// inline const QGSettings *SettingsPtr(const QString &schema_id, const QByteArray &path = QByteArray(), QObject *parent = nullptr) { +// if (QGSettings::isSchemaInstalled(schema_id.toUtf8())) { +// QGSettings *settings = new QGSettings(schema_id.toUtf8(), path, parent); +// return settings; +// } +// qDebug() << "Cannot find gsettings, schema_id:" << schema_id; +// return nullptr; +// } + +// /** +// * @brief SettingsPtr 根据给定信息返回一个QGSettings指针 +// * @param module 传入QGSettings构造函数时,会添加"com.deepin.dde.dock.module."前缀 +// * @param path If non-empty, specifies the path for a relocatable schema +// * @param parent 创建指针的付对象 +// * @return +// */ +// inline const QGSettings *ModuleSettingsPtr(const QString &module, const QByteArray &path = QByteArray(), QObject *parent = nullptr) { +// return SettingsPtr("com.deepin.dde.dock.module." + module, path, parent); +// } + +/* convert 'some-key' to 'someKey' or 'SomeKey'. + * the second form is needed for appending to 'set' for 'setSomeKey' + */ +inline QString qtify_name(const char *name) +{ + bool next_cap = false; + QString result; + + while (*name) { + if (*name == '-') { + next_cap = true; + } else if (next_cap) { + result.append(QChar(*name).toUpper().toLatin1()); + next_cap = false; + } else { + result.append(*name); + } + + name++; + } + + return result; +} + +/** + * @brief SettingValue 根据给定信息返回获取的值 + * @param schema_id The id of the schema + * @param path If non-empty, specifies the path for a relocatable schema + * @param key 对应信息的key值 + * @param fallback 如果找不到信息,返回此默认值 + * @return + */ +inline const QVariant SettingValue(const QString &schema_id, const QByteArray &path = QByteArray(), const QString &key = QString(), const QVariant &fallback = QVariant()){ + // const QGSettings *settings = SettingsPtr(schema_id, path); + + // if (settings && ((settings->keys().contains(key)) || settings->keys().contains(qtify_name(key.toUtf8().data())))) { + // QVariant v = settings->get(key); + // delete settings; + // return v; + // } else{ + // qDebug() << "Cannot find gsettings, schema_id:" << schema_id + // << " path:" << path << " key:" << key + // << "Use fallback value:" << fallback; + // return fallback; + // } + return fallback; +} + +inline QPixmap renderSVG(const QString &path, const QSize &size, const qreal devicePixelRatio) { + QImageReader reader; + QPixmap pixmap; + reader.setFileName(path); + if (reader.canRead()) { + reader.setScaledSize(size * devicePixelRatio); + pixmap = QPixmap::fromImage(reader.read()); + pixmap.setDevicePixelRatio(devicePixelRatio); + } + else { + pixmap.load(path); + } + + return pixmap; +} + +inline QScreen *screenAt(const QPoint &point) { + for (QScreen *screen : qApp->screens()) { + const QRect r { screen->geometry() }; + const QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() }; + if (rect.contains(point)) { + return screen; + } + } + + return nullptr; +} + +//!!! 注意:这里传入的QPoint是未计算缩放的 +inline QScreen *screenAtByScaled(const QPoint &point) { + for (QScreen *screen : qApp->screens()) { + const QRect r { screen->geometry() }; + QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() }; + if (rect.contains(point)) { + return screen; + } + } + + return nullptr; +} + +inline bool isSettingConfigured(const QString& id, const QString& path, const QString& keyName) { + // if (!QGSettings::isSchemaInstalled(id.toUtf8())) { + // return false; + // } + // QGSettings setting(id.toUtf8(), path.toUtf8()); + // QVariant v = setting.get(keyName); + // if (!v.isValid()) { + // return false; + // } + // return v.toBool(); + return false; +} + +/** +* @brief 比较两个插件版本号的大小 +* @param pluginApi1 第一个插件版本号 +* @param pluginApi2 第二个插件版本号 +* @return 0:两个版本号相等,1:第一个版本号大,-1:第二个版本号大 +*/ +inline int comparePluginApi(const QString &pluginApi1, const QString &pluginApi2) { + // 版本号相同 + if (pluginApi1 == pluginApi2) + return 0; + + // 拆分版本号 + QStringList subPluginApis1 = pluginApi1.split(".", Qt::SkipEmptyParts, Qt::CaseSensitive); + QStringList subPluginApis2 = pluginApi2.split(".", Qt::SkipEmptyParts, Qt::CaseSensitive); + for (int i = 0; i < subPluginApis1.size(); ++i) { + auto subPluginApi1 = subPluginApis1[i]; + if (subPluginApis2.size() > i) { + auto subPluginApi2 = subPluginApis2[i]; + + // 相等判断下一个子版本号 + if (subPluginApi1 == subPluginApi2) + continue; + + // 转成整形比较 + if (subPluginApi1.toInt() > subPluginApi2.toInt()) { + return 1; + } else { + return -1; + } + } + } + + // 循环结束但是没有返回,说明子版本号个数不同,且前面的子版本号都相同 + // 子版本号多的版本号大 + if (subPluginApis1.size() > subPluginApis2.size()) { + return 1; + } else { + return -1; + } +} + +/** +* @brief 当前是否处于wayland的环境 +* @return true:是,false:否 +*/ +inline bool isWaylandEnvironment() +{ + return QGuiApplication::platformName().startsWith("wayland", Qt::CaseInsensitive); +} +} + +#endif // UTILS diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.cpp new file mode 100644 index 000000000..45c7d4a54 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.cpp @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "tipswidget.h" + +#include +#include +#include + +#define MARGIN 10 + +NETWORKPLUGIN_USE_NAMESPACE + +TipsWidget::TipsWidget(QWidget *parent) + : QFrame(parent) +{ +} + +void TipsWidget::setContext(const QList> &textList) +{ + m_textList = textList; + + int width = 0; + int height = 0; + int titleWidth = 0; + for (QPair textPair : m_textList) + titleWidth = qMax(titleWidth, fontMetrics().horizontalAdvance(textPair.first)); + + for (QPair textPair : m_textList) { + QString key = textPair.first; + QStringList values = textPair.second; + if (values.size() > 0) { + for (const QString &value : values) { + QString text = m_spliter + value; + width = qMax(width, fontMetrics().horizontalAdvance(text) + MARGIN * 2); + height += fontMetrics().boundingRect(text).height(); + } + } else { + height += fontMetrics().boundingRect(key).height(); + width = MARGIN * 2; + } + } + + width += titleWidth; + setFixedSize(width, height); + + update(); +} + +void TipsWidget::setSpliter(const QString &spliter) +{ + m_spliter = spliter; +} + +// 计算右侧文字的左侧位置 +int TipsWidget::calcValueX() +{ + int nMaxWidth = 0; + for (QPair textPair : m_textList) { + int nCurrentTextWidth = fontMetrics().boundingRect(textPair.first).width(); + nMaxWidth = qMax(nMaxWidth, nCurrentTextWidth); + } + return MARGIN + nMaxWidth + fontMetrics().horizontalAdvance(m_spliter); +} + +/** + * @brief TipsWidget::paintEvent 任务栏插件提示信息绘制 + * @param event + */ +void TipsWidget::paintEvent(QPaintEvent *event) +{ + QFrame::paintEvent(event); + + QPainter painter(this); + painter.setPen(QPen(palette().brightText(), 1)); + + QTextOption option; + option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter); + + int y = 0; + int valueX = calcValueX(); + for (QPair textPair : m_textList) { + QString key = textPair.first; + QStringList values = textPair.second; + QString displayText = (values.size() > 0 ? (QString("%1%2").arg(key).arg(m_spliter)) : key); + int lineHeight = fontMetrics().boundingRect(displayText).height(); + painter.drawText(QRect(MARGIN, y, rect().width(), lineHeight), displayText, option); + for (const QString &text : values) { + int textHeight = fontMetrics().boundingRect(text).height(); + painter.drawText(QRect(valueX, y, rect().width(), textHeight), text, option); + y += textHeight; + } + } +} + +bool TipsWidget::event(QEvent *event) +{ + if (event->type() == QEvent::FontChange) + setContext(m_textList); + + return QFrame::event(event); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.h new file mode 100644 index 000000000..022941256 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef TIPSWIDGET_H +#define TIPSWIDGET_H + +#include "../plugin_global.h" + +#include + +NETWORKPLUGIN_BEGIN_NAMESPACE + +class TipsWidget : public QFrame +{ + Q_OBJECT + +public: + explicit TipsWidget(QWidget *parent = nullptr); + + void setContext(const QList> &textList); + void setSpliter(const QString &spliter); + +protected: + void paintEvent(QPaintEvent *event) override; + bool event(QEvent *event) override; + int calcValueX(); + +private: + QList> m_textList; + QString m_spliter; +}; + +NETWORKPLUGIN_END_NAMESPACE + +#endif // TIPSWIDGET_H diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/CMakeLists.txt b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/CMakeLists.txt new file mode 100644 index 000000000..464f3248a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.7) + +set(PLUGIN_NAME "dock-network-plugin") + +project(${PLUGIN_NAME}) +# 启用 qt moc 的支持 +set(CMAKE_AUTOMOC ON) +# 启用 qrc 资源文件的支持 +set(CMAKE_AUTORCC ON) + +file(GLOB_RECURSE SRCS "*.h" "*.cpp" "item/*.h" "item/*.cpp" "../common-plugin/*.h" "../common-plugin/*.cpp") + +find_package(Qt6 COMPONENTS Core Widgets DBus Network LinguistTools REQUIRED) +find_package(PkgConfig REQUIRED) +find_package(Dtk6 REQUIRED COMPONENTS Core) +find_package(Dtk6 REQUIRED COMPONENTS Widget) + +file(GLOB TS_FILES "translations/*.ts") +qt_add_translation(QM_FILES ${TS_FILES}) +add_custom_target(language ALL DEPENDS ${QM_FILES}) + +add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") +add_library(${PLUGIN_NAME} SHARED ${SRCS} ../common-plugin/network.qrc) + +target_include_directories(${PLUGIN_NAME} PUBLIC + ${NETINTERFACEINCLUDE} + "../common-plugin" + "../../../interfaces" +) + +target_link_libraries(${PLUGIN_NAME} PRIVATE + dde-network-core_static +) + +install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/tmp/plugins/quick-trays) +# 安装 .qm 文件 +install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/${PLUGIN_NAME}/tmp/translations) diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/lupdate.sh b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/lupdate.sh new file mode 100755 index 000000000..f1456e52e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/lupdate.sh @@ -0,0 +1,10 @@ +#!/bin/bash +if [ ! -d "translations/" ];then + mkdir translations +fi +cd ./translations +rm -f dock-hotspot-plugin_en_US.ts +lupdate ../ ../../src ../../common-plugin -ts -no-ui-lines -locations none -no-obsolete dock-network-plugin_en_US.ts +cd ../ + +tx push -s --branch m23 diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/network.json b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/network.json new file mode 100644 index 000000000..5060fce05 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/network.json @@ -0,0 +1,5 @@ +{ + "api": "2.0.0", + "primary" : true, + "depends-daemon-dbus-service": "org.deepin.dde.Network1" +} diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.cpp b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.cpp new file mode 100644 index 000000000..23b2d5ea6 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.cpp @@ -0,0 +1,343 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkplugin.h" +#include "networkpluginhelper.h" +#include "networkdialog.h" +#include "quickpanel.h" +#include "item/devicestatushandler.h" +#include "networkdialog/thememanager.h" + +#include + +#include + +#include +#include +#include +#include + +#define STATE_KEY "enabled" + +NETWORKPLUGIN_USE_NAMESPACE + +NetworkPlugin::NetworkPlugin(QObject *parent) + : QObject(parent) + , m_networkHelper(Q_NULLPTR) + , m_networkDialog(Q_NULLPTR) + , m_quickPanel(Q_NULLPTR) + , m_clickTime(-10000) +{ + NetworkController::setIPConflictCheck(true); + QTranslator *translator = new QTranslator(this); + QString languagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + QString("dock-network-plugin/tmp/translations"), + QStandardPaths::LocateDirectory); + translator->load(QString(languagePath+"/dock-network-plugin_%1.qm").arg(QLocale::system().name())); + QCoreApplication::installTranslator(translator); +} + +NetworkPlugin::~NetworkPlugin() +{ +} + +const QString NetworkPlugin::pluginName() const +{ + return "network"; +} + +const QString NetworkPlugin::pluginDisplayName() const +{ + return tr("Network"); +} + +void NetworkPlugin::init(PluginProxyInterface *proxyInter) +{ + m_proxyInter = proxyInter; + if (m_networkHelper) + return; + + m_networkDialog = new NetworkDialog(this); + m_networkDialog->setServerName("dde-network-dialog" + QString::number(getuid()) + "dock"); + m_networkHelper.reset(new NetworkPluginHelper(m_networkDialog)); + connect(m_networkHelper.data(), &NetworkPluginHelper::iconChanged, this, &NetworkPlugin::onIconUpdated); + m_quickPanel = new QuickPanel(); + + if (!pluginIsDisable()) + loadPlugin(); + + connect(m_networkDialog, &NetworkDialog::requestShow, this, &NetworkPlugin::showNetworkDialog); + + connect(m_quickPanel, &QuickPanel::iconClicked, this, [this]() { + m_networkHelper->invokeMenuItem(m_quickPanel->userData().toString()); + }); + connect(m_quickPanel, &QuickPanel::panelClicked, this, &NetworkPlugin::showNetworkDialog); + + m_networkHelper->setIconDark(Dtk::Gui::DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType); + // 主题发生变化触发的信号 + connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged, this, [this]() { + m_networkHelper->setIconDark(Dtk::Gui::DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType); + }); +} + +void NetworkPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) +{ + Q_UNUSED(checked) + + if (itemKey == NETWORK_KEY) + m_networkHelper->invokeMenuItem(menuId); +} + +void NetworkPlugin::refreshIcon(const QString &itemKey) +{ + if (itemKey == NETWORK_KEY) + emit m_networkHelper->viewUpdate(); +} + +void NetworkPlugin::pluginStateSwitched() +{ + m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable()); + + refreshPluginItemsVisible(); +} + +bool NetworkPlugin::pluginIsDisable() +{ + return !m_proxyInter->getValue(this, STATE_KEY, true).toBool(); +} + +const QString NetworkPlugin::itemCommand(const QString &itemKey) +{ + Q_UNUSED(itemKey) + if (m_networkHelper->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(); +} + +const QString NetworkPlugin::itemContextMenu(const QString &itemKey) +{ + return QString(); +} + +QWidget *NetworkPlugin::itemWidget(const QString &itemKey) +{ + if (itemKey == QUICK_ITEM_KEY) { + return m_quickPanel; + } + return Q_NULLPTR; +} + +QWidget *NetworkPlugin::itemTipsWidget(const QString &itemKey) +{ + if (itemKey == NETWORK_KEY && !m_networkDialog->panel()->isVisible()) + return m_networkHelper->itemTips(); + + return Q_NULLPTR; +} + +QWidget *NetworkPlugin::itemPopupApplet(const QString &itemKey) +{ + Q_UNUSED(itemKey); + return m_networkDialog->panel(); +} + +int NetworkPlugin::itemSortKey(const QString &itemKey) +{ + const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); + return m_proxyInter->getValue(this, key, 3).toInt(); +} + +void NetworkPlugin::setSortKey(const QString &itemKey, const int order) +{ + const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); + m_proxyInter->saveValue(this, key, order); +} + +void NetworkPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + +PluginFlags NetworkPlugin::flags() const +{ + return PluginFlag::Type_Common | PluginFlag::Quick_Multi | PluginFlag::Attribute_CanDrag | PluginFlag::Attribute_CanInsert | PluginFlag::Attribute_CanSetting; +} + +void NetworkPlugin::loadPlugin() +{ + m_proxyInter->itemAdded(this, NETWORK_KEY); +} + +void NetworkPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) + m_proxyInter->itemRemoved(this, NETWORK_KEY); + else + m_proxyInter->itemAdded(this, NETWORK_KEY); +} + +void NetworkPlugin::updateQuickPanel() +{ + QList devices = NetworkController::instance()->devices(); + int wiredConnectionCount = 0; + int wirelessConnectionCount = 0; + QString wiredConnection; + QString wirelessConnection; + QList wiredList; + QList wirelessList; + + for (NetworkDeviceBase *device : devices) { + switch (device->deviceType()) { + case DeviceType::Wired: { + WiredDevice *wiredDevice = static_cast(device); + wiredList.append(wiredDevice); + if (wiredDevice->isConnected()) { + QList items = wiredDevice->items(); + for (WiredConnection *item : items) { + if (item->status() == ConnectionStatus::Activated) { + wiredConnectionCount++; + wiredConnection = item->connection()->id(); + } + } + } + } break; + case DeviceType::Wireless: { + WirelessDevice *wirelessDevice = static_cast(device); + wirelessList.append(wirelessDevice); + if (wirelessDevice->isConnected()) { + QList items = wirelessDevice->items(); + for (WirelessConnection *item : items) { + if (item->status() == ConnectionStatus::Activated) { + wirelessConnectionCount++; + wirelessConnection = item->connection()->ssid(); + } + } + } + } break; + default: + break; + } + } + + if (!wirelessList.isEmpty()) { + NetDeviceStatus status = DeviceStatusHandler::wirelessStatus(wirelessList); + updateQuickPanelDescription(status, wirelessConnectionCount, wirelessConnection, NetworkPluginHelper::MenuWirelessEnable); + m_quickPanel->setText(tr("Wireless Network")); + m_quickPanel->setIcon(QIcon::fromTheme(ThemeManager::ref().getIcon("wireless-80-symbolic"))); + } else if (!wiredList.isEmpty()) { + NetDeviceStatus status = DeviceStatusHandler::wiredStatus(wiredList); + updateQuickPanelDescription(status, wiredConnectionCount, wiredConnection, NetworkPluginHelper::MenuWiredEnable); + m_quickPanel->setText(tr("Wired Network")); + m_quickPanel->setIcon(QIcon::fromTheme(ThemeManager::ref().getIcon("network-wired-symbolic"))); + } else { + m_quickPanel->setText(pluginDisplayName()); + m_quickPanel->setDescription(description()); + m_quickPanel->setActive(false); + m_quickPanel->setUserData(NetworkPluginHelper::MenuSettings); + m_quickPanel->setIcon(QIcon::fromTheme(ThemeManager::ref().getIcon("network-error-symbolic"))); + } +} + +void NetworkPlugin::updateQuickPanelDescription(NetDeviceStatus status, int connectionCount, const QString &Connection, int enableMenu) +{ + QString statusName = networkStateName(status); + bool isEnabled = (status != NetDeviceStatus::Disabled); + + if (statusName.isEmpty() && connectionCount != 0) { + if (connectionCount == 1) { + m_quickPanel->setDescription(Connection); + } else { + m_quickPanel->setDescription(tr("Connected") + QString(" (%1)").arg(connectionCount)); + } + } else { + m_quickPanel->setDescription(statusName); + } + m_quickPanel->setActive(isEnabled); + m_quickPanel->setUserData(isEnabled ? (enableMenu + 1) : enableMenu); +} + +QString NetworkPlugin::networkStateName(NetDeviceStatus status) const +{ + switch (status) { + case NetDeviceStatus::Disabled: + return tr("Device disabled"); + case NetDeviceStatus::Unknown: + case NetDeviceStatus::Nocable: + return tr("Network cable unplugged"); + case NetDeviceStatus::Disconnected: + return tr("Not connected"); + case NetDeviceStatus::Connecting: + case NetDeviceStatus::Authenticating: + return tr("Connecting"); + case NetDeviceStatus::ObtainingIP: + case NetDeviceStatus::ObtainIpFailed: + return tr("Obtaining address"); + case NetDeviceStatus::ConnectNoInternet: + return tr("Connected but no Internet access"); + case NetDeviceStatus::IpConflicted: + return tr("IP conflict"); + case NetDeviceStatus::ConnectFailed: + return tr("Connection failed"); + default: + break; + } + return QString(); +} + +void NetworkPlugin::onIconUpdated() +{ + // update quick panel + m_proxyInter->updateDockInfo(this, DockPart::QuickPanel); + // update quick plugin area + m_proxyInter->updateDockInfo(this, DockPart::QuickShow); + + updateQuickPanel(); +} + +QIcon NetworkPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) +{ + switch(dockPart) { + case DockPart::DCCSetting: + case DockPart::QuickShow: + return m_networkHelper->icon(themeType); + default: + break; + } + + return QIcon(); +} + +PluginsItemInterface::PluginMode NetworkPlugin::status() const +{ + // get the plugin status + PluginState plugState = m_networkHelper->getPluginState(); + switch (plugState) { + case PluginState::Unknown: + case PluginState::Disabled: + case PluginState::Nocable: + return PluginMode::Disabled; + default: + break; + } + + return PluginMode::Active; +} + +QString NetworkPlugin::description() const +{ + return m_quickPanel ? m_quickPanel->description() : QString(); +} + +void NetworkPlugin::showNetworkDialog() +{ + if (m_networkDialog->panel()->isVisible()) + return; + m_proxyInter->requestSetAppletVisible(this, NETWORK_KEY, true); +} diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.h b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.h new file mode 100644 index 000000000..21d661624 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.h @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPLUGIN_H +#define NETWORKPLUGIN_H + +#include "pluginsiteminterface.h" +#include "../common-plugin/utils.h" + +#define NETWORK_KEY "network-item-key" + +NETWORKPLUGIN_BEGIN_NAMESPACE +class NetworkPluginHelper; +class NetworkDialog; +class TrayIcon; +NETWORKPLUGIN_END_NAMESPACE + +class QuickPanel; +enum class NetDeviceStatus; + +class NetworkPlugin : public QObject, PluginsItemInterface +{ + Q_OBJECT + + Q_INTERFACES(PluginsItemInterface) + Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "network.json") + +public Q_SLOTS: + void showNetworkDialog(); + +public: + explicit NetworkPlugin(QObject *parent = Q_NULLPTR); + ~NetworkPlugin() Q_DECL_OVERRIDE; + + const QString pluginName() const override; + const QString pluginDisplayName() const override; + void init(PluginProxyInterface *proxyInter) override; + void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override; + void refreshIcon(const QString &itemKey) override; + void pluginStateSwitched() override; + bool pluginIsAllowDisable() override { return true; } + bool pluginIsDisable() override; + const QString itemCommand(const QString &itemKey) override; + const QString itemContextMenu(const QString &itemKey) override; + QWidget *itemWidget(const QString &itemKey) override; + QWidget *itemTipsWidget(const QString &itemKey) override; + QWidget *itemPopupApplet(const QString &itemKey) override; + + int itemSortKey(const QString &itemKey) override; + void setSortKey(const QString &itemKey, const int order) override; + + void pluginSettingsChanged() override; + PluginFlags flags() const override; + +protected: + QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override; + PluginMode status() const override; + QString description() const override; + +private: + void loadPlugin(); + void refreshPluginItemsVisible(); + void updateQuickPanel(); + void updateQuickPanelDescription(NetDeviceStatus status, int connectionCount, const QString &Connection, int enableMenu); + QString networkStateName(NetDeviceStatus status) const; + +private Q_SLOTS: + void onIconUpdated(); + +private: + QScopedPointer m_networkHelper; + NETWORKPLUGIN_NAMESPACE::NetworkDialog *m_networkDialog; + QuickPanel *m_quickPanel; + int m_clickTime; +}; + +#endif // NETWORKPLUGIN_H diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.cpp b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.cpp new file mode 100644 index 000000000..6966592e2 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.cpp @@ -0,0 +1,212 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "quickpanel.h" + +#include +#include +#include + +#include +#include +#include + +DWIDGET_USE_NAMESPACE + +const QSize IconSize(24, 24); // 图标大小 + +class HighlightIconEngine : public QIconEngine +{ +public: + explicit HighlightIconEngine(QIcon icon = QIcon()) + : QIconEngine() + , m_icon(icon) + { + } + + virtual void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) + { + QSize pixmapSize = rect.size(); + qreal scale = 1; + if (painter->device() && (!QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps))) + scale = painter->device()->devicePixelRatioF(); + + pixmapSize *= scale; + + QPixmap pm = m_icon.pixmap(pixmapSize, mode, state); + if (pm.isNull()) + return; + + if (state == QIcon::On) { + QPainter pa(&pm); + pa.setCompositionMode(QPainter::CompositionMode_SourceIn); + pa.fillRect(pm.rect(), qApp->palette().highlight()); + } + + pm.setDevicePixelRatio(scale); + painter->drawPixmap(rect, pm); + } + + virtual QIconEngine *clone() const + { + return new HighlightIconEngine(m_icon); + } + +private: + QIcon m_icon; +}; + +QuickPanel::QuickPanel(QWidget *parent) + : QWidget(parent) + , m_iconButton(new DIconButton(this)) + , m_text(new DLabel(this)) + , m_description(new DLabel(this)) + , m_hover(false) +{ + initUi(); + initConnect(); +} + +const QVariant &QuickPanel::userData() const +{ + return m_userData; +} + +void QuickPanel::setUserData(const QVariant &data) +{ + m_userData = data; +} + +const QString QuickPanel::text() const +{ + return m_text->text(); +} + +const QString QuickPanel::description() const +{ + return m_description->text(); +} + +void QuickPanel::setIcon(const QIcon &icon) +{ + m_iconButton->setIcon(QIcon(new HighlightIconEngine(icon))); +} + +void QuickPanel::setText(const QString &text) +{ + m_text->setText(text); +} + +void QuickPanel::setDescription(const QString &description) +{ + m_description->setText(description); + m_description->setToolTip(description); +} + +void QuickPanel::setActive(bool active) +{ + m_iconButton->setChecked(active); +} + +void QuickPanel::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::RenderHint::Antialiasing); + const DPalette &dp = palette(); + painter.setPen(Qt::NoPen); + painter.setBrush(dp.brush(m_hover ? DPalette::ObviousBackground : DPalette::ItemBackground)); + painter.drawRoundedRect(rect(), 8, 8); +} + +void QuickPanel::mouseReleaseEvent(QMouseEvent *event) +{ + if (!m_iconButton->rect().contains(event->pos()) && rect().contains(event->pos())) { + emit panelClicked(); + } +} + +void QuickPanel::enterEvent(QEnterEvent *event) +{ + setHover(true); +} + +void QuickPanel::leaveEvent(QEvent *event) +{ + setHover(false); +} + +bool QuickPanel::eventFilter(QObject *watched, QEvent *event) +{ + switch (event->type()) { + case QEvent::Enter: + setHover(false); + break; + case QEvent::Leave: + setHover(true); + break; + default: + break; + } + return QWidget::eventFilter(watched, event); +} + +void QuickPanel::initUi() +{ + QHBoxLayout *mainLayout = new QHBoxLayout(this); + // 文本 + QWidget *labelWidget = new QWidget(this); + QVBoxLayout *layout = new QVBoxLayout(labelWidget); + layout->setContentsMargins(0, 10, 0, 10); + layout->setSpacing(0); + QFont nameFont = DFontSizeManager::instance()->t6(); + nameFont.setBold(true); + m_text->setFont(nameFont); + m_text->setElideMode(Qt::ElideRight); + layout->addWidget(m_text); + m_description->setFont(DFontSizeManager::instance()->t10()); + m_description->setElideMode(Qt::ElideRight); + layout->addWidget(m_description); + + // 图标 + m_iconButton->setEnabledCircle(true); + m_iconButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_iconButton->setIconSize(IconSize); + m_iconButton->installEventFilter(this); + m_iconButton->setCheckable(true); + + // 进入图标 + QWidget *expandWidget = new QWidget(this); + QVBoxLayout *expandLayout = new QVBoxLayout(expandWidget); + QLabel *enterIcon = new QLabel(expandWidget); + qreal ratio = devicePixelRatioF(); + QSize size = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? QSize(16, 16) : QSize(16, 16) * ratio; + QPixmap enterPixmap = DStyle::standardIcon(style(), DStyle::SP_ArrowEnter).pixmap(size); + enterPixmap.setDevicePixelRatio(ratio); + enterIcon->setPixmap(enterPixmap); + expandLayout->setContentsMargins(0, 0, 0, 0); + expandLayout->setSpacing(0); + expandLayout->addWidget(enterIcon); + + mainLayout->setContentsMargins(10, 0, 10, 0); + mainLayout->setSpacing(0); + mainLayout->addWidget(m_iconButton); + mainLayout->addSpacing(10); + mainLayout->addWidget(labelWidget); + mainLayout->addStretch(); + mainLayout->addWidget(expandWidget); +} + +void QuickPanel::initConnect() +{ + connect(m_iconButton, &DIconButton::clicked, this, &QuickPanel::iconClicked); +} + +void QuickPanel::setHover(bool hover) +{ + if (hover == m_hover) + return; + + m_hover = hover; + update(); +} diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.h b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.h new file mode 100644 index 000000000..3224fbcfb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.h @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef QUICKPANEL_H +#define QUICKPANEL_H + +#include +#include +#include + +namespace Dtk { +namespace Widget { +class DLabel; +class DIconButton; +} +} + +class QuickPanel : public QWidget +{ + Q_OBJECT + +public: + explicit QuickPanel(QWidget *parent = nullptr); + const QVariant &userData() const; + void setUserData(const QVariant &data); + const QString text() const; + const QString description() const; + +public Q_SLOTS: + void setIcon(const QIcon &icon); + void setText(const QString &text); + void setDescription(const QString &description); + void setActive(bool active); + +Q_SIGNALS: + void panelClicked(); + void iconClicked(); + +protected: + void paintEvent(QPaintEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void enterEvent(QEnterEvent *event) override; + void leaveEvent(QEvent *event) override; + bool eventFilter(QObject *watched, QEvent *event) override; + +private: + void initUi(); + void initConnect(); + void setHover(bool hover); + +private: + QVariant m_userData; + + Dtk::Widget::DIconButton *m_iconButton; + Dtk::Widget::DLabel *m_text; + Dtk::Widget::DLabel *m_description; + + bool m_hover; +}; + +#endif // QUICKPANEL_H diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin.ts new file mode 100644 index 000000000..be67a9974 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin.ts @@ -0,0 +1,283 @@ + + + + + DeviceControllItem + + Wireless Network + + + + Wired Network + + + + + NetworkPlugin + + Network + + + + Wireless Network + + + + Wired Network + + + + Connected + + + + Device disabled + + + + Network cable unplugged + + + + Not connected + + + + Connecting + + + + Obtaining address + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + + + + Password + + + + Cancel + button + + + + Connect + button + + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + + + + SSID + + + + Protocol + + + + Security Type + + + + Band + + + + Channel + + + + Interface + + + + MAC + + + + IPv4 + + + + Netmask + + + + Gateway + + + + Primary DNS + + + + IPv6 + + + + Prefix + + + + Speed + + + + + dde::network::NetworkDeviceRealize + + Device disabled + + + + Connected but no Internet access + + + + Not connected + + + + Network cable unplugged + + + + Connecting + + + + Authenticating + + + + Obtaining IP address + + + + Connected + + + + Disconnected + + + + IP conflict + + + + Failed + + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + + + + Wired Network %1 + + + + Wireless Network + + + + Wireless Network %1 + + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + + + + Network cable unplugged + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + Connection failed + + + + IP conflict + + + + Disable wired connection + + + + Enable wired connection + + + + Disable wireless connection + + + + Enable wireless connection + + + + Disable network + + + + Enable network + + + + Network settings + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ar.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ar.ts new file mode 100644 index 000000000..905281607 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ar.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + الشبكة + + + + dde::network::NetworkDetails + + Hotspot + نقطة الإتصال + + + SSID + SSID + + + Protocol + + + + Security Type + + + + Band + الحزمة + + + Channel + القناة + + + Interface + الواجهة + + + MAC + ماك + + + IPv4 + IPv4 + + + Netmask + قناع الشبكة + + + Gateway + البوابة + + + Primary DNS + DNS رئيسي + + + IPv6 + IPv6 + + + Prefix + البادئة + + + Speed + السرعة + + + + dde::network::NetworkDeviceRealize + + Device disabled + جهاز ملغى + + + Connected but no Internet access + متصل لكن لا يوجد اتصال بالإنترنت + + + Not connected + غير متصل + + + Network cable unplugged + سلك الشبكة غير موصول + + + Connecting + يتصل + + + Authenticating + المصادقة + + + Obtaining IP address + جاري الحصول على عنوان IP + + + Connected + متصل + + + Disconnected + غير متصل + + + IP conflict + + + + Failed + فشل + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + شبكة سلكية + + + Wired Network %1 + شبكة سلكية 1% + + + Wireless Network + شبكة لاسلكية + + + Wireless Network %1 + الشبكة اللاسلكية : %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + جهاز ملغى + + + Network cable unplugged + سلك الشبكة غير موصول + + + Not connected + غير متصل + + + Connecting + يتصل + + + Connected but no Internet access + متصل لكن لا يوجد اتصال بالإنترنت + + + Connection failed + + + + IP conflict + + + + Disable wired connection + تعطيل الاتصال السلكي + + + Enable wired connection + تفعيل الاتصال السلكي + + + Disable wireless connection + تعطيل الاتصال اللاسلكي + + + Enable wireless connection + تفعيل الاتصال اللاسلكي + + + Disable network + تعطيل الشبكة + + + Enable network + تمكين الشبكة + + + Network settings + إعدادات الشبكة + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_az.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_az.ts new file mode 100644 index 000000000..5ecdef90e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_az.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Simsiz şəbəkə + + + Wired Network + Naqilli şəbəkə + + + + NetworkPlugin + + Network + Şəbəkə + + + Wireless Network + + + + Wired Network + Naqilli şəbəkə + + + Device disabled + Cihaz söndürülüb + + + Network cable unplugged + Şəbəkə kabeli çıxarılıb + + + Not connected + Bağlantı yoxdur + + + Connecting + Qoşulur + + + Connected but no Internet access + Qoşulub, lakin internetə giriş yoxdur + + + IP conflict + İP ziddiyyəti + + + Connection failed + Qoşulma alınmadı + + + + WirelessItem + + Connect to hidden network + Gizli şəbəkəyə qoşulun + + + Password + Şifrə + + + Cancel + button + İmtina + + + Connect + button + Qoşulun + + + Name (SSID) + Ad (SSİD) + + + + dde::network::NetworkDetails + + Hotspot + Qoşulma nöqtəsi + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Təhlükəsizlik növü + + + Band + Aralıq + + + Channel + Kanal + + + Interface + İnterfeys + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Şəbəkə maskası + + + Gateway + Şəbəkə keçidi + + + Primary DNS + Birinci DNS + + + IPv6 + IPv6 + + + Prefix + Prefiks + + + Speed + Sürət + + + + dde::network::NetworkDeviceRealize + + Device disabled + Cihaz söndürülüb + + + Connected but no Internet access + Qoşulub, lakin internetə giriş yoxdur + + + Not connected + Bağlantı yoxdur + + + Network cable unplugged + Şəbəkə kabeli çıxarılıb + + + Connecting + Qoşulur... + + + Authenticating + Doğrulanır + + + Obtaining IP address + İP ünvanları alınır + + + Connected + Qoşuldu + + + Disconnected + Bağlantı kəsildi + + + IP conflict + İP ziddiyyəti + + + Failed + Uğursuz + + + Obtaining address + Ünvan alınır + + + + dde::network::NetworkProcesser + + Wired Network + Simli şəbəkə + + + Wired Network %1 + Simli şəbəkəsi %1 + + + Wireless Network + Simsiz şəbəkə + + + Wireless Network %1 + Simsiz şəbəkə %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Cihaz söndürülüb + + + Network cable unplugged + Şəbəkə kabeli çıxarılıb + + + Not connected + Bağlantı yoxdur + + + Connecting + Qoşulur... + + + Connected but no Internet access + Qoşulub, lakin internetə giriş yoxdur + + + Connection failed + Qoşulma alınmadı + + + IP conflict + İP ziddiyyəti + + + Disable wired connection + Simli bağlantını söndürmək + + + Enable wired connection + Simli bağlantını qoşmaq + + + Disable wireless connection + Simsiz bağlantını söndürmək + + + Enable wireless connection + Simsiz bağlantını qoşmaq + + + Disable network + Şəbəkəni söndürmək + + + Enable network + Şəbəkəni qoşmaq + + + Network settings + Şəbəkə ayarları + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_bo.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_bo.ts new file mode 100644 index 000000000..3cce45ce5 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_bo.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + སྐུད་མེད་དྲ་རྒྱ། + + + Wired Network + སྐུད་ཡོད་དྲ་རྒྱ། + + + + NetworkPlugin + + Network + དྲ་རྒྱ། + + + Wireless Network + + + + Wired Network + སྐུད་ཡོད་དྲ་རྒྱ། + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + ཡིབ་དྲ་དང་མཐུད་པ། + + + Password + གསང་ཨང་འཇུག་རོགས། + + + Cancel + button + འདོར་བ། + + + Connect + button + འབྲེལ་མཐུད། + + + Name (SSID) + དྲ་བའི་མིང་(SSID)ནང་འཇུག་བྱེད་རོགས། + + + + dde::network::NetworkDetails + + Hotspot + ཚ་གནས། + + + SSID + SSID + + + Protocol + གྲོས་མཐུན། + + + Security Type + བདེ་འཇགས་རིགས། + + + Band + བྱུང་རིམ། + + + Channel + དྲ་རྒྱའི་རྒྱུ་ལམ། + + + Interface + མཐུད་ཁ། + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + བུ་དྲ་ཡིབ་ཨང་། + + + Gateway + དྲ་སྒོ། + + + Primary DNS + སྔོན་འདེམས་DNS + + + IPv6 + IPv6 + + + Prefix + སྔོན་སྦྱོར། + + + Speed + མྱུར་ཚད། + + + + dde::network::NetworkDeviceRealize + + Device disabled + སྒྲིག་ཆས་སྤྱོད་མི་ཆོག + + + Connected but no Internet access + དྲ་རྒྱ་དང་འབྲེལ་ཟིན་ཡང་མཉམ་སྦྲེལ་དྲ་རྒྱར་འཛུལ་མི་ཐུབ། + + + Not connected + སྦྲེལ་མེད་པ། + + + Network cable unplugged + དྲ་སྐུད་མཐུད་མི་འདུག + + + Connecting + སྦྲེལ་བཞིན་པ། + + + Authenticating + ར་སྤྲོད་བྱེད་བཞིན་པ། + + + Obtaining IP address + IP གནས་ཡུལ་འཚོལ་བཞིན་པ། + + + Connected + སྦྲེལ་ཟིན། + + + Disconnected + བཅད་ཟིན། + + + IP conflict + IPགནས་ཡུལ་འགལ་ཟླ་བྱུང་བ། + + + Failed + ཕམ་པ། + + + Obtaining address + གནས་ཡུལ་འཚོལ་བཞིན་པ། + + + + dde::network::NetworkProcesser + + Wired Network + སྐུད་ཡོད་དྲ་རྒྱ། + + + Wired Network %1 + སྐུད་ཡོད་དྲ་རྒྱ་%1 + + + Wireless Network + སྐུད་མེད་དྲ་རྒྱ། + + + Wireless Network %1 + སྐུད་མེད་དྲ་རྒྱ་%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + སྒྲིག་ཆས་སྤྱོད་མི་ཆོག + + + Network cable unplugged + དྲ་སྐུད་མཐུད་མི་འདུག + + + Not connected + སྦྲེལ་མེད་པ། + + + Connecting + སྦྲེལ་བཞིན་པ། + + + Connected but no Internet access + དྲ་རྒྱ་དང་འབྲེལ་ཟིན་ཡང་མཉམ་སྦྲེལ་དྲ་རྒྱར་འཛུལ་མི་ཐུབ། + + + Connection failed + འབྲེལ་མཐུད་བྱེད་མ་ཐུབ། + + + IP conflict + IPགནས་ཡུལ་འགལ་ཟླ་བྱུང་བ། + + + Disable wired connection + སྐུད་ཡོད་དྲ་རྒྱ་ཁ་རྒྱོབ། + + + Enable wired connection + སྐུད་ཡོད་དྲ་རྒྱ་སྤྱོད་པ། + + + Disable wireless connection + སྐུད་མེད་དྲ་རྒྱ་ཁ་རྒྱོབ། + + + Enable wireless connection + སྐུད་མེད་དྲ་རྒྱ་སྤྱོད་པ། + + + Disable network + དྲ་རྒྱ་ཁ་རྒྱོབ། + + + Enable network + དྲ་རྒྱ་སྤྱོད་པ། + + + Network settings + དྲ་རྒྱ་སྒྲིག་འགོད། + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ca.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ca.ts new file mode 100644 index 000000000..da3d1eacb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ca.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + Xarxa sense fil + + + Wired Network + Xarxa amb fil + + + + NetworkPlugin + + Network + Xarxa + + + Wireless Network + Xarxa sense fil + + + Wired Network + Xarxa amb fil + + + Connected + + + + Device disabled + Dispositiu inhabilitat + + + Network cable unplugged + Cable de xarxa desendollat + + + Not connected + No connectat + + + Connecting + Es connecta + + + Obtaining address + + + + Connected but no Internet access + Connectat però sense accés a Internet + + + IP conflict + Conflicte d'IP + + + Connection failed + Ha fallat la connexió. + + + + WirelessItem + + Connect to hidden network + Connecta amb una xarxa oculta + + + Password + Contrasenya + + + Cancel + button + Cancel·la + + + Connect + button + Connecta + + + Name (SSID) + Nom (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Punt d'accés + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Tipus de seguretat + + + Band + Banda + + + Channel + Canal + + + Interface + Interfície + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Màscara de xarxa + + + Gateway + Passarel·la + + + Primary DNS + DNS primari + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Velocitat + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositiu inhabilitat + + + Connected but no Internet access + Connectat però sense accés a Internet + + + Not connected + No connectat + + + Network cable unplugged + Cable de xarxa desendollat + + + Connecting + Es connecta + + + Authenticating + S'autentica + + + Obtaining IP address + S'obté l'adreça IP + + + Connected + Connectat + + + Disconnected + Desconnectat + + + IP conflict + Conflicte d'IP + + + Failed + Ha fallat + + + Obtaining address + S'obté l'adreça + + + + dde::network::NetworkProcesser + + Wired Network + Xarxa amb fil + + + Wired Network %1 + Xarxa amb fil %1 + + + Wireless Network + Xarxa sense fil + + + Wireless Network %1 + Xarxa sense fil %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositiu inhabilitat + + + Network cable unplugged + Cable de xarxa desendollat + + + Not connected + No connectat + + + Connecting + Es connecta + + + Connected but no Internet access + Connectat però sense accés a Internet + + + Connection failed + Ha fallat la connexió. + + + IP conflict + Conflicte d'IP + + + Disable wired connection + Inhabilita la connexió amb fil + + + Enable wired connection + Habilita la connexió amb fil + + + Disable wireless connection + Inhabilita la connexió sense fil + + + Enable wireless connection + Habilita la connexió sense fil + + + Disable network + Inhabilita la xarxa + + + Enable network + Habilita la xarxa + + + Network settings + Configuració de la xarxa + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_cs.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_cs.ts new file mode 100644 index 000000000..fa885ee46 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_cs.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Bezdrátová síť + + + Wired Network + Drátová síť + + + + NetworkPlugin + + Network + Síť + + + Wireless Network + + + + Wired Network + Drátová síť + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Připojit se ke skryté síti + + + Password + Heslo + + + Cancel + button + Zrušit + + + Connect + button + Připojit + + + Name (SSID) + Název (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Přípojný bod + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Typ zabezpečení + + + Band + Pásmo + + + Channel + Kanál + + + Interface + Rozhraní + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska sítě + + + Gateway + Brána + + + Primary DNS + Hlavní DNS + + + IPv6 + IPv6 + + + Prefix + Předpona + + + Speed + Rychlost + + + + dde::network::NetworkDeviceRealize + + Device disabled + Zařízení zakázáno + + + Connected but no Internet access + Připojeno, ale bez přístupu k internetu + + + Not connected + Nepřipojeno + + + Network cable unplugged + Síťový kabel odpojen + + + Connecting + Připojuje se + + + Authenticating + Ověřování + + + Obtaining IP address + Získávání IP adresy + + + Connected + Připojeno + + + Disconnected + Odpojeno + + + IP conflict + Střet IP adres + + + Failed + Nepodařilo se + + + Obtaining address + Získávání adresy + + + + dde::network::NetworkProcesser + + Wired Network + Drátová síť + + + Wired Network %1 + Drátová síť %1 + + + Wireless Network + Bezdrátová síť + + + Wireless Network %1 + Bezdrátová síť %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Zařízení zakázáno + + + Network cable unplugged + Síťový kabel odpojen + + + Not connected + Nepřipojeno + + + Connecting + Připojuje se + + + Connected but no Internet access + Připojeno, ale bez přístupu k Internetu + + + Connection failed + Připojení se nezdařilo + + + IP conflict + Střet IP adres + + + Disable wired connection + Vypnout drátové připojení + + + Enable wired connection + Zapnout drátové připojení + + + Disable wireless connection + Vypnout bezdrátové připojení + + + Enable wireless connection + Zapnout bezdrátové připojení + + + Disable network + Zakázat síť + + + Enable network + Povolit síť + + + Network settings + Nastavení sítě + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_da.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_da.ts new file mode 100644 index 000000000..d4b8543fa --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_da.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + Netværk + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + + + + Security Type + + + + Band + Bånd + + + Channel + Kanal + + + Interface + Grænseflade + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmaske + + + Gateway + Gateway + + + Primary DNS + Primær DNS + + + IPv6 + IPv6 + + + Prefix + Præfiks + + + Speed + Hastighed + + + + dde::network::NetworkDeviceRealize + + Device disabled + Enhed deaktiveret + + + Connected but no Internet access + Tilsluttet men ingen internetadgang + + + Not connected + Ikke tilsluttet + + + Network cable unplugged + Netværkskablet er frakoblet + + + Connecting + Opretter forbindelse + + + Authenticating + Autentificering + + + Obtaining IP address + Indhenter IP-adresse + + + Connected + Tilsluttet + + + Disconnected + Afbrudt + + + IP conflict + + + + Failed + Mislykkedet + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Kablet netværk + + + Wired Network %1 + Kablet netværk %1 + + + Wireless Network + Trådløst netværk + + + Wireless Network %1 + Trådløst netværk %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Enhed deaktiveret + + + Network cable unplugged + Netværkskablet er frakoblet + + + Not connected + Ikke tilsluttet + + + Connecting + Opretter forbindelse + + + Connected but no Internet access + Tilsluttet men ingen internetadgang + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Deaktivér kablet forbindelse + + + Enable wired connection + Aktivér kablet forbindelse + + + Disable wireless connection + Deaktivér trådløs forbindelse + + + Enable wireless connection + Aktivér trådløs forbindelse + + + Disable network + Deaktivér netværk + + + Enable network + Aktivér netværk + + + Network settings + Netværksindstillinger + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_de.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_de.ts new file mode 100644 index 000000000..2ef751222 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_de.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Drahtlosnetzwerk + + + Wired Network + Kabelgebundenes Netzwerk + + + + NetworkPlugin + + Network + Netzwerk + + + Wireless Network + + + + Wired Network + Kabelgebundenes Netzwerk + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Mit verstecktem Netzwerk verbinden + + + Password + Passwort + + + Cancel + button + Abbrechen + + + Connect + button + Verbinden + + + Name (SSID) + Name (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokoll + + + Security Type + Sicherheitstyp + + + Band + Band + + + Channel + Kanal + + + Interface + Schnittstelle + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netzmaske + + + Gateway + Gateway + + + Primary DNS + Primärer DNS + + + IPv6 + IPv6 + + + Prefix + Präfix + + + Speed + Geschwindigkeit + + + + dde::network::NetworkDeviceRealize + + Device disabled + Gerät deaktiviert + + + Connected but no Internet access + Verbunden, aber kein Internetzugang + + + Not connected + Nicht verbunden + + + Network cable unplugged + Netzwerkkabel abgezogen + + + Connecting + Wird verbunden + + + Authenticating + Wird authentifiziert + + + Obtaining IP address + IP-Adresse wird abgerufen + + + Connected + Verbunden + + + Disconnected + Getrennt + + + IP conflict + IP Konflikt + + + Failed + Fehlgeschlagen + + + Obtaining address + Adresse wird abgerufen + + + + dde::network::NetworkProcesser + + Wired Network + Kabelgebundenes Netzwerk + + + Wired Network %1 + Kabelgebundenes Netzwerk %1 + + + Wireless Network + Drahtlosnetzwerk + + + Wireless Network %1 + Drahtlosnetzwerk %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Gerät deaktiviert + + + Network cable unplugged + Netzwerkkabel abgezogen + + + Not connected + Nicht verbunden + + + Connecting + Wird verbunden + + + Connected but no Internet access + Verbunden, aber kein Internetzugang + + + Connection failed + Verbindung fehlgeschlagen + + + IP conflict + IP Konflikt + + + Disable wired connection + Kabelgebundene Verbindung deaktivieren + + + Enable wired connection + Kabelgebundene Verbindung aktivieren + + + Disable wireless connection + Drahtlosverbindung deaktivieren + + + Enable wireless connection + Drahtlosverbindung aktivieren + + + Disable network + Netzwerk deaktivieren + + + Enable network + Netzwerk aktivieren + + + Network settings + Netzwerkeinstellungen + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_el.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_el.ts new file mode 100644 index 000000000..6d1af6638 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_el.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Ασύρματο Δίκτυο + + + Wired Network + Ενσύρματο Δίκτυο + + + + NetworkPlugin + + Network + Δίκτυο + + + Wireless Network + + + + Wired Network + Ενσύρματο Δίκτυο + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Σύνδεση σε κρυφό δίκτυο + + + Password + Κωδικός πρόσβασης + + + Cancel + button + Ακύρωση + + + Connect + button + Σύνδεση + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Πρωτόκολλο + + + Security Type + Τύπος Ασφαλείας + + + Band + Mπάντα + + + Channel + Kανάλι + + + Interface + Διεπαφή + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Μάσκα Δικτύου + + + Gateway + Gateway + + + Primary DNS + Πρωτεύον DNS + + + IPv6 + IPv6 + + + Prefix + Πρόθεμα + + + Speed + Ταχύτητα + + + + dde::network::NetworkDeviceRealize + + Device disabled + Συσκευή Αποσυνδέθηκε + + + Connected but no Internet access + Συνδεδεμένο αλλά χωρίς πρόσβαση στο διαδίκτυο + + + Not connected + Δεν Συνδέθηκε + + + Network cable unplugged + Το καλώδιο δικτύου, αποσυνδέθηκε + + + Connecting + Σύνδεση + + + Authenticating + Πιστοποίηση + + + Obtaining IP address + Απόκτηση Διεύθυνσης IP + + + Connected + Συνδέθηκε + + + Disconnected + Αποσυνδέθηκε + + + IP conflict + Αντιτίθεση IP + + + Failed + Αποτυχία + + + Obtaining address + Απόκτηση Διεύθυνσης + + + + dde::network::NetworkProcesser + + Wired Network + Ενσύρματο Δίκτυο + + + Wired Network %1 + Ενσύρματο Δίκτυο %1 + + + Wireless Network + Ασύρματο Δίκτυο + + + Wireless Network %1 + Ασύρματο Δίκτυο %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Συσκευή Αποσυνδέθηκε + + + Network cable unplugged + Το καλώδιο δικτύου, αποσυνδέθηκε + + + Not connected + Δεν Συνδέθηκε + + + Connecting + Σύνδεση + + + Connected but no Internet access + Συνδεδεμένο αλλά χωρίς πρόσβαση στο διαδίκτυο + + + Connection failed + Αποτυχία σύνδεσης + + + IP conflict + Αντιτίθεση IP + + + Disable wired connection + Απενεργοποιήστε την ενσύρματη σύνδεση + + + Enable wired connection + Ενεργοποιήστε την ενσύρματη σύνδεση + + + Disable wireless connection + Απενεργοποιήστε την ασύρματη σύνδεση + + + Enable wireless connection + Ενεργοποιήστε την ασύρματη σύνδεση + + + Disable network + Απενεργοποίηση δικτύου + + + Enable network + Ενεργοποίηση δικτύου + + + Network settings + Ρυθμίσεις δικτύου + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_AU.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_AU.ts new file mode 100644 index 000000000..b192aeddb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_AU.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Wireless Network + + + Wired Network + Wired Network + + + + NetworkPlugin + + Network + Network + + + Wireless Network + + + + Wired Network + Wired Network + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Connect to hidden network + + + Password + Password + + + Cancel + button + Cancel + + + Connect + button + Connect + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Security Type + + + Band + Band + + + Channel + Channel + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmask + + + Gateway + Gateway + + + Primary DNS + Primary DNS + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Speed + + + + dde::network::NetworkDeviceRealize + + Device disabled + Device disabled + + + Connected but no Internet access + Connected but no Internet access + + + Not connected + Not connected + + + Network cable unplugged + Network cable unplugged + + + Connecting + Connecting + + + Authenticating + Authenticating + + + Obtaining IP address + Obtaining IP address + + + Connected + Connected + + + Disconnected + Disconnected + + + IP conflict + + + + Failed + Failed + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Wired Network + + + Wired Network %1 + Wired Network %1 + + + Wireless Network + Wireless Network + + + Wireless Network %1 + Wired Network %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Device disabled + + + Network cable unplugged + Network cable unplugged + + + Not connected + Not connected + + + Connecting + Connecting + + + Connected but no Internet access + Connected but no Internet access + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Disable wired connection + + + Enable wired connection + Enable wired connection + + + Disable wireless connection + Disable wireless connection + + + Enable wireless connection + Enable wireless connection + + + Disable network + Disable network + + + Enable network + Enable network + + + Network settings + Network settings + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_US.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_US.ts new file mode 100644 index 000000000..bd1016b8a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_US.ts @@ -0,0 +1,283 @@ + + + + + DeviceControllItem + + Wireless Network + Wireless Network + + + Wired Network + Wired Network + + + + NetworkPlugin + + Network + Network + + + Wireless Network + Wireless Network + + + Wired Network + Wired Network + + + Connected + Connected + + + Device disabled + Device disabled + + + Network cable unplugged + Network cable unplugged + + + Not connected + Not connected + + + Connecting + Connecting + + + Obtaining address + Obtaining address + + + Connected but no Internet access + Connected but no Internet access + + + IP conflict + IP conflict + + + Connection failed + Connection failed + + + + WirelessItem + + Connect to hidden network + Connect to hidden network + + + Password + Password + + + Cancel + button + Cancel + + + Connect + button + Connect + + + Name (SSID) + Name (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Security Type + + + Band + Band + + + Channel + Channel + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmask + + + Gateway + Gateway + + + Primary DNS + Primary DNS + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Speed + + + + dde::network::NetworkDeviceRealize + + Device disabled + Device disabled + + + Connected but no Internet access + Connected but no Internet access + + + Not connected + Not connected + + + Network cable unplugged + Network cable unplugged + + + Connecting + Connecting + + + Authenticating + Authenticating + + + Obtaining IP address + Obtaining IP address + + + Connected + Connected + + + Disconnected + Disconnected + + + IP conflict + IP conflict + + + Failed + Failed + + + Obtaining address + Obtaining address + + + + dde::network::NetworkProcesser + + Wired Network + Wired Network + + + Wired Network %1 + Wired Network %1 + + + Wireless Network + Wireless Network + + + Wireless Network %1 + Wireless Network %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Device disabled + + + Network cable unplugged + Network cable unplugged + + + Not connected + Not connected + + + Connecting + Connecting + + + Connected but no Internet access + Connected but no Internet access + + + Connection failed + Connection failed + + + IP conflict + IP conflict + + + Disable wired connection + Disable wired connection + + + Enable wired connection + Enable wired connection + + + Disable wireless connection + Disable wireless connection + + + Enable wireless connection + Enable wireless connection + + + Disable network + Disable network + + + Enable network + Enable network + + + Network settings + Network settings + + + diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_es.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_es.ts new file mode 100644 index 000000000..7d974cd60 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_es.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Red inalámbrica + + + Wired Network + Red cableada + + + + NetworkPlugin + + Network + Red + + + Wireless Network + + + + Wired Network + Red cableada + + + Device disabled + Dispositivo deshabilitado + + + Network cable unplugged + Cable de red desconectado + + + Not connected + Sin conexión + + + Connecting + Conectando + + + Connected but no Internet access + Conectado pero sin acceso a Internet + + + IP conflict + Conflicto de IP + + + Connection failed + Conexión fallida + + + + WirelessItem + + Connect to hidden network + Conectarse a una red oculta + + + Password + Contraseña + + + Cancel + button + Cancelar + + + Connect + button + Conectar + + + Name (SSID) + Nombre (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Punto de acceso + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de seguridad + + + Band + Banda + + + Channel + Canal + + + Interface + Interfaz + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de red + + + Gateway + Puerta de enlace + + + Primary DNS + DNS primario + + + IPv6 + IPv6 + + + Prefix + Prefijo + + + Speed + Velocidad + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo deshabilitado + + + Connected but no Internet access + Conectado pero sin acceso a Internet + + + Not connected + Sin conexión + + + Network cable unplugged + Cable de red desconectado + + + Connecting + Conectando + + + Authenticating + Autentificando + + + Obtaining IP address + Obteniendo dirección IP + + + Connected + Conectado + + + Disconnected + Desconectado + + + IP conflict + Conflicto de IP + + + Failed + Fallido + + + Obtaining address + Obtención de la dirección + + + + dde::network::NetworkProcesser + + Wired Network + Red cableada + + + Wired Network %1 + Red cableada %1 + + + Wireless Network + Red inalámbrica + + + Wireless Network %1 + Red inalámbrica %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo deshabilitado + + + Network cable unplugged + Cable de red desconectado + + + Not connected + Sin conexión + + + Connecting + Conectando + + + Connected but no Internet access + Conectado pero sin acceso a Internet + + + Connection failed + Conexión fallida + + + IP conflict + Conflicto de IP + + + Disable wired connection + Desactivar conexión por cable + + + Enable wired connection + Activar conexión por cable + + + Disable wireless connection + Desactivar conexión inalámbrica + + + Enable wireless connection + Activar conexión inalámbrica + + + Disable network + Desactivar red + + + Enable network + Activar red + + + Network settings + Ajustes de red + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fa.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fa.ts new file mode 100644 index 000000000..9f8a65c64 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fa.ts @@ -0,0 +1,275 @@ + + + DeviceControllItem + + + Wireless Network + شبکه بیسیم + + + + Wired Network + شبکه کابلی + + + + NetworkPanel + + + Wired connection: %1 + اتصال سیمی %1 + + + + Wired Network + شبکه کابلی + + + + Wireless connection: %1 + + + + + Wireless Network + شبکه بیسیم + + + + Device disabled + دستگاه غیرفعال است + + + + Network cable unplugged + کابل شبکه وصل نشده است + + + + Not connected + متصل نیست + + + + Connecting + در حال اتصال + + + + Connected but no Internet access + متصل است اما دسترسی به اینترنت ندارد + + + + Connection failed + + + + + Disable wired connection + + + + + Enable wired connection + + + + + Disable wireless connection + + + + + Enable wireless connection + + + + + Disable network + غیر فعال کردن شبکه + + + + Enable network + فعال کردن شبکه + + + + Network settings + تنظیمات شبکه + + + + IP conflict + + + + + NetworkPlugin + + + Network + شبکه + + + + dde::network::NetworkController + + + Wired Network + شبکه کابلی + + + + Wired Network %1 + شبکه سیمی %1 + + + + Wireless Network + شبکه بیسیم + + + + Wireless Network %1 + شبکه بی سیم %1 + + + + dde::network::NetworkDetails + + + Hotspot + هات اسپات + + + + SSID + SSID + + + + Protocol + + + + + Security Type + + + + + Band + باند + + + + Channel + کانال + + + + Interface + رابط + + + + MAC + MAC + + + + IPv4 + IPv4 + + + + Gateway + درگاه + + + + Primary DNS + DNS اولیه + + + + Netmask + Netmask + + + + IPv6 + IPv6 + + + + Prefix + پیشوند + + + + Speed + سرعت + + + + dde::network::NetworkDeviceBase + + + Disconnected + قطع اتصال + + + + Connecting + در حال اتصال + + + + Authenticating + تأیید اعتبار + + + + Obtaining address + + + + + Connected + متصل شده + + + + Failed + عدم اعمال + + + + Device disabled + دستگاه غیرفعال است + + + + Connected but no Internet access + متصل است اما دسترسی به اینترنت ندارد + + + + Not connected + متصل نیست + + + + Network cable unplugged + کابل شبکه وصل نشده است + + + + Obtaining IP address + در حال به دست آوردن نشانی IP + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fi.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fi.ts new file mode 100644 index 000000000..2e279fcb0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fi.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Langaton verkko + + + Wired Network + Kaapeli + + + + NetworkPlugin + + Network + Verkko + + + Wireless Network + + + + Wired Network + Kaapeli + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Yhdistä piilotettuun verkkoon + + + Password + Salasana + + + Cancel + button + Peruuta + + + Connect + button + Yhdistä + + + Name (SSID) + Nimi (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Tukiasema + + + SSID + SSID + + + Protocol + Protokolla + + + Security Type + Suojaustyyppi + + + Band + Taajuusalue + + + Channel + Kanava + + + Interface + Liitäntä + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Verkkopeite + + + Gateway + Yhdyskäytävä + + + Primary DNS + Ensisijainen DNS + + + IPv6 + IPv6 + + + Prefix + Etuliite + + + Speed + Nopeus + + + + dde::network::NetworkDeviceRealize + + Device disabled + Laite suljettu + + + Connected but no Internet access + Yhdistetty, mutta ei internet osoitetta + + + Not connected + Ei yhteyttä + + + Network cable unplugged + Verkkokaapeli irrotettu + + + Connecting + Yhdistää + + + Authenticating + Todennus + + + Obtaining IP address + Hakee IP osoitetta + + + Connected + Yhdistetty + + + Disconnected + Katkaistu + + + IP conflict + IP ristiriita + + + Failed + Epäonnistui + + + Obtaining address + Osoitteen haku + + + + dde::network::NetworkProcesser + + Wired Network + Kaapeli + + + Wired Network %1 + Kaapeli %1 + + + Wireless Network + Langaton verkko + + + Wireless Network %1 + Langaton verkko: %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Laite suljettu + + + Network cable unplugged + Verkkokaapeli irrotettu + + + Not connected + Ei yhteyttä + + + Connecting + Yhdistää + + + Connected but no Internet access + Yhdistetty, mutta ei internet osoitetta + + + Connection failed + Yhteys epäonnistui + + + IP conflict + IP ristiriita + + + Disable wired connection + Poista kiinteä yhteys + + + Enable wired connection + Kytke kiinteä yhteys + + + Disable wireless connection + Poista langaton käytöstä + + + Enable wireless connection + Kytke langaton käyttöön + + + Disable network + Poista verkko käytöstä + + + Enable network + Kytke verkko käyttöön + + + Network settings + Verkon asetukset + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fr.ts new file mode 100644 index 000000000..b6fd80a6d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fr.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Réseau sans fil + + + Wired Network + Réseau filaire + + + + NetworkPlugin + + Network + Réseau + + + Wireless Network + + + + Wired Network + Réseau filaire + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Se connecter à un réseau caché + + + Password + Mot de passe + + + Cancel + button + Annuler + + + Connect + button + Relier + + + Name (SSID) + Nom (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Point d'accès + + + SSID + SSID + + + Protocol + Protocole + + + Security Type + Type de sécurité + + + Band + Bande + + + Channel + Canal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Masque de réseau + + + Gateway + passerelle + + + Primary DNS + DNS primaire + + + IPv6 + IPv6 + + + Prefix + Préfixe + + + Speed + Vitesse + + + + dde::network::NetworkDeviceRealize + + Device disabled + Périphérique désactivé + + + Connected but no Internet access + Connecté mais pas d’accès internet + + + Not connected + Pas connecté + + + Network cable unplugged + Câble réseau débranché + + + Connecting + Connexion en cours + + + Authenticating + Authentification + + + Obtaining IP address + Obtention d'adresse IP + + + Connected + Connecté + + + Disconnected + Déconnecté + + + IP conflict + Conflit IP + + + Failed + Échoué + + + Obtaining address + Obtenir l'adresse + + + + dde::network::NetworkProcesser + + Wired Network + Réseau filaire + + + Wired Network %1 + Réseau filaire %1 + + + Wireless Network + Réseau sans fil + + + Wireless Network %1 + Réseau sans fil %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Périphérique désactivé + + + Network cable unplugged + Câble réseau débranché + + + Not connected + Pas connecté + + + Connecting + Connexion en cours + + + Connected but no Internet access + Connecté mais pas d’accès internet + + + Connection failed + La connexion a échoué + + + IP conflict + Conflit IP + + + Disable wired connection + Désactiver la connexion filaire + + + Enable wired connection + Activer la connexion filaire + + + Disable wireless connection + Désactiver la connexion sans fil + + + Enable wireless connection + Activer la connexion sans fil + + + Disable network + Désactiver le réseau + + + Enable network + Activer le réseau + + + Network settings + Paramètres réseau + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_gl_ES.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_gl_ES.ts new file mode 100644 index 000000000..bf680af54 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_gl_ES.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rede sen fíos + + + Wired Network + Rede con fíos + + + + NetworkPlugin + + Network + Rede + + + Wireless Network + + + + Wired Network + Rede con fíos + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Conectar a unha rede oculta + + + Password + Contrasinal + + + Cancel + button + Cancelar + + + Connect + button + Conectar + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Punto de acceso + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de seguranza + + + Band + Banda + + + Channel + Canle + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de rede + + + Gateway + Pasarela + + + Primary DNS + DNS primario + + + IPv6 + IPv6 + + + Prefix + Prefixo + + + Speed + Velocidade + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo desactivado + + + Connected but no Internet access + Conectado pero sen acceso a internet + + + Not connected + Sen conexión + + + Network cable unplugged + Cabo de rede desconectado + + + Connecting + Conectando + + + Authenticating + Autenticando + + + Obtaining IP address + Obtendo o enderezo IP + + + Connected + Conectado + + + Disconnected + Desconectado + + + IP conflict + + + + Failed + Con erros + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Rede con fíos + + + Wired Network %1 + Rede con fíos % 1 + + + Wireless Network + Rede sen fíos + + + Wireless Network %1 + Rede sen fíos %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo desactivado + + + Network cable unplugged + Cabo de rede desconectado + + + Not connected + Sen conexión + + + Connecting + Conectando + + + Connected but no Internet access + Conectado pero sen acceso a internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Desactivar a conexión con fíos + + + Enable wired connection + Activa a conexión con fíos + + + Disable wireless connection + Desactivar a conexión sen fíos + + + Enable wireless connection + Activar a conexión sen fíos + + + Disable network + Desactivar a rede + + + Enable network + Activar a rede + + + Network settings + Axustes da rede + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hi_IN.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hi_IN.ts new file mode 100644 index 000000000..c5f216012 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hi_IN.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + केबल रहित नेटवर्क + + + Wired Network + केबल नेटवर्क + + + + NetworkPlugin + + Network + नेटवर्क + + + Wireless Network + + + + Wired Network + केबल नेटवर्क + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + छुपे नेटवर्क से जुड़ें + + + Password + कूटशब्द + + + Cancel + button + रद्द करें + + + Connect + button + कनेक्ट करें + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + हॉटस्पॉट + + + SSID + SSID + + + Protocol + प्रोटोकॉल + + + Security Type + सुरक्षा प्रकार + + + Band + बैंड + + + Channel + चैनल + + + Interface + इंटरफेस + + + MAC + MAC + + + IPv4 + आईपीवी4 + + + Netmask + Netmask + + + Gateway + नेटवर्क गेटवे + + + Primary DNS + प्राथमिक DNS + + + IPv6 + आईपीवी6 + + + Prefix + नेटवर्क उपसर्ग + + + Speed + गति + + + + dde::network::NetworkDeviceRealize + + Device disabled + उपकरण निष्क्रिय है + + + Connected but no Internet access + कनेक्ट है परंतु नेटवर्क हेतु अभिगम नहीं है + + + Not connected + कनेक्ट नहीं है + + + Network cable unplugged + नेटवर्क केबल हटी हुई है + + + Connecting + कनेक्ट हो रहा है + + + Authenticating + प्रमाणीकृत किया जा रहा है + + + Obtaining IP address + IP अड्रेस प्राप्त किया जा रहा है + + + Connected + कनेक्ट है + + + Disconnected + डिस्कनेक्ट है + + + IP conflict + आईपी विरोधाभास + + + Failed + विफल रहा + + + Obtaining address + नेटवर्क पता प्राप्त करना जारी + + + + dde::network::NetworkProcesser + + Wired Network + केबल नेटवर्क + + + Wired Network %1 + केबल नेटवर्क %1 + + + Wireless Network + केबल रहित नेटवर्क + + + Wireless Network %1 + केबल रहित नेटवर्क %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + उपकरण निष्क्रिय है + + + Network cable unplugged + नेटवर्क केबल हटी हुई है + + + Not connected + कनेक्ट नहीं है + + + Connecting + कनेक्ट हो रहा है + + + Connected but no Internet access + कनेक्ट है परंतु नेटवर्क हेतु अभिगम नहीं है + + + Connection failed + कनेक्ट करना विफल रहा + + + IP conflict + आईपी विरोधाभास + + + Disable wired connection + केबल कनेक्शन निष्क्रिय करें + + + Enable wired connection + केबल कनेक्शन सक्रिय करें + + + Disable wireless connection + केबल रहित कनेक्शन निष्क्रिय करें + + + Enable wireless connection + केबल रहित कनेक्शन सक्रिय करें + + + Disable network + नेटवर्क निष्क्रिय करें + + + Enable network + नेटवर्क सक्रिय करें + + + Network settings + नेटवर्क सेटिंग्स + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hr.ts new file mode 100644 index 000000000..d4882db30 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hr.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Bežična mreža + + + Wired Network + Žična mreža + + + + NetworkPlugin + + Network + Mreža + + + Wireless Network + + + + Wired Network + Žična mreža + + + Device disabled + Uređaj je onemogućen + + + Network cable unplugged + Mrežni kabel je isključen + + + Not connected + Nije spojeno + + + Connecting + Povezujem se + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Poveži na skrivenu mrežu + + + Password + Lozinka + + + Cancel + button + Otkaži + + + Connect + button + Poveži + + + Name (SSID) + Ime (SSID) + + + + dde::network::NetworkDetails + + Hotspot + + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Vrsta sigurnosti + + + Band + Frekvencija + + + Channel + Kanal + + + Interface + Sučelje + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska podmreže + + + Gateway + Pristupnik + + + Primary DNS + Primaran DNS + + + IPv6 + IPv6 + + + Prefix + Prefiks + + + Speed + Brzina + + + + dde::network::NetworkDeviceRealize + + Device disabled + Uređaj je onemogućen + + + Connected but no Internet access + Spojen ali nema pristupa internetu + + + Not connected + Nije spojeno + + + Network cable unplugged + Mrežni kabel je isključen + + + Connecting + Povezujem se + + + Authenticating + Autentifikacija + + + Obtaining IP address + Dobivam IP adresu + + + Connected + Spojeno + + + Disconnected + Odspojeno + + + IP conflict + + + + Failed + Neuspjelo + + + Obtaining address + Dobivanje adrese + + + + dde::network::NetworkProcesser + + Wired Network + Žična mreža + + + Wired Network %1 + Žična mreža %1 + + + Wireless Network + Bežična mreža + + + Wireless Network %1 + Bežična mreža %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Uređaj je onemogućen + + + Network cable unplugged + Mrežni kabel je isključen + + + Not connected + Nije spojeno + + + Connecting + Povezujem se + + + Connected but no Internet access + Spojen ali nema pristupa internetu + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Onemogući žično povezivanje + + + Enable wired connection + Omogući žično povezivanje + + + Disable wireless connection + Onemogući bežično povezivaqnje + + + Enable wireless connection + Omogući bežično povezivanje + + + Disable network + Onemogući mrežu + + + Enable network + Omogući mrežu + + + Network settings + Mrežne postavke + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hu.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hu.ts new file mode 100644 index 000000000..34cb39467 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hu.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Vezeték nélküli hálózat + + + Wired Network + Vezetékes hálózat + + + + NetworkPlugin + + Network + Hálózat + + + Wireless Network + Vezeték nélküli hálózat + + + Wired Network + Vezetékes hálózat + + + Device disabled + Eszköz letiltva + + + Network cable unplugged + A hálózati kábel kihúzva + + + Not connected + Nincs csatlakozva + + + Connecting + Csatlakozás + + + Connected but no Internet access + Csatlakoztatva, de nincs internet hozzáférés + + + IP conflict + IP cím ütközés + + + Connection failed + A kapcsolódás sikertelen + + + + WirelessItem + + Connect to hidden network + Csatlakozás rejtett hálózathoz + + + Password + Jelszó + + + Cancel + button + Mégsem + + + Connect + button + Kapcsolódás + + + Name (SSID) + Név (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokoll + + + Security Type + Biztonság típusa + + + Band + Sáv + + + Channel + Csatorna + + + Interface + Felület + + + MAC + MAC cím + + + IPv4 + IPv4 + + + Netmask + Hálózati maszk + + + Gateway + Átjáró + + + Primary DNS + Elsődleges DNS + + + IPv6 + IPv6 + + + Prefix + Előtag + + + Speed + Sebesség + + + + dde::network::NetworkDeviceRealize + + Device disabled + Eszköz letiltva + + + Connected but no Internet access + Csatlakoztatva, de nincs internet hozzáférés + + + Not connected + Nincs csatlakozva + + + Network cable unplugged + A hálózati kábel kihúzva + + + Connecting + Csatlakozás + + + Authenticating + Hitelesítés + + + Obtaining IP address + IP cím lekérése + + + Connected + Csatlakozva + + + Disconnected + Szétkapcsolva + + + IP conflict + IP cím ütközés + + + Failed + Sikertelen + + + Obtaining address + Cím lekérése + + + + dde::network::NetworkProcesser + + Wired Network + Vezetékes hálózat + + + Wired Network %1 + Vezetékes hálózat %1 + + + Wireless Network + Vezeték nélküli hálózat + + + Wireless Network %1 + Vezeték nélküli hálózat %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Eszköz letiltva + + + Network cable unplugged + A hálózati kábel kihúzva + + + Not connected + Nincs csatlakozva + + + Connecting + Csatlakozás + + + Connected but no Internet access + Csatlakoztatva, de nincs internet hozzáférés + + + Connection failed + A kapcsolódás sikertelen + + + IP conflict + IP cím ütközés + + + Disable wired connection + Vezetékes kapcsolat letiltása + + + Enable wired connection + Vezetékes kapcsolat engedélyezése + + + Disable wireless connection + Vezeték-nélküli kapcsolat letiltása + + + Enable wireless connection + Vezeték nélküli kapcsolat engedélyezése + + + Disable network + Hálózat letiltása + + + Enable network + Hálózat engedélyezése + + + Network settings + Hálózati beállítások + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_it.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_it.ts new file mode 100644 index 000000000..b08185a43 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_it.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Connessione WiFi + + + Wired Network + Connessione cablata + + + + NetworkPlugin + + Network + Rete + + + Wireless Network + + + + Wired Network + Connessione cablata + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Connetti ad una rete nascosta + + + Password + Password + + + Cancel + button + Annulla + + + Connect + button + Connetti + + + Name (SSID) + Nome (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocollo + + + Security Type + Tipo sicurezza + + + Band + Banda + + + Channel + Canale + + + Interface + Interfaccia + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmask + + + Gateway + Gateway + + + Primary DNS + DNS Primario + + + IPv6 + IPv6 + + + Prefix + Prefisso + + + Speed + Velocità + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo disattivato + + + Connected but no Internet access + Connesso senza accesso ad internet + + + Not connected + Non connesso + + + Network cable unplugged + Cavo di rete scollegato + + + Connecting + Connessione in corso + + + Authenticating + Autentificazione in corso + + + Obtaining IP address + Ottenimento indirizzo IP + + + Connected + Connesso + + + Disconnected + Disconnesso + + + IP conflict + Conflitto IP + + + Failed + Connessione fallita + + + Obtaining address + Ottenimento indirizzo + + + + dde::network::NetworkProcesser + + Wired Network + Connessione cablata + + + Wired Network %1 + Connessione cablata %1 + + + Wireless Network + Connessione WiFi + + + Wireless Network %1 + Rete wireless %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo disattivato + + + Network cable unplugged + Cavo di rete scollegato + + + Not connected + Non connesso + + + Connecting + Connessione in corso + + + Connected but no Internet access + Connesso senza accesso ad internet + + + Connection failed + Connessione fallita + + + IP conflict + Conflitto IP + + + Disable wired connection + Disattiva connessione cablata + + + Enable wired connection + Attiva connessione cablata + + + Disable wireless connection + Disattiva connessione WiFi + + + Enable wireless connection + Attiva connessione WiFi + + + Disable network + Disabilita Rete + + + Enable network + Abilita Rete + + + Network settings + Impostazioni Rete + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ja.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ja.ts new file mode 100644 index 000000000..509e556a8 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ja.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + 無線ネットワーク + + + Wired Network + 有線ネットワーク + + + + NetworkPlugin + + Network + ネットワーク + + + Wireless Network + + + + Wired Network + 有線ネットワーク + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + 非表示のネットワークへ接続 + + + Password + パスワード + + + Cancel + button + キャンセル + + + Connect + button + 接続 + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + ホットスポット + + + SSID + SSID + + + Protocol + プロトコル + + + Security Type + セキュリティタイプ + + + Band + バンド + + + Channel + チャンネル + + + Interface + インターフェース + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + ネットマスク + + + Gateway + ゲートウェイ + + + Primary DNS + プライマリ DNS + + + IPv6 + IPv6 + + + Prefix + プレフィックス + + + Speed + 速度 + + + + dde::network::NetworkDeviceRealize + + Device disabled + デバイスが無効 + + + Connected but no Internet access + 接続済み、インターネットアクセスなし + + + Not connected + 未接続 + + + Network cable unplugged + ネットワークケーブル未接続 + + + Connecting + 接続試行中 + + + Authenticating + 認証中 + + + Obtaining IP address + IP アドレスを取得中 + + + Connected + 接続済み + + + Disconnected + 切断 + + + IP conflict + + + + Failed + 失敗 + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + 有線ネットワーク + + + Wired Network %1 + 有線ネットワーク %1 + + + Wireless Network + 無線ネットワーク + + + Wireless Network %1 + 無線接続 %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + デバイスが無効 + + + Network cable unplugged + ネットワークケーブル未接続 + + + Not connected + 未接続 + + + Connecting + 接続試行中 + + + Connected but no Internet access + 接続済み、インターネットアクセスなし + + + Connection failed + + + + IP conflict + + + + Disable wired connection + 有線接続を無効にする + + + Enable wired connection + 有線接続を有効にする + + + Disable wireless connection + 無線接続を無効にする + + + Enable wireless connection + 無線接続を有効にする + + + Disable network + ネットワークを無効にする + + + Enable network + ネットワークを有効にする + + + Network settings + ネットワーク設定 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_kab.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_kab.ts new file mode 100644 index 000000000..aa84380a0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_kab.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + Azeḍḍa + + + + dde::network::NetworkDetails + + Hotspot + + + + SSID + SSID + + + Protocol + Apṛutukul + + + Security Type + Anaw n tɣellist + + + Band + Tasfift + + + Channel + Abadu + + + Interface + Agrudem + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Tagelmust n uzeṭṭa + + + Gateway + Tileggit + + + Primary DNS + DNS agejdan + + + IPv6 + IPv6 + + + Prefix + Uzwir + + + Speed + Arured + + + + dde::network::NetworkDeviceRealize + + Device disabled + Ibenk yensa + + + Connected but no Internet access + Yeqqen maca ulac adduf ɣer internet + + + Not connected + Ur yeqqin ara + + + Network cable unplugged + Agatu n uzeḍḍa yenser + + + Connecting + Tuqqna + + + Authenticating + Asesteb + + + Obtaining IP address + Awway n tansa n IP + + + Connected + Yeqqen + + + Disconnected + Yeffeɣ seg tuqqna + + + IP conflict + + + + Failed + Ur yeddi ara + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Azeṭṭa agatwan + + + Wired Network %1 + Azeḍḍa s tnelli %1 + + + Wireless Network + Azeṭṭa war tinelli + + + Wireless Network %1 + Azeṭṭa war tinelli %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Ibenk yensa + + + Network cable unplugged + Agatu n uzeḍḍa yenser + + + Not connected + Ur yeqqin ara + + + Connecting + Tuqqna + + + Connected but no Internet access + Yeqqen maca ulac adduf ɣer internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Sens tuqqna n tnelli + + + Enable wired connection + Srmed tuqqna n tnelli + + + Disable wireless connection + Sens tuqqna war tinelli + + + Enable wireless connection + Sermed tuqqna war tinelli + + + Disable network + Sens azeḍḍa + + + Enable network + Sexsi azeḍḍa + + + Network settings + Iɣewwaren n uzeḍḍa + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ko.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ko.ts new file mode 100644 index 000000000..0b7489a40 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ko.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + 무선 네트워크 + + + Wired Network + 유선 네트워크 + + + + NetworkPlugin + + Network + 네트워크 + + + Wireless Network + + + + Wired Network + 유선 네트워크 + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + 숨겨진 네트워크에 연결 + + + Password + 비밀번호 + + + Cancel + button + 취소 + + + Connect + button + 연결 + + + Name (SSID) + 명칭(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 핫스팟 + + + SSID + SSID + + + Protocol + 프로토콜 + + + Security Type + 보안 유형 + + + Band + 밴드 + + + Channel + 채널 + + + Interface + 인터페이스 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 넷마스크 + + + Gateway + 게이트웨이 + + + Primary DNS + 기본 DNS + + + IPv6 + IPv6 + + + Prefix + 접두사 + + + Speed + 속도 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 디바이스 사용해제됨 + + + Connected but no Internet access + 연결됨, 인터넷 없음 + + + Not connected + 연결되지 않음 + + + Network cable unplugged + 네트워크 케이블이 연결되어 있지 않습니다. + + + Connecting + 연결 중 + + + Authenticating + 인증 중 + + + Obtaining IP address + IP 주소 가져오는 중 + + + Connected + 연결됨 + + + Disconnected + 연결 끊김 + + + IP conflict + IP 충돌 + + + Failed + 실패 + + + Obtaining address + 주소 불러오는 중 + + + + dde::network::NetworkProcesser + + Wired Network + 유선 네트워크 + + + Wired Network %1 + 유선 네트워크 %1 + + + Wireless Network + 무선 네트워크 + + + Wireless Network %1 + 무선 네트워크 %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 디바이스 사용해제됨 + + + Network cable unplugged + 네트워크 케이블이 연결되어 있지 않습니다. + + + Not connected + 연결되지 않음 + + + Connecting + 연결 중 + + + Connected but no Internet access + 연결됨, 인터넷 없음 + + + Connection failed + 연결 실패 + + + IP conflict + IP 충돌 + + + Disable wired connection + 유선 연결 사용안함 + + + Enable wired connection + 유선 연결 사용가능 + + + Disable wireless connection + 무선 연결 사용안함 + + + Enable wireless connection + 무선 연결 사용가능 + + + Disable network + 네트워크 사용안함 + + + Enable network + 네트워크 사용 + + + Network settings + 네트워크 설정 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_lt.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_lt.ts new file mode 100644 index 000000000..843b90f35 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_lt.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Belaidis tinklas + + + Wired Network + Laidinis tinklas + + + + NetworkPlugin + + Network + Tinklas + + + Wireless Network + + + + Wired Network + Laidinis tinklas + + + Device disabled + Įrenginys išjungtas + + + Network cable unplugged + Atjungtas tinklo laidas + + + Not connected + Neprijungta + + + Connecting + Jungiamasi + + + Connected but no Internet access + Prisijungta, bet nėra prieigos prie interneto + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Prisijungti prie paslėpto tinklo + + + Password + Slaptažodis + + + Cancel + button + Atsisakyti + + + Connect + button + Prisijungti + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Prieigos taškas + + + SSID + SSID + + + Protocol + Protokolas + + + Security Type + Saugumo tipas + + + Band + Juosta + + + Channel + Kanalas + + + Interface + Sąsaja + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Tinklo kaukė + + + Gateway + Tinklų sietuvas + + + Primary DNS + Pirminis DNS + + + IPv6 + IPv6 + + + Prefix + Priešdelis + + + Speed + Greitis + + + + dde::network::NetworkDeviceRealize + + Device disabled + Įrenginys išjungtas + + + Connected but no Internet access + Prisijungta, bet nėra prieigos prie interneto + + + Not connected + Neprijungta + + + Network cable unplugged + Atjungtas tinklo laidas + + + Connecting + Jungiamasi + + + Authenticating + Nustatoma tapatybė + + + Obtaining IP address + Gaunamas IP adresas + + + Connected + Prisijungta + + + Disconnected + Atsijungta + + + IP conflict + + + + Failed + Nepavyko + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Laidinis tinklas + + + Wired Network %1 + Laidinis tinklas %1 + + + Wireless Network + Belaidis tinklas + + + Wireless Network %1 + Belaidis tinklas %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Įrenginys išjungtas + + + Network cable unplugged + Atjungtas tinklo laidas + + + Not connected + Neprijungta + + + Connecting + Jungiamasi + + + Connected but no Internet access + Prisijungta, bet nėra prieigos prie interneto + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Išjungti laidinį ryšį + + + Enable wired connection + Įjungti laidinį ryšį + + + Disable wireless connection + Išjungti belaidį ryšį + + + Enable wireless connection + Įjungti belaidį ryšį + + + Disable network + Išjungti tinklą + + + Enable network + Įjungti tinklą + + + Network settings + Tinklo nustatymai + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ms.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ms.ts new file mode 100644 index 000000000..a0ed33ef3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ms.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rangkaian Tanpa Wayar + + + Wired Network + Rangkaian Berwayar + + + + NetworkPlugin + + Network + Rangkaian + + + Wireless Network + + + + Wired Network + Rangkaian Berwayar + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Sambung ke rangkaian tersembunyi + + + Password + Kata Laluan + + + Cancel + button + Batal + + + Connect + button + Sambung + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Kawasan Khas + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Jenis Keselamatan + + + Band + Jalur + + + Channel + Saluran + + + Interface + Antara Muka + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Topeng Rangkaian + + + Gateway + Get Laluan + + + Primary DNS + DNS Utama + + + IPv6 + IPv6 + + + Prefix + Awalan + + + Speed + Kelajuan + + + + dde::network::NetworkDeviceRealize + + Device disabled + Peranti dilumpuhkan + + + Connected but no Internet access + Bersambung tetapi tiada capaian Internet + + + Not connected + Tidak bersambung + + + Network cable unplugged + Kabel rangkaian telah dicabut + + + Connecting + Menyambung + + + Authenticating + Mengesahihkan + + + Obtaining IP address + Mendapatkan alamat IP + + + Connected + Bersambung + + + Disconnected + Terputus + + + IP conflict + IP berkonflik + + + Failed + Gagal + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Rangkaian Berwayar + + + Wired Network %1 + Rangkaian Berwayar %1 + + + Wireless Network + Rangkaian Tanpa Wayar + + + Wireless Network %1 + Sambungan Tanpa Wayar %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Peranti dilumpuhkan + + + Network cable unplugged + Kabel rangkaian telah dicabut + + + Not connected + Tidak bersambung + + + Connecting + Menyambung + + + Connected but no Internet access + Bersambung tetapi tiada capaian Internet + + + Connection failed + Sambungan gagal + + + IP conflict + IP berkonflik + + + Disable wired connection + Lumpuhkan sambungan berwayar + + + Enable wired connection + Benarkan sambungan berwayar + + + Disable wireless connection + Lumpuhkan sambungan tanpa wayar + + + Enable wireless connection + Benarkan sambungan tanpa wayar + + + Disable network + Lumpuhkan rangkaian + + + Enable network + Benarkan rangkaian + + + Network settings + Tetapan rangkaian + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_nl.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_nl.ts new file mode 100644 index 000000000..19e065884 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_nl.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Draadloos netwerk + + + Wired Network + Bekabeld netwerk + + + + NetworkPlugin + + Network + Netwerk + + + Wireless Network + + + + Wired Network + Bekabeld netwerk + + + Device disabled + Apparaat uitgeschakeld + + + Network cable unplugged + Geen netwerkkabel aangesloten + + + Not connected + Niet verbonden + + + Connecting + Bezig met verbinden… + + + Connected but no Internet access + Verbonden, maar geen internettoegang + + + IP conflict + IP-conflict + + + Connection failed + Verbinding mislukt + + + + WirelessItem + + Connect to hidden network + Verbinden met verborgen netwerk + + + Password + Wachtwoord + + + Cancel + button + Annuleren + + + Connect + button + Verbinden + + + Name (SSID) + Naam (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Soort beveiliging + + + Band + Band + + + Channel + Kanaal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmasker + + + Gateway + Gateway + + + Primary DNS + Primaire dns-server + + + IPv6 + IPv6 + + + Prefix + Voorvoegsel + + + Speed + Snelheid + + + + dde::network::NetworkDeviceRealize + + Device disabled + Apparaat uitgeschakeld + + + Connected but no Internet access + Verbonden, maar geen internettoegang + + + Not connected + Niet verbonden + + + Network cable unplugged + Geen netwerkkabel aangesloten + + + Connecting + Bezig met verbinden… + + + Authenticating + Bezig met authenticeren… + + + Obtaining IP address + Bezig met verkrijgen van ip-adres… + + + Connected + Verbonden + + + Disconnected + Niet verbonden + + + IP conflict + IP-conflict + + + Failed + Mislukt + + + Obtaining address + Bezig met verkrijgen van adres… + + + + dde::network::NetworkProcesser + + Wired Network + Bekabeld netwerk + + + Wired Network %1 + Bekabeld netwerk: %1 + + + Wireless Network + Draadloos netwerk + + + Wireless Network %1 + Draadloos netwerk: %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Apparaat uitgeschakeld + + + Network cable unplugged + Geen netwerkkabel aangesloten + + + Not connected + Niet verbonden + + + Connecting + Bezig met verbinden… + + + Connected but no Internet access + Verbonden, maar geen internettoegang + + + Connection failed + Verbinding mislukt + + + IP conflict + IP-conflict + + + Disable wired connection + Bekabelde verbinding uitschakelen + + + Enable wired connection + Bekabelde verbinding inschakelen + + + Disable wireless connection + Draadloze verbinding uitschakelen + + + Enable wireless connection + Draadloze verbinding inschakelen + + + Disable network + Netwerk uitschakelen + + + Enable network + Netwerk inschakelen + + + Network settings + Netwerkinstellingen + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pl.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pl.ts new file mode 100644 index 000000000..a8f27f07c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pl.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + Sieć bezprzewodowa + + + Wired Network + Sieć przewodowa + + + + NetworkPlugin + + Network + Sieć + + + Wireless Network + Sieć bezprzewodowa + + + Wired Network + Sieć przewodowa + + + Connected + + + + Device disabled + Urządzenie wyłączone + + + Network cable unplugged + Kabel sieciowy odłączony + + + Not connected + Nie połączono + + + Connecting + Łączenie + + + Obtaining address + + + + Connected but no Internet access + Połączono, brak dostępu do Internetu + + + IP conflict + Konflikt adresów IP + + + Connection failed + Połączenie nieudane + + + + WirelessItem + + Connect to hidden network + Połącz z siecią ukrytą + + + Password + Hasło + + + Cancel + button + Anuluj + + + Connect + button + Połącz + + + Name (SSID) + Nazwa (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokół + + + Security Type + Typ zabezpieczenia + + + Band + Pasmo + + + Channel + Kanał + + + Interface + Interfejs + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska sieci + + + Gateway + Brama + + + Primary DNS + Podstawowy DNS + + + IPv6 + IPv6 + + + Prefix + Prefiks + + + Speed + Prędkość + + + + dde::network::NetworkDeviceRealize + + Device disabled + Urządzenie wyłączone + + + Connected but no Internet access + Połączono, brak dostępu do Internetu + + + Not connected + Nie połączono + + + Network cable unplugged + Kabel sieciowy odłączony + + + Connecting + Łączenie + + + Authenticating + Uwierzytelnianie + + + Obtaining IP address + Uzyskiwanie adresu IP + + + Connected + Połączono + + + Disconnected + Rozłączono + + + IP conflict + Konflikt IP + + + Failed + Wystąpił błąd + + + Obtaining address + Uzyskiwanie adresu + + + + dde::network::NetworkProcesser + + Wired Network + Połączenie przewodowe + + + Wired Network %1 + Połączenie przewodowe %1 + + + Wireless Network + Połączenie bezprzewodowe + + + Wireless Network %1 + Połączenie bezprzewodowe %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Urządzenie wyłączone + + + Network cable unplugged + Kabel sieciowy odłączony + + + Not connected + Nie połączono + + + Connecting + Łączenie + + + Connected but no Internet access + Połączono, brak dostępu do Internetu + + + Connection failed + Połączenie nieudane + + + IP conflict + Konflikt IP + + + Disable wired connection + Wyłącz połączenie przewodowe + + + Enable wired connection + Włącz połączenie przewodowe + + + Disable wireless connection + Wyłącz połączenie bezprzewodowe + + + Enable wireless connection + Włącz połączenie bezprzewodowe + + + Disable network + Wyłącz sieć + + + Enable network + Włącz sieć + + + Network settings + Ustawienia sieci + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt.ts new file mode 100644 index 000000000..aaacc8089 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rede sem fios + + + Wired Network + Rede por cabo + + + + NetworkPlugin + + Network + Rede + + + Wireless Network + + + + Wired Network + Rede por cabo + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Ligar a uma rede oculta + + + Password + Palavra-passe + + + Cancel + button + Cancelar + + + Connect + button + Ligar + + + Name (SSID) + Nome (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Ponto de Acesso + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de Segurança + + + Band + Banda + + + Channel + Canal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de rede + + + Gateway + Gateway + + + Primary DNS + DNS Principal + + + IPv6 + IPv6 + + + Prefix + Prefixo + + + Speed + Velocidade + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo desativado + + + Connected but no Internet access + Ligado mas sem acesso à Internet + + + Not connected + Não ligado + + + Network cable unplugged + Cabo de rede desligado + + + Connecting + A ligar + + + Authenticating + A autenticar + + + Obtaining IP address + A obter endereço de IP + + + Connected + Ligado + + + Disconnected + Desligado + + + IP conflict + Conflito de IP + + + Failed + Falha + + + Obtaining address + A obter endereço + + + + dde::network::NetworkProcesser + + Wired Network + Rede por cabo + + + Wired Network %1 + Rede por cabo %1 + + + Wireless Network + Rede sem fios + + + Wireless Network %1 + Rede sem fios %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo desativado + + + Network cable unplugged + Cabo de rede desligado + + + Not connected + Não ligado + + + Connecting + A ligar + + + Connected but no Internet access + Ligado mas sem acesso à Internet + + + Connection failed + Falha na ligação + + + IP conflict + Conflito de IP + + + Disable wired connection + Desativar ligação por cabo + + + Enable wired connection + Ativar ligação por cabo + + + Disable wireless connection + Desativar ligação sem fios + + + Enable wireless connection + Ativar ligação sem fios + + + Disable network + Desativar rede + + + Enable network + Ativar rede + + + Network settings + Definições de rede + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt_BR.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt_BR.ts new file mode 100644 index 000000000..ff1247eb2 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt_BR.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rede Wi-Fi + + + Wired Network + Rede Cabeada + + + + NetworkPlugin + + Network + Rede + + + Wireless Network + + + + Wired Network + Rede Cabeada + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Conectar-se à rede oculta + + + Password + Senha + + + Cancel + button + Cancelar + + + Connect + button + Conectar + + + Name (SSID) + Nome (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de Segurança + + + Band + Frequência + + + Channel + Canal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de Sub-rede + + + Gateway + Gateway + + + Primary DNS + DNS Primário + + + IPv6 + IPv6 + + + Prefix + Prefixo + + + Speed + Velocidade + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo desabilitado + + + Connected but no Internet access + Conectado, sem internet + + + Not connected + Não conectado + + + Network cable unplugged + Cabo de rede desconectado + + + Connecting + Conectando + + + Authenticating + Autenticando + + + Obtaining IP address + Obtendo endereço IP + + + Connected + Conectado + + + Disconnected + Desconectado + + + IP conflict + Conflito de IP + + + Failed + Falhou + + + Obtaining address + Obtendo endereço + + + + dde::network::NetworkProcesser + + Wired Network + Rede Cabeada + + + Wired Network %1 + Rede Cabeada %1 + + + Wireless Network + Rede Wi-Fi + + + Wireless Network %1 + Rede Wi-Fi %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo desabilitado + + + Network cable unplugged + Cabo de rede desconectado + + + Not connected + Não conectado + + + Connecting + Conectando + + + Connected but no Internet access + Conectado, sem internet + + + Connection failed + A conexão falhou + + + IP conflict + Conflito de IP + + + Disable wired connection + Desativar conexão cabeada + + + Enable wired connection + Ativar conexão cabeada + + + Disable wireless connection + Desativar conexão Wi-Fi + + + Enable wireless connection + Ativar conexão Wi-Fi + + + Disable network + Desativar rede + + + Enable network + Ativar rede + + + Network settings + Configurações de rede + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ro.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ro.ts new file mode 100644 index 000000000..7f64c62e0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ro.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rețea fără fir + + + Wired Network + Rețea conectată + + + + NetworkPlugin + + Network + Reţea + + + Wireless Network + + + + Wired Network + Rețea conectată + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Conectare la rețele ascunse + + + Password + Parola + + + Cancel + button + Anulează + + + Connect + button + Conectare + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Tip Securitate + + + Band + Bandă + + + Channel + Canal + + + Interface + Interfață + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Mască de rețea + + + Gateway + Portalul + + + Primary DNS + DNS primar + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Viteză + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispozitiv Dezactivat + + + Connected but no Internet access + Conectat dar fară acces Internet + + + Not connected + Neconectat + + + Network cable unplugged + Cablu Reţea Deconectat + + + Connecting + Conectare + + + Authenticating + Autentificare + + + Obtaining IP address + Obţinere Adresă IP + + + Connected + Conectat + + + Disconnected + Deconectat + + + IP conflict + + + + Failed + Eșuat + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Rețea conectată + + + Wired Network %1 + Rețea Cablu %1 + + + Wireless Network + Rețea fără fir + + + Wireless Network %1 + Rețea fără fir %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispozitiv Dezactivat + + + Network cable unplugged + Cablu Reţea Deconectat + + + Not connected + Neconectat + + + Connecting + Conectare + + + Connected but no Internet access + Conectat dar fară acces Internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Dezactivați conexiunea prin cablu + + + Enable wired connection + Activați conexiunea prin cablu + + + Disable wireless connection + Dezactivați conexiunea fără fir + + + Enable wireless connection + Activați conexiunea fără fir + + + Disable network + Dezactivați conexiunea la rețea + + + Enable network + Activați rețeaua + + + Network settings + Configurări de rețea + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ru.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ru.ts new file mode 100644 index 000000000..d3d398a37 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ru.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Беспроводная сеть + + + Wired Network + Проводная сеть + + + + NetworkPlugin + + Network + Сеть + + + Wireless Network + + + + Wired Network + Проводная сеть + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Подключиться к скрытой сети + + + Password + Пароль + + + Cancel + button + Отмена + + + Connect + button + Подключить + + + Name (SSID) + Имя (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Точка доступа + + + SSID + SSID + + + Protocol + Протокол + + + Security Type + Тип безопасности + + + Band + Диапазон + + + Channel + Канал + + + Interface + Интерфейс + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Маска сети + + + Gateway + Шлюз + + + Primary DNS + Основной DNS + + + IPv6 + IPv6 + + + Prefix + Префикс + + + Speed + Скорость + + + + dde::network::NetworkDeviceRealize + + Device disabled + Устройство отключено + + + Connected but no Internet access + Подключено, без доступа к Интернету + + + Not connected + Не подключено + + + Network cable unplugged + Сетевой кабель отключен + + + Connecting + Соединение + + + Authenticating + Аутентификация + + + Obtaining IP address + Получение IP адреса + + + Connected + Подключено + + + Disconnected + Отключено + + + IP conflict + Конфликт IP-адресов + + + Failed + Ошибка + + + Obtaining address + Получение адреса + + + + dde::network::NetworkProcesser + + Wired Network + Проводная сеть + + + Wired Network %1 + Проводная сеть %1 + + + Wireless Network + Беспроводная сеть + + + Wireless Network %1 + Беспроводная сеть %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Устройство отключено + + + Network cable unplugged + Сетевой кабель отключен + + + Not connected + Не подключено + + + Connecting + Соединение + + + Connected but no Internet access + Подключено, без доступа к Интернету + + + Connection failed + Ошибка подключения + + + IP conflict + Конфликт IP-адресов + + + Disable wired connection + Отключить проводное соединение + + + Enable wired connection + Включить проводное соединение + + + Disable wireless connection + Отключить проводное соединение + + + Enable wireless connection + Включить проводное соединение + + + Disable network + Отключить сеть + + + Enable network + Включить сеть + + + Network settings + Настройки сети + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_si.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_si.ts new file mode 100644 index 000000000..e7f49d0f9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_si.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + රැහැන් රහිත ජාලය + + + Wired Network + රැහැන්ගත ජාලය + + + + NetworkPlugin + + Network + ජාලය + + + Wireless Network + + + + Wired Network + රැහැන්ගත ජාලය + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + සැඟවුණු ජාලයකට සම්බන්ධ වන්න + + + Password + මුර පදය + + + Cancel + button + අවලංගු කරන්න + + + Connect + button + සම්බන්ධ කරන්න + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + හොට්ස්පොට් + + + SSID + SSID + + + Protocol + ප්රොටෝකෝලය + + + Security Type + ආරක්ෂක වර්ගය + + + Band + කලාපය + + + Channel + නාලිකාව + + + Interface + අතුරුමුහුණත + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + නෙට්මාස්ක් + + + Gateway + දොරටුව-gateway + + + Primary DNS + ප්‍රාථමික DNS + + + IPv6 + IPv6 + + + Prefix + උපසර්ගය + + + Speed + වේගය + + + + dde::network::NetworkDeviceRealize + + Device disabled + උපාංගය අක්‍රීය කර ඇත + + + Connected but no Internet access + ජාලගතව ඇතත් අන්තර්ජාල ප්‍රවේශය නොමැත + + + Not connected + සම්බන්ධතා නොමැත + + + Network cable unplugged + ජාල කේබලය විසන්ධි කර ඇත + + + Connecting + සම්බන්ධ වෙමින් පවතී + + + Authenticating + සත්‍යාපනය කිරීම + + + Obtaining IP address + IP ලිපිනය ලබා ගැනීම + + + Connected + සම්බන්ධයි + + + Disconnected + විසන්ධි වි ඇත + + + IP conflict + + + + Failed + අසමත් විය + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + රැහැන්ගත ජාලය + + + Wired Network %1 + රැහැන්ගත ජාලය %1 + + + Wireless Network + රැහැන් රහිත ජාලය + + + Wireless Network %1 + රැහැන් රහිත ජාලය %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + උපාංගය අක්‍රීය කර ඇත + + + Network cable unplugged + ජාල කේබලය විසන්ධි කර ඇත + + + Not connected + සම්බන්ධතා නොමැත + + + Connecting + සම්බන්ධ වෙමින් පවතී + + + Connected but no Internet access + ජාලගතව ඇතත් අන්තර්ජාල ප්‍රවේශය නොමැත + + + Connection failed + + + + IP conflict + + + + Disable wired connection + රැහැන් සම්බන්ධතාවය අක්‍රීය කරන්න + + + Enable wired connection + රැහැන් සම්බන්ධතාවය සක්‍රීය කරන්න + + + Disable wireless connection + රැහැන් රහිත සම්බන්ධතාවය අක්‍රීය කරන්න + + + Enable wireless connection + රැහැන් රහිත සම්බන්ධතාවය සක්‍රීය කරන්න + + + Disable network + ජාලය අක්‍රීය කරන්න + + + Enable network + ජාලය සක්‍රීය කරන්න + + + Network settings + ජාල සැකසුම් + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sk.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sk.ts new file mode 100644 index 000000000..cfdddf464 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sk.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + Sieť + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + + + + Security Type + + + + Band + Pásmo + + + Channel + Kanál + + + Interface + Rozhranie + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska + + + Gateway + Brána + + + Primary DNS + Primárna DNS + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Rýchlosť + + + + dde::network::NetworkDeviceRealize + + Device disabled + Zariadenie zakázané + + + Connected but no Internet access + Pripojené, ale bez prístupu na internet + + + Not connected + Nepripojené + + + Network cable unplugged + Sieťový kábel odpojený + + + Connecting + Pripájanie + + + Authenticating + Overujem + + + Obtaining IP address + Získavanie IP adresy + + + Connected + Pripojené + + + Disconnected + Odpojené + + + IP conflict + + + + Failed + Zlyhanie + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Drôtová sieť + + + Wired Network %1 + Káblová sieť %1 + + + Wireless Network + Bezdrôtová sieť + + + Wireless Network %1 + Bezdrôtová sieť %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Zariadenie zakázané + + + Network cable unplugged + Sieťový kábel odpojený + + + Not connected + Nepripojené + + + Connecting + Pripájanie + + + Connected but no Internet access + Pripojené, ale bez prístupu na internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Vypnúť káblové pripojenie + + + Enable wired connection + Zapnúť káblové pripojenie + + + Disable wireless connection + Vypnúť bezdrôtové pripojenie + + + Enable wireless connection + Zapnúť bezdrôtové pripojenie + + + Disable network + Zakázať sieť + + + Enable network + Povoliť sieť + + + Network settings + Nastavenia siete + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sl.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sl.ts new file mode 100644 index 000000000..0aa524821 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sl.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Brezžično omrežje + + + Wired Network + Ožičeno omrežje + + + + NetworkPlugin + + Network + Omrežje + + + Wireless Network + + + + Wired Network + Ožičeno omrežje + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Povezava na skrito omrežje + + + Password + Geslo + + + Cancel + button + Prekini + + + Connect + button + Poveži + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Dostopna točka + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Vrsta varnosti + + + Band + Pas + + + Channel + Kanal + + + Interface + Vmesnik + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Omrežna maska + + + Gateway + Prehod + + + Primary DNS + Prednostni DNS + + + IPv6 + IPv6 + + + Prefix + Predpona + + + Speed + Hitrost + + + + dde::network::NetworkDeviceRealize + + Device disabled + Naprava onemogočena + + + Connected but no Internet access + Povezano, brez dostopa do spleta + + + Not connected + Brez povezave + + + Network cable unplugged + Omrežni kabel je izklopljen + + + Connecting + Povezovanje + + + Authenticating + Overjanje + + + Obtaining IP address + Pridobivanje IP naslova + + + Connected + Povezava vzpostavljena + + + Disconnected + Povezava prekinjena + + + IP conflict + IP spor + + + Failed + Ni uspelo + + + Obtaining address + Pridobivanje naslova + + + + dde::network::NetworkProcesser + + Wired Network + Ožičeno omrežje + + + Wired Network %1 + Žično omrežje %1 + + + Wireless Network + Brezžično omrežje + + + Wireless Network %1 + Brezžično omrežje %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Naprava onemogočena + + + Network cable unplugged + Omrežni kabel je izklopljen + + + Not connected + Brez povezave + + + Connecting + Povezovanje + + + Connected but no Internet access + Povezano, brez dostopa do spleta + + + Connection failed + Povezava ni uspela + + + IP conflict + IP spor + + + Disable wired connection + Onemogoči žično povezavo + + + Enable wired connection + Omogoči žično povezavo + + + Disable wireless connection + Onemogoči brezžično povezavo + + + Enable wireless connection + Omogoči brezžično povezavo + + + Disable network + Onemogoči omrežje + + + Enable network + Omogoči omrežje + + + Network settings + Nastavitve omrežja + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sq.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sq.ts new file mode 100644 index 000000000..88f02592d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sq.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Rrjet Pa Fill + + + Wired Network + Rrjet Me Fill + + + + NetworkPlugin + + Network + Rrjet + + + Wireless Network + + + + Wired Network + Rrjet Me Fill + + + Device disabled + Pajisje e çaktivizuar + + + Network cable unplugged + Kablloja e rrjetit është e hequr + + + Not connected + Jo e lidhur + + + Connecting + Po lidhet + + + Connected but no Internet access + E lidhur, por pa hyrje Internet + + + IP conflict + Përplasje IP-sh + + + Connection failed + Lidhja dështoi + + + + WirelessItem + + Connect to hidden network + Lidhu me rrjet të fshehur + + + Password + Fjalëkalim + + + Cancel + button + Anuloje + + + Connect + button + Lidhu + + + Name (SSID) + Emër (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokoll + + + Security Type + Lloj Sigurie + + + Band + Bandë + + + Channel + Kanal + + + Interface + Ndërfaqe + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + NetMask-ë + + + Gateway + Kanal + + + Primary DNS + DNS Parësore + + + IPv6 + IPv6 + + + Prefix + Parashtesë + + + Speed + Shpejtësi + + + + dde::network::NetworkDeviceRealize + + Device disabled + Pajisje e çaktivizuar + + + Connected but no Internet access + E lidhur, por pa hyrje Internet + + + Not connected + Jo e lidhur + + + Network cable unplugged + Kablloja e rrjetit është e hequr + + + Connecting + Po lidhet + + + Authenticating + Po bëhet mirëfilltësim + + + Obtaining IP address + Po merret adresë IP + + + Connected + E lidhur + + + Disconnected + E shkëputur + + + IP conflict + Përplasje IP-sh + + + Failed + U dështua + + + Obtaining address + Po merret adresë + + + + dde::network::NetworkProcesser + + Wired Network + Rrjet Me Fill + + + Wired Network %1 + Rrjet Me Fill %1 + + + Wireless Network + Rrjet Pa Fill + + + Wireless Network %1 + Rrjet Pa Fill %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Pajisje e çaktivizuar + + + Network cable unplugged + Kablloja e rrjetit është e hequr + + + Not connected + Jo e lidhur + + + Connecting + Po lidhet + + + Connected but no Internet access + E lidhur, por pa hyrje Internet + + + Connection failed + Lidhja dështoi + + + IP conflict + Përplasje IP-sh + + + Disable wired connection + Çaktivizo lidhje me fill + + + Enable wired connection + Aktivizo lidhje me fill + + + Disable wireless connection + Çaktivizo lidhje pa fill + + + Enable wireless connection + Aktivizo lidhje pa fill + + + Disable network + Çaktivizo rrjetin + + + Enable network + Aktivizo rrjetin + + + Network settings + Rregullime rrjeti + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sr.ts new file mode 100644 index 000000000..db6d2cd68 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sr.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Бежична мрежа + + + Wired Network + Жична мрежа + + + + NetworkPlugin + + Network + Мрежа + + + Wireless Network + + + + Wired Network + Жична мрежа + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Повежи се на скривену мрежу + + + Password + Лозинка + + + Cancel + button + Откажи + + + Connect + button + Повежи се + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Врућа тачка + + + SSID + ССИД + + + Protocol + Протокол + + + Security Type + Врста безбедности + + + Band + Опсег + + + Channel + Канал + + + Interface + Сучеље + + + MAC + МАК + + + IPv4 + ИПв4 + + + Netmask + Мрежна маска + + + Gateway + Мрежни пролаз + + + Primary DNS + Основни ДНС + + + IPv6 + ИПв6 + + + Prefix + Префикс + + + Speed + Брзина протока + + + + dde::network::NetworkDeviceRealize + + Device disabled + Уређај је онемогућен + + + Connected but no Internet access + Повезани сте, али нема интернета + + + Not connected + Нисте повезани + + + Network cable unplugged + Мрежни кабл је ископчан + + + Connecting + Повезивање + + + Authenticating + Идентификовање + + + Obtaining IP address + Прибављање ИП адресе + + + Connected + Повезани сте + + + Disconnected + Нисте поевзани + + + IP conflict + ИП сукоб + + + Failed + Неуспешно + + + Obtaining address + Прибављање адресе + + + + dde::network::NetworkProcesser + + Wired Network + Жична мрежа + + + Wired Network %1 + Жичана мрежа %1 + + + Wireless Network + Бежична мрежа + + + Wireless Network %1 + Бежична мрежа %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Уређај је онемогућен + + + Network cable unplugged + Мрежни кабл је ископчан + + + Not connected + Нисте повезани + + + Connecting + Повезивање + + + Connected but no Internet access + Повезани сте, али нема интернета + + + Connection failed + Неуспешно повезивање + + + IP conflict + ИП сукоб + + + Disable wired connection + Искључи жичану везу + + + Enable wired connection + Укључи жичану везу + + + Disable wireless connection + Искључи бежичану везу + + + Enable wireless connection + Укључи бежичану везу + + + Disable network + Искључи мрежу + + + Enable network + Укључи мрежу + + + Network settings + Подешавање мреже + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_tr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_tr.ts new file mode 100644 index 000000000..55824fb25 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_tr.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Kablosuz Ağ + + + Wired Network + Kablolu Ağ + + + + NetworkPlugin + + Network + + + + Wireless Network + + + + Wired Network + Kablolu Ağ + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Gizli ağa bağlan + + + Password + Parola + + + Cancel + button + İptal + + + Connect + button + Bağlan + + + Name (SSID) + İsim (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Bağlantı Noktası + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Güvenlik Türü + + + Band + Bant + + + Channel + Kanal + + + Interface + Arayüz + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Ağ Maskesi + + + Gateway + Ağ Geçidi + + + Primary DNS + Birincil DNS + + + IPv6 + IPv6 + + + Prefix + Ön Ek + + + Speed + Hız + + + + dde::network::NetworkDeviceRealize + + Device disabled + Aygıt devre dışı + + + Connected but no Internet access + Bağlandı ancak İnternet erişimi yok + + + Not connected + Bağlı değil + + + Network cable unplugged + Ağ kablosu takılı değil + + + Connecting + Bağlanıyor + + + Authenticating + Kimlik doğrulanıyor + + + Obtaining IP address + IP adresi elde ediliyor + + + Connected + Bağlandı + + + Disconnected + Bağlantı kesildi + + + IP conflict + IP çakışması + + + Failed + Başarısız + + + Obtaining address + Adres elde ediliyor + + + + dde::network::NetworkProcesser + + Wired Network + Kablolu Ağ + + + Wired Network %1 + Kablolu Ağ %1 + + + Wireless Network + Kablosuz Ağ + + + Wireless Network %1 + Kablosuz Ağ%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Aygıt devre dışı + + + Network cable unplugged + Ağ kablosu takılı değil + + + Not connected + Bağlı değil + + + Connecting + Bağlanıyor + + + Connected but no Internet access + Bağlandı ancak İnternet erişimi yok + + + Connection failed + Bağlantı başarısız + + + IP conflict + IP çakışması + + + Disable wired connection + Kablolu bağlantıyı devre dışı bırak + + + Enable wired connection + Kablolu bağlantıyı etkinleştir + + + Disable wireless connection + Kablosuz bağlantıyı devre dışı bırak + + + Enable wireless connection + Kablosuz bağlantıyı etkinleştir + + + Disable network + Ağı devre dışı bırak + + + Enable network + Ağı etkinleştir + + + Network settings + Ay ayarları + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ug.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ug.ts new file mode 100644 index 000000000..b75630823 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ug.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + سىمسىز تور + + + Wired Network + سىملىق تور + + + + NetworkPlugin + + Network + تور + + + Wireless Network + + + + Wired Network + سىملىق تور + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + يوشۇرۇن تورغا ئۇلاش + + + Password + پارولنى كىرگۈزۈڭ + + + Cancel + button + بىكار قىلىش + + + Connect + button + ئۇلاش + + + Name (SSID) + تور نامىنى كىرگۈزۈڭ(SSID) + + + + dde::network::NetworkDetails + + Hotspot + ھەمبەھىر نۇقتىسى + + + SSID + SSID + + + Protocol + كېلىشىم + + + Security Type + بىخەتەرلىك تۈرى + + + Band + دولقۇن بۆلىكى + + + Channel + قانال + + + Interface + ئۇلىنىش ئېغىزى + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + تور قەۋىتى + + + Gateway + تور قانىلى + + + Primary DNS + شەخسىي DNS + + + IPv6 + IPv6 + + + Prefix + قوشۇمچە + + + Speed + تېزلىكى + + + + dde::network::NetworkDeviceRealize + + Device disabled + ئۈسكۈنە ئىشلىتىش چەكلەندى + + + Connected but no Internet access + تورغا ئۇلاندى،ئەمما تورنى زىيارەت قىلالمىدى + + + Not connected + ئۇلانمىدى + + + Network cable unplugged + تور سىمى ئۇلانمىغان + + + Connecting + ئۇلىنىۋاتىدۇ + + + Authenticating + دەلىللەۋاتىدۇ + + + Obtaining IP address + IP ئادرېسىغا ئېرىشىش + + + Connected + ئۇلاندى + + + Disconnected + ئۈزۈلدى + + + IP conflict + IP ئادرېس توقۇنۇشۇپ قالدى + + + Failed + مەغلۇب بولدى + + + Obtaining address + ئادرېسىغا ئېرىشىۋاتىدۇ + + + + dde::network::NetworkProcesser + + Wired Network + سىملىق تور + + + Wired Network %1 + سىملىق تور%1 + + + Wireless Network + سىمسىز تور + + + Wireless Network %1 + سىمسىز تور%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + ئۈسكۈنە ئىشلىتىش چەكلەندى + + + Network cable unplugged + تور سىمى ئۇلانمىغان + + + Not connected + ئۇلانمىدى + + + Connecting + ئۇلىنىۋاتىدۇ + + + Connected but no Internet access + تورغا ئۇلاندى،ئەمما تورنى زىيارەت قىلالمىدى + + + Connection failed + ئۇلىنىش مەغلۇپ بولدى + + + IP conflict + IP ئادرېس توقۇنۇشۇپ قالدى + + + Disable wired connection + سىملىق تورنى تاقاش + + + Enable wired connection + سىملىق تورنى ئېچىش + + + Disable wireless connection + سىمسىز تورنى تاقاش + + + Enable wireless connection + سىمسىز تورنى ئېچىش + + + Disable network + تورنى تاقاش + + + Enable network + تورنى قوزغىتىش + + + Network settings + تور تەڭشىكى + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_uk.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_uk.ts new file mode 100644 index 000000000..769935f45 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_uk.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + Бездротова мережа + + + Wired Network + Провідна мережа + + + + NetworkPlugin + + Network + Мережа + + + Wireless Network + Бездротова мережа + + + Wired Network + Провідна мережа + + + Connected + + + + Device disabled + Пристрій вимкнено + + + Network cable unplugged + Кабель мережі від'єднано + + + Not connected + Не з'єднано + + + Connecting + З'єднання + + + Obtaining address + + + + Connected but no Internet access + З'єднано, але немає доступу до інтернету + + + IP conflict + Конфлікт IP + + + Connection failed + Не вдалося встановити з'єднання + + + + WirelessItem + + Connect to hidden network + Встановлення з'єднання із прихованою мережею + + + Password + Пароль + + + Cancel + button + Скасувати + + + Connect + button + З'єднатися + + + Name (SSID) + Назва (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Точка доступу + + + SSID + SSID + + + Protocol + Протокол + + + Security Type + Тип захисту + + + Band + Група + + + Channel + Канал + + + Interface + Інтерфейс + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Маска мережі + + + Gateway + Шлюз + + + Primary DNS + Основний DNS + + + IPv6 + IPv6 + + + Prefix + Префікс + + + Speed + Швидкість + + + + dde::network::NetworkDeviceRealize + + Device disabled + Пристрій вимкнено + + + Connected but no Internet access + З'єднано, але немає доступу до інтернету + + + Not connected + Не з'єднано + + + Network cable unplugged + Кабель мережі від'єднано + + + Connecting + З'єднання + + + Authenticating + Розпізнавання + + + Obtaining IP address + Отримуємо IP-адресу + + + Connected + З'єднано + + + Disconnected + Роз'єднано + + + IP conflict + Конфлікт IP + + + Failed + Помилка + + + Obtaining address + Отримання адреси + + + + dde::network::NetworkProcesser + + Wired Network + Дротова мережа + + + Wired Network %1 + Дротова мережа %1 + + + Wireless Network + Бездротова мережа + + + Wireless Network %1 + Бездротова мережа %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Пристрій вимкнено + + + Network cable unplugged + Кабель мережі від'єднано + + + Not connected + Не з'єднано + + + Connecting + З'єднання + + + Connected but no Internet access + З'єднано, але немає доступу до інтернету + + + Connection failed + Не вдалося встановити з'єднання + + + IP conflict + Конфлікт IP + + + Disable wired connection + Вимкнути дротове з'єднання + + + Enable wired connection + Увімкнути дротове з'єднання + + + Disable wireless connection + Вимкнути бездротове з'єднання + + + Enable wireless connection + Увімкнути бездротове з'єднання + + + Disable network + Вимкнути мережу + + + Enable network + Увімкнути мережу + + + Network settings + Параметри мережі + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_vi.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_vi.ts new file mode 100644 index 000000000..03d1dfc39 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_vi.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Mạng không dây + + + Wired Network + Mạng kết nối dây + + + + NetworkPlugin + + Network + Mạng + + + Wireless Network + + + + Wired Network + Mạng kết nối dây + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Kết nối với mạng ẩn + + + Password + Mật mã + + + Cancel + button + Hủy + + + Connect + button + Kết nối + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Điểm truy cập + + + SSID + SSID + + + Protocol + Giao thức + + + Security Type + Loại bảo mật + + + Band + Băng tần + + + Channel + Kênh + + + Interface + Giao diện + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Mặt nạ mạng + + + Gateway + Cổng vào + + + Primary DNS + DNS Đầu + + + IPv6 + IPv6 + + + Prefix + Tiền tố + + + Speed + Tốt độ + + + + dde::network::NetworkDeviceRealize + + Device disabled + Thiết bị bị vô hiệu hóa + + + Connected but no Internet access + Đã kết nối nhưng không có truy cập Internet + + + Not connected + Không được kết nối + + + Network cable unplugged + Mạng dây đã ngắt + + + Connecting + Đang kết nối + + + Authenticating + Đang xác nhận + + + Obtaining IP address + Đang lấy địa chỉ IP + + + Connected + Đã kết nối + + + Disconnected + Đã ngắt kết nối + + + IP conflict + + + + Failed + Thất bại + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Mạng kết nối dây + + + Wired Network %1 + Mạng kết nối dây %1 + + + Wireless Network + Mạng không dây + + + Wireless Network %1 + Mạng Không dây %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Thiết bị bị vô hiệu hóa + + + Network cable unplugged + Mạng dây đã ngắt + + + Not connected + Không được kết nối + + + Connecting + Đang kết nối + + + Connected but no Internet access + Đã kết nối nhưng không có truy cập Internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Tắt kết nối mạng dây + + + Enable wired connection + Mở kết nối mạng dây + + + Disable wireless connection + Tắt kết nối wifi + + + Enable wireless connection + Bật kết nối wifi + + + Disable network + Vô hiệu hóa mạng + + + Enable network + Cho phép mạng + + + Network settings + Thiết lập mạng + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_CN.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_CN.ts new file mode 100644 index 000000000..9124fc4a8 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_CN.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + 无线网络 + + + Wired Network + 有线网络 + + + + NetworkPlugin + + Network + 网络 + + + Wireless Network + 无线网络 + + + Wired Network + 有线网络 + + + Connected + 已连接 + + + Device disabled + 设备已禁用 + + + Network cable unplugged + 未插入网线 + + + Not connected + 未连接 + + + Connecting + 正在连接 + + + Obtaining address + 获取地址中 + + + Connected but no Internet access + 已连接网络但无法访问互联网 + + + IP conflict + IP地址冲突 + + + Connection failed + 连接失败 + + + + WirelessItem + + Connect to hidden network + 连接到隐藏网络 + + + Password + 请输入密码 + + + Cancel + button + 取 消 + + + Connect + button + 连 接 + + + Name (SSID) + 请输入网络名称(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 热点 + + + SSID + SSID + + + Protocol + 协议 + + + Security Type + 安全类型 + + + Band + 频段 + + + Channel + 网络通道 + + + Interface + 接口 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 子网掩码 + + + Gateway + 网关 + + + Primary DNS + 首选DNS + + + IPv6 + IPv6 + + + Prefix + 前缀 + + + Speed + 速率 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 设备已禁用 + + + Connected but no Internet access + 已连接网络但无法访问互联网 + + + Not connected + 未连接 + + + Network cable unplugged + 未插入网线 + + + Connecting + 正在连接 + + + Authenticating + 认证中 + + + Obtaining IP address + 正在获取IP地址 + + + Connected + 已连接 + + + Disconnected + 已断开 + + + IP conflict + IP地址冲突 + + + Failed + 失败 + + + Obtaining address + 获取地址中 + + + + dde::network::NetworkProcesser + + Wired Network + 有线网络 + + + Wired Network %1 + 有线网络%1 + + + Wireless Network + 无线网络 + + + Wireless Network %1 + 无线网络%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 设备已禁用 + + + Network cable unplugged + 未插入网线 + + + Not connected + 未连接 + + + Connecting + 正在连接 + + + Connected but no Internet access + 已连接网络但无法访问互联网 + + + Connection failed + 连接失败 + + + IP conflict + IP地址冲突 + + + Disable wired connection + 关闭有线网络 + + + Enable wired connection + 启用有线网络 + + + Disable wireless connection + 关闭无线网络 + + + Enable wireless connection + 启用无线网络 + + + Disable network + 关闭网络 + + + Enable network + 启用网络 + + + Network settings + 网络设置 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_HK.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_HK.ts new file mode 100644 index 000000000..aceae9ddf --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_HK.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + 無線網絡 + + + Wired Network + 有線網絡 + + + + NetworkPlugin + + Network + 網絡 + + + Wireless Network + 無線網絡 + + + Wired Network + 有線網絡 + + + Connected + 已連接 + + + Device disabled + 設備已禁用 + + + Network cable unplugged + 未插入網線 + + + Not connected + 未連接 + + + Connecting + 正在連接 + + + Obtaining address + 獲取地址中 + + + Connected but no Internet access + 已連接網絡但無法訪問互聯網 + + + IP conflict + IP位址衝突 + + + Connection failed + 連接失敗 + + + + WirelessItem + + Connect to hidden network + 連接到隱藏網絡 + + + Password + 請輸入密碼 + + + Cancel + button + 取 消 + + + Connect + button + 連 接 + + + Name (SSID) + 請輸入網絡名稱(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 熱點 + + + SSID + SSID + + + Protocol + 協議 + + + Security Type + 安全類型 + + + Band + 頻段 + + + Channel + 網絡通道 + + + Interface + 接口 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 子網掩碼 + + + Gateway + 網關 + + + Primary DNS + 首選DNS + + + IPv6 + IPv6 + + + Prefix + 前綴 + + + Speed + 速率 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 設備已禁用 + + + Connected but no Internet access + 已連接網絡但無法訪問互聯網 + + + Not connected + 未連接 + + + Network cable unplugged + 未插入網線 + + + Connecting + 正在連接 + + + Authenticating + 認證中 + + + Obtaining IP address + 正在獲取IP位址 + + + Connected + 已連接 + + + Disconnected + 已斷開 + + + IP conflict + IP位址衝突 + + + Failed + 失敗 + + + Obtaining address + 獲取地址中 + + + + dde::network::NetworkProcesser + + Wired Network + 有線網絡 + + + Wired Network %1 + 有線網絡%1 + + + Wireless Network + 無線網絡 + + + Wireless Network %1 + 無線網絡%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 設備已禁用 + + + Network cable unplugged + 未插入網線 + + + Not connected + 未連接 + + + Connecting + 正在連接 + + + Connected but no Internet access + 已連接網絡但無法訪問互聯網 + + + Connection failed + 連接失敗 + + + IP conflict + IP位址衝突 + + + Disable wired connection + 關閉有線網絡 + + + Enable wired connection + 啟用有線網絡 + + + Disable wireless connection + 關閉無線網絡 + + + Enable wireless connection + 啟用無線網絡 + + + Disable network + 關閉網絡 + + + Enable network + 啟用網絡 + + + Network settings + 網絡設定 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_TW.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_TW.ts new file mode 100644 index 000000000..f02e3d4d6 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_TW.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + 無線網路 + + + Wired Network + 有線網路 + + + + NetworkPlugin + + Network + 網路 + + + Wireless Network + 無線網路 + + + Wired Network + 有線網路 + + + Connected + 已連接 + + + Device disabled + 裝置已禁用 + + + Network cable unplugged + 未插入網路線 + + + Not connected + 未連接 + + + Connecting + 正在連線 + + + Obtaining address + 獲取地址中 + + + Connected but no Internet access + 已連接網路但無法訪問網路 + + + IP conflict + IP位址衝突 + + + Connection failed + 連線失敗 + + + + WirelessItem + + Connect to hidden network + 連接到隱藏網路 + + + Password + 請輸入密碼 + + + Cancel + button + 取 消 + + + Connect + button + 連 接 + + + Name (SSID) + 請輸入網路名稱(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 熱點 + + + SSID + SSID + + + Protocol + 協議 + + + Security Type + 安全類型 + + + Band + 頻段 + + + Channel + 網路通道 + + + Interface + 介面 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 子網掩碼 + + + Gateway + 網關 + + + Primary DNS + 首選DNS + + + IPv6 + IPv6 + + + Prefix + 前綴 + + + Speed + 速率 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 裝置已禁用 + + + Connected but no Internet access + 已連接網路但無法訪問網路 + + + Not connected + 未連接 + + + Network cable unplugged + 未插入網路線 + + + Connecting + 正在連線 + + + Authenticating + 認證中 + + + Obtaining IP address + 正在獲取IP位址 + + + Connected + 已連接 + + + Disconnected + 已斷開 + + + IP conflict + IP位址衝突 + + + Failed + 失敗 + + + Obtaining address + 獲取地址中 + + + + dde::network::NetworkProcesser + + Wired Network + 有線網路 + + + Wired Network %1 + 有線網路%1 + + + Wireless Network + 無線網路 + + + Wireless Network %1 + 無線網路%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 裝置已禁用 + + + Network cable unplugged + 未插入網路線 + + + Not connected + 未連接 + + + Connecting + 正在連線 + + + Connected but no Internet access + 已連接網路但無法訪問網路 + + + Connection failed + 連線失敗 + + + IP conflict + IP位址衝突 + + + Disable wired connection + 關閉有線網路 + + + Enable wired connection + 啟用有線網路 + + + Disable wireless connection + 關閉無線網路 + + + Enable wireless connection + 啟用無線網路 + + + Disable network + 關閉網路 + + + Enable network + 啟用網路 + + + Network settings + 網路設定 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/src/CMakeLists.txt b/panels/dock/tray/plugins/dde-network-core/src/CMakeLists.txt new file mode 100644 index 000000000..1eff7e0fb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/CMakeLists.txt @@ -0,0 +1,68 @@ +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +file(GLOB_RECURSE SOURCEFILES "*.h" "*.cpp") +add_library(${PROJECT_NAME} SHARED ${SOURCEFILES}) + +find_package(Qt6 COMPONENTS Core DBus Network REQUIRED) +find_package(Dtk6 COMPONENTS Core Widget REQUIRED) + +target_include_directories(${PROJECT_NAME} PUBLIC + realize + ${NETINTERFACEINCLUDE} + "../common-plugin/" +) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt6::Core + Qt6::DBus + Qt6::Network + Dtk6::Core + Dtk6::Gui + Dtk6::Widget + KF6::NetworkManagerQt +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION ${CMAKE_PROJECT_VERSION} + SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} +) + +########### static lib for tests ############### +add_library(${PROJECT_NAME}_static STATIC + ${SOURCEFILES} +) +target_link_libraries(${PROJECT_NAME}_static PUBLIC + Qt6::Core + Qt6::DBus + Qt6::Network + Dtk6::Core + Dtk6::Gui + Dtk6::Widget + KF6::NetworkManagerQt +) +target_include_directories(${PROJECT_NAME}_static PUBLIC + "$" +) +set_target_properties(${PROJECT_NAME}_static PROPERTIES POSITION_INDEPENDENT_CODE ON) + +configure_file(dde-network-core.pc.in ../dde-network-core.pc @ONLY) + +set(INTERFACEFILES + dslcontroller.h + hotspotcontroller.h + networkconst.h + networkcontroller.h + networkdetails.h + networkdevicebase.h + proxycontroller.h + vpncontroller.h + wireddevice.h + wirelessdevice.h) + +# install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +# install(FILES ${CMAKE_BINARY_DIR}/dde-network-core.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +# install(FILES ${INTERFACEFILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libddenetworkcore) +# install(FILES ../config/org.deepin.dde.network.json DESTINATION ${CMAKE_INSTALL_DATADIR}/dsg/configs/org.deepin.dde.network) diff --git a/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.cpp b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.cpp new file mode 100644 index 000000000..19984479e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.cpp @@ -0,0 +1,184 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dccdbusinterface.h" +#include "dccdbusinterface_p.h" + +#include +#include +#include +#include +#include +#include +#include + +const QString DBusService = QStringLiteral("org.freedesktop.DBus"); +const QString DBusPath = QStringLiteral("/org/freedesktop/DBus"); +const QString DBusInterface = QStringLiteral("org.freedesktop.DBus"); +const QString NameOwnerChanged = QStringLiteral("NameOwnerChanged"); + +const QString PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +const QString PropertiesChanged = QStringLiteral("PropertiesChanged"); +const static char *PropertyName = "propname"; + +using namespace dde::network; + +DCCDBusInterfacePrivate::DCCDBusInterfacePrivate(DCCDBusInterface *interface, QObject *parent) + : QObject(interface) + , m_parent(parent) + , q_ptr(interface) +{ + QDBusMessage message = QDBusMessage::createMethodCall(DBusService, DBusPath, DBusInterface, "NameHasOwner"); + message << interface->service(); + interface->connection().callWithCallback(message, this, SLOT(onDBusNameHasOwner(bool))); + + QStringList argumentMatch; + argumentMatch << interface->interface(); + interface->connection().connect(interface->service(), interface->path(), PropertiesInterface, PropertiesChanged, argumentMatch, QString(), this, SLOT(onPropertiesChanged(QString, QVariantMap, QStringList))); +} + +QVariant DCCDBusInterfacePrivate::demarshall(const QMetaProperty &metaProperty, const QVariant &value) +{ + if (value.userType() == metaProperty.userType()) + return value; + + QVariant result = QVariant(metaProperty.metaType(), nullptr); + if (value.userType() == qMetaTypeId()) { + QDBusArgument dbusArg = value.value(); + QDBusMetaType::demarshall(dbusArg, metaProperty.metaType(), result.data()); + } + + return result; +} + +QVariant DCCDBusInterfacePrivate::updateProp(const char *propname, const QVariant &value) +{ + QVariant result; + const QMetaObject *metaObj = m_parent->metaObject(); + int i = metaObj->indexOfProperty(propname); + if (i != -1) { + QMetaProperty metaProperty = metaObj->property(i); + result = demarshall(metaProperty, value); + m_propertyMap.insert(propname, result); + QMetaObject::invokeMethod(m_parent, propname + QString("Changed").toLatin1(), Qt::DirectConnection, QGenericArgument(result.typeName(), result.data())); + } else + qInfo() << "invalid property changed:" << propname << value; + + return result; +} + +void DCCDBusInterfacePrivate::initDBusConnection() +{ + Q_Q(DCCDBusInterface); + QDBusConnection connection = q->connection(); + QStringList signalList; + QDBusInterface inter(q->service(), q->path(), q->interface(), connection); + const QMetaObject *meta = inter.metaObject(); + for (int i = meta->methodOffset(); i < meta->methodCount(); ++i) { + const QMetaMethod &method = meta->method(i); + if (method.methodType() == QMetaMethod::Signal) { + signalList << method.methodSignature(); + } + } + const QMetaObject *parentMeta = m_parent->metaObject(); + for (const QString &signal : signalList) { + int i = parentMeta->indexOfSignal(QMetaObject::normalizedSignature(signal.toLatin1())); + if (i != -1) { + const QMetaMethod &parentMethod = parentMeta->method(i); + connection.connect(q->service(), q->path(), q->interface(), parentMethod.name(), m_parent, QT_STRINGIFY(QSIGNAL_CODE) + parentMethod.methodSignature()); + } + } +} + +void DCCDBusInterfacePrivate::onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties) +{ + Q_UNUSED(interfaceName) + Q_UNUSED(invalidatedProperties) + for (QVariantMap::const_iterator it = changedProperties.cbegin(); it != changedProperties.cend(); ++it) + updateProp((it.key() + m_suffix).toLatin1(), it.value()); +} + +void DCCDBusInterfacePrivate::onAsyncPropertyFinished(QDBusPendingCallWatcher *w) +{ + QDBusPendingReply reply = *w; + if (!reply.isError()) { + updateProp(w->property(PropertyName).toString().toLatin1(), reply.value()); + } + w->deleteLater(); +} + +void DCCDBusInterfacePrivate::onDBusNameHasOwner(bool valid) +{ + Q_Q(DCCDBusInterface); + if (valid) + initDBusConnection(); + else + q->connection().connect(DBusService, DBusPath, DBusInterface, NameOwnerChanged, this, SLOT(onDBusNameOwnerChanged(QString, QString, QString))); +} + +void DCCDBusInterfacePrivate::onDBusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOWner) +{ + Q_Q(DCCDBusInterface); + if (name == q->service() && oldOwner.isEmpty()) { + initDBusConnection(); + q->connection().disconnect(DBusService, DBusPath, DBusInterface, NameOwnerChanged, this, SLOT(onDBusNameOwnerChanged(QString, QString, QString))); + } +} +////////////////////////////////////////////////////////// +DCCDBusInterface::DCCDBusInterface(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, interface.toLatin1(), connection, parent) + , d_ptr(new DCCDBusInterfacePrivate(this, parent)) +{ +} + +DCCDBusInterface::~DCCDBusInterface() +{ +} + +QString DCCDBusInterface::suffix() const +{ + Q_D(const DCCDBusInterface); + return d->m_suffix; +} + +void DCCDBusInterface::setSuffix(const QString &suffix) +{ + Q_D(DCCDBusInterface); + d->m_suffix = suffix; +} + +inline QString originalPropname(const char *propname, QString suffix) +{ + QString propStr(propname); + return propStr.left(propStr.length() - suffix.length()); +} + +QVariant DCCDBusInterface::property(const char *propname) +{ + Q_D(DCCDBusInterface); + if (d->m_propertyMap.contains(propname)) + return d->m_propertyMap.value(propname); + + QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), PropertiesInterface, QStringLiteral("Get")); + msg << interface() << originalPropname(propname, d->m_suffix); + QDBusPendingReply prop = connection().asyncCall(msg); + if (prop.value().isValid()) + return d->updateProp(propname, prop.value()); + + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(prop, this); + watcher->setProperty(PropertyName, propname); + connect(watcher, &QDBusPendingCallWatcher::finished, d, &DCCDBusInterfacePrivate::onAsyncPropertyFinished); + if (d->m_propertyMap.contains(propname)) + return d->m_propertyMap.value(propname); + + return QVariant(); +} + +void DCCDBusInterface::setProperty(const char *propname, const QVariant &value) +{ + Q_D(const DCCDBusInterface); + QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), PropertiesInterface, QStringLiteral("Set")); + msg << interface() << originalPropname(propname, d->m_suffix) << value; + connection().asyncCall(msg); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.h b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.h new file mode 100644 index 000000000..9087903b5 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCCDBUSINTERFACE_H +#define DCCDBUSINTERFACE_H + +#include + +namespace dde { +namespace network { + +class DCCDBusInterfacePrivate; + +class DCCDBusInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + explicit DCCDBusInterface(const QString &service, const QString &path, const QString &interface = QString(), + const QDBusConnection &connection = QDBusConnection::sessionBus(), QObject *parent = nullptr); + virtual ~DCCDBusInterface() override; + + QString suffix() const; + void setSuffix(const QString &suffix); + + QVariant property(const char *propname); + void setProperty(const char *propname, const QVariant &value); + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(DCCDBusInterface) + Q_DISABLE_COPY(DCCDBusInterface) +}; + +} +} + +#endif // DCCDBUSINTERFACE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface_p.h b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface_p.h new file mode 100644 index 000000000..842b83aff --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface_p.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later +#ifndef DCCDBUSINTERFACE_P_H +#define DCCDBUSINTERFACE_P_H + +#include "dccdbusinterface.h" + +class QDBusPendingCallWatcher; + +namespace dde { +namespace network { + +class DCCDBusInterfacePrivate : public QObject +{ + Q_OBJECT + +public: + explicit DCCDBusInterfacePrivate(DCCDBusInterface *interface, QObject *parent); + QVariant demarshall(const QMetaProperty &metaProperty, const QVariant &value); + QVariant updateProp(const char *propname, const QVariant &value); + void initDBusConnection(); + +private Q_SLOTS: + void onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties); + void onAsyncPropertyFinished(QDBusPendingCallWatcher *w); + void onDBusNameHasOwner(bool valid); + void onDBusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOWner); + +public: + QObject *m_parent; + QString m_suffix; + QVariantMap m_propertyMap; + + DCCDBusInterface *q_ptr; + Q_DECLARE_PUBLIC(DCCDBusInterface) +}; + +} +} + +#endif // DCCDBUSINTERFACE_P_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/dde-network-core.pc.in b/panels/dock/tray/plugins/dde-network-core/src/dde-network-core.pc.in new file mode 100644 index 000000000..0020bb661 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dde-network-core.pc.in @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/libddenetworkcore + +Name: libddenetworkcore +Description: networkcore interface +Version: @VERSION@ +Libs: -L${libdir} -ldde-network-core +Cflags: -I${includedir} diff --git a/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.cpp new file mode 100644 index 000000000..98db6da12 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.cpp @@ -0,0 +1,178 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dslcontroller.h" +#include "networkdevicebase.h" +#include "networkdbusproxy.h" + +#include + +#include + +using namespace dde::network; +using namespace NetworkManager; + +DSLController::DSLController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) +{ + Q_ASSERT(m_networkInter); +} + +DSLController::~DSLController() +{ +} + +void DSLController::connectItem(DSLItem *item) +{ + // 查找该连接对应的设备的path + QString devicePath = "/"; + if (m_deviceInfo.contains(item->connection()->hwAddress())) + devicePath = m_deviceInfo[item->connection()->hwAddress()]; + + m_networkInter->ActivateConnection(item->connection()->uuid(), QDBusObjectPath(devicePath)); +} + +void DSLController::connectItem(const QString &uuid) +{ + // 根据UUID查找对应的DSL项,然后连接 + for (DSLItem *item : m_items) { + if (item->connection()->uuid() == uuid) { + connectItem(item); + break; + } + } +} + +void DSLController::disconnectItem() +{ + if (!m_activePath.isEmpty()) + deactivateConnection(m_activePath); +} + +void DSLController::updateDevice(const QList &devices) +{ + m_deviceInfo.clear(); + for (NetworkDeviceBase *device : devices) + m_deviceInfo[device->realHwAdr()] = device->path(); +} + +void DSLController::updateDSLItems(const QJsonArray &dsljson) +{ + // 更新DSL具体项的数据,先从列表中查找是否存在当前连接的path,如果找到,就直接更新, + // 没有找到的情况下就新建一个连接,并且将新连接添加到新列表中 + QStringList paths; + QList newItems, changeItems; + for (QJsonValue value : dsljson) { + QJsonObject dsl = value.toObject(); + QString path = dsl.value("Path").toString(); + DSLItem *item = findItem(path); + if (!item) { + item = new DSLItem; + m_items << item; + newItems << item; + } else { + if (item->connection()->id() != dsl.value("Id").toString()) + changeItems << item; + } + + item->setConnection(dsl); + paths << path; + } + + // 如果ID发生变化的数量大于0,则向外抛出连接变化的信号 + if (changeItems.size()) + Q_EMIT itemChanged(changeItems); + + // 如果新连接列表的数量大于0,则向外抛出连接新增的信号 + if (newItems.size() > 0) + Q_EMIT itemAdded(newItems); + + QList rmItems; + for (DSLItem *item : m_items) { + if (!paths.contains(item->connection()->path())) + rmItems << item; + } + + for (DSLItem *item : rmItems) + m_items.removeOne(item); + + // 如果有连接移除,则向外抛出连接移除的信号 + if (rmItems.size() > 0) + Q_EMIT itemRemoved(rmItems); + + for (DSLItem *item : rmItems) + delete item; +} + +void DSLController::updateActiveConnections(const QJsonObject &connectionJson) +{ + // 先保存所有的连接状态 + QMap allConnectionStatus; + // 恢复所有的状态为未连接 + for (DSLItem *item : m_items) { + allConnectionStatus[item->connection()->uuid()] = item->status(); + item->setConnectionStatus(ConnectionStatus::Deactivated); + } + + m_activePath.clear(); + bool statusChanged = false; + // 找到对应的连接,将其修改成连接成功 + QStringList keys = connectionJson.keys(); + for (int i = 0; i < keys.size(); i++) { + QString key = keys[i]; + QJsonObject json = connectionJson.value(key).toObject(); + QString uuid = json.value("Uuid").toString(); + DSLItem *dslItem = findDSLItemByUuid(uuid); + if (dslItem) { + ConnectionStatus state = convertConnectionStatus(json.value("State").toInt()); + dslItem->setConnectionStatus(state); + if (state == ConnectionStatus::Activated) + m_activePath = key; + if (allConnectionStatus.contains(uuid)) { + ConnectionStatus oldStatus = allConnectionStatus[uuid]; + if (!statusChanged && oldStatus != state) + statusChanged = true; + } + } + } + + if (statusChanged) + Q_EMIT activeConnectionChanged(); +} + +DSLItem *DSLController::findItem(const QString &path) +{ + for (DSLItem *item : m_items) { + if (item->connection()->path() == path) + return item; + } + + return Q_NULLPTR; +} + +DSLItem *DSLController::findDSLItemByUuid(const QString &uuid) +{ + // 根据uuid在列表中查询指定的dsl连接 + for (DSLItem *item : m_items) { + if (item->connection()->uuid() == uuid) + return item; + } + + return Q_NULLPTR; +} + +/** + * @brief UDSLItem::connection + * @return + */ +DSLItem::DSLItem() + : ControllItems() +{ +} + +DSLItem::~DSLItem() +{ +} + diff --git a/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.h b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.h new file mode 100644 index 000000000..14ad52b46 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.h @@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DSLCONTROLLER_H +#define DSLCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include +#include + +namespace dde { + +namespace network { + +class DSLItem; +class NetworkDeviceBase; +class NetworkDBusProxy; + +class DSLController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + void connectItem(DSLItem *item); // 连接到当前的DSL + void connectItem(const QString &uuid); // 根据UUID连接当前DSL + void disconnectItem(); // 断开连接 + inline QList items() const { return m_items; } // 返回所有的DSL列表 + +Q_SIGNALS: + void itemAdded(const QList &); // 新增DSL项目 + void itemRemoved(const QList &); // 移除DSL项目 + void itemChanged(const QList &); // 项目发生变化(一般是ID发生了变化) + void activeConnectionChanged(); // 连接状态发生变化 + +protected: + explicit DSLController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~DSLController(); + + void updateDevice(const QList &devices); + void updateDSLItems(const QJsonArray &dsljson); + void updateActiveConnections(const QJsonObject &connectionJson); // 更新DSL的活动连接信息 + +private: + DSLItem *findItem(const QString &path); + DSLItem *findDSLItemByUuid(const QString &uuid); + +private: + QList m_items; + NetworkDBusProxy *m_networkInter; + QMap m_deviceInfo; + QString m_activePath; +}; + +class DSLItem : public ControllItems +{ + friend class DSLController; + +protected: + DSLItem(); + ~DSLItem(); +}; + +} + +} + +#endif // UDSLCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.cpp new file mode 100644 index 000000000..333b01f2d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.cpp @@ -0,0 +1,351 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "hotspotcontroller.h" +#include "wirelessdevice.h" +#include "networkdbusproxy.h" + +#include +#include +#include + +#include + +using namespace dde::network; +using namespace NetworkManager; + +HotspotController::HotspotController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) +{ + Q_ASSERT(m_networkInter); +} + +HotspotController::~HotspotController() +{ +} + +void HotspotController::setEnabled(WirelessDevice *device, const bool enable) +{ + QList deviceHotsItem = items(device); + if (enable) { + auto getTimeStamp = [](const QString &path) { + NetworkManager::Connection::Ptr connection(new NetworkManager::Connection(path)); + return connection->settings()->timestamp(); + }; + // 在打开热点的时候,默认打开上次打开的热点 + auto lastNode = std::max_element(deviceHotsItem.begin(), deviceHotsItem.end(), [ getTimeStamp ](HotspotItem *item1, HotspotItem *item2) { + return getTimeStamp(item1->connection()->path()) < getTimeStamp(item2->connection()->path()); + }); + if (lastNode != deviceHotsItem.end()) + m_networkInter->ActivateConnection((*lastNode)->connection()->uuid(), QDBusObjectPath(device->path())); + } else { + // 在关闭热点的时候,找到当前已经连接的热点,并断开它的连接 + disconnectItem(device); + } +} + +bool HotspotController::enabled(WirelessDevice *device) +{ + return device->hotspotEnabled(); +} + +bool HotspotController::supportHotspot() +{ + return m_devices.size() > 0; +} + +void HotspotController::connectItem(HotspotItem *item) +{ + // 获取当前连接的UUID和设备的path + m_networkInter->ActivateConnection(item->connection()->uuid(), QDBusObjectPath(item->devicePath())); +} + +void HotspotController::connectItem(WirelessDevice *device, const QString &uuid) +{ + for (HotspotItem *item : m_hotspotItems) { + if (item->device() == device && item->connection()->uuid() == uuid) { + connectItem(item); + break; + } + } +} + +void HotspotController::disconnectItem(WirelessDevice *device) +{ + QList deviceHotspotsItem = items(device); + for (HotspotItem *item : deviceHotspotsItem) { + if (item->status() == ConnectionStatus::Activated && + !item->activeConnection().isEmpty()) { + deactivateConnection(item->activeConnection()); + } + } +} + +QList HotspotController::items(WirelessDevice *device) +{ + // 获取当前设备对应的所有的热点 + QList items; + for (HotspotItem *item : m_hotspotItems) { + if (item->device() == device) + items << item; + } + + return items; +} + +QList HotspotController::devices() +{ + return m_devices; +} + +HotspotItem *HotspotController::findItem(WirelessDevice *device, const QJsonObject &json) +{ + // 从列表中查找指定UUID的连接 + for (HotspotItem *item : m_hotspotItems) { + if (item->device() == device + && item->connection()->uuid() == json.value("Uuid").toString()) + return item; + } + + return Q_NULLPTR; +} + +bool HotspotController::isHotspotConnection(const QString &uuid) +{ + for (HotspotItem *item : m_hotspotItems) { + if (item->connection()->uuid() == uuid) + return true; + } + + return false; +} + +void HotspotController::updateActiveConnection(const QJsonObject &activeConnections) +{ + QList activeDevices; + // 先保存所有的连接状态 + QMap allConnectionStatus; + for (HotspotItem *item : m_hotspotItems) { + allConnectionStatus[item->connection()->uuid()] = item->status(); + item->setConnectionStatus(ConnectionStatus::Deactivated); + item->setActiveConnection(""); + } + + // 在这里记录一个标记,用来表示是否发送活动连接发生变化的信号, + // 因为这个连接更新后,紧接着会调用获取活动连接信息的信号,响应这个信号会调用下面的updateActiveConnectionInfo函数 + bool activeConnChanged = false; + + QStringList keys = activeConnections.keys(); + for (int i = 0; i < keys.size(); i++) { + QString path = keys[i]; + QJsonObject activeConnection = activeConnections.value(path).toObject(); + + QString uuid = activeConnection.value("Uuid").toString(); + + if (!isHotspotConnection(uuid)) + continue; + + ConnectionStatus state = convertConnectionStatus(activeConnection.value("State").toInt()); + + QJsonArray devicePaths = activeConnection.value("Devices").toArray(); + for (const QJsonValue jsonValue : devicePaths) { + QString devicePath = jsonValue.toString(); + WirelessDevice *device = findDevice(devicePath); + HotspotItem *hotspotItem = findItem(device, activeConnection); + if (!hotspotItem) + continue; + + hotspotItem->setConnectionStatus(state); + hotspotItem->setActiveConnection(path); + if (!allConnectionStatus.contains(uuid)) + continue; + + ConnectionStatus oldConnectionStatus = allConnectionStatus[uuid]; + // 上一次热点的连接状态为正在激活,当前连接状态为激活 + // 或者上一次热点的连接状态为正在取消激活,当前连接状态为取消激活,将其判断为最近一次有效的连接 + // 此时去更新热点开关的使能状态 + if ((oldConnectionStatus == ConnectionStatus::Activating && state == ConnectionStatus::Activated) + || (oldConnectionStatus == ConnectionStatus::Deactivating && state == ConnectionStatus::Deactivated)) { + Q_EMIT enableHotspotSwitch(true); + } + + if (oldConnectionStatus != hotspotItem->status()) { + activeConnChanged = true; + if (!activeDevices.contains(device)) + activeDevices << device; + } + } + } + if (activeConnChanged) + Q_EMIT activeConnectionChanged(activeDevices); +} + +WirelessDevice *HotspotController::findDevice(const QString &path) +{ + for (WirelessDevice *device : m_devices) { + if (device->path() == path) + return device; + } + + return Q_NULLPTR; +} + +void HotspotController::updateDevices(const QList &devices) +{ + QList tmpDevices = m_devices; + m_devices.clear(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + if (!device->supportHotspot()) + continue; + + if (!device->isEnabled()) + continue; + + m_devices << static_cast(device); + } + + // 移除不在列表中的热点的数据,防止数据更新不及时访问了野指针 + for (auto it = m_hotspotItems.begin(); it != m_hotspotItems.end();) { + if (!m_devices.contains((*it)->device())) { + delete (*it); + it = m_hotspotItems.erase(it); + } else { + ++it; + } + } + + bool hotspotEnabled = (m_devices.size() > 0); + if ((tmpDevices.size() > 0) != hotspotEnabled) + Q_EMIT enabledChanged(hotspotEnabled); + + // 查找移除的设备 + QList rmDevices; + for (WirelessDevice *device : tmpDevices) { + if (!m_devices.contains(device)) + rmDevices << device; + } + + // 查找新增的设备 + QList newDevices; + for (WirelessDevice *device : m_devices) { + if (!tmpDevices.contains(device)) + newDevices << device; + } + + // 告诉外面有新增的热点设备 + if (newDevices.size() > 0) + Q_EMIT deviceAdded(newDevices); + + // 告诉外面有移除的热点设备 + if (rmDevices.size() > 0) + Q_EMIT deviceRemove(rmDevices); +} + +void HotspotController::updateConnections(const QJsonArray &jsons) +{ + // 筛选出通用的(HwAddress为空)热点和指定HwAddress的热点 + QList commonConnections; + QMap> deviceConnections; + for (QJsonValue jsonValue : jsons) { + QJsonObject json = jsonValue.toObject(); + QString hwAddress = json.value("HwAddress").toString(); + if (hwAddress.isEmpty()) + commonConnections << json; + else + deviceConnections[hwAddress] << json; + } + + // 将所有热点的UUID缓存,用来对比不存在的热点,删除不存在的热点 + QMap> newItems; + QMap> infoChangeItems; + QStringList allHotsItem; + // HwAddress为空的热点适用于所有的设备,HwAddress不为空的热点只适用于指定的设备 + for (WirelessDevice *device : m_devices) { + QList hotspotJsons = commonConnections; + if (deviceConnections.contains(device->realHwAdr())) + hotspotJsons << deviceConnections[device->realHwAdr()]; + + for (QJsonValue value : hotspotJsons) { + QJsonObject json = value.toObject(); + HotspotItem *item = findItem(device, json); + if (!item) { + item = new HotspotItem(device); + m_hotspotItems << item; + newItems[device] << item; + } else { + if (item->connection()->ssid() != json.value("Ssid").toString()) + infoChangeItems[device] << item; + } + + item->setConnection(json); + QString pathName = QString("%1-%2").arg(device->path()).arg(json.value("Path").toString()); + allHotsItem << pathName; + } + } + + // 若现有连接发生变化,则抛出变化的信号 + if (infoChangeItems.size() > 0) + Q_EMIT itemChanged(infoChangeItems); + + // 如果有新增的连接,则发送新增连接的信号 + if (newItems.size() > 0) + Q_EMIT itemAdded(newItems); + + QMap> rmItemsMap; + QList rmItems; + // 删除列表中不存在的设备 + for (HotspotItem *item : m_hotspotItems) { + QString pathKey = QString("%1-%2").arg(item->device()->path()).arg(item->connection()->path()); + if (!allHotsItem.contains(pathKey)) { + rmItemsMap[item->device()] << item; + rmItems << item; + } + } + + // 从原来的列表中移除已经删除的对象 + for (HotspotItem *item : rmItems) + m_hotspotItems.removeOne(item); + + // 如果有删除的连接,向外发送删除的信号 + if (rmItemsMap.size() > 0) + Q_EMIT itemRemoved(rmItemsMap); + + // 清空已经删除的对象 + for (HotspotItem *item : rmItems) + delete item; +} + +/** + * @brief UHotspotItem::UHotspotItem + */ + +HotspotItem::HotspotItem(WirelessDevice *device) + : ControllItems() + , m_device(device) + , m_devicePath(m_device->path()) +{ +} + +HotspotItem::~HotspotItem() +{ +} + +QString HotspotItem::name() const +{ + return connection()->id(); +} + +WirelessDevice *HotspotItem::device() const +{ + return m_device; +} + +QString HotspotItem::devicePath() const +{ + return m_devicePath; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.h b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.h new file mode 100644 index 000000000..2270cc6a7 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.h @@ -0,0 +1,93 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef HOTSPOTCONTROLLER_H +#define HOTSPOTCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include +#include + +namespace dde { + +namespace network { + +class Connection; +class HotspotItem; +class WirelessDevice; +class NetworkDeviceBase; +class NetworkDBusProxy; + +class HotspotController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + void setEnabled(WirelessDevice *device, const bool enable); // 开启还是关闭个人热点 + bool enabled(WirelessDevice *device); // 设备的热点是否可用 + bool supportHotspot(); // 是否支持个人热点 + void connectItem(HotspotItem *item); // 连接到个人热点 + void connectItem(WirelessDevice *device, const QString &uuid); // 连接到个人热点 + void disconnectItem(WirelessDevice *device); // 断开连接 + QList items(WirelessDevice *device); // 返回列表 + QList devices(); // 获取支持热点的设备列表 + +Q_SIGNALS: + void enabledChanged(const bool &); // 热点是否可用发生了变化 + void itemAdded(const QMap> &); // 新增连接的信号 + void itemRemoved(const QMap> &); // 删除连接的信号 + void itemChanged(const QMap> &); // 连接信息改变的信号 + void activeConnectionChanged(const QList &); // 活动连接发生变化 + void deviceAdded(const QList &); // 新增热点设备 + void deviceRemove(const QList &); // 删除热点设备 + void enableHotspotSwitch(const bool &); // 使能热点开关 + +protected: + explicit HotspotController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~HotspotController(); + + void updateDevices(const QList &devices); + void updateConnections(const QJsonArray &jsons); + HotspotItem *findItem(WirelessDevice *device, const QJsonObject &json); + + void updateActiveConnection(const QJsonObject &activeConnections); + + WirelessDevice *findDevice(const QString &path); + bool isHotspotConnection(const QString &uuid); + +private: + QList m_devices; + QList m_hotspotItems; + NetworkDBusProxy *m_networkInter; +}; + +class HotspotItem : public ControllItems +{ + friend class HotspotController; + +public: + QString name() const; // 个人热点名称 + WirelessDevice *device() const; // 当前热点对应的无线设备 + +protected: + HotspotItem(WirelessDevice *device); + ~HotspotItem(); + + QString devicePath() const; // 返回设备的路径 + +private: + WirelessDevice *m_device; + QString m_devicePath; +}; + +} + +} + +#endif // UHOTSPOTCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.cpp b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.cpp new file mode 100644 index 000000000..ba8a9d9ce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.cpp @@ -0,0 +1,307 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "ipconfilctchecker.h" +#include "networkdevicebase.h" +#include "realize/netinterface.h" +#include "networkdbusproxy.h" + +#include +#include +#include +#include +#include + +#include +#include + +const static QString networkService = "org.deepin.dde.Network1"; +const static QString networkPath = "/org/deepin/dde/Network1"; + +using namespace dde::network; + +IPConfilctChecker::IPConfilctChecker(NetworkProcesser *networkProcesser, const bool ipChecked, QObject *parent) + : QObject(parent) + , m_networkInter(new NetworkDBusProxy(this)) + , m_networkProcesser(networkProcesser) + , m_ipNeedCheck(ipChecked) + , m_thread(new QThread(this)) +{ + this->moveToThread(m_thread); + + Q_ASSERT(m_networkProcesser); + connect(m_networkInter, &NetworkDBusProxy::IPConflict, this, &IPConfilctChecker::onIPConfilct); // IP冲突发出的信号 + // 构造所有的设备冲突检测对象 + connect(m_networkProcesser, &NetworkProcesser::deviceAdded, this, &IPConfilctChecker::onDeviceAdded, Qt::QueuedConnection); + m_thread->start(); +} + +IPConfilctChecker::~IPConfilctChecker() +{ +} + +void IPConfilctChecker::release() +{ + m_thread->quit(); + m_thread->wait(); +} + +void IPConfilctChecker::onDeviceAdded(QList devices) +{ + for (NetworkDeviceBase *device : devices) { + DeviceIPChecker *ipChecker = new DeviceIPChecker(device, m_networkInter, this); + connect(ipChecker, &DeviceIPChecker::conflictStatusChanged, this, &IPConfilctChecker::conflictStatusChanged); + if (m_ipNeedCheck) + connect(ipChecker, &DeviceIPChecker::ipConflictCheck, this, &IPConfilctChecker::onSenderIPInfo); + m_deviceCheckers << ipChecker; + } +} + +void IPConfilctChecker::clearUnExistDevice() +{ + QList devices = m_networkProcesser->devices(); + for (DeviceIPChecker *ipChecker : m_deviceCheckers) { + if (!devices.contains(ipChecker->device())) { + m_deviceCheckers.removeOne(ipChecker); + delete ipChecker; + } + } +} + +void IPConfilctChecker::onIPConfilct(const QString &ip, const QString &macAddress) +{ + // 此处通过调用后台获取IP地址,如果直接使用当前网络库中设备的IP地址,就有如下问题 + // 如果是在控制中心修改手动IP的话,从当前库中获取到的IP地址就不是最新的地址,因此此处需要从后台获取实时IP + QString activeConnectionInfo =m_networkInter->GetActiveConnectionInfo(); + handlerIpConflict(ip, macAddress, activeConnectionInfo); +} + +void IPConfilctChecker::onSenderIPInfo(const QStringList &ips) +{ + for (const QString &ip : ips) { + m_networkInter->RequestIPConflictCheck(ip, ""); + QThread::msleep(500); + } +} + +void IPConfilctChecker::handlerIpConflict(const QString &ip, const QString &macAddress, const QString &activeConnectionInfo) +{ + QMap deviceIps = parseDeviceIp(activeConnectionInfo); + NetworkDeviceBase *conflictDevice = Q_NULLPTR; + if (deviceIps.contains(ip)) + conflictDevice = deviceIps[ip]; + else { + // 可能是修改前的ip,从现存的checker里找是否有存在的,并更新ip。 + for (DeviceIPChecker *checker : m_deviceCheckers) { + if (checker->ipV4().contains(ip)) { + QStringList ips; + for (auto it = deviceIps.begin(); it != deviceIps.end(); it++) { + if (it.value() == checker->device()) + ips << it.key(); + } + + if (ips.isEmpty()) { + // 已经没有checker 对应的device 了,应该销毁这个checker + m_deviceCheckers.removeOne(checker); + if (checker->ipConflicted()) { + conflictStatusChanged(checker->device(), false); + } + checker->deleteLater(); + } else { + checker->setDeviceInfo(ips, macAddress); + checker->handlerIpConflict(); + } + } + } + return; + } + + // 如果不是本机IP,不做任何处理 + if (!conflictDevice) { + return; + } + + // 先从列表中查找对应的设备检测对象 + DeviceIPChecker *ipChecker = Q_NULLPTR; + for (DeviceIPChecker *checker : m_deviceCheckers) { + if (checker->device() == conflictDevice) { + ipChecker = checker; + break; + } + } + + if (!ipChecker) { + ipChecker = new DeviceIPChecker(conflictDevice, m_networkInter, this); + connect(ipChecker, &DeviceIPChecker::conflictStatusChanged, this, &IPConfilctChecker::conflictStatusChanged); + if (m_ipNeedCheck) + connect(ipChecker, &DeviceIPChecker::ipConflictCheck, this, &IPConfilctChecker::onSenderIPInfo); + m_deviceCheckers << ipChecker; + } + + QStringList ips; + for (auto it = deviceIps.begin(); it != deviceIps.end(); it++) { + if (it.value() == conflictDevice) + ips << it.key(); + } + + ipChecker->setDeviceInfo(ips, macAddress); + ipChecker->handlerIpConflict(); +} + +QMap IPConfilctChecker::parseDeviceIp(const QString &activeConnectionInfo) +{ + QMap tmpDevicePath; + QList devices = m_networkProcesser->devices(); + for (NetworkDeviceBase *device : devices) + tmpDevicePath[device->path()] = device; + + QJsonParseError error; + QJsonDocument json = QJsonDocument::fromJson(activeConnectionInfo.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) + return QMap(); + + QMap deviceIp; + const QJsonArray &infoArray = json.array(); + for (const QJsonValue &infoValue : infoArray) { + QJsonObject info = infoValue.toObject(); + if (!info.contains("IPv4") && !info.contains("Ip4")) + continue; + + const QString devicePath = info.value("Device").toString(); + if (!tmpDevicePath.contains(devicePath)) + continue; + + NetworkDeviceBase *device = tmpDevicePath[devicePath]; + + if (info.contains("IPv4")) { + QJsonObject ipv4TopObject = info.value("IPv4").toObject(); + QJsonArray ipv4Addresses = ipv4TopObject.value("Addresses").toArray(); + for (const QJsonValue addr : ipv4Addresses) { + const QJsonObject addrObject = addr.toObject(); + QString ipAddr = addrObject.value("Address").toString(); + ipAddr = ipAddr.remove("\""); + deviceIp[ipAddr] = device; + } + } else { + QJsonValue ipv4Info = info.value("Ip4"); + QJsonObject ipv4Object = ipv4Info.toObject(); + const QString ipv4 = ipv4Object.value("Address").toString(); + if (ipv4.isEmpty()) + continue; + + deviceIp[ipv4] = device; + } + } + + return deviceIp; +} + +/** + * @brief 构造函数 + * @param device 对应的设备 + * @param netInter + * @param parent + */ +DeviceIPChecker::DeviceIPChecker(NetworkDeviceBase *device, NetworkDBusProxy *netInter, QObject *parent) + : QObject(parent) + , m_device(device) + , m_networkInter(netInter) + , m_conflictCount(0) + , m_clearCount(0) + , m_count(0) + , m_ipConflicted(false) +{ + auto requestConflictCheck = [ this ] () { + // 当设备的IP地址发生变化的时候,请求IP冲突, 只有在上一次请求和该次请求发生的时间大于2秒,才发出信号 + m_ipV4 = m_device->ipv4(); + if (!m_ipV4.isEmpty()) { + m_changeIpv4s << m_ipV4; + QTimer::singleShot(800, this, [ this ] { + if (m_changeIpv4s.size() > 0) { + emit ipConflictCheck(m_changeIpv4s[m_changeIpv4s.size() - 1]); + m_changeIpv4s.clear(); + } + }); + } + }; + connect(device, &NetworkDeviceBase::ipV4Changed, this, requestConflictCheck); + connect(device, &NetworkDeviceBase::enableChanged, this, requestConflictCheck); + + QTimer *timer = new QTimer(this); + + connect(timer, &QTimer::timeout, this, [this] () { + if (m_ipConflicted) { + // 如果确定是有冲突,则冷却至少5秒检测一次,直到冲突解除。 + emit ipConflictCheck(m_ipV4); + } else { + // 如果无冲突, 则冷却至少180秒检测一次。 + if ((m_count++ % 36) == 0) { + emit ipConflictCheck(m_ipV4); + } + } + }); + timer->start(5000); +} + +DeviceIPChecker::~DeviceIPChecker() +{ +} + +NetworkDeviceBase *DeviceIPChecker::device() +{ + return m_device; +} + +void DeviceIPChecker::setDeviceInfo(const QStringList &ipv4, const QString &macAddress) +{ + m_ipV4 = ipv4; + m_macAddress = macAddress; +} + +void DeviceIPChecker::handlerIpConflict() +{ + if (m_macAddress.isEmpty()) { + m_conflictCount = 0; + // 如果MAC地址为空,则表示IP冲突已经解决,则让每个网卡恢复之前的状态 + if (m_clearCount < 3 && m_ipConflicted) { + emit ipConflictCheck(m_ipV4); + } else { + // 拿到最后一次设备冲突的状态 + bool lastConfilctStatus = m_ipConflicted; + m_ipConflicted = false; + + // IP冲突状态发生变化的时候才会发送该信号 + if (lastConfilctStatus) + Q_EMIT conflictStatusChanged(m_device, false); + } + m_clearCount++; + } else { + m_clearCount = 0; + + // 如果少于两次,则继续确认 + if (m_conflictCount < 1 && !m_ipConflicted) { + emit ipConflictCheck(m_ipV4); + } else { + // 如果大于3次,则认为当前IP冲突了 + // 拿到最后一次设备冲突的状态 + bool lastConflictStatus = m_ipConflicted; + m_ipConflicted = true; + + // 最后一次IP不冲突,本次IP冲突的时候才发送设备状态变化的信号 + if (!lastConflictStatus) + Q_EMIT conflictStatusChanged(m_device, true); + } + m_conflictCount++; + } +} + +QStringList DeviceIPChecker::ipV4() +{ + return m_ipV4; +} + +bool DeviceIPChecker::ipConflicted() +{ + return m_ipConflicted; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.h b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.h new file mode 100644 index 000000000..e5f7d2351 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.h @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef IPCONFILCTCHECKER_H +#define IPCONFILCTCHECKER_H + +#include +#include "netutils.h" + +#include "networkconst.h" + +class QThread; + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class NetworkProcesser; +class DeviceIPChecker; +class NetworkDBusProxy; + +class IPConfilctChecker : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void conflictStatusChanged(NetworkDeviceBase *, const bool); + +public: + explicit IPConfilctChecker(NetworkProcesser *networkProcesser, const bool ipChecked, QObject *parent = nullptr); + ~IPConfilctChecker(); + + void release(); + +private Q_SLOT: + void onDeviceAdded(QList devices); + void onIPConfilct(const QString &ip, const QString &macAddress); + void onSenderIPInfo(const QStringList &ips); + +private: + void handlerIpConflict(const QString &ip, const QString &macAddress, const QString &activeConnectionInfo); + QMap parseDeviceIp(const QString &activeConnectionInfo); + void clearUnExistDevice(); + +private: + NetworkDBusProxy *m_networkInter; + NetworkProcesser *m_networkProcesser; + QList m_deviceCheckers; + bool m_ipNeedCheck; + QThread *m_thread; +}; + +class DeviceIPChecker : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void conflictStatusChanged(NetworkDeviceBase *, const bool); + void ipConflictCheck(const QStringList &); + +public: + explicit DeviceIPChecker(NetworkDeviceBase *device, NetworkDBusProxy *netInter, QObject *parent); + ~DeviceIPChecker(); + NetworkDeviceBase *device(); + void setDeviceInfo(const QStringList &ipv4, const QString &macAddress); + void handlerIpConflict(); + QStringList ipV4(); + bool ipConflicted(); + +private: + NetworkDeviceBase *m_device; + NetworkDBusProxy *m_networkInter; + QStringList m_ipV4; + QString m_macAddress; + int m_conflictCount; + int m_clearCount; + int m_count; + bool m_ipConflicted; + QList m_changeIpv4s; +}; + +} +} + +#endif // IPCONFILCTCHECKER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/netutils.cpp b/panels/dock/tray/plugins/dde-network-core/src/netutils.cpp new file mode 100644 index 000000000..ad901a352 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/netutils.cpp @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "netutils.h" + +namespace dde { +namespace network { + +Connectivity connectivityValue(uint sourceConnectivity) +{ + switch (sourceConnectivity) { + case 0: return Connectivity::Unknownconnectivity; + case 1: return Connectivity::Noconnectivity; + case 2: return Connectivity::Portal; + case 3: return Connectivity::Limited; + case 4: return Connectivity::Full; + default: break; + } + + return Connectivity::Unknownconnectivity; +} + +DeviceStatus convertDeviceStatus(int sourceDeviceStatus) +{ + switch (sourceDeviceStatus) { + case 0: return DeviceStatus::Unknown; + case 10: return DeviceStatus::Unmanaged; + case 20: return DeviceStatus::Unavailable; + case 30: return DeviceStatus::Disconnected; + case 40: return DeviceStatus::Prepare; + case 50: return DeviceStatus::Config; + case 60: return DeviceStatus::Needauth; + case 70: return DeviceStatus::IpConfig; + case 80: return DeviceStatus::IpCheck; + case 90: return DeviceStatus::Secondaries; + case 100: return DeviceStatus::Activated; + case 110: return DeviceStatus::Deactivation; + case 120: return DeviceStatus::Failed; + default: break; + } + + return DeviceStatus::Unknown; +} + +ConnectionStatus convertConnectionStatus(int sourceConnectionStatus) +{ + switch (sourceConnectionStatus) { + case 0: return ConnectionStatus::Unknown; + case 1: return ConnectionStatus::Activating; + case 2: return ConnectionStatus::Activated; + case 3: return ConnectionStatus::Deactivating; + case 4: return ConnectionStatus::Deactivated; + } + + return ConnectionStatus::Unknown; +} + +} +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/netutils.h b/panels/dock/tray/plugins/dde-network-core/src/netutils.h new file mode 100644 index 000000000..fdf89a300 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/netutils.h @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETUTILS_H +#define NETUTILS_H + +#include "networkconst.h" + +#include + +namespace dde { +namespace network { + +// an alias for numeric zero, no flags set. +#define DEVICE_INTERFACE_FLAG_NONE 0 +// the interface is enabled from the administrative point of view. Corresponds to kernel IFF_UP. +#define DEVICE_INTERFACE_FLAG_UP 0x1 +// the physical link is up. Corresponds to kernel IFF_LOWER_UP. +#define DEVICE_INTERFACE_FLAG_LOWER_UP 0x2 +// the interface has carrier. In most cases this is equal to the value of @NM_DEVICE_INTERFACE_FLAG_LOWER_UP +#define DEVICE_INTERFACE_FLAG_CARRIER 0x10000 + +// wifi6的标记 +#define AP_FLAGS_HE 0x10 + +Connectivity connectivityValue(uint sourceConnectivity); +DeviceStatus convertDeviceStatus(int sourceDeviceStatus); +ConnectionStatus convertConnectionStatus(int sourceConnectionStatus); + +} +} +#endif // UTILS_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkconst.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkconst.cpp new file mode 100644 index 000000000..5b8ea5ad4 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkconst.cpp @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkconst.h" + +namespace dde { + +namespace network { + +Connection::Connection() +{ +} + +Connection::~Connection() +{ +} + +QString Connection::path() +{ + return m_data.value("Path").toString(); +} + +QString Connection::uuid() +{ + return m_data.value("Uuid").toString(); +} + +QString Connection::id() +{ + return m_data.value("Id").toString(); +} + +QString Connection::hwAddress() +{ + return m_data.value("HwAddress").toString(); +} + +QString Connection::clonedAddress() +{ + return m_data.value("ClonedAddress").toString(); +} + +QString Connection::ssid() +{ + return m_data.value("Ssid").toString(); +} + +void Connection::updateConnection(const QJsonObject &data) +{ + m_data = data; +} + +// 连接具体项的基类 +ControllItems::ControllItems() + : m_connection(new Connection) + , m_status(ConnectionStatus::Unknown) +{ +} + +ControllItems::~ControllItems() +{ + delete m_connection; +} + +Connection *ControllItems::connection() const +{ + return m_connection; +} + +QString ControllItems::activeConnection() const +{ + return m_activeConnection; +} + +void ControllItems::setConnection(const QJsonObject &jsonObj) +{ + m_connection->updateConnection(jsonObj); +} + +void ControllItems::setActiveConnection(const QString &activeConnection) +{ + m_activeConnection = activeConnection; +} + +ConnectionStatus ControllItems::status() const +{ + return m_status; +} + +bool ControllItems::connected() const +{ + return (status() == ConnectionStatus::Activated); +} + +void ControllItems::setConnectionStatus(const ConnectionStatus &status) +{ + m_status = status; +} + +} + +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkconst.h b/panels/dock/tray/plugins/dde-network-core/src/networkconst.h new file mode 100644 index 000000000..f35f2c877 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkconst.h @@ -0,0 +1,181 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKCONST_H +#define NETWORKCONST_H + +#include +#include +#include + +namespace dde { + +namespace network { + +/* + * 系统代理类型 + */ +enum class SysProxyType { + Http = 0, // http类型 + Https, // https类型 + Ftp, // ftp类型 + Socks // socks类型 +}; + +/* + * 应用代理类型 + */ +enum class AppProxyType { + Http = 0, // http类型 + Socks4, // sock4类型 + Socks5 // sock5类型 +}; + +/* + * 设备类型 + */ +enum class DeviceType { + Unknown = 0, // 未知设备 + Wired, // 有线网卡 + Wireless // 无线网卡 +}; + +/* + * @brief 设备状态 + */ +enum class DeviceStatus { + Unknown = 0, // 未知状态 + Unmanaged = 10, // 未管理 + Unavailable = 20, // 不可用 + Disconnected = 30, // 断开连接 + Prepare = 40, // 正在准备状态 + Config = 50, // 正在配置连接信息 + Needauth = 60, // 需要认证 + IpConfig = 70, // 正在配置IP + IpCheck = 80, // 正在进行IP检验 + Secondaries = 90, // 设备正在等待第二个在当前设备连接成功之前必须激活的连接(例如VPN) + Activated = 100, // 激活状态,也就是连接成功 + Deactivation = 110, // 断开连接 + Failed = 120, // 连接失败 + IpConfilct = 121 // ip冲突 +}; + +/* + * 连接状态 + */ +enum class Connectivity { + /* 网络连接未知。这意味着连接检查已禁用(例如,在服务器上安装)或尚未运行。 + 图形外壳程序应假定Internet连接可用,并且不显示强制门户窗口。*/ + Unknownconnectivity = 0, + /* 主机未连接到任何网络。没有活动的连接包含默认的Internet路由,因此甚至尝试进行连 + 接检查也没有意义。图形shell应使用此状态来指示网络连接不可用。*/ + Noconnectivity, + /* Internet连接被捕获的入口网关劫持。图形shell可以打开sandboxed web浏览器窗口 + (因为捕获的门户通常会尝试对https连接进行中间人攻击),以便对网关进行身份验证, + 并在浏览器窗口关闭时使用CheckConnectivity()重新触发连接检查。*/ + Portal, + Limited, // 主机已连接到网络,似乎无法访问完整的Internet,但尚未检测到捕获的门户 + Full // 主机已连接到网络,并且似乎能够访问完整的Internet。 +}; + +/*** + * 加载网络的方式 + */ + +enum class ServiceLoadType { + LoadFromInter = 0, // 从后台加载 + LoadFromManager, // 从NetworkManager加载 + LoadFromService // 从后台服务加载(备用) +}; + +/** + * @brief 系统代理配置 + */ +struct SysProxyConfig +{ + SysProxyType type; // 系统代理类型,是一个枚举变量(http,https,ftp,socks) + QString url; // 代理的URL,一般用于自动代理的URL,手动代理的代理值 + uint port; // 代理的端口,一般是手动代理 +}; +/** + * @brief 应用代理配置 + */ +struct AppProxyConfig +{ + AppProxyType type; // 应用代理类型,枚举变量(http,socks4,socks5) + QString ip; // IP地址 + uint port; // 端口 + QString username; // 用户名 + QString password; // 密码 +}; + +enum class ProxyMethod { + Init = -1, // 初始化状态,用来对数据进行初始化 + None = 0, // 没有设置,对应字符串”none”,如果设置成这个,此时是关闭代理 + Auto, // 自动模式,对应字符串”auto” + Manual // 手动模式,对应字符串”manual” +}; + +/** + * @brief 当前网络连接状态 + */ +enum class ConnectionStatus { + Unknown = 0, // 普通状态 + Activating = 1, // 连接中 + Activated = 2, // 连接成功 + Deactivating = 3, // 断开连接中 + Deactivated = 4 // 连接已断开 +}; + +class Connection +{ + friend class ControllItems; + +public: + QString path(); // 对应connections数据中的path + QString uuid(); // 对应connections数据中的uuid + QString id(); // 对应connections数据中的id + QString hwAddress(); // 对应connections数据中的hwAddress + QString clonedAddress(); // 对应connections数据中的clonedAddress + QString ssid(); // 对应connections数据中的Ssid + +protected: + Connection(); + ~Connection(); + void updateConnection(const QJsonObject &data); + +private: + QJsonObject m_data; +}; + +class ControllItems +{ +public: + ControllItems(); + virtual ~ControllItems(); + + Connection *connection() const; + QString activeConnection() const; + + bool connected() const; //网络是否连接成功 + virtual ConnectionStatus status() const; // 当前连接的连接状态 + +protected: + void setConnection(const QJsonObject &jsonObj); + void setActiveConnection(const QString &activeConnection); + virtual void setConnectionStatus(const ConnectionStatus &status); + +private: + Connection *m_connection; + QString m_activeConnection; + ConnectionStatus m_status; +}; + +} + +} +Q_DECLARE_METATYPE(dde::network::ControllItems); +Q_DECLARE_METATYPE(dde::network::ControllItems *); + +#endif // UNETWORKCONST_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.cpp new file mode 100644 index 000000000..0ccaa68d3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.cpp @@ -0,0 +1,116 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dslcontroller.h" +#include "hotspotcontroller.h" +#include "networkcontroller.h" +#include "networkdetails.h" +#include "networkdevicebase.h" +#include "proxycontroller.h" +#include "vpncontroller.h" +#include "wireddevice.h" +#include "wirelessdevice.h" +#include "netutils.h" +#include "realize/networkmanagerprocesser.h" +#include "realize/networkinterprocesser.h" + +using namespace dde::network; + +// 默认是异步方式 +bool NetworkController::m_sync = false; +// 只有任务栏需要检测IP冲突,因此任务栏需要调用相关的接口来检测,其他的应用是不需要检测冲突的 +bool NetworkController::m_checkIpConflicted = false; +// 默认从网络后台检测 +ServiceLoadType NetworkController::m_serviceLoadType = ServiceLoadType::LoadFromInter; + +NetworkController::NetworkController() + : QObject(Q_NULLPTR) + , m_proxyController(Q_NULLPTR) + , m_vpnController(Q_NULLPTR) + , m_dslController(Q_NULLPTR) + , m_hotspotController(Q_NULLPTR) +{ + if (m_serviceLoadType == ServiceLoadType::LoadFromManager) + m_processer = new NetworkManagerProcesser(this); + else + m_processer = new NetworkInterProcesser(m_sync, m_checkIpConflicted, this); + + connect(m_processer, &NetworkProcesser::deviceAdded, this, &NetworkController::deviceAdded); + connect(m_processer, &NetworkProcesser::deviceRemoved, this, &NetworkController::deviceRemoved); + connect(m_processer, &NetworkProcesser::connectivityChanged, this, &NetworkController::connectivityChanged); + connect(m_processer, &NetworkProcesser::connectionChanged, this, &NetworkController::connectionChanged); + connect(m_processer, &NetworkProcesser::activeConnectionChange, this, &NetworkController::activeConnectionChange); +} + +NetworkController::~NetworkController() +{ +} + +NetworkController *NetworkController::instance() +{ + static NetworkController instance; + return &instance; +} + +void NetworkController::setActiveSync(const bool sync) +{ + m_sync = sync; +} + +void NetworkController::setServiceType(const ServiceLoadType serviceType) +{ + m_serviceLoadType = serviceType; +} + +void NetworkController::setIPConflictCheck(const bool &checkIp) +{ + m_checkIpConflicted = checkIp; +} + +void NetworkController::updateSync(const bool sync) +{ + NetworkInterProcesser *processer = qobject_cast(m_processer); + if (processer) + processer->updateSync(sync); +} + +ProxyController *NetworkController::proxyController() +{ + return m_processer->proxyController(); +} + +VPNController *NetworkController::vpnController() +{ + return m_processer->vpnController(); +} + +DSLController *NetworkController::dslController() +{ + return m_processer->dslController(); +} + +HotspotController *NetworkController::hotspotController() +{ + return m_processer->hotspotController(); +} + +QList NetworkController::networkDetails() +{ + return m_processer->networkDetails(); +} + +QList NetworkController::devices() const +{ + return m_processer->devices(); +} + +Connectivity NetworkController::connectivity() +{ + return m_processer->connectivity(); +} + +void NetworkController::retranslate() +{ + m_processer->retranslate(); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.h b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.h new file mode 100644 index 000000000..0b2077932 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.h @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKCONTROLLER_H +#define NETWORKCONTROLLER_H + +#include "networkconst.h" + +#include + +namespace dde { + +namespace network { + +class ProxyController; +class VPNController; +class DSLController; +class HotspotController; +class NetworkDetails; +class NetworkDeviceBase; +class NetworkProcesser; + +enum InterfaceFlags { + NM_DEVICE_INTERFACE_FLAG_NONE = 0, // an alias for numeric zero, no flags set. + NM_DEVICE_INTERFACE_FLAG_UP = 0x1, // the interface is enabled from the administrative point of view. Corresponds to kernel IFF_UP. + NM_DEVICE_INTERFACE_FLAG_LOWER_UP = 0x2, // the physical link is up. Corresponds to kernel IFF_LOWER_UP. + NM_DEVICE_INTERFACE_FLAG_CARRIER = 0x10000, // the interface has carrier. In most cases this is equal to the value of @NM_DEVICE_INTERFACE_FLAG_LOWER_UP +}; + +class NetworkController : public QObject +{ + Q_OBJECT + +public: + static NetworkController *instance(); // 对外返回的单例 + static void setActiveSync(const bool sync = false); // 设置QDbus服务通讯的方式 ,true表示同步获取,false表示异步获取 + static void setServiceType(const ServiceLoadType serviceType); // 是否系统级(用于在登录界面,此时尚未进入用户,无法访问用户接口) + static void setIPConflictCheck(const bool &checkIp); // 设置是否主动检测IP冲突 + void updateSync(const bool sync); // 用于中途更新同步或异步方式 + + ProxyController *proxyController(); // 返回代理控制管理器 + VPNController *vpnController(); // 返回VPN控制器 + DSLController *dslController(); // DSL控制器 + HotspotController *hotspotController(); // 个人热点控制器 + QList networkDetails(); // 网络详情 + QList devices() const; // 当前网络设备列表 + Connectivity connectivity(); // 获取网络连接状态 + void retranslate(); // 更新翻译 + +Q_SIGNALS: + void deviceAdded(QList); // 新增设备发出的信号 + void deviceRemoved(QList); // 移除设备发出的信号 + void connectivityChanged(const Connectivity &) const; // 网络连接状态发生变化的时候发出的信号 + void connectionChanged(); // 连接信息发生变化的时候触发的信号 + void activeConnectionChange(); // 网络数据发生变化 + +protected: + explicit NetworkController(); + ~NetworkController(); + +private: + NetworkProcesser *m_processer; + ProxyController *m_proxyController; + VPNController *m_vpnController; + DSLController *m_dslController; + HotspotController *m_hotspotController; + QList m_networkDetails; + static bool m_sync; + static ServiceLoadType m_serviceLoadType; + static bool m_checkIpConflicted; +}; + +} + +} + +#endif // UNETWORKCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.cpp new file mode 100644 index 000000000..55d67fc52 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.cpp @@ -0,0 +1,255 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkdbusproxy.h" +#include "dccdbusinterface.h" + +#include +#include +#include +#include +#include + +const QString NetworkService = QStringLiteral("org.deepin.dde.Network1"); +const QString NetworkPath = QStringLiteral("/org/deepin/dde/Network1"); +const QString NetworkInterface = QStringLiteral("org.deepin.dde.Network1"); + +const QString ProxyChainsService = QStringLiteral("org.deepin.dde.Network1"); +const QString ProxyChainsPath = QStringLiteral("/org/deepin/dde/Network1/ProxyChains"); +const QString ProxyChainsInterface = QStringLiteral("org.deepin.dde.Network1.ProxyChains"); + +const QString AirplaneModeService = QStringLiteral("org.deepin.dde.AirplaneMode1"); +const QString AirplaneModePath = QStringLiteral("/org/deepin/dde/AirplaneMode1"); +const QString AirplaneModeInterface = QStringLiteral("org.deepin.dde.AirplaneMode1"); + +const QString PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +const QString PropertiesChanged = QStringLiteral("PropertiesChanged"); +using namespace dde::network; + +NetworkDBusProxy::NetworkDBusProxy(QObject *parent) + : QObject(parent) + , m_networkInter(new DCCDBusInterface(NetworkService, NetworkPath, NetworkInterface, QDBusConnection::sessionBus(), this)) + , m_proxyChainsInter(new DCCDBusInterface(ProxyChainsService, ProxyChainsPath, ProxyChainsInterface, QDBusConnection::sessionBus(), this)) + , m_airplaneModeInter(new DCCDBusInterface(AirplaneModeService, AirplaneModePath, AirplaneModeInterface, QDBusConnection::systemBus(), this)) +{ +} + +// networkInter property +QString NetworkDBusProxy::activeConnections() +{ + return qvariant_cast(m_networkInter->property("ActiveConnections")); +} + +QString NetworkDBusProxy::connections() +{ + return qvariant_cast(m_networkInter->property("Connections")); +} + +uint NetworkDBusProxy::connectivity() +{ + return qvariant_cast(m_networkInter->property("Connectivity")); +} + +QString NetworkDBusProxy::devices() +{ + return qvariant_cast(m_networkInter->property("Devices")); +} + +bool NetworkDBusProxy::networkingEnabled() +{ + return qvariant_cast(m_networkInter->property("NetworkingEnabled")); +} +void NetworkDBusProxy::setNetworkingEnabled(bool value) +{ + m_networkInter->setProperty("NetworkingEnabled", QVariant::fromValue(value)); +} + +uint NetworkDBusProxy::state() +{ + return qvariant_cast(m_networkInter->property("State")); +} + +bool NetworkDBusProxy::vpnEnabled() +{ + return qvariant_cast(m_networkInter->property("VpnEnabled")); +} +void NetworkDBusProxy::setVpnEnabled(bool value) +{ + m_networkInter->setProperty("VpnEnabled", QVariant::fromValue(value)); +} + +QString NetworkDBusProxy::wirelessAccessPoints() +{ + return qvariant_cast(m_networkInter->property("WirelessAccessPoints")); +} +// proxyChains property +QString NetworkDBusProxy::iP() +{ + return qvariant_cast(m_proxyChainsInter->property("IP")); +} + +QString NetworkDBusProxy::password() +{ + return qvariant_cast(m_proxyChainsInter->property("Password")); +} + +uint NetworkDBusProxy::port() +{ + return qvariant_cast(m_proxyChainsInter->property("Port")); +} + +QString NetworkDBusProxy::type() +{ + return qvariant_cast(m_proxyChainsInter->property("Type")); +} + +QString NetworkDBusProxy::user() +{ + return qvariant_cast(m_proxyChainsInter->property("User")); +} + +bool NetworkDBusProxy::enabled() +{ + return qvariant_cast(m_airplaneModeInter->property("Enabled")); +} + +void NetworkDBusProxy::ShowPage(const QString &url) +{ + QDBusMessage message = QDBusMessage::createMethodCall("org.deepin.dde.ControlCenter1", "/org/deepin/dde/ControlCenter1", "org.deepin.dde.ControlCenter1", "ShowPage"); + message << QVariant::fromValue(url); + QDBusConnection::sessionBus().asyncCall(message); +} +// networkInter property +void NetworkDBusProxy::EnableDevice(const QDBusObjectPath &devPath, bool enabled) +{ + m_networkInter->asyncCall(QStringLiteral("EnableDevice"), QVariant::fromValue(devPath), QVariant::fromValue(enabled)); +} + +QString NetworkDBusProxy::GetProxyMethod() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetProxyMethod"))); +} + +void NetworkDBusProxy::SetProxyMethod(const QString &proxyMode) +{ + m_networkInter->asyncCall(QStringLiteral("SetProxyMethod"), QVariant::fromValue(proxyMode)); +} + +void NetworkDBusProxy::SetProxyMethod(const QString &proxyMode, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(proxyMode); + m_networkInter->callWithCallback(QStringLiteral("SetProxyMethod"), argumentList, receiver, member); +} + +QString NetworkDBusProxy::GetProxyIgnoreHosts() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetProxyIgnoreHosts"))); +} + +void NetworkDBusProxy::SetProxyIgnoreHosts(const QString &ignoreHosts) +{ + m_networkInter->asyncCall(QStringLiteral("SetProxyIgnoreHosts"), QVariant::fromValue(ignoreHosts)); +} + +void NetworkDBusProxy::SetProxyIgnoreHosts(const QString &ignoreHosts, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(ignoreHosts); + m_networkInter->callWithCallback(QStringLiteral("SetProxyIgnoreHosts"), argumentList, receiver, member); +} + +QString NetworkDBusProxy::GetAutoProxy() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetAutoProxy"))); +} + +void NetworkDBusProxy::SetAutoProxy(const QString &proxyAuto) +{ + m_networkInter->asyncCall(QStringLiteral("SetAutoProxy"), QVariant::fromValue(proxyAuto)); +} + +void NetworkDBusProxy::SetAutoProxy(const QString &proxyAuto, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(proxyAuto); + m_networkInter->callWithCallback(QStringLiteral("SetAutoProxy"), argumentList, receiver, member); +} + +QStringList NetworkDBusProxy::GetProxy(const QString &proxyType) +{ + QStringList out; + QDBusMessage reply = m_networkInter->call(QDBus::Block, QStringLiteral("GetProxy"), QVariant::fromValue(proxyType)); + if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 2) { + out << qdbus_cast(reply.arguments().at(0)); + out << qdbus_cast(reply.arguments().at(1)); + } + return out; +} + +void NetworkDBusProxy::SetProxy(const QString &proxyType, const QString &host, const QString &port) +{ + m_networkInter->asyncCall(QStringLiteral("SetProxy"), QVariant::fromValue(proxyType), QVariant::fromValue(host), QVariant::fromValue(port)); +} + +void NetworkDBusProxy::SetProxy(const QString &proxyType, const QString &host, const QString &port, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(proxyType) << QVariant::fromValue(host) << QVariant::fromValue(port); + m_networkInter->callWithCallback(QStringLiteral("SetProxy"), argumentList, receiver, member); +} + +QString NetworkDBusProxy::GetActiveConnectionInfo() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetActiveConnectionInfo"))); +} + +QDBusObjectPath NetworkDBusProxy::ActivateConnection(const QString &uuid, const QDBusObjectPath &devicePath) +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("ActivateConnection"), QVariant::fromValue(uuid), QVariant::fromValue(devicePath))); +} + +QDBusObjectPath NetworkDBusProxy::ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath) +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("ActivateAccessPoint"), QVariant::fromValue(uuid), QVariant::fromValue(apPath), QVariant::fromValue(devPath))); +} + +bool NetworkDBusProxy::ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath, QObject *receiver, const char *member, const char *errorSlot) +{ + QList argumentList; + argumentList << QVariant::fromValue(uuid) << QVariant::fromValue(apPath) << QVariant::fromValue(devPath); + return m_networkInter->callWithCallback(QStringLiteral("ActivateAccessPoint"), argumentList, receiver, member, errorSlot); +} + +void NetworkDBusProxy::DisconnectDevice(const QDBusObjectPath &devPath) +{ + m_networkInter->asyncCall(QStringLiteral("DisconnectDevice"), QVariant::fromValue(devPath)); +} + +void NetworkDBusProxy::RequestIPConflictCheck(const QString &ip, const QString &ifc) +{ + m_networkInter->asyncCall(QStringLiteral("RequestIPConflictCheck"), QVariant::fromValue(ip), QVariant::fromValue(ifc)); +} + +bool NetworkDBusProxy::IsDeviceEnabled(const QDBusObjectPath &devPath) +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("IsDeviceEnabled"), QVariant::fromValue(devPath))); +} + +void NetworkDBusProxy::RequestWirelessScan() +{ + m_networkInter->asyncCall(QStringLiteral("RequestWirelessScan")); +} + +void NetworkDBusProxy::Set(const QString &type0, const QString &ip, uint port, const QString &user, const QString &password) +{ + m_proxyChainsInter->asyncCall(QStringLiteral("Set"), QVariant::fromValue(type0), QVariant::fromValue(ip), QVariant::fromValue(port), QVariant::fromValue(user), QVariant::fromValue(password)); +} + +uint NetworkDBusProxy::Notify(const QString &in0, uint in1, const QString &in2, const QString &in3, const QString &in4, const QStringList &in5, const QVariantMap &in6, int in7) +{ + QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify"); + message << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2) << QVariant::fromValue(in3) << QVariant::fromValue(in4) << QVariant::fromValue(in5) << QVariant::fromValue(in6) << QVariant::fromValue(in7); + return QDBusPendingReply(QDBusConnection::sessionBus().asyncCall(message)); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.h b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.h new file mode 100644 index 000000000..11af97e9c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.h @@ -0,0 +1,125 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDBUSPROXY_H +#define NETWORKDBUSPROXY_H +#include +#include +class QDBusInterface; +class QDBusMessage; + +namespace dde { +namespace network { + +class DCCDBusInterface; + +class NetworkDBusProxy : public QObject +{ + Q_OBJECT +public: + explicit NetworkDBusProxy(QObject *parent = nullptr); + // networkInter + Q_PROPERTY(QString ActiveConnections READ activeConnections NOTIFY ActiveConnectionsChanged) + QString activeConnections(); + Q_PROPERTY(QString Connections READ connections NOTIFY ConnectionsChanged) + QString connections(); + Q_PROPERTY(uint Connectivity READ connectivity NOTIFY ConnectivityChanged) + uint connectivity(); + Q_PROPERTY(QString Devices READ devices NOTIFY DevicesChanged) + QString devices(); + Q_PROPERTY(bool NetworkingEnabled READ networkingEnabled WRITE setNetworkingEnabled NOTIFY NetworkingEnabledChanged) + bool networkingEnabled(); + void setNetworkingEnabled(bool value); + Q_PROPERTY(uint State READ state NOTIFY StateChanged) + uint state(); + Q_PROPERTY(bool VpnEnabled READ vpnEnabled WRITE setVpnEnabled NOTIFY VpnEnabledChanged) + bool vpnEnabled(); + void setVpnEnabled(bool value); + Q_PROPERTY(QString WirelessAccessPoints READ wirelessAccessPoints NOTIFY WirelessAccessPointsChanged) + QString wirelessAccessPoints(); + // proxyChains + Q_PROPERTY(QString IP READ iP NOTIFY IPChanged) + QString iP(); + Q_PROPERTY(QString Password READ password NOTIFY PasswordChanged) + QString password(); + Q_PROPERTY(uint Port READ port NOTIFY PortChanged) + uint port(); + Q_PROPERTY(QString Type READ type NOTIFY TypeChanged) + QString type(); + Q_PROPERTY(QString User READ user NOTIFY UserChanged) + QString user(); + // airplaneMode + Q_PROPERTY(bool Enabled READ enabled NOTIFY EnabledChanged) + bool enabled(); + + static void ShowPage(const QString &url); + +Q_SIGNALS: // SIGNALS + // networkInter + void AccessPointAdded(const QString &in0, const QString &in1); + void AccessPointPropertiesChanged(const QString &in0, const QString &in1); + void AccessPointRemoved(const QString &in0, const QString &in1); + void ActiveConnectionInfoChanged(); + void DeviceEnabled(const QString &device, bool enabled); + void IPConflict(const QString &in0, const QString &in1); + // begin property changed signals + void ActiveConnectionsChanged(const QString &value) const; + void ConnectionsChanged(const QString &value) const; + void ConnectivityChanged(uint value) const; + void DevicesChanged(const QString &value) const; + void NetworkingEnabledChanged(bool value) const; + void StateChanged(uint value) const; + void VpnEnabledChanged(bool value) const; + void WirelessAccessPointsChanged(const QString &value) const; + // proxyChains + // begin property changed signals + void IPChanged(const QString &value) const; + void PasswordChanged(const QString &value) const; + void PortChanged(uint value) const; + void TypeChanged(const QString &value) const; + void UserChanged(const QString &value) const; + // airplaneMode + // begin property changed signals + void BluetoothEnabledChanged(bool value) const; + void EnabledChanged(bool value) const; + void WifiEnabledChanged(bool value) const; + +public Q_SLOTS: + // networkInter + void EnableDevice(const QDBusObjectPath &devPath, bool enabled); + QString GetProxyMethod(); + void SetProxyMethod(const QString &proxyMode); + void SetProxyMethod(const QString &proxyMode, QObject *receiver, const char *member); + QString GetProxyIgnoreHosts(); + void SetProxyIgnoreHosts(const QString &ignoreHosts); + void SetProxyIgnoreHosts(const QString &ignoreHosts, QObject *receiver, const char *member); + QString GetAutoProxy(); + void SetAutoProxy(const QString &proxyAuto); + void SetAutoProxy(const QString &proxyAuto, QObject *receiver, const char *member); + QStringList GetProxy(const QString &proxyType); // 返回值待处理 + void SetProxy(const QString &proxyType, const QString &host, const QString &port); + void SetProxy(const QString &proxyType, const QString &host, const QString &port, QObject *receiver, const char *member); + QString GetActiveConnectionInfo(); + QDBusObjectPath ActivateConnection(const QString &uuid, const QDBusObjectPath &devicePath); + QDBusObjectPath ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath); + bool ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath, QObject *receiver, const char *member, const char *errorSlot); + void DisconnectDevice(const QDBusObjectPath &devPath); + void RequestIPConflictCheck(const QString &ip, const QString &ifc); + bool IsDeviceEnabled(const QDBusObjectPath &devPath); + void RequestWirelessScan(); + + // proxyChains + void Set(const QString &type0, const QString &ip, uint port, const QString &user, const QString &password); + // Notifications + static uint Notify(const QString &in0, uint in1, const QString &in2, const QString &in3, const QString &in4, const QStringList &in5, const QVariantMap &in6, int in7); + +private: + DCCDBusInterface *m_networkInter; + DCCDBusInterface *m_proxyChainsInter; + DCCDBusInterface *m_airplaneModeInter; +}; + +} +} +#endif // NETWORKDBUSPROXY_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdetails.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.cpp new file mode 100644 index 000000000..387fc5b4a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.cpp @@ -0,0 +1,268 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkdetails.h" +#include "networkdevicebase.h" +#include "wireddevice.h" +#include "wirelessdevice.h" + +#include + +#include +#include +#include +#include + +#include + +using namespace NetworkManager; +using namespace dde::network; + +NetworkDetails::NetworkDetails(QObject *parent) + : QObject(parent) +{ +} + +NetworkDetails::~NetworkDetails() +{ +} + +static const QString compressedIpv6Addr(const QString &ipv6Adr) +{ + if (ipv6Adr.contains("::")) + return ipv6Adr; + + // NOTE(sbw): Calculate longest zero sequence, ensure + int start = 0, len = 0; + int maxStart = 0, maxLen = 0; + const QStringList &sequence = ipv6Adr.split(':'); + for (int i = 0; i != sequence.size(); i++) { + if (sequence[i] == "0000") { + len += 5; + } else { + if (len > maxLen) { + maxStart = start; + maxLen = len; + } + start = (i + 1) * 5; + len = 0; + } + } + + if (maxLen) + return QString(ipv6Adr).replace(maxStart, maxLen, ':'); + + if (len > maxLen) { + if (start) + return QString(ipv6Adr).replace(start, len, ':'); + + return QString("::"); + } + + return ipv6Adr; +} + +QString NetworkDetails::prefixToNetMask(int prefixLength) +{ + uint32_t mask = (0xFFFFFFFF << (32 - prefixLength)) & 0xFFFFFFFF; + uint8_t m1 = mask >> 24; + uint8_t m2 = (mask >> 16) & 0xFF; + uint8_t m3 = (mask >> 8) & 0xFF; + uint8_t m4 = mask & 0xFF; + return QString("%1.%2.%3.%4").arg(m1).arg(m2).arg(m3).arg(m4); +} + +void NetworkDetails::updateData(const QJsonObject &info) +{ + m_items.clear(); + m_name.clear(); + m_devicePath = info.value("Device").toString(); + const QString type = info.value("ConnectionType").toString(); + const bool isHotspot = type == "wireless-hotspot"; + const bool isWireless = type == "wireless"; + QJsonObject hotspotInfo = info.value("Hotspot").toObject(); + if (isHotspot) { + m_name = tr("Hotspot"); + appendInfo(tr("SSID"), hotspotInfo.value("Ssid").toString()); + } else { + m_name = info.value("ConnectionName").toString(); + } + + if (isWireless) { + // 协议 + const QString &protocol = info.value("Protocol").toString(); + if (!protocol.isEmpty()) + appendInfo(tr("Protocol"), protocol); + + // 安全类型 + const QString &securityType = info.value("Security").toString(); + appendInfo(tr("Security Type"), securityType); + + // 网络通道 + const QString &channel = QString::number(hotspotInfo.value("Channel").toInt()); + if (!channel.isEmpty()) + appendInfo(tr("Channel"), channel); + } + if (isWireless || isHotspot) { + // 频段 + const QString &band = hotspotInfo.value("Band").toString(); + QString bandInfo = band == "a" ? "5 GHz" : (band == "bg" ? "2.4 GHz" : "automatic"); + appendInfo(tr("Band"), bandInfo); + } + if (isHotspot) { + const QString securityType = info.value("Security").toString(); + appendInfo(tr("Security Type"), securityType); + } + // 接口 + const auto device = info.value("DeviceInterface").toString(); + if (!device.isEmpty()) + appendInfo(tr("Interface"), device); + // MAC地址 + const QString mac = info.value("HwAddress").toString(); + if (!mac.isEmpty()) + appendInfo(tr("MAC"), mac); + if (!isHotspot) { + // ipv4 + if (info.contains("IPv4")) { + QJsonObject ipv4TopObject = info["IPv4"].toObject(); + QJsonArray ipv4Array = ipv4TopObject.value("Addresses").toArray(); + for (const QJsonValue ipv4Value : ipv4Array) { + const QJsonObject ipv4Object = ipv4Value.toObject(); + QString ip = ipv4Object.value("Address").toString(); + ip = ip.remove("\""); + if(ip != "0.0.0.0"){ + appendInfo(tr("IPv4"), ip); + } + int prefix = ipv4Object.value("Prefix").toInt(); + QString ip4Netmask = prefixToNetMask(prefix); + if (!ip4Netmask.isEmpty()) + appendInfo(tr("Netmask"), ip4Netmask); + } + const QString gateway = ipv4TopObject.value("Gateway").toString(); + if (!gateway.isEmpty()) + appendInfo(tr("Gateway"), gateway); + + const auto ip4PrimaryDns = ipv4TopObject.value("Nameservers").toArray(); + if (!ip4PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), ip4PrimaryDns.first().toString()); + } else { + const auto ipv4 = info.value("Ip4").toObject(); + if (!ipv4.isEmpty()) { + // ipv4 地址 + const auto ip4Addr = ipv4.value("Address").toString(); + if (!ip4Addr.isEmpty() and ip4Addr != "0.0.0.0") { + appendInfo(tr("IPv4"), ip4Addr); + } + // ipv4 子网掩码 + const auto ip4Netmask = ipv4.value("Mask").toString(); + if (!ip4Netmask.isEmpty()) + appendInfo(tr("Netmask"), ip4Netmask); + // ipv4 网关 + const auto gateway = ipv4.value("Gateways").toArray(); + if (!gateway.isEmpty()) + appendInfo(tr("Gateway"), gateway.first().toString()); + // ipv4 首选DNS + const auto ip4PrimaryDns = ipv4.value("Dnses").toArray(); + if (!ip4PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), ip4PrimaryDns.first().toString()); + } + } + // ipv6 + if (info.contains("IPv6")) { + QJsonObject ipv6TopObject = info["IPv6"].toObject(); + QJsonArray ipv6Array = ipv6TopObject.value("Addresses").toArray(); + for (const QJsonValue ipv6Value : ipv6Array) { + const QJsonObject ipv6Object = ipv6Value.toObject(); + QString ip = ipv6Object.value("Address").toString(); + ip = ip.remove("\""); + if(ip != "0::0"){ + appendInfo(tr("IPv6"), ip); + } + QString ip6Prefix = QString::number(ipv6Object.value("Prefix").toInt()); + if (!ip6Prefix.isEmpty()) + appendInfo(tr("Prefix"), ip6Prefix); + } + const QString gateway = ipv6TopObject.value("Gateway").toString(); + if (!gateway.isEmpty()) + appendInfo(tr("Gateway"), gateway); + + const auto ip4PrimaryDns = ipv6TopObject.value("Nameservers").toArray(); + if (!ip4PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), ip4PrimaryDns.first().toString()); + } else { + const auto ipv6 = info.value("Ip6").toObject(); + if (!ipv6.isEmpty()) { + // ipv6地址 + const auto& ipv6Address = ipv6Infomation(info, InfoType::Ip); + if(ipv6Address != "0::0"){ + appendInfo(tr("IPv6"), compressedIpv6Addr(ipv6Address)); + } + // ipv6前缀 + const auto ip6Prefix = QString::number(ipv6.value("Prefix").toInt()); + if (!ip6Prefix.isEmpty()) + appendInfo(tr("Prefix"), ip6Prefix); + // ipv6网关 + appendInfo(tr("Gateway"), compressedIpv6Addr(ipv6Infomation(info, InfoType::Gateway))); + + // ipv6 首选DNS + const auto ip6PrimaryDns = ipv6.value("Dnses").toArray(); + if (!ip6PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), compressedIpv6Addr(ip6PrimaryDns.first().toString())); + } + } + // 速率 + const QString speed = info.value("Speed").toString(); + if (!speed.isEmpty()) + appendInfo(tr("Speed"), speed); + } +} + +void NetworkDetails::appendInfo(const QString &title, const QString &value) +{ + m_items << qMakePair(title, value); +} + +QString NetworkDetails::ipv6Infomation(QJsonObject connectinfo, NetworkDetails::InfoType type) +{ + NetworkManager::Connection::Ptr connection = findConnectionByUuid(connectinfo.value("ConnectionUuid").toString()); + if (connection.isNull()) + return QString(); + + ConnectionSettings::Ptr connectionSettings = connection->settings(); + Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(Setting::Ipv6).staticCast(); + if (ipv6Setting.isNull()) + return QString(); + + QList addressInfos = ipv6Setting->addresses(); + if (ipv6Setting->method() == Ipv6Setting::Manual) { + if (addressInfos.count() == 0) { + qDebug() << "ipv6Setting error! "; + return QString(); + } + + switch (type) { + case Ip: + return addressInfos[0].ip().toString(); + case Gateway: + return addressInfos[0].gateway().toString(); + } + } + + if (ipv6Setting->method() == Ipv6Setting::Automatic || ipv6Setting->method() == Ipv6Setting::LinkLocal) { + const auto ipv6 = connectinfo.value("Ip6").toObject(); + switch (type) { + case Ip: + return ipv6.value("Address").toString(); + case Gateway: + return ipv6.value("Address").toString(); + } + } + + return QString(); +} + +QString NetworkDetails::devicePath() +{ + return m_devicePath; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdetails.h b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.h new file mode 100644 index 000000000..fca1e4625 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.h @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDETAILS_H +#define NETWORKDETAILS_H + +#include + +class QJsonObject; + +namespace dde { + +namespace network { + +class NetworkDeviceBase; + +class NetworkDetails : QObject +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + +private: + enum InfoType { + Ip, + Gateway + }; + +public: + // 连接的网络名称 + inline QString name() { return m_name; } + inline QList> items() { return m_items; } + +private: + NetworkDetails(QObject *parent = Q_NULLPTR); + ~NetworkDetails(); + + void updateData(const QJsonObject &info); + void appendInfo(const QString &title, const QString &value); + QString ipv6Infomation(QJsonObject connectinfo, InfoType type); + QString devicePath(); + + QString prefixToNetMask(int prefixLength); + +private: + QString m_name; + QString m_devicePath; + QList> m_items; +}; + +} + +} + +#endif // UNETWORKDETAILS_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.cpp new file mode 100644 index 000000000..f268bccf3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.cpp @@ -0,0 +1,176 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "realize/netinterface.h" +#include "networkdevicebase.h" +#include "netutils.h" + +using namespace dde::network; + +bool NetworkDeviceBase::IPValid() +{ + // 判读获取IP地址失败需要满足最后一个状态为未连接,上一个状态为失败,并且包含Config和IpConfig + if (m_statusQueue.size() == MaxQueueSize + && m_statusQueue[MaxQueueSize - 1] == DeviceStatus::Disconnected + && m_statusQueue[MaxQueueSize - 2] == DeviceStatus::Failed + && m_statusQueue.contains(DeviceStatus::Config) + && m_statusQueue.contains(DeviceStatus::IpConfig)) { + return false; + } + + return true; +} + +DeviceStatus NetworkDeviceBase::deviceStatus() const +{ + return deviceRealize()->deviceStatus(); +} + +QString NetworkDeviceBase::interface() const +{ + return deviceRealize()->interface(); +} + +QString NetworkDeviceBase::driver() const +{ + return deviceRealize()->driver(); +} + +bool NetworkDeviceBase::managed() const +{ + return deviceRealize()->managed(); +} + +QString NetworkDeviceBase::vendor() const +{ + return deviceRealize()->vendor(); +} + +QString NetworkDeviceBase::uniqueUuid() const +{ + return deviceRealize()->uniqueUuid(); +} + +bool NetworkDeviceBase::usbDevice() const +{ + return deviceRealize()->usbDevice(); +} + +QString NetworkDeviceBase::path() const +{ + return deviceRealize()->path(); +} + +QString NetworkDeviceBase::activeAp() const +{ + return deviceRealize()->activeAp(); +} + +bool NetworkDeviceBase::supportHotspot() const +{ + return deviceRealize()->supportHotspot(); +} + +QString NetworkDeviceBase::realHwAdr() const +{ + return deviceRealize()->realHwAdr(); +} + +QString NetworkDeviceBase::usingHwAdr() const +{ + return deviceRealize()->usingHwAdr(); +} + +QStringList NetworkDeviceBase::ipv4() const +{ + return deviceRealize()->ipv4(); +} + +QStringList NetworkDeviceBase::ipv6() const +{ + return deviceRealize()->ipv6(); +} + +QJsonObject NetworkDeviceBase::activeConnectionInfo() const +{ + return deviceRealize()->activeConnectionInfo(); +} + +void NetworkDeviceBase::setEnabled(bool enabled) +{ + deviceRealize()->setEnabled(enabled); +} + +void NetworkDeviceBase::disconnectNetwork() +{ + deviceRealize()->disconnectNetwork(); +} + +Connectivity NetworkDeviceBase::connectivity() +{ + return deviceRealize()->connectivity(); +} + +void NetworkDeviceBase::setName(const QString &name) +{ + if (m_name != name) { + m_name = name; + Q_EMIT nameChanged(name); + } +} + +QString NetworkDeviceBase::deviceName() +{ + return m_name; +} + +NetworkDeviceBase::NetworkDeviceBase(NetworkDeviceRealize *deviceInter, QObject *parent) + : QObject(parent) + , m_deviceInterface(deviceInter) + , m_enabled(true) +{ + Q_ASSERT(m_deviceInterface); + m_deviceInterface->setDevice(this); + + connect(m_deviceInterface, &NetworkDeviceRealize::deviceStatusChanged, this, &NetworkDeviceBase::deviceStatusChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::enableChanged, this, &NetworkDeviceBase::enableChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::connectionChanged, this, &NetworkDeviceBase::connectionChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::nameChanged, this, &NetworkDeviceBase::nameChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::removed, this, &NetworkDeviceBase::removed); + connect(m_deviceInterface, &NetworkDeviceRealize::activeConnectionChanged, this, &NetworkDeviceBase::activeConnectionChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::ipV4Changed, this, &NetworkDeviceBase::ipV4Changed); +} + +NetworkDeviceBase::~NetworkDeviceBase() +{ + delete m_deviceInterface; +} + +NetworkDeviceRealize *NetworkDeviceBase::deviceRealize() const +{ + return m_deviceInterface; +} + +void NetworkDeviceBase::enqueueStatus(const DeviceStatus &status) +{ + if (m_statusQueue.size() >= MaxQueueSize) + m_statusQueue.dequeue(); + + m_statusQueue.enqueue(status); +} + +QString NetworkDeviceBase::getStatusName() +{ + return deviceRealize()->getStatusName(); +} + +QString NetworkDeviceBase::statusStringDetail() +{ + return deviceRealize()->statusStringDetail(); +} + +bool NetworkDeviceBase::isEnabled() const +{ + return m_deviceInterface->isEnabled(); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.h b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.h new file mode 100644 index 000000000..30d947e55 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.h @@ -0,0 +1,106 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDEVICEBASE_H +#define NETWORKDEVICEBASE_H + +#include "networkconst.h" + +#include +#include + +namespace dde { + +namespace network { + +class NetworkDeviceRealize; + +#define MaxQueueSize 4 + +class NetworkDeviceBase : public QObject +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + friend class IPConfilctChecker; + + Q_PROPERTY(QString statusName READ getStatusName) + Q_PROPERTY(QString statusDetail READ statusStringDetail) // 当前状态详细说明,取代statusStringDetail接口 + Q_PROPERTY(bool enabled READ isEnabled) // 当前网卡是否启用,对应于isEnabled() 接口,向外提供接口的同时,这里也给出属性 + Q_PROPERTY(bool IPValid READ IPValid) // IP是否合法,对应于isIPValid接口 + Q_PROPERTY(QString interface READ interface) // 对应于interface() 接口 + Q_PROPERTY(QString driver READ driver) // 对应于driver()接口 + Q_PROPERTY(bool managed READ managed) // 对应于managed接口 + Q_PROPERTY(QString vendor READ vendor) // 对应于vendor接口 + Q_PROPERTY(QString uniqueUuid READ uniqueUuid) // 对应于uniqueUuid接口 + Q_PROPERTY(bool usbDevice READ usbDevice) // 对应于usbDevice接口 + Q_PROPERTY(QString path READ path) // 对应于path接口 + Q_PROPERTY(QString activeAp READ activeAp) // 对应于ActiveAp接口 + Q_PROPERTY(bool supportHotspot READ supportHotspot) // 对应于supportHotspot接口 + Q_PROPERTY(QString realHwAdr READ realHwAdr) // 对应于realHwAdr接口 + Q_PROPERTY(QString usingHwAdr READ usingHwAdr) // 对应于usingHwAdr接口 + Q_PROPERTY(QStringList ipv4 READ ipv4) // 对应于ipv4接口 + Q_PROPERTY(QStringList ipv6 READ ipv6) // 对应于ipv6接口 + Q_PROPERTY(QString deviceName READ deviceName WRITE setName NOTIFY nameChanged) // 对应于设备名称 + +Q_SIGNALS: + void deviceStatusChanged(const DeviceStatus &) const; // 状态发生变化的时候触发的信号 + void enableChanged(const bool) const; // 开启设备或禁用设备的时候发出的信号(参数值True表示开启设备,False表示禁用设备) + void connectionChanged(); // 连接发生变化的时候触发的信号 + void nameChanged(const QString &); // 网卡名称发生变化的时候触发的信号 + void removed(); // 设备移除 + void activeConnectionChanged(); // 活动连接发生变化的时候发出的信号 + void ipV4Changed(); // IPV4地址变化 + +public: + bool isEnabled() const; // 当前的网卡是否启用 + virtual bool isConnected() const = 0; // 当前网络的网络是否处于连接状态 + bool IPValid(); // IP是否合法 + virtual DeviceType deviceType() const = 0; // 设备类型 未识别 无线网卡 有线网卡,直接在子类中返回当前的类型即可 + DeviceStatus deviceStatus() const; // 设备状态 + QString interface() const; // 返回设备上的Interface + QString driver() const; // 驱动,对应于备上返回值的Driver + bool managed() const; // 对应于设备上返回值的Managed + QString vendor() const; // 对应于设备上返回值的Vendor + QString uniqueUuid() const; // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + bool usbDevice() const; // 是否是USB设备,对应于设备上返回值的UsbDevice + QString path() const; // 设备路径,对应于设备上返回值的Path + QString activeAp() const; // 对应于设备上返回值的ActiveAp + bool supportHotspot() const; // 是否支持热点,对应于设备上返回值的SupportHotspot + QString realHwAdr() const; // mac地址 + QString usingHwAdr() const; // 正在使用的mac地址 + QStringList ipv4() const; // IPV4地址 + QStringList ipv6() const; // IPV6地址 + QJsonObject activeConnectionInfo() const; // 获取当前活动连接的信息 + void setEnabled(bool enabled); // 开启或禁用网卡 + void disconnectNetwork(); // 断开网络连接,该方法是一个虚方法,具体在子类 + Connectivity connectivity(); + virtual void setName(const QString &name); // 设置设备的名称 + virtual QString deviceName(); // 设备名称 + +protected: + explicit NetworkDeviceBase(NetworkDeviceRealize *deviceInter, QObject *parent = Q_NULLPTR); + virtual ~NetworkDeviceBase(); + NetworkDeviceRealize *deviceRealize() const; + void enqueueStatus(const DeviceStatus &status); + virtual bool getHotspotEnabeld() { return false; } + +protected: + QString getStatusName(); + QString statusStringDetail(); + +private: + NetworkDeviceRealize *m_deviceInterface; + bool m_enabled; + QQueue m_statusQueue; + QString m_name; +}; + +} + +} + +#endif // UNETWORKDEVICEBASE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.cpp new file mode 100644 index 000000000..62ec619d3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.cpp @@ -0,0 +1,325 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "proxycontroller.h" +#include "networkdbusproxy.h" + +#include +#include + +using namespace dde::network; + +ProxyController::ProxyController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) + , m_proxyMothod(ProxyMethod::Init) +{ + Q_ASSERT(m_networkInter); + // 设置成同步的方式,目的是为了在初始化的时候能正确的返回应用代理的数据, + // 否则,如果是异步的方式,那么在初始化的时候查询应用代理的数据的时候,返回空 + // 后续ProxyChains的每个信号都会触发一次,将会触发多次appProxyChanged信号 + // 连接应用代理的相关的槽 + connect(m_networkInter, &NetworkDBusProxy::IPChanged, this, &ProxyController::onIPChanged); + connect(m_networkInter, &NetworkDBusProxy::PasswordChanged, this, &ProxyController::onPasswordChanged); + connect(m_networkInter, &NetworkDBusProxy::TypeChanged, this, &ProxyController::onTypeChanged); + connect(m_networkInter, &NetworkDBusProxy::UserChanged, this, &ProxyController::onUserChanged); + connect(m_networkInter, &NetworkDBusProxy::PortChanged, this, &ProxyController::onPortChanged); + // 初始化应用代理的相关的数据 + m_appProxyConfig.type = appProxyType(m_networkInter->type()); + m_appProxyConfig.ip = m_networkInter->iP(); + m_appProxyConfig.port = m_networkInter->port(); + m_appProxyConfig.username = m_networkInter->user(); + m_appProxyConfig.password = m_networkInter->password(); + // 判断是否存在proxychains4来决定是否存在应用代理 + m_appProxyExist = !QStandardPaths::findExecutable("proxychains4").isEmpty(); +} + +ProxyController::~ProxyController() +{ +} + +void ProxyController::setProxyMethod(const ProxyMethod &pm) +{ + // 设置代理模式,手动模式,自动模式和关闭代理 + QString methodName = convertProxyMethod(pm); + m_networkInter->SetProxyMethod(methodName, this, SLOT(queryProxyMethod())); +} + +void ProxyController::setProxyIgnoreHosts(const QString &hosts) +{ + m_networkInter->SetProxyIgnoreHosts(hosts, this, SLOT(queryProxyIgnoreHosts())); +} + +void ProxyController::setAutoProxy(const QString &proxy) +{ + m_networkInter->SetAutoProxy(proxy, this, SLOT(queryAutoProxy())); +} + +void ProxyController::setProxy(const SysProxyType &type, const QString &addr, const QString &port) +{ + QString uType = convertSysProxyType(type); + switch (type) { + case SysProxyType::Ftp: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataByFtp())); + break; + case SysProxyType::Http: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataByHttp())); + break; + case SysProxyType::Https: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataByHttps())); + break; + case SysProxyType::Socks: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataBySocks())); + break; + } +} + +void ProxyController::setAppProxy(const AppProxyConfig &config) +{ + m_networkInter->Set(appProxyType(config.type), config.ip, config.port, config.username, config.password); +} + +AppProxyConfig ProxyController::appProxy() const +{ + return m_appProxyConfig; +} + +SysProxyConfig ProxyController::proxy(const SysProxyType &type) const +{ + // 根据列表的类型返回实际的配置 + for (SysProxyConfig config : m_sysProxyConfig) { + if (config.type == type) + return config; + } + + return SysProxyConfig(); +} + +bool ProxyController::appProxyExist() const +{ + return m_appProxyExist; +} + +void ProxyController::querySysProxyData() +{ + // 查询系统代理的数据 + m_sysProxyConfig.clear(); + + static QStringList proxyTypes = {"http", "https", "ftp", "socks"}; + + // 依次获取每种类型的数据,并填充到列表中 + for (QString type : proxyTypes) + queryProxyDataByType(type); + + // 查询自动代理 + queryAutoProxy(); + // 查询代理模式 + queryProxyMethod(); + // 查询忽略的主机 + queryProxyIgnoreHosts(); +} + +void ProxyController::queryAutoProxy() +{ + QString autoProxyURL = m_networkInter->GetAutoProxy(); + if (m_autoProxyURL != autoProxyURL) { + m_autoProxyURL = autoProxyURL; + Q_EMIT autoProxyChanged(autoProxyURL); + } +} + +QString ProxyController::convertProxyMethod(const ProxyMethod &method) +{ + switch (method) { + case ProxyMethod::Auto: return "auto"; + case ProxyMethod::Manual: return "manual"; + default: break; + } + + return "none"; +} + +QString ProxyController::convertSysProxyType(const SysProxyType &type) +{ + switch (type) { + case SysProxyType::Ftp: return "ftp"; + case SysProxyType::Http: return "http"; + case SysProxyType::Https: return "https"; + case SysProxyType::Socks: return "socks"; + } + + return "http"; +} + +SysProxyType ProxyController::convertSysProxyType(const QString &type) +{ + if (type == "ftp") + return SysProxyType::Ftp; + + if (type == "http") + return SysProxyType::Http; + + if (type == "https") + return SysProxyType::Https; + + if (type == "socks") + return SysProxyType::Socks; + + return SysProxyType::Http; +} + +void ProxyController::queryProxyDataByFtp() +{ + queryProxyDataByType("ftp"); +} + +void ProxyController::queryProxyDataByHttp() +{ + queryProxyDataByType("http"); +} + +void ProxyController::queryProxyDataByHttps() +{ + queryProxyDataByType("https"); +} + +void ProxyController::queryProxyDataBySocks() +{ + queryProxyDataByType("socks"); +} + +void ProxyController::queryProxyDataByType(const QString &type) +{ + SysProxyType uType = convertSysProxyType(type); + QStringList proxy = m_networkInter->GetProxy(type); + if (proxy.size() != 2) + return; + bool finded = false; + // 先查找原来是否存在响应的代理,如果存在,就直接更新最新的数据 + for (SysProxyConfig &conf : m_sysProxyConfig) { + if (conf.type == uType) { + QString url = proxy.at(0); + uint port = proxy.at(1).toUInt(); + if (url != conf.url || port != conf.port) { + conf.url = url; + conf.port = port; + Q_EMIT proxyChanged(conf); + } + finded = true; + break; + } + } + // 如果不存在,直接将数据放入内存中 + if (!finded) { + SysProxyConfig proxyConfig; + proxyConfig.url = proxy.at(0); + proxyConfig.port = proxy.at(1).toUInt(); + proxyConfig.type = uType; + m_sysProxyConfig << proxyConfig; + Q_EMIT proxyChanged(proxyConfig); + } +} + +ProxyMethod ProxyController::convertProxyMethod(const QString &method) +{ + // 根据传入的字符串获取代理模式的枚举值 + if (method == "auto") + return ProxyMethod::Auto; + + if (method == "manual") + return ProxyMethod::Manual; + + return ProxyMethod::None; +} + +void ProxyController::queryProxyMethod() +{ + // 查询代理模式 + ProxyMethod method = convertProxyMethod(m_networkInter->GetProxyMethod()); + if (method != m_proxyMothod) { + m_proxyMothod = method; + Q_EMIT proxyMethodChanged(method); + } +} + +void ProxyController::queryProxyIgnoreHosts() +{ + // 查询忽略的代理主机 + QString proxyIgnoreHosts = m_networkInter->GetProxyIgnoreHosts(); + if (m_proxyIgnoreHosts != proxyIgnoreHosts) { + m_proxyIgnoreHosts = proxyIgnoreHosts; + Q_EMIT proxyIgnoreHostsChanged(proxyIgnoreHosts); + } +} + +void ProxyController::onIPChanged(const QString &value) +{ + // 应用代理的IP发生变化 + if (value != m_appProxyConfig.ip) { + m_appProxyConfig.ip = value; + Q_EMIT appIPChanged(value); + } +} + +void ProxyController::onPasswordChanged(const QString &value) +{ + // 应用代理的密码发生变化 + if (value != m_appProxyConfig.password) { + m_appProxyConfig.password = value; + Q_EMIT appPasswordChanged(value); + } +} + +AppProxyType ProxyController::appProxyType(const QString &v) +{ + if (v == "http") + return AppProxyType::Http; + + if (v == "socks4") + return AppProxyType::Socks4; + + if (v == "socks5") + return AppProxyType::Socks5; + + return AppProxyType::Http; +} + +QString ProxyController::appProxyType(const AppProxyType &v) +{ + switch (v) { + case AppProxyType::Http: return "http"; + case AppProxyType::Socks4: return "socks4"; + case AppProxyType::Socks5: return "socks5"; + } + + return "http"; +} + +void ProxyController::onTypeChanged(const QString &value) +{ + // 应用代理类型发生变化 + AppProxyType t = appProxyType(value); + if (t != m_appProxyConfig.type) { + m_appProxyConfig.type = t; + Q_EMIT appTypeChanged(t); + } +} + +void ProxyController::onUserChanged(const QString &value) +{ + // 应用代理用户名发生变化 + if (value != m_appProxyConfig.username) { + m_appProxyConfig.username = value; + Q_EMIT appUsernameChanged(value); + } +} + +void ProxyController::onPortChanged(uint value) +{ + // 应用代理端口发生变化 + if (value != m_appProxyConfig.port) { + m_appProxyConfig.port = value; + Q_EMIT appPortChanged(value); + } +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.h b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.h new file mode 100644 index 000000000..6f228026c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.h @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef PROXYCONTROLLER_H +#define PROXYCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include + +namespace dde { + +namespace network { +class NetworkDBusProxy; + +class ProxyController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + /* 系统代理 */ + void querySysProxyData(); // 查询系统代理,一般在控制中心点击的时候实时调用 + void setProxyMethod(const ProxyMethod &pm); // 设置代理模式 + inline ProxyMethod proxyMethod() const { return m_proxyMothod; } // 返回代理模式 + void setProxyIgnoreHosts(const QString &hosts); // 设置忽略的主机 + inline QString proxyIgnoreHosts() const { return m_proxyIgnoreHosts; } // 返回代理主机列表 + void setAutoProxy(const QString &proxy); // 设置自动代理的配置URL + inline QString autoProxy() { return m_autoProxyURL; } // 返回自动代理的配置URL + void setProxy(const SysProxyType &type, + const QString &addr, const QString &port); // 设置代理信息,type是一个枚举类型,一般是manual模式下设置 + SysProxyConfig proxy(const SysProxyType &type) const; // 获取对应类型下的系统代理数据 + + /* 应用代理 */ + bool appProxyExist() const; + void setAppProxy(const AppProxyConfig &config); // 设置应用代理数据 + AppProxyConfig appProxy() const; // 获取应用代理数据 + +Q_SIGNALS: + /* 系统代理 */ + void autoProxyChanged(const QString &); // 自动代理发生变化 + void proxyChanged(const SysProxyConfig &); // 某种代理数据发生变化的时候触发的信号 + void proxyMethodChanged(const ProxyMethod &); // 代理模式发生变化 + void proxyIgnoreHostsChanged(const QString &); // 忽略的主机发生变化 + /* 应用代理 */ + void appIPChanged(const QString &ip); // 应用代理IP发生变化 + void appPasswordChanged(const QString &password); // 应用代理密码发生变化 + void appTypeChanged(const AppProxyType &type); // 应用代理类型发生变化 + void appUsernameChanged(const QString &username); // 应用代理用户名发生变化 + void appPortChanged(const uint &port); // 应用代理端口发生变化 + +protected: + explicit ProxyController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~ProxyController(); + + ProxyMethod convertProxyMethod(const QString &method); // 将代理模式字符串转换为枚举 + QString convertProxyMethod(const ProxyMethod &method); // 将代理模式枚举转换为字符串 + + QString convertSysProxyType(const SysProxyType &type); // 将代理模式枚举值转换为字符串 + SysProxyType convertSysProxyType(const QString &type); // 将代理模式字符串转换为枚举值 + + AppProxyType appProxyType(const QString &v); // 系统代理类型转换,字符串到枚举 + QString appProxyType(const AppProxyType &v); // 系统代理类型转换,枚举到字符串 + +private Q_SLOTS: + void onIPChanged(const QString &value); + void onPasswordChanged(const QString &value); + void onTypeChanged(const QString &value); + void onUserChanged(const QString &value); + void onPortChanged(uint value); + + void queryAutoProxy(); // 查询自动代理的URL + void queryProxyMethod(); // 查询自动代理模式 + void queryProxyIgnoreHosts(); // 查询代理忽略的主机 + void queryProxyDataByType(const QString &type); // 查询代理数据 + + void queryProxyDataByFtp(); + void queryProxyDataByHttp(); + void queryProxyDataByHttps(); + void queryProxyDataBySocks(); +private: + NetworkDBusProxy *m_networkInter; + QList m_sysProxyConfig; + QString m_autoProxyURL; + ProxyMethod m_proxyMothod; + QString m_proxyIgnoreHosts; + AppProxyConfig m_appProxyConfig; + bool m_appProxyExist; +}; + +} + +} + +#endif // UPROXYCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.cpp new file mode 100644 index 000000000..ef242438d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.cpp @@ -0,0 +1,838 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "deviceinterrealize.h" +#include "wireddevice.h" +#include "wirelessdevice.h" +#include "networkdbusproxy.h" + +#include +#include + +using namespace dde::network; + +#define UNKNOW_MODE 0 +#define ADHOC_MODE 1 +#define INFRA_MODE 2 +#define AP_MODE 3 + +#define ACTIVATING 1 +#define ACTIVATED 2 +#define DEACTIVATING 3 +#define DEACTIVATED 4 + +const QStringList DeviceInterRealize::ipv4() +{ + if (!isConnected() || !isEnabled()) + return QStringList(); + + if (m_activeInfoData.contains("IPv4")) { + QJsonObject ipv4TopObject = m_activeInfoData["IPv4"].toObject(); + QJsonArray ipv4Array = ipv4TopObject.value("Addresses").toArray(); + QStringList ipv4s; + for (const QJsonValue ipv4Value : ipv4Array) { + const QJsonObject ipv4Object = ipv4Value.toObject(); + QString ip = ipv4Object.value("Address").toString(); + ip = ip.remove("\""); + ipv4s << ip; + } + ipv4s = getValidIPV4(ipv4s); + return ipv4s; + } + + // 返回IPv4地址 + QJsonValue ipJsonData = m_activeInfoData["Ip4"]; + QJsonObject objIpv4 = ipJsonData.toObject(); + return { objIpv4.value("Address").toString() }; +} + +const QStringList DeviceInterRealize::ipv6() +{ + if (!isConnected() || !isEnabled() || !m_activeInfoData.contains("Ip6")) + return QStringList(); + + if (m_activeInfoData.contains("IPv6")) { + QJsonObject ipv6TopObject = m_activeInfoData["IPv6"].toObject(); + QJsonArray ipv6Array = ipv6TopObject.value("Addresses").toArray(); + QStringList ipv6s; + for (const QJsonValue ipv6Value : ipv6Array) { + const QJsonObject ipv6Object = ipv6Value.toObject(); + QString ip = ipv6Object.value("Address").toString(); + ip = ip.remove("\""); + ipv6s << ip; + } + return ipv6s; + } + + // 返回IPv4地址 + QJsonValue ipJsonData = m_activeInfoData["Ip6"]; + QJsonObject objIpv6 = ipJsonData.toObject(); + return { objIpv6.value("Address").toString() }; +} + +QJsonObject DeviceInterRealize::activeConnectionInfo() const +{ + return m_activeInfoData; +} + +QStringList DeviceInterRealize::getValidIPV4(const QStringList &ipv4s) +{ + if (ipv4s.size() > 1 || ipv4s.size() == 0) + return ipv4s; + + // 检查IP列表,如果发现有IP为0.0.0.0,则让其重新获取一次,保证IP获取正确 + // 这种情况一般发生在关闭热点后,因此在此处处理 + if (isIpv4Address(ipv4s[0])) + return ipv4s; + + const QString activeConnInfo = m_networkInter->GetActiveConnectionInfo(); + QJsonParseError error; + QJsonDocument json = QJsonDocument::fromJson(activeConnInfo.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) + return ipv4s; + + if (!json.isArray()) + return ipv4s; + + QJsonArray infoArray = json.array(); + for (const QJsonValue ipInfo : infoArray) { + const QJsonObject ipObject = ipInfo.toObject(); + if (ipObject.value("Device").toString() != this->path()) + continue; + + if (!ipObject.contains("IPv4")) + return ipv4s; + + QJsonObject ipV4Object = ipObject.value("IPv4").toObject(); + if (!ipV4Object.contains("Addresses")) + return ipv4s; + + QStringList ipAddresses; + QJsonArray ipv4Addresses = ipV4Object.value("Addresses").toArray(); + for (const QJsonValue addr : ipv4Addresses) { + const QJsonObject addressObject = addr.toObject(); + QString ip = addressObject.value("Address").toString(); + if (isIpv4Address(ip)) + ipAddresses << ip; + } + if (ipAddresses.size() > 0) { + m_activeInfoData = ipObject; + return ipAddresses; + } + } + + return ipv4s; +} + +bool DeviceInterRealize::isIpv4Address(const QString &ip) const +{ + QHostAddress ipAddr(ip); + if (ipAddr == QHostAddress(QHostAddress::Null) || ipAddr == QHostAddress(QHostAddress::AnyIPv4) + || ipAddr.protocol() != QAbstractSocket::NetworkLayerProtocol::IPv4Protocol) { + return false; + } + + QRegularExpression regExpIP("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[\\.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"); + return regExpIP.match(ip).hasMatch(); +} + +void DeviceInterRealize::setEnabled(bool enabled) +{ + m_networkInter->EnableDevice(QDBusObjectPath(path()), enabled); +} + +Connectivity DeviceInterRealize::connectivity() +{ + return m_connectivity; +} + +void DeviceInterRealize::deviceConnectionFailed() +{ + // 连接失败 +// Q_EMIT connectionFailed(item); + Q_EMIT deviceStatusChanged(DeviceStatus::Failed); +} + +void DeviceInterRealize::deviceConnectionSuccess() +{ + Q_EMIT deviceStatusChanged(DeviceStatus::Activated); +} + +DeviceInterRealize::DeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent) + : NetworkDeviceRealize(ipChecker, parent) + , m_networkInter(networkInter) + , m_enabled(true) + , m_connectivity(Connectivity::Full) +{ +} + +DeviceInterRealize::~DeviceInterRealize() +{ +} + +NetworkDBusProxy *DeviceInterRealize::networkInter() +{ + return m_networkInter; +} + +void DeviceInterRealize::updateDeviceInfo(const QJsonObject &info) +{ + m_data = info; + DeviceStatus stat = convertDeviceStatus(info.value("State").toInt()); + + setDeviceStatus(stat); +} + +void DeviceInterRealize::initDeviceInfo() +{ + if (m_networkInter) { + // 状态发生变化后,获取设备的实时信息 + m_enabled = m_networkInter->IsDeviceEnabled(QDBusObjectPath(path())); + } +} + +void DeviceInterRealize::setDeviceEnabledStatus(const bool &enabled) +{ + m_enabled = enabled; + Q_EMIT enableChanged(enabled); +} + +void DeviceInterRealize::updateActiveConnectionInfo(const QList &infos) +{ + const QStringList oldIpv4 = ipv4(); + m_activeInfoData = QJsonObject(); + for (const QJsonObject &info : infos) { + if (info.value("ConnectionType").toString() == deviceKey()) { + // 如果找到了当前硬件地址的连接信息,则直接使用这个数据 + m_activeInfoData = info; + break; + } + } + + // 获取到完整的IP地址后,向外发送连接改变的信号 + if (!m_activeInfoData.isEmpty()) + Q_EMIT connectionChanged(); + + QStringList ipv4s = ipv4(); + bool ipChanged = false; + if (oldIpv4.size() != ipv4s.size()) { + ipChanged = true; + } else { + for (const QString &ip : ipv4s) { + if (!oldIpv4.contains(ip)) { + ipChanged = true; + break; + } + } + } + if (ipChanged) + Q_EMIT ipV4Changed(); +} + +void DeviceInterRealize::setDeviceStatus(const DeviceStatus &status) +{ + // 如果是开启热点,就让其renweus断开的状态 + DeviceStatus stat = status; + if (mode() == AP_MODE) + stat = DeviceStatus::Disconnected; + + NetworkDeviceRealize::setDeviceStatus(stat); +} + +int DeviceInterRealize::mode() const +{ + if (m_data.contains("Mode")) + return m_data.value("Mode").toInt(); + + return UNKNOW_MODE; +} + +/** + * @brief 有线设备类的具体实现 + */ + +WiredDeviceInterRealize::WiredDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent) + : DeviceInterRealize(ipChecker, networkInter, parent) +{ +} + +WiredDeviceInterRealize::~WiredDeviceInterRealize() +{ + for (auto item : m_connections) { + delete item; + } + m_connections.clear(); +} + +bool WiredDeviceInterRealize::connectNetwork(WiredConnection *connection) +{ + if (!connection) + return false; + + networkInter()->ActivateConnection(connection->connection()->uuid(), QDBusObjectPath(path())); + return true; +} + +void WiredDeviceInterRealize::disconnectNetwork() +{ + networkInter()->DisconnectDevice(QDBusObjectPath(path())); +} + +bool WiredDeviceInterRealize::isConnected() const +{ + for (WiredConnection *connection : m_connections) { + if (connection->connected()) + return true; + } + + return false; +} + +QList WiredDeviceInterRealize::wiredItems() const +{ + return m_connections; +} + +WiredConnection *WiredDeviceInterRealize::findConnection(const QString &path) +{ + for (WiredConnection *conn : m_connections) { + if (conn->connection()->path() == path) + return conn; + } + + return Q_NULLPTR; +} + +void WiredDeviceInterRealize::setDeviceEnabledStatus(const bool &enabled) +{ + if (!enabled) { + // 禁用网卡的情况下,先清空连接信息 + for (WiredConnection *connection : m_connections) + connection->setConnectionStatus(ConnectionStatus::Deactivated); + } + + DeviceInterRealize::setDeviceEnabledStatus(enabled); +} + +void WiredDeviceInterRealize::updateConnection(const QJsonArray &info) +{ + QList newWiredConnections; + QList changedWiredConnections; + QStringList connPaths; + for (const QJsonValue &jsonValue : info) { + const QJsonObject &jsonObj = jsonValue.toObject(); + const QString IfcName = jsonObj.value("IfcName").toString(); + if (!IfcName.isEmpty() && IfcName != interface()) + continue; + + const QString path = jsonObj.value("Path").toString(); + WiredConnection *conn = findConnection(path); + if (!conn) { + conn = new WiredConnection; + m_connections << conn; + newWiredConnections << conn; + } else { + if (conn->connection()->id() != jsonObj.value("Id").toString() + || conn->connection()->ssid() != jsonObj.value("Ssid").toString()) + changedWiredConnections << conn; + } + + conn->setConnection(jsonObj); + if (!connPaths.contains(path)) + connPaths << path; + } + + QList rmConns; + for (WiredConnection *connection : m_connections) { + if (!connPaths.contains(connection->connection()->path())) + rmConns << connection; + } + + for (WiredConnection *connection : rmConns) + m_connections.removeOne(connection); + + if (changedWiredConnections.size()) + Q_EMIT connectionPropertyChanged(changedWiredConnections); + + if (newWiredConnections.size() > 0) + Q_EMIT connectionAdded(newWiredConnections); + + if (rmConns.size() > 0) + Q_EMIT connectionRemoved(rmConns); + + // 提交改变信号后,删除不在的连接 + for (WiredConnection *connection : rmConns) + delete connection; + + // 排序 + sortWiredItem(m_connections); +} + +WiredConnection *WiredDeviceInterRealize::findWiredConnectionByUuid(const QString &uuid) +{ + for (WiredConnection *connection : m_connections) { + if (connection->connection()->uuid() == uuid) + return connection; + } + + return Q_NULLPTR; +} + +static ConnectionStatus convertStatus(int status) +{ + if (status == ACTIVATING) + return ConnectionStatus::Activating; + + if (status == ACTIVATED) + return ConnectionStatus::Activated; + + if (status == DEACTIVATING) + return ConnectionStatus::Deactivating; + + if (status == DEACTIVATED) + return ConnectionStatus::Deactivated; + + return ConnectionStatus::Unknown; +} + +void WiredDeviceInterRealize::updateActiveInfo(const QList &info) +{ + bool changeStatus = false; + // 根据返回的UUID找到对应的连接,找到State=2的连接变成连接成功状态 + for (const QJsonObject &activeInfo : info) { + const QString uuid = activeInfo.value("Uuid").toString(); + WiredConnection *connection = findWiredConnectionByUuid(uuid); + if (!connection) + continue; + + ConnectionStatus status = convertStatus(activeInfo.value("State").toInt()); + if (connection->status() != status) { + connection->setConnectionStatus(status); + changeStatus = true; + } + } + + // 调用基类的函数,更改设备的状态,同时向外发送信号 + DeviceInterRealize::updateActiveInfo(info); + if (changeStatus) + Q_EMIT activeConnectionChanged(); +} + +QString WiredDeviceInterRealize::deviceKey() +{ + return "wired"; +} + +/** + * @brief WirelessDeviceInterRealize::WirelessDeviceInterRealize + * @param networkInter + * @param parent + */ + +bool WirelessDeviceInterRealize::isConnected() const +{ + for (AccessPoints *ap : m_accessPoints) { + if (ap->status() == ConnectionStatus::Activated) + return true; + } + + return false; +} + +QList WirelessDeviceInterRealize::accessPointItems() const +{ + if (needShowAccessPoints()) + return m_accessPoints; + + return QList(); +} + +void WirelessDeviceInterRealize::scanNetwork() +{ + networkInter()->RequestWirelessScan(); +} + +void WirelessDeviceInterRealize::connectNetwork(const AccessPoints *item) +{ + WirelessConnection *wirelessConn = findConnectionByAccessPoint(item); + if (!wirelessConn) + return; + + const QString uuid = wirelessConn->connection()->uuid(); + const QString apPath = item->path(); + const QString devPath = path(); + + qInfo() << "Connect to the AP, uuid:" << uuid << ", access point path:" << apPath << ", device path:" << devPath; + networkInter()->ActivateAccessPoint(uuid, QDBusObjectPath(apPath), QDBusObjectPath(devPath), this, SLOT(deviceConnectionSuccess()), SLOT(deviceConnectionFailed())); +} + +AccessPoints *WirelessDeviceInterRealize::activeAccessPoints() const +{ + // 如果网卡是关闭的状态下,肯定是没有连接 + if (!isEnabled()) + return Q_NULLPTR; + + for (AccessPoints *ap : m_accessPoints) { + if (ap->connected()) + return ap; + } + + return Q_NULLPTR; +} + +void WirelessDeviceInterRealize::disconnectNetwork() +{ + networkInter()->DisconnectDevice(QDBusObjectPath(path())); +} + +QList WirelessDeviceInterRealize::items() const +{ + QList lstItems; + for (WirelessConnection *item : m_connections) { + if (item->accessPoints()) + lstItems << item; + } + + return lstItems; +} + +WirelessDeviceInterRealize::WirelessDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent) + : DeviceInterRealize(ipChecker, networkInter, parent) +{ +} + +WirelessDeviceInterRealize::~WirelessDeviceInterRealize() +{ + clearListData(m_accessPoints); + clearListData(m_connections); +} + +WirelessConnection *WirelessDeviceInterRealize::findConnectionByPath(const QString &path) +{ + for (WirelessConnection *conn : m_connections) { + if (conn->connection()->path() == path) + return conn; + } + + return Q_NULLPTR; +} + +AccessPoints *WirelessDeviceInterRealize::findAccessPoint(const QString &ssid) +{ + for (AccessPoints *accessPoint : m_accessPoints) { + if (accessPoint->ssid() == ssid) + return accessPoint; + } + + return Q_NULLPTR; +} + +WirelessConnection *WirelessDeviceInterRealize::findConnectionByAccessPoint(const AccessPoints *accessPoint) +{ + if (!accessPoint) + return Q_NULLPTR; + + for (WirelessConnection *connection : m_connections) { + if (connection->accessPoints() == accessPoint) + return connection; + + if (connection->connection()->ssid() == accessPoint->ssid()) + return connection; + } + + return Q_NULLPTR; +} + +/** + * @brief 同步热点和连接的信息 + */ +void WirelessDeviceInterRealize::syncConnectionAccessPoints() +{ + if (m_accessPoints.isEmpty()) { + clearListData(m_connections); + return; + } + + QList connections; + // 找到每个热点对应的Connection,并将其赋值 + for (AccessPoints *accessPoint : m_accessPoints) { + WirelessConnection *connection = findConnectionByAccessPoint(accessPoint); + if (!connection) { + connection = WirelessConnection::createConnection(accessPoint); + m_connections << connection; + } + + connection->m_accessPoints = accessPoint; + connections << connection; + } + updateActiveInfo(); + // 删除列表中没有AccessPoints的Connection,让两边保持数据一致 + QList rmConns; + for (WirelessConnection *connection : m_connections) { + if (!connections.contains(connection)) + rmConns << connection; + } + + for (WirelessConnection *rmConnection : rmConns) { + m_connections.removeOne(rmConnection); + delete rmConnection; + } +} + +void WirelessDeviceInterRealize::updateActiveInfo() +{ + if (m_activeAccessPoints.isEmpty()) + return; + + QList tmpApList = m_accessPoints; + // 遍历活动连接列表,找到对应的wlan,改变其连接状态,State赋值即可 + bool changed = false; + AccessPoints *activeAp = Q_NULLPTR; + for (const QJsonObject &aapInfo : m_activeAccessPoints) { + int connectionStatus = aapInfo.value("State").toInt(); + QString ssid = aapInfo.value("Id").toString(); + AccessPoints *ap = findAccessPoint(ssid); + if (!ap) + continue; + + tmpApList.removeAll(ap); + ConnectionStatus status = convertConnectionStatus(connectionStatus); + if (ap->status() == status) + continue; + + ap->updateConnectionStatus(status); + changed = true; + if (ap->status() == ConnectionStatus::Activated) + activeAp = ap; + } + + // 将其它连接变成普通状态 + for (AccessPoints *ap : tmpApList) + ap->updateConnectionStatus(ConnectionStatus::Unknown); + + if (changed) { + Q_EMIT activeConnectionChanged(); + } + + // 如果发现其中一个连接成功,将这个连接成功的信号移到最上面,然后则向外发送连接成功的信号 + if (activeAp) { + int pos = m_accessPoints.indexOf(activeAp); + m_accessPoints.move(pos, 0); + Q_EMIT connectionSuccess(activeAp); + } + + // 调用基类的方法触发连接发生变化,同时向外抛出连接变化的信号 + DeviceInterRealize::updateActiveInfo(m_activeAccessPoints); +} + +QList WirelessDeviceInterRealize::wirelessItems() const +{ + return m_connections; +} + +bool WirelessDeviceInterRealize::needShowAccessPoints() const +{ + // Mode=3表示开启热点 + if (mode() == AP_MODE) + return false; + // 如果当前设备热点为空(关闭热点),则让显示所有的网络列表 + return m_hotspotInfo.isEmpty(); +} + +void WirelessDeviceInterRealize::updateActiveConnectionInfo(const QList &infos) +{ + bool enabledHotspotOld = hotspotEnabled(); + + m_hotspotInfo = QJsonObject(); + for (const QJsonObject &info : infos) { + const QString devicePath = info.value("Device").toString(); + const QString connectionType = info.value("ConnectionType").toString(); + if (devicePath == this->path() && connectionType == "wireless-hotspot") { + m_hotspotInfo = info; + setDeviceStatus(DeviceStatus::Disconnected); + break; + } + } + + bool enabledHotspot = hotspotEnabled(); + if (enabledHotspotOld != enabledHotspot) + Q_EMIT hotspotEnableChanged(enabledHotspot); + + DeviceInterRealize::updateActiveConnectionInfo(infos); +} + +bool dde::network::WirelessDeviceInterRealize::hotspotEnabled() +{ + return !m_hotspotInfo.isEmpty(); +} + +void WirelessDeviceInterRealize::updateAccesspoint(const QJsonArray &json) +{ + auto isWifi6 = [](const QJsonObject &json) { + if (json.contains("Flags")) { + int flag = json.value("Flags").toInt(); + if (flag & AP_FLAGS_HE) + return true; + } + + return false; + }; + + // 先过滤相同的ssid,找出信号强度最大的那个 + QMap ssidMaxStrength; + QMap ssidPath; + QMap wifi6Ssids; + for (const QJsonValue &jsonValue : json) { + const QJsonObject obj = jsonValue.toObject(); + const QString ssid = obj.value("Ssid").toString(); + const int strength = obj.value("Strength").toInt(); + const QString path = obj.value("Path").toString(); + if (ssidMaxStrength.contains(ssid)) { + const int nOldStrength = ssidMaxStrength.value(ssid); + if (nOldStrength < strength) { + // 找到了对应的热点,更新热点的信号强度 + ssidMaxStrength[ssid] = strength; + ssidPath[ssid] = path; + } + } else { + // 第一次直接插入SSID和信号强度和路径 + ssidMaxStrength[ssid] = strength; + ssidPath[ssid] = path; + } + if (isWifi6(obj)) + wifi6Ssids[ssid] = obj.value("Flags").toInt(); + } + + QList newAp; + QList changedAp; + QStringList ssids; + for (const QJsonValue &jsonValue : json) { + QJsonObject accessInfo = jsonValue.toObject(); + const QString ssid = accessInfo.value("Ssid").toString(); + const QString maxSsidPath = ssidPath.value(ssid); + const QString path = accessInfo.value("Path").toString(); + if (path != maxSsidPath) + continue; + + // 如果当前的SSID存在WiFi6,就让其显示WiFi6的属性 + if (wifi6Ssids.contains(ssid)) + accessInfo["extendFlags"] = wifi6Ssids[ssid]; + + // 从网络列表中查找现有的网络 + AccessPoints *accessPoint = findAccessPoint(ssid); + if (!accessPoint) { + // 如果没有找到这个网络,就新建一个网络,添加到网络列表 + accessPoint = new AccessPoints(accessInfo, this); + accessPoint->m_devicePath = this->path(); + m_accessPoints << accessPoint; + newAp << accessPoint; + } else { + int strength = accessInfo.value("Strength").toInt(); + if (accessPoint->strength() != strength) + changedAp << accessPoint; + + accessPoint->updateAccessPoints(accessInfo); + } + + if (!ssids.contains(ssid)) + ssids << ssid; + } + + if (changedAp.size()) + Q_EMIT accessPointInfoChanged(changedAp); + + if (newAp.size() > 0) + Q_EMIT networkAdded(newAp); + + // 更新网络和连接的关系 + QList rmAccessPoints; + for (AccessPoints *ap : m_accessPoints) { + if (!ssids.contains(ap->ssid())) + rmAccessPoints << ap; + } + + if (rmAccessPoints.size() > 0) { + for (AccessPoints *ap : rmAccessPoints) + m_accessPoints.removeOne(ap); + + Q_EMIT networkRemoved(rmAccessPoints); + } + + for (AccessPoints *ap : rmAccessPoints) + ap->deleteLater(); + + createConnection(m_connectionJson); + syncConnectionAccessPoints(); +} + +void WirelessDeviceInterRealize::setDeviceEnabledStatus(const bool &enabled) +{ + if (!enabled) { + // 禁用网卡的情况下,直接清空原来的连接信息 + m_activeAccessPoints.clear(); + // 向外抛出删除wlan连接的信号,这里暂时不清空AccessPoints列表,防止再打开网卡的时候重复创建 + Q_EMIT networkRemoved(m_accessPoints); + } + + DeviceInterRealize::setDeviceEnabledStatus(enabled); +} + +void WirelessDeviceInterRealize::updateConnection(const QJsonArray &info) +{ + m_connectionJson = info; + + createConnection(info); + + syncConnectionAccessPoints(); +} + +void WirelessDeviceInterRealize::createConnection(const QJsonArray &info) +{ + QStringList connPaths; + for (const QJsonValue &jsonValue : info) { + const QJsonObject &jsonObj = jsonValue.toObject(); + const QString hwAddress = jsonObj.value("HwAddress").toString(); + if (!hwAddress.isEmpty() && hwAddress != realHwAdr()) + continue; + + // only update its own connection instead of all devices connection. + const QString ifcName = jsonObj.value("IfcName").toString(); + if (!ifcName.isEmpty() && ifcName != interface()) + continue; + + const QString path = jsonObj.value("Path").toString(); + WirelessConnection *connection = findConnectionByPath(path); + if (!connection) { + connection = new WirelessConnection; + m_connections << connection; + } + + connection->setConnection(jsonObj); + if (!connPaths.contains(path)) + connPaths << path; + } + + QList rmConns; + for (WirelessConnection *conn : m_connections) { + if (!connPaths.contains(conn->connection()->path())) + rmConns << conn; + } + + // 提交改变信号后,删除不在的连接 + for (WirelessConnection *conn : rmConns) { + m_connections.removeOne(conn); + delete conn; + } +} + +void WirelessDeviceInterRealize::updateActiveInfo(const QList &info) +{ + m_activeAccessPoints = info; + updateActiveInfo(); +} + +QString WirelessDeviceInterRealize::deviceKey() +{ + return "wireless"; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.h b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.h new file mode 100644 index 000000000..08c8ea5ce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.h @@ -0,0 +1,165 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEVICEINTERREALIZE_H +#define DEVICEINTERREALIZE_H + +#include "netinterface.h" +#include "networkconst.h" +#include "netutils.h" + +#include +#include + +namespace dde { + +namespace network { + +#define MaxQueueSize 4 +class NetworkDBusProxy; +class DeviceInterRealize : public NetworkDeviceRealize +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkDeviceBase; + +public: + inline bool isEnabled() const override { return m_enabled; } // 当前的网卡是否启用 + inline QString interface() const override { return m_data.value("Interface").toString(); } // 返回设备上的Interface + inline QString driver() const override { return m_data.value("Driver").toString(); } // 驱动,对应于备上返回值的Driver + inline bool managed() const override { return m_data.value("Managed").toBool(); } // 对应于设备上返回值的Managed + inline QString vendor() const override { return m_data.value("Vendor").toString(); } // 对应于设备上返回值的Vendor + inline QString uniqueUuid() const override { return m_data.value("UniqueUuid").toString(); } // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + inline bool usbDevice() const override { return m_data.value("UsbDevice").toBool(); } // 是否是USB设备,对应于设备上返回值的UsbDevice + inline QString path() const override { return m_data.value("Path").toString(); } // 设备路径,对应于设备上返回值的Path + inline QString activeAp() const override { return m_data.value("ActiveAp").toString(); } // 对应于设备上返回值的ActiveAp + inline bool supportHotspot() const override { return m_data.value("SupportHotspot").toBool(); } // 是否支持热点,对应于设备上返回值的SupportHotspot + inline QString realHwAdr() const override { return m_data.value("HwAddress").toString(); } // mac地址 + inline QString usingHwAdr() const override { return m_data.value("ClonedAddress").toString(); } // 正在使用的mac地址 + const QStringList ipv4() override; // IPV4地址 + const QStringList ipv6() override; // IPV6地址 + QJsonObject activeConnectionInfo() const override; // 获取当前活动连接的信息 + void setEnabled(bool enabled) override; // 开启或禁用网卡 + Connectivity connectivity(); + +protected Q_SLOTS: + void deviceConnectionFailed(); + void deviceConnectionSuccess(); + +protected: + explicit DeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + virtual ~DeviceInterRealize() override; + NetworkDBusProxy *networkInter(); + void updateDeviceInfo(const QJsonObject &info); + void initDeviceInfo(); + QStringList getValidIPV4(const QStringList &ipv4s); + bool isIpv4Address(const QString &ip) const; + virtual bool isConnected() const = 0; // 当前网络的网络是否处于连接状态 + virtual void updateConnection(const QJsonArray &info) = 0; + virtual QString deviceKey() = 0; // 返回设备对应的key值 + virtual void setDeviceEnabledStatus(const bool &enabled); + virtual void updateActiveInfo(const QList &) {} // 当前连接发生变化,例如从一个连接切换到另外一个连接 + virtual void updateActiveConnectionInfo(const QList &infos); // 当前连接发生变化后,获取设备的活动信息,例如IP等 + void setDeviceStatus(const DeviceStatus &status) override; + int mode() const; + +private: + NetworkDBusProxy *m_networkInter; + QJsonObject m_data; + QJsonObject m_activeInfoData; + bool m_enabled; + Connectivity m_connectivity; + QQueue m_statusQueue; + QString m_name; +}; + +class WiredDeviceInterRealize : public DeviceInterRealize +{ + Q_OBJECT + + friend class NetworkInterProcesser; + +private: + WiredDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent); + ~WiredDeviceInterRealize() override; + +public: + bool connectNetwork(WiredConnection *connection) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + void disconnectNetwork() override; // 断开网络连接 + QList wiredItems() const override; // 有线网络连接列表 + +private: + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + void updateConnection(const QJsonArray &info) override; + void updateActiveInfo(const QList &info) override; + QString deviceKey() override; + WiredConnection *findConnection(const QString &path); + WiredConnection *findWiredConnectionByUuid(const QString &uuid); + void setDeviceEnabledStatus(const bool &enabled) override; + +private: + QList m_connections; +}; + +class WirelessDeviceInterRealize : public DeviceInterRealize +{ + Q_OBJECT + + friend class NetworkInterProcesser; + +public: + QList accessPointItems() const override; // 当前网卡上所有的网络列表 + void scanNetwork() override; // 重新加载所有的无线网络列表 + void connectNetwork(const AccessPoints *item) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + void disconnectNetwork() override; // 断开连接 + QList items() const; // 无线网络连接列表 + AccessPoints *activeAccessPoints() const override; // 当前活动的无线连接 + +protected: + WirelessDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent); + ~WirelessDeviceInterRealize() override; + +private: + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + AccessPoints *findAccessPoint(const QString &ssid); + WirelessConnection *findConnectionByAccessPoint(const AccessPoints *accessPoint); + void syncConnectionAccessPoints(); + void updateActiveInfo(); + QList wirelessItems() const override; // 无线网络连接列表 + bool needShowAccessPoints() const; // 是否需要显示所有的无线网络,一般情况下,在开启热点后,不显示无线网络 + +protected: + void updateConnection(const QJsonArray &info) override; + void createConnection(const QJsonArray &info); + void updateActiveInfo(const QList &info) override; + QString deviceKey() override; + WirelessConnection *findConnectionByPath(const QString &path); + void updateAccesspoint(const QJsonArray &json); + void setDeviceEnabledStatus(const bool &enabled) override; + void updateActiveConnectionInfo(const QList &infos) override; + bool hotspotEnabled() override; + + template + void clearListData(QList &dataList) { + for (T *data : dataList) + delete data; + + dataList.clear(); + } + +private: + QList m_connections; + QList m_accessPoints; + QJsonObject m_activeHotspotInfo; + QList m_activeAccessPoints; + QJsonObject m_hotspotInfo; + QJsonArray m_connectionJson; +}; + +} + +} + +#endif // INTERDEVICE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.cpp new file mode 100644 index 000000000..10a57f162 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.cpp @@ -0,0 +1,762 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "devicemanagerrealize.h" +#include "netutils.h" +#include "networkdevicebase.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +using namespace dde::network; +using namespace NetworkManager; + +DeviceManagerRealize::DeviceManagerRealize(IPConfilctChecker *ipChecker, QSharedPointer device, QObject *parent) + : NetworkDeviceRealize(ipChecker, parent) + , m_wDevice(device) + , m_activeWiredConnection(Q_NULLPTR) + , m_activeWirelessConnection(Q_NULLPTR) +{ + // 初始化有线连接 + onWiredConnectionChanged(); + // 初始化无线连接 + onWirelessConnectionChanged(); + // 初始化信号槽的连接 + initSigSlotConnection(); + // 改变状态 + changeStatus(m_wDevice->state()); + // 获取是否开启热点 + m_hotspotEnabled = getHotspotIsEnabled(); +} + +void DeviceManagerRealize::initSigSlotConnection() +{ + connect(m_wDevice.get(), &NetworkManager::Device::availableConnectionChanged, this, &DeviceManagerRealize::onWiredConnectionChanged); + connect(m_wDevice.get(), &NetworkManager::Device::stateChanged, this, &DeviceManagerRealize::onStatusChanged); + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + if (!wirelessDevice.isNull()) { + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::accessPointAppeared, this, &DeviceManagerRealize::onWirelessConnectionChanged); + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::accessPointDisappeared, this, &DeviceManagerRealize::onWirelessConnectionChanged); + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::activeAccessPointChanged, this, &DeviceManagerRealize::onWirelessConnectionChanged); + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::modeChanged, this, [ this ] { + bool oldEnabled = m_hotspotEnabled; + m_hotspotEnabled = getHotspotIsEnabled(); + if (m_hotspotEnabled) + setDeviceStatus(DeviceStatus::Disconnected); + if (oldEnabled != m_hotspotEnabled) + Q_EMIT hotspotEnableChanged(m_hotspotEnabled); + }); + } + } + + QDBusConnection::systemBus().connect("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", "DeviceEnabled", this, SLOT(onDeviceEnabledChanged(QDBusObjectPath, bool))); +} + +DeviceManagerRealize::~DeviceManagerRealize() +{ +} + +bool DeviceManagerRealize::isEnabled() const +{ + QDBusInterface dbusInter("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", QDBusConnection::systemBus()); + QDBusPendingCall reply = dbusInter.asyncCall("IsDeviceEnabled", m_wDevice->uni()); + reply.waitForFinished(); + QDBusPendingReply replyResult = reply.reply(); + return replyResult.argumentAt(0).toBool(); +} + +QString DeviceManagerRealize::interface() const +{ + return m_wDevice->interfaceName(); +} + +QString DeviceManagerRealize::driver() const +{ + return m_wDevice->driver(); +} + +bool DeviceManagerRealize::managed() const +{ + return m_wDevice->managed(); +} + +QString DeviceManagerRealize::vendor() const +{ + return QString(); +} + +QString DeviceManagerRealize::uniqueUuid() const +{ + return m_wDevice->udi(); +} + +bool DeviceManagerRealize::usbDevice() const +{ + return false; +} + +QString DeviceManagerRealize::path() const +{ + return m_wDevice->uni(); +} + +QString DeviceManagerRealize::activeAp() const +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + AccessPoint::Ptr ap = wirelessDevice->activeAccessPoint(); + if (ap) + return ap->ssid(); + } + + return QString(); +} + +bool DeviceManagerRealize::supportHotspot() const +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + return (wirelessDevice->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap)); + } + + return false; +} + +QString DeviceManagerRealize::realHwAdr() const +{ + if (m_wDevice->type() == NetworkManager::Device::Ethernet) { + QSharedPointer device = m_wDevice.staticCast(); + return device->hardwareAddress(); + } + + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + QSharedPointer device = m_wDevice.staticCast(); + return device->hardwareAddress(); + } + + return QString(); +} + +QString DeviceManagerRealize::usingHwAdr() const +{ + return QString(); +} + +const QStringList DeviceManagerRealize::ipv4() +{ + if (!device() || !device()->isConnected() || !isEnabled()) + return QStringList(); + + NetworkManager::IpAddresses ipv4AddrList = m_wDevice->ipV4Config().addresses(); + QStringList ipv4s; + for (const IpAddress &ipAddr : ipv4AddrList) + ipv4s << ipAddr.ip().toString(); + + return ipv4s; +} + +const QStringList DeviceManagerRealize::ipv6() +{ + if (!device() || !device()->isConnected() || !isEnabled()) + return QStringList(); + + NetworkManager::IpAddresses ipv6AddrList = m_wDevice->ipV6Config().addresses(); + QStringList ipv6s; + for (const IpAddress &ipAddr : ipv6AddrList) + ipv6s << ipAddr.ip().toString(); + + return ipv6s; +} + +QJsonObject DeviceManagerRealize::activeConnectionInfo() const +{ + return QJsonObject(); +} + +void DeviceManagerRealize::setEnabled(bool enabled) +{ + bool currentEnabled = isEnabled(); + if (currentEnabled != enabled) { + qInfo() << "set Device " << m_wDevice->uni() << " enabled:" << (enabled ? "true" : "false"); + QDBusInterface dbusInter("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", QDBusConnection::systemBus()); + QDBusReply reply = dbusInter.call("EnableDevice", m_wDevice->uni(), enabled); + if (enabled) { + // 如果是开启,则让其自动连接 + QString activeConnectionPath = reply.value().path(); + if (activeConnectionPath != "/") { + NetworkManager::activateConnection(activeConnectionPath, m_wDevice->uni(), QString()); + qInfo() << "connected:" << activeConnectionPath; + } + } + } +} + +void DeviceManagerRealize::disconnectNetwork() +{ + NetworkManager::ActiveConnection::Ptr activeConnection = m_wDevice->activeConnection(); + if (!activeConnection.isNull()) + NetworkManager::deactivateConnection(activeConnection->path()); +} + +QList DeviceManagerRealize::accessPointItems() const +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) + return m_accessPoints; + + return QList(); +} + +void DeviceManagerRealize::scanNetwork() +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + NetworkManager::WirelessDevice::Ptr device = m_wDevice.staticCast(); + device->requestScan(); +} + +void DeviceManagerRealize::connectNetwork(const AccessPoints *item) +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + WirelessConnection *conn = findConnectionByAccessPoint(item, m_wirelessConnections); + if (conn) + NetworkManager::activateConnection(conn->connection()->path(), m_wDevice->uni(), ""); +} + +QList DeviceManagerRealize::wirelessItems() const +{ + return m_wirelessConnections; +} + +AccessPoints *DeviceManagerRealize::activeAccessPoints() const +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return nullptr; + + QSharedPointer device = m_wDevice.staticCast(); + AccessPoint::Ptr currentActiveAp = device->activeAccessPoint(); + if (!currentActiveAp.isNull()) { + for (AccessPoints *ap : m_accessPoints) { + if (ap->ssid() == currentActiveAp->ssid()) + return ap; + } + } + + return nullptr; +} + +bool DeviceManagerRealize::connectNetwork(WiredConnection *connection) +{ + if (m_wDevice->type() != NetworkManager::Device::Ethernet) + return false; + + NetworkManager::activateConnection(connection->connection()->path(), m_wDevice->uni(), ""); + return true; +} + +QList DeviceManagerRealize::wiredItems() const +{ + return m_wiredConnections; +} + +void DeviceManagerRealize::onWiredConnectionChanged() +{ + if (m_wDevice->type() != NetworkManager::Device::Ethernet) + return; + + NetworkManager::Connection::List connections = m_wDevice->availableConnections(); + QList newConnection; + QList allConnection; + for (QSharedPointer conn : connections) { + if (conn->settings()->connectionType() != ConnectionSettings::ConnectionType::Wired) + continue; + + QJsonObject json = createConnectionJson(conn); + WiredConnection *wiredConn = findWiredConnection(conn->path()); + if (!wiredConn) { + wiredConn = new WiredConnection(); + newConnection << wiredConn; + } + wiredConn->setConnection(json); + allConnection << wiredConn; + } + QList rmConnection; + for (WiredConnection *conn : m_wiredConnections) { + if (!allConnection.contains(conn)) { + m_wiredConnections.removeOne(conn); + rmConnection << conn; + } + } + sortWiredItem(allConnection); + + m_wiredConnections = allConnection; + if (newConnection.size() > 0 || rmConnection.size() > 0) { + if (newConnection.size() > 0) + Q_EMIT connectionAdded(newConnection); + + if (rmConnection.size() > 0) + Q_EMIT connectionRemoved(rmConnection); + + for (WiredConnection *conn : rmConnection) { + if (conn == m_activeWiredConnection) + m_activeWiredConnection = Q_NULLPTR; + + delete conn; + } + } +} + +void DeviceManagerRealize::changeWiredStatus(Device::State newstate) +{ + if (m_wDevice->type() != NetworkManager::Device::Ethernet) + return; + + // 查看当前活动连接是否存在与连接列表中,如果不存在,就将当前活动连接置空 + if (m_activeWiredConnection && !m_wiredConnections.contains(m_activeWiredConnection)) + m_activeWiredConnection = Q_NULLPTR; + + ConnectionStatus oldStatus = ConnectionStatus::Unknown; + if (m_activeWiredConnection) + oldStatus = m_activeWiredConnection->status(); + + NetworkManager::ActiveConnection::Ptr activeConn = m_wDevice->activeConnection(); + if (activeConn.isNull()) { + // 断开了连接以后,如果以前存在连接,则向外抛出断开的信号 + if (m_activeWiredConnection) { + m_activeWiredConnection->setConnectionStatus(ConnectionStatus::Deactivated); + m_activeWiredConnection = nullptr; + Q_EMIT activeConnectionChanged(); + } + return; + } + + WiredConnection *currentConnection = findWiredConnectionByUuid(activeConn->uuid()); + if (!currentConnection) { + return; + } + + ConnectionStatus newStatus = convertStatus(newstate); + if (m_activeWiredConnection && currentConnection != m_activeWiredConnection) { + m_activeWiredConnection->setConnectionStatus(ConnectionStatus::Deactivated); + oldStatus = ConnectionStatus::Unknown; + } + if(oldStatus != newStatus){ + m_activeWiredConnection = currentConnection; + currentConnection->setConnectionStatus(newStatus); + Q_EMIT activeConnectionChanged(); + } +} + +void DeviceManagerRealize::changeWirelessStatus(Device::State newstate) +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + if (m_activeWirelessConnection && !m_wirelessConnections.contains(m_activeWirelessConnection)) + m_activeWirelessConnection = Q_NULLPTR; + + ConnectionStatus oldStatus = ConnectionStatus::Unknown; + if (m_activeWirelessConnection) { + AccessPoints *activePoint = findAccessPoints(m_activeWirelessConnection->connection()->ssid()); + if (activePoint) + oldStatus = activePoint->status(); + } + + NetworkManager::ActiveConnection::Ptr activeConn = m_wDevice->activeConnection(); + if (activeConn.isNull()) { + if (m_activeWirelessConnection) { + AccessPoints *ap = findAccessPoints(m_activeWirelessConnection->connection()->ssid()); + if (ap) + ap->updateConnectionStatus(ConnectionStatus::Deactivated); + + m_activeWirelessConnection = nullptr; + Q_EMIT activeConnectionChanged(); + } + return; + } + + WirelessConnection *currentConnection = findWirelessConnectionBySsid(activeConn->id()); + if (!currentConnection) { + Q_EMIT activeConnectionChanged(); + return; + } + + if (m_activeWirelessConnection && m_activeWirelessConnection != currentConnection) { + AccessPoints *ap = findAccessPoints(m_activeWirelessConnection->connection()->ssid()); + if (ap) + ap->updateConnectionStatus(ConnectionStatus::Deactivated); + oldStatus = ConnectionStatus::Unknown; + } + + ConnectionStatus newStatus = convertStatus(newstate); + if (newStatus != oldStatus) { + m_activeWirelessConnection = currentConnection; + AccessPoints *ap = findAccessPoints(currentConnection->connection()->ssid()); + if (ap) { + ap->updateConnectionStatus(newStatus); + Q_EMIT activeConnectionChanged(); + } + } +} + +WirelessConnection *DeviceManagerRealize::findWirelessConnectionByUuid(const QString &uuid) +{ + for (WirelessConnection *conn : m_wirelessConnections) { + if (conn->connection()->uuid() == uuid) + return conn; + } + + return Q_NULLPTR; +} + +void DeviceManagerRealize::changeStatus(Device::State newstate) +{ + // 转换当前获取的状态为设备的状态 + setDeviceStatus(convertDeviceStatus(newstate)); + switch (m_wDevice->type()) { + case NetworkManager::Device::Ethernet: + changeWiredStatus(newstate); + break; + case NetworkManager::Device::Wifi: + changeWirelessStatus(newstate); + break; + default: break; + } +} + +bool DeviceManagerRealize::getHotspotIsEnabled() +{ + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + NetworkManager::WirelessDevice::OperationMode mode = wirelessDevice->mode(); + return (mode == NetworkManager::WirelessDevice::OperationMode::ApMode); +} + +bool DeviceManagerRealize::hotspotEnabled() +{ + return m_hotspotEnabled; +} + +void DeviceManagerRealize::onStatusChanged(Device::State newstate, Device::State oldstate, Device::StateChangeReason reason) +{ + Q_UNUSED(oldstate); + Q_UNUSED(reason); + + changeStatus(newstate); +} + +void DeviceManagerRealize::onDeviceEnabledChanged(QDBusObjectPath path, bool enabled) +{ + if (m_wDevice && m_wDevice->uni() == path.path()) { + Q_EMIT enableChanged(enabled); + } +} + +WiredConnection *DeviceManagerRealize::findWiredConnectionByUuid(const QString &uuid) +{ + for (WiredConnection *conn : m_wiredConnections) { + if (conn->connection()->uuid() == uuid) + return conn; + } + + return Q_NULLPTR; +} + +void DeviceManagerRealize::onWirelessConnectionChanged() +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + NetworkManager::Connection::List connections = m_wDevice->availableConnections(); + QList newConnection; + QList allConnection; + for (QSharedPointer conn : connections) { + if (conn->settings()->connectionType() != ConnectionSettings::ConnectionType::Wireless) + continue; + + const QJsonObject json = createConnectionJson(conn); + WirelessConnection *wirelessConn = findWirelessConnection(conn->path()); + if (!wirelessConn) { + wirelessConn = new WirelessConnection(); + newConnection << wirelessConn; + } + + wirelessConn->setConnection(json); + allConnection << wirelessConn; + } + + createWlans(allConnection); +} + +void DeviceManagerRealize::createWlans(QList &allConnections) +{ + QList newAps, allAccessPoints; + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + NetworkManager::WirelessNetwork::List networks = wirelessDevice->networks(); + for (QSharedPointer network : networks) { + QSharedPointer ap = network->referenceAccessPoint(); + const QJsonObject json = createWlanJson(ap); + AccessPoints *accessPoint = findAccessPoints(ap->ssid()); + if (!accessPoint) { + accessPoint = new AccessPoints(json); + accessPoint->m_devicePath = path(); + newAps << accessPoint; + } else { + accessPoint->updateAccessPoints(json); + } + + allAccessPoints << accessPoint; + } + QList rmAps; + for (AccessPoints *ap : m_accessPoints) { + if (!allAccessPoints.contains(ap)) { + m_accessPoints.removeOne(ap); + rmAps << ap; + } + } + // 在信号发送之前同步accessPoints数据,因为在抛出信号后,外面可能通过获取内部所有的WLAN数据来更新内容,此时需要保证WLAN列表是最新的 + m_accessPoints = allAccessPoints; + // 确保激活的在列表中 + AccessPoint::Ptr activeAp = wirelessDevice->activeAccessPoint(); + if (!activeAp.isNull()) { + const QJsonObject json = createWlanJson(activeAp); + AccessPoints *accessPoint = findAccessPoints(activeAp->ssid()); + if (!accessPoint) { + accessPoint = new AccessPoints(json); + newAps << accessPoint; + allAccessPoints << accessPoint; + m_accessPoints << accessPoint; + } else { + accessPoint->updateAccessPoints(json); + } + } + syncWlanAndConnections(allConnections); + + // 删除不存在的Connections,也放在信号发送之前,原因和accessPoints一样 + QList rmConnections; + for (WirelessConnection *conn : m_wirelessConnections) { + if (!allConnections.contains(conn) && !rmConnections.contains(conn)) + rmConnections << conn; + } + + if (rmConnections.contains(m_activeWirelessConnection)) + m_activeWirelessConnection = Q_NULLPTR; + + m_wirelessConnections = allConnections; + + if (rmAps.size() > 0 || newAps.size() > 0) { + if (newAps.size() > 0) { + Q_EMIT networkAdded(newAps); + // 新增无线网络之前最好先刷新网络列表状态,因为考虑到连接隐藏网络的时候,没有触发网络状态变化信号,因此此处需要手动调用 + changeStatus(m_wDevice->state()); + } + + if (rmAps.size() > 0) + Q_EMIT networkRemoved(rmAps); + + for (AccessPoints *ap : rmAps) + delete ap; + } + + // 删除无用的数据 + for (WirelessConnection *rmConn : rmConnections) + delete rmConn; +} + +void DeviceManagerRealize::syncWlanAndConnections(QList &allConnections) +{ + if (m_accessPoints.isEmpty()) { + clearListData(allConnections); + return; + } + + QList connections; + // 找到每个热点对应的Connection,并将其赋值 + for (AccessPoints *accessPoint : m_accessPoints) { + WirelessConnection *connection = findConnectionByAccessPoint(accessPoint, allConnections); + if (!connection) { + connection = WirelessConnection::createConnection(accessPoint); + m_wirelessConnections << connection; + } + + connection->m_accessPoints = accessPoint; + connections << connection; + } + // 删除列表中没有AccessPoints的Connection,让两边保持数据一致 + QList rmConns; + for (WirelessConnection *connection : allConnections) { + if (!connections.contains(connection)) + rmConns << connection; + } + + for (WirelessConnection *rmConnection : rmConns) { + allConnections.removeOne(rmConnection); + + // 如果当前所有的无线连接列表中有不存在的连接,那么需要将其从无线连接中移除,然后再delete + // 因为后面会将m_wirelessConnections中不存在于allConnections的连接delete,如果 + // 此处不从m_wirelessConnections移除掉这个connection,那么后面就会出现删除两次引起报错 + if (m_wirelessConnections.contains(rmConnection)) + m_wirelessConnections.removeOne(rmConnection); + + delete rmConnection; + } + + allConnections = connections; +} + +AccessPoints *DeviceManagerRealize::findAccessPoints(const QString &ssid) +{ + for (AccessPoints *ap : m_accessPoints) { + if (ap->ssid() == ssid) + return ap; + } + + return Q_NULLPTR; +} + +QJsonObject DeviceManagerRealize::createWlanJson(QSharedPointer ap) +{ + QJsonObject jsonObject; + jsonObject.insert("Ssid", ap->ssid()); + jsonObject.insert("Strength", ap->signalStrength()); + bool secured = ap->capabilities() == AccessPoint::Capability::Privacy || ap->wpaFlags() != 0 || ap->rsnFlags() != 0; + jsonObject.insert("Secured", secured); + jsonObject.insert("SecuredInEap", secured); + jsonObject.insert("Flags", static_cast(ap->capabilities())); + int frequency = static_cast(ap->frequency()); + jsonObject.insert("Frequency", frequency); + jsonObject.insert("Path", ap->uni()); + return jsonObject; +} + +QJsonObject DeviceManagerRealize::createConnectionJson(QSharedPointer networkConnection) +{ + QJsonObject json; + json.insert("Path", networkConnection->path()); + json.insert("Uuid", networkConnection->uuid()); + json.insert("Id", networkConnection->settings()->id()); + json.insert("HwAddress", realHwAdr()); + json.insert("ClonedAddress", realHwAdr()); + json.insert("Ssid", networkConnection->name()); + return json; +} + +WirelessConnection *DeviceManagerRealize::findConnectionByAccessPoint(const AccessPoints *accessPoint, QList &allConnections) +{ + for (WirelessConnection *connection : allConnections) { + if (connection->accessPoints() == accessPoint) + return connection; + + if (connection->connection()->ssid() == accessPoint->ssid()) + return connection; + } + + return Q_NULLPTR; +} + +WiredConnection *DeviceManagerRealize::findWiredConnection(const QString &path) +{ + for (WiredConnection *connection : m_wiredConnections) { + if (connection->connection()->path() == path) + return connection; + } + + return Q_NULLPTR; +} + +WirelessConnection *DeviceManagerRealize::findWirelessConnectionBySsid(const QString &ssid) +{ + for (WirelessConnection *connection : m_wirelessConnections) { + if (connection->connection()->ssid() == ssid) + return connection; + } + + return Q_NULLPTR; +} + +WirelessConnection *DeviceManagerRealize::findWirelessConnection(const QString &path) +{ + for (WirelessConnection *connection : m_wirelessConnections) { + if (connection->connection()->path() == path) + return connection; + } + + return Q_NULLPTR; +} + +ConnectionStatus DeviceManagerRealize::convertStatus(Device::State state) +{ + switch (state) { + case Device::State::Failed: + case Device::State::Unmanaged: + case Device::State::Unavailable: + case Device::State::Disconnected: + return ConnectionStatus::Deactivated; + case Device::State::Preparing: + case Device::State::NeedAuth: + case Device::State::CheckingIp: + case Device::State::ConfiguringIp: + case Device::State::ConfiguringHardware: + case Device::State::WaitingForSecondaries: + return ConnectionStatus::Activating; + case Device::State::Activated: + return ConnectionStatus::Activated; + case Device::State::Deactivating: + return ConnectionStatus::Deactivating; + default: break; + } + + return ConnectionStatus::Unknown; +} + +DeviceStatus DeviceManagerRealize::convertDeviceStatus(Device::State state) +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + // 如果当前网卡开启了热点,则认为它是连接断开的状态 + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + if (wirelessDevice->mode() == NetworkManager::WirelessDevice::OperationMode::ApMode) + return DeviceStatus::Disconnected; + } + switch (state) { + case Device::State::Failed: + return DeviceStatus::Failed; + case Device::State::NeedAuth: + return DeviceStatus::Needauth; + case Device::State::Activated: + return DeviceStatus::Activated; + case Device::State::Preparing: + return DeviceStatus::Prepare; + case Device::State::Unmanaged: + return DeviceStatus::Unmanaged; + case Device::State::CheckingIp: + return DeviceStatus::IpCheck; + case Device::State::Unavailable: + return DeviceStatus::Unavailable; + case Device::State::Deactivating: + return DeviceStatus::Deactivation; + case Device::State::Disconnected: + return DeviceStatus::Disconnected; + case Device::State::ConfiguringIp: + case Device::State::ConfiguringHardware: + return DeviceStatus::Config; + case Device::State::WaitingForSecondaries: + return DeviceStatus::Secondaries; + default: break; + } + + return DeviceStatus::Unknown; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.h b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.h new file mode 100644 index 000000000..98e5de6cb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.h @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEVICEMANAGERREALIZE_H +#define DEVICEMANAGERREALIZE_H + +#include "netinterface.h" + +#include + +namespace NetworkManager { +class WirelessNetwork; +class AccessPoint; +} + +using namespace NetworkManager; + +namespace dde { +namespace network { + +class DeviceManagerRealize : public NetworkDeviceRealize +{ + Q_OBJECT + +public: + explicit DeviceManagerRealize(IPConfilctChecker *ipChecker, QSharedPointer device, QObject *parent = nullptr); + ~DeviceManagerRealize() override; + +protected: + bool isEnabled() const override; // 当前的网卡是否启用 + QString interface() const override; // 返回设备上的Interface + QString driver() const override; // 驱动,对应于备上返回值的Driver + bool managed() const override; // 对应于设备上返回值的Managed + QString vendor() const override; // 对应于设备上返回值的Vendor + QString uniqueUuid() const override; // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + bool usbDevice() const override; // 是否是USB设备,对应于设备上返回值的UsbDevice + QString path() const override; // 设备路径,对应于设备上返回值的Path + QString activeAp() const override; // 对应于设备上返回值的ActiveAp + bool supportHotspot() const override; // 是否支持热点,对应于设备上返回值的SupportHotspot + QString realHwAdr() const override; // mac地址 + QString usingHwAdr() const override; // 正在使用的mac地址 + const QStringList ipv4() override; // IPV4地址 + const QStringList ipv6() override; // IPV6地址 + QJsonObject activeConnectionInfo() const override; // 获取当前活动连接的信息 + void setEnabled(bool enabled) override; // 开启或禁用网卡 + void disconnectNetwork() override; // 断开网络连接,该方法是一个虚方法,具体在子类 + + // 无线网络接口 + QList accessPointItems() const override; // 当前网卡上所有的网络列表 + void scanNetwork() override; // 重新加载所有的无线网络列表 + void connectNetwork(const AccessPoints *item) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + QList wirelessItems() const override; // 无线网络连接列表 + AccessPoints *activeAccessPoints() const override; // 当前活动的无线连接 + + // 有线网络接口 + bool connectNetwork(WiredConnection *connection) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + QList wiredItems() const override; // 有线网络连接列表 + +private: + template + void clearListData(QList &dataList) { + for (T *data : dataList) + delete data; + + dataList.clear(); + } + +private: + void initSigSlotConnection(); + void createWlans(QList &allConnections); + void syncWlanAndConnections(QList &allConnections); + + AccessPoints *findAccessPoints(const QString &ssid); + QJsonObject createWlanJson(QSharedPointer ap); + QJsonObject createConnectionJson(QSharedPointer networkConnection); + WirelessConnection *findConnectionByAccessPoint(const AccessPoints *accessPoint, QList &allConnections); + + WiredConnection *findWiredConnection(const QString &path); + WiredConnection *findWiredConnectionByUuid(const QString &uuid); + WirelessConnection *findWirelessConnectionBySsid(const QString &ssid); + WirelessConnection *findWirelessConnection(const QString &path); + WirelessConnection *findWirelessConnectionByUuid(const QString &uuid); + ConnectionStatus convertStatus(Device::State state); + DeviceStatus convertDeviceStatus(Device::State state); + + void changeWiredStatus(Device::State newstate); + void changeWirelessStatus(Device::State newstate); + void changeStatus(Device::State newstate); + + bool getHotspotIsEnabled(); + bool hotspotEnabled() override; + +private slots: + void onWiredConnectionChanged(); + void onWirelessConnectionChanged(); + void onStatusChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); + void onDeviceEnabledChanged(QDBusObjectPath path, bool enabled); + +private: + QSharedPointer m_wDevice; + QList m_accessPoints; + QList m_wiredConnections; + QList m_wirelessConnections; + WiredConnection *m_activeWiredConnection; + WirelessConnection *m_activeWirelessConnection; + bool m_hotspotEnabled; + QQueue m_statusQueue; +}; + +} +} +#endif // DEVICEMANAGERREALIZE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.cpp new file mode 100644 index 000000000..7376642d0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.cpp @@ -0,0 +1,386 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "netinterface.h" +#include "networkdevicebase.h" + +#include +#include + +namespace dde { +namespace network { + +NetworkProcesser::NetworkProcesser(QObject *parent) + : QObject (parent) +{ +} + +NetworkProcesser::~NetworkProcesser() +{ +} + +QList NetworkProcesser::networkDetails() +{ + return QList(); +} + +ProxyController *NetworkProcesser::proxyController() +{ + return Q_NULLPTR; +} + +VPNController *NetworkProcesser::vpnController() +{ + return Q_NULLPTR; +} + +DSLController *NetworkProcesser::dslController() +{ + return Q_NULLPTR; +} + +HotspotController *NetworkProcesser::hotspotController() +{ + return Q_NULLPTR; +} + +void NetworkProcesser::updateDeviceName() +{ + QList wiredDevice; + QList wirelessDevice; + + QList allDevices = this->devices(); + for (NetworkDeviceBase *device : allDevices) { + if (device->deviceType() == DeviceType::Wired) + wiredDevice << device; + else if (device->deviceType() == DeviceType::Wireless) + wirelessDevice << device; + } + + // 更改有线设备的名称 + if (wiredDevice.size() == 1) { + wiredDevice[0]->setName(tr("Wired Network")); + } else if (wiredDevice.size() > 1) { + for (int i = 0; i < wiredDevice.size(); i++) { + QString name = QString(tr("Wired Network %1")).arg(i + 1); + wiredDevice[i]->setName(name); + } + } + + // 更改无线设备的名称 + if (wirelessDevice.size() == 1) { + wirelessDevice[0]->setName(tr("Wireless Network")); + } else if (wirelessDevice.size() > 1) { + for (int i = 0; i < wirelessDevice.size(); i++) { + QString name = QString(tr("Wireless Network %1")).arg(i + 1); + wirelessDevice[i]->setName(name); + } + } +} + +void NetworkProcesser::retranslate() +{ + updateDeviceName(); +} + +/** + * @brief 设备接口基类,具体实现在子类中实现 + * @return + */ +void NetworkDeviceRealize::setDevice(NetworkDeviceBase *device) +{ + m_device = device; +} + +bool NetworkDeviceRealize::isEnabled() const +{ + return false; +} + +bool NetworkDeviceRealize::IPValid() +{ + // 判读获取IP地址失败需要满足最后一个状态为未连接,上一个状态为失败,并且包含Config和IpConfig + return !(m_statusQueue.size() == MaxQueueSize + && m_statusQueue[MaxQueueSize - 1] == DeviceStatus::Disconnected + && m_statusQueue[MaxQueueSize - 2] == DeviceStatus::Failed + && m_statusQueue.contains(DeviceStatus::Config) + && m_statusQueue.contains(DeviceStatus::IpConfig)); +} + +QString NetworkDeviceRealize::interface() const +{ + return QString(); +} + +QString NetworkDeviceRealize::driver() const +{ + return QString(); +} + +bool NetworkDeviceRealize::managed() const +{ + return false; +} + +QString NetworkDeviceRealize::vendor() const +{ + return QString(); +} + +QString NetworkDeviceRealize::uniqueUuid() const +{ + return QString(); +} + +bool NetworkDeviceRealize::usbDevice() const +{ + return false; +} + +QString NetworkDeviceRealize::path() const +{ + return QString(); +} + +QString NetworkDeviceRealize::activeAp() const +{ + return QString(); +} + +bool NetworkDeviceRealize::supportHotspot() const +{ + return false; +} + +QString NetworkDeviceRealize::realHwAdr() const +{ + return QString(); +} + +QString NetworkDeviceRealize::usingHwAdr() const +{ + return QString(); +} + +const QStringList NetworkDeviceRealize::ipv4() +{ + return QStringList(); +} + +const QStringList NetworkDeviceRealize::ipv6() +{ + return QStringList(); +} + +QJsonObject NetworkDeviceRealize::activeConnectionInfo() const +{ + return QJsonObject(); +} + +void NetworkDeviceRealize::setEnabled(bool enabled) +{ + Q_UNUSED(enabled); +} + +void NetworkDeviceRealize::disconnectNetwork() +{ +} + +Connectivity NetworkDeviceRealize::connectivity() +{ + return m_connectivity; +} + +DeviceStatus NetworkDeviceRealize::deviceStatus() const +{ + if (m_ipConflicted) + return DeviceStatus::IpConfilct; + + return m_deviceStatus; +} + +QList NetworkDeviceRealize::accessPointItems() const +{ + return QList(); +} + +void NetworkDeviceRealize::connectNetwork(const AccessPoints *item) +{ + Q_UNUSED(item); +} + +QList NetworkDeviceRealize::wirelessItems() const +{ + return QList(); +} + +AccessPoints *NetworkDeviceRealize::activeAccessPoints() const +{ + return nullptr; +} + +bool NetworkDeviceRealize::connectNetwork(WiredConnection *connection) +{ + Q_UNUSED(connection); + return false; +} + +QList NetworkDeviceRealize::wiredItems() const +{ + return QList(); +} + +NetworkDeviceRealize::NetworkDeviceRealize(IPConfilctChecker *ipConflictChecker, QObject *parent) + : QObject (parent) + , m_device(nullptr) + , m_connectivity(Connectivity::Full) + , m_deviceStatus(DeviceStatus::Unknown) + , m_ipConflictChecker(ipConflictChecker) + , m_ipConflicted(false) +{ + Q_ASSERT(m_ipConflictChecker); + connect(m_ipConflictChecker, &IPConfilctChecker::conflictStatusChanged, this, &NetworkDeviceRealize::onConflictStatusChanged); +} + +NetworkDeviceRealize::~NetworkDeviceRealize() +{ +} + +NetworkDeviceBase *NetworkDeviceRealize::device() const +{ + return m_device; +} + +QString NetworkDeviceRealize::statusStringDetail() +{ + if (!isEnabled() || !m_device) + return tr("Device disabled"); + + if (m_deviceStatus == DeviceStatus::Activated && m_connectivity != Connectivity::Full) + return tr("Connected but no Internet access"); + + // 确认 没有获取IP显示未连接状态(DHCP服务关闭) + if (!IPValid()) + return tr("Not connected"); + + switch (m_deviceStatus) { + case DeviceStatus::Unknown: + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: { + switch (m_device->deviceType()) { + case DeviceType::Unknown: return QString(); + case DeviceType::Wired: return tr("Network cable unplugged"); + default: break; + } + break; + } + case DeviceStatus::Disconnected: return tr("Not connected"); + case DeviceStatus::Prepare: + case DeviceStatus::Config: return tr("Connecting"); + case DeviceStatus::Needauth: return tr("Authenticating"); + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: + case DeviceStatus::Secondaries: return tr("Obtaining IP address"); + case DeviceStatus::Activated: return tr("Connected"); + case DeviceStatus::Deactivation: return tr("Disconnected"); + case DeviceStatus::IpConfilct: return tr("IP conflict"); + default: break; + } + + return tr("Failed"); +} + +QString NetworkDeviceRealize::getStatusName() +{ + if (hotspotEnabled()) + return tr("Disconnected"); + + switch (m_deviceStatus) { + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: + case DeviceStatus::Disconnected: return tr("Disconnected"); + case DeviceStatus::Prepare: + case DeviceStatus::Config: return tr("Connecting"); + case DeviceStatus::Needauth: return tr("Authenticating"); + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: return tr("Obtaining address"); + case DeviceStatus::Activated: return tr("Connected"); + case DeviceStatus::Deactivation: return tr("Disconnected"); + case DeviceStatus::Failed: return tr("Failed"); + case DeviceStatus::IpConfilct: return tr("IP conflict"); + default:; + } + + return QString(); +} + +void NetworkDeviceRealize::enqueueStatus(const DeviceStatus &status) +{ + if (m_statusQueue.size() >= MaxQueueSize) + m_statusQueue.dequeue(); + + m_statusQueue.enqueue(status); +} + +void NetworkDeviceRealize::setDeviceStatus(const DeviceStatus &status) +{ + if (m_deviceStatus == status) + return; + + m_deviceStatus = status; + enqueueStatus(status); + // 状态发生变化后,需要向外抛出一个信号 + Q_EMIT deviceStatusChanged(status); +} + +void NetworkDeviceRealize::sortWiredItem(QList &items) +{ + // 按照最后面的数字从小到大排序,如果名字中没有数字,就按照创建的先后顺序来排序(path数字的大小) + std::sort(items.begin(), items.end(), [ ] (WiredConnection *conn1, WiredConnection *conn2) { + QString lastChar1 = conn1->connection()->id().right(1); + QString lastChar2 = conn2->connection()->id().right(1); + int rightCount = 3; + int index1 = 0; + int index2 = 0; + bool ok1 = false, ok2 = false; + do { + if (!ok1) { + lastChar1 = conn1->connection()->id().right(rightCount); + index1 = lastChar1.toInt(&ok1); + } + if (!ok2) { + lastChar2 = conn2->connection()->id().right(rightCount); + index2 = lastChar2.toInt(&ok2); + } + if ((ok1 && ok2) || rightCount <= 0) + break; + + rightCount--; + } while (true); + + if (ok1 && ok2) + return index1 < index2; + QString path1 = conn1->connection()->path(); + QString path2 = conn2->connection()->path(); + path1 = path1.replace("\\", "/"); + path2 = path2.replace("\\", "/"); + QString configName1 = path1.mid(path1.lastIndexOf("/") + 1); + QString configName2 = path2.mid(path2.lastIndexOf("/") + 1); + return configName1.toInt() < configName2.toInt(); + }); +} + +void NetworkDeviceRealize::onConflictStatusChanged(NetworkDeviceBase *device, const bool confilcted) +{ + if (device != m_device) + return; + + if (m_ipConflicted != confilcted) { + m_ipConflicted = confilcted; + Q_EMIT deviceStatusChanged(deviceStatus()); + } +} + +} +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.h b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.h new file mode 100644 index 000000000..7de0c1a94 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.h @@ -0,0 +1,150 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETINTERFACE_H +#define NETINTERFACE_H + +#include "networkconst.h" + +#include +#include + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class ProxyController; +class VPNController; +class DSLController; +class HotspotController; +class NetworkDetails; +class DSLItem; +class VPNItem; +class HotspotItem; +class WirelessDevice; +class AccessPoints; +class WiredDevice; +class WiredConnection; +class WirelessConnection; +class IPConfilctChecker; + +class NetworkProcesser : public QObject +{ + Q_OBJECT + +public: + virtual QList devices() = 0; + virtual Connectivity connectivity() = 0; + virtual QList networkDetails(); + virtual ProxyController *proxyController(); // 返回代理控制管理器 + virtual VPNController *vpnController(); // 返回VPN控制器 + virtual DSLController *dslController(); // DSL控制器 + virtual HotspotController *hotspotController(); // 个人热点控制器 + virtual void retranslate(); // 更新翻译 + +protected: + explicit NetworkProcesser(QObject *parent); + virtual ~NetworkProcesser(); + +Q_SIGNALS: + void deviceAdded(QList); // 新增设备发出的信号 + void deviceRemoved(QList); // 移除设备发出的信号 + void connectivityChanged(const Connectivity &) const; // 网络连接状态发生变化的时候发出的信号 + void connectionChanged(); // 连接信息发生变化的时候触发的信号 + void activeConnectionChange(); // 网络数据发生变化 + +protected: + void updateDeviceName(); // 更新设备名称 +}; + +class NetworkDeviceRealize : public QObject +{ + Q_OBJECT + + friend class NetworkDeviceBase; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +Q_SIGNALS: + void deviceStatusChanged(const DeviceStatus &) const; // 状态发生变化的时候触发的信号 + void enableChanged(const bool) const; // 开启设备或禁用设备的时候发出的信号(参数值True表示开启设备,False表示禁用设备) + void connectionChanged(); // 连接发生变化的时候触发的信号 + void nameChanged(const QString &); // 网卡名称发生变化的时候触发的信号 + void removed(); // 设备移除 + // 无线网络信号 + void networkAdded(QList); // wlan新增网络 + void networkRemoved(QList); // wlan列表减少网络 + void connectionSuccess(const AccessPoints *); // 连接无线网络wlan成功,参数为对应的wlan + void hotspotEnableChanged(const bool &); // 热点是否可用发生变化 + void accessPointInfoChanged(const QList &); // wlan信号强度发生变化的网络 + void activeConnectionChanged(); // 活动连接发生变化的时候发出的信号 + // 有线设备的信号 + void connectionAdded(const QList); // 新增连接 + void connectionRemoved(const QList); // 删除连接 + void connectionPropertyChanged(const QList &); // 连接属性发生变化 + void ipV4Changed(); // IPv4地址发生变化 + +public: + void setDevice(NetworkDeviceBase *device); // 设置当前的设备 + virtual bool isEnabled() const; // 当前的网卡是否启用 + virtual bool IPValid(); // IP是否合法 + virtual QString interface() const; // 返回设备上的Interface + virtual QString driver() const; // 驱动,对应于备上返回值的Driver + virtual bool managed() const; // 对应于设备上返回值的Managed + virtual QString vendor() const; // 对应于设备上返回值的Vendor + virtual QString uniqueUuid() const; // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + virtual bool usbDevice() const; // 是否是USB设备,对应于设备上返回值的UsbDevice + virtual QString path() const; // 设备路径,对应于设备上返回值的Path + virtual QString activeAp() const; // 对应于设备上返回值的ActiveAp + virtual bool supportHotspot() const; // 是否支持热点,对应于设备上返回值的SupportHotspot + virtual QString realHwAdr() const; // mac地址 + virtual QString usingHwAdr() const; // 正在使用的mac地址 + virtual const QStringList ipv4(); // IPV4地址 + virtual const QStringList ipv6(); // IPV6地址 + virtual QJsonObject activeConnectionInfo() const; // 获取当前活动连接的信息 + virtual void setEnabled(bool enabled); // 开启或禁用网卡 + virtual void disconnectNetwork(); // 断开网络连接,该方法是一个虚方法,具体在子类 + Connectivity connectivity(); + virtual DeviceStatus deviceStatus() const; + + // 无线网络接口 + virtual QList accessPointItems() const; // 当前网卡上所有的网络列表 + virtual void scanNetwork() {} // 重新加载所有的无线网络列表 + virtual void connectNetwork(const AccessPoints *item); // 连接网络,连接成功抛出deviceStatusChanged信号 + virtual QList wirelessItems() const; // 无线网络连接列表 + virtual AccessPoints *activeAccessPoints() const; // 当前活动的无线连接 + virtual bool hotspotEnabled() { return false; } // 无线网络是否开启热点 + + // 有线网络接口 + virtual bool connectNetwork(WiredConnection *connection); // 连接网络,连接成功抛出deviceStatusChanged信号 + virtual QList wiredItems() const; // 有线网络连接列表 + +protected: + NetworkDeviceRealize(IPConfilctChecker *ipConflictChecker, QObject *parent); + virtual ~NetworkDeviceRealize(); + + NetworkDeviceBase *device() const; + + virtual QString statusStringDetail(); + virtual QString getStatusName(); + void enqueueStatus(const DeviceStatus &status); + virtual void setDeviceStatus(const DeviceStatus &status); + void sortWiredItem(QList &items); + +private Q_SLOTS: + void onConflictStatusChanged(NetworkDeviceBase *device, const bool confilcted); + +private: + NetworkDeviceBase *m_device; + Connectivity m_connectivity; + QQueue m_statusQueue; + DeviceStatus m_deviceStatus; + IPConfilctChecker *m_ipConflictChecker; + bool m_ipConflicted; +}; + +} +} + +#endif // INTERFACE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.cpp new file mode 100644 index 000000000..7759c76e9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.cpp @@ -0,0 +1,683 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkinterprocesser.h" +#include "ipconfilctchecker.h" +#include "networkdbusproxy.h" + +#include "dslcontroller.h" +#include "hotspotcontroller.h" +#include "networkdetails.h" +#include "networkdevicebase.h" +#include "proxycontroller.h" +#include "vpncontroller.h" +#include "wireddevice.h" +#include "wirelessdevice.h" +#include "deviceinterrealize.h" + +#include +#include +#include + +namespace dde { +namespace network { + + +#define CHANGE_CONNECTIONS "ConnectionsChanged" +#define CHANGE_ACTIVECONNECTIONS "ActiveConnectionsChanged" +#define CHANGE_WIRELESSACCESSPOINTS "WirelessAccessPointsChanged" + +NetworkInterProcesser::NetworkInterProcesser(bool sync, bool ipCheck, QObject *parent) + : NetworkProcesser(parent) + , m_proxyController(Q_NULLPTR) + , m_vpnController(Q_NULLPTR) + , m_dslController(Q_NULLPTR) + , m_hotspotController(Q_NULLPTR) + , m_networkInter(new NetworkDBusProxy(this)) + , m_connectivity(Connectivity::Full) + , m_sync(sync) + , m_changedTimer(new QTimer(this)) + , m_ipChecker(new IPConfilctChecker(this, ipCheck)) +{ + initConnection(); + initDeviceService(); +} + +NetworkInterProcesser::~NetworkInterProcesser() +{ + m_ipChecker->release(); + m_ipChecker->deleteLater(); +} + +void NetworkInterProcesser::initNetData(NetworkDBusProxy *networkInt) +{ + onDevicesChanged(networkInt->devices()); + doChangeConnectionList(networkInt->connections()); + doChangeAccesspoint(networkInt->wirelessAccessPoints()); + doChangeActiveConnections(networkInt->activeConnections()); +} + +void NetworkInterProcesser::updateSync(const bool sync) +{ + m_sync = sync; +} + +void NetworkInterProcesser::initDeviceService() +{ + // 同步的方式来获取设备列表和连接列表 + initNetData(m_networkInter); +} + +void NetworkInterProcesser::initConnection() +{ + // 定为100毫秒内,基本上连接、活动连接和热点发生变化的时候都会在100毫秒内发出信号 + // 这里需要用一个timer来执行,因为在实际情况中,ConnectionsChanged信号和ActiveConnectionsChanged信号发出的前后顺序 + // 可能会乱,如果先发送ActiveConnectionsChanged,而此时ConnectionsChanged信号却还没有发出来,此时连接列表可能为空(初次启动) + // 导致后发出的ConnectionsChanged中的所有的连接获取到的连接状态可能是错误的,所以此处用一个定时器来接收,这样就算发送的顺序是乱的, + // 但是它们都能在100毫秒内全部返回,这样在定时器里按照顺序来处理这些信号的数据,保证数据的准确性 + m_changedTimer->setInterval(100); + auto onDataChanged = [ this ](const char *infoName, const QString infoValue) { + // 这里需要用QStringList来保存,因为对于ActiveConnectionsChanged信号来说,在多个网卡存在的情况下,这个信号会发送多次 + // 每次的内容可能会不一样,例如断开连接,第一次发送的信号是第一个网卡的连接状态,第二次发送的信号是第二个网卡的连接状态,必须保证每个 + // 信号都能被正确接收并处理,否则就会出现信号丢失引起状态不正确的问题 + QStringList infoValues = m_changedTimer->property(infoName).toStringList(); + // 移除重复的,不能调用QStringList的removeDuplicates方法,因为这样移除可能会导致将最新的给移除引起错误 + if (infoValues.contains(infoValue)) + infoValues.removeOne(infoValue); + infoValues << infoValue; + m_changedTimer->setProperty(infoName, infoValues); + if (!m_changedTimer->isActive()) + m_changedTimer->start(); + }; + + connect(m_changedTimer, &QTimer::timeout, this, &NetworkInterProcesser::onConnectionInfoChanged); + connect(m_networkInter, &NetworkDBusProxy::DevicesChanged, this, &NetworkInterProcesser::onDevicesChanged); // 设备状态发生变化 + connect(m_networkInter, &NetworkDBusProxy::ConnectionsChanged, this, [ onDataChanged ](const QString &connections) { // 连接发生变化 + onDataChanged(CHANGE_CONNECTIONS, connections); + }); + connect(m_networkInter, &NetworkDBusProxy::ActiveConnectionsChanged, this, [ onDataChanged ](const QString &activeConnections) { // 当前活动连接发生变化 + onDataChanged(CHANGE_ACTIVECONNECTIONS, activeConnections); + }); + connect(m_networkInter, &NetworkDBusProxy::WirelessAccessPointsChanged, this, [ onDataChanged ](const QString &accessPoints) { // 热点发生变化 + onDataChanged(CHANGE_WIRELESSACCESSPOINTS, accessPoints); + }); + connect(m_networkInter, &NetworkDBusProxy::DeviceEnabled, this, &NetworkInterProcesser::onDeviceEnableChanged); // 关闭设备或启用设备 + + connect(m_networkInter, &NetworkDBusProxy::ConnectivityChanged, this, &NetworkInterProcesser::onConnectivityChanged); // 网络状态发生变化 + + connect(m_networkInter, &NetworkDBusProxy::ActiveConnectionInfoChanged, this, [this] { + QString activeConnectionInfo = m_networkInter->GetActiveConnectionInfo(); + activeConnInfoChanged(activeConnectionInfo); + }); +} + +NetworkDeviceBase *NetworkInterProcesser::findDevices(const QString &path) const +{ + // 查找指定路径的设备 + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == path) + return device; + } + + return Q_NULLPTR; +} + +static DeviceType deviceType(const QString &type) +{ + if (type == "wireless") + return DeviceType::Wireless; + + if (type == "wired") + return DeviceType::Wired; + + return DeviceType::Unknown; +} + +void NetworkInterProcesser::onDevicesChanged(const QString &value) +{ + if (value.isEmpty()) + return; + + bool unManager = false; + const QJsonObject data = QJsonDocument::fromJson(value.toUtf8()).object(); + QStringList devPaths; + QList newDevices; + QStringList keys = data.keys(); + for (int i = 0; i < keys.size(); i++) { + QString key = keys[i]; + DeviceType type = deviceType(key); + if (type == DeviceType::Unknown) + continue; + + QJsonArray deviceList = data.value(key).toArray(); + for (const QJsonValue jsonValue : deviceList) { + const QJsonObject &deviceInfo = jsonValue.toObject(); + const QString path = deviceInfo.value("Path").toString(); + if (!deviceInfo.value("Managed").toBool()) { + // 如果managed为false,且在设备列表中未找到,则不添加到设备 + NetworkDeviceBase *device = findDevices(path); + if (!device) + continue; + + unManager = true; + } + + // 根据标志位InterfaceFlags判断网络连接是否有效(无线网络不需要根据这个标志位来判断,因为无线网络在开启飞行模式后,这个标志位会变成0,但是需要显示无线网卡) + if (type != DeviceType::Wireless) { + if (!deviceInfo.value("InterfaceFlags").isUndefined()) { + if (!(deviceInfo.value("InterfaceFlags").toInt() & DEVICE_INTERFACE_FLAG_UP)) { + continue; + } + } + } + + NetworkDeviceBase *device = findDevices(path); + if (!device) { + switch (type) { + case DeviceType::Wireless: { + DeviceInterRealize *wirelessRealize = new WirelessDeviceInterRealize(m_ipChecker, m_networkInter, nullptr); + device = new WirelessDevice(wirelessRealize, this); + wirelessRealize->updateDeviceInfo(deviceInfo); + break; + } + case DeviceType::Wired: { + DeviceInterRealize *wiredRealize = new WiredDeviceInterRealize(m_ipChecker, m_networkInter, nullptr); + device = new WiredDevice(wiredRealize, this); + wiredRealize->updateDeviceInfo(deviceInfo); + break; + } + default: + break; + } + if (device) { + newDevices << device; + m_devices << device; + } + } else { + DeviceInterRealize *deviceRealized = static_cast(device->deviceRealize()); + deviceRealized->updateDeviceInfo(deviceInfo); + } + if (device) { + // 将所有的设备路径添加到缓存中 + if (!devPaths.contains(device->path())) + devPaths << device->path(); + } + } + } + // 对设备进行排序,有线网络始终排在无线网络前面 + auto getPathIndex = [ ](const QString path)->int { + int index = path.lastIndexOf("/"); + QString tmpIndexValue = path.mid(index + 1); + return tmpIndexValue.toInt(); + }; + + std::sort(m_devices.begin(), m_devices.end(), [ = ] (NetworkDeviceBase *dev1, NetworkDeviceBase *dev2) { + if (dev1->deviceType() == DeviceType::Wired && dev2->deviceType() == DeviceType::Wireless) + return true; + + if (dev1->deviceType() == DeviceType::Wireless && dev2->deviceType() == DeviceType::Wired) + return false; + + return getPathIndex(dev1->path()) < getPathIndex(dev2->path()); + }); + // 更新设备的连接信息,因为读取设备状态信息的时候,需要这个连接信息 + updateDeviceConnectiveInfo(); + // 删除已经移除的设备 + QList rmDevices; + for (NetworkDeviceBase *device : m_devices) { + if (!devPaths.contains(device->path())) + rmDevices << device; + } + + for (NetworkDeviceBase *device : rmDevices) + m_devices.removeOne(device); + + if (newDevices.size() > 0 || rmDevices.size() > 0) { + // 更新设备名称 + updateDeviceName(); + + // 告诉外面新增的设备列表 + if (newDevices.size() > 0) { + // 初始化设备的数据,包括设备是否可用等信息 + bool wirelessExist = false; + for (NetworkDeviceBase *device : newDevices) { + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->initDeviceInfo(); + if (device->deviceType() == DeviceType::Wireless) + wirelessExist = true; + } + + // 更新设备的时候,同时需要更新连接信息,因为可能连接的信号发生在设备更新信息之前 + updateConnectionsInfo(newDevices); + // 如果新增的设备中存在无线网卡,则同时需要更新wlan的信息,因为存在如下情况 + // 如果关闭热点的时候,会先移除设备,然后再新增设备,此时如果不更新wlan,这种情况下,新增的那个无线设备的wlan就会为空 + if (wirelessExist) + doChangeAccesspoint(m_networkInter->wirelessAccessPoints()); + } + // 设备列表发生变化的同时,需要同时更新网络连接状态 + doChangeActiveConnections(m_networkInter->activeConnections()); + + // 设备列表发生变化的同时,需要同时更新DSL的相关的信息,因为DSL里面用到了设备的信息,需要获取设备路径等 + updateDSLData(); + + // 设备列表发生变化后,同时也需要更新设备热点的信息 + updateDeviceHotpot(); + + // 发送删除的设备列表信号,此时这些设备对象还未析构,外面调用来处理响应的操作,统一在一个线程中处理 + if (rmDevices.size() > 0) { + for (NetworkDeviceBase *device : rmDevices) + Q_EMIT device->removed(); + + Q_EMIT deviceRemoved(rmDevices); + // 在移除设备后,需要立刻将网络详情中对应的项移除 + updateNetworkDetails(); + } + + // 需要将新增设备的信号放到更新设备数据之后,因为外部接收到新增设备信号的时候,需要更新设备信息,如果放到更新设备数据前面,则里面的数据不是最新的数据 + if (newDevices.size() > 0) + Q_EMIT deviceAdded(newDevices); + + // 一定要将删除设备放到最后,因为在发出信号后,外面可能还会用到 + for (NetworkDeviceBase *device : rmDevices) + delete device; + } + // 如果发现有Manager=false的对象,则让它等一秒后从设备列表中移除manager==false的对象,因为可能是关闭热点引起的Manager=false + if (unManager) { + QTimer::singleShot(1000, this, [ this ] { + QList unManagerDevices; + for (NetworkDeviceBase *device : m_devices) { + if (!device->managed()) + unManagerDevices << device; + } + + if (unManagerDevices.size() > 0) { + for (NetworkDeviceBase *device : unManagerDevices) + m_devices.removeOne(device); + + for (NetworkDeviceBase *device : unManagerDevices) + Q_EMIT device->removed(); + + Q_EMIT deviceRemoved(unManagerDevices); + // 在移除设备后,需要立刻将网络详情中对应的项移除 + updateNetworkDetails(); + // 删除对象 + for (NetworkDeviceBase *device : unManagerDevices) + delete device; + } + }); + } +} + +void NetworkInterProcesser::doChangedData(changedFunction func, const char *infoName) +{ + QStringList changeDatas = m_changedTimer->property(infoName).toStringList(); + if (!changeDatas.isEmpty()) { + for (QString changeData : changeDatas) + (this->*func)(changeData); + + changeDatas.clear(); + m_changedTimer->setProperty(infoName, changeDatas); + } +} + +void NetworkInterProcesser::onConnectionInfoChanged() +{ + // 触发数据改变的顺序,1.无线网络 2.连接信息 3.活动连接信息,理由如下 + // 连接信息中更新无线连接的时候,需要从无线网络中获取wlan数据进行同步,所以需要先同步无线网络(wlan), + // 活动连接信息需要更新的是已经存在的连接,因此需要先同步连接信息,活动连接信息放到最后同步 + doChangedData(&NetworkInterProcesser::doChangeAccesspoint, CHANGE_WIRELESSACCESSPOINTS); + doChangedData(&NetworkInterProcesser::doChangeConnectionList, CHANGE_CONNECTIONS); + doChangedData(&NetworkInterProcesser::doChangeActiveConnections, CHANGE_ACTIVECONNECTIONS); + if (m_changedTimer->isActive()) + m_changedTimer->stop(); +} + +void NetworkInterProcesser::doChangeConnectionList(const QString &connections) +{ + if (connections.isEmpty()) + return; + + m_connections = QJsonDocument::fromJson(connections.toUtf8()).object(); + updateConnectionsInfo(m_devices); + + // 更新VPN的数据 + if (m_vpnController && m_connections.contains("vpn")) + m_vpnController->updateVPNItems(m_connections.value("vpn").toArray()); + + // 更新DSL的数据 + updateDSLData(); + + // 更新热点的数据 + updateDeviceHotpot(); + + // 向外抛出信号告知连接发生了变化 + Q_EMIT connectionChanged(); +} + +void NetworkInterProcesser::doChangeActiveConnections(const QString &activeConnections) +{ + // 初次进来的时候,活动连接内容为空,此时需要返回。 + // 如果不判断这个的话,那么在初始化的时候就会向外部发送activeConnectionChange信号,引起网络列表的显示的问题 + if (activeConnections.isEmpty()) + return; + + activeInfoChanged(activeConnections); + // 同步IP地址等信息 + QString activeConnectionInfo =m_networkInter->GetActiveConnectionInfo(); + activeConnInfoChanged(activeConnectionInfo); + onConnectivityChanged(m_networkInter->connectivity()); + updateDeviceConnectiveInfo(); +} + +void NetworkInterProcesser::updateDeviceConnectiveInfo() +{ + for (NetworkDeviceBase *device : m_devices) + device->deviceRealize()->m_connectivity = m_connectivity; +} + +void NetworkInterProcesser::activeConnInfoChanged(const QString &conns) +{ + // 当没有激活的连接时,需要更新对应的连接信息和网络详细信息为空 + if (conns == "null") { + for (NetworkDeviceBase *device : m_devices){ + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateActiveConnectionInfo(QList()); + m_networkDetails.clear(); + } + + Q_EMIT activeConnectionChange(); + + return; + } + + QJsonParseError error; + m_activeConnectionInfo = QJsonDocument::fromJson(conns.toUtf8(), &error).array(); + if (error.error == QJsonParseError::NoError) { + QMultiMap deviceInfoMap; + for (QJsonValue jsonValue : m_activeConnectionInfo) { + QJsonObject connInfo = jsonValue.toObject(); + const QString devPath = connInfo.value("Device").toString(); + NetworkDeviceBase *device = findDevices(devPath); + if (!device) + continue; + + deviceInfoMap.insert(device, connInfo); + } + + for (auto it = deviceInfoMap.begin(); it != deviceInfoMap.end(); it++) { + NetworkDeviceBase *device = it.key(); + QList json = deviceInfoMap.values(device); + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateActiveConnectionInfo(json); + } + // 对于没有发送的设备,直接让其显示空 + for (NetworkDeviceBase *device : m_devices) { + if (!deviceInfoMap.contains(device)) { + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateActiveConnectionInfo(QList()); + } + } + } + // 同时需要更新网络信息 + updateNetworkDetails(); + + Q_EMIT activeConnectionChange(); +} + +void NetworkInterProcesser::doChangeAccesspoint(const QString &accessPoints) +{ + if (accessPoints.isEmpty()) + return; + + const QJsonObject json = QJsonDocument::fromJson(accessPoints.toUtf8()).object(); + + for (NetworkDeviceBase *device : m_devices) { + // 只有无线网卡才会有wlan连接信息 + if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *d = static_cast(device); + if (json.contains(d->path())) { + QJsonArray array = json.value(d->path()).toArray(); + + WirelessDeviceInterRealize *deviceRealize = qobject_cast(d->deviceRealize()); + if (deviceRealize) + deviceRealize->updateAccesspoint(array); + } + } + } +} + +void NetworkInterProcesser::onDeviceEnableChanged(const QString &devicePath, bool enabled) +{ + NetworkDeviceBase *device = findDevices(devicePath); + if (device) { + DeviceInterRealize *interDevice = static_cast(device->deviceRealize()); + interDevice->setDeviceEnabledStatus(enabled); + // 如果改设备是无线设备,且支持热点,则更新热点的信息 + if (!m_hotspotController) + return; + // 如果当前设备是无线设备切当前设备支持热点,则更新当前设备的热点信息 + if (device->deviceType() == DeviceType::Wireless && device->supportHotspot()) + updateDeviceHotpot(); + } +} + +void NetworkInterProcesser::onConnectivityChanged(uint conectivity) +{ + Connectivity conn = static_cast(conectivity); + if (conn == m_connectivity) + return; + + m_connectivity = conn; + updateDeviceConnectiveInfo(); + Q_EMIT connectivityChanged(m_connectivity); +} + +void NetworkInterProcesser::updateConnectionsInfo(const QList &devices) +{ + if (devices.isEmpty() || m_connections.isEmpty()) + return; + + static QList> devConnInfo + = {{ "wired", DeviceType::Wired }, { "wireless", DeviceType::Wireless }}; + + for (const QPair &connInfo : devConnInfo) { + if (m_connections.contains(connInfo.first)) { + const QJsonArray &connlist = m_connections.value(connInfo.first).toArray(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == connInfo.second) { + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateConnection(connlist); + } + } + } + } +} + +void NetworkInterProcesser::activeInfoChanged(const QString &conns) +{ + // 当前活动连接发生变化 + m_activeConection = QJsonDocument::fromJson(conns.toUtf8()).object(); + QMap> devActiveConn; + for (const QJsonValue info : m_activeConection) { + const QJsonObject connInfo = info.toObject(); + const QJsonArray devArray = connInfo.value("Devices").toArray(); + for (const QJsonValue &value : devArray) { + const QString devPath = value.toString(); + devActiveConn[devPath] << connInfo; + } + } + + // 更新DSL的活动连接信息 + if (m_dslController) + m_dslController->updateActiveConnections(m_activeConection); + + // 更新设备的活动连接信息 + for (auto it = devActiveConn.begin(); it != devActiveConn.end(); it++) { + const QString devPath = it.key(); + NetworkDeviceBase *device = findDevices(devPath); + if (!device) + continue; + + const QList devInfos = it.value(); + DeviceInterRealize *deviceInt = static_cast(device->deviceRealize()); + deviceInt->updateActiveInfo(devInfos); + } + + // 更新热点的活动连接信息 + if (m_hotspotController) + m_hotspotController->updateActiveConnection(m_activeConection); + + // 更新VPN的活动连接信息 + if (m_vpnController) + m_vpnController->updateActiveConnection(m_activeConection); +} + +Connectivity NetworkInterProcesser::connectivity() +{ + return m_connectivity; +} + +QList NetworkInterProcesser::devices() +{ + return m_devices; +} + +QList NetworkInterProcesser::networkDetails() +{ + return m_networkDetails; +} + +void NetworkInterProcesser::updateDeviceHotpot() +{ + if (!m_hotspotController) + return; + + m_hotspotController->updateDevices(m_devices); + + if (!m_connections.contains("wireless-hotspot")) + return; + + const QJsonArray hotspots = m_connections.value("wireless-hotspot").toArray(); + // 更新连接的信息 + m_hotspotController->updateConnections(hotspots); +} + +void NetworkInterProcesser::updateNetworkDetails() +{ + QStringList devicePaths; + for (NetworkDeviceBase *device : m_devices) { + if (!device->isEnabled()) + continue; + + devicePaths << device->path(); + } + + + // 删除多余的网络详情的数据 + if (m_networkDetails.size() >= m_activeConnectionInfo.size()) { + for (int i = m_networkDetails.size() - 1; i >= m_activeConnectionInfo.size(); i--) { + NetworkDetails *detail = m_networkDetails[i]; + m_networkDetails.removeOne(detail); + delete detail; + } + } + + // 遍历网络详情列表,更新内存中的记录 + for (int i = 0; i < m_activeConnectionInfo.size(); i++) { + QJsonObject activeConnection = m_activeConnectionInfo.at(i).toObject(); + + NetworkDetails *detail = Q_NULLPTR; + if (i < m_networkDetails.size()) { + detail = m_networkDetails[i]; + } else { + detail = new NetworkDetails(this); + m_networkDetails << detail; + } + + detail->updateData(activeConnection); + } + + // 删除不在设备列表中的项 + const auto details = m_networkDetails; + for (NetworkDetails *detail : details) { + if (!devicePaths.contains(detail->devicePath())) { + m_networkDetails.removeOne(detail); + delete detail; + } + } + + if (m_devices.size() > 0) { + std::sort(m_networkDetails.begin(), m_networkDetails.end(), [ & ] (NetworkDetails *detail1, NetworkDetails *detail2) { + int index1 = -1; + int index2 = -1; + for (int i = 0; i < m_devices.size(); i++) { + NetworkDeviceBase *device = m_devices[i]; + if (device->path() == detail1->devicePath()) + index1 = i; + else if (device->path() == detail2->devicePath()) + index2 = i; + } + + return index1 < index2; + }); + } +} + +void NetworkInterProcesser::updateDSLData() +{ + if (!m_dslController || !m_connections.contains("pppoe")) + return; + + m_dslController->updateDevice(m_devices); + m_dslController->updateDSLItems(m_connections.value("pppoe").toArray()); + m_dslController->updateActiveConnections(m_activeConection); +} + +ProxyController *NetworkInterProcesser::proxyController() +{ + // 因为有的地方不会调用这个接口,所以该对象延迟创建 + if (!m_proxyController) + m_proxyController = new ProxyController(m_networkInter, this); + + return m_proxyController; +} + +VPNController *NetworkInterProcesser::vpnController() +{ + // 延迟创建 + if (!m_vpnController) { + m_vpnController = new VPNController(m_networkInter, this); + if (m_connections.contains("vpn")) + m_vpnController->updateVPNItems(m_connections.value("vpn").toArray()); + m_vpnController->updateActiveConnection(m_activeConection); + } + + return m_vpnController; +} + +DSLController *NetworkInterProcesser::dslController() +{ + // 延迟创建 + if (!m_dslController) { + m_dslController = new DSLController(m_networkInter, this); + updateDSLData(); + } + + return m_dslController; +} + +HotspotController *NetworkInterProcesser::hotspotController() +{ + // 延迟创建 + if (!m_hotspotController) { + m_hotspotController = new HotspotController(m_networkInter, this); + updateDeviceHotpot(); + m_hotspotController->updateActiveConnection(m_activeConection); + } + + return m_hotspotController; +} + +} +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.h b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.h new file mode 100644 index 000000000..93cbd1687 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.h @@ -0,0 +1,98 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPROCESSER_H +#define NETWORKPROCESSER_H + +#include "netinterface.h" +#include "netutils.h" + +#include + +class QTimer; + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class ProxyController; +class VPNController; +class DSLController; +class HotspotController; +class NetworkDetails; +class IPConfilctChecker; +class NetworkDBusProxy; + +class NetworkInterProcesser : public NetworkProcesser +{ + Q_OBJECT + + friend class NetworkController; + + typedef void (NetworkInterProcesser::*changedFunction)(const QString &); + +protected: + explicit NetworkInterProcesser(bool sync, bool ipCheck, QObject *parent); + ~NetworkInterProcesser() override; + + void initDeviceService(); + void initConnection(); + void initNetData(NetworkDBusProxy *networkInt); // 填充基本数据 + + void updateSync(const bool sync); + + NetworkDeviceBase *findDevices(const QString &path) const; // 根据设备path查找设备 + void updateConnectionsInfo(const QList &devices); // 更新设备连接信息 + void activeInfoChanged(const QString &conns); // 更新活动连接信息 + void updateDeviceConnectiveInfo(); // 更新设备信号连接强度信息 + void activeConnInfoChanged(const QString &conns); // 活动连接信息发生变化 + void updateDeviceHotpot(); // 更新热点设备数据 + + void updateNetworkDetails(); // 更新网络连接信息 + + void updateDSLData(); // 更新DSL的数据 + void updateVPNActiveConnection(); // 更新VPN的活动连接信息 + + void doChangeConnectionList(const QString &connections); + void doChangeActiveConnections(const QString &activeConnections); + void doChangeAccesspoint(const QString &accessPoints); + + void doChangedData(changedFunction func, const char *infoName); + +protected: + ProxyController *proxyController() override; // 返回代理控制管理器 + VPNController *vpnController() override; // 返回VPN控制器 + DSLController *dslController() override; // DSL控制器 + HotspotController *hotspotController() override; // 个人热点控制器 + Connectivity connectivity() override; // 获取当前的信号 + QList devices() override; // 获取当前的所有的设备 + QList networkDetails() override; // 获取设备的网络详情 + +protected Q_SLOTS: + void onDevicesChanged(const QString &value); + void onConnectionInfoChanged(); // 变化的网络连接的状态 + void onDeviceEnableChanged(const QString &devicePath, bool enabled); + void onConnectivityChanged(uint conectivity); + +private: + ProxyController *m_proxyController; + VPNController *m_vpnController; + DSLController *m_dslController; + HotspotController *m_hotspotController; + QList m_devices; + NetworkDBusProxy *m_networkInter; + QJsonObject m_connections; + Connectivity m_connectivity; + QJsonArray m_activeConnectionInfo; + QJsonObject m_activeConection; + QList m_networkDetails; + bool m_sync; + QTimer *m_changedTimer; + IPConfilctChecker *m_ipChecker; +}; + +} +} + +#endif // NETWORKPROCESSER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.cpp new file mode 100644 index 000000000..bb7e3329f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.cpp @@ -0,0 +1,317 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "devicemanagerrealize.h" +#include "dslcontroller.h" +#include "hotspotcontroller.h" +#include "networkdevicebase.h" +#include "networkmanagerprocesser.h" +#include "proxycontroller.h" +#include "vpncontroller.h" +#include "ipconfilctchecker.h" +#include "networkdbusproxy.h" + +#include +#include +#include + +#include +#include + +#include +#include + +using namespace dde::network; +using namespace NetworkManager; + +const static QString networkService = "org.deepin.dde.Network1"; +const static QString networkPath = "/org/deepin/dde/Network1"; + +NetworkManagerProcesser::NetworkManagerProcesser(QObject *parent) + : NetworkProcesser(parent) + , m_proxyController(Q_NULLPTR) + , m_vpnController(Q_NULLPTR) + , m_dslController(Q_NULLPTR) + , m_hotspotController(Q_NULLPTR) + , m_networkInter(Q_NULLPTR) + , m_connectivity(dde::network::Connectivity::Unknownconnectivity) + , m_ipChecker(new IPConfilctChecker(this, false)) +{ + Device::List allDevices = NetworkManager::networkInterfaces(); + for (Device::Ptr device : allDevices) + onDeviceAdded(device->uni()); + + initConnections(); + onConnectivityChanged(NetworkManager::connectivity()); +} + +NetworkManagerProcesser::~NetworkManagerProcesser() +{ + m_ipChecker->release(); + m_ipChecker->deleteLater(); +} + +void NetworkManagerProcesser::initConnections() +{ + connect(NetworkManager::notifier(), &Notifier::deviceAdded, this, &NetworkManagerProcesser::onDeviceAdded); + connect(NetworkManager::notifier(), &Notifier::deviceRemoved, this, &NetworkManagerProcesser::onDeviceRemove); + connect(NetworkManager::notifier(), &Notifier::connectivityChanged, this, &NetworkManagerProcesser::onConnectivityChanged); + QDBusConnection::systemBus().connect("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", "DeviceEnabled", this, SLOT(onDeviceEnabledChanged(QDBusObjectPath, bool))); +} + +QList NetworkManagerProcesser::devices() +{ + return m_devices; +} + +dde::network::Connectivity NetworkManagerProcesser::connectivity() +{ + return m_connectivity; +} + +QList NetworkManagerProcesser::networkDetails() +{ + return m_details; +} + +ProxyController *NetworkManagerProcesser::proxyController() +{ + if (!m_proxyController) + m_proxyController = new ProxyController(networkInter(), this); + + return m_proxyController; +} + +VPNController *NetworkManagerProcesser::vpnController() +{ + if (!m_vpnController) + m_vpnController = new VPNController(networkInter(), this); + + return m_vpnController; +} + +DSLController *NetworkManagerProcesser::dslController() +{ + if (!m_dslController) + m_dslController = new DSLController(networkInter(), this); + + return m_dslController; +} + +HotspotController *NetworkManagerProcesser::hotspotController() +{ + if (!m_hotspotController) + m_hotspotController = new HotspotController(networkInter(), this); + + return m_hotspotController; +} + +void NetworkManagerProcesser::sortDevice() +{ + auto getPathIndex = [](const QString path)->int { + int index = path.lastIndexOf("/"); + QString tmpIndexValue = path.mid(index + 1); + return tmpIndexValue.toInt(); + }; + // 有线网络始终在无线网络的前面,如果两者都是有线或者无线网络,则按照path的顺序来排序 + std::sort(m_devices.begin(), m_devices.end(), [ = ](NetworkDeviceBase *device1, NetworkDeviceBase *device2) { + if (device1->deviceType() == DeviceType::Wired && device2->deviceType() == DeviceType::Wireless) + return true; + + if (device1->deviceType() == DeviceType::Wireless && device2->deviceType() == DeviceType::Wired) + return false; + + return getPathIndex(device1->path()) < getPathIndex(device2->path()); + }); +} + +void NetworkManagerProcesser::onDeviceAdded(const QString &uni) +{ + auto deviceExist = [ this ] (const QString &uni)->bool { + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == uni) + return true; + } + + return false; + }; + + if (deviceExist(uni)) + return; + + Device::Ptr currentDevice(nullptr); + Device::List allDevices = NetworkManager::networkInterfaces(); + for (Device::Ptr device : allDevices) { + if (device->uni() != uni) + continue; + + if (device->type() == Device::Wifi || device->type() == Device::Ethernet) + currentDevice = device; + + break; + } + + if (!currentDevice) + return; + + auto createDevice = [ = ](const Device::Ptr &device)->NetworkDeviceBase * { + if (device->type() == Device::Wifi) { + // 无线网络 + NetworkManager::WirelessDevice::Ptr wDevice = device.staticCast(); + DeviceManagerRealize *deviceRealize = new DeviceManagerRealize(m_ipChecker, wDevice); + return new WirelessDevice(deviceRealize, Q_NULLPTR); + } + + if (device->type() == Device::Ethernet) { + // 有线网络 + NetworkManager::WiredDevice::Ptr wDevice = device.staticCast(); + DeviceManagerRealize *deviceRealize = new DeviceManagerRealize(m_ipChecker, wDevice); + return new WiredDevice(deviceRealize, Q_NULLPTR); + } + + return nullptr; + }; + + // 无线网卡不管是否down,都显示,因为在开启飞行模式后,需要显示网卡的信息 + auto deviceCreateOrRemove = [this, deviceExist, + createDevice](const Device::Ptr &device) { + bool hasFlag = true; + #ifdef USE_DEEPIN_NMQT + hasFlag = device->interfaceFlags() & DEVICE_INTERFACE_FLAG_UP; + #endif + if (device->managed() && (hasFlag || device->type() == Device::Wifi)) { + // 如果由非manager变成manager的模式,则新增设备 + if (!deviceExist(device->uni())) { + NetworkDeviceBase *newDevice = createDevice(device); + if (newDevice) { + m_devices << newDevice; + sortDevice(); + updateDeviceName(); + Q_EMIT deviceAdded({ newDevice }); + } + } + } else { + // 如果由manager变成非manager模式,则移除设备 + NetworkDeviceBase *rmDevice = nullptr; + for (NetworkDeviceBase *dev : m_devices) { + if (dev->path() == device->uni()) { + m_devices.removeOne(dev); + rmDevice = dev; + break; + } + } + if (rmDevice) { + Q_EMIT rmDevice->removed(); + sortDevice(); + updateDeviceName(); + Q_EMIT deviceRemoved({ rmDevice }); + delete rmDevice; + rmDevice = nullptr; + } + } + }; + + NetworkDeviceBase *newDevice = Q_NULLPTR; + bool hasFlag = true; +#ifdef USE_DEEPIN_NMQT + hasFlag = currentDevice->interfaceFlags() & DEVICE_INTERFACE_FLAG_UP; +#endif + if (currentDevice->managed() && (hasFlag || currentDevice->type() == Device::Wifi)) + newDevice = createDevice(currentDevice); +#ifdef USE_DEEPIN_NMQT + connect(currentDevice.get(), &Device::interfaceFlagsChanged, this, [ currentDevice, deviceCreateOrRemove ] { + deviceCreateOrRemove(currentDevice); + }); +#endif + connect(currentDevice.get(), &Device::managedChanged, this, [ currentDevice, deviceCreateOrRemove ] { + deviceCreateOrRemove(currentDevice); + }); + + if (newDevice) { + m_devices << newDevice; + sortDevice(); + updateDeviceName(); + Q_EMIT deviceAdded({ newDevice }); + } +} + +void NetworkManagerProcesser::onDeviceRemove(const QString &uni) +{ + NetworkDeviceBase *rmDevice = Q_NULLPTR; + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == uni) { + m_devices.removeOne(device); + rmDevice = device; + break; + } + } + + if (rmDevice) { + Q_EMIT rmDevice->removed(); + sortDevice(); + updateDeviceName(); + Q_EMIT deviceRemoved({ rmDevice }); + delete rmDevice; + } +} + +void NetworkManagerProcesser::onConnectivityChanged(NetworkManager::Connectivity conntity) +{ + dde::network::Connectivity ctity; + switch (conntity) { + case NetworkManager::Connectivity::Full: { + ctity = dde::network::Connectivity::Full; + break; + } + case NetworkManager::Connectivity::Portal: { + ctity = dde::network::Connectivity::Portal; + break; + } + case NetworkManager::Connectivity::Limited: { + ctity = dde::network::Connectivity::Limited; + break; + } + case NetworkManager::Connectivity::NoConnectivity: { + ctity = dde::network::Connectivity::Noconnectivity; + break; + } + case NetworkManager::Connectivity::UnknownConnectivity: { + ctity = dde::network::Connectivity::Unknownconnectivity; + break; + } + } + if (m_connectivity != ctity) { + m_connectivity = ctity; + for (NetworkDeviceBase *device : m_devices) { + DeviceManagerRealize *deviceRealize = static_cast(device->deviceRealize()); + deviceRealize->m_connectivity = m_connectivity; + } + Q_EMIT connectivityChanged(m_connectivity); + } +} + +void NetworkManagerProcesser::onDeviceEnabledChanged(QDBusObjectPath path, bool enabled) +{ + NetworkDeviceBase *device = findDevice(path.path()); + if (device) + Q_EMIT device->enableChanged(enabled); +} + +NetworkDeviceBase *NetworkManagerProcesser::findDevice(const QString devicePath) +{ + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == devicePath) + return device; + } + + return Q_NULLPTR; +} + +NetworkDBusProxy *NetworkManagerProcesser::networkInter() +{ + if (!m_networkInter) + m_networkInter = new NetworkDBusProxy(this); + + return m_networkInter; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.h b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.h new file mode 100644 index 000000000..3f61fa9b3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.h @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKMANAGERPROCESSER_H +#define NETWORKMANAGERPROCESSER_H + +#include "netinterface.h" +#include "networkconst.h" +#include "netutils.h" + +#include + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class IPConfilctChecker; +class NetworkDBusProxy; + +class NetworkManagerProcesser : public NetworkProcesser +{ + Q_OBJECT + +public: + explicit NetworkManagerProcesser(QObject *parent = Q_NULLPTR); + ~NetworkManagerProcesser() override; + +protected: + QList devices() override; + dde::network::Connectivity connectivity() override; + QList networkDetails() override; + ProxyController *proxyController() override; // 返回代理控制管理器 + VPNController *vpnController() override; // 返回VPN控制器 + DSLController *dslController() override; // DSL控制器 + HotspotController *hotspotController() override; // 个人热点控制器 + +private: + void initConnections(); + NetworkDeviceBase *findDevice(const QString devicePath); + NetworkDBusProxy *networkInter(); + void sortDevice(); + +private slots: + void onDeviceAdded(const QString &uni); + void onDeviceRemove(const QString &uni); + void onConnectivityChanged(NetworkManager::Connectivity conntity); + void onDeviceEnabledChanged(QDBusObjectPath path, bool enabled); + +private: + QList m_devices; + QList m_details; + ProxyController *m_proxyController; + VPNController *m_vpnController; + DSLController *m_dslController; + HotspotController *m_hotspotController; + NetworkDBusProxy *m_networkInter; + dde::network::Connectivity m_connectivity; + IPConfilctChecker *m_ipChecker; +}; + +} +} + +#endif // NETWORKMANAGERPROCESSER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.cpp new file mode 100644 index 000000000..29828672a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.cpp @@ -0,0 +1,172 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "vpncontroller.h" +#include "networkconst.h" +#include "networkdbusproxy.h" + +#include "networkmanagerqt/manager.h" + +#include + +using namespace dde::network; +using namespace NetworkManager; + +void VPNController::setEnabled(const bool enabled) +{ + m_networkInter->setVpnEnabled(enabled); +} + +void VPNController::connectItem(VPNItem *item) +{ + connectItem(item->connection()->uuid()); +} + +void VPNController::connectItem(const QString &uuid) +{ + m_networkInter->ActivateConnection(uuid, QDBusObjectPath("/")); +} + +void VPNController::disconnectItem() +{ + if (!m_activePath.isEmpty()) + deactivateConnection(m_activePath); +} + +VPNController::VPNController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) + , m_enabled(false) +{ + Q_ASSERT(m_networkInter); + connect(m_networkInter, &NetworkDBusProxy::VpnEnabledChanged, this, &VPNController::onEnableChanged); + onEnableChanged(m_networkInter->vpnEnabled()); +} + +VPNController::~VPNController() +{ +} + +void VPNController::updateVPNItems(const QJsonArray &vpnArrays) +{ + // 更新列表中的VPN状态 + QList newVpns; + QList changeVpns; + QStringList paths; + for (const QJsonValue jsonValue : vpnArrays) { + QJsonObject vpn = jsonValue.toObject(); + QString path = vpn.value("Path").toString(); + VPNItem *item = findItem(path); + if (!item) { + item = new VPNItem; + item->setConnection(vpn); + m_vpnItems << item; + newVpns << item; + } else { + if (item->connection()->id() != vpn.value("Id").toString()) + changeVpns << item; + + item->setConnection(vpn); + } + + paths << path; + } + + if (changeVpns.size()) + Q_EMIT itemChanged(changeVpns); + + if (newVpns.size()) + Q_EMIT itemAdded(newVpns); + + // 将列表中不存在的VPN删除 + QList rmVpns; + for (VPNItem *item : m_vpnItems) { + if (!paths.contains(item->connection()->path())) + rmVpns << item; + } + + for (VPNItem *item : rmVpns) + m_vpnItems.removeOne(item); + + if (rmVpns.size() > 0) + Q_EMIT itemRemoved(rmVpns); + + // 删除移除的对象 + for (VPNItem *item : rmVpns) + delete item; +} + +void VPNController::updateActiveConnection(const QJsonObject &activeConection) +{ + // 先将所有的连接都置为未连接状态 + QMap allConnectionStatus; + for (VPNItem *item : m_vpnItems) { + allConnectionStatus[item->connection()->uuid()] = item->status(); + item->setConnectionStatus(ConnectionStatus::Deactivated); + } + + // 获取当前所有的活动连接,并记录活动连接是否发生过变化 + m_activePath.clear(); + bool statusChanged = false; + QStringList keys = activeConection.keys(); + for (QString key : keys) { + QJsonObject json = activeConection.value(key).toObject(); + VPNItem *vpnItem = findItemByUuid(json.value("Uuid").toString()); + if (vpnItem) { + ConnectionStatus state = convertConnectionStatus(json.value("State").toInt()); + vpnItem->setConnectionStatus(state); + if (state == ConnectionStatus::Activated) + m_activePath = key; + + QString uuid = vpnItem->connection()->uuid(); + if (allConnectionStatus.contains(uuid)) { + ConnectionStatus oldStatus = allConnectionStatus[uuid]; + if (!statusChanged && oldStatus != state) + statusChanged = true; + } + } + } + + if (statusChanged) + Q_EMIT activeConnectionChanged(); +} + +VPNItem *VPNController::findItem(const QString &path) +{ + for (VPNItem *item : m_vpnItems) { + if (item->connection()->path() == path) + return item; + } + + return Q_NULLPTR; +} + +VPNItem *VPNController::findItemByUuid(const QString &uuid) +{ + for (VPNItem *item : m_vpnItems) { + if (item->connection()->uuid() == uuid) + return item; + } + + return Q_NULLPTR; +} + +void VPNController::onEnableChanged(const bool enabled) +{ + m_enabled = enabled; + Q_EMIT enableChanged(enabled); +} + +/** + * @brief UVPNItem详细项 + */ + +VPNItem::VPNItem() + : ControllItems() +{ +} + +VPNItem::~VPNItem() +{ +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.h b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.h new file mode 100644 index 000000000..485fccb00 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.h @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef VPNCONTROLLER_H +#define VPNCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include + +namespace dde { + +namespace network { +class NetworkDBusProxy; +class VPNItem; + +class VPNController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + void setEnabled(const bool enabled); // 开启或者关闭VPN + inline bool enabled() const { return m_enabled; } // VPN开启还是关闭 + void connectItem(VPNItem *item); // 连接VPN + void connectItem(const QString &uuid); // 连接VPN(重载函数) + void disconnectItem(); // 断开当前活动VPN连接 + inline QList items() { return m_vpnItems; } // 获取所有的VPN列表 + +Q_SIGNALS: + void enableChanged(const bool); // 开启关闭VPN发出的信号 + void itemAdded(const QList &); // 新增VPN发出的信号 + void itemRemoved(const QList &); // 移除VPN发出的信号 + void itemChanged(const QList &); // VPN项发生变化(ID) + void activeConnectionChanged(); // 活动连接发生变化的时候发出的信号 + +protected: + explicit VPNController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~VPNController(); + + void updateVPNItems(const QJsonArray &vpnArrays); + void updateActiveConnection(const QJsonObject &activeConection); + +private: + VPNItem *findItem(const QString &path); + VPNItem *findItemByUuid(const QString &uuid); + +private Q_SLOTS: + void onEnableChanged(const bool enabled); + +private: + NetworkDBusProxy *m_networkInter; + bool m_enabled; + QList m_vpnItems; + QString m_activePath; +}; + +class VPNItem : public ControllItems +{ + friend class VPNController; + +protected: + VPNItem(); + ~VPNItem(); +}; + +} + +} + +#endif // UVPNCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/wireddevice.cpp b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.cpp new file mode 100644 index 000000000..aa5a04e4d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.cpp @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "wireddevice.h" +#include "networkconst.h" +#include "realize/netinterface.h" + +using namespace dde::network; + +WiredDevice::WiredDevice(NetworkDeviceRealize *devcieRealize, QObject *parent) + : NetworkDeviceBase(devcieRealize, parent) +{ + connect(devcieRealize, &NetworkDeviceRealize::connectionAdded, this, &WiredDevice::connectionAdded); + connect(devcieRealize, &NetworkDeviceRealize::connectionRemoved, this, &WiredDevice::connectionRemoved); + connect(devcieRealize, &NetworkDeviceRealize::connectionPropertyChanged, this, &WiredDevice::connectionPropertyChanged); + connect(devcieRealize, &NetworkDeviceRealize::activeConnectionChanged, this, &WiredDevice::activeConnectionChanged); +} + +WiredDevice::~WiredDevice() +{ +} + +bool WiredDevice::connectNetwork(WiredConnection *connection) +{ + NetworkDeviceRealize *deviceInterface = deviceRealize(); + return deviceInterface->connectNetwork(connection); +} + +bool WiredDevice::connectNetwork(const QString &path) +{ + QList wiredItems = items(); + for (WiredConnection *connection : wiredItems) { + if (connection->connection()->path() == path) + return connectNetwork(connection); + } + + return false; +} + +bool WiredDevice::isConnected() const +{ + QList wiredItems = items(); + for (WiredConnection *connection : wiredItems) { + if (connection->connected()) + return true; + } + + return false; +} + +DeviceType WiredDevice::deviceType() const +{ + return DeviceType::Wired; +} + +QList WiredDevice::items() const +{ + return deviceRealize()->wiredItems(); +} + +WiredConnection::WiredConnection() + : ControllItems() +{ +} + +WiredConnection::~WiredConnection() +{ +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/wireddevice.h b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.h new file mode 100644 index 000000000..a17e5e997 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.h @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef WIREDDEVICE_H +#define WIREDDEVICE_H + +#include "networkdevicebase.h" + +namespace dde { + +namespace network { + +class WiredConnection; + +class WiredDevice : public NetworkDeviceBase +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +private: + WiredDevice(NetworkDeviceRealize *devcieRealize, QObject *parent); + ~WiredDevice() override; + +Q_SIGNALS: + void connectionAdded(const QList); // 新增连接 + void connectionRemoved(const QList); // 删除连接 + void connectionPropertyChanged(const QList &); // 连接属性发生变化 + +public: + bool connectNetwork(WiredConnection *connection); // 连接网络,连接成功抛出deviceStatusChanged信号 + bool connectNetwork(const QString &path); // 连接网络重载函数,参数为配置路径 + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + DeviceType deviceType() const override; // 返回设备类型,适应基类统一的接口 + QList items() const; // 有线网络连接列表 +}; + +class WiredConnection : public ControllItems +{ + friend class WiredDevice; + friend class WiredDeviceInterRealize; + friend class DeviceManagerRealize; + +protected: + WiredConnection(); + ~WiredConnection(); + +}; + +} + +} + +#endif // UWIREDDEVICE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.cpp b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.cpp new file mode 100644 index 000000000..780ae4b9d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.cpp @@ -0,0 +1,237 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "wirelessdevice.h" +#include "netutils.h" +#include "realize/netinterface.h" + +using namespace dde::network; + +bool WirelessDevice::isConnected() const +{ + QList aps = deviceRealize()->accessPointItems(); + return std::any_of(aps.begin(), aps.end(), [](const AccessPoints *ap) { + return ap->status() == ConnectionStatus::Activated; + }); +} + +DeviceType WirelessDevice::deviceType() const +{ + return DeviceType::Wireless; +} + +QList WirelessDevice::accessPointItems() const +{ + /* 理论上,如果网卡是禁用状态,这里应该直接返回空列表 + * 但是由于在禁用网卡或者打开网卡的时候,后台的反应比较慢,控制中心无法实时获取,所以这里暂时让其先返回所有的网络列表, + * 等后台反应慢的问题改好后,再把注释打开 + * if (!isEnabled()) + return QList();*/ + + return deviceRealize()->accessPointItems(); +} + +void WirelessDevice::scanNetwork() +{ + deviceRealize()->scanNetwork(); +} + +void WirelessDevice::connectNetwork(const AccessPoints *item) +{ + deviceRealize()->connectNetwork(item); +} + +AccessPoints *WirelessDevice::activeAccessPoints() const +{ + return deviceRealize()->activeAccessPoints(); +} + +bool WirelessDevice::hotspotEnabled() const +{ + return deviceRealize()->hotspotEnabled(); +} + +void WirelessDevice::connectNetwork(const QString &ssid) +{ + AccessPoints *apConnection = findAccessPoint(ssid); + if (apConnection) + connectNetwork(apConnection); +} + +QList WirelessDevice::items() const +{ + return deviceRealize()->wirelessItems(); +} + +WirelessDevice::WirelessDevice(NetworkDeviceRealize *networkInter, QObject *parent) + : NetworkDeviceBase(networkInter, parent) +{ + connect(networkInter, &NetworkDeviceRealize::networkAdded, this, &WirelessDevice::networkAdded); + connect(networkInter, &NetworkDeviceRealize::networkRemoved, this, &WirelessDevice::networkRemoved); + connect(networkInter, &NetworkDeviceRealize::connectionSuccess, this, &WirelessDevice::connectionSuccess); + connect(networkInter, &NetworkDeviceRealize::hotspotEnableChanged, this, &WirelessDevice::hotspotEnableChanged); + connect(networkInter, &NetworkDeviceRealize::accessPointInfoChanged, this, &WirelessDevice::accessPointInfoChanged); +} + +WirelessDevice::~WirelessDevice() +{ +} + +AccessPoints *WirelessDevice::findAccessPoint(const QString &ssid) +{ + QList accessPoints = deviceRealize()->accessPointItems(); + for (AccessPoints *accessPoint : accessPoints) { + if (accessPoint->ssid() == ssid) + return accessPoint; + } + + return Q_NULLPTR; +} + +/** + * @brief 无线网络连接 + */ +AccessPoints::AccessPoints(const QJsonObject &json, QObject *parent) + : QObject(parent) + , m_json(json) + , m_status(ConnectionStatus::Unknown) +{ +} + +AccessPoints::~AccessPoints() +{ +} + +QString AccessPoints::ssid() const +{ + return m_json.value("Ssid").toString(); +} + +int AccessPoints::strength() const +{ + if (m_json.isEmpty()) + return -1; + + return m_json.value("Strength").toInt(); +} + +bool AccessPoints::secured() const +{ + return m_json.value("Secured").toBool(); +} + +bool AccessPoints::securedInEap() const +{ + return m_json.value("SecuredInEap").toBool(); +} + +int AccessPoints::frequency() const +{ + return m_json.value("Frequency").toInt(); +} + +QString AccessPoints::path() const +{ + return m_json.value("Path").toString(); +} + +QString AccessPoints::devicePath() const +{ + return m_devicePath; +} + +bool AccessPoints::connected() const +{ + return (m_status == ConnectionStatus::Activated); +} + +ConnectionStatus AccessPoints::status() const +{ + return m_status; +} + +bool AccessPoints::hidden() const +{ + if (m_json.contains("Hidden")) + return m_json.value("Hidden").toBool(); + + return false; +} + +AccessPoints::WlanType AccessPoints::type() const +{ + // 根据需求,在当前Wlan未连接的情况下,才判断是否有同名Wlan中存在Wlan6,如果当前已连接,则直接判断 + if (!connected()) { + // 如果是重名的Wlan,则判断同名的Wlan的Flags是否为Wlan6 + if (m_json.contains("extendFlags")) { + int flag = m_json.value("extendFlags").toInt(); + if (flag & AP_FLAGS_HE) + return WlanType::wlan6; + } + } + + if (m_json.contains("Flags")) { + int flag = m_json.value("Flags").toInt(); + if (flag & AP_FLAGS_HE) + return WlanType::wlan6; + } + + return WlanType::wlan; +} + +void AccessPoints::updateAccessPoints(const QJsonObject &json) +{ + int nOldStrength = strength(); + bool oldSecured = secured(); + m_json = json; + int nStrength = strength(); + if (nOldStrength != -1 && nStrength != nOldStrength) + Q_EMIT strengthChanged(nStrength); + + bool newSecured = secured(); + if (oldSecured != newSecured) + Q_EMIT securedChanged(newSecured); +} + +void AccessPoints::updateConnectionStatus(ConnectionStatus status) +{ + if (m_status == status) + return; + + m_status = status; + Q_EMIT connectionStatusChanged(status); +} + +/** + * @brief 无线连接信息 + */ +AccessPoints *WirelessConnection::accessPoints() const +{ + return m_accessPoints; +} + +ConnectionStatus WirelessConnection::status() const +{ + return m_accessPoints ? m_accessPoints->status() :ConnectionStatus::Unknown; +} + +WirelessConnection::WirelessConnection() + : ControllItems() + , m_accessPoints(Q_NULLPTR) +{ +} + +WirelessConnection::~WirelessConnection() +{ +} + +WirelessConnection *WirelessConnection::createConnection(AccessPoints *ap) +{ + WirelessConnection *wirelessConnection = new WirelessConnection; + QJsonObject json; + json.insert("Ssid", ap->ssid()); + wirelessConnection->setConnection(json); + wirelessConnection->m_accessPoints = ap; + return wirelessConnection; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.h b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.h new file mode 100644 index 000000000..8645e3777 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.h @@ -0,0 +1,138 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef WIRELESSDEVICE_H +#define WIRELESSDEVICE_H + +#include "networkdevicebase.h" + +namespace dde { + +namespace network { + +class AccessPoints; +class WirelessConnection; +class NetworkDeviceRealize; +/** + * @brief 无线网络设备-无线网卡 + */ +class WirelessDevice : public NetworkDeviceBase +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + DeviceType deviceType() const override; // 返回设备类型,适应基类统一的接口 + QList accessPointItems() const; // 当前网卡上所有的网络列表 + void scanNetwork(); // 重新加载所有的无线网络列表 + void connectNetwork(const AccessPoints *item); // 连接网络,连接成功抛出deviceStatusChanged信号 + void connectNetwork(const QString &ssid); // 连接网络,重载函数 + QList items() const; // 无线网络连接列表 + AccessPoints *activeAccessPoints() const; // 当前活动的无线连接 + bool hotspotEnabled() const; // 是否开启热点 + +Q_SIGNALS: + void networkAdded(QList); // wlan新增网络 + void networkRemoved(QList); // wlan列表减少网络 + void connectionSuccess(const AccessPoints *); // 连接无线网络wlan成功,参数为对应的wlan + void hotspotEnableChanged(const bool &); // 热点是否可用发生变化 + void accessPointInfoChanged(const QList &); // wlan信号强度发生变化的网络 + +protected: + WirelessDevice(NetworkDeviceRealize *networkInter, QObject *parent); + ~WirelessDevice() override; + +private: + AccessPoints *findAccessPoint(const QString &ssid); +}; + +/** + * @brief 无线网络连接-wlan + */ + +class AccessPoints : public QObject +{ + Q_OBJECT + + friend class WirelessDevice; + friend class WirelessDeviceInterRealize; + friend class DeviceManagerRealize; + + Q_PROPERTY(QString ssid READ ssid) + Q_PROPERTY(int strength READ strength) + Q_PROPERTY(bool secured READ secured) + Q_PROPERTY(bool securedInEap READ securedInEap) + Q_PROPERTY(int frequency READ frequency) + Q_PROPERTY(QString path READ path) + Q_PROPERTY(QString devicePath READ devicePath) + Q_PROPERTY(bool connected READ connected) + +public: + enum class WlanType { wlan, wlan6 }; + +protected: + AccessPoints(const QJsonObject &json, QObject *parent = Q_NULLPTR); + ~AccessPoints(); + +public: + QString ssid() const; // 网络SSID,对应于返回接口中的Ssid + int strength() const; // 信号强度,对应于返回接口中的Strength + bool secured() const; // 是否加密,对应于返回接口中的Secured + bool securedInEap() const; // 对应于返回接口中的SecuredInEap + int frequency() const; // 频率,对应于返回接口中的Frequency + QString path() const; // 路径,对应于返回接口中的Path + QString devicePath() const; // 对应的设备的路径,为返回接口中的key值 + bool connected() const; // 网络是否连接成功 + ConnectionStatus status() const; // 当前网络的连接状态 + bool hidden() const; // 是否为隐藏网络 + WlanType type() const; + +Q_SIGNALS: + void strengthChanged(const int) const; // 当前信号强度变化 + void connectionStatusChanged(ConnectionStatus); + void securedChanged(bool); + +protected: + void updateAccessPoints(const QJsonObject &json); + void updateConnectionStatus(ConnectionStatus); + +private: + QJsonObject m_json; + QString m_devicePath; + ConnectionStatus m_status; +}; + +/** + * @brief 无线连接信息 + */ + +class WirelessConnection: public ControllItems +{ + friend class WirelessDevice; + friend class WirelessDeviceInterRealize; + friend class DeviceManagerRealize; + +public: + AccessPoints *accessPoints() const; // 返回当前对应的wlan的指针 + ConnectionStatus status() const override; + +protected: + WirelessConnection(); + virtual ~WirelessConnection() override; + + static WirelessConnection *createConnection(AccessPoints *ap); + +private: + AccessPoints *m_accessPoints; +}; + +} + +} + +#endif // UWIRELESSDEVICE_H diff --git a/panels/dock/tray/plugins/display/CMakeLists.txt b/panels/dock/tray/plugins/display/CMakeLists.txt index 428d9267c..8195ff866 100644 --- a/panels/dock/tray/plugins/display/CMakeLists.txt +++ b/panels/dock/tray/plugins/display/CMakeLists.txt @@ -34,6 +34,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ../../widgets ../../frame + ../../frame/util ../../frame/qtdbusextended ./dbusinterface/generation_dbus_interface componments) diff --git a/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt b/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt index 2fe400398..b459b109b 100644 --- a/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt +++ b/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt @@ -25,6 +25,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ./dbusinterface ./dbusinterface/generation_dbus_interface + ../../frame/util ../../frame/qtdbusextended) target_link_libraries(${PLUGIN_NAME} PRIVATE diff --git a/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt b/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt index d713262f7..d0f178850 100644 --- a/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt +++ b/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt @@ -28,6 +28,7 @@ add_library(${PLUGIN_NAME} SHARED ${SRCS}) set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../loader/) target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ./pluginadapter + ../../frame/util ../../frame/drag ../../frame/dbusinterface ../../frame/dbusinterface/generation_dbus_interface/ diff --git a/panels/dock/tray/plugins/shutdown/CMakeLists.txt b/panels/dock/tray/plugins/shutdown/CMakeLists.txt index ef3a58d78..d3efc5b77 100644 --- a/panels/dock/tray/plugins/shutdown/CMakeLists.txt +++ b/panels/dock/tray/plugins/shutdown/CMakeLists.txt @@ -26,6 +26,7 @@ add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") add_library(${PLUGIN_NAME} SHARED ${SRCS} shutdown.qrc) set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../) target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} + ../../frame/util ../../interfaces ../../widgets) target_link_libraries(${PLUGIN_NAME} PRIVATE diff --git a/panels/dock/tray/plugins/sound/CMakeLists.txt b/panels/dock/tray/plugins/sound/CMakeLists.txt index dffbf4432..ffaf8a221 100644 --- a/panels/dock/tray/plugins/sound/CMakeLists.txt +++ b/panels/dock/tray/plugins/sound/CMakeLists.txt @@ -33,6 +33,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ../../widgets ../../frame + ../../frame/util ../../frame/accessible ../../frame/qtdbusextended )