This is the base class for network protocols which provides a common API for network protocols. More...
#include <qnetworkprotocol.h>
Inherits QObject.
Inherited by QFtp and QLocalFs.
This is a baseclass which should be used for implementations of network protocols which can then be used in Qt (e.g. in the filedialog) together with the QUrlOperator.
The easiest way to implement a new network protocol is, to reimplement the operation[something]( QNetworkOperation * ) methods. Of course only the ones, which are supported, should be reimplemented. To specify which operations are supported, also reimplement supportedOperations() and return an int there, which is ore'd together using the supported operations from the QNetworkProtocol::Operation enum.
When you implement a network protocol this way, be careful that you always emit the correct signals. Also, always emit the finished() signal when an operation is done (on failure or success!). The Qt Network Architecture relies on correctly emitted finished() signals.
For a detailed description about the Qt Network Architecture, and also how to implement and use network protocols in Qt, look at the Qt Network Documentation
ConHostFound
- Host has been found
ConConnected
- Connection to the host has been established
ConClosed
- connection has been closed
NoError
- No error occurred
ErrValid
- The URL you are operating on is not valid
ErrUnknownProtocol
- There is no protocol implementation available for the protocol of the URL you are operating on (e.g. if the protocol is http and no http implementation has been registered)
ErrUnsupported
- The operation is not supported by the protocol
ErrParse
- Parse error of the URL
ErrLoginIncorrect
- You needed to login but the username and or password are wrong
ErrHostNotFound
- The specified host (in the URL) couldn´t be found
ErrListChlidren
- An error occurred while listing the children
ErrMkdir
- An error occurred when creating a directory
ErrRemove
- An error occurred while removing a child
ErrRename
- An error occurred while renaming a child
ErrGet
- An error occurred while getting (retrieving) data
ErrPut
- An error occurred while putting (uploading) data
ErrFileNotExisting
- A file which is needed by the operation doesn't exist
ErrPermissionDenied
- The permission for doing the operation has been denied
When implementing custom network protocols, you should also use these values of error codes. If this is not possible, you can define your own ones by using an integer value which doesn't conflict with one of these vales.
OpListChildren
- Listing the children of a URL, e.g. of a directory
OpMkdir
- Create a directory
OpRemove
- remove a child (e.g. file)
OpRename
- rename a child (e.g. file )
OpGet
- get data from a location
OpPut
- put data to a location
StWaiting
- The operation is in the queue of the QNetworkProtocol
and is waiting for being prcessed
StInProgress
- The operation is just processed
StDone
- The operation has been processed succesfully
StFailed
- The operation has been processed but an error occurred
StStopped
- The operation has been processed but has been stopped before it finished
Constructor of the network protocol baseclass. Does some initialization and connecting of signals and slots.
[virtual]
Destructor.
[virtual]
Adds the operation op the operation queue. The operation will be processed as soon as possible. This method returns immediately.
Returns TRUE, of autodeleting is enabled, else FALSE.
See also QNetworkProtocol::setAutoDelete().
[virtual protected]
For processing operations the newtork protocol baseclass calls this method quite often. This should be reimplemented by new network protocols. It should return TRUE, if the connection is ok (open), else FALSE. If the connection is not open, the protocol should open it.
If the connection can't be opened (e.g. because you already tried it, but the host couldn't be found or something like that), set the state of op to QNetworkProtocol::StFailed and emit the finished() signal with this QNetworkOperation as argument.
op is the operation which needs an open connection.
Reimplemented in QFtp.
[virtual]
Clears the operation queue.
[signal]
This signal is emitted whenever the state of the connection of the network protocol is changed. state describes the new state, which is one of ConHostFound, ConConnected, ConClosed data is a message text.
[signal]
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.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
[signal]
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.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
[signal]
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.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
[signal]
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.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
[static]
Static method to get a new instance of a network protocol. E.g. if you need to do some FTP operations, do
QFtp *ftp = QNetworkProtocol::getNetworkProtocol( "ftp" );
This returns now either NULL, if no protocol for ftp was registered, or a pointer to a new instance of an FTP implementation. The ownership of the pointer is transferred to you, so you have to delete it, if you don´t need it anymore.
Normally you should not work directly with network protocols, so you will not need to call this method yourself. Rather use the QUrlOperator, which makes working with network protocols much more convenient.
See also QUrlOperator.
[static]
Returns TRUE, if only a protocol for working on the local filesystem is registered, or FALSE if also other network protocols are registered.
[signal]
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.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
[signal]
This signal is emitted if a new child has been read. QNetworkProtocol automatically connects that to a slot which creates a list of QUrlInfo objects (with just the one QUrlInfo i) and emits then newChildren() signal with this created list.
So this is just a convenience signal when implementing an own network protocol. In all other cases just care about the newChildren() signal with the list of QUrlInfo objects.
[signal]
This signal is emitted after listChildren() was called and new children (e.g. files) have been read from 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.
When a protocol emits this signal, QNetworkProtocol is smart enough to let the QUrlOperator, which is used by the network protocol, emit its corresponding signal.
When implementing an own network protocol and reading children in most cases you don't read one child at once, but a list of them. That's why this signal takes a list of QUrlInfo objects. But if you read only one child at once, you can use the convenience signal newChild(), which takes only a single QUrlInfo object.
[virtual protected]
When implemeting a new newtork protocol this method should be reimplemented, if the protocol supports getting data, and process this QNetworkOperation.
When you reimplement this method, it's very important that you emit the correct signals at the correct time (esp. the finished() signal after processing an operation). So have a look at the Qt Network Documentation, there it is described in detail how to reimplement this method. Also you may look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
Returns the operation, which is just processed, or NULL of none is processed at the moment.
[virtual protected]
When implemeting a new newtork protocol this method should be reimplemented, if the protocol supports listing children, and this method should then process this QNetworkOperation.
When you reimplement this method, it's very important that you emit the correct signals at the correct time (esp. the finished() signal after processing an operation). So have a look at the Qt Network Documentation, there it is described in detail how to reimplement this method. Also you may look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
[virtual protected]
When implemeting a new newtork protocol this method should be reimplemented, if the protocol supports making directories, and this method should then process this QNetworkOperation.
When you reimplement this method, it's very important that you emit the correct signals at the correct time (esp. the finished() signal after processing an operation). So have a look at the Qt Network Documentation, there it is described in detail how to reimplement this method. Also you may look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
[virtual protected]
When implemeting a new newtork protocol this method should be reimplemented, if the protocol supports putting data, and this method should then process this QNetworkOperation.
When you reimplement this method, it's very important that you emit the correct signals at the correct time (esp. the finished() signal after processing an operation). So have a look at the Qt Network Documentation, there it is described in detail how to reimplement this method. Also you may look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
[virtual protected]
When implemeting a new newtork protocol this method should be reimplemented, if the protocol supports removing children, and this method should then process this QNetworkOperation.
When you reimplement this method, it's very important that you emit the correct signals at the correct time (esp. the finished() signal after processing an operation). So have a look at the Qt Network Documentation, there it is described in detail how to reimplement this method. Also you may look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
[virtual protected]
When implemeting a new newtork protocol this method should be reimplemented, if the protocol supports renaming children, and this method should then process this QNetworkOperation.
When you reimplement this method, it's very important that you emit the correct signals at the correct time (esp. the finished() signal after processing an operation). So have a look at the Qt Network Documentation, there it is described in detail how to reimplement this method. Also you may look at the example implementation of qt/extenstions/network/examples/networkprotocol/nntp.cpp.
[static]
Static method to register a network protocol for Qt. E.g. if you have a implementation of NNTP (called Nntp), which is derived from QNetworkProtocol, call
QNetworkProtocol::registerNetworkProtocol( "nntp", new QNetworkProtocolFactory After that, this implementation is registered for nntp operations.
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.
When a protocol emits this signal, QNetworkProtocol is smart enough
to let the QUrlOperator, which is used by the network protocol, emit
its corresponding signal.
Because it's sometimes hard to care about removing network protocol
instances, QNetworkProtocol provides an autodelete mechanism. If
you set b to TRUE, this network protocol instance gets removed
after it has been i milliseconds inactive (this means i ms after
the last operation has been processed).
If you set b to FALSE, the autodelete mechanism is switched off.
NOTE: If you switch on autodeleting, the QNetworkProtocol also
deletes its QUrlOperator!.
Sets the QUrlOperator, on which the protocol works.
See also QUrlOperator.
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.
When a protocol emits this signal, QNetworkProtocol is smart enough
to let the QUrlOperator, which is used by the network protocol, emit
its corresponding signal.
Stops the current operation which is just processed and clears
all waiting operations.
Returns an int, which is or'd together using the enum values
of Returns the QUrlOperator on which the protocol works.
For internal use only.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit,
copyright © 1995-2000
Trolltech, all rights reserved.void QNetworkProtocol::removed ( QNetworkOperation * op )
[signal]
void QNetworkProtocol::setAutoDelete ( bool b, int i = 10000 )
[virtual]
void QNetworkProtocol::setUrl ( QUrlOperator * u )
[virtual]
void QNetworkProtocol::start ( QNetworkOperation * op )
[signal]
void QNetworkProtocol::stop ()
[virtual]
int QNetworkProtocol::supportedOperations () const
[virtual]
QNetworkProtocol::Operation,
which describes which operations
are supported by the network protocol. Should be reimplemented by new
network protocols.
QUrlOperator * QNetworkProtocol::url () const
void QNetworkProtocol::processOperation ( QNetworkOperation * op )
[virtual protected]
Copyright © 2000 Trolltech Trademarks