diff --git a/src/plugin-power/operation/powerdbusproxy.cpp b/src/plugin-power/operation/powerdbusproxy.cpp index 8e21ea52b0..3ef51a826f 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 c04aca4db2..c41dbb0fbf 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; @@ -90,6 +91,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; @@ -119,6 +126,7 @@ class PowerDBusProxy : public QObject void PowerSavingModeBrightnessDropPercentChanged(uint value) const; void ModeChanged(const QString &value) const; void BatteryCapacityChanged(double value) const; + void noPasswdLoginChanged(bool value); public slots: // SystemPower @@ -131,6 +139,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 64c9766036..3e8a94897a 100644 --- a/src/plugin-power/operation/powermodel.cpp +++ b/src/plugin-power/operation/powermodel.cpp @@ -336,3 +336,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 24da35c56e..ac338e0001 100644 --- a/src/plugin-power/operation/powermodel.h +++ b/src/plugin-power/operation/powermodel.h @@ -120,6 +120,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); @@ -160,6 +166,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; @@ -198,6 +206,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 4ba6a8239a..f38a0aa7ac 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); @@ -79,6 +80,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 e828883ce8..72a6ca328b 100644 --- a/src/plugin-power/window/generalmodule.cpp +++ b/src/plugin-power/window/generalmodule.cpp @@ -268,7 +268,8 @@ void GeneralModule::initUI() false)); // 唤醒设置 - appendChild(new TitleModule("wakeupSettingsTitle", tr("Wakeup Settings"))); + auto wakeupTitle = new TitleModule("wakeupSettingsTitle", tr("Wakeup Settings")); + appendChild(wakeupTitle); group = new SettingsGroupModule("wakeupSettingsGroup", tr("Wakeup Settings")); appendChild(group); group->appendChild( @@ -311,4 +312,10 @@ void GeneralModule::initUI() &GeneralModule::requestSetWakeDisplay); return wakeDisplayNeedPassword; })); + wakeupTitle->setVisible(!m_model->isNoPasswdLogin()); + group->setVisible(!m_model->isNoPasswdLogin()); + connect(m_model, &PowerModel::noPasswdLoginChanged, group, [group,wakeupTitle](bool value){ + group->setVisible(!value); + wakeupTitle->setVisible(!value); + }); }