mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat:gsettings control power display
This commit is contained in:
parent
e37fce938b
commit
7a731315ab
@ -112,6 +112,22 @@
|
||||
</description>
|
||||
</key>
|
||||
</schema>
|
||||
<schema path="/com/deepin/dde/dock/module/bluetooth/" id="com.deepin.dde.dock.module.bluetooth" gettext-domain="DDE">
|
||||
<key type="b" name="control">
|
||||
<default>false</default>
|
||||
<summary>Blocking event</summary>
|
||||
<description>
|
||||
Blocking mouse events
|
||||
</description>
|
||||
</key>
|
||||
<key type="b" name="enable">
|
||||
<default>true</default>
|
||||
<summary>Module Enable</summary>
|
||||
<description>
|
||||
Control Module Enable
|
||||
</description>
|
||||
</key>
|
||||
</schema>
|
||||
<schema path="/com/deepin/dde/dock/module/power/" id="com.deepin.dde.dock.module.power" gettext-domain="DDE">
|
||||
<key type="b" name="control">
|
||||
<default>false</default>
|
||||
@ -127,6 +143,13 @@
|
||||
Control Module Enable
|
||||
</description>
|
||||
</key>
|
||||
<key type="b" name="showtimetofull">
|
||||
<default>true</default>
|
||||
<summary>Show TimeToFull</summary>
|
||||
<description>
|
||||
Show TimeToFull
|
||||
</description>
|
||||
</key>
|
||||
</schema>
|
||||
<schema path="/com/deepin/dde/dock/module/shutdown/" id="com.deepin.dde.dock.module.shutdown" gettext-domain="DDE">
|
||||
<key type="b" name="control">
|
||||
|
@ -20,6 +20,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../syst
|
||||
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
|
||||
${Qt5DBus_INCLUDE_DIRS}
|
||||
${DFrameworkDBus_INCLUDE_DIRS}
|
||||
${QGSettings_INCLUDE_DIRS}
|
||||
../../interfaces)
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
||||
${DtkWidget_LIBRARIES}
|
||||
@ -27,6 +28,7 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE
|
||||
${Qt5Svg_LIBRARIES}
|
||||
${Qt5DBus_LIBRARIES}
|
||||
${DFrameworkDBus_LIBRARIES}
|
||||
${QGSettings_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins/system-trays)
|
||||
|
@ -23,14 +23,21 @@
|
||||
#include "dbus/dbusaccount.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QGSettings>
|
||||
|
||||
#define PLUGIN_STATE_KEY "enable"
|
||||
|
||||
PowerPlugin::PowerPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
static QGSettings *GSettingsByApp()
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.power");
|
||||
return &settings;
|
||||
}
|
||||
|
||||
m_pluginLoaded(false),
|
||||
m_tipsLabel(new TipsWidget)
|
||||
PowerPlugin::PowerPlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_pluginLoaded(false)
|
||||
, m_showTimeToFull(true)
|
||||
, m_tipsLabel(new TipsWidget)
|
||||
{
|
||||
m_tipsLabel->setVisible(false);
|
||||
m_tipsLabel->setObjectName("power");
|
||||
@ -181,6 +188,7 @@ void PowerPlugin::loadPlugin()
|
||||
m_systemPowerInter = new SystemPowerInter("com.deepin.system.Power", "/com/deepin/system/Power", QDBusConnection::systemBus(), this);
|
||||
m_systemPowerInter->setSync(true);
|
||||
|
||||
connect(GSettingsByApp(), &QGSettings::changed, this, &PowerPlugin::onGSettingsChanged);
|
||||
connect(m_systemPowerInter, &SystemPowerInter::BatteryStatusChanged, this, &PowerPlugin::refreshTipsData);
|
||||
connect(m_systemPowerInter, &SystemPowerInter::BatteryTimeToEmptyChanged, this, &PowerPlugin::refreshTipsData);
|
||||
connect(m_systemPowerInter, &SystemPowerInter::BatteryTimeToFullChanged, this, &PowerPlugin::refreshTipsData);
|
||||
@ -188,6 +196,8 @@ void PowerPlugin::loadPlugin()
|
||||
connect(m_powerInter, &DBusPower::BatteryPercentageChanged, this, &PowerPlugin::updateBatteryVisible);
|
||||
|
||||
updateBatteryVisible();
|
||||
|
||||
onGSettingsChanged("showtimetofull");
|
||||
}
|
||||
|
||||
void PowerPlugin::refreshPluginItemsVisible()
|
||||
@ -203,6 +213,20 @@ void PowerPlugin::refreshPluginItemsVisible()
|
||||
}
|
||||
}
|
||||
|
||||
void PowerPlugin::onGSettingsChanged(const QString &key)
|
||||
{
|
||||
if (key != "showtimetofull") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GSettingsByApp()->keys().contains("showtimetofull")) {
|
||||
const bool isEnable = GSettingsByApp()->keys().contains("showtimetofull") && GSettingsByApp()->get("showtimetofull").toBool();
|
||||
m_showTimeToFull = isEnable && GSettingsByApp()->get("showtimetofull").toBool();
|
||||
}
|
||||
|
||||
refreshTipsData();
|
||||
}
|
||||
|
||||
void PowerPlugin::refreshTipsData()
|
||||
{
|
||||
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
|
||||
@ -220,9 +244,19 @@ void PowerPlugin::refreshTipsData()
|
||||
if (min == 0)
|
||||
tips = tr("Charged");
|
||||
else
|
||||
tips = tr("Capacity %1, %2 min remaining").arg(value).arg(min);
|
||||
{
|
||||
if(m_showTimeToFull)
|
||||
tips = tr("Capacity %1, %2 min remaining").arg(value).arg(min);
|
||||
else {
|
||||
tips = tr("Capacity %1");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tips = tr("Capacity %1, %2 hr %3 min remaining").arg(value).arg(hour).arg(min);
|
||||
if(m_showTimeToFull)
|
||||
tips = tr("Capacity %1, %2 hr %3 min remaining").arg(value).arg(hour).arg(min);
|
||||
else {
|
||||
tips = tr("Capacity %1").arg(value).arg(hour);
|
||||
}
|
||||
}
|
||||
|
||||
m_tipsLabel->setText(tips);
|
||||
@ -237,9 +271,17 @@ void PowerPlugin::refreshTipsData()
|
||||
if(timeToFull == 0) { // 电量已充満或电量计算中,剩余充满时间会返回0
|
||||
tips = tr("Capacity %1 ....").arg(value);
|
||||
} else if (hour == 0) {
|
||||
tips = tr("Charging %1, %2 min until full").arg(value).arg(min);
|
||||
if(m_showTimeToFull)
|
||||
tips = tr("Charging %1, %2 min until full").arg(value).arg(min);
|
||||
else {
|
||||
tips = tr("Charging %1").arg(value);
|
||||
}
|
||||
} else {
|
||||
tips = tr("Charging %1, %2 hr %3 min until full").arg(value).arg(hour).arg(min);
|
||||
if(m_showTimeToFull)
|
||||
tips = tr("Charging %1, %2 hr %3 min until full").arg(value).arg(hour).arg(min);
|
||||
else {
|
||||
tips = tr("Charging %1").arg(value);
|
||||
}
|
||||
}
|
||||
|
||||
m_tipsLabel->setText(tips);
|
||||
|
@ -72,10 +72,12 @@ private:
|
||||
void updateBatteryVisible();
|
||||
void loadPlugin();
|
||||
void refreshPluginItemsVisible();
|
||||
void onGSettingsChanged(const QString &key);
|
||||
void refreshTipsData();
|
||||
|
||||
private:
|
||||
bool m_pluginLoaded;
|
||||
bool m_showTimeToFull;
|
||||
|
||||
PowerStatusWidget *m_powerStatusWidget;
|
||||
TipsWidget *m_tipsLabel;
|
||||
|
@ -71,22 +71,34 @@ QPixmap PowerStatusWidget::getBatteryIcon()
|
||||
const bool plugged = !m_powerInter->onBattery();
|
||||
|
||||
/*根据新需求,电池电量显示分别是*/
|
||||
/* 0-5%; 6-20% 21-40% 41-60% 61-80% 81-100% */
|
||||
/* 0-5%、6-10%、11%-20%、21-30%、31-40%、41-50%、51-60%、61%-70%、71-80%、81-90%、91-100% */
|
||||
QString percentageStr;
|
||||
if (percentage <= 5 && percentage >= 0) {
|
||||
if (percentage < 0) {
|
||||
percentageStr = "000";
|
||||
} else if (percentage <= 5 && percentage >= 0) {
|
||||
percentageStr = "000";
|
||||
} else if (percentage <= 10) {
|
||||
percentageStr = "010";
|
||||
} else if (percentage <= 20) {
|
||||
percentageStr = "020";
|
||||
} else if (percentage <= 40) {
|
||||
} else if (percentage <= 30) {
|
||||
percentageStr = "030";
|
||||
}else if (percentage <= 40) {
|
||||
percentageStr = "040";
|
||||
} else if (percentage <= 60) {
|
||||
} else if (percentage <= 50) {
|
||||
percentageStr = "050";
|
||||
}else if (percentage <= 60) {
|
||||
percentageStr = "060";
|
||||
} else if (percentage < 80) {
|
||||
} else if (percentage <= 70) {
|
||||
percentageStr = "070";
|
||||
}else if (percentage < 80) {
|
||||
percentageStr = "080";
|
||||
} else if (percentage <= 100){
|
||||
} else if (percentage <= 90) {
|
||||
percentageStr = "090";
|
||||
}else if (percentage <= 100){
|
||||
percentageStr = "100";
|
||||
} else {
|
||||
percentageStr = "000";
|
||||
percentageStr = "100";
|
||||
}
|
||||
|
||||
QString iconStr = QString("battery-%1-%2")
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" ?><!DOCTYPE TS><TS language="en" version="2.1">
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="en">
|
||||
<context>
|
||||
<name>AbstractPluginsController</name>
|
||||
<message>
|
||||
@ -213,10 +215,6 @@
|
||||
<source>Charging %1, %2 hr %3 min until full</source>
|
||||
<translation>Charging %1, %2 hr %3 min until full</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Charging %1 ....</source>
|
||||
<translation>Charging %1 ....</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Charged</source>
|
||||
<translation>Charged</translation>
|
||||
@ -225,6 +223,14 @@
|
||||
<source>Capacity %1 ....</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Capacity %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Charging %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ShowDesktopPlugin</name>
|
||||
@ -383,4 +389,4 @@
|
||||
<translation>Wireless Network %1</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
</TS>
|
||||
|
Loading…
x
Reference in New Issue
Block a user