[epiphany] ephy-hosts-view: ensure "all hosts" is selected by default



commit 161c78698fcce7a6cad9a562691dd51ec087265c
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Wed Mar 7 18:57:24 2012 +0200

    ephy-hosts-view: ensure "all hosts" is selected by default
    
    If no host can be selected, always select the "all hosts" row.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671575

 lib/widgets/ephy-hosts-view.c |   42 +++++++++++++++++++++++++++-------------
 src/ephy-history-window.c     |    8 ++----
 2 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/lib/widgets/ephy-hosts-view.c b/lib/widgets/ephy-hosts-view.c
index b6c6e75..e59d89c 100644
--- a/lib/widgets/ephy-hosts-view.c
+++ b/lib/widgets/ephy-hosts-view.c
@@ -53,6 +53,16 @@ ephy_hosts_view_new (void)
   return g_object_new (EPHY_TYPE_HOSTS_VIEW, NULL);
 }
 
+/**
+ * ephy_hosts_view_select_host:
+ * @view: A #EphyHostView
+ * @host: a @host or %NULL to select the first item
+ *
+ * Selects the row pointed by @host or, when not found or row is
+ * %NULL, select the first item ("All sites").
+ *
+ * Returns: whether @host was found.
+ **/
 gboolean
 ephy_hosts_view_select_host (EphyHostsView *view,
                              EphyHistoryHost *host)
@@ -63,25 +73,29 @@ ephy_hosts_view_select_host (EphyHostsView *view,
   gboolean found = FALSE;
 
   g_return_val_if_fail (EPHY_IS_HOSTS_VIEW (view), FALSE);
-  g_return_val_if_fail (host != NULL, FALSE);
 
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
 
   gtk_tree_model_get_iter_first (model, &iter);
-  do {
-    gtk_tree_model_get (model, &iter,
-                        EPHY_HOSTS_STORE_COLUMN_ID, &id,
-                        -1);
-    if (id == host->id) {
-      found = TRUE;
-      break;
-    }
-  } while (gtk_tree_model_iter_next (model, &iter));
-
-  if (found) {
-    gtk_tree_selection_select_iter (
-      gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), &iter);
+
+  if (host != NULL) {
+    do {
+      gtk_tree_model_get (model, &iter,
+                          EPHY_HOSTS_STORE_COLUMN_ID, &id,
+                          -1);
+      if (id == host->id) {
+        found = TRUE;
+        break;
+      }
+    } while (gtk_tree_model_iter_next (model, &iter));
   }
 
+  if (host == NULL || found == FALSE) {
+    gtk_tree_model_get_iter_first (model, &iter);
+  }
+
+  gtk_tree_selection_select_iter (
+    gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), &iter);
+
   return found;
 }
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index b403622..f8369ba 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -1039,11 +1039,9 @@ on_get_hosts_cb (gpointer service,
 	selected_host = get_selected_host (window);
 	ephy_hosts_store_clear (EPHY_HOSTS_STORE (window->priv->hosts_store));
 	ephy_hosts_store_add_hosts (window->priv->hosts_store, hosts);
-	if (selected_host) {
-		ephy_hosts_view_select_host (EPHY_HOSTS_VIEW (window->priv->hosts_view),
-					     selected_host);
-		ephy_history_host_free (selected_host);
-	}
+	ephy_hosts_view_select_host (EPHY_HOSTS_VIEW (window->priv->hosts_view),
+				     selected_host);
+	ephy_history_host_free (selected_host);
 out:
 	g_list_free_full (hosts, (GDestroyNotify)ephy_history_host_free);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]