From d177c1e4311d6f1ce584f790a2b7bc1d5310c31d Mon Sep 17 00:00:00 2001 From: fengli Date: Mon, 28 Aug 2023 11:12:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=BA=E9=80=9A?= =?UTF-8?q?=E8=BF=87QtDBus=E8=B0=83=E7=94=A8dde=E6=8E=A5=E5=8F=A3=E5=B9=B6?= =?UTF-8?q?=E5=85=BC=E5=AE=B9V20=E4=B8=8EV23=E6=8E=A5=E5=8F=A3=E5=8F=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改为通过QtDBus调用dde接口并兼容V20与V23接口变化 Log: 修改为通过QtDBus调用dde接口并兼容V20与V23接口变化 --- deepin-system-monitor-main/CMakeLists.txt | 3 +- .../model/accounts_info_model.cpp | 80 ++++++++++++------- .../model/accounts_info_model.h | 24 +++--- 3 files changed, 65 insertions(+), 42 deletions(-) diff --git a/deepin-system-monitor-main/CMakeLists.txt b/deepin-system-monitor-main/CMakeLists.txt index c62b5224..723ff90f 100644 --- a/deepin-system-monitor-main/CMakeLists.txt +++ b/deepin-system-monitor-main/CMakeLists.txt @@ -603,8 +603,7 @@ set(LIBS ) if (USE_DEEPIN_WAYLAND) - message("................................link wayland: ${OS_BUILD_V23}") - if (OS_BUILD_V23) + if (DWayland_FOUND) list(APPEND LIBS DWaylandClient DWaylandServer) else() list(APPEND LIBS KF5::WaylandClient KF5::WaylandServer) diff --git a/deepin-system-monitor-main/model/accounts_info_model.cpp b/deepin-system-monitor-main/model/accounts_info_model.cpp index c36caab1..75f0305f 100644 --- a/deepin-system-monitor-main/model/accounts_info_model.cpp +++ b/deepin-system-monitor-main/model/accounts_info_model.cpp @@ -1,20 +1,43 @@ #include "accounts_info_model.h" #include #include +#include +#include +#include #include #include #define PKEXEC_PATH "/usr/bin/pkexec" #define PKILL_PATH "/usr/bin/pkill" -const QString AccountsService("com.deepin.daemon.Accounts"); -const QString LoginService("org.freedesktop.login1"); -const QString ControlCenterService("com.deepin.dde.ControlCenter"); +#ifdef OS_BUILD_V23 +const QString AccountsService = "org.deepin.dde.Accounts1"; +const QString AccountsPath = "/org/deepin/dde/Accounts1"; +const QString AccountsInterface = "org.deepin.dde.Accounts1"; +const QString UserInterface = "org.deepin.dde.Accounts1.User"; + +const QString ControlCenterService = "org.deepin.dde.ControlCenter1"; +const QString ControlCenterPath = "/org/deepin/dde/ControlCenter1"; +const QString ControlCenterInterface = "org.deepin.dde.ControlCenter1"; +#else +const QString AccountsService = "com.deepin.daemon.Accounts"; +const QString AccountsPath = "/com/deepin/daemon/Accounts"; +const QString AccountsInterface = "com.deepin.daemon.Accounts"; +const QString UserInterface = "com.deepin.daemon.Accounts.User"; + +const QString ControlCenterService = "com.deepin.dde.ControlCenter"; +const QString ControlCenterPath = "/com/deepin/dde/ControlCenter"; +const QString ControlCenterInterface = "com.deepin.dde.ControlCenter"; +#endif + +const QString LoginService = "org.freedesktop.login1"; +const QString LoginPath = "/org/freedesktop/login1"; +const QString LoginInterface = "org.freedesktop.login1.Manager"; AccountsInfoModel::AccountsInfoModel(QObject *parent): QObject(parent) - , m_accountsInter(new Accounts(AccountsService, "/com/deepin/daemon/Accounts", QDBusConnection::systemBus(), this)) - , m_LoginInter(new LoginManager(LoginService, "/org/freedesktop/login1", QDBusConnection::systemBus(), this)) - , m_controlInter(new ControlCenter(ControlCenterService, "/com/deepin/dde/ControlCenter", QDBusConnection::sessionBus(), this)) + , m_accountsInter(new QDBusInterface(AccountsService, AccountsPath, AccountsInterface, QDBusConnection::systemBus(), this)) + , m_LoginInter(new QDBusInterface(LoginService, LoginPath, LoginInterface, QDBusConnection::systemBus(), this)) + , m_controlInter(new QDBusInterface(ControlCenterService, ControlCenterPath, ControlCenterInterface, QDBusConnection::sessionBus(), this)) , m_currentUserType(-1) { qDBusRegisterMetaType(); @@ -26,13 +49,17 @@ AccountsInfoModel::AccountsInfoModel(QObject *parent): QObject(parent) //获取online userList updateUserOnlineStatus(); qInfo() << "AccountsInfoModel constructor line 29" << "online user list:" << m_onlineUsers; - updateUserList(m_accountsInter->userList()); - qInfo() << "AccountsInfoModel constructor line 31" << "Accounts user list:" << m_accountsInter->userList(); - connect(m_accountsInter, &Accounts::UserListChanged, this, &AccountsInfoModel::onUserListChanged, Qt::QueuedConnection); - connect(m_LoginInter, &LoginManager::SessionNew, this, &AccountsInfoModel::onSessionNew, Qt::QueuedConnection); - connect(m_LoginInter, &LoginManager::SessionRemoved, this, &AccountsInfoModel::onSessionNew, Qt::QueuedConnection); + QStringList userList = m_accountsInter->property("UserList").toStringList(); + updateUserList(userList); + qInfo() << "AccountsInfoModel constructor line 31" << "Accounts user list:" << userList; + QDBusConnection::systemBus().connect(AccountsService, AccountsPath, AccountsInterface, "UserListChanged", + this, SLOT(onUserListChanged(QStringList))); + QDBusConnection::systemBus().connect(LoginService, LoginPath, LoginInterface, "SessionNew", + this, SLOT(onSessionNew(QString, QDBusObjectPath))); + QDBusConnection::systemBus().connect(LoginService, LoginPath, LoginInterface, "SessionRemoved", + this, SLOT(onSessionNew(QString, QDBusObjectPath))); } void AccountsInfoModel::onUserListChanged(const QStringList &userPathList) @@ -41,16 +68,13 @@ void AccountsInfoModel::onUserListChanged(const QStringList &userPathList) qInfo() << "get update:" << userPathList; } - - - - void AccountsInfoModel::onSessionNew(const QString &in0, const QDBusObjectPath &in1) { Q_UNUSED(in0); Q_UNUSED(in1); updateUserOnlineStatus(); } + void AccountsInfoModel::onSessionRemoved(const QString &in0, const QDBusObjectPath &in1) { Q_UNUSED(in0); @@ -58,19 +82,20 @@ void AccountsInfoModel::onSessionRemoved(const QString &in0, const QDBusObjectPa updateUserOnlineStatus(); } - void AccountsInfoModel::updateUserList(const QStringList &userPathList) { qInfo() << "AccountsInfoModel updateUserList line 61" << "updateUserList begins!" ; m_userMap.clear(); for (QString userPath : userPathList) { - AccountsUser *userDBus = new AccountsUser("com.deepin.daemon.Accounts", userPath, QDBusConnection::systemBus(), this); + QDBusInterface *userDBus = new QDBusInterface(AccountsService, userPath, UserInterface, QDBusConnection::systemBus(), this); User *newUser = new User; - newUser->setName(userDBus->userName()); - newUser->setFullname(userDBus->fullName()); - newUser->setIconFile(userDBus->iconFile()); - newUser->setUserType(userDBus->accountType()); - newUser->setUserUid(userDBus->uid()); + + newUser->setName(userDBus->property("UserName").toString()); + newUser->setFullname(userDBus->property("FullName").toString()); + newUser->setIconFile(userDBus->property("IconFile").toString()); + newUser->setUserType(userDBus->property("AccountType").toInt()); + newUser->setUserUid(userDBus->property("Uid").toString()); + //当前用户 if (newUser->name() == m_currentUserName) { newUser->setIsCurrentUser(true); @@ -78,10 +103,7 @@ void AccountsInfoModel::updateUserList(const QStringList &userPathList) } qInfo() << "AccountsInfoModel updateUserList line 78" << "get user info of :" << newUser->name(); m_userMap.insert(newUser->name(), newUser); - } - - } @@ -137,7 +159,7 @@ bool AccountsInfoModel::lockSessionByUserName(const QString &userName) if (m_sessionList.size() > 0) { for (SessionInfo si : m_sessionList) { if (si.userName == userName) { - m_LoginInter->LockSession(si.sessionId); + m_LoginInter->call("LockSession", si.sessionId); return true; } } @@ -159,7 +181,7 @@ bool AccountsInfoModel::activateSessionByUserName(const QString &userName) for (SessionInfo si : m_sessionList) { if (si.userName == userName) { - m_LoginInter->ActivateSession(si.sessionId); + m_LoginInter->call("ActivateSession", si.sessionId); return true; } @@ -180,7 +202,7 @@ bool AccountsInfoModel::LogoutByUserName(const QString &userName) for (SessionInfo si : m_sessionList) { if (si.userName == userName) { qInfo() << "found" << userName << si.sessionId; - qInfo() << m_LoginInter->TerminateSession(si.sessionId).error(); +// qInfo() << m_LoginInter->TerminateSession(si.sessionId).error(); return true; } @@ -219,7 +241,7 @@ bool AccountsInfoModel::LogoutByUserName(const QString &userName) void AccountsInfoModel::EditAccount() { if (m_controlInter) - m_controlInter->ShowPage("accounts", "Accounts Detail"); + m_controlInter->call("ShowPage", "accounts", "Accounts Detail"); } diff --git a/deepin-system-monitor-main/model/accounts_info_model.h b/deepin-system-monitor-main/model/accounts_info_model.h index 19331d11..6d9f8995 100644 --- a/deepin-system-monitor-main/model/accounts_info_model.h +++ b/deepin-system-monitor-main/model/accounts_info_model.h @@ -1,17 +1,19 @@ #ifndef ACCOUNTS_INFO_MODEL_H #define ACCOUNTS_INFO_MODEL_H #include "user.h" -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include +#include +#include -using Accounts = com::deepin::daemon::Accounts; -using AccountsUser = com::deepin::daemon::accounts::User; -using LoginManager = org::freedesktop::login1::Manager; -using ControlCenter = com::deepin::dde::ControlCenter; +//using Accounts = com::deepin::daemon::Accounts; +//using AccountsUser = com::deepin::daemon::accounts::User; +//using LoginManager = org::freedesktop::login1::Manager; +//using ControlCenter = com::deepin::dde::ControlCenter; typedef struct _SessionInfo { QString sessionId; @@ -80,11 +82,11 @@ public Q_SLOTS: private: - Accounts *m_accountsInter; + QDBusInterface *m_accountsInter; QMap m_userMap ; QStringList m_onlineUsers; - LoginManager *m_LoginInter; - ControlCenter *m_controlInter; + QDBusInterface *m_LoginInter; + QDBusInterface *m_controlInter; QString m_currentUserName; int m_currentUserType; SessionInfoList m_sessionList {};