propertiesView: Add button to copy coordiantes

Copy location coordinates in a machine readable format for use in other apps.

Closes #164

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/371>
This commit is contained in:
Sophie Herold 2024-02-09 22:06:24 +01:00
parent 0dc71357f1
commit 8b60dc7dcb
3 changed files with 68 additions and 5 deletions

View file

@ -20,6 +20,7 @@ use std::cell::{OnceCell, RefCell};
use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::translate::IntoGlib;
use glib::Properties;
use gtk::CompositeTemplate;
@ -91,6 +92,10 @@ mod imp {
obj.imp().open_directory().await;
});
klass.install_action("properties.copy-location", None, move |obj, _, _| {
obj.imp().copy_location();
});
klass.install_action("properties.open-location", None, move |obj, _, _| {
obj.imp().open_location();
});
@ -280,6 +285,26 @@ mod imp {
};
}
/// Copy GPS location
fn copy_location(&self) {
let obj = self.obj();
if let Some(location) = obj.image().and_then(|x| x.metadata().gps_location()) {
let clipboard = obj.display().clipboard();
clipboard.set_text(&location.machine_readable());
let _ = obj.activate_action(
"win.show-toast",
Some(
&(
gettext("Image Coordinates Copied"),
adw::ToastPriority::Normal.into_glib(),
)
.to_variant(),
),
);
}
}
/// Open GPS location in apps like Maps via `geo:` URI
fn open_location(&self) {
let obj = self.obj();

View file

@ -104,9 +104,23 @@
<child>
<object class="AdwActionRow" id="location">
<property name="title" translatable="yes">Location</property>
<property name="activatable-widget">location_button</property>
<property name="subtitle-selectable">True</property>
<style>
<class name="numeric" />
</style>
<child type="suffix">
<object class="GtkButton" id="location_button">
<object class="GtkButton">
<property name="valign">center</property>
<property name="action-name">properties.copy-location</property>
<property name="icon-name">edit-copy-symbolic</property>
<property name="tooltip-text" translatable="yes">Copy Coordinates</property>
<style>
<class name="flat" />
</style>
</object>
</child>
<child type="suffix">
<object class="GtkButton">
<property name="valign">center</property>
<property name="action-name">properties.open-location</property>
<property name="icon-name">mark-location-symbolic</property>