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 P_("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_string ("file-system-backend",
99 P_("File System Backend"),
100 P_("Name of file system backend to use"),
102 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
103 g_object_interface_install_property (g_iface,
104 g_param_spec_object ("filter",
106 P_("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 P_("Whether to select folders rather than files"),
115 g_object_interface_install_property (g_iface,
116 g_param_spec_boolean ("local-only",
118 P_("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",
123 P_("Preview widget"),
124 P_("Application supplied widget for custom previews."),
127 g_object_interface_install_property (g_iface,
128 g_param_spec_boolean ("preview-widget-active",
129 P_("Preview Widget Active"),
130 P_("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 P_("Application supplied widget for extra options."),
139 g_object_interface_install_property (g_iface,
140 g_param_spec_boolean ("select-multiple",
141 P_("Select Multiple"),
142 P_("Whether to allow multiple files to be selected"),
146 g_object_interface_install_property (g_iface,
147 g_param_spec_boolean ("show-hidden",
149 P_("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_local_only:
219 * @chooser: a #GtkFileChooser
220 * @local_only: %TRUE if only local files can be selected
222 * Sets whether only local files can be selected in the
223 * file selector. If @local_only is %TRUE (the default),
224 * then the selected file are files are guaranteed to be
225 * accessible through the operating systems native file
226 * file system and therefore the application only
227 * needs to worry about the filename functions in
228 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
229 * rather than the URI functions like
230 * gtk_file_chooser_get_uri(),
235 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
238 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
240 g_object_set (chooser, "local-only", local_only, NULL);
244 * gtk_file_chooser_get_local_only:
245 * @chooser: a #GtkFileChoosre
247 * Gets whether only local files can be selected in the
248 * file selector. See gtk_file_chooser_set_local_only()
250 * Return value: %TRUE if only local files can be selected.
255 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
259 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
261 g_object_get (chooser, "local-only", &local_only, NULL);
267 * gtk_file_chooser_set_select_multiple:
268 * @chooser: a #GtkFileChooser
269 * @select_multiple: %TRUE if multiple files can be selected.
271 * Sets whether multiple files can be selected in the file selector. This is
272 * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
273 * GTK_FILE_CHOOSER_ACTION_SAVE. It cannot be set with either of the folder
279 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
280 gboolean select_multiple)
282 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
284 g_object_set (chooser, "select-multiple", select_multiple, NULL);
288 * gtk_file_chooser_get_select_multiple:
289 * @chooser: a #GtkFileChooser
291 * Gets whether multiple files can be selected in the file
292 * selector. See gtk_file_chooser_set_select_multiple().
294 * Return value: %TRUE if multiple files can be selected.
299 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
301 gboolean select_multiple;
303 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
305 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
307 return select_multiple;
311 * gtk_file_chooser_get_filename:
312 * @chooser: a #GtkFileChooser
314 * Gets the filename for the currently selected file in
315 * the file selector. If multiple files are selected,
316 * one of the filenames will be returned at random.
318 * If the file chooser is in folder mode, this function returns the selected
321 * Return value: The currently selected filename, or %NULL
322 * if no file is selected, or the selected file can't
323 * be represented with a local filename. Free with g_free().
328 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
330 GtkFileSystem *file_system;
332 gchar *result = NULL;
334 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
336 file_system = _gtk_file_chooser_get_file_system (chooser);
337 path = gtk_file_chooser_get_path (chooser);
340 result = gtk_file_system_path_to_filename (file_system, path);
341 gtk_file_path_free (path);
348 * gtk_file_chooser_set_filename:
349 * @chooser: a #GtkFileChooser
350 * @filename: the filename to set as current
352 * Sets @filename as the current filename for the the file chooser;
353 * If the file name isn't in the current folder of @chooser, then the
354 * current folder of @chooser will be changed to the folder containing
355 * @filename. This is equivalent to a sequence of
356 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
358 * Note that the file must exist, or nothing will be done except
359 * for the directory change. To pre-enter a filename for the user, as in
360 * a save-as dialog, use gtk_file_chooser_set_current_name()
365 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
366 const gchar *filename)
368 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
370 gtk_file_chooser_unselect_all (chooser);
371 gtk_file_chooser_select_filename (chooser, filename);
375 * gtk_file_chooser_select_filename:
376 * @chooser: a #GtkFileChooser
377 * @filename: the filename to select
379 * Selects a filename. If the file name isn't in the current
380 * folder of @chooser, then the current folder of @chooser will
381 * be changed to the folder containing @filename.
386 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
387 const gchar *filename)
389 GtkFileSystem *file_system;
392 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
393 g_return_if_fail (filename != NULL);
395 file_system = _gtk_file_chooser_get_file_system (chooser);
397 path = gtk_file_system_filename_to_path (file_system, filename);
400 _gtk_file_chooser_select_path (chooser, path);
401 gtk_file_path_free (path);
406 * gtk_file_chooser_unselect_filename:
407 * @chooser: a #GtkFileChooser
408 * @filename: the filename to unselect
410 * Unselects a currently selected filename. If the filename
411 * is not in the current directory, does not exist, or
412 * is otherwise not currently selected, does nothing.
417 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
418 const char *filename)
420 GtkFileSystem *file_system;
423 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
424 g_return_if_fail (filename != NULL);
426 file_system = _gtk_file_chooser_get_file_system (chooser);
428 path = gtk_file_system_filename_to_path (file_system, filename);
431 _gtk_file_chooser_unselect_path (chooser, path);
432 gtk_file_path_free (path);
436 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
438 file_paths_to_strings (GtkFileSystem *fs,
440 gchar * (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
446 for (; paths; paths = paths->next)
452 string = (* convert_func) (fs, path);
455 strings = g_slist_prepend (strings, string);
458 return g_slist_reverse (strings);
462 * gtk_file_chooser_get_filenames:
463 * @chooser: a #GtkFileChooser
465 * Lists all the selected files and subfolders in the current folder of
466 * @chooser. The returned names are full absolute paths. If files in the current
467 * folder cannot be represented as local filenames they will be ignored. (See
468 * gtk_file_chooser_get_uris())
470 * Return value: a #GSList containing the filenames of all selected
471 * files and subfolders in the current folder. Free the returned list
472 * with g_slist_free(), and the filenames with g_free().
477 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
479 GtkFileSystem *file_system;
483 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
485 file_system = _gtk_file_chooser_get_file_system (chooser);
486 paths = _gtk_file_chooser_get_paths (chooser);
488 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
489 gtk_file_paths_free (paths);
494 * gtk_file_chooser_set_current_folder:
495 * @chooser: a #GtkFileChooser
496 * @filename: the full path of the new current folder
498 * Sets the current folder for @chooser from a local filename.
499 * The user will be shown the full contents of the current folder,
500 * plus user interface elements for navigating to other folders.
505 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
506 const gchar *filename)
508 GtkFileSystem *file_system;
511 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
512 g_return_if_fail (filename != NULL);
514 file_system = _gtk_file_chooser_get_file_system (chooser);
516 path = gtk_file_system_filename_to_path (file_system, filename);
519 _gtk_file_chooser_set_current_folder_path (chooser, path);
520 gtk_file_path_free (path);
525 * gtk_file_chooser_get_current_folder:
526 * @chooser: a #GtkFileChooser
528 * Gets the current folder of @chooser as a local filename.
529 * See gtk_file_chooser_set_current_folder().
531 * Return value: the full path of the current folder, or %NULL
532 * if the current path cannot be represented as a local filename.
533 * Free with g_free().
538 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
540 GtkFileSystem *file_system;
544 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
546 file_system = _gtk_file_chooser_get_file_system (chooser);
548 path = _gtk_file_chooser_get_current_folder_path (chooser);
549 filename = gtk_file_system_path_to_filename (file_system, path);
550 gtk_file_path_free (path);
556 * gtk_file_chooser_set_current_name:
557 * @chooser: a #GtkFileChooser
558 * @name: the filename to use, as a UTF-8 string
560 * Sets the current name in the file selector, as if entered
561 * by the user. Note that the name passed in here is a UTF-8
562 * string rather than a filename. This function is meant for
563 * such uses as a suggested name in a "Save As..." dialog.
565 * If you want to preselect a particular existing file, you
566 * should use gtk_file_chooser_set_filename() instead.
571 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
574 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
575 g_return_if_fail (name != NULL);
577 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
581 * gtk_file_chooser_get_uri:
582 * @chooser: a #GtkFileChooser
584 * Gets the URI for the currently selected file in
585 * the file selector. If multiple files are selected,
586 * one of the filenames will be returned at random.
588 * If the file chooser is in folder mode, this function returns the selected
591 * Return value: The currently selected URI, or %NULL
592 * if no file is selected. Free with g_free()
597 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
599 GtkFileSystem *file_system;
601 gchar *result = NULL;
603 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
605 file_system = _gtk_file_chooser_get_file_system (chooser);
606 path = gtk_file_chooser_get_path (chooser);
609 result = gtk_file_system_path_to_uri (file_system, path);
610 gtk_file_path_free (path);
617 * gtk_file_chooser_set_uri:
618 * @chooser: a #GtkFileChooser
619 * @uri: the URI to set as current
621 * Sets the file referred to by @uri as the current file for the the
622 * file chooser; If the file name isn't in the current folder of @chooser,
623 * then the current folder of @chooser will be changed to the folder containing
624 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
625 * followed by gtk_file_chooser_select_uri().
627 * Note that the file must exist, or nothing will be done except
628 * for the directory change. To pre-enter a filename for the user, as in
629 * a save-as dialog, use gtk_file_chooser_set_current_name()
634 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
637 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
639 gtk_file_chooser_unselect_all (chooser);
640 gtk_file_chooser_select_uri (chooser, uri);
644 * gtk_file_chooser_select_uri:
645 * @chooser: a #GtkFileChooser
646 * @uri: the URI to select
648 * Selects the file to by @uri. If the URI doesn't refer to a
649 * file in the current folder of @chooser, then the current folder of
650 * @chooser will be changed to the folder containing @filename.
655 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
658 GtkFileSystem *file_system;
661 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
662 g_return_if_fail (uri != NULL);
664 file_system = _gtk_file_chooser_get_file_system (chooser);
666 path = gtk_file_system_uri_to_path (file_system, uri);
669 _gtk_file_chooser_select_path (chooser, path);
670 gtk_file_path_free (path);
675 * gtk_file_chooser_unselect_uri:
676 * @chooser: a #GtkFileChooser
677 * @uri: the URI to unselect
679 * Unselects the file referred to by @uri. If the file
680 * is not in the current directory, does not exist, or
681 * 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:
707 * @chooser: a #GtkFileChooser
709 * Selects all the files in the current folder of a file chooser.
714 gtk_file_chooser_select_all (GtkFileChooser *chooser)
716 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
718 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
722 * gtk_file_chooser_unselect_all:
723 * @chooser: a #GtkFileChooser
725 * Unselects all the files in the current folder of a file chooser.
730 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
733 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
735 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
739 * gtk_file_chooser_get_uris:
740 * @chooser: a #GtkFileChooser
742 * Lists all the selected files and subfolders in the current folder of
743 * @chooser. The returned names are full absolute URIs.
745 * Return value: a #GSList containing the URIs of all selected
746 * files and subfolders in the current folder. Free the returned list
747 * with g_slist_free(), and the filenames with g_free().
752 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
754 GtkFileSystem *file_system;
758 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
760 file_system = _gtk_file_chooser_get_file_system (chooser);
761 paths = _gtk_file_chooser_get_paths (chooser);
763 result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
764 gtk_file_paths_free (paths);
769 * gtk_file_chooser_set_current_folder_uri:
770 * @chooser: a #GtkFileChooser
771 * @uri: the URI for the new current folder
773 * Sets the current folder for @chooser from an URI.
774 * The user will be shown the full contents of the current folder,
775 * plus user interface elements for navigating to other folders.
780 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
783 GtkFileSystem *file_system;
786 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
787 g_return_if_fail (uri != NULL);
789 file_system = _gtk_file_chooser_get_file_system (chooser);
791 path = gtk_file_system_uri_to_path (file_system, uri);
794 _gtk_file_chooser_set_current_folder_path (chooser, path);
795 gtk_file_path_free (path);
800 * gtk_file_chooser_get_current_folder_uri:
801 * @chooser: a #GtkFileChooser
803 * Gets the current folder of @chooser as an URI.
804 * See gtk_file_chooser_set_current_folder_uri().
806 * Return value: the URI for the current folder.
807 * Free with g_free().
812 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
814 GtkFileSystem *file_system;
818 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
820 file_system = _gtk_file_chooser_get_file_system (chooser);
822 path = _gtk_file_chooser_get_current_folder_path (chooser);
823 uri = gtk_file_system_path_to_uri (file_system, path);
824 gtk_file_path_free (path);
830 * _gtk_file_chooser_set_current_folder_path:
831 * @chooser: a #GtkFileChooser
832 * @path: the #GtkFilePath for the new folder
834 * Sets the current folder for @chooser from a #GtkFilePath.
835 * Internal function, see gtk_file_chooser_set_current_folder_uri().
840 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
841 const GtkFilePath *path)
843 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
844 g_return_if_fail (path != NULL);
846 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
850 * _gtk_file_chooser_get_current_folder_path:
851 * @chooser: a #GtkFileChooser
853 * Gets the current folder of @chooser as #GtkFilePath.
854 * See gtk_file_chooser_get_current_folder_uri().
856 * Return value: the #GtkFilePath for the current folder.
857 * Free with gtk_file_path_free().
862 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
864 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
866 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
870 * _gtk_file_chooser_select_path:
871 * @chooser: a #GtkFileChooser
872 * @path: the path to select
874 * Selects the file referred to by @path. An internal function. See
875 * _gtk_file_chooser_select_uri().
880 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
881 const GtkFilePath *path)
883 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
885 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
889 * _gtk_file_chooser_unselect_path:
890 * @chooser: a #GtkFileChooser
891 * @path: the filename to path
893 * Unselects the file referred to by @path. An internal
894 * function. See _gtk_file_chooser_unselect_uri().
899 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
900 const GtkFilePath *path)
902 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
904 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
908 * _gtk_file_chooser_get_paths:
909 * @chooser: a #GtkFileChooser
911 * Lists all the selected files and subfolders in the current folder of @chooser
912 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
914 * Return value: a #GSList containing a #GtkFilePath for each selected
915 * file and subfolder in the current folder. Free the returned list
916 * with g_slist_free(), and the paths with gtk_file_path_free().
921 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
923 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
925 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
929 gtk_file_chooser_get_path (GtkFileChooser *chooser)
932 GtkFilePath *result = NULL;
934 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
936 list = _gtk_file_chooser_get_paths (chooser);
940 list = g_slist_delete_link (list, list);
941 gtk_file_paths_free (list);
948 * _gtk_file_chooser_get_file_system:
949 * @chooser: a #GtkFileChooser
951 * Gets the #GtkFileSystem of @chooser; this is an internal
952 * implementation detail, used for conversion between paths
953 * and filenames and URIs.
955 * Return value: the file system for @chooser.
960 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
962 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
964 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
970 * gtk_file_chooser_set_preview_widget:
971 * @chooser: a #GtkFileChooser
972 * @preview_widget: widget for displaying preview.
974 * Sets an application-supplied widget to use to display a custom preview
975 * of the currently selected file. To implement a preview, after setting the
976 * preview widget, you connect to the ::selection-changed
977 * signal, and call gtk_file_chooser_get_preview_filename() or
978 * gtk_file_chooser_get_preview_uri() on each change. If you can
979 * display a preview of the new file, update your widget and
980 * set the preview active using gtk_file_chooser_set_preview_widget_active().
981 * Otherwise, set the preview inactive.
983 * When there is no application-supplied preview widget, or the
984 * application-supplied preview widget is not active, the file chooser
985 * may display an internally generated preview of the current file or
986 * it may display no preview at all.
991 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
992 GtkWidget *preview_widget)
994 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
996 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1000 * gtk_file_chooser_get_preview_widget:
1001 * @chooser: a #GtkFileChooser
1003 * Gets the current preview widget; see
1004 * gtk_file_chooser_set_preview_widget().
1006 * Return value: the current preview widget, or %NULL
1011 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1013 GtkWidget *preview_widget;
1015 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1017 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1019 /* Horrid hack; g_object_get() refs returned objects but
1020 * that contradicts the memory management conventions
1024 g_object_unref (preview_widget);
1026 return preview_widget;
1030 * gtk_file_chooser_set_preview_widget_active:
1031 * @chooser: a #GtkFileChooser
1032 * @active: whether to display the user-specified preview widget
1034 * Sets whether the preview widget set by
1035 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1036 * current filename. When @active is set to false, the file chooser
1037 * may display an internally generated preview of the current file
1038 * or it may display no preview at all. See
1039 * gtk_file_chooser_set_preview_widget() for more details.
1044 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1047 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1049 g_object_set (chooser, "preview-widget-active", active, NULL);
1053 * gtk_file_chooser_get_preview_widget_active:
1054 * @chooser: a #GtkFileChooser
1056 * Gets whether the preview widget set by
1057 * gtk_file_chooser_set_preview_widget_active() should be shown for the
1058 * current filename. See gtk_file_chooser_set_preview_widget_active().
1060 * Return value: %TRUE if the preview widget is active for the
1066 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1070 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1072 g_object_get (chooser, "preview-widget-active", &active, NULL);
1078 * gtk_file_chooser_get_preview_filename:
1079 * @chooser: a #GtkFileChooser
1081 * Gets the filename that should be previewed in a custom preview
1082 * Internal function, see gtk_file_chooser_get_preview_uri().
1084 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1085 * is selected. Free with gtk_file_path_free().
1090 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1092 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1094 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1098 * _gtk_file_chooser_add_shortcut_folder:
1099 * @chooser: a #GtkFileChooser
1100 * @path: path of the folder to add
1101 * @error: location to store error, or %NULL
1103 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1104 * Internal function, see gtk_file_chooser_add_shortcut_folder().
1106 * Return value: %TRUE if the folder could be added successfully, %FALSE
1112 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1113 const GtkFilePath *path,
1116 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1117 g_return_val_if_fail (path != NULL, FALSE);
1119 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1123 * _gtk_file_chooser_remove_shortcut_folder:
1124 * @chooser: a #GtkFileChooser
1125 * @path: path of the folder to remove
1126 * @error: location to store error, or %NULL
1128 * Removes a folder from the shortcut folders in a file chooser. Internal
1129 * function, see gtk_file_chooser_remove_shortcut_folder().
1131 * Return value: %TRUE if the folder could be removed successfully, %FALSE
1137 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1138 const GtkFilePath *path,
1141 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1142 g_return_val_if_fail (path != NULL, FALSE);
1144 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1148 * gtk_file_chooser_get_preview_filename:
1149 * @chooser: a #GtkFileChooser
1151 * Gets the filename that should be previewed in a custom preview
1152 * widget. See gtk_file_chooser_set_preview_widget().
1154 * Return value: the filename to preview, or %NULL if no file
1155 * is selected, or if the selected file cannot be represented
1156 * as a local filename. Free with g_free()
1161 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1163 GtkFileSystem *file_system;
1165 gchar *result = NULL;
1167 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1169 file_system = _gtk_file_chooser_get_file_system (chooser);
1170 path = _gtk_file_chooser_get_preview_path (chooser);
1173 result = gtk_file_system_path_to_filename (file_system, path);
1174 gtk_file_path_free (path);
1181 * gtk_file_chooser_get_preview_uri:
1182 * @chooser: a #GtkFileChooser
1184 * Gets the URI that should be previewed in a custom preview
1185 * widget. See gtk_file_chooser_set_preview_widget().
1187 * Return value: the URI for the file to preview, or %NULL if no file is
1188 * selected. Free with g_free().
1193 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1195 GtkFileSystem *file_system;
1197 gchar *result = NULL;
1199 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1201 file_system = _gtk_file_chooser_get_file_system (chooser);
1202 path = _gtk_file_chooser_get_preview_path (chooser);
1205 result = gtk_file_system_path_to_uri (file_system, path);
1206 gtk_file_path_free (path);
1213 * gtk_file_chooser_set_extra_widget:
1214 * @chooser: a #GtkFileChooser
1215 * @extra_widget: widget for extra options
1217 * Sets an application-supplied widget to provide extra options to the user.
1222 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1223 GtkWidget *extra_widget)
1225 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1227 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1231 * gtk_file_chooser_get_extra_widget:
1232 * @chooser: a #GtkFileChooser
1234 * Gets the current preview widget; see
1235 * gtk_file_chooser_set_extra_widget().
1237 * Return value: the current extra widget, or %NULL
1242 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1244 GtkWidget *extra_widget;
1246 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1248 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1250 /* Horrid hack; g_object_get() refs returned objects but
1251 * that contradicts the memory management conventions
1255 g_object_unref (extra_widget);
1257 return extra_widget;
1261 * gtk_file_chooser_add_filter:
1262 * @chooser: a #GtkFileChooser
1263 * @filter: a #GtkFileFilter
1265 * Adds @filter to the list of filters that the user can select between.
1266 * When a filter is selected, only files that are passed by that
1267 * filter are displayed.
1272 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1273 GtkFileFilter *filter)
1275 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1277 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1281 * gtk_file_chooser_remove_filter:
1282 * @chooser: a #GtkFileChooser
1283 * @filter: a #GtkFileFilter
1285 * Removes @filter from the list of filters that the user can select between.
1290 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1291 GtkFileFilter *filter)
1293 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1295 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1299 * gtk_file_chooser_list_filters:
1300 * @chooser: a #GtkFileChooser
1302 * Lists the current set of user-selectable filters; see
1303 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1305 * Return value: a #GSList containing the current set of
1306 * user selectable filters. The contents of the list are
1307 * owned by GTK+, but you must free the list itself with
1308 * g_slist_free() when you are done with it.
1313 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1315 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1317 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1321 * gtk_file_chooser_set_filter:
1322 * @chooser: a #GtkFileChooser
1323 * @filter: a #GtkFileFilter
1325 * Sets the current filter; only the files that pass the
1326 * filter will be displayed. If the user-selectable list of filters
1327 * is non-empty, then the filter should be one of the filters
1328 * in that list. Setting the current filter when the list of
1329 * filters is empty is useful if you want to restrict the displayed
1330 * set of files without letting the user change it.
1335 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1336 GtkFileFilter *filter)
1338 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1339 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1341 g_object_set (chooser, "filter", filter, NULL);
1345 * gtk_file_chooser_get_filter:
1346 * @chooser: a #GtkFileChooser
1348 * Gets the current filter; see gtk_file_chooser_set_filter().
1350 * Return value: the current filter, or %NULL
1355 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1357 GtkFileFilter *filter;
1359 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1361 g_object_get (chooser, "filter", &filter, NULL);
1362 /* Horrid hack; g_object_get() refs returned objects but
1363 * that contradicts the memory management conventions
1367 g_object_unref (filter);
1373 * gtk_file_chooser_add_shortcut_folder:
1374 * @chooser: a #GtkFileChooser
1375 * @folder: filename of the folder to add
1376 * @error: location to store error, or %NULL
1378 * Adds a folder to be displayed with the shortcut folders in a file chooser.
1379 * Note that shortcut folders do not get saved, as they are provided by the
1380 * application. For example, you can use this to add a
1381 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1383 * Return value: %TRUE if the folder could be added successfully, %FALSE
1384 * otherwise. In the latter case, the @error will be set as appropriate.
1389 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
1396 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1397 g_return_val_if_fail (folder != NULL, FALSE);
1399 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1403 GTK_FILE_CHOOSER_ERROR,
1404 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1405 _("Invalid filename: %s"),
1410 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1412 gtk_file_path_free (path);
1418 * gtk_file_chooser_remove_shortcut_folder:
1419 * @chooser: a #GtkFileChooser
1420 * @folder: filename of the folder to remove
1421 * @error: location to store error, or %NULL
1423 * Removes a folder from a file chooser's list of shortcut folders.
1425 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1426 * In the latter case, the @error will be set as appropriate.
1428 * See also: gtk_file_chooser_add_shortcut_folder()
1433 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
1440 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1441 g_return_val_if_fail (folder != NULL, FALSE);
1443 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1447 GTK_FILE_CHOOSER_ERROR,
1448 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1449 _("Invalid filename: %s"),
1454 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1456 gtk_file_path_free (path);
1462 * gtk_file_chooser_list_shortcut_folders:
1463 * @chooser: a #GtkFileChooser
1465 * Queries the list of shortcut folders in the file chooser, as set by
1466 * gtk_file_chooser_set_shortcut_folders().
1468 * Return value: A list of folder filenames, or %NULL if there are no shortcut
1469 * folders. Free the returned list with g_slist_free(), and the filenames with
1475 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1480 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1482 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1484 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1486 gtk_file_system_path_to_filename);
1487 gtk_file_paths_free (folders);
1492 * gtk_file_chooser_add_shortcut_folder_uri:
1493 * @chooser: a #GtkFileChooser
1494 * @uri: URI of the folder to add
1495 * @error: location to store error, or %NULL
1497 * Adds a folder URI to be displayed with the shortcut folders in a file
1498 * chooser. Note that shortcut folders do not get saved, as they are provided
1499 * by the application. For example, you can use this to add a
1500 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1502 * Return value: %TRUE if the folder could be added successfully, %FALSE
1503 * otherwise. In the latter case, the @error will be set as appropriate.
1508 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
1515 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1516 g_return_val_if_fail (uri != NULL, FALSE);
1518 path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1522 GTK_FILE_CHOOSER_ERROR,
1523 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1524 _("Invalid filename: %s"),
1529 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1531 gtk_file_path_free (path);
1537 * gtk_file_chooser_remove_shortcut_folder_uri:
1538 * @chooser: a #GtkFileChooser
1539 * @uri: URI of the folder to remove
1540 * @error: location to store error, or %NULL
1542 * Removes a folder URI from a file chooser's list of shortcut folders.
1544 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
1545 * In the latter case, the @error will be set as appropriate.
1547 * See also: gtk_file_chooser_add_shortcut_folder_uri()
1552 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
1559 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1560 g_return_val_if_fail (uri != NULL, FALSE);
1562 path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1566 GTK_FILE_CHOOSER_ERROR,
1567 GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1568 _("Invalid filename: %s"),
1573 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1575 gtk_file_path_free (path);
1581 * gtk_file_chooser_list_shortcut_folder_uris:
1582 * @chooser: a #GtkFileChooser
1584 * Queries the list of shortcut folders in the file chooser, as set by
1585 * gtk_file_chooser_set_shortcut_folder_uris().
1587 * Return value: A list of folder URIs, or %NULL if there are no shortcut
1588 * folders. Free the returned list with g_slist_free(), and the URIs with
1594 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1599 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1601 folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1603 result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1605 gtk_file_system_path_to_uri);
1606 gtk_file_paths_free (folders);