1 /* GTK - The GIMP Toolkit
2 * gtkfilechooser.c: Abstract interface for file selector GUIs
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include "gtkfilechooser.h"
22 #include "gtkfilechooserprivate.h"
23 #include "gtkfilechooserenums.h"
24 #include "gtkfilesystem.h"
28 static void gtk_file_chooser_class_init (gpointer g_iface);
30 static GtkFilePath *gtk_file_chooser_get_path (GtkFileChooser *chooser);
33 gtk_file_chooser_get_type (void)
35 static GType file_chooser_type = 0;
37 if (!file_chooser_type)
39 static const GTypeInfo file_chooser_info =
41 sizeof (GtkFileChooserIface), /* class_size */
43 NULL, /* base_finalize */
44 (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
47 file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
49 &file_chooser_info, 0);
51 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
54 return file_chooser_type;
58 gtk_file_chooser_class_init (gpointer g_iface)
60 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
62 g_signal_new ("current-folder-changed",
65 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
67 g_cclosure_marshal_VOID__VOID,
69 g_signal_new ("selection-changed",
72 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
74 g_cclosure_marshal_VOID__VOID,
76 g_signal_new ("update-preview",
79 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
81 g_cclosure_marshal_VOID__VOID,
83 g_signal_new ("file-activated",
86 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
88 g_cclosure_marshal_VOID__VOID,
91 g_object_interface_install_property (g_iface,
92 g_param_spec_enum ("action",
94 _("The type of operation that the file selector is performing"),
95 GTK_TYPE_FILE_CHOOSER_ACTION,
96 GTK_FILE_CHOOSER_ACTION_OPEN,
98 g_object_interface_install_property (g_iface,
99 g_param_spec_object ("file-system",
101 _("File system object to use"),
102 GTK_TYPE_FILE_SYSTEM,
103 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
104 g_object_interface_install_property (g_iface,
105 g_param_spec_object ("filter",
107 _("The current filter for selecting which files are displayed"),
108 GTK_TYPE_FILE_FILTER,
110 g_object_interface_install_property (g_iface,
111 g_param_spec_boolean ("folder-mode",
113 _("Whether to select folders rather than files"),
116 g_object_interface_install_property (g_iface,
117 g_param_spec_boolean ("local-only",
119 _("Whether the selected file(s) should be limited to local file: URLs"),
122 g_object_interface_install_property (g_iface,
123 g_param_spec_object ("preview-widget",
125 _("Application supplied widget for custom previews."),
128 g_object_interface_install_property (g_iface,
129 g_param_spec_boolean ("preview-widget-active",
130 _("Preview Widget Active"),
131 _("Whether the application supplied widget for custom previews should be shown."),
134 g_object_interface_install_property (g_iface,
135 g_param_spec_object ("extra-widget",
137 _("Application supplied widget for extra options."),
140 g_object_interface_install_property (g_iface,
141 g_param_spec_boolean ("select-multiple",
142 _("Select Multiple"),
143 _("Whether to allow multiple files to be selected"),
147 g_object_interface_install_property (g_iface,
148 g_param_spec_boolean ("show-hidden",
150 _("Whether the hidden files and folders should be displayed"),
156 * gtk_file_chooser_set_action:
157 * @chooser: a #GtkFileChooser
158 * @action: the action that the file selector is performing
160 * Sets the type of operation that that the chooser is performing; the
161 * user interface is adapted to suit the selected action. For example,
162 * an option to create a new folder might be shown if the action is
163 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
164 * %GTK_FILE_CHOOSER_ACTION_OPEN.
167 gtk_file_chooser_set_action (GtkFileChooser *chooser,
168 GtkFileChooserAction action)
170 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
172 g_object_set (chooser, "action", action, NULL);
176 * gtk_file_chooser_get_action:
177 * @chooser: a #GtkFileChooser
179 * Gets the type of operation that the file chooser is performing; see
180 * gtk_file_chooser_set_action().
182 * Return value: the action that the file selector is performing
185 gtk_file_chooser_get_action (GtkFileChooser *chooser)
187 GtkFileChooserAction action;
189 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
191 g_object_get (chooser, "action", &action, NULL);
197 * gtk_file_chooser_set_folder_mode:
198 * @chooser: a #GtkFileChooser
199 * @folder_mode: %TRUE if the file chooser is used to select folders
202 * Sets whether the file chooser is used to select folders
203 * rather than files. If in folder mode, only folders are displayed
204 * to the use, and not the individual files inside the folders
205 * and the user selects a single folder rather than one or
209 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
210 gboolean folder_mode)
212 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
214 g_object_set (chooser, "folder-mode", folder_mode, NULL);
218 * gtk_file_chooser_get_folder_mode:
219 * @chooser: a #GtkFileChooser
221 * Gets whether the file chooser is used to select folders
222 * rather than files. See gtk_file_chooser_set_folder_mode()
224 * Return value: %TRUE if the file chooser is used to select
225 folders rather than files.
228 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
230 gboolean folder_mode;
232 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
234 g_object_get (chooser, "folder-mode", &folder_mode, NULL);
240 * gtk_file_chooser_set_local_only:
241 * @chooser: a #GtkFileChooser
242 * @local_only: %TRUE if only local files can be selected
244 * Sets whether only local files can be selected in the
245 * file selector. If @local_only is %TRUE (the default),
246 * then the selected file are files are guaranteed to be
247 * accessible through the operating systems native file
248 * file system and therefore the application only
249 * needs to worry about the filename functions in
250 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
251 * rather than the URI functions like
252 * gtk_file_chooser_get_uri(),
255 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
258 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
260 g_object_set (chooser, "local-only", local_only, NULL);
264 * gtk_file_chooser_get_local_only:
265 * @chooser: a #GtkFileChoosre
267 * Gets whether only local files can be selected in the
268 * file selector. See gtk_file_chooser_set_local_only()
270 * Return value: %TRUE if only local files can be selected.
273 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
277 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
279 g_object_get (chooser, "local-only", &local_only, NULL);
285 * gtk_file_chooser_set_select_multiple:
286 * @chooser: a #GtkFileChooser
287 * @select_multiple: %TRUE if multiple files can be selected.
289 * Sets whether multiple files can be selected in the file
290 * selector. If the file selector if in folder mode (see
291 * gtk_file_selector_set_folder_mode()) then only one folder
292 * can be selected, without regard to this setting.
295 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
296 gboolean select_multiple)
298 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
300 g_object_set (chooser, "select-multiple", select_multiple, NULL);
304 * gtk_file_chooser_get_select_multiple:
305 * @chooser: a #GtkFileChooser
307 * Gets whether multiple files can be selected in the file
308 * selector. See gtk_file_chooser_set_select_multiple().
310 * Return value: %TRUE if multiple files can be selected.
313 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
315 gboolean select_multiple;
317 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
319 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
321 return select_multiple;
325 * gtk_file_chooser_get_filename:
326 * @chooser: a #GtkFileChooser
328 * Gets the filename for the currently selected file in
329 * the file selector. If multiple files are selected,
330 * one of the filenames will be returned at random.
332 * Return value: The currently selected filename, or %NULL
333 * if no file is selected, or the selected file can't
334 * be represented with a local filename. Free with g_free().
337 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
339 GtkFileSystem *file_system;
341 gchar *result = NULL;
343 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
345 file_system = _gtk_file_chooser_get_file_system (chooser);
346 path = gtk_file_chooser_get_path (chooser);
349 result = gtk_file_system_path_to_filename (file_system, path);
350 gtk_file_path_free (path);
357 * gtk_file_chooser_set_filename:
358 * @chooser: a #GtkFileChooser
359 * @filename: the filename to set as current
361 * Sets @filename as the current filename for the the file chooser;
362 * If the file name isn't in the current folder of @chooser, then the
363 * current folder of @chooser will be changed to the folder containing
364 * @filename. This is equivalent to a sequence of
365 * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
367 * Note that the file must exist, or nothing will be done except
368 * for the directory change. To pre-enter a filename for the user, as in
369 * a save-as dialog, use gtk_file_chooser_set_current_name()
372 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
373 const gchar *filename)
375 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
377 gtk_file_chooser_unselect_all (chooser);
378 gtk_file_chooser_select_filename (chooser, filename);
382 * gtk_file_chooser_select_filename:
383 * @chooser: a #GtkFileChooser
384 * @filename: the filename to select
386 * Selects a filename. If the file name isn't in the current
387 * folder of @chooser, then the current folder of @chooser will
388 * be changed to the folder containing @filename.
391 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
392 const gchar *filename)
394 GtkFileSystem *file_system;
397 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
398 g_return_if_fail (filename != NULL);
400 file_system = _gtk_file_chooser_get_file_system (chooser);
402 path = gtk_file_system_filename_to_path (file_system, filename);
405 _gtk_file_chooser_select_path (chooser, path);
406 gtk_file_path_free (path);
411 * gtk_file_chooser_unselect_filename:
412 * @chooser: a #GtkFileChooser
413 * @filename: the filename to unselect
415 * Unselects a currently selected filename. If the filename
416 * is not in the current directory, does not exist, or
417 * is otherwise not currently selected, does nothing.
420 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
421 const char *filename)
423 GtkFileSystem *file_system;
426 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
427 g_return_if_fail (filename != NULL);
429 file_system = _gtk_file_chooser_get_file_system (chooser);
431 path = gtk_file_system_filename_to_path (file_system, filename);
434 _gtk_file_chooser_unselect_path (chooser, path);
435 gtk_file_path_free (path);
440 * gtk_file_chooser_get_filenames:
441 * @chooser: a #GtkFileChooser
443 * Lists all the files and subfolders in the current folder of
444 * @chooser. The returned names are full absolute paths. If files
445 * in the current folder cannot be represented as local filenames
446 * they will be ignored. (See gtk_file_chooser_get_uris())
448 * Return value: a #GList containing the filenames of all
449 * files and subfolders in the current folder. Free the returned list
450 * with g_lists_free(), and the filenames with g_free().
453 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
455 GtkFileSystem *file_system;
458 GSList *result = NULL;
460 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
462 file_system = _gtk_file_chooser_get_file_system (chooser);
463 paths = _gtk_file_chooser_get_paths (chooser);
465 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
467 gchar *filename = gtk_file_system_path_to_filename (file_system, tmp_list->data);
469 result = g_slist_prepend (result, filename);
472 gtk_file_paths_free (paths);
474 return g_slist_reverse (result);
478 * gtk_file_chooser_set_current_folder:
479 * @chooser: a #GtkFileChooser
480 * @filename: the full path of the new current folder
482 * Sets the current folder for @chooser from a local filename.
483 * The user will be shown the full contents of the current folder,
484 * plus user interface elements for navigating to other folders.
487 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
488 const gchar *filename)
490 GtkFileSystem *file_system;
493 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
494 g_return_if_fail (filename != NULL);
496 file_system = _gtk_file_chooser_get_file_system (chooser);
498 path = gtk_file_system_filename_to_path (file_system, filename);
501 _gtk_file_chooser_set_current_folder_path (chooser, path);
502 gtk_file_path_free (path);
507 * gtk_file_chooser_get_current_folder:
508 * @chooser: a #GtkFileChooser
510 * Gets the current folder of @chooser as a local filename.
511 * See gtk_file_chooser_set_current_folder().
513 * Return value: the full path of the current folder, or %NULL
514 * if the current path cannot be represented as a local filename.
515 * Free with g_free().
518 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
520 GtkFileSystem *file_system;
524 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
526 file_system = _gtk_file_chooser_get_file_system (chooser);
528 path = _gtk_file_chooser_get_current_folder_path (chooser);
529 filename = gtk_file_system_path_to_filename (file_system, path);
530 gtk_file_path_free (path);
536 * gtk_file_chooser_set_current_name:
537 * @chooser: a #GtkFileChooser
538 * @name: the filename to use, as a UTF-8 string
540 * Sets the current name in the file selector, as if entered
541 * by the user. Note that the name passed in here is a UTF-8
542 * string rather than a filename. This function is meant for
543 * such uses as a suggested name in a "Save As..." dialog.
545 * If you want to preselect a particular existing file, you
546 * should use gtk_file_chooser_set_filename() instead.
549 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
552 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
553 g_return_if_fail (name != NULL);
555 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
559 * gtk_file_chooser_get_uri:
560 * @chooser: a #GtkFileChooser
562 * Gets the URI for the currently selected file in
563 * the file selector. If multiple files are selected,
564 * one of the filenames will be returned at random.
566 * Return value: The currently selected URI, or %NULL
567 * if no file is selected. Free with g_free()
570 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
572 GtkFileSystem *file_system;
574 gchar *result = NULL;
576 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
578 file_system = _gtk_file_chooser_get_file_system (chooser);
579 path = gtk_file_chooser_get_path (chooser);
582 result = gtk_file_system_path_to_uri (file_system, path);
583 gtk_file_path_free (path);
590 * gtk_file_chooser_set_uri:
591 * @chooser: a #GtkFileChooser
592 * @uri: the URI to set as current
594 * Sets the file referred to by @uri as the current file for the the
595 * file chooser; If the file name isn't in the current folder of @chooser,
596 * then the current folder of @chooser will be changed to the folder containing
597 * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
598 * followed by gtk_file_chooser_select_uri().
600 * Note that the file must exist, or nothing will be done except
601 * for the directory change. To pre-enter a filename for the user, as in
602 * a save-as dialog, use gtk_file_chooser_set_current_name()
605 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
608 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
610 gtk_file_chooser_unselect_all (chooser);
611 gtk_file_chooser_select_uri (chooser, uri);
615 * gtk_file_chooser_select_uri:
616 * @chooser: a #GtkFileChooser
617 * @uri: the URI to select
619 * Selects the file to by @uri. If the URI doesn't refer to a
620 * file in the current folder of @chooser, then the current folder of
621 * @chooser will be changed to the folder containing @filename.
624 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
627 GtkFileSystem *file_system;
630 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
631 g_return_if_fail (uri != NULL);
633 file_system = _gtk_file_chooser_get_file_system (chooser);
635 path = gtk_file_system_uri_to_path (file_system, uri);
638 _gtk_file_chooser_select_path (chooser, path);
639 gtk_file_path_free (path);
644 * gtk_file_chooser_unselect_uri:
645 * @chooser: a #GtkFileChooser
646 * @uri: the URI to unselect
648 * Unselects the file referred to by @uri. If the file
649 * is not in the current directory, does not exist, or
650 * is otherwise not currently selected, does nothing.
653 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
656 GtkFileSystem *file_system;
659 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
660 g_return_if_fail (uri != NULL);
662 file_system = _gtk_file_chooser_get_file_system (chooser);
664 path = gtk_file_system_uri_to_path (file_system, uri);
667 _gtk_file_chooser_unselect_path (chooser, path);
668 gtk_file_path_free (path);
673 gtk_file_chooser_select_all (GtkFileChooser *chooser)
675 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
677 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
681 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
684 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
686 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
690 * gtk_file_chooser_get_filenames:
691 * @chooser: a #GtkFileChooser
693 * Lists all the files and subfolders in the current folder of
694 * @chooser. The returned names are full absolute URIs.
696 * Return value: a #GList containing the URIs of all
697 * files and subfolders in the current folder. Free the returned list
698 * with g_lists_free(), and the filenames with g_free().
701 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
703 GtkFileSystem *file_system;
706 GSList *result = NULL;
708 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
710 file_system = _gtk_file_chooser_get_file_system (chooser);
711 paths = _gtk_file_chooser_get_paths (chooser);
713 for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
715 gchar *uri = gtk_file_system_path_to_uri (file_system, tmp_list->data);
717 result = g_slist_prepend (result, uri);
720 gtk_file_paths_free (paths);
722 return g_slist_reverse (result);
726 * gtk_file_chooser_set_current_folder_uri:
727 * @chooser: a #GtkFileChooser
728 * @uri: the URI for the new current folder
730 * Sets the current folder for @chooser from an URI.
731 * The user will be shown the full contents of the current folder,
732 * plus user interface elements for navigating to other folders.
735 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
738 GtkFileSystem *file_system;
741 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
742 g_return_if_fail (uri != NULL);
744 file_system = _gtk_file_chooser_get_file_system (chooser);
746 path = gtk_file_system_uri_to_path (file_system, uri);
749 _gtk_file_chooser_set_current_folder_path (chooser, path);
750 gtk_file_path_free (path);
755 * gtk_file_chooser_get_current_folder_uri:
756 * @chooser: a #GtkFileChooser
758 * Gets the current folder of @chooser as an URI.
759 * See gtk_file_chooser_set_current_folder_uri().
761 * Return value: the URI for the current folder.
762 * Free with g_free().
765 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
767 GtkFileSystem *file_system;
771 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
773 file_system = _gtk_file_chooser_get_file_system (chooser);
775 path = _gtk_file_chooser_get_current_folder_path (chooser);
776 uri = gtk_file_system_path_to_uri (file_system, path);
777 gtk_file_path_free (path);
783 * _gtk_file_chooser_set_current_folder_path:
784 * @chooser: a #GtkFileChooser
785 * @path: the #GtkFilePath for the new folder
787 * Sets the current folder for @chooser from a #GtkFilePath.
788 * Internal function, see gtk_file_chooser_set_current_folder_uri().
791 _gtk_file_chooser_set_current_folder_path (GtkFileChooser *chooser,
792 const GtkFilePath *path)
794 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
795 g_return_if_fail (path != NULL);
797 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
801 * _gtk_file_chooser_get_current_folder_path:
802 * @chooser: a #GtkFileChooser
804 * Gets the current folder of @chooser as #GtkFilePath.
805 * See gtk_file_chooser_get_current_folder_uri().
807 * Return value: the #GtkFilePath for the current folder.
808 * Fre with gtk_file_path_free ().
811 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
813 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
815 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
819 * _gtk_file_chooser_select_path:
820 * @chooser: a #GtkFileChooser
821 * @path: the path to select
823 * Selects the file referred to by @path. An internal function. See
824 * _gtk_file_chooser_select_uri().
827 _gtk_file_chooser_select_path (GtkFileChooser *chooser,
828 const GtkFilePath *path)
830 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
832 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
836 * _gtk_file_chooser_unselect_path:
837 * @chooser: a #GtkFileChooser
838 * @path: the filename to path
840 * Unselects the file referred to by @path. An internal
841 * function. See _gtk_file_chooser_unselect_uri().
844 _gtk_file_chooser_unselect_path (GtkFileChooser *chooser,
845 const GtkFilePath *path)
847 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
849 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
853 * _gtk_file_chooser_get_paths:
854 * @chooser: a #GtkFileChooser
856 * Lists all the files and subfolders in the current folder of
857 * @chooser as #GtkFilePath. An internal function, see
858 * gtk_file_chooser_get_uris().
860 * Return value: a #GList containing a #GtkFilePath for each
861 * files and subfolder in the current folder. Free the returned list
862 * with g_lists_free(), and the paths with gtk_file_path_free().
865 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
867 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
869 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
873 gtk_file_chooser_get_path (GtkFileChooser *chooser)
876 GtkFilePath *result = NULL;
878 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
880 list = _gtk_file_chooser_get_paths (chooser);
884 list = g_slist_delete_link (list, list);
885 gtk_file_paths_free (list);
892 * _gtk_file_chooser_get_file_system:
893 * @chooser: a #GtkFileChooser
895 * Gets the #GtkFileSystem of @chooser; this is an internal
896 * implementation detail, used for conversion between paths
897 * and filenames and URIs.
899 * Return value: the file system for @chooser.
902 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
904 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
906 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
912 * gtk_file_chooser_set_preview_widget:
913 * @chooser: a #GtkFileChooser
914 * @preview_widget: widget for displaying preview.
916 * Sets an application-supplied widget to use to display a custom preview
917 * of the currently selected file. To implement a preview, after setting the
918 * preview widget, you connect to the ::selection-changed
919 * signal, and call gtk_file_chooser_get_preview_filename() or
920 * gtk_file_chooser_get_preview_uri() on each change. If you can
921 * display a preview of the new file, update your widget
922 * and set the preview active using gtk_file_chooser_set_preview_widget_active().
923 * Otherwise, set the preview inactive.
925 * When there is no application-supplied preview widget, or the
926 * application-supplied preview widget is not active, the file chooser
927 * may display an internally generated preview of the current file or
928 * it may display no preview at all.
931 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
932 GtkWidget *preview_widget)
934 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
936 g_object_set (chooser, "preview-widget", preview_widget, NULL);
940 * gtk_file_chooser_get_preview_widget:
941 * @chooser: a #GtkFileChooser
943 * Gets the current preview widget; see
944 * gtk_file_chooser_set_preview_widget().
946 * Return value: the current preview widget, or %NULL
949 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
951 GtkWidget *preview_widget;
953 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
955 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
957 /* Horrid hack; g_object_get() refs returned objects but
958 * that contradicts the memory management conventions
962 g_object_unref (preview_widget);
964 return preview_widget;
968 * gtk_file_chooser_set_preview_widget_active:
969 * @chooser: a #GtkFileChooser
970 * @active: whether to display the user-specified preview widget
972 * Sets whether the preview widget set by
973 * gtk_file_chooser_set_preview_widget_active() should be shown for the
974 * current filename. When @active is set to false, the file chooser
975 * may display an internally generated preview of the current file
976 * or it may display no preview at all. See
977 * gtk_file_chooser_set_preview_widget() for more details.
980 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
983 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
985 g_object_set (chooser, "preview-widget-active", active, NULL);
989 * gtk_file_chooser_get_preview_widget_active:
990 * @chooser: a #GtkFileChooser
992 * Gets whether the preview widget set by
993 * gtk_file_chooser_set_preview_widget_active() should be shown for the
994 * current filename. See gtk_file_chooser_set_preview_widget_active().
996 * Return value: %TRUE if the preview widget is active for the
1000 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1004 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1006 g_object_get (chooser, "preview-widget-active", &active, NULL);
1012 * gtk_file_chooser_get_preview_filename:
1013 * @chooser: a #GtkFileChooser
1015 * Gets the filename that should be previewed in a custom preview
1016 * Internal function, see gtk_file_chooser_get_preview_uri().n
1018 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1019 * is selected. Free with gtk_file_path_free().
1022 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1024 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1026 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1030 * gtk_file_chooser_get_preview_filename:
1031 * @chooser: a #GtkFileChooser
1033 * Gets the filename that should be previewed in a custom preview
1034 * widget. See gtk_file_chooser_set_preview_widget().
1036 * Return value: the filename to preview, or %NULL if no file
1037 * is selected, or if the selected file cannot be represented
1038 * as a local filename. Free with g_free()
1041 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1043 GtkFileSystem *file_system;
1045 gchar *result = NULL;
1047 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1049 file_system = _gtk_file_chooser_get_file_system (chooser);
1050 path = _gtk_file_chooser_get_preview_path (chooser);
1053 result = gtk_file_system_path_to_filename (file_system, path);
1054 gtk_file_path_free (path);
1061 * gtk_file_chooser_get_preview_filename:
1062 * @chooser: a #GtkFileChooser
1064 * Gets the URI that should be previewed in a custom preview
1065 * widget. See gtk_file_chooser_set_preview_widget().
1067 * Return value: the URI for the file to preview, or %NULL if no file
1068 * is selected. Free with g_free().
1071 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1073 GtkFileSystem *file_system;
1075 gchar *result = NULL;
1077 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1079 file_system = _gtk_file_chooser_get_file_system (chooser);
1080 path = _gtk_file_chooser_get_preview_path (chooser);
1083 result = gtk_file_system_path_to_uri (file_system, path);
1084 gtk_file_path_free (path);
1091 * gtk_file_chooser_set_extra_widget:
1092 * @chooser: a #GtkFileChooser
1093 * @extra_widget: widget for extra options
1095 * Sets an application-supplied widget to provide extra options to the user.
1098 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1099 GtkWidget *extra_widget)
1101 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1103 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1107 * gtk_file_chooser_get_extra_widget:
1108 * @chooser: a #GtkFileChooser
1110 * Gets the current preview widget; see
1111 * gtk_file_chooser_set_extra_widget().
1113 * Return value: the current extra widget, or %NULL
1116 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1118 GtkWidget *extra_widget;
1120 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1122 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1124 /* Horrid hack; g_object_get() refs returned objects but
1125 * that contradicts the memory management conventions
1129 g_object_unref (extra_widget);
1131 return extra_widget;
1135 * gtk_file_chooser_add_filter:
1136 * @chooser: a #GtkFileChooser
1137 * @filter: a #GtkFileFilter
1139 * Adds @filter to the list of filters that the user can select between.
1140 * When a filter is selected, only files that are passed by that
1141 * filter are displayed.
1144 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1145 GtkFileFilter *filter)
1147 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1149 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1153 * gtk_file_chooser_add_filter:
1154 * @chooser: a #GtkFileChooser
1155 * @filter: a #GtkFileFilter
1157 * Removes @filter from the list of filters that the user can select between.
1160 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1161 GtkFileFilter *filter)
1163 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1165 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1169 * gtk_file_chooser_list_filters:
1170 * @choooser: a #GtkFileChooser
1172 * Lists the current set of user-selectable filters; see
1173 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1175 * Return value: a #GSList containing the current set of
1176 * user selectable filters. The contents of the list are
1177 * owned by GTK+, but you must free the list itself with
1178 * g_slist_free() when you are done with it.
1181 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1183 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1185 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1189 * gtk_file_chooser_set_filter:
1190 * @chooser: a #GtkFileChooser
1191 * @filter: a #GtkFileFilter
1193 * Sets the current filter; only the files that pass the
1194 * filter will be displayed. If the user-selectable list of filters
1195 * is non-empty, then the filter should be one of the filters
1196 * in that list. Setting the current filter when the list of
1197 * filters is empty is useful if you want to restrict the displayed
1198 * set of files without letting the user change it.
1201 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1202 GtkFileFilter *filter)
1204 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1205 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1207 g_object_set (chooser, "filter", filter, NULL);
1211 * gtk_file_chooser_get_filter:
1212 * @chooser: a #GtkFileChooser
1214 * Gets the current filter; see gtk_file_chooser_set_filter().
1216 * Return value: the current filter, or %NULL
1219 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1221 GtkFileFilter *filter;
1223 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1225 g_object_get (chooser, "filter", &filter, NULL);
1226 /* Horrid hack; g_object_get() refs returned objects but
1227 * that contradicts the memory management conventions
1231 g_object_unref (filter);