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