aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-prefs.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-03-29 20:52:37 -0500
committerTed Gould <ted@gould.cx>2011-03-29 20:52:37 -0500
commitc5309d7ec6d6de6683569d88bd17a418a11dbfdf (patch)
treed34e3eab25f3e03bf681e7775d6316abe5a13e86 /src/datetime-prefs.c
parent7aa23563b3667b313f9f19e3bbace6e794703526 (diff)
parentd455a0cfb2d3f1fd9e244c5db636ad766dcc287d (diff)
downloadayatana-indicator-datetime-c5309d7ec6d6de6683569d88bd17a418a11dbfdf.tar.gz
ayatana-indicator-datetime-c5309d7ec6d6de6683569d88bd17a418a11dbfdf.tar.bz2
ayatana-indicator-datetime-c5309d7ec6d6de6683569d88bd17a418a11dbfdf.zip
* Upstream Merge
* indicator-datetime-preferences crashed with SIGSEGV in g_utf8_normalize() (LP: #727089) * Uninstalling Evolution removes calendar from clock applet (LP: #691953) * clock doesn't update on timezone change (LP: #735445) * Cannot change main location (LP: #729029) * indicator-datetime-preferences crashed with SIGSEGV in g_simple_async_result_complete() (LP: #734951) * Time zone map looks identical when sensitive vs. insensitive (LP: #740846) * "Locations" window behaves like a modal dialog (LP: #740924) * Added location for clock menu isn't used or remembered (LP: #740930) * Time not displayed for added location in "Locations" window (LP: #740931) * "UTC" location can be removed but not re-added (LP: #740938) * "Locations" window bottom bar is missing a border (LP: #740941) * Add and Remove buttons in "Locations" window have unnecessary tooltips (LP: #740944) * No separator between "Add Event" and locations (LP: #740971) * indicator-datetime-preferences crashed with SIGSEGV in g_atomic_int_exchange_and_add() (LP: #740978) * inicator-datetime dosen't show corretly the time when changing from 24 hours format to 12 hours (LP: #743394)
Diffstat (limited to 'src/datetime-prefs.c')
-rw-r--r--src/datetime-prefs.c84
1 files changed, 61 insertions, 23 deletions
diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c
index fbc88f2..b1335ca 100644
--- a/src/datetime-prefs.c
+++ b/src/datetime-prefs.c
@@ -53,6 +53,7 @@ GtkWidget * date_spin = NULL;
guint save_time_id = 0;
gboolean user_edited_time = FALSE;
gboolean changing_time = FALSE;
+GtkWidget * loc_dlg = NULL;
/* Turns the boolean property into a string gsettings */
static GVariant *
@@ -183,10 +184,30 @@ ntp_query_answered (GObject *object, GAsyncResult *res, gpointer user_data)
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
@@ -495,46 +516,65 @@ setup_time_spinners (GtkWidget * time, GtkWidget * date)
}
static void
+hide_locations ()
+{
+ if (loc_dlg != NULL)
+ gtk_widget_destroy (loc_dlg);
+}
+
+static void
show_locations (GtkWidget * button, GtkWidget * dlg)
{
- GtkWidget * locationsDlg = datetime_setup_locations_dialog (GTK_WINDOW (dlg), tzmap);
- gtk_widget_show_all (locationsDlg);
+ if (loc_dlg == NULL) {
+ loc_dlg = datetime_setup_locations_dialog (tzmap);
+ gtk_window_set_transient_for (GTK_WINDOW (loc_dlg), GTK_WINDOW (dlg));
+ g_signal_connect (loc_dlg, "destroy", G_CALLBACK (gtk_widget_destroyed), &loc_dlg);
+ g_signal_connect (dlg, "focus-in-event", G_CALLBACK (hide_locations), NULL);
+ gtk_widget_show_all (loc_dlg);
+ }
+ else {
+ gtk_window_present_with_time (GTK_WINDOW (loc_dlg), gtk_get_current_event_time ());
+ }
}
static gboolean
timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model,
GtkTreeIter * iter, gpointer user_data)
{
- GValue value = {0};
- const gchar * strval;
+ const gchar * name, * zone;
- gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_ZONE, &value);
- strval = g_value_get_string (&value);
+ gtk_tree_model_get (model, iter,
+ TIMEZONE_COMPLETION_NAME, &name,
+ TIMEZONE_COMPLETION_ZONE, &zone,
+ -1);
- if (strval != NULL && strval[0] != 0) {
- cc_timezone_map_set_timezone (tzmap, strval);
- }
- else {
- GValue lon_value = {0}, lat_value = {0};
+ 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
}
@@ -604,8 +644,6 @@ create_dialog (void)
/* And completion entry */
TimezoneCompletion * completion = timezone_completion_new ();
- gtk_entry_set_completion (GTK_ENTRY (WIG ("timezoneEntry")),
- GTK_ENTRY_COMPLETION (completion));
timezone_completion_watch_entry (completion, GTK_ENTRY (WIG ("timezoneEntry")));
g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), NULL);