Compare commits

...

63 Commits

Author SHA1 Message Date
Federico Mena Quintero
586ac41c68 Get master's fixes for the file chooser 2009-10-01 15:59:06 -05:00
Federico Mena Quintero
988e4f1134 Fix thinkos in which fields get used
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-30 18:49:33 -05:00
Federico Mena Quintero
f03c304a25 Oops, it's gsize, not GSize
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-30 18:39:33 -05:00
Federico Mena Quintero
87bb81887a Fix a g_strdup_printf()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-30 17:55:12 -05:00
Federico Mena Quintero
5a80b1fb2d Put the list of column types in a macro
Every call to _gtk_file_system_model_new*() gets the same list of column types,
so we now keep the list in a macro instead of having duplicated copies all around.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 14:28:36 -05:00
Federico Mena Quintero
f38a3c0d74 Clarify the arguments of g_file_query_info_async()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 14:20:19 -05:00
Federico Mena Quintero
1a8c032dde Make copy_attribute() a function instead of a macro
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 13:32:08 -05:00
Federico Mena Quintero
c6cb5eebdc Don't leak a treepath if the treeview is not populated yet
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 13:25:29 -05:00
Federico Mena Quintero
b2cc6279b2 Factor out function to set a fixed size for the icon cell renderers
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 13:14:49 -05:00
Federico Mena Quintero
525bd57c67 Comment that the column order needs to be kept in sync across two functions
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 13:08:11 -05:00
Federico Mena Quintero
e462f7957d Fix typo in a comment
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 13:03:34 -05:00
Federico Mena Quintero
b525a47ad0 Make get_selected_file() return a ref'ed file
The old semantics was to return a GFile* owned by the file system model; the new
semantics is to hand out new references whenever possible.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-11 12:44:46 -05:00
Federico Mena Quintero
ff2660ed80 In set_filter(), handle the case where the new filter is the same as the old filter
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-10 17:22:16 -05:00
Federico Mena Quintero
2216cbd9a3 s/get_is_visible/iter_is_visible for clarity
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-10 16:33:37 -05:00
Federico Mena Quintero
25509380c4 Remove obsolete comment
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-10 15:36:15 -05:00
Federico Mena Quintero
fdafb0ec30 Make the code match the docs in _gtk_file_system_model_clear_cache()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-04 13:53:46 -05:00
Federico Mena Quintero
49268a750f Free some missing fields in ::finalize()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-04 13:42:46 -05:00
Federico Mena Quintero
616ad664f4 Clarify variable names in gtk_file_system_model_sort()
To comply with the i -> indexes; r -> rows convention.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-04 13:06:54 -05:00
Federico Mena Quintero
eb70ceb551 Nothing to do for ref/unref_node
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-04 12:49:53 -05:00
Federico Mena Quintero
64319ec227 Clarify a couple of spots with comments
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-04 12:32:10 -05:00
Federico Mena Quintero
f9939a13f8 Clarify array indexes vs. row numbers
There was some confusion between "index" as used for the model->files[] array,
and node->index as used for our 1-based row numbers.  Now we use "index" only
for indices in the model->files[] array, and node->row for row numbers.  Functions
and variables are renamed to clarify whether they refer to indexes or rows.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-04 12:01:16 -05:00
Federico Mena Quintero
8e3cea214e Big comment on how GtkFileSystemModel works
Let's have some documentation on the idea behind this beast...

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-03 18:34:17 -05:00
Federico Mena Quintero
ba79bbcc65 Remove obsolete code to use a cached mime-type
The non-standard "filechooser::mime-type" was a remnant of the recent-files code using
a hand-built GFileInfo; now we just query the file info ourselves.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-03 12:09:09 -05:00
Federico Mena Quintero
c79c73161c Fix thinko in node_should_be_visible()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 18:26:00 -05:00
Federico Mena Quintero
66d7626930 Factory out functions to emit row_inserted, row_changed, row_deleted
This is to avoid temporary variables for the path/iter and to avoid duplicated code.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 17:10:46 -05:00
Federico Mena Quintero
79101f3588 When updating a file, handle the case where the old file info is the same as the new one
This prevents us from inadvertently losing the last ref to the info.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 15:23:21 -05:00
Federico Mena Quintero
ec4ce57e87 When removing a file, also remove it from the file_lookup hash table
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 15:21:45 -05:00
Federico Mena Quintero
c68c0e5a1c Comment on how the file_lookup hash table gets rebuilt on demand
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 14:51:02 -05:00
Federico Mena Quintero
8a013f6c3e Clarify the arguments to g_file_query_info_async()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 13:58:47 -05:00
Federico Mena Quintero
299a997aea Show an error dialog when we can't read the folder's contents
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-09-02 13:43:03 -05:00
Federico Mena Quintero
2c9989c5d1 Clarify the code flow in gtk_file_system_model_got_files()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-31 16:13:05 -05:00
Federico Mena Quintero
28ae6fd0be Remove the dir_thaw_source while disposing the model
Otherwise that timeout may trigger after the model has died.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-31 15:53:45 -05:00
Federico Mena Quintero
85346c0d99 Make _gtk_file_system_model_remove_file() static
It was only used internally by the model.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-31 15:11:44 -05:00
Federico Mena Quintero
3fc06dd8bb Make _gtk_file_system_model_add_file() static
It was only used internally by the model, anyway.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-31 15:08:43 -05:00
Federico Mena Quintero
1e865a99c1 Clarify the comments that some fields in GtkFileSystemModel can be NULL
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 19:27:40 -05:00
Federico Mena Quintero
8792f8092e Clarify the arguments to g_file_monitor_directory()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 19:25:18 -05:00
Federico Mena Quintero
3352e4b955 Clarify an argument to g_file_enumerate_children_async()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 19:14:07 -05:00
Federico Mena Quintero
e5f16d59fc Fix and tighten an assertion
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 19:10:51 -05:00
Federico Mena Quintero
627ce4c77d Complete the documentation string for _gtk_file_system_model_new()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 19:10:26 -05:00
Federico Mena Quintero
7d9460fc57 Start with a file array with a resonable preallocated size
g_array_new() doesn't reserve any size by default, so during the initial population
of the file array, we'll do more reallocs than strictly needed.  We'll start with
a reasonable preallocated size, in this case the number of files which we can
get in a single chunk out of GIO.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 18:52:24 -05:00
Federico Mena Quintero
7eedd893f0 Compute the node size only once to avoid the scary macro
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 18:42:49 -05:00
Federico Mena Quintero
cae66dbe90 g_error() as soon as we catch an invalid column type
There's no point in running a GtkFileSystemModel with invalid column types.
This way we can also avoid clearing the memory of the column_types array.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-08-26 18:38:03 -05:00
Benjamin Otte
99ae34dbb4 Make number of validated rows depend on time, not on number of rows
Previously, do_validate_rows() validated 300 rows per iteration. While
this is usually not problematic, tree views with a lot of columns or
complex cell renderers could take inacceptably long, like:
- Epiphany's location bar entry completion has multiline and marked up
  text in every cell. Validating a single row took ~1.5ms here.
