Skip to content

Commit

Permalink
feat: support set low power percentage
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
Decodetalkers committed Sep 26, 2023
1 parent 2736c47 commit b3d6d70
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/plugin-power/operation/powerdbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ void PowerDBusProxy::setPowerSavingModeBrightnessDropPercent(uint value)
m_sysPowerInter->setProperty("PowerSavingModeBrightnessDropPercent", QVariant::fromValue(value));
}

uint PowerDBusProxy::powerSavingModeAutoBatteryPercent()
{
return qvariant_cast<uint>(m_sysPowerInter->property("PowerSavingModeAutoBatteryPercent"));
}

void PowerDBusProxy::setPowerSavingModeAutoBatteryPercent(uint value)
{
m_sysPowerInter->setProperty("PowerSavingModeAutoBatteryPercent", QVariant::fromValue(value));
}

QString PowerDBusProxy::mode()
{
return qvariant_cast<QString>(m_sysPowerInter->property("Mode"));
Expand Down
7 changes: 7 additions & 0 deletions src/plugin-power/operation/powerdbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ class PowerDBusProxy : public QObject
Q_PROPERTY(bool PowerSavingModeAutoWhenBatteryLow READ powerSavingModeAutoWhenBatteryLow WRITE setPowerSavingModeAutoWhenBatteryLow NOTIFY PowerSavingModeAutoWhenBatteryLowChanged)
bool powerSavingModeAutoWhenBatteryLow();
void setPowerSavingModeAutoWhenBatteryLow(bool value);

Q_PROPERTY(uint PowerSavingModeBrightnessDropPercent READ powerSavingModeBrightnessDropPercent WRITE setPowerSavingModeBrightnessDropPercent NOTIFY PowerSavingModeBrightnessDropPercentChanged)
uint powerSavingModeBrightnessDropPercent();
void setPowerSavingModeBrightnessDropPercent(uint value);

Q_PROPERTY(uint PowerSavingModeAutoBatteryPercent READ powerSavingModeAutoBatteryPercent WRITE setPowerSavingModeAutoBatteryPercent NOTIFY PowerSavingModeAutoBatteryPercentChanged)
uint powerSavingModeAutoBatteryPercent();
void setPowerSavingModeAutoBatteryPercent(uint value);

Q_PROPERTY(QString Mode READ mode NOTIFY ModeChanged)
QString mode();
Q_PROPERTY(bool PowerSavingModeAuto READ powerSavingModeAuto WRITE setPowerSavingModeAuto NOTIFY PowerSavingModeAutoChanged)
Expand Down Expand Up @@ -117,6 +123,7 @@ class PowerDBusProxy : public QObject
void BatteryPercentageChanged(double value) const;
void PowerSavingModeAutoWhenBatteryLowChanged(bool value) const;
void PowerSavingModeBrightnessDropPercentChanged(uint value) const;
void PowerSavingModeAutoBatteryPercentChanged(uint value) const;
void ModeChanged(const QString &value) const;
void BatteryCapacityChanged(double value) const;

Expand Down
10 changes: 10 additions & 0 deletions src/plugin-power/operation/powermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ PowerModel::PowerModel(QObject *parent)
, m_bPowerSavingModeAutoWhenQuantifyLow(0)
, m_bPowerSavingModeAuto(false)
, m_dPowerSavingModeLowerBrightnessThreshold(0)
, m_dPowerSavingModeAutoBatteryPercentage(0)
, m_nLinePowerPressPowerBtnAction(0)
, m_nLinePowerLidClosedAction(0)
, m_nBatteryPressPowerBtnAction(0)
Expand Down Expand Up @@ -204,6 +205,15 @@ void PowerModel::setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingMod
}
}

void PowerModel::setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModeAutoBatteryPercentage)
{
if (dPowerSavingModeAutoBatteryPercentage != m_dPowerSavingModeAutoBatteryPercentage) {
m_dPowerSavingModeAutoBatteryPercentage = dPowerSavingModeAutoBatteryPercentage;

Q_EMIT powerSavingModeAutoBatteryPercentageChanged(dPowerSavingModeAutoBatteryPercentage);
}
}

