Commit Graph

146 Commits

Author SHA1 Message Date
Peter Bloomfield
b9155dcb1a file-system-model: Refactor a helper
Push more common code into the helper for
gtk_file_system_model_query_done() and
gtk_file_system_model_one_query_done().
2020-04-26 17:38:49 -04:00
Peter Bloomfield
d85f02a994 file-system-model: Avoid use-after free
This is a possible fix for https://gitlab.gnome.org/GNOME/gtk/-/issues/2657

Use a NULL return from g_file_query_info_finish() to detect cancellation
of the query, and avoid derferencing a stale pointer.
2020-04-26 16:47:23 -04:00
Bastien Nocera
8cb45cdeae filechooser: Fallback if content-type unavailable
Fallback to fast-content-type if the content-type attribute isn't
available, as is the case for most remote filesystems.

Closes: #2482
2020-02-28 17:33:08 +01:00
Benjamin Otte
2e941acb29 filesystemmodel: Guard variable with correct compiler flags 2020-02-22 07:33:41 +01:00
Benjamin Otte
b8cf7ea1c6 dnd: Port the TreeModel machinery to GValue DND 2020-02-18 02:40:00 +01:00
Emmanuele Bassi
25fd230327 gtk: Drop the "plus"
Source names should use "[gtk]" without the plus.
2019-02-05 11:26:20 +01:00
Emmanuele Bassi
888dfe499d Drop the Big GDK Lock
GDK has a lock to mark critical sections inside the backends.
Additionally, code that would re-enter into the GTK main loop was
supposed to hold the lock.

Back in the Good Old Days™ this was guaranteed to kind of work only on
the X11 backend, and would cause a neat explosion on any other GDK
backend.

During GTK+ 3.x we deprecated the API to enter and leave the critical
sections, and now we can remove all the internal uses of the lock, since
external API that uses GTK+ 4.x won't be able to hold the GDK lock.

https://bugzilla.gnome.org/show_bug.cgi?id=793124
2018-02-03 12:07:10 +01:00
Emmanuele Bassi
c655759cef Replace gdk_threads_add_timeout* with g_timeout_add()
The main GDK thread lock is not portable and deprecated.

The only reason why gdk_threads_add_timeout() and
gdk_threads_add_timeout_full() exist is to allow invoking a callback
with the GDK lock held, in case 3rd party libraries still use the
deprecated gdk_threads_enter()/gdk_threads_leave() API.

Since we're removing the GDK lock, and we're releasing a new major API,
such code cannot exist any more; this means we can use the GLib API for
installing timeout callbacks.

https://bugzilla.gnome.org/show_bug.cgi?id=793124
2018-02-03 12:06:58 +01:00
Benjamin Otte
43c212ac28 build: Enable -Wswitch-enum and -Wswitch-default
This patch makes that work using 1 of 2 options:

1. Add all missing enums to the switch statement
  or
2. Cast the switch argument to a uint to avoid having to do that (mostly
   for GdkEventType).

I even found a bug while doing that: clearing a GtkImage with a surface
did not notify thae surface property.

The reason for enabling this flag even though it is tedious at times is
that it is very useful when adding values to an enum, because it makes
GTK immediately warn about all the switch statements where this enum is
relevant.
And I expect changes to enums to be frequent during the GTK4 development
cycle.
2017-10-06 21:23:39 +02:00
Benjamin Otte
e1a03ead7a Use NULL for generic marshallers in g_signal_new()
glib will use the correct marshaller automatically. And as a side
effect, we also get all glib optimizations, like a va marshaller.
2016-08-29 16:20:54 +02:00
Ting-Wei Lan
5436c74a19 Fix return value error in _gtk_file_system_model_get_directory 2015-07-06 03:27:42 +08:00
Matthias Clasen
9a44467318 Add a getter for the directory to file system model
This will allow us to aovid reloading if the directory is
unchanged.
2015-07-04 00:29:26 -04:00
Matthias Clasen
1d63335c8e Use infos from search engine instead of getting them again
When the search engine provides hits with GFileInfo, use that
to add the hits to the model directly, without going through
another round of async get_info calls.

