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 P_("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_string ("file-system-backend",
99 P_("File System Backend"),
100 P_("Name of file system backend to use"),
102 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
103 g_object_interface_install_property (g_iface,
104 g_param_spec_object ("filter",
106 P_("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 ("local-only",
112 P_("Whether the selected file(s) should be limited to local file: URLs"),
115 g_object_interface_install_property (g_iface,
116 g_param_spec_object ("preview-widget",
117 P_("Preview widget"),
118 P_("Application supplied widget for custom previews."),
121 g_object_interface_install_property (g_iface,
122 g_param_spec_boolean ("preview-widget-active",
123 P_("Preview Widget Active"),
124 P_("Whether the application supplied widget for custom previews should be shown."),
127 g_object_interface_install_property (g_iface,
128 g_param_spec_boolean ("use-preview-label",
129 P_("Use Preview Label"),
130 P_("Whether to display a stock label with the name of the previewed file."),
133 g_object_interface_install_property (g_iface,
134 g_param_spec_object ("extra-widget",
136 P_("Application supplied widget for extra options."),
139 g_object_interface_install_property (g_iface,
140 g_param_spec_boolean ("select-multiple",
141 P_("Select Multiple"),
142 P_("Whether to allow multiple files to be selected"),
146 g_object_interface_install_property (g_iface,
147 g_param_spec_boolean ("show-hidden",
149 P_("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_local_only:
219 * @chooser: a #GtkFileChooser
220 * @local_only: %TRUE if only local files can be selected
222 * Sets whether only local files can be selected in the
223 * file selector. If @local_only is %TRUE (the default),
224 * then the selected file are files are guaranteed to be
225 * accessible through the operating systems native file
226 * file system and therefore the application only
227 * needs to worry about the filename functions in
228 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
229 * rather than the URI functions like
230 * gtk_file_chooser_get_uri(),
235 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
238 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
240 g_object_set (chooser, "local-only", local_only, NULL);
244 * gtk_file_chooser_get_local_only:
245 * @chooser: a #GtkFileChoosre
247 * Gets whether only local files can be selected in the
248 * file selector. See gtk_file_chooser_set_local_only()
250 * Return value: %TRUE if only local files can be selected.
255 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
259 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
261 g_object_get (chooser, "local-only", &local_only, NULL);
267 * gtk_file_chooser_set_select_multiple:
268 * @chooser: a #GtkFileChooser
269 * @select_multiple: %TRUE if multiple files can be selected.
271 * Sets whether multiple files can be selected in the file selector. This is
272 * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
273 * GTK_FILE_CHOOSER_ACTION_SAVE. It cannot be set with either of the folder
279 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
280 gboolean select_multiple)
282 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
284 g_object_set (chooser, "select-multiple", select_multiple, NULL);
288 * gtk_file_chooser_get_select_multiple:
289 * @chooser: a #GtkFileChooser
291 * Gets whether multiple files can be selected in the file
292 * selector. See gtk_file_chooser_set_select_multiple().
294 * Return value: %TRUE if multiple files can be selected.
299 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
301 gboolean select_multiple;
303 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
305 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
307 return select_multiple;
311 * gtk_file_chooser_get_filename:
312 * @chooser: a #GtkFileChooser
314 * Gets the filename for the currently selected file in
315 * the file selector. If multiple files are selected,
316 * one of the filenames will be returned at random.
318 * If the file chooser is in folder mode, this function returns the selected
321 * Return value: The currently selected filename, or %NULL
322 * if no file is selected, or the selected file can't
323 * be represented with a local filename. Free with g_free().
328 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
330 GtkFileSystem *file_system;
332 gchar *result = NULL;
334 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
336 file_system = _gtk_file_chooser_get_file_system (chooser);
337 path = gtk_file_chooser_get_path (chooser);
340 result = gtk_file_system_path_to_filename (file_system, path);
341 gtk_file_path_free (path);
348 * gtk_file_chooser_set_filename:
349 * @chooser: a #GtkFileChooser
350 * @filename: the filename to set as current
352 * Sets @filename as the current filename for the the file chooser;
353 * If the file name isn't in the current folder of @chooser, then the
354 * current folder of @chooser will be changed to the folder containing
355 * @filename. This is equivalent to a sequence of
356 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
358 * Note that the file must exist, or nothing will be done except
359 * for the directory change. To pre-enter a filename for the user, as in
360 * a save-as dialog, use gtk_file_chooser_set_current_name()
362 * Return value: %TRUE if both the folder could be changed and the file was
363 * selected successfully, %FALSE otherwise.
368 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
369 const gchar *filename)
371 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
373 gtk_file_chooser_unselect_all (chooser);
374 return gtk_file_chooser_select_filename (chooser, filename);
378 * gtk_file_chooser_select_filename:
379 * @chooser: a #GtkFileChooser
380 * @filename: the filename to select
382 * Selects a filename. If the file name isn't in the current
383 * folder of @chooser, then the current folder of @chooser will
384 * be changed to the folder containing @filename.
386 * Return value: %TRUE if both the folder could be changed and the file was
387 * selected successfully, %FALSE otherwise.
392 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
393 const gchar *filename)
395 GtkFileSystem *file_system;
399 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
400 g_return_val_if_fail (filename != NULL, FALSE);
402 file_system = _gtk_file_chooser_get_file_system (chooser);
404 path = gtk_file_system_filename_to_path (file_system, filename);
407 result = _gtk_file_chooser_select_path (chooser, path, NULL);
408 gtk_file_path_free (path);
417 * gtk_file_chooser_unselect_filename:
418 * @chooser: a #GtkFileChooser
419 * @filename: the filename to unselect
421 * Unselects a currently selected filename. If the filename
422 * is not in the current directory, does not exist, or
423 * is otherwise not currently selected, does nothing.
428 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
429 const char *filename)
431 GtkFileSystem *file_system;
434 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
435 g_return_if_fail (filename != NULL);
437 file_system = _gtk_file_chooser_get_file_system (chooser);
439 path = gtk_file_system_filename_to_path (file_system, filename);
442 _gtk_file_chooser_unselect_path (chooser, path);
443 gtk_file_path_free (path);
447 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
449 file_paths_to_strings (GtkFileSystem *fs,
451 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
457 for (; paths; paths = paths->next)
463 string = (* convert_func) (fs, path);
466 strings = g_slist_prepend (strings, string);
469 return g_slist_reverse (strings);
473 * gtk_file_chooser_get_filenames:
474 * @chooser: a #GtkFileChooser
476 * Lists all the selected files and subfolders in the current folder of
477 * @chooser. The returned names are full absolute paths. If files in the current
478 * folder cannot be represented as local filenames they will be ignored. (See
479 * gtk_file_chooser_get_uris())
481 * Return value: a #GSList containing the filenames of all selected
482 * files and subfolders in the current folder. Free the returned list
483 * with g_slist_free(), and the filenames with g_free().
488 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
490 GtkFileSystem *file_system;
494 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
496 file_system = _gtk_file_chooser_get_file_system (chooser);
497 paths = _gtk_file_chooser_get_paths (chooser);
499 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
500 gtk_file_paths_free (paths);
505 * gtk_file_chooser_set_current_folder:
506 * @chooser: a #GtkFileChooser
507 * @filename: the full path of the new current folder
509 * Sets the current folder for @chooser from a local filename.
510 * The user will be shown the full contents of the current folder,
511 * plus user interface elements for navigating to other folders.
513 * Return value: %TRUE if the folder could be changed successfully, %FALSE
519 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
520 const gchar *filename)
522 GtkFileSystem *file_system;
526 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
527 g_return_val_if_fail (filename != NULL, FALSE);
529 file_system = _gtk_file_chooser_get_file_system (chooser);
531 path = gtk_file_system_filename_to_path (file_system, filename);
534 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
535 gtk_file_path_free (path);
544 * gtk_file_chooser_get_current_folder:
545 * @chooser: a #GtkFileChooser
547 * Gets the current folder of @chooser as a local filename.
548 * See gtk_file_chooser_set_current_folder().
550 * Return value: the full path of the current folder, or %NULL
551 * if the current path cannot be represented as a local filename.
552 * Free with g_free().
557 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
559 GtkFileSystem *file_system;
563 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
565 file_system = _gtk_file_chooser_get_file_system (chooser);
567 path = _gtk_file_chooser_get_current_folder_path (chooser);
568 filename = gtk_file_system_path_to_filename (file_system, path);
569 gtk_file_path_free (path);
575 * gtk_file_chooser_set_current_name:
576 * @chooser: a #GtkFileChooser
577 * @name: the filename to use, as a UTF-8 string
579 * Sets the current name in the file selector, as if entered
580 * by the user. Note that the name passed in here is a UTF-8
581 * string rather than a filename. This function is meant for
582 * such uses as a suggested name in a "Save As..." dialog.
584 * If you want to preselect a particular existing file, you
585 * should use gtk_file_chooser_set_filename() instead.
590 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
593 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
594 g_return_if_fail (name != NULL);
596 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
600 * gtk_file_chooser_get_uri:
601 * @chooser: a #GtkFileChooser
603 * Gets the URI for the currently selected file in
604 * the file selector. If multiple files are selected,
605 * one of the filenames will be returned at random.
607 * If the file chooser is in folder mode, this function returns the selected
610 * Return value: The currently selected URI, or %NULL
611 * if no file is selected. Free with g_free()
616 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
618 GtkFileSystem *file_system;
620 gchar *result = NULL;
622 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
624 file_system = _gtk_file_chooser_get_file_system (chooser);
625 path = gtk_file_chooser_get_path (chooser);
628 result = gtk_file_system_path_to_uri (file_system, path);
629 gtk_file_path_free (path);
636 * gtk_file_chooser_set_uri:
637 * @chooser: a #GtkFileChooser
638 * @uri: the URI to set as current
640 * Sets the file referred to by @uri as the current file for the the
641 * file chooser; If the file name isn't in the current folder of @chooser,
642 * then the current folder of @chooser will be changed to the folder containing
643 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
644 * followed by gtk_file_chooser_select_uri().
646 * Note that the file must exist, or nothing will be done except
647 * for the directory change. To pre-enter a filename for the user, as in
648 * a save-as dialog, use gtk_file_chooser_set_current_name()
650 * Return value: %TRUE if both the folder could be changed and the URI was
651 * selected successfully, %FALSE otherwise.
656 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
659 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
661 gtk_file_chooser_unselect_all (chooser);
662 return gtk_file_chooser_select_uri (chooser, uri);
666 * gtk_file_chooser_select_uri:
667 * @chooser: a #GtkFileChooser
668 * @uri: the URI to select
670 * Selects the file to by @uri. If the URI doesn't refer to a
671 * file in the current folder of @chooser, then the current folder of
672 * @chooser will be changed to the folder containing @filename.
674 * Return value: %TRUE if both the folder could be changed and the URI was
675 * selected successfully, %FALSE otherwise.
680 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
683 GtkFileSystem *file_system;
687 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
688 g_return_val_if_fail (uri != NULL, FALSE);
690 file_system = _gtk_file_chooser_get_file_system (chooser);
692 path = gtk_file_system_uri_to_path (file_system, uri);
695 result = _gtk_file_chooser_select_path (chooser, path, NULL);
696 gtk_file_path_free (path);
705 * gtk_file_chooser_unselect_uri:
706 * @chooser: a #GtkFileChooser
707 * @uri: the URI to unselect
709 * Unselects the file referred to by @uri. If the file
710 * is not in the current directory, does not exist, or
711 * is otherwise not currently selected, does nothing.
716 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
719 GtkFileSystem *file_system;
722 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
723 g_return_if_fail (uri != NULL);
725 file_system = _gtk_file_chooser_get_file_system (chooser);
727 path = gtk_file_system_uri_to_path (file_system, uri);
730 _gtk_file_chooser_unselect_path (chooser, path);
731 gtk_file_path_free (path);
736 * gtk_file_chooser_select_all:
737 * @chooser: a #GtkFileChooser
739 * Selects all the files in the current folder of a file chooser.
744 gtk_file_chooser_select_all (GtkFileChooser *chooser)
746 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
748 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
752 * gtk_file_chooser_unselect_all:
753 * @chooser: a #GtkFileChooser
755 * Unselects all the files in the current folder of a file chooser.
760 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
763 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
765 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
769 * gtk_file_chooser_get_uris:
770 * @chooser: a #GtkFileChooser
772 * Lists all the selected files and subfolders in the current folder of
773 * @chooser. The returned names are full absolute URIs.
775 * Return value: a #GSList containing the URIs of all selected
776 * files and subfolders in the current folder. Free the returned list
777 * with g_slist_free(), and the filenames with g_free().
782 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
784 GtkFileSystem *file_system;
788 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
790 file_system = _gtk_file_chooser_get_file_system (chooser);
791 paths = _gtk_file_chooser_get_paths (chooser);
793 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
794 gtk_file_paths_free (paths);
799 * gtk_file_chooser_set_current_folder_uri:
800 * @chooser: a #GtkFileChooser
801 * @uri: the URI for the new current folder
803 * Sets the current folder for @chooser from an URI.
804 * The user will be shown the full contents of the current folder,
805 * plus user interface elements for navigating to other folders.
807 * Return value: %TRUE if the folder could be changed successfully, %FALSE
813 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
816 GtkFileSystem *file_system;
820 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
821 g_return_val_if_fail (uri != NULL, FALSE);
823 file_system = _gtk_file_chooser_get_file_system (chooser);
825 path = gtk_file_system_uri_to_path (file_system, uri);
828 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
829 gtk_file_path_free (path);
838 * gtk_file_chooser_get_current_folder_uri:
839 * @chooser: a #GtkFileChooser
841 * Gets the current folder of @chooser as an URI.
842 * See gtk_file_chooser_set_current_folder_uri().
844 * Return value: the URI for the current folder.
845 * Free with g_free().
850 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
852 GtkFileSystem *file_system;
856 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
858 file_system = _gtk_file_chooser_get_file_system (chooser);
860 path = _gtk_file_chooser_get_current_folder_path (chooser);
861 uri = gtk_file_system_path_to_uri (file_system, path);
862 gtk_file_path_free (path);
868 * _gtk_file_chooser_set_current_folder_path:
869 * @chooser: a #GtkFileChooser
870 * @path: the #GtkFilePath for the new folder
871 * @error: location to store error, or %NULL.
873 * Sets the current folder for @chooser from a #GtkFilePath.
874 * Internal function, see gtk_file_chooser_set_current_folder_uri().
876 * Return value: %TRUE if the folder could be changed successfully, %FALSE
882 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
883 const GtkFilePath *path,
886 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
887 g_return_val_if_fail (path != NULL, FALSE);
888 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
890 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path, error);
894 * _gtk_file_chooser_get_current_folder_path:
895 * @chooser: a #GtkFileChooser
897 * Gets the current folder of @chooser as #GtkFilePath.
898 * See gtk_file_chooser_get_current_folder_uri().
900 * Return value: the #GtkFilePath for the current folder.
901 * Free with gtk_file_path_free().
906 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
908 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
910 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
914 * _gtk_file_chooser_select_path:
915 * @chooser: a #GtkFileChooser
916 * @path: the path to select
917 * @error: location to store error, or %NULL
919 * Selects the file referred to by @path. An internal function. See
920 * _gtk_file_chooser_select_uri().
922 * Return value: %TRUE if both the folder could be changed and the path was
923 * selected successfully, %FALSE otherwise.
928 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
929 const GtkFilePath *path,
932 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
933 g_return_val_if_fail (path != NULL, FALSE);
934 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
936 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path, error);
940 * _gtk_file_chooser_unselect_path:
941 * @chooser: a #GtkFileChooser
942 * @path: the filename to path
944 * Unselects the file referred to by @path. An internal
945 * function. See _gtk_file_chooser_unselect_uri().
950 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
951 const GtkFilePath *path)
953 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
955 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
959 * _gtk_file_chooser_get_paths:
960 * @chooser: a #GtkFileChooser
962 * Lists all the selected files and subfolders in the current folder of @chooser
963 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
965 * Return value: a #GSList containing a #GtkFilePath for each selected
966 * file and subfolder in the current folder. Free the returned list
967 * with g_slist_free(), and the paths with gtk_file_path_free().
972 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
974 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
976 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
980 gtk_file_chooser_get_path (GtkFileChooser *chooser)
983 GtkFilePath *result = NULL;
985 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
987 list = _gtk_file_chooser_get_paths (chooser);
991 list = g_slist_delete_link (list, list);
992 gtk_file_paths_free (list);
999 * _gtk_file_chooser_get_file_system:
1000 * @chooser: a #GtkFileChooser
1002 * Gets the #GtkFileSystem of @chooser; this is an internal
1003 * implementation detail, used for conversion between paths
1004 * and filenames and URIs.
1006 * Return value: the file system for @chooser.
1011 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1013 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1015 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1021 * gtk_file_chooser_set_preview_widget:
1022 * @chooser: a #GtkFileChooser
1023 * @preview_widget: widget for displaying preview.
1025 * Sets an application-supplied widget to use to display a custom preview
1026 * of the currently selected file. To implement a preview, after setting the
1027 * preview widget, you connect to the ::selection-changed
1028 * signal, and call gtk_file_chooser_get_preview_filename() or
1029 * gtk_file_chooser_get_preview_uri() on each change. If you can
1030 * display a preview of the new file, update your widget and
1031 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1032 * Otherwise, set the preview inactive.
1034 * When there is no application-supplied preview widget, or the
1035 * application-supplied preview widget is not active, the file chooser
1036 * may display an internally generated preview of the current file or
1037 * it may display no preview at all.
1042 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1043 GtkWidget *preview_widget)
1045 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1047 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1051 * gtk_file_chooser_get_preview_widget:
1052 * @chooser: a #GtkFileChooser
1054 * Gets the current preview widget; see
1055 * gtk_file_chooser_set_preview_widget().
1057 * Return value: the current preview widget, or %NULL
1062 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1064 GtkWidget *preview_widget;
1066 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1068 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1070 /* Horrid hack; g_object_get() refs returned objects but
1071 * that contradicts the memory management conventions
1075 g_object_unref (preview_widget);
1077 return preview_widget;
1081 * gtk_file_chooser_set_preview_widget_active:
1082 * @chooser: a #GtkFileChooser
1083 * @active: whether to display the user-specified preview widget
1085 * Sets whether the preview widget set by
1086 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1087 * current filename. When @active is set to false, the file chooser
1088 * may display an internally generated preview of the current file
1089 * or it may display no preview at all. See
1090 * gtk_file_chooser_set_preview_widget() for more details.
1095 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1098 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1100 g_object_set (chooser, "preview-widget-active", active, NULL);
1104 * gtk_file_chooser_get_preview_widget_active:
1105 * @chooser: a #GtkFileChooser
1107 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1108 * should be shown for the current filename. See
1109 * gtk_file_chooser_set_preview_widget_active().
1111 * Return value: %TRUE if the preview widget is active for the current filename.
1116 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1120 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1122 g_object_get (chooser, "preview-widget-active", &active, NULL);
1128 * gtk_file_chooser_set_use_preview_label:
1129 * @chooser: a #GtkFileChooser
1130 * @use_label: whether to display a stock label with the name of the previewed file
1132 * Sets whether the file chooser should display a stock label with the name of
1133 * the file that is being previewed; the default is %TRUE. Applications that
1134 * want to draw the whole preview area themselves should set this to %FALSE and
1135 * display the name themselves in their preview widget.
1137 * See also: gtk_file_chooser_set_preview_widget()
1142 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1145 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1147 g_object_set (chooser, "use-preview-label", use_label, NULL);
1151 * gtk_file_chooser_get_use_preview_label:
1152 * @chooser: a #GtkFileChooser
1154 * Gets whether a stock label should be drawn with the name of the previewed
1155 * file. See gtk_file_chooser_set_use_preview_label().
1157 * Return value: %TRUE if the file chooser is set to display a label with the
1158 * name of the previewed file, %FALSE otherwise.
1161 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1165 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1167 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1173 * gtk_file_chooser_get_preview_filename:
1174 * @chooser: a #GtkFileChooser
1176 * Gets the filename that should be previewed in a custom preview
1177 * Internal function, see gtk_file_chooser_get_preview_uri().
1179 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1180 * is selected. Free with gtk_file_path_free().
1185 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1187 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1189 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1193 * _gtk_file_chooser_add_shortcut_folder:
1194 * @chooser: a #GtkFileChooser
1195 * @path: path of the folder to add
1196 * @error: location to store error, or %NULL
1198 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1199 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1201 * Return value: %TRUE if the folder could be added successfully, %FALSE
1207 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1208 const GtkFilePath *path,
1211 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1212 g_return_val_if_fail (path != NULL, FALSE);
1214 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1218 * _gtk_file_chooser_remove_shortcut_folder:
1219 * @chooser: a #GtkFileChooser
1220 * @path: path of the folder to remove
1221 * @error: location to store error, or %NULL
1223 * Removes a folder from the shortcut folders in a file chooser. Internal
1224 * function, see gtk_file_chooser_remove_shortcut_folder().
1226 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1232 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1233 const GtkFilePath *path,
1236 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1237 g_return_val_if_fail (path != NULL, FALSE);
1239 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1243 * gtk_file_chooser_get_preview_filename:
1244 * @chooser: a #GtkFileChooser
1246 * Gets the filename that should be previewed in a custom preview
1247 * widget. See gtk_file_chooser_set_preview_widget().
1249 * Return value: the filename to preview, or %NULL if no file
1250 * is selected, or if the selected file cannot be represented
1251 * as a local filename. Free with g_free()
1256 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1258 GtkFileSystem *file_system;
1260 gchar *result = NULL;
1262 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1264 file_system = _gtk_file_chooser_get_file_system (chooser);
1265 path = _gtk_file_chooser_get_preview_path (chooser);
1268 result = gtk_file_system_path_to_filename (file_system, path);
1269 gtk_file_path_free (path);
1276 * gtk_file_chooser_get_preview_uri:
1277 * @chooser: a #GtkFileChooser
1279 * Gets the URI that should be previewed in a custom preview
1280 * widget. See gtk_file_chooser_set_preview_widget().
1282 * Return value: the URI for the file to preview, or %NULL if no file is
1283 * selected. Free with g_free().
1288 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1290 GtkFileSystem *file_system;
1292 gchar *result = NULL;
1294 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1296 file_system = _gtk_file_chooser_get_file_system (chooser);
1297 path = _gtk_file_chooser_get_preview_path (chooser);
1300 result = gtk_file_system_path_to_uri (file_system, path);
1301 gtk_file_path_free (path);
1308 * gtk_file_chooser_set_extra_widget:
1309 * @chooser: a #GtkFileChooser
1310 * @extra_widget: widget for extra options
1312 * Sets an application-supplied widget to provide extra options to the user.
1317 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1318 GtkWidget *extra_widget)
1320 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1322 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1326 * gtk_file_chooser_get_extra_widget:
1327 * @chooser: a #GtkFileChooser
1329 * Gets the current preview widget; see
1330 * gtk_file_chooser_set_extra_widget().
1332 * Return value: the current extra widget, or %NULL
1337 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1339 GtkWidget *extra_widget;
1341 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1343 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1345 /* Horrid hack; g_object_get() refs returned objects but
1346 * that contradicts the memory management conventions
1350 g_object_unref (extra_widget);
1352 return extra_widget;
1356 * gtk_file_chooser_add_filter:
1357 * @chooser: a #GtkFileChooser
1358 * @filter: a #GtkFileFilter
1360 * Adds @filter to the list of filters that the user can select between.
1361 * When a filter is selected, only files that are passed by that
1362 * filter are displayed.
1367 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1368 GtkFileFilter *filter)
1370 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1372 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1376 * gtk_file_chooser_remove_filter:
1377 * @chooser: a #GtkFileChooser
1378 * @filter: a #GtkFileFilter
1380 * Removes @filter from the list of filters that the user can select between.
1385 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1386 GtkFileFilter *filter)
1388 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1390 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1394 * gtk_file_chooser_list_filters:
1395 * @chooser: a #GtkFileChooser
1397 * Lists the current set of user-selectable filters; see
1398 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1400 * Return value: a #GSList containing the current set of
1401 * user selectable filters. The contents of the list are
1402 * owned by GTK+, but you must free the list itself with
1403 * g_slist_free() when you are done with it.
1408 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1410 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1412 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1416 * gtk_file_chooser_set_filter:
1417 * @chooser: a #GtkFileChooser
1418 * @filter: a #GtkFileFilter
1420 * Sets the current filter; only the files that pass the
1421 * filter will be displayed. If the user-selectable list of filters
1422 * is non-empty, then the filter should be one of the filters
1423 * in that list. Setting the current filter when the list of
1424 * filters is empty is useful if you want to restrict the displayed
1425 * set of files without letting the user change it.
1430 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1431 GtkFileFilter *filter)
1433 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1434 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1436 g_object_set (chooser, "filter", filter, NULL);
1440 * gtk_file_chooser_get_filter:
1441 * @chooser: a #GtkFileChooser
1443 * Gets the current filter; see gtk_file_chooser_set_filter().
1445 * Return value: the current filter, or %NULL
1450 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1452 GtkFileFilter *filter;
1454 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1456 g_object_get (chooser, "filter", &filter, NULL);
1457 /* Horrid hack; g_object_get() refs returned objects but
1458 * that contradicts the memory management conventions
1462 g_object_unref (filter);
1468 * gtk_file_chooser_add_shortcut_folder:
1469 * @chooser: a #GtkFileChooser
1470 * @folder: filename of the folder to add
1471 * @error: location to store error, or %NULL
1473 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1474 * Note that shortcut folders do not get saved, as they are provided by the
1475 * application. For example, you can use this to add a
1476 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1478 * Return value: %TRUE if the folder could be added successfully, %FALSE
1479 * otherwise. In the latter case, the @error will be set as appropriate.
1484 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1491 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1492 g_return_val_if_fail (folder != NULL, FALSE);
1494 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1498 GTK_FILE_CHOOSER_ERROR,
1499 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1500 _("Invalid filename: %s"),
1505 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1507 gtk_file_path_free (path);
1513 * gtk_file_chooser_remove_shortcut_folder:
1514 * @chooser: a #GtkFileChooser
1515 * @folder: filename of the folder to remove
1516 * @error: location to store error, or %NULL
1518 * Removes a folder from a file chooser's list of shortcut folders.
1520 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1521 * In the latter case, the @error will be set as appropriate.
1523 * See also: gtk_file_chooser_add_shortcut_folder()
1528 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1535 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1536 g_return_val_if_fail (folder != NULL, FALSE);
1538 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1542 GTK_FILE_CHOOSER_ERROR,
1543 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1544 _("Invalid filename: %s"),
1549 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1551 gtk_file_path_free (path);
1557 * gtk_file_chooser_list_shortcut_folders:
1558 * @chooser: a #GtkFileChooser
1560 * Queries the list of shortcut folders in the file chooser, as set by
1561 * gtk_file_chooser_set_shortcut_folders().
1563 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1564 * folders. Free the returned list with g_slist_free(), and the filenames with
1570 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1575 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1577 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1579 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1581 gtk_file_system_path_to_filename);
1582 gtk_file_paths_free (folders);
1587 * gtk_file_chooser_add_shortcut_folder_uri:
1588 * @chooser: a #GtkFileChooser
1589 * @uri: URI of the folder to add
1590 * @error: location to store error, or %NULL
1592 * Adds a folder URI to be displayed with the shortcut folders in a file
1593 * chooser. Note that shortcut folders do not get saved, as they are provided
1594 * by the application. For example, you can use this to add a
1595 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1597 * Return value: %TRUE if the folder could be added successfully, %FALSE
1598 * otherwise. In the latter case, the @error will be set as appropriate.
1603 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1610 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1611 g_return_val_if_fail (uri != NULL, FALSE);
1613 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1617 GTK_FILE_CHOOSER_ERROR,
1618 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1619 _("Invalid filename: %s"),
1624 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1626 gtk_file_path_free (path);
1632 * gtk_file_chooser_remove_shortcut_folder_uri:
1633 * @chooser: a #GtkFileChooser
1634 * @uri: URI of the folder to remove
1635 * @error: location to store error, or %NULL
1637 * Removes a folder URI from a file chooser's list of shortcut folders.
1639 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1640 * In the latter case, the @error will be set as appropriate.
1642 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1647 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1654 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1655 g_return_val_if_fail (uri != NULL, FALSE);
1657 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1661 GTK_FILE_CHOOSER_ERROR,
1662 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1663 _("Invalid filename: %s"),
1668 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1670 gtk_file_path_free (path);
1676 * gtk_file_chooser_list_shortcut_folder_uris:
1677 * @chooser: a #GtkFileChooser
1679 * Queries the list of shortcut folders in the file chooser, as set by
1680 * gtk_file_chooser_set_shortcut_folder_uris().
1682 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1683 * folders. Free the returned list with g_slist_free(), and the URIs with
1689 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1694 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1696 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1698 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1700 gtk_file_system_path_to_uri);
1701 gtk_file_paths_free (folders);