]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooser.c
Update the docs with the policies for Save dialogs
[~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 "config.h"
22 #include "gtkfilechooser.h"
23 #include "gtkfilechooserprivate.h"
24 #include "gtkintl.h"
25 #include "gtktypebuiltins.h"
26 #include "gtkprivate.h"
27 #include "gtkmarshalers.h"
28
29
30 /**
31  * SECTION:gtkfilechooser
32  * @Short_description: File chooser interface used by GtkFileChooserWidget and GtkFileChooserDialog
33  * @Title: GtkFileChooser
34  * @See_also: #GtkFileChooserDialog, #GtkFileChooserWidget, #GtkFileChooserButton
35  *
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
42  * interface.
43  *
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:
48  * <variablelist>
49  *    <varlistentry>
50  *       <term>Bookmarks</term>
51  *       <listitem>
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.
55  *       </listitem>
56  *    </varlistentry>
57  *    <varlistentry>
58  *       <term>Shortcuts</term>
59  *       <listitem>
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
63  *          user.
64  *       </listitem>
65  *    </varlistentry>
66  *    <varlistentry>
67  *       <term>Volumes</term>
68  *       <listitem>
69  *          are provided by the underlying filesystem abstraction. They are
70  *          the "roots" of the filesystem.
71  *       </listitem>
72  *    </varlistentry>
73  * </variablelist>
74  *
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
85  * variable.
86  * <note>
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.
95  * </note>
96  * </refsect2>
97  * <refsect2 id="gtkfilechooser-preview">
98  * <title>Adding a Preview Widget</title>
99  * <para>
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.
106  * </para>
107  * <para>
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.
115  * </para>
116  * <example id="example-gtkfilechooser-preview">
117  * <title>Sample Usage</title>
118  * <programlisting>
119  * {
120  *   GtkImage *preview;
121  *
122  *   ...
123  *
124  *   preview = gtk_image_new (<!-- -->);
125  *
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);
129  * }
130  *
131  * static void
132  * update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
133  * {
134  *   GtkWidget *preview;
135  *   char *filename;
136  *   GdkPixbuf *pixbuf;
137  *   gboolean have_preview;
138  *
139  *   preview = GTK_WIDGET (data);
140  *   filename = gtk_file_chooser_get_preview_filename (file_chooser);
141  *
142  *   pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
143  *   have_preview = (pixbuf != NULL);
144  *   g_free (filename);
145  *
146  *   gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
147  *   if (pixbuf)
148  *     g_object_unref (pixbuf);
149  *
150  *   gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
151  * }
152  * </programlisting>
153  * </example>
154  * </refsect2>
155  * <refsect2 id="gtkfilechooser-extra">
156  * <title>Adding Extra Widgets</title>
157  * <para>
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.
164  * </para>
165  * <example id="example-gtkfilechooser-extra">
166  * <title>Sample Usage</title>
167  * <programlisting>
168  *
169  *   GtkWidget *toggle;
170  *
171  *   ...
172  *
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);
176  * }
177  * </programlisting>
178  * </example>
179  * <note>
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.
184  * </note>
185  * </refsect2>
186  * <refsect2 id="gtkfilechooser-key-bindings">
187  * <title>Key Bindings</title>
188  * <para>
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.
195  * </para>
196  * <example id="gtkfilechooser-key-binding-example">
197  * <title>GtkFileChooser key binding example</title>
198  * <para>
199  * The default keys that activate the key-binding signals in
200  * <classname>GtkFileChooserDefaultClass</classname> are as
201  * follows:
202  * </para>
203  *      <informaltable>
204  *        <tgroup cols="2">
205  *          <tbody>
206  *            <row>
207  *              <entry>Signal name</entry>
208  *              <entry>Default key combinations</entry>
209  *            </row>
210  *            <row>
211  *              <entry>location-popup</entry>
212  *              <entry>
213  *                <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo> (empty path);
214  *                <keycap>/</keycap> (path of "/")
215  *                <footnote>
216  *                    Both the individual <keycap>/</keycap> key and the
217  *                    numeric keypad's "divide" key are supported.
218  *                </footnote>;
219  *                <keycap>~</keycap> (path of "~")
220  *              </entry>
221  *            </row>
222  *            <row>
223  *              <entry>up-folder</entry>
224  *              <entry>
225  *                <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>;
226  *                <keycombo><keycap>Alt</keycap><keycap>Shift</keycap><keycap>Up</keycap></keycombo>
227  *                <footnote>
228  *                    Both the individual Up key and the numeric
229  *                    keypad's Up key are supported.
230  *                </footnote>;
231  *                <keycap>Backspace</keycap>
232  *              </entry>
233  *            </row>
234  *            <row>
235  *              <entry>down-folder</entry>
236  *              <entry>
237  *                <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>;
238  *                <keycombo><keycap>Alt</keycap><keycap>Shift</keycap><keycap>Down</keycap></keycombo>
239  *                <footnote>
240  *                    Both the individual Down key and the numeric
241  *                    keypad's Down key are supported.
242  *                </footnote>
243  *              </entry>
244  *            </row>
245  *            <row>
246  *              <entry>home-folder</entry>
247  *              <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
248  *            </row>
249  *            <row>
250  *              <entry>desktop-folder</entry>
251  *              <entry><keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo></entry>
252  *            </row>
253  *            <row>
254  *              <entry>quick-bookmark</entry>
255  *              <entry><keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo> through <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo></entry>
256  *            </row>
257  *          </tbody>
258  *        </tgroup>
259  *      </informaltable>
260  * <para>
261  * You can change these defaults to something else.  For
262  * example, to add a <keycap>Shift</keycap> modifier to a few
263  * of the default bindings, you can include the following
264  * fragment in your <filename>.config/gtk-3.0/gtk.css</filename> file:
265  * </para>
266  * <programlisting>
267  * @binding-set MyOwnFilechooserBindings
268  * {
269  *   bind "&lt;Alt&gt;&lt;Shift&gt;Up" { "up-folder" () }
270  *   bind "&lt;Alt&gt;&lt;Shift&gt;Down" { "down-folder" () }
271  *   bind "&lt;Alt&gt;&lt;Shift&gt;Home" { "home-folder" () }
272  * }
273  *
274  * GtkFileChooserDefault
275  * {
276  *    gtk-key-bindings: MyOwnFilechooserBindings
277  * }
278  * </programlisting>
279  * </example>
280  * <refsect3 id="GtkFileChooserDefault-location-popup">
281  * <title>The &quot;GtkFileChooserDefault::location-popup&quot; signal</title>
282  * <programlisting>
283  *    void user_function (GtkFileChooserDefault *chooser,
284  *                        const char            *path,
285  * <link linkend="gpointer">gpointer</link>      user_data);
286  * </programlisting>
287  * <para>
288  * This is used to make the file chooser show a "Location"
289  * dialog which the user can use to manually type the name of
290  * the file he wishes to select.  The
291  * <parameter>path</parameter> argument is a string that gets
292  * put in the text entry for the file name.  By default this is bound to
293  * <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
294  * with a <parameter>path</parameter> string of "" (the empty
295  * string).  It is also bound to <keycap>/</keycap> with a
296  * <parameter>path</parameter> string of "<literal>/</literal>"
297  * (a slash):  this lets you type <keycap>/</keycap> and
298  * immediately type a path name.  On Unix systems, this is bound to
299  * <keycap>~</keycap> (tilde) with a <parameter>path</parameter> string
300  * of "~" itself for access to home directories.
301  * </para>
302  *      <variablelist role="params">
303  *        <varlistentry>
304  *          <term><parameter>chooser</parameter>&nbsp;:</term>
305  *          <listitem>
306  *            <simpara>
307  *              the object which received the signal.
308  *            </simpara>
309  *          </listitem>
310  *        </varlistentry>
311  *        <varlistentry>
312  *          <term><parameter>path</parameter>&nbsp;:</term>
313  *          <listitem>
314  *            <simpara>
315  *              default contents for the text entry for the file name
316  *            </simpara>
317  *          </listitem>
318  *        </varlistentry>
319  *        <varlistentry>
320  *          <term><parameter>user_data</parameter>&nbsp;:</term>
321  *          <listitem>
322  *            <simpara>
323  *              user data set when the signal handler was connected.
324  *            </simpara>
325  *          </listitem>
326  *        </varlistentry>
327  *      </variablelist>
328  * <note>
329  *    You can create your own bindings for the
330  *    #GtkFileChooserDefault::location-popup signal with custom
331  *    <parameter>path</parameter> strings, and have a crude form
332  *    of easily-to-type bookmarks.  For example, say you access
333  *    the path <filename>/home/username/misc</filename> very
334  *    frequently.  You could then create an <keycombo>
335  *    <keycap>Alt</keycap> <keycap>M</keycap> </keycombo>
336  *    shortcut by including the following in your
337  *    <filename>.config/gtk-3.0/gtk.css</filename>:
338  *    <programlisting>
339  *    @binding-set MiscShortcut
340  *    {
341  *      bind "&lt;Alt&gt;M" { "location-popup" ("/home/username/misc") }
342  *    }
343  *
344  *    GtkFileChooserDefault
345  *    {
346  *      gtk-key-bindings: MiscShortcut
347  *    }
348  *    </programlisting>
349  * </note>
350  * </refsect3>
351  * <refsect3 id="GtkFileChooserDefault-up-folder">
352  * <title>The &quot;GtkFileChooserDefault::up-folder&quot; signal</title>
353  * <programlisting>
354  *           void user_function (GtkFileChooserDefault *chooser,
355  *                               <link linkend="gpointer">gpointer</link> user_data);
356  * </programlisting>
357  * <para>
358  * This is used to make the file chooser go to the parent of
359  * the current folder in the file hierarchy.  By default this
360  * is bound to <keycap>Backspace</keycap> and
361  * <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>
362  * (the Up key in the numeric keypad also works).
363  * </para>
364  *      <variablelist role="params">
365  *        <varlistentry>
366  *          <term><parameter>chooser</parameter>&nbsp;:</term>
367  *          <listitem>
368  *            <simpara>
369  *              the object which received the signal.
370  *            </simpara>
371  *          </listitem>
372  *        </varlistentry>
373  *        <varlistentry>
374  *          <term><parameter>user_data</parameter>&nbsp;:</term>
375  *          <listitem>
376  *            <simpara>
377  *              user data set when the signal handler was connected.
378  *            </simpara>
379  *          </listitem>
380  *        </varlistentry>
381  *      </variablelist>
382  * </refsect3>
383  * <refsect3 id="GtkFileChooserDefault-down-folder">
384  * <title>The &quot;GtkFileChooserDefault::down-folder&quot; signal</title>
385  * <programlisting>
386  *           void user_function (GtkFileChooserDefault *chooser,
387  *                               <link linkend="gpointer">gpointer</link> user_data);
388  * </programlisting>
389  * <para>
390  * This is used to make the file chooser go to a child of the
391  * current folder in the file hierarchy.  The subfolder that
392  * will be used is displayed in the path bar widget of the file
393  * chooser.  For example, if the path bar is showing
394  * "/foo/<emphasis>bar/</emphasis>baz", then this will cause
395  * the file chooser to switch to the "baz" subfolder.  By
396  * default this is bound to
397  * <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>
398  * (the Down key in the numeric keypad also works).
399  * </para>
400  *      <variablelist role="params">
401  *        <varlistentry>
402  *          <term><parameter>chooser</parameter>&nbsp;:</term>
403  *          <listitem>
404  *            <simpara>
405  *              the object which received the signal.
406  *            </simpara>
407  *          </listitem>
408  *        </varlistentry>
409  *        <varlistentry>
410  *          <term><parameter>user_data</parameter>&nbsp;:</term>
411  *          <listitem>
412  *            <simpara>
413  *              user data set when the signal handler was connected.
414  *            </simpara>
415  *          </listitem>
416  *        </varlistentry>
417  *      </variablelist>
418  * </refsect3>
419  * <refsect3 id="GtkFileChooserDefault-home-folder">
420  * <title>The &quot;GtkFileChooserDefault::home-folder&quot; signal</title>
421  * <programlisting>
422  *           void user_function (GtkFileChooserDefault *chooser,
423  *                               <link linkend="gpointer">gpointer</link> user_data);
424  * </programlisting>
425  * <para>
426  * This is used to make the file chooser show the user's home
427  * folder in the file list.  By default this is bound to
428  * <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>
429  * (the Home key in the numeric keypad also works).
430  * </para>
431  *      <variablelist role="params">
432  *        <varlistentry>
433  *          <term><parameter>chooser</parameter>&nbsp;:</term>
434  *          <listitem>
435  *            <simpara>
436  *              the object which received the signal.
437  *            </simpara>
438  *          </listitem>
439  *        </varlistentry>
440  *        <varlistentry>
441  *          <term><parameter>user_data</parameter>&nbsp;:</term>
442  *          <listitem>
443  *            <simpara>
444  *              user data set when the signal handler was connected.
445  *            </simpara>
446  *          </listitem>
447  *        </varlistentry>
448  *      </variablelist>
449  * </refsect3>
450  * <refsect3 id="GtkFileChooserDefault-desktop-folder">
451  * <title>The &quot;GtkFileChooserDefault::desktop-folder&quot; signal</title>
452  * <programlisting>
453  *           void user_function (GtkFileChooserDefault *chooser,
454  *                               <link linkend="gpointer">gpointer</link> user_data);
455  * </programlisting>
456  * <para>
457  * This is used to make the file chooser show the user's Desktop
458  * folder in the file list.  By default this is bound to
459  * <keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo>.
460  * </para>
461  *      <variablelist role="params">
462  *        <varlistentry>
463  *          <term><parameter>chooser</parameter>&nbsp;:</term>
464  *          <listitem>
465  *            <simpara>
466  *              the object which received the signal.
467  *            </simpara>
468  *          </listitem>
469  *        </varlistentry>
470  *        <varlistentry>
471  *          <term><parameter>user_data</parameter>&nbsp;:</term>
472  *          <listitem>
473  *            <simpara>
474  *              user data set when the signal handler was connected.
475  *            </simpara>
476  *          </listitem>
477  *        </varlistentry>
478  *      </variablelist>
479  * </refsect3>
480  * <refsect3 id="GtkFileChooserDefault-quick-bookmark">
481  * <title>The &quot;GtkFileChooserDefault::quick-bookmark&quot; signal</title>
482  * <programlisting>
483  *           void user_function (GtkFileChooserDefault *chooser,
484  *                               gint bookmark_index,
485  *                               <link linkend="gpointer">gpointer</link> user_data);
486  * </programlisting>
487  * <para>
488  * This is used to make the file chooser switch to the bookmark
489  * specified in the <parameter>bookmark_index</parameter> parameter.
490  * For example, if you have three bookmarks, you can pass 0, 1, 2 to
491  * this signal to switch to each of them, respectively.  By default this is bound to
492  * <keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo>,
493  * <keycombo><keycap>Alt</keycap><keycap>2</keycap></keycombo>,
494  * etc. until
495  * <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo>.  Note
496  * that in the default binding,
497  * that <keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo> is
498  * actually defined to switch to the bookmark at index 0, and so on
499  * successively;
500  * <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo> is
501  * defined to switch to the bookmark at index 10.
502  * </para>
503  *      <variablelist role="params">
504  *        <varlistentry>
505  *          <term><parameter>chooser</parameter>&nbsp;:</term>
506  *          <listitem>
507  *            <simpara>
508  *              the object which received the signal.
509  *            </simpara>
510  *          </listitem>
511  *        </varlistentry>
512  *        <varlistentry>
513  *          <term><parameter>bookmark_indes</parameter>&nbsp;:</term>
514  *          <listitem>
515  *            <simpara>
516  *              index of the bookmark to switch to; the indices start at 0.
517  *            </simpara>
518  *          </listitem>
519  *        </varlistentry>
520  *        <varlistentry>
521  *          <term><parameter>user_data</parameter>&nbsp;:</term>
522  *          <listitem>
523  *            <simpara>
524  *              user data set when the signal handler was connected.
525  *            </simpara>
526  *          </listitem>
527  *        </varlistentry>
528  *      </variablelist>
529  * </refsect3>
530  * </refsect2>
531  */
532
533
534 typedef GtkFileChooserIface GtkFileChooserInterface;
535 G_DEFINE_INTERFACE (GtkFileChooser, gtk_file_chooser, GTK_TYPE_WIDGET);
536
537 static gboolean
538 confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
539                                GValue                *return_accu,
540                                const GValue          *handler_return,
541                                gpointer               dummy)
542 {
543   gboolean continue_emission;
544   GtkFileChooserConfirmation conf;
545
546   conf = g_value_get_enum (handler_return);
547   g_value_set_enum (return_accu, conf);
548   continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
549
550   return continue_emission;
551 }
552
553 static void
554 gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
555 {
556   GType iface_type = G_TYPE_FROM_INTERFACE (iface);
557
558   /**
559    * GtkFileChooser::current-folder-changed
560    * @chooser: the object which received the signal.
561    *
562    * This signal is emitted when the current folder in a #GtkFileChooser
563    * changes.  This can happen due to the user performing some action that
564    * changes folders, such as selecting a bookmark or visiting a folder on the
565    * file list.  It can also happen as a result of calling a function to
566    * explicitly change the current folder in a file chooser.
567    *
568    * Normally you do not need to connect to this signal, unless you need to keep
569    * track of which folder a file chooser is showing.
570    *
571    * See also:  gtk_file_chooser_set_current_folder(),
572    * gtk_file_chooser_get_current_folder(),
573    * gtk_file_chooser_set_current_folder_uri(),
574    * gtk_file_chooser_get_current_folder_uri().
575    */
576   g_signal_new (I_("current-folder-changed"),
577                 iface_type,
578                 G_SIGNAL_RUN_LAST,
579                 G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
580                 NULL, NULL,
581                 g_cclosure_marshal_VOID__VOID,
582                 G_TYPE_NONE, 0);
583
584   /**
585    * GtkFileChooser::selection-changed
586    * @chooser: the object which received the signal.
587    *
588    * This signal is emitted when there is a change in the set of selected files
589    * in a #GtkFileChooser.  This can happen when the user modifies the selection
590    * with the mouse or the keyboard, or when explicitly calling functions to
591    * change the selection.
592    *
593    * Normally you do not need to connect to this signal, as it is easier to wait
594    * for the file chooser to finish running, and then to get the list of
595    * selected files using the functions mentioned below.
596    *
597    * See also: gtk_file_chooser_select_filename(),
598    * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
599    * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
600    * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
601    * gtk_file_chooser_get_uris().
602    */
603   g_signal_new (I_("selection-changed"),
604                 iface_type,
605                 G_SIGNAL_RUN_LAST,
606                 G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
607                 NULL, NULL,
608                 g_cclosure_marshal_VOID__VOID,
609                 G_TYPE_NONE, 0);
610
611   /**
612    * GtkFileChooser::update-preview
613    * @chooser: the object which received the signal.
614    *
615    * This signal is emitted when the preview in a file chooser should be
616    * regenerated.  For example, this can happen when the currently selected file
617    * changes.  You should use this signal if you want your file chooser to have
618    * a preview widget.
619    *
620    * Once you have installed a preview widget with
621    * gtk_file_chooser_set_preview_widget(), you should update it when this
622    * signal is emitted.  You can use the functions
623    * gtk_file_chooser_get_preview_filename() or
624    * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
625    * Your widget may not be able to preview all kinds of files; your callback
626    * must call gtk_file_chooser_set_preview_widget_active() to inform the file
627    * chooser about whether the preview was generated successfully or not.
628    *
629    * Please see the example code in <xref linkend="gtkfilechooser-preview"/>.
630    *
631    * See also: gtk_file_chooser_set_preview_widget(),
632    * gtk_file_chooser_set_preview_widget_active(),
633    * gtk_file_chooser_set_use_preview_label(),
634    * gtk_file_chooser_get_preview_filename(),
635    * gtk_file_chooser_get_preview_uri().
636    */
637   g_signal_new (I_("update-preview"),
638                 iface_type,
639                 G_SIGNAL_RUN_LAST,
640                 G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
641                 NULL, NULL,
642                 g_cclosure_marshal_VOID__VOID,
643                 G_TYPE_NONE, 0);
644
645   /**
646    * GtkFileChooser::file-activated
647    * @chooser: the object which received the signal.
648    *
649    * This signal is emitted when the user "activates" a file in the file
650    * chooser.  This can happen by double-clicking on a file in the file list, or
651    * by pressing <keycap>Enter</keycap>.
652    *
653    * Normally you do not need to connect to this signal.  It is used internally
654    * by #GtkFileChooserDialog to know when to activate the default button in the
655    * dialog.
656    *
657    * See also: gtk_file_chooser_get_filename(),
658    * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
659    * gtk_file_chooser_get_uris().
660    */
661   g_signal_new (I_("file-activated"),
662                 iface_type,
663                 G_SIGNAL_RUN_LAST,
664                 G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
665                 NULL, NULL,
666                 g_cclosure_marshal_VOID__VOID,
667                 G_TYPE_NONE, 0);
668
669   /**
670    * GtkFileChooser::confirm-overwrite:
671    * @chooser: the object which received the signal.
672    *
673    * This signal gets emitted whenever it is appropriate to present a
674    * confirmation dialog when the user has selected a file name that
675    * already exists.  The signal only gets emitted when the file
676    * chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode.
677    *
678    * Most applications just need to turn on the
679    * #GtkFileChooser:do-overwrite-confirmation property (or call the
680    * gtk_file_chooser_set_do_overwrite_confirmation() function), and
681    * they will automatically get a stock confirmation dialog.
682    * Applications which need to customize this behavior should do
683    * that, and also connect to the #GtkFileChooser::confirm-overwrite
684    * signal.
685    *
686    * A signal handler for this signal must return a
687    * #GtkFileChooserConfirmation value, which indicates the action to
688    * take.  If the handler determines that the user wants to select a
689    * different filename, it should return
690    * %GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN.  If it determines
691    * that the user is satisfied with his choice of file name, it
692    * should return %GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME.
693    * On the other hand, if it determines that the stock confirmation
694    * dialog should be used, it should return
695    * %GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example
696    * illustrates this.
697    * <example id="gtkfilechooser-confirmation">
698    * <title>Custom confirmation</title>
699    * <programlisting>
700    * static GtkFileChooserConfirmation
701    * confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
702    * {
703    *   char *uri;
704    *
705    *   uri = gtk_file_chooser_get_uri (chooser);
706    *
707    *   if (is_uri_read_only (uri))
708    *     {
709    *       if (user_wants_to_replace_read_only_file (uri))
710    *         return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
711    *       else
712    *         return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
713    *     } else
714    *       return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
715    * }
716    *
717    * ...
718    *
719    * chooser = gtk_file_chooser_dialog_new (...);
720    *
721    * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
722    * g_signal_connect (chooser, "confirm-overwrite",
723    *                   G_CALLBACK (confirm_overwrite_callback), NULL);
724    *
725    * if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
726    *         save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
727    *
728    * gtk_widget_destroy (chooser);
729    * </programlisting>
730    * </example>
731    *
732    * Returns: a #GtkFileChooserConfirmation value that indicates which
733    *  action to take after emitting the signal.
734    *
735    * Since: 2.8
736    */
737   g_signal_new (I_("confirm-overwrite"),
738                 iface_type,
739                 G_SIGNAL_RUN_LAST,
740                 G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
741                 confirm_overwrite_accumulator, NULL,
742                 _gtk_marshal_ENUM__VOID,
743                 GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
744   
745   g_object_interface_install_property (iface,
746                                        g_param_spec_enum ("action",
747                                                           P_("Action"),
748                                                           P_("The type of operation that the file selector is performing"),
749                                                           GTK_TYPE_FILE_CHOOSER_ACTION,
750                                                           GTK_FILE_CHOOSER_ACTION_OPEN,
751                                                           GTK_PARAM_READWRITE));
752   g_object_interface_install_property (iface,
753                                        g_param_spec_object ("filter",
754                                                             P_("Filter"),
755                                                             P_("The current filter for selecting which files are displayed"),
756                                                             GTK_TYPE_FILE_FILTER,
757                                                             GTK_PARAM_READWRITE));
758   g_object_interface_install_property (iface,
759                                        g_param_spec_boolean ("local-only",
760                                                              P_("Local Only"),
761                                                              P_("Whether the selected file(s) should be limited to local file: URLs"),
762                                                              TRUE,
763                                                              GTK_PARAM_READWRITE));
764   g_object_interface_install_property (iface,
765                                        g_param_spec_object ("preview-widget",
766                                                             P_("Preview widget"),
767                                                             P_("Application supplied widget for custom previews."),
768                                                             GTK_TYPE_WIDGET,
769                                                             GTK_PARAM_READWRITE));
770   g_object_interface_install_property (iface,
771                                        g_param_spec_boolean ("preview-widget-active",
772                                                              P_("Preview Widget Active"),
773                                                              P_("Whether the application supplied widget for custom previews should be shown."),
774                                                              TRUE,
775                                                              GTK_PARAM_READWRITE));
776   g_object_interface_install_property (iface,
777                                        g_param_spec_boolean ("use-preview-label",
778                                                              P_("Use Preview Label"),
779                                                              P_("Whether to display a stock label with the name of the previewed file."),
780                                                              TRUE,
781                                                              GTK_PARAM_READWRITE));
782   g_object_interface_install_property (iface,
783                                        g_param_spec_object ("extra-widget",
784                                                             P_("Extra widget"),
785                                                             P_("Application supplied widget for extra options."),
786                                                             GTK_TYPE_WIDGET,
787                                                             GTK_PARAM_READWRITE));
788   g_object_interface_install_property (iface,
789                                        g_param_spec_boolean ("select-multiple",
790                                                              P_("Select Multiple"),
791                                                              P_("Whether to allow multiple files to be selected"),
792                                                              FALSE,
793                                                              GTK_PARAM_READWRITE));
794
795   g_object_interface_install_property (iface,
796                                        g_param_spec_boolean ("show-hidden",
797                                                              P_("Show Hidden"),
798                                                              P_("Whether the hidden files and folders should be displayed"),
799                                                              FALSE,
800                                                              GTK_PARAM_READWRITE));
801
802   /**
803    * GtkFileChooser:do-overwrite-confirmation:
804    * 
805    * Whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode
806    * will present an overwrite confirmation dialog if the user
807    * selects a file name that already exists.
808    *
809    * Since: 2.8
810    */
811   g_object_interface_install_property (iface,
812                                        g_param_spec_boolean ("do-overwrite-confirmation",
813                                                              P_("Do overwrite confirmation"),
814                                                              P_("Whether a file chooser in save mode "
815                                                                 "will present an overwrite confirmation dialog "
816                                                                 "if necessary."),
817                                                              FALSE,
818                                                              GTK_PARAM_READWRITE));
819
820   /**
821    * GtkFileChooser:create-folders:
822    * 
823    * Whether a file chooser not in %GTK_FILE_CHOOSER_ACTION_OPEN mode
824    * will offer the user to create new folders.
825    *
826    * Since: 2.18
827    */
828   g_object_interface_install_property (iface,
829                                        g_param_spec_boolean ("create-folders",
830                                                              P_("Allow folder creation"),
831                                                              P_("Whether a file chooser not in open mode "
832                                                                 "will offer the user to create new folders."),
833                                                              TRUE,
834                                                              GTK_PARAM_READWRITE));
835 }
836
837 /**
838  * gtk_file_chooser_error_quark:
839  *
840  * Registers an error quark for #GtkFileChooser if necessary.
841  * 
842  * Return value: The error quark used for #GtkFileChooser errors.
843  *
844  * Since: 2.4
845  **/
846 GQuark
847 gtk_file_chooser_error_quark (void)
848 {
849   return g_quark_from_static_string ("gtk-file-chooser-error-quark");
850 }
851
852 /**
853  * gtk_file_chooser_set_action:
854  * @chooser: a #GtkFileChooser
855  * @action: the action that the file selector is performing
856  * 
857  * Sets the type of operation that the chooser is performing; the
858  * user interface is adapted to suit the selected action. For example,
859  * an option to create a new folder might be shown if the action is
860  * %GTK_FILE_CHOOSER_ACTION_SAVE but not if the action is
861  * %GTK_FILE_CHOOSER_ACTION_OPEN.
862  *
863  * Since: 2.4
864  **/
865 void
866 gtk_file_chooser_set_action (GtkFileChooser       *chooser,
867                              GtkFileChooserAction  action)
868 {
869   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
870
871   g_object_set (chooser, "action", action, NULL);
872 }
873
874 /**
875  * gtk_file_chooser_get_action:
876  * @chooser: a #GtkFileChooser
877  * 
878  * Gets the type of operation that the file chooser is performing; see
879  * gtk_file_chooser_set_action().
880  * 
881  * Return value: the action that the file selector is performing
882  *
883  * Since: 2.4
884  **/
885 GtkFileChooserAction
886 gtk_file_chooser_get_action (GtkFileChooser *chooser)
887 {
888   GtkFileChooserAction action;
889   
890   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
891
892   g_object_get (chooser, "action", &action, NULL);
893
894   return action;
895 }
896
897 /**
898  * gtk_file_chooser_set_local_only:
899  * @chooser: a #GtkFileChooser
900  * @local_only: %TRUE if only local files can be selected
901  * 
902  * Sets whether only local files can be selected in the
903  * file selector. If @local_only is %TRUE (the default),
904  * then the selected file are files are guaranteed to be
905  * accessible through the operating systems native file
906  * file system and therefore the application only
907  * needs to worry about the filename functions in
908  * #GtkFileChooser, like gtk_file_chooser_get_filename(),
909  * rather than the URI functions like
910  * gtk_file_chooser_get_uri(),
911  *
912  * Since: 2.4
913  **/
914 void
915 gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
916                                  gboolean        local_only)
917 {
918   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
919
920   g_object_set (chooser, "local-only", local_only, NULL);
921 }
922
923 /**
924  * gtk_file_chooser_get_local_only:
925  * @chooser: a #GtkFileChooser
926  * 
927  * Gets whether only local files can be selected in the
928  * file selector. See gtk_file_chooser_set_local_only()
929  * 
930  * Return value: %TRUE if only local files can be selected.
931  *
932  * Since: 2.4
933  **/
934 gboolean
935 gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
936 {
937   gboolean local_only;
938   
939   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
940
941   g_object_get (chooser, "local-only", &local_only, NULL);
942
943   return local_only;
944 }
945
946 /**
947  * gtk_file_chooser_set_select_multiple:
948  * @chooser: a #GtkFileChooser
949  * @select_multiple: %TRUE if multiple files can be selected.
950  * 
951  * Sets whether multiple files can be selected in the file selector.  This is
952  * only relevant if the action is set to be %GTK_FILE_CHOOSER_ACTION_OPEN or
953  * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
954  *
955  * Since: 2.4
956  **/
957 void
958 gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
959                                       gboolean        select_multiple)
960 {
961   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
962
963   g_object_set (chooser, "select-multiple", select_multiple, NULL);
964 }
965
966 /**
967  * gtk_file_chooser_get_select_multiple:
968  * @chooser: a #GtkFileChooser
969  * 
970  * Gets whether multiple files can be selected in the file
971  * selector. See gtk_file_chooser_set_select_multiple().
972  * 
973  * Return value: %TRUE if multiple files can be selected.
974  *
975  * Since: 2.4
976  **/
977 gboolean
978 gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
979 {
980   gboolean select_multiple;
981   
982   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
983
984   g_object_get (chooser, "select-multiple", &select_multiple, NULL);
985
986   return select_multiple;
987 }
988
989 /**
990  * gtk_file_chooser_set_create_folders:
991  * @chooser: a #GtkFileChooser
992  * @create_folders: %TRUE if the New Folder button should be displayed
993  * 
994  * Sets whether file choser will offer to create new folders.
995  * This is only relevant if the action is not set to be 
996  * %GTK_FILE_CHOOSER_ACTION_OPEN.
997  *
998  * Since: 2.18
999  **/
1000 void
1001 gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
1002                                      gboolean        create_folders)
1003 {
1004   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1005
1006   g_object_set (chooser, "create-folders", create_folders, NULL);
1007 }
1008
1009 /**
1010  * gtk_file_chooser_get_create_folders:
1011  * @chooser: a #GtkFileChooser
1012  * 
1013  * Gets whether file choser will offer to create new folders.
1014  * See gtk_file_chooser_set_create_folders().
1015  * 
1016  * Return value: %TRUE if the New Folder button should be displayed.
1017  *
1018  * Since: 2.18
1019  **/
1020 gboolean
1021 gtk_file_chooser_get_create_folders (GtkFileChooser *chooser)
1022 {
1023   gboolean create_folders;
1024   
1025   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1026
1027   g_object_get (chooser, "create-folders", &create_folders, NULL);
1028
1029   return create_folders;
1030 }
1031
1032 /**
1033  * gtk_file_chooser_get_filename:
1034  * @chooser: a #GtkFileChooser
1035  * 
1036  * Gets the filename for the currently selected file in
1037  * the file selector. If multiple files are selected,
1038  * one of the filenames will be returned at random.
1039  *
1040  * If the file chooser is in folder mode, this function returns the selected
1041  * folder.
1042  * 
1043  * Return value: (type filename): The currently selected filename, or %NULL
1044  *  if no file is selected, or the selected file can't
1045  *  be represented with a local filename. Free with g_free().
1046  *
1047  * Since: 2.4
1048  **/
1049 gchar *
1050 gtk_file_chooser_get_filename (GtkFileChooser *chooser)
1051 {
1052   GFile *file;
1053   gchar *result = NULL;
1054
1055   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1056
1057   file = gtk_file_chooser_get_file (chooser);
1058
1059   if (file)
1060     {
1061       result = g_file_get_path (file);
1062       g_object_unref (file);
1063     }
1064
1065   return result;
1066 }
1067
1068 /**
1069  * gtk_file_chooser_set_filename:
1070  * @chooser: a #GtkFileChooser
1071  * @filename: (type filename): the filename to set as current
1072  * 
1073  * Sets @filename as the current filename for the file chooser, by changing to
1074  * the file's parent folder and actually selecting the file in list; all other
1075  * files will be unselected.  If the @chooser is in
1076  * %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name will also appear in
1077  * the dialog's file name entry.
1078  *
1079  * Note that the file must exist, or nothing will be done except
1080  * for the directory change.
1081  *
1082  * You should use this function only when implementing a <guimenuitem>File/Save
1083  * As...</guimenuitem> dialog for which you already have a file name to which
1084  * the user may save.  For example, when the user opens an existing file and
1085  * then does <guimenuitem>File/Save As...</guimenuitem> on it to save a copy or
1086  * a modified version.  If you don't have a file name already &mdash; for
1087  * example, if the user just created a new file and is saving it for the first
1088  * time, do not call this function.  Instead, use something similar to this:
1089  * |[
1090  * if (document_is_new)
1091  *   {
1092  *     /&ast; the user just created a new document &ast;/
1093  *     gtk_file_chooser_set_current_name (chooser, "Untitled document");
1094  *   }
1095  * else
1096  *   {
1097  *     /&ast; the user edited an existing document &ast;/ 
1098  *     gtk_file_chooser_set_filename (chooser, existing_filename);
1099  *   }
1100  * ]|
1101  *
1102  * In the first case, the file chooser will present the user with useful suggestions
1103  * as to where to save his new file.  In the second case, the file's existing location
1104  * is already known, so the file chooser will use it.
1105  * 
1106  * Return value: Not useful.
1107  *
1108  * Since: 2.4
1109  **/
1110 gboolean
1111 gtk_file_chooser_set_filename (GtkFileChooser *chooser,
1112                                const gchar    *filename)
1113 {
1114   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1115
1116   gtk_file_chooser_unselect_all (chooser);
1117   return gtk_file_chooser_select_filename (chooser, filename);
1118 }
1119
1120 /**
1121  * gtk_file_chooser_select_filename:
1122  * @chooser: a #GtkFileChooser
1123  * @filename: (type filename): the filename to select
1124  * 
1125  * Selects a filename. If the file name isn't in the current
1126  * folder of @chooser, then the current folder of @chooser will
1127  * be changed to the folder containing @filename.
1128  *
1129  * Return value: Not useful.
1130  *
1131  * See also: gtk_file_chooser_set_filename()
1132  *
1133  * Since: 2.4
1134  **/
1135 gboolean
1136 gtk_file_chooser_select_filename (GtkFileChooser *chooser,
1137                                   const gchar    *filename)
1138 {
1139   GFile *file;
1140   gboolean result;
1141   
1142   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1143   g_return_val_if_fail (filename != NULL, FALSE);
1144
1145   file = g_file_new_for_path (filename);
1146   result = gtk_file_chooser_select_file (chooser, file, NULL);
1147   g_object_unref (file);
1148
1149   return result;
1150 }
1151
1152 /**
1153  * gtk_file_chooser_unselect_filename:
1154  * @chooser: a #GtkFileChooser
1155  * @filename: (type filename): the filename to unselect
1156  * 
1157  * Unselects a currently selected filename. If the filename
1158  * is not in the current directory, does not exist, or
1159  * is otherwise not currently selected, does nothing.
1160  *
1161  * Since: 2.4
1162  **/
1163 void
1164 gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
1165                                     const char     *filename)
1166 {
1167   GFile *file;
1168
1169   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1170   g_return_if_fail (filename != NULL);
1171
1172   file = g_file_new_for_path (filename);
1173   gtk_file_chooser_unselect_file (chooser, file);
1174   g_object_unref (file);
1175 }
1176
1177 /* Converts a list of GFile* to a list of strings using the specified function */
1178 static GSList *
1179 files_to_strings (GSList  *files,
1180                   gchar * (*convert_func) (GFile *file))
1181 {
1182   GSList *strings;
1183
1184   strings = NULL;
1185
1186   for (; files; files = files->next)
1187     {
1188       GFile *file;
1189       gchar *string;
1190
1191       file = files->data;
1192       string = (* convert_func) (file);
1193
1194       if (string)
1195         strings = g_slist_prepend (strings, string);
1196     }
1197
1198   return g_slist_reverse (strings);
1199 }
1200
1201 /**
1202  * gtk_file_chooser_get_filenames:
1203  * @chooser: a #GtkFileChooser
1204  * 
1205  * Lists all the selected files and subfolders in the current folder of
1206  * @chooser. The returned names are full absolute paths. If files in the current
1207  * folder cannot be represented as local filenames they will be ignored. (See
1208  * gtk_file_chooser_get_uris())
1209  *
1210  * Return value: (element-type filename) (transfer full): a #GSList
1211  *    containing the filenames of all selected files and subfolders in
1212  *    the current folder. Free the returned list with g_slist_free(),
1213  *    and the filenames with g_free().
1214  *
1215  * Since: 2.4
1216  **/
1217 GSList *
1218 gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
1219 {
1220   GSList *files, *result;
1221   
1222   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1223
1224   files = gtk_file_chooser_get_files (chooser);
1225
1226   result = files_to_strings (files, g_file_get_path);
1227   g_slist_foreach (files, (GFunc) g_object_unref, NULL);
1228   g_slist_free (files);
1229
1230   return result;
1231 }
1232
1233 /**
1234  * gtk_file_chooser_set_current_folder:
1235  * @chooser: a #GtkFileChooser
1236  * @filename: (type filename): the full path of the new current folder
1237  * 
1238  * Sets the current folder for @chooser from a local filename.
1239  * The user will be shown the full contents of the current folder,
1240  * plus user interface elements for navigating to other folders.
1241  *
1242  * In general, you should not use this function.  See the <link
1243  * linkend="gtkfilechooserdialog-setting-up">section on setting up a file
1244  * chooser dialog</link> for the rationale behind this.
1245  *
1246  * Return value: Not useful.
1247  *
1248  * Since: 2.4
1249  **/
1250 gboolean
1251 gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
1252                                      const gchar    *filename)
1253 {
1254   GFile *file;
1255   gboolean result;
1256   
1257   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1258   g_return_val_if_fail (filename != NULL, FALSE);
1259
1260   file = g_file_new_for_path (filename);
1261   result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
1262   g_object_unref (file);
1263
1264   return result;
1265 }
1266
1267 /**
1268  * gtk_file_chooser_get_current_folder:
1269  * @chooser: a #GtkFileChooser
1270  * 
1271  * Gets the current folder of @chooser as a local filename.
1272  * See gtk_file_chooser_set_current_folder().
1273  *
1274  * Note that this is the folder that the file chooser is currently displaying
1275  * (e.g. "/home/username/Documents"), which is <emphasis>not the same</emphasis>
1276  * as the currently-selected folder if the chooser is in
1277  * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode
1278  * (e.g. "/home/username/Documents/selected-folder/".  To get the
1279  * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
1280  * usual way to get the selection.
1281  * 
1282  * Return value: (type filename): the full path of the current folder,
1283  * or %NULL if the current path cannot be represented as a local
1284  * filename.  Free with g_free().  This function will also return
1285  * %NULL if the file chooser was unable to load the last folder that
1286  * was requested from it; for example, as would be for calling
1287  * gtk_file_chooser_set_current_folder() on a nonexistent folder.
1288  *
1289  * Since: 2.4
1290  **/
1291 gchar *
1292 gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
1293 {
1294   GFile *file;
1295   gchar *filename;
1296   
1297   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1298
1299   file = gtk_file_chooser_get_current_folder_file (chooser);
1300   if (!file)
1301     return NULL;
1302
1303   filename = g_file_get_path (file);
1304   g_object_unref (file);
1305
1306   return filename;
1307 }
1308
1309 /**
1310  * gtk_file_chooser_set_current_name:
1311  * @chooser: a #GtkFileChooser
1312  * @name: (type filename): the filename to use, as a UTF-8 string
1313  * 
1314  * Sets the current name in the file selector, as if entered
1315  * by the user. Note that the name passed in here is a UTF-8
1316  * string rather than a filename. This function is meant for
1317  * such uses as a suggested name in a "Save As..." dialog.  You can
1318  * pass "Untitled.doc" or a similarly suitable suggestion for the @name.
1319  *
1320  * If you want to preselect a particular existing file, you should use
1321  * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
1322  * Please see the documentation for those functions for an example of using
1323  * gtk_file_chooser_set_current_name() as well.
1324  *
1325  * Since: 2.4
1326  **/
1327 void
1328 gtk_file_chooser_set_current_name  (GtkFileChooser *chooser,
1329                                     const gchar    *name)
1330 {
1331   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1332   g_return_if_fail (name != NULL);
1333   
1334   GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
1335 }
1336
1337 /**
1338  * gtk_file_chooser_get_uri:
1339  * @chooser: a #GtkFileChooser
1340  * 
1341  * Gets the URI for the currently selected file in
1342  * the file selector. If multiple files are selected,
1343  * one of the filenames will be returned at random.
1344  * 
1345  * If the file chooser is in folder mode, this function returns the selected
1346  * folder.
1347  * 
1348  * Return value: The currently selected URI, or %NULL
1349  *  if no file is selected. Free with g_free()
1350  *
1351  * Since: 2.4
1352  **/
1353 gchar *
1354 gtk_file_chooser_get_uri (GtkFileChooser *chooser)
1355 {
1356   GFile *file;
1357   gchar *result = NULL;
1358   
1359   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1360
1361   file = gtk_file_chooser_get_file (chooser);
1362   if (file)
1363     {
1364       result = g_file_get_uri (file);
1365       g_object_unref (file);
1366     }
1367
1368   return result;
1369 }
1370
1371 /**
1372  * gtk_file_chooser_set_uri:
1373  * @chooser: a #GtkFileChooser
1374  * @uri: the URI to set as current
1375  * 
1376  * Sets the file referred to by @uri as the current file for the file chooser,
1377  * by changing to the URI's parent folder and actually selecting the URI in the
1378  * list.  If the @chooser is %GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI's base
1379  * name will also appear in the dialog's file name entry.
1380  *
1381  * Note that the URI must exist, or nothing will be done except for the 
1382  * directory change.
1383  *
1384  * You should use this function only when implementing a <guimenuitem>File/Save
1385  * As...</guimenuitem> dialog for which you already have a file name to which
1386  * the user may save.  For example, whenthe user opens an existing file and then
1387  * does <guimenuitem>File/Save As...</guimenuitem> on it to save a copy or a
1388  * modified version.  If you don't have a file name already &mdash; for example,
1389  * if the user just created a new file and is saving it for the first time, do
1390  * not call this function.  Instead, use something similar to this:
1391  * |[
1392  * if (document_is_new)
1393  *   {
1394  *     /&ast; the user just created a new document &ast;/
1395  *     gtk_file_chooser_set_current_name (chooser, "Untitled document");
1396  *   }
1397  * else
1398  *   {
1399  *     /&ast; the user edited an existing document &ast;/ 
1400  *     gtk_file_chooser_set_uri (chooser, existing_uri);
1401  *   }
1402  * ]|
1403  *
1404  *
1405  * In the first case, the file chooser will present the user with useful suggestions
1406  * as to where to save his new file.  In the second case, the file's existing location
1407  * is already known, so the file chooser will use it.
1408  * 
1409  * Return value: Not useful.
1410  *
1411  * Since: 2.4
1412  **/
1413 gboolean
1414 gtk_file_chooser_set_uri (GtkFileChooser *chooser,
1415                           const char     *uri)
1416 {
1417   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1418
1419   gtk_file_chooser_unselect_all (chooser);
1420   return gtk_file_chooser_select_uri (chooser, uri);
1421 }
1422
1423 /**
1424  * gtk_file_chooser_select_uri:
1425  * @chooser: a #GtkFileChooser
1426  * @uri: the URI to select
1427  * 
1428  * Selects the file to by @uri. If the URI doesn't refer to a
1429  * file in the current folder of @chooser, then the current folder of
1430  * @chooser will be changed to the folder containing @filename.
1431  *
1432  * Return value: Not useful.
1433  *
1434  * Since: 2.4
1435  **/
1436 gboolean
1437 gtk_file_chooser_select_uri (GtkFileChooser *chooser,
1438                              const char     *uri)
1439 {
1440   GFile *file;
1441   gboolean result;
1442   
1443   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1444   g_return_val_if_fail (uri != NULL, FALSE);
1445
1446   file = g_file_new_for_uri (uri);
1447   result = gtk_file_chooser_select_file (chooser, file, NULL);
1448   g_object_unref (file);
1449
1450   return result;
1451 }
1452
1453 /**
1454  * gtk_file_chooser_unselect_uri:
1455  * @chooser: a #GtkFileChooser
1456  * @uri: the URI to unselect
1457  * 
1458  * Unselects the file referred to by @uri. If the file
1459  * is not in the current directory, does not exist, or
1460  * is otherwise not currently selected, does nothing.
1461  *
1462  * Since: 2.4
1463  **/
1464 void
1465 gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
1466                                const char     *uri)
1467 {
1468   GFile *file;
1469
1470   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1471   g_return_if_fail (uri != NULL);
1472
1473   file = g_file_new_for_uri (uri);
1474   gtk_file_chooser_unselect_file (chooser, file);
1475   g_object_unref (file);
1476 }
1477
1478 /**
1479  * gtk_file_chooser_select_all:
1480  * @chooser: a #GtkFileChooser
1481  * 
1482  * Selects all the files in the current folder of a file chooser.
1483  *
1484  * Since: 2.4
1485  **/
1486 void
1487 gtk_file_chooser_select_all (GtkFileChooser *chooser)
1488 {
1489   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1490   
1491   GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
1492 }
1493
1494 /**
1495  * gtk_file_chooser_unselect_all:
1496  * @chooser: a #GtkFileChooser
1497  * 
1498  * Unselects all the files in the current folder of a file chooser.
1499  *
1500  * Since: 2.4
1501  **/
1502 void
1503 gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
1504 {
1505
1506   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1507   
1508   GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
1509 }
1510
1511 /**
1512  * gtk_file_chooser_get_uris:
1513  * @chooser: a #GtkFileChooser
1514  * 
1515  * Lists all the selected files and subfolders in the current folder of
1516  * @chooser. The returned names are full absolute URIs.
1517  *
1518  * Return value: (element-type utf8) (transfer full): a #GSList containing the URIs of all selected
1519  *   files and subfolders in the current folder. Free the returned list
1520  *   with g_slist_free(), and the filenames with g_free().
1521  *
1522  * Since: 2.4
1523  **/
1524 GSList *
1525 gtk_file_chooser_get_uris (GtkFileChooser *chooser)
1526 {
1527   GSList *files, *result;
1528   
1529   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1530
1531   files = gtk_file_chooser_get_files (chooser);
1532
1533   result = files_to_strings (files, g_file_get_uri);
1534   g_slist_foreach (files, (GFunc) g_object_unref, NULL);
1535   g_slist_free (files);
1536
1537   return result;
1538 }
1539
1540 /**
1541  * gtk_file_chooser_set_current_folder_uri:
1542  * @chooser: a #GtkFileChooser
1543  * @uri: the URI for the new current folder
1544  * 
1545  * Sets the current folder for @chooser from an URI.
1546  * The user will be shown the full contents of the current folder,
1547  * plus user interface elements for navigating to other folders.
1548  *
1549  * In general, you should not use this function.  See the <link
1550  * linkend="gtkfilechooserdialog-setting-up">section on setting up a file
1551  * chooser dialog</link> for the rationale behind this.
1552  *
1553  * Return value: %TRUE if the folder could be changed successfully, %FALSE
1554  * otherwise.
1555  *
1556  * Since: 2.4
1557  **/
1558 gboolean
1559 gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
1560                                          const gchar    *uri)
1561 {
1562   GFile *file;
1563   gboolean result;
1564   
1565   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1566   g_return_val_if_fail (uri != NULL, FALSE);
1567
1568   file = g_file_new_for_uri (uri);
1569   result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
1570   g_object_unref (file);
1571
1572   return result;
1573 }
1574
1575 /**
1576  * gtk_file_chooser_get_current_folder_uri:
1577  * @chooser: a #GtkFileChooser
1578  *
1579  * Gets the current folder of @chooser as an URI.
1580  * See gtk_file_chooser_set_current_folder_uri().
1581  *
1582  * Note that this is the folder that the file chooser is currently displaying
1583  * (e.g. "file:///home/username/Documents"), which is <emphasis>not the same</emphasis>
1584  * as the currently-selected folder if the chooser is in
1585  * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode
1586  * (e.g. "file:///home/username/Documents/selected-folder/".  To get the
1587  * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
1588  * usual way to get the selection.
1589  * 
1590  * Return value: the URI for the current folder.  Free with g_free().  This
1591  * function will also return %NULL if the file chooser was unable to load the
1592  * last folder that was requested from it; for example, as would be for calling
1593  * gtk_file_chooser_set_current_folder_uri() on a nonexistent folder.
1594  *
1595  * Since: 2.4
1596  */
1597 gchar *
1598 gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
1599 {
1600   GFile *file;
1601   gchar *uri;
1602   
1603   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1604
1605   file = gtk_file_chooser_get_current_folder_file (chooser);
1606   if (!file)
1607     return NULL;
1608
1609   uri = g_file_get_uri (file);
1610   g_object_unref (file);
1611
1612   return uri;
1613 }
1614
1615 /**
1616  * gtk_file_chooser_set_current_folder_file:
1617  * @chooser: a #GtkFileChooser
1618  * @file: the #GFile for the new folder
1619  * @error: (allow-none): location to store error, or %NULL.
1620  *
1621  * Sets the current folder for @chooser from a #GFile.
1622  * Internal function, see gtk_file_chooser_set_current_folder_uri().
1623  *
1624  * Return value: %TRUE if the folder could be changed successfully, %FALSE
1625  * otherwise.
1626  *
1627  * Since: 2.14
1628  **/
1629 gboolean
1630 gtk_file_chooser_set_current_folder_file (GtkFileChooser  *chooser,
1631                                           GFile           *file,
1632                                           GError         **error)
1633 {
1634   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1635   g_return_val_if_fail (G_IS_FILE (file), FALSE);
1636   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1637
1638   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_folder (chooser, file, error);
1639 }
1640
1641 /**
1642  * gtk_file_chooser_get_current_folder_file:
1643  * @chooser: a #GtkFileChooser
1644  *
1645  * Gets the current folder of @chooser as #GFile.
1646  * See gtk_file_chooser_get_current_folder_uri().
1647  *
1648  * Return value: (transfer full): the #GFile for the current folder.
1649  *
1650  * Since: 2.14
1651  */
1652 GFile *
1653 gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser)
1654 {
1655   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1656
1657   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_folder (chooser);
1658 }
1659
1660 /**
1661  * gtk_file_chooser_select_file:
1662  * @chooser: a #GtkFileChooser
1663  * @file: the file to select
1664  * @error: (allow-none): location to store error, or %NULL
1665  * 
1666  * Selects the file referred to by @file. An internal function. See
1667  * _gtk_file_chooser_select_uri().
1668  *
1669  * Return value: Not useful.
1670  *
1671  * Since: 2.14
1672  **/
1673 gboolean
1674 gtk_file_chooser_select_file (GtkFileChooser  *chooser,
1675                               GFile           *file,
1676                               GError         **error)
1677 {
1678   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1679   g_return_val_if_fail (G_IS_FILE (file), FALSE);
1680   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1681
1682   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->select_file (chooser, file, error);
1683 }
1684
1685 /**
1686  * gtk_file_chooser_unselect_file:
1687  * @chooser: a #GtkFileChooser
1688  * @file: a #GFile
1689  * 
1690  * Unselects the file referred to by @file. If the file is not in the current
1691  * directory, does not exist, or is otherwise not currently selected, does nothing.
1692  *
1693  * Since: 2.14
1694  **/
1695 void
1696 gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
1697                                 GFile          *file)
1698 {
1699   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1700   g_return_if_fail (G_IS_FILE (file));
1701
1702   GTK_FILE_CHOOSER_GET_IFACE (chooser)->unselect_file (chooser, file);
1703 }
1704
1705 /**
1706  * gtk_file_chooser_get_files:
1707  * @chooser: a #GtkFileChooser
1708  * 
1709  * Lists all the selected files and subfolders in the current folder of @chooser
1710  * as #GFile. An internal function, see gtk_file_chooser_get_uris().
1711  *
1712  * Return value: (element-type GFile) (transfer full): a #GSList
1713  *   containing a #GFile for each selected file and subfolder in the
1714  *   current folder.  Free the returned list with g_slist_free(), and
1715  *   the files with g_object_unref().
1716  *
1717  * Since: 2.14
1718  **/
1719 GSList *
1720 gtk_file_chooser_get_files (GtkFileChooser *chooser)
1721 {
1722   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1723
1724   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_files (chooser);
1725 }
1726
1727 /**
1728  * gtk_file_chooser_set_file:
1729  * @chooser: a #GtkFileChooser
1730  * @file: the #GFile to set as current
1731  * @error: (allow-none): location to store the error, or %NULL to ignore errors.
1732  *
1733  * Sets @file as the current filename for the file chooser, by changing
1734  * to the file's parent folder and actually selecting the file in list.  If
1735  * the @chooser is in %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
1736  * will also appear in the dialog's file name entry.
1737  *
1738  * If the file name isn't in the current folder of @chooser, then the current
1739  * folder of @chooser will be changed to the folder containing @filename. This
1740  * is equivalent to a sequence of gtk_file_chooser_unselect_all() followed by
1741  * gtk_file_chooser_select_filename().
1742  *
1743  * Note that the file must exist, or nothing will be done except
1744  * for the directory change.
1745  *
1746  * If you are implementing a <guimenuitem>File/Save As...</guimenuitem> dialog,
1747  * you should use this function if you already have a file name to which the
1748  * user may save; for example, when the user opens an existing file and then
1749  * does <guimenuitem>File/Save As...</guimenuitem> on it.  If you don't have
1750  * a file name already &mdash; for example, if the user just created a new
1751  * file and is saving it for the first time, do not call this function.
1752  * Instead, use something similar to this:
1753  * |[
1754  * if (document_is_new)
1755  *   {
1756  *     /&ast; the user just created a new document &ast;/
1757  *     gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
1758  *     gtk_file_chooser_set_current_name (chooser, "Untitled document");
1759  *   }
1760  * else
1761  *   {
1762  *     /&ast; the user edited an existing document &ast;/
1763  *     gtk_file_chooser_set_file (chooser, existing_file);
1764  *   }
1765  * ]|
1766  *
1767  * Return value: Not useful.
1768  *
1769  * Since: 2.14
1770  **/
1771 gboolean
1772 gtk_file_chooser_set_file (GtkFileChooser  *chooser,
1773                            GFile           *file,
1774                            GError         **error)
1775 {
1776   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1777   g_return_val_if_fail (G_IS_FILE (file), FALSE);
1778   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1779
1780   gtk_file_chooser_unselect_all (chooser);
1781   return gtk_file_chooser_select_file (chooser, file, error);
1782 }
1783
1784 /**
1785  * gtk_file_chooser_get_file:
1786  * @chooser: a #GtkFileChooser
1787  *
1788  * Gets the #GFile for the currently selected file in
1789  * the file selector. If multiple files are selected,
1790  * one of the files will be returned at random.
1791  *
1792  * If the file chooser is in folder mode, this function returns the selected
1793  * folder.
1794  *
1795  * Returns: (transfer full): a selected #GFile. You own the returned file;
1796  *     use g_object_unref() to release it.
1797  *
1798  * Since: 2.14
1799  **/
1800 GFile *
1801 gtk_file_chooser_get_file (GtkFileChooser *chooser)
1802 {
1803   GSList *list;
1804   GFile *result = NULL;
1805   
1806   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1807
1808   list = gtk_file_chooser_get_files (chooser);
1809   if (list)
1810     {
1811       result = list->data;
1812       list = g_slist_delete_link (list, list);
1813
1814       g_slist_foreach (list, (GFunc) g_object_unref, NULL);
1815       g_slist_free (list);
1816     }
1817
1818   return result;
1819 }
1820
1821 /**
1822  * _gtk_file_chooser_get_file_system:
1823  * @chooser: a #GtkFileChooser
1824  * 
1825  * Gets the #GtkFileSystem of @chooser; this is an internal
1826  * implementation detail, used for conversion between paths
1827  * and filenames and URIs.
1828  * 
1829  * Return value: the file system for @chooser.
1830  *
1831  * Since: 2.4
1832  **/
1833 GtkFileSystem *
1834 _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
1835 {
1836   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1837
1838   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
1839 }
1840
1841 /* Preview widget
1842  */
1843 /**
1844  * gtk_file_chooser_set_preview_widget:
1845  * @chooser: a #GtkFileChooser
1846  * @preview_widget: widget for displaying preview.
1847  *
1848  * Sets an application-supplied widget to use to display a custom preview
1849  * of the currently selected file. To implement a preview, after setting the
1850  * preview widget, you connect to the #GtkFileChooser::update-preview
1851  * signal, and call gtk_file_chooser_get_preview_filename() or
1852  * gtk_file_chooser_get_preview_uri() on each change. If you can
1853  * display a preview of the new file, update your widget and
1854  * set the preview active using gtk_file_chooser_set_preview_widget_active().
1855  * Otherwise, set the preview inactive.
1856  *
1857  * When there is no application-supplied preview widget, or the
1858  * application-supplied preview widget is not active, the file chooser
1859  * may display an internally generated preview of the current file or
1860  * it may display no preview at all.
1861  *
1862  * Since: 2.4
1863  **/
1864 void
1865 gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
1866                                      GtkWidget      *preview_widget)
1867 {
1868   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1869
1870   g_object_set (chooser, "preview-widget", preview_widget, NULL);
1871 }
1872
1873 /**
1874  * gtk_file_chooser_get_preview_widget:
1875  * @chooser: a #GtkFileChooser
1876  *
1877  * Gets the current preview widget; see
1878  * gtk_file_chooser_set_preview_widget().
1879  *
1880  * Return value: (transfer none): the current preview widget, or %NULL
1881  *
1882  * Since: 2.4
1883  **/
1884 GtkWidget *
1885 gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
1886 {
1887   GtkWidget *preview_widget;
1888   
1889   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
1890
1891   g_object_get (chooser, "preview-widget", &preview_widget, NULL);
1892   
1893   /* Horrid hack; g_object_get() refs returned objects but
1894    * that contradicts the memory management conventions
1895    * for accessors.
1896    */
1897   if (preview_widget)
1898     g_object_unref (preview_widget);
1899
1900   return preview_widget;
1901 }
1902
1903 /**
1904  * gtk_file_chooser_set_preview_widget_active:
1905  * @chooser: a #GtkFileChooser
1906  * @active: whether to display the user-specified preview widget
1907  * 
1908  * Sets whether the preview widget set by
1909  * gtk_file_chooser_set_preview_widget() should be shown for the
1910  * current filename. When @active is set to false, the file chooser
1911  * may display an internally generated preview of the current file
1912  * or it may display no preview at all. See
1913  * gtk_file_chooser_set_preview_widget() for more details.
1914  *
1915  * Since: 2.4
1916  **/
1917 void
1918 gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
1919                                             gboolean        active)
1920 {
1921   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1922   
1923   g_object_set (chooser, "preview-widget-active", active, NULL);
1924 }
1925
1926 /**
1927  * gtk_file_chooser_get_preview_widget_active:
1928  * @chooser: a #GtkFileChooser
1929  * 
1930  * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget()
1931  * should be shown for the current filename. See
1932  * gtk_file_chooser_set_preview_widget_active().
1933  * 
1934  * Return value: %TRUE if the preview widget is active for the current filename.
1935  *
1936  * Since: 2.4
1937  **/
1938 gboolean
1939 gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
1940 {
1941   gboolean active;
1942   
1943   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1944
1945   g_object_get (chooser, "preview-widget-active", &active, NULL);
1946
1947   return active;
1948 }
1949
1950 /**
1951  * gtk_file_chooser_set_use_preview_label:
1952  * @chooser: a #GtkFileChooser
1953  * @use_label: whether to display a stock label with the name of the previewed file
1954  * 
1955  * Sets whether the file chooser should display a stock label with the name of
1956  * the file that is being previewed; the default is %TRUE.  Applications that
1957  * want to draw the whole preview area themselves should set this to %FALSE and
1958  * display the name themselves in their preview widget.
1959  *
1960  * See also: gtk_file_chooser_set_preview_widget()
1961  *
1962  * Since: 2.4
1963  **/
1964 void
1965 gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
1966                                         gboolean        use_label)
1967 {
1968   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
1969
1970   g_object_set (chooser, "use-preview-label", use_label, NULL);
1971 }
1972
1973 /**
1974  * gtk_file_chooser_get_use_preview_label:
1975  * @chooser: a #GtkFileChooser
1976  * 
1977  * Gets whether a stock label should be drawn with the name of the previewed
1978  * file.  See gtk_file_chooser_set_use_preview_label().
1979  * 
1980  * Return value: %TRUE if the file chooser is set to display a label with the
1981  * name of the previewed file, %FALSE otherwise.
1982  **/
1983 gboolean
1984 gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
1985 {
1986   gboolean use_label;
1987   
1988   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
1989
1990   g_object_get (chooser, "use-preview-label", &use_label, NULL);
1991
1992   return use_label;
1993 }
1994
1995 /**
1996  * gtk_file_chooser_get_preview_file:
1997  * @chooser: a #GtkFileChooser
1998  *
1999  * Gets the #GFile that should be previewed in a custom preview
2000  * Internal function, see gtk_file_chooser_get_preview_uri().
2001  *
2002  * Return value: (transfer full): the #GFile for the file to preview,
2003  *     or %NULL if no file is selected. Free with g_object_unref().
2004  *
2005  * Since: 2.14
2006  **/
2007 GFile *
2008 gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
2009 {
2010   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2011
2012   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser);
2013 }
2014
2015 /**
2016  * _gtk_file_chooser_add_shortcut_folder:
2017  * @chooser: a #GtkFileChooser
2018  * @file: file for the folder to add
2019  * @error: (allow-none): location to store error, or %NULL
2020  * 
2021  * Adds a folder to be displayed with the shortcut folders in a file chooser.
2022  * Internal function, see gtk_file_chooser_add_shortcut_folder().
2023  * 
2024  * Return value: %TRUE if the folder could be added successfully, %FALSE
2025  * otherwise.
2026  *
2027  * Since: 2.4
2028  **/
2029 gboolean
2030 _gtk_file_chooser_add_shortcut_folder (GtkFileChooser  *chooser,
2031                                        GFile           *file,
2032                                        GError         **error)
2033 {
2034   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2035   g_return_val_if_fail (G_IS_FILE (file), FALSE);
2036
2037   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
2038 }
2039
2040 /**
2041  * _gtk_file_chooser_remove_shortcut_folder:
2042  * @chooser: a #GtkFileChooser
2043  * @file: file for the folder to remove
2044  * @error: (allow-none): location to store error, or %NULL
2045  * 
2046  * Removes a folder from the shortcut folders in a file chooser.  Internal
2047  * function, see gtk_file_chooser_remove_shortcut_folder().
2048  * 
2049  * Return value: %TRUE if the folder could be removed successfully, %FALSE
2050  * otherwise.
2051  *
2052  * Since: 2.4
2053  **/
2054 gboolean
2055 _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser  *chooser,
2056                                           GFile           *file,
2057                                           GError         **error)
2058 {
2059   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2060   g_return_val_if_fail (G_IS_FILE (file), FALSE);
2061
2062   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
2063 }
2064
2065 /**
2066  * gtk_file_chooser_get_preview_filename:
2067  * @chooser: a #GtkFileChooser
2068  * 
2069  * Gets the filename that should be previewed in a custom preview
2070  * widget. See gtk_file_chooser_set_preview_widget().
2071  * 
2072  * Return value: (type filename): the filename to preview, or %NULL if
2073  *  no file is selected, or if the selected file cannot be represented
2074  *  as a local filename. Free with g_free()
2075  *
2076  * Since: 2.4
2077  **/
2078 char *
2079 gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
2080 {
2081   GFile *file;
2082   gchar *result = NULL;
2083   
2084   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2085
2086   file = gtk_file_chooser_get_preview_file (chooser);
2087   if (file)
2088     {
2089       result = g_file_get_path (file);
2090       g_object_unref (file);
2091     }
2092
2093   return result;
2094 }
2095
2096 /**
2097  * gtk_file_chooser_get_preview_uri:
2098  * @chooser: a #GtkFileChooser
2099  * 
2100  * Gets the URI that should be previewed in a custom preview
2101  * widget. See gtk_file_chooser_set_preview_widget().
2102  * 
2103  * Return value: the URI for the file to preview, or %NULL if no file is
2104  * selected. Free with g_free().
2105  *
2106  * Since: 2.4
2107  **/
2108 char *
2109 gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
2110 {
2111   GFile *file;
2112   gchar *result = NULL;
2113   
2114   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2115
2116   file = gtk_file_chooser_get_preview_file (chooser);
2117   if (file)
2118     {
2119       result = g_file_get_uri (file);
2120       g_object_unref (file);
2121     }
2122
2123   return result;
2124 }
2125
2126 /**
2127  * gtk_file_chooser_set_extra_widget:
2128  * @chooser: a #GtkFileChooser
2129  * @extra_widget: widget for extra options
2130  * 
2131  * Sets an application-supplied widget to provide extra options to the user.
2132  *
2133  * Since: 2.4
2134  **/
2135 void
2136 gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
2137                                    GtkWidget      *extra_widget)
2138 {
2139   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2140
2141   g_object_set (chooser, "extra-widget", extra_widget, NULL);
2142 }
2143
2144 /**
2145  * gtk_file_chooser_get_extra_widget:
2146  * @chooser: a #GtkFileChooser
2147  *
2148  * Gets the current preview widget; see
2149  * gtk_file_chooser_set_extra_widget().
2150  *
2151  * Return value: (transfer none): the current extra widget, or %NULL
2152  *
2153  * Since: 2.4
2154  **/
2155 GtkWidget *
2156 gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
2157 {
2158   GtkWidget *extra_widget;
2159   
2160   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2161
2162   g_object_get (chooser, "extra-widget", &extra_widget, NULL);
2163   
2164   /* Horrid hack; g_object_get() refs returned objects but
2165    * that contradicts the memory management conventions
2166    * for accessors.
2167    */
2168   if (extra_widget)
2169     g_object_unref (extra_widget);
2170
2171   return extra_widget;
2172 }
2173
2174 /**
2175  * gtk_file_chooser_add_filter:
2176  * @chooser: a #GtkFileChooser
2177  * @filter: a #GtkFileFilter
2178  * 
2179  * Adds @filter to the list of filters that the user can select between.
2180  * When a filter is selected, only files that are passed by that
2181  * filter are displayed. 
2182  * 
2183  * Note that the @chooser takes ownership of the filter, so you have to 
2184  * ref and sink it if you want to keep a reference.
2185  *
2186  * Since: 2.4
2187  **/
2188 void
2189 gtk_file_chooser_add_filter (GtkFileChooser *chooser,
2190                              GtkFileFilter  *filter)
2191 {
2192   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2193
2194   GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
2195 }
2196
2197 /**
2198  * gtk_file_chooser_remove_filter:
2199  * @chooser: a #GtkFileChooser
2200  * @filter: a #GtkFileFilter
2201  * 
2202  * Removes @filter from the list of filters that the user can select between.
2203  *
2204  * Since: 2.4
2205  **/
2206 void
2207 gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
2208                                 GtkFileFilter  *filter)
2209 {
2210   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2211
2212   GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
2213 }
2214
2215 /**
2216  * gtk_file_chooser_list_filters:
2217  * @chooser: a #GtkFileChooser
2218  * 
2219  * Lists the current set of user-selectable filters; see
2220  * gtk_file_chooser_add_filter(), gtk_file_chooser_remove_filter().
2221  *
2222  * Return value: (element-type GtkFileFilter) (transfer container): a
2223  *  #GSList containing the current set of user selectable filters. The
2224  *  contents of the list are owned by GTK+, but you must free the list
2225  *  itself with g_slist_free() when you are done with it.
2226  *
2227  * Since: 2.4
2228  **/
2229 GSList *
2230 gtk_file_chooser_list_filters  (GtkFileChooser *chooser)
2231 {
2232   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2233
2234   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
2235 }
2236
2237 /**
2238  * gtk_file_chooser_set_filter:
2239  * @chooser: a #GtkFileChooser
2240  * @filter: a #GtkFileFilter
2241  * 
2242  * Sets the current filter; only the files that pass the
2243  * filter will be displayed. If the user-selectable list of filters
2244  * is non-empty, then the filter should be one of the filters
2245  * in that list. Setting the current filter when the list of
2246  * filters is empty is useful if you want to restrict the displayed
2247  * set of files without letting the user change it.
2248  *
2249  * Since: 2.4
2250  **/
2251 void
2252 gtk_file_chooser_set_filter (GtkFileChooser *chooser,
2253                              GtkFileFilter  *filter)
2254 {
2255   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2256   g_return_if_fail (GTK_IS_FILE_FILTER (filter));
2257
2258   g_object_set (chooser, "filter", filter, NULL);
2259 }
2260
2261 /**
2262  * gtk_file_chooser_get_filter:
2263  * @chooser: a #GtkFileChooser
2264  *
2265  * Gets the current filter; see gtk_file_chooser_set_filter().
2266  *
2267  * Return value: (transfer none): the current filter, or %NULL
2268  *
2269  * Since: 2.4
2270  **/
2271 GtkFileFilter *
2272 gtk_file_chooser_get_filter (GtkFileChooser *chooser)
2273 {
2274   GtkFileFilter *filter;
2275   
2276   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2277
2278   g_object_get (chooser, "filter", &filter, NULL);
2279   /* Horrid hack; g_object_get() refs returned objects but
2280    * that contradicts the memory management conventions
2281    * for accessors.
2282    */
2283   if (filter)
2284     g_object_unref (filter);
2285
2286   return filter;
2287 }
2288
2289 /**
2290  * gtk_file_chooser_add_shortcut_folder:
2291  * @chooser: a #GtkFileChooser
2292  * @folder: (type filename): filename of the folder to add
2293  * @error: (allow-none): location to store error, or %NULL
2294  * 
2295  * Adds a folder to be displayed with the shortcut folders in a file chooser.
2296  * Note that shortcut folders do not get saved, as they are provided by the
2297  * application.  For example, you can use this to add a
2298  * "/usr/share/mydrawprogram/Clipart" folder to the volume list.
2299  * 
2300  * Return value: %TRUE if the folder could be added successfully, %FALSE
2301  * otherwise.  In the latter case, the @error will be set as appropriate.
2302  *
2303  * Since: 2.4
2304  **/
2305 gboolean
2306 gtk_file_chooser_add_shortcut_folder (GtkFileChooser    *chooser,
2307                                       const char        *folder,
2308                                       GError           **error)
2309 {
2310   GFile *file;
2311   gboolean result;
2312
2313   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2314   g_return_val_if_fail (folder != NULL, FALSE);
2315
2316   file = g_file_new_for_path (folder);
2317   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
2318   g_object_unref (file);
2319
2320   return result;
2321 }
2322
2323 /**
2324  * gtk_file_chooser_remove_shortcut_folder:
2325  * @chooser: a #GtkFileChooser
2326  * @folder: (type filename): filename of the folder to remove
2327  * @error: (allow-none): location to store error, or %NULL
2328  * 
2329  * Removes a folder from a file chooser's list of shortcut folders.
2330  * 
2331  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
2332  * In the latter case, the @error will be set as appropriate.
2333  *
2334  * See also: gtk_file_chooser_add_shortcut_folder()
2335  *
2336  * Since: 2.4
2337  **/
2338 gboolean
2339 gtk_file_chooser_remove_shortcut_folder (GtkFileChooser    *chooser,
2340                                          const char        *folder,
2341                                          GError           **error)
2342 {
2343   GFile *file;
2344   gboolean result;
2345
2346   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2347   g_return_val_if_fail (folder != NULL, FALSE);
2348
2349   file = g_file_new_for_path (folder);
2350   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
2351   g_object_unref (file);
2352
2353   return result;
2354 }
2355
2356 /**
2357  * gtk_file_chooser_list_shortcut_folders:
2358  * @chooser: a #GtkFileChooser
2359  * 
2360  * Queries the list of shortcut folders in the file chooser, as set by
2361  * gtk_file_chooser_add_shortcut_folder().
2362  *
2363  * Return value: (element-type filename) (transfer full): A list of
2364  * folder filenames, or %NULL if there are no shortcut folders.  Free
2365  * the returned list with g_slist_free(), and the filenames with
2366  * g_free().
2367  *
2368  * Since: 2.4
2369  **/
2370 GSList *
2371 gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
2372 {
2373   GSList *folders;
2374   GSList *result;
2375
2376   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2377
2378   folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
2379
2380   result = files_to_strings (folders, g_file_get_path);
2381   g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
2382   g_slist_free (folders);
2383
2384   return result;
2385 }
2386
2387 /**
2388  * gtk_file_chooser_add_shortcut_folder_uri:
2389  * @chooser: a #GtkFileChooser
2390  * @uri: URI of the folder to add
2391  * @error: (allow-none): location to store error, or %NULL
2392  * 
2393  * Adds a folder URI to be displayed with the shortcut folders in a file
2394  * chooser.  Note that shortcut folders do not get saved, as they are provided
2395  * by the application.  For example, you can use this to add a
2396  * "file:///usr/share/mydrawprogram/Clipart" folder to the volume list.
2397  * 
2398  * Return value: %TRUE if the folder could be added successfully, %FALSE
2399  * otherwise.  In the latter case, the @error will be set as appropriate.
2400  *
2401  * Since: 2.4
2402  **/
2403 gboolean
2404 gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser    *chooser,
2405                                           const char        *uri,
2406                                           GError           **error)
2407 {
2408   GFile *file;
2409   gboolean result;
2410
2411   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2412   g_return_val_if_fail (uri != NULL, FALSE);
2413
2414   file = g_file_new_for_uri (uri);
2415   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
2416   g_object_unref (file);
2417
2418   return result;
2419 }
2420
2421 /**
2422  * gtk_file_chooser_remove_shortcut_folder_uri:
2423  * @chooser: a #GtkFileChooser
2424  * @uri: URI of the folder to remove
2425  * @error: (allow-none): location to store error, or %NULL
2426  * 
2427  * Removes a folder URI from a file chooser's list of shortcut folders.
2428  * 
2429  * Return value: %TRUE if the operation succeeds, %FALSE otherwise.  
2430  * In the latter case, the @error will be set as appropriate.
2431  *
2432  * See also: gtk_file_chooser_add_shortcut_folder_uri()
2433  *
2434  * Since: 2.4
2435  **/
2436 gboolean
2437 gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser    *chooser,
2438                                              const char        *uri,
2439                                              GError           **error)
2440 {
2441   GFile *file;
2442   gboolean result;
2443
2444   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2445   g_return_val_if_fail (uri != NULL, FALSE);
2446
2447   file = g_file_new_for_uri (uri);
2448   result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
2449   g_object_unref (file);
2450
2451   return result;
2452 }
2453
2454 /**
2455  * gtk_file_chooser_list_shortcut_folder_uris:
2456  * @chooser: a #GtkFileChooser
2457  * 
2458  * Queries the list of shortcut folders in the file chooser, as set by
2459  * gtk_file_chooser_add_shortcut_folder_uri().
2460  *
2461  * Return value: (element-type utf8) (transfer full): A list of folder
2462  * URIs, or %NULL if there are no shortcut folders.  Free the returned
2463  * list with g_slist_free(), and the URIs with g_free().
2464  *
2465  * Since: 2.4
2466  **/
2467 GSList *
2468 gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
2469 {
2470   GSList *folders;
2471   GSList *result;
2472
2473   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2474
2475   folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
2476
2477   result = files_to_strings (folders, g_file_get_uri);
2478   g_slist_foreach (folders, (GFunc) g_object_unref, NULL);
2479   g_slist_free (folders);
2480
2481   return result;
2482 }
2483
2484 GSList *
2485 _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
2486 {
2487   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
2488
2489   return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
2490 }
2491
2492 /**
2493  * gtk_file_chooser_set_show_hidden:
2494  * @chooser: a #GtkFileChooser
2495  * @show_hidden: %TRUE if hidden files and folders should be displayed.
2496  * 
2497  * Sets whether hidden files and folders are displayed in the file selector.  
2498  *
2499  * Since: 2.6
2500  **/
2501 void
2502 gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
2503                                   gboolean        show_hidden)
2504 {
2505   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2506
2507   g_object_set (chooser, "show-hidden", show_hidden, NULL);
2508 }
2509
2510 /**
2511  * gtk_file_chooser_get_show_hidden:
2512  * @chooser: a #GtkFileChooser
2513  * 
2514  * Gets whether hidden files and folders are displayed in the file selector.   
2515  * See gtk_file_chooser_set_show_hidden().
2516  * 
2517  * Return value: %TRUE if hidden files and folders are displayed.
2518  *
2519  * Since: 2.6
2520  **/
2521 gboolean
2522 gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
2523 {
2524   gboolean show_hidden;
2525   
2526   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2527
2528   g_object_get (chooser, "show-hidden", &show_hidden, NULL);
2529
2530   return show_hidden;
2531 }
2532
2533 /**
2534  * gtk_file_chooser_set_do_overwrite_confirmation:
2535  * @chooser: a #GtkFileChooser
2536  * @do_overwrite_confirmation: whether to confirm overwriting in save mode
2537  * 
2538  * Sets whether a file chooser in %GTK_FILE_CHOOSER_ACTION_SAVE mode will present
2539  * a confirmation dialog if the user types a file name that already exists.  This
2540  * is %FALSE by default.
2541  *
2542  * Regardless of this setting, the @chooser will emit the
2543  * #GtkFileChooser::confirm-overwrite signal when appropriate.
2544  *
2545  * If all you need is the stock confirmation dialog, set this property to %TRUE.
2546  * You can override the way confirmation is done by actually handling the
2547  * #GtkFileChooser::confirm-overwrite signal; please refer to its documentation
2548  * for the details.
2549  *
2550  * Since: 2.8
2551  **/
2552 void
2553 gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
2554                                                 gboolean        do_overwrite_confirmation)
2555 {
2556   g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
2557
2558   g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
2559 }
2560
2561 /**
2562  * gtk_file_chooser_get_do_overwrite_confirmation:
2563  * @chooser: a #GtkFileChooser
2564  * 
2565  * Queries whether a file chooser is set to confirm for overwriting when the user
2566  * types a file name that already exists.
2567  * 
2568  * Return value: %TRUE if the file chooser will present a confirmation dialog;
2569  * %FALSE otherwise.
2570  *
2571  * Since: 2.8
2572  **/
2573 gboolean
2574 gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
2575 {
2576   gboolean do_overwrite_confirmation;
2577
2578   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
2579
2580   g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
2581
2582   return do_overwrite_confirmation;
2583 }