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