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