Add an option to make glib-compile-resources use G_GNUC_INTERNAL
[platform/upstream/glib.git] / docs / reference / gio / migrating-gnome-vfs.xml
1   <chapter>
2     <title>Migrating from GnomeVFS to GIO</title>
3
4     <table id="gnome-vfs-vs-gio">
5       <title>Comparison of GnomeVFS and GIO concepts</title>
6       <tgroup cols="2">
7         <thead>
8           <row><entry>GnomeVFS</entry><entry>GIO</entry></row>
9         </thead>
10         <tbody>
11           <row><entry>GnomeVFSURI</entry><entry>GFile</entry></row>
12           <row><entry>GnomeVFSFileInfo</entry><entry>GFileInfo</entry></row>
13           <row><entry>GnomeVFSResult</entry><entry>GError, with G_IO_ERROR values</entry></row>
14           <row><entry>GnomeVFSHandle &amp; GnomeVFSAsyncHandle</entry><entry>GInputStream or GOutputStream</entry></row>
15           <row><entry>GnomeVFSDirectoryHandle</entry><entry>GFileEnumerator</entry></row>
16           <row><entry>mime type</entry><entry>content type</entry></row>
17           <row><entry>GnomeVFSMonitor</entry><entry>GFileMonitor</entry></row>
18           <row><entry>GnomeVFSVolumeMonitor</entry><entry>GVolumeMonitor</entry></row>
19           <row><entry>GnomeVFSVolume</entry><entry>GMount</entry></row>
20           <row><entry>GnomeVFSDrive</entry><entry>GVolume</entry></row>
21           <row><entry>-</entry><entry>GDrive</entry></row>
22           <row><entry>GnomeVFSContext</entry><entry>GCancellable</entry></row>
23           <row><entry>gnome_vfs_async_cancel</entry><entry>g_cancellable_cancel</entry></row>
24         </tbody>
25       </tgroup>
26     </table>
27
28     <section>
29       <title>Trash handling</title>
30
31       <para>
32         The handling of trashed files has been changed in GIO, compared
33         to gnome-vfs. gnome-vfs has a home-grown trash implementation that 
34         predates the freedesktop.org <ulink url="http://www.freedesktop.org/wiki/Specifications/trash-spec">Desktop Trash Can</ulink> specification
35         that is implemented in GIO. The location for storing trashed files 
36         has changed from <filename>$HOME/.Trash</filename> to 
37         <filename>$HOME/.local/share/Trash</filename> (or more correctly
38         <filename>$XDG_DATA_HOME/Trash</filename>), which means that 
39         there is a need for migrating files that have been trashed by 
40         gnome-vfs to the new location.
41       </para>
42       <para>
43         In gnome-vfs, the <filename>trash://</filename> scheme offering a 
44         merged view of all trash directories was implemented in nautilus,
45         and trash-handling applications had to find and monitor all trash 
46         directories themselves. With GIO, the <filename>trash://</filename>
47         implementation has been moved to gvfs and applications can simply
48         monitor that location:
49       </para>
50 <informalexample><programlisting>
51 static void
52 file_changed (GFileMonitor      *file_monitor,
53               GFile             *child,
54               GFile             *other_file,
55               GFileMonitorEvent  event_type,
56               gpointer           user_data)
57 {
58   switch (event_type)
59   {
60   case G_FILE_MONITOR_EVENT_DELETED:
61     g_print ("'%s' removed from trash\n", g_file_get_basename (child));
62     break;
63   case G_FILE_MONITOR_EVENT_CREATED:
64     g_print ("'%s' added to trash\n", g_file_get_basename (child));
65     break;
66   default: ;
67   }
68 }
69
70 static void
71 start_monitoring_trash (void)
72 {
73   GFile *file;
74   GFileMonitor *monitor;
75
76   file = g_file_new_for_uri ("trash://");
77   monitor = g_file_monitor_directory (file, 0, NULL, NULL);
78   g_object_unref (file);
79
80   g_signal_connect (monitor, "changed", G_CALLBACK (file_changed), NULL);
81
82   /* ... */
83
84 }       
85 </programlisting></informalexample> 
86       <para>
87         GIO exposes some useful metadata about trashed files. There are
88         trash::orig-path and trash::deletion-date attributes. The 
89         standard::icon attribute of the <filename>trash://</filename> 
90         itself provides a suitable icon for displaying the trash can on 
91         the desktop. If you are using this icon, make sure to monitor
92         this attribute for changes, since the icon may be updated to
93         reflect that state of the trash can.
94       </para>
95       <para>
96         Moving a file to the trash is much simpler with GIO. Instead of
97         using gnome_vfs_find_directory() with %GNOME_VFS_DIRECTORY_KIND_TRASH 
98         to find out where to move the trashed file, just use the g_file_trash()
99         function.
100       </para>
101     </section>
102
103     <section>
104       <title>Operations on multiple files</title>
105
106       <para>
107         gnome-vfs has the dreaded gnome_vfs_xfer_uri_list() function which
108         has tons of options and offers the equivalent of cp, mv, ln, mkdir
109         and rm at the same time. 
110       </para>
111       <para>
112         GIO offers a much simpler I/O scheduler functionality instead, that
113         lets you schedule a function to be called in a separate thread, or
114         if threads are not available, as an idle in the mainloop.
115         See g_io_scheduler_push_job(). 
116       </para>
117
118     </section>
119
120     <section>
121       <title>Mime monitoring</title>
122
123       <para>
124         gnome-vfs offered a way to monitor the association between mime types
125         and default handlers for changes, with the #GnomeVFSMIMEMonitor object.
126         GIO does not offer a replacement for this functionality at this time,
127         since we have not found a compelling use case where
128         #GnomeVFSMIMEMonitor was used. If you think you have such a use
129         case, please report it at
130         <ulink url="http://bugzilla.gnome.org">bugzilla.gnome.org</ulink>.
131       </para>
132     </section>
133   </chapter>