1 /* GTK - The GIMP Toolkit
2 * gtkfilechooser.c: Abstract interface for file selector GUIs
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include "gtkfilechooser.h"
23 #include "gtkfilechooserprivate.h"
24 #include "gtkfilesystem.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkprivate.h"
28 #include "gtkmarshalers.h"
31 static void gtk_file_chooser_class_init (gpointer g_iface);
33 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
36 gtk_file_chooser_get_type (void)
38 static GType file_chooser_type = 0;
40 if (!file_chooser_type)
42 static const GTypeInfo file_chooser_info =
44 sizeof (GtkFileChooserIface), /* class_size */
46 NULL, /* base_finalize */
47 (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
50 file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
52 &file_chooser_info, 0);
54 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
57 return file_chooser_type;
61 confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
63 const GValue *handler_return,
66 gboolean continue_emission;
67 GtkFileChooserConfirmation conf;
69 conf = g_value_get_enum (handler_return);
70 g_value_set_enum (return_accu, conf);
71 continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
73 return continue_emission;
77 gtk_file_chooser_class_init (gpointer g_iface)
79 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
82 * GtkFileChooser::current-folder-changed
83 * @chooser: the object which received the signal.
85 * This signal is emitted when the current folder in a #GtkFileChooser
86 * changes. This can happen due to the user performing some action that
87 * changes folders, such as selecting a bookmark or visiting a folder on the
88 * file list. It can also happen as a result of calling a function to
89 * explicitly change the current folder in a file chooser.
91 * Normally you do not need to connect to this signal, unless you need to keep
92 * track of which folder a file chooser is showing.
94 * See also: gtk_file_chooser_set_current_folder(),
95 * gtk_file_chooser_get_current_folder(),
96 * gtk_file_chooser_set_current_folder_uri(),
97 * gtk_file_chooser_get_current_folder_uri().
99 g_signal_new (I_("current-folder-changed"),
102 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
104 g_cclosure_marshal_VOID__VOID,
108 * GtkFileChooser::selection-changed
109 * @chooser: the object which received the signal.
111 * This signal is emitted when there is a change in the set of selected files
112 * in a #GtkFileChooser. This can happen when the user modifies the selection
113 * with the mouse or the keyboard, or when explicitly calling functions to
114 * change the selection.
116 * Normally you do not need to connect to this signal, as it is easier to wait
117 * for the file chooser to finish running, and then to get the list of
118 * selected files using the functions mentioned below.
120 * See also: gtk_file_chooser_select_filename(),
121 * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
122 * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
123 * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
124 * gtk_file_chooser_get_uris().
126 g_signal_new (I_("selection-changed"),
129 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
131 g_cclosure_marshal_VOID__VOID,
135 * GtkFileChooser::update-preview
136 * @chooser: the object which received the signal.
138 * This signal is emitted when the preview in a file chooser should be
139 * regenerated. For example, this can happen when the currently selected file
140 * changes. You should use this signal if you want your file chooser to have
143 * Once you have installed a preview widget with
144 * gtk_file_chooser_set_preview_widget(), you should update it when this
145 * signal is emitted. You can use the functions
146 * gtk_file_chooser_get_preview_filename() or
147 * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
148 * Your widget may not be able to preview all kinds of files; your callback
149 * must call gtk_file_chooser_set_preview_wiget_active() to inform the file
150 * chooser about whether the preview was generated successfully or not.
152 * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
154 * See also: gtk_file_chooser_set_preview_widget(),
155 * gtk_file_chooser_set_preview_widget_active(),
156 * gtk_file_chooser_set_use_preview_label(),
157 * gtk_file_chooser_get_preview_filename(),
158 * gtk_file_chooser_get_preview_uri().
160 g_signal_new (I_("update-preview"),
163 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
165 g_cclosure_marshal_VOID__VOID,
169 * GtkFileChooser::file-activated
170 * @chooser: the object which received the signal.
172 * This signal is emitted when the user "activates" a file in the file
173 * chooser. This can happen by double-clicking on a file in the file list, or
174 * by pressing <keycap>Enter</keycap>.
176 * Normally you do not need to connect to this signal. It is used internally
177 * by #GtkFileChooserDialog to know when to activate the default button in the
180 * See also: gtk_file_chooser_get_filename(),
181 * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
182 * gtk_file_chooser_get_uris().
184 g_signal_new (I_("file-activated"),
187 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
189 g_cclosure_marshal_VOID__VOID,
192 /* Documented in the docbook files */
193 g_signal_new (I_("confirm-overwrite"),
196 G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
197 confirm_overwrite_accumulator, NULL,
198 _gtk_marshal_ENUM__VOID,
199 GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
201 g_object_interface_install_property (g_iface,
202 g_param_spec_enum ("action",
204 P_("The type of operation that the file selector is performing"),
205 GTK_TYPE_FILE_CHOOSER_ACTION,
206 GTK_FILE_CHOOSER_ACTION_OPEN,
207 GTK_PARAM_READWRITE));
208 g_object_interface_install_property (g_iface,
209 g_param_spec_string ("file-system-backend",
210 P_("File System Backend"),
211 P_("Name of file system backend to use"),
213 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
214 g_object_interface_install_property (g_iface,
215 g_param_spec_object ("filter",
217 P_("The current filter for selecting which files are displayed"),
218 GTK_TYPE_FILE_FILTER,
219 GTK_PARAM_READWRITE));
220 g_object_interface_install_property (g_iface,
221 g_param_spec_boolean ("local-only",
223 P_("Whether the selected file(s) should be limited to local file: URLs"),
225 GTK_PARAM_READWRITE));
226 g_object_interface_install_property (g_iface,
227 g_param_spec_object ("preview-widget",
228 P_("Preview widget"),
229 P_("Application supplied widget for custom previews."),
231 GTK_PARAM_READWRITE));
232 g_object_interface_install_property (g_iface,
233 g_param_spec_boolean ("preview-widget-active",
234 P_("Preview Widget Active"),
235 P_("Whether the application supplied widget for custom previews should be shown."),
237 GTK_PARAM_READWRITE));
238 g_object_interface_install_property (g_iface,
239 g_param_spec_boolean ("use-preview-label",
240 P_("Use Preview Label"),
241 P_("Whether to display a stock label with the name of the previewed file."),
243 GTK_PARAM_READWRITE));
244 g_object_interface_install_property (g_iface,
245 g_param_spec_object ("extra-widget",
247 P_("Application supplied widget for extra options."),
249 GTK_PARAM_READWRITE));
250 g_object_interface_install_property (g_iface,
251 g_param_spec_boolean ("select-multiple",
252 P_("Select Multiple"),
253 P_("Whether to allow multiple files to be selected"),
255 GTK_PARAM_READWRITE));
257 g_object_interface_install_property (g_iface,
258 g_param_spec_boolean ("show-hidden",
260 P_("Whether the hidden files and folders should be displayed"),
262 GTK_PARAM_READWRITE));
265 * GtkFileChooser:do-overwrite-confirmation:
267 * Whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode
268 * will present an overwrite confirmation dialog if the user
269 * selects a file name that already exists.
273 g_object_interface_install_property (g_iface,
274 g_param_spec_boolean ("do-overwrite-confirmation",
275 P_("Do overwrite confirmation"),
276 P_("Whether a file chooser in save mode "
277 "will present an overwrite confirmation dialog "
280 GTK_PARAM_READWRITE));
284 * gtk_file_chooser_error_quark:
286 * Registers an error quark for #GtkFileChooser if necessary.
288 * Return value: The error quark used for #GtkFileChooser errors.
293 gtk_file_chooser_error_quark (void)
295 static GQuark quark = 0;
297 quark = g_quark_from_static_string ("gtk-file-chooser-error-quark");
302 * gtk_file_chooser_set_action:
303 * @chooser: a #GtkFileChooser
304 * @action: the action that the file selector is performing
306 * Sets the type of operation that the chooser is performing; the
307 * user interface is adapted to suit the selected action. For example,
308 * an option to create a new folder might be shown if the action is
309 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
310 * %GTK_FILE_CHOOSER_ACTION_OPEN.
315 gtk_file_chooser_set_action (GtkFileChooser *chooser,
316 GtkFileChooserAction action)
318 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
320 g_object_set (chooser, "action", action, NULL);
324 * gtk_file_chooser_get_action:
325 * @chooser: a #GtkFileChooser
327 * Gets the type of operation that the file chooser is performing; see
328 * gtk_file_chooser_set_action().
330 * Return value: the action that the file selector is performing
335 gtk_file_chooser_get_action (GtkFileChooser *chooser)
337 GtkFileChooserAction action;
339 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
341 g_object_get (chooser, "action", &action, NULL);
347 * gtk_file_chooser_set_local_only:
348 * @chooser: a #GtkFileChooser
349 * @local_only: %TRUE if only local files can be selected
351 * Sets whether only local files can be selected in the
352 * file selector. If @local_only is %TRUE (the default),
353 * then the selected file are files are guaranteed to be
354 * accessible through the operating systems native file
355 * file system and therefore the application only
356 * needs to worry about the filename functions in
357 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
358 * rather than the URI functions like
359 * gtk_file_chooser_get_uri(),
364 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
367 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
369 g_object_set (chooser, "local-only", local_only, NULL);
373 * gtk_file_chooser_get_local_only:
374 * @chooser: a #GtkFileChoosre
376 * Gets whether only local files can be selected in the
377 * file selector. See gtk_file_chooser_set_local_only()
379 * Return value: %TRUE if only local files can be selected.
384 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
388 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
390 g_object_get (chooser, "local-only", &local_only, NULL);
396 * gtk_file_chooser_set_select_multiple:
397 * @chooser: a #GtkFileChooser
398 * @select_multiple: %TRUE if multiple files can be selected.
400 * Sets whether multiple files can be selected in the file selector. This is
401 * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
402 * GTK_FILE_CHOOSER_ACTION_SAVE. It cannot be set with either of the folder
408 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
409 gboolean select_multiple)
411 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
413 g_object_set (chooser, "select-multiple", select_multiple, NULL);
417 * gtk_file_chooser_get_select_multiple:
418 * @chooser: a #GtkFileChooser
420 * Gets whether multiple files can be selected in the file
421 * selector. See gtk_file_chooser_set_select_multiple().
423 * Return value: %TRUE if multiple files can be selected.
428 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
430 gboolean select_multiple;
432 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
434 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
436 return select_multiple;
440 * gtk_file_chooser_get_filename:
441 * @chooser: a #GtkFileChooser
443 * Gets the filename for the currently selected file in
444 * the file selector. If multiple files are selected,
445 * one of the filenames will be returned at random.
447 * If the file chooser is in folder mode, this function returns the selected
450 * Return value: The currently selected filename, or %NULL
451 * if no file is selected, or the selected file can't
452 * be represented with a local filename. Free with g_free().
457 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
459 GtkFileSystem *file_system;
461 gchar *result = NULL;
463 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
465 file_system = _gtk_file_chooser_get_file_system (chooser);
466 path = gtk_file_chooser_get_path (chooser);
469 result = gtk_file_system_path_to_filename (file_system, path);
470 gtk_file_path_free (path);
477 * gtk_file_chooser_set_filename:
478 * @chooser: a #GtkFileChooser
479 * @filename: the filename to set as current
481 * Sets @filename as the current filename for the file chooser, by changing
482 * to the file's parent folder and actually selecting the file in list. If
483 * the @chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
484 * will also appear in the dialog's file name entry.
486 * If the file name isn't in the current folder of @chooser, then the current
487 * folder of @chooser will be changed to the folder containing @filename. This
488 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
489 * gtk_file_chooser_select_filename().
491 * Note that the file must exist, or nothing will be done except
492 * for the directory change.
494 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog, you
495 * should use this function if you already have a file name to which the user may save; for example,
496 * when the user opens an existing file and then does <guimenuitem>File/Save As...</guimenuitem>
497 * on it. If you don't have a file name already — for example, if the user just created
498 * a new file and is saving it for the first time, do not call this function. Instead, use
499 * something similar to this:
502 * if (document_is_new)
504 * /<!-- -->* the user just created a new document *<!-- -->/
505 * gtk_file_chooser_set_current_folder (chooser, default_folder_for_saving);
506 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
510 * /<!-- -->* the user edited an existing document *<!-- -->/
511 * gtk_file_chooser_set_filename (chooser, existing_filename);
515 * Return value: %TRUE if both the folder could be changed and the file was
516 * selected successfully, %FALSE otherwise.
521 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
522 const gchar *filename)
524 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
526 gtk_file_chooser_unselect_all (chooser);
527 return gtk_file_chooser_select_filename (chooser, filename);
531 * gtk_file_chooser_select_filename:
532 * @chooser: a #GtkFileChooser
533 * @filename: the filename to select
535 * Selects a filename. If the file name isn't in the current
536 * folder of @chooser, then the current folder of @chooser will
537 * be changed to the folder containing @filename.
539 * Return value: %TRUE if both the folder could be changed and the file was
540 * selected successfully, %FALSE otherwise.
545 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
546 const gchar *filename)
548 GtkFileSystem *file_system;
552 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
553 g_return_val_if_fail (filename != NULL, FALSE);
555 file_system = _gtk_file_chooser_get_file_system (chooser);
557 path = gtk_file_system_filename_to_path (file_system, filename);
560 result = _gtk_file_chooser_select_path (chooser, path, NULL);
561 gtk_file_path_free (path);
570 * gtk_file_chooser_unselect_filename:
571 * @chooser: a #GtkFileChooser
572 * @filename: the filename to unselect
574 * Unselects a currently selected filename. If the filename
575 * is not in the current directory, does not exist, or
576 * is otherwise not currently selected, does nothing.
581 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
582 const char *filename)
584 GtkFileSystem *file_system;
587 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
588 g_return_if_fail (filename != NULL);
590 file_system = _gtk_file_chooser_get_file_system (chooser);
592 path = gtk_file_system_filename_to_path (file_system, filename);
595 _gtk_file_chooser_unselect_path (chooser, path);
596 gtk_file_path_free (path);
600 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
602 file_paths_to_strings (GtkFileSystem *fs,
604 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
610 for (; paths; paths = paths->next)
616 string = (* convert_func) (fs, path);
619 strings = g_slist_prepend (strings, string);
622 return g_slist_reverse (strings);
626 * gtk_file_chooser_get_filenames:
627 * @chooser: a #GtkFileChooser
629 * Lists all the selected files and subfolders in the current folder of
630 * @chooser. The returned names are full absolute paths. If files in the current
631 * folder cannot be represented as local filenames they will be ignored. (See
632 * gtk_file_chooser_get_uris())
634 * Return value: a #GSList containing the filenames of all selected
635 * files and subfolders in the current folder. Free the returned list
636 * with g_slist_free(), and the filenames with g_free().
641 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
643 GtkFileSystem *file_system;
647 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
649 file_system = _gtk_file_chooser_get_file_system (chooser);
650 paths = _gtk_file_chooser_get_paths (chooser);
652 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
653 gtk_file_paths_free (paths);
658 * gtk_file_chooser_set_current_folder:
659 * @chooser: a #GtkFileChooser
660 * @filename: the full path of the new current folder
662 * Sets the current folder for @chooser from a local filename.
663 * The user will be shown the full contents of the current folder,
664 * plus user interface elements for navigating to other folders.
666 * Return value: %TRUE if the folder could be changed successfully, %FALSE
672 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
673 const gchar *filename)
675 GtkFileSystem *file_system;
679 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
680 g_return_val_if_fail (filename != NULL, FALSE);
682 file_system = _gtk_file_chooser_get_file_system (chooser);
684 path = gtk_file_system_filename_to_path (file_system, filename);
687 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
688 gtk_file_path_free (path);
697 * gtk_file_chooser_get_current_folder:
698 * @chooser: a #GtkFileChooser
700 * Gets the current folder of @chooser as a local filename.
701 * See gtk_file_chooser_set_current_folder().
703 * Return value: the full path of the current folder, or %NULL if the current
704 * path cannot be represented as a local filename. Free with g_free(). This
705 * function will also return %NULL if the file chooser was unable to load the
706 * last folder that was requested from it; for example, as would be for calling
707 * gtk_file_chooser_set_current_folder() on a nonexistent folder.
712 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
714 GtkFileSystem *file_system;
718 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
720 file_system = _gtk_file_chooser_get_file_system (chooser);
722 path = _gtk_file_chooser_get_current_folder_path (chooser);
723 filename = gtk_file_system_path_to_filename (file_system, path);
724 gtk_file_path_free (path);
730 * gtk_file_chooser_set_current_name:
731 * @chooser: a #GtkFileChooser
732 * @name: the filename to use, as a UTF-8 string
734 * Sets the current name in the file selector, as if entered
735 * by the user. Note that the name passed in here is a UTF-8
736 * string rather than a filename. This function is meant for
737 * such uses as a suggested name in a "Save As..." dialog.
739 * If you want to preselect a particular existing file, you should use
740 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
741 * Please see the documentation for those functions for an example of using
742 * gtk_file_chooser_set_current_name() as well.
747 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
750 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
751 g_return_if_fail (name != NULL);
753 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
757 * gtk_file_chooser_get_uri:
758 * @chooser: a #GtkFileChooser
760 * Gets the URI for the currently selected file in
761 * the file selector. If multiple files are selected,
762 * one of the filenames will be returned at random.
764 * If the file chooser is in folder mode, this function returns the selected
767 * Return value: The currently selected URI, or %NULL
768 * if no file is selected. Free with g_free()
773 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
775 GtkFileSystem *file_system;
777 gchar *result = NULL;
779 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
781 file_system = _gtk_file_chooser_get_file_system (chooser);
782 path = gtk_file_chooser_get_path (chooser);
785 result = gtk_file_system_path_to_uri (file_system, path);
786 gtk_file_path_free (path);
793 * gtk_file_chooser_set_uri:
794 * @chooser: a #GtkFileChooser
795 * @uri: the URI to set as current
797 * Sets the file referred to by @uri as the current file for the file chooser,
798 * by changing to the URI's parent folder and actually selecting the URI in the
799 * list. If the @chooser is #GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
800 * name will also appear in the dialog's file name entry.
802 * If the URI isn't in the current folder of @chooser, then the current folder
803 * of @chooser will be changed to the folder containing @uri. This is equivalent
804 * to a sequence of gtk_file_chooser_unselect_all() followed by
805 * gtk_file_chooser_select_uri().
807 * Note that the URI must exist, or nothing will be done except
808 * for the directory change.
809 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog, you
810 * should use this function if you already have a file name to which the user may save; for example,
811 * when the user opens an existing file and then does <guimenuitem>File/Save As...</guimenuitem>
812 * on it. If you don't have a file name already — for example, if the user just created
813 * a new file and is saving it for the first time, do not call this function. Instead, use
814 * something similar to this:
817 * if (document_is_new)
819 * /<!-- -->* the user just created a new document *<!-- -->/
820 * gtk_file_chooser_set_current_folder_uri (chooser, default_folder_for_saving);
821 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
825 * /<!-- -->* the user edited an existing document *<!-- -->/
826 * gtk_file_chooser_set_uri (chooser, existing_uri);
830 * Return value: %TRUE if both the folder could be changed and the URI was
831 * selected successfully, %FALSE otherwise.
836 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
839 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
841 gtk_file_chooser_unselect_all (chooser);
842 return gtk_file_chooser_select_uri (chooser, uri);
846 * gtk_file_chooser_select_uri:
847 * @chooser: a #GtkFileChooser
848 * @uri: the URI to select
850 * Selects the file to by @uri. If the URI doesn't refer to a
851 * file in the current folder of @chooser, then the current folder of
852 * @chooser will be changed to the folder containing @filename.
854 * Return value: %TRUE if both the folder could be changed and the URI was
855 * selected successfully, %FALSE otherwise.
860 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
863 GtkFileSystem *file_system;
867 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
868 g_return_val_if_fail (uri != NULL, FALSE);
870 file_system = _gtk_file_chooser_get_file_system (chooser);
872 path = gtk_file_system_uri_to_path (file_system, uri);
875 result = _gtk_file_chooser_select_path (chooser, path, NULL);
876 gtk_file_path_free (path);
885 * gtk_file_chooser_unselect_uri:
886 * @chooser: a #GtkFileChooser
887 * @uri: the URI to unselect
889 * Unselects the file referred to by @uri. If the file
890 * is not in the current directory, does not exist, or
891 * is otherwise not currently selected, does nothing.
896 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
899 GtkFileSystem *file_system;
902 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
903 g_return_if_fail (uri != NULL);
905 file_system = _gtk_file_chooser_get_file_system (chooser);
907 path = gtk_file_system_uri_to_path (file_system, uri);
910 _gtk_file_chooser_unselect_path (chooser, path);
911 gtk_file_path_free (path);
916 * gtk_file_chooser_select_all:
917 * @chooser: a #GtkFileChooser
919 * Selects all the files in the current folder of a file chooser.
924 gtk_file_chooser_select_all (GtkFileChooser *chooser)
926 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
928 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
932 * gtk_file_chooser_unselect_all:
933 * @chooser: a #GtkFileChooser
935 * Unselects all the files in the current folder of a file chooser.
940 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
943 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
945 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
949 * gtk_file_chooser_get_uris:
950 * @chooser: a #GtkFileChooser
952 * Lists all the selected files and subfolders in the current folder of
953 * @chooser. The returned names are full absolute URIs.
955 * Return value: a #GSList containing the URIs of all selected
956 * files and subfolders in the current folder. Free the returned list
957 * with g_slist_free(), and the filenames with g_free().
962 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
964 GtkFileSystem *file_system;
968 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
970 file_system = _gtk_file_chooser_get_file_system (chooser);
971 paths = _gtk_file_chooser_get_paths (chooser);
973 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
974 gtk_file_paths_free (paths);
979 * gtk_file_chooser_set_current_folder_uri:
980 * @chooser: a #GtkFileChooser
981 * @uri: the URI for the new current folder
983 * Sets the current folder for @chooser from an URI.
984 * The user will be shown the full contents of the current folder,
985 * plus user interface elements for navigating to other folders.
987 * Return value: %TRUE if the folder could be changed successfully, %FALSE
993 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
996 GtkFileSystem *file_system;
1000 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1001 g_return_val_if_fail (uri != NULL, FALSE);
1003 file_system = _gtk_file_chooser_get_file_system (chooser);
1005 path = gtk_file_system_uri_to_path (file_system, uri);
1008 result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
1009 gtk_file_path_free (path);
1018 * gtk_file_chooser_get_current_folder_uri:
1019 * @chooser: a #GtkFileChooser
1021 * Gets the current folder of @chooser as an URI.
1022 * See gtk_file_chooser_set_current_folder_uri().
1024 * Return value: the URI for the current folder. Free with g_free(). This
1025 * function will also return %NULL if the file chooser was unable to load the
1026 * last folder that was requested from it; for example, as would be for calling
1027 * gtk_file_chooser_set_current_folder_uri() on a nonexistent folder.
1032 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
1034 GtkFileSystem *file_system;
1038 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1040 file_system = _gtk_file_chooser_get_file_system (chooser);
1042 path = _gtk_file_chooser_get_current_folder_path (chooser);
1043 uri = gtk_file_system_path_to_uri (file_system, path);
1044 gtk_file_path_free (path);
1050 * _gtk_file_chooser_set_current_folder_path:
1051 * @chooser: a #GtkFileChooser
1052 * @path: the #GtkFilePath for the new folder
1053 * @error: location to store error, or %NULL.
1055 * Sets the current folder for @chooser from a #GtkFilePath.
1056 * Internal function, see gtk_file_chooser_set_current_folder_uri().
1058 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1064 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
1065 const GtkFilePath *path,
1068 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1069 g_return_val_if_fail (path != NULL, FALSE);
1070 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1072 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path, error);
1076 * _gtk_file_chooser_get_current_folder_path:
1077 * @chooser: a #GtkFileChooser
1079 * Gets the current folder of @chooser as #GtkFilePath.
1080 * See gtk_file_chooser_get_current_folder_uri().
1082 * Return value: the #GtkFilePath for the current folder.
1083 * Free with gtk_file_path_free().
1088 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
1090 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1092 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1096 * _gtk_file_chooser_select_path:
1097 * @chooser: a #GtkFileChooser
1098 * @path: the path to select
1099 * @error: location to store error, or %NULL
1101 * Selects the file referred to by @path. An internal function. See
1102 * _gtk_file_chooser_select_uri().
1104 * Return value: %TRUE if both the folder could be changed and the path was
1105 * selected successfully, %FALSE otherwise.
1110 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
1111 const GtkFilePath *path,
1114 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1115 g_return_val_if_fail (path != NULL, FALSE);
1116 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1118 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path, error);
1122 * _gtk_file_chooser_unselect_path:
1123 * @chooser: a #GtkFileChooser
1124 * @path: the filename to path
1126 * Unselects the file referred to by @path. An internal
1127 * function. See _gtk_file_chooser_unselect_uri().
1132 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
1133 const GtkFilePath *path)
1135 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1137 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
1141 * _gtk_file_chooser_get_paths:
1142 * @chooser: a #GtkFileChooser
1144 * Lists all the selected files and subfolders in the current folder of @chooser
1145 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
1147 * Return value: a #GSList containing a #GtkFilePath for each selected
1148 * file and subfolder in the current folder. Free the returned list
1149 * with g_slist_free(), and the paths with gtk_file_path_free().
1154 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
1156 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1158 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
1161 static GtkFilePath *
1162 gtk_file_chooser_get_path (GtkFileChooser *chooser)
1165 GtkFilePath *result = NULL;
1167 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1169 list = _gtk_file_chooser_get_paths (chooser);
1172 result = list->data;
1173 list = g_slist_delete_link (list, list);
1174 gtk_file_paths_free (list);
1181 * _gtk_file_chooser_get_file_system:
1182 * @chooser: a #GtkFileChooser
1184 * Gets the #GtkFileSystem of @chooser; this is an internal
1185 * implementation detail, used for conversion between paths
1186 * and filenames and URIs.
1188 * Return value: the file system for @chooser.
1193 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1195 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1197 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1203 * gtk_file_chooser_set_preview_widget:
1204 * @chooser: a #GtkFileChooser
1205 * @preview_widget: widget for displaying preview.
1207 * Sets an application-supplied widget to use to display a custom preview
1208 * of the currently selected file. To implement a preview, after setting the
1209 * preview widget, you connect to the ::update-preview
1210 * signal, and call gtk_file_chooser_get_preview_filename() or
1211 * gtk_file_chooser_get_preview_uri() on each change. If you can
1212 * display a preview of the new file, update your widget and
1213 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1214 * Otherwise, set the preview inactive.
1216 * When there is no application-supplied preview widget, or the
1217 * application-supplied preview widget is not active, the file chooser
1218 * may display an internally generated preview of the current file or
1219 * it may display no preview at all.
1224 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1225 GtkWidget *preview_widget)
1227 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1229 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1233 * gtk_file_chooser_get_preview_widget:
1234 * @chooser: a #GtkFileChooser
1236 * Gets the current preview widget; see
1237 * gtk_file_chooser_set_preview_widget().
1239 * Return value: the current preview widget, or %NULL
1244 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1246 GtkWidget *preview_widget;
1248 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1250 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1252 /* Horrid hack; g_object_get() refs returned objects but
1253 * that contradicts the memory management conventions
1257 g_object_unref (preview_widget);
1259 return preview_widget;
1263 * gtk_file_chooser_set_preview_widget_active:
1264 * @chooser: a #GtkFileChooser
1265 * @active: whether to display the user-specified preview widget
1267 * Sets whether the preview widget set by
1268 * gtk_file_chooser_set_preview_widget() should be shown for the
1269 * current filename. When @active is set to false, the file chooser
1270 * may display an internally generated preview of the current file
1271 * or it may display no preview at all. See
1272 * gtk_file_chooser_set_preview_widget() for more details.
1277 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1280 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1282 g_object_set (chooser, "preview-widget-active", active, NULL);
1286 * gtk_file_chooser_get_preview_widget_active:
1287 * @chooser: a #GtkFileChooser
1289 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1290 * should be shown for the current filename. See
1291 * gtk_file_chooser_set_preview_widget_active().
1293 * Return value: %TRUE if the preview widget is active for the current filename.
1298 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1302 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1304 g_object_get (chooser, "preview-widget-active", &active, NULL);
1310 * gtk_file_chooser_set_use_preview_label:
1311 * @chooser: a #GtkFileChooser
1312 * @use_label: whether to display a stock label with the name of the previewed file
1314 * Sets whether the file chooser should display a stock label with the name of
1315 * the file that is being previewed; the default is %TRUE. Applications that
1316 * want to draw the whole preview area themselves should set this to %FALSE and
1317 * display the name themselves in their preview widget.
1319 * See also: gtk_file_chooser_set_preview_widget()
1324 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1327 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1329 g_object_set (chooser, "use-preview-label", use_label, NULL);
1333 * gtk_file_chooser_get_use_preview_label:
1334 * @chooser: a #GtkFileChooser
1336 * Gets whether a stock label should be drawn with the name of the previewed
1337 * file. See gtk_file_chooser_set_use_preview_label().
1339 * Return value: %TRUE if the file chooser is set to display a label with the
1340 * name of the previewed file, %FALSE otherwise.
1343 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1347 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1349 g_object_get (chooser, "use-preview-label", &use_label, NULL);
1355 * gtk_file_chooser_get_preview_filename:
1356 * @chooser: a #GtkFileChooser
1358 * Gets the filename that should be previewed in a custom preview
1359 * Internal function, see gtk_file_chooser_get_preview_uri().
1361 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1362 * is selected. Free with gtk_file_path_free().
1367 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1369 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1371 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1375 * _gtk_file_chooser_add_shortcut_folder:
1376 * @chooser: a #GtkFileChooser
1377 * @path: path of the folder to add
1378 * @error: location to store error, or %NULL
1380 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1381 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1383 * Return value: %TRUE if the folder could be added successfully, %FALSE
1389 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1390 const GtkFilePath *path,
1393 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1394 g_return_val_if_fail (path != NULL, FALSE);
1396 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1400 * _gtk_file_chooser_remove_shortcut_folder:
1401 * @chooser: a #GtkFileChooser
1402 * @path: path of the folder to remove
1403 * @error: location to store error, or %NULL
1405 * Removes a folder from the shortcut folders in a file chooser. Internal
1406 * function, see gtk_file_chooser_remove_shortcut_folder().
1408 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1414 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1415 const GtkFilePath *path,
1418 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1419 g_return_val_if_fail (path != NULL, FALSE);
1421 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1425 * gtk_file_chooser_get_preview_filename:
1426 * @chooser: a #GtkFileChooser
1428 * Gets the filename that should be previewed in a custom preview
1429 * widget. See gtk_file_chooser_set_preview_widget().
1431 * Return value: the filename to preview, or %NULL if no file
1432 * is selected, or if the selected file cannot be represented
1433 * as a local filename. Free with g_free()
1438 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1440 GtkFileSystem *file_system;
1442 gchar *result = NULL;
1444 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1446 file_system = _gtk_file_chooser_get_file_system (chooser);
1447 path = _gtk_file_chooser_get_preview_path (chooser);
1450 result = gtk_file_system_path_to_filename (file_system, path);
1451 gtk_file_path_free (path);
1458 * gtk_file_chooser_get_preview_uri:
1459 * @chooser: a #GtkFileChooser
1461 * Gets the URI that should be previewed in a custom preview
1462 * widget. See gtk_file_chooser_set_preview_widget().
1464 * Return value: the URI for the file to preview, or %NULL if no file is
1465 * selected. Free with g_free().
1470 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1472 GtkFileSystem *file_system;
1474 gchar *result = NULL;
1476 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1478 file_system = _gtk_file_chooser_get_file_system (chooser);
1479 path = _gtk_file_chooser_get_preview_path (chooser);
1482 result = gtk_file_system_path_to_uri (file_system, path);
1483 gtk_file_path_free (path);
1490 * gtk_file_chooser_set_extra_widget:
1491 * @chooser: a #GtkFileChooser
1492 * @extra_widget: widget for extra options
1494 * Sets an application-supplied widget to provide extra options to the user.
1499 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1500 GtkWidget *extra_widget)
1502 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1504 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1508 * gtk_file_chooser_get_extra_widget:
1509 * @chooser: a #GtkFileChooser
1511 * Gets the current preview widget; see
1512 * gtk_file_chooser_set_extra_widget().
1514 * Return value: the current extra widget, or %NULL
1519 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1521 GtkWidget *extra_widget;
1523 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1525 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1527 /* Horrid hack; g_object_get() refs returned objects but
1528 * that contradicts the memory management conventions
1532 g_object_unref (extra_widget);
1534 return extra_widget;
1538 * gtk_file_chooser_add_filter:
1539 * @chooser: a #GtkFileChooser
1540 * @filter: a #GtkFileFilter
1542 * Adds @filter to the list of filters that the user can select between.
1543 * When a filter is selected, only files that are passed by that
1544 * filter are displayed.
1546 * Note that the @chooser takes ownership of the filter, so you have to
1547 * ref and sink it if you want to keep a reference.
1552 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1553 GtkFileFilter *filter)
1555 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1557 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1561 * gtk_file_chooser_remove_filter:
1562 * @chooser: a #GtkFileChooser
1563 * @filter: a #GtkFileFilter
1565 * Removes @filter from the list of filters that the user can select between.
1570 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1571 GtkFileFilter *filter)
1573 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1575 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1579 * gtk_file_chooser_list_filters:
1580 * @chooser: a #GtkFileChooser
1582 * Lists the current set of user-selectable filters; see
1583 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1585 * Return value: a #GSList containing the current set of
1586 * user selectable filters. The contents of the list are
1587 * owned by GTK+, but you must free the list itself with
1588 * g_slist_free() when you are done with it.
1593 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1595 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1597 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1601 * gtk_file_chooser_set_filter:
1602 * @chooser: a #GtkFileChooser
1603 * @filter: a #GtkFileFilter
1605 * Sets the current filter; only the files that pass the
1606 * filter will be displayed. If the user-selectable list of filters
1607 * is non-empty, then the filter should be one of the filters
1608 * in that list. Setting the current filter when the list of
1609 * filters is empty is useful if you want to restrict the displayed
1610 * set of files without letting the user change it.
1615 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1616 GtkFileFilter *filter)
1618 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1619 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1621 g_object_set (chooser, "filter", filter, NULL);
1625 * gtk_file_chooser_get_filter:
1626 * @chooser: a #GtkFileChooser
1628 * Gets the current filter; see gtk_file_chooser_set_filter().
1630 * Return value: the current filter, or %NULL
1635 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1637 GtkFileFilter *filter;
1639 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1641 g_object_get (chooser, "filter", &filter, NULL);
1642 /* Horrid hack; g_object_get() refs returned objects but
1643 * that contradicts the memory management conventions
1647 g_object_unref (filter);
1653 * gtk_file_chooser_add_shortcut_folder:
1654 * @chooser: a #GtkFileChooser
1655 * @folder: filename of the folder to add
1656 * @error: location to store error, or %NULL
1658 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1659 * Note that shortcut folders do not get saved, as they are provided by the
1660 * application. For example, you can use this to add a
1661 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1663 * Return value: %TRUE if the folder could be added successfully, %FALSE
1664 * otherwise. In the latter case, the @error will be set as appropriate.
1669 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1676 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1677 g_return_val_if_fail (folder != NULL, FALSE);
1679 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1683 GTK_FILE_CHOOSER_ERROR,
1684 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1685 _("Invalid filename: %s"),
1690 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1692 gtk_file_path_free (path);
1698 * gtk_file_chooser_remove_shortcut_folder:
1699 * @chooser: a #GtkFileChooser
1700 * @folder: filename of the folder to remove
1701 * @error: location to store error, or %NULL
1703 * Removes a folder from a file chooser's list of shortcut folders.
1705 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1706 * In the latter case, the @error will be set as appropriate.
1708 * See also: gtk_file_chooser_add_shortcut_folder()
1713 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1720 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1721 g_return_val_if_fail (folder != NULL, FALSE);
1723 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1727 GTK_FILE_CHOOSER_ERROR,
1728 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1729 _("Invalid filename: %s"),
1734 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1736 gtk_file_path_free (path);
1742 * gtk_file_chooser_list_shortcut_folders:
1743 * @chooser: a #GtkFileChooser
1745 * Queries the list of shortcut folders in the file chooser, as set by
1746 * gtk_file_chooser_add_shortcut_folder().
1748 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1749 * folders. Free the returned list with g_slist_free(), and the filenames with
1755 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1760 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1762 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1764 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1766 gtk_file_system_path_to_filename);
1767 gtk_file_paths_free (folders);
1772 * gtk_file_chooser_add_shortcut_folder_uri:
1773 * @chooser: a #GtkFileChooser
1774 * @uri: URI of the folder to add
1775 * @error: location to store error, or %NULL
1777 * Adds a folder URI to be displayed with the shortcut folders in a file
1778 * chooser. Note that shortcut folders do not get saved, as they are provided
1779 * by the application. For example, you can use this to add a
1780 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1782 * Return value: %TRUE if the folder could be added successfully, %FALSE
1783 * otherwise. In the latter case, the @error will be set as appropriate.
1788 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1795 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1796 g_return_val_if_fail (uri != NULL, FALSE);
1798 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1802 GTK_FILE_CHOOSER_ERROR,
1803 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1804 _("Invalid filename: %s"),
1809 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1811 gtk_file_path_free (path);
1817 * gtk_file_chooser_remove_shortcut_folder_uri:
1818 * @chooser: a #GtkFileChooser
1819 * @uri: URI of the folder to remove
1820 * @error: location to store error, or %NULL
1822 * Removes a folder URI from a file chooser's list of shortcut folders.
1824 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1825 * In the latter case, the @error will be set as appropriate.
1827 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1832 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1839 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1840 g_return_val_if_fail (uri != NULL, FALSE);
1842 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1846 GTK_FILE_CHOOSER_ERROR,
1847 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1848 _("Invalid filename: %s"),
1853 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1855 gtk_file_path_free (path);
1861 * gtk_file_chooser_list_shortcut_folder_uris:
1862 * @chooser: a #GtkFileChooser
1864 * Queries the list of shortcut folders in the file chooser, as set by
1865 * gtk_file_chooser_add_shortcut_folder_uri().
1867 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1868 * folders. Free the returned list with g_slist_free(), and the URIs with
1874 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1879 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1881 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1883 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1885 gtk_file_system_path_to_uri);
1886 gtk_file_paths_free (folders);
1892 * gtk_file_chooser_set_show_hidden:
1893 * @chooser: a #GtkFileChooser
1894 * @show_hidden: %TRUE if hidden files and folders should be displayed.
1896 * Sets whether hidden files and folders are displayed in the file selector.
1901 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1902 gboolean show_hidden)
1904 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1906 g_object_set (chooser, "show-hidden", show_hidden, NULL);
1910 * gtk_file_chooser_get_show_hidden:
1911 * @chooser: a #GtkFileChooser
1913 * Gets whether hidden files and folders are displayed in the file selector.
1914 * See gtk_file_chooser_set_show_hidden().
1916 * Return value: %TRUE if hidden files and folders are displayed.
1921 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1923 gboolean show_hidden;
1925 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1927 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1933 * gtk_file_chooser_set_do_overwrite_confirmation:
1934 * @chooser: a #GtkFileChooser
1935 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1937 * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1938 * a confirmation dialog if the user types a file name that already exists. This
1939 * is %FALSE by default.
1941 * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1942 * signal when appropriate.
1944 * If all you need is the stock confirmation dialog, set this property to %TRUE.
1945 * You can override the way confirmation is done by actually handling the
1946 * "confirm-overwrite" signal; please refer to its documentation for the
1952 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
1953 gboolean do_overwrite_confirmation)
1955 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1957 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
1961 * gtk_file_chooser_get_do_overwrite_confirmation:
1962 * @chooser: a #GtkFileChooser
1964 * Queries whether a file chooser is set to confirm for overwriting when the user
1965 * types a file name that already exists.
1967 * Return value: %TRUE if the file chooser will present a confirmation dialog;
1973 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
1975 gboolean do_overwrite_confirmation;
1977 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1979 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
1981 return do_overwrite_confirmation;
1986 /* DLL ABI stability backward compatibility versions */
1988 #undef gtk_file_chooser_get_filename
1991 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
1993 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
1994 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
1996 g_free (utf8_filename);
2001 #undef gtk_file_chooser_set_filename
2004 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
2005 const gchar *filename)
2007 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2008 gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
2010 g_free (utf8_filename);
2015 #undef gtk_file_chooser_select_filename
2018 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2019 const gchar *filename)
2021 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2022 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2024 g_free (utf8_filename);
2029 #undef gtk_file_chooser_unselect_filename
2032 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2033 const char *filename)
2035 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2037 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2038 g_free (utf8_filename);
2041 #undef gtk_file_chooser_get_filenames
2044 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2046 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2047 GSList *rover = list;
2051 gchar *tem = (gchar *) rover->data;
2052 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2054 rover = rover->next;
2060 #undef gtk_file_chooser_set_current_folder
2063 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2064 const gchar *filename)
2066 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2067 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2069 g_free (utf8_filename);
2074 #undef gtk_file_chooser_get_current_folder
2077 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2079 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2080 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2082 g_free (utf8_folder);
2087 #undef gtk_file_chooser_get_preview_filename
2090 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2092 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2093 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2095 g_free (utf8_filename);
2100 #undef gtk_file_chooser_add_shortcut_folder
2103 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2107 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2109 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2111 g_free (utf8_folder);
2116 #undef gtk_file_chooser_remove_shortcut_folder
2119 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2123 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2125 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2127 g_free (utf8_folder);
2132 #undef gtk_file_chooser_list_shortcut_folders
2135 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2137 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2138 GSList *rover = list;
2142 gchar *tem = (gchar *) rover->data;
2143 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2145 rover = rover->next;
2153 #define __GTK_FILE_CHOOSER_C__
2154 #include "gtkaliasdef.c"