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