Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support balance_performance #1458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::isBalancePerformanceSupported()
{
return qvariant_cast<bool>(m_sysPowerInter->property("IsBalancePerformanceSupported"));
}

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 IsBalancePerformanceSupported READ isBalancePerformanceSupported NOTIFY IsBalancePerformanceSupportedChanged)
bool isBalancePerformanceSupported();
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 IsBalancePerformanceSupportedChanged(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->isBalancePerformanceSupported());

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
89 changes: 79 additions & 10 deletions src/plugin-power/window/generalmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,38 @@
#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
DWIDGET_USE_NAMESPACE

static QString get_translate(const QString &type)
{
if (type == BALANCE) {
return QObject::tr("Auto adjust CPU operating frequency based on CPU load condition");
}
if (type == BALANCEPERFORMANCE) {
return QObject::tr(
"Aggressively adjust CPU operating frequency based on CPU load condition");
}
if (type == PERFORMANCE) {
return QObject::tr("Be good to imporving performance, but power consumption and heat "
"generation will increase");
}
return QObject::tr("CPU always works under low frequency, will reduce power consumption");
}

GeneralModule::GeneralModule(PowerModel *model, PowerWorker *work, QObject *parent)
: PageModule("general", tr("General"), DIconTheme::findQIcon("dcc_general_purpose"), parent)
, m_model(model)
, m_work(work)
{
m_powerPlanMap.insert(BALANCE, tr("Balanced"));
m_powerPlanMap.insert(BALANCEPERFORMANCE, tr("Balance Performance"));
m_powerPlanMap.insert(PERFORMANCE, tr("High Performance"));
m_powerPlanMap.insert(POWERSAVE, tr("Power Saver"));

Expand Down Expand Up @@ -77,8 +95,15 @@ void GeneralModule::initUI()
QMap<QString, QString>::iterator iter;
for (iter = m_powerPlanMap.begin(); iter != m_powerPlanMap.end(); ++iter) {
DStandardItem *powerPlanItem = new DStandardItem(iter.value());
DStandardItem *powerPlanItemTip = new DStandardItem(::get_translate(iter.key()));
powerPlanItemTip->setEnabled(false);
powerPlanItemTip->setEditable(false);
powerPlanItemTip->setBackgroundRole(DPalette::Window);
powerPlanItemTip->setTextColorRole(DPalette::TextTips);
powerPlanItemTip->setSizeHint(QSize(-1, 20));
powerPlanItem->setData(iter.key(), PowerPlanRole);
m_powerPlanModel->appendRow(powerPlanItem);
m_powerPlanModel->appendRow(powerPlanItemTip);
}

//  性能设置
Expand All @@ -94,7 +119,7 @@ void GeneralModule::initUI()
powerplanListview->setModel(m_powerPlanModel);
powerplanListview->setEditTriggers(QAbstractItemView::NoEditTriggers);
powerplanListview->setBackgroundType(
DStyledItemDelegate::BackgroundType::ClipCornerBackground);
DStyledItemDelegate::BackgroundType::RoundedBackground);
powerplanListview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
powerplanListview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
powerplanListview->setSelectionMode(QAbstractItemView::NoSelection);
Expand All @@ -104,10 +129,10 @@ void GeneralModule::initUI()
int row_count = m_powerPlanModel->rowCount();
if (!isSupport) {
int cur_place = powerplanListview->currentIndex().row();
for (int i = 0; i < row_count; ++i) {
for (int i = 0; i < row_count; i += 2) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == PERFORMANCE) {
m_powerPlanModel->removeRow(i);
m_powerPlanModel->removeRows(i, 2);

if (cur_place == i || cur_place < 0) {
powerplanListview->clicked(m_powerPlanModel->index(0, 0));
Expand All @@ -117,7 +142,7 @@ void GeneralModule::initUI()
}
} else {
bool findHighPerform = false;
for (int i = 0; i < row_count; ++i) {
for (int i = 0; i < row_count; i += 2) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == PERFORMANCE) {
findHighPerform = true;
Expand All @@ -128,12 +153,55 @@ void GeneralModule::initUI()
DStandardItem *powerPlanItem =
new DStandardItem(m_powerPlanMap.value(PERFORMANCE));
powerPlanItem->setData(PERFORMANCE, PowerPlanRole);
m_powerPlanModel->insertRow(1, powerPlanItem);
if (row_count == 6) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑用 insertRows,放置下标错乱问题,

DStandardItem *powerPlanItemTip =
new DStandardItem(::get_translate(PERFORMANCE));
m_powerPlanModel->insertRow(4, { powerPlanItem, powerPlanItemTip });
} else {
DStandardItem *powerPlanItemTip =
new DStandardItem(::get_translate(PERFORMANCE));
m_powerPlanModel->insertRow(2, { powerPlanItem, powerPlanItemTip });
}
}
}
};
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 += 2) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == BALANCEPERFORMANCE) {
m_powerPlanModel->removeRows(i, 2);

if (cur_place == i || cur_place < 0) {
powerplanListview->clicked(m_powerPlanModel->index(0, 0));
}
break;
}
}
} else {
bool findBalancePerform = false;
for (int i = 0; i < row_count; i += 2) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == BALANCEPERFORMANCE) {
findBalancePerform = true;
break;
}
}
if (!findBalancePerform) {
DStandardItem *powerPlanItem =
new DStandardItem(m_powerPlanMap.value(BALANCEPERFORMANCE));
powerPlanItem->setData(PERFORMANCE, PowerPlanRole);
DStandardItem *powerPlanItemTip =
new DStandardItem(::get_translate(BALANCEPERFORMANCE));
m_powerPlanModel->insertRow(2, { powerPlanItem, powerPlanItemTip });
}
}
};
onBalancePerformanceSupportedChanged(m_model->isBalancePerformanceSupported());
connect(powerplanListview,
&DListView::clicked,
this,
Expand All @@ -150,7 +218,7 @@ void GeneralModule::initUI()

auto onCurPowerPlanChanged = [this](const QString &curPowerPlan) {
int row_count = m_powerPlanModel->rowCount();
for (int i = 0; i < row_count; ++i) {
for (int i = 0; i < row_count; i += 2) {
QStandardItem *items = m_powerPlanModel->item(i, 0);
if (items->data(PowerPlanRole).toString() == curPowerPlan) {
items->setCheckState(Qt::Checked);
Expand Down Expand Up @@ -220,7 +288,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
Loading