diff --git a/autotests/integration/nightcolor_test.cpp b/autotests/integration/nightcolor_test.cpp index 3c77ec563c..f5bccf13f9 100644 --- a/autotests/integration/nightcolor_test.cpp +++ b/autotests/integration/nightcolor_test.cpp @@ -29,9 +29,6 @@ private Q_SLOTS: void testConfigRead_data(); void testConfigRead(); - void testChangeConfiguration_data(); - void testChangeConfiguration(); - void testAutoLocationUpdate(); }; void NightColorTest::initTestCase() @@ -64,267 +61,48 @@ void NightColorTest::cleanup() void NightColorTest::testConfigRead_data() { - QTest::addColumn("active"); + QTest::addColumn("active"); QTest::addColumn("mode"); - QTest::addColumn("nightTemperature"); - QTest::addColumn("latitudeFixed"); - QTest::addColumn("longitudeFixed"); - QTest::addColumn("morningBeginFixed"); - QTest::addColumn("eveningBeginFixed"); - QTest::addColumn("transitionTime"); - QTest::addColumn("success"); - QTest::newRow("activeMode0") << "true" << 0 << 4500 << 45.5 << 35.1 << "0600" << "1800" << 30 << true; - QTest::newRow("activeMode1") << "true" << 1 << 2500 << -10.5 << -8. << "0020" << "2000" << 60 << true; - QTest::newRow("activeMode2") << "true" << 3 << 3500 << 45.5 << 35.1 << "0600" << "1800" << 60 << true; - QTest::newRow("notActiveMode2") << "false" << 2 << 5000 << 90. << -180. << "0600" << "1800" << 1 << true; - QTest::newRow("wrongData1") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << 999999 << false; - QTest::newRow("wrongData2") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << -2 << false; + QTest::newRow("activeMode0") << true << 0; + QTest::newRow("activeMode1") << true << 1; + QTest::newRow("activeMode2") << true << 3; + QTest::newRow("notActiveMode2") << false << 2; + QTest::newRow("wrongData1") << false << 4; } void NightColorTest::testConfigRead() { - QFETCH(QString, active); + QFETCH(bool, active); QFETCH(int, mode); - QFETCH(int, nightTemperature); - QFETCH(double, latitudeFixed); - QFETCH(double, longitudeFixed); - QFETCH(QString, morningBeginFixed); - QFETCH(QString, eveningBeginFixed); - QFETCH(int, transitionTime); - QFETCH(bool, success); const bool activeDefault = true; const int modeDefault = 0; - const int nightTemperatureUpperEnd = NEUTRAL_TEMPERATURE; - const double latitudeFixedDefault = 0; - const double longitudeFixedDefault = 0; - const QTime morningBeginFixedDefault = QTime(6,0,0); - const QTime eveningBeginFixedDefault = QTime(18,0,0); - const int transitionTimeDefault = 30; KConfigGroup cfgGroup = kwinApp()->config()->group("NightColor"); cfgGroup.writeEntry("Active", activeDefault); cfgGroup.writeEntry("Mode", modeDefault); - cfgGroup.writeEntry("NightTemperature", nightTemperatureUpperEnd); - cfgGroup.writeEntry("LatitudeFixed", latitudeFixedDefault); - cfgGroup.writeEntry("LongitudeFixed", longitudeFixedDefault); - cfgGroup.writeEntry("MorningBeginFixed", morningBeginFixedDefault.toString("hhmm")); - cfgGroup.writeEntry("EveningBeginFixed", eveningBeginFixedDefault.toString("hhmm")); - cfgGroup.writeEntry("TransitionTime", transitionTimeDefault); - + kwinApp()->config()->sync(); NightColorManager *manager = NightColorManager::self(); - manager->reparseConfigAndReset(); - auto info = manager->info(); - QVERIFY(!info.isEmpty()); + manager->reconfigure(); - QCOMPARE(info.value("Active").toBool(), activeDefault); - QCOMPARE(info.value("Mode").toInt(), modeDefault); - QCOMPARE(info.value("NightTemperature").toInt(), nightTemperatureUpperEnd); - QCOMPARE(info.value("LatitudeFixed").toDouble(), latitudeFixedDefault); - QCOMPARE(info.value("LongitudeFixed").toDouble(), longitudeFixedDefault); - QCOMPARE(QTime::fromString(info.value("MorningBeginFixed").toString(), Qt::ISODate), morningBeginFixedDefault); - QCOMPARE(QTime::fromString(info.value("EveningBeginFixed").toString(), Qt::ISODate), eveningBeginFixedDefault); - QCOMPARE(info.value("TransitionTime").toInt(), transitionTimeDefault); + QCOMPARE(manager->isEnabled(), activeDefault); + QCOMPARE(manager->mode(), modeDefault); cfgGroup.writeEntry("Active", active); cfgGroup.writeEntry("Mode", mode); - cfgGroup.writeEntry("NightTemperature", nightTemperature); - cfgGroup.writeEntry("LatitudeFixed", latitudeFixed); - cfgGroup.writeEntry("LongitudeFixed", longitudeFixed); - cfgGroup.writeEntry("MorningBeginFixed", morningBeginFixed); - cfgGroup.writeEntry("EveningBeginFixed", eveningBeginFixed); - cfgGroup.writeEntry("TransitionTime", transitionTime); + kwinApp()->config()->sync(); - manager->reparseConfigAndReset(); - info = manager->info(); - QVERIFY(!info.isEmpty()); + manager->reconfigure(); - if (success) { - QCOMPARE(info.value("Active").toBool() ? QString("true") : QString("false"), active); - QCOMPARE(info.value("Mode").toInt(), mode); - QCOMPARE(info.value("NightTemperature").toInt(), nightTemperature); - QCOMPARE(info.value("LatitudeFixed").toDouble(), latitudeFixed); - QCOMPARE(info.value("LongitudeFixed").toDouble(), longitudeFixed); - QCOMPARE(QTime::fromString(info.value("MorningBeginFixed").toString(), Qt::ISODate), QTime::fromString(morningBeginFixed, "hhmm")); - QCOMPARE(QTime::fromString(info.value("EveningBeginFixed").toString(), Qt::ISODate), QTime::fromString(eveningBeginFixed, "hhmm")); - QCOMPARE(info.value("TransitionTime").toInt(), transitionTime); + QCOMPARE(manager->isEnabled(), active); + if (mode > 3 || mode < 0) { + QCOMPARE(manager->mode(), 0); } else { - QCOMPARE(info.value("Active").toBool(), activeDefault); - QCOMPARE(info.value("Mode").toInt(), modeDefault); - QCOMPARE(info.value("NightTemperature").toInt(), nightTemperatureUpperEnd); - QCOMPARE(info.value("LatitudeFixed").toDouble(), latitudeFixedDefault); - QCOMPARE(info.value("LongitudeFixed").toDouble(), longitudeFixedDefault); - QCOMPARE(QTime::fromString(info.value("MorningBeginFixed").toString(), Qt::ISODate), morningBeginFixedDefault); - QCOMPARE(QTime::fromString(info.value("EveningBeginFixed").toString(), Qt::ISODate), eveningBeginFixedDefault); - QCOMPARE(info.value("TransitionTime").toInt(), transitionTimeDefault); - } -} - -void NightColorTest::testChangeConfiguration_data() -{ - QTest::addColumn("activeReadIn"); - QTest::addColumn("modeReadIn"); - QTest::addColumn("nightTemperatureReadIn"); - QTest::addColumn("latitudeFixedReadIn"); - QTest::addColumn("longitudeFixedReadIn"); - QTest::addColumn("morBeginFixedReadIn"); - QTest::addColumn("eveBeginFixedReadIn"); - QTest::addColumn("transitionTimeReadIn"); - QTest::addColumn("successReadIn"); - - QTest::newRow("data0") << true << 0 << 4500 << 45.5 << 35.1 << QTime(6,0,0) << QTime(18,0,0) << 30 << true; - QTest::newRow("data1") << true << 1 << 2500 << -10.5 << -8. << QTime(0,2,0) << QTime(20,0,0) << 60 << true; - QTest::newRow("data2") << false << 2 << 5000 << 90. << -180. << QTime(6,0,0) << QTime(19,1,1) << 1 << true; - QTest::newRow("data3") << false << 3 << 2000 << 90. << -180. << QTime(6,0,0) << QTime(18,0,0) << 1 << true; - QTest::newRow("wrongData0") << true << 4 << 4500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; - QTest::newRow("wrongData1") << true << 0 << 500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; - QTest::newRow("wrongData2") << true << 0 << 7000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; - QTest::newRow("wrongData3") << true << 0 << 4500 << 91. << -181. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; - QTest::newRow("wrongData4") << true << 0 << 4500 << 0. << 0. << QTime(18,0,0) << QTime(6,0,0) << 30 << false; - QTest::newRow("wrongData5") << true << 0 << 4500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 0 << false; - QTest::newRow("wrongData6") << true << 0 << 4500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << -1 << false; - QTest::newRow("wrongData7") << true << 0 << 4500 << 0. << 0. << QTime(12,0,0) << QTime(12,30,0) << 30 << false; - QTest::newRow("wrongData8") << true << 0 << 4500 << 0. << 0. << QTime(1,0,0) << QTime(23,30,0) << 90 << false; -} - -void NightColorTest::testChangeConfiguration() -{ - QFETCH(bool, activeReadIn); - QFETCH(int, modeReadIn); - QFETCH(int, nightTemperatureReadIn); - QFETCH(double, latitudeFixedReadIn); - QFETCH(double, longitudeFixedReadIn); - QFETCH(QTime, morBeginFixedReadIn); - QFETCH(QTime, eveBeginFixedReadIn); - QFETCH(int, transitionTimeReadIn); - QFETCH(bool, successReadIn); - - const bool activeDefault = true; - const int modeDefault = 0; - const int nightTemperatureDefault = DEFAULT_NIGHT_TEMPERATURE; - const double latitudeFixedDefault = 0; - const double longitudeFixedDefault = 0; - const QTime morningBeginFixedDefault = QTime(6,0,0); - const QTime eveningBeginFixedDefault = QTime(18,0,0); - const int transitionTimeDefault = 30; - - // init with default values - bool active = activeDefault; - int mode = modeDefault; - int nightTemperature = nightTemperatureDefault; - double latitudeFixed = latitudeFixedDefault; - double longitudeFixed = longitudeFixedDefault; - QTime morningBeginFixed = morningBeginFixedDefault; - QTime eveningBeginFixed = eveningBeginFixedDefault; - int transitionTime = transitionTimeDefault; - - bool activeExpect = activeDefault; - int modeExpect = modeDefault; - int nightTemperatureExpect = nightTemperatureDefault; - double latitudeFixedExpect = latitudeFixedDefault; - double longitudeFixedExpect = longitudeFixedDefault; - QTime morningBeginFixedExpect = morningBeginFixedDefault; - QTime eveningBeginFixedExpect = eveningBeginFixedDefault; - int transitionTimeExpect = transitionTimeDefault; - - QHash data; - - auto setData = [&active, &mode, &nightTemperature, - &latitudeFixed, &longitudeFixed, - &morningBeginFixed, &eveningBeginFixed, &transitionTime, - &data]() { - data["Active"] = active; - data["Mode"] = mode; - data["NightTemperature"] = nightTemperature; - - data["LatitudeFixed"] = latitudeFixed; - data["LongitudeFixed"] = longitudeFixed; - - data["MorningBeginFixed"] = morningBeginFixed.toString(Qt::ISODate); - data["EveningBeginFixed"] = eveningBeginFixed.toString(Qt::ISODate); - data["TransitionTime"] = transitionTime; - }; - - auto compareValues = [&activeExpect, &modeExpect, &nightTemperatureExpect, - &latitudeFixedExpect, &longitudeFixedExpect, - &morningBeginFixedExpect, &eveningBeginFixedExpect, - &transitionTimeExpect](QHash info) { - QCOMPARE(info.value("Active").toBool(), activeExpect); - QCOMPARE(info.value("Mode").toInt(), modeExpect); - QCOMPARE(info.value("NightTemperature").toInt(), nightTemperatureExpect); - QCOMPARE(info.value("LatitudeFixed").toDouble(), latitudeFixedExpect); - QCOMPARE(info.value("LongitudeFixed").toDouble(), longitudeFixedExpect); - QCOMPARE(info.value("MorningBeginFixed").toString(), morningBeginFixedExpect.toString(Qt::ISODate)); - QCOMPARE(info.value("EveningBeginFixed").toString(), eveningBeginFixedExpect.toString(Qt::ISODate)); - QCOMPARE(info.value("TransitionTime").toInt(), transitionTimeExpect); - }; - - NightColorManager *manager = NightColorManager::self(); - - // test with default values - setData(); - manager->changeConfiguration(data); - compareValues(manager->info()); - - // set to test values - active = activeReadIn; - mode = modeReadIn; - nightTemperature = nightTemperatureReadIn; - latitudeFixed = latitudeFixedReadIn; - longitudeFixed = longitudeFixedReadIn; - morningBeginFixed = morBeginFixedReadIn; - eveningBeginFixed = eveBeginFixedReadIn; - transitionTime = transitionTimeReadIn; - - if (successReadIn) { - activeExpect = activeReadIn; - modeExpect = modeReadIn; - nightTemperatureExpect = nightTemperatureReadIn; - latitudeFixedExpect = latitudeFixedReadIn; - longitudeFixedExpect = longitudeFixedReadIn; - morningBeginFixedExpect = morBeginFixedReadIn; - eveningBeginFixedExpect = eveBeginFixedReadIn; - transitionTimeExpect = transitionTimeReadIn; + QCOMPARE(manager->mode(), mode); } - // test with test values - setData(); - QCOMPARE(manager->changeConfiguration(data), successReadIn); - compareValues(manager->info()); -} - -void NightColorTest::testAutoLocationUpdate() -{ - NightColorManager *manager = NightColorManager::self(); - auto info = manager->info(); - QCOMPARE(info.value("LatitudeAuto").toDouble(), 0.); - QCOMPARE(info.value("LongitudeAuto").toDouble(), 0.); - - // wrong latitude value - manager->autoLocationUpdate(91, 15); - info = manager->info(); - QCOMPARE(info.value("LatitudeAuto").toDouble(), 0.); - QCOMPARE(info.value("LongitudeAuto").toDouble(), 0.); - - // wrong longitude value - manager->autoLocationUpdate(50, -181); - info = manager->info(); - QCOMPARE(info.value("LatitudeAuto").toDouble(), 0.); - QCOMPARE(info.value("LongitudeAuto").toDouble(), 0.); - - // change - manager->autoLocationUpdate(50, -180); - info = manager->info(); - QCOMPARE(info.value("LatitudeAuto").toDouble(), 50.); - QCOMPARE(info.value("LongitudeAuto").toDouble(), -180.); - - // small deviation only - manager->autoLocationUpdate(51.5, -179.5); - info = manager->info(); - QCOMPARE(info.value("LongitudeAuto").toDouble(), -180.); - QCOMPARE(info.value("LatitudeAuto").toDouble(), 50.); } WAYLANDTEST_MAIN(NightColorTest) diff --git a/src/plugins/nightcolor/nightcolordbusinterface.cpp b/src/plugins/nightcolor/nightcolordbusinterface.cpp index cc01a4f4ba..189fc05dbd 100644 --- a/src/plugins/nightcolor/nightcolordbusinterface.cpp +++ b/src/plugins/nightcolor/nightcolordbusinterface.cpp @@ -179,7 +179,6 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::configChange, this, &NightColorDBusInterface::nightColorConfigChanged); new ColorCorrectAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this); } @@ -247,16 +246,6 @@ quint32 NightColorDBusInterface::scheduledTransitionDuration() const return quint32(m_manager->scheduledTransitionDuration()); } -QHash NightColorDBusInterface::nightColorInfo() -{ - return m_manager->info(); -} - -bool NightColorDBusInterface::setNightColorConfig(QHash data) -{ - return m_manager->changeConfiguration(data); -} - void NightColorDBusInterface::nightColorAutoLocationUpdate(double latitude, double longitude) { m_manager->autoLocationUpdate(latitude, longitude); diff --git a/src/plugins/nightcolor/nightcolordbusinterface.h b/src/plugins/nightcolor/nightcolordbusinterface.h index a54885af44..d75fea5772 100644 --- a/src/plugins/nightcolor/nightcolordbusinterface.h +++ b/src/plugins/nightcolor/nightcolordbusinterface.h @@ -50,65 +50,13 @@ public: quint32 scheduledTransitionDuration() const; public Q_SLOTS: - /** - * @brief Gives information about the current state of Night Color. - * - * The returned variant hash has always the fields: - * - ActiveEnabled - * - Active - * - Mode - * - NightTemperatureEnabled - * - NightTemperature - * - Running - * - CurrentColorTemperature - * - LatitudeAuto - * - LongitudeAuto - * - LocationEnabled - * - LatitudeFixed - * - LongitudeFixed - * - TimingsEnabled - * - MorningBeginFixed - * - EveningBeginFixed - * - TransitionTime - * - * @return QHash - * @see nightColorConfigChange - * @see signalNightColorConfigChange - * @since 5.12 - */ - QHash nightColorInfo(); - /** - * @brief Allows changing the Night Color configuration. - * - * The provided variant hash can have the following fields: - * - Active - * - Mode - * - NightTemperature - * - LatitudeAuto - * - LongitudeAuto - * - LatitudeFixed - * - LongitudeFixed - * - MorningBeginFixed - * - EveningBeginFixed - * - TransitionTime - * - * It returns true if the configuration change was successful, otherwise false. - * A change request for the location or timings needs to provide all relevant fields at the same time - * to be successful. Otherwise the whole change request will get ignored. A change request will be ignored - * as a whole as well, if one of the provided information has been sent in a wrong format. - * - * @return bool - * @see nightColorInfo - * @see signalNightColorConfigChange - * @since 5.12 - */ - bool setNightColorConfig(QHash data); /** * @brief For receiving auto location updates, primarily through the KDE Daemon * @return void * @since 5.12 */ void nightColorAutoLocationUpdate(double latitude, double longitude); + /** * @brief Temporarily blocks Night Color. * @since 5.18 @@ -120,19 +68,6 @@ public Q_SLOTS: */ void uninhibit(uint cookie); -Q_SIGNALS: - /** - * @brief Emits that the Night Color configuration has been changed. - * - * The provided variant hash provides the same fields as nightColorInfo - * - * @return void - * @see nightColorInfo - * @see nightColorConfigChange - * @since 5.12 - */ - void nightColorConfigChanged(QHash data); - private Q_SLOTS: void removeInhibitorService(const QString &serviceName); diff --git a/src/plugins/nightcolor/nightcolormanager.cpp b/src/plugins/nightcolor/nightcolormanager.cpp index 5c81deaa82..90cc6c4ed4 100644 --- a/src/plugins/nightcolor/nightcolormanager.cpp +++ b/src/plugins/nightcolor/nightcolormanager.cpp @@ -87,6 +87,10 @@ NightColorManager::~NightColorManager() void NightColorManager::init() { NightColorSettings::instance(kwinApp()->config()); + + m_configWatcher = KConfigWatcher::create(kwinApp()->config()); + connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, &NightColorManager::reconfigure); + // we may always read in the current config readConfig(); @@ -162,11 +166,11 @@ void NightColorManager::hardReset() resetAllTimers(); } -void NightColorManager::reparseConfigAndReset() +void NightColorManager::reconfigure() { cancelAllTimers(); readConfig(); - hardReset(); + resetAllTimers(); } void NightColorManager::toggle() @@ -650,200 +654,6 @@ void NightColorManager::commitGammaRamps(int temperature) setCurrentTemperature(temperature); } -QHash NightColorManager::info() const -{ - return QHash { - { QStringLiteral("Available"), isAvailable() }, - - { QStringLiteral("ActiveEnabled"), true}, - { QStringLiteral("Active"), m_active}, - - { QStringLiteral("ModeEnabled"), true}, - { QStringLiteral("Mode"), (int)m_mode}, - - { QStringLiteral("NightTemperatureEnabled"), true}, - { QStringLiteral("NightTemperature"), m_nightTargetTemp}, - - { QStringLiteral("Running"), m_running}, - { QStringLiteral("CurrentColorTemperature"), m_currentTemp}, - - { QStringLiteral("LatitudeAuto"), m_latAuto}, - { QStringLiteral("LongitudeAuto"), m_lngAuto}, - - { QStringLiteral("LocationEnabled"), true}, - { QStringLiteral("LatitudeFixed"), m_latFixed}, - { QStringLiteral("LongitudeFixed"), m_lngFixed}, - - { QStringLiteral("TimingsEnabled"), true}, - { QStringLiteral("MorningBeginFixed"), m_morning.toString(Qt::ISODate)}, - { QStringLiteral("EveningBeginFixed"), m_evening.toString(Qt::ISODate)}, - { QStringLiteral("TransitionTime"), m_trTime}, - }; -} - -bool NightColorManager::changeConfiguration(QHash data) -{ - bool activeUpdate, modeUpdate, tempUpdate, locUpdate, timeUpdate; - activeUpdate = modeUpdate = tempUpdate = locUpdate = timeUpdate = false; - - bool active = m_active; - NightColorMode mode = m_mode; - int nightT = m_nightTargetTemp; - - double lat = m_latFixed; - double lng = m_lngFixed; - - QTime mor = m_morning; - QTime eve = m_evening; - int trT = m_trTime; - - QHash::const_iterator iter1, iter2, iter3; - - iter1 = data.constFind("Active"); - if (iter1 != data.constEnd()) { - if (!iter1.value().canConvert()) { - return false; - } - bool act = iter1.value().toBool(); - activeUpdate = m_active != act; - active = act; - } - - iter1 = data.constFind("Mode"); - if (iter1 != data.constEnd()) { - if (!iter1.value().canConvert()) { - return false; - } - int mo = iter1.value().toInt(); - if (mo < 0 || 3 < mo) { - return false; - } - NightColorMode moM; - switch (mo) { - case 0: - moM = NightColorMode::Automatic; - break; - case 1: - moM = NightColorMode::Location; - break; - case 2: - moM = NightColorMode::Timings; - break; - case 3: - moM = NightColorMode::Constant; - break; - } - modeUpdate = m_mode != moM; - mode = moM; - } - - iter1 = data.constFind("NightTemperature"); - if (iter1 != data.constEnd()) { - if (!iter1.value().canConvert()) { - return false; - } - int nT = iter1.value().toInt(); - if (nT < MIN_TEMPERATURE || NEUTRAL_TEMPERATURE < nT) { - return false; - } - tempUpdate = m_nightTargetTemp != nT; - nightT = nT; - } - - iter1 = data.constFind("LatitudeFixed"); - iter2 = data.constFind("LongitudeFixed"); - if (iter1 != data.constEnd() && iter2 != data.constEnd()) { - if (!iter1.value().canConvert() || !iter2.value().canConvert()) { - return false; - } - double la = iter1.value().toDouble(); - double ln = iter2.value().toDouble(); - if (!checkLocation(la, ln)) { - return false; - } - locUpdate = m_latFixed != la || m_lngFixed != ln; - lat = la; - lng = ln; - } - - iter1 = data.constFind("MorningBeginFixed"); - iter2 = data.constFind("EveningBeginFixed"); - iter3 = data.constFind("TransitionTime"); - if (iter1 != data.constEnd() && iter2 != data.constEnd() && iter3 != data.constEnd()) { - if (!iter1.value().canConvert() || !iter2.value().canConvert() || !iter3.value().canConvert()) { - return false; - } - QTime mo = QTime::fromString(iter1.value().toString(), Qt::ISODate); - QTime ev = QTime::fromString(iter2.value().toString(), Qt::ISODate); - if (!mo.isValid() || !ev.isValid()) { - return false; - } - int tT = iter3.value().toInt(); - - int diffME = mo.msecsTo(ev); - if (diffME <= 0 || qMin(diffME, MSC_DAY - diffME) <= tT * 60 * 1000 || tT < 1) { - // morning not strictly before evening, transition time too long or transition time out of bounds - return false; - } - - timeUpdate = m_morning != mo || m_evening != ev || m_trTime != tT; - mor = mo; - eve = ev; - trT = tT; - } - - if (!(activeUpdate || modeUpdate || tempUpdate || locUpdate || timeUpdate)) { - return true; - } - - bool resetNeeded = activeUpdate || modeUpdate || tempUpdate || - (locUpdate && mode == NightColorMode::Location) || - (timeUpdate && mode == NightColorMode::Timings); - - if (resetNeeded) { - cancelAllTimers(); - } - - NightColorSettings *s = NightColorSettings::self(); - if (activeUpdate) { - setEnabled(active); - s->setActive(active); - } - - if (modeUpdate) { - setMode(mode); - s->setMode(mode); - } - - if (tempUpdate) { - m_nightTargetTemp = nightT; - s->setNightTemperature(nightT); - } - - if (locUpdate) { - m_latFixed = lat; - m_lngFixed = lng; - s->setLatitudeFixed(lat); - s->setLongitudeFixed(lng); - } - - if (timeUpdate) { - m_morning = mor; - m_evening = eve; - m_trTime = trT; - s->setMorningBeginFixed(mor.toString("hhmm")); - s->setEveningBeginFixed(eve.toString("hhmm")); - s->setTransitionTime(trT); - } - s->save(); - - if (resetNeeded) { - resetAllTimers(); - } - Q_EMIT configChange(info()); - return true; -} - void NightColorManager::autoLocationUpdate(double latitude, double longitude) { qCDebug(KWIN_NIGHTCOLOR, "Received new location (lat: %f, lng: %f)", latitude, longitude); @@ -866,7 +676,6 @@ void NightColorManager::autoLocationUpdate(double latitude, double longitude) s->save(); resetAllTimers(); - Q_EMIT configChange(info()); } void NightColorManager::setEnabled(bool enabled) diff --git a/src/plugins/nightcolor/nightcolormanager.h b/src/plugins/nightcolor/nightcolormanager.h index c8e0ffbc55..8efeecbc93 100644 --- a/src/plugins/nightcolor/nightcolormanager.h +++ b/src/plugins/nightcolor/nightcolormanager.h @@ -16,6 +16,8 @@ #include #include +#include + class QTimer; namespace KWin @@ -81,18 +83,6 @@ public: void init(); - /** - * Get current configuration - * @see changeConfiguration - * @since 5.12 - */ - QHash info() const; - /** - * Change configuration - * @see info - * @since 5.12 - */ - bool changeConfiguration(QHash data); void autoLocationUpdate(double latitude, double longitude); /** @@ -186,7 +176,7 @@ public: qint64 scheduledTransitionDuration() const; // for auto tests - void reparseConfigAndReset(); + void reconfigure(); static NightColorManager *self(); public Q_SLOTS: @@ -194,8 +184,6 @@ public Q_SLOTS: void quickAdjust(); Q_SIGNALS: - void configChange(QHash data); - /** * Emitted whenever the night color manager is blocked or unblocked. */ @@ -305,6 +293,7 @@ private: int m_nightTargetTemp = DEFAULT_NIGHT_TEMPERATURE; int m_inhibitReferenceCount = 0; + KConfigWatcher::Ptr m_configWatcher; }; } // namespace KWin diff --git a/src/plugins/nightcolor/nightcolorsettings.kcfg b/src/plugins/nightcolor/nightcolorsettings.kcfg index d235fba1f9..32fadcb50e 100644 --- a/src/plugins/nightcolor/nightcolorsettings.kcfg +++ b/src/plugins/nightcolor/nightcolorsettings.kcfg @@ -45,10 +45,10 @@ 0. - "0600" + 0600 - "1800" + 1800 30 diff --git a/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml b/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml index 4dd8ab7d59..15afb82fd0 100644 --- a/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml +++ b/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml @@ -1,23 +1,10 @@ - - - - - - - - - - - - -