Skip to content

Commit

Permalink
feat: support balance_performance
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
Decodetalkers committed Oct 24, 2023
1 parent 1542865 commit 86273ed
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/plugin-power/operation/powerdbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ bool PowerDBusProxy::isHighPerformanceSupported()
return qvariant_cast<bool>(m_powerInter->property("IsHighPerformanceSupported"));
}

bool PowerDBusProxy::isBalacnePerformanceSupported()
{
return qvariant_cast<bool>(m_powerInter->property("IsBalacnePerformanceSupported"));
}

int PowerDBusProxy::linePowerScreenBlackDelay()
{
return qvariant_cast<int>(m_powerInter->property("LinePowerScreenBlackDelay"));
Expand Down
3 changes: 3 additions & 0 deletions src/plugin-power/operation/powerdbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class PowerDBusProxy : public QObject
void setBatteryLidClosedAction(int value);
Q_PROPERTY(bool IsHighPerformanceSupported READ isHighPerformanceSupported NOTIFY IsHighPerformanceSupportedChanged)
bool isHighPerformanceSupported();
Q_PROPERTY(bool IsBalacnePerformanceSupported READ isBalacnePerformanceSupportedChanged NOTIFY IsBalacnePerformanceSupportedChanged)
bool isBalacnePerformanceSupported();
Q_PROPERTY(int LinePowerScreenBlackDelay READ linePowerScreenBlackDelay WRITE setLinePowerScreenBlackDelay NOTIFY LinePowerScreenBlackDelayChanged)
int linePowerScreenBlackDelay();
void setLinePowerScreenBlackDelay(int value);
Expand Down Expand Up @@ -116,6 +118,7 @@ class PowerDBusProxy : public QObject
void BatteryLockDelayChanged(int value) const;
void LinePowerLockDelayChanged(int value) const;
void IsHighPerformanceSupportedChanged(bool value) const;
void IsBalacnePerformanceSupportedChanged(bool value) const;
void LinePowerPressPowerBtnActionChanged(int value) const;
void LinePowerLidClosedActionChanged(int value) const;
void BatteryPressPowerBtnActionChanged(int value) const;
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 @@ -40,6 +40,7 @@ PowerModel::PowerModel(QObject *parent)
, m_isShutdown(false)
, m_powerPlan("")
, m_isHighPerformanceSupported(false)
, m_isBalancePerformanceSupported(false)
{
}

Expand Down Expand Up @@ -321,6 +322,14 @@ void PowerModel::setHighPerformanceSupported(bool isHighSupport)
Q_EMIT highPerformaceSupportChanged(isHighSupport);
}

void PowerModel::setBalancePerformanceSupported(bool isBalancePerformanceSupported)
{
if (m_isBalancePerformanceSupported == isBalancePerformanceSupported)
return;
m_isBalancePerformanceSupported = isBalancePerformanceSupported;
Q_EMIT highPerformaceSupportChanged(isBalancePerformanceSupported);
}

void PowerModel::setSuspend(bool suspend)
{
if (suspend == m_isSuspend)
Expand Down
3 changes: 3 additions & 0 deletions src/plugin-power/operation/powermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class PowerModel : public QObject
inline bool isHighPerformanceSupported() const { return m_isHighPerformanceSupported; }
void setHighPerformanceSupported(bool isHighSupport);

inline bool isBalancePerformanceSupported() const { return m_isBalancePerformanceSupported; }
void setBalancePerformanceSupported(bool isBalancePerformanceSupported);
// ----
inline bool isNoPasswdLogin() const { return m_noPasswdLogin; }

Expand Down Expand Up @@ -211,6 +213,7 @@ class PowerModel : public QObject

QString m_powerPlan;
bool m_isHighPerformanceSupported;
bool m_isBalancePerformanceSupported;

// Account
bool m_noPasswdLogin;
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 @@ -85,6 +85,7 @@ void PowerWorker::active()
m_powerModel->setNoPasswdLogin(m_powerDBusProxy->noPasswdLogin());

setHighPerformanceSupported(m_powerDBusProxy->isHighPerformanceSupported());
setBalancePerformanceSupported(m_powerDBusProxy->isBalacnePerformanceSupported());

setScreenBlackDelayToModelOnPower(m_powerDBusProxy->linePowerScreenBlackDelay());
setSleepDelayToModelOnPower(m_powerDBusProxy->linePowerSleepDelay());
Expand Down Expand Up @@ -204,6 +205,11 @@ void PowerWorker::setHighPerformanceSupported(bool state)
m_powerModel->setHighPerformanceSupported(state);
}

