64e754fc89a2c1e737c382cf67da3ca9dbd89f6a
[platform/upstream/glib2.0.git] / docs / reference / gio / html / ch20.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Migrating from GnomeVFS to GIO</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="migrating.html" title="Part III. Migrating to GIO">
9 <link rel="prev" href="ch19.html" title="Migrating from POSIX to GIO">
10 <link rel="next" href="ch20s02.html" title="Operations on multiple files">
11 <meta name="generator" content="GTK-Doc V1.13 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 <link rel="part" href="pt01.html" title="Part I. GIO Overview">
14 <link rel="chapter" href="ch01.html" title="Introduction">
15 <link rel="chapter" href="ch02.html" title="Compiling GIO applications">
16 <link rel="chapter" href="ch03.html" title="Running GIO applications">
17 <link rel="chapter" href="extending-gio.html" title="Extending GIO">
18 <link rel="part" href="pt02.html" title="Part II. API Reference">
19 <link rel="chapter" href="file_ops.html" title="File Operations">
20 <link rel="chapter" href="file_mon.html" title="File System Monitoring">
21 <link rel="chapter" href="async.html" title="Asynchronous I/O">
22 <link rel="chapter" href="conversion.html" title="Data conversion">
23 <link rel="chapter" href="streaming.html" title="Streaming I/O">
24 <link rel="chapter" href="types.html" title="File types and applications">
25 <link rel="chapter" href="volume_mon.html" title="Volumes and Drives">
26 <link rel="chapter" href="icons.html" title="Icons">
27 <link rel="chapter" href="failable_initialization.html" title="Failable Initialization">
28 <link rel="chapter" href="networking.html" title="Lowlevel platform-independent network support">
29 <link rel="chapter" href="resolver.html" title="DNS resolution">
30 <link rel="chapter" href="highlevel-socket.html" title="Highlevel network functionallity">
31 <link rel="chapter" href="utils.html" title="Utilities">
32 <link rel="chapter" href="extending.html" title="Extending GIO">
33 <link rel="part" href="migrating.html" title="Part III. Migrating to GIO">
34 <link rel="chapter" href="ch19.html" title="Migrating from POSIX to GIO">
35 <link rel="chapter" href="ch20.html" title="Migrating from GnomeVFS to GIO">
36 <link rel="chapter" href="gio-hierarchy.html" title="Object Hierarchy">
37 <link rel="index" href="api-index-full.html" title="Index">
38 <link rel="index" href="api-index-deprecated.html" title="Index of deprecated symbols">
39 <link rel="index" href="api-index-2-18.html" title="Index of new symbols in 2.18">
40 <link rel="index" href="api-index-2-20.html" title="Index of new symbols in 2.20">
41 <link rel="index" href="api-index-2-22.html" title="Index of new symbols in 2.22">
42 <link rel="index" href="api-index-2-24.html" title="Index of new symbols in 2.24">
43 </head>
44 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
45 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
46 <td><a accesskey="p" href="ch19.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
47 <td><a accesskey="u" href="migrating.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
48 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
49 <th width="100%" align="center">GIO Reference Manual</th>
50 <td><a accesskey="n" href="ch20s02.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
51 </tr></table>
52 <div class="chapter" title="Migrating from GnomeVFS to GIO">
53 <div class="titlepage"><div><div><h2 class="title">
54 <a name="id554953"></a>Migrating from GnomeVFS to GIO</h2></div></div></div>
55 <div class="toc"><dl>
56 <dt><span class="section"><a href="ch20.html#id559976">Trash handling</a></span></dt>
57 <dt><span class="section"><a href="ch20s02.html">Operations on multiple files</a></span></dt>
58 <dt><span class="section"><a href="ch20s03.html">Mime monitoring</a></span></dt>
59 </dl></div>
60 <div class="table">
61 <a name="gnome-vfs-vs-gio"></a><p class="title"><b>Table 5. Comparison of GnomeVFS and GIO concepts</b></p>
62 <div class="table-contents"><table summary="Comparison of GnomeVFS and GIO concepts" border="1">
63 <colgroup>
64 <col>
65 <col>
66 </colgroup>
67 <thead><tr>
68 <th>GnomeVFS</th>
69 <th>GIO</th>
70 </tr></thead>
71 <tbody>
72 <tr>
73 <td>GnomeVFSURI</td>
74 <td>GFile</td>
75 </tr>
76 <tr>
77 <td>GnomeVFSFileInfo</td>
78 <td>GFileInfo</td>
79 </tr>
80 <tr>
81 <td>GnomeVFSResult</td>
82 <td>GError, with G_IO_ERROR values</td>
83 </tr>
84 <tr>
85 <td>GnomeVFSHandle &amp; GnomeVFSAsyncHandle</td>
86 <td>GInputStream or GOutputStream</td>
87 </tr>
88 <tr>
89 <td>GnomeVFSDirectoryHandle</td>
90 <td>GFileEnumerator</td>
91 </tr>
92 <tr>
93 <td>mime type</td>
94 <td>content type</td>
95 </tr>
96 <tr>
97 <td>GnomeVFSMonitor</td>
98 <td>GFileMonitor</td>
99 </tr>
100 <tr>
101 <td>GnomeVFSVolumeMonitor</td>
102 <td>GVolumeMonitor</td>
103 </tr>
104 <tr>
105 <td>GnomeVFSVolume</td>
106 <td>GMount</td>
107 </tr>
108 <tr>
109 <td>GnomeVFSDrive</td>
110 <td>GVolume</td>
111 </tr>
112 <tr>
113 <td>-</td>
114 <td>GDrive</td>
115 </tr>
116 <tr>
117 <td>GnomeVFSContext</td>
118 <td>GCancellable</td>
119 </tr>
120 <tr>
121 <td>gnome_vfs_async_cancel</td>
122 <td>g_cancellable_cancel</td>
123 </tr>
124 </tbody>
125 </table></div>
126 </div>
127 <br class="table-break"><div class="section" title="Trash handling">
128 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
129 <a name="id559976"></a>Trash handling</h2></div></div></div>
130 <p>
131         The handling of trashed files has been changed in GIO, compared
132         to gnome-vfs. gnome-vfs has a home-grown trash implementation that 
133         predates the freedesktop.org <a class="ulink" href="http://www.freedesktop.org/wiki/Specifications/trash-spec" target="_top">Desktop Trash Can</a> specification
134         that is implemented in GIO. The location for storing trashed files 
135         has changed from <code class="filename">$HOME/.Trash</code> to 
136         <code class="filename">$HOME/.local/share/Trash</code> (or more correctly
137         <code class="filename">$XDG_DATA_HOME/Trash</code>), which means that 
138         there is a need for migrating files that have been trashed by 
139         gnome-vfs to the new location.
140       </p>
141 <p>
142         In gnome-vfs, the <code class="filename">trash://</code> scheme offering a 
143         merged view of all trash directories was implemented in nautilus,
144         and trash-handling applications had to find and monitor all trash 
145         directories themselves. With GIO, the <code class="filename">trash://</code>
146         implementation has been moved to gvfs and applications can simply
147         monitor that location:
148       </p>
149 <div class="informalexample"><pre class="programlisting">
150 static void
151 file_changed (GFileMonitor      *file_monitor,
152               GFile             *child,
153               GFile             *other_file,
154               GFileMonitorEvent  event_type,
155               gpointer           user_data)
156 {
157   switch (event_type)
158   {
159   case G_FILE_MONITOR_EVENT_DELETED:
160     g_print ("'%s' removed from trash\n", g_file_get_basename (child));
161     break;
162   case G_FILE_MONITOR_EVENT_CREATED:
163     g_print ("'%s' added to trash\n", g_file_get_basename (child));
164     break;
165   default: ;
166   }
167 }
168
169 static void
170 start_monitoring_trash (void)
171 {
172   GFile *file;
173   GFileMonitor *monitor;
174
175   file = g_file_new_for_uri ("trash://");
176   monitor = g_file_monitor_directory (file, 0, NULL, NULL);
177   g_object_unref (file);
178
179   g_signal_connect (monitor, "changed", G_CALLBACK (file_changed), NULL);
180
181   /* ... */
182
183 }       
184 </pre></div>
185 <p>
186         GIO exposes some useful metadata about trashed files. There are
187         trash::orig-path and trash::deletion-date attributes. The 
188         standard::icon attribute of the <code class="filename">trash://</code> 
189         itself provides a suitable icon for displaying the trash can on 
190         the desktop. If you are using this icon, make sure to monitor
191         this attribute for changes, since the icon may be updated to
192         reflect that state of the trash can.
193       </p>
194 <p>
195         Moving a file to the trash is much simpler with GIO. Instead of
196         using <a href="/usr/share/gtk-doc/html/gnome-vfs-2.0/gnome-vfs-2.0-gnome-vfs-directory-find-ops.html#gnome-vfs-find-directory"><code class="function">gnome_vfs_find_directory()</code></a> with <code class="literal">GNOME_VFS_DIRECTORY_KIND_TRASH</code> 
197         to find out where to move the trashed file, just use the <a class="link" href="GFile.html#g-file-trash" title="g_file_trash ()"><code class="function">g_file_trash()</code></a>
198         function.
199       </p>
200 </div>
201 </div>
202 <div class="footer">
203 <hr>
204           Generated by GTK-Doc V1.13</div>
205 </body>
206 </html>