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