void PowerModel::setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction)
{
if (nLinePowerPressPowerBtnAction != m_nLinePowerPressPowerBtnAction) {
Expand Down
5 changes: 5 additions & 0 deletions src/plugin-power/operation/powermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class PowerModel : public QObject
inline int powerSavingModeLowerBrightnessThreshold() const { return m_dPowerSavingModeLowerBrightnessThreshold; }
void setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingModeLowerBrightnessThreshold);

inline int powerSavingModeAutoBatteryPercentage() const { return m_dPowerSavingModeAutoBatteryPercentage; }
void setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModeAutoBatteryPercentage);

inline int linePowerPressPowerBtnAction() const { return m_nLinePowerPressPowerBtnAction; }
void setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction);

Expand Down Expand Up @@ -146,6 +149,7 @@ class PowerModel : public QObject
void powerSavingModeAutoWhenQuantifyLowChanged(const bool state);
void powerSavingModeAutoChanged(const bool state);
void powerSavingModeLowerBrightnessThresholdChanged(const uint level);
void powerSavingModeAutoBatteryPercentageChanged(const uint level);
//electric
void linePowerPressPowerBtnActionChanged(const int reply);
void linePowerLidClosedActionChanged(const int reply);
Expand Down Expand Up @@ -184,6 +188,7 @@ class PowerModel : public QObject
bool m_bPowerSavingModeAutoWhenQuantifyLow;
bool m_bPowerSavingModeAuto;
uint m_dPowerSavingModeLowerBrightnessThreshold;
uint m_dPowerSavingModeAutoBatteryPercentage;
int m_nLinePowerPressPowerBtnAction;
int m_nLinePowerLidClosedAction;
int m_nBatteryPressPowerBtnAction;
Expand Down
6 changes: 6 additions & 0 deletions src/plugin-power/operation/powerworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ PowerWorker::PowerWorker(PowerModel *model, QObject *parent)
connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeAutoWhenBatteryLowChanged, m_powerModel, &PowerModel::setPowerSavingModeAutoWhenQuantifyLow);
connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeAutoChanged, m_powerModel, &PowerModel::setPowerSavingModeAuto);
connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeBrightnessDropPercentChanged, m_powerModel, &PowerModel::setPowerSavingModeLowerBrightnessThreshold);
connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeAutoBatteryPercentChanged, m_powerModel, &PowerModel::setPowerSavingModeAutoBatteryPercentage);
connect(m_powerDBusProxy, &PowerDBusProxy::LinePowerPressPowerBtnActionChanged, m_powerModel, &PowerModel::setLinePowerPressPowerBtnAction);
connect(m_powerDBusProxy, &PowerDBusProxy::LinePowerLidClosedActionChanged, m_powerModel, &PowerModel::setLinePowerLidClosedAction);
connect(m_powerDBusProxy, &PowerDBusProxy::BatteryPressPowerBtnActionChanged, m_powerModel, &PowerModel::setBatteryPressPowerBtnAction);
Expand Down Expand Up @@ -214,6 +215,11 @@ void PowerWorker::setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingMo
m_powerDBusProxy->setPowerSavingModeBrightnessDropPercent(dPowerSavingModeLowerBrightnessThreshold);
}

void PowerWorker::setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModeBatteryPercentage)
{
m_powerDBusProxy->setPowerSavingModeAutoBatteryPercent(dPowerSavingModeBatteryPercentage);
}

