From 7c75a2fd06d38c9a437528669c49d188c14c72e9 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Thu, 8 Jun 2023 18:14:07 +0200 Subject: [PATCH] Create the OSM QtLocation plugin only once Just loading that plugin already triggers an HTTP request, so lets only do that when really needed and even more importantly, not for every single location delegate again. --- src/main.cpp | 1 + .../Component/Timeline/LocationDelegate.qml | 12 +---------- .../Component/Timeline/OsmLocationPlugin.qml | 21 +++++++++++++++++++ src/res.qrc | 1 + 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 src/qml/Component/Timeline/OsmLocationPlugin.qml diff --git a/src/main.cpp b/src/main.cpp index 243cad6a9..c95ffabb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -283,6 +283,7 @@ int main(int argc, char *argv[]) qmlRegisterSingletonType("org.kde.neochat", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue { return engine->toScriptValue(KAboutData::applicationData()); }); + qmlRegisterSingletonType(QUrl("qrc:/OsmLocationPlugin.qml"), "org.kde.neochat", 1, 0, "OsmLocationPlugin"); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) qRegisterMetaTypeStreamOperators(); diff --git a/src/qml/Component/Timeline/LocationDelegate.qml b/src/qml/Component/Timeline/LocationDelegate.qml index 1970d3b6f..b792ab902 100644 --- a/src/qml/Component/Timeline/LocationDelegate.qml +++ b/src/qml/Component/Timeline/LocationDelegate.qml @@ -47,18 +47,8 @@ TimelineContainer { center: QtPositioning.coordinate(root.latitude, root.longitude) zoomLevel: 15 - plugin: Plugin { - name: "osm" - PluginParameter { - name: "osm.useragent" - value: Application.name + "/" + Application.version + " (kde-devel@kde.org)" - } - PluginParameter { - name: "osm.mapping.providersrepository.address" - value: "https://autoconfig.kde.org/qtlocation/" - } - } + plugin: OsmLocationPlugin.plugin onCopyrightLinkActivated: Qt.openUrlExternally(link) diff --git a/src/qml/Component/Timeline/OsmLocationPlugin.qml b/src/qml/Component/Timeline/OsmLocationPlugin.qml new file mode 100644 index 000000000..0b37a8fcf --- /dev/null +++ b/src/qml/Component/Timeline/OsmLocationPlugin.qml @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2021 Tobias Fella +// SPDX-License-Identifier: GPL-2.0-or-later + +pragma Singleton + +import QtQuick 2.15 +import QtLocation 5.15 + +QtObject { + property var plugin: Plugin { + name: "osm" + PluginParameter { + name: "osm.useragent" + value: Application.name + "/" + Application.version + " (kde-devel@kde.org)" + } + PluginParameter { + name: "osm.mapping.providersrepository.address" + value: "https://autoconfig.kde.org/qtlocation/" + } + } +} diff --git a/src/res.qrc b/src/res.qrc index 95d291adb..578b30961 100644 --- a/src/res.qrc +++ b/src/res.qrc @@ -126,5 +126,6 @@ qml/Component/InvitationView.qml qml/Component/AvatarTabButton.qml qml/Page/RoomList/SpaceDrawer.qml + qml/Component/Timeline/OsmLocationPlugin.qml