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