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));
274 * GtkFileChooser:create-folders:
276 * Whether a file chooser not in %GTK_FILE_CHOOSER_ACTION_OPEN mode
277 * will offer the user to create new folders.
281 g_object_interface_install_property (g_iface,
282 g_param_spec_boolean ("create-folders",
283 P_("Allow folders creation"),
284 P_("Whether a file chooser not in open mode "
285 "will offer the user to create new folders."),
287 GTK_PARAM_READWRITE));
291 * gtk_file_chooser_error_quark:
293 * Registers an error quark for #GtkFileChooser if necessary.
295 * Return value: The error quark used for #GtkFileChooser errors.
300 gtk_file_chooser_error_quark (void)
302 return g_quark_from_static_string ("gtk-file-chooser-error-quark");
306 * gtk_file_chooser_set_action:
307 * @chooser: a #GtkFileChooser
308 * @action: the action that the file selector is performing
310 * Sets the type of operation that the chooser is performing; the
311 * user interface is adapted to suit the selected action. For example,
312 * an option to create a new folder might be shown if the action is
313 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
314 * %GTK_FILE_CHOOSER_ACTION_OPEN.
319 gtk_file_chooser_set_action (GtkFileChooser *chooser,
320 GtkFileChooserAction action)
322 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
324 g_object_set (chooser, "action", action, NULL);
328 * gtk_file_chooser_get_action:
329 * @chooser: a #GtkFileChooser
331 * Gets the type of operation that the file chooser is performing; see
332 * gtk_file_chooser_set_action().
334 * Return value: the action that the file selector is performing
339 gtk_file_chooser_get_action (GtkFileChooser *chooser)
341 GtkFileChooserAction action;
343 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
345 g_object_get (chooser, "action", &action, NULL);
351 * gtk_file_chooser_set_local_only:
352 * @chooser: a #GtkFileChooser
353 * @local_only: %TRUE if only local files can be selected
355 * Sets whether only local files can be selected in the
356 * file selector. If @local_only is %TRUE (the default),
357 * then the selected file are files are guaranteed to be
358 * accessible through the operating systems native file
359 * file system and therefore the application only
360 * needs to worry about the filename functions in
361 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
362 * rather than the URI functions like
363 * gtk_file_chooser_get_uri(),
368 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
371 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
373 g_object_set (chooser, "local-only", local_only, NULL);
377 * gtk_file_chooser_get_local_only:
378 * @chooser: a #GtkFileChoosre
380 * Gets whether only local files can be selected in the
381 * file selector. See gtk_file_chooser_set_local_only()
383 * Return value: %TRUE if only local files can be selected.
388 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
392 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
394 g_object_get (chooser, "local-only", &local_only, NULL);
400 * gtk_file_chooser_set_select_multiple:
401 * @chooser: a #GtkFileChooser
402 * @select_multiple: %TRUE if multiple files can be selected.
404 * Sets whether multiple files can be selected in the file selector. This is
405 * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
406 * GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
411 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
412 gboolean select_multiple)
414 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
416 g_object_set (chooser, "select-multiple", select_multiple, NULL);
420 * gtk_file_chooser_get_select_multiple:
421 * @chooser: a #GtkFileChooser
423 * Gets whether multiple files can be selected in the file
424 * selector. See gtk_file_chooser_set_select_multiple().
426 * Return value: %TRUE if multiple files can be selected.
431 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
433 gboolean select_multiple;
435 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
437 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
439 return select_multiple;
443 * gtk_file_chooser_set_create_folders:
444 * @chooser: a #GtkFileChooser
445 * @create_folders: %TRUE if the New Folder button should be displayed
447 * Sets whether file choser will offer to create new folders.
448 * This is only relevant if the action is not set to be
449 * GTK_FILE_CHOOSER_ACTION_OPEN.
454 gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
455 gboolean create_folders)
457 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
459 g_object_set (chooser, "create-folders", create_folders, NULL);
463 * gtk_file_chooser_get_create_folders:
464 * @chooser: a #GtkFileChooser
466 * Gets whether file choser will offer to create new folders.
467 * See gtk_file_chooser_set_create_folders().
469 * Return value: %TRUE if the New Folder button should be displayed.
474 gtk_file_chooser_get_create_folders (GtkFileChooser *chooser)
476 gboolean create_folders;
478 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
480 g_object_get (chooser, "create-folders", &create_folders, NULL);
482 return create_folders;
486 * gtk_file_chooser_get_filename:
487 * @chooser: a #GtkFileChooser
489 * Gets the filename for the currently selected file in
490 * the file selector. If multiple files are selected,
491 * one of the filenames will be returned at random.
493 * If the file chooser is in folder mode, this function returns the selected
496 * Return value: The currently selected filename, or %NULL
497 * if no file is selected, or the selected file can't
498 * be represented with a local filename. Free with g_free().
503 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
506 gchar *result = NULL;
508 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
510 file = gtk_file_chooser_get_file (chooser);
514 result = g_file_get_path (file);
515 g_object_unref (file);
522 * gtk_file_chooser_set_filename:
523 * @chooser: a #GtkFileChooser
524 * @filename: the filename to set as current
526 * Sets @filename as the current filename for the file chooser, by changing
527 * to the file's parent folder and actually selecting the file in list. If
528 * the @chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
529 * will also appear in the dialog's file name entry.
531 * If the file name isn't in the current folder of @chooser, then the current
532 * folder of @chooser will be changed to the folder containing @filename. This
533 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
534 * gtk_file_chooser_select_filename().
536 * Note that the file must exist, or nothing will be done except
537 * for the directory change.
539 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
540 * you should use this function if you already have a file name to which the
541 * user may save; for example, when the user opens an existing file and then
542 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
543 * a file name already — for example, if the user just created a new
544 * file and is saving it for the first time, do not call this function.
545 * Instead, use something similar to this:
547 * if (document_is_new)
549 * /* the user just created a new document */
550 * gtk_file_chooser_set_current_folder (chooser, default_folder_for_saving);
551 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
555 * /* the user edited an existing document */
556 * gtk_file_chooser_set_filename (chooser, existing_filename);
560 * Return value: %TRUE if both the folder could be changed and the file was
561 * selected successfully, %FALSE otherwise.
566 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
567 const gchar *filename)
569 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
571 gtk_file_chooser_unselect_all (chooser);
572 return gtk_file_chooser_select_filename (chooser, filename);
576 * gtk_file_chooser_select_filename:
577 * @chooser: a #GtkFileChooser
578 * @filename: the filename to select
580 * Selects a filename. If the file name isn't in the current
581 * folder of @chooser, then the current folder of @chooser will
582 * be changed to the folder containing @filename.
584 * Return value: %TRUE if both the folder could be changed and the file was
585 * selected successfully, %FALSE otherwise.
590 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
591 const gchar *filename)
596 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
597 g_return_val_if_fail (filename != NULL, FALSE);
599 file = g_file_new_for_path (filename);
600 result = gtk_file_chooser_select_file (chooser, file, NULL);
601 g_object_unref (file);
607 * gtk_file_chooser_unselect_filename:
608 * @chooser: a #GtkFileChooser
609 * @filename: the filename to unselect
611 * Unselects a currently selected filename. If the filename
612 * is not in the current directory, does not exist, or
613 * is otherwise not currently selected, does nothing.
618 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
619 const char *filename)
623 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
624 g_return_if_fail (filename != NULL);
626 file = g_file_new_for_path (filename);
627 gtk_file_chooser_unselect_file (chooser, file);
628 g_object_unref (file);
631 /* Converts a list of GFile* to a list of strings using the specified function */
633 files_to_strings (GSList *files,
634 gchar * (*convert_func) (GFile *file))
640 for (; files; files = files->next)
646 string = (* convert_func) (file);
649 strings = g_slist_prepend (strings, string);
652 return g_slist_reverse (strings);
656 * gtk_file_chooser_get_filenames:
657 * @chooser: a #GtkFileChooser
659 * Lists all the selected files and subfolders in the current folder of
660 * @chooser. The returned names are full absolute paths. If files in the current
661 * folder cannot be represented as local filenames they will be ignored. (See
662 * gtk_file_chooser_get_uris())
664 * Return value: a #GSList containing the filenames of all selected
665 * files and subfolders in the current folder. Free the returned list
666 * with g_slist_free(), and the filenames with g_free().
671 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
673 GSList *files, *result;
675 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
677 files = gtk_file_chooser_get_files (chooser);
679 result = files_to_strings (files, g_file_get_path);
680 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
681 g_slist_free (files);
687 * gtk_file_chooser_set_current_folder:
688 * @chooser: a #GtkFileChooser
689 * @filename: the full path of the new current folder
691 * Sets the current folder for @chooser from a local filename.
692 * The user will be shown the full contents of the current folder,
693 * plus user interface elements for navigating to other folders.
695 * Return value: %TRUE if the folder could be changed successfully, %FALSE
701 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
702 const gchar *filename)
707 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
708 g_return_val_if_fail (filename != NULL, FALSE);
710 file = g_file_new_for_path (filename);
711 result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
712 g_object_unref (file);
718 * gtk_file_chooser_get_current_folder:
719 * @chooser: a #GtkFileChooser
721 * Gets the current folder of @chooser as a local filename.
722 * See gtk_file_chooser_set_current_folder().
724 * Note that this is the folder that the file chooser is currently displaying
725 * (e.g. "/home/username/Documents"), which is <emphasis>not the same</emphasis>
726 * as the currently-selected folder if the chooser is in
727 * #GTK_FILE_CHOOSER_SELECT_FOLDER mode
728 * (e.g. "/home/username/Documents/selected-folder/". To get the
729 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
730 * usual way to get the selection.
732 * Return value: the full path of the current folder, or %NULL if the current
733 * path cannot be represented as a local filename. Free with g_free(). This
734 * function will also return %NULL if the file chooser was unable to load the
735 * last folder that was requested from it; for example, as would be for calling
736 * gtk_file_chooser_set_current_folder() on a nonexistent folder.
741 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
746 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
748 file = gtk_file_chooser_get_current_folder_file (chooser);
752 filename = g_file_get_path (file);
753 g_object_unref (file);
759 * gtk_file_chooser_set_current_name:
760 * @chooser: a #GtkFileChooser
761 * @name: the filename to use, as a UTF-8 string
763 * Sets the current name in the file selector, as if entered
764 * by the user. Note that the name passed in here is a UTF-8
765 * string rather than a filename. This function is meant for
766 * such uses as a suggested name in a "Save As..." dialog.
768 * If you want to preselect a particular existing file, you should use
769 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
770 * Please see the documentation for those functions for an example of using
771 * gtk_file_chooser_set_current_name() as well.
776 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
779 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
780 g_return_if_fail (name != NULL);
782 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
786 * gtk_file_chooser_get_uri:
787 * @chooser: a #GtkFileChooser
789 * Gets the URI for the currently selected file in
790 * the file selector. If multiple files are selected,
791 * one of the filenames will be returned at random.
793 * If the file chooser is in folder mode, this function returns the selected
796 * Return value: The currently selected URI, or %NULL
797 * if no file is selected. Free with g_free()
802 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
805 gchar *result = NULL;
807 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
809 file = gtk_file_chooser_get_file (chooser);
812 result = g_file_get_uri (file);
813 g_object_unref (file);
820 * gtk_file_chooser_set_uri:
821 * @chooser: a #GtkFileChooser
822 * @uri: the URI to set as current
824 * Sets the file referred to by @uri as the current file for the file chooser,
825 * by changing to the URI's parent folder and actually selecting the URI in the
826 * list. If the @chooser is #GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
827 * name will also appear in the dialog's file name entry.
829 * If the URI isn't in the current folder of @chooser, then the current folder
830 * of @chooser will be changed to the folder containing @uri. This is equivalent
831 * to a sequence of gtk_file_chooser_unselect_all() followed by
832 * gtk_file_chooser_select_uri().
834 * Note that the URI must exist, or nothing will be done except for the
836 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
837 * you should use this function if you already have a file name to which the
838 * user may save; for example, when the user opens an existing file and then
839 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
840 * a file name already — for example, if the user just created a new
841 * file and is saving it for the first time, do not call this function.
842 * Instead, use something similar to this:
844 * if (document_is_new)
846 * /* the user just created a new document */
847 * gtk_file_chooser_set_current_folder_uri (chooser, default_folder_for_saving);
848 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
852 * /* the user edited an existing document */
853 * gtk_file_chooser_set_uri (chooser, existing_uri);
857 * Return value: %TRUE if both the folder could be changed and the URI was
858 * selected successfully, %FALSE otherwise.
863 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
866 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
868 gtk_file_chooser_unselect_all (chooser);
869 return gtk_file_chooser_select_uri (chooser, uri);
873 * gtk_file_chooser_select_uri:
874 * @chooser: a #GtkFileChooser
875 * @uri: the URI to select
877 * Selects the file to by @uri. If the URI doesn't refer to a
878 * file in the current folder of @chooser, then the current folder of
879 * @chooser will be changed to the folder containing @filename.
881 * Return value: %TRUE if both the folder could be changed and the URI was
882 * selected successfully, %FALSE otherwise.
887 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
893 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
894 g_return_val_if_fail (uri != NULL, FALSE);
896 file = g_file_new_for_uri (uri);
897 result = gtk_file_chooser_select_file (chooser, file, NULL);
898 g_object_unref (file);
904 * gtk_file_chooser_unselect_uri:
905 * @chooser: a #GtkFileChooser
906 * @uri: the URI to unselect
908 * Unselects the file referred to by @uri. If the file
909 * is not in the current directory, does not exist, or
910 * is otherwise not currently selected, does nothing.
915 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
920 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
921 g_return_if_fail (uri != NULL);
923 file = g_file_new_for_uri (uri);
924 gtk_file_chooser_unselect_file (chooser, file);
925 g_object_unref (file);
929 * gtk_file_chooser_select_all:
930 * @chooser: a #GtkFileChooser
932 * Selects all the files in the current folder of a file chooser.
937 gtk_file_chooser_select_all (GtkFileChooser *chooser)
939 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
941 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
945 * gtk_file_chooser_unselect_all:
946 * @chooser: a #GtkFileChooser
948 * Unselects all the files in the current folder of a file chooser.
953 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
956 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
958 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
962 * gtk_file_chooser_get_uris:
963 * @chooser: a #GtkFileChooser
965 * Lists all the selected files and subfolders in the current folder of
966 * @chooser. The returned names are full absolute URIs.
968 * Return value: a #GSList containing the URIs of all selected
969 * files and subfolders in the current folder. Free the returned list
970 * with g_slist_free(), and the filenames with g_free().
975 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
977 GSList *files, *result;
979 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
981 files = gtk_file_chooser_get_files (chooser);
983 result = files_to_strings (files, g_file_get_uri);
984 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
985 g_slist_free (files);
991 * gtk_file_chooser_set_current_folder_uri:
992 * @chooser: a #GtkFileChooser
993 * @uri: the URI for the new current folder
995 * Sets the current folder for @chooser from an URI.
996 * The user will be shown the full contents of the current folder,
997 * plus user interface elements for navigating to other folders.
999 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1005 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
1011 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1012 g_return_val_if_fail (uri != NULL, FALSE);
1014 file = g_file_new_for_uri (uri);
1015 result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
1016 g_object_unref (file);
1022 * gtk_file_chooser_get_current_folder_uri:
1023 * @chooser: a #GtkFileChooser
1025 * Gets the current folder of @chooser as an URI.
1026 * See gtk_file_chooser_set_current_folder_uri().
1028 * Note that this is the folder that the file chooser is currently displaying
1029 * (e.g. "file:///home/username/Documents"), which is <emphasis>not the same</emphasis>
1030 * as the currently-selected folder if the chooser is in
1031 * #GTK_FILE_CHOOSER_SELECT_FOLDER mode
1032 * (e.g. "file:///home/username/Documents/selected-folder/". To get the
1033 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
1034 * usual way to get the selection.
1036 * Return value: the URI for the current folder. Free with g_free(). This
1037 * function will also return %NULL if the file chooser was unable to load the
1038 * last folder that was requested from it; for example, as would be for calling
1039 * gtk_file_chooser_set_current_folder_uri() on a nonexistent folder.
1044 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
1049 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1051 file = gtk_file_chooser_get_current_folder_file (chooser);
1055 uri = g_file_get_uri (file);
1056 g_object_unref (file);
1062 * gtk_file_chooser_set_current_folder_file:
1063 * @chooser: a #GtkFileChooser
1064 * @file: the #GFile for the new folder
1065 * @error: location to store error, or %NULL.
1067 * Sets the current folder for @chooser from a #GFile.
1068 * Internal function, see gtk_file_chooser_set_current_folder_uri().
1070 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1076 gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
1080 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1081 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1082 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1084 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, file, error);
1088 * gtk_file_chooser_get_current_folder_file:
1089 * @chooser: a #GtkFileChooser
1091 * Gets the current folder of @chooser as #GFile.
1092 * See gtk_file_chooser_get_current_folder_uri().
1094 * Return value: the #GFile for the current folder.
1099 gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser)
1101 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1103 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1107 * gtk_file_chooser_select_file:
1108 * @chooser: a #GtkFileChooser
1109 * @file: the file to select
1110 * @error: location to store error, or %NULL
1112 * Selects the file referred to by @file. An internal function. See
1113 * _gtk_file_chooser_select_uri().
1115 * Return value: %TRUE if both the folder could be changed and the path was
1116 * selected successfully, %FALSE otherwise.
1121 gtk_file_chooser_select_file (GtkFileChooser *chooser,
1125 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1126 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1127 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1129 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_file (chooser, file, error);
1133 * gtk_file_chooser_unselect_file:
1134 * @chooser: a #GtkFileChooser
1137 * Unselects the file referred to by @file. If the file is not in the current
1138 * directory, does not exist, or is otherwise not currently selected, does nothing.
1143 gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
1146 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1147 g_return_if_fail (G_IS_FILE (file));
1149 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_file (chooser, file);
1153 * gtk_file_chooser_get_files:
1154 * @chooser: a #GtkFileChooser
1156 * Lists all the selected files and subfolders in the current folder of @chooser
1157 * as #GFile. An internal function, see gtk_file_chooser_get_uris().
1159 * Return value: a #GSList containing a #GFile for each selected
1160 * file and subfolder in the current folder. Free the returned list
1161 * with g_slist_free(), and the files with g_object_unref().
1166 gtk_file_chooser_get_files (GtkFileChooser *chooser)
1168 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1170 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_files (chooser);
1174 * gtk_file_chooser_set_file:
1175 * @chooser: a #GtkFileChooser
1176 * @file: the #GFile to set as current
1177 * @error: location to store the error, or %NULL to ignore errors.
1179 * Sets @file as the current filename for the file chooser, by changing
1180 * to the file's parent folder and actually selecting the file in list. If
1181 * the @chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
1182 * will also appear in the dialog's file name entry.
1184 * If the file name isn't in the current folder of @chooser, then the current
1185 * folder of @chooser will be changed to the folder containing @filename. This
1186 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
1187 * gtk_file_chooser_select_filename().
1189 * Note that the file must exist, or nothing will be done except
1190 * for the directory change.
1192 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
1193 * you should use this function if you already have a file name to which the
1194 * user may save; for example, when the user opens an existing file and then
1195 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
1196 * a file name already — for example, if the user just created a new
1197 * file and is saving it for the first time, do not call this function.
1198 * Instead, use something similar to this:
1200 * if (document_is_new)
1202 * /* the user just created a new document */
1203 * gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
1204 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
1208 * /* the user edited an existing document */
1209 * gtk_file_chooser_set_file (chooser, existing_file);
1213 * Return value: %TRUE if both the folder could be changed and the file was
1214 * selected successfully, %FALSE otherwise.
1219 gtk_file_chooser_set_file (GtkFileChooser *chooser,
1223 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1224 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1225 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1227 gtk_file_chooser_unselect_all (chooser);
1228 return gtk_file_chooser_select_file (chooser, file, error);
1232 * gtk_file_chooser_get_file:
1233 * @chooser: a #GtkFileChooser
1235 * Gets the #GFile for the currently selected file in
1236 * the file selector. If multiple files are selected,
1237 * one of the files will be returned at random.
1239 * If the file chooser is in folder mode, this function returns the selected
1242 * Returns: a selected #GFile
1247 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1250 GFile *result = NULL;
1252 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1254 list = gtk_file_chooser_get_files (chooser);
1257 result = list->data;
1258 list = g_slist_delete_link (list, list);
1260 g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1261 g_slist_free (list);
1268 * _gtk_file_chooser_get_file_system:
1269 * @chooser: a #GtkFileChooser
1271 * Gets the #GtkFileSystem of @chooser; this is an internal
1272 * implementation detail, used for conversion between paths
1273 * and filenames and URIs.
1275 * Return value: the file system for @chooser.
1280 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1282 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1284 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1290 * gtk_file_chooser_set_preview_widget:
1291 * @chooser: a #GtkFileChooser
1292 * @preview_widget: widget for displaying preview.
1294 * Sets an application-supplied widget to use to display a custom preview
1295 * of the currently selected file. To implement a preview, after setting the
1296 * preview widget, you connect to the ::update-preview
1297 * signal, and call gtk_file_chooser_get_preview_filename() or
1298 * gtk_file_chooser_get_preview_uri() on each change. If you can
1299 * display a preview of the new file, update your widget and
1300 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1301 * Otherwise, set the preview inactive.
1303 * When there is no application-supplied preview widget, or the
1304 * application-supplied preview widget is not active, the file chooser
1305 * may display an internally generated preview of the current file or
1306 * it may display no preview at all.
1311 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1312 GtkWidget *preview_widget)
1314 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1316 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1320 * gtk_file_chooser_get_preview_widget:
1321 * @chooser: a #GtkFileChooser
1323 * Gets the current preview widget; see
1324 * gtk_file_chooser_set_preview_widget().
1326 * Return value: the current preview widget, or %NULL
1331 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1333 GtkWidget *preview_widget;
1335 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1337 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1339 /* Horrid hack; g_object_get() refs returned objects but
1340 * that contradicts the memory management conventions
1344 g_object_unref (preview_widget);
1346 return preview_widget;
1350 * gtk_file_chooser_set_preview_widget_active:
1351 * @chooser: a #GtkFileChooser
1352 * @active: whether to display the user-specified preview widget
1354 * Sets whether the preview widget set by
1355 * gtk_file_chooser_set_preview_widget() should be shown for the
1356 * current filename. When @active is set to false, the file chooser
1357 * may display an internally generated preview of the current file
1358 * or it may display no preview at all. See
1359 * gtk_file_chooser_set_preview_widget() for more details.
1364 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1367 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1369 g_object_set (chooser, "preview-widget-active", active, NULL);
1373 * gtk_file_chooser_get_preview_widget_active:
1374 * @chooser: a #GtkFileChooser
1376 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1377 * should be shown for the current filename. See
1378 * gtk_file_chooser_set_preview_widget_active().
1380 * Return value: %TRUE if the preview widget is active for the current filename.
1385 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1389 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1391 g_object_get (chooser, "preview-widget-active", &active, NULL);
1397 * gtk_file_chooser_set_use_preview_label:
1398 * @chooser: a #GtkFileChooser
1399 * @use_label: whether to display a stock label with the name of the previewed file
1401 * Sets whether the file chooser should display a stock label with the name of
1402 * the file that is being previewed; the default is %TRUE. Applications that
1403 * want to draw the whole preview area themselves should set this to %FALSE and
1404 * display the name themselves in their preview widget.
1406 * See also: gtk_file_chooser_set_preview_widget()
1411 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1414 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1416 g_object_set (chooser, "use-preview-label", use_label, NULL);
1420 * gtk_file_chooser_get_use_preview_label:
1421 * @chooser: a #GtkFileChooser
1423 * Gets whether a stock label should be drawn with the name of the previewed
1424 * file. See gtk_file_chooser_set_use_preview_label().
1426 * Return value: %TRUE if the file chooser is set to display a label with the
1427 * name of the previewed file, %FALSE otherwise.
1430 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1434 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1436 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1442 * gtk_file_chooser_get_preview_file:
1443 * @chooser: a #GtkFileChooser
1445 * Gets the #GFile that should be previewed in a custom preview
1446 * Internal function, see gtk_file_chooser_get_preview_uri().
1448 * Return value: the #GFile for the file to preview, or %NULL if no file
1449 * is selected. Free with g_object_unref().
1454 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
1456 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1458 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
1462 * _gtk_file_chooser_add_shortcut_folder:
1463 * @chooser: a #GtkFileChooser
1464 * @file: file for the folder to add
1465 * @error: location to store error, or %NULL
1467 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1468 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1470 * Return value: %TRUE if the folder could be added successfully, %FALSE
1476 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1480 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1481 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1483 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1487 * _gtk_file_chooser_remove_shortcut_folder:
1488 * @chooser: a #GtkFileChooser
1489 * @file: file for the folder to remove
1490 * @error: location to store error, or %NULL
1492 * Removes a folder from the shortcut folders in a file chooser. Internal
1493 * function, see gtk_file_chooser_remove_shortcut_folder().
1495 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1501 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1505 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1506 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1508 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1512 * gtk_file_chooser_get_preview_filename:
1513 * @chooser: a #GtkFileChooser
1515 * Gets the filename that should be previewed in a custom preview
1516 * widget. See gtk_file_chooser_set_preview_widget().
1518 * Return value: the filename to preview, or %NULL if no file
1519 * is selected, or if the selected file cannot be represented
1520 * as a local filename. Free with g_free()
1525 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1528 gchar *result = NULL;
1530 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1532 file = gtk_file_chooser_get_preview_file (chooser);
1535 result = g_file_get_path (file);
1536 g_object_unref (file);
1543 * gtk_file_chooser_get_preview_uri:
1544 * @chooser: a #GtkFileChooser
1546 * Gets the URI that should be previewed in a custom preview
1547 * widget. See gtk_file_chooser_set_preview_widget().
1549 * Return value: the URI for the file to preview, or %NULL if no file is
1550 * selected. Free with g_free().
1555 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1558 gchar *result = NULL;
1560 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1562 file = gtk_file_chooser_get_preview_file (chooser);
1565 result = g_file_get_uri (file);
1566 g_object_unref (file);
1573 * gtk_file_chooser_set_extra_widget:
1574 * @chooser: a #GtkFileChooser
1575 * @extra_widget: widget for extra options
1577 * Sets an application-supplied widget to provide extra options to the user.
1582 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1583 GtkWidget *extra_widget)
1585 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1587 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1591 * gtk_file_chooser_get_extra_widget:
1592 * @chooser: a #GtkFileChooser
1594 * Gets the current preview widget; see
1595 * gtk_file_chooser_set_extra_widget().
1597 * Return value: the current extra widget, or %NULL
1602 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1604 GtkWidget *extra_widget;
1606 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1608 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1610 /* Horrid hack; g_object_get() refs returned objects but
1611 * that contradicts the memory management conventions
1615 g_object_unref (extra_widget);
1617 return extra_widget;
1621 * gtk_file_chooser_add_filter:
1622 * @chooser: a #GtkFileChooser
1623 * @filter: a #GtkFileFilter
1625 * Adds @filter to the list of filters that the user can select between.
1626 * When a filter is selected, only files that are passed by that
1627 * filter are displayed.
1629 * Note that the @chooser takes ownership of the filter, so you have to
1630 * ref and sink it if you want to keep a reference.
1635 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1636 GtkFileFilter *filter)
1638 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1640 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1644 * gtk_file_chooser_remove_filter:
1645 * @chooser: a #GtkFileChooser
1646 * @filter: a #GtkFileFilter
1648 * Removes @filter from the list of filters that the user can select between.
1653 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1654 GtkFileFilter *filter)
1656 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1658 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1662 * gtk_file_chooser_list_filters:
1663 * @chooser: a #GtkFileChooser
1665 * Lists the current set of user-selectable filters; see
1666 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1668 * Return value: a #GSList containing the current set of
1669 * user selectable filters. The contents of the list are
1670 * owned by GTK+, but you must free the list itself with
1671 * g_slist_free() when you are done with it.
1676 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1678 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1680 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1684 * gtk_file_chooser_set_filter:
1685 * @chooser: a #GtkFileChooser
1686 * @filter: a #GtkFileFilter
1688 * Sets the current filter; only the files that pass the
1689 * filter will be displayed. If the user-selectable list of filters
1690 * is non-empty, then the filter should be one of the filters
1691 * in that list. Setting the current filter when the list of
1692 * filters is empty is useful if you want to restrict the displayed
1693 * set of files without letting the user change it.
1698 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1699 GtkFileFilter *filter)
1701 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1702 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1704 g_object_set (chooser, "filter", filter, NULL);
1708 * gtk_file_chooser_get_filter:
1709 * @chooser: a #GtkFileChooser
1711 * Gets the current filter; see gtk_file_chooser_set_filter().
1713 * Return value: the current filter, or %NULL
1718 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1720 GtkFileFilter *filter;
1722 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1724 g_object_get (chooser, "filter", &filter, NULL);
1725 /* Horrid hack; g_object_get() refs returned objects but
1726 * that contradicts the memory management conventions
1730 g_object_unref (filter);
1736 * gtk_file_chooser_add_shortcut_folder:
1737 * @chooser: a #GtkFileChooser
1738 * @folder: filename of the folder to add
1739 * @error: location to store error, or %NULL
1741 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1742 * Note that shortcut folders do not get saved, as they are provided by the
1743 * application. For example, you can use this to add a
1744 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1746 * Return value: %TRUE if the folder could be added successfully, %FALSE
1747 * otherwise. In the latter case, the @error will be set as appropriate.
1752 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1759 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1760 g_return_val_if_fail (folder != NULL, FALSE);
1762 file = g_file_new_for_path (folder);
1763 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1764 g_object_unref (file);
1770 * gtk_file_chooser_remove_shortcut_folder:
1771 * @chooser: a #GtkFileChooser
1772 * @folder: filename of the folder to remove
1773 * @error: location to store error, or %NULL
1775 * Removes a folder from a file chooser's list of shortcut folders.
1777 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1778 * In the latter case, the @error will be set as appropriate.
1780 * See also: gtk_file_chooser_add_shortcut_folder()
1785 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1792 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1793 g_return_val_if_fail (folder != NULL, FALSE);
1795 file = g_file_new_for_path (folder);
1796 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1797 g_object_unref (file);
1803 * gtk_file_chooser_list_shortcut_folders:
1804 * @chooser: a #GtkFileChooser
1806 * Queries the list of shortcut folders in the file chooser, as set by
1807 * gtk_file_chooser_add_shortcut_folder().
1809 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1810 * folders. Free the returned list with g_slist_free(), and the filenames with
1816 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1821 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1823 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1825 result = files_to_strings (folders, g_file_get_path);
1826 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1827 g_slist_free (folders);
1833 * gtk_file_chooser_add_shortcut_folder_uri:
1834 * @chooser: a #GtkFileChooser
1835 * @uri: URI of the folder to add
1836 * @error: location to store error, or %NULL
1838 * Adds a folder URI to be displayed with the shortcut folders in a file
1839 * chooser. Note that shortcut folders do not get saved, as they are provided
1840 * by the application. For example, you can use this to add a
1841 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1843 * Return value: %TRUE if the folder could be added successfully, %FALSE
1844 * otherwise. In the latter case, the @error will be set as appropriate.
1849 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1856 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1857 g_return_val_if_fail (uri != NULL, FALSE);
1859 file = g_file_new_for_uri (uri);
1860 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1861 g_object_unref (file);
1867 * gtk_file_chooser_remove_shortcut_folder_uri:
1868 * @chooser: a #GtkFileChooser
1869 * @uri: URI of the folder to remove
1870 * @error: location to store error, or %NULL
1872 * Removes a folder URI from a file chooser's list of shortcut folders.
1874 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1875 * In the latter case, the @error will be set as appropriate.
1877 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1882 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1889 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1890 g_return_val_if_fail (uri != NULL, FALSE);
1892 file = g_file_new_for_uri (uri);
1893 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1894 g_object_unref (file);
1900 * gtk_file_chooser_list_shortcut_folder_uris:
1901 * @chooser: a #GtkFileChooser
1903 * Queries the list of shortcut folders in the file chooser, as set by
1904 * gtk_file_chooser_add_shortcut_folder_uri().
1906 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1907 * folders. Free the returned list with g_slist_free(), and the URIs with
1913 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1918 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1920 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1922 result = files_to_strings (folders, g_file_get_uri);
1923 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1924 g_slist_free (folders);
1930 _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
1932 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1934 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1938 * gtk_file_chooser_set_show_hidden:
1939 * @chooser: a #GtkFileChooser
1940 * @show_hidden: %TRUE if hidden files and folders should be displayed.
1942 * Sets whether hidden files and folders are displayed in the file selector.
1947 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1948 gboolean show_hidden)
1950 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1952 g_object_set (chooser, "show-hidden", show_hidden, NULL);
1956 * gtk_file_chooser_get_show_hidden:
1957 * @chooser: a #GtkFileChooser
1959 * Gets whether hidden files and folders are displayed in the file selector.
1960 * See gtk_file_chooser_set_show_hidden().
1962 * Return value: %TRUE if hidden files and folders are displayed.
1967 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1969 gboolean show_hidden;
1971 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1973 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1979 * gtk_file_chooser_set_do_overwrite_confirmation:
1980 * @chooser: a #GtkFileChooser
1981 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1983 * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1984 * a confirmation dialog if the user types a file name that already exists. This
1985 * is %FALSE by default.
1987 * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1988 * signal when appropriate.
1990 * If all you need is the stock confirmation dialog, set this property to %TRUE.
1991 * You can override the way confirmation is done by actually handling the
1992 * "confirm-overwrite" signal; please refer to its documentation for the
1998 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
1999 gboolean do_overwrite_confirmation)
2001 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2003 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
2007 * gtk_file_chooser_get_do_overwrite_confirmation:
2008 * @chooser: a #GtkFileChooser
2010 * Queries whether a file chooser is set to confirm for overwriting when the user
2011 * types a file name that already exists.
2013 * Return value: %TRUE if the file chooser will present a confirmation dialog;
2019 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
2021 gboolean do_overwrite_confirmation;
2023 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2025 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
2027 return do_overwrite_confirmation;
2030 #if defined (G_OS_WIN32) && !defined (_WIN64)
2032 /* DLL ABI stability backward compatibility versions */
2034 #undef gtk_file_chooser_get_filename
2037 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
2039 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
2040 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2042 g_free (utf8_filename);
2047 #undef gtk_file_chooser_set_filename
2050 gtk_file_chooser_set_filename (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_filename_utf8 (chooser, utf8_filename);
2056 g_free (utf8_filename);
2061 #undef gtk_file_chooser_select_filename
2064 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2065 const gchar *filename)
2067 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2068 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2070 g_free (utf8_filename);
2075 #undef gtk_file_chooser_unselect_filename
2078 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2079 const char *filename)
2081 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2083 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2084 g_free (utf8_filename);
2087 #undef gtk_file_chooser_get_filenames
2090 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2092 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2093 GSList *rover = list;
2097 gchar *tem = (gchar *) rover->data;
2098 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2100 rover = rover->next;
2106 #undef gtk_file_chooser_set_current_folder
2109 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2110 const gchar *filename)
2112 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2113 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2115 g_free (utf8_filename);
2120 #undef gtk_file_chooser_get_current_folder
2123 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2125 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2126 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2128 g_free (utf8_folder);
2133 #undef gtk_file_chooser_get_preview_filename
2136 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2138 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2139 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2141 g_free (utf8_filename);
2146 #undef gtk_file_chooser_add_shortcut_folder
2149 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2153 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2155 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2157 g_free (utf8_folder);
2162 #undef gtk_file_chooser_remove_shortcut_folder
2165 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2169 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2171 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2173 g_free (utf8_folder);
2178 #undef gtk_file_chooser_list_shortcut_folders
2181 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2183 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2184 GSList *rover = list;
2188 gchar *tem = (gchar *) rover->data;
2189 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2191 rover = rover->next;
2199 #define __GTK_FILE_CHOOSER_C__
2200 #include "gtkaliasdef.c"