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_base_init (gpointer g_iface);
30 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
31 static GtkFilePath *gtk_file_chooser_get_preview_path (GtkFileChooser *chooser);
34 gtk_file_chooser_get_type (void)
36 static GType file_chooser_type = 0;
38 if (!file_chooser_type)
40 static const GTypeInfo file_chooser_info =
42 sizeof (GtkFileChooserIface), /* class_size */
43 gtk_file_chooser_base_init, /* base_init */
44 NULL, /* base_finalize */
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_base_init (gpointer g_iface)
60 static gboolean initialized = FALSE;
64 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
66 g_signal_new ("current-folder-changed",
69 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
71 g_cclosure_marshal_VOID__VOID,
73 g_signal_new ("selection-changed",
76 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
78 g_cclosure_marshal_VOID__VOID,
81 g_object_interface_install_property (g_iface,
82 g_param_spec_enum ("action",
84 _("The type of operation that the file selector is performing"),
85 GTK_TYPE_FILE_CHOOSER_ACTION,
86 GTK_FILE_CHOOSER_ACTION_OPEN,
88 g_object_interface_install_property (g_iface,
89 g_param_spec_object ("file-system",
91 _("File system object to use"),
93 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
94 g_object_interface_install_property (g_iface,
95 g_param_spec_boolean ("folder-mode",
97 _("Whether to select folders rather than files"),
100 g_object_interface_install_property (g_iface,
101 g_param_spec_boolean ("local-only",
103 _("Whether the selected file(s) should be limited to local file: URLs"),
106 g_object_interface_install_property (g_iface,
107 g_param_spec_object ("preview-widget",
109 _("Application supplied widget for custom previews."),
112 g_object_interface_install_property (g_iface,
113 g_param_spec_boolean ("preview-widget-active",
114 _("Preview Widget Active"),
115 _("Whether the application supplied widget for custom previews should be shown."),
118 g_object_interface_install_property (g_iface,
119 g_param_spec_boolean ("select-multiple",
120 _("Select Multiple"),
121 _("Whether to allow multiple files to be selected"),
125 g_object_interface_install_property (g_iface,
126 g_param_spec_boolean ("show-hidden",
128 _("Whether the hidden files and folders should be displayed"),
136 * gtk_file_chooser_set_action:
137 * @chooser: a #GtkFileChooser
138 * @action: the action that the file selector is performing
140 * Sets the type of operation that that the chooser is performing; the
141 * user interface is adapted to suit the selected action. For example,
142 * an option to create a new folder might be shown if the action is
143 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
144 * %GTK_FILE_CHOOSER_ACTION_OPEN.
147 gtk_file_chooser_set_action (GtkFileChooser *chooser,
148 GtkFileChooserAction action)
150 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
152 g_object_set (chooser, "action", action, NULL);
156 * gtk_file_chooser_get_action:
157 * @chooser: a #GtkFileChooser
159 * Gets the type of operation that the file chooser is performing; see
160 * gtk_file_chooser_set_action().
162 * Return value: the action that the file selector is performing
165 gtk_file_chooser_get_action (GtkFileChooser *chooser)
167 GtkFileChooserAction action;
169 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
171 g_object_get (chooser, "action", &action, NULL);
177 * gtk_file_chooser_set_folder_mode:
178 * @chooser: a #GtkFileChooser
179 * @folder_mode: %TRUE if the file chooser is used to select folders
182 * Sets whether the file chooser is used to select folders
183 * rather than files. If in folder mode, only folders are displayed
184 * to the use, and not the individual files inside the folders
185 * and the user selects a single folder rather than one or
189 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
190 gboolean folder_mode)
192 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
194 g_object_set (chooser, "folder-mode", folder_mode, NULL);
198 * gtk_file_chooser_get_folder_mode:
199 * @chooser: a #GtkFileChooser
201 * Gets whether the file chooser is used to select folders
202 * rather than files. See gtk_file_chooser_set_folder_mode()
204 * Return value: %TRUE if the file chooser is used to select
205 folders rather than files.
208 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
210 gboolean folder_mode;
212 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
214 g_object_get (chooser, "folder-mode", &folder_mode, NULL);
220 * gtk_file_chooser_set_local_only:
221 * @chooser: a #GtkFileChooser
222 * @local_only: %TRUE if only local files can be selected
224 * Sets whether only local files can be selected in the
225 * file selector. If @local_only is %TRUE (the default),
226 * then the selected file are files are guaranteed to be
227 * accessible through the operating systems native file
228 * file system and therefore the application only
229 * needs to worry about the filename functions in
230 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
231 * rather than the URI functions like
232 * 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.
253 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
257 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
259 g_object_get (chooser, "local-only", &local_only, NULL);
265 * gtk_file_chooser_set_select_multiple:
266 * @chooser: a #GtkFileChooser
267 * @select_multiple: %TRUE if multiple files can be selected.
269 * Sets whether multiple files can be selected in the file
270 * selector. If the file selector if in folder mode (see
271 * gtk_file_selector_set_folder_mode()) then only one folder
272 * can be selected, without regard to this setting.
275 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
276 gboolean select_multiple)
278 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
280 g_object_set (chooser, "select-multiple", select_multiple, NULL);
284 * gtk_file_chooser_get_select_multiple:
285 * @chooser: a #GtkFileChooser
287 * Gets whether multiple files can be selected in the file
288 * selector. See gtk_file_chooser_set_select_multiple().
290 * Return value: %TRUE if multiple files can be selected.
293 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
295 gboolean select_multiple;
297 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
299 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
301 return select_multiple;
305 * gtk_file_chooser_get_filename:
306 * @chooser: a #GtkFileChooser
308 * Gets the filename for the currently selected file in
309 * the file selector. If multiple files are selected,
310 * one of the filenames will be returned at random.
312 * Return value: The currently selected filename, or %NULL
313 * if no file is selected, or the selected file can't
314 * be represented with a local filename. Free with g_free().
317 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
319 GtkFileSystem *file_system;
321 gchar *result = NULL;
323 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
325 file_system = _gtk_file_chooser_get_file_system (chooser);
326 path = gtk_file_chooser_get_path (chooser);
329 result = gtk_file_system_path_to_filename (file_system, path);
330 gtk_file_path_free (path);
337 * gtk_file_chooser_set_filename:
338 * @chooser: a #GtkFileChooser
339 * @filename: the filename to set as current
341 * Sets @filename as the current filename for the the file chooser;
342 * If the file name isn't in the current folder of @chooser, then the
343 * current folder of @chooser will be changed to the folder containing
344 * @filename. This is equivalent to a sequence of
345 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
347 * Note that the file must exist, or nothing will be done except
348 * for the directory change. To pre-enter a filename for the user, as in
349 * a save-as dialog, use gtk_file_chooser_set_current_name()
352 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
353 const gchar *filename)
355 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
357 gtk_file_chooser_unselect_all (chooser);
358 gtk_file_chooser_select_filename (chooser, filename);
362 * gtk_file_chooser_select_filename:
363 * @chooser: a #GtkFileChooser
364 * @filename: the filename to select
366 * Selects a filename. If the file name isn't in the current
367 * folder of @chooser, then the current folder of @chooser will
368 * be changed to the folder containing @filename.
371 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
372 const gchar *filename)
374 GtkFileSystem *file_system;
377 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
378 g_return_if_fail (filename != NULL);
380 file_system = _gtk_file_chooser_get_file_system (chooser);
382 path = gtk_file_system_filename_to_path (file_system, filename);
385 _gtk_file_chooser_select_path (chooser, path);
386 gtk_file_path_free (path);
391 * gtk_file_chooser_unselect_filename:
392 * @chooser: a #GtkFileChooser
393 * @filename: the filename to unselect
395 * Unselects a currently selected filename. If the filename
396 * is not in the current directory, does not exist, or
397 * is otherwise not currently selected, does nothing.
400 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
401 const char *filename)
403 GtkFileSystem *file_system;
406 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
407 g_return_if_fail (filename != NULL);
409 file_system = _gtk_file_chooser_get_file_system (chooser);
411 path = gtk_file_system_filename_to_path (file_system, filename);
414 _gtk_file_chooser_unselect_path (chooser, path);
415 gtk_file_path_free (path);
420 * gtk_file_chooser_get_filenames:
421 * @chooser: a #GtkFileChooser
423 * Lists all the files and subfolders in the current folder of
424 * @chooser. The returned names are full absolute paths. If files
425 * in the current folder cannot be represented as local filenames
426 * they will be ignored. (See gtk_file_chooser_get_uris())
428 * Return value: a #GList containing the filenames of all
429 * files and subfolders in the current folder. Free the returned list
430 * with g_lists_free(), and the filenames with g_free().
433 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
435 GtkFileSystem *file_system;
438 GSList *result = NULL;
440 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
442 file_system = _gtk_file_chooser_get_file_system (chooser);
443 paths = _gtk_file_chooser_get_paths (chooser);
445 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
447 gchar *filename = gtk_file_system_path_to_filename (file_system, tmp_list->data);
449 result = g_slist_prepend (result, filename);
452 gtk_file_paths_free (paths);
454 return g_slist_reverse (result);
458 * gtk_file_chooser_set_current_folder:
459 * @chooser: a #GtkFileChooser
460 * @filename: the full path of the new current folder
462 * Sets the current folder for @chooser from a local filename.
463 * The user will be shown the full contents of the current folder,
464 * plus user interface elements for navigating to other folders.
467 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
468 const gchar *filename)
470 GtkFileSystem *file_system;
473 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
474 g_return_if_fail (filename != NULL);
476 file_system = _gtk_file_chooser_get_file_system (chooser);
478 path = gtk_file_system_filename_to_path (file_system, filename);
481 _gtk_file_chooser_set_current_folder_path (chooser, path);
482 gtk_file_path_free (path);
487 * gtk_file_chooser_get_current_folder:
488 * @chooser: a #GtkFileChooser
490 * Gets the current folder of @chooser as a local filename.
491 * See gtk_file_chooser_set_current_folder().
493 * Return value: the full path of the current folder, or %NULL
494 * if the current path cannot be represented as a local filename.
495 * Free with g_free().
498 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
500 GtkFileSystem *file_system;
504 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
506 file_system = _gtk_file_chooser_get_file_system (chooser);
508 path = _gtk_file_chooser_get_current_folder_path (chooser);
509 filename = gtk_file_system_path_to_filename (file_system, path);
510 gtk_file_path_free (path);
516 * gtk_file_chooser_set_current_name:
517 * @chooser: a #GtkFileChooser
518 * @name: the filename to use, as a UTF-8 string
520 * Sets the current name in the file selector, as if entered
521 * by the user. Note that the name passed in here is a UTF-8
522 * string rather than a filename. This function is meant for
523 * such uses as a suggested name in a "Save As..." dialog.
525 * If you want to preselect a particular existing file, you
526 * should use gtk_file_chooser_set_filename() instead.
529 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
532 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
533 g_return_if_fail (name != NULL);
535 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
539 * gtk_file_chooser_get_uri:
540 * @chooser: a #GtkFileChooser
542 * Gets the URI for the currently selected file in
543 * the file selector. If multiple files are selected,
544 * one of the filenames will be returned at random.
546 * Return value: The currently selected URI, or %NULL
547 * if no file is selected. Free with g_free()
550 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
552 GtkFileSystem *file_system;
554 gchar *result = NULL;
556 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
558 file_system = _gtk_file_chooser_get_file_system (chooser);
559 path = gtk_file_chooser_get_path (chooser);
562 result = gtk_file_system_path_to_uri (file_system, path);
563 gtk_file_path_free (path);
570 * gtk_file_chooser_set_uri:
571 * @chooser: a #GtkFileChooser
572 * @uri: the URI to set as current
574 * Sets the file referred to by @uri as the current file for the the
575 * file chooser; If the file name isn't in the current folder of @chooser,
576 * then the current folder of @chooser will be changed to the folder containing
577 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
578 * followed by gtk_file_chooser_select_uri().
580 * Note that the file must exist, or nothing will be done except
581 * for the directory change. To pre-enter a filename for the user, as in
582 * a save-as dialog, use gtk_file_chooser_set_current_name()
585 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
588 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
590 gtk_file_chooser_unselect_all (chooser);
591 gtk_file_chooser_select_uri (chooser, uri);
595 * gtk_file_chooser_select_uri:
596 * @chooser: a #GtkFileChooser
597 * @uri: the URI to select
599 * Selects the file to by @uri. If the URI doesn't refer to a
600 * file in the current folder of @chooser, then the current folder of
601 * @chooser will be changed to the folder containing @filename.
604 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
607 GtkFileSystem *file_system;
610 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
611 g_return_if_fail (uri != NULL);
613 file_system = _gtk_file_chooser_get_file_system (chooser);
615 path = gtk_file_system_uri_to_path (file_system, uri);
618 _gtk_file_chooser_select_path (chooser, path);
619 gtk_file_path_free (path);
624 * gtk_file_chooser_unselect_uri:
625 * @chooser: a #GtkFileChooser
626 * @uri: the URI to unselect
628 * Unselects the file referred to by @uri. If the file
629 * is not in the current directory, does not exist, or
630 * is otherwise not currently selected, does nothing.
633 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
636 GtkFileSystem *file_system;
639 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
640 g_return_if_fail (uri != NULL);
642 file_system = _gtk_file_chooser_get_file_system (chooser);
644 path = gtk_file_system_uri_to_path (file_system, uri);
647 _gtk_file_chooser_unselect_path (chooser, path);
648 gtk_file_path_free (path);
653 gtk_file_chooser_select_all (GtkFileChooser *chooser)
655 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
657 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
661 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
664 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
666 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
670 * gtk_file_chooser_get_filenames:
671 * @chooser: a #GtkFileChooser
673 * Lists all the files and subfolders in the current folder of
674 * @chooser. The returned names are full absolute URIs.
676 * Return value: a #GList containing the URIs of all
677 * files and subfolders in the current folder. Free the returned list
678 * with g_lists_free(), and the filenames with g_free().
681 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
683 GtkFileSystem *file_system;
686 GSList *result = NULL;
688 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
690 file_system = _gtk_file_chooser_get_file_system (chooser);
691 paths = _gtk_file_chooser_get_paths (chooser);
693 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
695 gchar *uri = gtk_file_system_path_to_uri (file_system, tmp_list->data);
697 result = g_slist_prepend (result, uri);
700 gtk_file_paths_free (paths);
702 return g_slist_reverse (result);
706 * gtk_file_chooser_set_current_folder_uri:
707 * @chooser: a #GtkFileChooser
708 * @uri: the URI for the new current folder
710 * Sets the current folder for @chooser from an URI.
711 * The user will be shown the full contents of the current folder,
712 * plus user interface elements for navigating to other folders.
715 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
718 GtkFileSystem *file_system;
721 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
722 g_return_if_fail (uri != NULL);
724 file_system = _gtk_file_chooser_get_file_system (chooser);
726 path = gtk_file_system_uri_to_path (file_system, uri);
729 _gtk_file_chooser_set_current_folder_path (chooser, path);
730 gtk_file_path_free (path);
735 * gtk_file_chooser_get_current_folder_uri:
736 * @chooser: a #GtkFileChooser
738 * Gets the current folder of @chooser as an URI.
739 * See gtk_file_chooser_set_current_folder_uri().
741 * Return value: the URI for the current folder.
742 * Free with g_free().
745 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
747 GtkFileSystem *file_system;
751 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
753 file_system = _gtk_file_chooser_get_file_system (chooser);
755 path = _gtk_file_chooser_get_current_folder_path (chooser);
756 uri = gtk_file_system_path_to_uri (file_system, path);
757 gtk_file_path_free (path);
763 * _gtk_file_chooser_set_current_folder_path:
764 * @chooser: a #GtkFileChooser
765 * @path: the #GtkFilePath for the new folder
767 * Sets the current folder for @chooser from a #GtkFilePath.
768 * Internal function, see _gtk_file_chooser_set_current_folder_uri().
771 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
772 const GtkFilePath *path)
774 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
775 g_return_if_fail (path != NULL);
777 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
781 * _gtk_file_chooser_get_current_folder_path:
782 * @chooser: a #GtkFileChooser
784 * Gets the current folder of @chooser as #GtkFilePath.
785 * See gtk_file_chooser_get_current_folder_uri().
787 * Return value: the #GtkFilePath for the current folder.
788 * Fre with gtk_file_path_free ().
791 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
793 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
795 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
799 * _gtk_file_chooser_select_path:
800 * @chooser: a #GtkFileChooser
801 * @path: the path to select
803 * Selects the file referred to by @path. An internal function. See
804 * _gtk_file_chooser_select_uri().
807 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
808 const GtkFilePath *path)
810 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
812 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
816 * _gtk_file_chooser_unselect_path:
817 * @chooser: a #GtkFileChooser
818 * @path: the filename to path
820 * Unselects the file referred to by @path. An internal
821 * function. See _gtk_file_chooser_unselect_uri().
824 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
825 const GtkFilePath *path)
827 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
829 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
833 * _gtk_file_chooser_get_paths:
834 * @chooser: a #GtkFileChooser
836 * Lists all the files and subfolders in the current folder of
837 * @chooser as #GtkFilePath. An internal function, see
838 * gtk_file_chooser_get_uris().
840 * Return value: a #GList containing a #GtkFilePath for each
841 * files and subfolder in the current folder. Free the returned list
842 * with g_lists_free(), and the paths with gtk_file_path_free().
845 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
847 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
849 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
853 gtk_file_chooser_get_path (GtkFileChooser *chooser)
856 GtkFilePath *result = NULL;
858 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
860 list = _gtk_file_chooser_get_paths (chooser);
864 list = g_slist_delete_link (list, list);
865 gtk_file_paths_free (list);
872 * _gtk_file_chooser_get_file_system:
873 * @chooser: a #GtkFileChooser
875 * Gets the #GtkFileSystem of @chooser; this is an internal
876 * implementation detail, used for conversion between paths
877 * and filenames and URIs.
879 * Return value: the file system for @chooser.
882 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
884 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
886 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
892 * gtk_file_chooser_set_preview_widget:
893 * @chooser: a #GtkFileChooser
894 * @preview_widget: widget for displaying preview.
896 * Sets an application-supplied widget to use to display a custom preview
897 * of the currently selected file. To implement a preview, after setting the
898 * preview widget, you connect to the ::selection-changed
899 * signal, and call gtk_file_chooser_get_preview_filename() or
900 * gtk_file_chooser_get_preview_uri() on each change. If you can
901 * display a preview of the new file, update your widget
902 * and set the preview active using gtk_file_chooser_set_preview_widget_active().
903 * Otherwise, set the preview inactive.
905 * When there is application-supplied preview widget, or the application-supplied
906 * preview widget is not active, the file chooser may display an internally
907 * generated preview of the current file or it may display no preview at all.
910 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
911 GtkWidget *preview_widget)
913 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
915 g_object_set (chooser, "preview-widget", preview_widget, NULL);
919 * gtk_file_chooser_get_preview_widget:
920 * @chooser: a #GtkFileChooser
922 * Gets the current preview widget; see
923 * gtk_file_chooser_set_preview_widget().
925 * Return value: the current preview widget, or %NULL
928 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
930 GtkWidget *preview_widget;
932 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
934 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
936 return preview_widget;
940 * gtk_file_chooser_set_preview_widget_active:
941 * @chooser: a #GtkFileChooser
942 * @active: whether to display the user-specified preview widget
944 * Sets whether the preview widget set by
945 * gtk_file_chooser_set_preview_widget_active() should be shown for the
946 * current filename. When @active is set to false, the file chooser
947 * may display an internally generated preview of the current file
948 * or it may display no preview at all. See
949 * gtk_file_chooser_set_preview_widget() for more details.
952 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
955 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
957 g_object_set (chooser, "preview-widget-active", active, NULL);
961 * gtk_file_chooser_get_preview_widget_active:
962 * @chooser: a #GtkFileChooser
964 * Gets whether the preview widget set by
965 * gtk_file_chooser_set_preview_widget_active() should be shown for the
966 * current filename. See gtk_file_chooser_set_preview_widget_active().
968 * Return value: %TRUE if the preview widget is active for the
972 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
976 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
978 g_object_get (chooser, "preview-widget-active", &active, NULL);
984 gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
990 * gtk_file_chooser_get_preview_filename:
991 * @chooser: a #GtkFileChooser
993 * Gets the filename that should be previewed in a custom preview
994 * widget. See gtk_file_chooser_set_preview_widget().
996 * Return value: the filename to display, or %NULL if no file
997 * is selected, or if the selected file cannot be represented
998 * as a local filename. Free with g_free()
1001 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1003 GtkFileSystem *file_system;
1005 gchar *result = NULL;
1007 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1009 file_system = _gtk_file_chooser_get_file_system (chooser);
1010 path = gtk_file_chooser_get_preview_path (chooser);
1013 result = gtk_file_system_path_to_filename (file_system, path);
1014 gtk_file_path_free (path);
1021 * gtk_file_chooser_get_preview_filename:
1022 * @chooser: a #GtkFileChooser
1024 * Gets the URI that should be previewed in a custom preview
1025 * widget. See gtk_file_chooser_set_preview_widget().
1027 * Return value: the URI to display, or %NULL if no file
1031 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1033 GtkFileSystem *file_system;
1035 gchar *result = NULL;
1037 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1039 file_system = _gtk_file_chooser_get_file_system (chooser);
1040 path = gtk_file_chooser_get_path (chooser);
1043 result = gtk_file_system_path_to_uri (file_system, path);
1044 gtk_file_path_free (path);