[fractal] room-history: Preview location before sending it



commit ed6f8a6ab6106e7103aa07d684984af36e8505ca
Author: Kévin Commaille <zecakeh tedomum fr>
Date:   Sun Apr 24 17:29:54 2022 +0200

    room-history: Preview location before sending it
    
    Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1085>

 src/components/media_content_viewer.rs             | 24 +++++++++++++++++++++-
 .../content/room_history/attachment_dialog.rs      |  7 +++++++
 src/session/content/room_history/mod.rs            |  9 +++++++-
 3 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/src/components/media_content_viewer.rs b/src/components/media_content_viewer.rs
index 8f06009c0..f17a1b79f 100644
--- a/src/components/media_content_viewer.rs
+++ b/src/components/media_content_viewer.rs
@@ -3,7 +3,7 @@ use gettextrs::gettext;
 use gtk::{gdk, gio, glib, glib::clone, subclass::prelude::*, CompositeTemplate};
 use log::warn;
 
-use super::AudioPlayer;
+use super::{AudioPlayer, LocationViewer};
 use crate::spawn;
 
 pub enum ContentType {
@@ -275,4 +275,26 @@ impl MediaContentViewer {
 
         self.show_fallback(content_type);
     }
+
+    /// View the given location as a geo URI.
+    pub fn view_location(&self, geo_uri: &str) {
+        self.show_loading();
+
+        let priv_ = self.imp();
+
+        let location = if let Some(location) = priv_
+            .viewer
+            .child()
+            .and_then(|widget| widget.downcast::<LocationViewer>().ok())
+        {
+            location
+        } else {
+            let location = LocationViewer::new();
+            priv_.viewer.set_child(Some(&location));
+            location
+        };
+
+        location.set_geo_uri(geo_uri);
+        self.show_viewer();
+    }
 }
diff --git a/src/session/content/room_history/attachment_dialog.rs 
b/src/session/content/room_history/attachment_dialog.rs
index db63a3653..5108c1e35 100644
--- a/src/session/content/room_history/attachment_dialog.rs
+++ b/src/session/content/room_history/attachment_dialog.rs
@@ -73,6 +73,13 @@ impl AttachmentDialog {
         obj
     }
 
+    pub fn for_location(transient_for: &gtk::Window, title: &str, geo_uri: &str) -> Self {
+        let obj: Self = glib::Object::new(&[("transient-for", transient_for), ("title", &title)])
+            .expect("Failed to create AttachmentDialog");
+        obj.imp().media.view_location(geo_uri);
+        obj
+    }
+
     /// Show the dialog asynchronously.
     ///
     /// Returns `gtk::ResponseType::Ok` if the user clicked on send, otherwise
diff --git a/src/session/content/room_history/mod.rs b/src/session/content/room_history/mod.rs
index dc258c090..b29705d6c 100644
--- a/src/session/content/room_history/mod.rs
+++ b/src/session/content/room_history/mod.rs
@@ -727,10 +727,17 @@ impl RoomHistory {
                 proxy.receive_location_updated().into_future()
             )?;
 
+            let geo_uri = format!("geo:{},{}", location.latitude(), location.longitude());
+
+            let window = self.root().unwrap().downcast::<gtk::Window>().unwrap();
+            let dialog = AttachmentDialog::for_location(&window, "Your Location", &geo_uri);
+            if dialog.run_future().await != gtk::ResponseType::Ok {
+                return Ok(());
+            }
+
             let iso8601_datetime =
                 glib::DateTime::from_unix_local(location.timestamp().as_secs() as i64)
                     .expect("Valid location timestamp");
-            let geo_uri = format!("geo:{},{}", location.latitude(), location.longitude());
             let location_body = gettext_f(
                 "User Location {geo_uri} at {iso8601_datetime}",
                 &[


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