Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Allow to suppress charging state notification #283

Open
wants to merge 11 commits into
base: xenial
Choose a base branch
from
1 change: 1 addition & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ install(FILES

add_custom_target(pkgversion ALL COMMAND dpkg-parsechangelog -l${CMAKE_SOURCE_DIR}/debian/changelog --show-field version > ${CMAKE_CURRENT_BINARY_DIR}/version)

install(FILES com.lomiri.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
install(FILES com.canonical.Unity8.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
install(FILES com.canonical.Unity.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/lib/unity8)
1 change: 1 addition & 0 deletions data/com.canonical.Unity8.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
<description>If too many unsuccessful login attempts have been made in a row, the greeter locks you out for a while. This unix timestamp indicates when you were locked out, so unity8 knows when to let you back in.</description>
</key>
</schema>

UniversalSuperBox marked this conversation as resolved.
Show resolved Hide resolved
</schemalist>
11 changes: 11 additions & 0 deletions data/com.lomiri.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<schemalist>

<schema path="/com/lomiri/ledindication/" id="com.lomiri.LedIndication" gettext-domain="lomiri">
<key type="b" name="charging-state-visible">
<default>true</default>
<summary>Whether the battery charging state should be shown using the notification led</summary>
<description>Toggle the visibility of the battery charging state in the notification led patterns</description>
</key>
</schema>

</schemalist>
21 changes: 19 additions & 2 deletions qml/Panel/Indicators/IndicatorsLight.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Lights 0.1
import QMenuModel 0.1 as QMenuModel
import Unity.Indicators 0.1 as Indicators
import Wizard 0.1
import GSettings 1.0

import "../../.."

Expand All @@ -45,10 +46,18 @@ QtObject {
property string batteryIconName: Status.batteryIcon
property string displayStatus: Powerd.status


onSupportsMultiColorLedChanged: {
updateLightState("onSupportsMultiColorLedChanged")
}

property var _lomiriSettings: GSettings {
schema.id: "com.lomiri.LedIndication"
onChanged: {
root.updateLightState("onChanged (settings)")
}
}

onDisplayStatusChanged: {
updateLightState("onDisplayStatusChanged")
}
Expand All @@ -65,8 +74,11 @@ QtObject {
+ ", icon: " + batteryIconName
+ ", displayStatus: " + displayStatus
+ ", deviceState: " + deviceState
+ ", batteryLevel: " + batteryLevel)
+ ", batteryLevel: " + batteryLevel
+ ", chargingStateVisible: " + _lomiriSettings.chargingStateVisible)

//
// If charging state visibility is disabled then only show messages.
//
// priorities:
// unread messsages (highest), full&charging, charging, low
Expand Down Expand Up @@ -114,7 +126,12 @@ QtObject {

// if device does not support a multi color led set led off
if(!supportsMultiColorLed) {
console.log("no support for Multicolor LED. " + indicatorState)
indicatorState = "INDICATOR_OFF"
return
}

// if charging state is not to be shown set led off
if(!_lomiriSettings.chargingStateVisible) {
indicatorState = "INDICATOR_OFF"
return
}
Expand Down
30 changes: 30 additions & 0 deletions tests/mocks/GSettings.1.0/fake_gsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GSettingsControllerQml::GSettingsControllerQml()
, m_edgeDragWidth(2)
, m_enableIndicatorMenu(true)
, m_appstoreUri("http://uappexplorer.com")
, m_chargingStateVisible(true)
{
}

Expand Down Expand Up @@ -160,6 +161,19 @@ void GSettingsControllerQml::setEnableIndicatorMenu(bool enableIndicatorMenu)
}
}

bool GSettingsControllerQml::chargingStateVisible() const
{
return m_chargingStateVisible;
}

void GSettingsControllerQml::setChargingStateVisible(bool chargingStateVisible)
{
if (m_chargingStateVisible != chargingStateVisible) {
m_chargingStateVisible = chargingStateVisible;
Q_EMIT chargingStateVisibleChanged(chargingStateVisible);
}
}

QString GSettingsControllerQml::appstoreUri() const
{
return m_appstoreUri;
Expand Down Expand Up @@ -398,3 +412,19 @@ void GSettingsQml::setEnableIndicatorMenu(const QVariant &enableIndicatorMenu)
GSettingsControllerQml::instance()->setEnableIndicatorMenu(enableIndicatorMenu.toBool());
}
}

QVariant GSettingsQml::chargingStateVisible() const
{
if (m_valid && m_schema->id() == "com.lomiri.LedIndication") {
return GSettingsControllerQml::instance()->chargingStateVisible();
} else {
return QVariant();
}
}

void GSettingsQml::setChargingStateVisible(const QVariant &chargingStateVisible)
{
if (m_valid && m_schema->id() == "com.lomiri.LedIndication") {
GSettingsControllerQml::instance()->setChargingStateVisible(chargingStateVisible.toBool());
}
}
13 changes: 13 additions & 0 deletions tests/mocks/GSettings.1.0/fake_gsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class GSettingsQml: public QObject, public QQmlParserStatus
Q_PROPERTY(QVariant edgeDragWidth READ edgeDragWidth WRITE setEdgeDragWidth NOTIFY edgeDragWidthChanged)
Q_PROPERTY(QVariant enableIndicatorMenu READ enableIndicatorMenu WRITE setEnableIndicatorMenu NOTIFY enableIndicatorMenuChanged)
Q_PROPERTY(QVariant appstoreUri READ appstoreUri NOTIFY appstoreUriChanged)
Q_PROPERTY(QVariant chargingStateVisible READ chargingStateVisible WRITE setChargingStateVisible NOTIFY chargingStateVisibleChanged)

public:
GSettingsQml(QObject *parent = nullptr);
Expand All @@ -77,6 +78,7 @@ class GSettingsQml: public QObject, public QQmlParserStatus
QVariant edgeDragWidth() const;
QVariant enableIndicatorMenu() const;
QVariant appstoreUri() const;
QVariant chargingStateVisible() const;

void setDisableHeight(const QVariant &val);
void setPictureUri(const QVariant &str);
Expand All @@ -87,6 +89,7 @@ class GSettingsQml: public QObject, public QQmlParserStatus
void setLauncherWidth(const QVariant &launcherWidth);
void setEdgeDragWidth(const QVariant &edgeDragWidth);
void setEnableIndicatorMenu(const QVariant &enableIndicatorMenu);
void setChargingStateVisible(const QVariant &chargingStateVisible);

Q_SIGNALS:
void disableHeightChanged();
Expand All @@ -100,6 +103,11 @@ class GSettingsQml: public QObject, public QQmlParserStatus
void edgeDragWidthChanged();
void enableIndicatorMenuChanged();
void appstoreUriChanged();
void chargingStateVisibleChanged();

// This signal is not implemented but it's declaration is required
// for qml elements using the GSettings onChanged event.
void changed(const QString &key, const QVariant &value);

private:
GSettingsSchemaQml* m_schema;
Expand Down Expand Up @@ -145,6 +153,9 @@ class GSettingsControllerQml: public QObject

QString appstoreUri() const;

bool chargingStateVisible() const;
Q_INVOKABLE void setChargingStateVisible(bool chargingStateVisible);

Q_SIGNALS:
void disableHeightChanged();
void pictureUriChanged(const QString&);
Expand All @@ -156,6 +167,7 @@ class GSettingsControllerQml: public QObject
void edgeDragWidthChanged(uint edgeDragWidth);
void enableIndicatorMenuChanged(bool enableIndicatorMenu);
void appstoreUriChanged(const QString &appstoreUri);
void chargingStateVisibleChanged(bool chargingStateVisible);

private:
GSettingsControllerQml();
Expand All @@ -170,6 +182,7 @@ class GSettingsControllerQml: public QObject
uint m_edgeDragWidth;
bool m_enableIndicatorMenu;
QString m_appstoreUri;
bool m_chargingStateVisible;

static GSettingsControllerQml* s_controllerInstance;
QList<GSettingsQml *> m_registeredGSettings;
Expand Down
49 changes: 33 additions & 16 deletions tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import QtQuick.Layouts 1.1
import Unity.Test 0.1 as UT
import Unity.Indicators 0.1 as Indicators
import Ubuntu.Components 1.3
import GSettings 1.0
import Powerd 0.1
import Lights 0.1
import QMenuModel 0.1
Expand Down Expand Up @@ -46,21 +47,16 @@ Item {
}
};

