Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

  • Qt 4.8
  • Qt3SupportLight
  • Q3NetworkProtocol

Q3NetworkProtocol Class

TheQ3NetworkProtocol class provides a common API for network protocols.More...

Header:#include <Q3NetworkProtocol>
Inherits:QObject
Inherited By:

Q3Ftp,Q3Http, andQ3LocalFs

Public Types

enumConnectionState { ConHostFound, ConConnected, ConClosed }
enumError { NoError, ErrValid, ErrUnknownProtocol, ErrUnsupported, ..., ErrPermissionDenied }
enumOperation { OpListChildren, OpMkDir, OpRemove, OpRename, OpGet, OpPut }
enumState { StWaiting, StInProgress, StDone, StFailed, StStopped }

Public Functions

Q3NetworkProtocol()
virtual~Q3NetworkProtocol()
virtual voidaddOperation(Q3NetworkOperation * op)
boolautoDelete() const
virtual voidclearOperationQueue()
Q3NetworkOperation *operationInProgress() const
virtual voidsetAutoDelete(bool b, int i = 10000)
virtual voidsetUrl(Q3UrlOperator * u)
virtual voidstop()
virtual intsupportedOperations() const
Q3UrlOperator *url() const
  • 29 public functions inherited fromQObject

Signals

voidconnectionStateChanged(int state, const QString & data)
voidcreatedDirectory(const QUrlInfo & i, Q3NetworkOperation * op)
voiddata(const QByteArray & data, Q3NetworkOperation * op)
voiddataTransferProgress(int bytesDone, int bytesTotal, Q3NetworkOperation * op)
voidfinished(Q3NetworkOperation * op)
voiditemChanged(Q3NetworkOperation * op)
voidnewChild(const QUrlInfo & i, Q3NetworkOperation * op)
voidnewChildren(const Q3ValueList<QUrlInfo> & i, Q3NetworkOperation * op)
voidremoved(Q3NetworkOperation * op)
voidstart(Q3NetworkOperation * op)

Static Public Members

Q3NetworkProtocol *getNetworkProtocol(const QString & protocol)
boolhasOnlyLocalFileSystem()
voidregisterNetworkProtocol(const QString & protocol, Q3NetworkProtocolFactoryBase * protocolFactory)
  • 7 static public members inherited fromQObject

Protected Functions

virtual boolcheckConnection(Q3NetworkOperation * op)
virtual voidoperationGet(Q3NetworkOperation * op)
virtual voidoperationListChildren(Q3NetworkOperation * op)
virtual voidoperationMkDir(Q3NetworkOperation * op)
virtual voidoperationPut(Q3NetworkOperation * op)
virtual voidoperationRemove(Q3NetworkOperation * op)
virtual voidoperationRename(Q3NetworkOperation * op)
  • 8 protected functions inherited fromQObject

Additional Inherited Members

Detailed Description

TheQ3NetworkProtocol class provides a common API for network protocols.

This is a base class which should be used for network protocols implementations that can then be used in Qt (e.g. in the file dialog) together with the Q3UrlOperator.

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 reimplementsupportedOperations() and return an int that is OR'd together using the supported operations from theQ3NetworkProtocol::Operation enum.

When you implement a network protocol this way, it is important to emit the correct signals. Also, always emit thefinished() signal when an operation is done (on successand on failure). Qt relies on correctly emittedfinished() signals.

Member Type Documentation

enum Q3NetworkProtocol::ConnectionState

When the connection state of a network protocol changes it emits the signalconnectionStateChanged(). The first argument is one of the following values:

ConstantValueDescription
Q3NetworkProtocol::ConHostFound0Host has been found.
Q3NetworkProtocol::ConConnected1Connection to the host has been established.
Q3NetworkProtocol::ConClosed2Connection has been closed.

enum Q3NetworkProtocol::Error

When an operation fails (finishes unsuccessfully), theQ3NetworkOperation of the operation returns an error code which has one of the following values:

ConstantValueDescription
Q3NetworkProtocol::NoError0No error occurred.
Q3NetworkProtocol::ErrValid1The URL you are operating on is not valid.
Q3NetworkProtocol::ErrUnknownProtocol2There 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).
Q3NetworkProtocol::ErrUnsupported3The operation is not supported by the protocol.
Q3NetworkProtocol::ErrParse4The URL could not be parsed correctly.
Q3NetworkProtocol::ErrLoginIncorrect5You needed to login but the username or password is wrong.
Q3NetworkProtocol::ErrHostNotFound6The specified host (in the URL) couldn't be found.
Q3NetworkProtocol::ErrListChildren7An error occurred while listing the children (files).
Q3NetworkProtocol::ErrMkDir?An error occurred when creating a directory.
Q3NetworkProtocol::ErrRemove?An error occurred when removing a child (file).
Q3NetworkProtocol::ErrRename?An error occurred when renaming a child (file).
Q3NetworkProtocol::ErrGet?An error occurred while getting (retrieving) data.
Q3NetworkProtocol::ErrPut?An error occurred while putting (uploading) data.
Q3NetworkProtocol::ErrFileNotExisting?A file which is needed by the operation doesn't exist.
Q3NetworkProtocol::ErrPermissionDenied?Permission for doing the operation has been denied.

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.

