[gnome-initial-setup] timezone: only cancel GeoClue after user input



commit 531c9667636f93fcf1406e1289aa801d82b01510
Author: Will Thompson <wjt endlessm com>
Date:   Mon Nov 12 21:23:14 2018 +0000

    timezone: only cancel GeoClue after user input
    
    Previously, this page would cancel the ongoing GeoClue request as soon
    as the page is displayed. But if the location comes in after the page
    has already been displayed but before the user has interacted with the
    page in any way, it seems a shame not to make use of it. Defer
    cancelling the request unless/until the user types in the search box,
    clicks on the map, or advances to the next page.

 .../pages/timezone/gis-timezone-page.c             | 43 +++++++++++++++++++---
 1 file changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/gnome-initial-setup/pages/timezone/gis-timezone-page.c 
b/gnome-initial-setup/pages/timezone/gis-timezone-page.c
index e1b8aaf..7a465ca 100644
--- a/gnome-initial-setup/pages/timezone/gis-timezone-page.c
+++ b/gnome-initial-setup/pages/timezone/gis-timezone-page.c
@@ -55,6 +55,8 @@
 #define CLOCK_SCHEMA "org.gnome.desktop.interface"
 #define CLOCK_FORMAT_KEY "clock-format"
 
+static void stop_geolocation (GisTimezonePage *page);
+
 struct _GisTimezonePagePrivate
 {
   GtkWidget *map;
@@ -64,12 +66,15 @@ struct _GisTimezonePagePrivate
   GCancellable *geoclue_cancellable;
   GClueClient *geoclue_client;
   GClueSimple *geoclue_simple;
+  gboolean in_geoclue_callback;
   GWeatherLocation *current_location;
   Timedate1 *dtm;
 
   GnomeWallClock *clock;
   GDesktopClockFormat clock_format;
   gboolean in_search;
+
+  gulong search_entry_text_changed_id;
 };
 typedef struct _GisTimezonePagePrivate GisTimezonePagePrivate;
 
@@ -132,6 +137,10 @@ set_location (GisTimezonePage  *page,
       tzid = gweather_timezone_get_tzid (zone);
 
       cc_timezone_map_set_timezone (CC_TIMEZONE_MAP (priv->map), tzid);
+
+      /* If this location is manually set, stop waiting for geolocation. */
+      if (!priv->in_geoclue_callback)
+        stop_geolocation (page);
     }
 }
 
@@ -141,6 +150,7 @@ on_location_notify (GClueSimple *simple,
                     gpointer     user_data)
 {
   GisTimezonePage *page = user_data;
+  GisTimezonePagePrivate *priv = gis_timezone_page_get_instance_private (page);
   GClueLocation *location;
   gdouble latitude, longitude;
   GWeatherLocation *glocation = NULL;
@@ -151,7 +161,9 @@ on_location_notify (GClueSimple *simple,
   longitude = gclue_location_get_longitude (location);
 
   glocation = gweather_location_find_nearest_city (NULL, latitude, longitude);
+  priv->in_geoclue_callback = TRUE;
   set_location (page, glocation);
+  priv->in_geoclue_callback = FALSE;
   gweather_location_unref (glocation);
 }
 
@@ -194,6 +206,19 @@ get_location_from_geoclue_async (GisTimezonePage *page)
                     page);
 }
 
+static void
+entry_text_changed (GtkEditable *editable,
+                    gpointer     user_data)
+{
+  GisTimezonePage *page = GIS_TIMEZONE_PAGE (user_data);
+  GisTimezonePagePrivate *priv = gis_timezone_page_get_instance_private (page);
+
+  stop_geolocation (GIS_TIMEZONE_PAGE (user_data));
+  g_signal_handler_disconnect (priv->search_entry,
+                               priv->search_entry_text_changed_id);
+  priv->search_entry_text_changed_id = 0;
+}
+
 static void
 entry_location_changed (GObject *object, GParamSpec *param, GisTimezonePage *page)
 {
@@ -396,6 +421,9 @@ gis_timezone_page_constructed (GObject *object)
   set_location (page, NULL);
   get_location_from_geoclue_async (page);
 
+  priv->search_entry_text_changed_id =
+      g_signal_connect (priv->search_entry, "changed",
+                        G_CALLBACK (entry_text_changed), page);
   g_signal_connect (priv->search_entry, "notify::location",
                     G_CALLBACK (entry_location_changed), page);
   g_signal_connect (priv->search_entry, "map",
@@ -426,13 +454,16 @@ gis_timezone_page_locale_changed (GisPage *page)
   gis_page_set_title (GIS_PAGE (page), _("Time Zone"));
 }
 
-static void
-gis_timezone_page_shown (GisPage *page)
+static gboolean
+gis_timezone_page_apply (GisPage      *page,
+                         GCancellable *cancellable)
 {
-  GisTimezonePage *tz_page = GIS_TIMEZONE_PAGE (page);
+  /* Once the user accepts the location, it would be unkind to change it if
+   * GeoClue suddenly tells us we're somewhere else.
+   */
+  stop_geolocation (GIS_TIMEZONE_PAGE (page));
 
-  /* Stop timezone geolocation if it hasn't finished by the time we get here */
-  stop_geolocation (tz_page);
+  return FALSE;
 }
 
 static void
@@ -449,7 +480,7 @@ gis_timezone_page_class_init (GisTimezonePageClass *klass)
 
   page_class->page_id = PAGE_ID;
   page_class->locale_changed = gis_timezone_page_locale_changed;
-  page_class->shown = gis_timezone_page_shown;
+  page_class->apply = gis_timezone_page_apply;
   object_class->constructed = gis_timezone_page_constructed;
   object_class->dispose = gis_timezone_page_dispose;
 }


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