The Official GNOME 2 Developers Guide

8.6 Transfers

Transfers are powerful utilities for transferring files from one place to another. You can copy anything from a single file to an entire directory tree with just a single statement, regardless of the file system type.

The API and mechanism is somewhat complicated. After you start a transfer, GnomeVFS periodically runs one of your callback functions. Your callback may need to answer a query, and that's the tricky part; you need to take a very close look at the callback parameters so that you know what kind of answer is appropriate.

The basic URI transfer function is

GnomeVFSResult gnome_vfs_xfer_uri(const GnomeVFSURI * src_uri , const GnomeVFSURI * target_uri , GnomeVFSXferOptions options , GnomeVFSXferErrorMode error_mode , GnomeVFSXferOverwriteMode overwrite_mode , GnomeVFSXferProgressCallback callback , gpointer data )

This function transfers src_uri to its corresponding location in target_uri .

Specify options as a bitwise OR of these constants:

Specify error_mode as one of the following:

The overwrite_mode parameter determines what GnomeVFS does when a transfer can overwrite a file:

Every few hundred milliseconds , or whenever interaction is necessary as noted in the preceding discussion, GnomeVFS invokes

callback ( info , data )

The full type definition for callback is

typedef gint (* GnomeVFSXferProgressCallback) (GnomeVFSXferProgressInfo *info, gpointer data);

Note that callback must be able to answer queries from GnomeVFS. To determine the answer, use the following general procedure:

  1. Look at info ->status to see what GnomeVFS wants.

  2. Figure out what return codes work for the status.

  3. Look at any other fields in info to make a final decision.

Detailed descriptions of each step follow.

Step 1:

The value of info ->status can be any of the following:

Step 2:

If info ->status says that everything is going well, return 1 to continue or 0 to terminate the transfer. For an error, your callback can return one of the following:

For overwrite questions, the return codes are

For duplicate filenames, set info ->duplicate_name (see the discussion that follows) and return 1 to continue or 0 to stop.

Step 3:

GnomeVFSXferProgressInfo is a large structure with these fields:

8.6.1 Additional Transfer Functions

Now that you've seen the particulars of transferring a single item, you are ready to see the other transfer utilities at your disposal:

afunc (* handle_addr , info , adata )

The type definition for afunc is

typedef gint (* GnomeVFSAsyncXferProgressCallback) (GnomeVFSAsyncHandle * handle , GnomeVFSXferProgressInfo * info , gpointer data );

For synchronous requests that require an answer, GnomeVFS makes the usual call to

callback ( info , data )

Категории