[gtk+/bgo593793-filechooser-recent-folders: 1/10] Utility function to extract folders from the recently-used list
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/bgo593793-filechooser-recent-folders: 1/10] Utility function to extract folders from the recently-used list
- Date: Wed, 29 Jun 2011 18:46:18 +0000 (UTC)
commit c2fc707b6a8c6be5da1da37e1a6f2882662cc4b7
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Jun 27 15:30:59 2011 -0500
Utility function to extract folders from the recently-used list
This extracts the parent folders from the items in the recently-used
list. We'll use it in the file chooser to present a list of
recently-used folders.
Signed-off-by: Federico Mena Quintero <federico gnome org>
gtk/gtkfilechooserutils.c | 72 +++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkfilechooserutils.h | 2 +
2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index e0fefcf..4e327a9 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -360,3 +360,75 @@ delegate_confirm_overwrite (GtkFileChooser *chooser,
g_signal_emit_by_name (data, "confirm-overwrite", &conf);
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)
+{
+ GFile *file;
+ GFile *parent;
+
+ file = g_file_new_for_uri (uri);
+ parent = g_file_get_parent (file);
+
+ g_object_unref (file);
+ return parent;
+
+}
+
+/* Extracts the parent folders out of the recent items, and returns
+ * a list of GFile* for those parents in MRU-first order.
+ */
+GList *
+_gtk_file_chooser_list_recent_folders (GtkRecentManager *manager)
+{
+ 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)
+ {
+ GtkRecentInfo *info = l->data;
+ const char *uri;
+ GFile *parent;
+
+ uri = gtk_recent_info_get_uri (info);
+ parent = get_parent_for_uri (uri);
+
+ if (parent)
+ {
+ if (!g_hash_table_lookup (folders, parent))
+ {
+ g_hash_table_insert (folders, parent, (gpointer) 1);
+ result = g_list_prepend (result, g_object_ref (parent));
+ }
+
+ g_object_unref (parent);
+ }
+ }
+
+ 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 8b80ab6..5187cbd 100644
--- a/gtk/gtkfilechooserutils.h
+++ b/gtk/gtkfilechooserutils.h
@@ -52,6 +52,8 @@ 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);
+
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]