]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooser.c
Added documentation to all the signals.
[~andy/gtk] / gtk / gtkfilechooser.c
1 /* GTK - The GIMP Toolkit
2  * gtkfilechooser.c: Abstract interface for file selector GUIs
3  * Copyright (C) 2003, Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include <config.h>
22 #include "gtkfilechooser.h"
23 #include "gtkfilechooserprivate.h"
24 #include "gtkfilesystem.h"
25 #include "gtkintl.h"
26 #include "gtktypebuiltins.h"
27
28 static void gtk_file_chooser_class_init (gpointer g_iface);
29
30 static GtkFilePath *gtk_file_chooser_get_path         (GtkFileChooser *chooser);
31
32 GType
33 gtk_file_chooser_get_type (void)
34 {
35   static GType file_chooser_type = 0;
36
37   if (!file_chooser_type)
38     {
39       static const GTypeInfo file_chooser_info =
40       {
41         sizeof (GtkFileChooserIface),  /* class_size */
42         NULL,                          /* base_init */
43         NULL,                          /* base_finalize */
44         (GClassInitFunc)gtk_file_chooser_class_init, /* class_init */
45       };
46
47       file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
48                                                   "GtkFileChooser",
49                                                   &file_chooser_info, 0);
50
51       g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
52     }
53
54   return file_chooser_type;
55 }
56
57 static void
58 gtk_file_chooser_class_init (gpointer g_iface)
59 {
60   GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
61
62   /**
63    * GtkFileChooser::current-folder-changed
64    * @chooser: the object which received the signal.
65    *
66    * This signal is emitted when the current folder in a #GtkFileChooser
67    * changes.  This can happen due to the user performing some action that
68    * changes folders, such as selecting a bookmark or visiting a folder on the
69    * file list.  It can also happen as a result of calling a function to
70    * explicitly change the current folder in a file chooser.
71    *
72    * Normally you do not need to connect to this signal, unless you need to keep
73    * track of which folder a file chooser is showing.
74    *
75    * See also:  gtk_file_chooser_set_current_folder(),
76    * gtk_file_chooser_get_current_folder(),
77    * gtk_file_chooser_set_current_folder_uri(),
78    * gtk_file_chooser_get_current_folder_uri().
79    */
80   g_signal_new ("current-folder-changed",
81                 iface_type,
82                 G_SIGNAL_RUN_LAST,
83                 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
84                 NULL, NULL,
85                 g_cclosure_marshal_VOID__VOID,
86                 G_TYPE_NONE, 0);
87
88   /**
89    * GtkFileChooser::selection-changed
90    * @chooser: the object which received the signal.
91    *
92    * This signal is emitted when there is a change in the set of selected files
93    * in a #GtkFileChooser.  This can happen when the user modifies the selection
94    * with the mouse or the keyboard, or when explicitly calling functions to
95    * change the selection.
96    *
97    * Normally you do not need to connect to this signal, as it is easier to wait
98    * for the file chooser to finish running, and then to get the list of
99    * selected files using the functions mentioned below.
100    *
101    * See also: gtk_file_chooser_select_filename(),
102    * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
103    * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
104    * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
105    * gtk_file_chooser_get_uris().
106    */
107   g_signal_new ("selection-changed",
108                 iface_type,
109                 G_SIGNAL_RUN_LAST,
110                 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
111                 NULL, NULL,
112                 g_cclosure_marshal_VOID__VOID,
113                 G_TYPE_NONE, 0);
114
115   /**
116    * GtkFileChooser::update-preview
117    * @chooser: the object which received the signal.
118    *
119    * This signal is emitted when the preview in a file chooser should be
120    * regenerated.  For example, this can happen when the currently selected file
121    * changes.  You should use this signal if you want your file chooser to have
122    * a preview widget.
123    *
124    * Once you have installed a preview widget with
125    * gtk_file_chooser_set_preview_widget(), you should update it when this
126    * signal is emitted.  You can use the functions
127    * gtk_file_chooser_get_preview_filename() or
128    * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
129    * Your widget may not be able to preview all kinds of files; your callback
130    * must call gtk_file_chooser_set_preview_wiget_active() to inform the file
131    * chooser about whether the preview was generated successfully or not.
132    *
133    * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
134    *
135    * See also: gtk_file_chooser_set_preview_widget(),
136    * gtk_file_chooser_set_preview_widget_active(),
137    * gtk_file_chooser_set_use_preview_label(),
138    * gtk_file_chooser_get_preview_filename(),
139    * gtk_file_chooser_get_preview_uri().
140    */
141   g_signal_new ("update-preview",
142                 iface_type,
143                 G_SIGNAL_RUN_LAST,
144                 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
145                 NULL, NULL,
146                 g_cclosure_marshal_VOID__VOID,
147                 G_TYPE_NONE, 0);
148
149   /**
150    * GtkFileChooser::file-activated
151    * @chooser: the object which received the signal.
152    *
153    * This signal is emitted when the user "activates" a file in the file
154    * chooser.  This can happen by double-clicking on a file in the file list, or
155    * by pressing <keycap>Enter</keycap>.
156    *
157    * Normally you do not need to connect to this signal.  It is used internally
158    * by #GtkFileChooserDialog to know when to activate the default button in the
159    * dialog.
160    *
161    * See also: gtk_file_chooser_get_filename(),
162    * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
163    * gtk_file_chooser_get_uris().
164    */
165   g_signal_new ("file-activated",
166                 iface_type,
167                 G_SIGNAL_RUN_LAST,
168                 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
169                 NULL, NULL,
170                 g_cclosure_marshal_VOID__VOID,
171                 G_TYPE_NONE, 0);
172   
173   g_object_interface_install_property (g_iface,
174                                        g_param_spec_enum ("action",
175                                                           P_("Action"),
176                                                           P_("The type of operation that the file selector is performing"),
177                                                           GTK_TYPE_FILE_CHOOSER_ACTION,
178                                                           GTK_FILE_CHOOSER_ACTION_OPEN,
179                                                           G_PARAM_READWRITE));
180   g_object_interface_install_property (g_iface,
181                                        g_param_spec_string ("file-system-backend",
182                                                             P_("File System Backend"),
183                                                             P_("Name of file system backend to use"),
184                                                             NULL, 
185                                                             G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
186   g_object_interface_install_property (g_iface,
187                                        g_param_spec_object ("filter",
188                                                             P_("Filter"),
189                                                             P_("The current filter for selecting which files are displayed"),
190                                                             GTK_TYPE_FILE_FILTER,
191                                                             G_PARAM_READWRITE));
192   g_object_interface_install_property (g_iface,
193                                        g_param_spec_boolean ("local-only",
194                                                              P_("Local Only"),
195                                                              P_("Whether the selected file(s) should be limited to local file: URLs"),
196                                                              TRUE,
197                                                              G_PARAM_READWRITE));
198   g_object_interface_install_property (g_iface,
199                                        g_param_spec_object ("preview-widget",
200                                                             P_("Preview widget"),
201                                                             P_("Application supplied widget for custom previews."),
202                                                             GTK_TYPE_WIDGET,
203                                                             G_PARAM_READWRITE));
204   g_object_interface_install_property (g_iface,
205                                        g_param_spec_boolean ("preview-widget-active",
206                                                              P_("Preview Widget Active"),
207                                                              P_("Whether the application supplied widget for custom previews should be shown."),
208                                                              TRUE,
209                                                              G_PARAM_READWRITE));
210   g_object_interface_install_property (g_iface,
211                                        g_param_spec_boolean ("use-preview-label",
212                                                              P_("Use Preview Label"),
213                                                              P_("Whether to display a stock label with the name of the previewed file."),
214                                                              TRUE,
215                                                              G_PARAM_READWRITE));
216   g_object_interface_install_property (g_iface,
217                                        g_param_spec_object ("extra-widget",
218                                                             P_("Extra widget"),
219                                                             P_("Application supplied widget for extra options."),
220                                                             GTK_TYPE_WIDGET,
221                                                             G_PARAM_READWRITE));
222   g_object_interface_install_property (g_iface,
223                                        g_param_spec_boolean ("select-multiple",
224                                                              P_("Select Multiple"),
225                                                              P_("Whether to allow multiple files to be selected"),
226                                                              FALSE,
227                                                              G_PARAM_READWRITE));
228   
229   g_object_interface_install_property (g_iface,
230                                        g_param_spec_boolean ("show-hidden",
231                                                              P_("Show Hidden"),
232                                                              P_("Whether the hidden files and folders should be displayed"),
233                                                              FALSE,
234                                                              G_PARAM_READWRITE));
235 }
236
237 /**
238  * gtk_file_chooser_error_quark:
239  *
240  * Registers an error quark for #GtkFileChooser if necessary.
241  * 
242  * Return value: The error quark used for #GtkFileChooser errors.
243  *
244  * Since: 2.4
245  **/
246 GQuark
247 gtk_file_chooser_error_quark (void)
248 {
249   static GQuark quark = 0;
250   if (quark == 0)
251     quark = g_quark_from_static_string ("gtk-file-chooser-error-quark");
252   return quark;
253 }
254
255 /**
256  * gtk_file_chooser_set_action:
257  * @chooser: a #GtkFileChooser
258  * @action: the action that the file selector is performing
259  * 
260  * Sets the type of operation that that the chooser is performing; the
261  * user interface is adapted to suit the selected action. For example,
262  * an option to create a new folder might be shown if the action is
263  * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
264  * %GTK_FILE_CHOOSER_ACTION_OPEN.
265  *
266  * Since: 2.4
267  **/
268 void
269 gtk_file_chooser_set_action (GtkFileChooser       *chooser,
270                              GtkFileChooserAction  action)
271 {
272   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
273
274   g_object_set (chooser, "action", action, NULL);
275 }
276
277 /**
278  * gtk_file_chooser_get_action:
279  * @chooser: a #GtkFileChooser
280  * 
281  * Gets the type of operation that the file chooser is performing; see
282  * gtk_file_chooser_set_action().
283  * 
284  * Return value: the action that the file selector is performing
285  *
286  * Since: 2.4
287  **/
288 GtkFileChooserAction
289 gtk_file_chooser_get_action (GtkFileChooser *chooser)
290 {
291   GtkFileChooserAction action;
292   
293   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
294
295   g_object_get (chooser, "action", &action, NULL);
296
297   return action;
298 }
299
300 /**
301  * gtk_file_chooser_set_local_only:
302  * @chooser: a #GtkFileChooser
303  * @local_only: %TRUE if only local files can be selected
304  * 
305  * Sets whether only local files can be selected in the
306  * file selector. If @local_only is %TRUE (the default),
307  * then the selected file are files are guaranteed to be
308  * accessible through the operating systems native file
309  * file system and therefore the application only
310  * needs to worry about the filename functions in
311  * #GtkFileChooser, like gtk_file_chooser_get_filename(),
312  * rather than the URI functions like
313  * gtk_file_chooser_get_uri(),
314  *
315  * Since: 2.4
316  **/
317 void
318 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
319                                  gboolean        local_only)
320 {
321   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
322
323   g_object_set (chooser, "local-only", local_only, NULL);
324 }
325
326 /**
327  * gtk_file_chooser_get_local_only:
328  * @chooser: a #GtkFileChoosre
329  * 
330  * Gets whether only local files can be selected in the
331  * file selector. See gtk_file_chooser_set_local_only()
332  * 
333  * Return value: %TRUE if only local files can be selected.
334  *
335  * Since: 2.4
336  **/
337 gboolean
338 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
339 {
340   gboolean local_only;
341   
342   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
343
344   g_object_get (chooser, "local-only", &local_only, NULL);
345
346   return local_only;
347 }
348
349 /**
350  * gtk_file_chooser_set_select_multiple:
351  * @chooser: a #GtkFileChooser
352  * @select_multiple: %TRUE if multiple files can be selected.
353  * 
354  * Sets whether multiple files can be selected in the file selector.  This is
355  * only relevant if the action is set to be GTK_FILE_CHOOSER_ACTION_OPEN or
356  * GTK_FILE_CHOOSER_ACTION_SAVE.  It cannot be set with either of the folder
357  * actions.
358  *
359  * Since: 2.4
360  **/
361 void
362 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
363                                       gboolean        select_multiple)
364 {
365   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
366
367   g_object_set (chooser, "select-multiple", select_multiple, NULL);
368 }
369
370 /**
371  * gtk_file_chooser_get_select_multiple:
372  * @chooser: a #GtkFileChooser
373  * 
374  * Gets whether multiple files can be selected in the file
375  * selector. See gtk_file_chooser_set_select_multiple().
376  * 
377  * Return value: %TRUE if multiple files can be selected.
378  *
379  * Since: 2.4
380  **/
381 gboolean
382 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
383 {
384   gboolean select_multiple;
385   
386   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
387
388   g_object_get (chooser, "select-multiple", &select_multiple, NULL);
389
390   return select_multiple;
391 }
392
393 /**
394  * gtk_file_chooser_get_filename:
395  * @chooser: a #GtkFileChooser
396  * 
397  * Gets the filename for the currently selected file in
398  * the file selector. If multiple files are selected,
399  * one of the filenames will be returned at random.
400  *
401  * If the file chooser is in folder mode, this function returns the selected
402  * folder.
403  * 
404  * Return value: The currently selected filename, or %NULL
405  *  if no file is selected, or the selected file can't
406  *  be represented with a local filename. Free with g_free().
407  *
408  * Since: 2.4
409  **/
410 gchar *
411 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
412 {
413   GtkFileSystem *file_system;
414   GtkFilePath *path;
415   gchar *result = NULL;
416   
417   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
418
419   file_system = _gtk_file_chooser_get_file_system (chooser);
420   path = gtk_file_chooser_get_path (chooser);
421   if (path)
422     {
423       result = gtk_file_system_path_to_filename (file_system, path);
424       gtk_file_path_free (path);
425     }
426
427   return result;
428 }
429
430 /**
431  * gtk_file_chooser_set_filename:
432  * @chooser: a #GtkFileChooser
433  * @filename: the filename to set as current
434  * 
435  * Sets @filename as the current filename for the the file chooser;
436  * If the file name isn't in the current folder of @chooser, then the
437  * current folder of @chooser will be changed to the folder containing
438  * @filename. This is equivalent to a sequence of
439  * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
440  *
441  * Note that the file must exist, or nothing will be done except
442  * for the directory change. To pre-enter a filename for the user, as in
443  * a save-as dialog, use gtk_file_chooser_set_current_name()
444  *
445  * Return value: %TRUE if both the folder could be changed and the file was
446  * selected successfully, %FALSE otherwise.
447  *
448  * Since: 2.4
449  **/
450 gboolean
451 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
452                                const gchar    *filename)
453 {
454   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
455
456   gtk_file_chooser_unselect_all (chooser);
457   return gtk_file_chooser_select_filename (chooser, filename);
458 }
459
460 /**
461  * gtk_file_chooser_select_filename:
462  * @chooser: a #GtkFileChooser
463  * @filename: the filename to select
464  * 
465  * Selects a filename. If the file name isn't in the current
466  * folder of @chooser, then the current folder of @chooser will
467  * be changed to the folder containing @filename.
468  *
469  * Return value: %TRUE if both the folder could be changed and the file was
470  * selected successfully, %FALSE otherwise.
471  *
472  * Since: 2.4
473  **/
474 gboolean
475 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
476                                   const gchar    *filename)
477 {
478   GtkFileSystem *file_system;
479   GtkFilePath *path;
480   gboolean result;
481   
482   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
483   g_return_val_if_fail (filename != NULL, FALSE);
484
485   file_system = _gtk_file_chooser_get_file_system (chooser);
486
487   path = gtk_file_system_filename_to_path (file_system, filename);
488   if (path)
489     {
490       result = _gtk_file_chooser_select_path (chooser, path, NULL);
491       gtk_file_path_free (path);
492     }
493   else
494     result = FALSE;
495
496   return result;
497 }
498
499 /**
500  * gtk_file_chooser_unselect_filename:
501  * @chooser: a #GtkFileChooser
502  * @filename: the filename to unselect
503  * 
504  * Unselects a currently selected filename. If the filename
505  * is not in the current directory, does not exist, or
506  * is otherwise not currently selected, does nothing.
507  *
508  * Since: 2.4
509  **/
510 void
511 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
512                                     const char     *filename)
513 {
514   GtkFileSystem *file_system;
515   GtkFilePath *path;
516   
517   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
518   g_return_if_fail (filename != NULL);
519
520   file_system = _gtk_file_chooser_get_file_system (chooser);
521
522   path = gtk_file_system_filename_to_path (file_system, filename);
523   if (path)
524     {
525       _gtk_file_chooser_unselect_path (chooser, path);
526       gtk_file_path_free (path);
527     }
528 }
529
530 /* Converts a list of GtkFilePath* to a list of strings using the specified function */
531 static GSList *
532 file_paths_to_strings (GtkFileSystem *fs,
533                        GSList        *paths,
534                        gchar *      (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
535 {
536   GSList *strings;
537
538   strings = NULL;
539
540   for (; paths; paths = paths->next)
541     {
542       GtkFilePath *path;
543       gchar *string;
544
545       path = paths->data;
546       string = (* convert_func) (fs, path);
547
548       if (string)
549         strings = g_slist_prepend (strings, string);
550     }
551
552   return g_slist_reverse (strings);
553 }
554
555 /**
556  * gtk_file_chooser_get_filenames:
557  * @chooser: a #GtkFileChooser
558  * 
559  * Lists all the selected files and subfolders in the current folder of
560  * @chooser. The returned names are full absolute paths. If files in the current
561  * folder cannot be represented as local filenames they will be ignored. (See
562  * gtk_file_chooser_get_uris())
563  * 
564  * Return value: a #GSList containing the filenames of all selected
565  *   files and subfolders in the current folder. Free the returned list
566  *   with g_slist_free(), and the filenames with g_free().
567  *
568  * Since: 2.4
569  **/
570 GSList *
571 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
572 {
573   GtkFileSystem *file_system;
574   GSList *paths;
575   GSList *result;
576   
577   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
578
579   file_system = _gtk_file_chooser_get_file_system (chooser);
580   paths = _gtk_file_chooser_get_paths (chooser);
581
582   result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_filename);
583   gtk_file_paths_free (paths);
584   return result;
585 }
586
587 /**
588  * gtk_file_chooser_set_current_folder:
589  * @chooser: a #GtkFileChooser
590  * @filename: the full path of the new current folder
591  * 
592  * Sets the current folder for @chooser from a local filename.
593  * The user will be shown the full contents of the current folder,
594  * plus user interface elements for navigating to other folders.
595  *
596  * Return value: %TRUE if the folder could be changed successfully, %FALSE
597  * otherwise.
598  *
599  * Since: 2.4
600  **/
601 gboolean
602 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
603                                      const gchar    *filename)
604 {
605   GtkFileSystem *file_system;
606   GtkFilePath *path;
607   gboolean result;
608   
609   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
610   g_return_val_if_fail (filename != NULL, FALSE);
611
612   file_system = _gtk_file_chooser_get_file_system (chooser);
613
614   path = gtk_file_system_filename_to_path (file_system, filename);
615   if (path)
616     {
617       result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
618       gtk_file_path_free (path);
619     }
620   else
621     result = FALSE;
622
623   return result;
624 }
625
626 /**
627  * gtk_file_chooser_get_current_folder:
628  * @chooser: a #GtkFileChooser
629  * 
630  * Gets the current folder of @chooser as a local filename.
631  * See gtk_file_chooser_set_current_folder().
632  * 
633  * Return value: the full path of the current folder, or %NULL
634  *  if the current path cannot be represented as a local filename.
635  *  Free with g_free().
636  *
637  * Since: 2.4
638  **/
639 gchar *
640 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
641 {
642   GtkFileSystem *file_system;
643   GtkFilePath *path;
644   gchar *filename;
645   
646   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
647
648   file_system = _gtk_file_chooser_get_file_system (chooser);
649
650   path = _gtk_file_chooser_get_current_folder_path (chooser);
651   filename = gtk_file_system_path_to_filename (file_system, path);
652   gtk_file_path_free (path);
653
654   return filename;
655 }
656
657 /**
658  * gtk_file_chooser_set_current_name:
659  * @chooser: a #GtkFileChooser
660  * @name: the filename to use, as a UTF-8 string
661  * 
662  * Sets the current name in the file selector, as if entered
663  * by the user. Note that the name passed in here is a UTF-8
664  * string rather than a filename. This function is meant for
665  * such uses as a suggested name in a "Save As..." dialog.
666  *
667  * If you want to preselect a particular existing file, you
668  * should use gtk_file_chooser_set_filename() instead.
669  *
670  * Since: 2.4
671  **/
672 void
673 gtk_file_chooser_set_current_name  (GtkFileChooser *chooser,
674                                     const gchar    *name)
675 {
676   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
677   g_return_if_fail (name != NULL);
678   
679   GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
680 }
681
682 /**
683  * gtk_file_chooser_get_uri:
684  * @chooser: a #GtkFileChooser
685  * 
686  * Gets the URI for the currently selected file in
687  * the file selector. If multiple files are selected,
688  * one of the filenames will be returned at random.
689  * 
690  * If the file chooser is in folder mode, this function returns the selected
691  * folder.
692  * 
693  * Return value: The currently selected URI, or %NULL
694  *  if no file is selected. Free with g_free()
695  *
696  * Since: 2.4
697  **/
698 gchar *
699 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
700 {
701   GtkFileSystem *file_system;
702   GtkFilePath *path;
703   gchar *result = NULL;
704   
705   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
706
707   file_system = _gtk_file_chooser_get_file_system (chooser);
708   path = gtk_file_chooser_get_path (chooser);
709   if (path)
710     {
711       result = gtk_file_system_path_to_uri (file_system, path);
712       gtk_file_path_free (path);
713     }
714
715   return result;
716 }
717
718 /**
719  * gtk_file_chooser_set_uri:
720  * @chooser: a #GtkFileChooser
721  * @uri: the URI to set as current
722  * 
723  * Sets the file referred to by @uri as the current file for the the
724  * file chooser; If the file name isn't in the current folder of @chooser,
725  * then the current folder of @chooser will be changed to the folder containing
726  * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
727  * followed by gtk_file_chooser_select_uri().
728  *
729  * Note that the file must exist, or nothing will be done except
730  * for the directory change. To pre-enter a filename for the user, as in
731  * a save-as dialog, use gtk_file_chooser_set_current_name()
732  *
733  * Return value: %TRUE if both the folder could be changed and the URI was
734  * selected successfully, %FALSE otherwise.
735  *
736  * Since: 2.4
737  **/
738 gboolean
739 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
740                           const char     *uri)
741 {
742   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
743
744   gtk_file_chooser_unselect_all (chooser);
745   return gtk_file_chooser_select_uri (chooser, uri);
746 }
747
748 /**
749  * gtk_file_chooser_select_uri:
750  * @chooser: a #GtkFileChooser
751  * @uri: the URI to select
752  * 
753  * Selects the file to by @uri. If the URI doesn't refer to a
754  * file in the current folder of @chooser, then the current folder of
755  * @chooser will be changed to the folder containing @filename.
756  *
757  * Return value: %TRUE if both the folder could be changed and the URI was
758  * selected successfully, %FALSE otherwise.
759  *
760  * Since: 2.4
761  **/
762 gboolean
763 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
764                              const char     *uri)
765 {
766   GtkFileSystem *file_system;
767   GtkFilePath *path;
768   gboolean result;
769   
770   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
771   g_return_val_if_fail (uri != NULL, FALSE);
772
773   file_system = _gtk_file_chooser_get_file_system (chooser);
774
775   path = gtk_file_system_uri_to_path (file_system, uri);
776   if (path)
777     {
778       result = _gtk_file_chooser_select_path (chooser, path, NULL);
779       gtk_file_path_free (path);
780     }
781   else
782     result = FALSE;
783
784   return result;
785 }
786
787 /**
788  * gtk_file_chooser_unselect_uri:
789  * @chooser: a #GtkFileChooser
790  * @uri: the URI to unselect
791  * 
792  * Unselects the file referred to by @uri. If the file
793  * is not in the current directory, does not exist, or
794  * is otherwise not currently selected, does nothing.
795  *
796  * Since: 2.4
797  **/
798 void
799 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
800                                const char     *uri)
801 {
802   GtkFileSystem *file_system;
803   GtkFilePath *path;
804   
805   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
806   g_return_if_fail (uri != NULL);
807
808   file_system = _gtk_file_chooser_get_file_system (chooser);
809
810   path = gtk_file_system_uri_to_path (file_system, uri);
811   if (path)
812     {
813       _gtk_file_chooser_unselect_path (chooser, path);
814       gtk_file_path_free (path);
815     }
816 }
817
818 /**
819  * gtk_file_chooser_select_all:
820  * @chooser: a #GtkFileChooser
821  * 
822  * Selects all the files in the current folder of a file chooser.
823  *
824  * Since: 2.4
825  **/
826 void
827 gtk_file_chooser_select_all (GtkFileChooser *chooser)
828 {
829   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
830   
831   GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
832 }
833
834 /**
835  * gtk_file_chooser_unselect_all:
836  * @chooser: a #GtkFileChooser
837  * 
838  * Unselects all the files in the current folder of a file chooser.
839  *
840  * Since: 2.4
841  **/
842 void
843 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
844 {
845
846   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
847   
848   GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
849 }
850
851 /**
852  * gtk_file_chooser_get_uris:
853  * @chooser: a #GtkFileChooser
854  * 
855  * Lists all the selected files and subfolders in the current folder of
856  * @chooser. The returned names are full absolute URIs.
857  * 
858  * Return value: a #GSList containing the URIs of all selected
859  *   files and subfolders in the current folder. Free the returned list
860  *   with g_slist_free(), and the filenames with g_free().
861  *
862  * Since: 2.4
863  **/
864 GSList *
865 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
866 {
867   GtkFileSystem *file_system;
868   GSList *paths;
869   GSList *result;
870   
871   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
872
873   file_system = _gtk_file_chooser_get_file_system (chooser);
874   paths = _gtk_file_chooser_get_paths (chooser);
875
876   result = file_paths_to_strings (file_system, paths, gtk_file_system_path_to_uri);
877   gtk_file_paths_free (paths);
878   return result;
879 }
880
881 /**
882  * gtk_file_chooser_set_current_folder_uri:
883  * @chooser: a #GtkFileChooser
884  * @uri: the URI for the new current folder
885  * 
886  * Sets the current folder for @chooser from an URI.
887  * The user will be shown the full contents of the current folder,
888  * plus user interface elements for navigating to other folders.
889  *
890  * Return value: %TRUE if the folder could be changed successfully, %FALSE
891  * otherwise.
892  *
893  * Since: 2.4
894  **/
895 gboolean
896 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
897                                          const gchar    *uri)
898 {
899   GtkFileSystem *file_system;
900   GtkFilePath *path;
901   gboolean result;
902   
903   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
904   g_return_val_if_fail (uri != NULL, FALSE);
905
906   file_system = _gtk_file_chooser_get_file_system (chooser);
907
908   path = gtk_file_system_uri_to_path (file_system, uri);
909   if (path)
910     {
911       result = _gtk_file_chooser_set_current_folder_path (chooser, path, NULL);
912       gtk_file_path_free (path);
913     }
914   else
915     result = FALSE;
916
917   return result;
918 }
919
920 /**
921  * gtk_file_chooser_get_current_folder_uri:
922  * @chooser: a #GtkFileChooser
923  * 
924  * Gets the current folder of @chooser as an URI.
925  * See gtk_file_chooser_set_current_folder_uri().
926  * 
927  * Return value: the URI for the current folder.
928  *  Free with g_free().
929  *
930  * Since: 2.4
931  */
932 gchar *
933 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
934 {
935   GtkFileSystem *file_system;
936   GtkFilePath *path;
937   gchar *uri;
938   
939   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
940
941   file_system = _gtk_file_chooser_get_file_system (chooser);
942
943   path = _gtk_file_chooser_get_current_folder_path (chooser);
944   uri = gtk_file_system_path_to_uri (file_system, path);
945   gtk_file_path_free (path);
946
947   return uri;
948 }
949
950 /**
951  * _gtk_file_chooser_set_current_folder_path:
952  * @chooser: a #GtkFileChooser
953  * @path: the #GtkFilePath for the new folder
954  * @error: location to store error, or %NULL.
955  * 
956  * Sets the current folder for @chooser from a #GtkFilePath.
957  * Internal function, see gtk_file_chooser_set_current_folder_uri().
958  *
959  * Return value: %TRUE if the folder could be changed successfully, %FALSE
960  * otherwise.
961  *
962  * Since: 2.4
963  **/
964 gboolean
965 _gtk_file_chooser_set_current_folder_path (GtkFileChooser    *chooser,
966                                            const GtkFilePath *path,
967                                            GError           **error)
968 {
969   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
970   g_return_val_if_fail (path != NULL, FALSE);
971   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
972
973   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path, error);
974 }
975
976 /**
977  * _gtk_file_chooser_get_current_folder_path:
978  * @chooser: a #GtkFileChooser
979  * 
980  * Gets the current folder of @chooser as #GtkFilePath.
981  * See gtk_file_chooser_get_current_folder_uri().
982  * 
983  * Return value: the #GtkFilePath for the current folder.
984  * Free with gtk_file_path_free().
985  *
986  * Since: 2.4
987  */
988 GtkFilePath *
989 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
990 {
991   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
992
993   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);  
994 }
995
996 /**
997  * _gtk_file_chooser_select_path:
998  * @chooser: a #GtkFileChooser
999  * @path: the path to select
1000  * @error: location to store error, or %NULL
1001  * 
1002  * Selects the file referred to by @path. An internal function. See
1003  * _gtk_file_chooser_select_uri().
1004  *
1005  * Return value: %TRUE if both the folder could be changed and the path was
1006  * selected successfully, %FALSE otherwise.
1007  *
1008  * Since: 2.4
1009  **/
1010 gboolean
1011 _gtk_file_chooser_select_path (GtkFileChooser    *chooser,
1012                                const GtkFilePath *path,
1013                                GError           **error)
1014 {
1015   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1016   g_return_val_if_fail (path != NULL, FALSE);
1017   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1018
1019   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path, error);
1020 }
1021
1022 /**
1023  * _gtk_file_chooser_unselect_path:
1024  * @chooser: a #GtkFileChooser
1025  * @path: the filename to path
1026  * 
1027  * Unselects the file referred to by @path. An internal
1028  * function. See _gtk_file_chooser_unselect_uri().
1029  *
1030  * Since: 2.4
1031  **/
1032 void
1033 _gtk_file_chooser_unselect_path (GtkFileChooser    *chooser,
1034                                  const GtkFilePath *path)
1035 {
1036   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1037
1038   GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
1039 }
1040
1041 /**
1042  * _gtk_file_chooser_get_paths:
1043  * @chooser: a #GtkFileChooser
1044  * 
1045  * Lists all the selected files and subfolders in the current folder of @chooser
1046  * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
1047  * 
1048  * Return value: a #GSList containing a #GtkFilePath for each selected
1049  *   file and subfolder in the current folder.  Free the returned list
1050  *   with g_slist_free(), and the paths with gtk_file_path_free().
1051  *
1052  * Since: 2.4
1053  **/
1054 GSList *
1055 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
1056 {
1057   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1058
1059   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
1060 }
1061
1062 static GtkFilePath *
1063 gtk_file_chooser_get_path (GtkFileChooser *chooser)
1064 {
1065   GSList *list;
1066   GtkFilePath *result = NULL;
1067   
1068   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1069
1070   list = _gtk_file_chooser_get_paths (chooser);
1071   if (list)
1072     {
1073       result = list->data;
1074       list = g_slist_delete_link (list, list);
1075       gtk_file_paths_free (list);
1076     }
1077
1078   return result;
1079 }
1080
1081 /**
1082  * _gtk_file_chooser_get_file_system:
1083  * @chooser: a #GtkFileChooser
1084  * 
1085  * Gets the #GtkFileSystem of @chooser; this is an internal
1086  * implementation detail, used for conversion between paths
1087  * and filenames and URIs.
1088  * 
1089  * Return value: the file system for @chooser.
1090  *
1091  * Since: 2.4
1092  **/
1093 GtkFileSystem *
1094 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1095 {
1096   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1097
1098   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1099 }
1100
1101 /* Preview widget
1102  */
1103 /**
1104  * gtk_file_chooser_set_preview_widget:
1105  * @chooser: a #GtkFileChooser
1106  * @preview_widget: widget for displaying preview.
1107  *
1108  * Sets an application-supplied widget to use to display a custom preview
1109  * of the currently selected file. To implement a preview, after setting the
1110  * preview widget, you connect to the ::selection-changed
1111  * signal, and call gtk_file_chooser_get_preview_filename() or
1112  * gtk_file_chooser_get_preview_uri() on each change. If you can
1113  * display a preview of the new file, update your widget and
1114  * set the preview active using gtk_file_chooser_set_preview_widget_active().
1115  * Otherwise, set the preview inactive.
1116  *
1117  * When there is no application-supplied preview widget, or the
1118  * application-supplied preview widget is not active, the file chooser
1119  * may display an internally generated preview of the current file or
1120  * it may display no preview at all.
1121  *
1122  * Since: 2.4
1123  **/
1124 void
1125 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1126                                      GtkWidget      *preview_widget)
1127 {
1128   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1129
1130   g_object_set (chooser, "preview-widget", preview_widget, NULL);
1131 }
1132
1133 /**
1134  * gtk_file_chooser_get_preview_widget:
1135  * @chooser: a #GtkFileChooser
1136  * 
1137  * Gets the current preview widget; see
1138  * gtk_file_chooser_set_preview_widget().
1139  * 
1140  * Return value: the current preview widget, or %NULL
1141  *
1142  * Since: 2.4
1143  **/
1144 GtkWidget *
1145 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1146 {
1147   GtkWidget *preview_widget;
1148   
1149   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1150
1151   g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1152   
1153   /* Horrid hack; g_object_get() refs returned objects but
1154    * that contradicts the memory management conventions
1155    * for accessors.
1156    */
1157   if (preview_widget)
1158     g_object_unref (preview_widget);
1159
1160   return preview_widget;
1161 }
1162
1163 /**
1164  * gtk_file_chooser_set_preview_widget_active:
1165  * @chooser: a #GtkFileChooser
1166  * @active: whether to display the user-specified preview widget
1167  * 
1168  * Sets whether the preview widget set by
1169  * gtk_file_chooser_set_preview_widget_active() should be shown for the
1170  * current filename. When @active is set to false, the file chooser
1171  * may display an internally generated preview of the current file
1172  * or it may display no preview at all. See
1173  * gtk_file_chooser_set_preview_widget() for more details.
1174  *
1175  * Since: 2.4
1176  **/
1177 void
1178 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1179                                             gboolean        active)
1180 {
1181   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1182   
1183   g_object_set (chooser, "preview-widget-active", active, NULL);
1184 }
1185
1186 /**
1187  * gtk_file_chooser_get_preview_widget_active:
1188  * @chooser: a #GtkFileChooser
1189  * 
1190  * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1191  * should be shown for the current filename. See
1192  * gtk_file_chooser_set_preview_widget_active().
1193  * 
1194  * Return value: %TRUE if the preview widget is active for the current filename.
1195  *
1196  * Since: 2.4
1197  **/
1198 gboolean
1199 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1200 {
1201   gboolean active;
1202   
1203   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1204
1205   g_object_get (chooser, "preview-widget-active", &active, NULL);
1206
1207   return active;
1208 }
1209
1210 /**
1211  * gtk_file_chooser_set_use_preview_label:
1212  * @chooser: a #GtkFileChooser
1213  * @use_label: whether to display a stock label with the name of the previewed file
1214  * 
1215  * Sets whether the file chooser should display a stock label with the name of
1216  * the file that is being previewed; the default is %TRUE.  Applications that
1217  * want to draw the whole preview area themselves should set this to %FALSE and
1218  * display the name themselves in their preview widget.
1219  *
1220  * See also: gtk_file_chooser_set_preview_widget()
1221  *
1222  * Since: 2.4
1223  **/
1224 void
1225 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1226                                         gboolean        use_label)
1227 {
1228   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1229
1230   g_object_set (chooser, "use-preview-label", use_label, NULL);
1231 }
1232
1233 /**
1234  * gtk_file_chooser_get_use_preview_label:
1235  * @chooser: a #GtkFileChooser
1236  * 
1237  * Gets whether a stock label should be drawn with the name of the previewed
1238  * file.  See gtk_file_chooser_set_use_preview_label().
1239  * 
1240  * Return value: %TRUE if the file chooser is set to display a label with the
1241  * name of the previewed file, %FALSE otherwise.
1242  **/
1243 gboolean
1244 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1245 {
1246   gboolean use_label;
1247   
1248   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1249
1250   g_object_get (chooser, "use-preview-label", &use_label, NULL);
1251
1252   return use_label;
1253 }
1254
1255 /**
1256  * gtk_file_chooser_get_preview_filename:
1257  * @chooser: a #GtkFileChooser
1258  * 
1259  * Gets the filename that should be previewed in a custom preview
1260  * Internal function, see gtk_file_chooser_get_preview_uri().
1261  * 
1262  * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1263  *  is selected. Free with gtk_file_path_free().
1264  *
1265  * Since: 2.4
1266  **/
1267 GtkFilePath *
1268 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1269 {
1270   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1271
1272   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1273 }
1274
1275 /**
1276  * _gtk_file_chooser_add_shortcut_folder:
1277  * @chooser: a #GtkFileChooser
1278  * @path: path of the folder to add
1279  * @error: location to store error, or %NULL
1280  * 
1281  * Adds a folder to be displayed with the shortcut folders in a file chooser.
1282  * Internal function, see gtk_file_chooser_add_shortcut_folder().
1283  * 
1284  * Return value: %TRUE if the folder could be added successfully, %FALSE
1285  * otherwise.
1286  *
1287  * Since: 2.4
1288  **/
1289 gboolean
1290 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
1291                                        const GtkFilePath *path,
1292                                        GError           **error)
1293 {
1294   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1295   g_return_val_if_fail (path != NULL, FALSE);
1296
1297   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1298 }
1299
1300 /**
1301  * _gtk_file_chooser_remove_shortcut_folder:
1302  * @chooser: a #GtkFileChooser
1303  * @path: path of the folder to remove
1304  * @error: location to store error, or %NULL
1305  * 
1306  * Removes a folder from the shortcut folders in a file chooser.  Internal
1307  * function, see gtk_file_chooser_remove_shortcut_folder().
1308  * 
1309  * Return value: %TRUE if the folder could be removed successfully, %FALSE
1310  * otherwise.
1311  *
1312  * Since: 2.4
1313  **/
1314 gboolean
1315 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
1316                                           const GtkFilePath *path,
1317                                           GError           **error)
1318 {
1319   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1320   g_return_val_if_fail (path != NULL, FALSE);
1321
1322   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1323 }
1324
1325 /**
1326  * gtk_file_chooser_get_preview_filename:
1327  * @chooser: a #GtkFileChooser
1328  * 
1329  * Gets the filename that should be previewed in a custom preview
1330  * widget. See gtk_file_chooser_set_preview_widget().
1331  * 
1332  * Return value: the filename to preview, or %NULL if no file
1333  *  is selected, or if the selected file cannot be represented
1334  *  as a local filename. Free with g_free()
1335  *
1336  * Since: 2.4
1337  **/
1338 char *
1339 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1340 {
1341   GtkFileSystem *file_system;
1342   GtkFilePath *path;
1343   gchar *result = NULL;
1344   
1345   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1346
1347   file_system = _gtk_file_chooser_get_file_system (chooser);
1348   path = _gtk_file_chooser_get_preview_path (chooser);
1349   if (path)
1350     {
1351       result = gtk_file_system_path_to_filename (file_system, path);
1352       gtk_file_path_free (path);
1353     }
1354
1355   return result;
1356 }
1357
1358 /**
1359  * gtk_file_chooser_get_preview_uri:
1360  * @chooser: a #GtkFileChooser
1361  * 
1362  * Gets the URI that should be previewed in a custom preview
1363  * widget. See gtk_file_chooser_set_preview_widget().
1364  * 
1365  * Return value: the URI for the file to preview, or %NULL if no file is
1366  * selected. Free with g_free().
1367  *
1368  * Since: 2.4
1369  **/
1370 char *
1371 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1372 {
1373   GtkFileSystem *file_system;
1374   GtkFilePath *path;
1375   gchar *result = NULL;
1376   
1377   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1378
1379   file_system = _gtk_file_chooser_get_file_system (chooser);
1380   path = _gtk_file_chooser_get_preview_path (chooser);
1381   if (path)
1382     {
1383       result = gtk_file_system_path_to_uri (file_system, path);
1384       gtk_file_path_free (path);
1385     }
1386
1387   return result;
1388 }
1389
1390 /**
1391  * gtk_file_chooser_set_extra_widget:
1392  * @chooser: a #GtkFileChooser
1393  * @extra_widget: widget for extra options
1394  * 
1395  * Sets an application-supplied widget to provide extra options to the user.
1396  *
1397  * Since: 2.4
1398  **/
1399 void
1400 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1401                                    GtkWidget      *extra_widget)
1402 {
1403   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1404
1405   g_object_set (chooser, "extra-widget", extra_widget, NULL);
1406 }
1407
1408 /**
1409  * gtk_file_chooser_get_extra_widget:
1410  * @chooser: a #GtkFileChooser
1411  * 
1412  * Gets the current preview widget; see
1413  * gtk_file_chooser_set_extra_widget().
1414  * 
1415  * Return value: the current extra widget, or %NULL
1416  *
1417  * Since: 2.4
1418  **/
1419 GtkWidget *
1420 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1421 {
1422   GtkWidget *extra_widget;
1423   
1424   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1425
1426   g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1427   
1428   /* Horrid hack; g_object_get() refs returned objects but
1429    * that contradicts the memory management conventions
1430    * for accessors.
1431    */
1432   if (extra_widget)
1433     g_object_unref (extra_widget);
1434
1435   return extra_widget;
1436 }
1437
1438 /**
1439  * gtk_file_chooser_add_filter:
1440  * @chooser: a #GtkFileChooser
1441  * @filter: a #GtkFileFilter
1442  * 
1443  * Adds @filter to the list of filters that the user can select between.
1444  * When a filter is selected, only files that are passed by that
1445  * filter are displayed.
1446  *
1447  * Since: 2.4
1448  **/
1449 void
1450 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1451                              GtkFileFilter  *filter)
1452 {
1453   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1454
1455   GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1456 }
1457
1458 /**
1459  * gtk_file_chooser_remove_filter:
1460  * @chooser: a #GtkFileChooser
1461  * @filter: a #GtkFileFilter
1462  * 
1463  * Removes @filter from the list of filters that the user can select between.
1464  *
1465  * Since: 2.4
1466  **/
1467 void
1468 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1469                                 GtkFileFilter  *filter)
1470 {
1471   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1472
1473   GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1474 }
1475
1476 /**
1477  * gtk_file_chooser_list_filters:
1478  * @chooser: a #GtkFileChooser
1479  * 
1480  * Lists the current set of user-selectable filters; see
1481  * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1482  * 
1483  * Return value: a #GSList containing the current set of
1484  *  user selectable filters. The contents of the list are
1485  *  owned by GTK+, but you must free the list itself with
1486  *  g_slist_free() when you are done with it.
1487  *
1488  * Since: 2.4
1489  **/
1490 GSList *
1491 gtk_file_chooser_list_filters  (GtkFileChooser *chooser)
1492 {
1493   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1494
1495   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1496 }
1497
1498 /**
1499  * gtk_file_chooser_set_filter:
1500  * @chooser: a #GtkFileChooser
1501  * @filter: a #GtkFileFilter
1502  * 
1503  * Sets the current filter; only the files that pass the
1504  * filter will be displayed. If the user-selectable list of filters
1505  * is non-empty, then the filter should be one of the filters
1506  * in that list. Setting the current filter when the list of
1507  * filters is empty is useful if you want to restrict the displayed
1508  * set of files without letting the user change it.
1509  *
1510  * Since: 2.4
1511  **/
1512 void
1513 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1514                              GtkFileFilter  *filter)
1515 {
1516   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1517   g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1518
1519   g_object_set (chooser, "filter", filter, NULL);
1520 }
1521
1522 /**
1523  * gtk_file_chooser_get_filter:
1524  * @chooser: a #GtkFileChooser
1525  * 
1526  * Gets the current filter; see gtk_file_chooser_set_filter().
1527  * 
1528  * Return value: the current filter, or %NULL
1529  *
1530  * Since: 2.4
1531  **/
1532 GtkFileFilter *
1533 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1534 {
1535   GtkFileFilter *filter;
1536   
1537   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1538
1539   g_object_get (chooser, "filter", &filter, NULL);
1540   /* Horrid hack; g_object_get() refs returned objects but
1541    * that contradicts the memory management conventions
1542    * for accessors.
1543    */
1544   if (filter)
1545     g_object_unref (filter);
1546
1547   return filter;
1548 }
1549
1550 /**
1551  * gtk_file_chooser_add_shortcut_folder:
1552  * @chooser: a #GtkFileChooser
1553  * @folder: filename of the folder to add
1554  * @error: location to store error, or %NULL
1555  * 
1556  * Adds a folder to be displayed with the shortcut folders in a file chooser.
1557  * Note that shortcut folders do not get saved, as they are provided by the
1558  * application.  For example, you can use this to add a
1559  * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1560  * 
1561  * Return value: %TRUE if the folder could be added successfully, %FALSE
1562  * otherwise.  In the latter case, the @error will be set as appropriate.
1563  *
1564  * Since: 2.4
1565  **/
1566 gboolean
1567 gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
1568                                       const char        *folder,
1569                                       GError           **error)
1570 {
1571   GtkFilePath *path;
1572   gboolean result;
1573
1574   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1575   g_return_val_if_fail (folder != NULL, FALSE);
1576
1577   path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1578   if (!path)
1579     {
1580       g_set_error (error,
1581                    GTK_FILE_CHOOSER_ERROR,
1582                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1583                    _("Invalid filename: %s"),
1584                    folder);
1585       return FALSE;
1586     }
1587
1588   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1589
1590   gtk_file_path_free (path);
1591
1592   return result;
1593 }
1594
1595 /**
1596  * gtk_file_chooser_remove_shortcut_folder:
1597  * @chooser: a #GtkFileChooser
1598  * @folder: filename of the folder to remove
1599  * @error: location to store error, or %NULL
1600  * 
1601  * Removes a folder from a file chooser's list of shortcut folders.
1602  * 
1603  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
1604  * In the latter case, the @error will be set as appropriate.
1605  *
1606  * See also: gtk_file_chooser_add_shortcut_folder()
1607  *
1608  * Since: 2.4
1609  **/
1610 gboolean
1611 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
1612                                          const char        *folder,
1613                                          GError           **error)
1614 {
1615   GtkFilePath *path;
1616   gboolean result;
1617
1618   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1619   g_return_val_if_fail (folder != NULL, FALSE);
1620
1621   path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1622   if (!path)
1623     {
1624       g_set_error (error,
1625                    GTK_FILE_CHOOSER_ERROR,
1626                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1627                    _("Invalid filename: %s"),
1628                    folder);
1629       return FALSE;
1630     }
1631
1632   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1633
1634   gtk_file_path_free (path);
1635
1636   return result;
1637 }
1638
1639 /**
1640  * gtk_file_chooser_list_shortcut_folders:
1641  * @chooser: a #GtkFileChooser
1642  * 
1643  * Queries the list of shortcut folders in the file chooser, as set by
1644  * gtk_file_chooser_set_shortcut_folders().
1645  * 
1646  * Return value: A list of folder filenames, or %NULL if there are no shortcut
1647  * folders.  Free the returned list with g_slist_free(), and the filenames with
1648  * g_free().
1649  *
1650  * Since: 2.4
1651  **/
1652 GSList *
1653 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1654 {
1655   GSList *folders;
1656   GSList *result;
1657
1658   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1659
1660   folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1661
1662   result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1663                                   folders,
1664                                   gtk_file_system_path_to_filename);
1665   gtk_file_paths_free (folders);
1666   return result;
1667 }
1668
1669 /**
1670  * gtk_file_chooser_add_shortcut_folder_uri:
1671  * @chooser: a #GtkFileChooser
1672  * @uri: URI of the folder to add
1673  * @error: location to store error, or %NULL
1674  * 
1675  * Adds a folder URI to be displayed with the shortcut folders in a file
1676  * chooser.  Note that shortcut folders do not get saved, as they are provided
1677  * by the application.  For example, you can use this to add a
1678  * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1679  * 
1680  * Return value: %TRUE if the folder could be added successfully, %FALSE
1681  * otherwise.  In the latter case, the @error will be set as appropriate.
1682  *
1683  * Since: 2.4
1684  **/
1685 gboolean
1686 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser    *chooser,
1687                                           const char        *uri,
1688                                           GError           **error)
1689 {
1690   GtkFilePath *path;
1691   gboolean result;
1692
1693   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1694   g_return_val_if_fail (uri != NULL, FALSE);
1695
1696   path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1697   if (!path)
1698     {
1699       g_set_error (error,
1700                    GTK_FILE_CHOOSER_ERROR,
1701                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1702                    _("Invalid filename: %s"),
1703                    uri);
1704       return FALSE;
1705     }
1706
1707   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1708
1709   gtk_file_path_free (path);
1710
1711   return result;
1712 }
1713
1714 /**
1715  * gtk_file_chooser_remove_shortcut_folder_uri:
1716  * @chooser: a #GtkFileChooser
1717  * @uri: URI of the folder to remove
1718  * @error: location to store error, or %NULL
1719  * 
1720  * Removes a folder URI from a file chooser's list of shortcut folders.
1721  * 
1722  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
1723  * In the latter case, the @error will be set as appropriate.
1724  *
1725  * See also: gtk_file_chooser_add_shortcut_folder_uri()
1726  *
1727  * Since: 2.4
1728  **/
1729 gboolean
1730 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser    *chooser,
1731                                              const char        *uri,
1732                                              GError           **error)
1733 {
1734   GtkFilePath *path;
1735   gboolean result;
1736
1737   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1738   g_return_val_if_fail (uri != NULL, FALSE);
1739
1740   path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1741   if (!path)
1742     {
1743       g_set_error (error,
1744                    GTK_FILE_CHOOSER_ERROR,
1745                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1746                    _("Invalid filename: %s"),
1747                    uri);
1748       return FALSE;
1749     }
1750
1751   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1752
1753   gtk_file_path_free (path);
1754
1755   return result;
1756 }
1757
1758 /**
1759  * gtk_file_chooser_list_shortcut_folder_uris:
1760  * @chooser: a #GtkFileChooser
1761  * 
1762  * Queries the list of shortcut folders in the file chooser, as set by
1763  * gtk_file_chooser_set_shortcut_folder_uris().
1764  * 
1765  * Return value: A list of folder URIs, or %NULL if there are no shortcut
1766  * folders.  Free the returned list with g_slist_free(), and the URIs with
1767  * g_free().
1768  *
1769  * Since: 2.4
1770  **/
1771 GSList *
1772 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1773 {
1774   GSList *folders;
1775   GSList *result;
1776
1777   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1778
1779   folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1780
1781   result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1782                                   folders,
1783                                   gtk_file_system_path_to_uri);
1784   gtk_file_paths_free (folders);
1785   return result;
1786 }