Component {
id: light
IndicatorsLight {}
}

Loader {
id: loader
sourceComponent: light
}

Component.onCompleted: {
ActionData.data = newMessage;
Powerd.setStatus(Powerd.On, Powerd.Unknown);
}

GSettings {
id: lomiriSettings
schema.id: "com.lomiri.LedIndication"
}

RowLayout {
anchors.fill: parent
anchors.margins: units.gu(1)
Expand Down Expand Up @@ -147,14 +143,15 @@ Item {
property color orangeRed: "orangeRed"

UT.UnityTestCase {
id: testCase
name: "IndicatorsLight"
when: windowShown

function init() {
// reload
ActionData.data = noNewMessage;
loader.sourceComponent = undefined;
loader.sourceComponent = light;
lomiriSettings.chargingStateVisible = true;
Powerd.setStatus(Powerd.On, Powerd.Unknown);
}

function test_LightsStatus_data() {
Expand Down Expand Up @@ -265,22 +262,42 @@ Item {
{ tag: "Powerd.Off while charging & no support for multicolor led",
expectedLightsState: Lights.Off,
powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: false },

//
// Charging state visibility
//
{ tag: "Powerd.Off with New Message & chargingStateVisible==false",
expectedLightsState: Lights.On,
powerd: Powerd.Off, actionData: newMessage, chargingStateVisible: false },
{ tag: "Powerd.Off while charging & chargingStateVisible==false",
expectedLightsState: Lights.Off,
powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, chargingStateVisible: false },
{ tag: "Powerd.Off while charging & chargingStateVisible==true",
expectedLightsState: Lights.On,
powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, chargingStateVisible: true },
{ tag: "Powerd.Off while charging & chargingStateVisible==true & no support for multicolor led",
expectedLightsState: Lights.Off,
powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, chargingStateVisible: true, supportsMultiColorLed: false },

]
}

function test_LightsStatus(data) {
console.log("----------------------------------------------------------------")
var item = createTemporaryQmlObject("import QtQuick 2.0; import\"" + Qt.resolvedUrl("../../../../qml/Panel/Indicators") + "\"; IndicatorsLight {}", testCase);

console.log("----------------------------------------------------------------")
if (data.hasOwnProperty("supportsMultiColorLed"))
loader.item.supportsMultiColorLed = data.supportsMultiColorLed
item.supportsMultiColorLed = data.supportsMultiColorLed
if (data.hasOwnProperty("chargingStateVisible"))
lomiriSettings.chargingStateVisible = data.chargingStateVisible
if (data.hasOwnProperty("powerd"))
Powerd.setStatus(data.powerd, Powerd.Unknown)
if (data.hasOwnProperty("actionData"))
ActionData.data = data.actionData
if (data.hasOwnProperty("wizardStatus"))
loader.item.batteryIconName = data.wizardStatus
item.batteryIconName = data.wizardStatus

compare(Lights.state, data.expectedLightsState, "Lights state does not match expected value");
compare(Lights.state, data.expectedLightsState, "Lights state does not match expected value")
if (data.hasOwnProperty("expectedLightsColor"))
compare(Lights.color, data.expectedLightsColor, "Lights color does not match expected value")
if (data.hasOwnProperty("expectedLightsOnMillisec"))
Expand Down