- In the list view in Nautilus, When enabling all columns, validating a
  single row would take ~3ms.
With 300 rows per iteration, that made those examples take 500ms/1s in a
signle main loop callback, and this obviously caused responsiveness
problems.

Now the code uses a timer and limits the time for validating rows to
30ms. This can cause less lines to be invalidated per call, so the
function might be called more often, but generally results in more
responsive applications.
2009-07-10 10:51:39 +02:00
Benjamin Otte
6bd907a60a Improve show_and_select_files() function
The previous function enumerated the whole directory and used a lot of
outdated API to decide how to show files.
The new code queries the filesystem model to decide about this.
The now unused old functions were removed.
2009-07-01 10:33:10 +02:00
Benjamin Otte
bfe2935455 Remove unused error argument from show_and_select_files() 2009-07-01 10:28:20 +02:00
Benjamin Otte
5f16b8c044 Enable the size column in recent files/search
Previously information about file sizes was not available for search
results and recent files, so the column was always hidden. As this
information is now available, we can stop the special handling and use
the same setting as in browse mode.
2009-07-01 10:24:41 +02:00
Benjamin Otte
34c0a31975 Use the faster accessor function in the sort functions
Use the faster _gtk_file_system_model_get_value() function instead of
gtk_tree_model_get() inside the sort functions. This gives a significant
speed-up when sorting large lists.
In a test case with 40.000 files, the sorting time went from ~5 seconds
to less than 0.5 seconds for my test case. There is 2 significant
problems with gtk_tree_model_get() that cause this:
1) The value is copied, which takes quite a bit of time for strings.
   ~25% of excessive time or ~1 second in my test
