1 /* GTK - The GIMP Toolkit
2 * gtkfilechooser.c: Abstract interface for file selector GUIs
3 * Copyright (C) 2003, Red Hat, Inc.
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.
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.
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.
22 #include "gtkfilechooser.h"
23 #include "gtkfilechooserprivate.h"
25 #include "gtktypebuiltins.h"
26 #include "gtkprivate.h"
27 #include "gtkmarshalers.h"
31 * SECTION:gtkfilechooser
32 * @Short_description: File chooser interface used by GtkFileChooserWidget and GtkFileChooserDialog
33 * @Title: GtkFileChooser
34 * @See_also: #GtkFileChooserDialog, #GtkFileChooserWidget, #GtkFileChooserButton
36 * #GtkFileChooser is an interface that can be implemented by file
37 * selection widgets. In GTK+, the main objects that implement this
38 * interface are #GtkFileChooserWidget, #GtkFileChooserDialog, and
39 * #GtkFileChooserButton. You do not need to write an object that
40 * implements the #GtkFileChooser interface unless you are trying to
41 * adapt an existing file selector to expose a standard programming
44 * #GtkFileChooser allows for shortcuts to various places in the filesystem.
45 * In the default implementation these are displayed in the left pane. It
46 * may be a bit confusing at first that these shortcuts come from various
47 * sources and in various flavours, so lets explain the terminology here:
50 * <term>Bookmarks</term>
52 * are created by the user, by dragging folders from the
53 * right pane to the left pane, or by using the "Add". Bookmarks
54 * can be renamed and deleted by the user.
58 * <term>Shortcuts</term>
60 * can be provided by the application or by the underlying filesystem
61 * abstraction (e.g. both the gnome-vfs and the Windows filesystems
62 * provide "Desktop" shortcuts). Shortcuts cannot be modified by the
67 * <term>Volumes</term>
69 * are provided by the underlying filesystem abstraction. They are
70 * the "roots" of the filesystem.
75 * <refsect2 id="gtkfilechooser-encodings">
76 * <title>File Names and Encodings</title>
77 * When the user is finished selecting files in a
78 * #GtkFileChooser, your program can get the selected names
79 * either as filenames or as URIs. For URIs, the normal escaping
80 * rules are applied if the URI contains non-ASCII characters.
81 * However, filenames are <emphasis>always</emphasis> returned in
82 * the character set specified by the
83 * <envar>G_FILENAME_ENCODING</envar> environment variable.
84 * Please see the Glib documentation for more details about this
87 * This means that while you can pass the result of
88 * gtk_file_chooser_get_filename() to
89 * <function>open(2)</function> or
90 * <function>fopen(3)</function>, you may not be able to
91 * directly set it as the text of a #GtkLabel widget unless you
92 * convert it first to UTF-8, which all GTK+ widgets expect.
93 * You should use g_filename_to_utf8() to convert filenames
94 * into strings that can be passed to GTK+ widgets.
97 * <refsect2 id="gtkfilechooser-preview">
98 * <title>Adding a Preview Widget</title>
100 * You can add a custom preview widget to a file chooser and then
101 * get notification about when the preview needs to be updated.
102 * To install a preview widget, use
103 * gtk_file_chooser_set_preview_widget(). Then, connect to the
104 * #GtkFileChooser::update-preview signal to get notified when
105 * you need to update the contents of the preview.
108 * Your callback should use
109 * gtk_file_chooser_get_preview_filename() to see what needs
110 * previewing. Once you have generated the preview for the
111 * corresponding file, you must call
112 * gtk_file_chooser_set_preview_widget_active() with a boolean
113 * flag that indicates whether your callback could successfully
114 * generate a preview.
116 * <example id="example-gtkfilechooser-preview">
117 * <title>Sample Usage</title>
124 * preview = gtk_image_new (<!-- -->);
126 * gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
127 * g_signal_connect (my_file_chooser, "update-preview",
128 * G_CALLBACK (update_preview_cb), preview);
132 * update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
134 * GtkWidget *preview;
137 * gboolean have_preview;
139 * preview = GTK_WIDGET (data);
140 * filename = gtk_file_chooser_get_preview_filename (file_chooser);
142 * pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
143 * have_preview = (pixbuf != NULL);
146 * gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
148 * g_object_unref (pixbuf);
150 * gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
155 * <refsect2 id="gtkfilechooser-extra">
156 * <title>Adding Extra Widgets</title>
158 * You can add extra widgets to a file chooser to provide options
159 * that are not present in the default design. For example, you
160 * can add a toggle button to give the user the option to open a
161 * file in read-only mode. You can use
162 * gtk_file_chooser_set_extra_widget() to insert additional
163 * widgets in a file chooser.
165 * <example id="example-gtkfilechooser-extra">
166 * <title>Sample Usage</title>
173 * toggle = gtk_check_button_new_with_label ("Open file read-only");
174 * gtk_widget_show (toggle);
175 * gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
180 * If you want to set more than one extra widget in the file
181 * chooser, you can a container such as a #GtkVBox or a #GtkTable
182 * and include your widgets in it. Then, set the container as
183 * the whole extra widget.
186 * <refsect2 id="gtkfilechooser-key-bindings">
187 * <title>Key Bindings</title>
189 * Internally, GTK+ implements a file chooser's graphical user
190 * interface with the private
191 * <classname>GtkFileChooserDefaultClass</classname>. This
192 * widget has several <link linkend="gtk-Bindings">key
193 * bindings</link> and their associated signals. This section
194 * describes the available key binding signals.
196 * <example id="gtkfilechooser-key-binding-example">
197 * <title>GtkFileChooser key binding example</title>
199 * The default keys that activate the key-binding signals in
200 * <classname>GtkFileChooserDefaultClass</classname> are as
207 * <entry>Signal name</entry>
208 * <entry>Default key combinations</entry>
211 * <entry>location-popup</entry>
213 * <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo> (empty path);
214 * <keycap>/</keycap> (path of "/")
216 * Both the individual <keycap>/</keycap> key and the
217 * numeric keypad's "divide" key are supported.
219 * <keycap>~</keycap> (path of "~")
223 * <entry>up-folder</entry>
225 * <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>
227 * Both the individual Up key and the numeric
228 * keypad's Up key are supported.
231 * <keycap>Backspace</keycap>
235 * <entry>down-folder</entry>
236 * <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
239 * <entry>home-folder</entry>
240 * <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
243 * <entry>desktop-folder</entry>
244 * <entry><keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo></entry>
247 * <entry>quick-bookmark</entry>
248 * <entry><keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo> through <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo></entry>
254 * You can change these defaults to something else. For
255 * example, to add a <keycap>Shift</keycap> modifier to a few
256 * of the default bindings, you can include the following
257 * fragment in your <filename>.gtkrc-3.0</filename> file:
260 * binding "my-own-gtkfilechooser-bindings" {
261 * bind "<Alt><Shift>Up" {
264 * bind "<Alt><Shift>Down" {
267 * bind "<Alt><Shift>Home" {
272 * class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
275 * <refsect3 id="GtkFileChooserDefault-location-popup">
276 * <title>The "GtkFileChooserDefault::location-popup" signal</title>
278 * void user_function (GtkFileChooserDefault *chooser,
280 * <link linkend="gpointer">gpointer</link> user_data);
283 * This is used to make the file chooser show a "Location"
284 * dialog which the user can use to manually type the name of
285 * the file he wishes to select. The
286 * <parameter>path</parameter> argument is a string that gets
287 * put in the text entry for the file name. By default this is bound to
288 * <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
289 * with a <parameter>path</parameter> string of "" (the empty
290 * string). It is also bound to <keycap>/</keycap> with a
291 * <parameter>path</parameter> string of "<literal>/</literal>"
292 * (a slash): this lets you type <keycap>/</keycap> and
293 * immediately type a path name. On Unix systems, this is bound to
294 * <keycap>~</keycap> (tilde) with a <parameter>path</parameter> string
295 * of "~" itself for access to home directories.
297 * <variablelist role="params">
299 * <term><parameter>chooser</parameter> :</term>
302 * the object which received the signal.
307 * <term><parameter>path</parameter> :</term>
310 * default contents for the text entry for the file name
315 * <term><parameter>user_data</parameter> :</term>
318 * user data set when the signal handler was connected.
324 * You can create your own bindings for the
325 * #GtkFileChooserDefault::location-popup signal with custom
326 * <parameter>path</parameter> strings, and have a crude form
327 * of easily-to-type bookmarks. For example, say you access
328 * the path <filename>/home/username/misc</filename> very
329 * frequently. You could then create an <keycombo>
330 * <keycap>Alt</keycap> <keycap>M</keycap> </keycombo>
331 * shortcut by including the following in your
332 * <filename>.gtkrc-3.0</filename>:
334 * binding "misc-shortcut" {
335 * bind "<Alt>M" {
336 * "location-popup" ("/home/username/misc")
340 * class "GtkFileChooserDefault" binding "misc-shortcut"
344 * <refsect3 id="GtkFileChooserDefault-up-folder">
345 * <title>The "GtkFileChooserDefault::up-folder" signal</title>
347 * void user_function (GtkFileChooserDefault *chooser,
348 * <link linkend="gpointer">gpointer</link> user_data);
351 * This is used to make the file chooser go to the parent of
352 * the current folder in the file hierarchy. By default this
353 * is bound to <keycap>Backspace</keycap> and
354 * <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>
355 * (the Up key in the numeric keypad also works).
357 * <variablelist role="params">
359 * <term><parameter>chooser</parameter> :</term>
362 * the object which received the signal.
367 * <term><parameter>user_data</parameter> :</term>
370 * user data set when the signal handler was connected.
376 * <refsect3 id="GtkFileChooserDefault-down-folder">
377 * <title>The "GtkFileChooserDefault::down-folder" signal</title>
379 * void user_function (GtkFileChooserDefault *chooser,
380 * <link linkend="gpointer">gpointer</link> user_data);
383 * This is used to make the file chooser go to a child of the
384 * current folder in the file hierarchy. The subfolder that
385 * will be used is displayed in the path bar widget of the file
386 * chooser. For example, if the path bar is showing
387 * "/foo/<emphasis>bar/</emphasis>baz", then this will cause
388 * the file chooser to switch to the "baz" subfolder. By
389 * default this is bound to
390 * <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>
391 * (the Down key in the numeric keypad also works).
393 * <variablelist role="params">
395 * <term><parameter>chooser</parameter> :</term>
398 * the object which received the signal.
403 * <term><parameter>user_data</parameter> :</term>
406 * user data set when the signal handler was connected.
412 * <refsect3 id="GtkFileChooserDefault-home-folder">
413 * <title>The "GtkFileChooserDefault::home-folder" signal</title>
415 * void user_function (GtkFileChooserDefault *chooser,
416 * <link linkend="gpointer">gpointer</link> user_data);
419 * This is used to make the file chooser show the user's home
420 * folder in the file list. By default this is bound to
421 * <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>
422 * (the Home key in the numeric keypad also works).
424 * <variablelist role="params">
426 * <term><parameter>chooser</parameter> :</term>
429 * the object which received the signal.
434 * <term><parameter>user_data</parameter> :</term>
437 * user data set when the signal handler was connected.
443 * <refsect3 id="GtkFileChooserDefault-desktop-folder">
444 * <title>The "GtkFileChooserDefault::desktop-folder" signal</title>
446 * void user_function (GtkFileChooserDefault *chooser,
447 * <link linkend="gpointer">gpointer</link> user_data);
450 * This is used to make the file chooser show the user's Desktop
451 * folder in the file list. By default this is bound to
452 * <keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo>.
454 * <variablelist role="params">
456 * <term><parameter>chooser</parameter> :</term>
459 * the object which received the signal.
464 * <term><parameter>user_data</parameter> :</term>
467 * user data set when the signal handler was connected.
473 * <refsect3 id="GtkFileChooserDefault-quick-bookmark">
474 * <title>The "GtkFileChooserDefault::quick-bookmark" signal</title>
476 * void user_function (GtkFileChooserDefault *chooser,
477 * gint bookmark_index,
478 * <link linkend="gpointer">gpointer</link> user_data);
481 * This is used to make the file chooser switch to the bookmark
482 * specified in the <parameter>bookmark_index</parameter> parameter.
483 * For example, if you have three bookmarks, you can pass 0, 1, 2 to
484 * this signal to switch to each of them, respectively. By default this is bound to
485 * <keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo>,
486 * <keycombo><keycap>Alt</keycap><keycap>2</keycap></keycombo>,
488 * <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo>. Note
489 * that in the default binding,
490 * that <keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo> is
491 * actually defined to switch to the bookmark at index 0, and so on
493 * <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo> is
494 * defined to switch to the bookmark at index 10.
496 * <variablelist role="params">
498 * <term><parameter>chooser</parameter> :</term>
501 * the object which received the signal.
506 * <term><parameter>bookmark_indes</parameter> :</term>
509 * index of the bookmark to switch to; the indices start at 0.
514 * <term><parameter>user_data</parameter> :</term>
517 * user data set when the signal handler was connected.
527 static void gtk_file_chooser_class_init (gpointer g_iface);
530 gtk_file_chooser_get_type (void)
532 static GType file_chooser_type = 0;
534 if (!file_chooser_type)
536 file_chooser_type = g_type_register_static_simple (G_TYPE_INTERFACE,
537 I_("GtkFileChooser"),
538 sizeof (GtkFileChooserIface),
539 (GClassInitFunc) gtk_file_chooser_class_init,
542 g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET);
545 return file_chooser_type;
549 confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
551 const GValue *handler_return,
554 gboolean continue_emission;
555 GtkFileChooserConfirmation conf;
557 conf = g_value_get_enum (handler_return);
558 g_value_set_enum (return_accu, conf);
559 continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
561 return continue_emission;
565 gtk_file_chooser_class_init (gpointer g_iface)
567 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
570 * GtkFileChooser::current-folder-changed
571 * @chooser: the object which received the signal.
573 * This signal is emitted when the current folder in a #GtkFileChooser
574 * changes. This can happen due to the user performing some action that
575 * changes folders, such as selecting a bookmark or visiting a folder on the
576 * file list. It can also happen as a result of calling a function to
577 * explicitly change the current folder in a file chooser.
579 * Normally you do not need to connect to this signal, unless you need to keep
580 * track of which folder a file chooser is showing.
582 * See also: gtk_file_chooser_set_current_folder(),
583 * gtk_file_chooser_get_current_folder(),
584 * gtk_file_chooser_set_current_folder_uri(),
585 * gtk_file_chooser_get_current_folder_uri().
587 g_signal_new (I_("current-folder-changed"),
590 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
592 g_cclosure_marshal_VOID__VOID,
596 * GtkFileChooser::selection-changed
597 * @chooser: the object which received the signal.
599 * This signal is emitted when there is a change in the set of selected files
600 * in a #GtkFileChooser. This can happen when the user modifies the selection
601 * with the mouse or the keyboard, or when explicitly calling functions to
602 * change the selection.
604 * Normally you do not need to connect to this signal, as it is easier to wait
605 * for the file chooser to finish running, and then to get the list of
606 * selected files using the functions mentioned below.
608 * See also: gtk_file_chooser_select_filename(),
609 * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
610 * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
611 * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
612 * gtk_file_chooser_get_uris().
614 g_signal_new (I_("selection-changed"),
617 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
619 g_cclosure_marshal_VOID__VOID,
623 * GtkFileChooser::update-preview
624 * @chooser: the object which received the signal.
626 * This signal is emitted when the preview in a file chooser should be
627 * regenerated. For example, this can happen when the currently selected file
628 * changes. You should use this signal if you want your file chooser to have
631 * Once you have installed a preview widget with
632 * gtk_file_chooser_set_preview_widget(), you should update it when this
633 * signal is emitted. You can use the functions
634 * gtk_file_chooser_get_preview_filename() or
635 * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
636 * Your widget may not be able to preview all kinds of files; your callback
637 * must call gtk_file_chooser_set_preview_widget_active() to inform the file
638 * chooser about whether the preview was generated successfully or not.
640 * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
642 * See also: gtk_file_chooser_set_preview_widget(),
643 * gtk_file_chooser_set_preview_widget_active(),
644 * gtk_file_chooser_set_use_preview_label(),
645 * gtk_file_chooser_get_preview_filename(),
646 * gtk_file_chooser_get_preview_uri().
648 g_signal_new (I_("update-preview"),
651 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
653 g_cclosure_marshal_VOID__VOID,
657 * GtkFileChooser::file-activated
658 * @chooser: the object which received the signal.
660 * This signal is emitted when the user "activates" a file in the file
661 * chooser. This can happen by double-clicking on a file in the file list, or
662 * by pressing <keycap>Enter</keycap>.
664 * Normally you do not need to connect to this signal. It is used internally
665 * by #GtkFileChooserDialog to know when to activate the default button in the
668 * See also: gtk_file_chooser_get_filename(),
669 * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
670 * gtk_file_chooser_get_uris().
672 g_signal_new (I_("file-activated"),
675 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
677 g_cclosure_marshal_VOID__VOID,
681 * GtkFileChooser::confirm-overwrite:
682 * @chooser: the object which received the signal.
684 * This signal gets emitted whenever it is appropriate to present a
685 * confirmation dialog when the user has selected a file name that
686 * already exists. The signal only gets emitted when the file
687 * chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode.
689 * Most applications just need to turn on the
690 * #GtkFileChooser:do-overwrite-confirmation property (or call the
691 * gtk_file_chooser_set_do_overwrite_confirmation() function), and
692 * they will automatically get a stock confirmation dialog.
693 * Applications which need to customize this behavior should do
694 * that, and also connect to the #GtkFileChooser::confirm-overwrite
697 * A signal handler for this signal must return a
698 * #GtkFileChooserConfirmation value, which indicates the action to
699 * take. If the handler determines that the user wants to select a
700 * different filename, it should return
701 * %GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN. If it determines
702 * that the user is satisfied with his choice of file name, it
703 * should return %GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME.
704 * On the other hand, if it determines that the stock confirmation
705 * dialog should be used, it should return
706 * %GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example
708 * <example id="gtkfilechooser-confirmation">
709 * <title>Custom confirmation</title>
711 * static GtkFileChooserConfirmation
712 * confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
716 * uri = gtk_file_chooser_get_uri (chooser);
718 * if (is_uri_read_only (uri))
720 * if (user_wants_to_replace_read_only_file (uri))
721 * return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
723 * return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
725 * return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
730 * chooser = gtk_file_chooser_dialog_new (...);
732 * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
733 * g_signal_connect (chooser, "confirm-overwrite",
734 * G_CALLBACK (confirm_overwrite_callback), NULL);
736 * if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
737 * save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
739 * gtk_widget_destroy (chooser);
743 * Returns: a #GtkFileChooserConfirmation value that indicates which
744 * action to take after emitting the signal.
748 g_signal_new (I_("confirm-overwrite"),
751 G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
752 confirm_overwrite_accumulator, NULL,
753 _gtk_marshal_ENUM__VOID,
754 GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
756 g_object_interface_install_property (g_iface,
757 g_param_spec_enum ("action",
759 P_("The type of operation that the file selector is performing"),
760 GTK_TYPE_FILE_CHOOSER_ACTION,
761 GTK_FILE_CHOOSER_ACTION_OPEN,
762 GTK_PARAM_READWRITE));
763 g_object_interface_install_property (g_iface,
764 g_param_spec_object ("filter",
766 P_("The current filter for selecting which files are displayed"),
767 GTK_TYPE_FILE_FILTER,
768 GTK_PARAM_READWRITE));
769 g_object_interface_install_property (g_iface,
770 g_param_spec_boolean ("local-only",
772 P_("Whether the selected file(s) should be limited to local file: URLs"),
774 GTK_PARAM_READWRITE));
775 g_object_interface_install_property (g_iface,
776 g_param_spec_object ("preview-widget",
777 P_("Preview widget"),
778 P_("Application supplied widget for custom previews."),
780 GTK_PARAM_READWRITE));
781 g_object_interface_install_property (g_iface,
782 g_param_spec_boolean ("preview-widget-active",
783 P_("Preview Widget Active"),
784 P_("Whether the application supplied widget for custom previews should be shown."),
786 GTK_PARAM_READWRITE));
787 g_object_interface_install_property (g_iface,
788 g_param_spec_boolean ("use-preview-label",
789 P_("Use Preview Label"),
790 P_("Whether to display a stock label with the name of the previewed file."),
792 GTK_PARAM_READWRITE));
793 g_object_interface_install_property (g_iface,
794 g_param_spec_object ("extra-widget",
796 P_("Application supplied widget for extra options."),
798 GTK_PARAM_READWRITE));
799 g_object_interface_install_property (g_iface,
800 g_param_spec_boolean ("select-multiple",
801 P_("Select Multiple"),
802 P_("Whether to allow multiple files to be selected"),
804 GTK_PARAM_READWRITE));
806 g_object_interface_install_property (g_iface,
807 g_param_spec_boolean ("show-hidden",
809 P_("Whether the hidden files and folders should be displayed"),
811 GTK_PARAM_READWRITE));
814 * GtkFileChooser:do-overwrite-confirmation:
816 * Whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode
817 * will present an overwrite confirmation dialog if the user
818 * selects a file name that already exists.
822 g_object_interface_install_property (g_iface,
823 g_param_spec_boolean ("do-overwrite-confirmation",
824 P_("Do overwrite confirmation"),
825 P_("Whether a file chooser in save mode "
826 "will present an overwrite confirmation dialog "
829 GTK_PARAM_READWRITE));
832 * GtkFileChooser:create-folders:
834 * Whether a file chooser not in %GTK_FILE_CHOOSER_ACTION_OPEN mode
835 * will offer the user to create new folders.
839 g_object_interface_install_property (g_iface,
840 g_param_spec_boolean ("create-folders",
841 P_("Allow folder creation"),
842 P_("Whether a file chooser not in open mode "
843 "will offer the user to create new folders."),
845 GTK_PARAM_READWRITE));
849 * gtk_file_chooser_error_quark:
851 * Registers an error quark for #GtkFileChooser if necessary.
853 * Return value: The error quark used for #GtkFileChooser errors.
858 gtk_file_chooser_error_quark (void)
860 return g_quark_from_static_string ("gtk-file-chooser-error-quark");
864 * gtk_file_chooser_set_action:
865 * @chooser: a #GtkFileChooser
866 * @action: the action that the file selector is performing
868 * Sets the type of operation that the chooser is performing; the
869 * user interface is adapted to suit the selected action. For example,
870 * an option to create a new folder might be shown if the action is
871 * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
872 * %GTK_FILE_CHOOSER_ACTION_OPEN.
877 gtk_file_chooser_set_action (GtkFileChooser *chooser,
878 GtkFileChooserAction action)
880 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
882 g_object_set (chooser, "action", action, NULL);
886 * gtk_file_chooser_get_action:
887 * @chooser: a #GtkFileChooser
889 * Gets the type of operation that the file chooser is performing; see
890 * gtk_file_chooser_set_action().
892 * Return value: the action that the file selector is performing
897 gtk_file_chooser_get_action (GtkFileChooser *chooser)
899 GtkFileChooserAction action;
901 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
903 g_object_get (chooser, "action", &action, NULL);
909 * gtk_file_chooser_set_local_only:
910 * @chooser: a #GtkFileChooser
911 * @local_only: %TRUE if only local files can be selected
913 * Sets whether only local files can be selected in the
914 * file selector. If @local_only is %TRUE (the default),
915 * then the selected file are files are guaranteed to be
916 * accessible through the operating systems native file
917 * file system and therefore the application only
918 * needs to worry about the filename functions in
919 * #GtkFileChooser, like gtk_file_chooser_get_filename(),
920 * rather than the URI functions like
921 * gtk_file_chooser_get_uri(),
926 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
929 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
931 g_object_set (chooser, "local-only", local_only, NULL);
935 * gtk_file_chooser_get_local_only:
936 * @chooser: a #GtkFileChoosre
938 * Gets whether only local files can be selected in the
939 * file selector. See gtk_file_chooser_set_local_only()
941 * Return value: %TRUE if only local files can be selected.
946 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
950 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
952 g_object_get (chooser, "local-only", &local_only, NULL);
958 * gtk_file_chooser_set_select_multiple:
959 * @chooser: a #GtkFileChooser
960 * @select_multiple: %TRUE if multiple files can be selected.
962 * Sets whether multiple files can be selected in the file selector. This is
963 * only relevant if the action is set to be %GTK_FILE_CHOOSER_ACTION_OPEN or
964 * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
969 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
970 gboolean select_multiple)
972 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
974 g_object_set (chooser, "select-multiple", select_multiple, NULL);
978 * gtk_file_chooser_get_select_multiple:
979 * @chooser: a #GtkFileChooser
981 * Gets whether multiple files can be selected in the file
982 * selector. See gtk_file_chooser_set_select_multiple().
984 * Return value: %TRUE if multiple files can be selected.
989 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
991 gboolean select_multiple;
993 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
995 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
997 return select_multiple;
1001 * gtk_file_chooser_set_create_folders:
1002 * @chooser: a #GtkFileChooser
1003 * @create_folders: %TRUE if the New Folder button should be displayed
1005 * Sets whether file choser will offer to create new folders.
1006 * This is only relevant if the action is not set to be
1007 * %GTK_FILE_CHOOSER_ACTION_OPEN.
1012 gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
1013 gboolean create_folders)
1015 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1017 g_object_set (chooser, "create-folders", create_folders, NULL);
1021 * gtk_file_chooser_get_create_folders:
1022 * @chooser: a #GtkFileChooser
1024 * Gets whether file choser will offer to create new folders.
1025 * See gtk_file_chooser_set_create_folders().
1027 * Return value: %TRUE if the New Folder button should be displayed.
1032 gtk_file_chooser_get_create_folders (GtkFileChooser *chooser)
1034 gboolean create_folders;
1036 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1038 g_object_get (chooser, "create-folders", &create_folders, NULL);
1040 return create_folders;
1044 * gtk_file_chooser_get_filename:
1045 * @chooser: a #GtkFileChooser
1047 * Gets the filename for the currently selected file in
1048 * the file selector. If multiple files are selected,
1049 * one of the filenames will be returned at random.
1051 * If the file chooser is in folder mode, this function returns the selected
1054 * Return value: The currently selected filename, or %NULL
1055 * if no file is selected, or the selected file can't
1056 * be represented with a local filename. Free with g_free().
1061 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
1064 gchar *result = NULL;
1066 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1068 file = gtk_file_chooser_get_file (chooser);
1072 result = g_file_get_path (file);
1073 g_object_unref (file);
1080 * gtk_file_chooser_set_filename:
1081 * @chooser: a #GtkFileChooser
1082 * @filename: the filename to set as current
1084 * Sets @filename as the current filename for the file chooser, by changing
1085 * to the file's parent folder and actually selecting the file in list. If
1086 * the @chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
1087 * will also appear in the dialog's file name entry.
1089 * If the file name isn't in the current folder of @chooser, then the current
1090 * folder of @chooser will be changed to the folder containing @filename. This
1091 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
1092 * gtk_file_chooser_select_filename().
1094 * Note that the file must exist, or nothing will be done except
1095 * for the directory change.
1097 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
1098 * you should use this function if you already have a file name to which the
1099 * user may save; for example, when the user opens an existing file and then
1100 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
1101 * a file name already — for example, if the user just created a new
1102 * file and is saving it for the first time, do not call this function.
1103 * Instead, use something similar to this:
1105 * if (document_is_new)
1107 * /* the user just created a new document */
1108 * gtk_file_chooser_set_current_folder (chooser, default_folder_for_saving);
1109 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
1113 * /* the user edited an existing document */
1114 * gtk_file_chooser_set_filename (chooser, existing_filename);
1118 * Return value: %TRUE if both the folder could be changed and the file was
1119 * selected successfully, %FALSE otherwise.
1124 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
1125 const gchar *filename)
1127 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1129 gtk_file_chooser_unselect_all (chooser);
1130 return gtk_file_chooser_select_filename (chooser, filename);
1134 * gtk_file_chooser_select_filename:
1135 * @chooser: a #GtkFileChooser
1136 * @filename: the filename to select
1138 * Selects a filename. If the file name isn't in the current
1139 * folder of @chooser, then the current folder of @chooser will
1140 * be changed to the folder containing @filename.
1142 * Return value: %TRUE if both the folder could be changed and the file was
1143 * selected successfully, %FALSE otherwise.
1148 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
1149 const gchar *filename)
1154 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1155 g_return_val_if_fail (filename != NULL, FALSE);
1157 file = g_file_new_for_path (filename);
1158 result = gtk_file_chooser_select_file (chooser, file, NULL);
1159 g_object_unref (file);
1165 * gtk_file_chooser_unselect_filename:
1166 * @chooser: a #GtkFileChooser
1167 * @filename: the filename to unselect
1169 * Unselects a currently selected filename. If the filename
1170 * is not in the current directory, does not exist, or
1171 * is otherwise not currently selected, does nothing.
1176 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
1177 const char *filename)
1181 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1182 g_return_if_fail (filename != NULL);
1184 file = g_file_new_for_path (filename);
1185 gtk_file_chooser_unselect_file (chooser, file);
1186 g_object_unref (file);
1189 /* Converts a list of GFile* to a list of strings using the specified function */
1191 files_to_strings (GSList *files,
1192 gchar * (*convert_func) (GFile *file))
1198 for (; files; files = files->next)
1204 string = (* convert_func) (file);
1207 strings = g_slist_prepend (strings, string);
1210 return g_slist_reverse (strings);
1214 * gtk_file_chooser_get_filenames:
1215 * @chooser: a #GtkFileChooser
1217 * Lists all the selected files and subfolders in the current folder of
1218 * @chooser. The returned names are full absolute paths. If files in the current
1219 * folder cannot be represented as local filenames they will be ignored. (See
1220 * gtk_file_chooser_get_uris())
1222 * Return value: (element-type utf8) (transfer full): a #GSList containing the filenames of all selected
1223 * files and subfolders in the current folder. Free the returned list
1224 * with g_slist_free(), and the filenames with g_free().
1229 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
1231 GSList *files, *result;
1233 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1235 files = gtk_file_chooser_get_files (chooser);
1237 result = files_to_strings (files, g_file_get_path);
1238 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
1239 g_slist_free (files);
1245 * gtk_file_chooser_set_current_folder:
1246 * @chooser: a #GtkFileChooser
1247 * @filename: the full path of the new current folder
1249 * Sets the current folder for @chooser from a local filename.
1250 * The user will be shown the full contents of the current folder,
1251 * plus user interface elements for navigating to other folders.
1253 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1259 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
1260 const gchar *filename)
1265 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1266 g_return_val_if_fail (filename != NULL, FALSE);
1268 file = g_file_new_for_path (filename);
1269 result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
1270 g_object_unref (file);
1276 * gtk_file_chooser_get_current_folder:
1277 * @chooser: a #GtkFileChooser
1279 * Gets the current folder of @chooser as a local filename.
1280 * See gtk_file_chooser_set_current_folder().
1282 * Note that this is the folder that the file chooser is currently displaying
1283 * (e.g. "/home/username/Documents"), which is <emphasis>not the same</emphasis>
1284 * as the currently-selected folder if the chooser is in
1285 * %GTK_FILE_CHOOSER_SELECT_FOLDER mode
1286 * (e.g. "/home/username/Documents/selected-folder/". To get the
1287 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
1288 * usual way to get the selection.
1290 * Return value: the full path of the current folder, or %NULL if the current
1291 * path cannot be represented as a local filename. Free with g_free(). This
1292 * function will also return %NULL if the file chooser was unable to load the
1293 * last folder that was requested from it; for example, as would be for calling
1294 * gtk_file_chooser_set_current_folder() on a nonexistent folder.
1299 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
1304 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1306 file = gtk_file_chooser_get_current_folder_file (chooser);
1310 filename = g_file_get_path (file);
1311 g_object_unref (file);
1317 * gtk_file_chooser_set_current_name:
1318 * @chooser: a #GtkFileChooser
1319 * @name: the filename to use, as a UTF-8 string
1321 * Sets the current name in the file selector, as if entered
1322 * by the user. Note that the name passed in here is a UTF-8
1323 * string rather than a filename. This function is meant for
1324 * such uses as a suggested name in a "Save As..." dialog.
1326 * If you want to preselect a particular existing file, you should use
1327 * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
1328 * Please see the documentation for those functions for an example of using
1329 * gtk_file_chooser_set_current_name() as well.
1334 gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
1337 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1338 g_return_if_fail (name != NULL);
1340 GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
1344 * gtk_file_chooser_get_uri:
1345 * @chooser: a #GtkFileChooser
1347 * Gets the URI for the currently selected file in
1348 * the file selector. If multiple files are selected,
1349 * one of the filenames will be returned at random.
1351 * If the file chooser is in folder mode, this function returns the selected
1354 * Return value: The currently selected URI, or %NULL
1355 * if no file is selected. Free with g_free()
1360 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
1363 gchar *result = NULL;
1365 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1367 file = gtk_file_chooser_get_file (chooser);
1370 result = g_file_get_uri (file);
1371 g_object_unref (file);
1378 * gtk_file_chooser_set_uri:
1379 * @chooser: a #GtkFileChooser
1380 * @uri: the URI to set as current
1382 * Sets the file referred to by @uri as the current file for the file chooser,
1383 * by changing to the URI's parent folder and actually selecting the URI in the
1384 * list. If the @chooser is %GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
1385 * name will also appear in the dialog's file name entry.
1387 * If the URI isn't in the current folder of @chooser, then the current folder
1388 * of @chooser will be changed to the folder containing @uri. This is equivalent
1389 * to a sequence of gtk_file_chooser_unselect_all() followed by
1390 * gtk_file_chooser_select_uri().
1392 * Note that the URI must exist, or nothing will be done except for the
1394 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
1395 * you should use this function if you already have a file name to which the
1396 * user may save; for example, when the user opens an existing file and then
1397 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
1398 * a file name already — for example, if the user just created a new
1399 * file and is saving it for the first time, do not call this function.
1400 * Instead, use something similar to this:
1402 * if (document_is_new)
1404 * /* the user just created a new document */
1405 * gtk_file_chooser_set_current_folder_uri (chooser, default_folder_for_saving);
1406 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
1410 * /* the user edited an existing document */
1411 * gtk_file_chooser_set_uri (chooser, existing_uri);
1415 * Return value: %TRUE if both the folder could be changed and the URI was
1416 * selected successfully, %FALSE otherwise.
1421 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
1424 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1426 gtk_file_chooser_unselect_all (chooser);
1427 return gtk_file_chooser_select_uri (chooser, uri);
1431 * gtk_file_chooser_select_uri:
1432 * @chooser: a #GtkFileChooser
1433 * @uri: the URI to select
1435 * Selects the file to by @uri. If the URI doesn't refer to a
1436 * file in the current folder of @chooser, then the current folder of
1437 * @chooser will be changed to the folder containing @filename.
1439 * Return value: %TRUE if both the folder could be changed and the URI was
1440 * selected successfully, %FALSE otherwise.
1445 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
1451 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1452 g_return_val_if_fail (uri != NULL, FALSE);
1454 file = g_file_new_for_uri (uri);
1455 result = gtk_file_chooser_select_file (chooser, file, NULL);
1456 g_object_unref (file);
1462 * gtk_file_chooser_unselect_uri:
1463 * @chooser: a #GtkFileChooser
1464 * @uri: the URI to unselect
1466 * Unselects the file referred to by @uri. If the file
1467 * is not in the current directory, does not exist, or
1468 * is otherwise not currently selected, does nothing.
1473 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
1478 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1479 g_return_if_fail (uri != NULL);
1481 file = g_file_new_for_uri (uri);
1482 gtk_file_chooser_unselect_file (chooser, file);
1483 g_object_unref (file);
1487 * gtk_file_chooser_select_all:
1488 * @chooser: a #GtkFileChooser
1490 * Selects all the files in the current folder of a file chooser.
1495 gtk_file_chooser_select_all (GtkFileChooser *chooser)
1497 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1499 GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
1503 * gtk_file_chooser_unselect_all:
1504 * @chooser: a #GtkFileChooser
1506 * Unselects all the files in the current folder of a file chooser.
1511 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
1514 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1516 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
1520 * gtk_file_chooser_get_uris:
1521 * @chooser: a #GtkFileChooser
1523 * Lists all the selected files and subfolders in the current folder of
1524 * @chooser. The returned names are full absolute URIs.
1526 * Return value: (element-type utf8) (transfer full): a #GSList containing the URIs of all selected
1527 * files and subfolders in the current folder. Free the returned list
1528 * with g_slist_free(), and the filenames with g_free().
1533 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
1535 GSList *files, *result;
1537 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1539 files = gtk_file_chooser_get_files (chooser);
1541 result = files_to_strings (files, g_file_get_uri);
1542 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
1543 g_slist_free (files);
1549 * gtk_file_chooser_set_current_folder_uri:
1550 * @chooser: a #GtkFileChooser
1551 * @uri: the URI for the new current folder
1553 * Sets the current folder for @chooser from an URI.
1554 * The user will be shown the full contents of the current folder,
1555 * plus user interface elements for navigating to other folders.
1557 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1563 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
1569 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1570 g_return_val_if_fail (uri != NULL, FALSE);
1572 file = g_file_new_for_uri (uri);
1573 result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
1574 g_object_unref (file);
1580 * gtk_file_chooser_get_current_folder_uri:
1581 * @chooser: a #GtkFileChooser
1583 * Gets the current folder of @chooser as an URI.
1584 * See gtk_file_chooser_set_current_folder_uri().
1586 * Note that this is the folder that the file chooser is currently displaying
1587 * (e.g. "file:///home/username/Documents"), which is <emphasis>not the same</emphasis>
1588 * as the currently-selected folder if the chooser is in
1589 * %GTK_FILE_CHOOSER_SELECT_FOLDER mode
1590 * (e.g. "file:///home/username/Documents/selected-folder/". To get the
1591 * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
1592 * usual way to get the selection.
1594 * Return value: the URI for the current folder. Free with g_free(). This
1595 * function will also return %NULL if the file chooser was unable to load the
1596 * last folder that was requested from it; for example, as would be for calling
1597 * gtk_file_chooser_set_current_folder_uri() on a nonexistent folder.
1602 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
1607 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1609 file = gtk_file_chooser_get_current_folder_file (chooser);
1613 uri = g_file_get_uri (file);
1614 g_object_unref (file);
1620 * gtk_file_chooser_set_current_folder_file:
1621 * @chooser: a #GtkFileChooser
1622 * @file: the #GFile for the new folder
1623 * @error: (allow-none): location to store error, or %NULL.
1625 * Sets the current folder for @chooser from a #GFile.
1626 * Internal function, see gtk_file_chooser_set_current_folder_uri().
1628 * Return value: %TRUE if the folder could be changed successfully, %FALSE
1634 gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
1638 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1639 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1640 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1642 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, file, error);
1646 * gtk_file_chooser_get_current_folder_file:
1647 * @chooser: a #GtkFileChooser
1649 * Gets the current folder of @chooser as #GFile.
1650 * See gtk_file_chooser_get_current_folder_uri().
1652 * Return value: the #GFile for the current folder.
1657 gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser)
1659 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1661 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1665 * gtk_file_chooser_select_file:
1666 * @chooser: a #GtkFileChooser
1667 * @file: the file to select
1668 * @error: (allow-none): location to store error, or %NULL
1670 * Selects the file referred to by @file. An internal function. See
1671 * _gtk_file_chooser_select_uri().
1673 * Return value: %TRUE if both the folder could be changed and the path was
1674 * selected successfully, %FALSE otherwise.
1679 gtk_file_chooser_select_file (GtkFileChooser *chooser,
1683 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1684 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1685 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1687 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_file (chooser, file, error);
1691 * gtk_file_chooser_unselect_file:
1692 * @chooser: a #GtkFileChooser
1695 * Unselects the file referred to by @file. If the file is not in the current
1696 * directory, does not exist, or is otherwise not currently selected, does nothing.
1701 gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
1704 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1705 g_return_if_fail (G_IS_FILE (file));
1707 GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_file (chooser, file);
1711 * gtk_file_chooser_get_files:
1712 * @chooser: a #GtkFileChooser
1714 * Lists all the selected files and subfolders in the current folder of @chooser
1715 * as #GFile. An internal function, see gtk_file_chooser_get_uris().
1717 * Return value: (element-type utf8) (transfer full): a #GSList containing a #GFile for each selected
1718 * file and subfolder in the current folder. Free the returned list
1719 * with g_slist_free(), and the files with g_object_unref().
1724 gtk_file_chooser_get_files (GtkFileChooser *chooser)
1726 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1728 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_files (chooser);
1732 * gtk_file_chooser_set_file:
1733 * @chooser: a #GtkFileChooser
1734 * @file: the #GFile to set as current
1735 * @error: (allow-none): location to store the error, or %NULL to ignore errors.
1737 * Sets @file as the current filename for the file chooser, by changing
1738 * to the file's parent folder and actually selecting the file in list. If
1739 * the @chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
1740 * will also appear in the dialog's file name entry.
1742 * If the file name isn't in the current folder of @chooser, then the current
1743 * folder of @chooser will be changed to the folder containing @filename. This
1744 * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
1745 * gtk_file_chooser_select_filename().
1747 * Note that the file must exist, or nothing will be done except
1748 * for the directory change.
1750 * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
1751 * you should use this function if you already have a file name to which the
1752 * user may save; for example, when the user opens an existing file and then
1753 * does <guimenuitem>File/Save As...</guimenuitem> on it. If you don't have
1754 * a file name already — for example, if the user just created a new
1755 * file and is saving it for the first time, do not call this function.
1756 * Instead, use something similar to this:
1758 * if (document_is_new)
1760 * /* the user just created a new document */
1761 * gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
1762 * gtk_file_chooser_set_current_name (chooser, "Untitled document");
1766 * /* the user edited an existing document */
1767 * gtk_file_chooser_set_file (chooser, existing_file);
1771 * Return value: %TRUE if both the folder could be changed and the file was
1772 * selected successfully, %FALSE otherwise.
1777 gtk_file_chooser_set_file (GtkFileChooser *chooser,
1781 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1782 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1783 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1785 gtk_file_chooser_unselect_all (chooser);
1786 return gtk_file_chooser_select_file (chooser, file, error);
1790 * gtk_file_chooser_get_file:
1791 * @chooser: a #GtkFileChooser
1793 * Gets the #GFile for the currently selected file in
1794 * the file selector. If multiple files are selected,
1795 * one of the files will be returned at random.
1797 * If the file chooser is in folder mode, this function returns the selected
1800 * Returns: a selected #GFile. You own the returned file; use
1801 * g_object_unref() to release it.
1806 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1809 GFile *result = NULL;
1811 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1813 list = gtk_file_chooser_get_files (chooser);
1816 result = list->data;
1817 list = g_slist_delete_link (list, list);
1819 g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1820 g_slist_free (list);
1827 * _gtk_file_chooser_get_file_system:
1828 * @chooser: a #GtkFileChooser
1830 * Gets the #GtkFileSystem of @chooser; this is an internal
1831 * implementation detail, used for conversion between paths
1832 * and filenames and URIs.
1834 * Return value: the file system for @chooser.
1839 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1841 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1843 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1849 * gtk_file_chooser_set_preview_widget:
1850 * @chooser: a #GtkFileChooser
1851 * @preview_widget: widget for displaying preview.
1853 * Sets an application-supplied widget to use to display a custom preview
1854 * of the currently selected file. To implement a preview, after setting the
1855 * preview widget, you connect to the #GtkFileChooser::update-preview
1856 * signal, and call gtk_file_chooser_get_preview_filename() or
1857 * gtk_file_chooser_get_preview_uri() on each change. If you can
1858 * display a preview of the new file, update your widget and
1859 * set the preview active using gtk_file_chooser_set_preview_widget_active().
1860 * Otherwise, set the preview inactive.
1862 * When there is no application-supplied preview widget, or the
1863 * application-supplied preview widget is not active, the file chooser
1864 * may display an internally generated preview of the current file or
1865 * it may display no preview at all.
1870 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1871 GtkWidget *preview_widget)
1873 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1875 g_object_set (chooser, "preview-widget", preview_widget, NULL);
1879 * gtk_file_chooser_get_preview_widget:
1880 * @chooser: a #GtkFileChooser
1882 * Gets the current preview widget; see
1883 * gtk_file_chooser_set_preview_widget().
1885 * Return value: the current preview widget, or %NULL
1890 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1892 GtkWidget *preview_widget;
1894 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1896 g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1898 /* Horrid hack; g_object_get() refs returned objects but
1899 * that contradicts the memory management conventions
1903 g_object_unref (preview_widget);
1905 return preview_widget;
1909 * gtk_file_chooser_set_preview_widget_active:
1910 * @chooser: a #GtkFileChooser
1911 * @active: whether to display the user-specified preview widget
1913 * Sets whether the preview widget set by
1914 * gtk_file_chooser_set_preview_widget() should be shown for the
1915 * current filename. When @active is set to false, the file chooser
1916 * may display an internally generated preview of the current file
1917 * or it may display no preview at all. See
1918 * gtk_file_chooser_set_preview_widget() for more details.
1923 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1926 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1928 g_object_set (chooser, "preview-widget-active", active, NULL);
1932 * gtk_file_chooser_get_preview_widget_active:
1933 * @chooser: a #GtkFileChooser
1935 * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1936 * should be shown for the current filename. See
1937 * gtk_file_chooser_set_preview_widget_active().
1939 * Return value: %TRUE if the preview widget is active for the current filename.
1944 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1948 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1950 g_object_get (chooser, "preview-widget-active", &active, NULL);
1956 * gtk_file_chooser_set_use_preview_label:
1957 * @chooser: a #GtkFileChooser
1958 * @use_label: whether to display a stock label with the name of the previewed file
1960 * Sets whether the file chooser should display a stock label with the name of
1961 * the file that is being previewed; the default is %TRUE. Applications that
1962 * want to draw the whole preview area themselves should set this to %FALSE and
1963 * display the name themselves in their preview widget.
1965 * See also: gtk_file_chooser_set_preview_widget()
1970 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1973 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1975 g_object_set (chooser, "use-preview-label", use_label, NULL);
1979 * gtk_file_chooser_get_use_preview_label:
1980 * @chooser: a #GtkFileChooser
1982 * Gets whether a stock label should be drawn with the name of the previewed
1983 * file. See gtk_file_chooser_set_use_preview_label().
1985 * Return value: %TRUE if the file chooser is set to display a label with the
1986 * name of the previewed file, %FALSE otherwise.
1989 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1993 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1995 g_object_get (chooser, "use-preview-label", &use_label, NULL);
2001 * gtk_file_chooser_get_preview_file:
2002 * @chooser: a #GtkFileChooser
2004 * Gets the #GFile that should be previewed in a custom preview
2005 * Internal function, see gtk_file_chooser_get_preview_uri().
2007 * Return value: the #GFile for the file to preview, or %NULL if no file
2008 * is selected. Free with g_object_unref().
2013 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
2015 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2017 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
2021 * _gtk_file_chooser_add_shortcut_folder:
2022 * @chooser: a #GtkFileChooser
2023 * @file: file for the folder to add
2024 * @error: (allow-none): location to store error, or %NULL
2026 * Adds a folder to be displayed with the shortcut folders in a file chooser.
2027 * Internal function, see gtk_file_chooser_add_shortcut_folder().
2029 * Return value: %TRUE if the folder could be added successfully, %FALSE
2035 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2039 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2040 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2042 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
2046 * _gtk_file_chooser_remove_shortcut_folder:
2047 * @chooser: a #GtkFileChooser
2048 * @file: file for the folder to remove
2049 * @error: (allow-none): location to store error, or %NULL
2051 * Removes a folder from the shortcut folders in a file chooser. Internal
2052 * function, see gtk_file_chooser_remove_shortcut_folder().
2054 * Return value: %TRUE if the folder could be removed successfully, %FALSE
2060 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2064 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2065 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2067 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
2071 * gtk_file_chooser_get_preview_filename:
2072 * @chooser: a #GtkFileChooser
2074 * Gets the filename that should be previewed in a custom preview
2075 * widget. See gtk_file_chooser_set_preview_widget().
2077 * Return value: the filename to preview, or %NULL if no file
2078 * is selected, or if the selected file cannot be represented
2079 * as a local filename. Free with g_free()
2084 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2087 gchar *result = NULL;
2089 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2091 file = gtk_file_chooser_get_preview_file (chooser);
2094 result = g_file_get_path (file);
2095 g_object_unref (file);
2102 * gtk_file_chooser_get_preview_uri:
2103 * @chooser: a #GtkFileChooser
2105 * Gets the URI that should be previewed in a custom preview
2106 * widget. See gtk_file_chooser_set_preview_widget().
2108 * Return value: the URI for the file to preview, or %NULL if no file is
2109 * selected. Free with g_free().
2114 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
2117 gchar *result = NULL;
2119 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2121 file = gtk_file_chooser_get_preview_file (chooser);
2124 result = g_file_get_uri (file);
2125 g_object_unref (file);
2132 * gtk_file_chooser_set_extra_widget:
2133 * @chooser: a #GtkFileChooser
2134 * @extra_widget: widget for extra options
2136 * Sets an application-supplied widget to provide extra options to the user.
2141 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
2142 GtkWidget *extra_widget)
2144 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2146 g_object_set (chooser, "extra-widget", extra_widget, NULL);
2150 * gtk_file_chooser_get_extra_widget:
2151 * @chooser: a #GtkFileChooser
2153 * Gets the current preview widget; see
2154 * gtk_file_chooser_set_extra_widget().
2156 * Return value: the current extra widget, or %NULL
2161 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
2163 GtkWidget *extra_widget;
2165 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2167 g_object_get (chooser, "extra-widget", &extra_widget, NULL);
2169 /* Horrid hack; g_object_get() refs returned objects but
2170 * that contradicts the memory management conventions
2174 g_object_unref (extra_widget);
2176 return extra_widget;
2180 * gtk_file_chooser_add_filter:
2181 * @chooser: a #GtkFileChooser
2182 * @filter: a #GtkFileFilter
2184 * Adds @filter to the list of filters that the user can select between.
2185 * When a filter is selected, only files that are passed by that
2186 * filter are displayed.
2188 * Note that the @chooser takes ownership of the filter, so you have to
2189 * ref and sink it if you want to keep a reference.
2194 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
2195 GtkFileFilter *filter)
2197 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2199 GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
2203 * gtk_file_chooser_remove_filter:
2204 * @chooser: a #GtkFileChooser
2205 * @filter: a #GtkFileFilter
2207 * Removes @filter from the list of filters that the user can select between.
2212 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
2213 GtkFileFilter *filter)
2215 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2217 GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
2221 * gtk_file_chooser_list_filters:
2222 * @chooser: a #GtkFileChooser
2224 * Lists the current set of user-selectable filters; see
2225 * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
2227 * Return value: (element-type utf8) (transfer container): a #GSList containing the current set of
2228 * user selectable filters. The contents of the list are
2229 * owned by GTK+, but you must free the list itself with
2230 * g_slist_free() when you are done with it.
2235 gtk_file_chooser_list_filters (GtkFileChooser *chooser)
2237 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2239 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
2243 * gtk_file_chooser_set_filter:
2244 * @chooser: a #GtkFileChooser
2245 * @filter: a #GtkFileFilter
2247 * Sets the current filter; only the files that pass the
2248 * filter will be displayed. If the user-selectable list of filters
2249 * is non-empty, then the filter should be one of the filters
2250 * in that list. Setting the current filter when the list of
2251 * filters is empty is useful if you want to restrict the displayed
2252 * set of files without letting the user change it.
2257 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
2258 GtkFileFilter *filter)
2260 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2261 g_return_if_fail (GTK_IS_FILE_FILTER (filter));
2263 g_object_set (chooser, "filter", filter, NULL);
2267 * gtk_file_chooser_get_filter:
2268 * @chooser: a #GtkFileChooser
2270 * Gets the current filter; see gtk_file_chooser_set_filter().
2272 * Return value: the current filter, or %NULL
2277 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
2279 GtkFileFilter *filter;
2281 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2283 g_object_get (chooser, "filter", &filter, NULL);
2284 /* Horrid hack; g_object_get() refs returned objects but
2285 * that contradicts the memory management conventions
2289 g_object_unref (filter);
2295 * gtk_file_chooser_add_shortcut_folder:
2296 * @chooser: a #GtkFileChooser
2297 * @folder: filename of the folder to add
2298 * @error: (allow-none): location to store error, or %NULL
2300 * Adds a folder to be displayed with the shortcut folders in a file chooser.
2301 * Note that shortcut folders do not get saved, as they are provided by the
2302 * application. For example, you can use this to add a
2303 * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
2305 * Return value: %TRUE if the folder could be added successfully, %FALSE
2306 * otherwise. In the latter case, the @error will be set as appropriate.
2311 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2318 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2319 g_return_val_if_fail (folder != NULL, FALSE);
2321 file = g_file_new_for_path (folder);
2322 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
2323 g_object_unref (file);
2329 * gtk_file_chooser_remove_shortcut_folder:
2330 * @chooser: a #GtkFileChooser
2331 * @folder: filename of the folder to remove
2332 * @error: (allow-none): location to store error, or %NULL
2334 * Removes a folder from a file chooser's list of shortcut folders.
2336 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
2337 * In the latter case, the @error will be set as appropriate.
2339 * See also: gtk_file_chooser_add_shortcut_folder()
2344 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2351 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2352 g_return_val_if_fail (folder != NULL, FALSE);
2354 file = g_file_new_for_path (folder);
2355 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
2356 g_object_unref (file);
2362 * gtk_file_chooser_list_shortcut_folders:
2363 * @chooser: a #GtkFileChooser
2365 * Queries the list of shortcut folders in the file chooser, as set by
2366 * gtk_file_chooser_add_shortcut_folder().
2368 * Return value: (element-type utf8) (transfer full): A list of folder filenames, or %NULL if there are no shortcut
2369 * folders. Free the returned list with g_slist_free(), and the filenames with
2375 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2380 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2382 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
2384 result = files_to_strings (folders, g_file_get_path);
2385 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
2386 g_slist_free (folders);
2392 * gtk_file_chooser_add_shortcut_folder_uri:
2393 * @chooser: a #GtkFileChooser
2394 * @uri: URI of the folder to add
2395 * @error: (allow-none): location to store error, or %NULL
2397 * Adds a folder URI to be displayed with the shortcut folders in a file
2398 * chooser. Note that shortcut folders do not get saved, as they are provided
2399 * by the application. For example, you can use this to add a
2400 * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
2402 * Return value: %TRUE if the folder could be added successfully, %FALSE
2403 * otherwise. In the latter case, the @error will be set as appropriate.
2408 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
2415 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2416 g_return_val_if_fail (uri != NULL, FALSE);
2418 file = g_file_new_for_uri (uri);
2419 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
2420 g_object_unref (file);
2426 * gtk_file_chooser_remove_shortcut_folder_uri:
2427 * @chooser: a #GtkFileChooser
2428 * @uri: URI of the folder to remove
2429 * @error: (allow-none): location to store error, or %NULL
2431 * Removes a folder URI from a file chooser's list of shortcut folders.
2433 * Return value: %TRUE if the operation succeeds, %FALSE otherwise.
2434 * In the latter case, the @error will be set as appropriate.
2436 * See also: gtk_file_chooser_add_shortcut_folder_uri()
2441 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
2448 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2449 g_return_val_if_fail (uri != NULL, FALSE);
2451 file = g_file_new_for_uri (uri);
2452 result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
2453 g_object_unref (file);
2459 * gtk_file_chooser_list_shortcut_folder_uris:
2460 * @chooser: a #GtkFileChooser
2462 * Queries the list of shortcut folders in the file chooser, as set by
2463 * gtk_file_chooser_add_shortcut_folder_uri().
2465 * Return value: (element-type utf8) (transfer full): A list of folder URIs, or %NULL if there are no shortcut
2466 * folders. Free the returned list with g_slist_free(), and the URIs with
2472 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
2477 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2479 folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
2481 result = files_to_strings (folders, g_file_get_uri);
2482 g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
2483 g_slist_free (folders);
2489 _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
2491 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2493 return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
2497 * gtk_file_chooser_set_show_hidden:
2498 * @chooser: a #GtkFileChooser
2499 * @show_hidden: %TRUE if hidden files and folders should be displayed.
2501 * Sets whether hidden files and folders are displayed in the file selector.
2506 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
2507 gboolean show_hidden)
2509 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2511 g_object_set (chooser, "show-hidden", show_hidden, NULL);
2515 * gtk_file_chooser_get_show_hidden:
2516 * @chooser: a #GtkFileChooser
2518 * Gets whether hidden files and folders are displayed in the file selector.
2519 * See gtk_file_chooser_set_show_hidden().
2521 * Return value: %TRUE if hidden files and folders are displayed.
2526 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
2528 gboolean show_hidden;
2530 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2532 g_object_get (chooser, "show-hidden", &show_hidden, NULL);
2538 * gtk_file_chooser_set_do_overwrite_confirmation:
2539 * @chooser: a #GtkFileChooser
2540 * @do_overwrite_confirmation: whether to confirm overwriting in save mode
2542 * Sets whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode will present
2543 * a confirmation dialog if the user types a file name that already exists. This
2544 * is %FALSE by default.
2546 * Regardless of this setting, the @chooser will emit the
2547 * #GtkFileChooser::confirm-overwrite signal when appropriate.
2549 * If all you need is the stock confirmation dialog, set this property to %TRUE.
2550 * You can override the way confirmation is done by actually handling the
2551 * #GtkFileChooser::confirm-overwrite signal; please refer to its documentation
2557 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
2558 gboolean do_overwrite_confirmation)
2560 g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2562 g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
2566 * gtk_file_chooser_get_do_overwrite_confirmation:
2567 * @chooser: a #GtkFileChooser
2569 * Queries whether a file chooser is set to confirm for overwriting when the user
2570 * types a file name that already exists.
2572 * Return value: %TRUE if the file chooser will present a confirmation dialog;
2578 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
2580 gboolean do_overwrite_confirmation;
2582 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2584 g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
2586 return do_overwrite_confirmation;
2589 #if defined (G_OS_WIN32) && !defined (_WIN64)
2591 /* DLL ABI stability backward compatibility versions */
2593 #undef gtk_file_chooser_get_filename
2596 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
2598 gchar *utf8_filename = gtk_file_chooser_get_filename_utf8 (chooser);
2599 gchar *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2601 g_free (utf8_filename);
2606 #undef gtk_file_chooser_set_filename
2609 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
2610 const gchar *filename)
2612 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2613 gboolean retval = gtk_file_chooser_set_filename_utf8 (chooser, utf8_filename);
2615 g_free (utf8_filename);
2620 #undef gtk_file_chooser_select_filename
2623 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
2624 const gchar *filename)
2626 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2627 gboolean retval = gtk_file_chooser_select_filename_utf8 (chooser, utf8_filename);
2629 g_free (utf8_filename);
2634 #undef gtk_file_chooser_unselect_filename
2637 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
2638 const char *filename)
2640 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2642 gtk_file_chooser_unselect_filename_utf8 (chooser, utf8_filename);
2643 g_free (utf8_filename);
2646 #undef gtk_file_chooser_get_filenames
2649 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
2651 GSList *list = gtk_file_chooser_get_filenames_utf8 (chooser);
2652 GSList *rover = list;
2656 gchar *tem = (gchar *) rover->data;
2657 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2659 rover = rover->next;
2665 #undef gtk_file_chooser_set_current_folder
2668 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
2669 const gchar *filename)
2671 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2672 gboolean retval = gtk_file_chooser_set_current_folder_utf8 (chooser, utf8_filename);
2674 g_free (utf8_filename);
2679 #undef gtk_file_chooser_get_current_folder
2682 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
2684 gchar *utf8_folder = gtk_file_chooser_get_current_folder_utf8 (chooser);
2685 gchar *retval = g_locale_from_utf8 (utf8_folder, -1, NULL, NULL, NULL);
2687 g_free (utf8_folder);
2692 #undef gtk_file_chooser_get_preview_filename
2695 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2697 char *utf8_filename = gtk_file_chooser_get_preview_filename_utf8 (chooser);
2698 char *retval = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
2700 g_free (utf8_filename);
2705 #undef gtk_file_chooser_add_shortcut_folder
2708 gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
2712 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2714 gtk_file_chooser_add_shortcut_folder_utf8 (chooser, utf8_folder, error);
2716 g_free (utf8_folder);
2721 #undef gtk_file_chooser_remove_shortcut_folder
2724 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
2728 char *utf8_folder = g_locale_to_utf8 (folder, -1, NULL, NULL, NULL);
2730 gtk_file_chooser_remove_shortcut_folder_utf8 (chooser, utf8_folder, error);
2732 g_free (utf8_folder);
2737 #undef gtk_file_chooser_list_shortcut_folders
2740 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2742 GSList *list = gtk_file_chooser_list_shortcut_folders_utf8 (chooser);
2743 GSList *rover = list;
2747 gchar *tem = (gchar *) rover->data;
2748 rover->data = g_locale_from_utf8 ((gchar *) rover->data, -1, NULL, NULL, NULL);
2750 rover = rover->next;