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.
22 #include "gtkfilechooser.h"
23 #include "gtkfilechooserprivate.h"
24 #include "gtkfilesystem.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkprivate.h"
28 #include "gtkmarshalers.h"
31 static void gtk_file_chooser_class_init (gpointer g_iface);
33 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
36 gtk_file_chooser_get_type (void)
38 static GType file_chooser_type = 0;
40 if (!file_chooser_type)
42 file_chooser_type = g_type_register_static_simple (G_TYPE_INTERFACE,
44 sizeof (GtkFileChooserIface),
45 gtk_file_chooser_class_init,
48 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
51 return file_chooser_type;
55 confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
57 const GValue *handler_return,
60 gboolean continue_emission;
61 GtkFileChooserConfirmation conf;
63 conf = g_value_get_enum (handler_return);
64 g_value_set_enum (return_accu, conf);
65 continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
67 return continue_emission;
71 gtk_file_chooser_class_init (gpointer g_iface)
73 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
76 * GtkFileChooser::current-folder-changed
77 * @chooser: the object which received the signal.
79 * This signal is emitted when the current folder in a #GtkFileChooser
80 * changes. This can happen due to the user performing some action that
81 * changes folders, such as selecting a bookmark or visiting a folder on the
82 * file list. It can also happen as a result of calling a function to
83 * explicitly change the current folder in a file chooser.
85 * Normally you do not need to connect to this signal, unless you need to keep
86 * track of which folder a file chooser is showing.
88 * See also: gtk_file_chooser_set_current_folder(),
89 * gtk_file_chooser_get_current_folder(),
90 * gtk_file_chooser_set_current_folder_uri(),
91 * gtk_file_chooser_get_current_folder_uri().
93 g_signal_new (I_("current-folder-changed"),
96 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
98 g_cclosure_marshal_VOID__VOID,
102 * GtkFileChooser::selection-changed
103 * @chooser: the object which received the signal.
105 * This signal is emitted when there is a change in the set of selected files
106 * in a #GtkFileChooser. This can happen when the user modifies the selection
107 * with the mouse or the keyboard, or when explicitly calling functions to
108 * change the selection.
110 * Normally you do not need to connect to this signal, as it is easier to wait
111 * for the file chooser to finish running, and then to get the list of
112 * selected files using the functions mentioned below.
114 * See also: gtk_file_chooser_select_filename(),
115 * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
116 * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
117 * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
118 * gtk_file_chooser_get_uris().
120 g_signal_new (I_("selection-changed"),
123 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
125 g_cclosure_marshal_VOID__VOID,
129 * GtkFileChooser::update-preview
130 * @chooser: the object which received the signal.
132 * This signal is emitted when the preview in a file chooser should be
133 * regenerated. For example, this can happen when the currently selected file
134 * changes. You should use this signal if you want your file chooser to have
137 * Once you have installed a preview widget with
138 * gtk_file_chooser_set_preview_widget(), you should update it when this
139 * signal is emitted. You can use the functions
140 * gtk_file_chooser_get_preview_filename() or
141 * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
142 * Your widget may not be able to preview all kinds of files; your callback
143 * must call gtk_file_chooser_set_preview_wiget_active() to inform the file
144 * chooser about whether the preview was generated successfully or not.
146 * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
148 * See also: gtk_file_chooser_set_preview_widget(),
149 * gtk_file_chooser_set_preview_widget_active(),
150 * gtk_file_chooser_set_use_preview_label(),
151 * gtk_file_chooser_get_preview_filename(),
152 * gtk_file_chooser_get_preview_uri().
154 g_signal_new (I_("update-preview"),
157 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
159 g_cclosure_marshal_VOID__VOID,
163 * GtkFileChooser::file-activated
164 * @chooser: the object which received the signal.
166 * This signal is emitted when the user "activates" a file in the file
167 * chooser. This can happen by double-clicking on a file in the file list, or
168 * by pressing <keycap>Enter</keycap>.
170 * Normally you do not need to connect to this signal. It is used internally
171 * by #GtkFileChooserDialog to know when to activate the default button in the
174 * See also: gtk_file_chooser_get_filename(),
175 * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
176 * gtk_file_chooser_get_uris().
178 g_signal_new (I_("file-activated"),
181 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
183 g_cclosure_marshal_VOID__VOID,
186 /* Documented in the docbook files */
187 g_signal_new (I_("confirm-overwrite"),
190 G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
191 confirm_overwrite_accumulator, NULL,
192 _gtk_marshal_ENUM__VOID,
193 GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
195 g_object_interface_install_property (g_iface,
196 g_param_spec_enum ("action",
198 P_("The type of operation that the file selector is performing"),
199 GTK_TYPE_FILE_CHOOSER_ACTION,
200 GTK_FILE_CHOOSER_ACTION_OPEN,
201 GTK_PARAM_READWRITE));
202 g_object_interface_install_property (g_iface,
203 g_param_spec_string ("file-system-backend",
204 P_("File System Backend"),
205 P_("Name of file system backend to use"),
207 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
208 g_object_interface_install_property (g_iface,
209 g_param_spec_object ("filter",
211 P_("The current filter for selecting which files are displayed"),
212 GTK_TYPE_FILE_FILTER,
213 GTK_PARAM_READWRITE));
214 g_object_interface_install_property (g_iface,
215 g_param_spec_boolean ("local-only",
217 P_("Whether the selected file(s) should be limited to local file: URLs"),
219 GTK_PARAM_READWRITE));
220 g_object_interface_install_property (g_iface,
221 g_param_spec_object ("preview-widget",
222 P_("Preview widget"),
223 P_("Application supplied widget for custom previews."),
225 GTK_PARAM_READWRITE));
226 g_object_interface_install_property (g_iface,
227 g_param_spec_boolean ("preview-widget-active",
228 P_("Preview Widget Active"),
229 P_("Whether the application supplied widget for custom previews should be shown."),
231 GTK_PARAM_READWRITE));
232 g_object_interface_install_property (g_iface,
233 g_param_spec_boolean ("use-preview-label",
234 P_("Use Preview Label"),
235 P_("Whether to display a stock label with the name of the previewed file."),
237 GTK_PARAM_READWRITE));
238 g_object_interface_install_property (g_iface,
239 g_param_spec_object ("extra-widget",
241 P_("Application supplied widget for extra options."),
243 GTK_PARAM_READWRITE));
244 g_object_interface_install_property (g_iface,
245 g_param_spec_boolean ("select-multiple",
246 P_("Select Multiple"),
247 P_("Whether to allow multiple files to be selected"),
249 GTK_PARAM_READWRITE));
251 g_object_interface_install_property (g_iface,
252 g_param_spec_boolean ("show-hidden",
254 P_("Whether the hidden files and folders should be displayed"),
256 GTK_PARAM_READWRITE));
259 * GtkFileChooser:do-overwrite-confirmation:
261 * Whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode
262 * will present an overwrite confirmation dialog if the user
263 * selects a file name that already exists.
267 g_object_interface_install_property (g_iface,
268 g_param_spec_boolean ("do-overwrite-confirmation",
269 P_("Do overwrite confirmation"),
270 P_("Whether a file chooser in save mode "
271 "will present an overwrite confirmation dialog "
274 GTK_PARAM_READWRITE));
278 * gtk_file_chooser_error_quark:
280 * Registers an error quark for #GtkFileChooser if necessary.
282 * Return value: The error quark used for #GtkFileChooser errors.
287 gtk_file_chooser_error_quark (void)
289 return g_quark_from_static_string ("gtk-file-chooser-error-quark");
293 * gtk_file_chooser_set_action:
294 * @chooser: a #GtkFileChooser
295 * @action: the action that the file selector is performing
297 * Sets the type of operation that the chooser is performing; the
298 * user interface is adapted to suit the selected action. For example,
299 * an option to create a new folder might be shown if the action is
300 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
301 * %GTK_FILE_CHOOSER_ACTION_OPEN.
306 gtk_file_chooser_set_action (GtkFileChooser *chooser,
307 GtkFileChooserAction action)
309 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
311 g_object_set (chooser, "action", action, NULL);
315 * gtk_file_chooser_get_action:
316 * @chooser: a #GtkFileChooser
318 * Gets the type of operation that the file chooser is performing; see
319 * gtk_file_chooser_set_action().
321 * Return value: the action that the file selector is performing
326 gtk_file_chooser_get_action (GtkFileChooser *chooser)
328 GtkFileChooserAction action;
330 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
332 g_object_get (chooser, "action", &action, NULL);
338 * gtk_file_chooser_set_local_only:
339 * @chooser: a #GtkFileChooser
340 * @local_only: %TRUE if only local files can be selected
342 * Sets whether only local files can be selected in the
343 * file selector. If @local_only is %TRUE (the default),
344 * then the selected file are files are guaranteed to be
345 * accessible through the operating systems native file
346 * file system and therefore the application only
347 * needs to worry about the filename functions in
348 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
349 * rather than the URI functions like
350 * gtk_file_chooser_get_uri(),
355 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
358 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
360 g_object_set (chooser, "local-only", local_only, NULL);
364 * gtk_file_chooser_get_local_only:
365 * @chooser: a #GtkFileChoosre
367 * Gets whether only local files can be selected in the
368 * file selector. See gtk_file_chooser_set_local_only()
370 * Return value: %TRUE if only local files can be selected.
375 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
379 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
381 g_object_get (chooser, "local-only", &local_only, NULL);
387 * gtk_file_chooser_set_select_multiple:
388 * @chooser: a #GtkFileChooser
389 * @select_multiple: %TRUE if multiple files can be selected.
391 * Sets whether multiple files can be selected in the file selector. This is
392 * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
393 * GTK_FILE_CHOOSER_ACTION_SAVE. It cannot be set with either of the folder
399 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
400 gboolean select_multiple)
402 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
404 g_object_set (chooser, "select-multiple", select_multiple, NULL);
408 * gtk_file_chooser_get_select_multiple:
409 * @chooser: a #GtkFileChooser
411 * Gets whether multiple files can be selected in the file
412 * selector. See gtk_file_chooser_set_select_multiple().
414 * Return value: %TRUE if multiple files can be selected.
419 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
421 gboolean select_multiple;
423 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
425 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
427 return select_multiple;
431 * gtk_file_chooser_get_filename:
432 * @chooser: a #GtkFileChooser
434 * Gets the filename for the currently selected file in
435 * the file selector. If multiple files are selected,
436 * one of the filenames will be returned at random.
438 * If the file chooser is in folder mode, this function returns the selected
441 * Return value: The currently selected filename, or %NULL
442 * if no file is selected, or the selected file can't
443 * be represented with a local filename. Free with g_free().
448 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
450 GtkFileSystem *file_system;
452 gchar *result = NULL;
454 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
456 file_system = _gtk_file_chooser_get_file_system (chooser);
457 path = gtk_file_chooser_get_path (chooser);
460 result = gtk_file_system_path_to_filename (file_system, path);
461 gtk_file_path_free (path);
468 * gtk_file_chooser_set_filename:
469 * @chooser: a #GtkFileChooser
470 * @filename: the filename to set as current
472 * Sets @filename as the current filename for the file chooser, by changing
473 * to the file's parent folder and actually selecting the file in list. If
474 * the @chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
475 * will also appear in the dialog's file name entry.
477 * If the file name isn't in the current folder of @chooser, then the current
478 * folder of @chooser will be changed to the folder containing @filename. This
479 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
480 * gtk_file_chooser_select_filename().
482 * Note that the file must exist, or nothing will be done except
483 * for the directory change.
485 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog, you
486 * should use this function if you already have a file name to which the user may save; for example,
487 * when the user opens an existing file and then does <guimenuitem>File/Save As...</guimenuitem>
488 * on it. If you don't have a file name already — for example, if the user just created
489 * a new file and is saving it for the first time, do not call this function. Instead, use
490 * something similar to this:
493 * if (document_is_new)
495 * /<!-- -->* the user just created a new document *<!-- -->/
496 * gtk_file_chooser_set_current_folder (chooser, default_folder_for_saving);
497 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
501 * /<!-- -->* the user edited an existing document *<!-- -->/
502 * gtk_file_chooser_set_filename (chooser, existing_filename);
506 * Return value: %TRUE if both the folder could be changed and the file was
507 * selected successfully, %FALSE otherwise.
512 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
513 const gchar *filename)
515 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
517 gtk_file_chooser_unselect_all (chooser);
518 return gtk_file_chooser_select_filename (chooser, filename);
522 * gtk_file_chooser_select_filename:
523 * @chooser: a #GtkFileChooser
524 * @filename: the filename to select
526 * Selects a filename. If the file name isn't in the current
527 * folder of @chooser, then the current folder of @chooser will
528 * be changed to the folder containing @filename.
530 * Return value: %TRUE if both the folder could be changed and the file was
531 * selected successfully, %FALSE otherwise.
536 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
537 const gchar *filename)
539 GtkFileSystem *file_system;
543 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
544 g_return_val_if_fail (filename != NULL, FALSE);
546 file_system = _gtk_file_chooser_get_file_system (chooser);
548 path = gtk_file_system_filename_to_path (file_system, filename);
551 result = _gtk_file_chooser_select_path (chooser, path, NULL);
552 gtk_file_path_free (path);
561 * gtk_file_chooser_unselect_filename:
562 * @chooser: a #GtkFileChooser
563 * @filename: the filename to unselect
565 * Unselects a currently selected filename. If the filename
566 * is not in the current directory, does not exist, or
567 * is otherwise not currently selected, does nothing.
572 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
573 const char *filename)
575 GtkFileSystem *file_system;
578 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
579 g_return_if_fail (filename != NULL);
581 file_system = _gtk_file_chooser_get_file_system (chooser);
583 path = gtk_file_system_filename_to_path (file_system, filename);
586 _gtk_file_chooser_unselect_path (chooser, path);
587 gtk_file_path_free (path);
591 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
593 file_paths_to_strings (GtkFileSystem *fs,
595 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
601 for (; paths; paths = paths->next)
607 string = (* convert_func) (fs, path);
610 strings = g_slist_prepend (strings, string);
613 return g_slist_reverse (strings);
617 * gtk_file_chooser_get_filenames:
618 * @chooser: a #GtkFileChooser
620 * Lists all the selected files and subfolders in the current folder of
621 * @chooser. The returned names are full absolute paths. If files in the current
622 * folder cannot be represented as local filenames they will be ignored. (See
623 * gtk_file_chooser_get_uris())
625 * Return value: a #GSList containing the filenames of all selected
626 * files and subfolders in the current folder. Free the returned list
627 * with g_slist_free(), and the filenames with g_free().
632 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
634 GtkFileSystem *file_system;
638 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
640 file_system = _gtk_file_chooser_get_file_system (chooser);
641 paths = _gtk_file_chooser_get_paths (chooser);
643 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
644 gtk_file_paths_free (paths);
649 * gtk_file_chooser_set_current_folder:
650 * @chooser: a #GtkFileChooser
651 * @filename: the full path of the new current folder
653 * Sets the current folder for @chooser from a local filename.
654 * The user will be shown the full contents of the current folder,
655 * plus user interface elements for navigating to other folders.
657 * Return value: %TRUE if the folder could be changed successfully, %FALSE
663 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
664 const gchar *filename)
666 GtkFileSystem *file_system;
670 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
671 g_return_val_if_fail (filename != NULL, FALSE);
673 file_system = _gtk_file_chooser_get_file_system (chooser);
675 path = gtk_file_system_filename_to_path (file_system, filename);
678 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
679 gtk_file_path_free (path);
688 * gtk_file_chooser_get_current_folder:
689 * @chooser: a #GtkFileChooser
691 * Gets the current folder of @chooser as a local filename.
692 * See gtk_file_chooser_set_current_folder().
694 * Note that this is the folder that the file chooser is currently displaying
695 * (e.g. "/home/username/Documents"), which is <emphasis>not the same</emphasis>
696 * as the currently-selected folder if the chooser is in
697 * #GTK_FILE_CHOOSER_SELECT_FOLDER mode
698 * (e.g. "/home/username/Documents/selected-folder/". To get the
699 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
700 * usual way to get the selection.
702 * Return value: the full path of the current folder, or %NULL if the current
703 * path cannot be represented as a local filename. Free with g_free(). This
704 * function will also return %NULL if the file chooser was unable to load the
705 * last folder that was requested from it; for example, as would be for calling
706 * gtk_file_chooser_set_current_folder() on a nonexistent folder.
711 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
713 GtkFileSystem *file_system;
717 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
719 file_system = _gtk_file_chooser_get_file_system (chooser);
721 path = _gtk_file_chooser_get_current_folder_path (chooser);
725 filename = gtk_file_system_path_to_filename (file_system, path);
726 gtk_file_path_free (path);
732 * gtk_file_chooser_set_current_name:
733 * @chooser: a #GtkFileChooser
734 * @name: the filename to use, as a UTF-8 string
736 * Sets the current name in the file selector, as if entered
737 * by the user. Note that the name passed in here is a UTF-8
738 * string rather than a filename. This function is meant for
739 * such uses as a suggested name in a "Save As..." dialog.
741 * If you want to preselect a particular existing file, you should use
742 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
743 * Please see the documentation for those functions for an example of using
744 * gtk_file_chooser_set_current_name() as well.
749 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
752 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
753 g_return_if_fail (name != NULL);
755 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
759 * gtk_file_chooser_get_uri:
760 * @chooser: a #GtkFileChooser
762 * Gets the URI for the currently selected file in
763 * the file selector. If multiple files are selected,
764 * one of the filenames will be returned at random.
766 * If the file chooser is in folder mode, this function returns the selected
769 * Return value: The currently selected URI, or %NULL
770 * if no file is selected. Free with g_free()
775 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
777 GtkFileSystem *file_system;
779 gchar *result = NULL;
781 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
783 file_system = _gtk_file_chooser_get_file_system (chooser);
784 path = gtk_file_chooser_get_path (chooser);
787 result = gtk_file_system_path_to_uri (file_system, path);
788 gtk_file_path_free (path);
795 * gtk_file_chooser_set_uri:
796 * @chooser: a #GtkFileChooser
797 * @uri: the URI to set as current
799 * Sets the file referred to by @uri as the current file for the file chooser,
800 * by changing to the URI's parent folder and actually selecting the URI in the
801 * list. If the @chooser is #GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
802 * name will also appear in the dialog's file name entry.
804 * If the URI isn't in the current folder of @chooser, then the current folder
805 * of @chooser will be changed to the folder containing @uri. This is equivalent
806 * to a sequence of gtk_file_chooser_unselect_all() followed by
807 * gtk_file_chooser_select_uri().
809 * Note that the URI must exist, or nothing will be done except
810 * for the directory change.
811 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog, you
812 * should use this function if you already have a file name to which the user may save; for example,
813 * when the user opens an existing file and then does <guimenuitem>File/Save As...</guimenuitem>
814 * on it. If you don't have a file name already — for example, if the user just created
815 * a new file and is saving it for the first time, do not call this function. Instead, use
816 * something similar to this:
819 * if (document_is_new)
821 * /<!-- -->* the user just created a new document *<!-- -->/
822 * gtk_file_chooser_set_current_folder_uri (chooser, default_folder_for_saving);
823 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
827 * /<!-- -->* the user edited an existing document *<!-- -->/
828 * gtk_file_chooser_set_uri (chooser, existing_uri);
832 * Return value: %TRUE if both the folder could be changed and the URI was
833 * selected successfully, %FALSE otherwise.
838 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
841 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
843 gtk_file_chooser_unselect_all (chooser);
844 return gtk_file_chooser_select_uri (chooser, uri);
848 * gtk_file_chooser_select_uri:
849 * @chooser: a #GtkFileChooser
850 * @uri: the URI to select
852 * Selects the file to by @uri. If the URI doesn't refer to a
853 * file in the current folder of @chooser, then the current folder of
854 * @chooser will be changed to the folder containing @filename.
856 * Return value: %TRUE if both the folder could be changed and the URI was
857 * selected successfully, %FALSE otherwise.
862 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
865 GtkFileSystem *file_system;
869 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
870 g_return_val_if_fail (uri != NULL, FALSE);
872 file_system = _gtk_file_chooser_get_file_system (chooser);
874 path = gtk_file_system_uri_to_path (file_system, uri);
877 result = _gtk_file_chooser_select_path (chooser, path, NULL);
878 gtk_file_path_free (path);
887 * gtk_file_chooser_unselect_uri:
888 * @chooser: a #GtkFileChooser
889 * @uri: the URI to unselect
891 * Unselects the file referred to by @uri. If the file
892 * is not in the current directory, does not exist, or
893 * is otherwise not currently selected, does nothing.
898 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
901 GtkFileSystem *file_system;
904 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
905 g_return_if_fail (uri != NULL);
907 file_system = _gtk_file_chooser_get_file_system (chooser);
909 path = gtk_file_system_uri_to_path (file_system, uri);
912 _gtk_file_chooser_unselect_path (chooser, path);
913 gtk_file_path_free (path);
918 * gtk_file_chooser_select_all:
919 * @chooser: a #GtkFileChooser
921 * Selects all the files in the current folder of a file chooser.
926 gtk_file_chooser_select_all (GtkFileChooser *chooser)
928 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
930 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
934 * gtk_file_chooser_unselect_all:
935 * @chooser: a #GtkFileChooser
937 * Unselects all the files in the current folder of a file chooser.
942 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
945 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
947 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
951 * gtk_file_chooser_get_uris:
952 * @chooser: a #GtkFileChooser
954 * Lists all the selected files and subfolders in the current folder of
955 * @chooser. The returned names are full absolute URIs.
957 * Return value: a #GSList containing the URIs of all selected
958 * files and subfolders in the current folder. Free the returned list
959 * with g_slist_free(), and the filenames with g_free().
964 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
966 GtkFileSystem *file_system;
970 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
972 file_system = _gtk_file_chooser_get_file_system (chooser);
973 paths = _gtk_file_chooser_get_paths (chooser);
975 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
976 gtk_file_paths_free (paths);
981 * gtk_file_chooser_set_current_folder_uri:
982 * @chooser: a #GtkFileChooser
983 * @uri: the URI for the new current folder
985 * Sets the current folder for @chooser from an URI.
986 * The user will be shown the full contents of the current folder,
987 * plus user interface elements for navigating to other folders.
989 * Return value: %TRUE if the folder could be changed successfully, %FALSE
995 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
998 GtkFileSystem *file_system;
1002 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1003 g_return_val_if_fail (uri != NULL, FALSE);
1005 file_system = _gtk_file_chooser_get_file_system (chooser);
1007 path = gtk_file_system_uri_to_path (file_system, uri);
1010 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
1011 gtk_file_path_free (path);
1020 * gtk_file_chooser_get_current_folder_uri:
1021 * @chooser: a #GtkFileChooser
1023 * Gets the current folder of @chooser as an URI.
1024 * See gtk_file_chooser_set_current_folder_uri().
1026 * Note that this is the folder that the file chooser is currently displaying
1027 * (e.g. "file:///home/username/Documents"), which is <emphasis>not the same</emphasis>
1028 * as the currently-selected folder if the chooser is in
1029 * #GTK_FILE_CHOOSER_SELECT_FOLDER mode
1030 * (e.g. "file:///home/username/Documents/selected-folder/". To get the
1031 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
1032 * usual way to get the selection.
1034 * Return value: the URI for the current folder. Free with g_free(). This
1035 * function will also return %NULL if the file chooser was unable to load the
1036 * last folder that was requested from it; for example, as would be for calling
1037 * gtk_file_chooser_set_current_folder_uri() on a nonexistent folder.
1042 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
1044 GtkFileSystem *file_system;
1048 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1050 file_system = _gtk_file_chooser_get_file_system (chooser);
1052 path = _gtk_file_chooser_get_current_folder_path (chooser);
1053 uri = gtk_file_system_path_to_uri (file_system, path);
1054 gtk_file_path_free (path);
1060 * _gtk_file_chooser_set_current_folder_path:
1061 * @chooser: a #GtkFileChooser
1062 * @path: the #GtkFilePath for the new folder
1063 * @error: location to store error, or %NULL.
1065 * Sets the current folder for @chooser from a #GtkFilePath.
1066 * Internal function, see gtk_file_chooser_set_current_folder_uri().
1068 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1074 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
1075 const GtkFilePath *path,
1078 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1079 g_return_val_if_fail (path != NULL, FALSE);
1080 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1082 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path, error);
1086 * _gtk_file_chooser_get_current_folder_path:
1087 * @chooser: a #GtkFileChooser
1089 * Gets the current folder of @chooser as #GtkFilePath.
1090 * See gtk_file_chooser_get_current_folder_uri().
1092 * Return value: the #GtkFilePath for the current folder.
1093 * Free with gtk_file_path_free().
1098 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
1100 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1102 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1106 * _gtk_file_chooser_select_path:
1107 * @chooser: a #GtkFileChooser
1108 * @path: the path to select
1109 * @error: location to store error, or %NULL
1111 * Selects the file referred to by @path. An internal function. See
1112 * _gtk_file_chooser_select_uri().
1114 * Return value: %TRUE if both the folder could be changed and the path was
1115 * selected successfully, %FALSE otherwise.
1120 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
1121 const GtkFilePath *path,
1124 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1125 g_return_val_if_fail (path != NULL, FALSE);
1126 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1128 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path, error);
1132 * _gtk_file_chooser_unselect_path:
1133 * @chooser: a #GtkFileChooser
1134 * @path: the filename to path
1136 * Unselects the file referred to by @path. An internal
1137 * function. See _gtk_file_chooser_unselect_uri().
1142 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
1143 const GtkFilePath *path)
1145 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1147 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
1151 * _gtk_file_chooser_get_paths:
1152 * @chooser: a #GtkFileChooser
1154 * Lists all the selected files and subfolders in the current folder of @chooser
1155 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
1157 * Return value: a #GSList containing a #GtkFilePath for each selected
1158 * file and subfolder in the current folder. Free the returned list
1159 * with g_slist_free(), and the paths with gtk_file_path_free().
1164 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
1166 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1168 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
1171 static GtkFilePath *
1172 gtk_file_chooser_get_path (GtkFileChooser *chooser)
1175 GtkFilePath *result = NULL;
1177 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1179 list = _gtk_file_chooser_get_paths (chooser);
1182 result = list->data;
1183 list = g_slist_delete_link (list, list);
1184 gtk_file_paths_free (list);
1191 * _gtk_file_chooser_get_file_system:
1192 * @chooser: a #GtkFileChooser
1194 * Gets the #GtkFileSystem of @chooser; this is an internal
1195 * implementation detail, used for conversion between paths
1196 * and filenames and URIs.
1198 * Return value: the file system for @chooser.
1203 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1205 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1207 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1213 * gtk_file_chooser_set_preview_widget:
1214 * @chooser: a #GtkFileChooser
1215 * @preview_widget: widget for displaying preview.
1217 * Sets an application-supplied widget to use to display a custom preview
1218 * of the currently selected file. To implement a preview, after setting the
1219 * preview widget, you connect to the ::update-preview
1220 * signal, and call gtk_file_chooser_get_preview_filename() or
1221 * gtk_file_chooser_get_preview_uri() on each change. If you can
1222 * display a preview of the new file, update your widget and
1223 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1224 * Otherwise, set the preview inactive.
1226 * When there is no application-supplied preview widget, or the
1227 * application-supplied preview widget is not active, the file chooser
1228 * may display an internally generated preview of the current file or
1229 * it may display no preview at all.
1234 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1235 GtkWidget *preview_widget)
1237 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1239 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1243 * gtk_file_chooser_get_preview_widget:
1244 * @chooser: a #GtkFileChooser
1246 * Gets the current preview widget; see
1247 * gtk_file_chooser_set_preview_widget().
1249 * Return value: the current preview widget, or %NULL
1254 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1256 GtkWidget *preview_widget;
1258 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1260 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1262 /* Horrid hack; g_object_get() refs returned objects but
1263 * that contradicts the memory management conventions
1267 g_object_unref (preview_widget);
1269 return preview_widget;
1273 * gtk_file_chooser_set_preview_widget_active:
1274 * @chooser: a #GtkFileChooser
1275 * @active: whether to display the user-specified preview widget
1277 * Sets whether the preview widget set by
1278 * gtk_file_chooser_set_preview_widget() should be shown for the
1279 * current filename. When @active is set to false, the file chooser
1280 * may display an internally generated preview of the current file
1281 * or it may display no preview at all. See
1282 * gtk_file_chooser_set_preview_widget() for more details.
1287 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1290 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1292 g_object_set (chooser, "preview-widget-active", active, NULL);
1296 * gtk_file_chooser_get_preview_widget_active:
1297 * @chooser: a #GtkFileChooser
1299 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1300 * should be shown for the current filename. See
1301 * gtk_file_chooser_set_preview_widget_active().
1303 * Return value: %TRUE if the preview widget is active for the current filename.
1308 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1312 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1314 g_object_get (chooser, "preview-widget-active", &active, NULL);
1320 * gtk_file_chooser_set_use_preview_label:
1321 * @chooser: a #GtkFileChooser
1322 * @use_label: whether to display a stock label with the name of the previewed file
1324 * Sets whether the file chooser should display a stock label with the name of
1325 * the file that is being previewed; the default is %TRUE. Applications that
1326 * want to draw the whole preview area themselves should set this to %FALSE and
1327 * display the name themselves in their preview widget.
1329 * See also: gtk_file_chooser_set_preview_widget()
1334 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1337 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1339 g_object_set (chooser, "use-preview-label", use_label, NULL);
1343 * gtk_file_chooser_get_use_preview_label:
1344 * @chooser: a #GtkFileChooser
1346 * Gets whether a stock label should be drawn with the name of the previewed
1347 * file. See gtk_file_chooser_set_use_preview_label().
1349 * Return value: %TRUE if the file chooser is set to display a label with the
1350 * name of the previewed file, %FALSE otherwise.
1353 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1357 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1359 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1365 * gtk_file_chooser_get_preview_filename:
1366 * @chooser: a #GtkFileChooser
1368 * Gets the filename that should be previewed in a custom preview
1369 * Internal function, see gtk_file_chooser_get_preview_uri().
1371 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1372 * is selected. Free with gtk_file_path_free().
1377 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1379 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1381 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1385 * _gtk_file_chooser_add_shortcut_folder:
1386 * @chooser: a #GtkFileChooser
1387 * @path: path of the folder to add
1388 * @error: location to store error, or %NULL
1390 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1391 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1393 * Return value: %TRUE if the folder could be added successfully, %FALSE
1399 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1400 const GtkFilePath *path,
1403 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1404 g_return_val_if_fail (path != NULL, FALSE);
1406 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1410 * _gtk_file_chooser_remove_shortcut_folder:
1411 * @chooser: a #GtkFileChooser
1412 * @path: path of the folder to remove
1413 * @error: location to store error, or %NULL
1415 * Removes a folder from the shortcut folders in a file chooser. Internal
1416 * function, see gtk_file_chooser_remove_shortcut_folder().
1418 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1424 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1425 const GtkFilePath *path,
1428 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1429 g_return_val_if_fail (path != NULL, FALSE);
1431 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1435 * gtk_file_chooser_get_preview_filename:
1436 * @chooser: a #GtkFileChooser
1438 * Gets the filename that should be previewed in a custom preview
1439 * widget. See gtk_file_chooser_set_preview_widget().
1441 * Return value: the filename to preview, or %NULL if no file
1442 * is selected, or if the selected file cannot be represented
1443 * as a local filename. Free with g_free()
1448 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1450 GtkFileSystem *file_system;
1452 gchar *result = NULL;
1454 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1456 file_system = _gtk_file_chooser_get_file_system (chooser);
1457 path = _gtk_file_chooser_get_preview_path (chooser);
1460 result = gtk_file_system_path_to_filename (file_system, path);
1461 gtk_file_path_free (path);
1468 * gtk_file_chooser_get_preview_uri:
1469 * @chooser: a #GtkFileChooser
1471 * Gets the URI that should be previewed in a custom preview
1472 * widget. See gtk_file_chooser_set_preview_widget().
1474 * Return value: the URI for the file to preview, or %NULL if no file is
1475 * selected. Free with g_free().
1480 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1482 GtkFileSystem *file_system;
1484 gchar *result = NULL;
1486 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1488 file_system = _gtk_file_chooser_get_file_system (chooser);
1489 path = _gtk_file_chooser_get_preview_path (chooser);
1492 result = gtk_file_system_path_to_uri (file_system, path);
1493 gtk_file_path_free (path);
1500 * gtk_file_chooser_set_extra_widget:
1501 * @chooser: a #GtkFileChooser
1502 * @extra_widget: widget for extra options
1504 * Sets an application-supplied widget to provide extra options to the user.
1509 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1510 GtkWidget *extra_widget)
1512 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1514 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1518 * gtk_file_chooser_get_extra_widget:
1519 * @chooser: a #GtkFileChooser
1521 * Gets the current preview widget; see
1522 * gtk_file_chooser_set_extra_widget().
1524 * Return value: the current extra widget, or %NULL
1529 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1531 GtkWidget *extra_widget;
1533 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1535 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1537 /* Horrid hack; g_object_get() refs returned objects but
1538 * that contradicts the memory management conventions
1542 g_object_unref (extra_widget);
1544 return extra_widget;
1548 * gtk_file_chooser_add_filter:
1549 * @chooser: a #GtkFileChooser
1550 * @filter: a #GtkFileFilter
1552 * Adds @filter to the list of filters that the user can select between.
1553 * When a filter is selected, only files that are passed by that
1554 * filter are displayed.
1556 * Note that the @chooser takes ownership of the filter, so you have to
1557 * ref and sink it if you want to keep a reference.
1562 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1563 GtkFileFilter *filter)
1565 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1567 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1571 * gtk_file_chooser_remove_filter:
1572 * @chooser: a #GtkFileChooser
1573 * @filter: a #GtkFileFilter
1575 * Removes @filter from the list of filters that the user can select between.
1580 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1581 GtkFileFilter *filter)
1583 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1585 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1589 * gtk_file_chooser_list_filters:
1590 * @chooser: a #GtkFileChooser
1592 * Lists the current set of user-selectable filters; see
1593 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1595 * Return value: a #GSList containing the current set of
1596 * user selectable filters. The contents of the list are
1597 * owned by GTK+, but you must free the list itself with
1598 * g_slist_free() when you are done with it.
1603 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1605 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1607 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1611 * gtk_file_chooser_set_filter:
1612 * @chooser: a #GtkFileChooser
1613 * @filter: a #GtkFileFilter
1615 * Sets the current filter; only the files that pass the
1616 * filter will be displayed. If the user-selectable list of filters
1617 * is non-empty, then the filter should be one of the filters
1618 * in that list. Setting the current filter when the list of
1619 * filters is empty is useful if you want to restrict the displayed
1620 * set of files without letting the user change it.
1625 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1626 GtkFileFilter *filter)
1628 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1629 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1631 g_object_set (chooser, "filter", filter, NULL);
1635 * gtk_file_chooser_get_filter:
1636 * @chooser: a #GtkFileChooser
1638 * Gets the current filter; see gtk_file_chooser_set_filter().
1640 * Return value: the current filter, or %NULL
1645 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1647 GtkFileFilter *filter;
1649 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1651 g_object_get (chooser, "filter", &filter, NULL);
1652 /* Horrid hack; g_object_get() refs returned objects but
1653 * that contradicts the memory management conventions
1657 g_object_unref (filter);
1663 * gtk_file_chooser_add_shortcut_folder:
1664 * @chooser: a #GtkFileChooser
1665 * @folder: filename of the folder to add
1666 * @error: location to store error, or %NULL
1668 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1669 * Note that shortcut folders do not get saved, as they are provided by the
1670 * application. For example, you can use this to add a
1671 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1673 * Return value: %TRUE if the folder could be added successfully, %FALSE
1674 * otherwise. In the latter case, the @error will be set as appropriate.
1679 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1686 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1687 g_return_val_if_fail (folder != NULL, FALSE);
1689 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1693 GTK_FILE_CHOOSER_ERROR,
1694 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1695 _("Invalid filename: %s"),
1700 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1702 gtk_file_path_free (path);
1708 * gtk_file_chooser_remove_shortcut_folder:
1709 * @chooser: a #GtkFileChooser
1710 * @folder: filename of the folder to remove
1711 * @error: location to store error, or %NULL
1713 * Removes a folder from a file chooser's list of shortcut folders.
1715 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1716 * In the latter case, the @error will be set as appropriate.
1718 * See also: gtk_file_chooser_add_shortcut_folder()
1723 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1730 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1731 g_return_val_if_fail (folder != NULL, FALSE);
1733 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1737 GTK_FILE_CHOOSER_ERROR,
1738 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1739 _("Invalid filename: %s"),
1744 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1746 gtk_file_path_free (path);
1752 * gtk_file_chooser_list_shortcut_folders:
1753 * @chooser: a #GtkFileChooser
1755 * Queries the list of shortcut folders in the file chooser, as set by
1756 * gtk_file_chooser_add_shortcut_folder().
1758 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1759 * folders. Free the returned list with g_slist_free(), and the filenames with
1765 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1770 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1772 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1774 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1776 gtk_file_system_path_to_filename);
1777 gtk_file_paths_free (folders);
1782 * gtk_file_chooser_add_shortcut_folder_uri:
1783 * @chooser: a #GtkFileChooser
1784 * @uri: URI of the folder to add
1785 * @error: location to store error, or %NULL
1787 * Adds a folder URI to be displayed with the shortcut folders in a file
1788 * chooser. Note that shortcut folders do not get saved, as they are provided
1789 * by the application. For example, you can use this to add a
1790 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1792 * Return value: %TRUE if the folder could be added successfully, %FALSE
1793 * otherwise. In the latter case, the @error will be set as appropriate.
1798 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1805 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1806 g_return_val_if_fail (uri != NULL, FALSE);
1808 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1812 GTK_FILE_CHOOSER_ERROR,
1813 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1814 _("Invalid filename: %s"),
1819 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1821 gtk_file_path_free (path);
1827 * gtk_file_chooser_remove_shortcut_folder_uri:
1828 * @chooser: a #GtkFileChooser
1829 * @uri: URI of the folder to remove
1830 * @error: location to store error, or %NULL
1832 * Removes a folder URI from a file chooser's list of shortcut folders.
1834 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1835 * In the latter case, the @error will be set as appropriate.
1837 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1842 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1849 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1850 g_return_val_if_fail (uri != NULL, FALSE);
1852 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1856 GTK_FILE_CHOOSER_ERROR,
1857 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1858 _("Invalid filename: %s"),
1863 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1865 gtk_file_path_free (path);
1871 * gtk_file_chooser_list_shortcut_folder_uris:
1872 * @chooser: a #GtkFileChooser
1874 * Queries the list of shortcut folders in the file chooser, as set by
1875 * gtk_file_chooser_add_shortcut_folder_uri().
1877 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1878 * folders. Free the returned list with g_slist_free(), and the URIs with
1884 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1889 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1891 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1893 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1895 gtk_file_system_path_to_uri);
1896 gtk_file_paths_free (folders);
1902 * gtk_file_chooser_set_show_hidden:
1903 * @chooser: a #GtkFileChooser
1904 * @show_hidden: %TRUE if hidden files and folders should be displayed.
1906 * Sets whether hidden files and folders are displayed in the file selector.
1911 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1912 gboolean show_hidden)
1914 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1916 g_object_set (chooser, "show-hidden", show_hidden, NULL);
1920 * gtk_file_chooser_get_show_hidden:
1921 * @chooser: a #GtkFileChooser
1923 * Gets whether hidden files and folders are displayed in the file selector.
1924 * See gtk_file_chooser_set_show_hidden().
1926 * Return value: %TRUE if hidden files and folders are displayed.
1931 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1933 gboolean show_hidden;
1935 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1937 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1943 * gtk_file_chooser_set_do_overwrite_confirmation:
1944 * @chooser: a #GtkFileChooser
1945 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1947 * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1948 * a confirmation dialog if the user types a file name that already exists. This
1949 * is %FALSE by default.
1951 * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1952 * signal when appropriate.
1954 * If all you need is the stock confirmation dialog, set this property to %TRUE.
1955 * You can override the way confirmation is done by actually handling the
1956 * "confirm-overwrite" signal; please refer to its documentation for the
1962 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
1963 gboolean do_overwrite_confirmation)
1965 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1967 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
1971 * gtk_file_chooser_get_do_overwrite_confirmation:
1972 * @chooser: a #GtkFileChooser
1974 * Queries whether a file chooser is set to confirm for overwriting when the user
1975 * types a file name that already exists.
1977 * Return value: %TRUE if the file chooser will present a confirmation dialog;
1983 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
1985 gboolean do_overwrite_confirmation;
1987 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1989 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
1991 return do_overwrite_confirmation;
1996 /* DLL ABI stability backward compatibility versions */
1998 #undef gtk_file_chooser_get_filename
2001 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
2003 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
2004 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2006 g_free (utf8_filename);
2011 #undef gtk_file_chooser_set_filename
2014 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
2015 const gchar *filename)
2017 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2018 gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
2020 g_free (utf8_filename);
2025 #undef gtk_file_chooser_select_filename
2028 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2029 const gchar *filename)
2031 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2032 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2034 g_free (utf8_filename);
2039 #undef gtk_file_chooser_unselect_filename
2042 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2043 const char *filename)
2045 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2047 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2048 g_free (utf8_filename);
2051 #undef gtk_file_chooser_get_filenames
2054 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2056 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2057 GSList *rover = list;
2061 gchar *tem = (gchar *) rover->data;
2062 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2064 rover = rover->next;
2070 #undef gtk_file_chooser_set_current_folder
2073 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2074 const gchar *filename)
2076 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2077 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2079 g_free (utf8_filename);
2084 #undef gtk_file_chooser_get_current_folder
2087 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2089 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2090 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2092 g_free (utf8_folder);
2097 #undef gtk_file_chooser_get_preview_filename
2100 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2102 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2103 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2105 g_free (utf8_filename);
2110 #undef gtk_file_chooser_add_shortcut_folder
2113 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2117 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2119 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2121 g_free (utf8_folder);
2126 #undef gtk_file_chooser_remove_shortcut_folder
2129 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2133 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2135 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2137 g_free (utf8_folder);
2142 #undef gtk_file_chooser_list_shortcut_folders
2145 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2147 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2148 GSList *rover = list;
2152 gchar *tem = (gchar *) rover->data;
2153 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2155 rover = rover->next;
2163 #define __GTK_FILE_CHOOSER_C__
2164 #include "gtkaliasdef.c"