From 03d782310b7d7db1de39602dff6a8facdc235f39 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 26 Sep 2019 11:41:05 +0300 Subject: [PATCH 1/2] [nightcolor] Add missing const qualifiers Summary: Mark some immutable variables with const to improve code readability. Test Plan: Compiles. Reviewers: #kwin, davidedmundson, romangg Reviewed By: #kwin, davidedmundson, romangg Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D24235 --- colorcorrection/manager.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/colorcorrection/manager.cpp b/colorcorrection/manager.cpp index 723bcce2a2..651d3a4af9 100644 --- a/colorcorrection/manager.cpp +++ b/colorcorrection/manager.cpp @@ -213,7 +213,7 @@ void Manager::readConfig() m_active = s->active(); - NightColorMode mode = s->mode(); + const NightColorMode mode = s->mode(); switch (s->mode()) { case NightColorMode::Automatic: case NightColorMode::Location: @@ -332,7 +332,7 @@ void Manager::quickAdjust() } int nextTemp; - int targetTemp = currentTargetTemp(); + const int targetTemp = currentTargetTemp(); if (m_currentTemp < targetTemp) { nextTemp = qMin(m_currentTemp + TEMPERATURE_STEP, targetTemp); @@ -387,9 +387,9 @@ void Manager::resetSlowUpdateTimer() delete m_slowUpdateTimer; m_slowUpdateTimer = nullptr; - QDateTime now = QDateTime::currentDateTime(); - bool isDay = daylight(); - int targetTemp = isDay ? m_dayTargetTemp : m_nightTargetTemp; + const QDateTime now = QDateTime::currentDateTime(); + const bool isDay = daylight(); + const int targetTemp = isDay ? m_dayTargetTemp : m_nightTargetTemp; // We've reached the target color temperature or the transition time is zero. if (m_prev.first == m_prev.second || m_currentTemp == targetTemp) { @@ -437,13 +437,13 @@ void Manager::slowUpdate(int targetTemp) void Manager::updateSunTimings(bool force) { - QDateTime todayNow = QDateTime::currentDateTime(); + const QDateTime todayNow = QDateTime::currentDateTime(); if (m_mode == NightColorMode::Timings) { - QDateTime morB = QDateTime(todayNow.date(), m_morning); - QDateTime morE = morB.addSecs(m_trTime * 60); - QDateTime eveB = QDateTime(todayNow.date(), m_evening); - QDateTime eveE = eveB.addSecs(m_trTime * 60); + const QDateTime morB = QDateTime(todayNow.date(), m_morning); + const QDateTime morE = morB.addSecs(m_trTime * 60); + const QDateTime eveB = QDateTime(todayNow.date(), m_evening); + const QDateTime eveE = eveB.addSecs(m_trTime * 60); if (morB <= todayNow && todayNow < eveB) { m_next = DateTimes(eveB, eveE); @@ -505,8 +505,8 @@ DateTimes Manager::getSunTimings(const QDateTime &dateTime, double latitude, dou // At locations near the poles it is possible, that we can't // calculate some or all sun timings (midnight sun). // In this case try to fallback to sensible default values. - bool beginDefined = !dateTimes.first.isNull(); - bool endDefined = !dateTimes.second.isNull(); + const bool beginDefined = !dateTimes.first.isNull(); + const bool endDefined = !dateTimes.second.isNull(); if (!beginDefined || !endDefined) { if (beginDefined) { dateTimes.second = dateTimes.first.addMSecs( FALLBACK_SLOW_UPDATE_TIME ); @@ -528,7 +528,7 @@ bool Manager::checkAutomaticSunTimings() const { if (m_prev.first.isValid() && m_prev.second.isValid() && m_next.first.isValid() && m_next.second.isValid()) { - QDateTime todayNow = QDateTime::currentDateTime(); + const QDateTime todayNow = QDateTime::currentDateTime(); return m_prev.first <= todayNow && todayNow < m_next.first && m_prev.first.msecsTo(m_next.first) < MSC_DAY * 23./24; } @@ -550,7 +550,7 @@ int Manager::currentTargetTemp() const return m_nightTargetTemp; } - QDateTime todayNow = QDateTime::currentDateTime(); + const QDateTime todayNow = QDateTime::currentDateTime(); auto f = [this, todayNow](int target1, int target2) { if (todayNow <= m_prev.second) { From 086428754ecfce28a7603475e6256c13985a6539 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 26 Sep 2019 11:47:59 +0300 Subject: [PATCH 2/2] [nightcolor] Print a debug message upon receiving new location from kded module Summary: This can be useful for debugging whether Night Color manager actually receives new location data from colorcorrectlocationupdater kded module. CCBUG: 412211 Test Plan: Run kwin with QT_LOGGING_RULES="kwin_colorcorrection.debug=true" Run from the terminal the following two commands qdbus org.kde.kded5 /kded unloadModule colorcorrectlocationupdater qdbus org.kde.kded5 /kded loadModule colorcorrectlocationupdater Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D24236 --- colorcorrection/manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/colorcorrection/manager.cpp b/colorcorrection/manager.cpp index 651d3a4af9..50b304ca0e 100644 --- a/colorcorrection/manager.cpp +++ b/colorcorrection/manager.cpp @@ -825,6 +825,8 @@ bool Manager::changeConfiguration(QHash data) void Manager::autoLocationUpdate(double latitude, double longitude) { + qCDebug(KWIN_COLORCORRECTION, "Received new location (lat: %f, lng: %f)", latitude, longitude); + if (!checkLocation(latitude, longitude)) { return; }