]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooser.c
c8078b12a5e23cd4d63c3d73e994e5a982713e9f
[~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
1243  *
1244  * Since: 2.14
1245  **/
1246 GFile *
1247 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1248 {
1249   GSList *list;
1250   GFile *result = NULL;
1251   
1252   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1253
1254   list = gtk_file_chooser_get_files (chooser);
1255   if (list)
1256     {
1257       result = list->data;
1258       list = g_slist_delete_link (list, list);
1259
1260       g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1261       g_slist_free (list);
1262     }
1263
1264   return result;
1265 }
1266
1267 /**
1268  * _gtk_file_chooser_get_file_system:
1269  * @chooser: a #GtkFileChooser
1270  * 
1271  * Gets the #GtkFileSystem of @chooser; this is an internal
1272  * implementation detail, used for conversion between paths
1273  * and filenames and URIs.
1274  * 
1275  * Return value: the file system for @chooser.
1276  *
1277  * Since: 2.4
1278  **/
1279 GtkFileSystem *
1280 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1281 {
1282   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1283
1284   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1285 }
1286
1287 /* Preview widget
1288  */
1289 /**
1290  * gtk_file_chooser_set_preview_widget:
1291  * @chooser: a #GtkFileChooser
1292  * @preview_widget: widget for displaying preview.
1293  *
1294  * Sets an application-supplied widget to use to display a custom preview
1295  * of the currently selected file. To implement a preview, after setting the
1296  * preview widget, you connect to the ::update-preview
1297  * signal, and call gtk_file_chooser_get_preview_filename() or
1298  * gtk_file_chooser_get_preview_uri() on each change. If you can
1299  * display a preview of the new file, update your widget and
1300  * set the preview active using gtk_file_chooser_set_preview_widget_active().
1301  * Otherwise, set the preview inactive.
1302  *
1303  * When there is no application-supplied preview widget, or the
1304  * application-supplied preview widget is not active, the file chooser
1305  * may display an internally generated preview of the current file or
1306  * it may display no preview at all.
1307  *
1308  * Since: 2.4
1309  **/
1310 void
1311 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1312                                      GtkWidget      *preview_widget)
1313 {
1314   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1315
1316   g_object_set (chooser, "preview-widget", preview_widget, NULL);
1317 }
1318
1319 /**
1320  * gtk_file_chooser_get_preview_widget:
1321  * @chooser: a #GtkFileChooser
1322  * 
1323  * Gets the current preview widget; see
1324  * gtk_file_chooser_set_preview_widget().
1325  * 
1326  * Return value: the current preview widget, or %NULL
1327  *
1328  * Since: 2.4
1329  **/
1330 GtkWidget *
1331 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1332 {
1333   GtkWidget *preview_widget;
1334   
1335   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1336
1337   g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1338   
1339   /* Horrid hack; g_object_get() refs returned objects but
1340    * that contradicts the memory management conventions
1341    * for accessors.
1342    */
1343   if (preview_widget)
1344     g_object_unref (preview_widget);
1345
1346   return preview_widget;
1347 }
1348
1349 /**
1350  * gtk_file_chooser_set_preview_widget_active:
1351  * @chooser: a #GtkFileChooser
1352  * @active: whether to display the user-specified preview widget
1353  * 
1354  * Sets whether the preview widget set by
1355  * gtk_file_chooser_set_preview_widget() should be shown for the
1356  * current filename. When @active is set to false, the file chooser
1357  * may display an internally generated preview of the current file
1358  * or it may display no preview at all. See
1359  * gtk_file_chooser_set_preview_widget() for more details.
1360  *
1361  * Since: 2.4
1362  **/
1363 void
1364 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1365                                             gboolean        active)
1366 {
1367   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1368   
1369   g_object_set (chooser, "preview-widget-active", active, NULL);
1370 }
1371
1372 /**
1373  * gtk_file_chooser_get_preview_widget_active:
1374  * @chooser: a #GtkFileChooser
1375  * 
1376  * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1377  * should be shown for the current filename. See
1378  * gtk_file_chooser_set_preview_widget_active().
1379  * 
1380  * Return value: %TRUE if the preview widget is active for the current filename.
1381  *
1382  * Since: 2.4
1383  **/
1384 gboolean
1385 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1386 {
1387   gboolean active;
1388   
1389   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1390
1391   g_object_get (chooser, "preview-widget-active", &active, NULL);
1392
1393   return active;
1394 }
1395
1396 /**
1397  * gtk_file_chooser_set_use_preview_label:
1398  * @chooser: a #GtkFileChooser
1399  * @use_label: whether to display a stock label with the name of the previewed file
1400  * 
1401  * Sets whether the file chooser should display a stock label with the name of
1402  * the file that is being previewed; the default is %TRUE.  Applications that
1403  * want to draw the whole preview area themselves should set this to %FALSE and
1404  * display the name themselves in their preview widget.
1405  *
1406  * See also: gtk_file_chooser_set_preview_widget()
1407  *
1408  * Since: 2.4
1409  **/
1410 void
1411 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1412                                         gboolean        use_label)
1413 {
1414   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1415
1416   g_object_set (chooser, "use-preview-label", use_label, NULL);
1417 }
1418
1419 /**
1420  * gtk_file_chooser_get_use_preview_label:
1421  * @chooser: a #GtkFileChooser
1422  * 
1423  * Gets whether a stock label should be drawn with the name of the previewed
1424  * file.  See gtk_file_chooser_set_use_preview_label().
1425  * 
1426  * Return value: %TRUE if the file chooser is set to display a label with the
1427  * name of the previewed file, %FALSE otherwise.
1428  **/
1429 gboolean
1430 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1431 {
1432   gboolean use_label;
1433   
1434   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1435
1436   g_object_get (chooser, "use-preview-label", &use_label, NULL);
1437
1438   return use_label;
1439 }
1440
1441 /**
1442  * gtk_file_chooser_get_preview_file:
1443  * @chooser: a #GtkFileChooser
1444  * 
1445  * Gets the #GFile that should be previewed in a custom preview
1446  * Internal function, see gtk_file_chooser_get_preview_uri().
1447  * 
1448  * Return value: the #GFile for the file to preview, or %NULL if no file
1449  *  is selected. Free with g_object_unref().
1450  *
1451  * Since: 2.14
1452  **/
1453 GFile *
1454 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
1455 {
1456   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1457
1458   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
1459 }
1460
1461 /**
1462  * _gtk_file_chooser_add_shortcut_folder:
1463  * @chooser: a #GtkFileChooser
1464  * @file: file for the folder to add
1465  * @error: location to store error, or %NULL
1466  * 
1467  * Adds a folder to be displayed with the shortcut folders in a file chooser.
1468  * Internal function, see gtk_file_chooser_add_shortcut_folder().
1469  * 
1470  * Return value: %TRUE if the folder could be added successfully, %FALSE
1471  * otherwise.
1472  *
1473  * Since: 2.4
1474  **/
1475 gboolean
1476 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser  *chooser,
1477                                        GFile           *file,
1478                                        GError         **error)
1479 {
1480   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1481   g_return_val_if_fail (G_IS_FILE (file), FALSE);
1482
1483   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1484 }
1485
1486 /**
1487  * _gtk_file_chooser_remove_shortcut_folder:
1488  * @chooser: a #GtkFileChooser
1489  * @file: file for the folder to remove
1490  * @error: location to store error, or %NULL
1491  * 
1492  * Removes a folder from the shortcut folders in a file chooser.  Internal
1493  * function, see gtk_file_chooser_remove_shortcut_folder().
1494  * 
1495  * Return value: %TRUE if the folder could be removed successfully, %FALSE
1496  * otherwise.
1497  *
1498  * Since: 2.4
1499  **/
1500 gboolean
1501 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser  *chooser,
1502                                           GFile           *file,
1503                                           GError         **error)
1504 {
1505   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1506   g_return_val_if_fail (G_IS_FILE (file), FALSE);
1507
1508   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1509 }
1510
1511 /**
1512  * gtk_file_chooser_get_preview_filename:
1513  * @chooser: a #GtkFileChooser
1514  * 
1515  * Gets the filename that should be previewed in a custom preview
1516  * widget. See gtk_file_chooser_set_preview_widget().
1517  * 
1518  * Return value: the filename to preview, or %NULL if no file
1519  *  is selected, or if the selected file cannot be represented
1520  *  as a local filename. Free with g_free()
1521  *
1522  * Since: 2.4
1523  **/
1524 char *
1525 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1526 {
1527   GFile *file;
1528   gchar *result = NULL;
1529   
1530   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1531
1532   file = gtk_file_chooser_get_preview_file (chooser);
1533   if (file)
1534     {
1535       result = g_file_get_path (file);
1536       g_object_unref (file);
1537     }
1538
1539   return result;
1540 }
1541
1542 /**
1543  * gtk_file_chooser_get_preview_uri:
1544  * @chooser: a #GtkFileChooser
1545  * 
1546  * Gets the URI that should be previewed in a custom preview
1547  * widget. See gtk_file_chooser_set_preview_widget().
1548  * 
1549  * Return value: the URI for the file to preview, or %NULL if no file is
1550  * selected. Free with g_free().
1551  *
1552  * Since: 2.4
1553  **/
1554 char *
1555 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1556 {
1557   GFile *file;
1558   gchar *result = NULL;
1559   
1560   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1561
1562   file = gtk_file_chooser_get_preview_file (chooser);
1563   if (file)
1564     {
1565       result = g_file_get_uri (file);
1566       g_object_unref (file);
1567     }
1568
1569   return result;
1570 }
1571
1572 /**
1573  * gtk_file_chooser_set_extra_widget:
1574  * @chooser: a #GtkFileChooser
1575  * @extra_widget: widget for extra options
1576  * 
1577  * Sets an application-supplied widget to provide extra options to the user.
1578  *
1579  * Since: 2.4
1580  **/
1581 void
1582 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1583                                    GtkWidget      *extra_widget)
1584 {
1585   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1586
1587   g_object_set (chooser, "extra-widget", extra_widget, NULL);
1588 }
1589
1590 /**
1591  * gtk_file_chooser_get_extra_widget:
1592  * @chooser: a #GtkFileChooser
1593  * 
1594  * Gets the current preview widget; see
1595  * gtk_file_chooser_set_extra_widget().
1596  * 
1597  * Return value: the current extra widget, or %NULL
1598  *
1599  * Since: 2.4
1600  **/
1601 GtkWidget *
1602 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1603 {
1604   GtkWidget *extra_widget;
1605   
1606   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1607
1608   g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1609   
1610   /* Horrid hack; g_object_get() refs returned objects but
1611    * that contradicts the memory management conventions
1612    * for accessors.
1613    */
1614   if (extra_widget)
1615     g_object_unref (extra_widget);
1616
1617   return extra_widget;
1618 }
1619
1620 /**
1621  * gtk_file_chooser_add_filter:
1622  * @chooser: a #GtkFileChooser
1623  * @filter: a #GtkFileFilter
1624  * 
1625  * Adds @filter to the list of filters that the user can select between.
1626  * When a filter is selected, only files that are passed by that
1627  * filter are displayed. 
1628  * 
1629  * Note that the @chooser takes ownership of the filter, so you have to 
1630  * ref and sink it if you want to keep a reference.
1631  *
1632  * Since: 2.4
1633  **/
1634 void
1635 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1636                              GtkFileFilter  *filter)
1637 {
1638   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1639
1640   GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1641 }
1642
1643 /**
1644  * gtk_file_chooser_remove_filter:
1645  * @chooser: a #GtkFileChooser
1646  * @filter: a #GtkFileFilter
1647  * 
1648  * Removes @filter from the list of filters that the user can select between.
1649  *
1650  * Since: 2.4
1651  **/
1652 void
1653 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1654                                 GtkFileFilter  *filter)
1655 {
1656   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1657
1658   GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1659 }
1660
1661 /**
1662  * gtk_file_chooser_list_filters:
1663  * @chooser: a #GtkFileChooser
1664  * 
1665  * Lists the current set of user-selectable filters; see
1666  * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1667  * 
1668  * Return value: a #GSList containing the current set of
1669  *  user selectable filters. The contents of the list are
1670  *  owned by GTK+, but you must free the list itself with
1671  *  g_slist_free() when you are done with it.
1672  *
1673  * Since: 2.4
1674  **/
1675 GSList *
1676 gtk_file_chooser_list_filters  (GtkFileChooser *chooser)
1677 {
1678   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1679
1680   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1681 }
1682
1683 /**
1684  * gtk_file_chooser_set_filter:
1685  * @chooser: a #GtkFileChooser
1686  * @filter: a #GtkFileFilter
1687  * 
1688  * Sets the current filter; only the files that pass the
1689  * filter will be displayed. If the user-selectable list of filters
1690  * is non-empty, then the filter should be one of the filters
1691  * in that list. Setting the current filter when the list of
1692  * filters is empty is useful if you want to restrict the displayed
1693  * set of files without letting the user change it.
1694  *
1695  * Since: 2.4
1696  **/
1697 void
1698 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1699                              GtkFileFilter  *filter)
1700 {
1701   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1702   g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1703
1704   g_object_set (chooser, "filter", filter, NULL);
1705 }
1706
1707 /**
1708  * gtk_file_chooser_get_filter:
1709  * @chooser: a #GtkFileChooser
1710  * 
1711  * Gets the current filter; see gtk_file_chooser_set_filter().
1712  * 
1713  * Return value: the current filter, or %NULL
1714  *
1715  * Since: 2.4
1716  **/
1717 GtkFileFilter *
1718 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1719 {
1720   GtkFileFilter *filter;
1721   
1722   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1723
1724   g_object_get (chooser, "filter", &filter, NULL);
1725   /* Horrid hack; g_object_get() refs returned objects but
1726    * that contradicts the memory management conventions
1727    * for accessors.
1728    */
1729   if (filter)
1730     g_object_unref (filter);
1731
1732   return filter;
1733 }
1734
1735 /**
1736  * gtk_file_chooser_add_shortcut_folder:
1737  * @chooser: a #GtkFileChooser
1738  * @folder: filename of the folder to add
1739  * @error: location to store error, or %NULL
1740  * 
1741  * Adds a folder to be displayed with the shortcut folders in a file chooser.
1742  * Note that shortcut folders do not get saved, as they are provided by the
1743  * application.  For example, you can use this to add a
1744  * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
1745  * 
1746  * Return value: %TRUE if the folder could be added successfully, %FALSE
1747  * otherwise.  In the latter case, the @error will be set as appropriate.
1748  *
1749  * Since: 2.4
1750  **/
1751 gboolean
1752 gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
1753                                       const char        *folder,
1754                                       GError           **error)
1755 {
1756   GFile *file;
1757   gboolean result;
1758
1759   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1760   g_return_val_if_fail (folder != NULL, FALSE);
1761
1762   file = g_file_new_for_path (folder);
1763   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1764   g_object_unref (file);
1765
1766   return result;
1767 }
1768
1769 /**
1770  * gtk_file_chooser_remove_shortcut_folder:
1771  * @chooser: a #GtkFileChooser
1772  * @folder: filename of the folder to remove
1773  * @error: location to store error, or %NULL
1774  * 
1775  * Removes a folder from a file chooser's list of shortcut folders.
1776  * 
1777  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
1778  * In the latter case, the @error will be set as appropriate.
1779  *
1780  * See also: gtk_file_chooser_add_shortcut_folder()
1781  *
1782  * Since: 2.4
1783  **/
1784 gboolean
1785 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
1786                                          const char        *folder,
1787                                          GError           **error)
1788 {
1789   GFile *file;
1790   gboolean result;
1791
1792   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1793   g_return_val_if_fail (folder != NULL, FALSE);
1794
1795   file = g_file_new_for_path (folder);
1796   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1797   g_object_unref (file);
1798
1799   return result;
1800 }
1801
1802 /**
1803  * gtk_file_chooser_list_shortcut_folders:
1804  * @chooser: a #GtkFileChooser
1805  * 
1806  * Queries the list of shortcut folders in the file chooser, as set by
1807  * gtk_file_chooser_add_shortcut_folder().
1808  * 
1809  * Return value: A list of folder filenames, or %NULL if there are no shortcut
1810  * folders.  Free the returned list with g_slist_free(), and the filenames with
1811  * g_free().
1812  *
1813  * Since: 2.4
1814  **/
1815 GSList *
1816 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1817 {
1818   GSList *folders;
1819   GSList *result;
1820
1821   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1822
1823   folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1824
1825   result = files_to_strings (folders, g_file_get_path);
1826   g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1827   g_slist_free (folders);
1828
1829   return result;
1830 }
1831
1832 /**
1833  * gtk_file_chooser_add_shortcut_folder_uri:
1834  * @chooser: a #GtkFileChooser
1835  * @uri: URI of the folder to add
1836  * @error: location to store error, or %NULL
1837  * 
1838  * Adds a folder URI to be displayed with the shortcut folders in a file
1839  * chooser.  Note that shortcut folders do not get saved, as they are provided
1840  * by the application.  For example, you can use this to add a
1841  * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
1842  * 
1843  * Return value: %TRUE if the folder could be added successfully, %FALSE
1844  * otherwise.  In the latter case, the @error will be set as appropriate.
1845  *
1846  * Since: 2.4
1847  **/
1848 gboolean
1849 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser    *chooser,
1850                                           const char        *uri,
1851                                           GError           **error)
1852 {
1853   GFile *file;
1854   gboolean result;
1855
1856   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1857   g_return_val_if_fail (uri != NULL, FALSE);
1858
1859   file = g_file_new_for_uri (uri);
1860   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
1861   g_object_unref (file);
1862
1863   return result;
1864 }
1865
1866 /**
1867  * gtk_file_chooser_remove_shortcut_folder_uri:
1868  * @chooser: a #GtkFileChooser
1869  * @uri: URI of the folder to remove
1870  * @error: location to store error, or %NULL
1871  * 
1872  * Removes a folder URI from a file chooser's list of shortcut folders.
1873  * 
1874  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
1875  * In the latter case, the @error will be set as appropriate.
1876  *
1877  * See also: gtk_file_chooser_add_shortcut_folder_uri()
1878  *
1879  * Since: 2.4
1880  **/
1881 gboolean
1882 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser    *chooser,
1883                                              const char        *uri,
1884                                              GError           **error)
1885 {
1886   GFile *file;
1887   gboolean result;
1888
1889   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1890   g_return_val_if_fail (uri != NULL, FALSE);
1891
1892   file = g_file_new_for_uri (uri);
1893   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
1894   g_object_unref (file);
1895
1896   return result;
1897 }
1898
1899 /**
1900  * gtk_file_chooser_list_shortcut_folder_uris:
1901  * @chooser: a #GtkFileChooser
1902  * 
1903  * Queries the list of shortcut folders in the file chooser, as set by
1904  * gtk_file_chooser_add_shortcut_folder_uri().
1905  * 
1906  * Return value: A list of folder URIs, or %NULL if there are no shortcut
1907  * folders.  Free the returned list with g_slist_free(), and the URIs with
1908  * g_free().
1909  *
1910  * Since: 2.4
1911  **/
1912 GSList *
1913 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
1914 {
1915   GSList *folders;
1916   GSList *result;
1917
1918   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1919
1920   folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
1921
1922   result = files_to_strings (folders, g_file_get_uri);
1923   g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
1924   g_slist_free (folders);
1925
1926   return result;
1927 }
1928
1929 GSList *
1930 _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
1931 {
1932   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1933
1934   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1935 }
1936
1937 /**
1938  * gtk_file_chooser_set_show_hidden:
1939  * @chooser: a #GtkFileChooser
1940  * @show_hidden: %TRUE if hidden files and folders should be displayed.
1941  * 
1942  * Sets whether hidden files and folders are displayed in the file selector.  
1943  *
1944  * Since: 2.6
1945  **/
1946 void
1947 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
1948                                   gboolean        show_hidden)
1949 {
1950   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1951
1952   g_object_set (chooser, "show-hidden", show_hidden, NULL);
1953 }
1954
1955 /**
1956  * gtk_file_chooser_get_show_hidden:
1957  * @chooser: a #GtkFileChooser
1958  * 
1959  * Gets whether hidden files and folders are displayed in the file selector.   
1960  * See gtk_file_chooser_set_show_hidden().
1961  * 
1962  * Return value: %TRUE if hidden files and folders are displayed.
1963  *
1964  * Since: 2.6
1965  **/
1966 gboolean
1967 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
1968 {
1969   gboolean show_hidden;
1970   
1971   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1972
1973   g_object_get (chooser, "show-hidden", &show_hidden, NULL);
1974
1975   return show_hidden;
1976 }
1977
1978 /**
1979  * gtk_file_chooser_set_do_overwrite_confirmation:
1980  * @chooser: a #GtkFileChooser
1981  * @do_overwrite_confirmation: whether to confirm overwriting in save mode
1982  * 
1983  * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
1984  * a confirmation dialog if the user types a file name that already exists.  This
1985  * is %FALSE by default.
1986  *
1987  * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
1988  * signal when appropriate.
1989  *
1990  * If all you need is the stock confirmation dialog, set this property to %TRUE.
1991  * You can override the way confirmation is done by actually handling the
1992  * "confirm-overwrite" signal; please refer to its documentation for the
1993  * details.
1994  *
1995  * Since: 2.8
1996  **/
1997 void
1998 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
1999                                                 gboolean        do_overwrite_confirmation)
2000 {
2001   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2002
2003   g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
2004 }
2005
2006 /**
2007  * gtk_file_chooser_get_do_overwrite_confirmation:
2008  * @chooser: a #GtkFileChooser
2009  * 
2010  * Queries whether a file chooser is set to confirm for overwriting when the user
2011  * types a file name that already exists.
2012  * 
2013  * Return value: %TRUE if the file chooser will present a confirmation dialog;
2014  * %FALSE otherwise.
2015  *
2016  * Since: 2.8
2017  **/
2018 gboolean
2019 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
2020 {
2021   gboolean do_overwrite_confirmation;
2022
2023   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2024
2025   g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
2026
2027   return do_overwrite_confirmation;
2028 }
2029
2030 #if defined (G_OS_WIN32) && !defined (_WIN64)
2031
2032 /* DLL ABI stability backward compatibility versions */
2033
2034 #undef gtk_file_chooser_get_filename
2035
2036 gchar *
2037 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
2038 {
2039   gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
2040   gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2041
2042   g_free (utf8_filename);
2043
2044   return retval;
2045 }
2046
2047 #undef gtk_file_chooser_set_filename
2048
2049 gboolean
2050 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
2051                                const gchar    *filename)
2052 {
2053   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2054   gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
2055
2056   g_free (utf8_filename);
2057
2058   return retval;
2059 }
2060
2061 #undef gtk_file_chooser_select_filename
2062
2063 gboolean
2064 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2065                                   const gchar    *filename)
2066 {
2067   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2068   gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2069
2070   g_free (utf8_filename);
2071
2072   return retval;
2073 }
2074
2075 #undef gtk_file_chooser_unselect_filename
2076
2077 void
2078 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2079                                     const char     *filename)
2080 {
2081   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2082
2083   gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2084   g_free (utf8_filename);
2085 }
2086
2087 #undef gtk_file_chooser_get_filenames
2088
2089 GSList *
2090 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2091 {
2092   GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2093   GSList *rover = list;
2094   
2095   while (rover)
2096     {
2097       gchar *tem = (gchar *) rover->data;
2098       rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2099       g_free (tem);
2100       rover = rover->next;
2101     }
2102
2103   return list;
2104 }
2105
2106 #undef gtk_file_chooser_set_current_folder
2107
2108 gboolean
2109 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2110                                      const gchar    *filename)
2111 {
2112   gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2113   gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2114
2115   g_free (utf8_filename);
2116
2117   return retval;
2118 }
2119
2120 #undef gtk_file_chooser_get_current_folder
2121
2122 gchar *
2123 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2124 {
2125   gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2126   gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2127
2128   g_free (utf8_folder);
2129
2130   return retval;
2131 }
2132
2133 #undef gtk_file_chooser_get_preview_filename
2134
2135 char *
2136 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2137 {
2138   char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2139   char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2140
2141   g_free (utf8_filename);
2142
2143   return retval;
2144 }
2145
2146 #undef gtk_file_chooser_add_shortcut_folder
2147
2148 gboolean
2149 gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
2150                                       const char        *folder,
2151                                       GError           **error)
2152 {
2153   char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2154   gboolean retval =
2155     gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2156
2157   g_free (utf8_folder);
2158
2159   return retval;
2160 }
2161
2162 #undef gtk_file_chooser_remove_shortcut_folder
2163
2164 gboolean
2165 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
2166                                          const char        *folder,
2167                                          GError           **error)
2168 {
2169   char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2170   gboolean retval =
2171     gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2172
2173   g_free (utf8_folder);
2174
2175   return retval;
2176 }
2177
2178 #undef gtk_file_chooser_list_shortcut_folders
2179
2180 GSList *
2181 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2182 {
2183   GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2184   GSList *rover = list;
2185   
2186   while (rover)
2187     {
2188       gchar *tem = (gchar *) rover->data;
2189       rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2190       g_free (tem);
2191       rover = rover->next;
2192     }
2193
2194   return list;
2195 }
2196
2197 #endif
2198
2199 #define __GTK_FILE_CHOOSER_C__
2200 #include "gtkaliasdef.c"