[gnome-maps/wip/mlundblad/libsoup3] WIP: Port to libsoup3




commit 0b38960c9d11ba628aa50ef953cebed761435267
Author: Marcus Lundblad <ml dfupdate se>
Date:   Wed Aug 17 22:49:12 2022 +0200

    WIP: Port to libsoup3

 lib/meson.build           |  2 +-
 meson.build               |  4 ++--
 org.gnome.Maps.json       | 18 +++++++++++++-----
 src/graphHopper.js        | 12 +++++++++---
 src/graphHopperGeocode.js | 26 ++++++++++++++------------
 src/main.js               |  6 +++---
 src/overpass.js           | 36 ++++++++++++++++++++----------------
 src/photonGeocode.js      | 23 +++++++++++------------
 tests/urisTest.js         |  2 +-
 tests/utilsTest.js        |  1 +
 tests/wikipediaTest.js    |  2 +-
 11 files changed, 76 insertions(+), 56 deletions(-)
---
diff --git a/lib/meson.build b/lib/meson.build
index ada8239d..82824e8c 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -49,7 +49,7 @@ gnome.generate_gir(
        includes: [
                'GLib-2.0',
                'GObject-2.0',
-               'Rest-0.7',
+               'Rest-1.0',
                'Shumate-1.0'
        ],
        install: true,
diff --git a/meson.build b/meson.build
index 13ddd0d4..f6b4a604 100644
--- a/meson.build
+++ b/meson.build
@@ -38,12 +38,12 @@ gtk4 = dependency('gtk4')
 geoclue2 = dependency('geoclue-2.0', version: '>= 0.12.99')
 libadwaita = dependency('libadwaita-1')
 gweather = dependency('gweather4', version: '>= 3.90.0')
-geocodeglib = dependency('geocode-glib-1.0', version: '>= 3.15.2')
+geocodeglib = dependency('geocode-glib-2.0', version: '>= 3.15.2')
 
 libmaps_deps = [
        dependency('shumate-1.0'),
        dependency('libxml-2.0'),
-       dependency('rest-0.7', version: '>= 0.7.90')
+       dependency('rest-1.0')
 ]
 
 msgfmt = find_program('msgfmt')
diff --git a/org.gnome.Maps.json b/org.gnome.Maps.json
index be095983..35a27a54 100644
--- a/org.gnome.Maps.json
+++ b/org.gnome.Maps.json
@@ -54,7 +54,8 @@
             "builddir" : true,
             "config-opts" : [
                 "--libdir=/app/lib",
-                "-Denable-gtk-doc=false"
+                "-Denable-gtk-doc=false",
+                "-Dsoup2=false"
             ],
             "sources" : [
                 {
@@ -68,7 +69,7 @@
             "config-opts" : [
                 "-Denable_vala=false",
                 "-Dgtk_doc=false",
-                "-Dsoup2=true"
+                "-Dsoup2=false"
             ],
             "buildsystem" : "meson",
             "sources" : [
@@ -81,11 +82,17 @@
         },
         {
             "name" : "librest",
+            "buildsystem": "meson",
+            "config-opts": [
+               "-Dgtk_doc=false",
+               "-Dexamples=false",
+               "-Dsoup2=false"
+            ],
             "sources" : [
                 {
                     "type" : "archive",
-                    "url" : "https://gitlab.gnome.org/GNOME/librest/-/archive/0.8.1/librest-0.8.1.tar.gz";,
-                    "sha256" : "2bdd1be07a9150b1c6ceea6e01dedf2efcff564381cae0cd6c7330403efe59d7"
+                    "url" : "https://gitlab.gnome.org/GNOME/librest/-/archive/1.0.0/librest-1.0.0.tar.gz";,
+                    "sha256" : "eeba5ddbf91a29decec01c3ccce64b922bd9bf52d631e307e185227295aea51d"
                 }
             ]
         },
@@ -95,7 +102,8 @@
             "config-opts": [
                 "-Ddemos=false",
                 "-Dgtk_doc=false",
-                "-Dvapi=false"
+                "-Dvapi=false",
+                "-Dlibsoup3=true"
             ],
             "sources" : [
                 {
diff --git a/src/graphHopper.js b/src/graphHopper.js
index 76a9b533..78044465 100644
--- a/src/graphHopper.js
+++ b/src/graphHopper.js
@@ -85,9 +85,15 @@ export class GraphHopper {
     _queryGraphHopper(points, transportationType, callback) {
         let url = this._buildURL(points, transportationType);
         let msg = Soup.Message.new('GET', url);
-        this._session.queue_message(msg, (session, message) => {
+        this._session.send_and_read_async(msg, GLib.PRIORITY_DEFAULT, null,
+                                          (source,res) => {
+            let bytes = this._session.send_and_read_finish(res);
+            let body = bytes ? Utils.getBufferText(bytes.get_data()) : null;
+
             try {
-                let result = this._parseMessage(message);
+                let result = this._parseMessage({ status_code:   msg.get_status(),
+                                                  response_body: body,
+                                                  uri:           url });
                 if (!result)
                     callback(null, null);
                 else
@@ -168,7 +174,7 @@ export class GraphHopper {
         if (status_code !== 200)
             return null;
 
-        let result = JSON.parse(response_body.data);
+        let result = JSON.parse(response_body);
 
         if (!Array.isArray(result.paths)) {
             Utils.debug("No route found");
diff --git a/src/graphHopperGeocode.js b/src/graphHopperGeocode.js
index 790beb2a..70020011 100644
--- a/src/graphHopperGeocode.js
+++ b/src/graphHopperGeocode.js
@@ -44,21 +44,20 @@ export class GraphHopperGeocode {
         let url = this._buildURL(string, latitude, longitude);
         let msg = Soup.Message.new('GET', url);
 
-        let handler = cancellable.connect(() => {
-            this._session.cancel_message(msg, Soup.Status.CANCELLED);
-        });
-
-        this._session.queue_message(msg, (session, message) => {
-            cancellable.disconnect(handler);
-
+        this._session.send_and_read_async(msg, GLib.PRIORITY_DEFAULT,
+                                          cancellable,
+                                          (source, res) => {
             if (cancellable.is_cancelled())
                 return;
 
-            if (message.status_code !== Soup.KnownStatusCode.OK) {
-                callback(null, msg.status_code);
+            if (msg.get_status() !== Soup.Status.OK) {
+                callback(null, msg.get_status());
             } else {
                 try {
-                    let result = this._parseMessage(message.response_body.data);
+                    let buffer =
+                        this._session.send_and_read_finish(res).get_data();
+                    let result = this._parseMessage(Utils.getBufferText(buffer));
+
                     if (!result)
                         callback(null, null);
                     else
@@ -76,10 +75,13 @@ export class GraphHopperGeocode {
         let msg = Soup.Message.new('GET', url);
 
         Application.application.mark_busy();
-        this._session.queue_message(msg, (session, message) => {
+        this._session.send_and_read_async(msg, GLib.PRIORITY_DEFAULT, null,
+                                          (source, res) => {
             Application.application.unmark_busy();
             try {
-                let result = this._parseMessage(message.response_body.data);
+                let buffer = this._session.send_and_read_finish(res).get_data();
+
+                let result = this._parseMessage(Utils.getBufferText(buffer));
                 if (!result)
                     callback(null, null);
                 else
diff --git a/src/main.js b/src/main.js
index b7f0b87b..c2d16458 100644
--- a/src/main.js
+++ b/src/main.js
@@ -21,7 +21,7 @@
  */
 
 import 'gi://Adw?version=1';
-import 'gi://GeocodeGlib?version=1.0';
+import 'gi://GeocodeGlib?version=2.0';
 import 'gi://Gdk?version=4.0';
 import 'gi://GdkPixbuf?version=2.0';
 import 'gi://Gio?version=2.0';
@@ -29,9 +29,9 @@ import 'gi://GLib?version=2.0';
 import 'gi://GObject?version=2.0';
 import 'gi://Gtk?version=4.0';
 import 'gi://GWeather?version=4.0';
-import 'gi://Rest?version=0.7';
+import 'gi://Rest?version=1.0';
 import 'gi://Shumate?version=1.0';
-import 'gi://Soup?version=2.4';
+import 'gi://Soup?version=3.0';
 
 import * as system from 'system';
 
diff --git a/src/overpass.js b/src/overpass.js
index 039cb4e6..8948b2a4 100644
--- a/src/overpass.js
+++ b/src/overpass.js
@@ -18,6 +18,7 @@
  */
 
 import Geocode from 'gi://GeocodeGlib';
+import GLib from 'gi://GLib';
 import GObject from 'gi://GObject';
 import Soup from 'gi://Soup';
 
@@ -67,17 +68,18 @@ export class Overpass extends GObject.Object {
     addInfo(place) {
         let url = this._getQueryUrl(Utils.osmTypeToString(place.osm_type),
                                     place.osm_id);
-        let uri = new Soup.URI(url);
-        let request = new Soup.Message({ method: 'GET',
-                                         uri: uri });
+        let request = Soup.Message.new('GET', url);
 
-        this._session.queue_message(request, (obj, message) => {
-            if (message.status_code !== Soup.KnownStatusCode.OK) {
-                Utils.debug('Failed to fetch Overpass result: ' + message.status_code);
+        this._session.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null,
+                                          (source, res) => {
+            if (request.get_status() !== Soup.Status.OK) {
+                Utils.debug('Failed to fetch Overpass result: ' +
+                            request.get_status());
                 return;
             }
             try {
-                let jsonObj = JSON.parse(message.response_body.data);
+                let buffer = this._session.send_and_read_finish(res).get_data();
+                let jsonObj = JSON.parse(Utils.getBufferText(buffer));
                 this._populatePlace(place, jsonObj);
                 this.place = place;
                 this.notify('place');
@@ -88,18 +90,20 @@ export class Overpass extends GObject.Object {
     }
 
     fetchPlace(osmType, osmId, callback) {
-        let url = this._getQueryUrl(osmType, osmId);
-        let uri = new Soup.URI(url);
-        let request = new Soup.Message({ method: 'GET',
-                                         uri: uri });
-
-        this._session.queue_message(request, (obj, message) => {
-            if (message.status_code !== Soup.KnownStatusCode.OK) {
-                Utils.debug('Failed to fetch Overpass result: ' + message.status_code);
+        let url = this._getQueryUrl(osmType, osmId)
+        let request = Soup.Message.new('GET', url);
+
+        this._session.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null,
+                                          (source, res) => {
+            if (request.get_status() !== Soup.Status.OK) {
+                Utils.debug('Failed to fetch Overpass result: ' +
+                            request.get_status());
                 callback(null);
+                return;
             }
             try {
-                let jsonObj = JSON.parse(message.response_body.data);
+                let buffer = this._session.send_and_read_finish(res).get_data();
+                let jsonObj = JSON.parse(Utils.getBufferText(buffer));
                 let place = this._createPlace(jsonObj, osmType, osmId);
                 callback(place);
             } catch(e) {
diff --git a/src/photonGeocode.js b/src/photonGeocode.js
index 4c3a9579..29c98c58 100644
--- a/src/photonGeocode.js
+++ b/src/photonGeocode.js
@@ -42,22 +42,19 @@ export class PhotonGeocode {
 
     search(string, latitude, longitude, cancellable, callback) {
         let url = this._buildURL(string, latitude, longitude);
-        let msg = Soup.Message.new('GET', url);
-        let handler = cancellable.connect(() => {
-            this._session.cancel_message(msg, Soup.Status.CANCELLED);
-        });
-
-        this._session.queue_message(msg, (session, message) => {
-            cancellable.disconnect(handler);
+        let msg = Soup.Message.new('GET', url)
 
+        this._session.send_and_read_async(msg, GLib.PRIORITY_DEFAULT, cancellable,
+                                          (source, res) => {
             if (cancellable.is_cancelled())
                 return;
 
-            if (message.status_code !== Soup.KnownStatusCode.OK) {
-                callback(null, msg.status_code);
+            if (msg.get_status() !== Soup.Status.OK) {
+                callback(null, msg.get_status());
             } else {
                 try {
-                    let result = this._parseMessage(message.response_body.data);
+                    let buffer = this._session.send_and_read_finish(res).get_data();
+                    let result = this._parseMessage(Utils.getBufferText(buffer));
                     if (!result)
                         callback(null, null);
                     else
@@ -75,10 +72,12 @@ export class PhotonGeocode {
         let msg = Soup.Message.new('GET', url);
 
         Application.application.mark_busy();
-        this._session.queue_message(msg, (session, message) => {
+        this._session.send_and_read_async(msg, GLib.PRIORITY_DEFAULT, null,
+                                          (source, res) => {
             Application.application.unmark_busy();
             try {
-                let result = this._parseMessage(message.response_body.data);
+                let buffer = this._session.send_and_read_finish(res).get_data();
+                let result = this._parseMessage(Utils.getBufferText(buffer));
                 if (!result)
                     callback(null, null);
                 else
diff --git a/tests/urisTest.js b/tests/urisTest.js
index f5fe6e86..8b8b4d9f 100644
--- a/tests/urisTest.js
+++ b/tests/urisTest.js
@@ -21,7 +21,7 @@
 
 import 'gi://Gdk?version=3.0';
 import 'gi://Gtk?version=3.0';
-import 'gi://Soup?version=2.4';
+import 'gi://Soup?version=3.0';
 
 const JsUnit = imports.jsUnit;
 
diff --git a/tests/utilsTest.js b/tests/utilsTest.js
index af3719e0..118f9a72 100644
--- a/tests/utilsTest.js
+++ b/tests/utilsTest.js
@@ -21,6 +21,7 @@
 
 import 'gi://Gdk?version=3.0';
 import 'gi://Gtk?version=3.0';
+import 'gi://GeocodeGlib?version=2.0';
 
 import GeocodeGlib from 'gi://GeocodeGlib';
 import GLib from 'gi://GLib';
diff --git a/tests/wikipediaTest.js b/tests/wikipediaTest.js
index 72d55178..9b6f2962 100644
--- a/tests/wikipediaTest.js
+++ b/tests/wikipediaTest.js
@@ -21,7 +21,7 @@
 
 import 'gi://Gdk?version=3.0';
 import 'gi://Gtk?version=3.0';
-import 'gi://Soup?version=2.4';
+import 'gi://Soup?version=3.0';
 
 import * as Wikipedia from './wikipedia.js';
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]