enum Q3NetworkProtocol::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 aQ3NetworkOperation is always one of these values.

ConstantValueDescription
Q3NetworkProtocol::OpListChildren1List the children of a URL, e.g. of a directory.
Q3NetworkProtocol::OpMkDir2Create a directory.
Q3NetworkProtocol::OpRemove4Remove a child (e.g. a file).
Q3NetworkProtocol::OpRename8Rename a child (e.g. a file).
Q3NetworkProtocol::OpGet32Get data from a location.
Q3NetworkProtocol::OpPut64Put data to a location.

enum Q3NetworkProtocol::State

This enum contains the state that aQ3NetworkOperation can have.

ConstantValueDescription
Q3NetworkProtocol::StWaiting0The operation is in theQ3NetworkProtocol's queue waiting to be prcessed.
Q3NetworkProtocol::StInProgress1The operation is being processed.
Q3NetworkProtocol::StDone2The operation has been processed successfully.
Q3NetworkProtocol::StFailed3The operation has been processed but an error occurred.
Q3NetworkProtocol::StStopped4The operation has been processed but has been stopped before it finished, and is waiting to be processed.

Member Function Documentation

Q3NetworkProtocol::Q3NetworkProtocol()

Constructor of the network protocol base class. Does some initialization and connecting of signals and slots.

[virtual]Q3NetworkProtocol::~Q3NetworkProtocol()

Destructor.

[virtual]void Q3NetworkProtocol::addOperation(Q3NetworkOperation * op)

Adds the operationop to the operation queue. The operation will be processed as soon as possible. This method returns immediately.

bool Q3NetworkProtocol::autoDelete() const

Returns true if auto-deleting is enabled; otherwise returns false.

See alsoQ3NetworkProtocol::setAutoDelete().

[virtual protected]bool Q3NetworkProtocol::checkConnection(Q3NetworkOperation * op)

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.

If the connection can't be opened (e.g. because you already tried but the host couldn't be found), set the state ofop toQ3NetworkProtocol::StFailed and emit thefinished() signal with thisQ3NetworkOperation as argument.

op is the operation that needs an open connection.

[virtual]void Q3NetworkProtocol::clearOperationQueue()

Clears the operation queue.

[signal]void Q3NetworkProtocol::connectionStateChanged(int state, constQString & data)

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 orConClosed.data is a message text.

[signal]void Q3NetworkProtocol::createdDirectory(constQUrlInfo & i,Q3NetworkOperation * op)

This signal is emitted when mkdir() has been successful 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 the information about the operation, including the state, etc. Using op->arg( 0 ), you can get the file name of the new directory.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

[signal]void Q3NetworkProtocol::data(constQByteArray & data,Q3NetworkOperation * op)

This signal is emitted when newdata has been received after calling get() or put().op 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 ).op is the pointer to the operation object, which contains all the information about the operation, including the state, etc.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator (which is used by the network protocol) emit its corresponding signal.

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

This signal is emitted during the transfer of data (using put() or get()).bytesDone is how many bytes ofbytesTotal have been transferred.bytesTotal may be -1, which means that the total number of bytes is not known.op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

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

This signal is emitted when an operation finishes. This signal is always emitted, for both success and failure.op 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.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

[static]Q3NetworkProtocol * Q3NetworkProtocol::getNetworkProtocol(constQString & protocol)

Static method to get a new instance of the network protocolprotocol. For example, if you need to do some FTP operations, do the following:

Q3Ftp*ftp=Q3NetworkProtocol::getNetworkProtocol("ftp" );

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.

Normally you should not work directly with network protocols, so you will not need to call this method yourself. Instead, use Q3UrlOperator, which makes working with network protocols much more convenient.

See alsoQ3UrlOperator.

[static]bool Q3NetworkProtocol::hasOnlyLocalFileSystem()

Returns true if the only protocol registered is for working on the local filesystem; returns false if other network protocols are also registered.

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

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 file names in the first and second arguments, accessible with op->arg( 0 ) and op->arg( 1 ) respectively.op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

[signal]void Q3NetworkProtocol::newChild(constQUrlInfo & i,Q3NetworkOperation * op)