To do this, we add a batched variant of the
_gtk_file_system_model_update_file call that takes lists of
GFiles and GFileInfos. Again, we can avoid repeated resorting
that happens when the files are updated individually.
2015-06-18 15:20:06 -04:00
Matthias Clasen
b2ceadb057 file system model: Add batched insertion
Add a batched version of gtk_file_system_model_add_and_query_file
that takes a list of files and avoids resorting the model for each
individual insertion. The querying is still done one-file-at-a-time,
so more optimization is certainly possible.
2015-06-18 13:11:30 -04:00
Matthias Clasen
d6543bc009 Remove no longer needed in-tree editing 2015-04-10 15:41:56 -04:00
Matthias Clasen
f9c5799c82 GtkFileChooser: Don't crash if invisible files are deleted
This is a crash that has been around for a long time, as
can be seen here:
https://bugzilla.redhat.com/show_bug.cgi?id=1048388
https://bugzilla.redhat.com/show_bug.cgi?id=984375
https://bugzilla.redhat.com/show_bug.cgi?id=1159015
https://bugzilla.redhat.com/show_bug.cgi?id=1059187
https://bugzilla.redhat.com/show_bug.cgi?id=1122172
https://bugzilla.redhat.com/show_bug.cgi?id=1016895
https://bugzilla.redhat.com/show_bug.cgi?id=1133235
https://bugzilla.redhat.com/show_bug.cgi?id=1077500
https://bugzilla.redhat.com/show_bug.cgi?id=1054378
https://bugzilla.redhat.com/show_bug.cgi?id=1173212

Fix suggested by Benjamin Otte.
2014-12-11 22:57:37 -05:00
Emmanuele Bassi
cbb2938587 Freeze file system model during editing
If a file system event arrives while GtkFileChooserWidget is asking the
user to edit the name of a newly created folder, the file system model
will drop the row with the editable cell, and the user will have to
start from scratch.

This makes creating new directories impossible inside a directory with a
file currently being downloaded, for instance, and it's really unhelpful
to the user because the editable row simply disappears.

We already have a mechanism in place to freeze the file system model, so
we can reuse it between the add_editable() and the remove_editable()
calls.

https://bugzilla.gnome.org/show_bug.cgi?id=729927
2014-11-25 23:03:27 -05:00
William Jon McCann
e709c965a4 Don't leak the queried file info
https://bugzilla.gnome.org/show_bug.cgi?id=554618
2014-02-21 14:51:25 -05:00
William Jon McCann
469d333aa2 docs: use Returns: consistently
Instead of Return value:
2014-02-19 18:56:05 -05:00
William Jon McCann
7a208fbbf3 docs: use proper apostrophe
https://wiki.gnome.org/Design/OS/Typography
2014-02-07 13:06:10 -05:00
William Jon McCann
2a45418b67 docs: use proper quotes 2014-02-05 15:08:42 -05:00
William Jon McCann
22586ea7c2 docs: use #*-struct instead of <structname> 2014-01-27 19:59:55 -05:00
Bastien Nocera
438cd857c4 all: Add names to timeouts
Add names to every timeout we setup, so it's easier to track their
usage, and debug possible misbehaviour.

https://bugzilla.gnome.org/show_bug.cgi?id=710651
2013-10-23 13:31:18 +02:00
Federico Mena Quintero
ea3a750f13 bgo#687196 - Fix model corruption during file removal
The main problem is that we were emitting the row-deleted signal for the model in the middle
of the process that actually deletes the row from the model (remove the row from the array,
update the model->file_lookup hash table, etc.).  In the model's caller, one of the row-deleted
callbacks was requesting an iter, which caused the model to revalidate itself - but it did
this while it was in an inconsistent state.  This led to an assertion failure later when the
model resorted itself.

The fix in remove_file() is like this:

* The filteredness/visibility of the deleted node is not updated.  The
  node will simply be gone; we don't need to update those values at
  all.

* We invalidate just the node that is being deleted.

* The model->file_lookup hash table is not completely nuked; instead,
  we carefully adjust its indices.

* The row-deleted signal is only emitted at the very end, when
  deletion is complete and the model is consistent.

Many thanks to William Hua for doing the detective work on this bug!

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-11-02 14:09:01 -06:00
Federico Mena Quintero
94e3d7faf1 Make freeze_updates() and thaw_updates() static functions
They were in the semi-public API of GtkFileSystemModel, but never actually used outside of it.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-11-01 17:21:47 -06:00
Federico Mena Quintero
1cee5ff0dd Comments on how the filtering and sorting processes work
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-11-01 17:19:10 -06:00
Federico Mena Quintero
f39f574914 Remove argument to _gtk_file_system_model_update_file() that should not be part of the internal API
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-10-31 20:54:02 -06:00
Federico Mena Quintero
281c592ea9 Rename gtk_tree_path_new_from_node() to tree_path_new_from_node()
This is a function internal to the file system model; let's not pollute the gtk_tree_path namespace.

