1 /* GTK - The GIMP Toolkit
2 * gtkfilesystem.h: Abstract file system interfaces
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __GTK_FILE_SYSTEM_H__
22 #define __GTK_FILE_SYSTEM_H__
24 /* This is a "semi-private" header; it is meant only for
25 * alternate GtkFileChooser backend modules; no stability guarantees
26 * are made at this point
28 #ifndef GTK_FILE_SYSTEM_ENABLE_UNSUPPORTED
29 #error "GtkFileSystem is not supported API for general use"
32 #include <glib-object.h>
33 #include <gtk/gtkwidget.h> /* For icon handling */
37 typedef gint64 GtkFileTime;
39 typedef struct _GtkFileFolder GtkFileFolder;
40 typedef struct _GtkFileFolderIface GtkFileFolderIface;
41 typedef struct _GtkFileInfo GtkFileInfo;
42 typedef struct _GtkFileSystem GtkFileSystem;
43 typedef struct _GtkFileSystemIface GtkFileSystemIface;
44 typedef struct _GtkFileSystemVolume GtkFileSystemVolume;
46 typedef struct _GtkFilePath GtkFilePath;
48 /* Mask of information about a file, for monitoring and
49 * gtk_file_system_get_info()
52 GTK_FILE_INFO_DISPLAY_NAME = 1 << 0,
53 GTK_FILE_INFO_IS_FOLDER = 1 << 1,
54 GTK_FILE_INFO_IS_HIDDEN = 1 << 2,
55 GTK_FILE_INFO_MIME_TYPE = 1 << 3,
56 GTK_FILE_INFO_MODIFICATION_TIME = 1 << 4,
57 GTK_FILE_INFO_SIZE = 1 << 5,
58 GTK_FILE_INFO_ICON = 1 << 6,
59 GTK_FILE_INFO_ALL = (1 << 7) - 1
62 /* GError enumeration for GtkFileSystem
65 #define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())
69 GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
70 GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
71 GTK_FILE_SYSTEM_ERROR_INVALID_URI,
72 GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
73 GTK_FILE_SYSTEM_ERROR_FAILED,
74 GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS
77 GQuark gtk_file_system_error_quark (void);
79 /* Boxed-type for gtk_file_folder_get_info() results
81 #define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())
83 GType gtk_file_info_get_type (void) G_GNUC_CONST;
85 GtkFileInfo *gtk_file_info_new (void);
86 GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
87 void gtk_file_info_free (GtkFileInfo *info);
90 G_CONST_RETURN gchar *gtk_file_info_get_display_name (const GtkFileInfo *info);
91 G_CONST_RETURN gchar *gtk_file_info_get_display_key (const GtkFileInfo *info);
92 void gtk_file_info_set_display_name (GtkFileInfo *info,
93 const gchar *display_name);
94 gboolean gtk_file_info_get_is_folder (const GtkFileInfo *info);
95 void gtk_file_info_set_is_folder (GtkFileInfo *info,
97 gboolean gtk_file_info_get_is_hidden (const GtkFileInfo *info);
98 void gtk_file_info_set_is_hidden (GtkFileInfo *info,
100 G_CONST_RETURN gchar *gtk_file_info_get_mime_type (const GtkFileInfo *info);
101 void gtk_file_info_set_mime_type (GtkFileInfo *info,
102 const gchar *mime_type);
103 GtkFileTime gtk_file_info_get_modification_time (const GtkFileInfo *info);
104 void gtk_file_info_set_modification_time (GtkFileInfo *info,
105 GtkFileTime modification_time);
106 gint64 gtk_file_info_get_size (const GtkFileInfo *info);
107 void gtk_file_info_set_size (GtkFileInfo *info,
110 void gtk_file_info_set_icon_name (GtkFileInfo *info,
111 const gchar *con_name);
112 G_CONST_RETURN gchar *gtk_file_info_get_icon_name (const GtkFileInfo *info);
113 GdkPixbuf *gtk_file_info_render_icon (const GtkFileInfo *info,
118 /* GtkFileSystemHandle
121 #define GTK_TYPE_FILE_SYSTEM_HANDLE (gtk_file_system_handle_get_type ())
122 #define GTK_FILE_SYSTEM_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandle))
123 #define GTK_IS_FILE_SYSTEM_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE))
124 #define GTK_FILE_SYSTEM_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandleUnixClass))
125 #define GTK_IS_FILE_SYSTEM_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_SYSTEM_HANDLE))
126 #define GTK_FILE_SYSTEM_HANDLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandleClass))
128 typedef struct _GtkFileSystemHandle GtkFileSystemHandle;
129 typedef struct _GtkFileSystemHandleClass GtkFileSystemHandleClass;
131 struct _GtkFileSystemHandle
133 GObject parent_instance;
135 GtkFileSystem *file_system;
140 struct _GtkFileSystemHandleClass
142 GObjectClass parent_class;
145 GType gtk_file_system_handle_get_type (void);
147 /* The base GtkFileSystem interface
149 #define GTK_TYPE_FILE_SYSTEM (gtk_file_system_get_type ())
150 #define GTK_FILE_SYSTEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
151 #define GTK_IS_FILE_SYSTEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
152 #define GTK_FILE_SYSTEM_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))
154 /* Callbacks for the asynchronous GtkFileSystem operations
157 typedef void (* GtkFileSystemGetInfoCallback) (GtkFileSystemHandle *handle,
158 const GtkFileInfo *file_info,
161 typedef void (* GtkFileSystemGetFolderCallback) (GtkFileSystemHandle *handle,
162 GtkFileFolder *folder,
165 typedef void (* GtkFileSystemCreateFolderCallback) (GtkFileSystemHandle *handle,
166 const GtkFilePath *path,
169 typedef void (* GtkFileSystemVolumeMountCallback) (GtkFileSystemHandle *handle,
170 GtkFileSystemVolume *volume,
177 struct _GtkFileSystemIface
179 GTypeInterface base_iface;
183 GSList * (*list_volumes) (GtkFileSystem *file_system);
184 GtkFileSystemVolume * (*get_volume_for_path) (GtkFileSystem *file_system,
185 const GtkFilePath *path);
187 GtkFileSystemHandle * (*get_folder) (GtkFileSystem *file_system,
188 const GtkFilePath *path,
189 GtkFileInfoType types,
190 GtkFileSystemGetFolderCallback callback,
192 GtkFileSystemHandle * (*get_info) (GtkFileSystem *file_system,
193 const GtkFilePath *path,
194 GtkFileInfoType types,
195 GtkFileSystemGetInfoCallback callback,
197 GtkFileSystemHandle * (*create_folder) (GtkFileSystem *file_system,
198 const GtkFilePath *path,
199 GtkFileSystemCreateFolderCallback callback,
202 void (*cancel_operation) (GtkFileSystemHandle *handle);
206 void (*volume_free) (GtkFileSystem *file_system,
207 GtkFileSystemVolume *volume);
208 GtkFilePath * (*volume_get_base_path) (GtkFileSystem *file_system,
209 GtkFileSystemVolume *volume);
210 gboolean (*volume_get_is_mounted) (GtkFileSystem *file_system,
211 GtkFileSystemVolume *volume);
212 GtkFileSystemHandle * (*volume_mount) (GtkFileSystem *file_system,
213 GtkFileSystemVolume *volume,
214 GtkFileSystemVolumeMountCallback callback,
216 char * (*volume_get_display_name) (GtkFileSystem *file_system,
217 GtkFileSystemVolume *volume);
218 gchar * (*volume_get_icon_name) (GtkFileSystem *file_system,
219 GtkFileSystemVolume *volume,
224 gboolean (*get_parent) (GtkFileSystem *file_system,
225 const GtkFilePath *path,
226 GtkFilePath **parent,
228 GtkFilePath * (*make_path) (GtkFileSystem *file_system,
229 const GtkFilePath *base_path,
230 const gchar *display_name,
232 gboolean (*parse) (GtkFileSystem *file_system,
233 const GtkFilePath *base_path,
235 GtkFilePath **folder,
238 gchar * (*path_to_uri) (GtkFileSystem *file_system,
239 const GtkFilePath *path);
240 gchar * (*path_to_filename) (GtkFileSystem *file_system,
241 const GtkFilePath *path);
242 GtkFilePath *(*uri_to_path) (GtkFileSystem *file_system,
244 GtkFilePath *(*filename_to_path) (GtkFileSystem *file_system,
249 gboolean (*insert_bookmark) (GtkFileSystem *file_system,
250 const GtkFilePath *path,
253 gboolean (*remove_bookmark) (GtkFileSystem *file_system,
254 const GtkFilePath *path,
256 GSList * (*list_bookmarks) (GtkFileSystem *file_system);
260 void (*volumes_changed) (GtkFileSystem *file_system);
261 void (*bookmarks_changed) (GtkFileSystem *file_system);
265 gchar * (*get_bookmark_label) (GtkFileSystem *file_system,
266 const GtkFilePath *path);
267 void (*set_bookmark_label) (GtkFileSystem *file_system,
268 const GtkFilePath *path,
272 GType gtk_file_system_get_type (void) G_GNUC_CONST;
274 GSList * gtk_file_system_list_volumes (GtkFileSystem *file_system);
276 GtkFileSystemVolume *gtk_file_system_get_volume_for_path (GtkFileSystem *file_system,
277 const GtkFilePath *path);
279 void gtk_file_system_volume_free (GtkFileSystem *file_system,
280 GtkFileSystemVolume *volume);
281 GtkFilePath * gtk_file_system_volume_get_base_path (GtkFileSystem *file_system,
282 GtkFileSystemVolume *volume);
283 gboolean gtk_file_system_volume_get_is_mounted (GtkFileSystem *file_system,
284 GtkFileSystemVolume *volume);
285 GtkFileSystemHandle *gtk_file_system_volume_mount (GtkFileSystem *file_system,
286 GtkFileSystemVolume *volume,
287 GtkFileSystemVolumeMountCallback callback,
289 char * gtk_file_system_volume_get_display_name (GtkFileSystem *file_system,
290 GtkFileSystemVolume *volume);
291 GdkPixbuf * gtk_file_system_volume_render_icon (GtkFileSystem *file_system,
292 GtkFileSystemVolume *volume,
296 gchar * gtk_file_system_volume_get_icon_name (GtkFileSystem *file_system,
297 GtkFileSystemVolume *volume,
300 gboolean gtk_file_system_get_parent (GtkFileSystem *file_system,
301 const GtkFilePath *path,
302 GtkFilePath **parent,
304 GtkFileSystemHandle *gtk_file_system_get_folder (GtkFileSystem *file_system,
305 const GtkFilePath *path,
306 GtkFileInfoType types,
307 GtkFileSystemGetFolderCallback callback,
309 GtkFileSystemHandle *gtk_file_system_get_info (GtkFileSystem *file_system,
310 const GtkFilePath *path,
311 GtkFileInfoType types,
312 GtkFileSystemGetInfoCallback callback,
314 GtkFileSystemHandle *gtk_file_system_create_folder (GtkFileSystem *file_system,
315 const GtkFilePath *path,
316 GtkFileSystemCreateFolderCallback callback,
318 void gtk_file_system_cancel_operation (GtkFileSystemHandle *handle);
319 GtkFilePath * gtk_file_system_make_path (GtkFileSystem *file_system,
320 const GtkFilePath *base_path,
321 const gchar *display_name,
323 gboolean gtk_file_system_parse (GtkFileSystem *file_system,
324 const GtkFilePath *base_path,
326 GtkFilePath **folder,
330 gchar * gtk_file_system_path_to_uri (GtkFileSystem *file_system,
331 const GtkFilePath *path);
332 gchar * gtk_file_system_path_to_filename (GtkFileSystem *file_system,
333 const GtkFilePath *path);
334 GtkFilePath *gtk_file_system_uri_to_path (GtkFileSystem *file_system,
336 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem *file_system,
337 const gchar *filename);
339 gboolean gtk_file_system_path_is_local (GtkFileSystem *filesystem,
340 const GtkFilePath *path);
342 gboolean gtk_file_system_insert_bookmark (GtkFileSystem *file_system,
343 const GtkFilePath *path,
346 gboolean gtk_file_system_remove_bookmark (GtkFileSystem *file_system,
347 const GtkFilePath *path,
349 GSList *gtk_file_system_list_bookmarks (GtkFileSystem *file_system);
351 gchar *gtk_file_system_get_bookmark_label (GtkFileSystem *file_system,
352 const GtkFilePath *path);
353 void gtk_file_system_set_bookmark_label (GtkFileSystem *file_system,
354 const GtkFilePath *path,
358 * Detailed information about a particular folder
360 #define GTK_TYPE_FILE_FOLDER (gtk_file_folder_get_type ())
361 #define GTK_FILE_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
362 #define GTK_IS_FILE_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
363 #define GTK_FILE_FOLDER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
365 struct _GtkFileFolderIface
367 GTypeInterface base_iface;
371 GtkFileInfo * (*get_info) (GtkFileFolder *folder,
372 const GtkFilePath *path,
374 gboolean (*list_children) (GtkFileFolder *folder,
378 /* ??? refresh() ??? */
382 void (*deleted) (GtkFileFolder *monitor);
383 void (*files_added) (GtkFileFolder *monitor,
385 void (*files_changed) (GtkFileFolder *monitor,
387 void (*files_removed) (GtkFileFolder *monitor,
390 /* Method / signal */
391 gboolean (*is_finished_loading) (GtkFileFolder *folder);
392 void (*finished_loading) (GtkFileFolder *folder);
395 GType gtk_file_folder_get_type (void) G_GNUC_CONST;
396 gboolean gtk_file_folder_list_children (GtkFileFolder *folder,
399 GtkFileInfo *gtk_file_folder_get_info (GtkFileFolder *folder,
400 const GtkFilePath *path,
403 gboolean gtk_file_folder_is_finished_loading (GtkFileFolder *folder);
407 #define GTK_TYPE_FILE_PATH (gtk_file_path_get_type ())
409 GType gtk_file_path_get_type (void) G_GNUC_CONST;
411 #define gtk_file_path_new_dup(str) \
412 ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
413 #define gtk_file_path_new_steal(str) \
414 ({ gchar *__s = (str); (GtkFilePath *)__s; })
415 #define gtk_file_path_get_string(path) \
416 ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
417 #define gtk_file_path_free(path) \
418 ({ GtkFilePath *__p = (path); g_free (__p); })
420 #define gtk_file_path_new_dup(str) ((GtkFilePath *)g_strdup(str))
421 #define gtk_file_path_new_steal(str) ((GtkFilePath *)(str))
422 #define gtk_file_path_get_string(str) ((const gchar *)(str))
423 #define gtk_file_path_free(path) g_free (path)
426 #define gtk_file_path_copy(path) gtk_file_path_new_dup (gtk_file_path_get_string(path))
428 int _gtk_file_system_win32_path_compare (const gchar *path1,
430 #define gtk_file_path_compare(path1,path2) \
431 _gtk_file_system_win32_path_compare (gtk_file_path_get_string (path1), \
432 gtk_file_path_get_string (path2))
434 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
435 gtk_file_path_get_string (path2))
438 GSList *gtk_file_paths_sort (GSList *paths);
439 GSList *gtk_file_paths_copy (GSList *paths);
440 void gtk_file_paths_free (GSList *paths);
442 /* GtkFileSystem modules support */
444 GtkFileSystem *gtk_file_system_create (const char *file_system_name);
448 #endif /* __GTK_FILE_SYSTEM_H__ */