2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2003-03-21 20:34:02 +00:00
|
|
|
|
* gtkfilesystemmodel.c: GtkTreeModel wrapping a GtkFileSystem
|
|
|
|
|
* Copyright (C) 2003, Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-03-21 20:34:02 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
|
#include "gtkfilesystemmodel.h"
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2020-07-11 22:11:32 +00:00
|
|
|
|
#include "gtkfilechooserutils.h"
|
2004-03-29 19:52:16 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2020-07-04 15:06:36 +00:00
|
|
|
|
#include "gtkfilter.h"
|
2021-07-26 21:03:15 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/* priority used for all async callbacks in the main loop
|
|
|
|
|
* This should be higher than redraw priorities so multiple callbacks
|
2022-10-22 01:09:24 +00:00
|
|
|
|
* firing can be handled without intermediate redraws
|
|
|
|
|
*/
|
2009-06-30 13:15:55 +00:00
|
|
|
|
#define IO_PRIORITY G_PRIORITY_DEFAULT
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/* random number that everyone else seems to use, too */
|
|
|
|
|
#define FILES_PER_QUERY 100
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
typedef struct _FileModelNode FileModelNode;
|
|
|
|
|
typedef struct _GtkFileSystemModelClass GtkFileSystemModelClass;
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
struct _FileModelNode
|
|
|
|
|
{
|
|
|
|
|
GFile * file; /* file represented by this node or NULL for editable */
|
|
|
|
|
GFileInfo * info; /* info for this file or NULL if unknown */
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-09-04 17:01:16 +00:00
|
|
|
|
guint row; /* if valid (see model->n_valid_indexes), visible nodes before and including
|
2009-09-03 23:22:21 +00:00
|
|
|
|
* this one - see the "Structure" comment above.
|
|
|
|
|
*/
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
guint visible :1; /* if the file is currently visible */
|
2012-07-11 20:47:53 +00:00
|
|
|
|
guint filtered_out :1;/* if the file is currently filtered out (i.e. it didn't pass the filters) */
|
2009-06-30 13:15:55 +00:00
|
|
|
|
guint frozen_add :1; /* true if the model was frozen and the entry has not been added yet */
|
2009-06-17 08:39:26 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
struct _GtkFileSystemModel
|
2009-06-17 08:39:26 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GObject parent_instance;
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GFile * dir; /* directory that's displayed */
|
|
|
|
|
guint dir_thaw_source;/* GSource id for unfreezing the model */
|
2009-08-27 00:27:40 +00:00
|
|
|
|
char * attributes; /* attributes the file info must contain, or NULL for all attributes */
|
|
|
|
|
GFileMonitor * dir_monitor; /* directory that is monitored, or NULL if monitoring was not supported */
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GCancellable * cancellable; /* cancellable in use for all operations - cancelled on dispose */
|
|
|
|
|
GArray * files; /* array of FileModelNode containing all our files */
|
2009-09-04 17:01:16 +00:00
|
|
|
|
guint n_nodes_valid; /* count of valid nodes (i.e. those whose node->row is accurate) */
|
|
|
|
|
GHashTable * file_lookup; /* mapping of GFile => array index in model->files
|
2009-09-02 19:51:02 +00:00
|
|
|
|
* This hash table doesn't always have the same number of entries as the files array;
|
|
|
|
|
* The hash table gets re-populated in node_get_for_file() if this mismatch is
|
|
|
|
|
* detected.
|
|
|
|
|
*/
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-24 14:36:20 +00:00
|
|
|
|
GtkFileFilter * filter; /* filter to use for deciding which nodes are visible */
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
guint frozen; /* number of times we're frozen */
|
2009-06-17 08:39:26 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gboolean filter_on_thaw :1;/* set when filtering needs to happen upon thawing */
|
|
|
|
|
|
|
|
|
|
guint show_hidden :1; /* whether to show hidden files */
|
|
|
|
|
guint show_folders :1;/* whether to show folders */
|
|
|
|
|
guint show_files :1; /* whether to show files */
|
2011-11-07 14:18:40 +00:00
|
|
|
|
guint filter_folders :1;/* whether filter applies to folders */
|
2009-06-30 13:15:55 +00:00
|
|
|
|
};
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
|
|
|
|
#define GTK_FILE_SYSTEM_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_MODEL, GtkFileSystemModelClass))
|
|
|
|
|
#define GTK_IS_FILE_SYSTEM_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_SYSTEM_MODEL))
|
|
|
|
|
#define GTK_FILE_SYSTEM_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_SYSTEM_MODEL, GtkFileSystemModelClass))
|
|
|
|
|
|
|
|
|
|
struct _GtkFileSystemModelClass
|
|
|
|
|
{
|
|
|
|
|
GObjectClass parent_class;
|
2004-03-29 19:52:16 +00:00
|
|
|
|
|
|
|
|
|
/* Signals */
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
void (*finished_loading) (GtkFileSystemModel *model, GError *error);
|
2004-03-29 19:52:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-11-01 23:21:47 +00:00
|
|
|
|
static void freeze_updates (GtkFileSystemModel *model);
|
|
|
|
|
static void thaw_updates (GtkFileSystemModel *model);
|
|
|
|
|
|
2012-11-01 02:54:02 +00:00
|
|
|
|
static guint node_get_for_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file);
|
|
|
|
|
|
2009-08-31 20:08:43 +00:00
|
|
|
|
static void add_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFileInfo *info);
|
2009-08-31 20:11:44 +00:00
|
|
|
|
static void remove_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file);
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/* iter setup:
|
|
|
|
|
* @user_data: the model
|
|
|
|
|
* @user_data2: GUINT_TO_POINTER of array index of current entry
|
|
|
|
|
*
|
2020-05-28 08:00:03 +00:00
|
|
|
|
* All other fields are unused. Note that the array index does not correspond
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* 1:1 with the path index as entries might not be visible.
|
|
|
|
|
*/
|
|
|
|
|
#define ITER_INDEX(iter) GPOINTER_TO_UINT((iter)->user_data2)
|
|
|
|
|
#define ITER_IS_VALID(model, iter) ((model) == (iter)->user_data)
|
|
|
|
|
#define ITER_INIT_FROM_INDEX(model, _iter, _index) G_STMT_START {\
|
|
|
|
|
g_assert (_index < (model)->files->len); \
|
|
|
|
|
(_iter)->user_data = (model); \
|
|
|
|
|
(_iter)->user_data2 = GUINT_TO_POINTER (_index); \
|
|
|
|
|
}G_STMT_END
|
2004-03-29 19:52:16 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/*** FileModelNode ***/
|
2004-03-29 19:52:16 +00:00
|
|
|
|
|
2009-09-03 23:22:21 +00:00
|
|
|
|
/* Get a FileModelNode structure given an index in the model->files array of nodes */
|
2022-10-12 12:18:39 +00:00
|
|
|
|
#define get_node(_model, _index) ((FileModelNode *) ((_model)->files->data + (_index) * sizeof (FileModelNode)))
|
2009-09-03 23:22:21 +00:00
|
|
|
|
|
|
|
|
|
/* Get an index within the model->files array of nodes, given a FileModelNode* */
|
2022-10-12 12:18:39 +00:00
|
|
|
|
#define node_index(_model, _node) (((char *) (_node) - (_model)->files->data) / sizeof (FileModelNode))
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2009-09-04 17:01:16 +00:00
|
|
|
|
/* @up_to_index: smallest model->files array index that will be valid after this call
|
|
|
|
|
* @up_to_row: smallest node->row that will be valid after this call
|
2009-09-03 23:22:21 +00:00
|
|
|
|
*
|
2009-09-04 17:01:16 +00:00
|
|
|
|
* If you want to validate up to an index or up to a row, specify the index or
|
|
|
|
|
* the row you want and specify G_MAXUINT for the other argument. Pass
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* G_MAXUINT for both arguments for “validate everything”.
|
2009-09-03 23:22:21 +00:00
|
|
|
|
*/
|
2003-03-21 20:34:02 +00:00
|
|
|
|
static void
|
2009-09-04 17:01:16 +00:00
|
|
|
|
node_validate_rows (GtkFileSystemModel *model, guint up_to_index, guint up_to_row)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-09-04 17:01:16 +00:00
|
|
|
|
guint i, row;
|
2004-03-29 19:52:16 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (model->files->len == 0)
|
|
|
|
|
return;
|
2009-09-04 17:01:16 +00:00
|
|
|
|
|
|
|
|
|
up_to_index = MIN (up_to_index, model->files->len - 1);
|
|
|
|
|
|
|
|
|
|
i = model->n_nodes_valid;
|
|
|
|
|
if (i != 0)
|
|
|
|
|
row = get_node (model, i - 1)->row;
|
2009-06-30 13:15:55 +00:00
|
|
|
|
else
|
2009-09-04 17:01:16 +00:00
|
|
|
|
row = 0;
|
|
|
|
|
|
|
|
|
|
while (i <= up_to_index && row <= up_to_row)
|
2009-06-30 13:15:55 +00:00
|
|
|
|
{
|
2009-09-04 17:01:16 +00:00
|
|
|
|
FileModelNode *node = get_node (model, i);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (node->visible)
|
2009-09-04 17:01:16 +00:00
|
|
|
|
row++;
|
|
|
|
|
node->row = row;
|
|
|
|
|
i++;
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
2009-09-04 17:01:16 +00:00
|
|
|
|
model->n_nodes_valid = i;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-21 14:40:51 +00:00
|
|
|
|
static guint G_GNUC_UNUSED
|
2009-09-04 17:01:16 +00:00
|
|
|
|
node_get_tree_row (GtkFileSystemModel *model, guint index)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-09-04 17:01:16 +00:00
|
|
|
|
if (model->n_nodes_valid <= index)
|
|
|
|
|
node_validate_rows (model, index, G_MAXUINT);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
2009-09-04 17:01:16 +00:00
|
|
|
|
return get_node (model, index)->row - 1;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
node_invalidate_index (GtkFileSystemModel *model, guint id)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-09-04 17:01:16 +00:00
|
|
|
|
model->n_nodes_valid = MIN (model->n_nodes_valid, id);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-08 07:25:02 +00:00
|
|
|
|
static void
|
2012-07-11 21:32:52 +00:00
|
|
|
|
node_set_visible_and_filtered_out (GtkFileSystemModel *model, guint id, gboolean visible, gboolean filtered_out)
|
2012-07-08 07:25:02 +00:00
|
|
|
|
{
|
|
|
|
|
FileModelNode *node = get_node (model, id);
|
|
|
|
|
|
2012-07-11 21:32:52 +00:00
|
|
|
|
/* Filteredness */
|
2012-07-08 07:25:02 +00:00
|
|
|
|
|
2022-10-11 02:19:40 +00:00
|
|
|
|
g_file_info_set_attribute_boolean (node->info, "filechooser::filtered-out", filtered_out);
|
|
|
|
|
|
2012-07-15 04:37:41 +00:00
|
|
|
|
if (node->filtered_out != filtered_out)
|
|
|
|
|
{
|
|
|
|
|
node->filtered_out = filtered_out;
|
|
|
|
|
}
|
2009-09-02 22:10:46 +00:00
|
|
|
|
|
2012-07-11 21:32:52 +00:00
|
|
|
|
/* Visibility */
|
2022-10-11 02:19:40 +00:00
|
|
|
|
|
|
|
|
|
g_file_info_set_attribute_boolean (node->info, "filechooser::visible", visible);
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (node->visible == visible ||
|
|
|
|
|
node->frozen_add)
|
|
|
|
|
return;
|
2004-01-22 02:39:31 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (visible)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
node->visible = TRUE;
|
|
|
|
|
node_invalidate_index (model, id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-10-21 11:44:13 +00:00
|
|
|
|
g_assert (node_get_tree_row (model, id) < model->files->len);
|
2009-09-02 22:10:46 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
node->visible = FALSE;
|
|
|
|
|
node_invalidate_index (model, id);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static gboolean
|
2012-07-11 20:47:53 +00:00
|
|
|
|
node_should_be_filtered_out (GtkFileSystemModel *model, guint id)
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
FileModelNode *node = get_node (model, id);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (node->info == NULL)
|
2012-07-08 07:25:02 +00:00
|
|
|
|
return TRUE;
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
2009-06-24 14:36:20 +00:00
|
|
|
|
if (model->filter == NULL)
|
2012-07-08 07:25:02 +00:00
|
|
|
|
return FALSE;
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
2022-10-09 21:50:23 +00:00
|
|
|
|
g_assert (g_file_info_has_attribute (node->info, "standard::file"));
|
2009-06-24 14:36:20 +00:00
|
|
|
|
|
2020-07-04 15:05:43 +00:00
|
|
|
|
return !gtk_filter_match (GTK_FILTER (model->filter), node->info);
|
2004-02-25 03:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-08 07:25:02 +00:00
|
|
|
|
static gboolean
|
2012-07-11 21:32:52 +00:00
|
|
|
|
node_should_be_visible (GtkFileSystemModel *model, guint id, gboolean filtered_out)
|
2012-07-08 07:25:02 +00:00
|
|
|
|
{
|
|
|
|
|
FileModelNode *node = get_node (model, id);
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
if (node->info == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!model->show_hidden &&
|
|
|
|
|
(g_file_info_get_is_hidden (node->info) || g_file_info_get_is_backup (node->info)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (_gtk_file_info_consider_as_directory (node->info))
|
|
|
|
|
{
|
|
|
|
|
if (!model->show_folders)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!model->filter_folders)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!model->show_files)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-11 21:32:52 +00:00
|
|
|
|
result = !filtered_out;
|
2012-07-08 07:25:02 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-11 21:32:52 +00:00
|
|
|
|
static void
|
|
|
|
|
node_compute_visibility_and_filters (GtkFileSystemModel *model, guint id)
|
|
|
|
|
{
|
|
|
|
|
gboolean filtered_out;
|
|
|
|
|
gboolean visible;
|
|
|
|
|
|
|
|
|
|
filtered_out = node_should_be_filtered_out (model, id);
|
|
|
|
|
visible = node_should_be_visible (model, id, filtered_out);
|
|
|
|
|
|
|
|
|
|
node_set_visible_and_filtered_out (model, id, visible, filtered_out);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 19:52:56 +00:00
|
|
|
|
/*** GListModel ***/
|
|
|
|
|
|
|
|
|
|
static GType
|
|
|
|
|
list_model_get_item_type (GListModel *list_model)
|
|
|
|
|
{
|
2022-10-09 21:52:12 +00:00
|
|
|
|
return G_TYPE_FILE_INFO;
|
2022-10-07 19:52:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static guint
|
|
|
|
|
list_model_get_n_items (GListModel *list_model)
|
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model = GTK_FILE_SYSTEM_MODEL (list_model);
|
|
|
|
|
|
|
|
|
|
return model->files->len - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
|
list_model_get_item (GListModel *list_model,
|
|
|
|
|
guint position)
|
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model = GTK_FILE_SYSTEM_MODEL (list_model);
|
|
|
|
|
FileModelNode *node;
|
|
|
|
|
|
|
|
|
|
/* The first items of GtkFileSystemModel is not really a file,
|
|
|
|
|
* so ignore it. */
|
|
|
|
|
if (position + 1 >= model->files->len)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
node = get_node (model, position + 1);
|
2022-10-09 21:52:12 +00:00
|
|
|
|
return g_object_ref (node->info);
|
2022-10-07 19:52:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_list_model_iface_init (GListModelInterface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->get_item_type = list_model_get_item_type;
|
|
|
|
|
iface->get_n_items = list_model_get_n_items;
|
|
|
|
|
iface->get_item = list_model_get_item;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/*** GtkFileSystemModel ***/
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/* Signal IDs */
|
|
|
|
|
enum {
|
|
|
|
|
FINISHED_LOADING,
|
|
|
|
|
LAST_SIGNAL
|
2006-05-01 21:41:12 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static guint file_system_model_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkFileSystemModel, _gtk_file_system_model, G_TYPE_OBJECT,
|
2022-10-07 19:52:56 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
|
|
|
|
|
g_list_model_iface_init))
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
|
static void
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gtk_file_system_model_dispose (GObject *object)
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GtkFileSystemModel *model = GTK_FILE_SYSTEM_MODEL (object);
|
|
|
|
|
|
2009-08-31 20:53:45 +00:00
|
|
|
|
if (model->dir_thaw_source)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (model->dir_thaw_source);
|
|
|
|
|
model->dir_thaw_source = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_cancellable_cancel (model->cancellable);
|
|
|
|
|
if (model->dir_monitor)
|
|
|
|
|
g_file_monitor_cancel (model->dir_monitor);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_file_system_model_parent_class)->dispose (object);
|
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model = GTK_FILE_SYSTEM_MODEL (object);
|
|
|
|
|
guint i;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
for (i = 0; i < model->files->len; i++)
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
FileModelNode *node = get_node (model, i);
|
2022-10-07 20:12:05 +00:00
|
|
|
|
g_clear_object (&node->file);
|
|
|
|
|
g_clear_object (&node->info);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
g_array_free (model->files, TRUE);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2022-10-07 20:12:05 +00:00
|
|
|
|
g_clear_object (&model->cancellable);
|
|
|
|
|
g_clear_pointer (&model->attributes, g_free);
|
|
|
|
|
g_clear_object (&model->dir);
|
|
|
|
|
g_clear_object (&model->dir_monitor);
|
|
|
|
|
g_clear_pointer (&model->file_lookup, g_hash_table_destroy);
|
|
|
|
|
g_clear_object (&model->filter);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_file_system_model_parent_class)->finalize (object);
|
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
_gtk_file_system_model_class_init (GtkFileSystemModelClass *class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gobject_class->finalize = gtk_file_system_model_finalize;
|
|
|
|
|
gobject_class->dispose = gtk_file_system_model_dispose;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
file_system_model_signals[FINISHED_LOADING] =
|
|
|
|
|
g_signal_new (I_("finished-loading"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkFileSystemModelClass, finished_loading),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2021-08-29 03:56:31 +00:00
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_ERROR);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
_gtk_file_system_model_init (GtkFileSystemModel *model)
|
|
|
|
|
{
|
|
|
|
|
model->show_files = TRUE;
|
|
|
|
|
model->show_folders = TRUE;
|
|
|
|
|
model->show_hidden = FALSE;
|
2011-11-07 14:18:40 +00:00
|
|
|
|
model->filter_folders = FALSE;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->file_lookup = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
|
|
|
|
|
model->cancellable = g_cancellable_new ();
|
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/*** API ***/
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_closed_enumerator (GObject *object, GAsyncResult *res, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
g_file_enumerator_close_finish (G_FILE_ENUMERATOR (object), res, NULL);
|
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
thaw_func (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model = data;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2012-11-01 23:21:47 +00:00
|
|
|
|
thaw_updates (model);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->dir_thaw_source = 0;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
return FALSE;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_got_files (GObject *object, GAsyncResult *res, gpointer data)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GFileEnumerator *enumerator = G_FILE_ENUMERATOR (object);
|
|
|
|
|
GtkFileSystemModel *model = data;
|
|
|
|
|
GList *walk, *files;
|
|
|
|
|
GError *error = NULL;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
files = g_file_enumerator_next_files_finish (enumerator, res, &error);
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (files)
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (model->dir_thaw_source == 0)
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2012-11-01 23:21:47 +00:00
|
|
|
|
freeze_updates (model);
|
2018-02-02 14:51:47 +00:00
|
|
|
|
model->dir_thaw_source = g_timeout_add_full (IO_PRIORITY + 1, 50,
|
|
|
|
|
thaw_func,
|
|
|
|
|
model,
|
|
|
|
|
NULL);
|
2021-07-26 21:03:15 +00:00
|
|
|
|
gdk_source_set_static_name_by_id (model->dir_thaw_source, "[gtk] thaw_func");
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
for (walk = files; walk; walk = walk->next)
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
info = walk->data;
|
|
|
|
|
name = g_file_info_get_name (info);
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Shouldn't happen, but the APIs allow it */
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
file = g_file_get_child (model->dir, name);
|
2009-08-31 20:08:43 +00:00
|
|
|
|
add_file (model, file, info);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_object_unref (file);
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
g_list_free (files);
|
2003-04-09 16:52:13 +00:00
|
|
|
|
|
2009-08-31 21:13:05 +00:00
|
|
|
|
g_file_enumerator_next_files_async (enumerator,
|
|
|
|
|
g_file_is_native (model->dir) ? 50 * FILES_PER_QUERY : FILES_PER_QUERY,
|
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_got_files,
|
|
|
|
|
model);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2009-11-02 18:49:11 +00:00
|
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
2009-11-02 18:49:11 +00:00
|
|
|
|
g_file_enumerator_close_async (enumerator,
|
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_closed_enumerator,
|
|
|
|
|
NULL);
|
|
|
|
|
if (model->dir_thaw_source != 0)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (model->dir_thaw_source);
|
|
|
|
|
model->dir_thaw_source = 0;
|
2012-11-01 23:21:47 +00:00
|
|
|
|
thaw_updates (model);
|
2009-11-02 18:49:11 +00:00
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-11-02 18:49:11 +00:00
|
|
|
|
g_signal_emit (model, file_system_model_signals[FINISHED_LOADING], 0, error);
|
|
|
|
|
}
|
2009-08-31 21:13:05 +00:00
|
|
|
|
|
2009-07-01 08:32:26 +00:00
|
|
|
|
if (error)
|
|
|
|
|
g_error_free (error);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-25 21:26:22 +00:00
|
|
|
|
/* Helper for gtk_file_system_model_query_done and
|
|
|
|
|
* gtk_file_system_model_one_query_done */
|
|
|
|
|
static void
|
2020-04-26 21:38:49 +00:00
|
|
|
|
query_done_helper (GObject * object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer data,
|
|
|
|
|
gboolean do_thaw_updates)
|
2020-04-25 21:26:22 +00:00
|
|
|
|
{
|
2022-10-12 03:32:35 +00:00
|
|
|
|
GtkFileSystemModel *model = GTK_FILE_SYSTEM_MODEL (data);
|
2020-04-26 21:38:49 +00:00
|
|
|
|
GFile *file = G_FILE (object);
|
|
|
|
|
GFileInfo *info;
|
2020-04-25 21:26:22 +00:00
|
|
|
|
|
2020-04-26 21:38:49 +00:00
|
|
|
|
info = g_file_query_info_finish (file, res, NULL);
|
2022-10-12 03:32:35 +00:00
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
_gtk_file_system_model_update_file (model, file, info);
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
2020-04-25 21:26:22 +00:00
|
|
|
|
|
2020-04-26 21:38:49 +00:00
|
|
|
|
if (do_thaw_updates)
|
|
|
|
|
thaw_updates (model);
|
2020-04-25 21:26:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
|
static void
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gtk_file_system_model_query_done (GObject * object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer data)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2020-04-26 21:38:49 +00:00
|
|
|
|
query_done_helper (object, res, data, FALSE);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_monitor_change (GFileMonitor * monitor,
|
|
|
|
|
GFile * file,
|
|
|
|
|
GFile * other_file,
|
|
|
|
|
GFileMonitorEvent type,
|
|
|
|
|
GtkFileSystemModel *model)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
switch (type)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
case G_FILE_MONITOR_EVENT_CREATED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_CHANGED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
|
|
|
|
|
/* We can treat all of these the same way */
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
model->attributes,
|
2009-09-02 18:54:52 +00:00
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
2009-06-30 13:15:55 +00:00
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_query_done,
|
|
|
|
|
model);
|
|
|
|
|
break;
|
|
|
|
|
case G_FILE_MONITOR_EVENT_DELETED:
|
2009-08-31 20:11:44 +00:00
|
|
|
|
remove_file (model, file);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
|
|
|
|
/* FIXME: use freeze/thaw with this somehow? */
|
|
|
|
|
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_UNMOUNTED:
|
2017-10-06 19:19:42 +00:00
|
|
|
|
case G_FILE_MONITOR_EVENT_MOVED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_RENAMED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_MOVED_IN:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_MOVED_OUT:
|
2009-06-30 13:15:55 +00:00
|
|
|
|
default:
|
|
|
|
|
/* ignore these */
|
|
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_got_enumerator (GObject *dir, GAsyncResult *res, gpointer data)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GtkFileSystemModel *model = data;
|
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
|
GError *error = NULL;
|
2004-03-01 19:48:28 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
enumerator = g_file_enumerate_children_finish (G_FILE (dir), res, &error);
|
|
|
|
|
if (enumerator == NULL)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2010-03-29 14:26:14 +00:00
|
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (model, file_system_model_signals[FINISHED_LOADING], 0, error);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
2009-06-30 13:15:55 +00:00
|
|
|
|
else
|
2003-04-09 16:52:13 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_file_enumerator_next_files_async (enumerator,
|
|
|
|
|
g_file_is_native (model->dir) ? 50 * FILES_PER_QUERY : FILES_PER_QUERY,
|
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_got_files,
|
|
|
|
|
model);
|
|
|
|
|
g_object_unref (enumerator);
|
|
|
|
|
model->dir_monitor = g_file_monitor_directory (model->dir,
|
2009-08-27 00:25:18 +00:00
|
|
|
|
G_FILE_MONITOR_NONE,
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->cancellable,
|
2009-08-27 00:25:18 +00:00
|
|
|
|
NULL); /* we don't mind if directory monitoring isn't supported, so the GError is NULL here */
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (model->dir_monitor)
|
|
|
|
|
g_signal_connect (model->dir_monitor,
|
|
|
|
|
"changed",
|
|
|
|
|
G_CALLBACK (gtk_file_system_model_monitor_change),
|
|
|
|
|
model);
|
2003-04-09 16:52:13 +00:00
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gtk_file_system_model_set_directory (GtkFileSystemModel *model,
|
|
|
|
|
GFile * dir,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char * attributes)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-08-27 00:10:51 +00:00
|
|
|
|
g_assert (G_IS_FILE (dir));
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
|
|
|
|
model->dir = g_object_ref (dir);
|
|
|
|
|
model->attributes = g_strdup (attributes);
|
|
|
|
|
|
|
|
|
|
g_file_enumerate_children_async (model->dir,
|
|
|
|
|
attributes,
|
2009-08-27 00:14:07 +00:00
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
2009-06-30 13:15:55 +00:00
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_got_enumerator,
|
|
|
|
|
model);
|
2003-04-09 16:52:13 +00:00
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_new:
|
2009-06-24 16:41:03 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* Creates a new `GtkFileSystemModel` object. You need to add files
|
2009-08-31 20:08:43 +00:00
|
|
|
|
* to the list using _gtk_file_system_model_add_and_query_file()
|
|
|
|
|
* or _gtk_file_system_model_update_file().
|
2009-06-24 16:41:03 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* Returns: the newly created `GtkFileSystemModel`
|
2009-06-24 16:41:03 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkFileSystemModel *
|
2022-10-12 12:18:39 +00:00
|
|
|
|
_gtk_file_system_model_new (void)
|
2009-06-24 16:41:03 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model;
|
|
|
|
|
|
2022-10-12 12:18:39 +00:00
|
|
|
|
model = g_object_new (GTK_TYPE_FILE_SYSTEM_MODEL, NULL);
|
2009-06-24 16:41:03 +00:00
|
|
|
|
|
2022-10-12 12:18:39 +00:00
|
|
|
|
model->files = g_array_sized_new (FALSE, FALSE, sizeof (FileModelNode), FILES_PER_QUERY);
|
|
|
|
|
/* add editable node at start */
|
|
|
|
|
g_array_set_size (model->files, 1);
|
|
|
|
|
memset (get_node (model, 0), 0, sizeof (FileModelNode));
|
2009-06-24 16:41:03 +00:00
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_new_for_directory:
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* @directory: the directory to show.
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @attributes: (nullable): attributes to immediately load or %NULL for all
|
2009-06-30 13:15:55 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* Creates a new `GtkFileSystemModel` object.
|
|
|
|
|
*
|
|
|
|
|
* The `GtkFileSystemModel` object wraps the given @directory as a
|
|
|
|
|
* `GtkTreeModel`. 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
|
2009-06-24 16:41:03 +00:00
|
|
|
|
* contents to reflect changes, if the @directory supports monitoring.
|
2021-05-20 13:17:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: the newly created `GtkFileSystemModel`
|
2009-06-30 13:15:55 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkFileSystemModel *
|
2022-10-12 12:18:39 +00:00
|
|
|
|
_gtk_file_system_model_new_for_directory (GFile *dir,
|
|
|
|
|
const char *attributes)
|
2006-05-01 21:41:12 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model;
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_return_val_if_fail (G_IS_FILE (dir), NULL);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2022-10-12 12:18:39 +00:00
|
|
|
|
model = _gtk_file_system_model_new ();
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gtk_file_system_model_set_directory (model, dir, attributes);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
return model;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_refilter_all (GtkFileSystemModel *model)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
guint i;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (model->frozen)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->filter_on_thaw = TRUE;
|
|
|
|
|
return;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 23:21:47 +00:00
|
|
|
|
freeze_updates (model);
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/* start at index 1, don't change the editable */
|
|
|
|
|
for (i = 1; i < model->files->len; i++)
|
2012-07-11 21:32:52 +00:00
|
|
|
|
node_compute_visibility_and_filters (model, i);
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->filter_on_thaw = FALSE;
|
2012-11-01 23:21:47 +00:00
|
|
|
|
thaw_updates (model);
|
2008-06-10 00:39:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_set_show_hidden:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* @show_hidden: whether hidden files should be displayed
|
2021-05-20 13:17:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets whether hidden files should be included in the `GtkTreeModel`
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* for display.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_set_show_hidden (GtkFileSystemModel *model,
|
|
|
|
|
gboolean show_hidden)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
show_hidden = show_hidden != FALSE;
|
2003-03-26 16:24:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (show_hidden != model->show_hidden)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->show_hidden = show_hidden;
|
|
|
|
|
gtk_file_system_model_refilter_all (model);
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_set_show_folders:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* @show_folders: whether folders should be displayed
|
2021-05-20 13:17:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets whether folders should be included in the `GtkTreeModel`
|
|
|
|
|
* for display.
|
|
|
|
|
*/
|
2009-06-30 13:15:55 +00:00
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_set_show_folders (GtkFileSystemModel *model,
|
|
|
|
|
gboolean show_folders)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
|
|
|
|
|
show_folders = show_folders != FALSE;
|
|
|
|
|
|
|
|
|
|
if (show_folders != model->show_folders)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->show_folders = show_folders;
|
|
|
|
|
gtk_file_system_model_refilter_all (model);
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
2003-03-26 16:24:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_set_show_files:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* @show_files: whether files (as opposed to folders) should be displayed.
|
|
|
|
|
*
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* Sets whether files (as opposed to folders) should be included
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* in the `GtkTreeModel` for display.
|
|
|
|
|
*/
|
2009-06-30 13:15:55 +00:00
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_set_show_files (GtkFileSystemModel *model,
|
|
|
|
|
gboolean show_files)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
|
|
|
|
|
show_files = show_files != FALSE;
|
|
|
|
|
|
|
|
|
|
if (show_files != model->show_files)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
model->show_files = show_files;
|
|
|
|
|
gtk_file_system_model_refilter_all (model);
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
2003-03-26 16:24:35 +00:00
|
|
|
|
|
2011-11-07 14:18:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_set_filter_folders:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2011-11-07 14:18:40 +00:00
|
|
|
|
* @filter_folders: whether the filter applies to folders
|
2021-05-20 13:17:04 +00:00
|
|
|
|
*
|
2011-11-07 14:18:40 +00:00
|
|
|
|
* Sets whether the filter set by _gtk_file_system_model_set_filter()
|
|
|
|
|
* applies to folders. By default, it does not and folders are always
|
|
|
|
|
* visible.
|
2021-05-20 13:17:04 +00:00
|
|
|
|
*/
|
2011-11-07 14:18:40 +00:00
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_set_filter_folders (GtkFileSystemModel *model,
|
|
|
|
|
gboolean filter_folders)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
|
|
|
|
|
filter_folders = filter_folders != FALSE;
|
|
|
|
|
|
|
|
|
|
if (filter_folders != model->filter_folders)
|
|
|
|
|
{
|
|
|
|
|
model->filter_folders = filter_folders;
|
|
|
|
|
gtk_file_system_model_refilter_all (model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-01 08:32:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_get_cancellable:
|
|
|
|
|
* @model: the model
|
|
|
|
|
*
|
|
|
|
|
* Gets the cancellable used by the @model. This is the cancellable used
|
|
|
|
|
* internally by the @model that will be cancelled when @model is
|
|
|
|
|
* disposed. So you can use it for operations that should be cancelled
|
|
|
|
|
* when the model goes away.
|
|
|
|
|
*
|
|
|
|
|
* Returns: The cancellable used by @model
|
|
|
|
|
**/
|
2009-06-30 13:15:55 +00:00
|
|
|
|
GCancellable *
|
|
|
|
|
_gtk_file_system_model_get_cancellable (GtkFileSystemModel *model)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model), NULL);
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
return model->cancellable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static guint
|
|
|
|
|
node_get_for_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile * file)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
2003-03-27 00:10:25 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
i = GPOINTER_TO_UINT (g_hash_table_lookup (model->file_lookup, file));
|
|
|
|
|
if (i != 0)
|
|
|
|
|
return i;
|
|
|
|
|
|
2009-09-02 19:51:02 +00:00
|
|
|
|
/* Node 0 is the editable row and has no associated file or entry in the table, so we start counting from 1.
|
|
|
|
|
*
|
|
|
|
|
* The invariant here is that the files in model->files[n] for n < g_hash_table_size (model->file_lookup)
|
2022-10-08 15:25:10 +00:00
|
|
|
|
* are already added to the hash table. this loop merely rebuilds our (file -> index) mapping on demand.
|
2009-09-02 19:51:02 +00:00
|
|
|
|
*
|
|
|
|
|
* If we exit the loop, the next pending batch of mappings will be resolved when this function gets called again
|
|
|
|
|
* with another file that is not yet in the mapping.
|
|
|
|
|
*/
|
2009-06-30 13:15:55 +00:00
|
|
|
|
for (i = g_hash_table_size (model->file_lookup) + 1; i < model->files->len; i++)
|
2003-03-27 00:10:25 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
FileModelNode *node = get_node (model, i);
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_hash_table_insert (model->file_lookup, node->file, GUINT_TO_POINTER (i));
|
|
|
|
|
if (g_file_equal (node->file, file))
|
|
|
|
|
return i;
|
2003-03-27 00:10:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
return 0;
|
2003-03-27 00:10:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 21:52:12 +00:00
|
|
|
|
GFileInfo *
|
|
|
|
|
_gtk_file_system_model_get_info_for_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file)
|
|
|
|
|
{
|
|
|
|
|
FileModelNode *node;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
|
|
|
|
|
i = node_get_for_file (model, file);
|
|
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
node = get_node (model, i);
|
|
|
|
|
return node->info;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 23:48:23 +00:00
|
|
|
|
/* When an element is added or removed to the model->files array, we need to
|
|
|
|
|
* update the model->file_lookup mappings of (node, index), as the indexes
|
|
|
|
|
* change. This function adds the specified increment to the index in that pair
|
|
|
|
|
* if the index is equal or after the specified id. We use this to slide the
|
|
|
|
|
* mappings up or down when a node is added or removed, respectively.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
adjust_file_lookup (GtkFileSystemModel *model, guint id, int increment)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer key;
|
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, model->file_lookup);
|
|
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
|
{
|
|
|
|
|
guint index = GPOINTER_TO_UINT (value);
|
|
|
|
|
|
|
|
|
|
if (index >= id)
|
|
|
|
|
{
|
|
|
|
|
index += increment;
|
|
|
|
|
g_hash_table_iter_replace (&iter, GUINT_TO_POINTER (index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
2009-08-31 20:08:43 +00:00
|
|
|
|
* add_file:
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* @model: the model
|
|
|
|
|
* @file: the file to add
|
|
|
|
|
* @info: the information to associate with the file
|
|
|
|
|
*
|
|
|
|
|
* Adds the given @file with its associated @info to the @model.
|
|
|
|
|
* If the model is frozen, the file will only show up after it is thawn.
|
|
|
|
|
**/
|
2009-08-31 20:08:43 +00:00
|
|
|
|
static void
|
|
|
|
|
add_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFileInfo *info)
|
2009-06-30 13:15:55 +00:00
|
|
|
|
{
|
|
|
|
|
FileModelNode *node;
|
2022-10-07 19:52:56 +00:00
|
|
|
|
guint position;
|
2003-03-27 00:10:25 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
g_return_if_fail (G_IS_FILE_INFO (info));
|
2003-03-27 00:10:25 +00:00
|
|
|
|
|
2022-10-12 12:18:39 +00:00
|
|
|
|
node = g_slice_alloc0 (sizeof (FileModelNode));
|
2009-06-30 13:15:55 +00:00
|
|
|
|
node->file = g_object_ref (file);
|
|
|
|
|
if (info)
|
2022-10-09 21:50:23 +00:00
|
|
|
|
{
|
|
|
|
|
g_file_info_set_attribute_object (info, "standard::file", G_OBJECT (file));
|
|
|
|
|
node->info = g_object_ref (info);
|
|
|
|
|
}
|
2009-06-30 13:15:55 +00:00
|
|
|
|
node->frozen_add = model->frozen ? TRUE : FALSE;
|
2008-06-10 00:39:35 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_array_append_vals (model->files, node, 1);
|
2022-10-12 12:18:39 +00:00
|
|
|
|
g_slice_free1 (sizeof (FileModelNode), node);
|
2003-03-27 00:10:25 +00:00
|
|
|
|
|
2022-10-07 19:52:56 +00:00
|
|
|
|
position = model->files->len - 1;
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (!model->frozen)
|
2012-07-11 21:32:52 +00:00
|
|
|
|
node_compute_visibility_and_filters (model, model->files->len -1);
|
|
|
|
|
|
2022-10-07 19:52:56 +00:00
|
|
|
|
/* Ignore the first item */
|
|
|
|
|
g_list_model_items_changed (G_LIST_MODEL (model), position - 1, 0, 1);
|
2003-03-27 00:10:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
2009-08-31 20:11:44 +00:00
|
|
|
|
* remove_file:
|
2009-06-30 13:15:55 +00:00
|
|
|
|
* @model: the model
|
|
|
|
|
* @file: file to remove from the model. The file must have been
|
|
|
|
|
* added to the model previously
|
|
|
|
|
*
|
|
|
|
|
* Removes the given file from the model. If the file is not part of
|
|
|
|
|
* @model, this function does nothing.
|
|
|
|
|
**/
|
2009-08-31 20:11:44 +00:00
|
|
|
|
static void
|
|
|
|
|
remove_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file)
|
2003-03-27 00:10:25 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
FileModelNode *node;
|
|
|
|
|
guint id;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
|
|
id = node_get_for_file (model, file);
|
|
|
|
|
if (id == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
node = get_node (model, id);
|
2012-11-01 23:48:23 +00:00
|
|
|
|
|
|
|
|
|
node_invalidate_index (model, id);
|
2009-09-02 20:21:45 +00:00
|
|
|
|
|
|
|
|
|
g_hash_table_remove (model->file_lookup, file);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_object_unref (node->file);
|
2012-11-01 23:48:23 +00:00
|
|
|
|
adjust_file_lookup (model, id, -1);
|
2009-09-02 20:21:45 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
if (node->info)
|
|
|
|
|
g_object_unref (node->info);
|
2009-09-02 20:21:45 +00:00
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_array_remove_index (model->files, id);
|
2012-11-01 23:48:23 +00:00
|
|
|
|
|
2022-10-07 19:52:56 +00:00
|
|
|
|
g_list_model_items_changed (G_LIST_MODEL (model), id - 1, 1, 0);
|
2003-03-27 00:10:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_update_file:
|
|
|
|
|
* @model: the model
|
|
|
|
|
* @file: the file
|
|
|
|
|
* @info: the new file info
|
|
|
|
|
*
|
|
|
|
|
* Tells the file system model that the file changed and that the
|
|
|
|
|
* new @info should be used for it now. If the file is not part of
|
|
|
|
|
* @model, it will get added automatically.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_update_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file,
|
2012-11-01 02:54:02 +00:00
|
|
|
|
GFileInfo *info)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
FileModelNode *node;
|
2022-10-12 12:18:39 +00:00
|
|
|
|
guint id;
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
g_return_if_fail (G_IS_FILE_INFO (info));
|
|
|
|
|
|
|
|
|
|
id = node_get_for_file (model, file);
|
|
|
|
|
if (id == 0)
|
2010-08-24 18:17:15 +00:00
|
|
|
|
{
|
|
|
|
|
add_file (model, file, info);
|
|
|
|
|
id = node_get_for_file (model, file);
|
|
|
|
|
}
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
|
|
|
|
node = get_node (model, id);
|
2009-09-02 20:23:21 +00:00
|
|
|
|
|
2022-10-09 21:49:37 +00:00
|
|
|
|
g_set_object (&node->info, info);
|
2009-09-02 20:23:21 +00:00
|
|
|
|
|
2022-10-09 21:50:23 +00:00
|
|
|
|
g_file_info_set_attribute_object (info, "standard::file", G_OBJECT (file));
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 19:18:30 +00:00
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_update_files (GtkFileSystemModel *model,
|
|
|
|
|
GList *files,
|
|
|
|
|
GList *infos)
|
|
|
|
|
{
|
|
|
|
|
GList *l, *i;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
|
|
|
|
|
freeze_updates (model);
|
|
|
|
|
|
|
|
|
|
for (l = files, i = infos; l; l = l->next, i = i->next)
|
|
|
|
|
_gtk_file_system_model_update_file (model, (GFile *)l->data, (GFileInfo *)i->data);
|
|
|
|
|
|
|
|
|
|
thaw_updates (model);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_set_filter:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @mode: a `GtkFileSystemModel`
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @filter: (nullable): %NULL or filter to use
|
2009-06-30 13:15:55 +00:00
|
|
|
|
*
|
2009-06-24 14:36:20 +00:00
|
|
|
|
* Sets a filter to be used for deciding if a row should be visible or not.
|
2011-11-07 14:18:40 +00:00
|
|
|
|
* Whether this filter applies to directories can be toggled with
|
|
|
|
|
* _gtk_file_system_model_set_filter_folders().
|
2009-06-30 13:15:55 +00:00
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_set_filter (GtkFileSystemModel *model,
|
2009-06-24 14:36:20 +00:00
|
|
|
|
GtkFileFilter * filter)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-09-10 22:22:12 +00:00
|
|
|
|
GtkFileFilter *old_filter;
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
2009-06-24 14:36:20 +00:00
|
|
|
|
g_return_if_fail (filter == NULL || GTK_IS_FILE_FILTER (filter));
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
2009-06-24 14:36:20 +00:00
|
|
|
|
if (filter)
|
|
|
|
|
g_object_ref (filter);
|
2009-09-10 22:22:12 +00:00
|
|
|
|
|
|
|
|
|
old_filter = model->filter;
|
2009-06-24 14:36:20 +00:00
|
|
|
|
model->filter = filter;
|
2009-06-30 13:15:55 +00:00
|
|
|
|
|
2009-09-10 22:22:12 +00:00
|
|
|
|
if (old_filter)
|
|
|
|
|
g_object_unref (old_filter);
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gtk_file_system_model_refilter_all (model);
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
2012-11-01 23:21:47 +00:00
|
|
|
|
* freeze_updates:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2009-06-30 13:15:55 +00:00
|
|
|
|
*
|
2012-11-01 23:21:47 +00:00
|
|
|
|
* Freezes most updates on the model, so that performing multiple operations on
|
|
|
|
|
* the files in the model do not cause any events. Use thaw_updates() to resume
|
|
|
|
|
* proper operations. It is fine to call this function multiple times as long as
|
|
|
|
|
* freeze and thaw calls are balanced.
|
2009-06-30 13:15:55 +00:00
|
|
|
|
**/
|
2012-11-01 23:21:47 +00:00
|
|
|
|
static void
|
|
|
|
|
freeze_updates (GtkFileSystemModel *model)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
|
|
|
|
|
model->frozen++;
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 13:15:55 +00:00
|
|
|
|
/**
|
2012-11-01 23:21:47 +00:00
|
|
|
|
* thaw_updates:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2009-06-30 13:15:55 +00:00
|
|
|
|
*
|
2012-11-01 23:21:47 +00:00
|
|
|
|
* Undoes the effect of a previous call to freeze_updates()
|
2009-06-30 13:15:55 +00:00
|
|
|
|
**/
|
2012-11-01 23:21:47 +00:00
|
|
|
|
static void
|
|
|
|
|
thaw_updates (GtkFileSystemModel *model)
|
2003-03-26 16:24:35 +00:00
|
|
|
|
{
|
2009-06-30 13:15:55 +00:00
|
|
|
|
gboolean stuff_added;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
g_return_if_fail (model->frozen > 0);
|
|
|
|
|
|
|
|
|
|
model->frozen--;
|
|
|
|
|
if (model->frozen > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
stuff_added = get_node (model, model->files->len - 1)->frozen_add;
|
|
|
|
|
|
|
|
|
|
if (model->filter_on_thaw)
|
|
|
|
|
gtk_file_system_model_refilter_all (model);
|
|
|
|
|
if (stuff_added)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < model->files->len; i++)
|
|
|
|
|
{
|
|
|
|
|
FileModelNode *node = get_node (model, i);
|
|
|
|
|
|
|
|
|
|
if (!node->frozen_add)
|
|
|
|
|
continue;
|
|
|
|
|
node->frozen_add = FALSE;
|
2012-07-11 21:32:52 +00:00
|
|
|
|
node_compute_visibility_and_filters (model, i);
|
2009-06-30 13:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-26 16:24:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-24 20:43:14 +00:00
|
|
|
|
/**
|
|
|
|
|
* _gtk_file_system_model_add_and_query_file:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @model: a `GtkFileSystemModel`
|
2009-06-24 20:43:14 +00:00
|
|
|
|
* @file: the file to add
|
|
|
|
|
* @attributes: attributes to query before adding the file
|
|
|
|
|
*
|
2020-05-28 08:00:03 +00:00
|
|
|
|
* This is a convenience function that calls g_file_query_info_async() on
|
2009-08-31 20:08:43 +00:00
|
|
|
|
* the given file, and when successful, adds it to the model.
|
|
|
|
|
* Upon failure, the @file is discarded.
|
2009-06-24 20:43:14 +00:00
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_add_and_query_file (GtkFileSystemModel *model,
|
|
|
|
|
GFile * file,
|
|
|
|
|
const char * attributes)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
|
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
attributes,
|
2009-09-02 18:54:52 +00:00
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
2009-06-24 20:43:14 +00:00
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_query_done,
|
|
|
|
|
model);
|
|
|
|
|
}
|
2015-06-18 16:19:06 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_system_model_one_query_done (GObject * object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
2020-04-26 21:38:49 +00:00
|
|
|
|
query_done_helper (object, res, data, TRUE);
|
2015-06-18 16:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_file_system_model_add_and_query_files (GtkFileSystemModel *model,
|
|
|
|
|
GList *list,
|
|
|
|
|
const char *attributes)
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
|
|
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
|
|
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
file = (GFile *)l->data;
|
|
|
|
|
freeze_updates (model);
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
attributes,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
IO_PRIORITY,
|
|
|
|
|
model->cancellable,
|
|
|
|
|
gtk_file_system_model_one_query_done,
|
|
|
|
|
model);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-02 23:12:22 +00:00
|
|
|
|
|
|
|
|
|
GFile *
|
|
|
|
|
_gtk_file_system_model_get_directory (GtkFileSystemModel *model)
|
|
|
|
|
{
|
2015-07-05 19:26:48 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model), NULL);
|
2015-07-02 23:12:22 +00:00
|
|
|
|
|
|
|
|
|
return model->dir;
|
|
|
|
|
}
|
|
|
|
|
|