diff --git a/gschema/com.deepin.dde.dock.module.gschema.xml b/gschema/com.deepin.dde.dock.module.gschema.xml
index 3d4c92f14..2af4a9313 100644
--- a/gschema/com.deepin.dde.dock.module.gschema.xml
+++ b/gschema/com.deepin.dde.dock.module.gschema.xml
@@ -112,6 +112,22 @@
+
+
+ false
+ Blocking event
+
+ Blocking mouse events
+
+
+
+ true
+ Module Enable
+
+ Control Module Enable
+
+
+
false
@@ -127,6 +143,13 @@
Control Module Enable
+
+ true
+ Show TimeToFull
+
+ Show TimeToFull
+
+
diff --git a/plugins/power/CMakeLists.txt b/plugins/power/CMakeLists.txt
index 39b7ec67c..a7819a9d3 100644
--- a/plugins/power/CMakeLists.txt
+++ b/plugins/power/CMakeLists.txt
@@ -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)
diff --git a/plugins/power/powerplugin.cpp b/plugins/power/powerplugin.cpp
index cbefd5fbc..72db7db2b 100644
--- a/plugins/power/powerplugin.cpp
+++ b/plugins/power/powerplugin.cpp
@@ -23,14 +23,21 @@
#include "dbus/dbusaccount.h"
#include
+#include
#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);
diff --git a/plugins/power/powerplugin.h b/plugins/power/powerplugin.h
index f1ce34dac..f8515612d 100644
--- a/plugins/power/powerplugin.h
+++ b/plugins/power/powerplugin.h
@@ -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;
diff --git a/plugins/power/powerstatuswidget.cpp b/plugins/power/powerstatuswidget.cpp
index 862543689..1d869be1f 100644
--- a/plugins/power/powerstatuswidget.cpp
+++ b/plugins/power/powerstatuswidget.cpp
@@ -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")
diff --git a/translations/dde-dock.ts b/translations/dde-dock.ts
index 465a2153b..c2c1fb86f 100644
--- a/translations/dde-dock.ts
+++ b/translations/dde-dock.ts
@@ -1,4 +1,6 @@
-
+
+
+
AbstractPluginsController
@@ -213,10 +215,6 @@
Charging %1, %2 hr %3 min until full
Charging %1, %2 hr %3 min until full
-
- Charging %1 ....
- Charging %1 ....
-
Charged
Charged
@@ -225,6 +223,14 @@
Capacity %1 ....
+
+ Capacity %1
+
+
+
+ Charging %1
+
+
ShowDesktopPlugin
@@ -383,4 +389,4 @@
Wireless Network %1
-
\ No newline at end of file
+