Source Code (Use browser search to find items of interest.)
Class Index
qt'QNetworkProtocol (./qt-2.1.0/src/kernel/qnetworkprotocol.h:64)
class Q_EXPORT QNetworkProtocol : public QObject
{
Q_OBJECT
public:
enum State {
StWaiting = 0,
StInProgress,
StDone,
StFailed,
StStopped
};
enum Operation {
OpListChildren = 1,
OpMkdir = 2,
OpRemove = 4,
OpRename = 8,
OpGet = 32,
OpPut = 64
};
enum ConnectionState {
ConHostFound,
ConConnected,
ConClosed
};
enum Error {
// no error
NoError = 0,
// general errors
ErrValid,
ErrUnknownProtocol,
ErrUnsupported,
ErrParse,
// errors on connect
ErrLoginIncorrect,
ErrHostNotFound,
// protocol errors
ErrListChlidren,
ErrMkdir,
ErrRemove,
ErrRename,
ErrGet,
ErrPut,
ErrFileNotExisting,
ErrPermissionDenied
};
QNetworkProtocol();
virtual ~QNetworkProtocol();
virtual void setUrl( QUrlOperator *u );
virtual void setAutoDelete( bool b, int i = 10000 );
bool autoDelete() const;
static void registerNetworkProtocol( const QString &protocol,
QNetworkProtocolFactoryBase *protocolFactory );
static QNetworkProtocol *getNetworkProtocol( const QString &protocol );
static bool hasOnlyLocalFileSystem();
virtual int supportedOperations() const;
virtual void addOperation( QNetworkOperation *op );
QUrlOperator *url() const;
QNetworkOperation *operationInProgress() const;
virtual void clearOperationQueue();
virtual void stop();
signals:
void data( const QByteArray &, QNetworkOperation *res );
void connectionStateChanged( int state, const QString &data );
void finished( QNetworkOperation *res );
void start( QNetworkOperation *res );
void newChildren( const QValueList<QUrlInfo> &, QNetworkOperation *res );
void newChild( const QUrlInfo &, QNetworkOperation *res );
void createdDirectory( const QUrlInfo &, QNetworkOperation *res );
void removed( QNetworkOperation *res );
void itemChanged( QNetworkOperation *res );
void dataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation *res );
protected:
virtual void processOperation( QNetworkOperation *op );
virtual void operationListChildren( QNetworkOperation *op );
virtual void operationMkDir( QNetworkOperation *op );
virtual void operationRemove( QNetworkOperation *op );
virtual void operationRename( QNetworkOperation *op );
virtual void operationGet( QNetworkOperation *op );
virtual void operationPut( QNetworkOperation *op );
virtual bool checkConnection( QNetworkOperation *op );
private:
QNetworkProtocolPrivate *d;
private slots:
void processNextOperation( QNetworkOperation *old );
void startOps();
void emitNewChildren( const QUrlInfo &i, QNetworkOperation *op );
void removeMe();
};
qt'QNetworkProtocol::QNetworkProtocol() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:312)
QNetworkProtocol::QNetworkProtocol()
: QObject()
{
d = new QNetworkProtocolPrivate;
d->url = 0;
d->opInProgress = 0;
d->opStartTimer = new QTimer( this );
d->removeTimer = new QTimer( this );
d->operationQueue.setAutoDelete( FALSE );
d->autoDelete = FALSE;
d->removeInterval = 10000;
d->oldOps.setAutoDelete( FALSE );
connect( d->opStartTimer, SIGNAL( timeout() ),
this, SLOT( startOps() ) );
connect( d->removeTimer, SIGNAL( timeout() ),
this, SLOT( removeMe() ) );
if ( url() ) {
connect( this, SIGNAL( data( const QByteArray &, QNetworkOperation * ) ),
url(), SIGNAL( data( const QByteArray &, QNetworkOperation * ) ) );
connect( this, SIGNAL( finished( QNetworkOperation * ) ),
url(), SIGNAL( finished( QNetworkOperation * ) ) );
connect( this, SIGNAL( start( QNetworkOperation * ) ),
url(), SIGNAL( start( QNetworkOperation * ) ) );
connect( this, SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ),
url(), SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ) );
connect( this, SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ),
url(), SLOT( addEntry( const QValueList<QUrlInfo> & ) ) );
connect( this, SIGNAL( createdDirectory( const QUrlInfo &, QNetworkOperation * ) ),
url(), SIGNAL( createdDirectory( const QUrlInfo &, QNetworkOperation * ) ) );
connect( this, SIGNAL( removed( QNetworkOperation * ) ),
url(), SIGNAL( removed( QNetworkOperation * ) ) );
connect( this, SIGNAL( itemChanged( QNetworkOperation * ) ),
url(), SIGNAL( itemChanged( QNetworkOperation * ) ) );
connect( this, SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ),
url(), SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ) );
connect( this, SIGNAL( connectionStateChanged( int, const QString & ) ),
url(), SIGNAL( connectionStateChanged( int, const QString & ) ) );
}
connect( this, SIGNAL( finished( QNetworkOperation * ) ),
this, SLOT( processNextOperation( QNetworkOperation * ) ) );
connect( this, SIGNAL( newChild( const QUrlInfo &, QNetworkOperation * ) ),
this, SLOT( emitNewChildren( const QUrlInfo &, QNetworkOperation * ) ) );
}
/*!
Destructor.
*/
qt'QNetworkProtocol::~QNetworkProtocol() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:364)
QNetworkProtocol::~QNetworkProtocol()
{
if ( !d )
return;
d->removeTimer->stop();
if ( d->opInProgress == d->operationQueue.head() )
d->operationQueue.dequeue();
if ( d->opInProgress )
d->opInProgress->free();
d->opInProgress = 0;
while ( d->operationQueue.head() ) {
d->operationQueue.head()->free();
d->operationQueue.dequeue();
}
while ( d->oldOps.first() ) {
d->oldOps.first()->free();
d->oldOps.removeFirst();
}
delete d->opStartTimer;
d->opStartTimer = 0;
delete d;
d = 0;
}
/*!
Sets the QUrlOperator, on which the protocol works.
\sa QUrlOperator
*/
qt'QNetworkProtocol::setUrl() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:394)
void QNetworkProtocol::setUrl( QUrlOperator *u )
{
if ( url() ) {
disconnect( this, SIGNAL( data( const QByteArray &, QNetworkOperation * ) ),
url(), SIGNAL( data( const QByteArray &, QNetworkOperation * ) ) );
disconnect( this, SIGNAL( finished( QNetworkOperation * ) ),
url(), SIGNAL( finished( QNetworkOperation * ) ) );
disconnect( this, SIGNAL( start( QNetworkOperation * ) ),
url(), SIGNAL( start( QNetworkOperation * ) ) );
disconnect( this, SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ),
url(), SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ) );
disconnect( this, SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ),
url(), SLOT( addEntry( const QValueList<QUrlInfo> & ) ) );
disconnect( this, SIGNAL( createdDirectory( const QUrlInfo &, QNetworkOperation * ) ),
url(), SIGNAL( createdDirectory( const QUrlInfo &, QNetworkOperation * ) ) );
disconnect( this, SIGNAL( removed( QNetworkOperation * ) ),
url(), SIGNAL( removed( QNetworkOperation * ) ) );
disconnect( this, SIGNAL( itemChanged( QNetworkOperation * ) ),
url(), SIGNAL( itemChanged( QNetworkOperation * ) ) );
disconnect( this, SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ),
url(), SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ) );
disconnect( this, SIGNAL( connectionStateChanged( int, const QString & ) ),
url(), SIGNAL( connectionStateChanged( int, const QString & ) ) );
}
d->url = u;
if ( url() ) {
connect( this, SIGNAL( data( const QByteArray &, QNetworkOperation * ) ),
url(), SIGNAL( data( const QByteArray &, QNetworkOperation * ) ) );
connect( this, SIGNAL( finished( QNetworkOperation * ) ),
url(), SIGNAL( finished( QNetworkOperation * ) ) );
connect( this, SIGNAL( start( QNetworkOperation * ) ),
url(), SIGNAL( start( QNetworkOperation * ) ) );
connect( this, SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ),
url(), SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ) );
connect( this, SIGNAL( newChildren( const QValueList<QUrlInfo> &, QNetworkOperation * ) ),
url(), SLOT( addEntry( const QValueList<QUrlInfo> & ) ) );
connect( this, SIGNAL( createdDirectory( const QUrlInfo &, QNetworkOperation * ) ),
url(), SIGNAL( createdDirectory( const QUrlInfo &, QNetworkOperation * ) ) );
connect( this, SIGNAL( removed( QNetworkOperation * ) ),
url(), SIGNAL( removed( QNetworkOperation * ) ) );
connect( this, SIGNAL( itemChanged( QNetworkOperation * ) ),
url(), SIGNAL( itemChanged( QNetworkOperation * ) ) );
connect( this, SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ),
url(), SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ) );
connect( this, SIGNAL( connectionStateChanged( int, const QString & ) ),
url(), SIGNAL( connectionStateChanged( int, const QString & ) ) );
}
if ( !d->opInProgress && !d->operationQueue.isEmpty() )
d->opStartTimer->start( 1, TRUE );
}
/*!
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 \a op to QNetworkProtocol::StFailed and emit the finished() signal with
this QNetworkOperation as argument.
\a op is the operation which needs an open connection.
*/
qt'QNetworkProtocol::checkConnection() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:463)
bool QNetworkProtocol::checkConnection( QNetworkOperation * )
{
return TRUE;
}
/*!
Returns an int, which is or'd together using the enum values
of \c QNetworkProtocol::Operation, which describes which operations
are supported by the network protocol. Should be reimplemented by new
network protocols.
*/
qt'QNetworkProtocol::supportedOperations() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:475)
int QNetworkProtocol::supportedOperations() const
{
return 0;
}
/*!
Adds the operation \a op the operation queue. The operation
will be processed as soon as possible. This method returns
immediately.
*/
qt'QNetworkProtocol::addOperation() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:486)
void QNetworkProtocol::addOperation( QNetworkOperation *op )
{
#ifdef QNETWORKPROTOCOL_DEBUG
qDebug( "QNetworkOperation: addOperation: %p %d", op, op->operation() );
#endif
d->operationQueue.enqueue( op );
if ( !d->opInProgress )
d->opStartTimer->start( 1, TRUE );
}
/*!
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<Nntp> );
After that, this implementation is registered for nntp operations.
*/
qt'QNetworkProtocol::registerNetworkProtocol() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:506)
void QNetworkProtocol::registerNetworkProtocol( const QString &protocol,
QNetworkProtocolFactoryBase *protocolFactory )
{
if ( !qNetworkProtocolRegister ) {
qNetworkProtocolRegister = new QNetworkProtocolDict;
QNetworkProtocol::registerNetworkProtocol( "file", new QNetworkProtocolFactory< QLocalFs > );
}
qNetworkProtocolRegister->insert( protocol, protocolFactory );
}
/*!
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.
\sa QUrlOperator
*/
qt'QNetworkProtocol::getNetworkProtocol() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:536)
QNetworkProtocol *QNetworkProtocol::getNetworkProtocol( const QString &protocol )
{
if ( !qNetworkProtocolRegister ) {
qNetworkProtocolRegister = new QNetworkProtocolDict;
QNetworkProtocol::registerNetworkProtocol( "file", new QNetworkProtocolFactory< QLocalFs > );
}
if ( protocol.isNull() )
return 0;
QNetworkProtocolFactoryBase *factory = qNetworkProtocolRegister->find( protocol );
if ( factory )
return factory->createObject();
return 0;
}
/*!
Returns TRUE, if only a protocol for working on the local filesystem is
registered, or FALSE if also other network protocols are registered.
*/
qt'QNetworkProtocol::hasOnlyLocalFileSystem() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:558)
bool QNetworkProtocol::hasOnlyLocalFileSystem()
{
if ( !qNetworkProtocolRegister )
return FALSE;
QDictIterator< QNetworkProtocolFactoryBase > it( *qNetworkProtocolRegister );
for ( ; it.current(); ++it )
if ( it.currentKey() != "file" )
return FALSE;
return TRUE;
}
/*!
\internal
Starts processing network operations.
*/
qt'QNetworkProtocol::startOps() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:575)
void QNetworkProtocol::startOps()
{
#ifdef QNETWORKPROTOCOL_DEBUG
qDebug( "QNetworkOperation: start processing operations" );
#endif
processNextOperation( 0 );
}
/*!
\internal
Processes the operation \a op. It calls the
corresponding operation[something]( QNetworkOperation * )
methods.
*/
qt'QNetworkProtocol::processOperation() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:590)
void QNetworkProtocol::processOperation( QNetworkOperation *op )
{
if ( !op )
return;
switch ( op->operation() ) {
case OpListChildren:
operationListChildren( op );
break;
case OpMkdir:
operationMkDir( op );
break;
case OpRemove:
operationRemove( op );
break;
case OpRename:
operationRename( op );
break;
case OpGet:
operationGet( op );
break;
case OpPut:
operationPut( op );
break;
}
}
/*!
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 <a href="network.html">Qt Network Documentation</a>,
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.
*/
qt'QNetworkProtocol::operationListChildren() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:631)
void QNetworkProtocol::operationListChildren( QNetworkOperation * )
{
}
/*!
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 <a href="network.html">Qt Network Documentation</a>,
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.
*/
qt'QNetworkProtocol::operationMkDir() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:649)
void QNetworkProtocol::operationMkDir( QNetworkOperation * )
{
}
/*!
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 <a href="network.html">Qt Network Documentation</a>,
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.
*/
qt'QNetworkProtocol::operationRemove() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:667)
void QNetworkProtocol::operationRemove( QNetworkOperation * )
{
}
/*!
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 <a href="network.html">Qt Network Documentation</a>,
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.
*/
qt'QNetworkProtocol::operationRename() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:685)
void QNetworkProtocol::operationRename( QNetworkOperation * )
{
}
/*!
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 <a href="network.html">Qt Network Documentation</a>,
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.
*/
qt'QNetworkProtocol::operationGet() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:703)
void QNetworkProtocol::operationGet( QNetworkOperation * )
{
}
/*!
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 <a href="network.html">Qt Network Documentation</a>,
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.
*/
qt'QNetworkProtocol::operationPut() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:721)
void QNetworkProtocol::operationPut( QNetworkOperation * )
{
}
/*!
\internal
Handles operations. Deletes the previous operation object and
tries to process the next operation. It also checks the connection state
and only processes the next operation, if the connection of the protocol
is open. Else it waits until the protocol opens the connection.
*/
qt'QNetworkProtocol::processNextOperation() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:733)
void QNetworkProtocol::processNextOperation( QNetworkOperation *old )
{
#ifdef QNETWORKPROTOCOL_DEBUG
qDebug( "QNetworkOperation: process next operation, old: %p", old );
#endif
d->removeTimer->stop();
if ( old )
d->oldOps.append( old );
if ( d->operationQueue.isEmpty() ) {
d->opInProgress = 0;
if ( d->autoDelete )
d->removeTimer->start( d->removeInterval, TRUE );
return;
}
QNetworkOperation *op = d->operationQueue.head();
d->opInProgress = 0;
if ( !checkConnection( op ) ) {
if ( op->state() != QNetworkProtocol::StFailed ) {
d->opStartTimer->start( 1, TRUE );
d->opInProgress = op;
} else {
d->opInProgress = op;
d->operationQueue.dequeue();
clearOperationQueue();
emit finished( op );
}
return;
}
d->opInProgress = op;
d->operationQueue.dequeue();
processOperation( op );
}
/*!
Returns the QUrlOperator on which the protocol works.
*/
qt'QNetworkProtocol::url() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:777)
QUrlOperator *QNetworkProtocol::url() const
{
return d->url;
}
/*!
Returns the operation, which is just processed, or NULL
of none is processed at the moment.
*/
qt'QNetworkProtocol::operationInProgress() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:787)
QNetworkOperation *QNetworkProtocol::operationInProgress() const
{
return d->opInProgress;
}
/*!
Clears the opeartion queue.
*/
qt'QNetworkProtocol::clearOperationQueue() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:796)
void QNetworkProtocol::clearOperationQueue()
{
d->operationQueue.dequeue();
d->opInProgress = 0;
d->operationQueue.setAutoDelete( TRUE );
d->operationQueue.clear();
}
/*!
Stops the current operation which is just processed and clears
all waiting operations.
*/
qt'QNetworkProtocol::stop() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:809)
void QNetworkProtocol::stop()
{
QNetworkOperation *op = d->opInProgress;
clearOperationQueue();
if ( op ) {
op->setState( StStopped );
op->setProtocolDetail( tr( "Operation stopped by the user" ) );
emit finished( op );
setUrl( 0 );
op->free();
}
}
/*!
Because it's sometimes hard to care about removing network protocol
instances, QNetworkProtocol provides an autodelete meachnism. If
you set \a b to TRUE, this network protocol instance gets removed
after it has been \a i milliseconds inactive (this means \a i ms after
the last operation has been processed).
If you set \a b to FALSE, the autodelete mechanism is switched off.
NOTE: If you switch on autodeleting, the QNetworkProtocol also
deletes its QUrlOperator!
*/
qt'QNetworkProtocol::setAutoDelete() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:834)
void QNetworkProtocol::setAutoDelete( bool b, int i )
{
d->autoDelete = b;
d->removeInterval = i;
}
/*!
Returns TRUE, of autodeleting is enabled, else FALSE.
\sa QNetworkProtocol::setAutoDelete()
*/
qt'QNetworkProtocol::autoDelete() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:846)
bool QNetworkProtocol::autoDelete() const
{
return d->autoDelete;
}
/*!
\internal
*/
qt'QNetworkProtocol::removeMe() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:855)
void QNetworkProtocol::removeMe()
{
if ( d->autoDelete ) {
#ifdef QNETWORKPROTOCOL_DEBUG
qDebug( "QNetworkOperation: autodelete of QNetworkProtocol %p", this );
#endif
delete url();
}
}
qt'QNetworkProtocol::emitNewChildren() (./qt-2.1.0/src/kernel/qnetworkprotocol.cpp:865)
void QNetworkProtocol::emitNewChildren( const QUrlInfo &i, QNetworkOperation *op )
{
QValueList<QUrlInfo> lst;
lst << i;
emit newChildren( lst, op );
}