1 /* GTK - The GIMP Toolkit
2 * gtkfilechooser.c: Abstract interface for file selector GUIs
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 #include "gtkfilechooser.h"
22 #include "gtkfilechooserprivate.h"
23 #include "gtkfilesystem.h"
25 #include "gtktypebuiltins.h"
27 static void gtk_file_chooser_class_init (gpointer g_iface);
29 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
32 gtk_file_chooser_get_type (void)
34 static GType file_chooser_type = 0;
36 if (!file_chooser_type)
38 static const GTypeInfo file_chooser_info =
40 sizeof (GtkFileChooserIface), /* class_size */
42 NULL, /* base_finalize */
43 (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
46 file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
48 &file_chooser_info, 0);
50 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
53 return file_chooser_type;
57 gtk_file_chooser_class_init (gpointer g_iface)
59 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
61 g_signal_new ("current-folder-changed",
64 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
66 g_cclosure_marshal_VOID__VOID,
68 g_signal_new ("selection-changed",
71 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
73 g_cclosure_marshal_VOID__VOID,
75 g_signal_new ("update-preview",
78 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
80 g_cclosure_marshal_VOID__VOID,
82 g_signal_new ("file-activated",
85 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
87 g_cclosure_marshal_VOID__VOID,
90 g_object_interface_install_property (g_iface,
91 g_param_spec_enum ("action",
93 _("The type of operation that the file selector is performing"),
94 GTK_TYPE_FILE_CHOOSER_ACTION,
95 GTK_FILE_CHOOSER_ACTION_OPEN,
97 g_object_interface_install_property (g_iface,
98 g_param_spec_object ("file-system",
100 _("File system object to use"),
101 GTK_TYPE_FILE_SYSTEM,
102 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
103 g_object_interface_install_property (g_iface,
104 g_param_spec_object ("filter",
106 _("The current filter for selecting which files are displayed"),
107 GTK_TYPE_FILE_FILTER,
109 g_object_interface_install_property (g_iface,
110 g_param_spec_boolean ("folder-mode",
112 _("Whether to select folders rather than files"),
115 g_object_interface_install_property (g_iface,
116 g_param_spec_boolean ("local-only",
118 _("Whether the selected file(s) should be limited to local file: URLs"),
121 g_object_interface_install_property (g_iface,
122 g_param_spec_object ("preview-widget",
124 _("Application supplied widget for custom previews."),
127 g_object_interface_install_property (g_iface,
128 g_param_spec_boolean ("preview-widget-active",
129 _("Preview Widget Active"),
130 _("Whether the application supplied widget for custom previews should be shown."),
133 g_object_interface_install_property (g_iface,
134 g_param_spec_object ("extra-widget",
136 _("Application supplied widget for extra options."),
139 g_object_interface_install_property (g_iface,
140 g_param_spec_boolean ("select-multiple",
141 _("Select Multiple"),
142 _("Whether to allow multiple files to be selected"),
146 g_object_interface_install_property (g_iface,
147 g_param_spec_boolean ("show-hidden",
149 _("Whether the hidden files and folders should be displayed"),
155 * gtk_file_chooser_error_quark:
157 * Registers an error quark for #GtkFileChooser if necessary.
159 * Return value: The error quark used for #GtkFileChooser errors.
164 gtk_file_chooser_error_quark (void)
166 static GQuark quark = 0;
168 quark = g_quark_from_static_string ("gtk-file-chooser-error-quark");
173 * gtk_file_chooser_set_action:
174 * @chooser: a #GtkFileChooser
175 * @action: the action that the file selector is performing
177 * Sets the type of operation that that the chooser is performing; the
178 * user interface is adapted to suit the selected action. For example,
179 * an option to create a new folder might be shown if the action is
180 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
181 * %GTK_FILE_CHOOSER_ACTION_OPEN.
186 gtk_file_chooser_set_action (GtkFileChooser *chooser,
187 GtkFileChooserAction action)
189 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
191 g_object_set (chooser, "action", action, NULL);
195 * gtk_file_chooser_get_action:
196 * @chooser: a #GtkFileChooser
198 * Gets the type of operation that the file chooser is performing; see
199 * gtk_file_chooser_set_action().
201 * Return value: the action that the file selector is performing
206 gtk_file_chooser_get_action (GtkFileChooser *chooser)
208 GtkFileChooserAction action;
210 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
212 g_object_get (chooser, "action", &action, NULL);
218 * gtk_file_chooser_set_folder_mode:
219 * @chooser: a #GtkFileChooser
220 * @folder_mode: %TRUE if the file chooser is used to select folders
223 * Sets whether the file chooser is used to select folders
224 * rather than files. If in folder mode, only folders are displayed
225 * to the use, and not the individual files inside the folders
226 * and the user selects a single folder rather than one or
232 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
233 gboolean folder_mode)
235 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
237 g_object_set (chooser, "folder-mode", folder_mode, NULL);
241 * gtk_file_chooser_get_folder_mode:
242 * @chooser: a #GtkFileChooser
244 * Gets whether the file chooser is used to select folders
245 * rather than files. See gtk_file_chooser_set_folder_mode()
247 * Return value: %TRUE if the file chooser is used to select
248 * folders rather than files.
253 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
255 gboolean folder_mode;
257 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
259 g_object_get (chooser, "folder-mode", &folder_mode, NULL);
265 * gtk_file_chooser_set_local_only:
266 * @chooser: a #GtkFileChooser
267 * @local_only: %TRUE if only local files can be selected
269 * Sets whether only local files can be selected in the
270 * file selector. If @local_only is %TRUE (the default),
271 * then the selected file are files are guaranteed to be
272 * accessible through the operating systems native file
273 * file system and therefore the application only
274 * needs to worry about the filename functions in
275 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
276 * rather than the URI functions like
277 * gtk_file_chooser_get_uri(),
282 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
285 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
287 g_object_set (chooser, "local-only", local_only, NULL);
291 * gtk_file_chooser_get_local_only:
292 * @chooser: a #GtkFileChoosre
294 * Gets whether only local files can be selected in the
295 * file selector. See gtk_file_chooser_set_local_only()
297 * Return value: %TRUE if only local files can be selected.
302 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
306 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
308 g_object_get (chooser, "local-only", &local_only, NULL);
314 * gtk_file_chooser_set_select_multiple:
315 * @chooser: a #GtkFileChooser
316 * @select_multiple: %TRUE if multiple files can be selected.
318 * Sets whether multiple files can be selected in the file
319 * selector. If the file selector if in folder mode (see
320 * gtk_file_selector_set_folder_mode()) then only one folder
321 * can be selected, without regard to this setting.
326 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
327 gboolean select_multiple)
329 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
331 g_object_set (chooser, "select-multiple", select_multiple, NULL);
335 * gtk_file_chooser_get_select_multiple:
336 * @chooser: a #GtkFileChooser
338 * Gets whether multiple files can be selected in the file
339 * selector. See gtk_file_chooser_set_select_multiple().
341 * Return value: %TRUE if multiple files can be selected.
346 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
348 gboolean select_multiple;
350 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
352 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
354 return select_multiple;
358 * gtk_file_chooser_get_filename:
359 * @chooser: a #GtkFileChooser
361 * Gets the filename for the currently selected file in
362 * the file selector. If multiple files are selected,
363 * one of the filenames will be returned at random.
365 * If the file chooser is in folder mode, this function returns the selected
368 * Return value: The currently selected filename, or %NULL
369 * if no file is selected, or the selected file can't
370 * be represented with a local filename. Free with g_free().
375 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
377 GtkFileSystem *file_system;
379 gchar *result = NULL;
381 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
383 file_system = _gtk_file_chooser_get_file_system (chooser);
384 path = gtk_file_chooser_get_path (chooser);
387 result = gtk_file_system_path_to_filename (file_system, path);
388 gtk_file_path_free (path);
395 * gtk_file_chooser_set_filename:
396 * @chooser: a #GtkFileChooser
397 * @filename: the filename to set as current
399 * Sets @filename as the current filename for the the file chooser;
400 * If the file name isn't in the current folder of @chooser, then the
401 * current folder of @chooser will be changed to the folder containing
402 * @filename. This is equivalent to a sequence of
403 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
405 * Note that the file must exist, or nothing will be done except
406 * for the directory change. To pre-enter a filename for the user, as in
407 * a save-as dialog, use gtk_file_chooser_set_current_name()
412 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
413 const gchar *filename)
415 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
417 gtk_file_chooser_unselect_all (chooser);
418 gtk_file_chooser_select_filename (chooser, filename);
422 * gtk_file_chooser_select_filename:
423 * @chooser: a #GtkFileChooser
424 * @filename: the filename to select
426 * Selects a filename. If the file name isn't in the current
427 * folder of @chooser, then the current folder of @chooser will
428 * be changed to the folder containing @filename.
433 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
434 const gchar *filename)
436 GtkFileSystem *file_system;
439 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
440 g_return_if_fail (filename != NULL);
442 file_system = _gtk_file_chooser_get_file_system (chooser);
444 path = gtk_file_system_filename_to_path (file_system, filename);
447 _gtk_file_chooser_select_path (chooser, path);
448 gtk_file_path_free (path);
453 * gtk_file_chooser_unselect_filename:
454 * @chooser: a #GtkFileChooser
455 * @filename: the filename to unselect
457 * Unselects a currently selected filename. If the filename
458 * is not in the current directory, does not exist, or
459 * is otherwise not currently selected, does nothing.
464 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
465 const char *filename)
467 GtkFileSystem *file_system;
470 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
471 g_return_if_fail (filename != NULL);
473 file_system = _gtk_file_chooser_get_file_system (chooser);
475 path = gtk_file_system_filename_to_path (file_system, filename);
478 _gtk_file_chooser_unselect_path (chooser, path);
479 gtk_file_path_free (path);
483 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
485 file_paths_to_strings (GtkFileSystem *fs,
487 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
493 for (; paths; paths = paths->next)
499 string = (* convert_func) (fs, path);
502 strings = g_slist_prepend (strings, string);
505 return g_slist_reverse (strings);
509 * gtk_file_chooser_get_filenames:
510 * @chooser: a #GtkFileChooser
512 * Lists all the selected files and subfolders in the current folder of
513 * @chooser. The returned names are full absolute paths. If files in the current
514 * folder cannot be represented as local filenames they will be ignored. (See
515 * gtk_file_chooser_get_uris())
517 * Return value: a #GSList containing the filenames of all selected
518 * files and subfolders in the current folder. Free the returned list
519 * with g_slist_free(), and the filenames with g_free().
524 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
526 GtkFileSystem *file_system;
530 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
532 file_system = _gtk_file_chooser_get_file_system (chooser);
533 paths = _gtk_file_chooser_get_paths (chooser);
535 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
536 gtk_file_paths_free (paths);
541 * gtk_file_chooser_set_current_folder:
542 * @chooser: a #GtkFileChooser
543 * @filename: the full path of the new current folder
545 * Sets the current folder for @chooser from a local filename.
546 * The user will be shown the full contents of the current folder,
547 * plus user interface elements for navigating to other folders.
552 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
553 const gchar *filename)
555 GtkFileSystem *file_system;
558 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
559 g_return_if_fail (filename != NULL);
561 file_system = _gtk_file_chooser_get_file_system (chooser);
563 path = gtk_file_system_filename_to_path (file_system, filename);
566 _gtk_file_chooser_set_current_folder_path (chooser, path);
567 gtk_file_path_free (path);
572 * gtk_file_chooser_get_current_folder:
573 * @chooser: a #GtkFileChooser
575 * Gets the current folder of @chooser as a local filename.
576 * See gtk_file_chooser_set_current_folder().
578 * Return value: the full path of the current folder, or %NULL
579 * if the current path cannot be represented as a local filename.
580 * Free with g_free().
585 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
587 GtkFileSystem *file_system;
591 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
593 file_system = _gtk_file_chooser_get_file_system (chooser);
595 path = _gtk_file_chooser_get_current_folder_path (chooser);
596 filename = gtk_file_system_path_to_filename (file_system, path);
597 gtk_file_path_free (path);
603 * gtk_file_chooser_set_current_name:
604 * @chooser: a #GtkFileChooser
605 * @name: the filename to use, as a UTF-8 string
607 * Sets the current name in the file selector, as if entered
608 * by the user. Note that the name passed in here is a UTF-8
609 * string rather than a filename. This function is meant for
610 * such uses as a suggested name in a "Save As..." dialog.
612 * If you want to preselect a particular existing file, you
613 * should use gtk_file_chooser_set_filename() instead.
618 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
621 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
622 g_return_if_fail (name != NULL);
624 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
628 * gtk_file_chooser_get_uri:
629 * @chooser: a #GtkFileChooser
631 * Gets the URI for the currently selected file in
632 * the file selector. If multiple files are selected,
633 * one of the filenames will be returned at random.
635 * If the file chooser is in folder mode, this function returns the selected
638 * Return value: The currently selected URI, or %NULL
639 * if no file is selected. Free with g_free()
644 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
646 GtkFileSystem *file_system;
648 gchar *result = NULL;
650 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
652 file_system = _gtk_file_chooser_get_file_system (chooser);
653 path = gtk_file_chooser_get_path (chooser);
656 result = gtk_file_system_path_to_uri (file_system, path);
657 gtk_file_path_free (path);
664 * gtk_file_chooser_set_uri:
665 * @chooser: a #GtkFileChooser
666 * @uri: the URI to set as current
668 * Sets the file referred to by @uri as the current file for the the
669 * file chooser; If the file name isn't in the current folder of @chooser,
670 * then the current folder of @chooser will be changed to the folder containing
671 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
672 * followed by gtk_file_chooser_select_uri().
674 * Note that the file must exist, or nothing will be done except
675 * for the directory change. To pre-enter a filename for the user, as in
676 * a save-as dialog, use gtk_file_chooser_set_current_name()
681 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
684 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
686 gtk_file_chooser_unselect_all (chooser);
687 gtk_file_chooser_select_uri (chooser, uri);
691 * gtk_file_chooser_select_uri:
692 * @chooser: a #GtkFileChooser
693 * @uri: the URI to select
695 * Selects the file to by @uri. If the URI doesn't refer to a
696 * file in the current folder of @chooser, then the current folder of
697 * @chooser will be changed to the folder containing @filename.
702 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
705 GtkFileSystem *file_system;
708 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
709 g_return_if_fail (uri != NULL);
711 file_system = _gtk_file_chooser_get_file_system (chooser);
713 path = gtk_file_system_uri_to_path (file_system, uri);
716 _gtk_file_chooser_select_path (chooser, path);
717 gtk_file_path_free (path);
722 * gtk_file_chooser_unselect_uri:
723 * @chooser: a #GtkFileChooser
724 * @uri: the URI to unselect
726 * Unselects the file referred to by @uri. If the file
727 * is not in the current directory, does not exist, or
728 * is otherwise not currently selected, does nothing.
733 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
736 GtkFileSystem *file_system;
739 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
740 g_return_if_fail (uri != NULL);
742 file_system = _gtk_file_chooser_get_file_system (chooser);
744 path = gtk_file_system_uri_to_path (file_system, uri);
747 _gtk_file_chooser_unselect_path (chooser, path);
748 gtk_file_path_free (path);
753 * gtk_file_chooser_select_all:
754 * @chooser: a #GtkFileChooser
756 * Selects all the files in the current folder of a file chooser.
761 gtk_file_chooser_select_all (GtkFileChooser *chooser)
763 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
765 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
769 * gtk_file_chooser_unselect_all:
770 * @chooser: a #GtkFileChooser
772 * Unselects all the files in the current folder of a file chooser.
777 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
780 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
782 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
786 * gtk_file_chooser_get_uris:
787 * @chooser: a #GtkFileChooser
789 * Lists all the selected files and subfolders in the current folder of
790 * @chooser. The returned names are full absolute URIs.
792 * Return value: a #GSList containing the URIs of all selected
793 * files and subfolders in the current folder. Free the returned list
794 * with g_slist_free(), and the filenames with g_free().
799 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
801 GtkFileSystem *file_system;
805 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
807 file_system = _gtk_file_chooser_get_file_system (chooser);
808 paths = _gtk_file_chooser_get_paths (chooser);
810 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
811 gtk_file_paths_free (paths);
816 * gtk_file_chooser_set_current_folder_uri:
817 * @chooser: a #GtkFileChooser
818 * @uri: the URI for the new current folder
820 * Sets the current folder for @chooser from an URI.
821 * The user will be shown the full contents of the current folder,
822 * plus user interface elements for navigating to other folders.
827 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
830 GtkFileSystem *file_system;
833 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
834 g_return_if_fail (uri != NULL);
836 file_system = _gtk_file_chooser_get_file_system (chooser);
838 path = gtk_file_system_uri_to_path (file_system, uri);
841 _gtk_file_chooser_set_current_folder_path (chooser, path);
842 gtk_file_path_free (path);
847 * gtk_file_chooser_get_current_folder_uri:
848 * @chooser: a #GtkFileChooser
850 * Gets the current folder of @chooser as an URI.
851 * See gtk_file_chooser_set_current_folder_uri().
853 * Return value: the URI for the current folder.
854 * Free with g_free().
859 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
861 GtkFileSystem *file_system;
865 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
867 file_system = _gtk_file_chooser_get_file_system (chooser);
869 path = _gtk_file_chooser_get_current_folder_path (chooser);
870 uri = gtk_file_system_path_to_uri (file_system, path);
871 gtk_file_path_free (path);
877 * _gtk_file_chooser_set_current_folder_path:
878 * @chooser: a #GtkFileChooser
879 * @path: the #GtkFilePath for the new folder
881 * Sets the current folder for @chooser from a #GtkFilePath.
882 * Internal function, see gtk_file_chooser_set_current_folder_uri().
887 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
888 const GtkFilePath *path)
890 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
891 g_return_if_fail (path != NULL);
893 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
897 * _gtk_file_chooser_get_current_folder_path:
898 * @chooser: a #GtkFileChooser
900 * Gets the current folder of @chooser as #GtkFilePath.
901 * See gtk_file_chooser_get_current_folder_uri().
903 * Return value: the #GtkFilePath for the current folder.
904 * Free with gtk_file_path_free().
909 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
911 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
913 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
917 * _gtk_file_chooser_select_path:
918 * @chooser: a #GtkFileChooser
919 * @path: the path to select
921 * Selects the file referred to by @path. An internal function. See
922 * _gtk_file_chooser_select_uri().
927 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
928 const GtkFilePath *path)
930 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
932 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
936 * _gtk_file_chooser_unselect_path:
937 * @chooser: a #GtkFileChooser
938 * @path: the filename to path
940 * Unselects the file referred to by @path. An internal
941 * function. See _gtk_file_chooser_unselect_uri().
946 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
947 const GtkFilePath *path)
949 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
951 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
955 * _gtk_file_chooser_get_paths:
956 * @chooser: a #GtkFileChooser
958 * Lists all the selected files and subfolders in the current folder of @chooser
959 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
961 * Return value: a #GSList containing a #GtkFilePath for each selected
962 * file and subfolder in the current folder. Free the returned list
963 * with g_slist_free(), and the paths with gtk_file_path_free().
968 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
970 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
972 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
976 gtk_file_chooser_get_path (GtkFileChooser *chooser)
979 GtkFilePath *result = NULL;
981 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
983 list = _gtk_file_chooser_get_paths (chooser);
987 list = g_slist_delete_link (list, list);
988 gtk_file_paths_free (list);
995 * _gtk_file_chooser_get_file_system:
996 * @chooser: a #GtkFileChooser
998 * Gets the #GtkFileSystem of @chooser; this is an internal
999 * implementation detail, used for conversion between paths
1000 * and filenames and URIs.
1002 * Return value: the file system for @chooser.
1007 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1009 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1011 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1017 * gtk_file_chooser_set_preview_widget:
1018 * @chooser: a #GtkFileChooser
1019 * @preview_widget: widget for displaying preview.
1021 * Sets an application-supplied widget to use to display a custom preview
1022 * of the currently selected file. To implement a preview, after setting the
1023 * preview widget, you connect to the ::selection-changed
1024 * signal, and call gtk_file_chooser_get_preview_filename() or
1025 * gtk_file_chooser_get_preview_uri() on each change. If you can
1026 * display a preview of the new file, update your widget and
1027 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1028 * Otherwise, set the preview inactive.
1030 * When there is no application-supplied preview widget, or the
1031 * application-supplied preview widget is not active, the file chooser
1032 * may display an internally generated preview of the current file or
1033 * it may display no preview at all.
1038 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1039 GtkWidget *preview_widget)
1041 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1043 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1047 * gtk_file_chooser_get_preview_widget:
1048 * @chooser: a #GtkFileChooser
1050 * Gets the current preview widget; see
1051 * gtk_file_chooser_set_preview_widget().
1053 * Return value: the current preview widget, or %NULL
1058 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1060 GtkWidget *preview_widget;
1062 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1064 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1066 /* Horrid hack; g_object_get() refs returned objects but
1067 * that contradicts the memory management conventions
1071 g_object_unref (preview_widget);
1073 return preview_widget;
1077 * gtk_file_chooser_set_preview_widget_active:
1078 * @chooser: a #GtkFileChooser
1079 * @active: whether to display the user-specified preview widget
1081 * Sets whether the preview widget set by
1082 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1083 * current filename. When @active is set to false, the file chooser
1084 * may display an internally generated preview of the current file
1085 * or it may display no preview at all. See
1086 * gtk_file_chooser_set_preview_widget() for more details.
1091 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1094 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1096 g_object_set (chooser, "preview-widget-active", active, NULL);
1100 * gtk_file_chooser_get_preview_widget_active:
1101 * @chooser: a #GtkFileChooser
1103 * Gets whether the preview widget set by
1104 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1105 * current filename. See gtk_file_chooser_set_preview_widget_active().
1107 * Return value: %TRUE if the preview widget is active for the
1113 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1117 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1119 g_object_get (chooser, "preview-widget-active", &active, NULL);
1125 * gtk_file_chooser_get_preview_filename:
1126 * @chooser: a #GtkFileChooser
1128 * Gets the filename that should be previewed in a custom preview
1129 * Internal function, see gtk_file_chooser_get_preview_uri().
1131 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1132 * is selected. Free with gtk_file_path_free().
1137 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1139 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1141 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1145 * _gtk_file_chooser_add_shortcut_folder:
1146 * @chooser: a #GtkFileChooser
1147 * @path: path of the folder to add
1148 * @error: location to store error, or %NULL
1150 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1151 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1153 * Return value: %TRUE if the folder could be added successfully, %FALSE
1159 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1160 const GtkFilePath *path,
1163 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1164 g_return_val_if_fail (path != NULL, FALSE);
1166 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1170 * _gtk_file_chooser_remove_shortcut_folder:
1171 * @chooser: a #GtkFileChooser
1172 * @path: path of the folder to remove
1173 * @error: location to store error, or %NULL
1175 * Removes a folder from the shortcut folders in a file chooser. Internal
1176 * function, see gtk_file_chooser_remove_shortcut_folder().
1178 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1184 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1185 const GtkFilePath *path,
1188 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1189 g_return_val_if_fail (path != NULL, FALSE);
1191 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1195 * gtk_file_chooser_get_preview_filename:
1196 * @chooser: a #GtkFileChooser
1198 * Gets the filename that should be previewed in a custom preview
1199 * widget. See gtk_file_chooser_set_preview_widget().
1201 * Return value: the filename to preview, or %NULL if no file
1202 * is selected, or if the selected file cannot be represented
1203 * as a local filename. Free with g_free()
1208 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1210 GtkFileSystem *file_system;
1212 gchar *result = NULL;
1214 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1216 file_system = _gtk_file_chooser_get_file_system (chooser);
1217 path = _gtk_file_chooser_get_preview_path (chooser);
1220 result = gtk_file_system_path_to_filename (file_system, path);
1221 gtk_file_path_free (path);
1228 * gtk_file_chooser_get_preview_uri:
1229 * @chooser: a #GtkFileChooser
1231 * Gets the URI that should be previewed in a custom preview
1232 * widget. See gtk_file_chooser_set_preview_widget().
1234 * Return value: the URI for the file to preview, or %NULL if no file is
1235 * selected. Free with g_free().
1240 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1242 GtkFileSystem *file_system;
1244 gchar *result = NULL;
1246 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1248 file_system = _gtk_file_chooser_get_file_system (chooser);
1249 path = _gtk_file_chooser_get_preview_path (chooser);
1252 result = gtk_file_system_path_to_uri (file_system, path);
1253 gtk_file_path_free (path);
1260 * gtk_file_chooser_set_extra_widget:
1261 * @chooser: a #GtkFileChooser
1262 * @extra_widget: widget for extra options
1264 * Sets an application-supplied widget to provide extra options to the user.
1269 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1270 GtkWidget *extra_widget)
1272 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1274 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1278 * gtk_file_chooser_get_extra_widget:
1279 * @chooser: a #GtkFileChooser
1281 * Gets the current preview widget; see
1282 * gtk_file_chooser_set_extra_widget().
1284 * Return value: the current extra widget, or %NULL
1289 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1291 GtkWidget *extra_widget;
1293 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1295 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1297 /* Horrid hack; g_object_get() refs returned objects but
1298 * that contradicts the memory management conventions
1302 g_object_unref (extra_widget);
1304 return extra_widget;
1308 * gtk_file_chooser_add_filter:
1309 * @chooser: a #GtkFileChooser
1310 * @filter: a #GtkFileFilter
1312 * Adds @filter to the list of filters that the user can select between.
1313 * When a filter is selected, only files that are passed by that
1314 * filter are displayed.
1319 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1320 GtkFileFilter *filter)
1322 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1324 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1328 * gtk_file_chooser_remove_filter:
1329 * @chooser: a #GtkFileChooser
1330 * @filter: a #GtkFileFilter
1332 * Removes @filter from the list of filters that the user can select between.
1337 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1338 GtkFileFilter *filter)
1340 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1342 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1346 * gtk_file_chooser_list_filters:
1347 * @chooser: a #GtkFileChooser
1349 * Lists the current set of user-selectable filters; see
1350 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1352 * Return value: a #GSList containing the current set of
1353 * user selectable filters. The contents of the list are
1354 * owned by GTK+, but you must free the list itself with
1355 * g_slist_free() when you are done with it.
1360 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1362 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1364 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1368 * gtk_file_chooser_set_filter:
1369 * @chooser: a #GtkFileChooser
1370 * @filter: a #GtkFileFilter
1372 * Sets the current filter; only the files that pass the
1373 * filter will be displayed. If the user-selectable list of filters
1374 * is non-empty, then the filter should be one of the filters
1375 * in that list. Setting the current filter when the list of
1376 * filters is empty is useful if you want to restrict the displayed
1377 * set of files without letting the user change it.
1382 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1383 GtkFileFilter *filter)
1385 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1386 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1388 g_object_set (chooser, "filter", filter, NULL);
1392 * gtk_file_chooser_get_filter:
1393 * @chooser: a #GtkFileChooser
1395 * Gets the current filter; see gtk_file_chooser_set_filter().
1397 * Return value: the current filter, or %NULL
1402 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1404 GtkFileFilter *filter;
1406 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1408 g_object_get (chooser, "filter", &filter, NULL);
1409 /* Horrid hack; g_object_get() refs returned objects but
1410 * that contradicts the memory management conventions
1414 g_object_unref (filter);
1420 * gtk_file_chooser_add_shortcut_folder:
1421 * @chooser: a #GtkFileChooser
1422 * @folder: filename of the folder to add
1423 * @error: location to store error, or %NULL
1425 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1426 * Note that shortcut folders do not get saved, as they are provided by the
1427 * application. For example, you can use this to add a
1428 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1430 * Return value: %TRUE if the folder could be added successfully, %FALSE
1431 * otherwise. In the latter case, the @error will be set as appropriate.
1436 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1443 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1444 g_return_val_if_fail (folder != NULL, FALSE);
1446 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1450 GTK_FILE_CHOOSER_ERROR,
1451 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1452 _("Invalid filename: %s"),
1457 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1459 gtk_file_path_free (path);
1465 * gtk_file_chooser_remove_shortcut_folder:
1466 * @chooser: a #GtkFileChooser
1467 * @folder: filename of the folder to remove
1468 * @error: location to store error, or %NULL
1470 * Removes a folder from a file chooser's list of shortcut folders.
1472 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1473 * In the latter case, the @error will be set as appropriate.
1475 * See also: gtk_file_chooser_add_shortcut_folder()
1480 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1487 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1488 g_return_val_if_fail (folder != NULL, FALSE);
1490 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1494 GTK_FILE_CHOOSER_ERROR,
1495 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1496 _("Invalid filename: %s"),
1501 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1503 gtk_file_path_free (path);
1509 * gtk_file_chooser_list_shortcut_folders:
1510 * @chooser: a #GtkFileChooser
1512 * Queries the list of shortcut folders in the file chooser, as set by
1513 * gtk_file_chooser_set_shortcut_folders().
1515 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1516 * folders. Free the returned list with g_slist_free(), and the filenames with
1522 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1527 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1529 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1531 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1533 gtk_file_system_path_to_filename);
1534 gtk_file_paths_free (folders);
1539 * gtk_file_chooser_add_shortcut_folder_uri:
1540 * @chooser: a #GtkFileChooser
1541 * @uri: URI of the folder to add
1542 * @error: location to store error, or %NULL
1544 * Adds a folder URI to be displayed with the shortcut folders in a file
1545 * chooser. Note that shortcut folders do not get saved, as they are provided
1546 * by the application. For example, you can use this to add a
1547 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1549 * Return value: %TRUE if the folder could be added successfully, %FALSE
1550 * otherwise. In the latter case, the @error will be set as appropriate.
1555 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1562 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1563 g_return_val_if_fail (uri != NULL, FALSE);
1565 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1569 GTK_FILE_CHOOSER_ERROR,
1570 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1571 _("Invalid filename: %s"),
1576 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1578 gtk_file_path_free (path);
1584 * gtk_file_chooser_remove_shortcut_folder_uri:
1585 * @chooser: a #GtkFileChooser
1586 * @uri: URI of the folder to remove
1587 * @error: location to store error, or %NULL
1589 * Removes a folder URI from a file chooser's list of shortcut folders.
1591 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1592 * In the latter case, the @error will be set as appropriate.
1594 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1599 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1606 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1607 g_return_val_if_fail (uri != NULL, FALSE);
1609 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1613 GTK_FILE_CHOOSER_ERROR,
1614 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1615 _("Invalid filename: %s"),
1620 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1622 gtk_file_path_free (path);
1628 * gtk_file_chooser_list_shortcut_folder_uris:
1629 * @chooser: a #GtkFileChooser
1631 * Queries the list of shortcut folders in the file chooser, as set by
1632 * gtk_file_chooser_set_shortcut_folder_uris().
1634 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1635 * folders. Free the returned list with g_slist_free(), and the URIs with
1641 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1646 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1648 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1650 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1652 gtk_file_system_path_to_uri);
1653 gtk_file_paths_free (folders);