MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Q3UrlOperator Class Reference

The Q3UrlOperator class provides common operations on URLs. More...

 #include <Q3UrlOperator>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Inherits: QObject and Q3Url.

Public Functions

Q3UrlOperator ()
Q3UrlOperator ( const QString & url )
Q3UrlOperator ( const Q3UrlOperator & url )
Q3UrlOperator ( const Q3UrlOperator & url, const QString & relUrl, bool checkSlash = false )
virtual ~Q3UrlOperator ()
virtual Q3PtrList<Q3NetworkOperation> copy ( const QString & from, const QString & to, bool move = false, bool toPath = true )
virtual void copy ( const QStringList & files, const QString & dest, bool move = false )
virtual const Q3NetworkOperation * get ( const QString & location = QString() )
virtual QUrlInfo info ( const QString & entry ) const
virtual bool isDir ( bool * ok = 0 )
virtual const Q3NetworkOperation * listChildren ()
virtual const Q3NetworkOperation * mkdir ( const QString & dirname )
QString nameFilter () const
virtual const Q3NetworkOperation * put ( const QByteArray & data, const QString & location = QString() )
virtual const Q3NetworkOperation * remove ( const QString & filename )
virtual const Q3NetworkOperation * rename ( const QString & oldname, const QString & newname )
virtual void setNameFilter ( const QString & nameFilter )
virtual void stop ()
Q3UrlOperator & operator= ( const Q3UrlOperator & url )
Q3UrlOperator & operator= ( const QString & url )

Reimplemented Public Functions

virtual void setPath ( const QString & path )
  • 29 public functions inherited from QObject
  • 37 public functions inherited from Q3Url

Signals

void connectionStateChanged ( int state, const QString & data )
void createdDirectory ( const QUrlInfo & i, Q3NetworkOperation * op )
void data ( const QByteArray & data, Q3NetworkOperation * op )
void dataTransferProgress ( int bytesDone, int bytesTotal, Q3NetworkOperation * op )
void finished ( Q3NetworkOperation * op )
void itemChanged ( Q3NetworkOperation * op )
void newChildren ( const Q3ValueList<QUrlInfo> & i, Q3NetworkOperation * op )
void removed ( Q3NetworkOperation * op )
void start ( Q3NetworkOperation * op )
void startedNextCopy ( const Q3PtrList<Q3NetworkOperation> & lst )

Protected Functions

virtual void clearEntries ()
void deleteNetworkProtocol ()
void getNetworkProtocol ()

Reimplemented Protected Functions

virtual bool parse ( const QString & url )
virtual void reset ()
  • 7 protected functions inherited from QObject
  • 2 protected functions inherited from Q3Url

Related Non-Members

void q3InitNetworkProtocols ()

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 5 static public members inherited from QObject
  • 3 static public members inherited from Q3Url

Detailed Description

