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