[gthumb] folder tree: update the locations to monitor after a timeout
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] folder tree: update the locations to monitor after a timeout
- Date: Mon, 31 Dec 2012 14:30:10 +0000 (UTC)
commit 27cf36cf6142a1ff3ef74a4d634a66fa5e4ddbae
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Dec 31 14:56:40 2012 +0100
folder tree: update the locations to monitor after a timeout
this reduces computation during a rapid series of node expansions and
collapses.
gthumb/gth-folder-tree.c | 39 ++++++++++++++++++++++++++++++++-------
1 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/gthumb/gth-folder-tree.c b/gthumb/gth-folder-tree.c
index bd1b72f..e418d12 100644
--- a/gthumb/gth-folder-tree.c
+++ b/gthumb/gth-folder-tree.c
@@ -36,6 +36,7 @@
#define EMPTY_URI "..."
#define LOADING_URI "."
#define PARENT_URI ".."
+#define UPDATE_MONITORED_LOCATIONS_DELAY 500
typedef enum {
@@ -74,6 +75,7 @@ enum {
typedef struct {
GHashTable *locations;
GList *sources;
+ guint update_id;
} MonitorData;
@@ -126,6 +128,10 @@ gth_folder_tree_finalize (GObject *object)
gtk_target_list_unref (folder_tree->priv->drag_target_list);
folder_tree->priv->drag_target_list = NULL;
}
+ if (folder_tree->priv->monitor.update_id != 0) {
+ g_source_remove (folder_tree->priv->monitor.update_id);
+ folder_tree->priv->monitor.update_id = 0;
+ }
g_hash_table_unref (folder_tree->priv->entry_points);
remove_all_locations_from_the_monitor (folder_tree);
g_hash_table_unref (folder_tree->priv->monitor.locations);
@@ -484,12 +490,19 @@ add_to_open_locations (GtkTreeView *tree_view,
}
-static void
-update_monitored_locations (GthFolderTree *folder_tree)
+static gboolean
+update_monitored_locations (gpointer user_data)
{
- GHashTable *open_locations;
- GList *locations;
- GList *scan;
+ GthFolderTree *folder_tree = user_data;
+ GHashTable *open_locations;
+ GList *locations;
+ GList *locations_to_remove;
+ GList *scan;
+
+ if (folder_tree->priv->monitor.update_id != 0) {
+ g_source_remove (folder_tree->priv->monitor.update_id);
+ folder_tree->priv->monitor.update_id = 0;
+ }
open_locations = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
gtk_tree_view_map_expanded_rows (GTK_TREE_VIEW (folder_tree),
@@ -541,6 +554,17 @@ update_monitored_locations (GthFolderTree *folder_tree)
g_list_free (locations);
g_hash_table_unref (open_locations);
+
+ return FALSE;
+}
+
+
+static void
+queue_update_monitored_locations (GthFolderTree *folder_tree)
+{
+ if (folder_tree->priv->monitor.update_id != 0)
+ g_source_remove (folder_tree->priv->monitor.update_id);
+ folder_tree->priv->monitor.update_id = g_timeout_add (UPDATE_MONITORED_LOCATIONS_DELAY, update_monitored_locations, folder_tree);
}
@@ -565,7 +589,7 @@ row_expanded_cb (GtkTreeView *tree_view,
if ((entry_type == ENTRY_TYPE_FILE) && ! loaded)
g_signal_emit (folder_tree, gth_folder_tree_signals[LIST_CHILDREN], 0, file_data->file);
- update_monitored_locations (folder_tree);
+ queue_update_monitored_locations (folder_tree);
_g_object_unref (file_data);
@@ -579,7 +603,7 @@ row_collapsed_cb (GtkTreeView *tree_view,
GtkTreePath *path,
gpointer user_data)
{
- update_monitored_locations (GTH_FOLDER_TREE (user_data));
+ queue_update_monitored_locations (GTH_FOLDER_TREE (user_data));
return FALSE;
}
@@ -1233,6 +1257,7 @@ gth_folder_tree_init (GthFolderTree *folder_tree)
folder_tree->priv->recalc_entry_points = FALSE;
folder_tree->priv->monitor.locations = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
folder_tree->priv->monitor.sources = NULL;
+ folder_tree->priv->monitor.update_id = 0;
folder_tree->priv->icon_cache = gth_icon_cache_new (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (folder_tree))),
_gtk_widget_lookup_for_size (GTK_WIDGET (folder_tree), GTK_ICON_SIZE_MENU));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]