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

Proposed by Michael Terry
Status: Merged
Merged at revision: 93
Proposed branch: lp:~mterry/indicator-datetime/remember-zone-name
Merge into: lp:indicator-datetime/0.3
Diff against target: 125 lines (+53/-21)
3 files modified
data/com.canonical.indicator.datetime.gschema.xml (+7/-0)
src/datetime-prefs.c (+45/-21)
src/settings-shared.h (+1/-0)
To merge this branch: bzr merge lp:~mterry/indicator-datetime/remember-zone-name
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+55425@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/com.canonical.indicator.datetime.gschema.xml'
2--- data/com.canonical.indicator.datetime.gschema.xml 2011-03-03 18:51:26 +0000
3+++ data/com.canonical.indicator.datetime.gschema.xml 2011-03-29 20:25:22 +0000
4@@ -100,5 +100,12 @@
5 indicator-datetime menu.
6 </description>
7 </key>
8+ <key name="timezone-name" type="s">
9+ <default>''</default>
10+ <summary>The name of the current timezone</summary>
11+ <description>
12+ 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).
13+ </description>
14+ </key>
15 </schema>
16 </schemalist>
17
18=== modified file 'src/datetime-prefs.c'
19--- src/datetime-prefs.c 2011-03-29 19:28:49 +0000
20+++ src/datetime-prefs.c 2011-03-29 20:25:22 +0000
21@@ -184,10 +184,30 @@
22 static void
23 sync_entry (const gchar * location)
24 {
25- gchar * name;
26- split_settings_location (location, NULL, &name);
27- gtk_entry_set_text (GTK_ENTRY (tz_entry), name);
28- g_free (name);
29+ gchar * new_zone, * new_name;
30+ gchar * old_zone, * old_name;
31+
32+ split_settings_location (location, &new_zone, &new_name);
33+
34+ GSettings * conf = g_settings_new (SETTINGS_INTERFACE);
35+ gchar * tz_name = g_settings_get_string (conf, SETTINGS_TIMEZONE_NAME_S);
36+ split_settings_location (tz_name, &old_zone, &old_name);
37+ g_free (tz_name);
38+ g_object_unref (conf);
39+
40+ // new_name is always just a sanitized version of a timezone.
41+ // old_name is potentially a saved "pretty" version of a timezone name from
42+ // geonames. So we prefer to use it if available and the zones match.
43+
44+ if (g_strcmp0 (old_zone, new_zone) == 0)
45+ gtk_entry_set_text (GTK_ENTRY (tz_entry), old_name);
46+ else
47+ gtk_entry_set_text (GTK_ENTRY (tz_entry), new_name);
48+
49+ g_free (new_zone);
50+ g_free (old_zone);
51+ g_free (new_name);
52+ g_free (old_name);
53 }
54
55 static void
56@@ -521,36 +541,40 @@
57 timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model,
58 GtkTreeIter * iter, gpointer user_data)
59 {
60- GValue value = {0};
61- const gchar * strval;
62-
63- gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_ZONE, &value);
64- strval = g_value_get_string (&value);
65-
66- if (strval != NULL && strval[0] != 0) {
67- cc_timezone_map_set_timezone (tzmap, strval);
68- }
69- else {
70- GValue lon_value = {0}, lat_value = {0};
71+ const gchar * name, * zone;
72+
73+ gtk_tree_model_get (model, iter,
74+ TIMEZONE_COMPLETION_NAME, &name,
75+ TIMEZONE_COMPLETION_ZONE, &zone,
76+ -1);
77+
78+ if (zone == NULL || zone[0] == 0) {
79 const gchar * strlon, * strlat;
80 gdouble lon = 0.0, lat = 0.0;
81
82- gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LONGITUDE, &lon_value);
83- strlon = g_value_get_string (&lon_value);
84+ gtk_tree_model_get (model, iter,
85+ TIMEZONE_COMPLETION_LONGITUDE, &strlon,
86+ TIMEZONE_COMPLETION_LATITUDE, &strlat,
87+ -1);
88+
89 if (strlon != NULL && strlon[0] != 0) {
90 lon = strtod(strlon, NULL);
91 }
92
93- gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LATITUDE, &lat_value);
94- strlat = g_value_get_string (&lat_value);
95 if (strlat != NULL && strlat[0] != 0) {
96 lat = strtod(strlat, NULL);
97 }
98
99- cc_timezone_map_set_coords (tzmap, lon, lat);
100+ zone = cc_timezone_map_get_timezone_at_coords (tzmap, lon, lat);
101 }
102
103- g_value_unset (&value);
104+ GSettings * conf = g_settings_new (SETTINGS_INTERFACE);
105+ gchar * tz_name = g_strdup_printf ("%s %s", zone, name);
106+ g_settings_set_string (conf, SETTINGS_TIMEZONE_NAME_S, tz_name);
107+ g_free (tz_name);
108+ g_object_unref (conf);
109+
110+ cc_timezone_map_set_timezone (tzmap, zone);
111
112 return FALSE; // Do normal action too
113 }
114
115=== modified file 'src/settings-shared.h'
116--- src/settings-shared.h 2011-03-21 18:17:44 +0000
117+++ src/settings-shared.h 2011-03-29 20:25:22 +0000
118@@ -34,6 +34,7 @@
119 #define SETTINGS_SHOW_EVENTS_S "show-events"
120 #define SETTINGS_SHOW_LOCATIONS_S "show-locations"
121 #define SETTINGS_LOCATIONS_S "locations"
122+#define SETTINGS_TIMEZONE_NAME_S "timezone-name"
123
124 enum {
125 SETTINGS_TIME_LOCALE = 0,

Subscribers

People subscribed via source and target branches