]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkfilechooser.sgml
=== Released 2.5.0 ===
[~andy/gtk] / docs / reference / gtk / tmpl / gtkfilechooser.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkFileChooser
3
4 <!-- ##### SECTION Short_Description ##### -->
5 File chooser interface used by #GtkFileChooserWidget and #GtkFileChooserDialog.
6
7 <!-- ##### SECTION Long_Description ##### -->
8     <para>
9       #GtkFileChooser is an interface that can be implemented by file
10       selection widgets.  In GTK+, the main objects that implement
11       this interface are #GtkFileChooserWidget and
12       #GtkFileChooserDialog.  You do not need to write an object that
13       implements the #GtkFileChooser interface unless you are trying
14       to adapt an existing file selector to expose a standard
15       programming interface.
16     </para>
17
18     <refsect2 id="gtkfilechooser-encodings">
19       <title>File Names and Encodings</title>
20
21       <para>
22         When the user is finished selecting files in a
23         #GtkFileChooser, your program can get the selected names
24         either as filenames or as URIs.  For URIs, the normal escaping
25         rules are applied if the URI contains non-ASCII characters.
26         However, filenames are <emphasis>always</emphasis> returned in
27         the character set specified by the
28         <envar>G_FILENAME_ENCODING</envar> environment variable.
29         Please see the Glib documentation for more details about this
30         variable.
31       </para>
32
33       <important>
34         <para>
35           This means that while you can pass the result of
36           gtk_file_chooser_get_filename() to
37           <function>open(2)</function> or
38           <function>fopen(3)</function>, you may not be able to
39           directly set it as the text of a #GtkLabel widget unless you
40           convert it first to UTF-8, which all GTK+ widgets expect.
41           You should use g_filename_to_utf8() to convert filenames
42           into strings that can be passed to GTK+ widgets.
43         </para>
44       </important>
45     </refsect2>
46
47     <refsect2 id="gtkfilechooser-preview">
48       <title>Adding a Preview Widget</title>
49
50       <para>
51         You can add a custom preview widget to a file chooser and then
52         get notification about when the preview needs to be updated.
53         To install a preview widget, use
54         gtk_file_chooser_set_preview_widget().  Then, connect to the
55         #GtkFileChooser::update-preview signal to get notified when
56         you need to update the contents of the preview.
57       </para>
58
59       <para>
60         Your callback should use
61         gtk_file_chooser_get_preview_filename() to see what needs
62         previewing.  Once you have generated the preview for the
63         corresponding file, you must call
64         gtk_file_chooser_set_preview_widget_active() with a boolean
65         flag that indicates whether your callback could successfully
66         generate a preview.
67       </para>
68
69       <example id="example-gtkfilechooser-preview">
70         <title>Sample Usage</title>
71
72         <programlisting>
73 {
74   GtkImage *preview;
75
76   ...
77
78   preview = gtk_image_new (<!-- -->);
79
80   gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
81   g_signal_connect (my_file_chooser, "update-preview",
82                     G_CALLBACK (update_preview_cb), preview);
83 }
84
85 static void
86 update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
87 {
88   GtkWidget *preview;
89   char *filename;
90   GdkPixbuf *pixbuf;
91   gboolean have_preview;
92
93   preview = GTK_WIDGET (data);
94   filename = gtk_file_chooser_get_preview_filename (file_chooser);
95
96   pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
97   have_preview = (pixbuf != NULL);
98   g_free (filename);
99
100   gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
101   if (pixbuf)
102     gdk_pixbuf_unref (pixbuf);
103
104   gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
105 }
106         </programlisting>
107       </example>
108     </refsect2>
109
110     <refsect2 id="gtkfilechooser-extra">
111       <title>Adding Extra Widgets</title>
112
113       <para>
114         You can add extra widgets to a file chooser to provide options
115         that are not present in the default design.  For example, you
116         can add a toggle button to give the user the option to open a
117         file in read-only mode.  You can use
118         gtk_file_chooser_set_extra_widget() to insert additional
119         widgets in a file chooser.
120       </para>
121
122       <example id="example-gtkfilechooser-extra">
123         <title>Sample Usage</title>
124
125         <programlisting>
126 {
127   GtkWidget *toggle;
128
129   ...
130
131   toggle = gtk_check_button_new_with_label ("Open file read-only");
132   gtk_widget_show (toggle);
133   gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
134 }
135         </programlisting>
136       </example>
137
138       <note>
139         <para>
140           If you want to set more than one extra widget in the file
141           chooser, you can a container such as a GtkVBox or a GtkTable
142           and include your widgets in it.  Then, set the container as
143           the whole extra widget.
144         </para>
145       </note>
146     </refsect2>
147
148     <refsect2 id="gtkfilechooser-key-bindings">
149       <title>Key Bindings</title>
150
151       <para>
152         Internally, GTK+ implements a file chooser's graphical user
153         interface with the private
154         <classname>GtkFileChooserDefaultClass</classname>.  This
155         widget has several <link linkend="gtk-Bindings">key
156         bindings</link> and their associated signals.  This section
157         describes the available key binding signals.
158       </para>
159
160       <example id="gtkfilechooser-key-binding-example">
161         <title>GtkFileChooser key binding example</title>
162
163         <para>
164           The default keys that activate the key-binding signals in
165           <classname>GtkFileChooserDefaultClass</classname> are as
166           follows:
167         </para>
168
169         <informaltable>
170           <tgroup cols="2">
171             <tbody>
172               <row>
173                 <entry>Signal name</entry>
174                 <entry>Key</entry>
175               </row>
176               <row>
177                 <entry>location-popup</entry>
178                 <entry><keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo></entry>
179               </row>
180               <row>
181                 <entry>up-folder</entry>
182                 <entry><keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo></entry>
183               </row>
184               <row>
185                 <entry>down-folder</entry>
186                 <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
187               </row>
188               <row>
189                 <entry>home-folder</entry>
190                 <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
191               </row>
192             </tbody>
193           </tgroup>
194         </informaltable>
195
196         <para>
197           To change these defaults to something else, you could
198           include the following fragment in your
199           <filename>.gtkrc-2.0</filename> file:
200         </para>
201
202         <programlisting>
203 binding "my-own-gtkfilechooser-bindings" {
204         bind "&lt;Alt&gt;&lt;Shift&gt;l" {
205                 "location-popup" ()
206         }
207         bind "&lt;Alt&gt;&lt;Shift&gt;Up" {
208                 "up-folder" ()
209         }
210         bind "&lt;Alt&gt;&lt;Shift&gt;Down" {
211                 "down-folder" ()
212         }
213         bind "&lt;Alt&gt;&lt;Shift&gt;Home" {
214                 "home-folder-folder" ()
215         }
216 }
217
218 class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
219         </programlisting>
220       </example>
221
222       <refsect3 id="GtkFileChooserDefault-location-popup">
223         <title>The &quot;GtkFileChooserDefault::location-popup&quot; signal</title>
224
225         <programlisting>
226           void user_function (GtkFileChooserDefault *chooser,
227                               <link linkend="gpointer">gpointer</link> user_data);
228         </programlisting>
229
230         <para>
231           This is used to make the file chooser show a "Location"
232           dialog which the user can use to manually type the name of
233           the file he wishes to select.  By default this is bound to
234           <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>.
235         </para>
236
237         <variablelist role="params">
238           <varlistentry>
239             <term><parameter>chooser</parameter>&nbsp;:</term>
240             <listitem>
241               <simpara>
242                 the object which received the signal.
243               </simpara>
244             </listitem>
245           </varlistentry>
246           <varlistentry>
247             <term><parameter>user_data</parameter>&nbsp;:</term>
248             <listitem>
249               <simpara>
250                 user data set when the signal handler was connected.
251               </simpara>
252             </listitem>
253           </varlistentry>
254         </variablelist>
255       </refsect3>
256
257       <refsect3 id="GtkFileChooserDefault-up-folder">
258         <title>The &quot;GtkFileChooserDefault::up-folder&quot; signal</title>
259
260         <programlisting>
261           void user_function (GtkFileChooserDefault *chooser,
262                               <link linkend="gpointer">gpointer</link> user_data);
263         </programlisting>
264
265         <para>
266           This is used to make the file chooser go to the parent of
267           the current folder in the file hierarchy.  By default this
268           is bound to
269           <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>.
270         </para>
271
272         <variablelist role="params">
273           <varlistentry>
274             <term><parameter>chooser</parameter>&nbsp;:</term>
275             <listitem>
276               <simpara>
277                 the object which received the signal.
278               </simpara>
279             </listitem>
280           </varlistentry>
281           <varlistentry>
282             <term><parameter>user_data</parameter>&nbsp;:</term>
283             <listitem>
284               <simpara>
285                 user data set when the signal handler was connected.
286               </simpara>
287             </listitem>
288           </varlistentry>
289         </variablelist>
290       </refsect3>
291
292       <refsect3 id="GtkFileChooserDefault-down-folder">
293         <title>The &quot;GtkFileChooserDefault::down-folder&quot; signal</title>
294
295         <programlisting>
296           void user_function (GtkFileChooserDefault *chooser,
297                               <link linkend="gpointer">gpointer</link> user_data);
298         </programlisting>
299
300         <para>
301           This is used to make the file chooser go to a child of the
302           current folder in the file hierarchy.  The subfolder that
303           will be used is displayed in the path bar widget of the file
304           chooser.  For example, if the path bar is showing
305           "/foo/<emphasis>bar/</emphasis>baz", then this will cause
306           the file chooser to switch to the "baz" subfolder.  By
307           default this is bound to
308           <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>.
309         </para>
310
311         <variablelist role="params">
312           <varlistentry>
313             <term><parameter>chooser</parameter>&nbsp;:</term>
314             <listitem>
315               <simpara>
316                 the object which received the signal.
317               </simpara>
318             </listitem>
319           </varlistentry>
320           <varlistentry>
321             <term><parameter>user_data</parameter>&nbsp;:</term>
322             <listitem>
323               <simpara>
324                 user data set when the signal handler was connected.
325               </simpara>
326             </listitem>
327           </varlistentry>
328         </variablelist>
329       </refsect3>
330
331       <refsect3 id="GtkFileChooserDefault-home-folder">
332         <title>The &quot;GtkFileChooserDefault::home-folder&quot; signal</title>
333
334         <programlisting>
335           void user_function (GtkFileChooserDefault *chooser,
336                               <link linkend="gpointer">gpointer</link> user_data);
337         </programlisting>
338
339         <para>
340           This is used to make the file chooser show the user's home
341           folder in the file list.  By default this is bound to
342           <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>.
343         </para>
344
345         <variablelist role="params">
346           <varlistentry>
347             <term><parameter>chooser</parameter>&nbsp;:</term>
348             <listitem>
349               <simpara>
350                 the object which received the signal.
351               </simpara>
352             </listitem>
353           </varlistentry>
354           <varlistentry>
355             <term><parameter>user_data</parameter>&nbsp;:</term>
356             <listitem>
357               <simpara>
358                 user data set when the signal handler was connected.
359               </simpara>
360             </listitem>
361           </varlistentry>
362         </variablelist>
363       </refsect3>
364     </refsect2>
365
366 <!-- ##### SECTION See_Also ##### -->
367     <para>
368       #GtkFileChooserDialog, #GtkFileChooserWidget
369     </para>
370
371 <!-- ##### STRUCT GtkFileChooser ##### -->
372 <para>
373
374 </para>
375
376
377 <!-- ##### SIGNAL GtkFileChooser::current-folder-changed ##### -->
378 <para>
379
380 </para>
381
382 @filechooser: the object which received the signal.
383
384 <!-- ##### SIGNAL GtkFileChooser::file-activated ##### -->
385 <para>
386
387 </para>
388
389 @filechooser: the object which received the signal.
390
391 <!-- ##### SIGNAL GtkFileChooser::selection-changed ##### -->
392 <para>
393
394 </para>
395
396 @filechooser: the object which received the signal.
397
398 <!-- ##### SIGNAL GtkFileChooser::update-preview ##### -->
399 <para>
400
401 </para>
402
403 @filechooser: the object which received the signal.
404
405 <!-- ##### ARG GtkFileChooser:action ##### -->
406 <para>
407
408 </para>
409
410 <!-- ##### ARG GtkFileChooser:extra-widget ##### -->
411 <para>
412
413 </para>
414
415 <!-- ##### ARG GtkFileChooser:file-system-backend ##### -->
416 <para>
417
418 </para>
419
420 <!-- ##### ARG GtkFileChooser:filter ##### -->
421 <para>
422
423 </para>
424
425 <!-- ##### ARG GtkFileChooser:local-only ##### -->
426 <para>
427
428 </para>
429
430 <!-- ##### ARG GtkFileChooser:preview-widget ##### -->
431 <para>
432
433 </para>
434
435 <!-- ##### ARG GtkFileChooser:preview-widget-active ##### -->
436 <para>
437
438 </para>
439
440 <!-- ##### ARG GtkFileChooser:select-multiple ##### -->
441 <para>
442
443 </para>
444
445 <!-- ##### ARG GtkFileChooser:show-hidden ##### -->
446 <para>
447
448 </para>
449
450 <!-- ##### ARG GtkFileChooser:use-preview-label ##### -->
451 <para>
452
453 </para>
454
455 <!-- ##### ENUM GtkFileChooserAction ##### -->
456     <para>
457       Describes whether a #GtkFileChooser is being used to open
458       existing files or to save to a possibly new file.
459     </para>
460
461 @GTK_FILE_CHOOSER_ACTION_OPEN: Indicates open mode.  The file chooser
462     will only let the user pick an existing file.
463 @GTK_FILE_CHOOSER_ACTION_SAVE: Indicates save mode.  The file chooser
464     will let the user pick an existing file, or type in a new
465     filename.
466 @GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: Indicates an Open mode for
467     selecting folders.  The file chooser will let the user pick an
468     existing folder.
469 @GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: Indicates a mode for creating a
470     new folder.  The file chooser will let the user name an existing or
471     new folder.
472
473 <!-- ##### MACRO GTK_FILE_CHOOSER_ERROR ##### -->
474     <para>
475       Used to get the #GError quark for #GtkFileChooser errors.
476     </para>
477
478
479
480 <!-- ##### ENUM GtkFileChooserError ##### -->
481     <para>
482       These identify the various errors that can occur while calling
483       #GtkFileChooser functions.
484     </para>
485
486 @GTK_FILE_CHOOSER_ERROR_NONEXISTENT: Indicates that a file does not exist.
487 @GTK_FILE_CHOOSER_ERROR_BAD_FILENAME: Indicates a malformed filename.
488
489 <!-- ##### FUNCTION gtk_file_chooser_error_quark ##### -->
490 <para>
491
492 </para>
493
494 @Returns: 
495
496
497 <!-- ##### FUNCTION gtk_file_chooser_set_action ##### -->
498 <para>
499
500 </para>
501
502 @chooser: 
503 @action: 
504
505
506 <!-- ##### FUNCTION gtk_file_chooser_get_action ##### -->
507 <para>
508
509 </para>
510
511 @chooser: 
512 @Returns: 
513
514
515 <!-- ##### FUNCTION gtk_file_chooser_set_local_only ##### -->
516 <para>
517
518 </para>
519
520 @chooser: 
521 @local_only: 
522 <!-- # Unused Parameters # -->
523 @files_only: 
524
525
526 <!-- ##### FUNCTION gtk_file_chooser_get_local_only ##### -->
527 <para>
528
529 </para>
530
531 @chooser: 
532 @Returns: 
533
534
535 <!-- ##### FUNCTION gtk_file_chooser_set_select_multiple ##### -->
536 <para>
537
538 </para>
539
540 @chooser: 
541 @select_multiple: 
542
543
544 <!-- ##### FUNCTION gtk_file_chooser_get_select_multiple ##### -->
545 <para>
546
547 </para>
548
549 @chooser: 
550 @Returns: 
551
552
553 <!-- ##### FUNCTION gtk_file_chooser_set_current_name ##### -->
554 <para>
555
556 </para>
557
558 @chooser: 
559 @name: 
560
561
562 <!-- ##### FUNCTION gtk_file_chooser_get_filename ##### -->
563 <para>
564
565 </para>
566
567 @chooser: 
568 @Returns: 
569
570
571 <!-- ##### FUNCTION gtk_file_chooser_set_filename ##### -->
572 <para>
573
574 </para>
575
576 @chooser: 
577 @filename: 
578 @Returns: 
579
580
581 <!-- ##### FUNCTION gtk_file_chooser_select_filename ##### -->
582 <para>
583
584 </para>
585
586 @chooser: 
587 @filename: 
588 @Returns: 
589
590
591 <!-- ##### FUNCTION gtk_file_chooser_unselect_filename ##### -->
592 <para>
593
594 </para>
595
596 @chooser: 
597 @filename: 
598
599
600 <!-- ##### FUNCTION gtk_file_chooser_select_all ##### -->
601 <para>
602
603 </para>
604
605 @chooser: 
606
607
608 <!-- ##### FUNCTION gtk_file_chooser_unselect_all ##### -->
609 <para>
610
611 </para>
612
613 @chooser: 
614
615
616 <!-- ##### FUNCTION gtk_file_chooser_get_filenames ##### -->
617 <para>
618
619 </para>
620
621 @chooser: 
622 @Returns: 
623
624
625 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder ##### -->
626 <para>
627
628 </para>
629
630 @chooser: 
631 @filename: 
632 @Returns: 
633
634
635 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder ##### -->
636 <para>
637
638 </para>
639
640 @chooser: 
641 @Returns: 
642
643
644 <!-- ##### FUNCTION gtk_file_chooser_get_uri ##### -->
645 <para>
646
647 </para>
648
649 @chooser: 
650 @Returns: 
651
652
653 <!-- ##### FUNCTION gtk_file_chooser_set_uri ##### -->
654 <para>
655
656 </para>
657
658 @chooser: 
659 @uri: 
660 @Returns: 
661
662
663 <!-- ##### FUNCTION gtk_file_chooser_select_uri ##### -->
664 <para>
665
666 </para>
667
668 @chooser: 
669 @uri: 
670 @Returns: 
671
672
673 <!-- ##### FUNCTION gtk_file_chooser_unselect_uri ##### -->
674 <para>
675
676 </para>
677
678 @chooser: 
679 @uri: 
680
681
682 <!-- ##### FUNCTION gtk_file_chooser_get_uris ##### -->
683 <para>
684
685 </para>
686
687 @chooser: 
688 @Returns: 
689
690
691 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder_uri ##### -->
692 <para>
693
694 </para>
695
696 @chooser: 
697 @uri: 
698 @Returns: 
699
700
701 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder_uri ##### -->
702 <para>
703
704 </para>
705
706 @chooser: 
707 @Returns: 
708
709
710 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget ##### -->
711 <para>
712
713 </para>
714
715 @chooser: 
716 @preview_widget: 
717
718
719 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget ##### -->
720 <para>
721
722 </para>
723
724 @chooser: 
725 @Returns: 
726
727
728 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget_active ##### -->
729 <para>
730
731 </para>
732
733 @chooser: 
734 @active: 
735
736
737 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget_active ##### -->
738 <para>
739
740 </para>
741
742 @chooser: 
743 @Returns: 
744
745
746 <!-- ##### FUNCTION gtk_file_chooser_set_use_preview_label ##### -->
747 <para>
748
749 </para>
750
751 @chooser: 
752 @use_label: 
753
754
755 <!-- ##### FUNCTION gtk_file_chooser_get_use_preview_label ##### -->
756 <para>
757
758 </para>
759
760 @chooser: 
761 @Returns: 
762
763
764 <!-- ##### FUNCTION gtk_file_chooser_get_preview_filename ##### -->
765 <para>
766
767 </para>
768
769 @chooser: 
770 @Returns: 
771 <!-- # Unused Parameters # -->
772 @file_chooser: 
773
774
775 <!-- ##### FUNCTION gtk_file_chooser_get_preview_uri ##### -->
776 <para>
777
778 </para>
779
780 @chooser: 
781 @Returns: 
782 <!-- # Unused Parameters # -->
783 @file_chooser: 
784
785
786 <!-- ##### FUNCTION gtk_file_chooser_set_extra_widget ##### -->
787 <para>
788
789 </para>
790
791 @chooser: 
792 @extra_widget: 
793
794
795 <!-- ##### FUNCTION gtk_file_chooser_get_extra_widget ##### -->
796 <para>
797
798 </para>
799
800 @chooser: 
801 @Returns: 
802
803
804 <!-- ##### FUNCTION gtk_file_chooser_add_filter ##### -->
805 <para>
806
807 </para>
808
809 @chooser: 
810 @filter: 
811
812
813 <!-- ##### FUNCTION gtk_file_chooser_remove_filter ##### -->
814 <para>
815
816 </para>
817
818 @chooser: 
819 @filter: 
820
821
822 <!-- ##### FUNCTION gtk_file_chooser_list_filters ##### -->
823 <para>
824
825 </para>
826
827 @chooser: 
828 @Returns: 
829
830
831 <!-- ##### FUNCTION gtk_file_chooser_set_filter ##### -->
832 <para>
833
834 </para>
835
836 @chooser: 
837 @filter: 
838
839
840 <!-- ##### FUNCTION gtk_file_chooser_get_filter ##### -->
841 <para>
842
843 </para>
844
845 @chooser: 
846 @Returns: 
847
848
849 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder ##### -->
850 <para>
851
852 </para>
853
854 @chooser: 
855 @folder: 
856 @error: 
857 @Returns: 
858
859
860 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder ##### -->
861 <para>
862
863 </para>
864
865 @chooser: 
866 @folder: 
867 @error: 
868 @Returns: 
869
870
871 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folders ##### -->
872 <para>
873
874 </para>
875
876 @chooser: 
877 @Returns: 
878
879
880 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder_uri ##### -->
881 <para>
882
883 </para>
884
885 @chooser: 
886 @uri: 
887 @error: 
888 @Returns: 
889 <!-- # Unused Parameters # -->
890 @folder: 
891
892
893 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder_uri ##### -->
894 <para>
895
896 </para>
897
898 @chooser: 
899 @uri: 
900 @error: 
901 @Returns: 
902 <!-- # Unused Parameters # -->
903 @folder: 
904
905
906 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folder_uris ##### -->
907 <para>
908
909 </para>
910
911 @chooser: 
912 @Returns: 
913
914
915
916 <!--
917 Local variables:
918 mode: sgml
919 sgml-parent-document: ("../gtk-docs.sgml" "book" "refentry")
920 End:
921 -->
922
923