bug fix:
1、极低电量提示信息显示不全的问题、按设计要求修改窗口; 2、连续调节亮度存在延迟的问题; 3、控制面板及托盘电源模式不同步的问题; 4、“此时间段进入睡眠”选项显示异常; 5、电池供电下,开机后短暂显示“正在充电”的问题; 6、开启节电计划的电量,无法存储的问题。
This commit is contained in:
parent
21ee22b7e0
commit
ea41f322c6
|
@ -427,9 +427,6 @@ void Power::batterySavingWidget()
|
|||
mNoticeLayout->addWidget(mLowBatteryAutoSavingLebel);
|
||||
mNoticeLayout->addSpacerItem(new QSpacerItem(0,160,QSizePolicy::Expanding,QSizePolicy::Expanding));
|
||||
mNoticeLayout->addWidget(mLowBatteryAutoSavingBtn);
|
||||
|
||||
|
||||
|
||||
BatteryLayout->addWidget(mNoticeLFrame);
|
||||
}
|
||||
|
||||
|
@ -544,22 +541,23 @@ void Power::setupComponent()
|
|||
mSleepComboBox->insertItem(6, sleepStringList.at(6), QVariant::fromValue(0));
|
||||
|
||||
//电源计划
|
||||
PowerplanStringList << tr("Balance Model") << tr("Save Model") << tr("Performance Model");
|
||||
mPowerComboBox->insertItem(0, PowerplanStringList.at(0), "Balance Model");
|
||||
mPowerComboBox->insertItem(1, PowerplanStringList.at(1), "Save Model");
|
||||
PowerplanStringList << tr("Save Model") << tr("Balance Model") << tr("Performance Model");
|
||||
mPowerComboBox->insertItem(0, PowerplanStringList.at(0), "Save Model");
|
||||
mPowerComboBox->insertItem(1, PowerplanStringList.at(1), "Balance Model");
|
||||
mPowerComboBox->insertItem(2, PowerplanStringList.at(2), "Performance Model");
|
||||
|
||||
BatteryplanStringList << tr("Balance Model") << tr("Save Model") << tr("Performance Model");
|
||||
mBatteryComboBox->insertItem(0, BatteryplanStringList.at(0), "Balance Model");
|
||||
mBatteryComboBox->insertItem(1, BatteryplanStringList.at(1), "Save Model");
|
||||
BatteryplanStringList << tr("Save Model") << tr("Balance Model") << tr("Performance Model");
|
||||
mBatteryComboBox->insertItem(0, BatteryplanStringList.at(0), "Save Model");
|
||||
mBatteryComboBox->insertItem(1, BatteryplanStringList.at(1), "Balance Model");
|
||||
mBatteryComboBox->insertItem(2, BatteryplanStringList.at(2), "Performance Model");
|
||||
|
||||
LowpowerStringList << tr("shutdown");
|
||||
|
||||
//低电量通知
|
||||
for (int i = 1; i < 5; i++) {
|
||||
mNoticeComboBox->insertItem(i - 1, QString("%1%").arg(i * 10));
|
||||
}
|
||||
mNoticeComboBox->insertItem(0, "10%", QVariant::fromValue(10));
|
||||
mNoticeComboBox->insertItem(1, "20%", QVariant::fromValue(20));
|
||||
mNoticeComboBox->insertItem(2, "30%", QVariant::fromValue(30));
|
||||
mNoticeComboBox->insertItem(3, "40%", QVariant::fromValue(40));
|
||||
}
|
||||
void Power::setupConnect()
|
||||
{
|
||||
|
@ -575,24 +573,7 @@ void Power::setupConnect()
|
|||
|
||||
connect(mPowerKeyComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
// 设置电源键
|
||||
settings->set(BUTTON_POWER_KEY, mPowerKeyComboBox->itemData(index));
|
||||
});
|
||||
|
||||
connect(mSleepComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
Q_UNUSED(index)
|
||||
int closeDisplayTime = mCloseComboBox->currentData(Qt::UserRole).toInt() * 60;
|
||||
int sleepComputerTime = mSleepComboBox->currentData(Qt::UserRole).toInt() * 60;
|
||||
if (0 == sleepComputerTime) {
|
||||
setConfigValue(SLEEP_COMPUTER_AC, -1);
|
||||
setConfigValue(SLEEP_COMPUTER_BATTERY, -1);
|
||||
} else {
|
||||
setConfigValue(SLEEP_COMPUTER_AC, QVariant(sleepComputerTime));
|
||||
setConfigValue(SLEEP_COMPUTER_BATTERY, QVariant(sleepComputerTime));
|
||||
if (sleepComputerTime < closeDisplayTime) {
|
||||
setConfigValue(SLEEP_DISPLAY_AC_KEY, QVariant(sleepComputerTime));
|
||||
setConfigValue(SLEEP_DISPLAY_BAT_KEY, QVariant(sleepComputerTime));
|
||||
}
|
||||
}
|
||||
settings->set(BUTTON_POWER_KEY, mPowerKeyComboBox->itemData(index));
|
||||
});
|
||||
|
||||
connect(mCloseComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
|
@ -605,36 +586,41 @@ void Power::setupConnect()
|
|||
} else {
|
||||
setConfigValue(SLEEP_DISPLAY_AC_KEY, QVariant(closeDisplayTime));
|
||||
setConfigValue(SLEEP_DISPLAY_BAT_KEY, QVariant(closeDisplayTime));
|
||||
if (closeDisplayTime > sleepComputerTime) {
|
||||
if (0 != sleepComputerTime && closeDisplayTime > sleepComputerTime) {
|
||||
setConfigValue(SLEEP_COMPUTER_AC, QVariant(closeDisplayTime));
|
||||
setConfigValue(SLEEP_COMPUTER_BATTERY, QVariant(closeDisplayTime));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(mSleepComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
Q_UNUSED(index)
|
||||
int closeDisplayTime = mCloseComboBox->currentData(Qt::UserRole).toInt() * 60;
|
||||
int sleepComputerTime = mSleepComboBox->currentData(Qt::UserRole).toInt() * 60;
|
||||
if (0 == sleepComputerTime) {
|
||||
setConfigValue(SLEEP_COMPUTER_AC, -1);
|
||||
setConfigValue(SLEEP_COMPUTER_BATTERY, -1);
|
||||
} else {
|
||||
setConfigValue(SLEEP_COMPUTER_AC, QVariant(sleepComputerTime));
|
||||
setConfigValue(SLEEP_COMPUTER_BATTERY, QVariant(sleepComputerTime));
|
||||
if (closeDisplayTime > sleepComputerTime) {
|
||||
setConfigValue(SLEEP_DISPLAY_AC_KEY, QVariant(sleepComputerTime));
|
||||
setConfigValue(SLEEP_DISPLAY_BAT_KEY, QVariant(sleepComputerTime));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(mCloseLidComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
setConfigValue(BUTTON_LID_AC, mCloseLidComboBox->itemData(index));
|
||||
setConfigValue(BUTTON_LID_BATTERY, mCloseLidComboBox->itemData(index));
|
||||
});
|
||||
|
||||
connect(mPowerComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
if (index == 0) {
|
||||
setConfigValue(POWER_POLICY_AC, 1);
|
||||
} else if (index == 1) {
|
||||
setConfigValue(POWER_POLICY_AC, 2);
|
||||
} else {
|
||||
setConfigValue(POWER_POLICY_AC, 0);
|
||||
}
|
||||
setConfigValue(POWER_POLICY_AC, index);
|
||||
});
|
||||
|
||||
connect(mBatteryComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
if (index == 0) {
|
||||
setConfigValue(POWER_POLICY_BATTERY, 1);
|
||||
} else if (index == 1) {
|
||||
setConfigValue(POWER_POLICY_BATTERY, 2);
|
||||
} else {
|
||||
setConfigValue(POWER_POLICY_BATTERY, 0);
|
||||
}
|
||||
setConfigValue(POWER_POLICY_BATTERY, index);
|
||||
});
|
||||
|
||||
connect(screensettings, &QGSettings::changed, [=]() {
|
||||
|
@ -665,6 +651,10 @@ void Power::setupConnect()
|
|||
qDebug()<<"BATTERY_SAVER_AUTO"<<checked;
|
||||
});
|
||||
|
||||
connect(mNoticeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
Q_UNUSED(index)
|
||||
setConfigValue(BATTERY_SAVER_PERCENT, mNoticeComboBox->currentData(Qt::UserRole).toInt());
|
||||
});
|
||||
|
||||
QDBusConnection::sessionBus().connect(
|
||||
UKUI_UPOWER_SERVICE,
|
||||
|
@ -678,8 +668,10 @@ void Power::setupConnect()
|
|||
void Power::initCustomPlanStatus(QStringList list)
|
||||
{
|
||||
if (mFirstLoad) {
|
||||
list << SLEEP_COMPUTER_AC << SLEEP_DISPLAY_AC_KEY << BUTTON_LID_AC << POWER_POLICY_AC << POWER_POLICY_BATTERY
|
||||
<< CRITICAL_BATTERY << ACTION_CRITICAL_BATTERY << LOW_BATTERY << BATTERY_SAVER << BATTERY_SAVER_BRIGHTNESS <<BATTERY_SAVER_AUTO;
|
||||
list << SLEEP_COMPUTER_AC << SLEEP_DISPLAY_AC_KEY << BUTTON_LID_AC
|
||||
<< POWER_POLICY_AC << POWER_POLICY_BATTERY << CRITICAL_BATTERY
|
||||
<< ACTION_CRITICAL_BATTERY << LOW_BATTERY << BATTERY_SAVER
|
||||
<< BATTERY_SAVER_BRIGHTNESS << BATTERY_SAVER_AUTO << BATTERY_SAVER_PERCENT;
|
||||
}
|
||||
// 信号阻塞
|
||||
mPowerKeyComboBox->blockSignals(true);
|
||||
|
@ -711,22 +703,10 @@ void Power::initCustomPlanStatus(QStringList list)
|
|||
mCloseLidComboBox->setCurrentIndex(mCloseLidComboBox->findData(getPowerConfData("GetButtonLidAc", t1.Str)));
|
||||
}
|
||||
if (-1 != list.indexOf(POWER_POLICY_AC)) {
|
||||
if (1 == getPowerConfData("GetPowerPolicyAc", t1.Int)) {
|
||||
mPowerComboBox->setCurrentIndex(0);
|
||||
} else if (2 == getPowerConfData("GetPowerPolicyAc", t1.Int)) {
|
||||
mPowerComboBox->setCurrentIndex(1);
|
||||
} else {
|
||||
mPowerComboBox->setCurrentIndex(2);
|
||||
}
|
||||
mPowerComboBox->setCurrentIndex(getPowerConfData("GetPowerPolicyAc", t1.Int));
|
||||
}
|
||||
if (-1 != list.indexOf(POWER_POLICY_BATTERY)) {
|
||||
if (1 == getPowerConfData("GetPowerPolicyBat", t1.Int)) {
|
||||
mBatteryComboBox->setCurrentIndex(0);
|
||||
} else if (2 == getPowerConfData("GetPowerPolicyBat", t1.Int)) {
|
||||
mBatteryComboBox->setCurrentIndex(1);
|
||||
} else {
|
||||
mBatteryComboBox->setCurrentIndex(2);
|
||||
}
|
||||
mBatteryComboBox->setCurrentIndex(getPowerConfData("GetPowerPolicyBat", t1.Int));
|
||||
}
|
||||
|
||||
if (-1 != list.indexOf(BATTERY_SAVER)) {
|
||||
|
@ -751,6 +731,12 @@ void Power::initCustomPlanStatus(QStringList list)
|
|||
mLowBatteryAutoSavingBtn->setChecked(getPowerConfData("GetBatterySaverAuto", t1.Bool));
|
||||
}
|
||||
|
||||
if (-1 != list.indexOf(BATTERY_SAVER_PERCENT)) {
|
||||
qDebug()<<"GetBatterySaverPercent"<<getPowerConfData("GetBatterySaverPercent", t1.Int);
|
||||
mNoticeComboBox->setCurrentIndex(
|
||||
mNoticeComboBox->findData(getPowerConfData("GetBatterySaverPercent", t1.Int)));
|
||||
}
|
||||
|
||||
// 信号阻塞解除
|
||||
mPowerKeyComboBox->blockSignals(false);
|
||||
mCloseComboBox->blockSignals(false);
|
||||
|
|
|
@ -126,6 +126,7 @@ void PowerTray::onActivatedIcon(QSystemTrayIcon::ActivationReason reason)
|
|||
powerWindow->hide();
|
||||
return;
|
||||
}
|
||||
powerWindow->setSliderValue();
|
||||
powerWindow->set_window_position();
|
||||
KWindowSystem::setState(powerWindow->winId(), NET::SkipTaskbar | NET::SkipPager);
|
||||
powerWindow->show();
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#define POWER_POLICY_AC "powerPolicyAc"
|
||||
#define POWER_POLICY_BATTERY "powerPolicyBattery"
|
||||
|
||||
|
||||
static const char *g_policyNameList[3] = {"Better endurance", "Better performance", "Best performance"};
|
||||
|
||||
powerwindow::powerwindow(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -77,6 +77,7 @@ powerwindow::powerwindow(QWidget *parent) : QWidget(parent)
|
|||
setWindowProperty(); //设置窗口属性
|
||||
initUI(); //初始化UI
|
||||
initgsetting();
|
||||
initPowerConfig();
|
||||
// set_window_position(); //设置出现在屏幕的位置以及大小
|
||||
watchTranspartency();
|
||||
#if 0
|
||||
|
@ -139,7 +140,6 @@ void powerwindow::initUI()
|
|||
percentageLabel = new PercentageLabel();
|
||||
|
||||
powerStateLabel = new QLabel(this);
|
||||
powerStateLabel->setText(tr("Charging"));
|
||||
powerStateLabel->setVisible(false);
|
||||
|
||||
powerTimeToEmpty = new QLabel(this);
|
||||
|
@ -234,6 +234,59 @@ void powerwindow::initUI()
|
|||
this->setLayout(m_pmainlayout);
|
||||
}
|
||||
|
||||
void powerwindow::initPowerConfig()
|
||||
{
|
||||
m_powerManagerInterface = new QDBusInterface("org.ukui.powermanagement", "/",
|
||||
"org.ukui.powermanagement.interface", QDBusConnection::systemBus(), this);
|
||||
|
||||
m_powerConfig = new QSettings(POWER_MANAGER_CONF_PATH, QSettings::NativeFormat, this);
|
||||
m_powerPolicyAC = 0;
|
||||
m_powerPolicyBAT = 0;
|
||||
getPowerConfig();
|
||||
|
||||
m_watcherPowerConfig = new QFileSystemWatcher(this);
|
||||
m_watcherPowerConfig->addPath(POWER_MANAGER_CONF_PATH);
|
||||
connect(m_watcherPowerConfig, &QFileSystemWatcher::fileChanged, this, &powerwindow::powerConfigChangedHandle);
|
||||
}
|
||||
|
||||
void powerwindow::powerConfigChangedHandle(const QString &path)
|
||||
{
|
||||
m_watcherPowerConfig->addPath(path);
|
||||
getPowerConfig();
|
||||
}
|
||||
|
||||
void powerwindow::getPowerConfig()
|
||||
{
|
||||
m_powerConfig->sync();
|
||||
m_powerConfig->beginGroup(POWER_MANAGER_CONF_PREFIX);
|
||||
m_powerPolicyAC = m_powerConfig->value(POWER_POLICY_AC).toInt();
|
||||
m_powerPolicyBAT = m_powerConfig->value(POWER_POLICY_BATTERY).toInt();
|
||||
m_powerConfig->endGroup();
|
||||
}
|
||||
|
||||
void powerwindow::sliderValueChanged(int value)
|
||||
{
|
||||
qDebug() << "slider value" << value << m_batteryState;
|
||||
|
||||
m_StateSlider->setToolTip(tr(g_policyNameList[value]));
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
setConfigValue(POWER_POLICY_AC, value);
|
||||
} else {
|
||||
setConfigValue(POWER_POLICY_BATTERY, value);
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::setSliderValue()
|
||||
{
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
m_StateSlider->setValue(m_powerPolicyAC);
|
||||
m_StateSlider->setToolTip(tr(g_policyNameList[m_powerPolicyAC]));
|
||||
} else {
|
||||
m_StateSlider->setValue(m_powerPolicyBAT);
|
||||
m_StateSlider->setToolTip(tr(g_policyNameList[m_powerPolicyBAT]));
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::initgsetting()
|
||||
{
|
||||
const QByteArray styleId(ORG_UKUI_STYLE);
|
||||
|
@ -247,22 +300,14 @@ void powerwindow::initgsetting()
|
|||
});
|
||||
m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt();
|
||||
}
|
||||
|
||||
const QByteArray powerId(POWER_MANAGER_SETTINGS);
|
||||
m_PowerManagerGsettings = new QGSettings(powerId);
|
||||
qDebug() << "gsettings init";
|
||||
connect(m_PowerManagerGsettings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if (key == POWER_POLICY_AC || key == POWER_POLICY_BATTERY) {
|
||||
qDebug() << "m_PowerManagerGsettings changed !";
|
||||
setSliderValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void powerwindow::get_power_list()
|
||||
{
|
||||
int size;
|
||||
size = ed->devices.size();
|
||||
int batteryState;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
DEVICE *dv;
|
||||
dv = ed->devices.at(i);
|
||||
|
@ -274,7 +319,16 @@ void powerwindow::get_power_list()
|
|||
|
||||
if (dv->m_dev.kind == UP_DEVICE_KIND_BATTERY) {
|
||||
percentageLabel->setText(QString("%1%").arg(dv->m_dev.Percentage));
|
||||
|
||||
batteryState = dv->m_dev.State;
|
||||
if (UP_DEVICE_STATE_CHARGING == batteryState) {
|
||||
powerStateLabel->setText(tr("Charging"));
|
||||
} else if (UP_DEVICE_STATE_DISCHARGING == batteryState) {
|
||||
powerStateLabel->setText(tr("Discharging"));
|
||||
} else if (UP_DEVICE_STATE_FULLY_CHARGED == batteryState) {
|
||||
powerStateLabel->setText(tr("fully charged"));
|
||||
} else {
|
||||
;
|
||||
}
|
||||
powerStateLabel->setVisible(true);
|
||||
powerTimeToEmpty->setVisible(false);
|
||||
}
|
||||
|
@ -322,34 +376,6 @@ void powerwindow::onBatteryChanged(QStringList args)
|
|||
percentageLabel->setText(QString("%1%").arg(battery));
|
||||
}
|
||||
|
||||
void powerwindow::chargeNotify(bool state)
|
||||
{
|
||||
// qDebug() << "powerwindow::chargeNotify";
|
||||
// if (!state) {
|
||||
// QList<QVariant> args;
|
||||
// args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("charge notification")
|
||||
// << tr("battery is charging") << QStringList() << QVariantMap() << (int)-1;
|
||||
// m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
// } else {
|
||||
// QList<QVariant> args;
|
||||
// args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("discharged notification")
|
||||
// << tr("battery is discharging") << QStringList() << QVariantMap() << (int)-1;
|
||||
// m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
// }
|
||||
}
|
||||
|
||||
void powerwindow::full_charge_notify(DEV dev)
|
||||
{
|
||||
// qDebug() << "powerwindow::full_charge_notify";
|
||||
// QList<QVariant> args;
|
||||
// args << tr("Power Manager")
|
||||
// << ((unsigned int)0)
|
||||
// // <<QString("battery-level-100-symbolic")
|
||||
// << "ukui-power-manager" << tr("fullly charged notification") << tr("battery is fullly charged")
|
||||
// << QStringList() << QVariantMap() << (int)-1;
|
||||
// m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
||||
|
||||
void powerwindow::lowBatteryNotify() {}
|
||||
|
||||
void powerwindow::criticalBatteryNotify() {}
|
||||
|
@ -412,73 +438,6 @@ void powerwindow::watchTranspartency()
|
|||
}
|
||||
}
|
||||
|
||||
void powerwindow::sliderValueChanged(int value)
|
||||
{
|
||||
qDebug() << "slider value" << value << m_batteryState;
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, EnergySaving);
|
||||
m_StateSlider->setToolTip(tr("Better endurance"));
|
||||
break;
|
||||
case 1:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, Balance);
|
||||
m_StateSlider->setToolTip(tr("Better performance"));
|
||||
break;
|
||||
case 2:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, Performance);
|
||||
m_StateSlider->setToolTip(tr("Best performance"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (value) {
|
||||
case 0:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, EnergySaving);
|
||||
m_StateSlider->setToolTip(tr("Better endurance"));
|
||||
break;
|
||||
case 1:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Balance);
|
||||
m_StateSlider->setToolTip(tr("Better performance"));
|
||||
break;
|
||||
case 2:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Performance);
|
||||
m_StateSlider->setToolTip(tr("Best performance"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::setSliderValue()
|
||||
{
|
||||
int policy = -1;
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
policy = m_PowerManagerGsettings->get(POWER_POLICY_AC).toInt();
|
||||
} else {
|
||||
policy = m_PowerManagerGsettings->get(POWER_POLICY_BATTERY).toInt();
|
||||
}
|
||||
qDebug() << "powerwindow::setSliderValue m_batteryState ; policy is :" << m_batteryState << policy;
|
||||
switch (policy) {
|
||||
case Performance:
|
||||
m_StateSlider->setValue(2);
|
||||
m_StateSlider->setToolTip(tr("Best performance"));
|
||||
break;
|
||||
case Balance:
|
||||
m_StateSlider->setValue(1);
|
||||
m_StateSlider->setToolTip(tr("Better performance"));
|
||||
break;
|
||||
case EnergySaving:
|
||||
m_StateSlider->setValue(0);
|
||||
m_StateSlider->setToolTip(tr("Better endurance"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QStyleOption opt;
|
||||
|
@ -507,3 +466,12 @@ bool powerwindow::eventFilter(QObject *watched, QEvent *event)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::setConfigValue(const QString key, const QVariant value)
|
||||
{
|
||||
QDBusVariant v1;
|
||||
QVariant v2;
|
||||
v1.setVariant(value);
|
||||
v2.setValue(v1);
|
||||
m_powerManagerInterface->call("SetPowerConfig", key, v2);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
#define KYLIN_BATTERY_CHARGING100_PATH1 ":/charging/battery1/1.svg"
|
||||
#define KYLIN_BATTERY_00_PATH1 ":/charging/battery1/1.svg"
|
||||
|
||||
#define POWER_MANAGER_CONF_PATH "/etc/power/power-manager.conf"
|
||||
#define POWER_MANAGER_CONF_PREFIX "config"
|
||||
|
||||
class powerwindow : public QWidget
|
||||
{
|
||||
|
@ -109,6 +111,7 @@ public:
|
|||
QMap<DEVICE*,QListWidgetItem*> device_item_map;
|
||||
KyLable *settingLabel;
|
||||
void get_power_list();
|
||||
void setSliderValue();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
@ -124,7 +127,15 @@ private :
|
|||
double transparency;
|
||||
QGSettings *transparency_gsettings = nullptr;
|
||||
QDBusInterface *m_notifyInterface;
|
||||
QGSettings *m_PowerManagerGsettings;
|
||||
// QGSettings *m_PowerManagerGsettings;
|
||||
|
||||
QPointer<QDBusInterface> m_powerManagerInterface;
|
||||
QPointer<QSettings> m_powerConfig;
|
||||
QPointer<QFileSystemWatcher> m_watcherPowerConfig;
|
||||
int m_powerPolicyAC;
|
||||
int m_powerPolicyBAT;
|
||||
|
||||
|
||||
enum powerPolicy
|
||||
{
|
||||
Performance = 0,
|
||||
|
@ -135,17 +146,19 @@ private :
|
|||
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void watchTranspartency();
|
||||
void setSliderValue();
|
||||
void initPowerConfig();
|
||||
void getPowerConfig();
|
||||
void setConfigValue(const QString key, const QVariant value);
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void batteryChange(int dev);
|
||||
void onBatteryChanged(QStringList args);
|
||||
|
||||
void chargeNotify(bool state);
|
||||
void criticalBatteryNotify();
|
||||
void lowBatteryNotify();
|
||||
void full_charge_notify(DEV dev);
|
||||
void sliderValueChanged(int);
|
||||
void powerConfigChangedHandle(const QString &path);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -2,20 +2,29 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#define BRIGHTNESS "brightnessAc"
|
||||
#define GET_BRIGHTNESS "GetBrightness"
|
||||
#define BRIGHTNESS_VALUE "brightness"
|
||||
CompatibleInterface::CompatibleInterface(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
|
||||
const QByteArray brightSettings(BRIGHTNESS_SCHEMA);
|
||||
brightnesssettings = new QGSettings(brightSettings, QByteArray(), this);
|
||||
|
||||
interface = new QDBusInterface("org.ukui.powermanagement",
|
||||
"/",
|
||||
"org.ukui.powermanagement.interface",
|
||||
QDBusConnection::systemBus());
|
||||
|
||||
connect(brightnesssettings, &QGSettings::changed, [=](QString key) {
|
||||
if (BRIGHTNESS == key) {
|
||||
QDBusInterface iface("org.ukui.upower",
|
||||
"/upower/PowerManager",
|
||||
"org.ukui.powerManager",
|
||||
QDBusConnection::sessionBus());
|
||||
iface.call("SetBrightness",brightnesssettings->get(BRIGHTNESS).toInt());
|
||||
qDebug()<<""<<brightnesssettings->get(BRIGHTNESS).toInt();
|
||||
brightnes=brightnesssettings->get(BRIGHTNESS).toInt();
|
||||
interface->call("RegulateBrightness",brightnes);
|
||||
qDebug()<<"brightness"<<brightnes;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
CompatibleInterface::~CompatibleInterface()
|
||||
{
|
||||
delete iface;
|
||||
delete interface;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QGSettings>
|
||||
#include <QtDBus>
|
||||
#include <QSettings>
|
||||
|
||||
#define BRIGHTNESS_SCHEMA "org.ukui.power-manager"
|
||||
|
||||
|
@ -12,10 +13,15 @@ class CompatibleInterface : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit CompatibleInterface(QObject *parent = nullptr);
|
||||
~CompatibleInterface();
|
||||
|
||||
private:
|
||||
QGSettings *brightnesssettings;
|
||||
|
||||
int brightnes;
|
||||
QDBusInterface *iface;
|
||||
QDBusInterface *interface;
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "dialog.h"
|
||||
#include <QDebug>
|
||||
#include <KWindowSystem>
|
||||
#include <QToolTip>
|
||||
#include <QEvent>
|
||||
|
||||
Dialog::Dialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
|
@ -12,24 +14,13 @@ Dialog::~Dialog() {}
|
|||
void Dialog::uiInit()
|
||||
{
|
||||
//初始化弹窗界面
|
||||
setFixedSize(510, 224);
|
||||
setFixedSize(480, 174);
|
||||
setWindowFlag(Qt::WindowStaysOnTopHint);
|
||||
KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_topLayout = new QHBoxLayout(this);
|
||||
m_verLayout = new QVBoxLayout(this);
|
||||
m_verLayout->setContentsMargins(10, 10, 24, 24);
|
||||
|
||||
m_icon = new QLabel(this);
|
||||
m_icon->setAlignment(Qt::AlignLeft);
|
||||
m_icon->setFixedSize(24, 24);
|
||||
m_icon->setPixmap(QIcon::fromTheme("ukui-power-manager").pixmap(QSize(24, 24)));
|
||||
|
||||
m_title = new QLabel(this);
|
||||
m_title->setMargin(0);
|
||||
m_title->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
m_title->setMinimumWidth(1);
|
||||
m_title->setText(tr("ukui-power-manager"));
|
||||
m_verLayout->setContentsMargins(10, 10, 10, 10);
|
||||
|
||||
m_closeButton = new QPushButton(this);
|
||||
m_closeButton->setFixedSize(32, 32);
|
||||
|
@ -43,24 +34,22 @@ void Dialog::uiInit()
|
|||
m_tipsLabel->setAlignment(Qt::AlignVCenter);
|
||||
m_tipsLabel->setMinimumWidth(1);
|
||||
m_tipsLabel->setFixedWidth(462);
|
||||
QString text = tr("The current battery level is very low. Please connect to the power supply as soon as possible "
|
||||
"to prevent the "
|
||||
"loss of files! The system will %1 automatically in 60 seconds......")
|
||||
.arg(m_showText);
|
||||
m_tipsLabel->setText(text);
|
||||
m_tipsLabel->setWordWrap(true); //自动换行
|
||||
m_warningText = tr("The system will %1 in 60 seconds as the battery is about to run out.")
|
||||
.arg(m_showText);
|
||||
QFontMetricsF fm(this->font());
|
||||
QString elidedText = fm.elidedText(m_warningText, Qt::ElideRight, 450, Qt::TextSingleLine);
|
||||
m_tipsLabel->setText(elidedText);
|
||||
m_tipsLabel->installEventFilter(this);
|
||||
|
||||
//初始化确认按钮
|
||||
m_confirmBtn = new QPushButton(this);
|
||||
m_confirmBtn->setFixedSize(112, 56);
|
||||
m_confirmBtn->setFixedSize(100, 36);
|
||||
m_confirmBtn->setProperty("isImportant", true);
|
||||
m_confirmBtn->setText(tr("I know"));
|
||||
|
||||
connect(m_closeButton, &QPushButton::clicked, this, &Dialog::confirmBtnClicked);
|
||||
connect(m_confirmBtn, &QPushButton::clicked, this, &Dialog::confirmBtnClicked);
|
||||
|
||||
m_topLayout->addWidget(m_icon, 0, Qt::AlignLeft | Qt::AlignVCenter);
|
||||
m_topLayout->addWidget(m_title, 10, Qt::AlignLeft);
|
||||
m_topLayout->addWidget(m_closeButton, 0, Qt::AlignRight);
|
||||
|
||||
m_verLayout->addWidget(m_tipsLabel, 0, Qt::AlignLeft | Qt::AlignCenter);
|
||||
|
@ -74,8 +63,8 @@ void Dialog::uiInit()
|
|||
void Dialog::timerInit(QString str)
|
||||
{
|
||||
m_veryLowBatControl = str;
|
||||
m_showTimer = new QTimer;
|
||||
m_clockTimer = new QTimer;
|
||||
m_showTimer = new QTimer(this);
|
||||
m_clockTimer = new QTimer(this);
|
||||
m_clockTimer->start(60000);
|
||||
m_showTimer->start(250);
|
||||
connect(m_showTimer, &QTimer::timeout, this, &Dialog::showTime);
|
||||
|
@ -90,12 +79,12 @@ void Dialog::confirmBtnClicked()
|
|||
|
||||
void Dialog::showTime()
|
||||
{
|
||||
QString text
|
||||
= tr("The current battery level is very low. Please connect to the power supply as soon as possible to prevent "
|
||||
"the loss of files! The system will %1 automatically in %2 seconds......")
|
||||
.arg(m_showText)
|
||||
.arg(m_clockTimer->remainingTime() / 1000);
|
||||
m_tipsLabel->setText(text);
|
||||
m_warningText = tr("The system will %1 in %2 seconds as the battery is about to run out.")
|
||||
.arg(m_showText)
|
||||
.arg(m_clockTimer->remainingTime() / 1000);
|
||||
QFontMetricsF fm(this->font());
|
||||
QString elidedText = fm.elidedText(m_warningText, Qt::ElideRight, 450, Qt::TextSingleLine);
|
||||
m_tipsLabel->setText(elidedText);
|
||||
}
|
||||
|
||||
void Dialog::stopTimer()
|
||||
|
@ -129,3 +118,16 @@ void Dialog::paintEvent(QPaintEvent *)
|
|||
p.drawRect(opt.rect);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
}
|
||||
|
||||
bool Dialog::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_tipsLabel) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
QFontMetricsF fm(this->font());
|
||||
if (fm.boundingRect(m_warningText).width() > 450) {
|
||||
QToolTip::showText(QCursor::pos(), m_warningText);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ private:
|
|||
|
||||
QString m_veryLowBatControl;
|
||||
QString m_showText;
|
||||
QString m_warningText;
|
||||
void uiInit();
|
||||
protected slots:
|
||||
void confirmBtnClicked();
|
||||
|
@ -34,6 +35,8 @@ protected slots:
|
|||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
|
||||
public:
|
||||
void timerInit(QString str);
|
||||
|
|
|
@ -22,6 +22,12 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
|
||||
QApplication a(argc, argv);
|
||||
initUkuiLog4qt("ukui-power-manager");
|
||||
QTranslator translator;
|
||||
|
|
|
@ -102,7 +102,6 @@ void PowerManagerCenter::initPowerData(const int &type)
|
|||
{
|
||||
if (Laptop == type) {
|
||||
m_onBattery = getOnBatteryState();
|
||||
m_brightness->setBrightness(m_config->getSysData().sysBrightness);
|
||||
qDebug() << "init on battery:" << m_onBattery;
|
||||
if (m_onBattery) {
|
||||
m_control->dealControlAction(POWER_POLICY_BATTERY, m_config->getSysData().sysPowerPolicyBat);
|
||||
|
@ -171,9 +170,7 @@ void PowerManagerCenter::dealSysDateChanged(const QString &type)
|
|||
{
|
||||
qDebug() << "change key :" << type;
|
||||
if (Laptop == m_config->machineType()) {
|
||||
if (BRIGHTNESS == type) {
|
||||
m_brightness->setBrightness(m_config->getSysData().sysBrightness);
|
||||
} else if (POWER_POLICY_BATTERY == type && m_onBattery) {
|
||||
if (POWER_POLICY_BATTERY == type && m_onBattery) {
|
||||
m_control->dealControlAction(POWER_POLICY_BATTERY, m_config->getSysData().sysPowerPolicyBat);
|
||||
} else if (BATTERY_SAVER) {
|
||||
m_batterySaving->dealBatterySaver(m_config->getSysData().sysBatterySaver);
|
||||
|
|
|
@ -4,44 +4,31 @@
|
|||
<context>
|
||||
<name>Dialog</name>
|
||||
<message>
|
||||
<location filename="../src/dialog.cpp" line="32"/>
|
||||
<source>ukui-power-manager</source>
|
||||
<translation>电源管理</translation>
|
||||
<translation type="vanished">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>The current battery level is very low. Please connect to the power supply as soon as possible to prevent the loss of files! The system will 1% automatically in 60 seconds......</source>
|
||||
<translation type="vanished">当前电池电量极低,请尽快接入电源,防止文件丢失!系统将在60秒后自动 1%......</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/dialog.cpp" line="57"/>
|
||||
<location filename="../src/dialog.cpp" line="44"/>
|
||||
<source>I know</source>
|
||||
<translation>知道了</translation>
|
||||
<translation>确定</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>The current battery level is very low. Please connect to the power supply as soon as possible to prevent the loss of files! The system will 1% automatically in 2% seconds......</source>
|
||||
<translation type="vanished">当前电池电量极低,请尽快接入电源,防止文件丢失!系统将在 2% 秒后自动 1% ......</translation>
|
||||
<location filename="../src/dialog.cpp" line="35"/>
|
||||
<source>The system will %1 in 60 seconds as the battery is about to run out.</source>
|
||||
<translation>电池电量即将耗尽,系统将在60秒后%1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>The current battery level is very low. Please connect to the power supply as soon as possible to prevent the loss of files! The system will %1 automatically in 2% seconds......</source>
|
||||
<translation type="vanished">当前电池电量极低,请尽快接入电源,防止文件丢失!系统将在2%秒后自动1% ......</translation>
|
||||
<location filename="../src/dialog.cpp" line="79"/>
|
||||
<source>The system will %1 in %2 seconds as the battery is about to run out.</source>
|
||||
<translation>电池电量即将耗尽,系统将在%2秒后%1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/dialog.cpp" line="46"/>
|
||||
<source>The current battery level is very low. Please connect to the power supply as soon as possible to prevent the loss of files! The system will %1 automatically in 60 seconds......</source>
|
||||
<translation>当前电池电量极低,请尽快接入电源,防止文件丢失!系统将在60秒后自动%1......</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/dialog.cpp" line="94"/>
|
||||
<source>The current battery level is very low. Please connect to the power supply as soon as possible to prevent the loss of files! The system will %1 automatically in %2 seconds......</source>
|
||||
<translation>当前电池电量极低,请尽快接入电源,防止文件丢失!系统将在 %2 秒后自动%1 ......</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/dialog.cpp" line="112"/>
|
||||
<location filename="../src/dialog.cpp" line="96"/>
|
||||
<source>shutdown</source>
|
||||
<translation>关机</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/dialog.cpp" line="114"/>
|
||||
<location filename="../src/dialog.cpp" line="98"/>
|
||||
<source>hibernate</source>
|
||||
<translation>休眠</translation>
|
||||
</message>
|
||||
|
|
Loading…
Reference in New Issue