← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~mterry/indicator-datetime/more-error-icons into lp:indicator-datetime

 

Michael Terry has proposed merging lp:~mterry/indicator-datetime/more-error-icons into lp:indicator-datetime.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)

For more details, see:
https://code.launchpad.net/~mterry/indicator-datetime/more-error-icons/+merge/55532

More error icon support, including tooltips for the icons.
-- 
https://code.launchpad.net/~mterry/indicator-datetime/more-error-icons/+merge/55532
Your team ayatana-commits is subscribed to branch lp:indicator-datetime.
=== modified file 'src/datetime-prefs-locations.c'
--- src/datetime-prefs-locations.c	2011-03-29 19:53:18 +0000
+++ src/datetime-prefs-locations.c	2011-03-30 13:13:55 +0000
@@ -154,6 +154,27 @@
   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 @@
   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,

=== modified file 'src/datetime-prefs.c'
--- src/datetime-prefs.c	2011-03-29 20:22:14 +0000
+++ src/datetime-prefs.c	2011-03-30 13:13:55 +0000
@@ -181,11 +181,12 @@
   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 @@
   // 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 @@
 }
 
 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 @@
   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"),


Follow ups