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