Skip to content

Commit

Permalink
fix: Add deepin-service-plugin-network
Browse files Browse the repository at this point in the history
Add deepin-service-plugin-network

pms: BUG-294423
pms: BUG-294395
  • Loading branch information
caixr23 committed Dec 27, 2024
1 parent 4fc5479 commit f81d8d8
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 68 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ add_subdirectory("example")
add_subdirectory("dss-network-plugin")
add_subdirectory("dss_example")
#add_subdirectory("dock-example")
add_subdirectory("network-service-plugin")
8 changes: 7 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Vcs-Browser: https://gerrit.uniontech.com/admin/repos/dde-network-core

Package: libdde-network-core
Architecture: any
Depends: ${misc:Depends},${shlibs:Depends},
Depends: ${misc:Depends},${shlibs:Depends},deepin-service-plugin-network
Description: the library of network
libdde-network-core module

Expand All @@ -49,3 +49,9 @@ Architecture: any
Depends: ${misc:Depends},${shlibs:Depends},libdde-network-core (= ${binary:Version})
Description: the plugin of network for dde-lock
dss-network-plugin module

Package: deepin-service-plugin-network
Architecture: any
Depends: ${misc:Depends},${shlibs:Depends},curl
Description: the plugin of network service for deepin-service-manager
deepin-service-plugin-network module
6 changes: 6 additions & 0 deletions debian/deepin-service-plugin-network.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/usr/share/deepin-service-manager/system/plugin-system-network.json
/usr/share/deepin-service-manager/user/plugin-session-network.json
/usr/share/dbus-1/system.d/org.deepin.service.SessionNetwork.conf
/usr/share/dbus-1/system.d/org.deepin.service.SystemNetwork.conf
/usr/lib/*/deepin-service-manager/libnetwork-service.so
/usr/share/deepin-service-manager/network-service/translations
30 changes: 14 additions & 16 deletions network-service-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
else()
ADD_DEFINITIONS(-DQM_FILES_DIR="/usr/share/deepin-service-manager/network-service/translations")
endif()

find_package(Qt5 COMPONENTS Core Widgets DBus Network REQUIRED)
find_package(KF5NetworkManagerQt REQUIRED)
set(QT_NS 5)
set(DTK_NS Dtk)
find_package(Qt${QT_NS} COMPONENTS Core Widgets DBus Network LinguistTools REQUIRED)
find_package(KF${QT_NS}NetworkManagerQt REQUIRED)
find_package(DtkCore REQUIRED)

file(GLOB TS_FILES "translations/*.ts")
Expand All @@ -34,12 +35,11 @@ add_library(${BIN_NAME} MODULE
)

target_include_directories(${BIN_NAME} PUBLIC
Qt5::Core
Qt5::DBus
${Qt5Network_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS}
${KF5_QT_INCLUDE_DIRS}
${DtkCore_INCLUDE_DIRS}
Qt${QT_NS}::Core
Qt${QT_NS}::DBus
Qt${QT_NS}::Network
KF${QT_NS}::NetworkManagerQt
${DTK_NS}::Core
.
system
session
Expand All @@ -51,13 +51,11 @@ target_include_directories(${BIN_NAME} PUBLIC
)

target_link_libraries(${BIN_NAME} PRIVATE
Qt5::Core
Qt5::DBus
${Qt5Network_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${DFrameworkDBus_LIBRARIES}
${KF5_QT_LIBRARIES}
${DtkCore_LIBRARIES}
Qt${QT_NS}::Core
Qt${QT_NS}::DBus
Qt${QT_NS}::Network
KF${QT_NS}::NetworkManagerQt
${DTK_NS}::Core
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#define LOGIN1SERVICE "org.freedesktop.login1"
#define LOGIN1MANAGERINTERFACE "org.freedesktop.login1.Session"

#define LOCKERVICE "com.deepin.dde.LockService"
#define LOCKPATH "/com/deepin/dde/LockService"
#define LOCKINTERFACE "com.deepin.dde.LockService"
#define LOCKERVICE "org.deepin.dde.LockService1"
#define LOCKPATH "/org/deepin/dde/LockService1"
#define LOCKINTERFACE "org.deepin.dde.LockService1"

#define SESSIONMANAGERSERVICE "com.deepin.SessionManager"
#define SESSIONMANAGERPATH "/com/deepin/SessionManager"
#define SESSIONMANAGERINTERFACE "com.deepin.SessionManager"
#define SESSIONMANAGERSERVICE "org.deepin.dde.SessionManager1"
#define SESSIONMANAGERPATH "/org/deepin/dde/SessionManager1"
#define SESSIONMANAGERINTERFACE "org.deepin.dde.SessionManager1"

#define IAM_SERVICE "com.deepin.udcp.iam"
#define IAM_PATH "/com/deepin/udcp/iam"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
#include "constants.h"

#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QDBusPendingReply>
#include <QDBusMetaType>
#include <QDBusServiceWatcher>
#include <QStandardPaths>
#include <QFile>
#include <QDir>

#include <NetworkManagerQt/Device>
#include <NetworkManagerQt/Manager>
Expand All @@ -29,7 +34,7 @@ using namespace accountnetwork::sessionservice;

#define NETWORKMANAGERINTERFACE "org.freedesktop.NetworkManager"

#define DEAMON_NETWORK_SERVICE "com.deepin.daemon.Network"
#define DEAMON_NETWORK_SERVICE "org.deepin.dde.Network1"
#define SECRET_SERVICE "org.freedesktop.secrets"

#define MANULCONNECTION 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "constants.h"

#include <QDBusConnection>
#include <QDBusInterface>

#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/WiredDevice>
Expand All @@ -21,9 +22,9 @@

using namespace accountnetwork::sessionservice;

#define SYS_NETWORK_SERVICE "com.deepin.system.Network"
#define SYS_NETWORK_PATH "/com/deepin/system/Network"
#define SYS_NETWORK_INTERFACE "com.deepin.system.Network"
#define SYS_NETWORK_SERVICE "org.deepin.dde.Network1"
#define SYS_NETWORK_PATH "/org/deepin/dde/Network1"
#define SYS_NETWORK_INTERFACE "org.deepin.dde.Network1"

NetworkActivator::NetworkActivator(AccountNetworkConfig *config, QObject *parent)
: QObject(parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

using namespace accountnetwork::systemservice;

#define LOCKERVICE "com.deepin.dde.LockService"
#define LOCKPATH "/com/deepin/dde/LockService"
#define LOCKINTERFACE "com.deepin.dde.LockService"
#define LOCKERVICE "org.deepin.dde.LockService1"
#define LOCKPATH "/org/deepin/dde/LockService1"
#define LOCKINTERFACE "org.deepin.dde.LockService1"

#define ACCOUNT_SERVICE "com.deepin.daemon.Accounts"
#define ACCOUNT_PATH "/com/deepin/daemon/Accounts"
#define ACCOUNT_INTERFACE "com.deepin.daemon.Accounts"
#define ACCOUNT_SERVICE "org.deepin.dde.Accounts1"
#define ACCOUNT_PATH "/org/deepin/dde/Accounts1"
#define ACCOUNT_INTERFACE "org.deepin.dde.Accounts1"

AccountManager::AccountManager(NetworkConfig *conf, QObject *parent)
: QObject (parent)
Expand All @@ -50,7 +50,7 @@ AccountManager::AccountManager(NetworkConfig *conf, QObject *parent)
QDBusInterface dbusInter(ACCOUNT_SERVICE, ACCOUNT_PATH, ACCOUNT_INTERFACE, QDBusConnection::systemBus());
QStringList userLists = dbusInter.property("UserList").toStringList();
for (const QString &user : userLists) {
QDBusInterface userInterface(ACCOUNT_SERVICE, user, "com.deepin.daemon.Accounts.User", QDBusConnection::systemBus());
QDBusInterface userInterface(ACCOUNT_SERVICE, user, "org.deepin.dde.Accounts1.User", QDBusConnection::systemBus());
m_userMap[user] = userInterface.property("UserName").toString();
}
}
Expand All @@ -70,7 +70,7 @@ QStringList AccountManager::primaryAccount() const
QDBusInterface dbusInter(ACCOUNT_SERVICE, ACCOUNT_PATH, ACCOUNT_INTERFACE, QDBusConnection::systemBus());
QStringList userLists = dbusInter.property("UserList").toStringList();
for (const QString &userPath : userLists) {
QDBusInterface interface(ACCOUNT_SERVICE, userPath, "com.deepin.daemon.Accounts.User", QDBusConnection::systemBus());
QDBusInterface interface(ACCOUNT_SERVICE, userPath, "org.deepin.dde.Accounts1.User", QDBusConnection::systemBus());
if (iamUsers.contains(interface.property("UserName").toString()))
continue;

Expand Down Expand Up @@ -131,7 +131,7 @@ void AccountManager::onAccountChanged(const QString &username)
void AccountManager::onUserAdded(const QString &path)
{
// 新增用户的时候,需要告知外部,如果是新增的域账户,外部需要处理
QDBusInterface interface(ACCOUNT_SERVICE, path, "com.deepin.daemon.Accounts.User", QDBusConnection::systemBus());
QDBusInterface interface(ACCOUNT_SERVICE, path, "org.deepin.dde.Accounts1.User", QDBusConnection::systemBus());
QString userName = interface.property("UserName").toString();
m_userMap[path] = userName;
emit accountAdded(userName, iamUserList().contains(QString::number(interface.property("Uid").toUInt())));
Expand Down
2 changes: 1 addition & 1 deletion network-service-plugin/ipconflicthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NetworkManager::Setting::SecretFlags IPConflictHandler::secretFlags(const Networ
return wirelessSecretSetting->wepKeyFlags();
}
if (currentKeyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaPsk ||
currentKeyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaSae) {
currentKeyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::SAE) {
return wirelessSecretSetting->pskFlags();
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions network-service-plugin/session/browserassist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

using namespace network::sessionservice;

#define dockService "com.deepin.dde.Dock"
#define dockPath "/com/deepin/dde/Dock"
#define dockInterface "com.deepin.dde.Dock"
#define dockService "org.deepin.dde.Dock1"
#define dockPath "/org/deepin/dde/Dock1"
#define dockInterface "org.deepin.dde.Dock1"

BrowserAssist::BrowserAssist(QObject *parent)
: QObject(parent)
Expand Down
3 changes: 2 additions & 1 deletion network-service-plugin/session/sessioncontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "browserassist.h"

#include <QDBusConnection>
#include <QDBusInterface>

using namespace network::sessionservice;

Expand Down Expand Up @@ -37,7 +38,7 @@ void SessionContainer::initConnection()
QDBusConnection::systemBus().connect(networkService, networkPath, networkInterface, "IpConflictChanged", this, SLOT(onIPConflictChanged(const QString &, const QString &, bool)));
QDBusConnection::systemBus().connect(networkService, networkPath, networkInterface, "PortalDetected", this, SLOT(onPortalDetected(const QString &)));
// 当系统代理发生变化的时候需要主动调用SystemNetwork服务的检查网络连通性的接口
QDBusConnection::sessionBus().connect("com.deepin.daemon.Network", "/com/deepin/daemon/Network", "com.deepin.daemon.Network", "ProxyMethodChanged", this, SLOT(onProxyMethodChanged(const QString &)));
QDBusConnection::sessionBus().connect("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", "ProxyMethodChanged", this, SLOT(onProxyMethodChanged(const QString &)));
}

void SessionContainer::initMember()
Expand Down
1 change: 1 addition & 0 deletions network-service-plugin/system/connectivitychecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <NetworkManagerQt/WirelessNetwork>

#include <QTimer>
#include <QProcess>

// 当没有进行配置的时候, 则访问我们官网
static const QStringList CheckUrls{
Expand Down
91 changes: 64 additions & 27 deletions network-service-plugin/system/networkinitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "networkinitialization.h"

#include "settingconfig.h"
#include "systemservice.h"

#include <QApplication>
#include <QEventLoop>

#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/WiredSetting>
#include <NetworkManagerQt/WirelessDevice>

#include <com_deepin_daemon_accounts_user.h>
#include <com_deepin_daemon_accounts.h>
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusServiceWatcher>
#include <QEventLoop>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QMutex>
#include <QTimer>
#include <QTranslator>

using namespace network::systemservice;

Expand All @@ -25,13 +34,13 @@ using namespace network::systemservice;

#define NETWORKMANAGER_SERVICE "org.freedesktop.NetworkManager"

#define LOCKERVICE "com.deepin.dde.LockService"
#define LOCKPATH "/com/deepin/dde/LockService"
#define LOCKINTERFACE "com.deepin.dde.LockService"
#define LOCKERVICE "org.deepin.dde.LockService1"
#define LOCKPATH "/org/deepin/dde/LockService1"
#define LOCKINTERFACE "org.deepin.dde.LockService1"

#define DEAMONACCOUNTSERVICE "com.deepin.daemon.Accounts"
#define DEAMONACCOUNTPATH "/com/deepin/daemon/Accounts"
#define DEAMONACCOUNTINTERFACE "com.deepin.daemon.Accounts"
#define DEAMONACCOUNTSERVICE "org.deepin.dde.Accounts1"
#define DEAMONACCOUNTPATH "/org/deepin/dde/Accounts1"
#define DEAMONACCOUNTINTERFACE "org.deepin.dde.Accounts1"

void NetworkInitialization::doInit()
{
Expand Down Expand Up @@ -280,29 +289,57 @@ bool NetworkInitialization::installUserTranslator(const QString &json)
qCDebug(DSM) << "user changed " << json;
QString locale;
if (json.startsWith("/")) {
com::deepin::daemon::accounts::User user("com.deepin.daemon.Accounts", json, QDBusConnection::systemBus());
locale = user.locale().split(".").first().trimmed();
QDBusMessage userMsg = QDBusMessage::createMethodCall(DEAMONACCOUNTSERVICE, json, "org.freedesktop.DBus.Properties", "Get");
userMsg << DEAMONACCOUNTINTERFACE ".User"
<< "Locale";
QDBusPendingReply<QVariant> userProp = QDBusConnection::systemBus().asyncCall(userMsg);
if (userProp.value().isValid()) {
locale = userProp.value().toString().split(".").first().trimmed();
}
qCDebug(DSM) << "get locale: " << locale;
}

QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8(), &error);
if (!locale.isEmpty() ) {
//do nothing
if (!locale.isEmpty()) {
// do nothing
} else if (error.error == QJsonParseError::NoError && doc.isObject()) {
int uid = doc.object().value("Uid").toInt();
com::deepin::daemon::accounts::User user("com.deepin.daemon.Accounts", QString("/com/deepin/daemon/Accounts/User%1").arg(uid), QDBusConnection::systemBus());
locale = user.locale().split(".").first();
const QString name = doc.object().value("Name").toString();
if (name.isEmpty()) {
return false;
}
QDBusMessage msg = QDBusMessage::createMethodCall(DEAMONACCOUNTSERVICE, DEAMONACCOUNTPATH, DEAMONACCOUNTINTERFACE, "FindUserByName");
msg << name;
QDBusPendingReply<QString> path = QDBusConnection::systemBus().asyncCall(msg);
if (path.isError()) {
return false;
}
QDBusMessage userMsg = QDBusMessage::createMethodCall(DEAMONACCOUNTSERVICE, path, "org.freedesktop.DBus.Properties", "Get");
userMsg << DEAMONACCOUNTINTERFACE ".User"
<< "Locale";
QDBusPendingReply<QVariant> userProp = QDBusConnection::systemBus().asyncCall(userMsg);
if (userProp.value().isValid()) {
locale = userProp.value().toString().split(".").first().trimmed();
}
} else if (m_accountServiceRegister) {
// 如果是非法的json,就直接从Accounts服务中获取
com::deepin::daemon::Accounts account("com.deepin.daemon.Accounts", "/com/deepin/daemon/Accounts", QDBusConnection::systemBus());
const QStringList userList = account.userList();
QDBusMessage msg = QDBusMessage::createMethodCall(DEAMONACCOUNTSERVICE, DEAMONACCOUNTPATH, "org.freedesktop.DBus.Properties", "Get");
msg << DEAMONACCOUNTINTERFACE << "UserList";
QDBusPendingReply<QVariant> prop = QDBusConnection::systemBus().asyncCall(msg);
if (!prop.value().isValid()) {
return false;
}
const QStringList userList = prop.value().toStringList();
qCDebug(DSM) << "found users" << userList;
if (userList.isEmpty())
return false;

com::deepin::daemon::accounts::User user("com.deepin.daemon.Accounts", userList.first(), QDBusConnection::systemBus());
locale = user.locale().split(".").first();
QDBusMessage userMsg = QDBusMessage::createMethodCall(DEAMONACCOUNTSERVICE, userList.first(), "org.freedesktop.DBus.Properties", "Get");
userMsg << DEAMONACCOUNTINTERFACE ".User"
<< "Locale";
QDBusPendingReply<QVariant> userProp = QDBusConnection::systemBus().asyncCall(userMsg);
if (userProp.value().isValid()) {
locale = userProp.value().toString().split(".").first().trimmed();
}
} else {
return false;
}
Expand All @@ -317,10 +354,10 @@ bool NetworkInitialization::installUserTranslator(const QString &json)
if (localTmp != locale) {
localTmp = locale;
static QTranslator translator;
QApplication::removeTranslator(&translator);
QCoreApplication::removeTranslator(&translator);
const QString qmFile = QString("%1/network-service-plugin_%2.qm").arg(QM_FILES_DIR).arg(locale);
translator.load(qmFile);
QApplication::installTranslator(&translator);
QCoreApplication::installTranslator(&translator);
qCDebug(DSM) << "install translation file" << qmFile;
}

Expand Down

0 comments on commit f81d8d8

Please sign in to comment.