Skip to content

Commit

Permalink
feat: set wakeupsetting to all false when nopasswd
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
Decodetalkers authored and deepin-bot[bot] committed Oct 13, 2023
1 parent 3c1b9c2 commit 93bfd55
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 27 deletions.
35 changes: 34 additions & 1 deletion src/plugin-power/operation/powerdbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusPendingReply>

#include <QDBusReply>
#include <QFile>
#include <QVariant>

#include <unistd.h>

const QString PowerService = QStringLiteral("org.deepin.dde.Power1");
const QString PowerPath = QStringLiteral("/org/deepin/dde/Power1");
Expand All @@ -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))
Expand All @@ -39,6 +50,28 @@ PowerDBusProxy::PowerDBusProxy(QObject *parent)
{
}

std::optional<QString> PowerDBusProxy::findUserById()
{
int id = getuid();
QDBusReply<QString> 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<bool>(m_currentAccountInter->property("NoPasswdLogin"));
}

// power
bool PowerDBusProxy::screenBlackLock()
{
Expand Down
10 changes: 10 additions & 0 deletions src/plugin-power/operation/powerdbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QObject>
#include <DDBusInterface>
#include <optional>
class QDBusInterface;
class QDBusMessage;
using Dtk::Core::DDBusInterface;
Expand Down Expand Up @@ -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<QString> findUserById();

signals:
// Power
void ScreenBlackLockChanged(bool value) const;
Expand Down Expand Up @@ -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
Expand All @@ -138,6 +146,8 @@ public slots:
bool login1ManagerCanHibernate();

private:
DDBusInterface *m_accountRootInter;
DDBusInterface *m_currentAccountInter;
DDBusInterface *m_powerInter;
DDBusInterface *m_sysPowerInter;
DDBusInterface *m_login1ManagerInter;
Expand Down
9 changes: 9 additions & 0 deletions src/plugin-power/operation/powermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/plugin-power/operation/powermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -203,6 +211,9 @@ class PowerModel : public QObject

QString m_powerPlan;
bool m_isHighPerformanceSupported;

// Account
bool m_noPasswdLogin;
};

#endif // POWERMODEL_H
3 changes: 3 additions & 0 deletions src/plugin-power/operation/powerworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
71 changes: 45 additions & 26 deletions src/plugin-power/window/generalmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <titledslideritem.h>

#include <DComboBox>
#include <DIconTheme>
#include <DListView>
#include <DSwitchButton>
#include <DIconTheme>

#define BALANCE "balance" // 平衡模式
#define PERFORMANCE "performance" // 高性能模式
Expand Down Expand Up @@ -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;
}));
}

0 comments on commit 93bfd55

Please sign in to comment.