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.
21 #include "gtkfilechooser.h"
22 #include "gtkfilechooserprivate.h"
23 #include "gtkfilechooserenums.h"
24 #include "gtkfilesystem.h"
28 static void gtk_file_chooser_class_init (gpointer g_iface);
30 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
33 gtk_file_chooser_get_type (void)
35 static GType file_chooser_type = 0;
37 if (!file_chooser_type)
39 static const GTypeInfo file_chooser_info =
41 sizeof (GtkFileChooserIface), /* class_size */
43 NULL, /* base_finalize */
44 (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
47 file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
49 &file_chooser_info, 0);
51 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
54 return file_chooser_type;
58 gtk_file_chooser_class_init (gpointer g_iface)
60 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
62 g_signal_new ("current-folder-changed",
65 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
67 g_cclosure_marshal_VOID__VOID,
69 g_signal_new ("selection-changed",
72 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
74 g_cclosure_marshal_VOID__VOID,
76 g_signal_new ("update-preview",
79 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
81 g_cclosure_marshal_VOID__VOID,
83 g_signal_new ("file-activated",
86 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
88 g_cclosure_marshal_VOID__VOID,
91 g_object_interface_install_property (g_iface,
92 g_param_spec_enum ("action",
94 _("The type of operation that the file selector is performing"),
95 GTK_TYPE_FILE_CHOOSER_ACTION,
96 GTK_FILE_CHOOSER_ACTION_OPEN,
98 g_object_interface_install_property (g_iface,
99 g_param_spec_object ("file-system",
101 _("File system object to use"),
102 GTK_TYPE_FILE_SYSTEM,
103 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
104 g_object_interface_install_property (g_iface,
105 g_param_spec_object ("filter",
107 _("The current filter for selecting which files are displayed"),
108 GTK_TYPE_FILE_FILTER,
110 g_object_interface_install_property (g_iface,
111 g_param_spec_boolean ("folder-mode",
113 _("Whether to select folders rather than files"),
116 g_object_interface_install_property (g_iface,
117 g_param_spec_boolean ("local-only",
119 _("Whether the selected file(s) should be limited to local file: URLs"),
122 g_object_interface_install_property (g_iface,
123 g_param_spec_object ("preview-widget",
125 _("Application supplied widget for custom previews."),
128 g_object_interface_install_property (g_iface,
129 g_param_spec_boolean ("preview-widget-active",
130 _("Preview Widget Active"),
131 _("Whether the application supplied widget for custom previews should be shown."),
134 g_object_interface_install_property (g_iface,
135 g_param_spec_object ("extra-widget",
137 _("Application supplied widget for extra options."),
140 g_object_interface_install_property (g_iface,
141 g_param_spec_boolean ("select-multiple",
142 _("Select Multiple"),
143 _("Whether to allow multiple files to be selected"),
147 g_object_interface_install_property (g_iface,
148 g_param_spec_boolean ("show-hidden",
150 _("Whether the hidden files and folders should be displayed"),
156 * gtk_file_chooser_error_quark:
158 * Registers an error quark for #GtkFileChooser if necessary.
160 * Return value: The error quark used for #GtkFileChooser errors.
163 gtk_file_chooser_error_quark (void)
165 static GQuark quark = 0;
167 quark = g_quark_from_static_string ("gtk-file-chooser-error-quark");
172 * gtk_file_chooser_set_action:
173 * @chooser: a #GtkFileChooser
174 * @action: the action that the file selector is performing
176 * Sets the type of operation that that the chooser is performing; the
177 * user interface is adapted to suit the selected action. For example,
178 * an option to create a new folder might be shown if the action is
179 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
180 * %GTK_FILE_CHOOSER_ACTION_OPEN.
183 gtk_file_chooser_set_action (GtkFileChooser *chooser,
184 GtkFileChooserAction action)
186 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
188 g_object_set (chooser, "action", action, NULL);
192 * gtk_file_chooser_get_action:
193 * @chooser: a #GtkFileChooser
195 * Gets the type of operation that the file chooser is performing; see
196 * gtk_file_chooser_set_action().
198 * Return value: the action that the file selector is performing
201 gtk_file_chooser_get_action (GtkFileChooser *chooser)
203 GtkFileChooserAction action;
205 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
207 g_object_get (chooser, "action", &action, NULL);
213 * gtk_file_chooser_set_folder_mode:
214 * @chooser: a #GtkFileChooser
215 * @folder_mode: %TRUE if the file chooser is used to select folders
218 * Sets whether the file chooser is used to select folders
219 * rather than files. If in folder mode, only folders are displayed
220 * to the use, and not the individual files inside the folders
221 * and the user selects a single folder rather than one or
225 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
226 gboolean folder_mode)
228 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
230 g_object_set (chooser, "folder-mode", folder_mode, NULL);
234 * gtk_file_chooser_get_folder_mode:
235 * @chooser: a #GtkFileChooser
237 * Gets whether the file chooser is used to select folders
238 * rather than files. See gtk_file_chooser_set_folder_mode()
240 * Return value: %TRUE if the file chooser is used to select
241 folders rather than files.
244 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
246 gboolean folder_mode;
248 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
250 g_object_get (chooser, "folder-mode", &folder_mode, NULL);
256 * gtk_file_chooser_set_local_only:
257 * @chooser: a #GtkFileChooser
258 * @local_only: %TRUE if only local files can be selected
260 * Sets whether only local files can be selected in the
261 * file selector. If @local_only is %TRUE (the default),
262 * then the selected file are files are guaranteed to be
263 * accessible through the operating systems native file
264 * file system and therefore the application only
265 * needs to worry about the filename functions in
266 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
267 * rather than the URI functions like
268 * gtk_file_chooser_get_uri(),
271 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
274 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
276 g_object_set (chooser, "local-only", local_only, NULL);
280 * gtk_file_chooser_get_local_only:
281 * @chooser: a #GtkFileChoosre
283 * Gets whether only local files can be selected in the
284 * file selector. See gtk_file_chooser_set_local_only()
286 * Return value: %TRUE if only local files can be selected.
289 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
293 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
295 g_object_get (chooser, "local-only", &local_only, NULL);
301 * gtk_file_chooser_set_select_multiple:
302 * @chooser: a #GtkFileChooser
303 * @select_multiple: %TRUE if multiple files can be selected.
305 * Sets whether multiple files can be selected in the file
306 * selector. If the file selector if in folder mode (see
307 * gtk_file_selector_set_folder_mode()) then only one folder
308 * can be selected, without regard to this setting.
311 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
312 gboolean select_multiple)
314 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
316 g_object_set (chooser, "select-multiple", select_multiple, NULL);
320 * gtk_file_chooser_get_select_multiple:
321 * @chooser: a #GtkFileChooser
323 * Gets whether multiple files can be selected in the file
324 * selector. See gtk_file_chooser_set_select_multiple().
326 * Return value: %TRUE if multiple files can be selected.
329 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
331 gboolean select_multiple;
333 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
335 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
337 return select_multiple;
341 * gtk_file_chooser_get_filename:
342 * @chooser: a #GtkFileChooser
344 * Gets the filename for the currently selected file in
345 * the file selector. If multiple files are selected,
346 * one of the filenames will be returned at random.
348 * Return value: The currently selected filename, or %NULL
349 * if no file is selected, or the selected file can't
350 * be represented with a local filename. Free with g_free().
353 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
355 GtkFileSystem *file_system;
357 gchar *result = NULL;
359 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
361 file_system = _gtk_file_chooser_get_file_system (chooser);
362 path = gtk_file_chooser_get_path (chooser);
365 result = gtk_file_system_path_to_filename (file_system, path);
366 gtk_file_path_free (path);
373 * gtk_file_chooser_set_filename:
374 * @chooser: a #GtkFileChooser
375 * @filename: the filename to set as current
377 * Sets @filename as the current filename for the the file chooser;
378 * If the file name isn't in the current folder of @chooser, then the
379 * current folder of @chooser will be changed to the folder containing
380 * @filename. This is equivalent to a sequence of
381 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
383 * Note that the file must exist, or nothing will be done except
384 * for the directory change. To pre-enter a filename for the user, as in
385 * a save-as dialog, use gtk_file_chooser_set_current_name()
388 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
389 const gchar *filename)
391 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
393 gtk_file_chooser_unselect_all (chooser);
394 gtk_file_chooser_select_filename (chooser, filename);
398 * gtk_file_chooser_select_filename:
399 * @chooser: a #GtkFileChooser
400 * @filename: the filename to select
402 * Selects a filename. If the file name isn't in the current
403 * folder of @chooser, then the current folder of @chooser will
404 * be changed to the folder containing @filename.
407 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
408 const gchar *filename)
410 GtkFileSystem *file_system;
413 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
414 g_return_if_fail (filename != NULL);
416 file_system = _gtk_file_chooser_get_file_system (chooser);
418 path = gtk_file_system_filename_to_path (file_system, filename);
421 _gtk_file_chooser_select_path (chooser, path);
422 gtk_file_path_free (path);
427 * gtk_file_chooser_unselect_filename:
428 * @chooser: a #GtkFileChooser
429 * @filename: the filename to unselect
431 * Unselects a currently selected filename. If the filename
432 * is not in the current directory, does not exist, or
433 * is otherwise not currently selected, does nothing.
436 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
437 const char *filename)
439 GtkFileSystem *file_system;
442 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
443 g_return_if_fail (filename != NULL);
445 file_system = _gtk_file_chooser_get_file_system (chooser);
447 path = gtk_file_system_filename_to_path (file_system, filename);
450 _gtk_file_chooser_unselect_path (chooser, path);
451 gtk_file_path_free (path);
455 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
457 file_paths_to_strings (GtkFileSystem *fs,
459 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
465 for (; paths; paths = paths->next)
471 string = (* convert_func) (fs, path);
474 strings = g_slist_prepend (strings, string);
477 return g_slist_reverse (strings);
481 * gtk_file_chooser_get_filenames:
482 * @chooser: a #GtkFileChooser
484 * Lists all the selected files and subfolders in the current folder of
485 * @chooser. The returned names are full absolute paths. If files in the current
486 * folder cannot be represented as local filenames they will be ignored. (See
487 * gtk_file_chooser_get_uris())
489 * Return value: a #GSList containing the filenames of all selected
490 * files and subfolders in the current folder. Free the returned list
491 * with g_slist_free(), and the filenames with g_free().
494 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
496 GtkFileSystem *file_system;
500 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
502 file_system = _gtk_file_chooser_get_file_system (chooser);
503 paths = _gtk_file_chooser_get_paths (chooser);
505 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
506 gtk_file_paths_free (paths);
511 * gtk_file_chooser_set_current_folder:
512 * @chooser: a #GtkFileChooser
513 * @filename: the full path of the new current folder
515 * Sets the current folder for @chooser from a local filename.
516 * The user will be shown the full contents of the current folder,
517 * plus user interface elements for navigating to other folders.
520 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
521 const gchar *filename)
523 GtkFileSystem *file_system;
526 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
527 g_return_if_fail (filename != NULL);
529 file_system = _gtk_file_chooser_get_file_system (chooser);
531 path = gtk_file_system_filename_to_path (file_system, filename);
534 _gtk_file_chooser_set_current_folder_path (chooser, path);
535 gtk_file_path_free (path);
540 * gtk_file_chooser_get_current_folder:
541 * @chooser: a #GtkFileChooser
543 * Gets the current folder of @chooser as a local filename.
544 * See gtk_file_chooser_set_current_folder().
546 * Return value: the full path of the current folder, or %NULL
547 * if the current path cannot be represented as a local filename.
548 * Free with g_free().
551 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
553 GtkFileSystem *file_system;
557 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
559 file_system = _gtk_file_chooser_get_file_system (chooser);
561 path = _gtk_file_chooser_get_current_folder_path (chooser);
562 filename = gtk_file_system_path_to_filename (file_system, path);
563 gtk_file_path_free (path);
569 * gtk_file_chooser_set_current_name:
570 * @chooser: a #GtkFileChooser
571 * @name: the filename to use, as a UTF-8 string
573 * Sets the current name in the file selector, as if entered
574 * by the user. Note that the name passed in here is a UTF-8
575 * string rather than a filename. This function is meant for
576 * such uses as a suggested name in a "Save As..." dialog.
578 * If you want to preselect a particular existing file, you
579 * should use gtk_file_chooser_set_filename() instead.
582 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
585 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
586 g_return_if_fail (name != NULL);
588 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
592 * gtk_file_chooser_get_uri:
593 * @chooser: a #GtkFileChooser
595 * Gets the URI for the currently selected file in
596 * the file selector. If multiple files are selected,
597 * one of the filenames will be returned at random.
599 * Return value: The currently selected URI, or %NULL
600 * if no file is selected. Free with g_free()
603 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
605 GtkFileSystem *file_system;
607 gchar *result = NULL;
609 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
611 file_system = _gtk_file_chooser_get_file_system (chooser);
612 path = gtk_file_chooser_get_path (chooser);
615 result = gtk_file_system_path_to_uri (file_system, path);
616 gtk_file_path_free (path);
623 * gtk_file_chooser_set_uri:
624 * @chooser: a #GtkFileChooser
625 * @uri: the URI to set as current
627 * Sets the file referred to by @uri as the current file for the the
628 * file chooser; If the file name isn't in the current folder of @chooser,
629 * then the current folder of @chooser will be changed to the folder containing
630 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
631 * followed by gtk_file_chooser_select_uri().
633 * Note that the file must exist, or nothing will be done except
634 * for the directory change. To pre-enter a filename for the user, as in
635 * a save-as dialog, use gtk_file_chooser_set_current_name()
638 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
641 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
643 gtk_file_chooser_unselect_all (chooser);
644 gtk_file_chooser_select_uri (chooser, uri);
648 * gtk_file_chooser_select_uri:
649 * @chooser: a #GtkFileChooser
650 * @uri: the URI to select
652 * Selects the file to by @uri. If the URI doesn't refer to a
653 * file in the current folder of @chooser, then the current folder of
654 * @chooser will be changed to the folder containing @filename.
657 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
660 GtkFileSystem *file_system;
663 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
664 g_return_if_fail (uri != NULL);
666 file_system = _gtk_file_chooser_get_file_system (chooser);
668 path = gtk_file_system_uri_to_path (file_system, uri);
671 _gtk_file_chooser_select_path (chooser, path);
672 gtk_file_path_free (path);
677 * gtk_file_chooser_unselect_uri:
678 * @chooser: a #GtkFileChooser
679 * @uri: the URI to unselect
681 * Unselects the file referred to by @uri. If the file
682 * is not in the current directory, does not exist, or
683 * is otherwise not currently selected, does nothing.
686 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
689 GtkFileSystem *file_system;
692 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
693 g_return_if_fail (uri != NULL);
695 file_system = _gtk_file_chooser_get_file_system (chooser);
697 path = gtk_file_system_uri_to_path (file_system, uri);
700 _gtk_file_chooser_unselect_path (chooser, path);
701 gtk_file_path_free (path);
706 gtk_file_chooser_select_all (GtkFileChooser *chooser)
708 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
710 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
714 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
717 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
719 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
723 * gtk_file_chooser_get_uris:
724 * @chooser: a #GtkFileChooser
726 * Lists all the selected files and subfolders in the current folder of
727 * @chooser. The returned names are full absolute URIs.
729 * Return value: a #GSList containing the URIs of all selected
730 * files and subfolders in the current folder. Free the returned list
731 * with g_slist_free(), and the filenames with g_free().
734 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
736 GtkFileSystem *file_system;
740 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
742 file_system = _gtk_file_chooser_get_file_system (chooser);
743 paths = _gtk_file_chooser_get_paths (chooser);
745 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
746 gtk_file_paths_free (paths);
751 * gtk_file_chooser_set_current_folder_uri:
752 * @chooser: a #GtkFileChooser
753 * @uri: the URI for the new current folder
755 * Sets the current folder for @chooser from an URI.
756 * The user will be shown the full contents of the current folder,
757 * plus user interface elements for navigating to other folders.
760 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
763 GtkFileSystem *file_system;
766 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
767 g_return_if_fail (uri != NULL);
769 file_system = _gtk_file_chooser_get_file_system (chooser);
771 path = gtk_file_system_uri_to_path (file_system, uri);
774 _gtk_file_chooser_set_current_folder_path (chooser, path);
775 gtk_file_path_free (path);
780 * gtk_file_chooser_get_current_folder_uri:
781 * @chooser: a #GtkFileChooser
783 * Gets the current folder of @chooser as an URI.
784 * See gtk_file_chooser_set_current_folder_uri().
786 * Return value: the URI for the current folder.
787 * Free with g_free().
790 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
792 GtkFileSystem *file_system;
796 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
798 file_system = _gtk_file_chooser_get_file_system (chooser);
800 path = _gtk_file_chooser_get_current_folder_path (chooser);
801 uri = gtk_file_system_path_to_uri (file_system, path);
802 gtk_file_path_free (path);
808 * _gtk_file_chooser_set_current_folder_path:
809 * @chooser: a #GtkFileChooser
810 * @path: the #GtkFilePath for the new folder
812 * Sets the current folder for @chooser from a #GtkFilePath.
813 * Internal function, see gtk_file_chooser_set_current_folder_uri().
816 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
817 const GtkFilePath *path)
819 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
820 g_return_if_fail (path != NULL);
822 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
826 * _gtk_file_chooser_get_current_folder_path:
827 * @chooser: a #GtkFileChooser
829 * Gets the current folder of @chooser as #GtkFilePath.
830 * See gtk_file_chooser_get_current_folder_uri().
832 * Return value: the #GtkFilePath for the current folder.
833 * Fre with gtk_file_path_free ().
836 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
838 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
840 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
844 * _gtk_file_chooser_select_path:
845 * @chooser: a #GtkFileChooser
846 * @path: the path to select
848 * Selects the file referred to by @path. An internal function. See
849 * _gtk_file_chooser_select_uri().
852 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
853 const GtkFilePath *path)
855 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
857 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
861 * _gtk_file_chooser_unselect_path:
862 * @chooser: a #GtkFileChooser
863 * @path: the filename to path
865 * Unselects the file referred to by @path. An internal
866 * function. See _gtk_file_chooser_unselect_uri().
869 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
870 const GtkFilePath *path)
872 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
874 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
878 * _gtk_file_chooser_get_paths:
879 * @chooser: a #GtkFileChooser
881 * Lists all the selected files and subfolders in the current folder of @chooser
882 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
884 * Return value: a #GSList containing a #GtkFilePath for each selected
885 * file and subfolder in the current folder. Free the returned list
886 * with g_slist_free(), and the paths with gtk_file_path_free().
889 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
891 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
893 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
897 gtk_file_chooser_get_path (GtkFileChooser *chooser)
900 GtkFilePath *result = NULL;
902 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
904 list = _gtk_file_chooser_get_paths (chooser);
908 list = g_slist_delete_link (list, list);
909 gtk_file_paths_free (list);
916 * _gtk_file_chooser_get_file_system:
917 * @chooser: a #GtkFileChooser
919 * Gets the #GtkFileSystem of @chooser; this is an internal
920 * implementation detail, used for conversion between paths
921 * and filenames and URIs.
923 * Return value: the file system for @chooser.
926 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
928 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
930 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
936 * gtk_file_chooser_set_preview_widget:
937 * @chooser: a #GtkFileChooser
938 * @preview_widget: widget for displaying preview.
940 * Sets an application-supplied widget to use to display a custom preview
941 * of the currently selected file. To implement a preview, after setting the
942 * preview widget, you connect to the ::selection-changed
943 * signal, and call gtk_file_chooser_get_preview_filename() or
944 * gtk_file_chooser_get_preview_uri() on each change. If you can
945 * display a preview of the new file, update your widget
946 * and set the preview active using gtk_file_chooser_set_preview_widget_active().
947 * Otherwise, set the preview inactive.
949 * When there is no application-supplied preview widget, or the
950 * application-supplied preview widget is not active, the file chooser
951 * may display an internally generated preview of the current file or
952 * it may display no preview at all.
955 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
956 GtkWidget *preview_widget)
958 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
960 g_object_set (chooser, "preview-widget", preview_widget, NULL);
964 * gtk_file_chooser_get_preview_widget:
965 * @chooser: a #GtkFileChooser
967 * Gets the current preview widget; see
968 * gtk_file_chooser_set_preview_widget().
970 * Return value: the current preview widget, or %NULL
973 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
975 GtkWidget *preview_widget;
977 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
979 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
981 /* Horrid hack; g_object_get() refs returned objects but
982 * that contradicts the memory management conventions
986 g_object_unref (preview_widget);
988 return preview_widget;
992 * gtk_file_chooser_set_preview_widget_active:
993 * @chooser: a #GtkFileChooser
994 * @active: whether to display the user-specified preview widget
996 * Sets whether the preview widget set by
997 * gtk_file_chooser_set_preview_widget_active() should be shown for the
998 * current filename. When @active is set to false, the file chooser
999 * may display an internally generated preview of the current file
1000 * or it may display no preview at all. See
1001 * gtk_file_chooser_set_preview_widget() for more details.
1004 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1007 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1009 g_object_set (chooser, "preview-widget-active", active, NULL);
1013 * gtk_file_chooser_get_preview_widget_active:
1014 * @chooser: a #GtkFileChooser
1016 * Gets whether the preview widget set by
1017 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1018 * current filename. See gtk_file_chooser_set_preview_widget_active().
1020 * Return value: %TRUE if the preview widget is active for the
1024 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1028 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1030 g_object_get (chooser, "preview-widget-active", &active, NULL);
1036 * gtk_file_chooser_get_preview_filename:
1037 * @chooser: a #GtkFileChooser
1039 * Gets the filename that should be previewed in a custom preview
1040 * Internal function, see gtk_file_chooser_get_preview_uri().
1042 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1043 * is selected. Free with gtk_file_path_free().
1046 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1048 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1050 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1054 * _gtk_file_chooser_add_shortcut_folder:
1055 * @chooser: a #GtkFileChooser
1056 * @path: path of the folder to add
1057 * @error: location to store error, or %NULL
1059 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1060 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1062 * Return value: TRUE if the folder could be added successfully, FALSE
1066 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1067 const GtkFilePath *path,
1070 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1071 g_return_val_if_fail (path != NULL, FALSE);
1073 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1077 * _gtk_file_chooser_remove_shortcut_folder:
1078 * @chooser: a #GtkFileChooser
1079 * @path: path of the folder to remove
1080 * @error: location to store error, or %NULL
1082 * Removes a folder from the shortcut folders in a file chooser. Internal
1083 * function, see gtk_file_chooser_remove_shortcut_folder().
1085 * Return value: TRUE if the folder could be removed successfully, FALSE
1089 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1090 const GtkFilePath *path,
1093 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1094 g_return_val_if_fail (path != NULL, FALSE);
1096 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1100 * gtk_file_chooser_get_preview_filename:
1101 * @chooser: a #GtkFileChooser
1103 * Gets the filename that should be previewed in a custom preview
1104 * widget. See gtk_file_chooser_set_preview_widget().
1106 * Return value: the filename to preview, or %NULL if no file
1107 * is selected, or if the selected file cannot be represented
1108 * as a local filename. Free with g_free()
1111 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1113 GtkFileSystem *file_system;
1115 gchar *result = NULL;
1117 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1119 file_system = _gtk_file_chooser_get_file_system (chooser);
1120 path = _gtk_file_chooser_get_preview_path (chooser);
1123 result = gtk_file_system_path_to_filename (file_system, path);
1124 gtk_file_path_free (path);
1131 * gtk_file_chooser_get_preview_filename:
1132 * @chooser: a #GtkFileChooser
1134 * Gets the URI that should be previewed in a custom preview
1135 * widget. See gtk_file_chooser_set_preview_widget().
1137 * Return value: the URI for the file to preview, or %NULL if no file
1138 * is selected. Free with g_free().
1141 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1143 GtkFileSystem *file_system;
1145 gchar *result = NULL;
1147 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1149 file_system = _gtk_file_chooser_get_file_system (chooser);
1150 path = _gtk_file_chooser_get_preview_path (chooser);
1153 result = gtk_file_system_path_to_uri (file_system, path);
1154 gtk_file_path_free (path);
1161 * gtk_file_chooser_set_extra_widget:
1162 * @chooser: a #GtkFileChooser
1163 * @extra_widget: widget for extra options
1165 * Sets an application-supplied widget to provide extra options to the user.
1168 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1169 GtkWidget *extra_widget)
1171 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1173 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1177 * gtk_file_chooser_get_extra_widget:
1178 * @chooser: a #GtkFileChooser
1180 * Gets the current preview widget; see
1181 * gtk_file_chooser_set_extra_widget().
1183 * Return value: the current extra widget, or %NULL
1186 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1188 GtkWidget *extra_widget;
1190 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1192 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1194 /* Horrid hack; g_object_get() refs returned objects but
1195 * that contradicts the memory management conventions
1199 g_object_unref (extra_widget);
1201 return extra_widget;
1205 * gtk_file_chooser_add_filter:
1206 * @chooser: a #GtkFileChooser
1207 * @filter: a #GtkFileFilter
1209 * Adds @filter to the list of filters that the user can select between.
1210 * When a filter is selected, only files that are passed by that
1211 * filter are displayed.
1214 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1215 GtkFileFilter *filter)
1217 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1219 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1223 * gtk_file_chooser_add_filter:
1224 * @chooser: a #GtkFileChooser
1225 * @filter: a #GtkFileFilter
1227 * Removes @filter from the list of filters that the user can select between.
1230 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1231 GtkFileFilter *filter)
1233 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1235 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1239 * gtk_file_chooser_list_filters:
1240 * @choooser: a #GtkFileChooser
1242 * Lists the current set of user-selectable filters; see
1243 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1245 * Return value: a #GSList containing the current set of
1246 * user selectable filters. The contents of the list are
1247 * owned by GTK+, but you must free the list itself with
1248 * g_slist_free() when you are done with it.
1251 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1253 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1255 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1259 * gtk_file_chooser_set_filter:
1260 * @chooser: a #GtkFileChooser
1261 * @filter: a #GtkFileFilter
1263 * Sets the current filter; only the files that pass the
1264 * filter will be displayed. If the user-selectable list of filters
1265 * is non-empty, then the filter should be one of the filters
1266 * in that list. Setting the current filter when the list of
1267 * filters is empty is useful if you want to restrict the displayed
1268 * set of files without letting the user change it.
1271 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1272 GtkFileFilter *filter)
1274 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1275 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1277 g_object_set (chooser, "filter", filter, NULL);
1281 * gtk_file_chooser_get_filter:
1282 * @chooser: a #GtkFileChooser
1284 * Gets the current filter; see gtk_file_chooser_set_filter().
1286 * Return value: the current filter, or %NULL
1289 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1291 GtkFileFilter *filter;
1293 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1295 g_object_get (chooser, "filter", &filter, NULL);
1296 /* Horrid hack; g_object_get() refs returned objects but
1297 * that contradicts the memory management conventions
1301 g_object_unref (filter);
1307 * gtk_file_chooser_add_shortcut_folder:
1308 * @chooser: a #GtkFileChooser
1309 * @folder: filename of the folder to add
1310 * @error: location to store error, or %NULL
1312 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1313 * Note that shortcut folders do not get saved, as they are provided by the
1314 * application. For example, you can use this to add a
1315 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1317 * Return value: TRUE if the folder could be added successfully, FALSE
1318 * otherwise. In the latter case, the @error will be set as appropriate.
1321 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1328 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1329 g_return_val_if_fail (folder != NULL, FALSE);
1331 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1335 GTK_FILE_CHOOSER_ERROR,
1336 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1337 "Invalid filename: %s",
1342 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1344 gtk_file_path_free (path);
1350 * gtk_file_chooser_remove_shortcut_folder:
1351 * @chooser: a #GtkFileChooser
1352 * @folder: filename of the folder to remove
1353 * @error: location to store error, or %NULL
1355 * Removes a folder from a file chooser's list of shortcut folders.
1357 * Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter
1358 * case, the @error will be set as appropriate.
1360 * See also: gtk_file_chooser_add_shortcut_folder()
1363 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1370 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1371 g_return_val_if_fail (folder != NULL, FALSE);
1373 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1377 GTK_FILE_CHOOSER_ERROR,
1378 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1379 "Invalid filename: %s",
1384 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1386 gtk_file_path_free (path);
1392 * gtk_file_chooser_list_shortcut_folders:
1393 * @chooser: a #GtkFileChooser
1395 * Queries the list of shortcut folders in the file chooser, as set by
1396 * gtk_file_chooser_set_shortcut_folders().
1398 * Return value: A list of folder filenames, or NULL if there are no shortcut
1399 * folders. Free the returned list with g_slist_free(), and the filenames with
1403 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1408 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1410 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1412 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1414 gtk_file_system_path_to_filename);
1415 gtk_file_paths_free (folders);
1420 * gtk_file_chooser_add_shortcut_folder_uri:
1421 * @chooser: a #GtkFileChooser
1422 * @folder: URI of the folder to add
1423 * @error: location to store error, or %NULL
1425 * Adds a folder URI to be displayed with the shortcut folders in a file
1426 * chooser. Note that shortcut folders do not get saved, as they are provided
1427 * by the application. For example, you can use this to add a
1428 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1430 * Return value: TRUE if the folder could be added successfully, FALSE
1431 * otherwise. In the latter case, the @error will be set as appropriate.
1434 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1441 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1442 g_return_val_if_fail (uri != NULL, FALSE);
1444 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1448 GTK_FILE_CHOOSER_ERROR,
1449 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1450 "Invalid filename: %s",
1455 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1457 gtk_file_path_free (path);
1463 * gtk_file_chooser_remove_shortcut_folder_uri:
1464 * @chooser: a #GtkFileChooser
1465 * @uri: URI of the folder to remove
1466 * @error: location to store error, or %NULL
1468 * Removes a folder URI from a file chooser's list of shortcut folders.
1470 * Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter
1471 * case, the @error will be set as appropriate.
1473 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1476 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1483 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1484 g_return_val_if_fail (uri != NULL, FALSE);
1486 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1490 GTK_FILE_CHOOSER_ERROR,
1491 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1492 "Invalid filename: %s",
1497 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1499 gtk_file_path_free (path);
1505 * gtk_file_chooser_list_shortcut_folder_uris:
1506 * @chooser: a #GtkFileChooser
1508 * Queries the list of shortcut folders in the file chooser, as set by
1509 * gtk_file_chooser_set_shortcut_folder_uris().
1511 * Return value: A list of folder URIs, or NULL if there are no shortcut
1512 * folders. Free the returned list with g_slist_free(), and the URIs with
1516 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1521 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1523 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1525 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1527 gtk_file_system_path_to_uri);
1528 gtk_file_paths_free (folders);