[gtk+/filesystemmodel] add a constructor that does not monitor a directory
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+/filesystemmodel] add a constructor that does not monitor a directory
- Date: Wed, 24 Jun 2009 21:13:24 +0000 (UTC)
commit b7bdb7069eb5061bd36f0531e828b7fef5ed3961
Author: Benjamin Otte <otte gnome org>
Date: Wed Jun 24 18:41:03 2009 +0200
add a constructor that does not monitor a directory
This is in preparation for switching search and recnt models to
GtkFileSystemModel
gtk/gtkfilechooserdefault.c | 35 ++++++++++---------
gtk/gtkfilesystemmodel.c | 78 ++++++++++++++++++++++++++++++++++---------
gtk/gtkfilesystemmodel.h | 6 +++-
3 files changed, 85 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 8aa30d4..cf5cbcf 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -6857,23 +6857,24 @@ set_list_model (GtkFileChooserDefault *impl,
set_busy_cursor (impl, TRUE);
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
- impl->browse_files_model = _gtk_file_system_model_new (impl->current_folder,
- "standard::name,standard::type,standard::display-name,"
- "standard::is-hidden,standard::is-backup,standard::size,"
- "standard::content-type,time::modified",
- file_system_model_set,
- impl,
- MODEL_COL_NUM_COLUMNS,
- G_TYPE_STRING,
- G_TYPE_INT64,
- G_TYPE_LONG,
- G_TYPE_FILE,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN,
- GDK_TYPE_PIXBUF,
- G_TYPE_STRING,
- G_TYPE_STRING,
- PANGO_TYPE_ELLIPSIZE_MODE);
+ impl->browse_files_model =
+ _gtk_file_system_model_new_for_directory (impl->current_folder,
+ "standard::name,standard::type,standard::display-name,"
+ "standard::is-hidden,standard::is-backup,standard::size,"
+ "standard::content-type,time::modified",
+ file_system_model_set,
+ impl,
+ MODEL_COL_NUM_COLUMNS,
+ G_TYPE_STRING,
+ G_TYPE_INT64,
+ G_TYPE_LONG,
+ G_TYPE_FILE,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN,
+ GDK_TYPE_PIXBUF,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ PANGO_TYPE_ELLIPSIZE_MODE);
_gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 8da4a0f..de89c60 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -1136,39 +1136,85 @@ gtk_file_system_model_set_directory (GtkFileSystemModel *model,
}
+static GtkFileSystemModel *
+_gtk_file_system_model_new_valist (GtkFileSystemModelGetValue get_func,
+ gpointer get_data,
+ guint n_columns,
+ va_list args)
+{
+ GtkFileSystemModel *model;
+
+ model = g_object_new (GTK_TYPE_FILE_SYSTEM_MODEL, NULL);
+ model->get_func = get_func;
+ model->get_data = get_data;
+
+ gtk_file_system_model_set_n_columns (model, n_columns, args);
+
+ return model;
+}
+
/**
* _gtk_file_system_model_new:
+ * @get_func: function to call for getting a value
+ * @get_data: user data argument passed to @get_func
+ * @n_columns: number of columns
+ * @...: @n_columns #GType types for the columns
+ *
+ * Creates a new #GtkFileSystemModel object. You need to add files
+ * to the list using _gtk_file_system_model_add_file().
+ *
+ * Return value: the newly created #GtkFileSystemModel
+ **/
+GtkFileSystemModel *
+_gtk_file_system_model_new (GtkFileSystemModelGetValue get_func,
+ gpointer get_data,
+ guint n_columns,
+ ...)
+{
+ GtkFileSystemModel *model;
+ va_list args;
+
+ g_return_val_if_fail (get_func != NULL, NULL);
+ g_return_val_if_fail (n_columns > 0, NULL);
+
+ va_start (args, n_columns);
+ model = _gtk_file_system_model_new_valist (get_func, get_data, n_columns, args);
+ va_end (args);
+
+ return model;
+}
+
+/**
+ * _gtk_file_system_model_new_for_directory:
* @directory: the directory to show.
* @attributes: attributes to immediately load or %NULL for all
- * @error: location to store error, or %NULL.
*
* Creates a new #GtkFileSystemModel object. The #GtkFileSystemModel
* object wraps the given @directory as a #GtkTreeModel.
- * The model will query the given @attributes immediately and only add
- * files with those attributes present.
+ * The model will query the given directory with the given @attributes
+ * and add all files inside the directory automatically. If supported,
+ * it will also monitor the drectory and update the model's
+ * contents to reflect changes, if the @directory supports monitoring.
*
- * Return value: the newly created #GtkFileSystemModel object, or NULL if there
- * was an error.
+ * Return value: the newly created #GtkFileSystemModel
**/
GtkFileSystemModel *
-_gtk_file_system_model_new (GFile * dir,
- const gchar * attributes,
- GtkFileSystemModelGetValue get_func,
- gpointer get_data,
- guint n_columns,
- ...)
+_gtk_file_system_model_new_for_directory (GFile * dir,
+ const gchar * attributes,
+ GtkFileSystemModelGetValue get_func,
+ gpointer get_data,
+ guint n_columns,
+ ...)
{
GtkFileSystemModel *model;
va_list args;
g_return_val_if_fail (G_IS_FILE (dir), NULL);
-
- model = g_object_new (GTK_TYPE_FILE_SYSTEM_MODEL, NULL);
- model->get_func = get_func;
- model->get_data = get_data;
+ g_return_val_if_fail (get_func != NULL, NULL);
+ g_return_val_if_fail (n_columns > 0, NULL);
va_start (args, n_columns);
- gtk_file_system_model_set_n_columns (model, n_columns, args);
+ model = _gtk_file_system_model_new_valist (get_func, get_data, n_columns, args);
va_end (args);
gtk_file_system_model_set_directory (model, dir, attributes);
diff --git a/gtk/gtkfilesystemmodel.h b/gtk/gtkfilesystemmodel.h
index ae04e2f..d27a647 100644
--- a/gtk/gtkfilesystemmodel.h
+++ b/gtk/gtkfilesystemmodel.h
@@ -42,7 +42,11 @@ typedef gboolean (*GtkFileSystemModelGetValue) (GtkFileSystemModel *model,
GValue *value,
gpointer user_data);
-GtkFileSystemModel *_gtk_file_system_model_new (GFile * dir,
+GtkFileSystemModel *_gtk_file_system_model_new (GtkFileSystemModelGetValue get_func,
+ gpointer get_data,
+ guint n_columns,
+ ...);
+GtkFileSystemModel *_gtk_file_system_model_new_for_directory(GFile * dir,
const gchar * attributes,
GtkFileSystemModelGetValue get_func,
gpointer get_data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]