Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQUrlOperator class provides common operations on URLs. More...
#include <ntqurloperator.h>
The TQUrlOperator class provides common operations on URLs.
This class operates on hierarchical structures (such as filesystems) using URLs. Its API facilitates all the common operations:
Operation | Function |
---|---|
List files | listChildren() |
Make a directory | mkdir() |
Remove a file | remove() |
Rename a file | rename() |
Get a file | get() |
Put a file | put() |
Copy a file | copy() |
You can obtain additional information about the URL with isDir() and info(). If a directory is to be traversed using listChildren(), a name filter can be set with setNameFilter().
A TQUrlOperator can be used like this, for example to download a file (and assuming that the FTP protocol is registered):
TQUrlOperator *op = new TQUrlOperator(); op->copy( TQString("ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz"), "file:/tmp" );
If you want to be notified about success/failure, progress, etc., you can connect to TQUrlOperator's signals, e.g. to start(), newChildren(), createdDirectory(), removed(), data(), dataTransferProgress(), startedNextCopy(), connectionStateChanged(), finished(), etc. A network operation can be stopped with stop().
The class uses the functionality of registered network protocols to perform these operations. Depending of the protocol of the URL, it uses an appropriate network protocol class for the operations. Each of the operation functions of TQUrlOperator creates a TQNetworkOperation object that describes the operation and puts it into the operation queue for the network protocol used. If no suitable protocol could be found (because no implementation of the necessary network protocol is registered), the URL operator emits errors. Not every protocol supports every operation, but error handling deals with this problem.
To register the available network protocols, use the qInitNetworkProtocols() function. The protocols currently supported are:
For more information about the TQt Network Architecture see the TQt Network Documentation.
See also TQNetworkProtocol, TQNetworkOperation, Input/Output and Networking, and Miscellaneous Classes.
If you pass strings like "/home/qt" the "file" protocol is assumed.
This signal is emitted whenever the URL operator's connection state changes. state describes the new state, which is a TQNetworkProtocol::ConnectionState value.
data is a string that describes the change of the connection. This can be used to display a message to the user.
At the end, finished() (with success or failure) is emitted, so check the state of the network operation object to see whether or not the operation was successful.
Because a move or copy operation consists of multiple operations (get(), put() and maybe remove()), this function doesn't return a single TQNetworkOperation, but rather a list of them. They are in the order: get(), put() and (if applicable) remove().
Copies the files to the directory dest. If move is TRUE the files are moved, not copied. dest must point to a directory.
This function calls copy() for each entry in files in turn. You don't get a result from this function; each time a new copy begins, startedNextCopy() is emitted, with a list of TQNetworkOperations that describe the new copy operation.
This signal is emitted when mkdir() succeeds and the directory has been created. i holds the information about the new directory.
op is a pointer to the operation object, which contains all the information about the operation, including the state. op->arg(0) holds the new directory's name.
See also TQNetworkOperation and TQNetworkProtocol.
This signal is emitted when new data has been received after calling get() or put(). op is a pointer to the operation object which contains all the information about the operation, including the state. op->arg(0) holds the name of the file whose data is retrieved and op->rawArg(1) holds the (raw) data.
See also TQNetworkOperation and TQNetworkProtocol.
This signal is emitted during data transfer (using put() or get()). bytesDone specifies how many bytes of bytesTotal have been transferred. More information about the operation is stored in op, a pointer to the network operation that is processed. bytesTotal may be -1, which means that the total number of bytes is not known.
See also TQNetworkOperation and TQNetworkProtocol.
This signal is emitted when an operation of some sort finishes, whether with success or failure. op is a pointer to the operation object, which contains all the information, including the state, of the operation which has been finished. Check the state and error code of the operation object to see whether or not the operation was successful.
See also TQNetworkOperation and TQNetworkProtocol.
If location is TQString::null, the path of this TQUrlOperator should point to a file when you use this operation. If location is not empty, it can be a relative URL (a child of the path to which the TQUrlOperator points) or an absolute URL.
For example, to get a web page you might do something like this:
TQUrlOperator op( "http://www.whatever.org/cgi-bin/search.pl?cmd=Hello" ); op.get();
For most other operations, the path of the TQUrlOperator must point to a directory. If you want to download a file you could do the following:
TQUrlOperator op( "ftp://ftp.whatever.org/pub" ); // do some other stuff like op.listChildren() or op.mkdir( "new_dir" ) op.get( "a_file.txt" );
This will get the data of ftp://ftp.whatever.org/pub/a_file.txt.
Never do anything like this:
TQUrlOperator op( "http://www.whatever.org/cgi-bin" ); op.get( "search.pl?cmd=Hello" ); // WRONG!
If location is not empty and relative it must not contain any queries or references, just the name of a child. So if you need to specify a query or reference, do it as shown in the first example or specify the full URL (such as http://www.whatever.org/cgi-bin/search.pl?cmd=Hello) as location.
See also copy().
This signal is emitted whenever a file which is a child of the URL has been changed, for example by successfully calling rename(). op is a pointer to the operation object which contains all the information about the operation, including the state. op->arg(0) holds the original file name and op->arg(1) holds the new file name (if it was changed).
See also TQNetworkOperation and TQNetworkProtocol.
Because the operation may not be executed immediately, a pointer to the TQNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the TQUrlOperator). The return value can also be 0 if the operation object couldn't be created.
The path of this TQUrlOperator must to point to a directory (because the children of this directory will be listed), not to a file.
Because the operation will not be executed immediately, a pointer to the TQNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the TQUrlOperator). The return value can also be 0 if the operation object couldn't be created.
The path of this TQUrlOperator must to point to a directory (not a file) because the new directory will be created in this path.
See also TQUrlOperator::setNameFilter() and TQDir::nameFilter().
This signal is emitted after listChildren() was called and new children (i.e. files) have been read from a list of files. i holds the information about the new files. op is a pointer to the operation object which contains all the information about the operation, including the state.
See also TQNetworkOperation and TQNetworkProtocol.
If location is TQString::null, the path of this TQUrlOperator should point to a file when you use this operation. If location is not empty, it can be a relative (a child of the path to which the TQUrlOperator points) or an absolute URL.
For putting some data to a file you can do the following:
TQUrlOperator op( "ftp://ftp.whatever.com/home/me/filename.dat" ); op.put( data );
For most other operations, the path of the TQUrlOperator must point to a directory. If you want to upload data to a file you could do the following:
TQUrlOperator op( "ftp://ftp.whatever.com/home/me" ); // do some other stuff like op.listChildren() or op.mkdir( "new_dir" ) op.put( data, "filename.dat" );
This will upload the data to ftp://ftp.whatever.com/home/me/filename.dat.
See also copy().
Because the operation will not be executed immediately, a pointer to the TQNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the TQUrlOperator). The return value can also be 0 if the operation object couldn't be created.
The path of this TQUrlOperator must point to a directory; because if filename is relative, it will try to remove it in this directory.
This signal is emitted when remove() has been succesful and the file has been removed.
op is a pointer to the operation object which contains all the information about the operation, including the state. op->arg(0) holds the name of the file that was removed.
See also TQNetworkOperation and TQNetworkProtocol.
Because the operation may not be executed immediately, a pointer to the TQNetworkOperation object created by this function is returned. This object contains all the data about the operation and is used to refer to this operation later (e.g. in the signals that are emitted by the TQUrlOperator). The return value can also be 0 if the operation object couldn't be created.
This path of this TQUrlOperator must to point to a directory because oldname and newname are handled relative to this directory.
See also TQDir::setNameFilter().
Some operations (such as listChildren()) emit this signal when they start processing the operation. op is a pointer to the operation object which contains all the information about the operation, including the state.
See also TQNetworkOperation and TQNetworkProtocol.
This signal is emitted if copy() starts a new copy operation. lst contains all TQNetworkOperations related to this copy operation.
See also copy().
This function registers the network protocols for FTP and HTTP. You must call this function before you use TQUrlOperator for these protocols.
This function is declared in ntqnetwork.h.
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|