[neon/kde/plasma-workspace/Neon/unstable] debian/patches: add Kai's kded geoip patch for testing

Carlos De Maine null at kde.org
Thu Oct 12 23:03:45 BST 2023


Git commit 45ad34e7cec92ff7f5598a716f7dbeb32db5d104 by Carlos De Maine.
Committed on 13/10/2023 at 00:03.
Pushed by carlosdem into branch 'Neon/unstable'.

add Kai's kded geoip patch for testing

D  +0    -22   debian/patches/0001_appstreamqt6
A  +287  -0    debian/patches/0001_kded_geoip
M  +1    -1    debian/patches/series

https://invent.kde.org/neon/kde/plasma-workspace/-/commit/45ad34e7cec92ff7f5598a716f7dbeb32db5d104

diff --git a/debian/patches/0001_appstreamqt6 b/debian/patches/0001_appstreamqt6
deleted file mode 100644
index 5b3e04b..0000000
--- a/debian/patches/0001_appstreamqt6
+++ /dev/null
@@ -1,22 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 97361771527d94c9d7f6d99b9289ba15daf5167f..1b264a988168437cbf3b93abbd20006f8fc01e1a 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -187,13 +187,13 @@ if(FONTCONFIG_FOUND)
-   find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS PrintSupport)
- endif()
- 
--find_package(AppStreamQt 1.0) # 1.0 will be the first release to support Qt6
--set_package_properties(AppStreamQt PROPERTIES DESCRIPTION "Access metadata for listing available software"
-+find_package(AppStreamQt6 1.0) # 1.0 will be the first release to support Qt6
-+set_package_properties(AppStreamQt6 PROPERTIES DESCRIPTION "Access metadata for listing available software"
-                        URL "https://www.freedesktop.org/wiki/Distributions/AppStream/"
-                        TYPE OPTIONAL)
- 
--if(${AppStreamQt_FOUND})
--    set(HAVE_APPSTREAMQT true)
-+if(${AppStreamQt6_FOUND})
-+    set(HAVE_APPSTREAMQT6 true)
- endif()
- 
- find_package(UDev REQUIRED)
diff --git a/debian/patches/0001_kded_geoip b/debian/patches/0001_kded_geoip
new file mode 100644
index 0000000..8aa13e8
--- /dev/null
+++ b/debian/patches/0001_kded_geoip
@@ -0,0 +1,287 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 8be461e754d1a02c08e21e4e0df573a7e611b27a..49f3a098337f75a3417a9add57c213da95dea819 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -60,7 +60,7 @@ find_package(KPipeWire CONFIG)
+ find_package(KF6NetworkManagerQt ${KF6_MIN_VERSION})
+ set_package_properties(KF6NetworkManagerQt PROPERTIES DESCRIPTION "Qt wrapper for NetworkManager API"
+                        TYPE OPTIONAL
+-                       PURPOSE "Needed by geolocation data engine."
++                       PURPOSE "Needed by geolocation data engine and location-based time zone changes."
+                       )
+ 
+ find_package(KF6Kirigami2 ${KF6_MIN_VERSION} CONFIG)
+@@ -390,6 +390,9 @@ add_subdirectory(wallpapers)
+ 
+ add_subdirectory(kioworkers)
+ add_subdirectory(ktimezoned)
++if(KF6NetworkManagerQt_FOUND)
++    add_subdirectory(geotimezoned)
++endif()
+ add_subdirectory(menu)
+ add_subdirectory(phonon)
+ 
+diff --git a/geotimezoned/CMakeLists.txt b/geotimezoned/CMakeLists.txt
+new file mode 100644
+index 0000000000000000000000000000000000000000..eb1ed5cdf13a362160ab3deda98b803857e87ee5
+--- /dev/null
++++ b/geotimezoned/CMakeLists.txt
+@@ -0,0 +1,29 @@
++# SPDX-License-Identifier: BSD-2-Clause
++# SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde at broulik.de>
++
++set(geotimezoned_SRCS
++    geotimezonemodule.cpp
++    geotimezonemodule.h
++)
++qt_add_dbus_interface(geotimezoned_SRCS org.freedesktop.timedated1.xml timedated_interface)
++
++kcoreaddons_add_plugin(geotimezoned
++    SOURCES
++    ${geotimezoned_SRCS}
++    INSTALL_NAMESPACE "kf6/kded"
++)
++
++ecm_qt_declare_logging_category(geotimezoned
++    HEADER geotimezoned_debug.h
++    IDENTIFIER GEOTIMEZONED_DEBUG
++    CATEGORY_NAME org.kde.plasma.geotimezoned
++    DESCRIPTION "Location-based System Time Zone"
++)
++
++target_link_libraries(geotimezoned
++    Qt6::DBus
++    Qt6::Network
++    KF6::DBusAddons
++    KF6::CoreAddons
++    KF6::NetworkManagerQt
++)
+diff --git a/geotimezoned/geotimezoned.json b/geotimezoned/geotimezoned.json
+new file mode 100644
+index 0000000000000000000000000000000000000000..49cd46c3fefa27686757580e4bacce621d82a954
+--- /dev/null
++++ b/geotimezoned/geotimezoned.json
+@@ -0,0 +1,6 @@
++{
++    "KPlugin": {
++        "Description": "Automatically change the system time zone based on the current location",
++        "Name": "Location-based System Time Zone"
++    }
++}
+diff --git a/geotimezoned/geotimezoned.json.license b/geotimezoned/geotimezoned.json.license
+new file mode 100644
+index 0000000000000000000000000000000000000000..23c18491745c9103d79d5a005eb50ce1e9748fda
+--- /dev/null
++++ b/geotimezoned/geotimezoned.json.license
+@@ -0,0 +1,2 @@
++SPDX-License-Identifier: CC0-1.0
++SPDX-FileCopyrightText: none
+diff --git a/geotimezoned/geotimezonemodule.cpp b/geotimezoned/geotimezonemodule.cpp
+new file mode 100644
+index 0000000000000000000000000000000000000000..348e8bbd3cd2cd15f312d85d37e2c6105ab7dedb
+--- /dev/null
++++ b/geotimezoned/geotimezonemodule.cpp
+@@ -0,0 +1,142 @@
++/*
++ * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <ghqalpha at broulik.de>
++ * SPDX-License-Identifier: GPL-2.0-or-later
++ */
++
++#include "geotimezonemodule.h"
++
++#include <KPluginFactory>
++
++#include <QDBusPendingCallWatcher>
++#include <QJsonDocument>
++#include <QJsonObject>
++#include <QNetworkAccessManager>
++#include <QNetworkReply>
++#include <QScopedPointer>
++#include <QStandardPaths>
++
++#include <NetworkManagerQt/ActiveConnection>
++#include <NetworkManagerQt/Manager>
++
++#include <chrono>
++
++#include "geotimezoned_debug.h"
++#include "timedated_interface.h"
++
++K_PLUGIN_CLASS_WITH_JSON(KdedGeoTimeZonePlugin, "geotimezoned.json")
++
++// TODO use our own endpoint.
++static const QUrl s_geoIpEndpoint{QStringLiteral("https://geoip.kde.org/v1/calamares")};
++
++static constexpr QLatin1String s_timedateService{"org.freedesktop.timedate1"};
++static constexpr QLatin1String s_timedatePath{"/org/freedesktop/timedate1"};
++
++KdedGeoTimeZonePlugin::KdedGeoTimeZonePlugin(QObject *parent, const QVariantList &args)
++    : KDEDModule(parent)
++{
++    Q_UNUSED(args);
++
++    m_nam.setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
++    m_nam.setStrictTransportSecurityEnabled(true);
++    m_nam.enableStrictTransportSecurityStore(true, QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/kded/hsts/"));
++
++    connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &KdedGeoTimeZonePlugin::checkTimeZone);
++    connect(NetworkManager::notifier(), &NetworkManager::Notifier::meteredChanged, this, &KdedGeoTimeZonePlugin::checkTimeZone);
++    connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionChanged, this, &KdedGeoTimeZonePlugin::checkTimeZone);
++
++    checkTimeZone();
++}
++
++bool KdedGeoTimeZonePlugin::shouldCheckTimeZone() const
++{
++    using namespace std::chrono_literals;
++    if (m_timer.isValid() && std::chrono::milliseconds{m_timer.elapsed()} < 1h) {
++        return false;
++    }
++
++    const auto connectivity = NetworkManager::connectivity();
++    if (connectivity == NetworkManager::Connectivity::NoConnectivity || connectivity == NetworkManager::Connectivity::Portal
++        || connectivity == NetworkManager::Connectivity::Limited) {
++        return false;
++    }
++
++    const auto metered = NetworkManager::metered();
++    if (metered == NetworkManager::Device::MeteredStatus::Yes || metered == NetworkManager::Device::MeteredStatus::GuessYes) {
++        return false;
++    }
++
++    const auto connection = NetworkManager::primaryConnection();
++    return connection && !connection->vpn();
++}
++
++void KdedGeoTimeZonePlugin::checkTimeZone()
++{
++    if (!shouldCheckTimeZone()) {
++        return;
++    }
++
++    QNetworkRequest request(s_geoIpEndpoint);
++    request.setPriority(QNetworkRequest::LowPriority);
++    request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
++
++    request.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("kded/geotimezoned/") + qApp->applicationVersion());
++
++    auto *reply = m_nam.get(request);
++    connect(reply, &QNetworkReply::finished, this, [this, reply] {
++        QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> replyPtr(reply);
++        if (replyPtr->error() != QNetworkReply::NoError) {
++            qCWarning(GEOTIMEZONED_DEBUG) << "Failed to load time zone from" << replyPtr->url() << replyPtr->errorString();
++            return;
++        }
++
++        const QJsonObject replyObject = QJsonDocument::fromJson(replyPtr->readAll()).object();
++        const QString timeZone = replyObject.value(QLatin1String("time_zone")).toString();
++        if (timeZone.isEmpty()) {
++            qCWarning(GEOTIMEZONED_DEBUG) << "Received no or an invalid time zone object" << replyObject;
++            return;
++        }
++
++        qCInfo(GEOTIMEZONED_DEBUG) << "Received time zone" << timeZone;
++        setGeoTimeZone(timeZone.toLatin1());
++        m_timer.restart();
++    });
++}
++
++void KdedGeoTimeZonePlugin::setGeoTimeZone(const QByteArray &geoTimeZoneId)
++{
++    // No change since we last asked.
++    if (m_geoTimeZoneId == geoTimeZoneId) {
++        qCDebug(GEOTIMEZONED_DEBUG) << "Time zone didn't change from" << m_geoTimeZoneId << "from last check";
++        return;
++    }
++
++    org::freedesktop::timedate1 timedateInterface{s_timedateService, s_timedatePath, QDBusConnection::systemBus()};
++
++    const QString currentTimeZoneId = timedateInterface.timezone();
++    if (currentTimeZoneId.isEmpty()) {
++        qCWarning(GEOTIMEZONED_DEBUG) << "Failed to get current system time zone from timedated";
++        return;
++    }
++
++    if (currentTimeZoneId == geoTimeZoneId) {
++        qCDebug(GEOTIMEZONED_DEBUG) << "Time zone" << geoTimeZoneId << "is the same as the current time zone";
++        return;
++    }
++
++    qCInfo(GEOTIMEZONED_DEBUG) << "Automatically changing time zone to" << geoTimeZoneId << "based on current location";
++    auto reply = timedateInterface.SetTimezone(QString::fromLatin1(geoTimeZoneId), false /*interactive*/);
++    auto *watcher = new QDBusPendingCallWatcher(reply, this);
++    connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, geoTimeZoneId](QDBusPendingCallWatcher *watcher) {
++        watcher->deleteLater();
++
++        QDBusPendingReply<> reply = *watcher;
++        if (reply.isError()) {
++            qCWarning(GEOTIMEZONED_DEBUG) << "Failed to set time zone to" << geoTimeZoneId << reply.error().message();
++            return;
++        }
++
++        m_geoTimeZoneId = geoTimeZoneId;
++    });
++}
++
++#include "geotimezonemodule.moc"
+diff --git a/geotimezoned/geotimezonemodule.h b/geotimezoned/geotimezonemodule.h
+new file mode 100644
+index 0000000000000000000000000000000000000000..1b1c3499cac3466a637696b6296bceda1ba1acc1
+--- /dev/null
++++ b/geotimezoned/geotimezonemodule.h
+@@ -0,0 +1,29 @@
++/*
++ * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <ghqalpha at broulik.de>
++ * SPDX-License-Identifier: GPL-2.0-or-later
++ */
++
++#pragma once
++
++#include <KDEDModule>
++
++#include <QByteArray>
++#include <QElapsedTimer>
++#include <QNetworkAccessManager>
++
++class KdedGeoTimeZonePlugin : public KDEDModule
++{
++    Q_OBJECT
++
++public:
++    KdedGeoTimeZonePlugin(QObject *parent, const QVariantList &args);
++
++private:
++    bool shouldCheckTimeZone() const;
++    void checkTimeZone();
++    void setGeoTimeZone(const QByteArray &geoTimeZoneId);
++
++    QNetworkAccessManager m_nam;
++    QElapsedTimer m_timer;
++    QByteArray m_geoTimeZoneId;
++};
+diff --git a/geotimezoned/org.freedesktop.timedated1.xml b/geotimezoned/org.freedesktop.timedated1.xml
+new file mode 100644
+index 0000000000000000000000000000000000000000..b21efbd66403b7d74a8b7f67f18a3bf7669e5555
+--- /dev/null
++++ b/geotimezoned/org.freedesktop.timedated1.xml
+@@ -0,0 +1,20 @@
++<?xml version="1.0"?>
++<!--
++ SPDX-License-Identifier: LGPL-2.1-or-later
++-->
++
++<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
++    "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
++
++<node>
++
++<interface name="org.freedesktop.timedate1">
++  <property name="Timezone" type="s" access="read"/>
++  <method name="SetTimezone">
++    <arg type="s" name="timezone" direction="in"/>
++    <arg type="b" name="interactive" direction="in"/>
++  </method>
++  <!-- Omitted the rest we don't use -->
++</interface>
++
++</node>
diff --git a/debian/patches/series b/debian/patches/series
index 8b13789..2fb6b20 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1 @@
-
+0001_kded_geoip


More information about the Neon-commits mailing list