[epiphany] Fill the history window asynchronously when resorted.



commit b3f380d41c779643216ac805f6e089cb97802ec6
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Feb 28 16:49:42 2014 +0200

    Fill the history window asynchronously when resorted.
    
    https://bugzilla.gnome.org/review?bug=699519
    
    In case the history window contents are resorted, to avoid freezing
    the user interface, do the following:
    * register a source to process the url list received from the service
    one url at a time, by adding it to the model, and freeing the url
    * in case it is finished or another sort is done, remove the source,
    and free the list it was processing
    * as clearing the liststore while it is set to a treeview emits the
    row deleted signal for each row, the liststore is set to null before
    clearing, it is cleared, and then set again for the treeview
    * as setting the model again resets the sort column and indicator
    on the treeview, those attributes must be set again.

 src/ephy-history-window.c |   64 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 54 insertions(+), 10 deletions(-)
---
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index 9091d5d..ef5d863 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -59,6 +59,9 @@ struct _EphyHistoryWindowPrivate
        GtkWidget *copy_location_menuitem;
        GtkWidget *treeview_popup_menu;
 
+       GList *urls;
+       guint sorter_source;
+
        char *search_text;
 
        gboolean  sort_ascending;
@@ -84,22 +87,32 @@ typedef enum
        COLUMN_LOCATION
 } EphyHistoryWindowColumns;
 
-static void
-add_urls (GtkListStore *store,
-         GList *urls)
+static gboolean
+add_urls_source (EphyHistoryWindow *self)
 {
+       GtkListStore *store = GTK_LIST_STORE (self->priv->liststore);
        EphyHistoryURL *url;
-       GList *iter;
+       GList *element = self->priv->urls;
 
-       for (iter = urls; iter != NULL; iter = iter->next) {
-               url = (EphyHistoryURL *)iter->data;
+       if (element) {
+               url = element->data;
                gtk_list_store_insert_with_values (store,
                                                   NULL, G_MAXINT,
                                                   COLUMN_DATE, url->last_visit_time,
                                                   COLUMN_NAME, url->title,
                                                   COLUMN_LOCATION, url->url,
                                                   -1);
+               self->priv->urls = g_list_remove_link (self->priv->urls, element);
+               ephy_history_url_free (url);
+               g_list_free (element);
+       }
+
+       if (self->priv->urls == NULL)
+       {
+               self->priv->sorter_source = 0;
+               return G_SOURCE_REMOVE;
        }
+       return G_SOURCE_CONTINUE;
 }
 
 static void
@@ -109,15 +122,32 @@ on_find_urls_cb (gpointer service,
                 gpointer user_data)
 {
        EphyHistoryWindow *self = EPHY_HISTORY_WINDOW (user_data);
-       GList *urls;
+       GtkTreeViewColumn *column;
 
        if (success != TRUE)
                return;
 
-       urls = (GList *)result_data;
+       if (self->priv->sorter_source != 0)
+       {
+               g_source_remove (self->priv->sorter_source);
+               self->priv->sorter_source = 0;
+       }
+
+       if (self->priv->urls != NULL)
+               g_list_free_full (self->priv->urls, (GDestroyNotify)ephy_history_url_free);
+
+       self->priv->urls = (GList *)result_data;
+
+       gtk_tree_view_set_model (GTK_TREE_VIEW (self->priv->treeview), NULL);
        gtk_list_store_clear (GTK_LIST_STORE (self->priv->liststore));
-       add_urls (GTK_LIST_STORE (self->priv->liststore), urls);
-       g_list_free_full (urls, (GDestroyNotify)ephy_history_url_free);
+       gtk_tree_view_set_model (GTK_TREE_VIEW (self->priv->treeview), GTK_TREE_MODEL 
(self->priv->liststore));
+
+       column = gtk_tree_view_get_column (GTK_TREE_VIEW (self->priv->treeview), self->priv->sort_column);
+       gtk_tree_view_column_set_sort_order (column, self->priv->sort_ascending ? GTK_SORT_ASCENDING : 
GTK_SORT_DESCENDING);
+       gtk_tree_view_column_set_sort_indicator (column, TRUE);
+
+       self->priv->sorter_source = g_idle_add ((GSourceFunc)add_urls_source, self);
+
 }
 
 static GList *
@@ -627,6 +657,18 @@ ephy_history_window_dispose (GObject *object)
                                                      self);
        g_clear_object (&self->priv->history_service);
 
+       if (self->priv->sorter_source != 0)
+       {
+               g_source_remove (self->priv->sorter_source);
+               self->priv->sorter_source = 0;
+       }
+
+       if (self->priv->urls != NULL)
+       {
+               g_list_free_full (self->priv->urls, (GDestroyNotify)ephy_history_url_free);
+               self->priv->urls = NULL;
+       }
+
        G_OBJECT_CLASS (ephy_history_window_parent_class)->dispose (object);
 }
 
@@ -779,8 +821,10 @@ ephy_history_window_init (EphyHistoryWindow *self)
 
        self->priv->cancellable = g_cancellable_new ();
 
+       self->priv->urls = NULL;
        self->priv->sort_ascending = FALSE;
        self->priv->sort_column = COLUMN_DATE;
+       self->priv->sorter_source = 0;
 
        ephy_gui_ensure_window_group (GTK_WINDOW (self));
 


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