2) The tree model functions need to lookup the interface vfunc. And
   gtk_tree_model_get() doesn't do that only once, but multiple times
   (verifying column id, getting the actual value, ...)
   ~75% of excessive time or ~3 seconds in my test
2009-07-01 10:21:03 +02:00
Benjamin Otte
fdeaab7124 Convert recent files to a GtkFileSystemModel
This does to the recent files what the last commit did to the search. It
uses a GtkFileSystemModel and its API niceties to show the recent files.
2009-07-01 10:15:14 +02:00
Benjamin Otte
0703eeab08 Convert search to use a GtkFileSystemModel
Replace the list model code with the file system model and use all the
file system model API niceties we get from that.
Also adds the function _gtk_file_system_model_add_and_query_file() which
g_file_query_info()'s the file before adding it, so it gets added with
the right information.
2009-07-01 10:11:00 +02:00
Benjamin Otte
f73596a9b2 Don't count the "enter directory name" line as a selected file 2009-07-01 09:54:27 +02:00
Benjamin Otte
0b6393d572 Add a constructor to filesystem model that does not monitor a directory
This is in preparation for switching search and recent models to use
GtkFileSystemModel
2009-07-01 09:54:22 +02:00
Benjamin Otte
6e715f77ef Make the filesystem model filter API use a GtkFileFilter
This gets rid of the vfunc API and does exactly what the file chooser
wants.
2009-07-01 09:54:15 +02:00
Benjamin Otte
08f5202516 Only query the absolutely necessary attributes
Since the time taken by g_file_enumerate_children() depends a lot on the
attributes that are queried, we query the minimum attributes that need
to be queired to display the file chooser.

In particular, the attributes for loading the icon are ignored, as icons
are loaded on demand (see previous commit).
2009-07-01 09:54:05 +02:00
Benjamin Otte
04b7b41b75 Load icons on-demand
Because loading icons takes a noticable performance, this code loads the
pixbuf on demand and only loads icons for rows that are visible. There
is a few caveats to this:
- The pixbuf cell renderer must report the proer size even if the icon
  is not yet loaded. This is achieved by setting a fixed size.
- On theme changes the cahced pixbufs and the cell renderer must be
  updated to conform to the new theme.
2009-07-01 09:53:58 +02:00
Benjamin Otte
e6dcb53237 Use the GtkTreeSortable of the filesystem model
Previously, there was a GtkTreeSortModel wrapped around the filesystem
model to make it sortable. As the new implementation implements the
GtkTreeSortable interface, we can use this instead.
2009-07-01 09:53:47 +02:00
Benjamin Otte
0725e54524 Clean up code to use the model directly
A lot of code special cases accesses to the tree view for the different
browse modes, which was previously necessary, because the models were
different. Now that they are identical in the first columns, there is no
such need anymore, and the functions don't need to be special cased.
2009-07-01 09:51:34 +02:00
Benjamin Otte
6c20020be6 Replace the cell data computations
Previously custom functions were used to compute the data passed to the
cell renderers. Now that all this data is saved by the tree models with
compatible nodes, the usual default attribute-to-column mapping can be
used.
With this, caching of the values can happen in the tree model, which
avoids costly lookups of icons or computation of strings. Last but not
least it avoids spurious bugs that could happen when strings changed
without anyone noticing, like the mtime when a new day begins.
2009-07-01 09:51:21 +02:00
Benjamin Otte
56f5382343 Consolidate tree models for different browse modes
All tree models in browse mode now share the first 10 column types
containing all the necessary information to display the model on screen.
Therefor it is now easy to just operate on the tree model associated
with the file tree view and in most cases it isn't necessary anymore to
special case the browse modes.
2009-07-01 09:50:44 +02:00
Benjamin Otte
585772c32e Simplify gtk_file_chooser_default_unselect_file() 2009-07-01 09:49:37 +02:00
Benjamin Otte
05c629ffe9 Creating the model no longer fails
So remove the code that checked for failure, as it's not needed anymore.
2009-07-01 09:48:32 +02:00
Benjamin Otte
69ff1d8a93 Implement new GtkFileSystemModel
The new model is mostly API-compatible with the old model (minimal
changes were required), but is a lot faster and has a lot of very
desirable features.
- the model does no longer support a tree, just a list of files in a
  given directory
