]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooser.c
Added methods for ::get_supports_bookmarks(), ::set_bookmarks(),
[~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 selected files and subfolders in the current folder of
444  * @chooser. The returned names are full absolute paths. If files in the current
445  * folder cannot be represented as local filenames they will be ignored. (See
446  * gtk_file_chooser_get_uris())
447  * 
448  * Return value: a #GSList containing the filenames of all selected
449  *   files and subfolders in the current folder. Free the returned list
450  *   with g_slist_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_uris:
691  * @chooser: a #GtkFileChooser
692  * 
693  * Lists all the selected files and subfolders in the current folder of
694  * @chooser. The returned names are full absolute URIs.
695  * 
696  * Return value: a #GSList containing the URIs of all selected
697  *   files and subfolders in the current folder. Free the returned list
698  *   with g_slist_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 selected files and subfolders in the current folder of @chooser
857  * as #GtkFilePath. An internal function, see gtk_file_chooser_get_uris().
858  * 
859  * Return value: a #GSList containing a #GtkFilePath for each selected
860  *   file and subfolder in the current folder.  Free the returned list
861  *   with g_slist_free(), and the paths with gtk_file_path_free().
862  **/
863 GSList *
864 _gtk_file_chooser_get_paths (GtkFileChooser *chooser)
865 {
866   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
867
868   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_paths (chooser);
869 }
870
871 static GtkFilePath *
872 gtk_file_chooser_get_path (GtkFileChooser *chooser)
873 {
874   GSList *list;
875   GtkFilePath *result = NULL;
876   
877   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
878
879   list = _gtk_file_chooser_get_paths (chooser);
880   if (list)
881     {
882       result = list->data;
883       list = g_slist_delete_link (list, list);
884       gtk_file_paths_free (list);
885     }
886
887   return result;
888 }
889
890 /**
891  * _gtk_file_chooser_get_file_system:
892  * @chooser: a #GtkFileChooser
893  * 
894  * Gets the #GtkFileSystem of @chooser; this is an internal
895  * implementation detail, used for conversion between paths
896  * and filenames and URIs.
897  * 
898  * Return value: the file system for @chooser.
899  **/
900 GtkFileSystem *
901 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
902 {
903   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
904
905   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
906 }
907
908 /* Preview widget
909  */
910 /**
911  * gtk_file_chooser_set_preview_widget:
912  * @chooser: a #GtkFileChooser
913  * @preview_widget: widget for displaying preview.
914  *
915  * Sets an application-supplied widget to use to display a custom preview
916  * of the currently selected file. To implement a preview, after setting the
917  * preview widget, you connect to the ::selection-changed
918  * signal, and call gtk_file_chooser_get_preview_filename() or
919  * gtk_file_chooser_get_preview_uri() on each change. If you can
920  * display a preview of the new file, update your widget
921  * and set the preview active using gtk_file_chooser_set_preview_widget_active().
922  * Otherwise, set the preview inactive.
923  *
924  * When there is no application-supplied preview widget, or the
925  * application-supplied preview widget is not active, the file chooser
926  * may display an internally generated preview of the current file or
927  * it may display no preview at all.
928  **/
929 void
930 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
931                                      GtkWidget      *preview_widget)
932 {
933   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
934
935   g_object_set (chooser, "preview-widget", preview_widget, NULL);
936 }
937
938 /**
939  * gtk_file_chooser_get_preview_widget:
940  * @chooser: a #GtkFileChooser
941  * 
942  * Gets the current preview widget; see
943  * gtk_file_chooser_set_preview_widget().
944  * 
945  * Return value: the current preview widget, or %NULL
946  **/
947 GtkWidget *
948 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
949 {
950   GtkWidget *preview_widget;
951   
952   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
953
954   g_object_get (chooser, "preview-widget", &preview_widget, NULL);
955   
956   /* Horrid hack; g_object_get() refs returned objects but
957    * that contradicts the memory management conventions
958    * for accessors.
959    */
960   if (preview_widget)
961     g_object_unref (preview_widget);
962
963   return preview_widget;
964 }
965
966 /**
967  * gtk_file_chooser_set_preview_widget_active:
968  * @chooser: a #GtkFileChooser
969  * @active: whether to display the user-specified preview widget
970  * 
971  * Sets whether the preview widget set by
972  * gtk_file_chooser_set_preview_widget_active() should be shown for the
973  * current filename. When @active is set to false, the file chooser
974  * may display an internally generated preview of the current file
975  * or it may display no preview at all. See
976  * gtk_file_chooser_set_preview_widget() for more details.
977  **/
978 void
979 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
980                                             gboolean        active)
981 {
982   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
983   
984   g_object_set (chooser, "preview-widget-active", active, NULL);
985 }
986
987 /**
988  * gtk_file_chooser_get_preview_widget_active:
989  * @chooser: a #GtkFileChooser
990  * 
991  * Gets whether the preview widget set by
992  * gtk_file_chooser_set_preview_widget_active() should be shown for the
993  * current filename. See gtk_file_chooser_set_preview_widget_active().
994  * 
995  * Return value: %TRUE if the preview widget is active for the
996  *  current filename.
997  **/
998 gboolean
999 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1000 {
1001   gboolean active;
1002   
1003   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1004
1005   g_object_get (chooser, "preview-widget-active", &active, NULL);
1006
1007   return active;
1008 }
1009
1010 /**
1011  * gtk_file_chooser_get_preview_filename:
1012  * @chooser: a #GtkFileChooser
1013  * 
1014  * Gets the filename that should be previewed in a custom preview
1015  * Internal function, see gtk_file_chooser_get_preview_uri().n
1016  * 
1017  * Return value: the #GtkFilePath for the file to preview, or %NULL if no file
1018  *  is selected. Free with gtk_file_path_free().
1019  **/
1020 GtkFilePath *
1021 _gtk_file_chooser_get_preview_path (GtkFileChooser *chooser)
1022 {
1023   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1024
1025   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_path (chooser);
1026 }
1027
1028 /**
1029  * gtk_file_chooser_get_preview_filename:
1030  * @chooser: a #GtkFileChooser
1031  * 
1032  * Gets the filename that should be previewed in a custom preview
1033  * widget. See gtk_file_chooser_set_preview_widget().
1034  * 
1035  * Return value: the filename to preview, or %NULL if no file
1036  *  is selected, or if the selected file cannot be represented
1037  *  as a local filename. Free with g_free()
1038  **/
1039 char *
1040 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
1041 {
1042   GtkFileSystem *file_system;
1043   GtkFilePath *path;
1044   gchar *result = NULL;
1045   
1046   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1047
1048   file_system = _gtk_file_chooser_get_file_system (chooser);
1049   path = _gtk_file_chooser_get_preview_path (chooser);
1050   if (path)
1051     {
1052       result = gtk_file_system_path_to_filename (file_system, path);
1053       gtk_file_path_free (path);
1054     }
1055
1056   return result;
1057 }
1058
1059 /**
1060  * gtk_file_chooser_get_preview_filename:
1061  * @chooser: a #GtkFileChooser
1062  * 
1063  * Gets the URI that should be previewed in a custom preview
1064  * widget. See gtk_file_chooser_set_preview_widget().
1065  * 
1066  * Return value: the URI for the file to preview, or %NULL if no file
1067  *  is selected. Free with g_free().
1068  **/
1069 char *
1070 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
1071 {
1072   GtkFileSystem *file_system;
1073   GtkFilePath *path;
1074   gchar *result = NULL;
1075   
1076   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1077
1078   file_system = _gtk_file_chooser_get_file_system (chooser);
1079   path = _gtk_file_chooser_get_preview_path (chooser);
1080   if (path)
1081     {
1082       result = gtk_file_system_path_to_uri (file_system, path);
1083       gtk_file_path_free (path);
1084     }
1085
1086   return result;
1087 }
1088
1089 /**
1090  * gtk_file_chooser_set_extra_widget:
1091  * @chooser: a #GtkFileChooser
1092  * @extra_widget: widget for extra options
1093  * 
1094  * Sets an application-supplied widget to provide extra options to the user.
1095  **/
1096 void
1097 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
1098                                    GtkWidget      *extra_widget)
1099 {
1100   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1101
1102   g_object_set (chooser, "extra-widget", extra_widget, NULL);
1103 }
1104
1105 /**
1106  * gtk_file_chooser_get_extra_widget:
1107  * @chooser: a #GtkFileChooser
1108  * 
1109  * Gets the current preview widget; see
1110  * gtk_file_chooser_set_extra_widget().
1111  * 
1112  * Return value: the current extra widget, or %NULL
1113  **/
1114 GtkWidget *
1115 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
1116 {
1117   GtkWidget *extra_widget;
1118   
1119   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1120
1121   g_object_get (chooser, "extra-widget", &extra_widget, NULL);
1122   
1123   /* Horrid hack; g_object_get() refs returned objects but
1124    * that contradicts the memory management conventions
1125    * for accessors.
1126    */
1127   if (extra_widget)
1128     g_object_unref (extra_widget);
1129
1130   return extra_widget;
1131 }
1132
1133 /**
1134  * gtk_file_chooser_add_filter:
1135  * @chooser: a #GtkFileChooser
1136  * @filter: a #GtkFileFilter
1137  * 
1138  * Adds @filter to the list of filters that the user can select between.
1139  * When a filter is selected, only files that are passed by that
1140  * filter are displayed.
1141  **/
1142 void
1143 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
1144                              GtkFileFilter  *filter)
1145 {
1146   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1147
1148   GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
1149 }
1150
1151 /**
1152  * gtk_file_chooser_add_filter:
1153  * @chooser: a #GtkFileChooser
1154  * @filter: a #GtkFileFilter
1155  * 
1156  * Removes @filter from the list of filters that the user can select between.
1157  **/
1158 void
1159 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
1160                                 GtkFileFilter  *filter)
1161 {
1162   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1163
1164   GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1165 }
1166
1167 /**
1168  * gtk_file_chooser_list_filters:
1169  * @choooser: a #GtkFileChooser
1170  * 
1171  * Lists the current set of user-selectable filters; see
1172  * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
1173  * 
1174  * Return value: a #GSList containing the current set of
1175  *  user selectable filters. The contents of the list are
1176  *  owned by GTK+, but you must free the list itself with
1177  *  g_slist_free() when you are done with it.
1178  **/
1179 GSList *
1180 gtk_file_chooser_list_filters  (GtkFileChooser *chooser)
1181 {
1182   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1183
1184   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1185 }
1186
1187 /**
1188  * gtk_file_chooser_set_filter:
1189  * @chooser: a #GtkFileChooser
1190  * @filter: a #GtkFileFilter
1191  * 
1192  * Sets the current filter; only the files that pass the
1193  * filter will be displayed. If the user-selectable list of filters
1194  * is non-empty, then the filter should be one of the filters
1195  * in that list. Setting the current filter when the list of
1196  * filters is empty is useful if you want to restrict the displayed
1197  * set of files without letting the user change it.
1198  **/
1199 void
1200 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
1201                              GtkFileFilter  *filter)
1202 {
1203   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1204   g_return_if_fail (GTK_IS_FILE_FILTER (filter));
1205
1206   g_object_set (chooser, "filter", filter, NULL);
1207 }
1208
1209 /**
1210  * gtk_file_chooser_get_filter:
1211  * @chooser: a #GtkFileChooser
1212  * 
1213  * Gets the current filter; see gtk_file_chooser_set_filter().
1214  * 
1215  * Return value: the current filter, or %NULL
1216  **/
1217 GtkFileFilter *
1218 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
1219 {
1220   GtkFileFilter *filter;
1221   
1222   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1223
1224   g_object_get (chooser, "filter", &filter, NULL);
1225   /* Horrid hack; g_object_get() refs returned objects but
1226    * that contradicts the memory management conventions
1227    * for accessors.
1228    */
1229   if (filter)
1230     g_object_unref (filter);
1231
1232   return filter;
1233 }
1234
1235 /* gtk_file_chooser_set_shortcut_folders:
1236  * @chooser: a #GtkFileChooser
1237  * @shortcut_folders: a list of #GtkFilePath, or NULL if you want to clear the
1238  * current list of shortcut folders.
1239  * 
1240  * Sets the list of shortcut folders to be shown in a file chooser.  Note that
1241  * these do not get saved, as they are provided by the application.  For
1242  * example, you can use this to add a "/usr/share/myapp/Clipart" folder to the
1243  * volume list.
1244  **/
1245 void
1246 gtk_file_chooser_set_shortcut_folders (GtkFileChooser *chooser,
1247                                        GSList         *shortcut_folders)
1248 {
1249   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1250
1251   GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_shortcut_folders (chooser, shortcut_folders);
1252 }
1253
1254 /**
1255  * gtk_file_chooser_list_shortcut_folders:
1256  * @chooser: a #GtkFileChooser
1257  * 
1258  * Queries the list of shortcut folders in the file chooser, as set by
1259  * gtk_file_chooser_set_shortcut_folders().
1260  * 
1261  * Return value: A list of #GtkFilePath, or NULL if there are no shortcut
1262  * folders.  You should use gtk_file_paths_free() to free this list.
1263  **/
1264 GSList *
1265 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
1266 {
1267   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1268
1269   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
1270 }