From ebdfe9b63e70ce8da73d7e2e3e8655e54975ab7c Mon Sep 17 00:00:00 2001 From: lixueman Date: Thu, 1 Sep 2022 17:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug133399=EF=BC=8C=E5=8D=95?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=94=B5=E6=BA=90=E5=8F=B3=E9=94=AE=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=88=87=E6=8D=A2=E7=94=A8=E6=88=B7=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RightClickMenu/rightclickmenu.cpp | 34 +++++++++++++++++-- .../RightClickMenu/rightclickmenu.h | 5 ++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/UserInterface/RightClickMenu/rightclickmenu.cpp b/src/UserInterface/RightClickMenu/rightclickmenu.cpp index f274607..69b30f6 100755 --- a/src/UserInterface/RightClickMenu/rightclickmenu.cpp +++ b/src/UserInterface/RightClickMenu/rightclickmenu.cpp @@ -101,6 +101,36 @@ void RightClickMenu::removeFromCollectionActionTriggerSlot() m_actionNumber = 18; } +bool RightClickMenu::hasMultipleUsers() +{ + QDBusInterface interface("org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus()); + if (!interface.isValid()) { + qCritical() << QDBusConnection::systemBus().lastError().message(); + return false; + } + + QDBusReply reply = interface.call("Get","org.freedesktop.Accounts","HasMultipleUsers"); + return reply.value().toBool(); +} + +bool RightClickMenu::canSwitch() +{ + QDBusInterface interface("org.freedesktop.DisplayManager", + "/org/freedesktop/DisplayManager/Seat0", + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus()); + if (!interface.isValid()) { + qCritical() << QDBusConnection::systemBus().lastError().message(); + return false; + } else { + QDBusReply reply = interface.call("Get","org.freedesktop.DisplayManager.Seat","CanSwitch"); + return reply.value().toBool(); + } +} + void RightClickMenu::fixToTaskbarActionTriggerSlot() { QDBusInterface iface("com.ukui.panel.desktop", @@ -265,12 +295,12 @@ int RightClickMenu::showShutdownMenu(const QPoint &pos, const bool &isFullWind) { m_actionNumber = 0; MenuBox m_showShutMenu; + QDBusReply reply; connect(&m_showShutMenu, &MenuBox::sendMainWinActiveSignal, this, &RightClickMenu::sendMainWinActiveSignal); QDBusInterface iface(DBUS_SESSION_NAME, DBUS_SESSION_PATH, DBUS_SESSION_INTERFACE, QDBusConnection::sessionBus()); - QDBusReply reply = iface.call("canSwitch"); - if (reply.isValid() && reply.value() == true) { + if (canSwitch() && hasMultipleUsers()) { m_showShutMenu.addAction(QIcon(getIconPixmap("stock-people-symbolic", 1)), tr("Switch user"), this, SLOT(switchUserActionTriggerSlot())); } diff --git a/src/UserInterface/RightClickMenu/rightclickmenu.h b/src/UserInterface/RightClickMenu/rightclickmenu.h index 4075294..5b5d474 100755 --- a/src/UserInterface/RightClickMenu/rightclickmenu.h +++ b/src/UserInterface/RightClickMenu/rightclickmenu.h @@ -78,7 +78,6 @@ private: int m_actionNumber; QProcess *m_cmdProc = nullptr; UkuiMenuInterface *m_ukuiMenuInterface = nullptr; - QStringList m_whiteList; protected: @@ -92,6 +91,10 @@ protected: */ QPixmap getIconPixmap(QString iconstr, int type); + bool hasMultipleUsers(); + + bool canSwitch(); + private Q_SLOTS: /** * @brief Fixed to all software