- the storage has been moved to a GArray as opposed to a tree
- no more dependency on GtkFileSystem
- columns are managed by the creator of the model, so any number of
  nodes can be added as needed. This also makes the API more similar
  to GtkListStore.
- Values are filled on demand using a function given when creating the
  model.
- The function can decide to let the model cache returned values or
  decide to be called again the next time the value is queried.
- implements GtkTreeSortable
- _gtk_file_system_model_get_value() was added to significantly speed
  up value access, which is necessary when sorting large models.
2009-07-01 09:47:45 +02:00
Benjamin Otte
27ab4f7937 move GtkFileSystemModel private stuff out of the private header 2009-06-30 14:55:27 +02:00
Benjamin Otte
278d1063c7 clean up code in gtk_list_store_set_n_columns()
Previous code's messiness noted by Francisco Javier Taboada Aguado
in http://mail.gnome.org/archives/gtk-devel-list/2009-June/msg00001.html
2009-06-30 13:31:54 +02:00
4 changed files with 2339 additions and 4005 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -194,17 +194,13 @@ struct _GtkFileChooserDefault
GtkWidget *search_entry;
GtkSearchEngine *search_engine;
GtkQuery *search_query;
GtkListStore *search_model;
GtkTreeModelFilter *search_model_filter;
GtkTreeModelSort *search_model_sort;
GtkFileSystemModel *search_model;
/* OPERATION_MODE_RECENT */
GtkWidget *recent_hbox;
GtkRecentManager *recent_manager;
GtkListStore *recent_model;
GtkFileSystemModel *recent_model;
guint load_recent_id;
GtkTreeModelFilter *recent_model_filter;
GtkTreeModelSort *recent_model_sort;
GtkWidget *filter_combo_hbox;
GtkWidget *filter_combo;
@@ -232,14 +228,11 @@ struct _GtkFileChooserDefault
*/
GtkTreeModel *shortcuts_combo_filter_model;
GtkTreeModelSort *sort_model;
/* Handles */
GSList *loading_shortcuts;
GSList *reload_icon_cancellables;
GCancellable *file_list_drag_data_received_cancellable;
GCancellable *update_current_folder_cancellable;
GCancellable *show_and_select_files_cancellable;
GCancellable *should_respond_get_info_cancellable;
GCancellable *file_exists_get_info_cancellable;
GCancellable *update_from_entry_cancellable;
@@ -316,63 +309,6 @@ struct _GtkFileChooserDefault
};
/* GtkFileSystemModel private */
typedef struct _FileModelNode FileModelNode;
struct _GtkFileSystemModel
{
GObject parent_instance;
GtkFileSystem *file_system;
gchar *attributes;
FileModelNode *roots;
GtkFolder *root_folder;
GFile *root_file;
GtkFileSystemModelFilter filter_func;
gpointer filter_data;
GSList *idle_clears;
GSource *idle_clear_source;
gushort max_depth;
GSList *pending_cancellables;
guint show_hidden : 1;
guint show_folders : 1;
guint show_files : 1;
guint folders_only : 1;
guint has_editable : 1;
};
struct _FileModelNode
{
GFile *file;
FileModelNode *next;
GFileInfo *info;
GtkFolder *folder;
FileModelNode *children;
FileModelNode *parent;
GtkFileSystemModel *model;
guint ref_count;
guint n_referenced_children;
gushort depth;
guint has_dummy : 1;
guint is_dummy : 1;
guint is_visible : 1;
guint loaded : 1;
guint idle_clear : 1;
guint load_pending : 1;
};
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_PRIVATE_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,8 @@
#ifndef __GTK_FILE_SYSTEM_MODEL_H__
#define __GTK_FILE_SYSTEM_MODEL_H__
#include "gtkfilesystem.h"
#include <gio/gio.h>
#include <gtk/gtkfilefilter.h>
#include <gtk/gtktreemodel.h>
G_BEGIN_DECLS
@@ -34,46 +35,58 @@ typedef struct _GtkFileSystemModel GtkFileSystemModel;
GType _gtk_file_system_model_get_type (void) G_GNUC_CONST;
typedef enum {
GTK_FILE_SYSTEM_MODEL_INFO,
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME,
GTK_FILE_SYSTEM_MODEL_N_COLUMNS
} GtkFileSystemModelColumns;
typedef gboolean (*GtkFileSystemModelGetValue) (GtkFileSystemModel *model,
GFile *file,
GFileInfo *info,
int column,
GValue *value,
gpointer user_data);
GtkFileSystemModel *_gtk_file_system_model_new (GtkFileSystem *file_system,
GFile *root_file,
gint max_depth,
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,
GError **error);
GtkFileSystemModelGetValue get_func,
gpointer get_data,
guint n_columns,
...);
GCancellable * _gtk_file_system_model_get_cancellable (GtkFileSystemModel *model);
gboolean _gtk_file_system_model_iter_is_visible (GtkFileSystemModel *model,
GtkTreeIter *iter);
GFileInfo * _gtk_file_system_model_get_info (GtkFileSystemModel *model,
GtkTreeIter *iter);
gboolean _gtk_file_system_model_get_iter_for_file(GtkFileSystemModel *model,
GtkTreeIter *iter,
GFile *file);
GFile * _gtk_file_system_model_get_file (GtkFileSystemModel *model,
GtkTreeIter *iter);
const GValue * _gtk_file_system_model_get_value (GtkFileSystemModel *model,
GtkTreeIter * iter,
int column);
void _gtk_file_system_model_add_and_query_file (GtkFileSystemModel *model,
GFile *file,
const char *attributes);
void _gtk_file_system_model_update_file (GtkFileSystemModel *model,
GFile *file,
GFileInfo *info,
gboolean requires_resort);
void _gtk_file_system_model_set_show_hidden (GtkFileSystemModel *model,
gboolean show_hidden);
void _gtk_file_system_model_set_show_folders (GtkFileSystemModel *model,
gboolean show_folders);
void _gtk_file_system_model_set_show_files (GtkFileSystemModel *model,
gboolean show_files);
typedef gboolean (*GtkFileSystemModelFilter) (GtkFileSystemModel *model,
GFile *file,
GFileInfo *info,
gpointer user_data);
void _gtk_file_system_model_freeze_updates (GtkFileSystemModel *model);
void _gtk_file_system_model_thaw_updates (GtkFileSystemModel *model);
void _gtk_file_system_model_clear_cache (GtkFileSystemModel *model,
int column);
void _gtk_file_system_model_set_filter (GtkFileSystemModel *model,
GtkFileSystemModelFilter filter,
gpointer user_data);
typedef void (*GtkFileSystemModelPathFunc) (GtkFileSystemModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer user_data);
void _gtk_file_system_model_path_do (GtkFileSystemModel *model,
GFile *file,
GtkFileSystemModelPathFunc func,
gpointer user_data);
GtkFileFilter *filter);
void _gtk_file_system_model_add_editable (GtkFileSystemModel *model,
GtkTreeIter *iter);