You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/man/man3/tqnetworkprotocol.3qt

387 lines
24 KiB

'\" t
.TH QNetworkProtocol 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QNetworkProtocol \- Common API for network protocols
.SH SYNOPSIS
\fC#include <ntqnetworkprotocol.h>\fR
.PP
Inherits TQObject.
.PP
Inherited by QFtp, QHttp, and QLocalFs.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "enum \fBState\fR { StWaiting = 0, StInProgress, StDone, StFailed, StStopped }"
.br
.ti -1c
.BI "enum \fBOperation\fR { OpListChildren = 1, OpMkDir = 2, OpMkdir = OpMkDir, OpRemove = 4, OpRename = 8, OpGet = 32, OpPut = 64 }"
.br
.ti -1c
.BI "enum \fBConnectionState\fR { ConHostFound, ConConnected, ConClosed }"
.br
.ti -1c
.BI "enum \fBError\fR { NoError = 0, ErrValid, ErrUnknownProtocol, ErrUnsupported, ErrParse, ErrLoginIncorrect, ErrHostNotFound, ErrListChildren, ErrListChlidren = ErrListChildren, ErrMkDir, ErrMkdir = ErrMkDir, ErrRemove, ErrRename, ErrGet, ErrPut, ErrFileNotExisting, ErrPermissionDenied }"
.br
.ti -1c
.BI "\fBQNetworkProtocol\fR ()"
.br
.ti -1c
.BI "virtual \fB~QNetworkProtocol\fR ()"
.br
.ti -1c
.BI "virtual void \fBsetUrl\fR ( QUrlOperator * u )"
.br
.ti -1c
.BI "virtual void \fBsetAutoDelete\fR ( bool b, int i = 10000 )"
.br
.ti -1c
.BI "bool \fBautoDelete\fR () const"
.br
.ti -1c
.BI "virtual int \fBsupportedOperations\fR () const"
.br
.ti -1c
.BI "virtual void \fBaddOperation\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "QUrlOperator * \fBurl\fR () const"
.br
.ti -1c
.BI "QNetworkOperation * \fBoperationInProgress\fR () const"
.br
.ti -1c
.BI "virtual void \fBclearOperationQueue\fR ()"
.br
.ti -1c
.BI "virtual void \fBstop\fR ()"
.br
.in -1c
.SS "Signals"
.in +1c
.ti -1c
.BI "void \fBdata\fR ( const QByteArray & data, QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBconnectionStateChanged\fR ( int state, const TQString & data )"
.br
.ti -1c
.BI "void \fBfinished\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBstart\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBnewChildren\fR ( const QValueList<QUrlInfo> & i, QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBnewChild\fR ( const QUrlInfo & i, QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBcreatedDirectory\fR ( const QUrlInfo & i, QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBremoved\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBitemChanged\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "void \fBdataTransferProgress\fR ( int bytesDone, int bytesTotal, QNetworkOperation * op )"
.br
.in -1c
.SS "Static Public Members"
.in +1c
.ti -1c
.BI "void \fBregisterNetworkProtocol\fR ( const TQString & protocol, QNetworkProtocolFactoryBase * protocolFactory )"
.br
.ti -1c
.BI "QNetworkProtocol * \fBgetNetworkProtocol\fR ( const TQString & protocol )"
.br
.ti -1c
.BI "bool \fBhasOnlyLocalFileSystem\fR ()"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual void \fBoperationListChildren\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "virtual void \fBoperationMkDir\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "virtual void \fBoperationRemove\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "virtual void \fBoperationRename\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "virtual void \fBoperationGet\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "virtual void \fBoperationPut\fR ( QNetworkOperation * op )"
.br
.ti -1c
.BI "virtual bool \fBcheckConnection\fR ( QNetworkOperation * op )"
.br
.in -1c
.SH DESCRIPTION
The QNetworkProtocol class provides a common API for network protocols.
.PP
This is a base class which should be used for network protocols implementations that can then be used in TQt (e.g. in the file dialog) together with the QUrlOperator.
.PP
The easiest way to implement a new network protocol is to reimplement the operation*() methods, e.g. operationGet(), etc. Only the supported operations should be reimplemented. To specify which operations are supported, also reimplement supportedOperations() and return an int that is OR'd together using the supported operations from the QNetworkProtocol::Operation enum.
.PP
When you implement a network protocol this way, it is important to emit the correct signals. Also, always emit the finished() signal when an operation is done (on success \fIand\fR on failure). TQt relies on correctly emitted finished() signals.
.PP
For a detailed description of the TQt Network Architecture and how to implement and use network protocols in Qt, see the TQt Network Documentation.
.PP
See also Input/Output and Networking.
.SS "Member Type Documentation"
.SH "QNetworkProtocol::ConnectionState"
When the connection state of a network protocol changes it emits the signal connectionStateChanged(). The first argument is one of the following values:
.TP
\fCQNetworkProtocol::ConHostFound\fR - Host has been found.
.TP
\fCQNetworkProtocol::ConConnected\fR - Connection to the host has been established.
.TP
\fCQNetworkProtocol::ConClosed\fR - Connection has been closed.
.SH "QNetworkProtocol::Error"
When an operation fails (finishes unsuccessfully), the QNetworkOperation of the operation returns an error code which has one of the following values:
.TP
\fCQNetworkProtocol::NoError\fR - No error occurred.
.TP
\fCQNetworkProtocol::ErrValid\fR - The URL you are operating on is not valid.
.TP
\fCQNetworkProtocol::ErrUnknownProtocol\fR - 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).
.TP
\fCQNetworkProtocol::ErrUnsupported\fR - The operation is not supported by the protocol.
.TP
\fCQNetworkProtocol::ErrParse\fR - The URL could not be parsed correctly.
.TP
\fCQNetworkProtocol::ErrLoginIncorrect\fR - You needed to login but the username or password is wrong.
.TP
\fCQNetworkProtocol::ErrHostNotFound\fR - The specified host (in the URL) couldn't be found.
.TP
\fCQNetworkProtocol::ErrListChildren\fR - An error occurred while listing the children (files).
.TP
\fCQNetworkProtocol::ErrMkDir\fR - An error occurred when creating a directory.
.TP
\fCQNetworkProtocol::ErrRemove\fR - An error occurred when removing a child (file).
.TP
\fCQNetworkProtocol::ErrRename\fR - An error occurred when renaming a child (file).
.TP
\fCQNetworkProtocol::ErrGet\fR - An error occurred while getting (retrieving) data.
.TP
\fCQNetworkProtocol::ErrPut\fR - An error occurred while putting (uploading) data.
.TP
\fCQNetworkProtocol::ErrFileNotExisting\fR - A file which is needed by the operation doesn't exist.
.TP
\fCQNetworkProtocol::ErrPermissionDenied\fR - Permission for doing the operation has been denied.
.PP
You should also use these error codes when implementing custom network protocols. If this is not possible, you can define your own error codes by using integer values that don't conflict with any of these values.
.SH "QNetworkProtocol::Operation"
This enum lists the possible operations that a network protocol can support. supportedOperations() returns an int of these that is OR'd together. Also, the type() of a QNetworkOperation is always one of these values.
.TP
\fCQNetworkProtocol::OpListChildren\fR - List the children of a URL, e.g. of a directory.
.TP
\fCQNetworkProtocol::OpMkDir\fR - Create a directory.
.TP
\fCQNetworkProtocol::OpRemove\fR - Remove a child (e.g. a file).
.TP
\fCQNetworkProtocol::OpRename\fR - Rename a child (e.g. a file).
.TP
\fCQNetworkProtocol::OpGet\fR - Get data from a location.
.TP
\fCQNetworkProtocol::OpPut\fR - Put data to a location.
.SH "QNetworkProtocol::State"
This enum contains the state that a QNetworkOperation can have.
.TP
\fCQNetworkProtocol::StWaiting\fR - The operation is in the QNetworkProtocol's queue waiting to be prcessed.
.TP
\fCQNetworkProtocol::StInProgress\fR - The operation is being processed.
.TP
\fCQNetworkProtocol::StDone\fR - The operation has been processed succesfully.
.TP
\fCQNetworkProtocol::StFailed\fR - The operation has been processed but an error occurred.
.TP
\fCQNetworkProtocol::StStopped\fR - The operation has been processed but has been stopped before it finished, and is waiting to be processed.
.PP
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QNetworkProtocol::QNetworkProtocol ()"
Constructor of the network protocol base class. Does some initialization and connecting of signals and slots.
.SH "QNetworkProtocol::~QNetworkProtocol ()\fC [virtual]\fR"
Destructor.
.SH "void QNetworkProtocol::addOperation ( QNetworkOperation * op )\fC [virtual]\fR"
Adds the operation \fIop\fR to the operation queue. The operation will be processed as soon as possible. This method returns immediately.
.SH "bool QNetworkProtocol::autoDelete () const"
Returns TRUE if auto-deleting is enabled; otherwise returns FALSE.
.PP
See also QNetworkProtocol::setAutoDelete().
.SH "bool QNetworkProtocol::checkConnection ( QNetworkOperation * op )\fC [virtual protected]\fR"
For processing operations the network protocol base class calls this method quite often. This should be reimplemented by new network protocols. It should return TRUE if the connection is OK (open); otherwise it should return FALSE. If the connection is not open the protocol should open it.
.PP
If the connection can't be opened (e.g. because you already tried but the host couldn't be found), set the state of \fIop\fR to QNetworkProtocol::StFailed and emit the finished() signal with this QNetworkOperation as argument.
.PP
\fIop\fR is the operation that needs an open connection.
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "void QNetworkProtocol::clearOperationQueue ()\fC [virtual]\fR"
Clears the operation queue.
.SH "void QNetworkProtocol::connectionStateChanged ( int state, const TQString & data )\fC [signal]\fR"
This signal is emitted whenever the state of the connection of the network protocol is changed. \fIstate\fR describes the new state, which is one of, ConHostFound, ConConnected or ConClosed. \fIdata\fR is a message text.
.SH "void QNetworkProtocol::createdDirectory ( const QUrlInfo & i, QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted when mkdir() has been succesful and the directory has been created. \fIi\fR holds the information about the new directory. \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc. Using op->arg( 0 ), you can get the file name of the new directory.
.PP
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.
.SH "void QNetworkProtocol::data ( const QByteArray & data, QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted when new \fIdata\fR has been received after calling get() or put(). \fIop\fR holds the name of the file from which data is retrieved or uploaded in its first argument, and the (raw) data in its second argument. You can get them with op->arg( 0 ) and op->rawArg( 1 ). \fIop\fR is the pointer to the operation object, which contains all the information about the operation, including the state, etc.
.PP
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.
.SH "void QNetworkProtocol::dataTransferProgress ( int bytesDone, int bytesTotal, QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted during the transfer of data (using put() or get()). \fIbytesDone\fR is how many bytes of \fIbytesTotal\fR have been transferred. \fIbytesTotal\fR may be -1, which means that the total number of bytes is not known. \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc.
.PP
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.
.SH "void QNetworkProtocol::finished ( QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted when an operation finishes. This signal is always emitted, for both success and failure. \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc. Check the state and error code of the operation object to determine whether or not the operation was successful.
.PP
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.
.SH "QNetworkProtocol * QNetworkProtocol::getNetworkProtocol ( const TQString & protocol )\fC [static]\fR"
Static method to get a new instance of the network protocol \fIprotocol\fR. For example, if you need to do some FTP operations, do the following:
.PP
.nf
.br
QFtp *ftp = QNetworkProtocol::getNetworkProtocol( "ftp" );
.br
.fi
This returns a pointer to a new instance of an ftp implementation or null if no protocol for ftp was registered. The ownership of the pointer is transferred to you, so you must delete it if you don't need it anymore.
.PP
Normally you should not work directly with network protocols, so you will not need to call this method yourself. Instead, use QUrlOperator, which makes working with network protocols much more convenient.
.PP
See also QUrlOperator.
.SH "bool QNetworkProtocol::hasOnlyLocalFileSystem ()\fC [static]\fR"
Returns TRUE if the only protocol registered is for working on the local filesystem; returns FALSE if other network protocols are also registered.
.SH "void QNetworkProtocol::itemChanged ( QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted whenever a file which is a child of this URL has been changed, e.g. by successfully calling rename(). \fIop\fR holds the original and the new file names in the first and second arguments, accessible with op->arg( 0 ) and op->arg( 1 ) respectively. \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc.
.PP
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.
.SH "void QNetworkProtocol::newChild ( const QUrlInfo & i, QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted if a new child (file) has been read. QNetworkProtocol automatically connects it to a slot which creates a list of QUrlInfo objects (with just one QUrlInfo \fIi\fR) and emits the newChildren() signal with this list. \fIop\fR is the pointer to the operation object which contains all the information about the operation that has finished, including the state, etc.
.PP
This is just a convenience signal useful for implementing your own network protocol. In all other cases connect to the newChildren() signal with its list of QUrlInfo objects.
.SH "void QNetworkProtocol::newChildren ( const QValueList<QUrlInfo> & i, QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted after listChildren() was called and new children (files) have been read from the list of files. \fIi\fR holds the information about the new children. \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc.
.PP
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.
.PP
When implementing your own network protocol and reading children, you usually don't read one child at once, but rather a list of them. That's why this signal takes a list of QUrlInfo objects. If you prefer to read just one child at a time you can use the convenience signal newChild(), which takes a single QUrlInfo object.
.SH "void QNetworkProtocol::operationGet ( QNetworkOperation * op )\fC [virtual protected]\fR"
When implementing a new network protocol, this method should be reimplemented if the protocol supports getting data; this method should then process the QNetworkOperation.
.PP
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the TQt Network Documentation which describes in detail how to reimplement this method. You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
.PP
\fIop\fR is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "QNetworkOperation * QNetworkProtocol::operationInProgress () const"
Returns the operation, which is being processed, or 0 of no operation is being processed at the moment.
.SH "void QNetworkProtocol::operationListChildren ( QNetworkOperation * op )\fC [virtual protected]\fR"
When implementing a new network protocol, this method should be reimplemented if the protocol supports listing children (files); this method should then process this QNetworkOperation.
.PP
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the TQt Network Documentation which describes in detail how to reimplement this method. You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
.PP
\fIop\fR is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "void QNetworkProtocol::operationMkDir ( QNetworkOperation * op )\fC [virtual protected]\fR"
When implementing a new network protocol, this method should be reimplemented if the protocol supports making directories; this method should then process this QNetworkOperation.
.PP
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the TQt Network Documentation which describes in detail how to reimplement this method. You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
.PP
\fIop\fR is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.
.SH "void QNetworkProtocol::operationPut ( QNetworkOperation * op )\fC [virtual protected]\fR"
When implementing a new network protocol, this method should be reimplemented if the protocol supports putting (uploading) data; this method should then process the QNetworkOperation.
.PP
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the TQt Network Documentation which describes in detail how to reimplement this method. You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
.PP
\fIop\fR is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.
.SH "void QNetworkProtocol::operationRemove ( QNetworkOperation * op )\fC [virtual protected]\fR"
When implementing a new network protocol, this method should be reimplemented if the protocol supports removing children (files); this method should then process this QNetworkOperation.
.PP
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the TQt Network Documentation which is describes in detail how to reimplement this method. You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
.PP
\fIop\fR is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.
.SH "void QNetworkProtocol::operationRename ( QNetworkOperation * op )\fC [virtual protected]\fR"
When implementing a new newtork protocol, this method should be reimplemented if the protocol supports renaming children (files); this method should then process this QNetworkOperation.
.PP
When you reimplement this method it's very important that you emit the correct signals at the correct time (especially the finished() signal after processing an operation). Take a look at the TQt Network Documentation which describes in detail how to reimplement this method. You may also want to look at the example implementation in examples/network/networkprotocol/nntp.cpp.
.PP
\fIop\fR is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.
.SH "void QNetworkProtocol::registerNetworkProtocol ( const TQString & protocol, QNetworkProtocolFactoryBase * protocolFactory )\fC [static]\fR"
Static method to register a network protocol for Qt. For example, if you have an implementation of NNTP (called Nntp) which is derived from QNetworkProtocol, call:
.PP
.nf
.br
QNetworkProtocol::registerNetworkProtocol( "nntp", new QNetworkProtocolFactory<Nntp> );
.br
.fi
after which your implementation is registered for future nntp operations.
.PP
The name of the protocol is given in \fIprotocol\fR and a pointer to the protocol factory is given in \fIprotocolFactory\fR.
.SH "void QNetworkProtocol::removed ( QNetworkOperation * op )\fC [signal]\fR"
This signal is emitted when remove() has been succesful and the file has been removed. \fIop\fR holds the file name of the removed file in the first argument, accessible with op->arg( 0 ). \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc.
.PP
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.
.SH "void QNetworkProtocol::setAutoDelete ( bool b, int i = 10000 )\fC [virtual]\fR"
Because it's sometimes hard to take care of removing network protocol instances, QNetworkProtocol provides an auto-delete mechanism. If you set \fIb\fR to TRUE, the network protocol instance is removed after it has been inactive for \fIi\fR milliseconds (i.e. \fIi\fR milliseconds after the last operation has been processed). If you set \fIb\fR to FALSE the auto-delete mechanism is switched off.
.PP
If you switch on auto-delete, the QNetworkProtocol also deletes its QUrlOperator.
.SH "void QNetworkProtocol::setUrl ( QUrlOperator * u )\fC [virtual]\fR"
Sets the QUrlOperator, on which the protocol works, to \fIu\fR.
.PP
See also QUrlOperator.
.SH "void QNetworkProtocol::start ( QNetworkOperation * op )\fC [signal]\fR"
Some operations (such as listChildren()) emit this signal when they start processing the operation. \fIop\fR is the pointer to the operation object which contains all the information about the operation, including the state, etc.
.PP
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.
.SH "void QNetworkProtocol::stop ()\fC [virtual]\fR"
Stops the current operation that is being processed and clears all waiting operations.
.SH "int QNetworkProtocol::supportedOperations () const\fC [virtual]\fR"
Returns an int that is OR'd together using the enum values of QNetworkProtocol::Operation, which describes which operations are supported by the network protocol. Should be reimplemented by new network protocols.
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "QUrlOperator * QNetworkProtocol::url () const"
Returns the QUrlOperator on which the protocol works.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqnetworkprotocol.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqnetworkprotocol.3qt) and the Qt
version (3.3.8).