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 "gtkfilesystem.h"
25 #include "gtktypebuiltins.h"
27 static void gtk_file_chooser_class_init (gpointer g_iface);
29 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
32 gtk_file_chooser_get_type (void)
34 static GType file_chooser_type = 0;
36 if (!file_chooser_type)
38 static const GTypeInfo file_chooser_info =
40 sizeof (GtkFileChooserIface), /* class_size */
42 NULL, /* base_finalize */
43 (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
46 file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
48 &file_chooser_info, 0);
50 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
53 return file_chooser_type;
57 gtk_file_chooser_class_init (gpointer g_iface)
59 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
61 g_signal_new ("current-folder-changed",
64 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
66 g_cclosure_marshal_VOID__VOID,
68 g_signal_new ("selection-changed",
71 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
73 g_cclosure_marshal_VOID__VOID,
75 g_signal_new ("update-preview",
78 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
80 g_cclosure_marshal_VOID__VOID,
82 g_signal_new ("file-activated",
85 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
87 g_cclosure_marshal_VOID__VOID,
90 g_object_interface_install_property (g_iface,
91 g_param_spec_enum ("action",
93 _("The type of operation that the file selector is performing"),
94 GTK_TYPE_FILE_CHOOSER_ACTION,
95 GTK_FILE_CHOOSER_ACTION_OPEN,
97 g_object_interface_install_property (g_iface,
98 g_param_spec_object ("file-system",
100 _("File system object to use"),
101 GTK_TYPE_FILE_SYSTEM,
102 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
103 g_object_interface_install_property (g_iface,
104 g_param_spec_object ("filter",
106 _("The current filter for selecting which files are displayed"),
107 GTK_TYPE_FILE_FILTER,
109 g_object_interface_install_property (g_iface,
110 g_param_spec_boolean ("folder-mode",
112 _("Whether to select folders rather than files"),
115 g_object_interface_install_property (g_iface,
116 g_param_spec_boolean ("local-only",
118 _("Whether the selected file(s) should be limited to local file: URLs"),
121 g_object_interface_install_property (g_iface,
122 g_param_spec_object ("preview-widget",
124 _("Application supplied widget for custom previews."),
127 g_object_interface_install_property (g_iface,
128 g_param_spec_boolean ("preview-widget-active",
129 _("Preview Widget Active"),
130 _("Whether the application supplied widget for custom previews should be shown."),
133 g_object_interface_install_property (g_iface,
134 g_param_spec_object ("extra-widget",
136 _("Application supplied widget for extra options."),
139 g_object_interface_install_property (g_iface,
140 g_param_spec_boolean ("select-multiple",
141 _("Select Multiple"),
142 _("Whether to allow multiple files to be selected"),
146 g_object_interface_install_property (g_iface,
147 g_param_spec_boolean ("show-hidden",
149 _("Whether the hidden files and folders should be displayed"),
155 * gtk_file_chooser_error_quark:
157 * Registers an error quark for #GtkFileChooser if necessary.
159 * Return value: The error quark used for #GtkFileChooser errors.
164 gtk_file_chooser_error_quark (void)
166 static GQuark quark = 0;
168 quark = g_quark_from_static_string ("gtk-file-chooser-error-quark");
173 * gtk_file_chooser_set_action:
174 * @chooser: a #GtkFileChooser
175 * @action: the action that the file selector is performing
177 * Sets the type of operation that that the chooser is performing; the
178 * user interface is adapted to suit the selected action. For example,
179 * an option to create a new folder might be shown if the action is
180 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
181 * %GTK_FILE_CHOOSER_ACTION_OPEN.
186 gtk_file_chooser_set_action (GtkFileChooser *chooser,
187 GtkFileChooserAction action)
189 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
191 g_object_set (chooser, "action", action, NULL);
195 * gtk_file_chooser_get_action:
196 * @chooser: a #GtkFileChooser
198 * Gets the type of operation that the file chooser is performing; see
199 * gtk_file_chooser_set_action().
201 * Return value: the action that the file selector is performing
206 gtk_file_chooser_get_action (GtkFileChooser *chooser)
208 GtkFileChooserAction action;
210 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
212 g_object_get (chooser, "action", &action, NULL);
218 * gtk_file_chooser_set_folder_mode:
219 * @chooser: a #GtkFileChooser
220 * @folder_mode: %TRUE if the file chooser is used to select folders
223 * Sets whether the file chooser is used to select folders
224 * rather than files. If in folder mode, only folders are displayed
225 * to the use, and not the individual files inside the folders
226 * and the user selects a single folder rather than one or
232 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
233 gboolean folder_mode)
235 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
237 g_object_set (chooser, "folder-mode", folder_mode, NULL);
241 * gtk_file_chooser_get_folder_mode:
242 * @chooser: a #GtkFileChooser
244 * Gets whether the file chooser is used to select folders
245 * rather than files. See gtk_file_chooser_set_folder_mode()
247 * Return value: %TRUE if the file chooser is used to select
248 * folders rather than files.
253 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
255 gboolean folder_mode;
257 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
259 g_object_get (chooser, "folder-mode", &folder_mode, NULL);
265 * gtk_file_chooser_set_local_only:
266 * @chooser: a #GtkFileChooser
267 * @local_only: %TRUE if only local files can be selected
269 * Sets whether only local files can be selected in the
270 * file selector. If @local_only is %TRUE (the default),
271 * then the selected file are files are guaranteed to be
272 * accessible through the operating systems native file
273 * file system and therefore the application only
274 * needs to worry about the filename functions in
275 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
276 * rather than the URI functions like
277 * gtk_file_chooser_get_uri(),
282 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
285 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
287 g_object_set (chooser, "local-only", local_only, NULL);
291 * gtk_file_chooser_get_local_only:
292 * @chooser: a #GtkFileChoosre
294 * Gets whether only local files can be selected in the
295 * file selector. See gtk_file_chooser_set_local_only()
297 * Return value: %TRUE if only local files can be selected.
302 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
306 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
308 g_object_get (chooser, "local-only", &local_only, NULL);
314 * gtk_file_chooser_set_select_multiple:
315 * @chooser: a #GtkFileChooser
316 * @select_multiple: %TRUE if multiple files can be selected.
318 * Sets whether multiple files can be selected in the file
319 * selector. If the file selector if in folder mode (see
320 * gtk_file_selector_set_folder_mode()) then only one folder
321 * can be selected, without regard to this setting.
326 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
327 gboolean select_multiple)
329 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
331 g_object_set (chooser, "select-multiple", select_multiple, NULL);
335 * gtk_file_chooser_get_select_multiple:
336 * @chooser: a #GtkFileChooser
338 * Gets whether multiple files can be selected in the file
339 * selector. See gtk_file_chooser_set_select_multiple().
341 * Return value: %TRUE if multiple files can be selected.
346 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
348 gboolean select_multiple;
350 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
352 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
354 return select_multiple;
358 * gtk_file_chooser_get_filename:
359 * @chooser: a #GtkFileChooser
361 * Gets the filename for the currently selected file in
362 * the file selector. If multiple files are selected,
363 * one of the filenames will be returned at random.
365 * Return value: The currently selected filename, or %NULL
366 * if no file is selected, or the selected file can't
367 * be represented with a local filename. Free with g_free().
372 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
374 GtkFileSystem *file_system;
376 gchar *result = NULL;
378 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
380 file_system = _gtk_file_chooser_get_file_system (chooser);
381 path = gtk_file_chooser_get_path (chooser);
384 result = gtk_file_system_path_to_filename (file_system, path);
385 gtk_file_path_free (path);
392 * gtk_file_chooser_set_filename:
393 * @chooser: a #GtkFileChooser
394 * @filename: the filename to set as current
396 * Sets @filename as the current filename for the the file chooser;
397 * If the file name isn't in the current folder of @chooser, then the
398 * current folder of @chooser will be changed to the folder containing
399 * @filename. This is equivalent to a sequence of
400 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
402 * Note that the file must exist, or nothing will be done except
403 * for the directory change. To pre-enter a filename for the user, as in
404 * a save-as dialog, use gtk_file_chooser_set_current_name()
409 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
410 const gchar *filename)
412 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
414 gtk_file_chooser_unselect_all (chooser);
415 gtk_file_chooser_select_filename (chooser, filename);
419 * gtk_file_chooser_select_filename:
420 * @chooser: a #GtkFileChooser
421 * @filename: the filename to select
423 * Selects a filename. If the file name isn't in the current
424 * folder of @chooser, then the current folder of @chooser will
425 * be changed to the folder containing @filename.
430 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
431 const gchar *filename)
433 GtkFileSystem *file_system;
436 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
437 g_return_if_fail (filename != NULL);
439 file_system = _gtk_file_chooser_get_file_system (chooser);
441 path = gtk_file_system_filename_to_path (file_system, filename);
444 _gtk_file_chooser_select_path (chooser, path);
445 gtk_file_path_free (path);
450 * gtk_file_chooser_unselect_filename:
451 * @chooser: a #GtkFileChooser
452 * @filename: the filename to unselect
454 * Unselects a currently selected filename. If the filename
455 * is not in the current directory, does not exist, or
456 * is otherwise not currently selected, does nothing.
461 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
462 const char *filename)
464 GtkFileSystem *file_system;
467 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
468 g_return_if_fail (filename != NULL);
470 file_system = _gtk_file_chooser_get_file_system (chooser);
472 path = gtk_file_system_filename_to_path (file_system, filename);
475 _gtk_file_chooser_unselect_path (chooser, path);
476 gtk_file_path_free (path);
480 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
482 file_paths_to_strings (GtkFileSystem *fs,
484 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
490 for (; paths; paths = paths->next)
496 string = (* convert_func) (fs, path);
499 strings = g_slist_prepend (strings, string);
502 return g_slist_reverse (strings);
506 * gtk_file_chooser_get_filenames:
507 * @chooser: a #GtkFileChooser
509 * Lists all the selected files and subfolders in the current folder of
510 * @chooser. The returned names are full absolute paths. If files in the current
511 * folder cannot be represented as local filenames they will be ignored. (See
512 * gtk_file_chooser_get_uris())
514 * Return value: a #GSList containing the filenames of all selected
515 * files and subfolders in the current folder. Free the returned list
516 * with g_slist_free(), and the filenames with g_free().
521 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
523 GtkFileSystem *file_system;
527 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
529 file_system = _gtk_file_chooser_get_file_system (chooser);
530 paths = _gtk_file_chooser_get_paths (chooser);
532 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
533 gtk_file_paths_free (paths);
538 * gtk_file_chooser_set_current_folder:
539 * @chooser: a #GtkFileChooser
540 * @filename: the full path of the new current folder
542 * Sets the current folder for @chooser from a local filename.
543 * The user will be shown the full contents of the current folder,
544 * plus user interface elements for navigating to other folders.
549 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
550 const gchar *filename)
552 GtkFileSystem *file_system;
555 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
556 g_return_if_fail (filename != NULL);
558 file_system = _gtk_file_chooser_get_file_system (chooser);
560 path = gtk_file_system_filename_to_path (file_system, filename);
563 _gtk_file_chooser_set_current_folder_path (chooser, path);
564 gtk_file_path_free (path);
569 * gtk_file_chooser_get_current_folder:
570 * @chooser: a #GtkFileChooser
572 * Gets the current folder of @chooser as a local filename.
573 * See gtk_file_chooser_set_current_folder().
575 * Return value: the full path of the current folder, or %NULL
576 * if the current path cannot be represented as a local filename.
577 * Free with g_free().
582 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
584 GtkFileSystem *file_system;
588 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
590 file_system = _gtk_file_chooser_get_file_system (chooser);
592 path = _gtk_file_chooser_get_current_folder_path (chooser);
593 filename = gtk_file_system_path_to_filename (file_system, path);
594 gtk_file_path_free (path);
600 * gtk_file_chooser_set_current_name:
601 * @chooser: a #GtkFileChooser
602 * @name: the filename to use, as a UTF-8 string
604 * Sets the current name in the file selector, as if entered
605 * by the user. Note that the name passed in here is a UTF-8
606 * string rather than a filename. This function is meant for
607 * such uses as a suggested name in a "Save As..." dialog.
609 * If you want to preselect a particular existing file, you
610 * should use gtk_file_chooser_set_filename() instead.
615 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
618 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
619 g_return_if_fail (name != NULL);
621 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
625 * gtk_file_chooser_get_uri:
626 * @chooser: a #GtkFileChooser
628 * Gets the URI for the currently selected file in
629 * the file selector. If multiple files are selected,
630 * one of the filenames will be returned at random.
632 * Return value: The currently selected URI, or %NULL
633 * if no file is selected. Free with g_free()
638 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
640 GtkFileSystem *file_system;
642 gchar *result = NULL;
644 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
646 file_system = _gtk_file_chooser_get_file_system (chooser);
647 path = gtk_file_chooser_get_path (chooser);
650 result = gtk_file_system_path_to_uri (file_system, path);
651 gtk_file_path_free (path);
658 * gtk_file_chooser_set_uri:
659 * @chooser: a #GtkFileChooser
660 * @uri: the URI to set as current
662 * Sets the file referred to by @uri as the current file for the the
663 * file chooser; If the file name isn't in the current folder of @chooser,
664 * then the current folder of @chooser will be changed to the folder containing
665 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
666 * followed by gtk_file_chooser_select_uri().
668 * Note that the file must exist, or nothing will be done except
669 * for the directory change. To pre-enter a filename for the user, as in
670 * a save-as dialog, use gtk_file_chooser_set_current_name()
675 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
678 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
680 gtk_file_chooser_unselect_all (chooser);
681 gtk_file_chooser_select_uri (chooser, uri);
685 * gtk_file_chooser_select_uri:
686 * @chooser: a #GtkFileChooser
687 * @uri: the URI to select
689 * Selects the file to by @uri. If the URI doesn't refer to a
690 * file in the current folder of @chooser, then the current folder of
691 * @chooser will be changed to the folder containing @filename.
696 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
699 GtkFileSystem *file_system;
702 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
703 g_return_if_fail (uri != NULL);
705 file_system = _gtk_file_chooser_get_file_system (chooser);
707 path = gtk_file_system_uri_to_path (file_system, uri);
710 _gtk_file_chooser_select_path (chooser, path);
711 gtk_file_path_free (path);
716 * gtk_file_chooser_unselect_uri:
717 * @chooser: a #GtkFileChooser
718 * @uri: the URI to unselect
720 * Unselects the file referred to by @uri. If the file
721 * is not in the current directory, does not exist, or
722 * is otherwise not currently selected, does nothing.
727 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
730 GtkFileSystem *file_system;
733 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
734 g_return_if_fail (uri != NULL);
736 file_system = _gtk_file_chooser_get_file_system (chooser);
738 path = gtk_file_system_uri_to_path (file_system, uri);
741 _gtk_file_chooser_unselect_path (chooser, path);
742 gtk_file_path_free (path);
747 * gtk_file_chooser_select_all:
748 * @chooser: a #GtkFileChooser
750 * Selects all the files in the current folder of a file chooser.
753 gtk_file_chooser_select_all (GtkFileChooser *chooser)
755 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
757 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
761 * gtk_file_chooser_unselect_all:
762 * @chooser: a #GtkFileChooser
764 * Unselects all the files in the current folder of a file chooser.
767 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
770 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
772 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
776 * gtk_file_chooser_get_uris:
777 * @chooser: a #GtkFileChooser
779 * Lists all the selected files and subfolders in the current folder of
780 * @chooser. The returned names are full absolute URIs.
782 * Return value: a #GSList containing the URIs of all selected
783 * files and subfolders in the current folder. Free the returned list
784 * with g_slist_free(), and the filenames with g_free().
789 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
791 GtkFileSystem *file_system;
795 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
797 file_system = _gtk_file_chooser_get_file_system (chooser);
798 paths = _gtk_file_chooser_get_paths (chooser);
800 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
801 gtk_file_paths_free (paths);
806 * gtk_file_chooser_set_current_folder_uri:
807 * @chooser: a #GtkFileChooser
808 * @uri: the URI for the new current folder
810 * Sets the current folder for @chooser from an URI.
811 * The user will be shown the full contents of the current folder,
812 * plus user interface elements for navigating to other folders.
817 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
820 GtkFileSystem *file_system;
823 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
824 g_return_if_fail (uri != NULL);
826 file_system = _gtk_file_chooser_get_file_system (chooser);
828 path = gtk_file_system_uri_to_path (file_system, uri);
831 _gtk_file_chooser_set_current_folder_path (chooser, path);
832 gtk_file_path_free (path);
837 * gtk_file_chooser_get_current_folder_uri:
838 * @chooser: a #GtkFileChooser
840 * Gets the current folder of @chooser as an URI.
841 * See gtk_file_chooser_set_current_folder_uri().
843 * Return value: the URI for the current folder.
844 * Free with g_free().
849 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
851 GtkFileSystem *file_system;
855 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
857 file_system = _gtk_file_chooser_get_file_system (chooser);
859 path = _gtk_file_chooser_get_current_folder_path (chooser);
860 uri = gtk_file_system_path_to_uri (file_system, path);
861 gtk_file_path_free (path);
867 * _gtk_file_chooser_set_current_folder_path:
868 * @chooser: a #GtkFileChooser
869 * @path: the #GtkFilePath for the new folder
871 * Sets the current folder for @chooser from a #GtkFilePath.
872 * Internal function, see gtk_file_chooser_set_current_folder_uri().
877 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
878 const GtkFilePath *path)
880 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
881 g_return_if_fail (path != NULL);
883 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
887 * _gtk_file_chooser_get_current_folder_path:
888 * @chooser: a #GtkFileChooser
890 * Gets the current folder of @chooser as #GtkFilePath.
891 * See gtk_file_chooser_get_current_folder_uri().
893 * Return value: the #GtkFilePath for the current folder.
894 * Free with gtk_file_path_free().
899 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
901 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
903 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
907 * _gtk_file_chooser_select_path:
908 * @chooser: a #GtkFileChooser
909 * @path: the path to select
911 * Selects the file referred to by @path. An internal function. See
912 * _gtk_file_chooser_select_uri().
917 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
918 const GtkFilePath *path)
920 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
922 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
926 * _gtk_file_chooser_unselect_path:
927 * @chooser: a #GtkFileChooser
928 * @path: the filename to path
930 * Unselects the file referred to by @path. An internal
931 * function. See _gtk_file_chooser_unselect_uri().
936 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
937 const GtkFilePath *path)
939 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
941 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
945 * _gtk_file_chooser_get_paths:
946 * @chooser: a #GtkFileChooser
948 * Lists all the selected files and subfolders in the current folder of @chooser
949 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
951 * Return value: a #GSList containing a #GtkFilePath for each selected
952 * file and subfolder in the current folder. Free the returned list
953 * with g_slist_free(), and the paths with gtk_file_path_free().
958 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
960 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
962 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
966 gtk_file_chooser_get_path (GtkFileChooser *chooser)
969 GtkFilePath *result = NULL;
971 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
973 list = _gtk_file_chooser_get_paths (chooser);
977 list = g_slist_delete_link (list, list);
978 gtk_file_paths_free (list);
985 * _gtk_file_chooser_get_file_system:
986 * @chooser: a #GtkFileChooser
988 * Gets the #GtkFileSystem of @chooser; this is an internal
989 * implementation detail, used for conversion between paths
990 * and filenames and URIs.
992 * Return value: the file system for @chooser.
997 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
999 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1001 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1007 * gtk_file_chooser_set_preview_widget:
1008 * @chooser: a #GtkFileChooser
1009 * @preview_widget: widget for displaying preview.
1011 * Sets an application-supplied widget to use to display a custom preview
1012 * of the currently selected file. To implement a preview, after setting the
1013 * preview widget, you connect to the ::selection-changed
1014 * signal, and call gtk_file_chooser_get_preview_filename() or
1015 * gtk_file_chooser_get_preview_uri() on each change. If you can
1016 * display a preview of the new file, update your widget and
1017 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1018 * Otherwise, set the preview inactive.
1020 * When there is no application-supplied preview widget, or the
1021 * application-supplied preview widget is not active, the file chooser
1022 * may display an internally generated preview of the current file or
1023 * it may display no preview at all.
1028 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1029 GtkWidget *preview_widget)
1031 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1033 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1037 * gtk_file_chooser_get_preview_widget:
1038 * @chooser: a #GtkFileChooser
1040 * Gets the current preview widget; see
1041 * gtk_file_chooser_set_preview_widget().
1043 * Return value: the current preview widget, or %NULL
1048 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1050 GtkWidget *preview_widget;
1052 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1054 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1056 /* Horrid hack; g_object_get() refs returned objects but
1057 * that contradicts the memory management conventions
1061 g_object_unref (preview_widget);
1063 return preview_widget;
1067 * gtk_file_chooser_set_preview_widget_active:
1068 * @chooser: a #GtkFileChooser
1069 * @active: whether to display the user-specified preview widget
1071 * Sets whether the preview widget set by
1072 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1073 * current filename. When @active is set to false, the file chooser
1074 * may display an internally generated preview of the current file
1075 * or it may display no preview at all. See
1076 * gtk_file_chooser_set_preview_widget() for more details.
1081 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1084 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1086 g_object_set (chooser, "preview-widget-active", active, NULL);
1090 * gtk_file_chooser_get_preview_widget_active:
1091 * @chooser: a #GtkFileChooser
1093 * Gets whether the preview widget set by
1094 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1095 * current filename. See gtk_file_chooser_set_preview_widget_active().
1097 * Return value: %TRUE if the preview widget is active for the
1103 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1107 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1109 g_object_get (chooser, "preview-widget-active", &active, NULL);
1115 * gtk_file_chooser_get_preview_filename:
1116 * @chooser: a #GtkFileChooser
1118 * Gets the filename that should be previewed in a custom preview
1119 * Internal function, see gtk_file_chooser_get_preview_uri().
1121 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1122 * is selected. Free with gtk_file_path_free().
1127 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1129 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1131 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1135 * _gtk_file_chooser_add_shortcut_folder:
1136 * @chooser: a #GtkFileChooser
1137 * @path: path of the folder to add
1138 * @error: location to store error, or %NULL
1140 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1141 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1143 * Return value: %TRUE if the folder could be added successfully, %FALSE
1149 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1150 const GtkFilePath *path,
1153 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1154 g_return_val_if_fail (path != NULL, FALSE);
1156 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1160 * _gtk_file_chooser_remove_shortcut_folder:
1161 * @chooser: a #GtkFileChooser
1162 * @path: path of the folder to remove
1163 * @error: location to store error, or %NULL
1165 * Removes a folder from the shortcut folders in a file chooser. Internal
1166 * function, see gtk_file_chooser_remove_shortcut_folder().
1168 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1174 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1175 const GtkFilePath *path,
1178 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1179 g_return_val_if_fail (path != NULL, FALSE);
1181 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1185 * gtk_file_chooser_get_preview_filename:
1186 * @chooser: a #GtkFileChooser
1188 * Gets the filename that should be previewed in a custom preview
1189 * widget. See gtk_file_chooser_set_preview_widget().
1191 * Return value: the filename to preview, or %NULL if no file
1192 * is selected, or if the selected file cannot be represented
1193 * as a local filename. Free with g_free()
1198 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1200 GtkFileSystem *file_system;
1202 gchar *result = NULL;
1204 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1206 file_system = _gtk_file_chooser_get_file_system (chooser);
1207 path = _gtk_file_chooser_get_preview_path (chooser);
1210 result = gtk_file_system_path_to_filename (file_system, path);
1211 gtk_file_path_free (path);
1218 * gtk_file_chooser_get_preview_uri:
1219 * @chooser: a #GtkFileChooser
1221 * Gets the URI that should be previewed in a custom preview
1222 * widget. See gtk_file_chooser_set_preview_widget().
1224 * Return value: the URI for the file to preview, or %NULL if no file is
1225 * selected. Free with g_free().
1230 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1232 GtkFileSystem *file_system;
1234 gchar *result = NULL;
1236 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1238 file_system = _gtk_file_chooser_get_file_system (chooser);
1239 path = _gtk_file_chooser_get_preview_path (chooser);
1242 result = gtk_file_system_path_to_uri (file_system, path);
1243 gtk_file_path_free (path);
1250 * gtk_file_chooser_set_extra_widget:
1251 * @chooser: a #GtkFileChooser
1252 * @extra_widget: widget for extra options
1254 * Sets an application-supplied widget to provide extra options to the user.
1259 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1260 GtkWidget *extra_widget)
1262 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1264 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1268 * gtk_file_chooser_get_extra_widget:
1269 * @chooser: a #GtkFileChooser
1271 * Gets the current preview widget; see
1272 * gtk_file_chooser_set_extra_widget().
1274 * Return value: the current extra widget, or %NULL
1279 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1281 GtkWidget *extra_widget;
1283 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1285 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1287 /* Horrid hack; g_object_get() refs returned objects but
1288 * that contradicts the memory management conventions
1292 g_object_unref (extra_widget);
1294 return extra_widget;
1298 * gtk_file_chooser_add_filter:
1299 * @chooser: a #GtkFileChooser
1300 * @filter: a #GtkFileFilter
1302 * Adds @filter to the list of filters that the user can select between.
1303 * When a filter is selected, only files that are passed by that
1304 * filter are displayed.
1309 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1310 GtkFileFilter *filter)
1312 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1314 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1318 * gtk_file_chooser_remove_filter:
1319 * @chooser: a #GtkFileChooser
1320 * @filter: a #GtkFileFilter
1322 * Removes @filter from the list of filters that the user can select between.
1327 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1328 GtkFileFilter *filter)
1330 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1332 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1336 * gtk_file_chooser_list_filters:
1337 * @choooser: a #GtkFileChooser
1339 * Lists the current set of user-selectable filters; see
1340 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1342 * Return value: a #GSList containing the current set of
1343 * user selectable filters. The contents of the list are
1344 * owned by GTK+, but you must free the list itself with
1345 * g_slist_free() when you are done with it.
1350 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1352 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1354 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1358 * gtk_file_chooser_set_filter:
1359 * @chooser: a #GtkFileChooser
1360 * @filter: a #GtkFileFilter
1362 * Sets the current filter; only the files that pass the
1363 * filter will be displayed. If the user-selectable list of filters
1364 * is non-empty, then the filter should be one of the filters
1365 * in that list. Setting the current filter when the list of
1366 * filters is empty is useful if you want to restrict the displayed
1367 * set of files without letting the user change it.
1372 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1373 GtkFileFilter *filter)
1375 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1376 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1378 g_object_set (chooser, "filter", filter, NULL);
1382 * gtk_file_chooser_get_filter:
1383 * @chooser: a #GtkFileChooser
1385 * Gets the current filter; see gtk_file_chooser_set_filter().
1387 * Return value: the current filter, or %NULL
1392 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1394 GtkFileFilter *filter;
1396 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1398 g_object_get (chooser, "filter", &filter, NULL);
1399 /* Horrid hack; g_object_get() refs returned objects but
1400 * that contradicts the memory management conventions
1404 g_object_unref (filter);
1410 * gtk_file_chooser_add_shortcut_folder:
1411 * @chooser: a #GtkFileChooser
1412 * @folder: filename of the folder to add
1413 * @error: location to store error, or %NULL
1415 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1416 * Note that shortcut folders do not get saved, as they are provided by the
1417 * application. For example, you can use this to add a
1418 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1420 * Return value: %TRUE if the folder could be added successfully, %FALSE
1421 * otherwise. In the latter case, the @error will be set as appropriate.
1426 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1433 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1434 g_return_val_if_fail (folder != NULL, FALSE);
1436 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1440 GTK_FILE_CHOOSER_ERROR,
1441 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1442 _("Invalid filename: %s"),
1447 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1449 gtk_file_path_free (path);
1455 * gtk_file_chooser_remove_shortcut_folder:
1456 * @chooser: a #GtkFileChooser
1457 * @folder: filename of the folder to remove
1458 * @error: location to store error, or %NULL
1460 * Removes a folder from a file chooser's list of shortcut folders.
1462 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1463 * In the latter case, the @error will be set as appropriate.
1465 * See also: gtk_file_chooser_add_shortcut_folder()
1470 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1477 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1478 g_return_val_if_fail (folder != NULL, FALSE);
1480 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1484 GTK_FILE_CHOOSER_ERROR,
1485 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1486 _("Invalid filename: %s"),
1491 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1493 gtk_file_path_free (path);
1499 * gtk_file_chooser_list_shortcut_folders:
1500 * @chooser: a #GtkFileChooser
1502 * Queries the list of shortcut folders in the file chooser, as set by
1503 * gtk_file_chooser_set_shortcut_folders().
1505 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1506 * folders. Free the returned list with g_slist_free(), and the filenames with
1512 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1517 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1519 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1521 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1523 gtk_file_system_path_to_filename);
1524 gtk_file_paths_free (folders);
1529 * gtk_file_chooser_add_shortcut_folder_uri:
1530 * @chooser: a #GtkFileChooser
1531 * @folder: URI of the folder to add
1532 * @error: location to store error, or %NULL
1534 * Adds a folder URI to be displayed with the shortcut folders in a file
1535 * chooser. Note that shortcut folders do not get saved, as they are provided
1536 * by the application. For example, you can use this to add a
1537 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1539 * Return value: %TRUE if the folder could be added successfully, %FALSE
1540 * otherwise. In the latter case, the @error will be set as appropriate.
1545 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1552 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1553 g_return_val_if_fail (uri != NULL, FALSE);
1555 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1559 GTK_FILE_CHOOSER_ERROR,
1560 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1561 _("Invalid filename: %s"),
1566 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1568 gtk_file_path_free (path);
1574 * gtk_file_chooser_remove_shortcut_folder_uri:
1575 * @chooser: a #GtkFileChooser
1576 * @uri: URI of the folder to remove
1577 * @error: location to store error, or %NULL
1579 * Removes a folder URI from a file chooser's list of shortcut folders.
1581 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1582 * In the latter case, the @error will be set as appropriate.
1584 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1589 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1596 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1597 g_return_val_if_fail (uri != NULL, FALSE);
1599 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1603 GTK_FILE_CHOOSER_ERROR,
1604 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1605 _("Invalid filename: %s"),
1610 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1612 gtk_file_path_free (path);
1618 * gtk_file_chooser_list_shortcut_folder_uris:
1619 * @chooser: a #GtkFileChooser
1621 * Queries the list of shortcut folders in the file chooser, as set by
1622 * gtk_file_chooser_set_shortcut_folder_uris().
1624 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1625 * folders. Free the returned list with g_slist_free(), and the URIs with
1631 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1636 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1638 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1640 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1642 gtk_file_system_path_to_uri);
1643 gtk_file_paths_free (folders);