修改bug133399,单用户电源右键存在切换用户选项

This commit is contained in:
lixueman 2022-09-01 17:04:41 +08:00
parent d2c9b3bab8
commit ebdfe9b63e
2 changed files with 36 additions and 3 deletions

View File

@ -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<QVariant> 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<QVariant> 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<bool> reply;
connect(&m_showShutMenu, &MenuBox::sendMainWinActiveSignal, this, &RightClickMenu::sendMainWinActiveSignal);
QDBusInterface iface(DBUS_SESSION_NAME, DBUS_SESSION_PATH,
DBUS_SESSION_INTERFACE, QDBusConnection::sessionBus());
QDBusReply<bool> 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()));
}

View File

@ -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