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"
25 #include "gtktypebuiltins.h"
26 #include "gtkprivate.h"
27 #include "gtkmarshalers.h"
30 static void gtk_file_chooser_class_init (gpointer g_iface);
33 gtk_file_chooser_get_type (void)
35 static GType file_chooser_type = 0;
37 if (!file_chooser_type)
39 file_chooser_type = g_type_register_static_simple (G_TYPE_INTERFACE,
41 sizeof (GtkFileChooserIface),
42 (GClassInitFunc) gtk_file_chooser_class_init,
45 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
48 return file_chooser_type;
52 confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
54 const GValue *handler_return,
57 gboolean continue_emission;
58 GtkFileChooserConfirmation conf;
60 conf = g_value_get_enum (handler_return);
61 g_value_set_enum (return_accu, conf);
62 continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
64 return continue_emission;
68 gtk_file_chooser_class_init (gpointer g_iface)
70 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
73 * GtkFileChooser::current-folder-changed
74 * @chooser: the object which received the signal.
76 * This signal is emitted when the current folder in a #GtkFileChooser
77 * changes. This can happen due to the user performing some action that
78 * changes folders, such as selecting a bookmark or visiting a folder on the
79 * file list. It can also happen as a result of calling a function to
80 * explicitly change the current folder in a file chooser.
82 * Normally you do not need to connect to this signal, unless you need to keep
83 * track of which folder a file chooser is showing.
85 * See also: gtk_file_chooser_set_current_folder(),
86 * gtk_file_chooser_get_current_folder(),
87 * gtk_file_chooser_set_current_folder_uri(),
88 * gtk_file_chooser_get_current_folder_uri().
90 g_signal_new (I_("current-folder-changed"),
93 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
95 g_cclosure_marshal_VOID__VOID,
99 * GtkFileChooser::selection-changed
100 * @chooser: the object which received the signal.
102 * This signal is emitted when there is a change in the set of selected files
103 * in a #GtkFileChooser. This can happen when the user modifies the selection
104 * with the mouse or the keyboard, or when explicitly calling functions to
105 * change the selection.
107 * Normally you do not need to connect to this signal, as it is easier to wait
108 * for the file chooser to finish running, and then to get the list of
109 * selected files using the functions mentioned below.
111 * See also: gtk_file_chooser_select_filename(),
112 * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
113 * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
114 * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
115 * gtk_file_chooser_get_uris().
117 g_signal_new (I_("selection-changed"),
120 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
122 g_cclosure_marshal_VOID__VOID,
126 * GtkFileChooser::update-preview
127 * @chooser: the object which received the signal.
129 * This signal is emitted when the preview in a file chooser should be
130 * regenerated. For example, this can happen when the currently selected file
131 * changes. You should use this signal if you want your file chooser to have
134 * Once you have installed a preview widget with
135 * gtk_file_chooser_set_preview_widget(), you should update it when this
136 * signal is emitted. You can use the functions
137 * gtk_file_chooser_get_preview_filename() or
138 * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
139 * Your widget may not be able to preview all kinds of files; your callback
140 * must call gtk_file_chooser_set_preview_widget_active() to inform the file
141 * chooser about whether the preview was generated successfully or not.
143 * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
145 * See also: gtk_file_chooser_set_preview_widget(),
146 * gtk_file_chooser_set_preview_widget_active(),
147 * gtk_file_chooser_set_use_preview_label(),
148 * gtk_file_chooser_get_preview_filename(),
149 * gtk_file_chooser_get_preview_uri().
151 g_signal_new (I_("update-preview"),
154 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
156 g_cclosure_marshal_VOID__VOID,
160 * GtkFileChooser::file-activated
161 * @chooser: the object which received the signal.
163 * This signal is emitted when the user "activates" a file in the file
164 * chooser. This can happen by double-clicking on a file in the file list, or
165 * by pressing <keycap>Enter</keycap>.
167 * Normally you do not need to connect to this signal. It is used internally
168 * by #GtkFileChooserDialog to know when to activate the default button in the
171 * See also: gtk_file_chooser_get_filename(),
172 * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
173 * gtk_file_chooser_get_uris().
175 g_signal_new (I_("file-activated"),
178 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
180 g_cclosure_marshal_VOID__VOID,
183 /* Documented in the docbook files */
184 g_signal_new (I_("confirm-overwrite"),
187 G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
188 confirm_overwrite_accumulator, NULL,
189 _gtk_marshal_ENUM__VOID,
190 GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
192 g_object_interface_install_property (g_iface,
193 g_param_spec_enum ("action",
195 P_("The type of operation that the file selector is performing"),
196 GTK_TYPE_FILE_CHOOSER_ACTION,
197 GTK_FILE_CHOOSER_ACTION_OPEN,
198 GTK_PARAM_READWRITE));
199 g_object_interface_install_property (g_iface,
200 g_param_spec_string ("file-system-backend",
201 P_("File System Backend"),
202 P_("Name of file system backend to use"),
204 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
205 g_object_interface_install_property (g_iface,
206 g_param_spec_object ("filter",
208 P_("The current filter for selecting which files are displayed"),
209 GTK_TYPE_FILE_FILTER,
210 GTK_PARAM_READWRITE));
211 g_object_interface_install_property (g_iface,
212 g_param_spec_boolean ("local-only",
214 P_("Whether the selected file(s) should be limited to local file: URLs"),
216 GTK_PARAM_READWRITE));
217 g_object_interface_install_property (g_iface,
218 g_param_spec_object ("preview-widget",
219 P_("Preview widget"),
220 P_("Application supplied widget for custom previews."),
222 GTK_PARAM_READWRITE));
223 g_object_interface_install_property (g_iface,
224 g_param_spec_boolean ("preview-widget-active",
225 P_("Preview Widget Active"),
226 P_("Whether the application supplied widget for custom previews should be shown."),
228 GTK_PARAM_READWRITE));
229 g_object_interface_install_property (g_iface,
230 g_param_spec_boolean ("use-preview-label",
231 P_("Use Preview Label"),
232 P_("Whether to display a stock label with the name of the previewed file."),
234 GTK_PARAM_READWRITE));
235 g_object_interface_install_property (g_iface,
236 g_param_spec_object ("extra-widget",
238 P_("Application supplied widget for extra options."),
240 GTK_PARAM_READWRITE));
241 g_object_interface_install_property (g_iface,
242 g_param_spec_boolean ("select-multiple",
243 P_("Select Multiple"),
244 P_("Whether to allow multiple files to be selected"),
246 GTK_PARAM_READWRITE));
248 g_object_interface_install_property (g_iface,
249 g_param_spec_boolean ("show-hidden",
251 P_("Whether the hidden files and folders should be displayed"),
253 GTK_PARAM_READWRITE));
256 * GtkFileChooser:do-overwrite-confirmation:
258 * Whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode
259 * will present an overwrite confirmation dialog if the user
260 * selects a file name that already exists.
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 save mode "
268 "will present an overwrite confirmation dialog "
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 return g_quark_from_static_string ("gtk-file-chooser-error-quark");
290 * gtk_file_chooser_set_action:
291 * @chooser: a #GtkFileChooser
292 * @action: the action that the file selector is performing
294 * Sets the type of operation that the chooser is performing; the
295 * user interface is adapted to suit the selected action. For example,
296 * an option to create a new folder might be shown if the action is
297 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
298 * %GTK_FILE_CHOOSER_ACTION_OPEN.
303 gtk_file_chooser_set_action (GtkFileChooser *chooser,
304 GtkFileChooserAction action)
306 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
308 g_object_set (chooser, "action", action, NULL);
312 * gtk_file_chooser_get_action:
313 * @chooser: a #GtkFileChooser
315 * Gets the type of operation that the file chooser is performing; see
316 * gtk_file_chooser_set_action().
318 * Return value: the action that the file selector is performing
323 gtk_file_chooser_get_action (GtkFileChooser *chooser)
325 GtkFileChooserAction action;
327 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
329 g_object_get (chooser, "action", &action, NULL);
335 * gtk_file_chooser_set_local_only:
336 * @chooser: a #GtkFileChooser
337 * @local_only: %TRUE if only local files can be selected
339 * Sets whether only local files can be selected in the
340 * file selector. If @local_only is %TRUE (the default),
341 * then the selected file are files are guaranteed to be
342 * accessible through the operating systems native file
343 * file system and therefore the application only
344 * needs to worry about the filename functions in
345 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
346 * rather than the URI functions like
347 * gtk_file_chooser_get_uri(),
352 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
355 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
357 g_object_set (chooser, "local-only", local_only, NULL);
361 * gtk_file_chooser_get_local_only:
362 * @chooser: a #GtkFileChoosre
364 * Gets whether only local files can be selected in the
365 * file selector. See gtk_file_chooser_set_local_only()
367 * Return value: %TRUE if only local files can be selected.
372 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
376 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
378 g_object_get (chooser, "local-only", &local_only, NULL);
384 * gtk_file_chooser_set_select_multiple:
385 * @chooser: a #GtkFileChooser
386 * @select_multiple: %TRUE if multiple files can be selected.
388 * Sets whether multiple files can be selected in the file selector. This is
389 * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
390 * GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
395 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
396 gboolean select_multiple)
398 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
400 g_object_set (chooser, "select-multiple", select_multiple, NULL);
404 * gtk_file_chooser_get_select_multiple:
405 * @chooser: a #GtkFileChooser
407 * Gets whether multiple files can be selected in the file
408 * selector. See gtk_file_chooser_set_select_multiple().
410 * Return value: %TRUE if multiple files can be selected.
415 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
417 gboolean select_multiple;
419 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
421 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
423 return select_multiple;
427 * gtk_file_chooser_get_filename:
428 * @chooser: a #GtkFileChooser
430 * Gets the filename for the currently selected file in
431 * the file selector. If multiple files are selected,
432 * one of the filenames will be returned at random.
434 * If the file chooser is in folder mode, this function returns the selected
437 * Return value: The currently selected filename, or %NULL
438 * if no file is selected, or the selected file can't
439 * be represented with a local filename. Free with g_free().
444 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
447 gchar *result = NULL;
449 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
451 file = gtk_file_chooser_get_file (chooser);
455 result = g_file_get_path (file);
456 g_object_unref (file);
463 * gtk_file_chooser_set_filename:
464 * @chooser: a #GtkFileChooser
465 * @filename: the filename to set as current
467 * Sets @filename as the current filename for the file chooser, by changing
468 * to the file's parent folder and actually selecting the file in list. If
469 * the @chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
470 * will also appear in the dialog's file name entry.
472 * If the file name isn't in the current folder of @chooser, then the current
473 * folder of @chooser will be changed to the folder containing @filename. This
474 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
475 * gtk_file_chooser_select_filename().
477 * Note that the file must exist, or nothing will be done except
478 * for the directory change.
480 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
481 * you should use this function if you already have a file name to which the
482 * user may save; for example, when the user opens an existing file and then
483 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
484 * a file name already — for example, if the user just created a new
485 * file and is saving it for the first time, do not call this function.
486 * Instead, use something similar to this:
488 * if (document_is_new)
490 * /* the user just created a new document */
491 * gtk_file_chooser_set_current_folder (chooser, default_folder_for_saving);
492 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
496 * /* the user edited an existing document */
497 * gtk_file_chooser_set_filename (chooser, existing_filename);
501 * Return value: %TRUE if both the folder could be changed and the file was
502 * selected successfully, %FALSE otherwise.
507 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
508 const gchar *filename)
510 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
512 gtk_file_chooser_unselect_all (chooser);
513 return gtk_file_chooser_select_filename (chooser, filename);
517 * gtk_file_chooser_select_filename:
518 * @chooser: a #GtkFileChooser
519 * @filename: the filename to select
521 * Selects a filename. If the file name isn't in the current
522 * folder of @chooser, then the current folder of @chooser will
523 * be changed to the folder containing @filename.
525 * Return value: %TRUE if both the folder could be changed and the file was
526 * selected successfully, %FALSE otherwise.
531 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
532 const gchar *filename)
537 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
538 g_return_val_if_fail (filename != NULL, FALSE);
540 file = g_file_new_for_path (filename);
541 result = gtk_file_chooser_select_file (chooser, file, NULL);
542 g_object_unref (file);
548 * gtk_file_chooser_unselect_filename:
549 * @chooser: a #GtkFileChooser
550 * @filename: the filename to unselect
552 * Unselects a currently selected filename. If the filename
553 * is not in the current directory, does not exist, or
554 * is otherwise not currently selected, does nothing.
559 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
560 const char *filename)
564 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
565 g_return_if_fail (filename != NULL);
567 file = g_file_new_for_path (filename);
568 gtk_file_chooser_unselect_file (chooser, file);
569 g_object_unref (file);
572 /* Converts a list of GFile* to a list of strings using the specified function */
574 files_to_strings (GSList *files,
575 gchar * (*convert_func) (GFile *file))
581 for (; files; files = files->next)
587 string = (* convert_func) (file);
590 strings = g_slist_prepend (strings, string);
593 return g_slist_reverse (strings);
597 * gtk_file_chooser_get_filenames:
598 * @chooser: a #GtkFileChooser
600 * Lists all the selected files and subfolders in the current folder of
601 * @chooser. The returned names are full absolute paths. If files in the current
602 * folder cannot be represented as local filenames they will be ignored. (See
603 * gtk_file_chooser_get_uris())
605 * Return value: a #GSList containing the filenames of all selected
606 * files and subfolders in the current folder. Free the returned list
607 * with g_slist_free(), and the filenames with g_free().
612 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
614 GSList *files, *result;
616 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
618 files = gtk_file_chooser_get_files (chooser);
620 result = files_to_strings (files, g_file_get_path);
621 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
622 g_slist_free (files);
628 * gtk_file_chooser_set_current_folder:
629 * @chooser: a #GtkFileChooser
630 * @filename: the full path of the new current folder
632 * Sets the current folder for @chooser from a local filename.
633 * The user will be shown the full contents of the current folder,
634 * plus user interface elements for navigating to other folders.
636 * Return value: %TRUE if the folder could be changed successfully, %FALSE
642 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
643 const gchar *filename)
648 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
649 g_return_val_if_fail (filename != NULL, FALSE);
651 file = g_file_new_for_path (filename);
652 result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
653 g_object_unref (file);
659 * gtk_file_chooser_get_current_folder:
660 * @chooser: a #GtkFileChooser
662 * Gets the current folder of @chooser as a local filename.
663 * See gtk_file_chooser_set_current_folder().
665 * Note that this is the folder that the file chooser is currently displaying
666 * (e.g. "/home/username/Documents"), which is <emphasis>not the same</emphasis>
667 * as the currently-selected folder if the chooser is in
668 * #GTK_FILE_CHOOSER_SELECT_FOLDER mode
669 * (e.g. "/home/username/Documents/selected-folder/". To get the
670 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
671 * usual way to get the selection.
673 * Return value: the full path of the current folder, or %NULL if the current
674 * path cannot be represented as a local filename. Free with g_free(). This
675 * function will also return %NULL if the file chooser was unable to load the
676 * last folder that was requested from it; for example, as would be for calling
677 * gtk_file_chooser_set_current_folder() on a nonexistent folder.
682 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
687 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
689 file = gtk_file_chooser_get_current_folder_file (chooser);
693 filename = g_file_get_path (file);
694 g_object_unref (file);
700 * gtk_file_chooser_set_current_name:
701 * @chooser: a #GtkFileChooser
702 * @name: the filename to use, as a UTF-8 string
704 * Sets the current name in the file selector, as if entered
705 * by the user. Note that the name passed in here is a UTF-8
706 * string rather than a filename. This function is meant for
707 * such uses as a suggested name in a "Save As..." dialog.
709 * If you want to preselect a particular existing file, you should use
710 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
711 * Please see the documentation for those functions for an example of using
712 * gtk_file_chooser_set_current_name() as well.
717 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
720 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
721 g_return_if_fail (name != NULL);
723 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
727 * gtk_file_chooser_get_uri:
728 * @chooser: a #GtkFileChooser
730 * Gets the URI for the currently selected file in
731 * the file selector. If multiple files are selected,
732 * one of the filenames will be returned at random.
734 * If the file chooser is in folder mode, this function returns the selected
737 * Return value: The currently selected URI, or %NULL
738 * if no file is selected. Free with g_free()
743 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
746 gchar *result = NULL;
748 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
750 file = gtk_file_chooser_get_file (chooser);
753 result = g_file_get_uri (file);
754 g_object_unref (file);
761 * gtk_file_chooser_set_uri:
762 * @chooser: a #GtkFileChooser
763 * @uri: the URI to set as current
765 * Sets the file referred to by @uri as the current file for the file chooser,
766 * by changing to the URI's parent folder and actually selecting the URI in the
767 * list. If the @chooser is #GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
768 * name will also appear in the dialog's file name entry.
770 * If the URI isn't in the current folder of @chooser, then the current folder
771 * of @chooser will be changed to the folder containing @uri. This is equivalent
772 * to a sequence of gtk_file_chooser_unselect_all() followed by
773 * gtk_file_chooser_select_uri().
775 * Note that the URI must exist, or nothing will be done except for the
777 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
778 * you should use this function if you already have a file name to which the
779 * user may save; for example, when the user opens an existing file and then
780 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
781 * a file name already — for example, if the user just created a new
782 * file and is saving it for the first time, do not call this function.
783 * Instead, use something similar to this:
785 * if (document_is_new)
787 * /* the user just created a new document */
788 * gtk_file_chooser_set_current_folder_uri (chooser, default_folder_for_saving);
789 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
793 * /* the user edited an existing document */
794 * gtk_file_chooser_set_uri (chooser, existing_uri);
798 * Return value: %TRUE if both the folder could be changed and the URI was
799 * selected successfully, %FALSE otherwise.
804 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
807 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
809 gtk_file_chooser_unselect_all (chooser);
810 return gtk_file_chooser_select_uri (chooser, uri);
814 * gtk_file_chooser_select_uri:
815 * @chooser: a #GtkFileChooser
816 * @uri: the URI to select
818 * Selects the file to by @uri. If the URI doesn't refer to a
819 * file in the current folder of @chooser, then the current folder of
820 * @chooser will be changed to the folder containing @filename.
822 * Return value: %TRUE if both the folder could be changed and the URI was
823 * selected successfully, %FALSE otherwise.
828 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
834 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
835 g_return_val_if_fail (uri != NULL, FALSE);
837 file = g_file_new_for_uri (uri);
838 result = gtk_file_chooser_select_file (chooser, file, NULL);
839 g_object_unref (file);
845 * gtk_file_chooser_unselect_uri:
846 * @chooser: a #GtkFileChooser
847 * @uri: the URI to unselect
849 * Unselects the file referred to by @uri. If the file
850 * is not in the current directory, does not exist, or
851 * is otherwise not currently selected, does nothing.
856 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
861 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
862 g_return_if_fail (uri != NULL);
864 file = g_file_new_for_uri (uri);
865 gtk_file_chooser_unselect_file (chooser, file);
866 g_object_unref (file);
870 * gtk_file_chooser_select_all:
871 * @chooser: a #GtkFileChooser
873 * Selects all the files in the current folder of a file chooser.
878 gtk_file_chooser_select_all (GtkFileChooser *chooser)
880 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
882 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
886 * gtk_file_chooser_unselect_all:
887 * @chooser: a #GtkFileChooser
889 * Unselects all the files in the current folder of a file chooser.
894 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
897 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
899 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
903 * gtk_file_chooser_get_uris:
904 * @chooser: a #GtkFileChooser
906 * Lists all the selected files and subfolders in the current folder of
907 * @chooser. The returned names are full absolute URIs.
909 * Return value: a #GSList containing the URIs of all selected
910 * files and subfolders in the current folder. Free the returned list
911 * with g_slist_free(), and the filenames with g_free().
916 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
918 GSList *files, *result;
920 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
922 files = gtk_file_chooser_get_files (chooser);
924 result = files_to_strings (files, g_file_get_uri);
925 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
926 g_slist_free (files);
932 * gtk_file_chooser_set_current_folder_uri:
933 * @chooser: a #GtkFileChooser
934 * @uri: the URI for the new current folder
936 * Sets the current folder for @chooser from an URI.
937 * The user will be shown the full contents of the current folder,
938 * plus user interface elements for navigating to other folders.
940 * Return value: %TRUE if the folder could be changed successfully, %FALSE
946 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
952 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
953 g_return_val_if_fail (uri != NULL, FALSE);
955 file = g_file_new_for_uri (uri);
956 result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
957 g_object_unref (file);
963 * gtk_file_chooser_get_current_folder_uri:
964 * @chooser: a #GtkFileChooser
966 * Gets the current folder of @chooser as an URI.
967 * See gtk_file_chooser_set_current_folder_uri().
969 * Note that this is the folder that the file chooser is currently displaying
970 * (e.g. "file:///home/username/Documents"), which is <emphasis>not the same</emphasis>
971 * as the currently-selected folder if the chooser is in
972 * #GTK_FILE_CHOOSER_SELECT_FOLDER mode
973 * (e.g. "file:///home/username/Documents/selected-folder/". To get the
974 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
975 * usual way to get the selection.
977 * Return value: the URI for the current folder. Free with g_free(). This
978 * function will also return %NULL if the file chooser was unable to load the
979 * last folder that was requested from it; for example, as would be for calling
980 * gtk_file_chooser_set_current_folder_uri() on a nonexistent folder.
985 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
990 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
992 file = gtk_file_chooser_get_current_folder_file (chooser);
996 uri = g_file_get_uri (file);
997 g_object_unref (file);
1003 * gtk_file_chooser_set_current_folder_file:
1004 * @chooser: a #GtkFileChooser
1005 * @file: the #GFile for the new folder
1006 * @error: location to store error, or %NULL.
1008 * Sets the current folder for @chooser from a #GFile.
1009 * Internal function, see gtk_file_chooser_set_current_folder_uri().
1011 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1017 gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
1021 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1022 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1023 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1025 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, file, error);
1029 * gtk_file_chooser_get_current_folder_file:
1030 * @chooser: a #GtkFileChooser
1032 * Gets the current folder of @chooser as #GFile.
1033 * See gtk_file_chooser_get_current_folder_uri().
1035 * Return value: the #GFile for the current folder.
1040 gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser)
1042 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1044 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1048 * gtk_file_chooser_select_file:
1049 * @chooser: a #GtkFileChooser
1050 * @file: the file to select
1051 * @error: location to store error, or %NULL
1053 * Selects the file referred to by @file. An internal function. See
1054 * _gtk_file_chooser_select_uri().
1056 * Return value: %TRUE if both the folder could be changed and the path was
1057 * selected successfully, %FALSE otherwise.
1062 gtk_file_chooser_select_file (GtkFileChooser *chooser,
1066 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1067 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1068 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1070 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_file (chooser, file, error);
1074 * gtk_file_chooser_unselect_file:
1075 * @chooser: a #GtkFileChooser
1078 * Unselects the file referred to by @file. If the file is not in the current
1079 * directory, does not exist, or is otherwise not currently selected, does nothing.
1084 gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
1087 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1088 g_return_if_fail (G_IS_FILE (file));
1090 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_file (chooser, file);
1094 * gtk_file_chooser_get_files:
1095 * @chooser: a #GtkFileChooser
1097 * Lists all the selected files and subfolders in the current folder of @chooser
1098 * as #GFile. An internal function, see gtk_file_chooser_get_uris().
1100 * Return value: a #GSList containing a #GFile for each selected
1101 * file and subfolder in the current folder. Free the returned list
1102 * with g_slist_free(), and the files with g_object_unref().
1107 gtk_file_chooser_get_files (GtkFileChooser *chooser)
1109 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1111 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_files (chooser);
1115 * gtk_file_chooser_set_file:
1116 * @chooser: a #GtkFileChooser
1117 * @file: the #GFile to set as current
1118 * @error: location to store the error, or %NULL to ignore errors.
1120 * Sets @file as the current filename for the file chooser, by changing
1121 * to the file's parent folder and actually selecting the file in list. If
1122 * the @chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
1123 * will also appear in the dialog's file name entry.
1125 * If the file name isn't in the current folder of @chooser, then the current
1126 * folder of @chooser will be changed to the folder containing @filename. This
1127 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
1128 * gtk_file_chooser_select_filename().
1130 * Note that the file must exist, or nothing will be done except
1131 * for the directory change.
1133 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
1134 * you should use this function if you already have a file name to which the
1135 * user may save; for example, when the user opens an existing file and then
1136 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
1137 * a file name already — for example, if the user just created a new
1138 * file and is saving it for the first time, do not call this function.
1139 * Instead, use something similar to this:
1141 * if (document_is_new)
1143 * /* the user just created a new document */
1144 * gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
1145 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
1149 * /* the user edited an existing document */
1150 * gtk_file_chooser_set_file (chooser, existing_file);
1154 * Return value: %TRUE if both the folder could be changed and the file was
1155 * selected successfully, %FALSE otherwise.
1160 gtk_file_chooser_set_file (GtkFileChooser *chooser,
1164 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1165 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1166 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1168 gtk_file_chooser_unselect_all (chooser);
1169 return gtk_file_chooser_select_file (chooser, file, error);
1173 * gtk_file_chooser_get_file:
1174 * @chooser: a #GtkFileChooser
1176 * Gets the #GFile for the currently selected file in
1177 * the file selector. If multiple files are selected,
1178 * one of the files will be returned at random.
1180 * If the file chooser is in folder mode, this function returns the selected
1183 * Returns: a selected #GFile
1186 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1189 GFile *result = NULL;
1191 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1193 list = gtk_file_chooser_get_files (chooser);
1196 result = list->data;
1197 list = g_slist_delete_link (list, list);
1199 g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1200 g_slist_free (list);
1207 * _gtk_file_chooser_get_file_system:
1208 * @chooser: a #GtkFileChooser
1210 * Gets the #GtkFileSystem of @chooser; this is an internal
1211 * implementation detail, used for conversion between paths
1212 * and filenames and URIs.
1214 * Return value: the file system for @chooser.
1219 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1221 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1223 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1229 * gtk_file_chooser_set_preview_widget:
1230 * @chooser: a #GtkFileChooser
1231 * @preview_widget: widget for displaying preview.
1233 * Sets an application-supplied widget to use to display a custom preview
1234 * of the currently selected file. To implement a preview, after setting the
1235 * preview widget, you connect to the ::update-preview
1236 * signal, and call gtk_file_chooser_get_preview_filename() or
1237 * gtk_file_chooser_get_preview_uri() on each change. If you can
1238 * display a preview of the new file, update your widget and
1239 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1240 * Otherwise, set the preview inactive.
1242 * When there is no application-supplied preview widget, or the
1243 * application-supplied preview widget is not active, the file chooser
1244 * may display an internally generated preview of the current file or
1245 * it may display no preview at all.
1250 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1251 GtkWidget *preview_widget)
1253 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1255 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1259 * gtk_file_chooser_get_preview_widget:
1260 * @chooser: a #GtkFileChooser
1262 * Gets the current preview widget; see
1263 * gtk_file_chooser_set_preview_widget().
1265 * Return value: the current preview widget, or %NULL
1270 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1272 GtkWidget *preview_widget;
1274 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1276 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1278 /* Horrid hack; g_object_get() refs returned objects but
1279 * that contradicts the memory management conventions
1283 g_object_unref (preview_widget);
1285 return preview_widget;
1289 * gtk_file_chooser_set_preview_widget_active:
1290 * @chooser: a #GtkFileChooser
1291 * @active: whether to display the user-specified preview widget
1293 * Sets whether the preview widget set by
1294 * gtk_file_chooser_set_preview_widget() should be shown for the
1295 * current filename. When @active is set to false, the file chooser
1296 * may display an internally generated preview of the current file
1297 * or it may display no preview at all. See
1298 * gtk_file_chooser_set_preview_widget() for more details.
1303 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1306 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1308 g_object_set (chooser, "preview-widget-active", active, NULL);
1312 * gtk_file_chooser_get_preview_widget_active:
1313 * @chooser: a #GtkFileChooser
1315 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1316 * should be shown for the current filename. See
1317 * gtk_file_chooser_set_preview_widget_active().
1319 * Return value: %TRUE if the preview widget is active for the current filename.
1324 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1328 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1330 g_object_get (chooser, "preview-widget-active", &active, NULL);
1336 * gtk_file_chooser_set_use_preview_label:
1337 * @chooser: a #GtkFileChooser
1338 * @use_label: whether to display a stock label with the name of the previewed file
1340 * Sets whether the file chooser should display a stock label with the name of
1341 * the file that is being previewed; the default is %TRUE. Applications that
1342 * want to draw the whole preview area themselves should set this to %FALSE and
1343 * display the name themselves in their preview widget.
1345 * See also: gtk_file_chooser_set_preview_widget()
1350 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1353 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1355 g_object_set (chooser, "use-preview-label", use_label, NULL);
1359 * gtk_file_chooser_get_use_preview_label:
1360 * @chooser: a #GtkFileChooser
1362 * Gets whether a stock label should be drawn with the name of the previewed
1363 * file. See gtk_file_chooser_set_use_preview_label().
1365 * Return value: %TRUE if the file chooser is set to display a label with the
1366 * name of the previewed file, %FALSE otherwise.
1369 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1373 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1375 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1381 * gtk_file_chooser_get_preview_file:
1382 * @chooser: a #GtkFileChooser
1384 * Gets the #GFile that should be previewed in a custom preview
1385 * Internal function, see gtk_file_chooser_get_preview_uri().
1387 * Return value: the #GFile for the file to preview, or %NULL if no file
1388 * is selected. Free with g_object_unref().
1393 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
1395 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1397 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
1401 * _gtk_file_chooser_add_shortcut_folder:
1402 * @chooser: a #GtkFileChooser
1403 * @file: file for the folder to add
1404 * @error: location to store error, or %NULL
1406 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1407 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1409 * Return value: %TRUE if the folder could be added successfully, %FALSE
1415 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1419 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1420 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1422 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1426 * _gtk_file_chooser_remove_shortcut_folder:
1427 * @chooser: a #GtkFileChooser
1428 * @file: file for the folder to remove
1429 * @error: location to store error, or %NULL
1431 * Removes a folder from the shortcut folders in a file chooser. Internal
1432 * function, see gtk_file_chooser_remove_shortcut_folder().
1434 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1440 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1444 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1445 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1447 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1451 * gtk_file_chooser_get_preview_filename:
1452 * @chooser: a #GtkFileChooser
1454 * Gets the filename that should be previewed in a custom preview
1455 * widget. See gtk_file_chooser_set_preview_widget().
1457 * Return value: the filename to preview, or %NULL if no file
1458 * is selected, or if the selected file cannot be represented
1459 * as a local filename. Free with g_free()
1464 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1467 gchar *result = NULL;
1469 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1471 file = gtk_file_chooser_get_preview_file (chooser);
1474 result = g_file_get_path (file);
1475 g_object_unref (file);
1482 * gtk_file_chooser_get_preview_uri:
1483 * @chooser: a #GtkFileChooser
1485 * Gets the URI that should be previewed in a custom preview
1486 * widget. See gtk_file_chooser_set_preview_widget().
1488 * Return value: the URI for the file to preview, or %NULL if no file is
1489 * selected. Free with g_free().
1494 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1497 gchar *result = NULL;
1499 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1501 file = gtk_file_chooser_get_preview_file (chooser);
1504 result = g_file_get_uri (file);
1505 g_object_unref (file);
1512 * gtk_file_chooser_set_extra_widget:
1513 * @chooser: a #GtkFileChooser
1514 * @extra_widget: widget for extra options
1516 * Sets an application-supplied widget to provide extra options to the user.
1521 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1522 GtkWidget *extra_widget)
1524 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1526 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1530 * gtk_file_chooser_get_extra_widget:
1531 * @chooser: a #GtkFileChooser
1533 * Gets the current preview widget; see
1534 * gtk_file_chooser_set_extra_widget().
1536 * Return value: the current extra widget, or %NULL
1541 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1543 GtkWidget *extra_widget;
1545 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1547 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1549 /* Horrid hack; g_object_get() refs returned objects but
1550 * that contradicts the memory management conventions
1554 g_object_unref (extra_widget);
1556 return extra_widget;
1560 * gtk_file_chooser_add_filter:
1561 * @chooser: a #GtkFileChooser
1562 * @filter: a #GtkFileFilter
1564 * Adds @filter to the list of filters that the user can select between.
1565 * When a filter is selected, only files that are passed by that
1566 * filter are displayed.
1568 * Note that the @chooser takes ownership of the filter, so you have to
1569 * ref and sink it if you want to keep a reference.
1574 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1575 GtkFileFilter *filter)
1577 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1579 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1583 * gtk_file_chooser_remove_filter:
1584 * @chooser: a #GtkFileChooser
1585 * @filter: a #GtkFileFilter
1587 * Removes @filter from the list of filters that the user can select between.
1592 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1593 GtkFileFilter *filter)
1595 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1597 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1601 * gtk_file_chooser_list_filters:
1602 * @chooser: a #GtkFileChooser
1604 * Lists the current set of user-selectable filters; see
1605 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1607 * Return value: a #GSList containing the current set of
1608 * user selectable filters. The contents of the list are
1609 * owned by GTK+, but you must free the list itself with
1610 * g_slist_free() when you are done with it.
1615 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1617 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1619 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1623 * gtk_file_chooser_set_filter:
1624 * @chooser: a #GtkFileChooser
1625 * @filter: a #GtkFileFilter
1627 * Sets the current filter; only the files that pass the
1628 * filter will be displayed. If the user-selectable list of filters
1629 * is non-empty, then the filter should be one of the filters
1630 * in that list. Setting the current filter when the list of
1631 * filters is empty is useful if you want to restrict the displayed
1632 * set of files without letting the user change it.
1637 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1638 GtkFileFilter *filter)
1640 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1641 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1643 g_object_set (chooser, "filter", filter, NULL);
1647 * gtk_file_chooser_get_filter:
1648 * @chooser: a #GtkFileChooser
1650 * Gets the current filter; see gtk_file_chooser_set_filter().
1652 * Return value: the current filter, or %NULL
1657 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1659 GtkFileFilter *filter;
1661 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1663 g_object_get (chooser, "filter", &filter, NULL);
1664 /* Horrid hack; g_object_get() refs returned objects but
1665 * that contradicts the memory management conventions
1669 g_object_unref (filter);
1675 * gtk_file_chooser_add_shortcut_folder:
1676 * @chooser: a #GtkFileChooser
1677 * @folder: filename of the folder to add
1678 * @error: location to store error, or %NULL
1680 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1681 * Note that shortcut folders do not get saved, as they are provided by the
1682 * application. For example, you can use this to add a
1683 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1685 * Return value: %TRUE if the folder could be added successfully, %FALSE
1686 * otherwise. In the latter case, the @error will be set as appropriate.
1691 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1698 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1699 g_return_val_if_fail (folder != NULL, FALSE);
1701 file = g_file_new_for_path (folder);
1702 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1703 g_object_unref (file);
1709 * gtk_file_chooser_remove_shortcut_folder:
1710 * @chooser: a #GtkFileChooser
1711 * @folder: filename of the folder to remove
1712 * @error: location to store error, or %NULL
1714 * Removes a folder from a file chooser's list of shortcut folders.
1716 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1717 * In the latter case, the @error will be set as appropriate.
1719 * See also: gtk_file_chooser_add_shortcut_folder()
1724 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1731 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1732 g_return_val_if_fail (folder != NULL, FALSE);
1734 file = g_file_new_for_path (folder);
1735 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1736 g_object_unref (file);
1742 * gtk_file_chooser_list_shortcut_folders:
1743 * @chooser: a #GtkFileChooser
1745 * Queries the list of shortcut folders in the file chooser, as set by
1746 * gtk_file_chooser_add_shortcut_folder().
1748 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1749 * folders. Free the returned list with g_slist_free(), and the filenames with
1755 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1760 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1762 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1764 result = files_to_strings (folders, g_file_get_path);
1765 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1766 g_slist_free (folders);
1772 * gtk_file_chooser_add_shortcut_folder_uri:
1773 * @chooser: a #GtkFileChooser
1774 * @uri: URI of the folder to add
1775 * @error: location to store error, or %NULL
1777 * Adds a folder URI to be displayed with the shortcut folders in a file
1778 * chooser. Note that shortcut folders do not get saved, as they are provided
1779 * by the application. For example, you can use this to add a
1780 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1782 * Return value: %TRUE if the folder could be added successfully, %FALSE
1783 * otherwise. In the latter case, the @error will be set as appropriate.
1788 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1795 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1796 g_return_val_if_fail (uri != NULL, FALSE);
1798 file = g_file_new_for_uri (uri);
1799 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1800 g_object_unref (file);
1806 * gtk_file_chooser_remove_shortcut_folder_uri:
1807 * @chooser: a #GtkFileChooser
1808 * @uri: URI of the folder to remove
1809 * @error: location to store error, or %NULL
1811 * Removes a folder URI from a file chooser's list of shortcut folders.
1813 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1814 * In the latter case, the @error will be set as appropriate.
1816 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1821 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1828 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1829 g_return_val_if_fail (uri != NULL, FALSE);
1831 file = g_file_new_for_uri (uri);
1832 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1833 g_object_unref (file);
1839 * gtk_file_chooser_list_shortcut_folder_uris:
1840 * @chooser: a #GtkFileChooser
1842 * Queries the list of shortcut folders in the file chooser, as set by
1843 * gtk_file_chooser_add_shortcut_folder_uri().
1845 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1846 * folders. Free the returned list with g_slist_free(), and the URIs with
1852 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1857 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1859 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1861 result = files_to_strings (folders, g_file_get_uri);
1862 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1863 g_slist_free (folders);
1870 * gtk_file_chooser_set_show_hidden:
1871 * @chooser: a #GtkFileChooser
1872 * @show_hidden: %TRUE if hidden files and folders should be displayed.
1874 * Sets whether hidden files and folders are displayed in the file selector.
1879 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1880 gboolean show_hidden)
1882 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1884 g_object_set (chooser, "show-hidden", show_hidden, NULL);
1888 * gtk_file_chooser_get_show_hidden:
1889 * @chooser: a #GtkFileChooser
1891 * Gets whether hidden files and folders are displayed in the file selector.
1892 * See gtk_file_chooser_set_show_hidden().
1894 * Return value: %TRUE if hidden files and folders are displayed.
1899 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1901 gboolean show_hidden;
1903 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1905 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1911 * gtk_file_chooser_set_do_overwrite_confirmation:
1912 * @chooser: a #GtkFileChooser
1913 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1915 * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1916 * a confirmation dialog if the user types a file name that already exists. This
1917 * is %FALSE by default.
1919 * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1920 * signal when appropriate.
1922 * If all you need is the stock confirmation dialog, set this property to %TRUE.
1923 * You can override the way confirmation is done by actually handling the
1924 * "confirm-overwrite" signal; please refer to its documentation for the
1930 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
1931 gboolean do_overwrite_confirmation)
1933 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1935 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
1939 * gtk_file_chooser_get_do_overwrite_confirmation:
1940 * @chooser: a #GtkFileChooser
1942 * Queries whether a file chooser is set to confirm for overwriting when the user
1943 * types a file name that already exists.
1945 * Return value: %TRUE if the file chooser will present a confirmation dialog;
1951 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
1953 gboolean do_overwrite_confirmation;
1955 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1957 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
1959 return do_overwrite_confirmation;
1964 /* DLL ABI stability backward compatibility versions */
1966 #undef gtk_file_chooser_get_filename
1969 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
1971 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
1972 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
1974 g_free (utf8_filename);
1979 #undef gtk_file_chooser_set_filename
1982 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
1983 const gchar *filename)
1985 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
1986 gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
1988 g_free (utf8_filename);
1993 #undef gtk_file_chooser_select_filename
1996 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
1997 const gchar *filename)
1999 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2000 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2002 g_free (utf8_filename);
2007 #undef gtk_file_chooser_unselect_filename
2010 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2011 const char *filename)
2013 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2015 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2016 g_free (utf8_filename);
2019 #undef gtk_file_chooser_get_filenames
2022 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2024 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2025 GSList *rover = list;
2029 gchar *tem = (gchar *) rover->data;
2030 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2032 rover = rover->next;
2038 #undef gtk_file_chooser_set_current_folder
2041 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2042 const gchar *filename)
2044 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2045 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2047 g_free (utf8_filename);
2052 #undef gtk_file_chooser_get_current_folder
2055 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2057 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2058 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2060 g_free (utf8_folder);
2065 #undef gtk_file_chooser_get_preview_filename
2068 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2070 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2071 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2073 g_free (utf8_filename);
2078 #undef gtk_file_chooser_add_shortcut_folder
2081 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2085 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2087 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2089 g_free (utf8_folder);
2094 #undef gtk_file_chooser_remove_shortcut_folder
2097 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2101 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2103 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2105 g_free (utf8_folder);
2110 #undef gtk_file_chooser_list_shortcut_folders
2113 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2115 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2116 GSList *rover = list;
2120 gchar *tem = (gchar *) rover->data;
2121 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2123 rover = rover->next;
2131 #define __GTK_FILE_CHOOSER_C__
2132 #include "gtkaliasdef.c"