aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/datetime-prefs-locations.c24
-rw-r--r--src/datetime-prefs.c52
2 files changed, 70 insertions, 6 deletions
diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c
index 2862022..9c23a40 100644
--- a/src/datetime-prefs-locations.c
+++ b/src/datetime-prefs-locations.c
@@ -154,6 +154,27 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model,
return FALSE; // Do normal action too
}
+static gboolean
+query_tooltip (GtkTreeView * tree, gint x, gint y, gboolean keyboard_mode,
+ GtkTooltip * tooltip, GtkCellRenderer * cell)
+{
+ GtkTreeModel * model;
+ GtkTreeIter iter;
+ if (!gtk_tree_view_get_tooltip_context (tree, &x, &y, keyboard_mode,
+ &model, NULL, &iter))
+ return FALSE;
+
+ const gchar * icon;
+ gtk_tree_model_get (model, &iter, COL_ICON, &icon, -1);
+ if (icon == NULL)
+ return FALSE;
+
+ GtkTreeViewColumn * col = gtk_tree_view_get_column (tree, 0);
+ gtk_tree_view_set_tooltip_cell (tree, tooltip, NULL, col, cell);
+ gtk_tooltip_set_text (tooltip, _("You need to complete this location for it to appear in the menu."));
+ return TRUE;
+}
+
static void
handle_edit_started (GtkCellRendererText * renderer, GtkCellEditable * editable,
gchar * path, TimezoneCompletion * completion)
@@ -371,6 +392,9 @@ datetime_setup_locations_dialog (CcTimezoneMap * map)
gtk_tree_view_column_pack_start (loc_col, cell, FALSE);
gtk_tree_view_column_add_attribute (loc_col, cell, "icon-name", COL_ICON);
+ gtk_widget_set_has_tooltip (tree, TRUE);
+ g_signal_connect (tree, "query-tooltip", G_CALLBACK (query_tooltip), cell);
+
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
_("Time"), cell,
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
@@ -580,6 +597,28 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model,
}
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)
{
switch (event->keyval) {
@@ -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"),