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 static const GTypeInfo file_chooser_info =
44 sizeof (GtkFileChooserIface), /* class_size */
46 NULL, /* base_finalize */
47 (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
50 file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
52 &file_chooser_info, 0);
54 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
57 return file_chooser_type;
61 confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
63 const GValue *handler_return,
66 gboolean continue_emission;
67 GtkFileChooserConfirmation conf;
69 conf = g_value_get_enum (handler_return);
70 g_value_set_enum (return_accu, conf);
71 continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
73 return continue_emission;
77 gtk_file_chooser_class_init (gpointer g_iface)
79 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
82 * GtkFileChooser::current-folder-changed
83 * @chooser: the object which received the signal.
85 * This signal is emitted when the current folder in a #GtkFileChooser
86 * changes. This can happen due to the user performing some action that
87 * changes folders, such as selecting a bookmark or visiting a folder on the
88 * file list. It can also happen as a result of calling a function to
89 * explicitly change the current folder in a file chooser.
91 * Normally you do not need to connect to this signal, unless you need to keep
92 * track of which folder a file chooser is showing.
94 * See also: gtk_file_chooser_set_current_folder(),
95 * gtk_file_chooser_get_current_folder(),
96 * gtk_file_chooser_set_current_folder_uri(),
97 * gtk_file_chooser_get_current_folder_uri().
99 g_signal_new ("current-folder-changed",
102 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
104 g_cclosure_marshal_VOID__VOID,
108 * GtkFileChooser::selection-changed
109 * @chooser: the object which received the signal.
111 * This signal is emitted when there is a change in the set of selected files
112 * in a #GtkFileChooser. This can happen when the user modifies the selection
113 * with the mouse or the keyboard, or when explicitly calling functions to
114 * change the selection.
116 * Normally you do not need to connect to this signal, as it is easier to wait
117 * for the file chooser to finish running, and then to get the list of
118 * selected files using the functions mentioned below.
120 * See also: gtk_file_chooser_select_filename(),
121 * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
122 * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
123 * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
124 * gtk_file_chooser_get_uris().
126 g_signal_new ("selection-changed",
129 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
131 g_cclosure_marshal_VOID__VOID,
135 * GtkFileChooser::update-preview
136 * @chooser: the object which received the signal.
138 * This signal is emitted when the preview in a file chooser should be
139 * regenerated. For example, this can happen when the currently selected file
140 * changes. You should use this signal if you want your file chooser to have
143 * Once you have installed a preview widget with
144 * gtk_file_chooser_set_preview_widget(), you should update it when this
145 * signal is emitted. You can use the functions
146 * gtk_file_chooser_get_preview_filename() or
147 * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
148 * Your widget may not be able to preview all kinds of files; your callback
149 * must call gtk_file_chooser_set_preview_wiget_active() to inform the file
150 * chooser about whether the preview was generated successfully or not.
152 * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
154 * See also: gtk_file_chooser_set_preview_widget(),
155 * gtk_file_chooser_set_preview_widget_active(),
156 * gtk_file_chooser_set_use_preview_label(),
157 * gtk_file_chooser_get_preview_filename(),
158 * gtk_file_chooser_get_preview_uri().
160 g_signal_new ("update-preview",
163 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
165 g_cclosure_marshal_VOID__VOID,
169 * GtkFileChooser::file-activated
170 * @chooser: the object which received the signal.
172 * This signal is emitted when the user "activates" a file in the file
173 * chooser. This can happen by double-clicking on a file in the file list, or
174 * by pressing <keycap>Enter</keycap>.
176 * Normally you do not need to connect to this signal. It is used internally
177 * by #GtkFileChooserDialog to know when to activate the default button in the
180 * See also: gtk_file_chooser_get_filename(),
181 * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
182 * gtk_file_chooser_get_uris().
184 g_signal_new ("file-activated",
187 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
189 g_cclosure_marshal_VOID__VOID,
192 /* Documented in the docbook files */
193 g_signal_new ("confirm-overwrite",
196 G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
197 confirm_overwrite_accumulator, NULL,
198 _gtk_marshal_ENUM__VOID,
199 GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
201 g_object_interface_install_property (g_iface,
202 g_param_spec_enum ("action",
204 P_("The type of operation that the file selector is performing"),
205 GTK_TYPE_FILE_CHOOSER_ACTION,
206 GTK_FILE_CHOOSER_ACTION_OPEN,
207 GTK_PARAM_READWRITE));
208 g_object_interface_install_property (g_iface,
209 g_param_spec_string ("file-system-backend",
210 P_("File System Backend"),
211 P_("Name of file system backend to use"),
213 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
214 g_object_interface_install_property (g_iface,
215 g_param_spec_object ("filter",
217 P_("The current filter for selecting which files are displayed"),
218 GTK_TYPE_FILE_FILTER,
219 GTK_PARAM_READWRITE));
220 g_object_interface_install_property (g_iface,
221 g_param_spec_boolean ("local-only",
223 P_("Whether the selected file(s) should be limited to local file: URLs"),
225 GTK_PARAM_READWRITE));
226 g_object_interface_install_property (g_iface,
227 g_param_spec_object ("preview-widget",
228 P_("Preview widget"),
229 P_("Application supplied widget for custom previews."),
231 GTK_PARAM_READWRITE));
232 g_object_interface_install_property (g_iface,
233 g_param_spec_boolean ("preview-widget-active",
234 P_("Preview Widget Active"),
235 P_("Whether the application supplied widget for custom previews should be shown."),
237 GTK_PARAM_READWRITE));
238 g_object_interface_install_property (g_iface,
239 g_param_spec_boolean ("use-preview-label",
240 P_("Use Preview Label"),
241 P_("Whether to display a stock label with the name of the previewed file."),
243 GTK_PARAM_READWRITE));
244 g_object_interface_install_property (g_iface,
245 g_param_spec_object ("extra-widget",
247 P_("Application supplied widget for extra options."),
249 GTK_PARAM_READWRITE));
250 g_object_interface_install_property (g_iface,
251 g_param_spec_boolean ("select-multiple",
252 P_("Select Multiple"),
253 P_("Whether to allow multiple files to be selected"),
255 GTK_PARAM_READWRITE));
257 g_object_interface_install_property (g_iface,
258 g_param_spec_boolean ("show-hidden",
260 P_("Whether the hidden files and folders should be displayed"),
262 GTK_PARAM_READWRITE));
264 g_object_interface_install_property (g_iface,
265 g_param_spec_boolean ("do-overwrite-confirmation",
266 P_("Do overwrite confirmation"),
267 P_("Whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE "
268 "will present an overwrite confirmation dialog if the user "
269 "selects a file name that already exists."),
271 GTK_PARAM_READWRITE));
275 * gtk_file_chooser_error_quark:
277 * Registers an error quark for #GtkFileChooser if necessary.
279 * Return value: The error quark used for #GtkFileChooser errors.
284 gtk_file_chooser_error_quark (void)
286 static GQuark quark = 0;
288 quark = 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 * Return value: the full path of the current folder, or %NULL
695 * if the current path cannot be represented as a local filename.
696 * Free with g_free().
701 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
703 GtkFileSystem *file_system;
707 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
709 file_system = _gtk_file_chooser_get_file_system (chooser);
711 path = _gtk_file_chooser_get_current_folder_path (chooser);
712 filename = gtk_file_system_path_to_filename (file_system, path);
713 gtk_file_path_free (path);
719 * gtk_file_chooser_set_current_name:
720 * @chooser: a #GtkFileChooser
721 * @name: the filename to use, as a UTF-8 string
723 * Sets the current name in the file selector, as if entered
724 * by the user. Note that the name passed in here is a UTF-8
725 * string rather than a filename. This function is meant for
726 * such uses as a suggested name in a "Save As..." dialog.
728 * If you want to preselect a particular existing file, you should use
729 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
730 * Please see the documentation for those functions for an example of using
731 * gtk_file_chooser_set_current_name() as well.
736 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
739 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
740 g_return_if_fail (name != NULL);
742 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
746 * gtk_file_chooser_get_uri:
747 * @chooser: a #GtkFileChooser
749 * Gets the URI for the currently selected file in
750 * the file selector. If multiple files are selected,
751 * one of the filenames will be returned at random.
753 * If the file chooser is in folder mode, this function returns the selected
756 * Return value: The currently selected URI, or %NULL
757 * if no file is selected. Free with g_free()
762 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
764 GtkFileSystem *file_system;
766 gchar *result = NULL;
768 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
770 file_system = _gtk_file_chooser_get_file_system (chooser);
771 path = gtk_file_chooser_get_path (chooser);
774 result = gtk_file_system_path_to_uri (file_system, path);
775 gtk_file_path_free (path);
782 * gtk_file_chooser_set_uri:
783 * @chooser: a #GtkFileChooser
784 * @uri: the URI to set as current
786 * Sets the file referred to by @uri as the current file for the file chooser,
787 * by changing to the URI's parent folder and actually selecting the URI in the
788 * list. If the @chooser is #GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
789 * name will also appear in the dialog's file name entry.
791 * If the URI isn't in the current folder of @chooser, then the current folder
792 * of @chooser will be changed to the folder containing @uri. This is equivalent
793 * to a sequence of gtk_file_chooser_unselect_all() followed by
794 * gtk_file_chooser_select_uri().
796 * Note that the URI must exist, or nothing will be done except
797 * for the directory change.
798 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog, you
799 * should use this function if you already have a file name to which the user may save; for example,
800 * when the user opens an existing file and then does <guimenuitem>File/Save As...</guimenuitem>
801 * on it. If you don't have a file name already — for example, if the user just created
802 * a new file and is saving it for the first time, do not call this function. Instead, use
803 * something similar to this:
806 * if (document_is_new)
808 * /<!-- -->* the user just created a new document *<!-- -->/
809 * gtk_file_chooser_set_current_folder_uri (chooser, default_folder_for_saving);
810 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
814 * /<!-- -->* the user edited an existing document *<!-- -->/
815 * gtk_file_chooser_set_uri (chooser, existing_uri);
819 * Return value: %TRUE if both the folder could be changed and the URI was
820 * selected successfully, %FALSE otherwise.
825 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
828 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
830 gtk_file_chooser_unselect_all (chooser);
831 return gtk_file_chooser_select_uri (chooser, uri);
835 * gtk_file_chooser_select_uri:
836 * @chooser: a #GtkFileChooser
837 * @uri: the URI to select
839 * Selects the file to by @uri. If the URI doesn't refer to a
840 * file in the current folder of @chooser, then the current folder of
841 * @chooser will be changed to the folder containing @filename.
843 * Return value: %TRUE if both the folder could be changed and the URI was
844 * selected successfully, %FALSE otherwise.
849 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
852 GtkFileSystem *file_system;
856 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
857 g_return_val_if_fail (uri != NULL, FALSE);
859 file_system = _gtk_file_chooser_get_file_system (chooser);
861 path = gtk_file_system_uri_to_path (file_system, uri);
864 result = _gtk_file_chooser_select_path (chooser, path, NULL);
865 gtk_file_path_free (path);
874 * gtk_file_chooser_unselect_uri:
875 * @chooser: a #GtkFileChooser
876 * @uri: the URI to unselect
878 * Unselects the file referred to by @uri. If the file
879 * is not in the current directory, does not exist, or
880 * is otherwise not currently selected, does nothing.
885 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
888 GtkFileSystem *file_system;
891 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
892 g_return_if_fail (uri != NULL);
894 file_system = _gtk_file_chooser_get_file_system (chooser);
896 path = gtk_file_system_uri_to_path (file_system, uri);
899 _gtk_file_chooser_unselect_path (chooser, path);
900 gtk_file_path_free (path);
905 * gtk_file_chooser_select_all:
906 * @chooser: a #GtkFileChooser
908 * Selects all the files in the current folder of a file chooser.
913 gtk_file_chooser_select_all (GtkFileChooser *chooser)
915 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
917 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
921 * gtk_file_chooser_unselect_all:
922 * @chooser: a #GtkFileChooser
924 * Unselects all the files in the current folder of a file chooser.
929 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
932 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
934 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
938 * gtk_file_chooser_get_uris:
939 * @chooser: a #GtkFileChooser
941 * Lists all the selected files and subfolders in the current folder of
942 * @chooser. The returned names are full absolute URIs.
944 * Return value: a #GSList containing the URIs of all selected
945 * files and subfolders in the current folder. Free the returned list
946 * with g_slist_free(), and the filenames with g_free().
951 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
953 GtkFileSystem *file_system;
957 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
959 file_system = _gtk_file_chooser_get_file_system (chooser);
960 paths = _gtk_file_chooser_get_paths (chooser);
962 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
963 gtk_file_paths_free (paths);
968 * gtk_file_chooser_set_current_folder_uri:
969 * @chooser: a #GtkFileChooser
970 * @uri: the URI for the new current folder
972 * Sets the current folder for @chooser from an URI.
973 * The user will be shown the full contents of the current folder,
974 * plus user interface elements for navigating to other folders.
976 * Return value: %TRUE if the folder could be changed successfully, %FALSE
982 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
985 GtkFileSystem *file_system;
989 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
990 g_return_val_if_fail (uri != NULL, FALSE);
992 file_system = _gtk_file_chooser_get_file_system (chooser);
994 path = gtk_file_system_uri_to_path (file_system, uri);
997 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
998 gtk_file_path_free (path);
1007 * gtk_file_chooser_get_current_folder_uri:
1008 * @chooser: a #GtkFileChooser
1010 * Gets the current folder of @chooser as an URI.
1011 * See gtk_file_chooser_set_current_folder_uri().
1013 * Return value: the URI for the current folder.
1014 * Free with g_free().
1019 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
1021 GtkFileSystem *file_system;
1025 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1027 file_system = _gtk_file_chooser_get_file_system (chooser);
1029 path = _gtk_file_chooser_get_current_folder_path (chooser);
1030 uri = gtk_file_system_path_to_uri (file_system, path);
1031 gtk_file_path_free (path);
1037 * _gtk_file_chooser_set_current_folder_path:
1038 * @chooser: a #GtkFileChooser
1039 * @path: the #GtkFilePath for the new folder
1040 * @error: location to store error, or %NULL.
1042 * Sets the current folder for @chooser from a #GtkFilePath.
1043 * Internal function, see gtk_file_chooser_set_current_folder_uri().
1045 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1051 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
1052 const GtkFilePath *path,
1055 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1056 g_return_val_if_fail (path != NULL, FALSE);
1057 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1059 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path, error);
1063 * _gtk_file_chooser_get_current_folder_path:
1064 * @chooser: a #GtkFileChooser
1066 * Gets the current folder of @chooser as #GtkFilePath.
1067 * See gtk_file_chooser_get_current_folder_uri().
1069 * Return value: the #GtkFilePath for the current folder.
1070 * Free with gtk_file_path_free().
1075 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
1077 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1079 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1083 * _gtk_file_chooser_select_path:
1084 * @chooser: a #GtkFileChooser
1085 * @path: the path to select
1086 * @error: location to store error, or %NULL
1088 * Selects the file referred to by @path. An internal function. See
1089 * _gtk_file_chooser_select_uri().
1091 * Return value: %TRUE if both the folder could be changed and the path was
1092 * selected successfully, %FALSE otherwise.
1097 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
1098 const GtkFilePath *path,
1101 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1102 g_return_val_if_fail (path != NULL, FALSE);
1103 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1105 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path, error);
1109 * _gtk_file_chooser_unselect_path:
1110 * @chooser: a #GtkFileChooser
1111 * @path: the filename to path
1113 * Unselects the file referred to by @path. An internal
1114 * function. See _gtk_file_chooser_unselect_uri().
1119 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
1120 const GtkFilePath *path)
1122 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1124 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
1128 * _gtk_file_chooser_get_paths:
1129 * @chooser: a #GtkFileChooser
1131 * Lists all the selected files and subfolders in the current folder of @chooser
1132 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
1134 * Return value: a #GSList containing a #GtkFilePath for each selected
1135 * file and subfolder in the current folder. Free the returned list
1136 * with g_slist_free(), and the paths with gtk_file_path_free().
1141 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
1143 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1145 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
1148 static GtkFilePath *
1149 gtk_file_chooser_get_path (GtkFileChooser *chooser)
1152 GtkFilePath *result = NULL;
1154 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1156 list = _gtk_file_chooser_get_paths (chooser);
1159 result = list->data;
1160 list = g_slist_delete_link (list, list);
1161 gtk_file_paths_free (list);
1168 * _gtk_file_chooser_get_file_system:
1169 * @chooser: a #GtkFileChooser
1171 * Gets the #GtkFileSystem of @chooser; this is an internal
1172 * implementation detail, used for conversion between paths
1173 * and filenames and URIs.
1175 * Return value: the file system for @chooser.
1180 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1182 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1184 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1190 * gtk_file_chooser_set_preview_widget:
1191 * @chooser: a #GtkFileChooser
1192 * @preview_widget: widget for displaying preview.
1194 * Sets an application-supplied widget to use to display a custom preview
1195 * of the currently selected file. To implement a preview, after setting the
1196 * preview widget, you connect to the ::update-preview
1197 * signal, and call gtk_file_chooser_get_preview_filename() or
1198 * gtk_file_chooser_get_preview_uri() on each change. If you can
1199 * display a preview of the new file, update your widget and
1200 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1201 * Otherwise, set the preview inactive.
1203 * When there is no application-supplied preview widget, or the
1204 * application-supplied preview widget is not active, the file chooser
1205 * may display an internally generated preview of the current file or
1206 * it may display no preview at all.
1211 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1212 GtkWidget *preview_widget)
1214 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1216 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1220 * gtk_file_chooser_get_preview_widget:
1221 * @chooser: a #GtkFileChooser
1223 * Gets the current preview widget; see
1224 * gtk_file_chooser_set_preview_widget().
1226 * Return value: the current preview widget, or %NULL
1231 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1233 GtkWidget *preview_widget;
1235 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1237 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1239 /* Horrid hack; g_object_get() refs returned objects but
1240 * that contradicts the memory management conventions
1244 g_object_unref (preview_widget);
1246 return preview_widget;
1250 * gtk_file_chooser_set_preview_widget_active:
1251 * @chooser: a #GtkFileChooser
1252 * @active: whether to display the user-specified preview widget
1254 * Sets whether the preview widget set by
1255 * gtk_file_chooser_set_preview_widget() should be shown for the
1256 * current filename. When @active is set to false, the file chooser
1257 * may display an internally generated preview of the current file
1258 * or it may display no preview at all. See
1259 * gtk_file_chooser_set_preview_widget() for more details.
1264 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1267 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1269 g_object_set (chooser, "preview-widget-active", active, NULL);
1273 * gtk_file_chooser_get_preview_widget_active:
1274 * @chooser: a #GtkFileChooser
1276 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1277 * should be shown for the current filename. See
1278 * gtk_file_chooser_set_preview_widget_active().
1280 * Return value: %TRUE if the preview widget is active for the current filename.
1285 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1289 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1291 g_object_get (chooser, "preview-widget-active", &active, NULL);
1297 * gtk_file_chooser_set_use_preview_label:
1298 * @chooser: a #GtkFileChooser
1299 * @use_label: whether to display a stock label with the name of the previewed file
1301 * Sets whether the file chooser should display a stock label with the name of
1302 * the file that is being previewed; the default is %TRUE. Applications that
1303 * want to draw the whole preview area themselves should set this to %FALSE and
1304 * display the name themselves in their preview widget.
1306 * See also: gtk_file_chooser_set_preview_widget()
1311 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1314 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1316 g_object_set (chooser, "use-preview-label", use_label, NULL);
1320 * gtk_file_chooser_get_use_preview_label:
1321 * @chooser: a #GtkFileChooser
1323 * Gets whether a stock label should be drawn with the name of the previewed
1324 * file. See gtk_file_chooser_set_use_preview_label().
1326 * Return value: %TRUE if the file chooser is set to display a label with the
1327 * name of the previewed file, %FALSE otherwise.
1330 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1334 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1336 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1342 * gtk_file_chooser_get_preview_filename:
1343 * @chooser: a #GtkFileChooser
1345 * Gets the filename that should be previewed in a custom preview
1346 * Internal function, see gtk_file_chooser_get_preview_uri().
1348 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1349 * is selected. Free with gtk_file_path_free().
1354 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1356 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1358 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1362 * _gtk_file_chooser_add_shortcut_folder:
1363 * @chooser: a #GtkFileChooser
1364 * @path: path of the folder to add
1365 * @error: location to store error, or %NULL
1367 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1368 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1370 * Return value: %TRUE if the folder could be added successfully, %FALSE
1376 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1377 const GtkFilePath *path,
1380 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1381 g_return_val_if_fail (path != NULL, FALSE);
1383 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1387 * _gtk_file_chooser_remove_shortcut_folder:
1388 * @chooser: a #GtkFileChooser
1389 * @path: path of the folder to remove
1390 * @error: location to store error, or %NULL
1392 * Removes a folder from the shortcut folders in a file chooser. Internal
1393 * function, see gtk_file_chooser_remove_shortcut_folder().
1395 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1401 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1402 const GtkFilePath *path,
1405 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1406 g_return_val_if_fail (path != NULL, FALSE);
1408 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1412 * gtk_file_chooser_get_preview_filename:
1413 * @chooser: a #GtkFileChooser
1415 * Gets the filename that should be previewed in a custom preview
1416 * widget. See gtk_file_chooser_set_preview_widget().
1418 * Return value: the filename to preview, or %NULL if no file
1419 * is selected, or if the selected file cannot be represented
1420 * as a local filename. Free with g_free()
1425 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1427 GtkFileSystem *file_system;
1429 gchar *result = NULL;
1431 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1433 file_system = _gtk_file_chooser_get_file_system (chooser);
1434 path = _gtk_file_chooser_get_preview_path (chooser);
1437 result = gtk_file_system_path_to_filename (file_system, path);
1438 gtk_file_path_free (path);
1445 * gtk_file_chooser_get_preview_uri:
1446 * @chooser: a #GtkFileChooser
1448 * Gets the URI that should be previewed in a custom preview
1449 * widget. See gtk_file_chooser_set_preview_widget().
1451 * Return value: the URI for the file to preview, or %NULL if no file is
1452 * selected. Free with g_free().
1457 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1459 GtkFileSystem *file_system;
1461 gchar *result = NULL;
1463 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1465 file_system = _gtk_file_chooser_get_file_system (chooser);
1466 path = _gtk_file_chooser_get_preview_path (chooser);
1469 result = gtk_file_system_path_to_uri (file_system, path);
1470 gtk_file_path_free (path);
1477 * gtk_file_chooser_set_extra_widget:
1478 * @chooser: a #GtkFileChooser
1479 * @extra_widget: widget for extra options
1481 * Sets an application-supplied widget to provide extra options to the user.
1486 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1487 GtkWidget *extra_widget)
1489 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1491 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1495 * gtk_file_chooser_get_extra_widget:
1496 * @chooser: a #GtkFileChooser
1498 * Gets the current preview widget; see
1499 * gtk_file_chooser_set_extra_widget().
1501 * Return value: the current extra widget, or %NULL
1506 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1508 GtkWidget *extra_widget;
1510 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1512 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1514 /* Horrid hack; g_object_get() refs returned objects but
1515 * that contradicts the memory management conventions
1519 g_object_unref (extra_widget);
1521 return extra_widget;
1525 * gtk_file_chooser_add_filter:
1526 * @chooser: a #GtkFileChooser
1527 * @filter: a #GtkFileFilter
1529 * Adds @filter to the list of filters that the user can select between.
1530 * When a filter is selected, only files that are passed by that
1531 * filter are displayed.
1533 * Note that the @chooser takes ownership of the filter, so you have to
1534 * ref and sink it if you want to keep a reference.
1539 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1540 GtkFileFilter *filter)
1542 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1544 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1548 * gtk_file_chooser_remove_filter:
1549 * @chooser: a #GtkFileChooser
1550 * @filter: a #GtkFileFilter
1552 * Removes @filter from the list of filters that the user can select between.
1557 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1558 GtkFileFilter *filter)
1560 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1562 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1566 * gtk_file_chooser_list_filters:
1567 * @chooser: a #GtkFileChooser
1569 * Lists the current set of user-selectable filters; see
1570 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1572 * Return value: a #GSList containing the current set of
1573 * user selectable filters. The contents of the list are
1574 * owned by GTK+, but you must free the list itself with
1575 * g_slist_free() when you are done with it.
1580 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1582 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1584 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1588 * gtk_file_chooser_set_filter:
1589 * @chooser: a #GtkFileChooser
1590 * @filter: a #GtkFileFilter
1592 * Sets the current filter; only the files that pass the
1593 * filter will be displayed. If the user-selectable list of filters
1594 * is non-empty, then the filter should be one of the filters
1595 * in that list. Setting the current filter when the list of
1596 * filters is empty is useful if you want to restrict the displayed
1597 * set of files without letting the user change it.
1602 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1603 GtkFileFilter *filter)
1605 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1606 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1608 g_object_set (chooser, "filter", filter, NULL);
1612 * gtk_file_chooser_get_filter:
1613 * @chooser: a #GtkFileChooser
1615 * Gets the current filter; see gtk_file_chooser_set_filter().
1617 * Return value: the current filter, or %NULL
1622 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1624 GtkFileFilter *filter;
1626 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1628 g_object_get (chooser, "filter", &filter, NULL);
1629 /* Horrid hack; g_object_get() refs returned objects but
1630 * that contradicts the memory management conventions
1634 g_object_unref (filter);
1640 * gtk_file_chooser_add_shortcut_folder:
1641 * @chooser: a #GtkFileChooser
1642 * @folder: filename of the folder to add
1643 * @error: location to store error, or %NULL
1645 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1646 * Note that shortcut folders do not get saved, as they are provided by the
1647 * application. For example, you can use this to add a
1648 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1650 * Return value: %TRUE if the folder could be added successfully, %FALSE
1651 * otherwise. In the latter case, the @error will be set as appropriate.
1656 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1663 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1664 g_return_val_if_fail (folder != NULL, FALSE);
1666 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1670 GTK_FILE_CHOOSER_ERROR,
1671 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1672 _("Invalid filename: %s"),
1677 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1679 gtk_file_path_free (path);
1685 * gtk_file_chooser_remove_shortcut_folder:
1686 * @chooser: a #GtkFileChooser
1687 * @folder: filename of the folder to remove
1688 * @error: location to store error, or %NULL
1690 * Removes a folder from a file chooser's list of shortcut folders.
1692 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1693 * In the latter case, the @error will be set as appropriate.
1695 * See also: gtk_file_chooser_add_shortcut_folder()
1700 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1707 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1708 g_return_val_if_fail (folder != NULL, FALSE);
1710 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1714 GTK_FILE_CHOOSER_ERROR,
1715 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1716 _("Invalid filename: %s"),
1721 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1723 gtk_file_path_free (path);
1729 * gtk_file_chooser_list_shortcut_folders:
1730 * @chooser: a #GtkFileChooser
1732 * Queries the list of shortcut folders in the file chooser, as set by
1733 * gtk_file_chooser_add_shortcut_folder().
1735 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1736 * folders. Free the returned list with g_slist_free(), and the filenames with
1742 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1747 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1749 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1751 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1753 gtk_file_system_path_to_filename);
1754 gtk_file_paths_free (folders);
1759 * gtk_file_chooser_add_shortcut_folder_uri:
1760 * @chooser: a #GtkFileChooser
1761 * @uri: URI of the folder to add
1762 * @error: location to store error, or %NULL
1764 * Adds a folder URI to be displayed with the shortcut folders in a file
1765 * chooser. Note that shortcut folders do not get saved, as they are provided
1766 * by the application. For example, you can use this to add a
1767 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1769 * Return value: %TRUE if the folder could be added successfully, %FALSE
1770 * otherwise. In the latter case, the @error will be set as appropriate.
1775 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1782 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1783 g_return_val_if_fail (uri != NULL, FALSE);
1785 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1789 GTK_FILE_CHOOSER_ERROR,
1790 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1791 _("Invalid filename: %s"),
1796 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1798 gtk_file_path_free (path);
1804 * gtk_file_chooser_remove_shortcut_folder_uri:
1805 * @chooser: a #GtkFileChooser
1806 * @uri: URI of the folder to remove
1807 * @error: location to store error, or %NULL
1809 * Removes a folder URI from a file chooser's list of shortcut folders.
1811 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1812 * In the latter case, the @error will be set as appropriate.
1814 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1819 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1826 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1827 g_return_val_if_fail (uri != NULL, FALSE);
1829 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1833 GTK_FILE_CHOOSER_ERROR,
1834 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1835 _("Invalid filename: %s"),
1840 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1842 gtk_file_path_free (path);
1848 * gtk_file_chooser_list_shortcut_folder_uris:
1849 * @chooser: a #GtkFileChooser
1851 * Queries the list of shortcut folders in the file chooser, as set by
1852 * gtk_file_chooser_add_shortcut_folder_uri().
1854 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1855 * folders. Free the returned list with g_slist_free(), and the URIs with
1861 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1866 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1868 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1870 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1872 gtk_file_system_path_to_uri);
1873 gtk_file_paths_free (folders);
1879 * gtk_file_chooser_set_show_hidden:
1880 * @chooser: a #GtkFileChooser
1881 * @show_hidden: %TRUE if hidden files and folders should be displayed.
1883 * Sets whether hidden files and folders are displayed in the file selector.
1888 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1889 gboolean show_hidden)
1891 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1893 g_object_set (chooser, "show-hidden", show_hidden, NULL);
1897 * gtk_file_chooser_get_show_hidden:
1898 * @chooser: a #GtkFileChooser
1900 * Gets whether hidden files and folders are displayed in the file selector.
1901 * See gtk_file_chooser_set_show_hidden().
1903 * Return value: %TRUE if hidden files and folders are displayed.
1908 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1910 gboolean show_hidden;
1912 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1914 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1920 * gtk_file_chooser_set_do_overwrite_confirmation:
1921 * @chooser: a #GtkFileChooser
1922 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1924 * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1925 * a confirmation dialog if the user types a file name that already exists. This
1926 * is %FALSE by default.
1928 * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1929 * signal when appropriate.
1931 * If all you need is the stock confirmation dialog, set this property to %TRUE.
1932 * You can override the way confirmation is done by actually handling the
1933 * "confirm-overwrite" signal; please refer to its documentation for the
1939 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
1940 gboolean do_overwrite_confirmation)
1942 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1944 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
1948 * gtk_file_chooser_get_do_overwrite_confirmation:
1949 * @chooser: a #GtkFileChooser
1951 * Queries whether a file chooser is set to confirm for overwriting when the user
1952 * types a file name that already exists.
1954 * Return value: %TRUE if the file chooser will present a confirmation dialog;
1960 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
1962 gboolean do_overwrite_confirmation;
1964 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1966 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
1968 return do_overwrite_confirmation;
1973 /* DLL ABI stability backward compatibility versions */
1975 #undef gtk_file_chooser_get_filename
1978 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
1980 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
1981 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
1983 g_free (utf8_filename);
1988 #undef gtk_file_chooser_set_filename
1991 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
1992 const gchar *filename)
1994 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
1995 gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
1997 g_free (utf8_filename);
2002 #undef gtk_file_chooser_select_filename
2005 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2006 const gchar *filename)
2008 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2009 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2011 g_free (utf8_filename);
2016 #undef gtk_file_chooser_unselect_filename
2019 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2020 const char *filename)
2022 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2024 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2025 g_free (utf8_filename);
2028 #undef gtk_file_chooser_get_filenames
2031 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2033 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2034 GSList *rover = list;
2038 gchar *tem = (gchar *) rover->data;
2039 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2041 rover = rover->next;
2047 #undef gtk_file_chooser_set_current_folder
2050 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2051 const gchar *filename)
2053 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2054 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2056 g_free (utf8_filename);
2061 #undef gtk_file_chooser_get_current_folder
2064 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2066 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2067 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2069 g_free (utf8_folder);
2074 #undef gtk_file_chooser_get_preview_filename
2077 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2079 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2080 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2082 g_free (utf8_filename);
2087 #undef gtk_file_chooser_add_shortcut_folder
2090 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2094 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2096 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2098 g_free (utf8_folder);
2103 #undef gtk_file_chooser_remove_shortcut_folder
2106 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2110 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2112 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2114 g_free (utf8_folder);
2119 #undef gtk_file_chooser_list_shortcut_folders
2122 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2124 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2125 GSList *rover = list;
2129 gchar *tem = (gchar *) rover->data;
2130 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2132 rover = rover->next;
2140 #define __GTK_FILE_CHOOSER_C__
2141 #include "gtkaliasdef.c"