[fractal] room-history: Use geo_uri crate for geo URI parsing/generation
- From: Kévin Commaille <kcommaille src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] room-history: Use geo_uri crate for geo URI parsing/generation
- Date: Wed, 5 Oct 2022 09:29:04 +0000 (UTC)
commit 85b5af0f372841c2a541d889f67f8acd99afec4c
Author: Paul van Tilburg <paul luon net>
Date: Fri Sep 16 20:56:49 2022 +0200
room-history: Use geo_uri crate for geo URI parsing/generation
Cargo.lock | 19 +++++++++++++++----
Cargo.toml | 1 +
src/components/location_viewer.rs | 15 ++++++---------
src/session/content/room_history/mod.rs | 8 +++++++-
4 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 0c59300cf..5e273e07b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1108,6 +1108,7 @@ dependencies = [
"ashpd",
"async-stream",
"futures",
+ "geo-uri",
"gettext-rs",
"gst-plugin-gtk4",
"gstreamer",
@@ -1448,6 +1449,16 @@ dependencies = [
"version_check",
]
+[[package]]
+name = "geo-uri"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75b28b0f9cef67676b9380cd7a918678a10d2c6bb64e5b6ac2f6a1bd41249b9"
+dependencies = [
+ "derive_builder 0.11.2",
+ "thiserror",
+]
+
[[package]]
name = "getopts"
version = "0.2.21"
@@ -4309,18 +4320,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.34"
+version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252"
+checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.34"
+version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487"
+checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [
"proc-macro2 1.0.43",
"quote 1.0.21",
diff --git a/Cargo.toml b/Cargo.toml
index f37178f4c..caaeeb3cc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -52,6 +52,7 @@ thiserror = "1.0.25"
rqrr = "0.4.0"
secular = { version = "1.0.1", features = ["bmp", "normalization"] }
pulldown-cmark = "0.9.2"
+geo-uri = "0.2.0"
[dependencies.sourceview]
package = "sourceview5"
diff --git a/src/components/location_viewer.rs b/src/components/location_viewer.rs
index 4159f8f61..b18e11b55 100644
--- a/src/components/location_viewer.rs
+++ b/src/components/location_viewer.rs
@@ -1,4 +1,5 @@
use adw::{prelude::*, subclass::prelude::*};
+use geo_uri::GeoUri;
use gtk::{glib, CompositeTemplate};
use shumate::prelude::*;
@@ -134,15 +135,11 @@ impl LocationViewer {
pub fn set_geo_uri(&self, uri: &str) {
let imp = self.imp();
- let mut uri = uri.trim_start_matches("geo:").split(',');
- let latitude = uri
- .next()
- .and_then(|lat_s| lat_s.parse::<f64>().ok())
- .unwrap_or_default();
- let longitude = uri
- .next()
- .and_then(|lon_s| lon_s.parse::<f64>().ok())
- .unwrap_or_default();
+ let (latitude, longitude) = match GeoUri::parse(uri) {
+ Ok(geo_uri) => (geo_uri.latitude(), geo_uri.longitude()),
+ // FIXME: Actually handle the error by showing it instead of the map.
+ Err(_) => return,
+ };
imp.map
.viewport()
diff --git a/src/session/content/room_history/mod.rs b/src/session/content/room_history/mod.rs
index 33edea632..f619961a1 100644
--- a/src/session/content/room_history/mod.rs
+++ b/src/session/content/room_history/mod.rs
@@ -14,6 +14,7 @@ use ashpd::{
WindowIdentifier,
};
use futures::TryFutureExt;
+use geo_uri::GeoUri;
use gettextrs::gettext;
use gtk::{
gdk, gio, glib,
@@ -922,7 +923,12 @@ impl RoomHistory {
proxy.receive_location_updated().into_future()
)?;
- let geo_uri = format!("geo:{},{}", location.latitude(), location.longitude());
+ let geo_uri = GeoUri::builder()
+ .latitude(location.latitude())
+ .longitude(location.longitude())
+ .build()
+ .expect("Got invalid coordinates from ashpd")
+ .to_string();
let window = self.root().unwrap().downcast::<gtk::Window>().unwrap();
let dialog =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]