]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooser.c
Add over-big test case for preview (much of size from a modified copy of
[~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 "gtkfilechooser.h"
22 #include "gtkfilechooserprivate.h"
23 #include "gtkfilechooserenums.h"
24 #include "gtkfilesystem.h"
25
26 #define _(str) (str)
27
28 static void gtk_file_chooser_base_init (gpointer g_iface);
29
30 static GtkFilePath *gtk_file_chooser_get_path         (GtkFileChooser *chooser);
31
32 GType
33 gtk_file_chooser_get_type (void)
34 {
35   static GType file_chooser_type = 0;
36
37   if (!file_chooser_type)
38     {
39       static const GTypeInfo file_chooser_info =
40       {
41         sizeof (GtkFileChooserIface),  /* class_size */
42         gtk_file_chooser_base_init,    /* base_init */
43         NULL,                          /* base_finalize */
44       };
45
46       file_chooser_type = g_type_register_static (G_TYPE_INTERFACE,
47                                                   "GtkFileChooser",
48                                                   &file_chooser_info, 0);
49
50       g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
51     }
52
53   return file_chooser_type;
54 }
55
56 static void
57 gtk_file_chooser_base_init (gpointer g_iface)
58 {
59   static gboolean initialized = FALSE;
60   
61   if (!initialized)
62     {
63       GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
64
65       g_signal_new ("current-folder-changed",
66                     iface_type,
67                     G_SIGNAL_RUN_LAST,
68                     G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
69                     NULL, NULL,
70                     g_cclosure_marshal_VOID__VOID,
71                     G_TYPE_NONE, 0);
72       g_signal_new ("selection-changed",
73                     iface_type,
74                     G_SIGNAL_RUN_LAST,
75                     G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
76                     NULL, NULL,
77                     g_cclosure_marshal_VOID__VOID,
78                     G_TYPE_NONE, 0);
79       g_signal_new ("update-preview",
80                     iface_type,
81                     G_SIGNAL_RUN_LAST,
82                     G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
83                     NULL, NULL,
84                     g_cclosure_marshal_VOID__VOID,
85                     G_TYPE_NONE, 0);
86
87       g_object_interface_install_property (g_iface,
88                                            g_param_spec_enum ("action",
89                                                               _("Action"),
90                                                               _("The type of operation that the file selector is performing"),
91                                                               GTK_TYPE_FILE_CHOOSER_ACTION,
92                                                               GTK_FILE_CHOOSER_ACTION_OPEN,
93                                                               G_PARAM_READWRITE));
94       g_object_interface_install_property (g_iface,
95                                            g_param_spec_object ("file-system",
96                                                                 _("File System"),
97                                                                 _("File system object to use"),
98                                                                 GTK_TYPE_FILE_SYSTEM,
99                                                                 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
100       g_object_interface_install_property (g_iface,
101                                            g_param_spec_object ("filter",
102                                                                 _("Filter"),
103                                                                 _("The current filter for selecting which files are displayed"),
104                                                                 GTK_TYPE_FILE_FILTER,
105                                                                 G_PARAM_READWRITE));
106       g_object_interface_install_property (g_iface,
107                                            g_param_spec_boolean ("folder-mode",
108                                                                  _("Folder Mode"),
109                                                                  _("Whether to select folders rather than files"),
110                                                                  FALSE,
111                                                                  G_PARAM_READWRITE));
112       g_object_interface_install_property (g_iface,
113                                            g_param_spec_boolean ("local-only",
114                                                                  _("Local Only"),
115                                                                  _("Whether the selected file(s) should be limited to local file: URLs"),
116                                                                  TRUE,
117                                                                  G_PARAM_READWRITE));
118       g_object_interface_install_property (g_iface,
119                                            g_param_spec_object ("preview-widget",
120                                                                 _("Preview widget"),
121                                                                 _("Application supplied widget for custom previews."),
122                                                                 GTK_TYPE_WIDGET,
123                                                                 G_PARAM_READWRITE));
124       g_object_interface_install_property (g_iface,
125                                            g_param_spec_boolean ("preview-widget-active",
126                                                                  _("Preview Widget Active"),
127                                                                  _("Whether the application supplied widget for custom previews should be shown."),
128                                                                  TRUE,
129                                                                  G_PARAM_READWRITE));
130       g_object_interface_install_property (g_iface,
131                                            g_param_spec_boolean ("select-multiple",
132                                                                  _("Select Multiple"),
133                                                                  _("Whether to allow multiple files to be selected"),
134                                                                  FALSE,
135                                                                  G_PARAM_READWRITE));
136       
137       g_object_interface_install_property (g_iface,
138                                            g_param_spec_boolean ("show-hidden",
139                                                                  _("Show Hidden"),
140                                                                  _("Whether the hidden files and folders should be displayed"),
141                                                                  FALSE,
142                                                                  G_PARAM_READWRITE));
143       initialized = TRUE;
144     }
145 }
146
147 /**
148  * gtk_file_chooser_set_action:
149  * @chooser: a #GtkFileChooser
150  * @action: the action that the file selector is performing
151  * 
152  * Sets the type of operation that that the chooser is performing; the
153  * user interface is adapted to suit the selected action. For example,
154  * an option to create a new folder might be shown if the action is
155  * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
156  * %GTK_FILE_CHOOSER_ACTION_OPEN.
157  **/
158 void
159 gtk_file_chooser_set_action (GtkFileChooser       *chooser,
160                              GtkFileChooserAction  action)
161 {
162   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
163
164   g_object_set (chooser, "action", action, NULL);
165 }
166
167 /**
168  * gtk_file_chooser_get_action:
169  * @chooser: a #GtkFileChooser
170  * 
171  * Gets the type of operation that the file chooser is performing; see
172  * gtk_file_chooser_set_action().
173  * 
174  * Return value: the action that the file selector is performing
175  **/
176 GtkFileChooserAction
177 gtk_file_chooser_get_action (GtkFileChooser *chooser)
178 {
179   GtkFileChooserAction action;
180   
181   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
182
183   g_object_get (chooser, "action", &action, NULL);
184
185   return action;
186 }
187
188 /**
189  * gtk_file_chooser_set_folder_mode:
190  * @chooser: a #GtkFileChooser
191  * @folder_mode: %TRUE if the file chooser is used to select folders
192  *               rather than files.
193  * 
194  * Sets whether the file chooser is used to select folders
195  * rather than files. If in folder mode, only folders are displayed
196  * to the use, and not the individual files inside the folders
197  * and the user selects a single folder rather than one or
198  * more files.
199  **/
200 void
201 gtk_file_chooser_set_folder_mode (GtkFileChooser *chooser,
202                                   gboolean        folder_mode)
203 {
204   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
205
206   g_object_set (chooser, "folder-mode", folder_mode, NULL);
207 }
208
209 /**
210  * gtk_file_chooser_get_folder_mode:
211  * @chooser: a #GtkFileChooser
212  * 
213  * Gets whether the file chooser is used to select folders
214  * rather than files. See gtk_file_chooser_set_folder_mode()
215  * 
216  * Return value: %TRUE if the file chooser is used to select
217                  folders rather than files.
218  **/
219 gboolean
220 gtk_file_chooser_get_folder_mode (GtkFileChooser *chooser)
221 {
222   gboolean folder_mode;
223   
224   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
225
226   g_object_get (chooser, "folder-mode", &folder_mode, NULL);
227
228   return folder_mode;
229 }
230
231 /**
232  * gtk_file_chooser_set_local_only:
233  * @chooser: a #GtkFileChooser
234  * @local_only: %TRUE if only local files can be selected
235  * 
236  * Sets whether only local files can be selected in the
237  * file selector. If @local_only is %TRUE (the default),
238  * then the selected file are files are guaranteed to be
239  * accessible through the operating systems native file
240  * file system and therefore the application only
241  * needs to worry about the filename functions in
242  * #GtkFileChooser, like gtk_file_chooser_get_filename(),
243  * rather than the URI functions like
244  * gtk_file_chooser_get_uri(),
245  **/
246 void
247 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
248                                  gboolean        local_only)
249 {
250   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
251
252   g_object_set (chooser, "local-only", local_only, NULL);
253 }
254
255 /**
256  * gtk_file_chooser_get_local_only:
257  * @chooser: a #GtkFileChoosre
258  * 
259  * Gets whether only local files can be selected in the
260  * file selector. See gtk_file_chooser_set_local_only()
261  * 
262  * Return value: %TRUE if only local files can be selected.
263  **/
264 gboolean
265 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
266 {
267   gboolean local_only;
268   
269   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
270
271   g_object_get (chooser, "local-only", &local_only, NULL);
272
273   return local_only;
274 }
275
276 /**
277  * gtk_file_chooser_set_select_multiple:
278  * @chooser: a #GtkFileChooser
279  * @select_multiple: %TRUE if multiple files can be selected.
280  * 
281  * Sets whether multiple files can be selected in the file
282  * selector. If the file selector if in folder mode (see
283  * gtk_file_selector_set_folder_mode()) then only one folder
284  * can be selected, without regard to this setting.
285  **/
286 void
287 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
288                                       gboolean        select_multiple)
289 {
290   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
291
292   g_object_set (chooser, "select-multiple", select_multiple, NULL);
293 }
294
295 /**
296  * gtk_file_chooser_get_select_multiple:
297  * @chooser: a #GtkFileChooser
298  * 
299  * Gets whether multiple files can be selected in the file
300  * selector. See gtk_file_chooser_set_select_multiple().
301  * 
302  * Return value: %TRUE if multiple files can be selected.
303  **/
304 gboolean
305 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
306 {
307   gboolean select_multiple;
308   
309   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
310
311   g_object_get (chooser, "select-multiple", &select_multiple, NULL);
312
313   return select_multiple;
314 }
315
316 /**
317  * gtk_file_chooser_get_filename:
318  * @chooser: a #GtkFileChooser
319  * 
320  * Gets the filename for the currently selected file in
321  * the file selector. If multiple files are selected,
322  * one of the filenames will be returned at random.
323  * 
324  * Return value: The currently selected filename, or %NULL
325  *  if no file is selected, or the selected file can't
326  *  be represented with a local filename. Free with g_free().
327  **/
328 gchar *
329 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
330 {
331   GtkFileSystem *file_system;
332   GtkFilePath *path;
333   gchar *result = NULL;
334   
335   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
336
337   file_system = _gtk_file_chooser_get_file_system (chooser);
338   path = gtk_file_chooser_get_path (chooser);
339   if (path)
340     {
341       result = gtk_file_system_path_to_filename (file_system, path);
342       gtk_file_path_free (path);
343     }
344
345   return result;
346 }
347
348 /**
349  * gtk_file_chooser_set_filename:
350  * @chooser: a #GtkFileChooser
351  * @filename: the filename to set as current
352  * 
353  * Sets @filename as the current filename for the the file chooser;
354  * If the file name isn't in the current folder of @chooser, then the
355  * current folder of @chooser will be changed to the folder containing
356  * @filename. This is equivalent to a sequence of
357  * gtk_file_chooser_unselect_all() followed by gtk_file_chooser_select_filename().
358  *
359  * Note that the file must exist, or nothing will be done except
360  * for the directory change. To pre-enter a filename for the user, as in
361  * a save-as dialog, use gtk_file_chooser_set_current_name()
362  **/
363 void
364 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
365                                const gchar    *filename)
366 {
367   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
368
369   gtk_file_chooser_unselect_all (chooser);
370   gtk_file_chooser_select_filename (chooser, filename);
371 }
372
373 /**
374  * gtk_file_chooser_select_filename:
375  * @chooser: a #GtkFileChooser
376  * @filename: the filename to select
377  * 
378  * Selects a filename. If the file name isn't in the current
379  * folder of @chooser, then the current folder of @chooser will
380  * be changed to the folder containing @filename.
381  **/
382 void
383 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
384                                   const gchar    *filename)
385 {
386   GtkFileSystem *file_system;
387   GtkFilePath *path;
388   
389   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
390   g_return_if_fail (filename != NULL);
391
392   file_system = _gtk_file_chooser_get_file_system (chooser);
393
394   path = gtk_file_system_filename_to_path (file_system, filename);
395   if (path)
396     {
397       _gtk_file_chooser_select_path (chooser, path);
398       gtk_file_path_free (path);
399     }
400 }
401
402 /**
403  * gtk_file_chooser_unselect_filename:
404  * @chooser: a #GtkFileChooser
405  * @filename: the filename to unselect
406  * 
407  * Unselects a currently selected filename. If the filename
408  * is not in the current directory, does not exist, or
409  * is otherwise not currently selected, does nothing.
410  **/
411 void
412 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
413                                     const char     *filename)
414 {
415   GtkFileSystem *file_system;
416   GtkFilePath *path;
417   
418   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
419   g_return_if_fail (filename != NULL);
420
421   file_system = _gtk_file_chooser_get_file_system (chooser);
422
423   path = gtk_file_system_filename_to_path (file_system, filename);
424   if (path)
425     {
426       _gtk_file_chooser_unselect_path (chooser, path);
427       gtk_file_path_free (path);
428     }
429 }
430
431 /**
432  * gtk_file_chooser_get_filenames:
433  * @chooser: a #GtkFileChooser
434  * 
435  * Lists all the files and subfolders in the current folder of
436  * @chooser. The returned names are full absolute paths. If files
437  * in the current folder cannot be represented as local filenames
438  * they will be ignored. (See gtk_file_chooser_get_uris())
439  * 
440  * Return value: a #GList containing the filenames of all
441  *   files and subfolders in the current folder. Free the returned list
442  *   with g_lists_free(), and the filenames with g_free().
443  **/
444 GSList *
445 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
446 {
447   GtkFileSystem *file_system;
448   GSList *paths;
449   GSList *tmp_list;
450   GSList *result = NULL;
451   
452   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
453
454   file_system = _gtk_file_chooser_get_file_system (chooser);
455   paths = _gtk_file_chooser_get_paths (chooser);
456
457   for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
458     {
459       gchar *filename = gtk_file_system_path_to_filename (file_system, tmp_list->data);
460       if (filename)
461         result = g_slist_prepend (result, filename);
462     }
463
464   gtk_file_paths_free (paths);
465
466   return g_slist_reverse (result);
467 }
468
469 /**
470  * gtk_file_chooser_set_current_folder:
471  * @chooser: a #GtkFileChooser
472  * @filename: the full path of the new current folder
473  * 
474  * Sets the current folder for @chooser from a local filename.
475  * The user will be shown the full contents of the current folder,
476  * plus user interface elements for navigating to other folders.
477  **/
478 void
479 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
480                                      const gchar    *filename)
481 {
482   GtkFileSystem *file_system;
483   GtkFilePath *path;
484   
485   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
486   g_return_if_fail (filename != NULL);
487
488   file_system = _gtk_file_chooser_get_file_system (chooser);
489
490   path = gtk_file_system_filename_to_path (file_system, filename);
491   if (path)
492     {
493       _gtk_file_chooser_set_current_folder_path (chooser, path);
494       gtk_file_path_free (path);
495     }
496 }
497
498 /**
499  * gtk_file_chooser_get_current_folder:
500  * @chooser: a #GtkFileChooser
501  * 
502  * Gets the current folder of @chooser as a local filename.
503  * See gtk_file_chooser_set_current_folder().
504  * 
505  * Return value: the full path of the current folder, or %NULL
506  *  if the current path cannot be represented as a local filename.
507  *  Free with g_free().
508  **/
509 gchar *
510 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
511 {
512   GtkFileSystem *file_system;
513   GtkFilePath *path;
514   gchar *filename;
515   
516   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
517
518   file_system = _gtk_file_chooser_get_file_system (chooser);
519
520   path = _gtk_file_chooser_get_current_folder_path (chooser);
521   filename = gtk_file_system_path_to_filename (file_system, path);
522   gtk_file_path_free (path);
523
524   return filename;
525 }
526
527 /**
528  * gtk_file_chooser_set_current_name:
529  * @chooser: a #GtkFileChooser
530  * @name: the filename to use, as a UTF-8 string
531  * 
532  * Sets the current name in the file selector, as if entered
533  * by the user. Note that the name passed in here is a UTF-8
534  * string rather than a filename. This function is meant for
535  * such uses as a suggested name in a "Save As..." dialog.
536  *
537  * If you want to preselect a particular existing file, you
538  * should use gtk_file_chooser_set_filename() instead.
539  **/
540 void
541 gtk_file_chooser_set_current_name  (GtkFileChooser *chooser,
542                                     const gchar    *name)
543 {
544   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
545   g_return_if_fail (name != NULL);
546   
547   GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
548 }
549
550 /**
551  * gtk_file_chooser_get_uri:
552  * @chooser: a #GtkFileChooser
553  * 
554  * Gets the URI for the currently selected file in
555  * the file selector. If multiple files are selected,
556  * one of the filenames will be returned at random.
557  * 
558  * Return value: The currently selected URI, or %NULL
559  *  if no file is selected. Free with g_free()
560  **/
561 gchar *
562 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
563 {
564   GtkFileSystem *file_system;
565   GtkFilePath *path;
566   gchar *result = NULL;
567   
568   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
569
570   file_system = _gtk_file_chooser_get_file_system (chooser);
571   path = gtk_file_chooser_get_path (chooser);
572   if (path)
573     {
574       result = gtk_file_system_path_to_uri (file_system, path);
575       gtk_file_path_free (path);
576     }
577
578   return result;
579 }
580
581 /**
582  * gtk_file_chooser_set_uri:
583  * @chooser: a #GtkFileChooser
584  * @uri: the URI to set as current
585  * 
586  * Sets the file referred to by @uri as the current file for the the
587  * file chooser; If the file name isn't in the current folder of @chooser,
588  * then the current folder of @chooser will be changed to the folder containing
589  * @uri. This is equivalent to a sequence of gtk_file_chooser_unselect_all()
590  * followed by gtk_file_chooser_select_uri().
591  *
592  * Note that the file must exist, or nothing will be done except
593  * for the directory change. To pre-enter a filename for the user, as in
594  * a save-as dialog, use gtk_file_chooser_set_current_name()
595  **/
596 void
597 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
598                           const char     *uri)
599 {
600   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
601
602   gtk_file_chooser_unselect_all (chooser);
603   gtk_file_chooser_select_uri (chooser, uri);
604 }
605
606 /**
607  * gtk_file_chooser_select_uri:
608  * @chooser: a #GtkFileChooser
609  * @uri: the URI to select
610  * 
611  * Selects the file to by @uri. If the URI doesn't refer to a
612  * file in the current folder of @chooser, then the current folder of
613  * @chooser will be changed to the folder containing @filename.
614  **/
615 void
616 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
617                              const char     *uri)
618 {
619   GtkFileSystem *file_system;
620   GtkFilePath *path;
621   
622   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
623   g_return_if_fail (uri != NULL);
624
625   file_system = _gtk_file_chooser_get_file_system (chooser);
626
627   path = gtk_file_system_uri_to_path (file_system, uri);
628   if (path)
629     {
630       _gtk_file_chooser_select_path (chooser, path);
631       gtk_file_path_free (path);
632     }
633 }
634
635 /**
636  * gtk_file_chooser_unselect_uri:
637  * @chooser: a #GtkFileChooser
638  * @uri: the URI to unselect
639  * 
640  * Unselects the file referred to by @uri. If the file
641  * is not in the current directory, does not exist, or
642  * is otherwise not currently selected, does nothing.
643  **/
644 void
645 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
646                                const char     *uri)
647 {
648   GtkFileSystem *file_system;
649   GtkFilePath *path;
650   
651   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
652   g_return_if_fail (uri != NULL);
653
654   file_system = _gtk_file_chooser_get_file_system (chooser);
655
656   path = gtk_file_system_uri_to_path (file_system, uri);
657   if (path)
658     {
659       _gtk_file_chooser_unselect_path (chooser, path);
660       gtk_file_path_free (path);
661     }
662 }
663
664 void
665 gtk_file_chooser_select_all (GtkFileChooser *chooser)
666 {
667   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
668   
669   GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
670 }
671
672 void
673 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
674 {
675
676   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
677   
678   GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
679 }
680
681 /**
682  * gtk_file_chooser_get_filenames:
683  * @chooser: a #GtkFileChooser
684  * 
685  * Lists all the files and subfolders in the current folder of
686  * @chooser. The returned names are full absolute URIs.
687  * 
688  * Return value: a #GList containing the URIs of all
689  *   files and subfolders in the current folder. Free the returned list
690  *   with g_lists_free(), and the filenames with g_free().
691  **/
692 GSList *
693 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
694 {
695   GtkFileSystem *file_system;
696   GSList *paths;
697   GSList *tmp_list;
698   GSList *result = NULL;
699   
700   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
701
702   file_system = _gtk_file_chooser_get_file_system (chooser);
703   paths = _gtk_file_chooser_get_paths (chooser);
704
705   for (tmp_list = paths; tmp_list; tmp_list = tmp_list->next)
706     {
707       gchar *uri = gtk_file_system_path_to_uri (file_system, tmp_list->data);
708       if (uri)
709         result = g_slist_prepend (result, uri);
710     }
711
712   gtk_file_paths_free (paths);
713
714   return g_slist_reverse (result);
715 }
716
717 /**
718  * gtk_file_chooser_set_current_folder_uri:
719  * @chooser: a #GtkFileChooser
720  * @uri: the URI for the new current folder
721  * 
722  * Sets the current folder for @chooser from an URI.
723  * The user will be shown the full contents of the current folder,
724  * plus user interface elements for navigating to other folders.
725  **/
726 void
727 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
728                                          const gchar    *uri)
729 {
730   GtkFileSystem *file_system;
731   GtkFilePath *path;
732   
733   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
734   g_return_if_fail (uri != NULL);
735
736   file_system = _gtk_file_chooser_get_file_system (chooser);
737
738   path = gtk_file_system_uri_to_path (file_system, uri);
739   if (path)
740     {
741       _gtk_file_chooser_set_current_folder_path (chooser, path);
742       gtk_file_path_free (path);
743     }
744 }
745
746 /**
747  * gtk_file_chooser_get_current_folder_uri:
748  * @chooser: a #GtkFileChooser
749  * 
750  * Gets the current folder of @chooser as an URI.
751  * See gtk_file_chooser_set_current_folder_uri().
752  * 
753  * Return value: the URI for the current folder.
754  *  Free with g_free().
755  */
756 gchar *
757 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
758 {
759   GtkFileSystem *file_system;
760   GtkFilePath *path;
761   gchar *uri;
762   
763   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
764
765   file_system = _gtk_file_chooser_get_file_system (chooser);
766
767   path = _gtk_file_chooser_get_current_folder_path (chooser);
768   uri = gtk_file_system_path_to_uri (file_system, path);
769   gtk_file_path_free (path);
770
771   return uri;
772 }
773
774 /**
775  * _gtk_file_chooser_set_current_folder_path:
776  * @chooser: a #GtkFileChooser
777  * @path: the #GtkFilePath for the new folder
778  * 
779  * Sets the current folder for @chooser from a #GtkFilePath.
780  * Internal function, see gtk_file_chooser_set_current_folder_uri().
781  **/
782 void
783 _gtk_file_chooser_set_current_folder_path (GtkFileChooser    *chooser,
784                                            const GtkFilePath *path)
785 {
786   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
787   g_return_if_fail (path != NULL);
788
789   GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, path);
790 }
791
792 /**
793  * _gtk_file_chooser_get_current_folder_path:
794  * @chooser: a #GtkFileChooser
795  * 
796  * Gets the current folder of @chooser as #GtkFilePath.
797  * See gtk_file_chooser_get_current_folder_uri().
798  * 
799  * Return value: the #GtkFilePath for the current folder.
800  * Fre with  gtk_file_path_free ().
801  */
802 GtkFilePath *
803 _gtk_file_chooser_get_current_folder_path (GtkFileChooser *chooser)
804 {
805   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
806
807   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);  
808 }
809
810 /**
811  * _gtk_file_chooser_select_path:
812  * @chooser: a #GtkFileChooser
813  * @path: the path to select
814  * 
815  * Selects the file referred to by @path. An internal function. See
816  * _gtk_file_chooser_select_uri().
817  **/
818 void
819 _gtk_file_chooser_select_path (GtkFileChooser    *chooser,
820                                const GtkFilePath *path)
821 {
822   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
823
824   GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_path (chooser, path);
825 }
826
827 /**
828  * _gtk_file_chooser_unselect_path:
829  * @chooser: a #GtkFileChooser
830  * @path: the filename to path
831  * 
832  * Unselects the file referred to by @path. An internal
833  * function. See _gtk_file_chooser_unselect_uri().
834  **/
835 void
836 _gtk_file_chooser_unselect_path (GtkFileChooser    *chooser,
837                                  const GtkFilePath *path)
838 {
839   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
840
841   GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_path (chooser, path);
842 }
843
844 /**
845  * _gtk_file_chooser_get_paths:
846  * @chooser: a #GtkFileChooser
847  * 
848  * Lists all the files and subfolders in the current folder of
849  * @chooser as #GtkFilePath. An internal function, see
850  * gtk_file_chooser_get_uris().
851  * 
852  * Return value: a #GList containing a #GtkFilePath for each
853  *   files and subfolder in the current folder. Free the returned list
854  *   with g_lists_free(), and the paths with gtk_file_path_free().
855  **/
856 GSList *
857 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
858 {
859   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
860
861   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
862 }
863
864 static GtkFilePath *
865 gtk_file_chooser_get_path (GtkFileChooser *chooser)
866 {
867   GSList *list;
868   GtkFilePath *result = NULL;
869   
870   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
871
872   list = _gtk_file_chooser_get_paths (chooser);
873   if (list)
874     {
875       result = list->data;
876       list = g_slist_delete_link (list, list);
877       gtk_file_paths_free (list);
878     }
879
880   return result;
881 }
882
883 /**
884  * _gtk_file_chooser_get_file_system:
885  * @chooser: a #GtkFileChooser
886  * 
887  * Gets the #GtkFileSystem of @chooser; this is an internal
888  * implementation detail, used for conversion between paths
889  * and filenames and URIs.
890  * 
891  * Return value: the file system for @chooser.
892  **/
893 GtkFileSystem *
894 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
895 {
896   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
897
898   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
899 }
900
901 /* Preview widget
902  */
903 /**
904  * gtk_file_chooser_set_preview_widget:
905  * @chooser: a #GtkFileChooser
906  * @preview_widget: widget for displaying preview.
907  *
908  * Sets an application-supplied widget to use to display a custom preview
909  * of the currently selected file. To implement a preview, after setting the
910  * preview widget, you connect to the ::selection-changed
911  * signal, and call gtk_file_chooser_get_preview_filename() or
912  * gtk_file_chooser_get_preview_uri() on each change. If you can
913  * display a preview of the new file, update your widget
914  * and set the preview active using gtk_file_chooser_set_preview_widget_active().
915  * Otherwise, set the preview inactive.
916  *
917  * When there is application-supplied preview widget, or the application-supplied
918  * preview widget is not active, the file chooser may display an internally
919  * generated preview of the current file or it may display no preview at all.
920  **/
921 void
922 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
923                                      GtkWidget      *preview_widget)
924 {
925   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
926
927   g_object_set (chooser, "preview-widget", preview_widget, NULL);
928 }
929
930 /**
931  * gtk_file_chooser_get_preview_widget:
932  * @chooser: a #GtkFileChooser
933  * 
934  * Gets the current preview widget; see
935  * gtk_file_chooser_set_preview_widget().
936  * 
937  * Return value: the current preview widget, or %NULL
938  **/
939 GtkWidget *
940 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
941 {
942   GtkWidget *preview_widget;
943   
944   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
945
946   g_object_get (chooser, "preview-widget", &preview_widget, NULL);
947   
948   /* Horrid hack; g_object_get() refs returned objects but
949    * that contradicts the memory management conventions
950    * for accessors.
951    */
952   if (preview_widget)
953     g_object_unref (preview_widget);
954
955   return preview_widget;
956 }
957
958 /**
959  * gtk_file_chooser_set_preview_widget_active:
960  * @chooser: a #GtkFileChooser
961  * @active: whether to display the user-specified preview widget
962  * 
963  * Sets whether the preview widget set by
964  * gtk_file_chooser_set_preview_widget_active() should be shown for the
965  * current filename. When @active is set to false, the file chooser
966  * may display an internally generated preview of the current file
967  * or it may display no preview at all. See
968  * gtk_file_chooser_set_preview_widget() for more details.
969  **/
970 void
971 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
972                                             gboolean        active)
973 {
974   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
975   
976   g_object_set (chooser, "preview-widget-active", active, NULL);
977 }
978
979 /**
980  * gtk_file_chooser_get_preview_widget_active:
981  * @chooser: a #GtkFileChooser
982  * 
983  * Gets whether the preview widget set by
984  * gtk_file_chooser_set_preview_widget_active() should be shown for the
985  * current filename. See gtk_file_chooser_set_preview_widget_active().
986  * 
987  * Return value: %TRUE if the preview widget is active for the
988  *  current filename.
989  **/
990 gboolean
991 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
992 {
993   gboolean active;
994   
995   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
996
997   g_object_get (chooser, "preview-widget-active", &active, NULL);
998
999   return active;
1000 }
1001
1002 /**
1003  * gtk_file_chooser_get_preview_filename:
1004  * @chooser: a #GtkFileChooser
1005  * 
1006  * Gets the filename that should be previewed in a custom preview
1007  * Internal function, see gtk_file_chooser_get_preview_uri().n
1008  * 
1009  * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1010  *  is selected. Free with gtk_file_path_free().
1011  **/
1012 GtkFilePath *
1013 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1014 {
1015   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1016
1017   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1018 }
1019
1020 /**
1021  * gtk_file_chooser_get_preview_filename:
1022  * @chooser: a #GtkFileChooser
1023  * 
1024  * Gets the filename that should be previewed in a custom preview
1025  * widget. See gtk_file_chooser_set_preview_widget().
1026  * 
1027  * Return value: the filename to preview, or %NULL if no file
1028  *  is selected, or if the selected file cannot be represented
1029  *  as a local filename. Free with g_free()
1030  **/
1031 char *
1032 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1033 {
1034   GtkFileSystem *file_system;
1035   GtkFilePath *path;
1036   gchar *result = NULL;
1037   
1038   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1039
1040   file_system = _gtk_file_chooser_get_file_system (chooser);
1041   path = _gtk_file_chooser_get_preview_path (chooser);
1042   if (path)
1043     {
1044       result = gtk_file_system_path_to_filename (file_system, path);
1045       gtk_file_path_free (path);
1046     }
1047
1048   return result;
1049 }
1050
1051 /**
1052  * gtk_file_chooser_get_preview_filename:
1053  * @chooser: a #GtkFileChooser
1054  * 
1055  * Gets the URI that should be previewed in a custom preview
1056  * widget. See gtk_file_chooser_set_preview_widget().
1057  * 
1058  * Return value: the URI for the file to preview, or %NULL if no file
1059  *  is selected. Free with g_free().
1060  **/
1061 char *
1062 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1063 {
1064   GtkFileSystem *file_system;
1065   GtkFilePath *path;
1066   gchar *result = NULL;
1067   
1068   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1069
1070   file_system = _gtk_file_chooser_get_file_system (chooser);
1071   path = _gtk_file_chooser_get_preview_path (chooser);
1072   if (path)
1073     {
1074       result = gtk_file_system_path_to_uri (file_system, path);
1075       gtk_file_path_free (path);
1076     }
1077
1078   return result;
1079 }
1080
1081 /**
1082  * gtk_file_chooser_add_filter:
1083  * @chooser: a #GtkFileChooser
1084  * @filter: a #GtkFileFilter
1085  * 
1086  * Adds @filter to the list of filters that the user can select between.
1087  * When a filter is selected, only files that are passed by that
1088  * filter are displayed.
1089  **/
1090 void
1091 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1092                              GtkFileFilter  *filter)
1093 {
1094   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1095
1096   GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1097 }
1098
1099 /**
1100  * gtk_file_chooser_add_filter:
1101  * @chooser: a #GtkFileChooser
1102  * @filter: a #GtkFileFilter
1103  * 
1104  * Removes @filter from the list of filters that the user can select between.
1105  **/
1106 void
1107 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1108                                 GtkFileFilter  *filter)
1109 {
1110   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1111
1112   GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1113 }
1114
1115 /**
1116  * gtk_file_chooser_list_filters:
1117  * @choooser: a #GtkFileChooser
1118  * 
1119  * Lists the current set of user-selectable filters; see
1120  * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1121  * 
1122  * Return value: a #GSList containing the current set of
1123  *  user selectable filters. The contents of the list are
1124  *  owned by GTK+, but you must free the list itself with
1125  *  g_slist_free() when you are done with it.
1126  **/
1127 GSList *
1128 gtk_file_chooser_list_filters  (GtkFileChooser *chooser)
1129 {
1130   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1131
1132   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1133 }
1134
1135 /**
1136  * gtk_file_chooser_set_filter:
1137  * @chooser: a #GtkFileChooser
1138  * @filter: a #GtkFileFilter
1139  * 
1140  * Sets the current filter; only the files that pass the
1141  * filter will be displayed. If the user-selectable list of filters
1142  * is non-empty, then the filter should be one of the filters
1143  * in that list. Setting the current filter when the list of
1144  * filters is empty is useful if you want to restrict the displayed
1145  * set of files without letting the user change it.
1146  **/
1147 void
1148 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1149                              GtkFileFilter  *filter)
1150 {
1151   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1152   g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1153
1154   g_object_set (chooser, "filter", filter, NULL);
1155 }
1156
1157 /**
1158  * gtk_file_chooser_get_filter:
1159  * @chooser: a #GtkFileChooser
1160  * 
1161  * Gets the current filter; see gtk_file_chooser_set_filter().
1162  * 
1163  * Return value: the current filter, or %NULL
1164  **/
1165 GtkFileFilter *
1166 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1167 {
1168   GtkFileFilter *filter;
1169   
1170   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1171
1172   g_object_get (chooser, "filter", &filter, NULL);
1173   /* Horrid hack; g_object_get() refs returned objects but
1174    * that contradicts the memory management conventions
1175    * for accessors.
1176    */
1177   if (filter)
1178     g_object_unref (filter);
1179
1180   return filter;
1181 }