Merge branch 'dev/sp2/powerplugin' into 'uos'

Dev/sp2/powerplugin

See merge request dde-v20/dde-dock!467
This commit is contained in:
范朋程 2020-05-20 18:24:31 +08:00
commit e15fd5385e
7 changed files with 351 additions and 16 deletions

View File

@ -66,3 +66,6 @@ install(FILES "cmake/DdeDock/DdeDockConfig.cmake"
## services files
install(FILES frame/com.deepin.dde.Dock.service
DESTINATION /usr/share/dbus-1/services)
install(FILES gschema/com.deepin.dde.dock.module.gschema.xml
DESTINATION share/glib-2.0/schemas)

View File

@ -0,0 +1,266 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema path="/com/deepin/dde/dock/module/app/" id="com.deepin.dde.dock.module.app" 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/activeapp/" id="com.deepin.dde.dock.module.activeapp" 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/dockapp/" id="com.deepin.dde.dock.module.dockapp" 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/launcher/" id="com.deepin.dde.dock.module.launcher" 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/datetime/" id="com.deepin.dde.dock.module.datetime" 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/network/" id="com.deepin.dde.dock.module.network" 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/onboard/" id="com.deepin.dde.dock.module.onboard" 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/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>
<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>
<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">
<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/sound/" id="com.deepin.dde.dock.module.sound" 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/trash/" id="com.deepin.dde.dock.module.trash" 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/systemtray/" id="com.deepin.dde.dock.module.systemtray" 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/tray/" id="com.deepin.dde.dock.module.tray" 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/menu/" id="com.deepin.dde.dock.module.menu" 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/AiAssistant/" id="com.deepin.dde.dock.module.AiAssistant" 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>
</schemalist>

View File

@ -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)

View File

@ -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").arg(value);
}
}
} 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);

View File

@ -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;

View File

@ -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")

View File

@ -265,7 +265,7 @@
</message>
<message>
<source>Charging %1 ....</source>
<translation>Charging %1 ....</translation>
<translation type="vanished">Charging %1 ....</translation>
</message>
<message>
<source>Charged</source>
@ -275,6 +275,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>