1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | |
---|
3 | /* gnome-vfs-xfer.h - File transfers in the GNOME Virtual File System. |
---|
4 | |
---|
5 | Copyright (C) 1999 Free Software Foundation |
---|
6 | |
---|
7 | The Gnome Library is free software; you can redistribute it and/or |
---|
8 | modify it under the terms of the GNU Library General Public License as |
---|
9 | published by the Free Software Foundation; either version 2 of the |
---|
10 | License, or (at your option) any later version. |
---|
11 | |
---|
12 | The Gnome Library is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | Library General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU Library General Public |
---|
18 | License along with the Gnome Library; see the file COPYING.LIB. If not, |
---|
19 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | Boston, MA 02111-1307, USA. |
---|
21 | |
---|
22 | Author: Ettore Perazzoli <ettore@comm2000.it> */ |
---|
23 | |
---|
24 | #ifndef GNOME_VFS_XFER_H |
---|
25 | #define GNOME_VFS_XFER_H |
---|
26 | |
---|
27 | #include <libgnomevfs/gnome-vfs-file-info.h> |
---|
28 | |
---|
29 | /* Xfer options. |
---|
30 | * FIXME bugzilla.eazel.com 1205: |
---|
31 | * Split these up into xfer options and xfer actions |
---|
32 | */ |
---|
33 | typedef enum { |
---|
34 | GNOME_VFS_XFER_DEFAULT = 0, |
---|
35 | GNOME_VFS_XFER_UNUSED_1 = 1 << 0, |
---|
36 | GNOME_VFS_XFER_FOLLOW_LINKS = 1 << 1, |
---|
37 | GNOME_VFS_XFER_UNUSED_2 = 1 << 2, |
---|
38 | GNOME_VFS_XFER_RECURSIVE = 1 << 3, |
---|
39 | GNOME_VFS_XFER_SAMEFS = 1 << 4, |
---|
40 | GNOME_VFS_XFER_DELETE_ITEMS = 1 << 5, |
---|
41 | GNOME_VFS_XFER_EMPTY_DIRECTORIES = 1 << 6, |
---|
42 | GNOME_VFS_XFER_NEW_UNIQUE_DIRECTORY = 1 << 7, |
---|
43 | GNOME_VFS_XFER_REMOVESOURCE = 1 << 8, |
---|
44 | GNOME_VFS_XFER_USE_UNIQUE_NAMES = 1 << 9, |
---|
45 | GNOME_VFS_XFER_LINK_ITEMS = 1 << 10 |
---|
46 | } GnomeVFSXferOptions; |
---|
47 | |
---|
48 | /* Progress status, to be reported to the caller of the transfer operation. */ |
---|
49 | typedef enum { |
---|
50 | GNOME_VFS_XFER_PROGRESS_STATUS_OK = 0, |
---|
51 | GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR = 1, |
---|
52 | GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE = 2, |
---|
53 | /* during the duplicate status the progress callback is asked to |
---|
54 | supply a new unique name */ |
---|
55 | GNOME_VFS_XFER_PROGRESS_STATUS_DUPLICATE = 3 |
---|
56 | } GnomeVFSXferProgressStatus; |
---|
57 | |
---|
58 | /* The different ways to deal with overwriting during a transfer operation. */ |
---|
59 | typedef enum { |
---|
60 | /* Interrupt transferring with an error (GNOME_VFS_ERROR_FILEEXISTS). */ |
---|
61 | GNOME_VFS_XFER_OVERWRITE_MODE_ABORT = 0, |
---|
62 | /* Invoke the progress callback with a |
---|
63 | `GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE' status code. */ |
---|
64 | GNOME_VFS_XFER_OVERWRITE_MODE_QUERY = 1, |
---|
65 | /* Overwrite files silently. */ |
---|
66 | GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE = 2, |
---|
67 | /* Ignore files silently. */ |
---|
68 | GNOME_VFS_XFER_OVERWRITE_MODE_SKIP = 3 |
---|
69 | } GnomeVFSXferOverwriteMode; |
---|
70 | |
---|
71 | /* This defines the actions to perform before a file is being overwritten |
---|
72 | (i.e., these are the answers that can be given to a replace query). */ |
---|
73 | typedef enum { |
---|
74 | GNOME_VFS_XFER_OVERWRITE_ACTION_ABORT = 0, |
---|
75 | GNOME_VFS_XFER_OVERWRITE_ACTION_REPLACE = 1, |
---|
76 | GNOME_VFS_XFER_OVERWRITE_ACTION_REPLACE_ALL = 2, |
---|
77 | GNOME_VFS_XFER_OVERWRITE_ACTION_SKIP = 3, |
---|
78 | GNOME_VFS_XFER_OVERWRITE_ACTION_SKIP_ALL = 4, |
---|
79 | } GnomeVFSXferOverwriteAction; |
---|
80 | |
---|
81 | typedef enum { |
---|
82 | /* Interrupt transferring with an error (code returned is code of the |
---|
83 | operation that has caused the error). */ |
---|
84 | GNOME_VFS_XFER_ERROR_MODE_ABORT = 0, |
---|
85 | /* Invoke the progress callback with a |
---|
86 | `GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR' status code. */ |
---|
87 | GNOME_VFS_XFER_ERROR_MODE_QUERY = 1, |
---|
88 | } GnomeVFSXferErrorMode; |
---|
89 | |
---|
90 | /* This defines the possible actions to be performed after an error has |
---|
91 | occurred. */ |
---|
92 | typedef enum { |
---|
93 | /* Interrupt operation and return `GNOME_VFS_ERROR_INTERRUPTED'. */ |
---|
94 | GNOME_VFS_XFER_ERROR_ACTION_ABORT = 0, |
---|
95 | /* Try the same operation again. */ |
---|
96 | GNOME_VFS_XFER_ERROR_ACTION_RETRY = 1, |
---|
97 | /* Skip this file and continue normally. */ |
---|
98 | GNOME_VFS_XFER_ERROR_ACTION_SKIP = 2 |
---|
99 | } GnomeVFSXferErrorAction; |
---|
100 | |
---|
101 | /* This specifies the current phase in the transfer operation. Phases whose |
---|
102 | comments are marked with `(*)' are always reported in "normal" (i.e. no |
---|
103 | error) condition; the other ones are only reported if an error happens in |
---|
104 | that specific phase. */ |
---|
105 | typedef enum { |
---|
106 | /* Initial phase */ |
---|
107 | GNOME_VFS_XFER_PHASE_INITIAL, |
---|
108 | /* Checking if destination can handle move/copy */ |
---|
109 | GNOME_VFS_XFER_CHECKING_DESTINATION, |
---|
110 | /* Collecting file list */ |
---|
111 | GNOME_VFS_XFER_PHASE_COLLECTING, |
---|
112 | /* File list collected (*) */ |
---|
113 | GNOME_VFS_XFER_PHASE_READYTOGO, |
---|
114 | /* Opening source file for reading */ |
---|
115 | GNOME_VFS_XFER_PHASE_OPENSOURCE, |
---|
116 | /* Creating target file for copy */ |
---|
117 | GNOME_VFS_XFER_PHASE_OPENTARGET, |
---|
118 | /* Copying data from source to target (*) */ |
---|
119 | GNOME_VFS_XFER_PHASE_COPYING, |
---|
120 | /* Moving file from source to target (*) */ |
---|
121 | GNOME_VFS_XFER_PHASE_MOVING, |
---|
122 | /* Reading data from source file */ |
---|
123 | GNOME_VFS_XFER_PHASE_READSOURCE, |
---|
124 | /* Writing data to target file */ |
---|
125 | GNOME_VFS_XFER_PHASE_WRITETARGET, |
---|
126 | /* Closing source file */ |
---|
127 | GNOME_VFS_XFER_PHASE_CLOSESOURCE, |
---|
128 | /* Closing target file */ |
---|
129 | GNOME_VFS_XFER_PHASE_CLOSETARGET, |
---|
130 | /* Deleting source file */ |
---|
131 | GNOME_VFS_XFER_PHASE_DELETESOURCE, |
---|
132 | /* Setting attributes on target file */ |
---|
133 | GNOME_VFS_XFER_PHASE_SETATTRIBUTES, |
---|
134 | /* Go to the next file (*) */ |
---|
135 | GNOME_VFS_XFER_PHASE_FILECOMPLETED, |
---|
136 | /* cleaning up after a move (removing source files, etc.) */ |
---|
137 | GNOME_VFS_XFER_PHASE_CLEANUP, |
---|
138 | /* Operation finished (*) */ |
---|
139 | GNOME_VFS_XFER_PHASE_COMPLETED, |
---|
140 | GNOME_VFS_XFER_NUM_PHASES |
---|
141 | } GnomeVFSXferPhase; |
---|
142 | |
---|
143 | /* Progress information for the transfer operation. This is especially useful |
---|
144 | for interactive programs. */ |
---|
145 | typedef struct { |
---|
146 | /* Progress status (see above for a description). */ |
---|
147 | GnomeVFSXferProgressStatus status; |
---|
148 | |
---|
149 | /* VFS status code. If `status' is |
---|
150 | `GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR', you should look at this |
---|
151 | member to know what has happened. */ |
---|
152 | GnomeVFSResult vfs_status; |
---|
153 | |
---|
154 | /* Current phase in the transferring process. */ |
---|
155 | GnomeVFSXferPhase phase; |
---|
156 | |
---|
157 | /* Source URI. FIXME bugzilla.eazel.com 1206: change name? */ |
---|
158 | gchar *source_name; |
---|
159 | |
---|
160 | /* Destination URI. FIXME bugzilla.eazel.com 1206: change name? */ |
---|
161 | gchar *target_name; |
---|
162 | |
---|
163 | /* Index of file being copied. */ |
---|
164 | gulong file_index; |
---|
165 | |
---|
166 | /* Total number of files to be copied. */ |
---|
167 | gulong files_total; |
---|
168 | |
---|
169 | /* Total number of bytes to be copied. */ |
---|
170 | GnomeVFSFileSize bytes_total; |
---|
171 | |
---|
172 | /* Total size of this file (in bytes). */ |
---|
173 | GnomeVFSFileSize file_size; |
---|
174 | |
---|
175 | /* Bytes copied for this file so far. */ |
---|
176 | GnomeVFSFileSize bytes_copied; |
---|
177 | |
---|
178 | /* Total amount of data copied from the beginning. */ |
---|
179 | GnomeVFSFileSize total_bytes_copied; |
---|
180 | |
---|
181 | /* Target unique name used when duplicating, etc. to avoid collisions */ |
---|
182 | gchar *duplicate_name; |
---|
183 | |
---|
184 | /* Count used in the unique name e.g. (copy 2), etc. */ |
---|
185 | int duplicate_count; |
---|
186 | |
---|
187 | gboolean top_level_item; |
---|
188 | /* indicates that the copied/moved/deleted item is an actual item |
---|
189 | * passed in the uri list rather than one encountered by recursively |
---|
190 | * traversing directories. Used by metadata copying. |
---|
191 | */ |
---|
192 | |
---|
193 | } GnomeVFSXferProgressInfo; |
---|
194 | |
---|
195 | /* This is the prototype for functions called during a transfer operation to |
---|
196 | report progress. If the return value is `FALSE' (0), the operation is |
---|
197 | interrupted immediately: the transfer function returns with the value of |
---|
198 | `vfs_status' if it is different from `GNOME_VFS_OK', or with |
---|
199 | `GNOME_VFS_ERROR_INTERRUPTED' otherwise. The effect of other values depend |
---|
200 | on the value of `info->status': |
---|
201 | |
---|
202 | - If the status is `GNOME_VFS_XFER_PROGRESS_STATUS_OK', the transfer |
---|
203 | operation is resumed normally. |
---|
204 | |
---|
205 | - If the status is `GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR', the return |
---|
206 | value is interpreted as a `GnomeVFSXferErrorAction' and operation is |
---|
207 | interrupted, continued or retried accordingly. |
---|
208 | |
---|
209 | - If the status is `GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE', the return |
---|
210 | value is interpreted as a `GnomeVFSXferOverwriteAction'. */ |
---|
211 | |
---|
212 | typedef gint (* GnomeVFSXferProgressCallback) (GnomeVFSXferProgressInfo *info, |
---|
213 | gpointer data); |
---|
214 | |
---|
215 | typedef struct GnomeVFSProgressCallbackState { |
---|
216 | |
---|
217 | /* xfer state */ |
---|
218 | GnomeVFSXferProgressInfo *progress_info; |
---|
219 | |
---|
220 | /* Callback called for every xfer operation. For async calls called |
---|
221 | in async xfer context. */ |
---|
222 | GnomeVFSXferProgressCallback sync_callback; |
---|
223 | |
---|
224 | /* Callback called periodically every few hundred miliseconds |
---|
225 | and whenever user interaction is needed. For async calls |
---|
226 | called in the context of the async call caller. */ |
---|
227 | GnomeVFSXferProgressCallback update_callback; |
---|
228 | |
---|
229 | /* User data passed to sync_callback. */ |
---|
230 | gpointer user_data; |
---|
231 | |
---|
232 | /* Async job state passed to the update callback. */ |
---|
233 | gpointer async_job_data; |
---|
234 | |
---|
235 | /* When will update_callback be called next. */ |
---|
236 | gint64 next_update_callback_time; |
---|
237 | |
---|
238 | /* When will update_callback be called next. */ |
---|
239 | gint64 next_text_update_callback_time; |
---|
240 | |
---|
241 | /* Period at which the update_callback will be called. */ |
---|
242 | gint64 update_callback_period; |
---|
243 | } GnomeVFSProgressCallbackState; |
---|
244 | |
---|
245 | GnomeVFSResult gnome_vfs_xfer_uri_list (const GList *source_uri_list, |
---|
246 | const GList *target_uri_list, |
---|
247 | GnomeVFSXferOptions xfer_options, |
---|
248 | GnomeVFSXferErrorMode error_mode, |
---|
249 | GnomeVFSXferOverwriteMode overwrite_mode, |
---|
250 | GnomeVFSXferProgressCallback progress_callback, |
---|
251 | gpointer data); |
---|
252 | GnomeVFSResult gnome_vfs_xfer_uri (const GnomeVFSURI *source_uri, |
---|
253 | const GnomeVFSURI *target_uri, |
---|
254 | GnomeVFSXferOptions xfer_options, |
---|
255 | GnomeVFSXferErrorMode error_mode, |
---|
256 | GnomeVFSXferOverwriteMode overwrite_mode, |
---|
257 | GnomeVFSXferProgressCallback progress_callback, |
---|
258 | gpointer data); |
---|
259 | GnomeVFSResult gnome_vfs_xfer_delete_list (const GList *source_uri_list, |
---|
260 | GnomeVFSXferErrorMode error_mode, |
---|
261 | GnomeVFSXferOptions xfer_options, |
---|
262 | GnomeVFSXferProgressCallback progress_callback, |
---|
263 | gpointer data); |
---|
264 | |
---|
265 | #endif /* GNOME_VFS_XFER_H */ |
---|