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. You own the returned file; use
1243 * g_object_unref() to release it.
1248 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1251 GFile *result = NULL;
1253 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1255 list = gtk_file_chooser_get_files (chooser);
1258 result = list->data;
1259 list = g_slist_delete_link (list, list);
1261 g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1262 g_slist_free (list);
1269 * _gtk_file_chooser_get_file_system:
1270 * @chooser: a #GtkFileChooser
1272 * Gets the #GtkFileSystem of @chooser; this is an internal
1273 * implementation detail, used for conversion between paths
1274 * and filenames and URIs.
1276 * Return value: the file system for @chooser.
1281 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1283 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1285 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1291 * gtk_file_chooser_set_preview_widget:
1292 * @chooser: a #GtkFileChooser
1293 * @preview_widget: widget for displaying preview.
1295 * Sets an application-supplied widget to use to display a custom preview
1296 * of the currently selected file. To implement a preview, after setting the
1297 * preview widget, you connect to the ::update-preview
1298 * signal, and call gtk_file_chooser_get_preview_filename() or
1299 * gtk_file_chooser_get_preview_uri() on each change. If you can
1300 * display a preview of the new file, update your widget and
1301 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1302 * Otherwise, set the preview inactive.
1304 * When there is no application-supplied preview widget, or the
1305 * application-supplied preview widget is not active, the file chooser
1306 * may display an internally generated preview of the current file or
1307 * it may display no preview at all.
1312 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1313 GtkWidget *preview_widget)
1315 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1317 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1321 * gtk_file_chooser_get_preview_widget:
1322 * @chooser: a #GtkFileChooser
1324 * Gets the current preview widget; see
1325 * gtk_file_chooser_set_preview_widget().
1327 * Return value: the current preview widget, or %NULL
1332 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1334 GtkWidget *preview_widget;
1336 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1338 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1340 /* Horrid hack; g_object_get() refs returned objects but
1341 * that contradicts the memory management conventions
1345 g_object_unref (preview_widget);
1347 return preview_widget;
1351 * gtk_file_chooser_set_preview_widget_active:
1352 * @chooser: a #GtkFileChooser
1353 * @active: whether to display the user-specified preview widget
1355 * Sets whether the preview widget set by
1356 * gtk_file_chooser_set_preview_widget() should be shown for the
1357 * current filename. When @active is set to false, the file chooser
1358 * may display an internally generated preview of the current file
1359 * or it may display no preview at all. See
1360 * gtk_file_chooser_set_preview_widget() for more details.
1365 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1368 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1370 g_object_set (chooser, "preview-widget-active", active, NULL);
1374 * gtk_file_chooser_get_preview_widget_active:
1375 * @chooser: a #GtkFileChooser
1377 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1378 * should be shown for the current filename. See
1379 * gtk_file_chooser_set_preview_widget_active().
1381 * Return value: %TRUE if the preview widget is active for the current filename.
1386 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1390 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1392 g_object_get (chooser, "preview-widget-active", &active, NULL);
1398 * gtk_file_chooser_set_use_preview_label:
1399 * @chooser: a #GtkFileChooser
1400 * @use_label: whether to display a stock label with the name of the previewed file
1402 * Sets whether the file chooser should display a stock label with the name of
1403 * the file that is being previewed; the default is %TRUE. Applications that
1404 * want to draw the whole preview area themselves should set this to %FALSE and
1405 * display the name themselves in their preview widget.
1407 * See also: gtk_file_chooser_set_preview_widget()
1412 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1415 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1417 g_object_set (chooser, "use-preview-label", use_label, NULL);
1421 * gtk_file_chooser_get_use_preview_label:
1422 * @chooser: a #GtkFileChooser
1424 * Gets whether a stock label should be drawn with the name of the previewed
1425 * file. See gtk_file_chooser_set_use_preview_label().
1427 * Return value: %TRUE if the file chooser is set to display a label with the
1428 * name of the previewed file, %FALSE otherwise.
1431 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1435 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1437 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1443 * gtk_file_chooser_get_preview_file:
1444 * @chooser: a #GtkFileChooser
1446 * Gets the #GFile that should be previewed in a custom preview
1447 * Internal function, see gtk_file_chooser_get_preview_uri().
1449 * Return value: the #GFile for the file to preview, or %NULL if no file
1450 * is selected. Free with g_object_unref().
1455 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
1457 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1459 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
1463 * _gtk_file_chooser_add_shortcut_folder:
1464 * @chooser: a #GtkFileChooser
1465 * @file: file for the folder to add
1466 * @error: location to store error, or %NULL
1468 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1469 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1471 * Return value: %TRUE if the folder could be added successfully, %FALSE
1477 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1481 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1482 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1484 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1488 * _gtk_file_chooser_remove_shortcut_folder:
1489 * @chooser: a #GtkFileChooser
1490 * @file: file for the folder to remove
1491 * @error: location to store error, or %NULL
1493 * Removes a folder from the shortcut folders in a file chooser. Internal
1494 * function, see gtk_file_chooser_remove_shortcut_folder().
1496 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1502 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1506 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1507 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1509 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1513 * gtk_file_chooser_get_preview_filename:
1514 * @chooser: a #GtkFileChooser
1516 * Gets the filename that should be previewed in a custom preview
1517 * widget. See gtk_file_chooser_set_preview_widget().
1519 * Return value: the filename to preview, or %NULL if no file
1520 * is selected, or if the selected file cannot be represented
1521 * as a local filename. Free with g_free()
1526 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1529 gchar *result = NULL;
1531 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1533 file = gtk_file_chooser_get_preview_file (chooser);
1536 result = g_file_get_path (file);
1537 g_object_unref (file);
1544 * gtk_file_chooser_get_preview_uri:
1545 * @chooser: a #GtkFileChooser
1547 * Gets the URI that should be previewed in a custom preview
1548 * widget. See gtk_file_chooser_set_preview_widget().
1550 * Return value: the URI for the file to preview, or %NULL if no file is
1551 * selected. Free with g_free().
1556 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1559 gchar *result = NULL;
1561 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1563 file = gtk_file_chooser_get_preview_file (chooser);
1566 result = g_file_get_uri (file);
1567 g_object_unref (file);
1574 * gtk_file_chooser_set_extra_widget:
1575 * @chooser: a #GtkFileChooser
1576 * @extra_widget: widget for extra options
1578 * Sets an application-supplied widget to provide extra options to the user.
1583 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1584 GtkWidget *extra_widget)
1586 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1588 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1592 * gtk_file_chooser_get_extra_widget:
1593 * @chooser: a #GtkFileChooser
1595 * Gets the current preview widget; see
1596 * gtk_file_chooser_set_extra_widget().
1598 * Return value: the current extra widget, or %NULL
1603 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1605 GtkWidget *extra_widget;
1607 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1609 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1611 /* Horrid hack; g_object_get() refs returned objects but
1612 * that contradicts the memory management conventions
1616 g_object_unref (extra_widget);
1618 return extra_widget;
1622 * gtk_file_chooser_add_filter:
1623 * @chooser: a #GtkFileChooser
1624 * @filter: a #GtkFileFilter
1626 * Adds @filter to the list of filters that the user can select between.
1627 * When a filter is selected, only files that are passed by that
1628 * filter are displayed.
1630 * Note that the @chooser takes ownership of the filter, so you have to
1631 * ref and sink it if you want to keep a reference.
1636 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1637 GtkFileFilter *filter)
1639 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1641 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1645 * gtk_file_chooser_remove_filter:
1646 * @chooser: a #GtkFileChooser
1647 * @filter: a #GtkFileFilter
1649 * Removes @filter from the list of filters that the user can select between.
1654 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1655 GtkFileFilter *filter)
1657 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1659 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1663 * gtk_file_chooser_list_filters:
1664 * @chooser: a #GtkFileChooser
1666 * Lists the current set of user-selectable filters; see
1667 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1669 * Return value: a #GSList containing the current set of
1670 * user selectable filters. The contents of the list are
1671 * owned by GTK+, but you must free the list itself with
1672 * g_slist_free() when you are done with it.
1677 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1679 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1681 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1685 * gtk_file_chooser_set_filter:
1686 * @chooser: a #GtkFileChooser
1687 * @filter: a #GtkFileFilter
1689 * Sets the current filter; only the files that pass the
1690 * filter will be displayed. If the user-selectable list of filters
1691 * is non-empty, then the filter should be one of the filters
1692 * in that list. Setting the current filter when the list of
1693 * filters is empty is useful if you want to restrict the displayed
1694 * set of files without letting the user change it.
1699 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1700 GtkFileFilter *filter)
1702 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1703 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1705 g_object_set (chooser, "filter", filter, NULL);
1709 * gtk_file_chooser_get_filter:
1710 * @chooser: a #GtkFileChooser
1712 * Gets the current filter; see gtk_file_chooser_set_filter().
1714 * Return value: the current filter, or %NULL
1719 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1721 GtkFileFilter *filter;
1723 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1725 g_object_get (chooser, "filter", &filter, NULL);
1726 /* Horrid hack; g_object_get() refs returned objects but
1727 * that contradicts the memory management conventions
1731 g_object_unref (filter);
1737 * gtk_file_chooser_add_shortcut_folder:
1738 * @chooser: a #GtkFileChooser
1739 * @folder: filename of the folder to add
1740 * @error: location to store error, or %NULL
1742 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1743 * Note that shortcut folders do not get saved, as they are provided by the
1744 * application. For example, you can use this to add a
1745 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1747 * Return value: %TRUE if the folder could be added successfully, %FALSE
1748 * otherwise. In the latter case, the @error will be set as appropriate.
1753 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1760 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1761 g_return_val_if_fail (folder != NULL, FALSE);
1763 file = g_file_new_for_path (folder);
1764 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1765 g_object_unref (file);
1771 * gtk_file_chooser_remove_shortcut_folder:
1772 * @chooser: a #GtkFileChooser
1773 * @folder: filename of the folder to remove
1774 * @error: location to store error, or %NULL
1776 * Removes a folder from a file chooser's list of shortcut folders.
1778 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1779 * In the latter case, the @error will be set as appropriate.
1781 * See also: gtk_file_chooser_add_shortcut_folder()
1786 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1793 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1794 g_return_val_if_fail (folder != NULL, FALSE);
1796 file = g_file_new_for_path (folder);
1797 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1798 g_object_unref (file);
1804 * gtk_file_chooser_list_shortcut_folders:
1805 * @chooser: a #GtkFileChooser
1807 * Queries the list of shortcut folders in the file chooser, as set by
1808 * gtk_file_chooser_add_shortcut_folder().
1810 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1811 * folders. Free the returned list with g_slist_free(), and the filenames with
1817 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1822 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1824 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1826 result = files_to_strings (folders, g_file_get_path);
1827 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1828 g_slist_free (folders);
1834 * gtk_file_chooser_add_shortcut_folder_uri:
1835 * @chooser: a #GtkFileChooser
1836 * @uri: URI of the folder to add
1837 * @error: location to store error, or %NULL
1839 * Adds a folder URI to be displayed with the shortcut folders in a file
1840 * chooser. Note that shortcut folders do not get saved, as they are provided
1841 * by the application. For example, you can use this to add a
1842 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1844 * Return value: %TRUE if the folder could be added successfully, %FALSE
1845 * otherwise. In the latter case, the @error will be set as appropriate.
1850 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1857 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1858 g_return_val_if_fail (uri != NULL, FALSE);
1860 file = g_file_new_for_uri (uri);
1861 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1862 g_object_unref (file);
1868 * gtk_file_chooser_remove_shortcut_folder_uri:
1869 * @chooser: a #GtkFileChooser
1870 * @uri: URI of the folder to remove
1871 * @error: location to store error, or %NULL
1873 * Removes a folder URI from a file chooser's list of shortcut folders.
1875 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1876 * In the latter case, the @error will be set as appropriate.
1878 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1883 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1890 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1891 g_return_val_if_fail (uri != NULL, FALSE);
1893 file = g_file_new_for_uri (uri);
1894 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1895 g_object_unref (file);
1901 * gtk_file_chooser_list_shortcut_folder_uris:
1902 * @chooser: a #GtkFileChooser
1904 * Queries the list of shortcut folders in the file chooser, as set by
1905 * gtk_file_chooser_add_shortcut_folder_uri().
1907 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1908 * folders. Free the returned list with g_slist_free(), and the URIs with
1914 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1919 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1921 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1923 result = files_to_strings (folders, g_file_get_uri);
1924 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1925 g_slist_free (folders);
1931 _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
1933 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1935 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1939 * gtk_file_chooser_set_show_hidden:
1940 * @chooser: a #GtkFileChooser
1941 * @show_hidden: %TRUE if hidden files and folders should be displayed.
1943 * Sets whether hidden files and folders are displayed in the file selector.
1948 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1949 gboolean show_hidden)
1951 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1953 g_object_set (chooser, "show-hidden", show_hidden, NULL);
1957 * gtk_file_chooser_get_show_hidden:
1958 * @chooser: a #GtkFileChooser
1960 * Gets whether hidden files and folders are displayed in the file selector.
1961 * See gtk_file_chooser_set_show_hidden().
1963 * Return value: %TRUE if hidden files and folders are displayed.
1968 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1970 gboolean show_hidden;
1972 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1974 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1980 * gtk_file_chooser_set_do_overwrite_confirmation:
1981 * @chooser: a #GtkFileChooser
1982 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1984 * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1985 * a confirmation dialog if the user types a file name that already exists. This
1986 * is %FALSE by default.
1988 * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1989 * signal when appropriate.
1991 * If all you need is the stock confirmation dialog, set this property to %TRUE.
1992 * You can override the way confirmation is done by actually handling the
1993 * "confirm-overwrite" signal; please refer to its documentation for the
1999 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
2000 gboolean do_overwrite_confirmation)
2002 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2004 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
2008 * gtk_file_chooser_get_do_overwrite_confirmation:
2009 * @chooser: a #GtkFileChooser
2011 * Queries whether a file chooser is set to confirm for overwriting when the user
2012 * types a file name that already exists.
2014 * Return value: %TRUE if the file chooser will present a confirmation dialog;
2020 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
2022 gboolean do_overwrite_confirmation;
2024 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2026 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
2028 return do_overwrite_confirmation;
2031 #if defined (G_OS_WIN32) && !defined (_WIN64)
2033 /* DLL ABI stability backward compatibility versions */
2035 #undef gtk_file_chooser_get_filename
2038 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
2040 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
2041 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2043 g_free (utf8_filename);
2048 #undef gtk_file_chooser_set_filename
2051 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
2052 const gchar *filename)
2054 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2055 gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
2057 g_free (utf8_filename);
2062 #undef gtk_file_chooser_select_filename
2065 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2066 const gchar *filename)
2068 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2069 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2071 g_free (utf8_filename);
2076 #undef gtk_file_chooser_unselect_filename
2079 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2080 const char *filename)
2082 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2084 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2085 g_free (utf8_filename);
2088 #undef gtk_file_chooser_get_filenames
2091 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2093 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2094 GSList *rover = list;
2098 gchar *tem = (gchar *) rover->data;
2099 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2101 rover = rover->next;
2107 #undef gtk_file_chooser_set_current_folder
2110 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2111 const gchar *filename)
2113 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2114 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2116 g_free (utf8_filename);
2121 #undef gtk_file_chooser_get_current_folder
2124 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2126 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2127 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2129 g_free (utf8_folder);
2134 #undef gtk_file_chooser_get_preview_filename
2137 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2139 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2140 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2142 g_free (utf8_filename);
2147 #undef gtk_file_chooser_add_shortcut_folder
2150 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2154 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2156 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2158 g_free (utf8_folder);
2163 #undef gtk_file_chooser_remove_shortcut_folder
2166 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2170 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2172 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2174 g_free (utf8_folder);
2179 #undef gtk_file_chooser_list_shortcut_folders
2182 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2184 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2185 GSList *rover = list;
2189 gchar *tem = (gchar *) rover->data;
2190 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2192 rover = rover->next;
2200 #define __GTK_FILE_CHOOSER_C__
2201 #include "gtkaliasdef.c"