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