void PowerWorker::setBalancePerformanceSupported(bool state)
{
m_powerModel->setBalancePerformanceSupported(state);
}

void PowerWorker::setPowerSavingModeAutoWhenQuantifyLow(bool bLowBatteryAutoIntoSaveEnergyMode)
{
m_powerDBusProxy->setPowerSavingModeAutoWhenBatteryLow(bLowBatteryAutoIntoSaveEnergyMode);
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 @@ -35,6 +35,7 @@ public Q_SLOTS:
void setResponseBatteryLockScreenDelay(const int delay);
void setResponsePowerLockScreenDelay(const int delay);
void setHighPerformanceSupported(bool state);
void setBalancePerformanceSupported(bool state);
//------------sp2 add-----------------------
void setPowerSavingModeAutoWhenQuantifyLow(bool bLowBatteryAutoIntoSaveEnergyMode);
void setPowerSavingModeAuto(bool bAutoIntoSaveEnergyMode);
Expand Down
48 changes: 44 additions & 4 deletions src/plugin-power/window/generalmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#include <DListView>
#include <DSwitchButton>

#define BALANCE "balance" // 平衡模式
#define PERFORMANCE "performance" // 高性能模式
#define POWERSAVE "powersave" // 节能模式
#define BALANCE "balance" // 平衡模式
#define PERFORMANCE "performance" // 高性能模式
#define BALANCEPERFORMANCE "balance_performance" // 高性能模式
#define POWERSAVE "powersave" // 节能模式

using namespace DCC_NAMESPACE;
DGUI_USE_NAMESPACE
Expand All @@ -33,6 +34,7 @@ GeneralModule::GeneralModule(PowerModel *model, PowerWorker *work, QObject *pare
{
m_powerPlanMap.insert(BALANCE, tr("Balanced"));
m_powerPlanMap.insert(PERFORMANCE, tr("High Performance"));
m_powerPlanMap.insert(BALANCEPERFORMANCE, tr("Balance Performance"));
m_powerPlanMap.insert(POWERSAVE, tr("Power Saver"));

connect(this, &GeneralModule::requestSetWakeDisplay, m_work, &PowerWorker::setScreenBlackLock);
Expand Down Expand Up @@ -133,7 +135,44 @@ void GeneralModule::initUI()
}
};
onHighPerformanceSupportChanged(m_model->isHighPerformanceSupported());
auto onBalancePerformanceSupportedChanged = [this, powerplanListview](
const bool isSupport) {
int row_count = m_powerPlanModel->rowCount();
if (!isSupport) {
int cur_place = powerplanListview->currentIndex().row();
for (int i = 0; i < row_count; ++i) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == BALANCEPERFORMANCE) {
m_powerPlanModel->removeRow(i);

if (cur_place == i || cur_place < 0) {
powerplanListview->clicked(m_powerPlanModel->index(0, 0));
}
break;
}
}
} else {
bool findHighPerform = false;
for (int i = 0; i < row_count; ++i) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == PERFORMANCE) {
findHighPerform = true;
break;
}
}
if (!findHighPerform) {
DStandardItem *powerPlanItem =
new DStandardItem(m_powerPlanMap.value(BALANCEPERFORMANCE));
powerPlanItem->setData(PERFORMANCE, PowerPlanRole);
if (row_count == 2) { // NOTE: means there is no High Performance, but it should be impossible
m_powerPlanModel->insertRow(1, powerPlanItem);
} else {
m_powerPlanModel->insertRow(2, powerPlanItem);
}
}
}
};
onBalancePerformanceSupportedChanged(m_model->isBalancePerformanceSupported());
connect(powerplanListview,
&DListView::clicked,
this,
Expand Down Expand Up @@ -220,7 +259,8 @@ void GeneralModule::initUI()
sldLowerBrightness->slider()->setPageStep(10);
sldLowerBrightness->slider()->setType(DCCSlider::Vernier);
sldLowerBrightness->slider()->setTickPosition(QSlider::NoTicks);
sldLowerBrightness->slider()->setValue(m_model->powerSavingModeAutoBatteryPercentage() / 10);
sldLowerBrightness->slider()->setValue(
m_model->powerSavingModeAutoBatteryPercentage() / 10);

sldLowerBrightness->setValueLiteral(
QString("%1%").arg(m_model->powerSavingModeAutoBatteryPercentage()));
Expand Down

0 comments on commit 86273ed

Please sign in to comment.