]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooser.c
377838809aee9bc50776e575f52f97bf6bd8434b
[~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 "gtkalias.h"
23 #include "gtkfilechooser.h"
24 #include "gtkfilechooserprivate.h"
25 #include "gtkfilesystem.h"
26 #include "gtkintl.h"
27 #include "gtktypebuiltins.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 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 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 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_active() 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  * Since: 2.4
1449  **/
1450 void
1451 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1452                              GtkFileFilter  *filter)
1453 {
1454   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1455
1456   GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1457 }
1458
1459 /**
1460  * gtk_file_chooser_remove_filter:
1461  * @chooser: a #GtkFileChooser
1462  * @filter: a #GtkFileFilter
1463  * 
1464  * Removes @filter from the list of filters that the user can select between.
1465  *
1466  * Since: 2.4
1467  **/
1468 void
1469 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1470                                 GtkFileFilter  *filter)
1471 {
1472   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1473
1474   GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1475 }
1476
1477 /**
1478  * gtk_file_chooser_list_filters:
1479  * @chooser: a #GtkFileChooser
1480  * 
1481  * Lists the current set of user-selectable filters; see
1482  * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1483  * 
1484  * Return value: a #GSList containing the current set of
1485  *  user selectable filters. The contents of the list are
1486  *  owned by GTK+, but you must free the list itself with
1487  *  g_slist_free() when you are done with it.
1488  *
1489  * Since: 2.4
1490  **/
1491 GSList *
1492 gtk_file_chooser_list_filters  (GtkFileChooser *chooser)
1493 {
1494   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1495
1496   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1497 }
1498
1499 /**
1500  * gtk_file_chooser_set_filter:
1501  * @chooser: a #GtkFileChooser
1502  * @filter: a #GtkFileFilter
1503  * 
1504  * Sets the current filter; only the files that pass the
1505  * filter will be displayed. If the user-selectable list of filters
1506  * is non-empty, then the filter should be one of the filters
1507  * in that list. Setting the current filter when the list of
1508  * filters is empty is useful if you want to restrict the displayed
1509  * set of files without letting the user change it.
1510  *
1511  * Since: 2.4
1512  **/
1513 void
1514 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1515                              GtkFileFilter  *filter)
1516 {
1517   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1518   g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1519
1520   g_object_set (chooser, "filter", filter, NULL);
1521 }
1522
1523 /**
1524  * gtk_file_chooser_get_filter:
1525  * @chooser: a #GtkFileChooser
1526  * 
1527  * Gets the current filter; see gtk_file_chooser_set_filter().
1528  * 
1529  * Return value: the current filter, or %NULL
1530  *
1531  * Since: 2.4
1532  **/
1533 GtkFileFilter *
1534 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1535 {
1536   GtkFileFilter *filter;
1537   
1538   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1539
1540   g_object_get (chooser, "filter", &filter, NULL);
1541   /* Horrid hack; g_object_get() refs returned objects but
1542    * that contradicts the memory management conventions
1543    * for accessors.
1544    */
1545   if (filter)
1546     g_object_unref (filter);
1547
1548   return filter;
1549 }
1550
1551 /**
1552  * gtk_file_chooser_add_shortcut_folder:
1553  * @chooser: a #GtkFileChooser
1554  * @folder: filename of the folder to add
1555  * @error: location to store error, or %NULL
1556  * 
1557  * Adds a folder to be displayed with the shortcut folders in a file chooser.
1558  * Note that shortcut folders do not get saved, as they are provided by the
1559  * application.  For example, you can use this to add a
1560  * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1561  * 
1562  * Return value: %TRUE if the folder could be added successfully, %FALSE
1563  * otherwise.  In the latter case, the @error will be set as appropriate.
1564  *
1565  * Since: 2.4
1566  **/
1567 gboolean
1568 gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
1569                                       const char        *folder,
1570                                       GError           **error)
1571 {
1572   GtkFilePath *path;
1573   gboolean result;
1574
1575   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1576   g_return_val_if_fail (folder != NULL, FALSE);
1577
1578   path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1579   if (!path)
1580     {
1581       g_set_error (error,
1582                    GTK_FILE_CHOOSER_ERROR,
1583                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1584                    _("Invalid filename: %s"),
1585                    folder);
1586       return FALSE;
1587     }
1588
1589   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1590
1591   gtk_file_path_free (path);
1592
1593   return result;
1594 }
1595
1596 /**
1597  * gtk_file_chooser_remove_shortcut_folder:
1598  * @chooser: a #GtkFileChooser
1599  * @folder: filename of the folder to remove
1600  * @error: location to store error, or %NULL
1601  * 
1602  * Removes a folder from a file chooser's list of shortcut folders.
1603  * 
1604  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
1605  * In the latter case, the @error will be set as appropriate.
1606  *
1607  * See also: gtk_file_chooser_add_shortcut_folder()
1608  *
1609  * Since: 2.4
1610  **/
1611 gboolean
1612 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
1613                                          const char        *folder,
1614                                          GError           **error)
1615 {
1616   GtkFilePath *path;
1617   gboolean result;
1618
1619   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1620   g_return_val_if_fail (folder != NULL, FALSE);
1621
1622   path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), folder);
1623   if (!path)
1624     {
1625       g_set_error (error,
1626                    GTK_FILE_CHOOSER_ERROR,
1627                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1628                    _("Invalid filename: %s"),
1629                    folder);
1630       return FALSE;
1631     }
1632
1633   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1634
1635   gtk_file_path_free (path);
1636
1637   return result;
1638 }
1639
1640 /**
1641  * gtk_file_chooser_list_shortcut_folders:
1642  * @chooser: a #GtkFileChooser
1643  * 
1644  * Queries the list of shortcut folders in the file chooser, as set by
1645  * gtk_file_chooser_add_shortcut_folder().
1646  * 
1647  * Return value: A list of folder filenames, or %NULL if there are no shortcut
1648  * folders.  Free the returned list with g_slist_free(), and the filenames with
1649  * g_free().
1650  *
1651  * Since: 2.4
1652  **/
1653 GSList *
1654 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1655 {
1656   GSList *folders;
1657   GSList *result;
1658
1659   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1660
1661   folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1662
1663   result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1664                                   folders,
1665                                   gtk_file_system_path_to_filename);
1666   gtk_file_paths_free (folders);
1667   return result;
1668 }
1669
1670 /**
1671  * gtk_file_chooser_add_shortcut_folder_uri:
1672  * @chooser: a #GtkFileChooser
1673  * @uri: URI of the folder to add
1674  * @error: location to store error, or %NULL
1675  * 
1676  * Adds a folder URI to be displayed with the shortcut folders in a file
1677  * chooser.  Note that shortcut folders do not get saved, as they are provided
1678  * by the application.  For example, you can use this to add a
1679  * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1680  * 
1681  * Return value: %TRUE if the folder could be added successfully, %FALSE
1682  * otherwise.  In the latter case, the @error will be set as appropriate.
1683  *
1684  * Since: 2.4
1685  **/
1686 gboolean
1687 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser    *chooser,
1688                                           const char        *uri,
1689                                           GError           **error)
1690 {
1691   GtkFilePath *path;
1692   gboolean result;
1693
1694   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1695   g_return_val_if_fail (uri != NULL, FALSE);
1696
1697   path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1698   if (!path)
1699     {
1700       g_set_error (error,
1701                    GTK_FILE_CHOOSER_ERROR,
1702                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1703                    _("Invalid filename: %s"),
1704                    uri);
1705       return FALSE;
1706     }
1707
1708   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, path, error);
1709
1710   gtk_file_path_free (path);
1711
1712   return result;
1713 }
1714
1715 /**
1716  * gtk_file_chooser_remove_shortcut_folder_uri:
1717  * @chooser: a #GtkFileChooser
1718  * @uri: URI of the folder to remove
1719  * @error: location to store error, or %NULL
1720  * 
1721  * Removes a folder URI from a file chooser's list of shortcut folders.
1722  * 
1723  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
1724  * In the latter case, the @error will be set as appropriate.
1725  *
1726  * See also: gtk_file_chooser_add_shortcut_folder_uri()
1727  *
1728  * Since: 2.4
1729  **/
1730 gboolean
1731 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser    *chooser,
1732                                              const char        *uri,
1733                                              GError           **error)
1734 {
1735   GtkFilePath *path;
1736   gboolean result;
1737
1738   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1739   g_return_val_if_fail (uri != NULL, FALSE);
1740
1741   path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
1742   if (!path)
1743     {
1744       g_set_error (error,
1745                    GTK_FILE_CHOOSER_ERROR,
1746                    GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
1747                    _("Invalid filename: %s"),
1748                    uri);
1749       return FALSE;
1750     }
1751
1752   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, path, error);
1753
1754   gtk_file_path_free (path);
1755
1756   return result;
1757 }
1758
1759 /**
1760  * gtk_file_chooser_list_shortcut_folder_uris:
1761  * @chooser: a #GtkFileChooser
1762  * 
1763  * Queries the list of shortcut folders in the file chooser, as set by
1764  * gtk_file_chooser_add_shortcut_folder_uri().
1765  * 
1766  * Return value: A list of folder URIs, or %NULL if there are no shortcut
1767  * folders.  Free the returned list with g_slist_free(), and the URIs with
1768  * g_free().
1769  *
1770  * Since: 2.4
1771  **/
1772 GSList *
1773 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1774 {
1775   GSList *folders;
1776   GSList *result;
1777
1778   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1779
1780   folders = GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1781
1782   result = file_paths_to_strings (_gtk_file_chooser_get_file_system (chooser),
1783                                   folders,
1784                                   gtk_file_system_path_to_uri);
1785   gtk_file_paths_free (folders);
1786   return result;
1787 }
1788
1789
1790 /**
1791  * gtk_file_chooser_set_show_hidden:
1792  * @chooser: a #GtkFileChooser
1793  * @show_hidden: %TRUE if hidden files and folders should be displayed.
1794  * 
1795  * Sets whether hidden files and folders are displayed in the file selector.  
1796  *
1797  * Since: 2.6
1798  **/
1799 void
1800 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1801                                   gboolean        show_hidden)
1802 {
1803   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1804
1805   g_object_set (chooser, "show-hidden", show_hidden, NULL);
1806 }
1807
1808 /**
1809  * gtk_file_chooser_get_show_hidden:
1810  * @chooser: a #GtkFileChooser
1811  * 
1812  * Gets whether hidden files and folders are displayed in the file selector.   
1813  * See gtk_file_chooser_set_show_hidden().
1814  * 
1815  * Return value: %TRUE if hidden files and folders are displayed.
1816  *
1817  * Since: 2.6
1818  **/
1819 gboolean
1820 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1821 {
1822   gboolean show_hidden;
1823   
1824   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1825
1826   g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1827
1828   return show_hidden;
1829 }
1830
1831 #ifdef G_OS_WIN32
1832
1833 /* DLL ABI stability backward compatibility versions */
1834
1835 #undef gtk_file_chooser_get_filename
1836
1837 gchar *
1838 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
1839 {
1840   gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
1841   gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
1842
1843   g_free (utf8_filename);
1844
1845   return retval;
1846 }
1847
1848 #undef gtk_file_chooser_set_filename
1849
1850 gboolean
1851 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
1852                                const gchar    *filename)
1853 {
1854   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
1855   gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
1856
1857   g_free (utf8_filename);
1858
1859   return retval;
1860 }
1861
1862 #undef gtk_file_chooser_select_filename
1863
1864 gboolean
1865 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
1866                                   const gchar    *filename)
1867 {
1868   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
1869   gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
1870
1871   g_free (utf8_filename);
1872
1873   return retval;
1874 }
1875
1876 #undef gtk_file_chooser_unselect_filename
1877
1878 void
1879 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
1880                                     const char     *filename)
1881 {
1882   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
1883
1884   gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
1885   g_free (utf8_filename);
1886 }
1887
1888 #undef gtk_file_chooser_get_filenames
1889
1890 GSList *
1891 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
1892 {
1893   GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
1894   GSList *rover = list;
1895   
1896   while (rover)
1897     {
1898       gchar *tem = (gchar *) rover->data;
1899       rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
1900       g_free (tem);
1901       rover = rover->next;
1902     }
1903
1904   return list;
1905 }
1906
1907 #undef gtk_file_chooser_set_current_folder
1908
1909 gboolean
1910 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
1911                                      const gchar    *filename)
1912 {
1913   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
1914   gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
1915
1916   g_free (utf8_filename);
1917
1918   return retval;
1919 }
1920
1921 #undef gtk_file_chooser_get_current_folder
1922
1923 gchar *
1924 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
1925 {
1926   gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
1927   gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
1928
1929   g_free (utf8_folder);
1930
1931   return retval;
1932 }
1933
1934 #undef gtk_file_chooser_get_preview_filename
1935
1936 char *
1937 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1938 {
1939   char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
1940   char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
1941
1942   g_free (utf8_filename);
1943
1944   return retval;
1945 }
1946
1947 #undef gtk_file_chooser_add_shortcut_folder
1948
1949 gboolean
1950 gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
1951                                       const char        *folder,
1952                                       GError           **error)
1953 {
1954   char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
1955   gboolean retval =
1956     gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
1957
1958   g_free (utf8_folder);
1959
1960   return retval;
1961 }
1962
1963 #undef gtk_file_chooser_remove_shortcut_folder
1964
1965 gboolean
1966 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
1967                                          const char        *folder,
1968                                          GError           **error)
1969 {
1970   char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
1971   gboolean retval =
1972     gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
1973
1974   g_free (utf8_folder);
1975
1976   return retval;
1977 }
1978
1979 #undef gtk_file_chooser_list_shortcut_folders
1980
1981 GSList *
1982 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1983 {
1984   GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
1985   GSList *rover = list;
1986   
1987   while (rover)
1988     {
1989       gchar *tem = (gchar *) rover->data;
1990       rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
1991       g_free (tem);
1992       rover = rover->next;
1993     }
1994
1995   return list;
1996 }
1997
1998 #endif