diff --git a/src/plugin-power/operation/powerdbusproxy.cpp b/src/plugin-power/operation/powerdbusproxy.cpp index a1fffc74d9..0511466001 100644 --- a/src/plugin-power/operation/powerdbusproxy.cpp +++ b/src/plugin-power/operation/powerdbusproxy.cpp @@ -7,8 +7,11 @@ #include #include #include - +#include #include +#include + +#include const QString PowerService = QStringLiteral("org.deepin.dde.Power1"); const QString PowerPath = QStringLiteral("/org/deepin/dde/Power1"); @@ -26,11 +29,19 @@ const QString UPowerService = QStringLiteral("org.freedesktop.UPower"); const QString UPowerPath = QStringLiteral("/org/freedesktop/UPower"); const QString UPowerInterface = QStringLiteral("org.freedesktop.UPower"); +const QString accountsService = QStringLiteral("org.deepin.dde.Accounts1"); +const QString defaultAccountsPath = QStringLiteral("/org/deepin/dde/Accounts1"); +const QString accountsInterface = QStringLiteral("org.deepin.dde.Accounts1"); + +const QString accountsUserInterface = QStringLiteral("org.deepin.dde.Accounts1.User"); + const QString PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); const QString PropertiesChanged = QStringLiteral("PropertiesChanged"); PowerDBusProxy::PowerDBusProxy(QObject *parent) : QObject(parent) + , m_accountRootInter(new DDBusInterface(accountsService, defaultAccountsPath, accountsInterface, QDBusConnection::systemBus(), this)) + , m_currentAccountInter(nullptr) , m_powerInter(new DDBusInterface(PowerService, PowerPath, PowerInterface, QDBusConnection::sessionBus(), this)) , m_sysPowerInter(new DDBusInterface(SysPowerService, SysPowerPath, SysPowerInterface, QDBusConnection::systemBus(), this)) , m_login1ManagerInter(new DDBusInterface(Login1ManagerService, Login1ManagerPath, Login1ManagerInterface, QDBusConnection::systemBus(), this)) @@ -39,6 +50,28 @@ PowerDBusProxy::PowerDBusProxy(QObject *parent) { } +std::optional PowerDBusProxy::findUserById() +{ + int id = getuid(); + QDBusReply reply = m_accountRootInter->callWithArgumentList(QDBus::CallMode::Block, "FindUserById", {QString::number(id)}); + if (reply.isValid()) { + return reply.value(); + } + return std::nullopt; +} + +bool PowerDBusProxy::noPasswdLogin() +{ + if (!m_currentAccountInter) { + auto path = findUserById(); + if (!path.has_value()) { + return false; + } + m_currentAccountInter = new DDBusInterface(accountsInterface, path.value(), accountsUserInterface, QDBusConnection::systemBus(), this); + } + return qvariant_cast(m_currentAccountInter->property("NoPasswdLogin")); +} + // power bool PowerDBusProxy::screenBlackLock() { diff --git a/src/plugin-power/operation/powerdbusproxy.h b/src/plugin-power/operation/powerdbusproxy.h index 6046887966..418820be25 100644 --- a/src/plugin-power/operation/powerdbusproxy.h +++ b/src/plugin-power/operation/powerdbusproxy.h @@ -6,6 +6,7 @@ #include #include +#include class QDBusInterface; class QDBusMessage; using Dtk::Core::DDBusInterface; @@ -96,6 +97,12 @@ class PowerDBusProxy : public QObject Q_PROPERTY(int MaxBacklightBrightness READ batteryCapacity) int maxBacklightBrightness(); + // USER + Q_PROPERTY(bool NoPasswdLogin READ noPasswdLogin NOTIFY noPasswdLoginChanged) + bool noPasswdLogin(); + + std::optional findUserById(); + signals: // Power void ScreenBlackLockChanged(bool value) const; @@ -126,6 +133,7 @@ class PowerDBusProxy : public QObject void PowerSavingModeAutoBatteryPercentChanged(uint value) const; void ModeChanged(const QString &value) const; void BatteryCapacityChanged(double value) const; + void noPasswdLoginChanged(bool value); public slots: // SystemPower @@ -138,6 +146,8 @@ public slots: bool login1ManagerCanHibernate(); private: + DDBusInterface *m_accountRootInter; + DDBusInterface *m_currentAccountInter; DDBusInterface *m_powerInter; DDBusInterface *m_sysPowerInter; DDBusInterface *m_login1ManagerInter; diff --git a/src/plugin-power/operation/powermodel.cpp b/src/plugin-power/operation/powermodel.cpp index d86584dd43..90c270aee4 100644 --- a/src/plugin-power/operation/powermodel.cpp +++ b/src/plugin-power/operation/powermodel.cpp @@ -346,3 +346,12 @@ void PowerModel::setShutdown(bool shutdown) Q_EMIT shutdownChanged(shutdown); } } + +void PowerModel::setNoPasswdLogin(bool value) +{ + if (value != m_noPasswdLogin) { + m_noPasswdLogin = value; + + Q_EMIT noPasswdLoginChanged(value); + } +} diff --git a/src/plugin-power/operation/powermodel.h b/src/plugin-power/operation/powermodel.h index 937a009928..8b29b4c239 100644 --- a/src/plugin-power/operation/powermodel.h +++ b/src/plugin-power/operation/powermodel.h @@ -123,6 +123,12 @@ class PowerModel : public QObject inline bool isHighPerformanceSupported() const { return m_isHighPerformanceSupported; } void setHighPerformanceSupported(bool isHighSupport); + // ---- + inline bool isNoPasswdLogin() const { return m_noPasswdLogin; } + + void setNoPasswdLogin(bool value); + + Q_SIGNALS: void sleepLockChanged(const bool sleepLock); void canSleepChanged(const bool canSleep); @@ -164,6 +170,8 @@ class PowerModel : public QObject void powerPlanChanged(const QString &value); void highPerformaceSupportChanged(bool value); + void noPasswdLoginChanged(bool value); + private: bool m_lidPresent; //以此判断是否为笔记本 bool m_sleepOnLidOnPowerClose; @@ -203,6 +211,9 @@ class PowerModel : public QObject QString m_powerPlan; bool m_isHighPerformanceSupported; + + // Account + bool m_noPasswdLogin; }; #endif // POWERMODEL_H diff --git a/src/plugin-power/operation/powerworker.cpp b/src/plugin-power/operation/powerworker.cpp index 3be8370db5..f2b8cb403b 100644 --- a/src/plugin-power/operation/powerworker.cpp +++ b/src/plugin-power/operation/powerworker.cpp @@ -22,6 +22,7 @@ PowerWorker::PowerWorker(PowerModel *model, QObject *parent) , m_powerModel(model) , m_powerDBusProxy(new PowerDBusProxy(this)) { + connect(m_powerDBusProxy, &PowerDBusProxy::noPasswdLoginChanged, m_powerModel, &PowerModel::setNoPasswdLogin); connect(m_powerDBusProxy, &PowerDBusProxy::ScreenBlackLockChanged, m_powerModel, &PowerModel::setScreenBlackLock); connect(m_powerDBusProxy, &PowerDBusProxy::SleepLockChanged, m_powerModel, &PowerModel::setSleepLock); connect(m_powerDBusProxy, &PowerDBusProxy::LidIsPresentChanged, m_powerModel, &PowerModel::setLidPresent); @@ -81,6 +82,8 @@ void PowerWorker::active() m_powerModel->setBatteryLidClosedAction(m_powerDBusProxy->batteryLidClosedAction()); m_powerModel->setPowerPlan(m_powerDBusProxy->mode()); + m_powerModel->setNoPasswdLogin(m_powerDBusProxy->noPasswdLogin()); + setHighPerformanceSupported(m_powerDBusProxy->isHighPerformanceSupported()); setScreenBlackDelayToModelOnPower(m_powerDBusProxy->linePowerScreenBlackDelay()); diff --git a/src/plugin-power/window/generalmodule.cpp b/src/plugin-power/window/generalmodule.cpp index de802d4c20..54f039002d 100644 --- a/src/plugin-power/window/generalmodule.cpp +++ b/src/plugin-power/window/generalmodule.cpp @@ -14,9 +14,9 @@ #include #include +#include #include #include -#include #define BALANCE "balance" // 平衡模式 #define PERFORMANCE "performance" // 高性能模式 @@ -320,44 +320,63 @@ void GeneralModule::initUI() appendChild(new TitleModule("wakeupSettingsTitle", tr("Wakeup Settings"))); group = new SettingsGroupModule("wakeupSettingsGroup", tr("Wakeup Settings")); appendChild(group); - group->appendChild( - new ItemModule("passwordIsRequiredToWakeUpTheComputer", - tr("Password is required to wake up the computer"), - [this](ModuleObject *module) -> QWidget * { - Q_UNUSED(module) - DSwitchButton *wakeComputerNeedPassword = new DSwitchButton(); - wakeComputerNeedPassword->setChecked(m_model->sleepLock()); - wakeComputerNeedPassword->setVisible( - m_model->canSuspend() && m_model->getSuspend()); // 配置显示 - connect(m_model, - &PowerModel::sleepLockChanged, - wakeComputerNeedPassword, - &DSwitchButton::setChecked); - connect(m_model, - &PowerModel::suspendChanged, - wakeComputerNeedPassword, - &DSwitchButton::setVisible); - connect(wakeComputerNeedPassword, - &DSwitchButton::checkedChanged, - this, - &GeneralModule::requestSetWakeComputer); - return wakeComputerNeedPassword; - })); + group->appendChild(new ItemModule( + "passwordIsRequiredToWakeUpTheComputer", + tr("Password is required to wake up the computer"), + [this](ModuleObject *module) -> QWidget * { + Q_UNUSED(module) + DSwitchButton *wakeComputerNeedPassword = new DSwitchButton(); + wakeComputerNeedPassword->setChecked(m_model->sleepLock() + && !m_model->isNoPasswdLogin()); + wakeComputerNeedPassword->setDisabled(m_model->isNoPasswdLogin()); + wakeComputerNeedPassword->setVisible(m_model->canSuspend() + && m_model->getSuspend()); // 配置显示 + connect(m_model, + &PowerModel::sleepLockChanged, + wakeComputerNeedPassword, + [wakeComputerNeedPassword, this](bool checked) { + wakeComputerNeedPassword->setChecked(checked + && !m_model->isNoPasswdLogin()); + }); + connect(m_model, + &PowerModel::suspendChanged, + wakeComputerNeedPassword, + &DSwitchButton::setVisible); + connect(wakeComputerNeedPassword, + &DSwitchButton::checkedChanged, + this, + &GeneralModule::requestSetWakeComputer); + connect(m_model, + &PowerModel::noPasswdLoginChanged, + wakeComputerNeedPassword, + &DSwitchButton::setDisabled); + return wakeComputerNeedPassword; + })); group->appendChild( new ItemModule("passwordIsRequiredToWakeUpTheMonitor", tr("Password is required to wake up the monitor"), [this](ModuleObject *module) -> QWidget * { Q_UNUSED(module) DSwitchButton *wakeDisplayNeedPassword = new DSwitchButton(); - wakeDisplayNeedPassword->setChecked(m_model->screenBlackLock()); + wakeDisplayNeedPassword->setChecked(m_model->screenBlackLock() + && !m_model->isNoPasswdLogin()); + wakeDisplayNeedPassword->setDisabled(m_model->isNoPasswdLogin()); connect(m_model, &PowerModel::screenBlackLockChanged, wakeDisplayNeedPassword, - &DSwitchButton::setChecked); + [wakeDisplayNeedPassword, this](bool checked) { + wakeDisplayNeedPassword->setChecked( + checked && !m_model->isNoPasswdLogin()); + }); + connect(wakeDisplayNeedPassword, &DSwitchButton::checkedChanged, this, &GeneralModule::requestSetWakeDisplay); + connect(m_model, + &PowerModel::noPasswdLoginChanged, + wakeDisplayNeedPassword, + &DSwitchButton::setDisabled); return wakeDisplayNeedPassword; })); }