← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~mterry/indicator-datetime/remember-zone-name into lp:indicator-datetime

 

Michael Terry has proposed merging lp:~mterry/indicator-datetime/remember-zone-name into lp:indicator-datetime.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)
Related bugs:
  Bug #729029 in Indicator Date and Time: "Cannot change main location"
  https://bugs.launchpad.net/indicator-datetime/+bug/729029

For more details, see:
https://code.launchpad.net/~mterry/indicator-datetime/remember-zone-name/+merge/55425
-- 
https://code.launchpad.net/~mterry/indicator-datetime/remember-zone-name/+merge/55425
Your team ayatana-commits is subscribed to branch lp:indicator-datetime.
=== modified file 'data/com.canonical.indicator.datetime.gschema.xml'
--- data/com.canonical.indicator.datetime.gschema.xml	2011-03-03 18:51:26 +0000
+++ data/com.canonical.indicator.datetime.gschema.xml	2011-03-29 20:24:32 +0000
@@ -100,5 +100,12 @@
 			  indicator-datetime menu.
 			</description>
 		</key>
+		<key name="timezone-name" type="s">
+			<default>''</default>
+			<summary>The name of the current timezone</summary>
+			<description>
+			  Some timezones can be known by many different cities or names.  This setting describes how the current zone prefers to be named.  Format is "TIMEZONE NAME" (e.g. "America/New_York Boston" to name the New_York zone Boston).
+			</description>
+		</key>
 	</schema>
 </schemalist>

=== modified file 'src/datetime-prefs.c'
--- src/datetime-prefs.c	2011-03-29 19:28:49 +0000
+++ src/datetime-prefs.c	2011-03-29 20:24:32 +0000
@@ -184,10 +184,30 @@
 static void
 sync_entry (const gchar * location)
 {
-  gchar * name;
-  split_settings_location (location, NULL, &name);
-  gtk_entry_set_text (GTK_ENTRY (tz_entry), name);
-  g_free (name);
+  gchar * new_zone, * new_name;
+  gchar * old_zone, * old_name;
+
+  split_settings_location (location, &new_zone, &new_name);
+
+  GSettings * conf = g_settings_new (SETTINGS_INTERFACE);
+  gchar * tz_name = g_settings_get_string (conf, SETTINGS_TIMEZONE_NAME_S);
+  split_settings_location (tz_name, &old_zone, &old_name);
+  g_free (tz_name);
+  g_object_unref (conf);
+
+  // new_name is always just a sanitized version of a timezone.
+  // old_name is potentially a saved "pretty" version of a timezone name from
+  // geonames.  So we prefer to use it if available and the zones match.
+
+  if (g_strcmp0 (old_zone, new_zone) == 0)
+    gtk_entry_set_text (GTK_ENTRY (tz_entry), old_name);
+  else
+    gtk_entry_set_text (GTK_ENTRY (tz_entry), new_name);
+
+  g_free (new_zone);
+  g_free (old_zone);
+  g_free (new_name);
+  g_free (old_name);
 }
 
 static void
@@ -521,36 +541,40 @@
 timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model,
                    GtkTreeIter * iter, gpointer user_data)
 {
-  GValue value = {0};
-  const gchar * strval;
-
-  gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_ZONE, &value);
-  strval = g_value_get_string (&value);
-
-  if (strval != NULL && strval[0] != 0) {
-    cc_timezone_map_set_timezone (tzmap, strval);
-  }
-  else {
-    GValue lon_value = {0}, lat_value = {0};
+  const gchar * name, * zone;
+
+  gtk_tree_model_get (model, iter,
+                      TIMEZONE_COMPLETION_NAME, &name,
+                      TIMEZONE_COMPLETION_ZONE, &zone,
+                      -1);
+
+  if (zone == NULL || zone[0] == 0) {
     const gchar * strlon, * strlat;
     gdouble lon = 0.0, lat = 0.0;
 
-    gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LONGITUDE, &lon_value);
-    strlon = g_value_get_string (&lon_value);
+    gtk_tree_model_get (model, iter,
+                        TIMEZONE_COMPLETION_LONGITUDE, &strlon,
+                        TIMEZONE_COMPLETION_LATITUDE, &strlat,
+                        -1);
+
     if (strlon != NULL && strlon[0] != 0) {
       lon = strtod(strlon, NULL);
     }
 
-    gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LATITUDE, &lat_value);
-    strlat = g_value_get_string (&lat_value);
     if (strlat != NULL && strlat[0] != 0) {
       lat = strtod(strlat, NULL);
     }
 
-    cc_timezone_map_set_coords (tzmap, lon, lat);
+    zone = cc_timezone_map_get_timezone_at_coords (tzmap, lon, lat);
   }
 
-  g_value_unset (&value);
+  GSettings * conf = g_settings_new (SETTINGS_INTERFACE);
+  gchar * tz_name = g_strdup_printf ("%s %s", zone, name);
+  g_settings_set_string (conf, SETTINGS_TIMEZONE_NAME_S, tz_name);
+  g_free (tz_name);
+  g_object_unref (conf);
+
+  cc_timezone_map_set_timezone (tzmap, zone);
 
   return FALSE; // Do normal action too
 }

=== modified file 'src/settings-shared.h'
--- src/settings-shared.h	2011-03-21 18:17:44 +0000
+++ src/settings-shared.h	2011-03-29 20:24:32 +0000
@@ -34,6 +34,7 @@
 #define SETTINGS_SHOW_EVENTS_S          "show-events"
 #define SETTINGS_SHOW_LOCATIONS_S       "show-locations"
 #define SETTINGS_LOCATIONS_S            "locations"
+#define SETTINGS_TIMEZONE_NAME_S        "timezone-name"
 
 enum {
 	SETTINGS_TIME_LOCALE = 0,


Follow ups