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);
33 gtk_file_chooser_get_type (void)
35 static GType file_chooser_type = 0;
37 if (!file_chooser_type)
39 static const GTypeInfo file_chooser_info =
41 sizeof (GtkFileChooserIface), /* class_size */
42 gtk_file_chooser_base_init, /* base_init */
43 NULL, /* base_finalize */
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_base_init (gpointer g_iface)
59 static gboolean initialized = FALSE;
63 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
65 g_signal_new ("current-folder-changed",
68 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
70 g_cclosure_marshal_VOID__VOID,
72 g_signal_new ("selection-changed",
75 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
77 g_cclosure_marshal_VOID__VOID,
79 g_signal_new ("update-preview",
82 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
84 g_cclosure_marshal_VOID__VOID,
87 g_object_interface_install_property (g_iface,
88 g_param_spec_enum ("action",
90 _("The type of operation that the file selector is performing"),
91 GTK_TYPE_FILE_CHOOSER_ACTION,
92 GTK_FILE_CHOOSER_ACTION_OPEN,
94 g_object_interface_install_property (g_iface,
95 g_param_spec_object ("file-system",
97 _("File system object to use"),
99 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
100 g_object_interface_install_property (g_iface,
101 g_param_spec_object ("filter",
103 _("The current filter for selecting which files are displayed"),
104 GTK_TYPE_FILE_FILTER,
106 g_object_interface_install_property (g_iface,
107 g_param_spec_boolean ("folder-mode",
109 _("Whether to select folders rather than files"),
112 g_object_interface_install_property (g_iface,
113 g_param_spec_boolean ("local-only",
115 _("Whether the selected file(s) should be limited to local file: URLs"),
118 g_object_interface_install_property (g_iface,
119 g_param_spec_object ("preview-widget",
121 _("Application supplied widget for custom previews."),
124 g_object_interface_install_property (g_iface,
125 g_param_spec_boolean ("preview-widget-active",
126 _("Preview Widget Active"),
127 _("Whether the application supplied widget for custom previews should be shown."),
130 g_object_interface_install_property (g_iface,
131 g_param_spec_boolean ("select-multiple",
132 _("Select Multiple"),
133 _("Whether to allow multiple files to be selected"),
137 g_object_interface_install_property (g_iface,
138 g_param_spec_boolean ("show-hidden",
140 _("Whether the hidden files and folders should be displayed"),
148 * gtk_file_chooser_set_action:
149 * @chooser: a #GtkFileChooser
150 * @action: the action that the file selector is performing
152 * Sets the type of operation that that the chooser is performing; the
153 * user interface is adapted to suit the selected action. For example,
154 * an option to create a new folder might be shown if the action is
155 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
156 * %GTK_FILE_CHOOSER_ACTION_OPEN.
159 gtk_file_chooser_set_action (GtkFileChooser *chooser,
160 GtkFileChooserAction action)
162 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
164 g_object_set (chooser, "action", action, NULL);
168 * gtk_file_chooser_get_action:
169 * @chooser: a #GtkFileChooser
171 * Gets the type of operation that the file chooser is performing; see
172 * gtk_file_chooser_set_action().
174 * Return value: the action that the file selector is performing
177 gtk_file_chooser_get_action (GtkFileChooser *chooser)
179 GtkFileChooserAction action;
181 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
183 g_object_get (chooser, "action", &action, NULL);
189 * gtk_file_chooser_set_folder_mode:
190 * @chooser: a #GtkFileChooser
191 * @folder_mode: %TRUE if the file chooser is used to select folders
194 * Sets whether the file chooser is used to select folders
195 * rather than files. If in folder mode, only folders are displayed
196 * to the use, and not the individual files inside the folders
197 * and the user selects a single folder rather than one or
201 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
202 gboolean folder_mode)
204 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
206 g_object_set (chooser, "folder-mode", folder_mode, NULL);
210 * gtk_file_chooser_get_folder_mode:
211 * @chooser: a #GtkFileChooser
213 * Gets whether the file chooser is used to select folders
214 * rather than files. See gtk_file_chooser_set_folder_mode()
216 * Return value: %TRUE if the file chooser is used to select
217 folders rather than files.
220 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
222 gboolean folder_mode;
224 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
226 g_object_get (chooser, "folder-mode", &folder_mode, NULL);
232 * gtk_file_chooser_set_local_only:
233 * @chooser: a #GtkFileChooser
234 * @local_only: %TRUE if only local files can be selected
236 * Sets whether only local files can be selected in the
237 * file selector. If @local_only is %TRUE (the default),
238 * then the selected file are files are guaranteed to be
239 * accessible through the operating systems native file
240 * file system and therefore the application only
241 * needs to worry about the filename functions in
242 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
243 * rather than the URI functions like
244 * gtk_file_chooser_get_uri(),
247 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
250 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
252 g_object_set (chooser, "local-only", local_only, NULL);
256 * gtk_file_chooser_get_local_only:
257 * @chooser: a #GtkFileChoosre
259 * Gets whether only local files can be selected in the
260 * file selector. See gtk_file_chooser_set_local_only()
262 * Return value: %TRUE if only local files can be selected.
265 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
269 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
271 g_object_get (chooser, "local-only", &local_only, NULL);
277 * gtk_file_chooser_set_select_multiple:
278 * @chooser: a #GtkFileChooser
279 * @select_multiple: %TRUE if multiple files can be selected.
281 * Sets whether multiple files can be selected in the file
282 * selector. If the file selector if in folder mode (see
283 * gtk_file_selector_set_folder_mode()) then only one folder
284 * can be selected, without regard to this setting.
287 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
288 gboolean select_multiple)
290 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
292 g_object_set (chooser, "select-multiple", select_multiple, NULL);
296 * gtk_file_chooser_get_select_multiple:
297 * @chooser: a #GtkFileChooser
299 * Gets whether multiple files can be selected in the file
300 * selector. See gtk_file_chooser_set_select_multiple().
302 * Return value: %TRUE if multiple files can be selected.
305 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
307 gboolean select_multiple;
309 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
311 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
313 return select_multiple;
317 * gtk_file_chooser_get_filename:
318 * @chooser: a #GtkFileChooser
320 * Gets the filename for the currently selected file in
321 * the file selector. If multiple files are selected,
322 * one of the filenames will be returned at random.
324 * Return value: The currently selected filename, or %NULL
325 * if no file is selected, or the selected file can't
326 * be represented with a local filename. Free with g_free().
329 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
331 GtkFileSystem *file_system;
333 gchar *result = NULL;
335 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
337 file_system = _gtk_file_chooser_get_file_system (chooser);
338 path = gtk_file_chooser_get_path (chooser);
341 result = gtk_file_system_path_to_filename (file_system, path);
342 gtk_file_path_free (path);
349 * gtk_file_chooser_set_filename:
350 * @chooser: a #GtkFileChooser
351 * @filename: the filename to set as current
353 * Sets @filename as the current filename for the the file chooser;
354 * If the file name isn't in the current folder of @chooser, then the
355 * current folder of @chooser will be changed to the folder containing
356 * @filename. This is equivalent to a sequence of
357 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
359 * Note that the file must exist, or nothing will be done except
360 * for the directory change. To pre-enter a filename for the user, as in
361 * a save-as dialog, use gtk_file_chooser_set_current_name()
364 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
365 const gchar *filename)
367 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
369 gtk_file_chooser_unselect_all (chooser);
370 gtk_file_chooser_select_filename (chooser, filename);
374 * gtk_file_chooser_select_filename:
375 * @chooser: a #GtkFileChooser
376 * @filename: the filename to select
378 * Selects a filename. If the file name isn't in the current
379 * folder of @chooser, then the current folder of @chooser will
380 * be changed to the folder containing @filename.
383 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
384 const gchar *filename)
386 GtkFileSystem *file_system;
389 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
390 g_return_if_fail (filename != NULL);
392 file_system = _gtk_file_chooser_get_file_system (chooser);
394 path = gtk_file_system_filename_to_path (file_system, filename);
397 _gtk_file_chooser_select_path (chooser, path);
398 gtk_file_path_free (path);
403 * gtk_file_chooser_unselect_filename:
404 * @chooser: a #GtkFileChooser
405 * @filename: the filename to unselect
407 * Unselects a currently selected filename. If the filename
408 * is not in the current directory, does not exist, or
409 * is otherwise not currently selected, does nothing.
412 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
413 const char *filename)
415 GtkFileSystem *file_system;
418 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
419 g_return_if_fail (filename != NULL);
421 file_system = _gtk_file_chooser_get_file_system (chooser);
423 path = gtk_file_system_filename_to_path (file_system, filename);
426 _gtk_file_chooser_unselect_path (chooser, path);
427 gtk_file_path_free (path);
432 * gtk_file_chooser_get_filenames:
433 * @chooser: a #GtkFileChooser
435 * Lists all the files and subfolders in the current folder of
436 * @chooser. The returned names are full absolute paths. If files
437 * in the current folder cannot be represented as local filenames
438 * they will be ignored. (See gtk_file_chooser_get_uris())
440 * Return value: a #GList containing the filenames of all
441 * files and subfolders in the current folder. Free the returned list
442 * with g_lists_free(), and the filenames with g_free().
445 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
447 GtkFileSystem *file_system;
450 GSList *result = NULL;
452 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
454 file_system = _gtk_file_chooser_get_file_system (chooser);
455 paths = _gtk_file_chooser_get_paths (chooser);
457 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
459 gchar *filename = gtk_file_system_path_to_filename (file_system, tmp_list->data);
461 result = g_slist_prepend (result, filename);
464 gtk_file_paths_free (paths);
466 return g_slist_reverse (result);
470 * gtk_file_chooser_set_current_folder:
471 * @chooser: a #GtkFileChooser
472 * @filename: the full path of the new current folder
474 * Sets the current folder for @chooser from a local filename.
475 * The user will be shown the full contents of the current folder,
476 * plus user interface elements for navigating to other folders.
479 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
480 const gchar *filename)
482 GtkFileSystem *file_system;
485 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
486 g_return_if_fail (filename != NULL);
488 file_system = _gtk_file_chooser_get_file_system (chooser);
490 path = gtk_file_system_filename_to_path (file_system, filename);
493 _gtk_file_chooser_set_current_folder_path (chooser, path);
494 gtk_file_path_free (path);
499 * gtk_file_chooser_get_current_folder:
500 * @chooser: a #GtkFileChooser
502 * Gets the current folder of @chooser as a local filename.
503 * See gtk_file_chooser_set_current_folder().
505 * Return value: the full path of the current folder, or %NULL
506 * if the current path cannot be represented as a local filename.
507 * Free with g_free().
510 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
512 GtkFileSystem *file_system;
516 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
518 file_system = _gtk_file_chooser_get_file_system (chooser);
520 path = _gtk_file_chooser_get_current_folder_path (chooser);
521 filename = gtk_file_system_path_to_filename (file_system, path);
522 gtk_file_path_free (path);
528 * gtk_file_chooser_set_current_name:
529 * @chooser: a #GtkFileChooser
530 * @name: the filename to use, as a UTF-8 string
532 * Sets the current name in the file selector, as if entered
533 * by the user. Note that the name passed in here is a UTF-8
534 * string rather than a filename. This function is meant for
535 * such uses as a suggested name in a "Save As..." dialog.
537 * If you want to preselect a particular existing file, you
538 * should use gtk_file_chooser_set_filename() instead.
541 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
544 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
545 g_return_if_fail (name != NULL);
547 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
551 * gtk_file_chooser_get_uri:
552 * @chooser: a #GtkFileChooser
554 * Gets the URI for the currently selected file in
555 * the file selector. If multiple files are selected,
556 * one of the filenames will be returned at random.
558 * Return value: The currently selected URI, or %NULL
559 * if no file is selected. Free with g_free()
562 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
564 GtkFileSystem *file_system;
566 gchar *result = NULL;
568 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
570 file_system = _gtk_file_chooser_get_file_system (chooser);
571 path = gtk_file_chooser_get_path (chooser);
574 result = gtk_file_system_path_to_uri (file_system, path);
575 gtk_file_path_free (path);
582 * gtk_file_chooser_set_uri:
583 * @chooser: a #GtkFileChooser
584 * @uri: the URI to set as current
586 * Sets the file referred to by @uri as the current file for the the
587 * file chooser; If the file name isn't in the current folder of @chooser,
588 * then the current folder of @chooser will be changed to the folder containing
589 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
590 * followed by gtk_file_chooser_select_uri().
592 * Note that the file must exist, or nothing will be done except
593 * for the directory change. To pre-enter a filename for the user, as in
594 * a save-as dialog, use gtk_file_chooser_set_current_name()
597 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
600 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
602 gtk_file_chooser_unselect_all (chooser);
603 gtk_file_chooser_select_uri (chooser, uri);
607 * gtk_file_chooser_select_uri:
608 * @chooser: a #GtkFileChooser
609 * @uri: the URI to select
611 * Selects the file to by @uri. If the URI doesn't refer to a
612 * file in the current folder of @chooser, then the current folder of
613 * @chooser will be changed to the folder containing @filename.
616 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
619 GtkFileSystem *file_system;
622 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
623 g_return_if_fail (uri != NULL);
625 file_system = _gtk_file_chooser_get_file_system (chooser);
627 path = gtk_file_system_uri_to_path (file_system, uri);
630 _gtk_file_chooser_select_path (chooser, path);
631 gtk_file_path_free (path);
636 * gtk_file_chooser_unselect_uri:
637 * @chooser: a #GtkFileChooser
638 * @uri: the URI to unselect
640 * Unselects the file referred to by @uri. If the file
641 * is not in the current directory, does not exist, or
642 * is otherwise not currently selected, does nothing.
645 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
648 GtkFileSystem *file_system;
651 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
652 g_return_if_fail (uri != NULL);
654 file_system = _gtk_file_chooser_get_file_system (chooser);
656 path = gtk_file_system_uri_to_path (file_system, uri);
659 _gtk_file_chooser_unselect_path (chooser, path);
660 gtk_file_path_free (path);
665 gtk_file_chooser_select_all (GtkFileChooser *chooser)
667 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
669 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
673 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
676 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
678 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
682 * gtk_file_chooser_get_filenames:
683 * @chooser: a #GtkFileChooser
685 * Lists all the files and subfolders in the current folder of
686 * @chooser. The returned names are full absolute URIs.
688 * Return value: a #GList containing the URIs of all
689 * files and subfolders in the current folder. Free the returned list
690 * with g_lists_free(), and the filenames with g_free().
693 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
695 GtkFileSystem *file_system;
698 GSList *result = NULL;
700 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
702 file_system = _gtk_file_chooser_get_file_system (chooser);
703 paths = _gtk_file_chooser_get_paths (chooser);
705 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
707 gchar *uri = gtk_file_system_path_to_uri (file_system, tmp_list->data);
709 result = g_slist_prepend (result, uri);
712 gtk_file_paths_free (paths);
714 return g_slist_reverse (result);
718 * gtk_file_chooser_set_current_folder_uri:
719 * @chooser: a #GtkFileChooser
720 * @uri: the URI for the new current folder
722 * Sets the current folder for @chooser from an URI.
723 * The user will be shown the full contents of the current folder,
724 * plus user interface elements for navigating to other folders.
727 gtk_file_chooser_set_current_folder_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_set_current_folder_path (chooser, path);
742 gtk_file_path_free (path);
747 * gtk_file_chooser_get_current_folder_uri:
748 * @chooser: a #GtkFileChooser
750 * Gets the current folder of @chooser as an URI.
751 * See gtk_file_chooser_set_current_folder_uri().
753 * Return value: the URI for the current folder.
754 * Free with g_free().
757 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
759 GtkFileSystem *file_system;
763 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
765 file_system = _gtk_file_chooser_get_file_system (chooser);
767 path = _gtk_file_chooser_get_current_folder_path (chooser);
768 uri = gtk_file_system_path_to_uri (file_system, path);
769 gtk_file_path_free (path);
775 * _gtk_file_chooser_set_current_folder_path:
776 * @chooser: a #GtkFileChooser
777 * @path: the #GtkFilePath for the new folder
779 * Sets the current folder for @chooser from a #GtkFilePath.
780 * Internal function, see gtk_file_chooser_set_current_folder_uri().
783 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
784 const GtkFilePath *path)
786 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
787 g_return_if_fail (path != NULL);
789 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
793 * _gtk_file_chooser_get_current_folder_path:
794 * @chooser: a #GtkFileChooser
796 * Gets the current folder of @chooser as #GtkFilePath.
797 * See gtk_file_chooser_get_current_folder_uri().
799 * Return value: the #GtkFilePath for the current folder.
800 * Fre with gtk_file_path_free ().
803 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
805 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
807 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
811 * _gtk_file_chooser_select_path:
812 * @chooser: a #GtkFileChooser
813 * @path: the path to select
815 * Selects the file referred to by @path. An internal function. See
816 * _gtk_file_chooser_select_uri().
819 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
820 const GtkFilePath *path)
822 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
824 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
828 * _gtk_file_chooser_unselect_path:
829 * @chooser: a #GtkFileChooser
830 * @path: the filename to path
832 * Unselects the file referred to by @path. An internal
833 * function. See _gtk_file_chooser_unselect_uri().
836 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
837 const GtkFilePath *path)
839 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
841 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
845 * _gtk_file_chooser_get_paths:
846 * @chooser: a #GtkFileChooser
848 * Lists all the files and subfolders in the current folder of
849 * @chooser as #GtkFilePath. An internal function, see
850 * gtk_file_chooser_get_uris().
852 * Return value: a #GList containing a #GtkFilePath for each
853 * files and subfolder in the current folder. Free the returned list
854 * with g_lists_free(), and the paths with gtk_file_path_free().
857 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
859 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
861 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
865 gtk_file_chooser_get_path (GtkFileChooser *chooser)
868 GtkFilePath *result = NULL;
870 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
872 list = _gtk_file_chooser_get_paths (chooser);
876 list = g_slist_delete_link (list, list);
877 gtk_file_paths_free (list);
884 * _gtk_file_chooser_get_file_system:
885 * @chooser: a #GtkFileChooser
887 * Gets the #GtkFileSystem of @chooser; this is an internal
888 * implementation detail, used for conversion between paths
889 * and filenames and URIs.
891 * Return value: the file system for @chooser.
894 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
896 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
898 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
904 * gtk_file_chooser_set_preview_widget:
905 * @chooser: a #GtkFileChooser
906 * @preview_widget: widget for displaying preview.
908 * Sets an application-supplied widget to use to display a custom preview
909 * of the currently selected file. To implement a preview, after setting the
910 * preview widget, you connect to the ::selection-changed
911 * signal, and call gtk_file_chooser_get_preview_filename() or
912 * gtk_file_chooser_get_preview_uri() on each change. If you can
913 * display a preview of the new file, update your widget
914 * and set the preview active using gtk_file_chooser_set_preview_widget_active().
915 * Otherwise, set the preview inactive.
917 * When there is application-supplied preview widget, or the application-supplied
918 * preview widget is not active, the file chooser may display an internally
919 * generated preview of the current file or it may display no preview at all.
922 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
923 GtkWidget *preview_widget)
925 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
927 g_object_set (chooser, "preview-widget", preview_widget, NULL);
931 * gtk_file_chooser_get_preview_widget:
932 * @chooser: a #GtkFileChooser
934 * Gets the current preview widget; see
935 * gtk_file_chooser_set_preview_widget().
937 * Return value: the current preview widget, or %NULL
940 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
942 GtkWidget *preview_widget;
944 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
946 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
948 /* Horrid hack; g_object_get() refs returned objects but
949 * that contradicts the memory management conventions
953 g_object_unref (preview_widget);
955 return preview_widget;
959 * gtk_file_chooser_set_preview_widget_active:
960 * @chooser: a #GtkFileChooser
961 * @active: whether to display the user-specified preview widget
963 * Sets whether the preview widget set by
964 * gtk_file_chooser_set_preview_widget_active() should be shown for the
965 * current filename. When @active is set to false, the file chooser
966 * may display an internally generated preview of the current file
967 * or it may display no preview at all. See
968 * gtk_file_chooser_set_preview_widget() for more details.
971 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
974 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
976 g_object_set (chooser, "preview-widget-active", active, NULL);
980 * gtk_file_chooser_get_preview_widget_active:
981 * @chooser: a #GtkFileChooser
983 * Gets whether the preview widget set by
984 * gtk_file_chooser_set_preview_widget_active() should be shown for the
985 * current filename. See gtk_file_chooser_set_preview_widget_active().
987 * Return value: %TRUE if the preview widget is active for the
991 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
995 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
997 g_object_get (chooser, "preview-widget-active", &active, NULL);
1003 * gtk_file_chooser_get_preview_filename:
1004 * @chooser: a #GtkFileChooser
1006 * Gets the filename that should be previewed in a custom preview
1007 * Internal function, see gtk_file_chooser_get_preview_uri().n
1009 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1010 * is selected. Free with gtk_file_path_free().
1013 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1015 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1017 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1021 * gtk_file_chooser_get_preview_filename:
1022 * @chooser: a #GtkFileChooser
1024 * Gets the filename that should be previewed in a custom preview
1025 * widget. See gtk_file_chooser_set_preview_widget().
1027 * Return value: the filename to preview, or %NULL if no file
1028 * is selected, or if the selected file cannot be represented
1029 * as a local filename. Free with g_free()
1032 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1034 GtkFileSystem *file_system;
1036 gchar *result = NULL;
1038 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1040 file_system = _gtk_file_chooser_get_file_system (chooser);
1041 path = _gtk_file_chooser_get_preview_path (chooser);
1044 result = gtk_file_system_path_to_filename (file_system, path);
1045 gtk_file_path_free (path);
1052 * gtk_file_chooser_get_preview_filename:
1053 * @chooser: a #GtkFileChooser
1055 * Gets the URI that should be previewed in a custom preview
1056 * widget. See gtk_file_chooser_set_preview_widget().
1058 * Return value: the URI for the file to preview, or %NULL if no file
1059 * is selected. Free with g_free().
1062 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1064 GtkFileSystem *file_system;
1066 gchar *result = NULL;
1068 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1070 file_system = _gtk_file_chooser_get_file_system (chooser);
1071 path = _gtk_file_chooser_get_preview_path (chooser);
1074 result = gtk_file_system_path_to_uri (file_system, path);
1075 gtk_file_path_free (path);
1082 * gtk_file_chooser_add_filter:
1083 * @chooser: a #GtkFileChooser
1084 * @filter: a #GtkFileFilter
1086 * Adds @filter to the list of filters that the user can select between.
1087 * When a filter is selected, only files that are passed by that
1088 * filter are displayed.
1091 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1092 GtkFileFilter *filter)
1094 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1096 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1100 * gtk_file_chooser_add_filter:
1101 * @chooser: a #GtkFileChooser
1102 * @filter: a #GtkFileFilter
1104 * Removes @filter from the list of filters that the user can select between.
1107 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1108 GtkFileFilter *filter)
1110 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1112 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1116 * gtk_file_chooser_list_filters:
1117 * @choooser: a #GtkFileChooser
1119 * Lists the current set of user-selectable filters; see
1120 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1122 * Return value: a #GSList containing the current set of
1123 * user selectable filters. The contents of the list are
1124 * owned by GTK+, but you must free the list itself with
1125 * g_slist_free() when you are done with it.
1128 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1130 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1132 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1136 * gtk_file_chooser_set_filter:
1137 * @chooser: a #GtkFileChooser
1138 * @filter: a #GtkFileFilter
1140 * Sets the current filter; only the files that pass the
1141 * filter will be displayed. If the user-selectable list of filters
1142 * is non-empty, then the filter should be one of the filters
1143 * in that list. Setting the current filter when the list of
1144 * filters is empty is useful if you want to restrict the displayed
1145 * set of files without letting the user change it.
1148 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1149 GtkFileFilter *filter)
1151 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1152 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1154 g_object_set (chooser, "filter", filter, NULL);
1158 * gtk_file_chooser_get_filter:
1159 * @chooser: a #GtkFileChooser
1161 * Gets the current filter; see gtk_file_chooser_set_filter().
1163 * Return value: the current filter, or %NULL
1166 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1168 GtkFileFilter *filter;
1170 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1172 g_object_get (chooser, "filter", &filter, NULL);
1173 /* Horrid hack; g_object_get() refs returned objects but
1174 * that contradicts the memory management conventions
1178 g_object_unref (filter);