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 selected files and subfolders in the current folder of
444 * @chooser. The returned names are full absolute paths. If files in the current
445 * folder cannot be represented as local filenames they will be ignored. (See
446 * gtk_file_chooser_get_uris())
448 * Return value: a #GSList containing the filenames of all selected
449 * files and subfolders in the current folder. Free the returned list
450 * with g_slist_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_uris:
691 * @chooser: a #GtkFileChooser
693 * Lists all the selected files and subfolders in the current folder of
694 * @chooser. The returned names are full absolute URIs.
696 * Return value: a #GSList containing the URIs of all selected
697 * files and subfolders in the current folder. Free the returned list
698 * with g_slist_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 selected files and subfolders in the current folder of @chooser
857 * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
859 * Return value: a #GSList containing a #GtkFilePath for each selected
860 * file and subfolder in the current folder. Free the returned list
861 * with g_slist_free(), and the paths with gtk_file_path_free().
864 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
866 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
868 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
872 gtk_file_chooser_get_path (GtkFileChooser *chooser)
875 GtkFilePath *result = NULL;
877 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
879 list = _gtk_file_chooser_get_paths (chooser);
883 list = g_slist_delete_link (list, list);
884 gtk_file_paths_free (list);
891 * _gtk_file_chooser_get_file_system:
892 * @chooser: a #GtkFileChooser
894 * Gets the #GtkFileSystem of @chooser; this is an internal
895 * implementation detail, used for conversion between paths
896 * and filenames and URIs.
898 * Return value: the file system for @chooser.
901 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
903 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
905 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
911 * gtk_file_chooser_set_preview_widget:
912 * @chooser: a #GtkFileChooser
913 * @preview_widget: widget for displaying preview.
915 * Sets an application-supplied widget to use to display a custom preview
916 * of the currently selected file. To implement a preview, after setting the
917 * preview widget, you connect to the ::selection-changed
918 * signal, and call gtk_file_chooser_get_preview_filename() or
919 * gtk_file_chooser_get_preview_uri() on each change. If you can
920 * display a preview of the new file, update your widget
921 * and set the preview active using gtk_file_chooser_set_preview_widget_active().
922 * Otherwise, set the preview inactive.
924 * When there is no application-supplied preview widget, or the
925 * application-supplied preview widget is not active, the file chooser
926 * may display an internally generated preview of the current file or
927 * it may display no preview at all.
930 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
931 GtkWidget *preview_widget)
933 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
935 g_object_set (chooser, "preview-widget", preview_widget, NULL);
939 * gtk_file_chooser_get_preview_widget:
940 * @chooser: a #GtkFileChooser
942 * Gets the current preview widget; see
943 * gtk_file_chooser_set_preview_widget().
945 * Return value: the current preview widget, or %NULL
948 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
950 GtkWidget *preview_widget;
952 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
954 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
956 /* Horrid hack; g_object_get() refs returned objects but
957 * that contradicts the memory management conventions
961 g_object_unref (preview_widget);
963 return preview_widget;
967 * gtk_file_chooser_set_preview_widget_active:
968 * @chooser: a #GtkFileChooser
969 * @active: whether to display the user-specified preview widget
971 * Sets whether the preview widget set by
972 * gtk_file_chooser_set_preview_widget_active() should be shown for the
973 * current filename. When @active is set to false, the file chooser
974 * may display an internally generated preview of the current file
975 * or it may display no preview at all. See
976 * gtk_file_chooser_set_preview_widget() for more details.
979 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
982 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
984 g_object_set (chooser, "preview-widget-active", active, NULL);
988 * gtk_file_chooser_get_preview_widget_active:
989 * @chooser: a #GtkFileChooser
991 * Gets whether the preview widget set by
992 * gtk_file_chooser_set_preview_widget_active() should be shown for the
993 * current filename. See gtk_file_chooser_set_preview_widget_active().
995 * Return value: %TRUE if the preview widget is active for the
999 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1003 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1005 g_object_get (chooser, "preview-widget-active", &active, NULL);
1011 * gtk_file_chooser_get_preview_filename:
1012 * @chooser: a #GtkFileChooser
1014 * Gets the filename that should be previewed in a custom preview
1015 * Internal function, see gtk_file_chooser_get_preview_uri().n
1017 * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1018 * is selected. Free with gtk_file_path_free().
1021 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1023 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1025 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1029 * gtk_file_chooser_get_preview_filename:
1030 * @chooser: a #GtkFileChooser
1032 * Gets the filename that should be previewed in a custom preview
1033 * widget. See gtk_file_chooser_set_preview_widget().
1035 * Return value: the filename to preview, or %NULL if no file
1036 * is selected, or if the selected file cannot be represented
1037 * as a local filename. Free with g_free()
1040 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1042 GtkFileSystem *file_system;
1044 gchar *result = NULL;
1046 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1048 file_system = _gtk_file_chooser_get_file_system (chooser);
1049 path = _gtk_file_chooser_get_preview_path (chooser);
1052 result = gtk_file_system_path_to_filename (file_system, path);
1053 gtk_file_path_free (path);
1060 * gtk_file_chooser_get_preview_filename:
1061 * @chooser: a #GtkFileChooser
1063 * Gets the URI that should be previewed in a custom preview
1064 * widget. See gtk_file_chooser_set_preview_widget().
1066 * Return value: the URI for the file to preview, or %NULL if no file
1067 * is selected. Free with g_free().
1070 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1072 GtkFileSystem *file_system;
1074 gchar *result = NULL;
1076 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1078 file_system = _gtk_file_chooser_get_file_system (chooser);
1079 path = _gtk_file_chooser_get_preview_path (chooser);
1082 result = gtk_file_system_path_to_uri (file_system, path);
1083 gtk_file_path_free (path);
1090 * gtk_file_chooser_set_extra_widget:
1091 * @chooser: a #GtkFileChooser
1092 * @extra_widget: widget for extra options
1094 * Sets an application-supplied widget to provide extra options to the user.
1097 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1098 GtkWidget *extra_widget)
1100 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1102 g_object_set (chooser, "extra-widget", extra_widget, NULL);
1106 * gtk_file_chooser_get_extra_widget:
1107 * @chooser: a #GtkFileChooser
1109 * Gets the current preview widget; see
1110 * gtk_file_chooser_set_extra_widget().
1112 * Return value: the current extra widget, or %NULL
1115 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1117 GtkWidget *extra_widget;
1119 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1121 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1123 /* Horrid hack; g_object_get() refs returned objects but
1124 * that contradicts the memory management conventions
1128 g_object_unref (extra_widget);
1130 return extra_widget;
1134 * gtk_file_chooser_add_filter:
1135 * @chooser: a #GtkFileChooser
1136 * @filter: a #GtkFileFilter
1138 * Adds @filter to the list of filters that the user can select between.
1139 * When a filter is selected, only files that are passed by that
1140 * filter are displayed.
1143 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1144 GtkFileFilter *filter)
1146 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1148 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1152 * gtk_file_chooser_add_filter:
1153 * @chooser: a #GtkFileChooser
1154 * @filter: a #GtkFileFilter
1156 * Removes @filter from the list of filters that the user can select between.
1159 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1160 GtkFileFilter *filter)
1162 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1164 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1168 * gtk_file_chooser_list_filters:
1169 * @choooser: a #GtkFileChooser
1171 * Lists the current set of user-selectable filters; see
1172 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1174 * Return value: a #GSList containing the current set of
1175 * user selectable filters. The contents of the list are
1176 * owned by GTK+, but you must free the list itself with
1177 * g_slist_free() when you are done with it.
1180 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
1182 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1184 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1188 * gtk_file_chooser_set_filter:
1189 * @chooser: a #GtkFileChooser
1190 * @filter: a #GtkFileFilter
1192 * Sets the current filter; only the files that pass the
1193 * filter will be displayed. If the user-selectable list of filters
1194 * is non-empty, then the filter should be one of the filters
1195 * in that list. Setting the current filter when the list of
1196 * filters is empty is useful if you want to restrict the displayed
1197 * set of files without letting the user change it.
1200 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1201 GtkFileFilter *filter)
1203 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1204 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1206 g_object_set (chooser, "filter", filter, NULL);
1210 * gtk_file_chooser_get_filter:
1211 * @chooser: a #GtkFileChooser
1213 * Gets the current filter; see gtk_file_chooser_set_filter().
1215 * Return value: the current filter, or %NULL
1218 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1220 GtkFileFilter *filter;
1222 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1224 g_object_get (chooser, "filter", &filter, NULL);
1225 /* Horrid hack; g_object_get() refs returned objects but
1226 * that contradicts the memory management conventions
1230 g_object_unref (filter);
1235 /* gtk_file_chooser_set_shortcut_folders:
1236 * @chooser: a #GtkFileChooser
1237 * @shortcut_folders: a list of #GtkFilePath, or NULL if you want to clear the
1238 * current list of shortcut folders.
1240 * Sets the list of shortcut folders to be shown in a file chooser. Note that
1241 * these do not get saved, as they are provided by the application. For
1242 * example, you can use this to add a "/usr/share/myapp/Clipart" folder to the
1246 gtk_file_chooser_set_shortcut_folders (GtkFileChooser *chooser,
1247 GSList *shortcut_folders)
1249 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1251 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_shortcut_folders (chooser, shortcut_folders);
1255 * gtk_file_chooser_list_shortcut_folders:
1256 * @chooser: a #GtkFileChooser
1258 * Queries the list of shortcut folders in the file chooser, as set by
1259 * gtk_file_chooser_set_shortcut_folders().
1261 * Return value: A list of #GtkFilePath, or NULL if there are no shortcut
1262 * folders. You should use gtk_file_paths_free() to free this list.
1265 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1267 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1269 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);