This signal is emitted if a new child (file) has been read.Q3NetworkProtocol automatically connects it to a slot which creates a list ofQUrlInfo objects (with just oneQUrlInfoi) and emits thenewChildren() signal with this list.op is the pointer to the operation object which contains all the information about the operation that has finished, including the state, etc.

This is just a convenience signal useful for implementing your own network protocol. In all other cases connect to thenewChildren() signal with its list ofQUrlInfo objects.

[signal]void Q3NetworkProtocol::newChildren(constQ3ValueList<QUrlInfo> & i,Q3NetworkOperation * op)

This signal is emitted after listChildren() was called and new children (files) have been read from the list of files.i holds the information about the new children.op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

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 ofQUrlInfo objects. If you prefer to read just one child at a time you can use the convenience signalnewChild(), which takes a singleQUrlInfo object.

[virtual protected]void Q3NetworkProtocol::operationGet(Q3NetworkOperation * op)

When implementing a new network protocol, this method should be reimplemented if the protocol supports getting data; this method should then process theQ3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

Q3NetworkOperation * Q3NetworkProtocol::operationInProgress() const

Returns the operation, which is being processed, or 0 of no operation is being processed at the moment.

[virtual protected]void Q3NetworkProtocol::operationListChildren(Q3NetworkOperation * op)

When implementing a new network protocol, this method should be reimplemented if the protocol supports listing children (files); this method should then process thisQ3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

[virtual protected]void Q3NetworkProtocol::operationMkDir(Q3NetworkOperation * op)

When implementing a new network protocol, this method should be reimplemented if the protocol supports making directories; this method should then process thisQ3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

[virtual protected]void Q3NetworkProtocol::operationPut(Q3NetworkOperation * op)

When implementing a new network protocol, this method should be reimplemented if the protocol supports putting (uploading) data; this method should then process theQ3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

[virtual protected]void Q3NetworkProtocol::operationRemove(Q3NetworkOperation * op)

When implementing a new network protocol, this method should be reimplemented if the protocol supports removing children (files); this method should then process thisQ3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

[virtual protected]void Q3NetworkProtocol::operationRename(Q3NetworkOperation * op)

When implementing a new network protocol, this method should be reimplemented if the protocol supports renaming children (files); this method should then process thisQ3NetworkOperation.

op is the pointer to the operation object which contains all the information on the operation that has finished, including the state, etc.

[static]void Q3NetworkProtocol::registerNetworkProtocol(constQString & protocol,Q3NetworkProtocolFactoryBase * protocolFactory)

Static method to register a network protocol for Qt. For example, if you have an implementation of NNTP (called Nntp) which is derived fromQ3NetworkProtocol, call:

Q3NetworkProtocol::registerNetworkProtocol("nntp",newQ3NetworkProtocolFactory<Nntp> );

after which your implementation is registered for future nntp operations.

The name of the protocol is given inprotocol and a pointer to the protocol factory is given inprotocolFactory.

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

This signal is emitted when remove() has been succesiisful and the file has been removed.op holds the file name of the removed file in the first argument, accessible with op->arg( 0 ).op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

[virtual]void Q3NetworkProtocol::setAutoDelete(bool b,int i = 10000)

Because it's sometimes hard to take care of removing network protocol instances,Q3NetworkProtocol provides an auto-delete mechanism. If you setb to true, the network protocol instance is removed after it has been inactive fori milliseconds (i.e.i milliseconds after the last operation has been processed). If you setb to false the auto-delete mechanism is switched off.

If you switch on auto-delete, theQ3NetworkProtocol also deletes its Q3UrlOperator.

See alsoautoDelete().

[virtual]void Q3NetworkProtocol::setUrl(Q3UrlOperator * u)

Sets the Q3UrlOperator, on which the protocol works, tou.

See alsourl() and Q3UrlOperator.

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

Some operations (such as listChildren()) emit this signal when they start processing the operation.op is the pointer to the operation object which contains all the information about the operation, including the state, etc.

When a protocol emits this signal,Q3NetworkProtocol is smart enough to let the Q3UrlOperator, which is used by the network protocol, emit its corresponding signal.

[virtual]void Q3NetworkProtocol::stop()

Stops the current operation that is being processed and clears all waiting operations.

[virtual]int Q3NetworkProtocol::supportedOperations() const

Returns an int that is OR'd together using the enum values ofQ3NetworkProtocol::Operation, which describes which operations are supported by the network protocol. Should be reimplemented by new network protocols.

Q3UrlOperator * Q3NetworkProtocol::url() const

Returns the Q3UrlOperator on which the protocol works.

See alsosetUrl().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp