Skip to content

Commit

Permalink
feat: hide wakeupsetting when nopasswd
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
Decodetalkers committed Oct 10, 2023
1 parent 2736c47 commit 4958ab0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 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 @@ -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<QString> findUserById();

signals:
// Power
void ScreenBlackLockChanged(bool value) const;
Expand Down Expand Up @@ -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
Expand All @@ -131,6 +139,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 @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/plugin-power/operation/powermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -198,6 +206,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 @@ -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());
Expand Down
9 changes: 8 additions & 1 deletion src/plugin-power/window/generalmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
}

0 comments on commit 4958ab0

Please sign in to comment.