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
1188 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1191 GFile *result = NULL;
1193 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1195 list = gtk_file_chooser_get_files (chooser);
1198 result = list->data;
1199 list = g_slist_delete_link (list, list);
1201 g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1202 g_slist_free (list);
1209 * _gtk_file_chooser_get_file_system:
1210 * @chooser: a #GtkFileChooser
1212 * Gets the #GtkFileSystem of @chooser; this is an internal
1213 * implementation detail, used for conversion between paths
1214 * and filenames and URIs.
1216 * Return value: the file system for @chooser.
1221 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1223 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1225 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1231 * gtk_file_chooser_set_preview_widget:
1232 * @chooser: a #GtkFileChooser
1233 * @preview_widget: widget for displaying preview.
1235 * Sets an application-supplied widget to use to display a custom preview
1236 * of the currently selected file. To implement a preview, after setting the
1237 * preview widget, you connect to the ::update-preview
1238 * signal, and call gtk_file_chooser_get_preview_filename() or
1239 * gtk_file_chooser_get_preview_uri() on each change. If you can
1240 * display a preview of the new file, update your widget and
1241 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1242 * Otherwise, set the preview inactive.
1244 * When there is no application-supplied preview widget, or the
1245 * application-supplied preview widget is not active, the file chooser
1246 * may display an internally generated preview of the current file or
1247 * it may display no preview at all.
1252 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1253 GtkWidget *preview_widget)
1255 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1257 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1261 * gtk_file_chooser_get_preview_widget:
1262 * @chooser: a #GtkFileChooser
1264 * Gets the current preview widget; see
1265 * gtk_file_chooser_set_preview_widget().
1267 * Return value: the current preview widget, or %NULL
1272 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1274 GtkWidget *preview_widget;
1276 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1278 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1280 /* Horrid hack; g_object_get() refs returned objects but
1281 * that contradicts the memory management conventions
1285 g_object_unref (preview_widget);
1287 return preview_widget;
1291 * gtk_file_chooser_set_preview_widget_active:
1292 * @chooser: a #GtkFileChooser
1293 * @active: whether to display the user-specified preview widget
1295 * Sets whether the preview widget set by
1296 * gtk_file_chooser_set_preview_widget() should be shown for the
1297 * current filename. When @active is set to false, the file chooser
1298 * may display an internally generated preview of the current file
1299 * or it may display no preview at all. See
1300 * gtk_file_chooser_set_preview_widget() for more details.
1305 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1308 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1310 g_object_set (chooser, "preview-widget-active", active, NULL);
1314 * gtk_file_chooser_get_preview_widget_active:
1315 * @chooser: a #GtkFileChooser
1317 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1318 * should be shown for the current filename. See
1319 * gtk_file_chooser_set_preview_widget_active().
1321 * Return value: %TRUE if the preview widget is active for the current filename.
1326 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1330 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1332 g_object_get (chooser, "preview-widget-active", &active, NULL);
1338 * gtk_file_chooser_set_use_preview_label:
1339 * @chooser: a #GtkFileChooser
1340 * @use_label: whether to display a stock label with the name of the previewed file
1342 * Sets whether the file chooser should display a stock label with the name of
1343 * the file that is being previewed; the default is %TRUE. Applications that
1344 * want to draw the whole preview area themselves should set this to %FALSE and
1345 * display the name themselves in their preview widget.
1347 * See also: gtk_file_chooser_set_preview_widget()
1352 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1355 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1357 g_object_set (chooser, "use-preview-label", use_label, NULL);
1361 * gtk_file_chooser_get_use_preview_label:
1362 * @chooser: a #GtkFileChooser
1364 * Gets whether a stock label should be drawn with the name of the previewed
1365 * file. See gtk_file_chooser_set_use_preview_label().
1367 * Return value: %TRUE if the file chooser is set to display a label with the
1368 * name of the previewed file, %FALSE otherwise.
1371 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1375 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1377 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1383 * gtk_file_chooser_get_preview_file:
1384 * @chooser: a #GtkFileChooser
1386 * Gets the #GFile that should be previewed in a custom preview
1387 * Internal function, see gtk_file_chooser_get_preview_uri().
1389 * Return value: the #GFile for the file to preview, or %NULL if no file
1390 * is selected. Free with g_object_unref().
1395 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
1397 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1399 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
1403 * _gtk_file_chooser_add_shortcut_folder:
1404 * @chooser: a #GtkFileChooser
1405 * @file: file for the folder to add
1406 * @error: location to store error, or %NULL
1408 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1409 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1411 * Return value: %TRUE if the folder could be added successfully, %FALSE
1417 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1421 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1422 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1424 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1428 * _gtk_file_chooser_remove_shortcut_folder:
1429 * @chooser: a #GtkFileChooser
1430 * @file: file for the folder to remove
1431 * @error: location to store error, or %NULL
1433 * Removes a folder from the shortcut folders in a file chooser. Internal
1434 * function, see gtk_file_chooser_remove_shortcut_folder().
1436 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1442 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1446 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1447 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1449 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1453 * gtk_file_chooser_get_preview_filename:
1454 * @chooser: a #GtkFileChooser
1456 * Gets the filename that should be previewed in a custom preview
1457 * widget. See gtk_file_chooser_set_preview_widget().
1459 * Return value: the filename to preview, or %NULL if no file
1460 * is selected, or if the selected file cannot be represented
1461 * as a local filename. Free with g_free()
1466 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1469 gchar *result = NULL;
1471 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1473 file = gtk_file_chooser_get_preview_file (chooser);
1476 result = g_file_get_path (file);
1477 g_object_unref (file);
1484 * gtk_file_chooser_get_preview_uri:
1485 * @chooser: a #GtkFileChooser
1487 * Gets the URI that should be previewed in a custom preview
1488 * widget. See gtk_file_chooser_set_preview_widget().
1490 * Return value: the URI for the file to preview, or %NULL if no file is
1491 * selected. Free with g_free().
1496 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1499 gchar *result = NULL;
1501 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1503 file = gtk_file_chooser_get_preview_file (chooser);
1506 result = g_file_get_uri (file);
1507 g_object_unref (file);
1514 * gtk_file_chooser_set_extra_widget:
1515 * @chooser: a #GtkFileChooser
1516 * @extra_widget: widget for extra options
1518 * Sets an application-supplied widget to provide extra options to the user.
1523 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1524 GtkWidget *extra_widget)
1526 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1528 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1532 * gtk_file_chooser_get_extra_widget:
1533 * @chooser: a #GtkFileChooser
1535 * Gets the current preview widget; see
1536 * gtk_file_chooser_set_extra_widget().
1538 * Return value: the current extra widget, or %NULL
1543 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1545 GtkWidget *extra_widget;
1547 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1549 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1551 /* Horrid hack; g_object_get() refs returned objects but
1552 * that contradicts the memory management conventions
1556 g_object_unref (extra_widget);
1558 return extra_widget;
1562 * gtk_file_chooser_add_filter:
1563 * @chooser: a #GtkFileChooser
1564 * @filter: a #GtkFileFilter
1566 * Adds @filter to the list of filters that the user can select between.
1567 * When a filter is selected, only files that are passed by that
1568 * filter are displayed.
1570 * Note that the @chooser takes ownership of the filter, so you have to
1571 * ref and sink it if you want to keep a reference.
1576 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1577 GtkFileFilter *filter)
1579 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1581 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1585 * gtk_file_chooser_remove_filter:
1586 * @chooser: a #GtkFileChooser
1587 * @filter: a #GtkFileFilter
1589 * Removes @filter from the list of filters that the user can select between.
1594 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1595 GtkFileFilter *filter)
1597 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1599 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1603 * gtk_file_chooser_list_filters:
1604 * @chooser: a #GtkFileChooser
1606 * Lists the current set of user-selectable filters; see
1607 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1609 * Return value: a #GSList containing the current set of
1610 * user selectable filters. The contents of the list are
1611 * owned by GTK+, but you must free the list itself with
1612 * g_slist_free() when you are done with it.
1617 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1619 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1621 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1625 * gtk_file_chooser_set_filter:
1626 * @chooser: a #GtkFileChooser
1627 * @filter: a #GtkFileFilter
1629 * Sets the current filter; only the files that pass the
1630 * filter will be displayed. If the user-selectable list of filters
1631 * is non-empty, then the filter should be one of the filters
1632 * in that list. Setting the current filter when the list of
1633 * filters is empty is useful if you want to restrict the displayed
1634 * set of files without letting the user change it.
1639 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1640 GtkFileFilter *filter)
1642 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1643 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1645 g_object_set (chooser, "filter", filter, NULL);
1649 * gtk_file_chooser_get_filter:
1650 * @chooser: a #GtkFileChooser
1652 * Gets the current filter; see gtk_file_chooser_set_filter().
1654 * Return value: the current filter, or %NULL
1659 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1661 GtkFileFilter *filter;
1663 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1665 g_object_get (chooser, "filter", &filter, NULL);
1666 /* Horrid hack; g_object_get() refs returned objects but
1667 * that contradicts the memory management conventions
1671 g_object_unref (filter);
1677 * gtk_file_chooser_add_shortcut_folder:
1678 * @chooser: a #GtkFileChooser
1679 * @folder: filename of the folder to add
1680 * @error: location to store error, or %NULL
1682 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1683 * Note that shortcut folders do not get saved, as they are provided by the
1684 * application. For example, you can use this to add a
1685 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1687 * Return value: %TRUE if the folder could be added successfully, %FALSE
1688 * otherwise. In the latter case, the @error will be set as appropriate.
1693 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1700 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1701 g_return_val_if_fail (folder != NULL, FALSE);
1703 file = g_file_new_for_path (folder);
1704 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1705 g_object_unref (file);
1711 * gtk_file_chooser_remove_shortcut_folder:
1712 * @chooser: a #GtkFileChooser
1713 * @folder: filename of the folder to remove
1714 * @error: location to store error, or %NULL
1716 * Removes a folder from a file chooser's list of shortcut folders.
1718 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1719 * In the latter case, the @error will be set as appropriate.
1721 * See also: gtk_file_chooser_add_shortcut_folder()
1726 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1733 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1734 g_return_val_if_fail (folder != NULL, FALSE);
1736 file = g_file_new_for_path (folder);
1737 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1738 g_object_unref (file);
1744 * gtk_file_chooser_list_shortcut_folders:
1745 * @chooser: a #GtkFileChooser
1747 * Queries the list of shortcut folders in the file chooser, as set by
1748 * gtk_file_chooser_add_shortcut_folder().
1750 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1751 * folders. Free the returned list with g_slist_free(), and the filenames with
1757 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1762 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1764 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1766 result = files_to_strings (folders, g_file_get_path);
1767 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1768 g_slist_free (folders);
1774 * gtk_file_chooser_add_shortcut_folder_uri:
1775 * @chooser: a #GtkFileChooser
1776 * @uri: URI of the folder to add
1777 * @error: location to store error, or %NULL
1779 * Adds a folder URI to be displayed with the shortcut folders in a file
1780 * chooser. Note that shortcut folders do not get saved, as they are provided
1781 * by the application. For example, you can use this to add a
1782 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1784 * Return value: %TRUE if the folder could be added successfully, %FALSE
1785 * otherwise. In the latter case, the @error will be set as appropriate.
1790 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1797 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1798 g_return_val_if_fail (uri != NULL, FALSE);
1800 file = g_file_new_for_uri (uri);
1801 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1802 g_object_unref (file);
1808 * gtk_file_chooser_remove_shortcut_folder_uri:
1809 * @chooser: a #GtkFileChooser
1810 * @uri: URI of the folder to remove
1811 * @error: location to store error, or %NULL
1813 * Removes a folder URI from a file chooser's list of shortcut folders.
1815 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1816 * In the latter case, the @error will be set as appropriate.
1818 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1823 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1830 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1831 g_return_val_if_fail (uri != NULL, FALSE);
1833 file = g_file_new_for_uri (uri);
1834 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1835 g_object_unref (file);
1841 * gtk_file_chooser_list_shortcut_folder_uris:
1842 * @chooser: a #GtkFileChooser
1844 * Queries the list of shortcut folders in the file chooser, as set by
1845 * gtk_file_chooser_add_shortcut_folder_uri().
1847 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1848 * folders. Free the returned list with g_slist_free(), and the URIs with
1854 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1859 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1861 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1863 result = files_to_strings (folders, g_file_get_uri);
1864 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1865 g_slist_free (folders);
1871 _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
1873 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1875 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
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;
1971 #if defined (G_OS_WIN32) && !defined (_WIN64)
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"