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