Bug Summary

File:plugins/filebrowser/lapiz-file-browser-store.c
Warning:line 2066, column 8
Although the value stored to 'node' is used in the enclosing expression, the value is never actually read from 'node'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name lapiz-file-browser-store.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/plugins/filebrowser -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I ../.. -I ../.. -I /usr/include/libxml2 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/local/include/ctksourceview-4 -I /usr/local/include/libbean-1.0 -I /usr/include/gobject-introspection-1.0 -D PIC -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/plugins/filebrowser -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-08-16-235558-33763-1 -x c lapiz-file-browser-store.c
1/*
2 * lapiz-file-browser-store.c - Lapiz plugin providing easy file access
3 * from the sidepanel
4 *
5 * Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#ifdef HAVE_CONFIG_H1
23#include <config.h>
24#endif
25
26#include <string.h>
27#include <glib/gi18n-lib.h>
28#include <gio/gio.h>
29
30#include "lapiz-file-browser-store.h"
31#include "lapiz-file-browser-marshal.h"
32#include "lapiz-file-browser-enum-types.h"
33#include "lapiz-file-browser-error.h"
34#include "lapiz-file-browser-utils.h"
35
36#define NODE_IS_DIR(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
(FILE_IS_DIR((node)->flags)((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
)
)
37#define NODE_IS_HIDDEN(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN
))
(FILE_IS_HIDDEN((node)->flags)((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN
)
)
38#define NODE_IS_TEXT(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_TEXT
))
(FILE_IS_TEXT((node)->flags)((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_TEXT
)
)
39#define NODE_LOADED(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED
))
(FILE_LOADED((node)->flags)((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED))
40#define NODE_IS_FILTERED(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED
))
(FILE_IS_FILTERED((node)->flags)((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED
)
)
41#define NODE_IS_DUMMY(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
(FILE_IS_DUMMY((node)->flags)((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
)
)
42
43#define FILE_BROWSER_NODE_DIR(node)((FileBrowserNodeDir *)(node)) ((FileBrowserNodeDir *)(node))
44
45#define DIRECTORY_LOAD_ITEMS_PER_CALLBACK100 100
46#define STANDARD_ATTRIBUTE_TYPES"standard::type" "," "standard::is-hidden" "," "standard::is-backup"
"," "standard::name" "," "standard::content-type" "," "standard::icon"
G_FILE_ATTRIBUTE_STANDARD_TYPE"standard::type" "," \
47 G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN"standard::is-hidden" "," \
48 G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP"standard::is-backup" "," \
49 G_FILE_ATTRIBUTE_STANDARD_NAME"standard::name" "," \
50 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"standard::content-type" "," \
51 G_FILE_ATTRIBUTE_STANDARD_ICON"standard::icon"
52
53typedef struct _FileBrowserNode FileBrowserNode;
54typedef struct _FileBrowserNodeDir FileBrowserNodeDir;
55typedef struct _AsyncData AsyncData;
56typedef struct _AsyncNode AsyncNode;
57
58typedef gint (*SortFunc) (FileBrowserNode * node1,
59 FileBrowserNode * node2);
60
61struct _AsyncData
62{
63 LapizFileBrowserStore * model;
64 GCancellable * cancellable;
65 gboolean trash;
66 GList * files;
67 GList * iter;
68 gboolean removed;
69};
70
71struct _AsyncNode
72{
73 FileBrowserNodeDir *dir;
74 GCancellable *cancellable;
75 GSList *original_children;
76};
77
78typedef struct {
79 LapizFileBrowserStore * model;
80 gchar * virtual_root;
81 GMountOperation * operation;
82 GCancellable * cancellable;
83} MountInfo;
84
85struct _FileBrowserNode
86{
87 GFile *file;
88 guint flags;
89 gchar *name;
90
91 GdkPixbuf *icon;
92 GdkPixbuf *emblem;
93
94 FileBrowserNode *parent;
95 gint pos;
96 gboolean inserted;
97};
98
99struct _FileBrowserNodeDir
100{
101 FileBrowserNode node;
102 GSList *children;
103
104 GCancellable *cancellable;
105 GFileMonitor *monitor;
106 LapizFileBrowserStore *model;
107};
108
109struct _LapizFileBrowserStorePrivate
110{
111 FileBrowserNode *root;
112 FileBrowserNode *virtual_root;
113 GType column_types[LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM];
114
115 LapizFileBrowserStoreFilterMode filter_mode;
116 LapizFileBrowserStoreFilterFunc filter_func;
117 gpointer filter_user_data;
118
119 SortFunc sort_func;
120
121 GSList *async_handles;
122 MountInfo *mount_info;
123};
124
125static FileBrowserNode *model_find_node (LapizFileBrowserStore *model,
126 FileBrowserNode *node,
127 GFile *uri);
128static void model_remove_node (LapizFileBrowserStore * model,
129 FileBrowserNode * node,
130 CtkTreePath * path,
131 gboolean free_nodes);
132
133static void set_virtual_root_from_node (LapizFileBrowserStore * model,
134 FileBrowserNode * node);
135
136static void lapiz_file_browser_store_iface_init (CtkTreeModelIface * iface);
137static CtkTreeModelFlags lapiz_file_browser_store_get_flags (CtkTreeModel * tree_model);
138static gint lapiz_file_browser_store_get_n_columns (CtkTreeModel * tree_model);
139static GType lapiz_file_browser_store_get_column_type (CtkTreeModel * tree_model,
140 gint index);
141static gboolean lapiz_file_browser_store_get_iter (CtkTreeModel * tree_model,
142 CtkTreeIter * iter,
143 CtkTreePath * path);
144static CtkTreePath *lapiz_file_browser_store_get_path (CtkTreeModel * tree_model,
145 CtkTreeIter * iter);
146static void lapiz_file_browser_store_get_value (CtkTreeModel * tree_model,
147 CtkTreeIter * iter,
148 gint column,
149 GValue * value);
150static gboolean lapiz_file_browser_store_iter_next (CtkTreeModel * tree_model,
151 CtkTreeIter * iter);
152static gboolean lapiz_file_browser_store_iter_children (CtkTreeModel * tree_model,
153 CtkTreeIter * iter,
154 CtkTreeIter * parent);
155static gboolean lapiz_file_browser_store_iter_has_child (CtkTreeModel * tree_model,
156 CtkTreeIter * iter);
157static gint lapiz_file_browser_store_iter_n_children (CtkTreeModel * tree_model,
158 CtkTreeIter * iter);
159static gboolean lapiz_file_browser_store_iter_nth_child (CtkTreeModel * tree_model,
160 CtkTreeIter * iter,
161 CtkTreeIter * parent,
162 gint n);
163static gboolean lapiz_file_browser_store_iter_parent (CtkTreeModel * tree_model,
164 CtkTreeIter * iter,
165 CtkTreeIter * child);
166static void lapiz_file_browser_store_row_inserted (CtkTreeModel * tree_model,
167 CtkTreePath * path,
168 CtkTreeIter * iter);
169
170static void lapiz_file_browser_store_drag_source_init (CtkTreeDragSourceIface * iface);
171static gboolean lapiz_file_browser_store_row_draggable (CtkTreeDragSource * drag_source,
172 CtkTreePath * path);
173static gboolean lapiz_file_browser_store_drag_data_delete (CtkTreeDragSource * drag_source,
174 CtkTreePath * path);
175static gboolean lapiz_file_browser_store_drag_data_get (CtkTreeDragSource * drag_source,
176 CtkTreePath * path,
177 CtkSelectionData * selection_data);
178
179static void file_browser_node_free (LapizFileBrowserStore * model,
180 FileBrowserNode * node);
181static void model_add_node (LapizFileBrowserStore * model,
182 FileBrowserNode * child,
183 FileBrowserNode * parent);
184static void model_clear (LapizFileBrowserStore * model,
185 gboolean free_nodes);
186static gint model_sort_default (FileBrowserNode * node1,
187 FileBrowserNode * node2);
188static void model_check_dummy (LapizFileBrowserStore * model,
189 FileBrowserNode * node);
190static void next_files_async (GFileEnumerator * enumerator,
191 AsyncNode * async);
192
193static void delete_files (AsyncData *data);
194
195G_DEFINE_DYNAMIC_TYPE_EXTENDED (LapizFileBrowserStore, lapiz_file_browser_store,static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
196 G_TYPE_OBJECT,static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
197 0,static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
198 G_ADD_PRIVATE_DYNAMIC (LapizFileBrowserStore)static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
199 G_IMPLEMENT_INTERFACE_DYNAMIC (CTK_TYPE_TREE_MODEL,static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
200 lapiz_file_browser_store_iface_init)static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
201 G_IMPLEMENT_INTERFACE_DYNAMIC (CTK_TYPE_TREE_DRAG_SOURCE,static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
202 lapiz_file_browser_store_drag_source_init))static void lapiz_file_browser_store_init (LapizFileBrowserStore
*self); static void lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass
*klass); static void lapiz_file_browser_store_class_finalize
(LapizFileBrowserStoreClass *klass); static gpointer lapiz_file_browser_store_parent_class
= ((void*)0); static GType lapiz_file_browser_store_type_id =
0; static gint LapizFileBrowserStore_private_offset; static void
lapiz_file_browser_store_class_intern_init (gpointer klass) {
lapiz_file_browser_store_parent_class = g_type_class_peek_parent
(klass); if (LapizFileBrowserStore_private_offset != 0) g_type_class_adjust_private_offset
(klass, &LapizFileBrowserStore_private_offset); lapiz_file_browser_store_class_init
((LapizFileBrowserStoreClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer lapiz_file_browser_store_get_instance_private
(LapizFileBrowserStore *self) { return (((gpointer) ((guint8
*) (self) + (glong) (LapizFileBrowserStore_private_offset))))
; } GType lapiz_file_browser_store_get_type (void) { return lapiz_file_browser_store_type_id
; } static void lapiz_file_browser_store_register_type (GTypeModule
*type_module) { GType g_define_type_id __attribute__ ((__unused__
)); const GTypeInfo g_define_type_info = { sizeof (LapizFileBrowserStoreClass
), (GBaseInitFunc) ((void*)0), (GBaseFinalizeFunc) ((void*)0)
, (GClassInitFunc)(void (*)(void)) lapiz_file_browser_store_class_intern_init
, (GClassFinalizeFunc)(void (*)(void)) lapiz_file_browser_store_class_finalize
, ((void*)0), sizeof (LapizFileBrowserStore), 0, (GInstanceInitFunc
)(void (*)(void)) lapiz_file_browser_store_init, ((void*)0) }
; lapiz_file_browser_store_type_id = g_type_module_register_type
(type_module, ((GType) ((20) << (2))), "LapizFileBrowserStore"
, &g_define_type_info, (GTypeFlags) 0); g_define_type_id =
lapiz_file_browser_store_type_id; { { LapizFileBrowserStore_private_offset
= sizeof (LapizFileBrowserStorePrivate); } { const GInterfaceInfo
g_implement_interface_info = { (GInterfaceInitFunc)(void (*)
(void)) lapiz_file_browser_store_iface_init, ((void*)0), ((void
*)0) }; g_type_module_add_interface (type_module, g_define_type_id
, (ctk_tree_model_get_type ()), &g_implement_interface_info
); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) lapiz_file_browser_store_drag_source_init, (
(void*)0), ((void*)0) }; g_type_module_add_interface (type_module
, g_define_type_id, (ctk_tree_drag_source_get_type ()), &
g_implement_interface_info); } ; } }
203
204/* Properties */
205enum {
206 PROP_0,
207
208 PROP_ROOT,
209 PROP_VIRTUAL_ROOT,
210 PROP_FILTER_MODE
211};
212
213/* Signals */
214enum
215{
216 BEGIN_LOADING,
217 END_LOADING,
218 ERROR,
219 NO_TRASH,
220 RENAME,
221 BEGIN_REFRESH,
222 END_REFRESH,
223 UNLOAD,
224 NUM_SIGNALS
225};
226
227static guint model_signals[NUM_SIGNALS] = { 0 };
228
229static void
230cancel_mount_operation (LapizFileBrowserStore *obj)
231{
232 if (obj->priv->mount_info != NULL((void*)0))
233 {
234 obj->priv->mount_info->model = NULL((void*)0);
235 g_cancellable_cancel (obj->priv->mount_info->cancellable);
236 obj->priv->mount_info = NULL((void*)0);
237 }
238}
239
240static void
241lapiz_file_browser_store_finalize (GObject * object)
242{
243 LapizFileBrowserStore *obj = LAPIZ_FILE_BROWSER_STORE (object)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((object)), ((lapiz_file_browser_store_get_type
()))))))
;
244 GSList *item;
245
246 /* Free all the nodes */
247 file_browser_node_free (obj, obj->priv->root);
248
249 /* Cancel any asynchronous operations */
250 for (item = obj->priv->async_handles; item; item = item->next)
251 {
252 AsyncData *data = (AsyncData *) (item->data);
253 g_cancellable_cancel (data->cancellable);
254
255 data->removed = TRUE(!(0));
256 }
257
258 cancel_mount_operation (obj);
259
260 g_slist_free (obj->priv->async_handles);
261 G_OBJECT_CLASS (lapiz_file_browser_store_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((lapiz_file_browser_store_parent_class)), (((GType) ((20)
<< (2))))))))
->finalize (object);
262}
263
264static void
265set_gvalue_from_node (GValue *value,
266 FileBrowserNode *node)
267{
268 gchar * uri;
269
270 if (node == NULL((void*)0) || !node->file) {
271 g_value_set_string (value, NULL((void*)0));
272 } else {
273 uri = g_file_get_uri (node->file);
274 g_value_take_string (value, uri);
275 }
276}
277
278static void
279lapiz_file_browser_store_get_property (GObject *object,
280 guint prop_id,
281 GValue *value,
282 GParamSpec *pspec)
283{
284 LapizFileBrowserStore *obj = LAPIZ_FILE_BROWSER_STORE (object)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((object)), ((lapiz_file_browser_store_get_type
()))))))
;
285
286 switch (prop_id)
287 {
288 case PROP_ROOT:
289 set_gvalue_from_node (value, obj->priv->root);
290 break;
291 case PROP_VIRTUAL_ROOT:
292 set_gvalue_from_node (value, obj->priv->virtual_root);
293 break;
294 case PROP_FILTER_MODE:
295 g_value_set_flags (value, obj->priv->filter_mode);
296 break;
297 default:
298 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "lapiz-file-browser-store.c", 298, ("property"), _glib__property_id
, _glib__pspec->name, g_type_name ((((((GTypeClass*) (((GTypeInstance
*) (_glib__pspec))->g_class))->g_type)))), (g_type_name
((((((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
;
299 break;
300 }
301}
302
303static void
304lapiz_file_browser_store_set_property (GObject *object,
305 guint prop_id,
306 const GValue *value,
307 GParamSpec *pspec)
308{
309 LapizFileBrowserStore *obj = LAPIZ_FILE_BROWSER_STORE (object)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((object)), ((lapiz_file_browser_store_get_type
()))))))
;
310
311 switch (prop_id)
312 {
313 case PROP_FILTER_MODE:
314 lapiz_file_browser_store_set_filter_mode (obj,
315 g_value_get_flags (value));
316 break;
317 default:
318 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "lapiz-file-browser-store.c", 318, ("property"), _glib__property_id
, _glib__pspec->name, g_type_name ((((((GTypeClass*) (((GTypeInstance
*) (_glib__pspec))->g_class))->g_type)))), (g_type_name
((((((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
;
319 break;
320 }
321}
322
323static void
324lapiz_file_browser_store_class_init (LapizFileBrowserStoreClass * klass)
325{
326 GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((klass)), (((GType) ((20) << (2))))))))
;
327
328 object_class->finalize = lapiz_file_browser_store_finalize;
329
330 object_class->get_property = lapiz_file_browser_store_get_property;
331 object_class->set_property = lapiz_file_browser_store_set_property;
332
333 g_object_class_install_property (object_class, PROP_ROOT,
334 g_param_spec_string ("root",
335 "Root",
336 "The root uri",
337 NULL((void*)0),
338 G_PARAM_READABLE));
339
340 g_object_class_install_property (object_class, PROP_VIRTUAL_ROOT,
341 g_param_spec_string ("virtual-root",
342 "Virtual Root",
343 "The virtual root uri",
344 NULL((void*)0),
345 G_PARAM_READABLE));
346
347 g_object_class_install_property (object_class, PROP_FILTER_MODE,
348 g_param_spec_flags ("filter-mode",
349 "Filter Mode",
350 "The filter mode",
351 LAPIZ_TYPE_FILE_BROWSER_STORE_FILTER_MODE(lapiz_file_browser_store_filter_mode_get_type()),
352 lapiz_file_browser_store_filter_mode_get_default (),
353 G_PARAM_READWRITE));
354
355 model_signals[BEGIN_LOADING] =
356 g_signal_new ("begin-loading",
357 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
358 G_SIGNAL_RUN_LAST,
359 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, begin_loading
))
360 begin_loading)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, begin_loading
))
, NULL((void*)0), NULL((void*)0),
361 g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE((GType) ((1) << (2))), 1,
362 CTK_TYPE_TREE_ITER(ctk_tree_iter_get_type ()));
363 model_signals[END_LOADING] =
364 g_signal_new ("end-loading",
365 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
366 G_SIGNAL_RUN_LAST,
367 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, end_loading
))
368 end_loading)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, end_loading
))
, NULL((void*)0), NULL((void*)0),
369 g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE((GType) ((1) << (2))), 1,
370 CTK_TYPE_TREE_ITER(ctk_tree_iter_get_type ()));
371 model_signals[ERROR] =
372 g_signal_new ("error", G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
373 G_SIGNAL_RUN_LAST,
374 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, error
))
375 error)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, error
))
, NULL((void*)0), NULL((void*)0),
376 lapiz_file_browser_marshal_VOID__UINT_STRING,
377 G_TYPE_NONE((GType) ((1) << (2))), 2, G_TYPE_UINT((GType) ((7) << (2))), G_TYPE_STRING((GType) ((16) << (2))));
378 model_signals[NO_TRASH] =
379 g_signal_new ("no-trash", G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
380 G_SIGNAL_RUN_LAST,
381 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, no_trash
))
382 no_trash)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, no_trash
))
, g_signal_accumulator_true_handled, NULL((void*)0),
383 lapiz_file_browser_marshal_BOOLEAN__POINTER,
384 G_TYPE_BOOLEAN((GType) ((5) << (2))), 1, G_TYPE_POINTER((GType) ((17) << (2))));
385 model_signals[RENAME] =
386 g_signal_new ("rename",
387 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
388 G_SIGNAL_RUN_LAST,
389 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, rename
))
390 rename)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, rename
))
, NULL((void*)0), NULL((void*)0),
391 lapiz_file_browser_marshal_VOID__STRING_STRING,
392 G_TYPE_NONE((GType) ((1) << (2))), 2,
393 G_TYPE_STRING((GType) ((16) << (2))),
394 G_TYPE_STRING((GType) ((16) << (2))));
395 model_signals[BEGIN_REFRESH] =
396 g_signal_new ("begin-refresh",
397 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
398 G_SIGNAL_RUN_LAST,
399 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, begin_refresh
))
400 begin_refresh)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, begin_refresh
))
, NULL((void*)0), NULL((void*)0),
401 g_cclosure_marshal_VOID__VOID,
402 G_TYPE_NONE((GType) ((1) << (2))), 0);
403 model_signals[END_REFRESH] =
404 g_signal_new ("end-refresh",
405 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
406 G_SIGNAL_RUN_LAST,
407 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, end_refresh
))
408 end_refresh)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, end_refresh
))
, NULL((void*)0), NULL((void*)0),
409 g_cclosure_marshal_VOID__VOID,
410 G_TYPE_NONE((GType) ((1) << (2))), 0);
411 model_signals[UNLOAD] =
412 g_signal_new ("unload",
413 G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)),
414 G_SIGNAL_RUN_LAST,
415 G_STRUCT_OFFSET (LapizFileBrowserStoreClass,((glong) __builtin_offsetof(LapizFileBrowserStoreClass, unload
))
416 unload)((glong) __builtin_offsetof(LapizFileBrowserStoreClass, unload
))
, NULL((void*)0), NULL((void*)0),
417 g_cclosure_marshal_VOID__STRING,
418 G_TYPE_NONE((GType) ((1) << (2))), 1,
419 G_TYPE_STRING((GType) ((16) << (2))));
420}
421
422static void
423lapiz_file_browser_store_class_finalize (LapizFileBrowserStoreClass *klass G_GNUC_UNUSED__attribute__ ((__unused__)))
424{
425 /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
426}
427
428static void
429lapiz_file_browser_store_iface_init (CtkTreeModelIface * iface)
430{
431 iface->get_flags = lapiz_file_browser_store_get_flags;
432 iface->get_n_columns = lapiz_file_browser_store_get_n_columns;
433 iface->get_column_type = lapiz_file_browser_store_get_column_type;
434 iface->get_iter = lapiz_file_browser_store_get_iter;
435 iface->get_path = lapiz_file_browser_store_get_path;
436 iface->get_value = lapiz_file_browser_store_get_value;
437 iface->iter_next = lapiz_file_browser_store_iter_next;
438 iface->iter_children = lapiz_file_browser_store_iter_children;
439 iface->iter_has_child = lapiz_file_browser_store_iter_has_child;
440 iface->iter_n_children = lapiz_file_browser_store_iter_n_children;
441 iface->iter_nth_child = lapiz_file_browser_store_iter_nth_child;
442 iface->iter_parent = lapiz_file_browser_store_iter_parent;
443 iface->row_inserted = lapiz_file_browser_store_row_inserted;
444}
445
446static void
447lapiz_file_browser_store_drag_source_init (CtkTreeDragSourceIface * iface)
448{
449 iface->row_draggable = lapiz_file_browser_store_row_draggable;
450 iface->drag_data_delete = lapiz_file_browser_store_drag_data_delete;
451 iface->drag_data_get = lapiz_file_browser_store_drag_data_get;
452}
453
454static void
455lapiz_file_browser_store_init (LapizFileBrowserStore * obj)
456{
457 obj->priv = lapiz_file_browser_store_get_instance_private (obj);
458
459 obj->priv->column_types[LAPIZ_FILE_BROWSER_STORE_COLUMN_URI] =
460 G_TYPE_STRING((GType) ((16) << (2)));
461 obj->priv->column_types[LAPIZ_FILE_BROWSER_STORE_COLUMN_NAME] =
462 G_TYPE_STRING((GType) ((16) << (2)));
463 obj->priv->column_types[LAPIZ_FILE_BROWSER_STORE_COLUMN_FLAGS] =
464 G_TYPE_UINT((GType) ((7) << (2)));
465 obj->priv->column_types[LAPIZ_FILE_BROWSER_STORE_COLUMN_ICON] =
466 GDK_TYPE_PIXBUF(gdk_pixbuf_get_type ());
467 obj->priv->column_types[LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM] =
468 GDK_TYPE_PIXBUF(gdk_pixbuf_get_type ());
469
470 // Default filter mode is hiding the hidden files
471 obj->priv->filter_mode = lapiz_file_browser_store_filter_mode_get_default ();
472 obj->priv->sort_func = model_sort_default;
473}
474
475static gboolean
476node_has_parent (FileBrowserNode * node, FileBrowserNode * parent)
477{
478 if (node->parent == NULL((void*)0))
479 return FALSE(0);
480
481 if (node->parent == parent)
482 return TRUE(!(0));
483
484 return node_has_parent (node->parent, parent);
485}
486
487static gboolean
488node_in_tree (LapizFileBrowserStore * model, FileBrowserNode * node)
489{
490 return node_has_parent (node, model->priv->virtual_root);
491}
492
493static gboolean
494model_node_visibility (LapizFileBrowserStore * model,
495 FileBrowserNode * node)
496{
497 if (node == NULL((void*)0))
498 return FALSE(0);
499
500 if (NODE_IS_DUMMY (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
)
501 return !NODE_IS_HIDDEN (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN
))
;
502
503 if (node == model->priv->virtual_root)
504 return TRUE(!(0));
505
506 if (!node_has_parent (node, model->priv->virtual_root))
507 return FALSE(0);
508
509 return !NODE_IS_FILTERED (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED
))
;
510}
511
512static gboolean
513model_node_inserted (LapizFileBrowserStore * model,
514 FileBrowserNode * node)
515{
516 return node == model->priv->virtual_root || (model_node_visibility (model, node) && node->inserted);
517}
518
519/* Interface implementation */
520
521static CtkTreeModelFlags
522lapiz_file_browser_store_get_flags (CtkTreeModel * tree_model)
523{
524 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((CtkTreeModelFlags) 0); } } while (0)
525 (CtkTreeModelFlags) 0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((CtkTreeModelFlags) 0); } } while (0)
;
526
527 return CTK_TREE_MODEL_ITERS_PERSIST;
528}
529
530static gint
531lapiz_file_browser_store_get_n_columns (CtkTreeModel * tree_model)
532{
533 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model), 0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return (0); } } while (0)
;
534
535 return LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM;
536}
537
538static GType
539lapiz_file_browser_store_get_column_type (CtkTreeModel * tree_model, gint idx)
540{
541 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return (((GType) ((0) << (2)))); } } while (0)
542 G_TYPE_INVALID)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return (((GType) ((0) << (2)))); } } while (0)
;
543 g_return_val_if_fail (idx < LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM &&do { if ((idx < LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM &&
idx >= 0)) { } else { g_return_if_fail_warning (((gchar*)
0), ((const char*) (__func__)), "idx < LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM && idx >= 0"
); return (((GType) ((0) << (2)))); } } while (0)
544 idx >= 0, G_TYPE_INVALID)do { if ((idx < LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM &&
idx >= 0)) { } else { g_return_if_fail_warning (((gchar*)
0), ((const char*) (__func__)), "idx < LAPIZ_FILE_BROWSER_STORE_COLUMN_NUM && idx >= 0"
); return (((GType) ((0) << (2)))); } } while (0)
;
545
546 return LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
->priv->column_types[idx];
547}
548
549static gboolean
550lapiz_file_browser_store_get_iter (CtkTreeModel * tree_model,
551 CtkTreeIter * iter, CtkTreePath * path)
552{
553 gint * indices, depth, i;
554 FileBrowserNode * node;
555 LapizFileBrowserStore * model;
556 gint num;
557
558 g_assert (LAPIZ_IS_FILE_BROWSER_STORE (tree_model))do { if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; }))))) ; else g_assertion_message_expr (((gchar*) 0), "lapiz-file-browser-store.c"
, 558, ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); } while (0)
;
559 g_assert (path != NULL)do { if (path != ((void*)0)) ; else g_assertion_message_expr (
((gchar*) 0), "lapiz-file-browser-store.c", 559, ((const char
*) (__func__)), "path != NULL"); } while (0)
;
560
561 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
562 indices = ctk_tree_path_get_indices (path);
563 depth = ctk_tree_path_get_depth (path);
564 node = model->priv->virtual_root;
565
566 for (i = 0; i < depth; ++i) {
567 GSList * item;
568
569 if (node == NULL((void*)0))
570 return FALSE(0);
571
572 num = 0;
573
574 if (!NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
575 return FALSE(0);
576
577 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item; item = item->next) {
578 FileBrowserNode * child;
579
580 child = (FileBrowserNode *) (item->data);
581
582 if (model_node_inserted (model, child)) {
583 if (num == indices[i]) {
584 node = child;
585 break;
586 }
587
588 num++;
589 }
590 }
591
592 if (item == NULL((void*)0))
593 return FALSE(0);
594
595 node = (FileBrowserNode *) (item->data);
596 }
597
598 iter->user_data = node;
599 iter->user_data2 = NULL((void*)0);
600 iter->user_data3 = NULL((void*)0);
601
602 return node != NULL((void*)0);
603}
604
605static CtkTreePath *
606lapiz_file_browser_store_get_path_real (LapizFileBrowserStore * model,
607 FileBrowserNode * node)
608{
609 CtkTreePath *path;
610 gint num = 0;
611
612 path = ctk_tree_path_new ();
613
614 while (node != model->priv->virtual_root) {
615 GSList *item;
616
617 if (node->parent == NULL((void*)0)) {
618 ctk_tree_path_free (path);
619 return NULL((void*)0);
620 }
621
622 num = 0;
623
624 for (item = FILE_BROWSER_NODE_DIR (node->parent)((FileBrowserNodeDir *)(node->parent))->children; item; item = item->next) {
625 FileBrowserNode *check;
626
627 check = (FileBrowserNode *) (item->data);
628
629 if (model_node_visibility (model, check) && (check == node || check->inserted)) {
630 if (check == node) {
631 ctk_tree_path_prepend_index (path,
632 num);
633 break;
634 }
635
636 ++num;
637 } else if (check == node) {
638 if (NODE_IS_DUMMY (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
)
639 g_warning ("Dummy not visible???");
640
641 ctk_tree_path_free (path);
642 return NULL((void*)0);
643 }
644 }
645
646 node = node->parent;
647 }
648
649 return path;
650}
651
652static CtkTreePath *
653lapiz_file_browser_store_get_path (CtkTreeModel * tree_model,
654 CtkTreeIter * iter)
655{
656 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return (((void*)0)); } } while (0)
;
657 g_return_val_if_fail (iter != NULL, NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
(((void*)0)); } } while (0)
;
658 g_return_val_if_fail (iter->user_data != NULL, NULL)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return (((void*)0)); } } while (0)
;
659
660 return lapiz_file_browser_store_get_path_real (LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
,
661 (FileBrowserNode *) (iter->user_data));
662}
663
664static void
665lapiz_file_browser_store_get_value (CtkTreeModel * tree_model,
666 CtkTreeIter * iter,
667 gint column,
668 GValue * value)
669{
670 FileBrowserNode *node;
671
672 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return; } } while (0)
;
673 g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
; } } while (0)
;
674 g_return_if_fail (iter->user_data != NULL)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return; } } while (0)
;
675
676 node = (FileBrowserNode *) (iter->user_data);
677
678 g_value_init (value, LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
->priv->column_types[column]);
679
680 switch (column) {
681 case LAPIZ_FILE_BROWSER_STORE_COLUMN_URI:
682 set_gvalue_from_node (value, node);
683 break;
684 case LAPIZ_FILE_BROWSER_STORE_COLUMN_NAME:
685 g_value_set_string (value, node->name);
686 break;
687 case LAPIZ_FILE_BROWSER_STORE_COLUMN_FLAGS:
688 g_value_set_uint (value, node->flags);
689 break;
690 case LAPIZ_FILE_BROWSER_STORE_COLUMN_ICON:
691 g_value_set_object (value, node->icon);
692 break;
693 case LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM:
694 g_value_set_object (value, node->emblem);
695 break;
696 default:
697 g_return_if_reached ()do { g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): should not be reached"
, "lapiz-file-browser-store.c", 697, ((const char*) (__func__
))); return; } while (0)
;
698 }
699}
700
701static gboolean
702lapiz_file_browser_store_iter_next (CtkTreeModel * tree_model,
703 CtkTreeIter * iter)
704{
705 LapizFileBrowserStore * model;
706 FileBrowserNode * node;
707 GSList * item;
708 GSList * first;
709
710 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
711 FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
;
712 g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
((0)); } } while (0)
;
713 g_return_val_if_fail (iter->user_data != NULL, FALSE)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return ((0)); } } while (0)
;
714
715 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
716 node = (FileBrowserNode *) (iter->user_data);
717
718 if (node->parent == NULL((void*)0))
719 return FALSE(0);
720
721 first = g_slist_next (g_slist_find (FILE_BROWSER_NODE_DIR (node->parent)->children, node))((g_slist_find (((FileBrowserNodeDir *)(node->parent))->
children, node)) ? (((GSList *)(g_slist_find (((FileBrowserNodeDir
*)(node->parent))->children, node)))->next) : ((void
*)0))
;
722
723 for (item = first; item; item = item->next) {
724 if (model_node_inserted (model, (FileBrowserNode *) (item->data))) {
725 iter->user_data = item->data;
726 return TRUE(!(0));
727 }
728 }
729
730 return FALSE(0);
731}
732
733static gboolean
734lapiz_file_browser_store_iter_children (CtkTreeModel * tree_model,
735 CtkTreeIter * iter,
736 CtkTreeIter * parent)
737{
738 FileBrowserNode * node;
739 LapizFileBrowserStore * model;
740 GSList * item;
741
742 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
743 FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
;
744 g_return_val_if_fail (parent == NULLdo { if ((parent == ((void*)0) || parent->user_data != ((void
*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "parent == NULL || parent->user_data != NULL"
); return ((0)); } } while (0)
745 || parent->user_data != NULL, FALSE)do { if ((parent == ((void*)0) || parent->user_data != ((void
*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "parent == NULL || parent->user_data != NULL"
); return ((0)); } } while (0)
;
746
747 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
748
749 if (parent == NULL((void*)0))
750 node = model->priv->virtual_root;
751 else
752 node = (FileBrowserNode *) (parent->user_data);
753
754 if (node == NULL((void*)0))
755 return FALSE(0);
756
757 if (!NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
758 return FALSE(0);
759
760 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item; item = item->next) {
761 if (model_node_inserted (model, (FileBrowserNode *) (item->data))) {
762 iter->user_data = item->data;
763 return TRUE(!(0));
764 }
765 }
766
767 return FALSE(0);
768}
769
770static gboolean
771filter_tree_model_iter_has_child_real (LapizFileBrowserStore * model,
772 FileBrowserNode * node)
773{
774 GSList *item;
775
776 if (!NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
777 return FALSE(0);
778
779 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item; item = item->next) {
780 if (model_node_inserted (model, (FileBrowserNode *) (item->data)))
781 return TRUE(!(0));
782 }
783
784 return FALSE(0);
785}
786
787static gboolean
788lapiz_file_browser_store_iter_has_child (CtkTreeModel * tree_model,
789 CtkTreeIter * iter)
790{
791 FileBrowserNode *node;
792 LapizFileBrowserStore *model;
793
794 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
795 FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
;
796 g_return_val_if_fail (iter == NULLdo { if ((iter == ((void*)0) || iter->user_data != ((void*
)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "iter == NULL || iter->user_data != NULL"
); return ((0)); } } while (0)
797 || iter->user_data != NULL, FALSE)do { if ((iter == ((void*)0) || iter->user_data != ((void*
)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "iter == NULL || iter->user_data != NULL"
); return ((0)); } } while (0)
;
798
799 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
800
801 if (iter == NULL((void*)0))
802 node = model->priv->virtual_root;
803 else
804 node = (FileBrowserNode *) (iter->user_data);
805
806 return filter_tree_model_iter_has_child_real (model, node);
807}
808
809static gint
810lapiz_file_browser_store_iter_n_children (CtkTreeModel * tree_model,
811 CtkTreeIter * iter)
812{
813 FileBrowserNode *node;
814 LapizFileBrowserStore *model;
815 GSList *item;
816 gint num = 0;
817
818 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
819 FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
;
820 g_return_val_if_fail (iter == NULLdo { if ((iter == ((void*)0) || iter->user_data != ((void*
)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "iter == NULL || iter->user_data != NULL"
); return ((0)); } } while (0)
821 || iter->user_data != NULL, FALSE)do { if ((iter == ((void*)0) || iter->user_data != ((void*
)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "iter == NULL || iter->user_data != NULL"
); return ((0)); } } while (0)
;
822
823 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
824
825 if (iter == NULL((void*)0))
826 node = model->priv->virtual_root;
827 else
828 node = (FileBrowserNode *) (iter->user_data);
829
830 if (!NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
831 return 0;
832
833 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item; item = item->next)
834 if (model_node_inserted (model, (FileBrowserNode *) (item->data)))
835 ++num;
836
837 return num;
838}
839
840static gboolean
841lapiz_file_browser_store_iter_nth_child (CtkTreeModel * tree_model,
842 CtkTreeIter * iter,
843 CtkTreeIter * parent, gint n)
844{
845 FileBrowserNode *node;
846 LapizFileBrowserStore *model;
847 GSList *item;
848 gint num = 0;
849
850 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
851 FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
;
852 g_return_val_if_fail (parent == NULLdo { if ((parent == ((void*)0) || parent->user_data != ((void
*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "parent == NULL || parent->user_data != NULL"
); return ((0)); } } while (0)
853 || parent->user_data != NULL, FALSE)do { if ((parent == ((void*)0) || parent->user_data != ((void
*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "parent == NULL || parent->user_data != NULL"
); return ((0)); } } while (0)
;
854
855 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
856
857 if (parent == NULL((void*)0))
858 node = model->priv->virtual_root;
859 else
860 node = (FileBrowserNode *) (parent->user_data);
861
862 if (!NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
863 return FALSE(0);
864
865 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item;
866 item = item->next) {
867 if (model_node_inserted (model, (FileBrowserNode *) (item->data))) {
868 if (num == n) {
869 iter->user_data = item->data;
870 return TRUE(!(0));
871 }
872
873 ++num;
874 }
875 }
876
877 return FALSE(0);
878}
879
880static gboolean
881lapiz_file_browser_store_iter_parent (CtkTreeModel * tree_model,
882 CtkTreeIter * iter,
883 CtkTreeIter * child)
884{
885 FileBrowserNode *node;
886 LapizFileBrowserStore *model;
887
888 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return ((0)); } } while (0)
;
889 g_return_val_if_fail (child != NULL, FALSE)do { if ((child != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "child != NULL");
return ((0)); } } while (0)
;
890 g_return_val_if_fail (child->user_data != NULL, FALSE)do { if ((child->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "child->user_data != NULL"
); return ((0)); } } while (0)
;
891
892 node = (FileBrowserNode *) (child->user_data);
893 model = LAPIZ_FILE_BROWSER_STORE (tree_model)((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((tree_model)), ((lapiz_file_browser_store_get_type
()))))))
;
894
895 if (!node_in_tree (model, node))
896 return FALSE(0);
897
898 if (node->parent == NULL((void*)0))
899 return FALSE(0);
900
901 iter->user_data = node->parent;
902 return TRUE(!(0));
903}
904
905static void
906lapiz_file_browser_store_row_inserted (CtkTreeModel *tree_model G_GNUC_UNUSED__attribute__ ((__unused__)),
907 CtkTreePath *path G_GNUC_UNUSED__attribute__ ((__unused__)),
908 CtkTreeIter *iter)
909{
910 FileBrowserNode * node = (FileBrowserNode *)(iter->user_data);
911
912 node->inserted = TRUE(!(0));
913}
914
915static gboolean
916lapiz_file_browser_store_row_draggable (CtkTreeDragSource * drag_source,
917 CtkTreePath * path)
918{
919 CtkTreeIter iter;
920 LapizFileBrowserStoreFlag flags;
921
922 if (!ctk_tree_model_get_iter (CTK_TREE_MODEL (drag_source)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((drag_source)), ((ctk_tree_model_get_type ()))))))
,
923 &iter, path))
924 {
925 return FALSE(0);
926 }
927
928 ctk_tree_model_get (CTK_TREE_MODEL (drag_source)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((drag_source)), ((ctk_tree_model_get_type ()))))))
, &iter,
929 LAPIZ_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
930 -1);
931
932 return !FILE_IS_DUMMY(flags)(flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY);
933}
934
935static gboolean
936lapiz_file_browser_store_drag_data_delete (CtkTreeDragSource *drag_source G_GNUC_UNUSED__attribute__ ((__unused__)),
937 CtkTreePath *path G_GNUC_UNUSED__attribute__ ((__unused__)))
938{
939 return FALSE(0);
940}
941
942static gboolean
943lapiz_file_browser_store_drag_data_get (CtkTreeDragSource * drag_source,
944 CtkTreePath * path,
945 CtkSelectionData * selection_data)
946{
947 CtkTreeIter iter;
948 gchar *uri;
949 gchar *uris[2] = {0, };
950 gboolean ret;
951
952 if (!ctk_tree_model_get_iter (CTK_TREE_MODEL (drag_source)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((drag_source)), ((ctk_tree_model_get_type ()))))))
,
953 &iter, path))
954 {
955 return FALSE(0);
956 }
957
958 ctk_tree_model_get (CTK_TREE_MODEL (drag_source)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((drag_source)), ((ctk_tree_model_get_type ()))))))
, &iter,
959 LAPIZ_FILE_BROWSER_STORE_COLUMN_URI, &uri,
960 -1);
961
962 g_assert (uri)do { if (uri) ; else g_assertion_message_expr (((gchar*) 0), "lapiz-file-browser-store.c"
, 962, ((const char*) (__func__)), "uri"); } while (0)
;
963
964 uris[0] = uri;
965 ret = ctk_selection_data_set_uris (selection_data, uris);
966
967 g_free (uri);
968
969 return ret;
970}
971
972#define FILTER_HIDDEN(mode)(mode & LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) (mode & LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN)
973#define FILTER_BINARY(mode)(mode & LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY) (mode & LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY)
974
975/* Private */
976static void
977model_begin_loading (LapizFileBrowserStore * model, FileBrowserNode * node)
978{
979 CtkTreeIter iter;
980
981 iter.user_data = node;
982 g_signal_emit (model, model_signals[BEGIN_LOADING], 0, &iter);
983}
984
985static void
986model_end_loading (LapizFileBrowserStore * model, FileBrowserNode * node)
987{
988 CtkTreeIter iter;
989
990 iter.user_data = node;
991 g_signal_emit (model, model_signals[END_LOADING], 0, &iter);
992}
993
994static void
995model_node_update_visibility (LapizFileBrowserStore * model,
996 FileBrowserNode * node)
997{
998 CtkTreeIter iter;
999
1000 node->flags &= ~LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED;
1001
1002 if (FILTER_HIDDEN (model->priv->filter_mode)(model->priv->filter_mode & LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN
)
&&
1003 NODE_IS_HIDDEN (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN
))
)
1004 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED;
1005 else if (FILTER_BINARY (model->priv->filter_mode)(model->priv->filter_mode & LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY
)
&&
1006 (!NODE_IS_TEXT (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_TEXT
))
&& !NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
))
1007 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED;
1008 else if (model->priv->filter_func) {
1009 iter.user_data = node;
1010
1011 if (!model->priv->
1012 filter_func (model, &iter,
1013 model->priv->filter_user_data))
1014 node->flags |=
1015 LAPIZ_FILE_BROWSER_STORE_FLAG_IS_FILTERED;
1016 }
1017}
1018
1019static gint
1020collate_nodes (FileBrowserNode * node1, FileBrowserNode * node2)
1021{
1022 if (node1->name == NULL((void*)0))
1023 return -1;
1024 else if (node2->name == NULL((void*)0))
1025 return 1;
1026 else {
1027 gchar *k1, *k2;
1028 gint result;
1029
1030 k1 = g_utf8_collate_key_for_filename (node1->name, -1);
1031 k2 = g_utf8_collate_key_for_filename (node2->name, -1);
1032
1033 result = strcmp (k1, k2);
1034
1035 g_free (k1);
1036 g_free (k2);
1037
1038 return result;
1039 }
1040}
1041
1042static gint
1043model_sort_default (FileBrowserNode * node1, FileBrowserNode * node2)
1044{
1045 gint f1;
1046 gint f2;
1047
1048 f1 = NODE_IS_DUMMY (node1)(((node1)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
;
1049 f2 = NODE_IS_DUMMY (node2)(((node2)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
;
1050
1051 if (f1 && f2)
1052 {
1053 return 0;
1054 }
1055 else if (f1 || f2)
1056 {
1057 return f1 ? -1 : 1;
1058 }
1059
1060 f1 = NODE_IS_DIR (node1)(((node1)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
;
1061 f2 = NODE_IS_DIR (node2)(((node2)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
;
1062
1063 if (f1 != f2)
1064 {
1065 return f1 ? -1 : 1;
1066 }
1067
1068 f1 = NODE_IS_HIDDEN (node1)(((node1)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN
))
;
1069 f2 = NODE_IS_HIDDEN (node2)(((node2)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN
))
;
1070
1071 if (f1 != f2)
1072 {
1073 return f2 ? -1 : 1;
1074 }
1075
1076 return collate_nodes (node1, node2);
1077}
1078
1079static void
1080model_resort_node (LapizFileBrowserStore * model, FileBrowserNode * node)
1081{
1082 FileBrowserNodeDir *dir;
1083 GSList *item;
1084 FileBrowserNode *child;
1085 gint pos = 0;
1086 CtkTreeIter iter;
1087 CtkTreePath *path;
1088 gint *neworder;
1089
1090 dir = FILE_BROWSER_NODE_DIR (node->parent)((FileBrowserNodeDir *)(node->parent));
1091
1092 if (!model_node_visibility (model, node->parent)) {
1093 /* Just sort the children of the parent */
1094 dir->children = g_slist_sort (dir->children,
1095 (GCompareFunc) (model->priv->
1096 sort_func));
1097 } else {
1098 /* Store current positions */
1099 for (item = dir->children; item; item = item->next) {
1100 child = (FileBrowserNode *) (item->data);
1101
1102 if (model_node_visibility (model, child))
1103 child->pos = pos++;
1104 }
1105
1106 dir->children = g_slist_sort (dir->children,
1107 (GCompareFunc) (model->priv->
1108 sort_func));
1109 neworder = g_new (gint, pos)((gint *) g_malloc_n ((pos), sizeof (gint)));
1110 pos = 0;
1111
1112 /* Store the new positions */
1113 for (item = dir->children; item; item = item->next) {
1114 child = (FileBrowserNode *) (item->data);
1115
1116 if (model_node_visibility (model, child))
1117 neworder[pos++] = child->pos;
1118 }
1119
1120 iter.user_data = node->parent;
1121 path =
1122 lapiz_file_browser_store_get_path_real (model,
1123 node->parent);
1124
1125 ctk_tree_model_rows_reordered (CTK_TREE_MODEL (model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
,
1126 path, &iter, neworder);
1127
1128 g_free (neworder);
1129 ctk_tree_path_free (path);
1130 }
1131}
1132
1133static void
1134row_changed (LapizFileBrowserStore * model,
1135 CtkTreePath ** path,
1136 CtkTreeIter * iter)
1137{
1138 CtkTreeRowReference *ref = ctk_tree_row_reference_new (CTK_TREE_MODEL (model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
, *path);
1139
1140 /* Insert a copy of the actual path here because the row-inserted
1141 signal may alter the path */
1142 ctk_tree_model_row_changed (CTK_TREE_MODEL(model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
, *path, iter);
1143 ctk_tree_path_free (*path);
1144
1145 *path = ctk_tree_row_reference_get_path (ref);
1146 ctk_tree_row_reference_free (ref);
1147}
1148
1149static void
1150row_inserted (LapizFileBrowserStore * model,
1151 CtkTreePath ** path,
1152 CtkTreeIter * iter)
1153{
1154 /* This function creates a row reference for the path because it's
1155 uncertain what might change the actual model/view when we insert
1156 a node, maybe another directory load is triggered for example.
1157 Because functions that use this function rely on the notion that
1158 the path remains pointed towards the inserted node, we use the
1159 reference to keep track. */
1160 CtkTreeRowReference *ref = ctk_tree_row_reference_new (CTK_TREE_MODEL (model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
, *path);
1161 CtkTreePath * copy = ctk_tree_path_copy (*path);
1162
1163 ctk_tree_model_row_inserted (CTK_TREE_MODEL(model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
, copy, iter);
1164 ctk_tree_path_free (copy);
1165
1166 if (ref)
1167 {
1168 ctk_tree_path_free (*path);
1169
1170 /* To restore the path, we get the path from the reference. But, since
1171 we inserted a row, the path will be one index further than the
1172 actual path of our node. We therefore call ctk_tree_path_prev */
1173 *path = ctk_tree_row_reference_get_path (ref);
1174 ctk_tree_path_prev (*path);
1175 }
1176
1177 ctk_tree_row_reference_free (ref);
1178}
1179
1180static void
1181row_deleted (LapizFileBrowserStore * model,
1182 const CtkTreePath * path)
1183{
1184 CtkTreePath *copy = ctk_tree_path_copy (path);
1185
1186 /* Delete a copy of the actual path here because the row-deleted
1187 signal may alter the path */
1188 ctk_tree_model_row_deleted (CTK_TREE_MODEL(model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
, copy);
1189 ctk_tree_path_free (copy);
1190}
1191
1192static void
1193model_refilter_node (LapizFileBrowserStore * model,
1194 FileBrowserNode * node,
1195 CtkTreePath ** path)
1196{
1197 gboolean old_visible;
1198 gboolean new_visible;
1199 FileBrowserNodeDir *dir;
1200 GSList *item;
1201 CtkTreeIter iter;
1202 CtkTreePath *tmppath = NULL((void*)0);
1203 gboolean in_tree;
1204
1205 if (node == NULL((void*)0))
1206 return;
1207
1208 old_visible = model_node_visibility (model, node);
1209 model_node_update_visibility (model, node);
1210
1211 in_tree = node_in_tree (model, node);
1212
1213 if (path == NULL((void*)0))
1214 {
1215 if (in_tree)
1216 tmppath = lapiz_file_browser_store_get_path_real (model,
1217 node);
1218 else
1219 tmppath = ctk_tree_path_new_first ();
1220
1221 path = &tmppath;
1222 }
1223
1224 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
) {
1225 if (in_tree)
1226 ctk_tree_path_down (*path);
1227
1228 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
1229
1230 for (item = dir->children; item; item = item->next) {
1231 model_refilter_node (model,
1232 (FileBrowserNode *) (item->data),
1233 path);
1234 }
1235
1236 if (in_tree)
1237 ctk_tree_path_up (*path);
1238 }
1239
1240 if (in_tree) {
1241 new_visible = model_node_visibility (model, node);
1242
1243 if (old_visible != new_visible) {
1244 if (old_visible) {
1245 node->inserted = FALSE(0);
1246 row_deleted (model, *path);
1247 } else {
1248 iter.user_data = node;
1249 row_inserted (model, path, &iter);
1250 ctk_tree_path_next (*path);
1251 }
1252 } else if (old_visible) {
1253 ctk_tree_path_next (*path);
1254 }
1255 }
1256
1257 model_check_dummy (model, node);
1258
1259 if (tmppath)
1260 ctk_tree_path_free (tmppath);
1261}
1262
1263static void
1264model_refilter (LapizFileBrowserStore * model)
1265{
1266 model_refilter_node (model, model->priv->root, NULL((void*)0));
1267}
1268
1269static void
1270file_browser_node_set_name (FileBrowserNode * node)
1271{
1272 g_free (node->name);
1273
1274 if (node->file) {
1275 node->name = lapiz_file_browser_utils_file_basename (node->file);
1276 } else {
1277 node->name = NULL((void*)0);
1278 }
1279}
1280
1281static void
1282file_browser_node_init (FileBrowserNode * node, GFile * file,
1283 FileBrowserNode * parent)
1284{
1285 if (file != NULL((void*)0)) {
1286 node->file = g_object_ref (file)((__typeof__ (file)) (g_object_ref) (file));
1287 file_browser_node_set_name (node);
1288 }
1289
1290 node->parent = parent;
1291}
1292
1293static FileBrowserNode *
1294file_browser_node_new (GFile * file, FileBrowserNode * parent)
1295{
1296 FileBrowserNode *node = g_slice_new0 (FileBrowserNode)((FileBrowserNode*) g_slice_alloc0 (sizeof (FileBrowserNode))
)
;
1297
1298 file_browser_node_init (node, file, parent);
1299 return node;
1300}
1301
1302static FileBrowserNode *
1303file_browser_node_dir_new (LapizFileBrowserStore * model,
1304 GFile * file, FileBrowserNode * parent)
1305{
1306 FileBrowserNode *node =
1307 (FileBrowserNode *) g_slice_new0 (FileBrowserNodeDir)((FileBrowserNodeDir*) g_slice_alloc0 (sizeof (FileBrowserNodeDir
)))
;
1308
1309 file_browser_node_init (node, file, parent);
1310
1311 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY;
1312
1313 FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->model = model;
1314
1315 return node;
1316}
1317
1318static void
1319file_browser_node_free_children (LapizFileBrowserStore * model,
1320 FileBrowserNode * node)
1321{
1322 GSList *item;
1323
1324 if (node == NULL((void*)0))
1325 return;
1326
1327 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
) {
1328 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item;
1329 item = item->next)
1330 file_browser_node_free (model,
1331 (FileBrowserNode *) (item->
1332 data));
1333
1334 g_slist_free (FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children);
1335 FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children = NULL((void*)0);
1336
1337 /* This node is no longer loaded */
1338 node->flags &= ~LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED;
1339 }
1340}
1341
1342static void
1343file_browser_node_free (LapizFileBrowserStore * model,
1344 FileBrowserNode * node)
1345{
1346 gchar *uri;
1347
1348 if (node == NULL((void*)0))
1349 return;
1350
1351 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
1352 {
1353 FileBrowserNodeDir *dir;
1354
1355 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
1356
1357 if (dir->cancellable) {
1358 g_cancellable_cancel (dir->cancellable);
1359 g_object_unref (dir->cancellable);
1360
1361 model_end_loading (model, node);
1362 }
1363
1364 file_browser_node_free_children (model, node);
1365
1366 if (dir->monitor) {
1367 g_file_monitor_cancel (dir->monitor);
1368 g_object_unref (dir->monitor);
1369 }
1370 }
1371
1372 if (node->file)
1373 {
1374 uri = g_file_get_uri (node->file);
1375 g_signal_emit (model, model_signals[UNLOAD], 0, uri);
1376
1377 g_free (uri);
1378 g_object_unref (node->file);
1379 }
1380
1381 if (node->icon)
1382 g_object_unref (node->icon);
1383
1384 if (node->emblem)
1385 g_object_unref (node->emblem);
1386
1387 g_free (node->name);
1388
1389 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
1390 g_slice_free (FileBrowserNodeDir, (FileBrowserNodeDir *)node)do { if (1) g_slice_free1 (sizeof (FileBrowserNodeDir), ((FileBrowserNodeDir
*)node)); else (void) ((FileBrowserNodeDir*) 0 == ((FileBrowserNodeDir
*)node)); } while (0)
;
1391 else
1392 g_slice_free (FileBrowserNode, (FileBrowserNode *)node)do { if (1) g_slice_free1 (sizeof (FileBrowserNode), ((FileBrowserNode
*)node)); else (void) ((FileBrowserNode*) 0 == ((FileBrowserNode
*)node)); } while (0)
;
1393}
1394
1395/**
1396 * model_remove_node_children:
1397 * @model: the #LapizFileBrowserStore
1398 * @node: the FileBrowserNode to remove
1399 * @path: the path of the node, or NULL to let the path be calculated
1400 * @free_nodes: whether to also remove the nodes from memory
1401 *
1402 * Removes all the children of node from the model. This function is used
1403 * to remove the child nodes from the _model_. Don't use it to just free
1404 * a node.
1405 **/
1406static void
1407model_remove_node_children (LapizFileBrowserStore * model,
1408 FileBrowserNode * node,
1409 CtkTreePath * path,
1410 gboolean free_nodes)
1411{
1412 FileBrowserNodeDir *dir;
1413 CtkTreePath *path_child;
1414 GSList *list;
1415 GSList *item;
1416
1417 if (node == NULL((void*)0) || !NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
1418 return;
1419
1420 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
1421
1422 if (dir->children == NULL((void*)0))
1423 return;
1424
1425 if (!model_node_visibility (model, node)) {
1426 // Node is invisible and therefore the children can just
1427 // be freed
1428 if (free_nodes)
1429 file_browser_node_free_children (model, node);
1430
1431 return;
1432 }
1433
1434 if (path == NULL((void*)0))
1435 path_child =
1436 lapiz_file_browser_store_get_path_real (model, node);
1437 else
1438 path_child = ctk_tree_path_copy (path);
1439
1440 ctk_tree_path_down (path_child);
1441
1442 list = g_slist_copy (dir->children);
1443
1444 for (item = list; item; item = item->next) {
1445 model_remove_node (model, (FileBrowserNode *) (item->data),
1446 path_child, free_nodes);
1447 }
1448
1449 g_slist_free (list);
1450 ctk_tree_path_free (path_child);
1451}
1452
1453/**
1454 * model_remove_node:
1455 * @model: the #LapizFileBrowserStore
1456 * @node: the FileBrowserNode to remove
1457 * @path: the path to use to remove this node, or NULL to use the path
1458 * calculated from the node itself
1459 * @free_nodes: whether to also remove the nodes from memory
1460 *
1461 * Removes this node and all its children from the model. This function is used
1462 * to remove the node from the _model_. Don't use it to just free
1463 * a node.
1464 **/
1465static void
1466model_remove_node (LapizFileBrowserStore * model,
1467 FileBrowserNode * node,
1468 CtkTreePath * path,
1469 gboolean free_nodes)
1470{
1471 gboolean free_path = FALSE(0);
1472 FileBrowserNode *parent;
1473
1474 if (path == NULL((void*)0)) {
1475 path =
1476 lapiz_file_browser_store_get_path_real (model, node);
1477 free_path = TRUE(!(0));
1478 }
1479
1480 model_remove_node_children (model, node, path, free_nodes);
1481
1482 /* Only delete if the node is visible in the tree (but only when it's
1483 not the virtual root) */
1484 if (model_node_visibility (model, node) && node != model->priv->virtual_root)
1485 {
1486 node->inserted = FALSE(0);
1487 row_deleted (model, path);
1488 }
1489
1490 if (free_path)
1491 ctk_tree_path_free (path);
1492
1493 parent = node->parent;
1494
1495 if (free_nodes) {
1496 /* Remove the node from the parents children list */
1497 if (parent)
1498 FILE_BROWSER_NODE_DIR (node->parent)((FileBrowserNodeDir *)(node->parent))->children =
1499 g_slist_remove (FILE_BROWSER_NODE_DIR((FileBrowserNodeDir *)(node->parent))
1500 (node->parent)((FileBrowserNodeDir *)(node->parent))->children,
1501 node);
1502 }
1503
1504 /* If this is the virtual root, than set the parent as the virtual root */
1505 if (node == model->priv->virtual_root)
1506 set_virtual_root_from_node (model, parent);
1507 else if (parent && model_node_visibility (model, parent) && !(free_nodes && NODE_IS_DUMMY(node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
))
1508 model_check_dummy (model, parent);
1509
1510 /* Now free the node if necessary */
1511 if (free_nodes)
1512 file_browser_node_free (model, node);
1513}
1514
1515/**
1516 * model_clear:
1517 * @model: the #LapizFileBrowserStore
1518 * @free_nodes: whether to also remove the nodes from memory
1519 *
1520 * Removes all nodes from the model. This function is used
1521 * to remove all the nodes from the _model_. Don't use it to just free the
1522 * nodes in the model.
1523 **/
1524static void
1525model_clear (LapizFileBrowserStore * model, gboolean free_nodes)
1526{
1527 CtkTreePath *path;
1528 FileBrowserNodeDir *dir;
1529 FileBrowserNode *dummy;
1530
1531 path = ctk_tree_path_new ();
1532 model_remove_node_children (model, model->priv->virtual_root, path,
1533 free_nodes);
1534 ctk_tree_path_free (path);
1535
1536 /* Remove the dummy if there is one */
1537 if (model->priv->virtual_root) {
1538 dir = FILE_BROWSER_NODE_DIR (model->priv->virtual_root)((FileBrowserNodeDir *)(model->priv->virtual_root));
1539
1540 if (dir->children != NULL((void*)0)) {
1541 dummy = (FileBrowserNode *) (dir->children->data);
1542
1543 if (NODE_IS_DUMMY (dummy)(((dummy)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
1544 && model_node_visibility (model, dummy)) {
1545 path = ctk_tree_path_new_first ();
1546
1547 dummy->inserted = FALSE(0);
1548 row_deleted (model, path);
1549 ctk_tree_path_free (path);
1550 }
1551 }
1552 }
1553}
1554
1555static void
1556file_browser_node_unload (LapizFileBrowserStore * model,
1557 FileBrowserNode * node, gboolean remove_children)
1558{
1559 FileBrowserNodeDir *dir;
1560
1561 if (node == NULL((void*)0))
1562 return;
1563
1564 if (!NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
|| !NODE_LOADED (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED
))
)
1565 return;
1566
1567 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
1568
1569 if (remove_children)
1570 model_remove_node_children (model, node, NULL((void*)0), TRUE(!(0)));
1571
1572 if (dir->cancellable) {
1573 g_cancellable_cancel (dir->cancellable);
1574 g_object_unref (dir->cancellable);
1575
1576 model_end_loading (model, node);
1577 dir->cancellable = NULL((void*)0);
1578 }
1579
1580 if (dir->monitor) {
1581 g_file_monitor_cancel (dir->monitor);
1582 g_object_unref (dir->monitor);
1583
1584 dir->monitor = NULL((void*)0);
1585 }
1586
1587 node->flags &= ~LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED;
1588}
1589
1590static void
1591model_recomposite_icon_real (LapizFileBrowserStore * tree_model,
1592 FileBrowserNode * node,
1593 GFileInfo * info)
1594{
1595 GdkPixbuf *icon;
1596
1597 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return; } } while (0)
;
1598 g_return_if_fail (node != NULL)do { if ((node != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "node != NULL"); return
; } } while (0)
;
1599
1600 if (node->file == NULL((void*)0))
1601 return;
1602
1603 if (info) {
1604 GIcon *gicon = g_file_info_get_icon (info);
1605 if (gicon != NULL((void*)0))
1606 icon = lapiz_file_browser_utils_pixbuf_from_icon (gicon, CTK_ICON_SIZE_MENU);
1607 else
1608 icon = NULL((void*)0);
1609 } else {
1610 icon = lapiz_file_browser_utils_pixbuf_from_file (node->file, CTK_ICON_SIZE_MENU);
1611 }
1612
1613 if (node->icon)
1614 g_object_unref (node->icon);
1615
1616 if (node->emblem) {
1617 gint icon_size;
1618
1619 ctk_icon_size_lookup (CTK_ICON_SIZE_MENU, NULL((void*)0), &icon_size);
1620
1621 if (icon == NULL((void*)0)) {
1622 node->icon =
1623 gdk_pixbuf_new (gdk_pixbuf_get_colorspace (node->emblem),
1624 gdk_pixbuf_get_has_alpha (node->emblem),
1625 gdk_pixbuf_get_bits_per_sample (node->emblem),
1626 icon_size,
1627 icon_size);
1628 } else {
1629 node->icon = gdk_pixbuf_copy (icon);
1630 g_object_unref (icon);
1631 }
1632
1633 gdk_pixbuf_composite (node->emblem, node->icon,
1634 icon_size - 10, icon_size - 10, 10,
1635 10, icon_size - 10, icon_size - 10,
1636 1, 1, GDK_INTERP_NEAREST, 255);
1637 } else {
1638 node->icon = icon;
1639 }
1640}
1641
1642static void
1643model_recomposite_icon (LapizFileBrowserStore * tree_model,
1644 CtkTreeIter * iter)
1645{
1646 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return; } } while (0)
;
1647 g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
; } } while (0)
;
1648 g_return_if_fail (iter->user_data != NULL)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return; } } while (0)
;
1649
1650 model_recomposite_icon_real (tree_model,
1651 (FileBrowserNode *) (iter->user_data),
1652 NULL((void*)0));
1653}
1654
1655static FileBrowserNode *
1656model_create_dummy_node (LapizFileBrowserStore *model G_GNUC_UNUSED__attribute__ ((__unused__)),
1657 FileBrowserNode *parent)
1658{
1659 FileBrowserNode *dummy;
1660
1661 dummy = file_browser_node_new (NULL((void*)0), parent);
1662 dummy->name = g_strdup (_("(Empty)"))g_strdup_inline (((char *) g_dgettext ("lapiz", "(Empty)")));
1663
1664 dummy->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY;
1665 dummy->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1666
1667 return dummy;
1668}
1669
1670static FileBrowserNode *
1671model_add_dummy_node (LapizFileBrowserStore * model,
1672 FileBrowserNode * parent)
1673{
1674 FileBrowserNode *dummy;
1675
1676 dummy = model_create_dummy_node (model, parent);
1677
1678 if (model_node_visibility (model, parent))
1679 dummy->flags &= ~LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1680
1681 model_add_node (model, dummy, parent);
1682
1683 return dummy;
1684}
1685
1686static void
1687model_check_dummy (LapizFileBrowserStore * model, FileBrowserNode * node)
1688{
1689 // Hide the dummy child if needed
1690 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
) {
1691 FileBrowserNode *dummy;
1692 CtkTreeIter iter;
1693 CtkTreePath *path;
1694 guint flags;
1695 FileBrowserNodeDir *dir;
1696
1697 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
1698
1699 if (dir->children == NULL((void*)0)) {
1700 model_add_dummy_node (model, node);
1701 return;
1702 }
1703
1704 dummy = (FileBrowserNode *) (dir->children->data);
1705
1706 if (!NODE_IS_DUMMY (dummy)(((dummy)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
) {
1707 dummy = model_create_dummy_node (model, node);
1708 dir->children = g_slist_prepend (dir->children, dummy);
1709 }
1710
1711 if (!model_node_visibility (model, node)) {
1712 dummy->flags |=
1713 LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1714 return;
1715 }
1716
1717 /* Temporarily set the node to invisible to check
1718 * for real children */
1719 flags = dummy->flags;
1720 dummy->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1721
1722 if (!filter_tree_model_iter_has_child_real (model, node)) {
1723 dummy->flags &=
1724 ~LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1725
1726 if (FILE_IS_HIDDEN (flags)(flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN)) {
1727 // Was hidden, needs to be inserted
1728 iter.user_data = dummy;
1729 path =
1730 lapiz_file_browser_store_get_path_real
1731 (model, dummy);
1732
1733 row_inserted (model, &path, &iter);
1734 ctk_tree_path_free (path);
1735 }
1736 } else {
1737 if (!FILE_IS_HIDDEN (flags)(flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN)) {
1738 // Was shown, needs to be removed
1739
1740 // To get the path we need to set it to visible temporarily
1741 dummy->flags &=
1742 ~LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1743 path =
1744 lapiz_file_browser_store_get_path_real
1745 (model, dummy);
1746 dummy->flags |=
1747 LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1748
1749 dummy->inserted = FALSE(0);
1750 row_deleted (model, path);
1751 ctk_tree_path_free (path);
1752 }
1753 }
1754 }
1755}
1756
1757static void
1758insert_node_sorted (LapizFileBrowserStore * model,
1759 FileBrowserNode * child,
1760 FileBrowserNode * parent)
1761{
1762 FileBrowserNodeDir *dir;
1763
1764 dir = FILE_BROWSER_NODE_DIR (parent)((FileBrowserNodeDir *)(parent));
1765
1766 if (model->priv->sort_func == NULL((void*)0)) {
1767 dir->children = g_slist_append (dir->children, child);
1768 } else {
1769 dir->children =
1770 g_slist_insert_sorted (dir->children, child,
1771 (GCompareFunc) (model->priv->
1772 sort_func));
1773 }
1774}
1775
1776static void
1777model_add_node (LapizFileBrowserStore * model, FileBrowserNode * child,
1778 FileBrowserNode * parent)
1779{
1780 /* Add child to parents children */
1781 insert_node_sorted (model, child, parent);
1782
1783 if (model_node_visibility (model, parent) &&
1784 model_node_visibility (model, child)) {
1785 CtkTreeIter iter;
1786 CtkTreePath *path;
1787
1788 iter.user_data = child;
1789 path = lapiz_file_browser_store_get_path_real (model, child);
1790
1791 /* Emit row inserted */
1792 row_inserted (model, &path, &iter);
1793 ctk_tree_path_free (path);
1794 }
1795
1796 model_check_dummy (model, parent);
1797 model_check_dummy (model, child);
1798}
1799
1800static void
1801model_add_nodes_batch (LapizFileBrowserStore * model,
1802 GSList * children,
1803 FileBrowserNode * parent)
1804{
1805 GSList *sorted_children;
1806 GSList *child;
1807 GSList *prev;
1808 GSList *l;
1809 FileBrowserNodeDir *dir;
1810
1811 dir = FILE_BROWSER_NODE_DIR (parent)((FileBrowserNodeDir *)(parent));
1812
1813 sorted_children = g_slist_sort (children, (GCompareFunc) model->priv->sort_func);
1814
1815 child = sorted_children;
1816 l = dir->children;
1817 prev = NULL((void*)0);
1818
1819 model_check_dummy (model, parent);
1820
1821 while (child) {
1822 FileBrowserNode *node = child->data;
1823 CtkTreeIter iter;
1824 CtkTreePath *path;
1825
1826 /* reached the end of the first list, just append the second */
1827 if (l == NULL((void*)0)) {
1828
1829 dir->children = g_slist_concat (dir->children, child);
1830
1831 for (l = child; l; l = l->next) {
1832 if (model_node_visibility (model, parent) &&
1833 model_node_visibility (model, l->data)) {
1834 iter.user_data = l->data;
1835 path = lapiz_file_browser_store_get_path_real (model, l->data);
1836
1837 // Emit row inserted
1838 row_inserted (model, &path, &iter);
1839 ctk_tree_path_free (path);
1840 }
1841
1842 model_check_dummy (model, l->data);
1843 }
1844
1845 break;
1846 }
1847
1848 if (model->priv->sort_func (l->data, node) > 0) {
1849 GSList *next_child;
1850
1851 if (prev == NULL((void*)0)) {
1852 /* prepend to the list */
1853 dir->children = g_slist_prepend (dir->children, child);
1854 } else {
1855 prev->next = child;
1856 }
1857
1858 next_child = child->next;
1859 prev = child;
1860 child->next = l;
1861 child = next_child;
1862
1863 if (model_node_visibility (model, parent) &&
1864 model_node_visibility (model, node)) {
1865 iter.user_data = node;
1866 path = lapiz_file_browser_store_get_path_real (model, node);
1867
1868 // Emit row inserted
1869 row_inserted (model, &path, &iter);
1870 ctk_tree_path_free (path);
1871 }
1872
1873 model_check_dummy (model, node);
1874
1875 /* try again at the same l position with the
1876 * next child */
1877 } else {
1878
1879 /* Move to the next item in the list */
1880 prev = l;
1881 l = l->next;
1882 }
1883 }
1884}
1885
1886static gchar const *
1887backup_content_type (GFileInfo * info)
1888{
1889 gchar const * content;
1890
1891 if (!g_file_info_get_is_backup (info))
1892 return NULL((void*)0);
1893
1894 content = g_file_info_get_content_type (info);
1895
1896 if (!content || g_content_type_equals (content, "application/x-trash"))
1897 return "text/plain";
1898
1899 return content;
1900}
1901
1902static void
1903file_browser_node_set_from_info (LapizFileBrowserStore * model,
1904 FileBrowserNode * node,
1905 GFileInfo * info,
1906 gboolean isadded)
1907{
1908 gchar const * content;
1909 gboolean free_info = FALSE(0);
1910 CtkTreePath * path;
1911 gchar * uri;
1912 GError * error = NULL((void*)0);
1913
1914 if (info == NULL((void*)0)) {
1915 info = g_file_query_info (node->file,
1916 STANDARD_ATTRIBUTE_TYPES"standard::type" "," "standard::is-hidden" "," "standard::is-backup"
"," "standard::name" "," "standard::content-type" "," "standard::icon"
,
1917 G_FILE_QUERY_INFO_NONE,
1918 NULL((void*)0),
1919 &error);
1920
1921 if (!info) {
1922 if (!(error->domain == G_IO_ERRORg_io_error_quark() && error->code == G_IO_ERROR_NOT_FOUND)) {
1923 uri = g_file_get_uri (node->file);
1924 g_warning ("Could not get info for %s: %s", uri, error->message);
1925 g_free (uri);
1926 }
1927 g_error_free (error);
1928
1929 return;
1930 }
1931
1932 free_info = TRUE(!(0));
1933 }
1934
1935 if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info))
1936 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
1937
1938 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
1939 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY;
1940 else {
1941 if (!(content = backup_content_type (info)))
1942 content = g_file_info_get_content_type (info);
1943
1944 if (!content ||
1945 g_content_type_is_unknown (content) ||
1946 g_content_type_is_a (content, "text/plain"))
1947 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_IS_TEXT;
1948 }
1949
1950 model_recomposite_icon_real (model, node, info);
1951
1952 if (free_info)
1953 g_object_unref (info);
1954
1955 if (isadded) {
1956 path = lapiz_file_browser_store_get_path_real (model, node);
1957 model_refilter_node (model, node, &path);
1958 ctk_tree_path_free (path);
1959
1960 model_check_dummy (model, node->parent);
1961 } else {
1962 model_node_update_visibility (model, node);
1963 }
1964}
1965
1966static FileBrowserNode *
1967node_list_contains_file (GSList *children, GFile * file)
1968{
1969 GSList *item;
1970
1971 for (item = children; item; item = item->next) {
1972 FileBrowserNode *node;
1973
1974 node = (FileBrowserNode *) (item->data);
1975
1976 if (node->file != NULL((void*)0)
1977 && g_file_equal (node->file, file))
1978 return node;
1979 }
1980
1981 return NULL((void*)0);
1982}
1983
1984static FileBrowserNode *
1985model_add_node_from_file (LapizFileBrowserStore * model,
1986 FileBrowserNode * parent,
1987 GFile * file,
1988 GFileInfo * info)
1989{
1990 FileBrowserNode *node;
1991 gboolean free_info = FALSE(0);
1992 GError * error = NULL((void*)0);
1993
1994 if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)((FileBrowserNodeDir *)(parent))->children, file)) == NULL((void*)0)) {
1995 if (info == NULL((void*)0)) {
1996 info = g_file_query_info (file,
1997 STANDARD_ATTRIBUTE_TYPES"standard::type" "," "standard::is-hidden" "," "standard::is-backup"
"," "standard::name" "," "standard::content-type" "," "standard::icon"
,
1998 G_FILE_QUERY_INFO_NONE,
1999 NULL((void*)0),
2000 &error);
2001 free_info = TRUE(!(0));
2002 }
2003
2004 if (!info) {
2005 g_warning ("Error querying file info: %s", error->message);
2006 g_error_free (error);
2007
2008 /* FIXME: What to do now then... */
2009 node = file_browser_node_new (file, parent);
2010 } else if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
2011 node = file_browser_node_dir_new (model, file, parent);
2012 } else {
2013 node = file_browser_node_new (file, parent);
2014 }
2015
2016 file_browser_node_set_from_info (model, node, info, FALSE(0));
2017 model_add_node (model, node, parent);
2018
2019 if (info && free_info)
2020 g_object_unref (info);
2021 }
2022
2023 return node;
2024}
2025
2026/* We pass in a copy of the list of parent->children so that we do
2027 * not have to check if a file already exists among the ones we just
2028 * added */
2029static void
2030model_add_nodes_from_files (LapizFileBrowserStore * model,
2031 FileBrowserNode * parent,
2032 GSList * original_children,
2033 GList * files)
2034{
2035 GList *item;
2036 GSList *nodes = NULL((void*)0);
2037
2038 for (item = files; item; item = item->next) {
2039 GFileInfo *info = G_FILE_INFO (item->data)((((GFileInfo*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((item->data)), ((g_file_info_get_type ()))))))
;
2040 GFileType type;
2041 gchar const * name;
2042 GFile * file;
2043 FileBrowserNode *node;
2044
2045 type = g_file_info_get_file_type (info);
2046
2047 /* Skip all non regular, non directory files */
2048 if (type != G_FILE_TYPE_REGULAR &&
2049 type != G_FILE_TYPE_DIRECTORY &&
2050 type != G_FILE_TYPE_SYMBOLIC_LINK) {
2051 g_object_unref (info);
2052 continue;
2053 }
2054
2055 name = g_file_info_get_name (info);
2056
2057 /* Skip '.' and '..' directories */
2058 if (type == G_FILE_TYPE_DIRECTORY &&
2059 (strcmp (name, ".") == 0 ||
2060 strcmp (name, "..") == 0)) {
2061 continue;
2062 }
2063
2064 file = g_file_get_child (parent->file, name);
2065
2066 if ((node = node_list_contains_file (original_children, file)) == NULL((void*)0)) {
Although the value stored to 'node' is used in the enclosing expression, the value is never actually read from 'node'
2067
2068 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
2069 node = file_browser_node_dir_new (model, file, parent);
2070 } else {
2071 node = file_browser_node_new (file, parent);
2072 }
2073
2074 file_browser_node_set_from_info (model, node, info, FALSE(0));
2075
2076 nodes = g_slist_prepend (nodes, node);
2077 }
2078
2079 g_object_unref (file);
2080 g_object_unref (info);
2081 }
2082
2083 if (nodes)
2084 model_add_nodes_batch (model, nodes, parent);
2085}
2086
2087static FileBrowserNode *
2088model_add_node_from_dir (LapizFileBrowserStore * model,
2089 FileBrowserNode * parent,
2090 GFile * file)
2091{
2092 FileBrowserNode *node;
2093
2094 /* Check if it already exists */
2095 if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)((FileBrowserNodeDir *)(parent))->children, file)) == NULL((void*)0)) {
2096 node = file_browser_node_dir_new (model, file, parent);
2097 file_browser_node_set_from_info (model, node, NULL((void*)0), FALSE(0));
2098
2099 if (node->name == NULL((void*)0)) {
2100 file_browser_node_set_name (node);
2101 }
2102
2103 if (node->icon == NULL((void*)0)) {
2104 node->icon = lapiz_file_browser_utils_pixbuf_from_theme ("folder", CTK_ICON_SIZE_MENU);
2105 }
2106
2107 model_add_node (model, node, parent);
2108 }
2109
2110 return node;
2111}
2112
2113static void
2114on_directory_monitor_event (GFileMonitor *monitor G_GNUC_UNUSED__attribute__ ((__unused__)),
2115 GFile *file,
2116 GFile *other_file G_GNUC_UNUSED__attribute__ ((__unused__)),
2117 GFileMonitorEvent event_type,
2118 FileBrowserNode *parent)
2119{
2120 FileBrowserNode *node;
2121 FileBrowserNodeDir *dir = FILE_BROWSER_NODE_DIR (parent)((FileBrowserNodeDir *)(parent));
2122
2123 switch (event_type) {
2124 case G_FILE_MONITOR_EVENT_DELETED:
2125 node = node_list_contains_file (dir->children, file);
2126
2127 if (node != NULL((void*)0)) {
2128 model_remove_node (dir->model, node, NULL((void*)0), TRUE(!(0)));
2129 }
2130 break;
2131 case G_FILE_MONITOR_EVENT_CREATED:
2132 if (g_file_query_exists (file, NULL((void*)0))) {
2133 model_add_node_from_file (dir->model, parent, file, NULL((void*)0));
2134 }
2135
2136 break;
2137 default:
2138 break;
2139 }
2140}
2141
2142static void
2143async_node_free (AsyncNode *async)
2144{
2145 g_object_unref (async->cancellable);
2146 g_slist_free (async->original_children);
2147 g_free (async);
2148}
2149
2150static void
2151model_iterate_next_files_cb (GFileEnumerator * enumerator,
2152 GAsyncResult * result,
2153 AsyncNode * async)
2154{
2155 GList * files;
2156 GError * error = NULL((void*)0);
2157 FileBrowserNodeDir * dir = async->dir;
2158 FileBrowserNode * parent = (FileBrowserNode *)dir;
2159
2160 files = g_file_enumerator_next_files_finish (enumerator, result, &error);
2161
2162 if (files == NULL((void*)0)) {
2163 g_file_enumerator_close (enumerator, NULL((void*)0), NULL((void*)0));
2164 async_node_free (async);
2165
2166 if (!error)
2167 {
2168 /* We're done loading */
2169 g_object_unref (dir->cancellable);
2170 dir->cancellable = NULL((void*)0);
2171
2172/*
2173 * FIXME: This is temporarly, it is a bug in gio:
2174 * http://bugzilla.gnome.org/show_bug.cgi?id=565924
2175 */
2176 if (g_file_is_native (parent->file) && dir->monitor == NULL((void*)0)) {
2177 dir->monitor = g_file_monitor_directory (parent->file,
2178 G_FILE_MONITOR_NONE,
2179 NULL((void*)0),
2180 NULL((void*)0));
2181 if (dir->monitor != NULL((void*)0))
2182 {
2183 g_signal_connect (dir->monitor,g_signal_connect_data ((dir->monitor), ("changed"), (((GCallback
) (on_directory_monitor_event))), (parent), ((void*)0), (GConnectFlags
) 0)
2184 "changed",g_signal_connect_data ((dir->monitor), ("changed"), (((GCallback
) (on_directory_monitor_event))), (parent), ((void*)0), (GConnectFlags
) 0)
2185 G_CALLBACK (on_directory_monitor_event),g_signal_connect_data ((dir->monitor), ("changed"), (((GCallback
) (on_directory_monitor_event))), (parent), ((void*)0), (GConnectFlags
) 0)
2186 parent)g_signal_connect_data ((dir->monitor), ("changed"), (((GCallback
) (on_directory_monitor_event))), (parent), ((void*)0), (GConnectFlags
) 0)
;
2187 }
2188 }
2189
2190 model_check_dummy (dir->model, parent);
2191 model_end_loading (dir->model, parent);
2192 } else {
2193 /* Simply return if we were cancelled */
2194 if (error->domain == G_IO_ERRORg_io_error_quark() && error->code == G_IO_ERROR_CANCELLED)
2195 return;
2196
2197 /* Otherwise handle the error appropriately */
2198 g_signal_emit (dir->model,
2199 model_signals[ERROR],
2200 0,
2201 LAPIZ_FILE_BROWSER_ERROR_LOAD_DIRECTORY,
2202 error->message);
2203
2204 file_browser_node_unload (dir->model, (FileBrowserNode *)parent, TRUE(!(0)));
2205 g_error_free (error);
2206 }
2207 } else if (g_cancellable_is_cancelled (async->cancellable)) {
2208 /* Check cancel state manually */
2209 g_file_enumerator_close (enumerator, NULL((void*)0), NULL((void*)0));
2210 async_node_free (async);
2211 } else {
2212 model_add_nodes_from_files (dir->model, parent, async->original_children, files);
2213
2214 g_list_free (files);
2215 next_files_async (enumerator, async);
2216 }
2217}
2218
2219static void
2220next_files_async (GFileEnumerator * enumerator,
2221 AsyncNode * async)
2222{
2223 g_file_enumerator_next_files_async (enumerator,
2224 DIRECTORY_LOAD_ITEMS_PER_CALLBACK100,
2225 G_PRIORITY_DEFAULT0,
2226 async->cancellable,
2227 (GAsyncReadyCallback)model_iterate_next_files_cb,
2228 async);
2229}
2230
2231static void
2232model_iterate_children_cb (GFile * file,
2233 GAsyncResult * result,
2234 AsyncNode * async)
2235{
2236 GError * error = NULL((void*)0);
2237 GFileEnumerator * enumerator;
2238
2239 if (g_cancellable_is_cancelled (async->cancellable))
2240 {
2241 async_node_free (async);
2242 return;
2243 }
2244
2245 enumerator = g_file_enumerate_children_finish (file, result, &error);
2246
2247 if (enumerator == NULL((void*)0)) {
2248 /* Simply return if we were cancelled or if the dir is not there */
2249 FileBrowserNodeDir *dir = async->dir;
2250
2251 /* Otherwise handle the error appropriately */
2252 g_signal_emit (dir->model,
2253 model_signals[ERROR],
2254 0,
2255 LAPIZ_FILE_BROWSER_ERROR_LOAD_DIRECTORY,
2256 error->message);
2257
2258 file_browser_node_unload (dir->model, (FileBrowserNode *)dir, TRUE(!(0)));
2259 g_error_free (error);
2260 async_node_free (async);
2261 } else {
2262 next_files_async (enumerator, async);
2263 }
2264}
2265
2266static void
2267model_load_directory (LapizFileBrowserStore * model,
2268 FileBrowserNode * node)
2269{
2270 FileBrowserNodeDir *dir;
2271 AsyncNode *async;
2272
2273 g_return_if_fail (NODE_IS_DIR (node))do { if (((((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
)))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "NODE_IS_DIR (node)"); return; } } while
(0)
;
2274
2275 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
2276
2277 /* Cancel a previous load */
2278 if (dir->cancellable != NULL((void*)0)) {
2279 file_browser_node_unload (dir->model, node, TRUE(!(0)));
2280 }
2281
2282 node->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED;
2283 model_begin_loading (model, node);
2284
2285 dir->cancellable = g_cancellable_new ();
2286
2287 async = g_new (AsyncNode, 1)((AsyncNode *) g_malloc_n ((1), sizeof (AsyncNode)));
2288 async->dir = dir;
2289 async->cancellable = g_object_ref (dir->cancellable)((__typeof__ (dir->cancellable)) (g_object_ref) (dir->cancellable
))
;
2290 async->original_children = g_slist_copy (dir->children);
2291
2292 /* Start loading async */
2293 g_file_enumerate_children_async (node->file,
2294 STANDARD_ATTRIBUTE_TYPES"standard::type" "," "standard::is-hidden" "," "standard::is-backup"
"," "standard::name" "," "standard::content-type" "," "standard::icon"
,
2295 G_FILE_QUERY_INFO_NONE,
2296 G_PRIORITY_DEFAULT0,
2297 async->cancellable,
2298 (GAsyncReadyCallback)model_iterate_children_cb,
2299 async);
2300}
2301
2302static GList *
2303get_parent_files (LapizFileBrowserStore * model, GFile * file)
2304{
2305 GList * result = NULL((void*)0);
2306
2307 result = g_list_prepend (result, g_object_ref (file)((__typeof__ (file)) (g_object_ref) (file)));
2308
2309 while ((file = g_file_get_parent (file))) {
2310 if (g_file_equal (file, model->priv->root->file)) {
2311 g_object_unref (file);
2312 break;
2313 }
2314
2315 result = g_list_prepend (result, file);
2316 }
2317
2318 return result;
2319}
2320
2321static void
2322model_fill (LapizFileBrowserStore * model, FileBrowserNode * node,
2323 CtkTreePath ** path)
2324{
2325 gboolean free_path = FALSE(0);
2326 CtkTreeIter iter = {0,};
2327 GSList *item;
2328 FileBrowserNode *child;
2329
2330 if (node == NULL((void*)0)) {
2331 node = model->priv->virtual_root;
2332 *path = ctk_tree_path_new ();
2333 free_path = TRUE(!(0));
2334 }
2335
2336 if (*path == NULL((void*)0)) {
2337 *path =
2338 lapiz_file_browser_store_get_path_real (model, node);
2339 free_path = TRUE(!(0));
2340 }
2341
2342 if (!model_node_visibility (model, node)) {
2343 if (free_path)
2344 ctk_tree_path_free (*path);
2345
2346 return;
2347 }
2348
2349 if (node != model->priv->virtual_root) {
2350 /* Insert node */
2351 iter.user_data = node;
2352
2353 row_inserted(model, path, &iter);
2354 }
2355
2356 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
) {
2357 /* Go to the first child */
2358 ctk_tree_path_down (*path);
2359
2360 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item;
2361 item = item->next) {
2362 child = (FileBrowserNode *) (item->data);
2363
2364 if (model_node_visibility (model, child)) {
2365 model_fill (model, child, path);
2366
2367 /* Increase path for next child */
2368 ctk_tree_path_next (*path);
2369 }
2370 }
2371
2372 /* Move back up to node path */
2373 ctk_tree_path_up (*path);
2374 }
2375
2376 model_check_dummy (model, node);
2377
2378 if (free_path)
2379 ctk_tree_path_free (*path);
2380}
2381
2382static void
2383set_virtual_root_from_node (LapizFileBrowserStore * model,
2384 FileBrowserNode * node)
2385{
2386 FileBrowserNode *next;
2387 FileBrowserNode *prev;
2388 FileBrowserNode *check;
2389 FileBrowserNodeDir *dir;
2390 GSList *item;
2391 GSList *copy;
2392 CtkTreePath *empty = NULL((void*)0);
2393
2394 g_assert (node != NULL)do { if (node != ((void*)0)) ; else g_assertion_message_expr (
((gchar*) 0), "lapiz-file-browser-store.c", 2394, ((const char
*) (__func__)), "node != NULL"); } while (0)
;
2395
2396 prev = node;
2397 next = prev->parent;
2398
2399 /* Free all the nodes below that we don't need in cache */
2400 while (prev != model->priv->root) {
2401 dir = FILE_BROWSER_NODE_DIR (next)((FileBrowserNodeDir *)(next));
2402 copy = g_slist_copy (dir->children);
2403
2404 for (item = copy; item; item = item->next) {
2405 check = (FileBrowserNode *) (item->data);
2406
2407 if (prev == node) {
2408 /* Only free the children, keeping this depth in cache */
2409 if (check != node) {
2410 file_browser_node_free_children
2411 (model, check);
2412 file_browser_node_unload (model,
2413 check,
2414 FALSE(0));
2415 }
2416 } else if (check != prev) {
2417 /* Only free when the node is not in the chain */
2418 dir->children =
2419 g_slist_remove (dir->children, check);
2420 file_browser_node_free (model, check);
2421 }
2422 }
2423
2424 if (prev != node)
2425 file_browser_node_unload (model, next, FALSE(0));
2426
2427 g_slist_free (copy);
2428 prev = next;
2429 next = prev->parent;
2430 }
2431
2432 /* Free all the nodes up that we don't need in cache */
2433 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item;
2434 item = item->next) {
2435 check = (FileBrowserNode *) (item->data);
2436
2437 if (NODE_IS_DIR (check)(((check)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
) {
2438 for (copy =
2439 FILE_BROWSER_NODE_DIR (check)((FileBrowserNodeDir *)(check))->children; copy;
2440 copy = copy->next) {
2441 file_browser_node_free_children (model,
2442 (FileBrowserNode
2443 *)
2444 (copy->
2445 data));
2446 file_browser_node_unload (model,
2447 (FileBrowserNode
2448 *) (copy->data),
2449 FALSE(0));
2450 }
2451 } else if (NODE_IS_DUMMY (check)(((check)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
) {
2452 check->flags |=
2453 LAPIZ_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
2454 }
2455 }
2456
2457 /* Now finally, set the virtual root, and load it up! */
2458 model->priv->virtual_root = node;
2459
2460 /* Notify that the virtual-root has changed before loading up new nodes so that the
2461 "root_changed" signal can be emitted before any "inserted" signals */
2462 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "virtual-root");
2463
2464 model_fill (model, NULL((void*)0), &empty);
2465
2466 if (!NODE_LOADED (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED
))
)
2467 model_load_directory (model, node);
2468}
2469
2470static void
2471set_virtual_root_from_file (LapizFileBrowserStore * model,
2472 GFile * file)
2473{
2474 GList * files;
2475 GList * item;
2476 FileBrowserNode * parent;
2477 GFile * check;
2478
2479 /* Always clear the model before altering the nodes */
2480 model_clear (model, FALSE(0));
2481
2482 /* Create the node path, get all the uri's */
2483 files = get_parent_files (model, file);
2484 parent = model->priv->root;
2485
2486 for (item = files; item; item = item->next) {
2487 check = G_FILE (item->data)((((GFile*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((item->data)), ((g_file_get_type ()))))))
;
2488
2489 parent = model_add_node_from_dir (model, parent, check);
2490 g_object_unref (check);
2491 }
2492
2493 g_list_free (files);
2494 set_virtual_root_from_node (model, parent);
2495}
2496
2497static FileBrowserNode *
2498model_find_node_children (LapizFileBrowserStore * model,
2499 FileBrowserNode * parent,
2500 GFile * file)
2501{
2502 FileBrowserNodeDir *dir;
2503 FileBrowserNode *child;
2504 FileBrowserNode *result;
2505 GSList *children;
2506
2507 if (!NODE_IS_DIR (parent)(((parent)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
)
2508 return NULL((void*)0);
2509
2510 dir = FILE_BROWSER_NODE_DIR (parent)((FileBrowserNodeDir *)(parent));
2511
2512 for (children = dir->children; children; children = children->next) {
2513 child = (FileBrowserNode *)(children->data);
2514
2515 result = model_find_node (model, child, file);
2516
2517 if (result)
2518 return result;
2519 }
2520
2521 return NULL((void*)0);
2522}
2523
2524static FileBrowserNode *
2525model_find_node (LapizFileBrowserStore * model,
2526 FileBrowserNode * node,
2527 GFile * file)
2528{
2529 if (node == NULL((void*)0))
2530 node = model->priv->root;
2531
2532 if (node->file && g_file_equal (node->file, file))
2533 return node;
2534
2535 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
&& g_file_has_prefix (file, node->file))
2536 return model_find_node_children (model, node, file);
2537
2538 return NULL((void*)0);
2539}
2540
2541static GQuark
2542lapiz_file_browser_store_error_quark (void)
2543{
2544 static GQuark quark = 0;
2545
2546 if (G_UNLIKELY (quark == 0)(quark == 0)) {
2547 quark = g_quark_from_string ("lapiz_file_browser_store_error");
2548 }
2549
2550 return quark;
2551}
2552
2553static GFile *
2554unique_new_name (GFile * directory, gchar const * name)
2555{
2556 GFile * newuri = NULL((void*)0);
2557 guint num = 0;
2558 gchar * newname;
2559
2560 while (newuri == NULL((void*)0) || g_file_query_exists (newuri, NULL((void*)0))) {
2561 if (newuri != NULL((void*)0))
2562 g_object_unref (newuri);
2563
2564 if (num == 0)
2565 newname = g_strdup (name)g_strdup_inline (name);
2566 else
2567 newname = g_strdup_printf ("%s(%d)", name, num);
2568
2569 newuri = g_file_get_child (directory, newname);
2570 g_free (newname);
2571
2572 ++num;
2573 }
2574
2575 return newuri;
2576}
2577
2578static LapizFileBrowserStoreResult
2579model_root_mounted (LapizFileBrowserStore * model, gchar const * virtual_root)
2580{
2581 model_check_dummy (model, model->priv->root);
2582 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "root");
2583
2584 if (virtual_root != NULL((void*)0))
2585 return
2586 lapiz_file_browser_store_set_virtual_root_from_string
2587 (model, virtual_root);
2588 else
2589 set_virtual_root_from_node (model,
2590 model->priv->root);
2591
2592 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2593}
2594
2595static void
2596handle_root_error (LapizFileBrowserStore * model, GError *error)
2597{
2598 FileBrowserNode * root;
2599
2600 g_signal_emit (model,
2601 model_signals[ERROR],
2602 0,
2603 LAPIZ_FILE_BROWSER_ERROR_SET_ROOT,
2604 error->message);
2605
2606 /* Set the virtual root to the root */
2607 root = model->priv->root;
2608 model->priv->virtual_root = root;
2609
2610 /* Set the root to be loaded */
2611 root->flags |= LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED;
2612
2613 /* Check the dummy */
2614 model_check_dummy (model, root);
2615
2616 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "root");
2617 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "virtual-root");
2618}
2619
2620static void
2621mount_cb (GFile * file,
2622 GAsyncResult * res,
2623 MountInfo * mount_info)
2624{
2625 gboolean mounted;
2626 GError * error = NULL((void*)0);
2627 LapizFileBrowserStore * model = mount_info->model;
2628
2629 mounted = g_file_mount_enclosing_volume_finish (file, res, &error);
2630
2631 if (mount_info->model)
2632 {
2633 model->priv->mount_info = NULL((void*)0);
2634 model_end_loading (model, model->priv->root);
2635 }
2636
2637 if (!mount_info->model || g_cancellable_is_cancelled (mount_info->cancellable))
2638 {
2639 // Reset because it might be reused?
2640 g_cancellable_reset (mount_info->cancellable);
2641 }
2642 else if (mounted)
2643 {
2644 model_root_mounted (model, mount_info->virtual_root);
2645 }
2646 else if (error->code != G_IO_ERROR_CANCELLED)
2647 {
2648 handle_root_error (model, error);
2649 }
2650
2651 if (error)
2652 g_error_free (error);
2653
2654 g_object_unref (mount_info->operation);
2655 g_object_unref (mount_info->cancellable);
2656 g_free (mount_info->virtual_root);
2657
2658 g_free (mount_info);
2659}
2660
2661static LapizFileBrowserStoreResult
2662model_mount_root (LapizFileBrowserStore * model, gchar const * virtual_root)
2663{
2664 GFileInfo * info;
2665 GError * error = NULL((void*)0);
2666 MountInfo * mount_info;
2667
2668 info = g_file_query_info (model->priv->root->file,
2669 G_FILE_ATTRIBUTE_STANDARD_TYPE"standard::type",
2670 G_FILE_QUERY_INFO_NONE,
2671 NULL((void*)0),
2672 &error);
2673
2674 if (!info) {
2675 if (error->code == G_IO_ERROR_NOT_MOUNTED) {
2676 /* Try to mount it */
2677 FILE_BROWSER_NODE_DIR (model->priv->root)((FileBrowserNodeDir *)(model->priv->root))->cancellable = g_cancellable_new ();
2678
2679 mount_info = g_new(MountInfo, 1)((MountInfo *) g_malloc_n ((1), sizeof (MountInfo)));
2680 mount_info->model = model;
2681 mount_info->virtual_root = g_strdup (virtual_root)g_strdup_inline (virtual_root);
2682
2683 /* FIXME: we should be setting the correct window */
2684 mount_info->operation = ctk_mount_operation_new (NULL((void*)0));
2685 mount_info->cancellable = g_object_ref (FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable)((__typeof__ (((FileBrowserNodeDir *)(model->priv->root
))->cancellable)) (g_object_ref) (((FileBrowserNodeDir *)(
model->priv->root))->cancellable))
;
2686
2687 model_begin_loading (model, model->priv->root);
2688 g_file_mount_enclosing_volume (model->priv->root->file,
2689 G_MOUNT_MOUNT_NONE,
2690 mount_info->operation,
2691 mount_info->cancellable,
2692 (GAsyncReadyCallback)mount_cb,
2693 mount_info);
2694
2695 model->priv->mount_info = mount_info;
2696 return LAPIZ_FILE_BROWSER_STORE_RESULT_MOUNTING;
2697 }
2698 else
2699 {
2700 handle_root_error (model, error);
2701 }
2702
2703 g_error_free (error);
2704 } else {
2705 g_object_unref (info);
2706
2707 return model_root_mounted (model, virtual_root);
2708 }
2709
2710 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2711}
2712
2713/* Public */
2714LapizFileBrowserStore *
2715lapiz_file_browser_store_new (gchar const *root)
2716{
2717 LapizFileBrowserStore *obj =
2718 LAPIZ_FILE_BROWSER_STORE (g_object_new((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((g_object_new ((lapiz_file_browser_store_get_type
()), ((void*)0)))), ((lapiz_file_browser_store_get_type ()))
))))
2719 (LAPIZ_TYPE_FILE_BROWSER_STORE,((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((g_object_new ((lapiz_file_browser_store_get_type
()), ((void*)0)))), ((lapiz_file_browser_store_get_type ()))
))))
2720 NULL))((((LapizFileBrowserStore*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((g_object_new ((lapiz_file_browser_store_get_type
()), ((void*)0)))), ((lapiz_file_browser_store_get_type ()))
))))
;
2721
2722 lapiz_file_browser_store_set_root (obj, root);
2723 return obj;
2724}
2725
2726void
2727lapiz_file_browser_store_set_value (LapizFileBrowserStore * tree_model,
2728 CtkTreeIter * iter, gint column,
2729 GValue * value)
2730{
2731 gpointer data;
2732 FileBrowserNode *node;
2733 CtkTreePath *path;
2734
2735 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (tree_model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((tree_model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (tree_model)"
); return; } } while (0)
;
2736 g_return_if_fail (column ==do { if ((column == LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM)) {
} else { g_return_if_fail_warning (((gchar*) 0), ((const char
*) (__func__)), "column == LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM"
); return; } } while (0)
2737 LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM)do { if ((column == LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM)) {
} else { g_return_if_fail_warning (((gchar*) 0), ((const char
*) (__func__)), "column == LAPIZ_FILE_BROWSER_STORE_COLUMN_EMBLEM"
); return; } } while (0)
;
2738 g_return_if_fail (G_VALUE_HOLDS_OBJECT (value))do { if (((((__extension__ ({ const GValue *__val = (const GValue
*) ((value)); GType __t = (((GType) ((20) << (2)))); gboolean
__r; if (!__val) __r = (0); else if (__val->g_type == __t
) __r = (!(0)); else __r = g_type_check_value_holds (__val, __t
); __r; })))))) { } else { g_return_if_fail_warning (((gchar*
) 0), ((const char*) (__func__)), "G_VALUE_HOLDS_OBJECT (value)"
); return; } } while (0)
;
2739 g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
; } } while (0)
;
2740 g_return_if_fail (iter->user_data != NULL)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return; } } while (0)
;
2741
2742 data = g_value_get_object (value);
2743
2744 if (data)
2745 g_return_if_fail (GDK_IS_PIXBUF (data))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((data)); GType __t = ((gdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; })))))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "GDK_IS_PIXBUF (data)"); return; } } while (0)
;
2746
2747 node = (FileBrowserNode *) (iter->user_data);
2748
2749 if (node->emblem)
2750 g_object_unref (node->emblem);
2751
2752 if (data)
2753 node->emblem = g_object_ref (GDK_PIXBUF (data))((__typeof__ (((((GdkPixbuf*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((data)), ((gdk_pixbuf_get_type ()))))))))
(g_object_ref) (((((GdkPixbuf*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((data)), ((gdk_pixbuf_get_type ()))))))))
;
2754 else
2755 node->emblem = NULL((void*)0);
2756
2757 model_recomposite_icon (tree_model, iter);
2758
2759 if (model_node_visibility (tree_model, node)) {
2760 path = lapiz_file_browser_store_get_path (CTK_TREE_MODEL (tree_model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((tree_model)), ((ctk_tree_model_get_type ()))))))
,
2761 iter);
2762 row_changed (tree_model, &path, iter);
2763 ctk_tree_path_free (path);
2764 }
2765}
2766
2767LapizFileBrowserStoreResult
2768lapiz_file_browser_store_set_virtual_root (LapizFileBrowserStore * model,
2769 CtkTreeIter * iter)
2770{
2771 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2772 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2773 g_return_val_if_fail (iter != NULL,do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
(LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while (0)
2774 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
(LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while (0)
;
2775 g_return_val_if_fail (iter->user_data != NULL,do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2776 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2777
2778 model_clear (model, FALSE(0));
2779 set_virtual_root_from_node (model,
2780 (FileBrowserNode *) (iter->user_data));
2781
2782 return TRUE(!(0));
2783}
2784
2785LapizFileBrowserStoreResult
2786lapiz_file_browser_store_set_virtual_root_from_string
2787 (LapizFileBrowserStore * model, gchar const *root) {
2788 GFile *file;
2789
2790 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2791 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2792
2793 file = g_file_new_for_uri (root);
2794 if (file == NULL((void*)0)) {
2795 g_warning ("Invalid uri (%s)", root);
2796 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2797 }
2798
2799 /* Check if uri is already the virtual root */
2800 if (model->priv->virtual_root &&
2801 g_file_equal (model->priv->virtual_root->file, file)) {
2802 g_object_unref (file);
2803 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2804 }
2805
2806 /* Check if uri is the root itself */
2807 if (g_file_equal (model->priv->root->file, file)) {
2808 g_object_unref (file);
2809
2810 /* Always clear the model before altering the nodes */
2811 model_clear (model, FALSE(0));
2812 set_virtual_root_from_node (model, model->priv->root);
2813 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2814 }
2815
2816 if (!g_file_has_prefix (file, model->priv->root->file)) {
2817 gchar *str, *str1;
2818
2819 str = g_file_get_parse_name (model->priv->root->file);
2820 str1 = g_file_get_parse_name (file);
2821
2822 g_warning
2823 ("Virtual root (%s) is not below actual root (%s)",
2824 str1, str);
2825
2826 g_free (str);
2827 g_free (str1);
2828
2829 g_object_unref (file);
2830 return LAPIZ_FILE_BROWSER_STORE_RESULT_ERROR;
2831 }
2832
2833 set_virtual_root_from_file (model, file);
2834 g_object_unref (file);
2835
2836 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2837}
2838
2839LapizFileBrowserStoreResult
2840lapiz_file_browser_store_set_virtual_root_top (LapizFileBrowserStore *
2841 model)
2842{
2843 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2844 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2845
2846 if (model->priv->virtual_root == model->priv->root)
2847 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2848
2849 model_clear (model, FALSE(0));
2850 set_virtual_root_from_node (model, model->priv->root);
2851
2852 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2853}
2854
2855LapizFileBrowserStoreResult
2856lapiz_file_browser_store_set_virtual_root_up (LapizFileBrowserStore *
2857 model)
2858{
2859 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2860 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2861
2862 if (model->priv->virtual_root == model->priv->root)
2863 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2864
2865 model_clear (model, FALSE(0));
2866 set_virtual_root_from_node (model,
2867 model->priv->virtual_root->parent);
2868
2869 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2870}
2871
2872gboolean
2873lapiz_file_browser_store_get_iter_virtual_root (LapizFileBrowserStore *
2874 model, CtkTreeIter * iter)
2875{
2876 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return ((0)); } } while (0)
;
2877 g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
((0)); } } while (0)
;
2878
2879 if (model->priv->virtual_root == NULL((void*)0))
2880 return FALSE(0);
2881
2882 iter->user_data = model->priv->virtual_root;
2883 return TRUE(!(0));
2884}
2885
2886gboolean
2887lapiz_file_browser_store_get_iter_root (LapizFileBrowserStore * model,
2888 CtkTreeIter * iter)
2889{
2890 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return ((0)); } } while (0)
;
2891 g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
((0)); } } while (0)
;
2892
2893 if (model->priv->root == NULL((void*)0))
2894 return FALSE(0);
2895
2896 iter->user_data = model->priv->root;
2897 return TRUE(!(0));
2898}
2899
2900gboolean
2901lapiz_file_browser_store_iter_equal (LapizFileBrowserStore * model,
2902 CtkTreeIter * iter1,
2903 CtkTreeIter * iter2)
2904{
2905 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return ((0)); } } while (0)
;
2906 g_return_val_if_fail (iter1 != NULL, FALSE)do { if ((iter1 != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter1 != NULL");
return ((0)); } } while (0)
;
2907 g_return_val_if_fail (iter2 != NULL, FALSE)do { if ((iter2 != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter2 != NULL");
return ((0)); } } while (0)
;
2908 g_return_val_if_fail (iter1->user_data != NULL, FALSE)do { if ((iter1->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter1->user_data != NULL"
); return ((0)); } } while (0)
;
2909 g_return_val_if_fail (iter2->user_data != NULL, FALSE)do { if ((iter2->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter2->user_data != NULL"
); return ((0)); } } while (0)
;
2910
2911 return (iter1->user_data == iter2->user_data);
2912}
2913
2914void
2915lapiz_file_browser_store_cancel_mount_operation (LapizFileBrowserStore *store)
2916{
2917 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (store))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((store)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (store)"
); return; } } while (0)
;
2918
2919 cancel_mount_operation (store);
2920}
2921
2922LapizFileBrowserStoreResult
2923lapiz_file_browser_store_set_root_and_virtual_root (LapizFileBrowserStore *
2924 model,
2925 gchar const *root,
2926 gchar const *virtual_root)
2927{
2928 GFile * file = NULL((void*)0);
2929 GFile * vfile = NULL((void*)0);
2930 FileBrowserNode * node;
2931 gboolean equal = FALSE(0);
2932
2933 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2934 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2935
2936 if (root == NULL((void*)0) && model->priv->root == NULL((void*)0))
2937 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2938
2939 if (root != NULL((void*)0)) {
2940 file = g_file_new_for_uri (root);
2941 }
2942
2943 if (root != NULL((void*)0) && model->priv->root != NULL((void*)0)) {
2944 equal = g_file_equal (file, model->priv->root->file);
2945
2946 if (equal && virtual_root == NULL((void*)0)) {
2947 g_object_unref (file);
2948 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2949 }
2950 }
2951
2952 if (virtual_root) {
2953 vfile = g_file_new_for_uri (virtual_root);
2954
2955 if (equal && g_file_equal (vfile, model->priv->virtual_root->file)) {
2956 if (file)
2957 g_object_unref (file);
2958
2959 g_object_unref (vfile);
2960 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
2961 }
2962
2963 g_object_unref (vfile);
2964 }
2965
2966 /* make sure to cancel any previous mount operations */
2967 cancel_mount_operation (model);
2968
2969 /* Always clear the model before altering the nodes */
2970 model_clear (model, TRUE(!(0)));
2971 file_browser_node_free (model, model->priv->root);
2972
2973 model->priv->root = NULL((void*)0);
2974 model->priv->virtual_root = NULL((void*)0);
2975
2976 if (file != NULL((void*)0)) {
2977 /* Create the root node */
2978 node = file_browser_node_dir_new (model, file, NULL((void*)0));
2979
2980 g_object_unref (file);
2981
2982 model->priv->root = node;
2983 return model_mount_root (model, virtual_root);
2984 } else {
2985 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "root");
2986 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "virtual-root");
2987 }
2988
2989 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
2990}
2991
2992LapizFileBrowserStoreResult
2993lapiz_file_browser_store_set_root (LapizFileBrowserStore * model,
2994 gchar const *root)
2995{
2996 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model),do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
2997 LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
2998 return lapiz_file_browser_store_set_root_and_virtual_root (model,
2999 root,
3000 NULL((void*)0));
3001}
3002
3003gchar *
3004lapiz_file_browser_store_get_root (LapizFileBrowserStore * model)
3005{
3006 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (((void*)0)); } } while (0)
;
3007
3008 if (model->priv->root == NULL((void*)0) || model->priv->root->file == NULL((void*)0))
3009 return NULL((void*)0);
3010 else
3011 return g_file_get_uri (model->priv->root->file);
3012}
3013
3014gchar *
3015lapiz_file_browser_store_get_virtual_root (LapizFileBrowserStore * model)
3016{
3017 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (((void*)0)); } } while (0)
;
3018
3019 if (model->priv->virtual_root == NULL((void*)0) || model->priv->virtual_root->file == NULL((void*)0))
3020 return NULL((void*)0);
3021 else
3022 return g_file_get_uri (model->priv->virtual_root->file);
3023}
3024
3025void
3026_lapiz_file_browser_store_iter_expanded (LapizFileBrowserStore * model,
3027 CtkTreeIter * iter)
3028{
3029 FileBrowserNode *node;
3030
3031 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return; } } while (0)
;
3032 g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
; } } while (0)
;
3033 g_return_if_fail (iter->user_data != NULL)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return; } } while (0)
;
3034
3035 node = (FileBrowserNode *) (iter->user_data);
3036
3037 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
&& !NODE_LOADED (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED
))
) {
3038 /* Load it now */
3039 model_load_directory (model, node);
3040 }
3041}
3042
3043void
3044_lapiz_file_browser_store_iter_collapsed (LapizFileBrowserStore * model,
3045 CtkTreeIter * iter)
3046{
3047 FileBrowserNode *node;
3048 GSList *item;
3049
3050 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return; } } while (0)
;
3051 g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
; } } while (0)
;
3052 g_return_if_fail (iter->user_data != NULL)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return; } } while (0)
;
3053
3054 node = (FileBrowserNode *) (iter->user_data);
3055
3056 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
&& NODE_LOADED (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED
))
) {
3057 /* Unload children of the children, keeping 1 depth in cache */
3058
3059 for (item = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node))->children; item;
3060 item = item->next) {
3061 node = (FileBrowserNode *) (item->data);
3062
3063 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
&& NODE_LOADED (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_LOADED
))
) {
3064 file_browser_node_unload (model, node,
3065 TRUE(!(0)));
3066 model_check_dummy (model, node);
3067 }
3068 }
3069 }
3070}
3071
3072LapizFileBrowserStoreFilterMode
3073lapiz_file_browser_store_get_filter_mode (LapizFileBrowserStore * model)
3074{
3075 return model->priv->filter_mode;
3076}
3077
3078void
3079lapiz_file_browser_store_set_filter_mode (LapizFileBrowserStore * model,
3080 LapizFileBrowserStoreFilterMode
3081 mode)
3082{
3083 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return; } } while (0)
;
3084
3085 if (model->priv->filter_mode == mode)
3086 return;
3087
3088 model->priv->filter_mode = mode;
3089 model_refilter (model);
3090
3091 g_object_notify (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), (((GType) ((20) << (2))))))))
, "filter-mode");
3092}
3093
3094void
3095lapiz_file_browser_store_set_filter_func (LapizFileBrowserStore * model,
3096 LapizFileBrowserStoreFilterFunc
3097 func, gpointer user_data)
3098{
3099 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return; } } while (0)
;
3100
3101 model->priv->filter_func = func;
3102 model->priv->filter_user_data = user_data;
3103 model_refilter (model);
3104}
3105
3106void
3107lapiz_file_browser_store_refilter (LapizFileBrowserStore * model)
3108{
3109 model_refilter (model);
3110}
3111
3112LapizFileBrowserStoreFilterMode
3113lapiz_file_browser_store_filter_mode_get_default (void)
3114{
3115 return LAPIZ_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
3116}
3117
3118void
3119lapiz_file_browser_store_refresh (LapizFileBrowserStore * model)
3120{
3121 g_return_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return; } } while (0)
;
3122
3123 if (model->priv->root == NULL((void*)0) || model->priv->virtual_root == NULL((void*)0))
3124 return;
3125
3126 /* Clear the model */
3127 g_signal_emit (model, model_signals[BEGIN_REFRESH], 0);
3128 file_browser_node_unload (model, model->priv->virtual_root, TRUE(!(0)));
3129 model_load_directory (model, model->priv->virtual_root);
3130 g_signal_emit (model, model_signals[END_REFRESH], 0);
3131}
3132
3133static void
3134reparent_node (FileBrowserNode * node, gboolean reparent)
3135{
3136 FileBrowserNodeDir * dir;
3137 GSList * child;
3138 GFile * parent;
3139 gchar * base;
3140
3141 if (!node->file) {
3142 return;
3143 }
3144
3145 if (reparent) {
3146 parent = node->parent->file;
3147 base = g_file_get_basename (node->file);
3148 g_object_unref (node->file);
3149
3150 node->file = g_file_get_child (parent, base);
3151 g_free (base);
3152 }
3153
3154 if (NODE_IS_DIR (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY
))
) {
3155 dir = FILE_BROWSER_NODE_DIR (node)((FileBrowserNodeDir *)(node));
3156
3157 for (child = dir->children; child; child = child->next) {
3158 reparent_node ((FileBrowserNode *)child->data, TRUE(!(0)));
3159 }
3160 }
3161}
3162
3163gboolean
3164lapiz_file_browser_store_rename (LapizFileBrowserStore * model,
3165 CtkTreeIter * iter,
3166 const gchar * new_name,
3167 GError ** error)
3168{
3169 FileBrowserNode *node;
3170 GFile * file;
3171 GFile * parent;
3172 GFile * previous;
3173 GError * err = NULL((void*)0);
3174 gchar * olduri;
3175 gchar * newuri;
3176 CtkTreePath *path;
3177
3178 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return ((0)); } } while (0)
;
3179 g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
((0)); } } while (0)
;
3180 g_return_val_if_fail (iter->user_data != NULL, FALSE)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return ((0)); } } while (0)
;
3181
3182 node = (FileBrowserNode *) (iter->user_data);
3183
3184 parent = g_file_get_parent (node->file);
3185 g_return_val_if_fail (parent != NULL, FALSE)do { if ((parent != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "parent != NULL")
; return ((0)); } } while (0)
;
3186
3187 file = g_file_get_child (parent, new_name);
3188 g_object_unref (parent);
3189
3190 if (g_file_equal (node->file, file)) {
3191 g_object_unref (file);
3192 return TRUE(!(0));
3193 }
3194
3195 if (g_file_move (node->file, file, G_FILE_COPY_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0), &err)) {
3196 previous = node->file;
3197 node->file = file;
3198
3199 /* This makes sure the actual info for the node is requeried */
3200 file_browser_node_set_name (node);
3201 file_browser_node_set_from_info (model, node, NULL((void*)0), TRUE(!(0)));
3202
3203 reparent_node (node, FALSE(0));
3204
3205 if (model_node_visibility (model, node)) {
3206 path = lapiz_file_browser_store_get_path_real (model, node);
3207 row_changed (model, &path, iter);
3208 ctk_tree_path_free (path);
3209
3210 /* Reorder this item */
3211 model_resort_node (model, node);
3212 } else {
3213 g_object_unref (previous);
3214
3215 if (error != NULL((void*)0))
3216 *error = g_error_new_literal (lapiz_file_browser_store_error_quark (),
3217 LAPIZ_FILE_BROWSER_ERROR_RENAME,
3218 _("The renamed file is currently filtered out. You need to adjust your filter settings to make the file visible")((char *) g_dgettext ("lapiz", "The renamed file is currently filtered out. You need to adjust your filter settings to make the file visible"
))
);
3219 return FALSE(0);
3220 }
3221
3222 olduri = g_file_get_uri (previous);
3223 newuri = g_file_get_uri (node->file);
3224
3225 g_signal_emit (model, model_signals[RENAME], 0, olduri, newuri);
3226
3227 g_object_unref (previous);
3228 g_free (olduri);
3229 g_free (newuri);
3230
3231 return TRUE(!(0));
3232 } else {
3233 g_object_unref (file);
3234
3235 if (err) {
3236 if (error != NULL((void*)0)) {
3237 *error =
3238 g_error_new_literal
3239 (lapiz_file_browser_store_error_quark (),
3240 LAPIZ_FILE_BROWSER_ERROR_RENAME,
3241 err->message);
3242 }
3243
3244 g_error_free (err);
3245 }
3246
3247 return FALSE(0);
3248 }
3249}
3250
3251static void
3252async_data_free (AsyncData * data)
3253{
3254 g_object_unref (data->cancellable);
3255
3256 g_list_foreach (data->files, (GFunc)g_object_unref, NULL((void*)0));
3257 g_list_free (data->files);
3258
3259 if (!data->removed)
3260 data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data);
3261
3262 g_free (data);
3263}
3264
3265static gboolean
3266emit_no_trash (AsyncData * data)
3267{
3268 /* Emit the no trash error */
3269 gboolean ret;
3270
3271 g_signal_emit (data->model, model_signals[NO_TRASH], 0, data->files, &ret);
3272 return ret;
3273}
3274
3275static void
3276delete_file_finished (GFile *file,
3277 GAsyncResult *res,
3278 AsyncData *data)
3279{
3280 GError * error = NULL((void*)0);
3281 gboolean ok;
3282
3283 if (data->trash)
3284 {
3285 ok = g_file_trash_finish (file, res, &error);
3286 }
3287 else
3288 {
3289 ok = g_file_delete_finish (file, res, &error);
3290 }
3291
3292 if (ok)
3293 {
3294 /* Remove the file from the model */
3295 FileBrowserNode *node = model_find_node (data->model, NULL((void*)0), file);
3296
3297 if (node != NULL((void*)0))
3298 {
3299 model_remove_node (data->model, node, NULL((void*)0), TRUE(!(0)));
3300 }
3301
3302 /* Process the next file */
3303 data->iter = data->iter->next;
3304 }
3305 else if (!ok && error != NULL((void*)0))
3306 {
3307 gint code = error->code;
3308 g_error_free (error);
3309
3310 if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) {
3311 /* Trash is not supported on this system. Ask the user
3312 * if he wants to delete completely the files instead.
3313 */
3314 if (emit_no_trash (data))
3315 {
3316 /* Changes this into a delete job */
3317 data->trash = FALSE(0);
3318 data->iter = data->files;
3319 }
3320 else
3321 {
3322 /* End the job */
3323 async_data_free (data);
3324 return;
3325 }
3326 }
3327 else if (code == G_IO_ERROR_CANCELLED)
3328 {
3329 /* Job has been cancelled, end the job */
3330 async_data_free (data);
3331 return;
3332 }
3333 }
3334
3335 /* Continue the job */
3336 delete_files (data);
3337}
3338
3339static void
3340delete_files (AsyncData *data)
3341{
3342 GFile *file;
3343
3344 /* Check if our job is done */
3345 if (data->iter == NULL((void*)0))
3346 {
3347 async_data_free (data);
3348 return;
3349 }
3350
3351 file = G_FILE (data->iter->data)((((GFile*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((data->iter->data)), ((g_file_get_type ()))))))
;
3352
3353 if (data->trash)
3354 {
3355 g_file_trash_async (file,
3356 G_PRIORITY_DEFAULT0,
3357 data->cancellable,
3358 (GAsyncReadyCallback)delete_file_finished,
3359 data);
3360 }
3361 else
3362 {
3363 g_file_delete_async (file,
3364 G_PRIORITY_DEFAULT0,
3365 data->cancellable,
3366 (GAsyncReadyCallback)delete_file_finished,
3367 data);
3368 }
3369}
3370
3371LapizFileBrowserStoreResult
3372lapiz_file_browser_store_delete_all (LapizFileBrowserStore *model,
3373 GList *rows, gboolean trash)
3374{
3375 FileBrowserNode * node;
3376 AsyncData * data;
3377 GList * files = NULL((void*)0);
3378 GList * row;
3379 CtkTreeIter iter;
3380 CtkTreePath * prev = NULL((void*)0);
3381 CtkTreePath * path;
3382
3383 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
3384
3385 if (rows == NULL((void*)0))
3386 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
3387
3388 /* First we sort the paths so that we can later on remove any
3389 files/directories that are actually subfiles/directories of
3390 a directory that's also deleted */
3391 rows = g_list_sort (g_list_copy (rows), (GCompareFunc)ctk_tree_path_compare);
3392
3393 for (row = rows; row; row = row->next) {
3394 path = (CtkTreePath *)(row->data);
3395
3396 if (!ctk_tree_model_get_iter (CTK_TREE_MODEL (model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((model)), ((ctk_tree_model_get_type ()))))))
, &iter, path))
3397 continue;
3398
3399 /* Skip if the current path is actually a descendant of the
3400 previous path */
3401 if (prev != NULL((void*)0) && ctk_tree_path_is_descendant (path, prev))
3402 continue;
3403
3404 prev = path;
3405 node = (FileBrowserNode *)(iter.user_data);
3406 files = g_list_prepend (files, g_object_ref (node->file)((__typeof__ (node->file)) (g_object_ref) (node->file)));
3407 }
3408
3409 data = g_new (AsyncData, 1)((AsyncData *) g_malloc_n ((1), sizeof (AsyncData)));
3410
3411 data->model = model;
3412 data->cancellable = g_cancellable_new ();
3413 data->files = files;
3414 data->trash = trash;
3415 data->iter = files;
3416 data->removed = FALSE(0);
3417
3418 model->priv->async_handles =
3419 g_slist_prepend (model->priv->async_handles, data);
3420
3421 delete_files (data);
3422 g_list_free (rows);
3423
3424 return LAPIZ_FILE_BROWSER_STORE_RESULT_OK;
3425}
3426
3427LapizFileBrowserStoreResult
3428lapiz_file_browser_store_delete (LapizFileBrowserStore * model,
3429 CtkTreeIter * iter, gboolean trash)
3430{
3431 FileBrowserNode *node;
3432 GList *rows = NULL((void*)0);
3433 LapizFileBrowserStoreResult result;
3434
3435 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
3436 g_return_val_if_fail (iter != NULL, LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
(LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while (0)
;
3437 g_return_val_if_fail (iter->user_data != NULL, LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE)do { if ((iter->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter->user_data != NULL"
); return (LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE); } } while
(0)
;
3438
3439 node = (FileBrowserNode *) (iter->user_data);
3440
3441 if (NODE_IS_DUMMY (node)(((node)->flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DUMMY
))
)
3442 return LAPIZ_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
3443
3444 rows = g_list_append(NULL((void*)0), lapiz_file_browser_store_get_path_real (model, node));
3445 result = lapiz_file_browser_store_delete_all (model, rows, trash);
3446
3447 g_list_foreach (rows, (GFunc)ctk_tree_path_free, NULL((void*)0));
3448 g_list_free (rows);
3449
3450 return result;
3451}
3452
3453gboolean
3454lapiz_file_browser_store_new_file (LapizFileBrowserStore * model,
3455 CtkTreeIter * parent,
3456 CtkTreeIter * iter)
3457{
3458 GFile * file;
3459 GFileOutputStream * stream;
3460 FileBrowserNodeDir *parent_node;
3461 gboolean result = FALSE(0);
3462 FileBrowserNode *node;
3463 GError * error = NULL((void*)0);
3464
3465 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return ((0)); } } while (0)
;
3466 g_return_val_if_fail (parent != NULL, FALSE)do { if ((parent != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "parent != NULL")
; return ((0)); } } while (0)
;
3467 g_return_val_if_fail (parent->user_data != NULL, FALSE)do { if ((parent->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "parent->user_data != NULL"
); return ((0)); } } while (0)
;
3468 g_return_val_if_fail (NODE_IS_DIRdo { if ((((((FileBrowserNode *) (parent->user_data))->
flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "NODE_IS_DIR ((FileBrowserNode *) (parent->user_data))"
); return ((0)); } } while (0)
3469 ((FileBrowserNode *) (parent->user_data)),do { if ((((((FileBrowserNode *) (parent->user_data))->
flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "NODE_IS_DIR ((FileBrowserNode *) (parent->user_data))"
); return ((0)); } } while (0)
3470 FALSE)do { if ((((((FileBrowserNode *) (parent->user_data))->
flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "NODE_IS_DIR ((FileBrowserNode *) (parent->user_data))"
); return ((0)); } } while (0)
;
3471 g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
((0)); } } while (0)
;
3472
3473 parent_node = FILE_BROWSER_NODE_DIR (parent->user_data)((FileBrowserNodeDir *)(parent->user_data));
3474 /* Translators: This is the default name of new files created by the file browser pane. */
3475 file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file")((char *) g_dgettext ("lapiz", "file")));
3476
3477 stream = g_file_create (file, G_FILE_CREATE_NONE, NULL((void*)0), &error);
3478
3479 if (!stream)
3480 {
3481 g_signal_emit (model, model_signals[ERROR], 0,
3482 LAPIZ_FILE_BROWSER_ERROR_NEW_FILE,
3483 error->message);
3484 g_error_free (error);
3485 } else {
3486 g_object_unref (stream);
3487 node = model_add_node_from_file (model,
3488 (FileBrowserNode *)parent_node,
3489 file,
3490 NULL((void*)0));
3491
3492 if (model_node_visibility (model, node)) {
3493 iter->user_data = node;
3494 result = TRUE(!(0));
3495 } else {
3496 g_signal_emit (model, model_signals[ERROR], 0,
3497 LAPIZ_FILE_BROWSER_ERROR_NEW_FILE,
3498 _((char *) g_dgettext ("lapiz", "The new file is currently filtered out. You need to adjust your filter settings to make the file visible"
))
3499 ("The new file is currently filtered out. You need to adjust your filter settings to make the file visible")((char *) g_dgettext ("lapiz", "The new file is currently filtered out. You need to adjust your filter settings to make the file visible"
))
);
3500 }
3501 }
3502
3503 g_object_unref (file);
3504 return result;
3505}
3506
3507gboolean
3508lapiz_file_browser_store_new_directory (LapizFileBrowserStore * model,
3509 CtkTreeIter * parent,
3510 CtkTreeIter * iter)
3511{
3512 GFile * file;
3513 FileBrowserNodeDir *parent_node;
3514 GError * error = NULL((void*)0);
3515 FileBrowserNode *node;
3516 gboolean result = FALSE(0);
3517
3518 g_return_val_if_fail (LAPIZ_IS_FILE_BROWSER_STORE (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((model)); GType __t = ((lapiz_file_browser_store_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "LAPIZ_IS_FILE_BROWSER_STORE (model)"
); return ((0)); } } while (0)
;
3519 g_return_val_if_fail (parent != NULL, FALSE)do { if ((parent != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "parent != NULL")
; return ((0)); } } while (0)
;
3520 g_return_val_if_fail (parent->user_data != NULL, FALSE)do { if ((parent->user_data != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "parent->user_data != NULL"
); return ((0)); } } while (0)
;
3521 g_return_val_if_fail (NODE_IS_DIRdo { if ((((((FileBrowserNode *) (parent->user_data))->
flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "NODE_IS_DIR ((FileBrowserNode *) (parent->user_data))"
); return ((0)); } } while (0)
3522 ((FileBrowserNode *) (parent->user_data)),do { if ((((((FileBrowserNode *) (parent->user_data))->
flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "NODE_IS_DIR ((FileBrowserNode *) (parent->user_data))"
); return ((0)); } } while (0)
3523 FALSE)do { if ((((((FileBrowserNode *) (parent->user_data))->
flags & LAPIZ_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "NODE_IS_DIR ((FileBrowserNode *) (parent->user_data))"
); return ((0)); } } while (0)
;
3524 g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "iter != NULL"); return
((0)); } } while (0)
;
3525
3526 parent_node = FILE_BROWSER_NODE_DIR (parent->user_data)((FileBrowserNodeDir *)(parent->user_data));
3527 /* Translators: This is the default name of new directories created by the file browser pane. */
3528 file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("directory")((char *) g_dgettext ("lapiz", "directory")));
3529
3530 if (!g_file_make_directory (file, NULL((void*)0), &error)) {
3531 g_signal_emit (model, model_signals[ERROR], 0,
3532 LAPIZ_FILE_BROWSER_ERROR_NEW_DIRECTORY,
3533 error->message);
3534 g_error_free (error);
3535 } else {
3536 node = model_add_node_from_file (model,
3537 (FileBrowserNode *)parent_node,
3538 file,
3539 NULL((void*)0));
3540
3541 if (model_node_visibility (model, node)) {
3542 iter->user_data = node;
3543 result = TRUE(!(0));
3544 } else {
3545 g_signal_emit (model, model_signals[ERROR], 0,
3546 LAPIZ_FILE_BROWSER_ERROR_NEW_FILE,
3547 _((char *) g_dgettext ("lapiz", "The new directory is currently filtered out. You need to adjust your filter settings to make the directory visible"
))
3548 ("The new directory is currently filtered out. You need to adjust your filter settings to make the directory visible")((char *) g_dgettext ("lapiz", "The new directory is currently filtered out. You need to adjust your filter settings to make the directory visible"
))
);
3549 }
3550 }
3551
3552 g_object_unref (file);
3553 return result;
3554}
3555
3556void
3557_lapiz_file_browser_store_register_type (GTypeModule *type_module)
3558{
3559 lapiz_file_browser_store_register_type (type_module);
3560}
3561
3562// ex:ts=8:noet: