summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2011-06-29 12:22:42 -0500
committerFederico Mena Quintero <federico@gnome.org>2011-06-29 14:06:36 -0500
commita3280339bdc326c6b8180bf9214894a1a94f0767 (patch)
treeb1f007ab13bc38a1644beea54e4be909bce2992a
parentb33827ee8ab72c51aa5e913718be6a97fabcef1e (diff)
downloadgtk+-a3280339bdc326c6b8180bf9214894a1a94f0767.tar.gz
Put recently-used folders in the recently-used list
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
-rw-r--r--gtk/gtkfilechooserdefault.c106
-rw-r--r--gtk/gtkfilechooserutils.c22
-rw-r--r--gtk/gtkfilechooserutils.h2
3 files changed, 62 insertions, 68 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 5d1c1dd0a8..ac7d9d6a3b 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -9057,12 +9057,6 @@ recent_idle_cleanup (gpointer data)
impl->load_recent_id = 0;
- if (load_data->items)
- {
- g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (load_data->items);
- }
-
g_free (load_data);
}
@@ -9092,13 +9086,61 @@ get_recent_files_limit (GtkWidget *widget)
return limit;
}
+/* Populates the file system model with the GtkRecentInfo* items in the provided list; frees the items */
+static void
+populate_model_with_recent_items (GtkFileChooserDefault *impl, GList *items)
+{
+ gint limit;
+ GList *l;
+ int n;
+
+ limit = get_recent_files_limit (GTK_WIDGET (impl));
+
+ n = 0;
+
+ for (l = items; l; l = l->next)
+ {
+ GtkRecentInfo *info = l->data;
+ GFile *file;
+
+ file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
+ _gtk_file_system_model_add_and_query_file (impl->recent_model,
+ file,
+ MODEL_ATTRIBUTES);
+ g_object_unref (file);
+
+ n++;
+ if (limit != -1 && n >= limit)
+ break;
+ }
+}
+
+static void
+populate_model_with_folders (GtkFileChooserDefault *impl, GList *items)
+{
+ GList *folders;
+ GList *l;
+
+ folders = _gtk_file_chooser_extract_recent_folders (items);
+
+ for (l = folders; l; l = l->next)
+ {
+ GFile *folder = l->data;
+
+ _gtk_file_system_model_add_and_query_file (impl->recent_model,
+ folder,
+ MODEL_ATTRIBUTES);
+ }
+
+ g_list_foreach (folders, (GFunc) g_object_unref, NULL);
+ g_list_free (folders);
+}
+
static gboolean
recent_idle_load (gpointer data)
{
RecentLoadData *load_data = data;
GtkFileChooserDefault *impl = load_data->impl;
- GList *walk;
- GFile *file;
if (!impl->recent_manager)
return FALSE;
@@ -9115,53 +9157,21 @@ recent_idle_load (gpointer data)
return TRUE;
}
- /* second iteration: preliminary MRU sorting and clamping */
+ /* second iteration: MRU sorting and clamping, and populating the model */
if (load_data->needs_sorting)
{
- gint limit;
- gint n_items;
-
load_data->items = g_list_sort (load_data->items, recent_sort_mru);
- n_items = g_list_length (load_data->items);
-
- limit = get_recent_files_limit (GTK_WIDGET (impl));
-
- if (limit != -1 && (n_items > limit))
- {
- GList *clamp, *l;
-
- clamp = g_list_nth (load_data->items, limit - 1);
- if (G_LIKELY (clamp))
- {
- l = clamp->next;
- clamp->next = NULL;
-
- g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (l);
- }
- }
-
- load_data->needs_sorting = FALSE;
-
- return TRUE;
- }
- /* finished loading items */
- for (walk = load_data->items; walk; walk = walk->next)
- {
- GtkRecentInfo *info = walk->data;
- file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
+ if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
+ populate_model_with_recent_items (impl, load_data->items);
+ else
+ populate_model_with_folders (impl, load_data->items);
- _gtk_file_system_model_add_and_query_file (impl->recent_model,
- file,
- MODEL_ATTRIBUTES);
- gtk_recent_info_unref (walk->data);
- g_object_unref (file);
+ g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
+ g_list_free (load_data->items);
+ load_data->items = NULL;
}
- g_list_free (load_data->items);
- load_data->items = NULL;
-
return FALSE;
}
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index 4e327a9418..9458abdaba 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -361,16 +361,6 @@ delegate_confirm_overwrite (GtkFileChooser *chooser,
return conf;
}
-static gint
-recent_sort_mru (gconstpointer a,
- gconstpointer b)
-{
- GtkRecentInfo *info_a = (GtkRecentInfo *) a;
- GtkRecentInfo *info_b = (GtkRecentInfo *) b;
-
- return (gtk_recent_info_get_modified (info_b) - gtk_recent_info_get_modified (info_a));
-}
-
static GFile *
get_parent_for_uri (const char *uri)
{
@@ -385,22 +375,18 @@ get_parent_for_uri (const char *uri)
}
-/* Extracts the parent folders out of the recent items, and returns
- * a list of GFile* for those parents in MRU-first order.
+/* Extracts the parent folders out of the supplied list of GtkRecentInfo* items, and returns
+ * a list of GFile* for those unique parents.
*/
GList *
-_gtk_file_chooser_list_recent_folders (GtkRecentManager *manager)
+_gtk_file_chooser_extract_recent_folders (GList *infos)
{
- GList *infos;
GList *l;
GList *result;
GHashTable *folders;
result = NULL;
- infos = gtk_recent_manager_get_items (manager);
- infos = g_list_sort (infos, recent_sort_mru);
-
folders = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
for (l = infos; l; l = l->next)
@@ -427,8 +413,6 @@ _gtk_file_chooser_list_recent_folders (GtkRecentManager *manager)
result = g_list_reverse (result);
g_hash_table_destroy (folders);
- g_list_foreach (infos, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (infos);
return result;
}
diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h
index 5187cbd99c..ba58d71bdc 100644
--- a/gtk/gtkfilechooserutils.h
+++ b/gtk/gtkfilechooserutils.h
@@ -52,7 +52,7 @@ void _gtk_file_chooser_set_delegate (GtkFileChooser *receiver,
GQuark _gtk_file_chooser_delegate_get_quark (void) G_GNUC_CONST;
-GList *_gtk_file_chooser_list_recent_folders (GtkRecentManager *manager);
+GList *_gtk_file_chooser_extract_recent_folders (GList *infos);
G_END_DECLS