1 /* GTK - The GIMP Toolkit
2 * gtkfilesystem.c: 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.
23 #include "gtkfilesystem.h"
24 #include "gtkicontheme.h"
31 GtkFileTime modification_time;
40 static void gtk_file_system_base_init (gpointer g_class);
41 static void gtk_file_folder_base_init (gpointer g_class);
44 gtk_file_system_error_quark (void)
46 static GQuark quark = 0;
48 quark = g_quark_from_static_string ("gtk-file-system-error-quark");
52 /*****************************************
54 *****************************************/
56 gtk_file_info_get_type (void)
58 static GType our_type = 0;
61 our_type = g_boxed_type_register_static ("GtkFileInfo",
62 (GBoxedCopyFunc) gtk_file_info_copy,
63 (GBoxedFreeFunc) gtk_file_info_free);
69 gtk_file_info_new (void)
73 info = g_new0 (GtkFileInfo, 1);
79 gtk_file_info_copy (GtkFileInfo *info)
81 GtkFileInfo *new_info;
83 g_return_val_if_fail (info != NULL, NULL);
85 new_info = g_memdup (info, sizeof (GtkFileInfo));
86 if (new_info->display_name)
87 new_info->display_name = g_strdup (new_info->display_name);
88 if (new_info->mime_type)
89 new_info->mime_type = g_strdup (new_info->mime_type);
95 gtk_file_info_free (GtkFileInfo *info)
97 g_return_if_fail (info != NULL);
99 if (info->display_name)
100 g_free (info->display_name);
102 g_free (info->mime_type);
103 if (info->display_key)
104 g_free (info->display_key);
109 G_CONST_RETURN gchar *
110 gtk_file_info_get_display_name (const GtkFileInfo *info)
112 g_return_val_if_fail (info != NULL, NULL);
114 return info->display_name;
118 * gtk_file_info_get_display_key:
119 * @info: a #GtkFileInfo
121 * Returns results of g_utf8_collate_key() on the display name
122 * for @info. This is useful when sorting a bunch of #GtkFileInfo
123 * structures since the collate key will be only computed once.
125 * Return value: The collate key for the display name, or %NULL
126 * if the display name hasn't been set.
128 G_CONST_RETURN gchar *
129 gtk_file_info_get_display_key (const GtkFileInfo *info)
131 g_return_val_if_fail (info != NULL, NULL);
133 if (!info->display_key && info->display_name)
135 /* Since info->display_key is only a cache, we cast off the const
137 ((GtkFileInfo *)info)->display_key = g_utf8_collate_key (info->display_name, -1);
140 return info->display_key;
144 gtk_file_info_set_display_name (GtkFileInfo *info,
145 const gchar *display_name)
147 g_return_if_fail (info != NULL);
149 if (info->display_name)
150 g_free (info->display_name);
151 if (info->display_key)
153 g_free (info->display_key);
154 info->display_key = NULL;
157 info->display_name = g_strdup (display_name);
161 gtk_file_info_get_is_folder (const GtkFileInfo *info)
163 g_return_val_if_fail (info != NULL, FALSE);
165 return info->is_folder;
169 gtk_file_info_set_is_folder (GtkFileInfo *info,
172 g_return_if_fail (info != NULL);
174 info->is_folder = is_folder != FALSE;
178 gtk_file_info_get_is_hidden (const GtkFileInfo *info)
180 g_return_val_if_fail (info != NULL, FALSE);
182 return info->is_hidden;
186 gtk_file_info_set_is_hidden (GtkFileInfo *info,
189 g_return_if_fail (info != NULL);
191 info->is_hidden = is_hidden != FALSE;
194 G_CONST_RETURN gchar *
195 gtk_file_info_get_mime_type (const GtkFileInfo *info)
197 g_return_val_if_fail (info != NULL, NULL);
199 return info->mime_type;
203 gtk_file_info_set_mime_type (GtkFileInfo *info,
204 const gchar *mime_type)
206 g_return_if_fail (info != NULL);
209 g_free (info->mime_type);
211 info->mime_type = g_strdup (mime_type);
215 gtk_file_info_get_modification_time (const GtkFileInfo *info)
217 g_return_val_if_fail (info != NULL, 0);
219 return info->modification_time;
223 gtk_file_info_set_modification_time (GtkFileInfo *info,
224 GtkFileTime modification_time)
226 g_return_if_fail (info != NULL);
228 info->modification_time = modification_time;
232 gtk_file_info_get_size (const GtkFileInfo *info)
234 g_return_val_if_fail (info != NULL, 0);
240 gtk_file_info_set_size (GtkFileInfo *info,
243 g_return_if_fail (info != NULL);
244 g_return_if_fail (size >= 0);
250 /*****************************************
252 *****************************************/
254 gtk_file_system_get_type (void)
256 static GType file_system_type = 0;
258 if (!file_system_type)
260 static const GTypeInfo file_system_info =
262 sizeof (GtkFileSystemIface), /* class_size */
263 gtk_file_system_base_init, /* base_init */
264 NULL, /* base_finalize */
267 file_system_type = g_type_register_static (G_TYPE_INTERFACE,
269 &file_system_info, 0);
271 g_type_interface_add_prerequisite (file_system_type, G_TYPE_OBJECT);
274 return file_system_type;
278 gtk_file_system_base_init (gpointer g_class)
280 static gboolean initialized = FALSE;
284 GType iface_type = G_TYPE_FROM_INTERFACE (g_class);
286 g_signal_new ("volumes-changed",
289 G_STRUCT_OFFSET (GtkFileSystemIface, volumes_changed),
291 g_cclosure_marshal_VOID__VOID,
293 g_signal_new ("bookmarks-changed",
296 G_STRUCT_OFFSET (GtkFileSystemIface, bookmarks_changed),
298 g_cclosure_marshal_VOID__VOID,
306 gtk_file_system_list_volumes (GtkFileSystem *file_system)
308 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
310 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->list_volumes (file_system);
314 gtk_file_system_get_folder (GtkFileSystem *file_system,
315 const GtkFilePath *path,
316 GtkFileInfoType types,
319 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
320 g_return_val_if_fail (path != NULL, NULL);
321 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
323 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_folder (file_system, path, types, error);
327 gtk_file_system_create_folder(GtkFileSystem *file_system,
328 const GtkFilePath *path,
331 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
332 g_return_val_if_fail (path != NULL, FALSE);
333 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
335 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->create_folder (file_system, path, error);
339 * gtk_file_system_get_volume_for_path:
340 * @file_system: a #GtkFileSystem
341 * @path: a #GtkFilePath
343 * Queries the file system volume that corresponds to a specific path.
344 * There might not be a volume for all paths (consinder for instance remote
345 * shared), so this can return NULL.
347 * Return value: the #GtkFileSystemVolume that corresponds to the specified
348 * @path, or NULL if there is no such volume. You should free this value with
349 * gtk_file_system_volume_free().
351 GtkFileSystemVolume *
352 gtk_file_system_get_volume_for_path (GtkFileSystem *file_system,
353 const GtkFilePath *path)
355 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
356 g_return_val_if_fail (path != NULL, NULL);
358 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_volume_for_path (file_system, path);
362 * gtk_file_system_volume_free:
363 * @file_system: a #GtkFileSystem
364 * @volume: a #GtkFileSystemVolume
366 * Frees a #GtkFileSystemVolume structure as returned by
367 * gtk_file_system_list_volumes().
370 gtk_file_system_volume_free (GtkFileSystem *file_system,
371 GtkFileSystemVolume *volume)
373 g_return_if_fail (GTK_IS_FILE_SYSTEM (file_system));
374 g_return_if_fail (volume != NULL);
376 GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_free (file_system, volume);
380 * gtk_file_system_volume_get_base_path:
381 * @file_system: a #GtkFileSystem
382 * @volume: a #GtkFileSystemVolume
384 * Queries the base path for a volume. For example, a CD-ROM device may yield a
385 * path of "/mnt/cdrom".
387 * Return value: a #GtkFilePath with the base mount path of the specified
391 gtk_file_system_volume_get_base_path (GtkFileSystem *file_system,
392 GtkFileSystemVolume *volume)
394 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
395 g_return_val_if_fail (volume != NULL, NULL);
397 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_get_base_path (file_system, volume);
401 * gtk_file_system_volume_get_is_mounted:
402 * @file_system: a #GtkFileSystem
403 * @volume: a #GtkFileSystemVolume
405 * Queries whether a #GtkFileSystemVolume is mounted or not. If it is not, it
406 * can be mounted with gtk_file_system_volume_mount().
408 * Return value: TRUE if the @volume is mounted, FALSE otherwise.
411 gtk_file_system_volume_get_is_mounted (GtkFileSystem *file_system,
412 GtkFileSystemVolume *volume)
414 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
415 g_return_val_if_fail (volume != NULL, FALSE);
417 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_get_is_mounted (file_system, volume);
421 * gtk_file_system_volume_mount:
422 * @file_system: a #GtkFileSystem
423 * @volume: a #GtkFileSystemVolume
424 * @error: location to store error, or %NULL
426 * Tries to mount an unmounted volume. This may cause the "volumes-changed"
427 * signal in the @file_system to be emitted.
429 * Return value: TRUE if the @volume was mounted successfully, FALSE otherwise.
432 gtk_file_system_volume_mount (GtkFileSystem *file_system,
433 GtkFileSystemVolume *volume,
436 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
437 g_return_val_if_fail (volume != NULL, FALSE);
438 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
440 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_mount (file_system, volume, error);
444 * gtk_file_system_volume_get_display_name:
445 * @file_system: a #GtkFileSystem
446 * @volume: a #GtkFileSystemVolume
448 * Queries the human-readable name for a @volume. This string can be displayed
449 * in a list of volumes that can be accessed, for example.
451 * Return value: A string with the human-readable name for a #GtkFileSystemVolume.
454 gtk_file_system_volume_get_display_name (GtkFileSystem *file_system,
455 GtkFileSystemVolume *volume)
457 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
458 g_return_val_if_fail (volume != NULL, NULL);
460 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_get_display_name (file_system, volume);
464 * gtk_file_system_volume_render_icon:
465 * @file_system: a #GtkFileSystem
466 * @volume: a #GtkFileSystemVolume
467 * @widget: Reference widget to render icons.
468 * @pixel_size: Size of the icon.
469 * @error: location to store error, or %NULL
471 * Renders an icon suitable for a file #GtkFileSystemVolume.
473 * Return value: A #GdkPixbuf containing an icon, or NULL if the icon could not
474 * be rendered. In the latter case, the @error value will be set as
478 gtk_file_system_volume_render_icon (GtkFileSystem *file_system,
479 GtkFileSystemVolume *volume,
484 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
485 g_return_val_if_fail (volume != NULL, NULL);
486 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
487 g_return_val_if_fail (pixel_size > 0, NULL);
488 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
490 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_render_icon (file_system,
498 * gtk_file_system_get_parent:
499 * @file_system: a #GtkFileSystem
500 * @path: base path name
501 * @parent: location to store parent path name
502 * @error: location to store error, or %NULL
504 * Gets the name of the parent folder of a path. If the path has no parent, as when
505 * you request the parent of a file system root, then @parent will be set to %NULL.
507 * Return value: %TRUE if the operation was successful: @parent will be set to
508 * the name of the @path's parent, or to %NULL if @path is already a file system
509 * root. If the operation fails, this function returns %FALSE, sets @parent to
510 * NULL, and sets the @error value if it is specified.
513 gtk_file_system_get_parent (GtkFileSystem *file_system,
514 const GtkFilePath *path,
515 GtkFilePath **parent,
520 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
521 g_return_val_if_fail (path != NULL, FALSE);
522 g_return_val_if_fail (parent != NULL, FALSE);
523 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
527 result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_parent (file_system, path, parent, error);
528 g_assert (result || *parent == NULL);
534 gtk_file_system_make_path (GtkFileSystem *file_system,
535 const GtkFilePath *base_path,
536 const gchar *display_name,
539 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
540 g_return_val_if_fail (base_path != NULL, NULL);
541 g_return_val_if_fail (display_name != NULL, NULL);
542 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
544 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->make_path (file_system, base_path, display_name, error);
548 * gtk_file_system_parse:
549 * @file_system: a #GtkFileSystem
550 * @base_path: reference folder with respect to which relative
551 * paths should be interpreted.
552 * @str: the string to parse
553 * @folder: location to store folder portion of result, or %NULL
554 * @file_part: location to store file portion of result, or %NULL
555 * @error: location to store error, or %NULL
557 * Given a string entered by a user, parse it (possibly using
558 * heuristics) into a folder path and a UTF-8 encoded
559 * filename part. (Suitable for passing to gtk_file_system_make_path())
561 * Note that the returned filename point may point to a subfolder
562 * of the returned folder. Adding a trailing path separator is needed
563 * to enforce the interpretation as a folder name.
565 * If parsing fails because the syntax of @str is not understood,
566 * and error of type GTK_FILE_SYSTEM_ERROR_BAD_FILENAME will
567 * be set in @error and %FALSE returned.
569 * If parsing fails because a path was encountered that doesn't
570 * exist on the filesystem, then an error of type
571 * %GTK_FILE_SYSTEM_ERROR_NONEXISTENT will be set in @error
572 * and %FALSE returned. (This only applies to parsing relative paths,
573 * not to interpretation of @file_part. No check is made as
574 * to whether @file_part exists.)
576 * Return value: %TRUE if the parsing succeeds, otherwise, %FALSE.
579 gtk_file_system_parse (GtkFileSystem *file_system,
580 const GtkFilePath *base_path,
582 GtkFilePath **folder,
586 GtkFilePath *tmp_folder = NULL;
587 gchar *tmp_file_part = NULL;
590 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
591 g_return_val_if_fail (base_path != NULL, FALSE);
592 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
595 result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->parse (file_system, base_path, str,
596 &tmp_folder, &tmp_file_part,
598 g_assert (result || (tmp_folder == NULL && tmp_file_part == NULL));
601 *folder = tmp_folder;
603 gtk_file_path_free (tmp_folder);
606 *file_part = tmp_file_part;
608 g_free (tmp_file_part);
615 gtk_file_system_path_to_uri (GtkFileSystem *file_system,
616 const GtkFilePath *path)
618 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
619 g_return_val_if_fail (path != NULL, NULL);
621 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->path_to_uri (file_system, path);
625 gtk_file_system_path_to_filename (GtkFileSystem *file_system,
626 const GtkFilePath *path)
628 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
629 g_return_val_if_fail (path != NULL, NULL);
631 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->path_to_filename (file_system, path);
635 gtk_file_system_uri_to_path (GtkFileSystem *file_system,
638 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
639 g_return_val_if_fail (uri != NULL, NULL);
641 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->uri_to_path (file_system, uri);
645 gtk_file_system_filename_to_path (GtkFileSystem *file_system,
646 const gchar *filename)
648 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
649 g_return_val_if_fail (filename != NULL, NULL);
651 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->filename_to_path (file_system, filename);
655 gtk_file_system_render_icon (GtkFileSystem *file_system,
656 const GtkFilePath *path,
661 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
662 g_return_val_if_fail (path != NULL, NULL);
663 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
664 g_return_val_if_fail (pixel_size > 0, NULL);
666 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->render_icon (file_system, path, widget, pixel_size, error);
670 * gtk_file_system_insert_bookmark:
671 * @file_system: a #GtkFileSystem
672 * @path: path of the bookmark to add
673 * @position: index in the bookmarks list at which the @path should be inserted; use 0
674 * for the beginning, and -1 or the number of bookmarks itself for the end of the list.
675 * @error: location to store error, or %NULL
677 * Adds a path for a folder to the user's bookmarks list. If the operation
678 * succeeds, the "bookmarks_changed" signal will be emitted. Bookmark paths are
679 * unique; if you try to insert a @path that already exists, the operation will
680 * fail and the @error will be set to #GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. To
681 * reorder the list of bookmarks, use gtk_file_system_remove_bookmark() to
682 * remove the path in question, and call gtk_file_system_insert_bookmark() with
683 * the new position for the path.
685 * Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter case,
686 * the @error value will be set.
689 gtk_file_system_insert_bookmark (GtkFileSystem *file_system,
690 const GtkFilePath *path,
694 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
695 g_return_val_if_fail (path != NULL, FALSE);
697 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->insert_bookmark (file_system, path, position, error);
701 * gtk_file_system_remove_bookmark:
702 * @file_system: a #GtkFileSystem
703 * @path: path of the bookmark to remove
704 * @error: location to store error, or %NULL
706 * Removes a bookmark folder from the user's bookmarks list. If the operation
707 * succeeds, the "bookmarks_changed" signal will be emitted. If you try to remove
708 * a @path which does not exist in the bookmarks list, the operation will fail
709 * and the @error will be set to GTK_FILE_SYSTEM_ERROR_NONEXISTENT.
711 * Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter
712 * case, the @error value will be set.
715 gtk_file_system_remove_bookmark (GtkFileSystem *file_system,
716 const GtkFilePath *path,
719 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
720 g_return_val_if_fail (path != NULL, FALSE);
722 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->remove_bookmark (file_system, path, error);
726 * gtk_file_system_list_bookmarks:
727 * @file_system: a #GtkFileSystem
729 * Queries the list of bookmarks in the file system.
731 * Return value: A list of #GtkFilePath, or NULL if there are no configured
732 * bookmarks. You should use gtk_file_paths_free() to free this list.
734 * See also: gtk_file_system_get_supports_bookmarks()
737 gtk_file_system_list_bookmarks (GtkFileSystem *file_system)
739 g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
741 return GTK_FILE_SYSTEM_GET_IFACE (file_system)->list_bookmarks (file_system);
744 /*****************************************
746 *****************************************/
748 gtk_file_folder_get_type (void)
750 static GType file_folder_type = 0;
752 if (!file_folder_type)
754 static const GTypeInfo file_folder_info =
756 sizeof (GtkFileFolderIface), /* class_size */
757 gtk_file_folder_base_init, /* base_init */
758 NULL, /* base_finalize */
761 file_folder_type = g_type_register_static (G_TYPE_INTERFACE,
763 &file_folder_info, 0);
765 g_type_interface_add_prerequisite (file_folder_type, G_TYPE_OBJECT);
768 return file_folder_type;
772 gtk_file_folder_base_init (gpointer g_class)
774 static gboolean initialized = FALSE;
778 GType iface_type = G_TYPE_FROM_INTERFACE (g_class);
780 g_signal_new ("deleted",
783 G_STRUCT_OFFSET (GtkFileFolderIface, deleted),
785 g_cclosure_marshal_VOID__VOID,
787 g_signal_new ("files-added",
790 G_STRUCT_OFFSET (GtkFileFolderIface, files_added),
792 g_cclosure_marshal_VOID__POINTER,
795 g_signal_new ("files-changed",
798 G_STRUCT_OFFSET (GtkFileFolderIface, files_changed),
800 g_cclosure_marshal_VOID__POINTER,
803 g_signal_new ("files-removed",
806 G_STRUCT_OFFSET (GtkFileFolderIface, files_removed),
808 g_cclosure_marshal_VOID__POINTER,
817 gtk_file_folder_list_children (GtkFileFolder *folder,
822 GSList *tmp_children = NULL;
824 g_return_val_if_fail (GTK_IS_FILE_FOLDER (folder), FALSE);
825 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
827 result = GTK_FILE_FOLDER_GET_IFACE (folder)->list_children (folder, &tmp_children, error);
828 g_assert (result || tmp_children == NULL);
831 *children = tmp_children;
833 gtk_file_paths_free (tmp_children);
839 gtk_file_folder_get_info (GtkFileFolder *folder,
840 const GtkFilePath *path,
843 g_return_val_if_fail (GTK_IS_FILE_FOLDER (folder), NULL);
844 g_return_val_if_fail (path != NULL, NULL);
845 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
847 return GTK_FILE_FOLDER_GET_IFACE (folder)->get_info (folder, path, error);
851 gtk_file_paths_sort (GSList *paths)
853 return g_slist_sort (paths, (GCompareFunc)strcmp);
857 * gtk_file_paths_copy:
858 * @paths: A #GSList of #GtkFilePath structures.
860 * Copies a list of #GtkFilePath structures.
862 * Return value: A copy of @paths. Since the contents of the list are copied as
863 * well, you should use gtk_file_paths_free() to free the result.
866 gtk_file_paths_copy (GSList *paths)
868 GSList *head, *tail, *l;
872 for (l = paths; l; l = l->next)
878 node = g_slist_alloc ();
885 node->data = gtk_file_path_copy (path);
893 gtk_file_paths_free (GSList *paths)
897 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
898 gtk_file_path_free (tmp_list->data);
900 g_slist_free (paths);
903 /*****************************************
904 * GtkFileSystem modules *
905 *****************************************/
907 typedef struct _GtkFileSystemModule GtkFileSystemModule;
908 typedef struct _GtkFileSystemModuleClass GtkFileSystemModuleClass;
910 struct _GtkFileSystemModule
912 GTypeModule parent_instance;
916 void (*init) (GTypeModule *module);
918 GtkFileSystem * (*create) (void);
923 struct _GtkFileSystemModuleClass
925 GTypeModuleClass parent_class;
928 G_DEFINE_TYPE (GtkFileSystemModule, gtk_file_system_module, G_TYPE_TYPE_MODULE);
929 #define GTK_TYPE_FILE_SYSTEM_MODULE (gtk_file_system_module_get_type ())
930 #define GTK_FILE_SYSTEM_MODULE(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), GTK_TYPE_FILE_SYSTEM_MODULE, GtkFileSystemModule))
933 static GSList *loaded_file_systems;
936 gtk_file_system_module_load (GTypeModule *module)
938 GtkFileSystemModule *fs_module = GTK_FILE_SYSTEM_MODULE (module);
940 fs_module->library = g_module_open (fs_module->path, 0);
941 if (!fs_module->library)
943 g_warning (g_module_error());
947 /* extract symbols from the lib */
948 if (!g_module_symbol (fs_module->library, "fs_module_init",
949 (gpointer *)&fs_module->init) ||
950 !g_module_symbol (fs_module->library, "fs_module_exit",
951 (gpointer *)&fs_module->exit) ||
952 !g_module_symbol (fs_module->library, "fs_module_create",
953 (gpointer *)&fs_module->create))
955 g_warning (g_module_error());
956 g_module_close (fs_module->library);
961 /* call the filesystems's init function to let it */
962 /* setup anything it needs to set up. */
963 fs_module->init (module);
969 gtk_file_system_module_unload (GTypeModule *module)
971 GtkFileSystemModule *fs_module = GTK_FILE_SYSTEM_MODULE (module);
975 g_module_close (fs_module->library);
976 fs_module->library = NULL;
978 fs_module->init = NULL;
979 fs_module->exit = NULL;
980 fs_module->create = NULL;
983 /* This only will ever be called if an error occurs during
987 gtk_file_system_module_finalize (GObject *object)
989 GtkFileSystemModule *module = GTK_FILE_SYSTEM_MODULE (object);
991 g_free (module->path);
993 G_OBJECT_CLASS (gtk_file_system_module_parent_class)->finalize (object);
997 gtk_file_system_module_class_init (GtkFileSystemModuleClass *class)
999 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
1000 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
1002 module_class->load = gtk_file_system_module_load;
1003 module_class->unload = gtk_file_system_module_unload;
1005 gobject_class->finalize = gtk_file_system_module_finalize;
1009 gtk_file_system_module_init (GtkFileSystemModule *fs_module)
1014 static GtkFileSystem *
1015 _gtk_file_system_module_create (GtkFileSystemModule *fs_module)
1019 if (g_type_module_use (G_TYPE_MODULE (fs_module)))
1021 fs = fs_module->create ();
1022 g_type_module_unuse (G_TYPE_MODULE (fs_module));
1030 _gtk_file_system_create (const char *file_system_name)
1034 GtkFileSystemModule *fs_module;
1037 for (l = loaded_file_systems; l != NULL; l = l->next)
1039 fs_module = l->data;
1041 if (strcmp (G_TYPE_MODULE (fs_module)->name, file_system_name) == 0)
1042 return _gtk_file_system_module_create (fs_module);
1046 if (g_module_supported ())
1048 module_path = _gtk_find_module (file_system_name, "filesystems");
1052 fs_module = g_object_new (GTK_TYPE_FILE_SYSTEM_MODULE, NULL);
1054 g_type_module_set_name (G_TYPE_MODULE (fs_module), file_system_name);
1055 fs_module->path = g_strdup (module_path);
1057 loaded_file_systems = g_slist_prepend (loaded_file_systems,
1060 fs = _gtk_file_system_module_create (fs_module);
1063 g_free (module_path);