Also, make the 'i' variable into 'r' as it refers to a row index, not a file-array index (for
consistency with the docs and the rest of the code).

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-10-31 20:21:47 -06:00
Matthias Clasen
46c1ea98d2 Emit row-changed notification
Emit row-changed when the filteredness of a visible row
changes in GtkFileSystemModel.
2012-07-15 00:41:49 -04:00
Federico Mena Quintero
cbb4ee4d55 Make computing and setting the visibility/filters atomic operations
This way we remove paired function calls (compute/set pairs), and also make
it possible to avoid computing a filter twice, as setting the visibility
depends on filteredness.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-07-15 00:41:48 -04:00
Federico Mena Quintero
435ee7741c Make it clear that 'filtered' means 'filtered_out'
It bothers me that we call gtk_file_filter_filter(), then negate the result,
and the return *that* from node_should_be_filtered().  So, rename 'filtered'
throughout GtkFileSystemModel to 'filtered_out' to mean things that didn't
pass the filter.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-07-15 00:41:48 -04:00
Federico Mena Quintero
914749bebe Remove superfluous check in node_set_filtered()
This was a copy-paste leftover from node_set_visible().  Filters are not
concerned with model freezes, so node_set_filtered() does not
need to handle freezes, either.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
2012-07-15 00:41:48 -04:00
William Jon McCann
c027b6d2cd Desensitize filtered folders when in folder selection mode
https://bugzilla.gnome.org/show_bug.cgi?id=679333
2012-07-15 00:41:47 -04:00
Javier Jardón
9d0febc9a6 Change FSF Address 2012-02-27 17:06:11 +00:00
Benjamin Otte
98fb16e307 filesystemmodel: Add a toggle for whether directories are filtered 2011-12-16 20:09:14 +01:00
Benjamin Otte
e97b05acbd filesystemmodel: Add a missing check
Paths with depth > 1 should return FALSE instead of pretending the depth
is 1.
2011-10-03 18:29:21 +02:00
Alexander Larsson
e274dbbdce Ensure we always grab the gdk lock in async callbacks
Async callbacks are delivered in idles, so we need to make sure
we get the gdk lock before calling any gdk/gtk stuff. This was
missing in a few places.
2011-03-28 12:49:17 +02:00
Sergey Orlov
a676f9dada bgo#614006 - GtkFileSystemModel - Make sure to generate node IDs are valid for new files
When a file was inserted during the period that the editable row was
active, the node IDs would not get updated correctly.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
2010-08-24 17:09:37 -05:00
Javier Jardón
0a07e9733b gtk/: fully remove gtkalias hacks
https://bugzilla.gnome.org/show_bug.cgi?id=623845
2010-07-10 02:51:26 +02:00
Colin Walters
905f988166 Revert "Add length to gtk_tree_path_get_indices"
This reverts commit eebb16eb1a.

Was an accidental commit.
2010-06-28 14:15:10 -04:00
Colin Walters
eebb16eb1a Add length to gtk_tree_path_get_indices
The old version wasn't introspectable as it didn't have a length
return parameter.  Also, delete gtk_tree_path_get_indices_with_depth,
since it's no longer needed.
2010-06-28 13:50:36 -04:00
Benjamin Otte
42abeadbb8 Can't select file on file browser after changing sort order
The row values are 1-indexed not 0-indexed, this has to be taken into
account when producing the new_order array.

https://bugzilla.gnome.org/show_bug.cgi?id=621414
2010-06-28 14:19:18 +02:00
Benjamin Otte
b08a6750dc filechooser: Fix a crash when removing files
The file removal code was not properly clearing the file=>array index
cache, so later lookups into that cache would return invalid array
indexes.

The easiest way to reproduce it is to create a directory with two files
and deleting both of them.

Reported-by: Javier Jardón <jjardon@gnome.org>
2010-05-02 14:34:43 +02:00
Benjamin Otte
9514e741cd Fix error case in filesystem model
We should not unref the model here, it might not even exist anymore.
Instead check if it exists and only use it if it does.
The unref was leftover from a previous fix in
ba9f53397f.

Spotted by Matthias Clasen in
https://bugzilla.gnome.org/show_bug.cgi?id=614099
2010-03-29 16:29:20 +02:00
Johan Dahlin
fe85272112 [annotations] Add allow-none
This commit was created using a script that searched for all docstrings
containing a parameter and the string 'or %NULL'.
Gdk backends and demos excluded as they are not part of a public API

https://bugzilla.gnome.org/show_bug.cgi?id=610474
2010-02-19 17:57:51 -02:00
Benjamin Otte
ba9f53397f Don't keep the filesystem model alive while querying files
This allows disposing of the filesystemmodel while the file enumeration
is still happening.
As the filechooser does not disconnect its signals because it assumes it
is the only owner of the model, this also prevents a SEGV when emitting
the "load-finished" signal in that case.
2009-11-02 20:11:09 +01:00
Federico Mena Quintero
f0e2d7d88b Fix thinkos in which fields get used
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:20 +02:00
Federico Mena Quintero
02d96465f4 Oops, it's gsize, not GSize
Signed-off-by: Federico Mena Quintero <federico@novell.com>
2009-10-15 22:06:19 +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