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