From 3f00f0b2b0790d6d8429d6d6812fcb78dcad9d7b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 28 Mar 2011 15:21:46 -0400 Subject: Don't allow enter presses to leave non-timezone content in the model --- src/datetime-prefs.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/datetime-prefs.c') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index fbc88f2..dfb94fe 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -604,8 +604,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); -- cgit v1.2.3 From 18ea5194b357dbd14dd724eb32013af8031a50be Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 11:17:52 -0400 Subject: treat locations dialog not as a modal dialog, but rather one that can be dismissed by interacting with the main dialog --- src/datetime-prefs.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/datetime-prefs.c') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index fbc88f2..5a6fd91 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 * @@ -494,11 +495,26 @@ setup_time_spinners (GtkWidget * time, GtkWidget * date) update_spinners (); } +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 -- cgit v1.2.3 From 095bf2692ce36c1197349a629dde3c714c845384 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 17:22:14 -0300 Subject: remember user's preferred location name for main timezone --- src/datetime-prefs.c | 62 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'src/datetime-prefs.c') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 4213ea9..b1335ca 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -184,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 @@ -521,36 +541,40 @@ 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 } -- cgit v1.2.3 From 642c67ed942d7ce49ab48303ba611b7f21d7e1d5 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 30 Mar 2011 09:12:39 -0400 Subject: add error icon to main timezone entry --- src/datetime-prefs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'src/datetime-prefs.c') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index b1335ca..4a32fd6 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -181,11 +181,12 @@ ntp_query_answered (GObject *object, GAsyncResult *res, gpointer user_data) g_variant_unref (answers); } -static void -sync_entry (const gchar * location) +static gchar * +get_zone_name (const gchar * location) { gchar * new_zone, * new_name; gchar * old_zone, * old_name; + gchar * rv; split_settings_location (location, &new_zone, &new_name); @@ -199,15 +200,31 @@ sync_entry (const gchar * location) // 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); + if (g_strcmp0 (old_zone, new_zone) == 0) { + rv = old_name; + old_name = NULL; + } + else { + rv = new_name; + new_name = NULL; + } g_free (new_zone); g_free (old_zone); g_free (new_name); g_free (old_name); + + return rv; +} + +static void +sync_entry (const gchar * location) +{ + gchar * name = get_zone_name (location); + gtk_entry_set_text (GTK_ENTRY (tz_entry), name); + g_free (name); + + gtk_entry_set_icon_from_stock (GTK_ENTRY (tz_entry), GTK_ENTRY_ICON_SECONDARY, NULL); } static void @@ -579,6 +596,28 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, return FALSE; // Do normal action too } +static gboolean +entry_focus_out (GtkEntry * entry, GdkEventFocus * event) +{ + // If the name left in the entry doesn't match the current timezone name, + // show an error icon. It's always an error for the user to manually type in + // a timezone. + TzLocation * location = cc_timezone_map_get_location (tzmap); + if (location == NULL) + return FALSE; + + gchar * name = get_zone_name (location->zone); + gboolean correct = (g_strcmp0 (gtk_entry_get_text (entry), name) == 0); + g_free (name); + + gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, + correct ? NULL : GTK_STOCK_DIALOG_ERROR); + gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, + _("You need to choose a location to change the time zone.")); + gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE); + return FALSE; +} + static gboolean key_pressed (GtkWidget * widget, GdkEventKey * event, gpointer user_data) { @@ -646,6 +685,7 @@ create_dialog (void) TimezoneCompletion * completion = timezone_completion_new (); timezone_completion_watch_entry (completion, GTK_ENTRY (WIG ("timezoneEntry"))); g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), NULL); + g_signal_connect (WIG ("timezoneEntry"), "focus-out-event", G_CALLBACK (entry_focus_out), NULL); /* Set up settings bindings */ g_settings_bind (conf, SETTINGS_SHOW_CLOCK_S, WIG ("showClockCheck"), -- cgit v1.2.3