Commit Graph

19421 Commits

Author SHA1 Message Date
Federico Mena Quintero
0144521438 Fix typo in a comment
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:18 +02:00
Federico Mena Quintero
6e3a6ba12f 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-10-15 22:06:18 +02:00
Federico Mena Quintero
7e9fbd16e4 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-10-15 22:06:17 +02:00
Federico Mena Quintero
fb1a72fcb0 s/get_is_visible/iter_is_visible for clarity
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:17 +02:00
Federico Mena Quintero
9efa64fba5 Remove obsolete comment
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:17 +02:00
Federico Mena Quintero
55a04b1da0 Make the code match the docs in _gtk_file_system_model_clear_cache()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:17 +02:00
Federico Mena Quintero
112d2430be Free some missing fields in ::finalize()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:17 +02:00
Federico Mena Quintero
5ea265ca61 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-10-15 22:06:17 +02:00
Federico Mena Quintero
7ecc87ed59 Nothing to do for ref/unref_node
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:17 +02:00
Federico Mena Quintero
8bf24cdd9d Clarify a couple of spots with comments
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:16 +02:00
Federico Mena Quintero
14cc3e17f5 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-10-15 22:06:16 +02:00
Federico Mena Quintero
d0468ee7e1 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-10-15 22:06:16 +02:00
Federico Mena Quintero
04c78019fb 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-10-15 22:06:16 +02:00
Federico Mena Quintero
6166fccf30 Fix thinko in node_should_be_visible()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:16 +02:00
Federico Mena Quintero
908911d6db 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-10-15 22:06:16 +02:00
Federico Mena Quintero
ad2e6ff52c 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-10-15 22:06:16 +02:00
Federico Mena Quintero
688917cdbb When removing a file, also remove it from the file_lookup hash table
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:15 +02:00
Federico Mena Quintero
385fa71ec0 Comment on how the file_lookup hash table gets rebuilt on demand
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:15 +02:00
Federico Mena Quintero
6820dee988 Clarify the arguments to g_file_query_info_async()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:15 +02:00
Federico Mena Quintero
ccee7ef4fb Show an error dialog when we can't read the folder's contents
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:15 +02:00
Federico Mena Quintero
3b86973075 Clarify the code flow in gtk_file_system_model_got_files()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:15 +02:00
Federico Mena Quintero
3f7c144605 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-10-15 22:06:15 +02:00
Federico Mena Quintero
30016185be 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-10-15 22:06:14 +02:00
Federico Mena Quintero
2e0382cf02 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-10-15 22:06:14 +02:00
Federico Mena Quintero
93588c6d5c Clarify the comments that some fields in GtkFileSystemModel can be NULL
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:14 +02:00
Federico Mena Quintero
88bb9342ab Clarify the arguments to g_file_monitor_directory()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:14 +02:00
Federico Mena Quintero
d2d997a021 Clarify an argument to g_file_enumerate_children_async()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:14 +02:00
Federico Mena Quintero
d5d9601852 Fix and tighten an assertion
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:14 +02:00
Federico Mena Quintero
86c32c2502 Complete the documentation string for _gtk_file_system_model_new()
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:14 +02:00
Federico Mena Quintero
3232c469fc 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-10-15 22:06:13 +02:00
Federico Mena Quintero
5110415684 Compute the node size only once to avoid the scary macro
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:13 +02:00
Federico Mena Quintero
dfe20ea1a8 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-10-15 22:06:13 +02:00
Benjamin Otte
836c3ab043 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-10-15 22:01:40 +02:00
Benjamin Otte
6bdaaea3a4 Remove unused error argument from show_and_select_files() 2009-10-15 22:01:40 +02:00
Benjamin Otte
682a3c8c75 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-10-15 22:01:40 +02:00
Benjamin Otte
d68bca1771 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-10-15 22:01:39 +02:00
Benjamin Otte
53a00e3cc3 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-10-15 22:01:39 +02:00
Benjamin Otte
5a31dfd66b 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-10-15 22:01:09 +02:00
Benjamin Otte
390a3910f5 Don't count the "enter directory name" line as a selected file 2009-10-15 22:00:09 +02:00
Benjamin Otte
affa8c8459 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-10-15 22:00:09 +02:00
Benjamin Otte
10e8d6abca 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-10-15 22:00:09 +02:00
Benjamin Otte
cd337e2a95 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-10-15 22:00:08 +02:00
Benjamin Otte
4a1ff32325 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-10-15 22:00:08 +02:00
Benjamin Otte
105e6fbc11 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-10-15 22:00:08 +02:00
Benjamin Otte
3e385ffd07 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-10-15 22:00:08 +02:00
Benjamin Otte
30c1a1ee2c 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-10-15 22:00:08 +02:00
Benjamin Otte
a5390ad49e 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-10-15 22:00:07 +02:00
Benjamin Otte
d6f3d0e7eb Simplify gtk_file_chooser_default_unselect_file() 2009-10-15 22:00:07 +02:00
Benjamin Otte
0ccb2f2427 Creating the model no longer fails
So remove the code that checked for failure, as it's not needed anymore.
2009-10-15 22:00:07 +02:00
Benjamin Otte
18b56b9970 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-10-15 22:00:06 +02:00