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