The Q3UrlOperator 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 Q3UrlOperator can be used like this, for example to download a file (and assuming that the FTP protocol is registered):

 Q3UrlOperator *op = new Q3UrlOperator();
 op->copy( QString("ftp://ftp.qt.nokia.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 Q3UrlOperator'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 Q3UrlOperator creates a Q3NetworkOperation 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:

See also Q3NetworkProtocol and Q3NetworkOperation.

Member Function Documentation

Q3UrlOperator::Q3UrlOperator ()

Constructs a Q3UrlOperator with an empty (i.e. invalid) URL.

Q3UrlOperator::Q3UrlOperator ( const QString & url )

Constructs a Q3UrlOperator using url and parses this string.

If you pass strings like "/home/qt" the "file" protocol is assumed.

Q3UrlOperator::Q3UrlOperator ( const Q3UrlOperator & url )

Constructs a copy of url.

Q3UrlOperator::Q3UrlOperator ( const Q3UrlOperator & url, const QString & relUrl, bool checkSlash = false )

Constructs a Q3UrlOperator. The URL on which this Q3UrlOperator operates is constructed out of the arguments url, relUrl and checkSlash: see the corresponding Q3Url constructor for an explanation of these arguments.

Q3UrlOperator::~Q3UrlOperator () [virtual]

Destructor.

void Q3UrlOperator::clearEntries () [virtual protected]

Clears the cache of children.

void Q3UrlOperator::connectionStateChanged ( int state, const QString & data ) [signal]

This signal is emitted whenever the URL operator's connection state changes. state describes the new state, which is a Q3NetworkProtocol::ConnectionState value.

data is a string that describes the change of the connection. This can be used to display a message to the user.

Q3PtrList<Q3NetworkOperation> Q3UrlOperator::copy ( const QString & from, const QString & to, bool move = false, bool toPath = true ) [virtual]

Copies the file from to to. If move is true, the file is moved (copied and removed). from must point to a file and to must point to a directory (into which from is copied) unless toPath is set to false. If toPath is set to false then the to variable is assumed to be the absolute file path (destination file path + file name). The copying is done using the get() and put() operations. If you want to be notified about the progress of the operation, connect to the dataTransferProgress() signal. Bear in mind that the get() and put() operations emit this signal through the Q3UrlOperator. The number of transferred bytes and the total bytes that you receive as arguments in this signal do not relate to the whole copy operation; they relate first to the get() and then to the put() operation. Always check what type of operation the signal comes from; this is given in the signal's last argument.

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 Q3NetworkOperation, but rather a list of them. They are in the order: get(), put() and (if applicable) remove().

See also get() and put().

void Q3UrlOperator::copy ( const QStringList & files, const QString & dest, bool move = false ) [virtual]

This is an overloaded function.

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 Q3NetworkOperations that describe the new copy operation.

void Q3UrlOperator::createdDirectory ( const QUrlInfo & i, Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

void Q3UrlOperator::data ( const QByteArray & data, Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

void Q3UrlOperator::dataTransferProgress ( int bytesDone, int bytesTotal, Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

void Q3UrlOperator::deleteNetworkProtocol () [protected]

Deletes the currently used network protocol.

void Q3UrlOperator::finished ( Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

const Q3NetworkOperation * Q3UrlOperator::get ( const QString & location = QString() ) [virtual]

Tells the network protocol to get data from location or, if it is empty, to get data from the location to which this URL points (see Q3Url::fileName() and Q3Url::encodedPathAndQuery()). What happens then depends on the network protocol. The data() signal is emitted when data comes in. Because it's unlikely that all data will come in at once, it is common for multiple data() signals to be emitted. The dataTransferProgress() signal is emitted while processing the operation. 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.

If location is empty, the path of this Q3UrlOperator 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 Q3UrlOperator points) or an absolute URL.

For example, to get a web page you might do something like this:

 Q3UrlOperator op( "http://www.whatever.org/cgi-bin/search.pl?cmd=Hello" );
 op.get();

For most other operations, the path of the Q3UrlOperator must point to a directory. If you want to download a file you could do the following:

 Q3UrlOperator 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:

 Q3UrlOperator 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().

void Q3UrlOperator::getNetworkProtocol () [protected]

Finds a network protocol for the URL and deletes the old network protocol.

QUrlInfo Q3UrlOperator::info ( const QString & entry ) const [virtual]

Returns the URL information for the child entry, or returns an empty QUrlInfo object if there is no information available about entry. Information about entry is only available after a successfully finished listChildren() operation.

bool Q3UrlOperator::isDir ( bool * ok = 0 ) [virtual]

Returns true if the URL is a directory; otherwise returns false. This may not always work correctly, if the protocol of the URL is something other than file (local filesystem). If you pass a bool pointer as the ok argument, *ok is set to true if the result of this function is known to be correct, and to false otherwise.

void Q3UrlOperator::itemChanged ( Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

const Q3NetworkOperation * Q3UrlOperator::listChildren () [virtual]

Starts listing the children of this URL (e.g. the files in the directory). The start() signal is emitted before the first entry is listed and finished() is emitted after the last one. The newChildren() signal is emitted for each list of new entries. If an error occurs, the signal finished() is emitted, so be sure to check the state of the network operation pointer.

Because the operation may not be executed immediately, a pointer to the Q3NetworkOperation 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 Q3UrlOperator). The return value can also be 0 if the operation object couldn't be created.

The path of this Q3UrlOperator must to point to a directory (because the children of this directory will be listed), not to a file.

const Q3NetworkOperation * Q3UrlOperator::mkdir ( const QString & dirname ) [virtual]

Tries to create a directory (child) with the name dirname. If it is successful, a newChildren() signal with the new child is emitted, and the createdDirectory() signal with the information about the new child is also emitted. The finished() signal (with success or failure) is emitted after the operation has been processed, so check the state of the network operation object to see whether or not the operation was successful.

Because the operation will not be executed immediately, a pointer to the Q3NetworkOperation 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 Q3UrlOperator). The return value can also be 0 if the operation object couldn't be created.

The path of this Q3UrlOperator must to point to a directory (not a file) because the new directory will be created in this path.

QString Q3UrlOperator::nameFilter () const

Returns the name filter of the URL.

See also Q3UrlOperator::setNameFilter() and QDir::nameFilter().

void Q3UrlOperator::newChildren ( const Q3ValueList<QUrlInfo> & i, Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

bool Q3UrlOperator::parse ( const QString & url ) [virtual protected]

Reimplemented from Q3Url::parse().

const Q3NetworkOperation * Q3UrlOperator::put ( const QByteArray & data, const QString & location = QString() ) [virtual]

This function tells the network protocol to put data in location. If location is empty, it puts the data in the location to which the URL points. What happens depends on the network protocol. Depending on the network protocol, some data might come back after putting data, in which case the data() signal is emitted. The dataTransferProgress() signal is emitted during processing of the operation. 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.

If location is empty, the path of this Q3UrlOperator 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 Q3UrlOperator points) or an absolute URL.

For putting some data to a file you can do the following:

 Q3UrlOperator op( "ftp://ftp.whatever.com/home/me/filename.dat" );
 op.put( data );

For most other operations, the path of the Q3UrlOperator must point to a directory. If you want to upload data to a file you could do the following:

 Q3UrlOperator 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().

const Q3NetworkOperation * Q3UrlOperator::remove ( const QString & filename ) [virtual]

Tries to remove the file (child) filename. If it succeeds the removed() signal is emitted. finished() (with success or failure) is also emitted after the operation has been processed, so check the state of the network operation object to see whether or not the operation was successful.

Because the operation will not be executed immediately, a pointer to the Q3NetworkOperation 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 Q3UrlOperator). The return value can also be 0 if the operation object couldn't be created.

The path of this Q3UrlOperator must point to a directory; because if filename is relative, it will try to remove it in this directory.

void Q3UrlOperator::removed ( Q3NetworkOperation * op ) [signal]

This signal is emitted when remove() has been successful 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 Q3NetworkOperation and Q3NetworkProtocol.

const Q3NetworkOperation * Q3UrlOperator::rename ( const QString & oldname, const QString & newname ) [virtual]

Tries to rename the file (child) called oldname to newname. If it succeeds, the itemChanged() signal is emitted. finished() (with success or failure) is also emitted after the operation has been processed, so check the state of the network operation object to see whether or not the operation was successful.

Because the operation may not be executed immediately, a pointer to the Q3NetworkOperation 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 Q3UrlOperator). The return value can also be 0 if the operation object couldn't be created.

This path of this Q3UrlOperator must to point to a directory because oldname and newname are handled relative to this directory.

void Q3UrlOperator::reset () [virtual protected]

Reimplemented from Q3Url::reset().

void Q3UrlOperator::setNameFilter ( const QString & nameFilter ) [virtual]

Sets the name filter of the URL to nameFilter.

See also nameFilter() and QDir::setNameFilter().

void Q3UrlOperator::setPath ( const QString & path ) [virtual]

Reimplemented from Q3Url::setPath().

void Q3UrlOperator::start ( Q3NetworkOperation * op ) [signal]

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 Q3NetworkOperation and Q3NetworkProtocol.

void Q3UrlOperator::startedNextCopy ( const Q3PtrList<Q3NetworkOperation> & lst ) [signal]

This signal is emitted if copy() starts a new copy operation. lst contains all Q3NetworkOperations related to this copy operation.

See also copy().

void Q3UrlOperator::stop () [virtual]

Stops the current network operation and removes all this Q3UrlOperator's waiting network operations.

Q3UrlOperator & Q3UrlOperator::operator= ( const Q3UrlOperator & url )

Assigns url to this object.

Q3UrlOperator & Q3UrlOperator::operator= ( const QString & url )

Assigns url to this object.

Related Non-Members

void q3InitNetworkProtocols ()

This function registers the network protocols for FTP and HTTP. You must call this function before you use QUrlOperator for these protocols.