Commit aa6dba84 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Show "you might need to reconnect charger" hint only when charging/fully charged

The hint shifts the UI about so don't show it we aren't actually charging right now

Also move code into a separate method for cleanliness
parent 30aab810
......@@ -128,14 +128,7 @@ void GeneralPage::fillUi()
connect(BatteryCriticalCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed()));
connect(chargeStartThresholdSpin, QOverload<int>::of(&QSpinBox::valueChanged), this, &GeneralPage::markAsChanged);
connect(chargeStopThresholdSpin, QOverload<int>::of(&QSpinBox::valueChanged), this, &GeneralPage::markAsChanged);
connect(chargeStopThresholdSpin, QOverload<int>::of(&QSpinBox::valueChanged), this, [this] {
if (chargeStopThresholdSpin->value() > m_chargeStopThreshold) {
chargeStopThresholdMessage->animatedShow();
} else {
chargeStopThresholdMessage->animatedHide();
}
});
connect(chargeStopThresholdSpin, QOverload<int>::of(&QSpinBox::valueChanged), this, &GeneralPage::onChargeStopThresholdChanged);
chargeStopThresholdMessage->hide();
connect(pausePlayersCheckBox, SIGNAL(stateChanged(int)), SLOT(changed()));
......@@ -272,4 +265,23 @@ void GeneralPage::onServiceUnregistered(const QString& service)
this);
}
void GeneralPage::onChargeStopThresholdChanged(int threshold)
{
if (threshold > m_chargeStopThreshold) {
// Only show message if there is actually a charging or fully charged battery
const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());
for (const Solid::Device &device : devices) {
const Solid::Battery *b = qobject_cast<const Solid::Battery*>(device.asDeviceInterface(Solid::DeviceInterface::Battery));
if (b->chargeState() == Solid::Battery::Charging || b->chargeState() == Solid::Battery::FullyCharged) {
chargeStopThresholdMessage->animatedShow();
break;
}
}
} else if (chargeStopThresholdMessage->isVisible()) {
chargeStopThresholdMessage->animatedHide();
}
markAsChanged();
}
#include "GeneralPage.moc"
......@@ -42,6 +42,7 @@ private Q_SLOTS:
void configureNotifications();
void onServiceRegistered(const QString &service);
void onServiceUnregistered(const QString &service);
void onChargeStopThresholdChanged(int threshold);
private:
void setChargeThresholdSupported(bool supported);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment