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 * Return value: The currently selected filename, or %NULL
366 * if no file is selected, or the selected file can't
367 * be represented with a local filename. Free with g_free().
372 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
374 GtkFileSystem *file_system;
376 gchar *result = NULL;
378 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
380 file_system = _gtk_file_chooser_get_file_system (chooser);
381 path = gtk_file_chooser_get_path (chooser);
384 result = gtk_file_system_path_to_filename (file_system, path);
385 gtk_file_path_free (path);
392 * gtk_file_chooser_set_filename:
393 * @chooser: a #GtkFileChooser
394 * @filename: the filename to set as current
396 * Sets @filename as the current filename for the the file chooser;
397 * If the file name isn't in the current folder of @chooser, then the
398 * current folder of @chooser will be changed to the folder containing
399 * @filename. This is equivalent to a sequence of
400 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
402 * Note that the file must exist, or nothing will be done except
403 * for the directory change. To pre-enter a filename for the user, as in
404 * a save-as dialog, use gtk_file_chooser_set_current_name()
409 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
410 const gchar *filename)
412 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
414 gtk_file_chooser_unselect_all (chooser);
415 gtk_file_chooser_select_filename (chooser, filename);
419 * gtk_file_chooser_select_filename:
420 * @chooser: a #GtkFileChooser
421 * @filename: the filename to select
423 * Selects a filename. If the file name isn't in the current
424 * folder of @chooser, then the current folder of @chooser will
425 * be changed to the folder containing @filename.
430 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
431 const gchar *filename)
433 GtkFileSystem *file_system;
436 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
437 g_return_if_fail (filename != NULL);
439 file_system = _gtk_file_chooser_get_file_system (chooser);
441 path = gtk_file_system_filename_to_path (file_system, filename);
444 _gtk_file_chooser_select_path (chooser, path);
445 gtk_file_path_free (path);
450 * gtk_file_chooser_unselect_filename:
451 * @chooser: a #GtkFileChooser
452 * @filename: the filename to unselect
454 * Unselects a currently selected filename. If the filename
455 * is not in the current directory, does not exist, or
456 * is otherwise not currently selected, does nothing.
461 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
462 const char *filename)
464 GtkFileSystem *file_system;
467 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
468 g_return_if_fail (filename != NULL);
470 file_system = _gtk_file_chooser_get_file_system (chooser);
472 path = gtk_file_system_filename_to_path (file_system, filename);
475 _gtk_file_chooser_unselect_path (chooser, path);
476 gtk_file_path_free (path);
480 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
482 file_paths_to_strings (GtkFileSystem *fs,
484 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
490 for (; paths; paths = paths->next)
496 string = (* convert_func) (fs, path);
499 strings = g_slist_prepend (strings, string);
502 return g_slist_reverse (strings);
506 * gtk_file_chooser_get_filenames:
507 * @chooser: a #GtkFileChooser
509 * Lists all the selected files and subfolders in the current folder of
510 * @chooser. The returned names are full absolute paths. If files in the current
511 * folder cannot be represented as local filenames they will be ignored. (See
512 * gtk_file_chooser_get_uris())
514 * Return value: a #GSList containing the filenames of all selected
515 * files and subfolders in the current folder. Free the returned list
516 * with g_slist_free(), and the filenames with g_free().
521 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
523 GtkFileSystem *file_system;
527 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
529 file_system = _gtk_file_chooser_get_file_system (chooser);
530 paths = _gtk_file_chooser_get_paths (chooser);
532 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
533 gtk_file_paths_free (paths);
538 * gtk_file_chooser_set_current_folder:
539 * @chooser: a #GtkFileChooser
540 * @filename: the full path of the new current folder
542 * Sets the current folder for @chooser from a local filename.
543 * The user will be shown the full contents of the current folder,
544 * plus user interface elements for navigating to other folders.
549 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
550 const gchar *filename)
552 GtkFileSystem *file_system;
555 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
556 g_return_if_fail (filename != NULL);
558 file_system = _gtk_file_chooser_get_file_system (chooser);
560 path = gtk_file_system_filename_to_path (file_system, filename);
563 _gtk_file_chooser_set_current_folder_path (chooser, path);
564 gtk_file_path_free (path);
569 * gtk_file_chooser_get_current_folder:
570 * @chooser: a #GtkFileChooser
572 * Gets the current folder of @chooser as a local filename.
573 * See gtk_file_chooser_set_current_folder().
575 * Return value: the full path of the current folder, or %NULL
576 * if the current path cannot be represented as a local filename.
577 * Free with g_free().
582 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
584 GtkFileSystem *file_system;
588 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
590 file_system = _gtk_file_chooser_get_file_system (chooser);
592 path = _gtk_file_chooser_get_current_folder_path (chooser);
593 filename = gtk_file_system_path_to_filename (file_system, path);
594 gtk_file_path_free (path);
600 * gtk_file_chooser_set_current_name:
601 * @chooser: a #GtkFileChooser
602 * @name: the filename to use, as a UTF-8 string
604 * Sets the current name in the file selector, as if entered
605 * by the user. Note that the name passed in here is a UTF-8
606 * string rather than a filename. This function is meant for
607 * such uses as a suggested name in a "Save As..." dialog.
609 * If you want to preselect a particular existing file, you
610 * should use gtk_file_chooser_set_filename() instead.
615 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
618 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
619 g_return_if_fail (name != NULL);
621 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
625 * gtk_file_chooser_get_uri:
626 * @chooser: a #GtkFileChooser
628 * Gets the URI for the currently selected file in
629 * the file selector. If multiple files are selected,
630 * one of the filenames will be returned at random.
632 * Return value: The currently selected URI, or %NULL
633 * if no file is selected. Free with g_free()
638 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
640 GtkFileSystem *file_system;
642 gchar *result = NULL;
644 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
646 file_system = _gtk_file_chooser_get_file_system (chooser);
647 path = gtk_file_chooser_get_path (chooser);
650 result = gtk_file_system_path_to_uri (file_system, path);
651 gtk_file_path_free (path);
658 * gtk_file_chooser_set_uri:
659 * @chooser: a #GtkFileChooser
660 * @uri: the URI to set as current
662 * Sets the file referred to by @uri as the current file for the the
663 * file chooser; If the file name isn't in the current folder of @chooser,
664 * then the current folder of @chooser will be changed to the folder containing
665 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
666 * followed by gtk_file_chooser_select_uri().
668 * Note that the file must exist, or nothing will be done except
669 * for the directory change. To pre-enter a filename for the user, as in
670 * a save-as dialog, use gtk_file_chooser_set_current_name()
675 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
678 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
680 gtk_file_chooser_unselect_all (chooser);
681 gtk_file_chooser_select_uri (chooser, uri);
685 * gtk_file_chooser_select_uri:
686 * @chooser: a #GtkFileChooser
687 * @uri: the URI to select
689 * Selects the file to by @uri. If the URI doesn't refer to a
690 * file in the current folder of @chooser, then the current folder of
691 * @chooser will be changed to the folder containing @filename.
696 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
699 GtkFileSystem *file_system;
702 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
703 g_return_if_fail (uri != NULL);
705 file_system = _gtk_file_chooser_get_file_system (chooser);
707 path = gtk_file_system_uri_to_path (file_system, uri);
710 _gtk_file_chooser_select_path (chooser, path);
711 gtk_file_path_free (path);
716 * gtk_file_chooser_unselect_uri:
717 * @chooser: a #GtkFileChooser
718 * @uri: the URI to unselect
720 * Unselects the file referred to by @uri. If the file
721 * is not in the current directory, does not exist, or
722 * is otherwise not currently selected, does nothing.
727 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
730 GtkFileSystem *file_system;
733 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
734 g_return_if_fail (uri != NULL);
736 file_system = _gtk_file_chooser_get_file_system (chooser);
738 path = gtk_file_system_uri_to_path (file_system, uri);
741 _gtk_file_chooser_unselect_path (chooser, path);
742 gtk_file_path_free (path);
747 * gtk_file_chooser_select_all:
748 * @chooser: a #GtkFileChooser
750 * Selects all the files in the current folder of a file chooser.
755 gtk_file_chooser_select_all (GtkFileChooser *chooser)
757 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
759 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
763 * gtk_file_chooser_unselect_all:
764 * @chooser: a #GtkFileChooser
766 * Unselects all the files in the current folder of a file chooser.
771 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
774 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
776 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
780 * gtk_file_chooser_get_uris:
781 * @chooser: a #GtkFileChooser
783 * Lists all the selected files and subfolders in the current folder of
784 * @chooser. The returned names are full absolute URIs.
786 * Return value: a #GSList containing the URIs of all selected
787 * files and subfolders in the current folder. Free the returned list
788 * with g_slist_free(), and the filenames with g_free().
793 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
795 GtkFileSystem *file_system;
799 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
801 file_system = _gtk_file_chooser_get_file_system (chooser);
802 paths = _gtk_file_chooser_get_paths (chooser);
804 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
805 gtk_file_paths_free (paths);
810 * gtk_file_chooser_set_current_folder_uri:
811 * @chooser: a #GtkFileChooser
812 * @uri: the URI for the new current folder
814 * Sets the current folder for @chooser from an URI.
815 * The user will be shown the full contents of the current folder,
816 * plus user interface elements for navigating to other folders.
821 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
824 GtkFileSystem *file_system;
827 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
828 g_return_if_fail (uri != NULL);
830 file_system = _gtk_file_chooser_get_file_system (chooser);
832 path = gtk_file_system_uri_to_path (file_system, uri);
835 _gtk_file_chooser_set_current_folder_path (chooser, path);
836 gtk_file_path_free (path);
841 * gtk_file_chooser_get_current_folder_uri:
842 * @chooser: a #GtkFileChooser
844 * Gets the current folder of @chooser as an URI.
845 * See gtk_file_chooser_set_current_folder_uri().
847 * Return value: the URI for the current folder.
848 * Free with g_free().
853 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
855 GtkFileSystem *file_system;
859 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
861 file_system = _gtk_file_chooser_get_file_system (chooser);
863 path = _gtk_file_chooser_get_current_folder_path (chooser);
864 uri = gtk_file_system_path_to_uri (file_system, path);
865 gtk_file_path_free (path);
871 * _gtk_file_chooser_set_current_folder_path:
872 * @chooser: a #GtkFileChooser
873 * @path: the #GtkFilePath for the new folder
875 * Sets the current folder for @chooser from a #GtkFilePath.
876 * Internal function, see gtk_file_chooser_set_current_folder_uri().
881 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
882 const GtkFilePath *path)
884 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
885 g_return_if_fail (path != NULL);
887 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
891 * _gtk_file_chooser_get_current_folder_path:
892 * @chooser: a #GtkFileChooser
894 * Gets the current folder of @chooser as #GtkFilePath.
895 * See gtk_file_chooser_get_current_folder_uri().
897 * Return value: the #GtkFilePath for the current folder.
898 * Free with gtk_file_path_free().
903 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
905 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
907 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
911 * _gtk_file_chooser_select_path:
912 * @chooser: a #GtkFileChooser
913 * @path: the path to select
915 * Selects the file referred to by @path. An internal function. See
916 * _gtk_file_chooser_select_uri().
921 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
922 const GtkFilePath *path)
924 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
926 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
930 * _gtk_file_chooser_unselect_path:
931 * @chooser: a #GtkFileChooser
932 * @path: the filename to path
934 * Unselects the file referred to by @path. An internal
935 * function. See _gtk_file_chooser_unselect_uri().
940 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
941 const GtkFilePath *path)
943 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
945 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
949 * _gtk_file_chooser_get_paths:
950 * @chooser: a #GtkFileChooser
952 * Lists all the selected files and subfolders in the current folder of @chooser
953 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
955 * Return value: a #GSList containing a #GtkFilePath for each selected
956 * file and subfolder in the current folder. Free the returned list
957 * with g_slist_free(), and the paths with gtk_file_path_free().
962 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
964 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
966 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
970 gtk_file_chooser_get_path (GtkFileChooser *chooser)
973 GtkFilePath *result = NULL;
975 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
977 list = _gtk_file_chooser_get_paths (chooser);
981 list = g_slist_delete_link (list, list);
982 gtk_file_paths_free (list);
989 * _gtk_file_chooser_get_file_system:
990 * @chooser: a #GtkFileChooser
992 * Gets the #GtkFileSystem of @chooser; this is an internal
993 * implementation detail, used for conversion between paths
994 * and filenames and URIs.
996 * Return value: the file system for @chooser.
1001 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1003 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1005 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1011 * gtk_file_chooser_set_preview_widget:
1012 * @chooser: a #GtkFileChooser
1013 * @preview_widget: widget for displaying preview.
1015 * Sets an application-supplied widget to use to display a custom preview
1016 * of the currently selected file. To implement a preview, after setting the
1017 * preview widget, you connect to the ::selection-changed
1018 * signal, and call gtk_file_chooser_get_preview_filename() or
1019 * gtk_file_chooser_get_preview_uri() on each change. If you can
1020 * display a preview of the new file, update your widget and
1021 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1022 * Otherwise, set the preview inactive.
1024 * When there is no application-supplied preview widget, or the
1025 * application-supplied preview widget is not active, the file chooser
1026 * may display an internally generated preview of the current file or
1027 * it may display no preview at all.
1032 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1033 GtkWidget *preview_widget)
1035 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1037 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1041 * gtk_file_chooser_get_preview_widget:
1042 * @chooser: a #GtkFileChooser
1044 * Gets the current preview widget; see
1045 * gtk_file_chooser_set_preview_widget().
1047 * Return value: the current preview widget, or %NULL
1052 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1054 GtkWidget *preview_widget;
1056 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1058 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1060 /* Horrid hack; g_object_get() refs returned objects but
1061 * that contradicts the memory management conventions
1065 g_object_unref (preview_widget);
1067 return preview_widget;
1071 * gtk_file_chooser_set_preview_widget_active:
1072 * @chooser: a #GtkFileChooser
1073 * @active: whether to display the user-specified preview widget
1075 * Sets whether the preview widget set by
1076 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1077 * current filename. When @active is set to false, the file chooser
1078 * may display an internally generated preview of the current file
1079 * or it may display no preview at all. See
1080 * gtk_file_chooser_set_preview_widget() for more details.
1085 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1088 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1090 g_object_set (chooser, "preview-widget-active", active, NULL);
1094 * gtk_file_chooser_get_preview_widget_active:
1095 * @chooser: a #GtkFileChooser
1097 * Gets whether the preview widget set by
1098 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1099 * current filename. See gtk_file_chooser_set_preview_widget_active().
1101 * Return value: %TRUE if the preview widget is active for the
1107 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1111 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1113 g_object_get (chooser, "preview-widget-active", &active, NULL);
1119 * gtk_file_chooser_get_preview_filename:
1120 * @chooser: a #GtkFileChooser
1122 * Gets the filename that should be previewed in a custom preview
1123 * Internal function, see gtk_file_chooser_get_preview_uri().
1125 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1126 * is selected. Free with gtk_file_path_free().
1131 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1133 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1135 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1139 * _gtk_file_chooser_add_shortcut_folder:
1140 * @chooser: a #GtkFileChooser
1141 * @path: path of the folder to add
1142 * @error: location to store error, or %NULL
1144 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1145 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1147 * Return value: %TRUE if the folder could be added successfully, %FALSE
1153 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1154 const GtkFilePath *path,
1157 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1158 g_return_val_if_fail (path != NULL, FALSE);
1160 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1164 * _gtk_file_chooser_remove_shortcut_folder:
1165 * @chooser: a #GtkFileChooser
1166 * @path: path of the folder to remove
1167 * @error: location to store error, or %NULL
1169 * Removes a folder from the shortcut folders in a file chooser. Internal
1170 * function, see gtk_file_chooser_remove_shortcut_folder().
1172 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1178 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1179 const GtkFilePath *path,
1182 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1183 g_return_val_if_fail (path != NULL, FALSE);
1185 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1189 * gtk_file_chooser_get_preview_filename:
1190 * @chooser: a #GtkFileChooser
1192 * Gets the filename that should be previewed in a custom preview
1193 * widget. See gtk_file_chooser_set_preview_widget().
1195 * Return value: the filename to preview, or %NULL if no file
1196 * is selected, or if the selected file cannot be represented
1197 * as a local filename. Free with g_free()
1202 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1204 GtkFileSystem *file_system;
1206 gchar *result = NULL;
1208 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1210 file_system = _gtk_file_chooser_get_file_system (chooser);
1211 path = _gtk_file_chooser_get_preview_path (chooser);
1214 result = gtk_file_system_path_to_filename (file_system, path);
1215 gtk_file_path_free (path);
1222 * gtk_file_chooser_get_preview_uri:
1223 * @chooser: a #GtkFileChooser
1225 * Gets the URI that should be previewed in a custom preview
1226 * widget. See gtk_file_chooser_set_preview_widget().
1228 * Return value: the URI for the file to preview, or %NULL if no file is
1229 * selected. Free with g_free().
1234 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1236 GtkFileSystem *file_system;
1238 gchar *result = NULL;
1240 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1242 file_system = _gtk_file_chooser_get_file_system (chooser);
1243 path = _gtk_file_chooser_get_preview_path (chooser);
1246 result = gtk_file_system_path_to_uri (file_system, path);
1247 gtk_file_path_free (path);
1254 * gtk_file_chooser_set_extra_widget:
1255 * @chooser: a #GtkFileChooser
1256 * @extra_widget: widget for extra options
1258 * Sets an application-supplied widget to provide extra options to the user.
1263 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1264 GtkWidget *extra_widget)
1266 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1268 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1272 * gtk_file_chooser_get_extra_widget:
1273 * @chooser: a #GtkFileChooser
1275 * Gets the current preview widget; see
1276 * gtk_file_chooser_set_extra_widget().
1278 * Return value: the current extra widget, or %NULL
1283 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1285 GtkWidget *extra_widget;
1287 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1289 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1291 /* Horrid hack; g_object_get() refs returned objects but
1292 * that contradicts the memory management conventions
1296 g_object_unref (extra_widget);
1298 return extra_widget;
1302 * gtk_file_chooser_add_filter:
1303 * @chooser: a #GtkFileChooser
1304 * @filter: a #GtkFileFilter
1306 * Adds @filter to the list of filters that the user can select between.
1307 * When a filter is selected, only files that are passed by that
1308 * filter are displayed.
1313 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1314 GtkFileFilter *filter)
1316 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1318 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1322 * gtk_file_chooser_remove_filter:
1323 * @chooser: a #GtkFileChooser
1324 * @filter: a #GtkFileFilter
1326 * Removes @filter from the list of filters that the user can select between.
1331 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1332 GtkFileFilter *filter)
1334 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1336 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1340 * gtk_file_chooser_list_filters:
1341 * @chooser: a #GtkFileChooser
1343 * Lists the current set of user-selectable filters; see
1344 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1346 * Return value: a #GSList containing the current set of
1347 * user selectable filters. The contents of the list are
1348 * owned by GTK+, but you must free the list itself with
1349 * g_slist_free() when you are done with it.
1354 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1356 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1358 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1362 * gtk_file_chooser_set_filter:
1363 * @chooser: a #GtkFileChooser
1364 * @filter: a #GtkFileFilter
1366 * Sets the current filter; only the files that pass the
1367 * filter will be displayed. If the user-selectable list of filters
1368 * is non-empty, then the filter should be one of the filters
1369 * in that list. Setting the current filter when the list of
1370 * filters is empty is useful if you want to restrict the displayed
1371 * set of files without letting the user change it.
1376 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1377 GtkFileFilter *filter)
1379 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1380 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1382 g_object_set (chooser, "filter", filter, NULL);
1386 * gtk_file_chooser_get_filter:
1387 * @chooser: a #GtkFileChooser
1389 * Gets the current filter; see gtk_file_chooser_set_filter().
1391 * Return value: the current filter, or %NULL
1396 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1398 GtkFileFilter *filter;
1400 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1402 g_object_get (chooser, "filter", &filter, NULL);
1403 /* Horrid hack; g_object_get() refs returned objects but
1404 * that contradicts the memory management conventions
1408 g_object_unref (filter);
1414 * gtk_file_chooser_add_shortcut_folder:
1415 * @chooser: a #GtkFileChooser
1416 * @folder: filename of the folder to add
1417 * @error: location to store error, or %NULL
1419 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1420 * Note that shortcut folders do not get saved, as they are provided by the
1421 * application. For example, you can use this to add a
1422 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1424 * Return value: %TRUE if the folder could be added successfully, %FALSE
1425 * otherwise. In the latter case, the @error will be set as appropriate.
1430 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1437 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1438 g_return_val_if_fail (folder != NULL, FALSE);
1440 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1444 GTK_FILE_CHOOSER_ERROR,
1445 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1446 _("Invalid filename: %s"),
1451 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1453 gtk_file_path_free (path);
1459 * gtk_file_chooser_remove_shortcut_folder:
1460 * @chooser: a #GtkFileChooser
1461 * @folder: filename of the folder to remove
1462 * @error: location to store error, or %NULL
1464 * Removes a folder from a file chooser's list of shortcut folders.
1466 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1467 * In the latter case, the @error will be set as appropriate.
1469 * See also: gtk_file_chooser_add_shortcut_folder()
1474 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1481 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1482 g_return_val_if_fail (folder != NULL, FALSE);
1484 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1488 GTK_FILE_CHOOSER_ERROR,
1489 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1490 _("Invalid filename: %s"),
1495 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1497 gtk_file_path_free (path);
1503 * gtk_file_chooser_list_shortcut_folders:
1504 * @chooser: a #GtkFileChooser
1506 * Queries the list of shortcut folders in the file chooser, as set by
1507 * gtk_file_chooser_set_shortcut_folders().
1509 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1510 * folders. Free the returned list with g_slist_free(), and the filenames with
1516 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1521 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1523 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1525 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1527 gtk_file_system_path_to_filename);
1528 gtk_file_paths_free (folders);
1533 * gtk_file_chooser_add_shortcut_folder_uri:
1534 * @chooser: a #GtkFileChooser
1535 * @uri: URI of the folder to add
1536 * @error: location to store error, or %NULL
1538 * Adds a folder URI to be displayed with the shortcut folders in a file
1539 * chooser. Note that shortcut folders do not get saved, as they are provided
1540 * by the application. For example, you can use this to add a
1541 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1543 * Return value: %TRUE if the folder could be added successfully, %FALSE
1544 * otherwise. In the latter case, the @error will be set as appropriate.
1549 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1556 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1557 g_return_val_if_fail (uri != NULL, FALSE);
1559 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1563 GTK_FILE_CHOOSER_ERROR,
1564 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1565 _("Invalid filename: %s"),
1570 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1572 gtk_file_path_free (path);
1578 * gtk_file_chooser_remove_shortcut_folder_uri:
1579 * @chooser: a #GtkFileChooser
1580 * @uri: URI of the folder to remove
1581 * @error: location to store error, or %NULL
1583 * Removes a folder URI from a file chooser's list of shortcut folders.
1585 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1586 * In the latter case, the @error will be set as appropriate.
1588 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1593 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1600 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1601 g_return_val_if_fail (uri != NULL, FALSE);
1603 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1607 GTK_FILE_CHOOSER_ERROR,
1608 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1609 _("Invalid filename: %s"),
1614 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1616 gtk_file_path_free (path);
1622 * gtk_file_chooser_list_shortcut_folder_uris:
1623 * @chooser: a #GtkFileChooser
1625 * Queries the list of shortcut folders in the file chooser, as set by
1626 * gtk_file_chooser_set_shortcut_folder_uris().
1628 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1629 * folders. Free the returned list with g_slist_free(), and the URIs with
1635 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1640 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1642 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1644 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1646 gtk_file_system_path_to_uri);
1647 gtk_file_paths_free (folders);