Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference |
|
The QUrlOperator class provides common operations on URLs (get() and more). More...
#include <qurloperator.h>
Inherited by FileSystemOperator.
The QUrlOperator class provides common operations on URLs (get() and more).
This class operates on hierarchical structures (like filesystems) using URLs. Its API allows do all common operations on it (listing children, removing children, renaming, etc.). But the class itself contains no functionality for that. It uses the functionality of registered network protocols. This means, depending of the protocol of the URL, it uses a fitting network protocol class for the operations. In detail, each of the operation methods of QUrlOperator create a QNetworkOperation object which describes the operation and puts it into the operation queue of the used network protocol. If no fitting protocol could be found (because no implementation of the needed network protocol is registered), the url operator emits errors. Also not each protocol supports each operation - but the error handling deals with this problem.
A QUrlOperator can be used like this (for e.g. downloading a file)
QUrlOperator op;
op.copy( QString("ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz"), "file:/tmp", FALSE );
Now, you also will connect to some signals of the QUrlOperator to get informed about success, errors, progress and more things.
Of course an implementation for the FTP protocol has to be registered for this example. In the Qt Network Extension Library there is an implementation of the FTP protocol.
For more information about the Qt Network Architecture take a look at the Qt Network Documentation.
See also QNetworkProtocol and QNetworkOperation.
You can pass strings such as "/home/qt": in this case the protocol "file" is assumed.
This signal is emitted whenever the state of the connection of the network protocol of the url operator is changed. state describes the new state, which is one of QNetworkProtocol::ConHostFound, QNetworkProtocol::ConConnected, QNetworkProtocol::ConClosed This enum is defined in QNetworkProtocol data is a message text.
Also at the end finished() (on success or failure) is emitted, so check the state of the network operation object to see if the operation was successful or not.
As a copy operation consists of multiple operations (get(), put() and maybe remove() (depending if you copy or move)) this method doesn't return a single QNetworkOperation, but a list of them. They are in the order get(), put(), remove(). As discussed, the third one (remove) is optional.
This method is just a convenience function of the copy method above. It calls the copy above for each entry in files one after the other. You don't get a result from this method, but each time a new copy is started, startedNextCopy() is emitted, with a list of QNetworkOperations which describe the new copy operation.
This signal is emitted when mkdir() has been succesful and the directory has been created. i holds the information about the new directory. op is the pointer to the operation object, which contains all infos of the operation, including the state and so on and using op->arg( 0 ) you also get the filename of the new directory.
See also QNetworkOperation and QNetworkProtocol.
This signal is emitted when new data has been received after e.g. calling get() or put(). op holds the name of the file which data is retrieved in the first argument and the data in the second argument (raw). You get them with op->arg( 0 ) and op->rawArg( 1 ).
op is the pointer to the operation object, which contains all infos of the operation, including the state and so on.
See also QNetworkOperation and QNetworkProtocol.
When transferring data (using put() or get()) this signal is emitted during the progress. bytesDone tells how many bytes of bytesTotal are transferred. More information about the operation is stored in the op, the pointer to the network operation which is processed. bytesTotal may be -1, which means that the number of total bytes is not known.
See also QNetworkOperation and QNetworkProtocol.
This signal is emitted when an operation of some sort finished. This signal is emitted always, this means on success and on failure. op is the pointer to the operation object, which contains all infos of the operation which has been finished, including the state and so on. To check if the operation was successful or not, check the state and error code of the operation object.
See also QNetworkOperation and QNetworkProtocol.
Now, if location is QString::null, the path of this QUrlOperator should point to a file when you use this operation. If location is not empty, it can be relative (a child of the path to which the QUrlOperator points) or an absolute URL.
E.g. for getting a Web page you might do something like
QUrlOperator op( "http://www.whatever.org/cgi-bin/search.pl?cmd=Hallo" ); op.get();
But as for the most other operations it is required that the path of the QUrlOperator points to a directory, you could do following if you want e.g. download a file
QUrlOperator 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.
But never do something like
QUrlOperator op( "http://www.whatever.org/cgi-bin" ); op.get( "search.pl?cmd=Hallo" );
This means 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 like in the first example or specify the full URL (like http://www.whatever.org/cgi-bin/search.pl?cmd=Hallo) as location.
See also copy().
This signal is emitted whenever a file, which is a child of this URL, has been changed e.g. by successfully calling rename(). op holds the original and the new filenames in the first and second arguments. You get them with op->arg( 0 ) and op->arg( 1 ).
op is the pointer to the operation object, which contains all infos of the operation, including the state and so on.
See also QNetworkOperation and QNetworkProtocol.
As the operation will not be executed immediately, a pointer to the QNetworkOperation object, which is created by this method, is returned. This object contains all data about the operation and is used to refer to this operation later (e.g. in the signals which are emitted by the QUrlOperator). The return value can be also 0 if the operation object couldn't be created.
The path of this QUrlOperator has to point to a directory, because the children of this directory will be listed, and not to a file, else this operation might not work!
As the operation will not be executed immediately, a pointer to the QNetworkOperation object, which is created by this method, is returned. This object contains all data about the operation and is used to refer to this operation later (e.g. in the signals which are emitted by the QUrlOperator). The return value can be also 0 if the operation object couldn't be created.
This path of this QUrlOperator has to point to a directory, as the new directory will be created in this path, and not to a file, else this operation might not work!
See also QUrlOperator::setNameFilter() and QDir::nameFilter().
This signal is emitted after listChildren() was called and new children (e.g. files) have been read from a list of files. i holds the information about the new children. op is the pointer to the operation object, which contains all infos of the operation, including the state and so on.
See also QNetworkOperation and QNetworkProtocol.
Now, if location is QString::null, the path of this QUrlOperator should point to a file when you use this operation. If location is not empty, it can be relative (a child of the path to which the QUrlOperator points) or an absolute URL.
E.g. for putting some data to a file you can do
QUrlOperator op( "ftp://ftp.whatever.com/home/me/filename" ); op.put( data );
But as for the most other operations it is required that the path of the QUrlOperator points to a directory, you could do following if you want e.g. upload data to a file
QUrlOperator op( "ftp://ftp.whatever.com/home/me" ); // do some other stuff like op.listChildren() or op.mkdir( "new Dir" ) op.put( data, "filename" );
This will upload the data to ftp://ftp.whatever.com/home/me/filename.
See also copy().
As the operation will not be executed immediately, a pointer to the QNetworkOperation object, which is created by this method, is returned. This object contains all data about the operation and is used to refer to this operation later (e.g. in the signals which are emitted by the QUrlOperator). The return value can be also 0 if the operation object couldn't be created.
This path of this QUrlOperator has to point to a directory, because if filename is relative, it will be tried to remove it in this directory, and not to a file, else this operation might not work!
This signal is emitted when remove() has been succesful and the file has been removed. op holds the filename of the removed file in the first argument, you get it with op->arg( 0 ).
op is the pointer to the operation object, which contains all infos of the operation, including the state and so on.
See also QNetworkOperation and QNetworkProtocol.
As the operation will not be executed immediately, a pointer to the QNetworkOperation object, which is created by this method, is returned. This object contains all data about the operation and is used to refer to this operation later (e.g. in the signals which are emitted by the QUrlOperator). The return value can be also 0 if the operation object couldn't be created.
This path of this QUrlOperator has to point to a directory, as oldname and newname are handled relatively to this directory, and not to a file, else this operation might not work!
See also QDir::setNameFilter().
Some operations (like listChildren()) emit this signal when they start processing the operation. op is the pointer to the operation object, which contains all infos of the operation, including the state and so on.
See also QNetworkOperation and QNetworkProtocol.
This signal is emitted if copy() started a new copy operation. lst contains all QNetworkOperations which describe this copy operation.
See also copy().
Reimplemented in FileSystemOperator.
This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.
| Copyright © 2005 Trolltech | Trademarks | Qtopia version 2.2.0
|