From 6c09758633961c6f9f790acb43a757f889c5fa10 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Tue, 10 Jun 2025 19:31:30 +1000 Subject: [PATCH] event-popover: Support the maps URI for opening locations Open gnome-maps (or other map application) when clicking on a map icon next to the location address. Resolves: https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/326 Signed-off-by: Alistair Francis Part-of: --- src/gui/gcal-event-popover.blp | 40 ++++++++++++++++++++++--------- src/gui/gcal-event-popover.c | 26 ++++++++++++++++++++ src/gui/icons/icons.gresource.xml | 1 + src/gui/icons/map-symbolic.svg | 2 ++ 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 src/gui/icons/map-symbolic.svg diff --git a/src/gui/gcal-event-popover.blp b/src/gui/gcal-event-popover.blp index 5cfe4616..029dc368 100644 --- a/src/gui/gcal-event-popover.blp +++ b/src/gui/gcal-event-popover.blp @@ -138,25 +138,43 @@ template $GcalEventPopover: Popover { Separator {} Box { - orientation: vertical; margin-top: 12; margin-bottom: 12; margin-start: 18; margin-end: 18; + spacing: 12; - Label { - halign: start; - label: _("Location"); + Box { + orientation: vertical; - styles [ - "heading", - ] + Label { + halign: start; + label: _("Location"); + + styles [ + "heading", + ] + } + + Label location_label { + halign: start; + selectable: true; + ellipsize: end; + } } - Label location_label { - halign: start; - selectable: true; - ellipsize: end; + Button { + halign: end; + hexpand: true; + valign: center; + tooltip-text: _("Open Location"); + icon-name: "map-symbolic"; + + styles [ + "circular", + ] + + clicked => $on_map_button_clicked_cb(template) not-swapped; } } } diff --git a/src/gui/gcal-event-popover.c b/src/gui/gcal-event-popover.c index 74bea2f7..1c1a7d43 100644 --- a/src/gui/gcal-event-popover.c +++ b/src/gui/gcal-event-popover.c @@ -642,6 +642,31 @@ on_join_meeting_cb (GcalMeetingRow *meeting_row, g_object_ref (self)); } +static void +on_map_button_clicked_cb (GtkButton *action_button, + GcalEventPopover *self) +{ + g_autoptr (GtkUriLauncher) uri_launcher = NULL; + g_autofree gchar *location = NULL; + g_autofree gchar *uri = NULL; + GtkWindow *window; + + window = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))); + g_assert (window != NULL); + + location = g_strdup (gcal_event_get_location (self->event)); + g_strstrip (location); + + uri = g_strconcat ("maps:q=", location, NULL); + g_assert (g_uri_is_valid (uri, G_URI_FLAGS_NONE, NULL)); + uri_launcher = gtk_uri_launcher_new (uri); + gtk_uri_launcher_launch (uri_launcher, + window, + NULL, + on_uri_launched_cb, + g_object_ref (self)); +} + static void on_time_format_changed_cb (GcalEventPopover *self) { @@ -771,6 +796,7 @@ gcal_event_popover_class_init (GcalEventPopoverClass *klass) gtk_widget_class_bind_template_callback (widget_class, on_action_button_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, on_ics_export_button_clicked_cb); + gtk_widget_class_bind_template_callback (widget_class, on_map_button_clicked_cb); } static void diff --git a/src/gui/icons/icons.gresource.xml b/src/gui/icons/icons.gresource.xml index 63a968c1..fa6a3770 100644 --- a/src/gui/icons/icons.gresource.xml +++ b/src/gui/icons/icons.gresource.xml @@ -16,5 +16,6 @@ info-outline-symbolic.svg loupe-large-symbolic.svg share-symbolic.svg + map-symbolic.svg diff --git a/src/gui/icons/map-symbolic.svg b/src/gui/icons/map-symbolic.svg new file mode 100644 index 00000000..53fee3ee --- /dev/null +++ b/src/gui/icons/map-symbolic.svg @@ -0,0 +1,2 @@ + +