void PowerWorker::setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction)
{
m_powerDBusProxy->setLinePowerPressPowerBtnAction(nLinePowerPressPowerBtnAction);
Expand Down
1 change: 1 addition & 0 deletions src/plugin-power/operation/powerworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Q_SLOTS:
void setPowerSavingModeAutoWhenQuantifyLow(bool bLowBatteryAutoIntoSaveEnergyMode);
void setPowerSavingModeAuto(bool bAutoIntoSaveEnergyMode);
void setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingModeLowerBrightnessThreshold);
void setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModebatteryPentage);
void setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction);
void setLinePowerLidClosedAction(int nLinePowerLidClosedAction);
void setBatteryPressPowerBtnAction(int nBatteryPressPowerBtnAction);
Expand Down
48 changes: 48 additions & 0 deletions src/plugin-power/window/generalmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ GeneralModule::GeneralModule(PowerModel *model, PowerWorker *work, QObject *pare
&GeneralModule::requestSetPowerSavingModeLowerBrightnessThreshold,
m_work,
&PowerWorker::setPowerSavingModeLowerBrightnessThreshold);
connect(this,
&GeneralModule::requestSetPowerSavingModeAutoBatteryPercentage,
m_work,
&PowerWorker::setPowerSavingModeAutoBatteryPercentage);
connect(this, &GeneralModule::requestSetPowerPlan, m_work, &PowerWorker::setPowerPlan);
initUI();
}
Expand Down Expand Up @@ -198,7 +202,51 @@ void GeneralModule::initUI()
itemAutoPowerSavingOnLowBattery,
&ItemModule::setVisible);
group->appendChild(itemAutoPowerSavingOnLowBattery);
ItemModule *itemAutoPowerSavingOnBatterySlider = new ItemModule(
"decreaseBrightness",
tr("Decrease Brightness"),
[this](ModuleObject *module) -> QWidget * {
Q_UNUSED(module)
TitledSliderItem *sldLowerBrightness =
new TitledSliderItem(tr("Battery Percentage when enter power saving"));
sldLowerBrightness->setAccessibleName("Battery Percentage when enter power saving");
QStringList annotions;
annotions << "10%"
<< "20%"
<< "30%"
<< "50%"
<< "40%";
sldLowerBrightness->setAnnotations(annotions);
sldLowerBrightness->slider()->setRange(1, 5);
sldLowerBrightness->slider()->setPageStep(10);
sldLowerBrightness->slider()->setType(DCCSlider::Vernier);
sldLowerBrightness->slider()->setTickPosition(QSlider::NoTicks);

sldLowerBrightness->setValueLiteral(
QString("%1%").arg(m_model->powerSavingModeAutoBatteryPercentage()));
connect(m_model,
&PowerModel::powerSavingModeLowerBrightnessThresholdChanged,
sldLowerBrightness,
[sldLowerBrightness](const uint dLevel) {
sldLowerBrightness->slider()->blockSignals(true);
sldLowerBrightness->slider()->setValue(dLevel / 10);
sldLowerBrightness->slider()->blockSignals(false);
});
connect(sldLowerBrightness->slider(),
&DCCSlider::valueChanged,
this,
[=](int value) {
sldLowerBrightness->setValueLiteral(annotions[value - 1]);
Q_EMIT requestSetPowerSavingModeAutoBatteryPercentage(value * 10);
});
return sldLowerBrightness;
},
false);
itemAutoPowerSavingOnBatterySlider->setVisible(m_model->haveBettary());
connect(m_model,
&PowerModel::haveBettaryChanged,
itemAutoPowerSavingOnBatterySlider,
&ItemModule::setVisible);
ItemModule *itemAutoPowerSavingOnBattery =
new ItemModule("autoPowerSavingOnBattery",
tr("Auto power saving on battery"),
Expand Down
1 change: 1 addition & 0 deletions src/plugin-power/window/generalmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GeneralModule : public DCC_NAMESPACE::PageModule
void requestSetWakeDisplay(const bool &state); // 唤醒显示器输入密码
void requestSetPowerSaveMode(const bool &state); // 节能模式
void requestSetPowerSavingModeLowerBrightnessThreshold(const int &level); // 节能模式亮度降低
void requestSetPowerSavingModeAutoBatteryPercentage(const int &level); // 节能模式亮度降低
void requestSetPowerPlan(const QString &powerPlan); // 性能模式的设置
public Q_SLOTS:

Expand Down

0 comments on commit b3d6d70

Please sign in to comment.