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