⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3urloperator.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    \endcode    This will upload the data to ftp://ftp.whatever.com/home/me/filename.dat.    \sa copy()*/const Q3NetworkOperation *Q3UrlOperator::put( const QByteArray &data, const QString &location ){    Q3Url u( *this );    if ( !location.isEmpty() )	u = Q3Url( *this, location );    if ( !u.isValid() )	return 0;    if ( !d->networkProtocol ) {	setProtocol( u.protocol() );	getNetworkProtocol();    }    Q3NetworkOperation *res = new Q3NetworkOperation( Q3NetworkProtocol::OpPut, u, QString(), QString() );    res->setRawArg( 1, data );    return startOperation( res );}/*!    Sets the name filter of the URL to \a nameFilter.    \sa QDir::setNameFilter()*/void Q3UrlOperator::setNameFilter( const QString &nameFilter ){    d->nameFilter = nameFilter;}/*!    Returns the name filter of the URL.    \sa Q3UrlOperator::setNameFilter() QDir::nameFilter()*/QString Q3UrlOperator::nameFilter() const{    return d->nameFilter;}/*!    Clears the cache of children.*/void Q3UrlOperator::clearEntries(){    d->entryMap.clear();}/*!    Adds an entry to the cache of children.*/void Q3UrlOperator::addEntry( const Q3ValueList<QUrlInfo> &i ){    Q3ValueList<QUrlInfo>::ConstIterator it = i.begin();    for ( ; it != i.end(); ++it )	d->entryMap[ ( *it ).name().stripWhiteSpace() ] = *it;}/*!    Returns the URL information for the child \a entry, or returns an    empty QUrlInfo object if there is no information available about    \a entry. Information about \a entry is only available after a successfully    finished listChildren() operation.*/QUrlInfo Q3UrlOperator::info( const QString &entry ) const{    if ( d->entryMap.contains( entry.stripWhiteSpace() ) ) {	return d->entryMap[ entry.stripWhiteSpace() ];    } else if ( entry == QLatin1String(".") || entry == QLatin1String("..") ) {	 // return a faked QUrlInfo	 QUrlInfo inf;	 inf.setName( entry );	 inf.setDir( true );	 inf.setFile( false );	 inf.setSymLink( false );	 inf.setOwner( tr( "(unknown)" ) );	 inf.setGroup( tr( "(unknown)" ) );	 inf.setSize( 0 );	 inf.setWritable( false );	 inf.setReadable( true );	 return inf;    }    return QUrlInfo();}/*!    Finds a network protocol for the URL and deletes the old network protocol.*/void Q3UrlOperator::getNetworkProtocol(){    delete d->networkProtocol;    Q3NetworkProtocol *p = Q3NetworkProtocol::getNetworkProtocol( protocol() );    if ( !p ) {	d->networkProtocol = 0;	return;    }    d->networkProtocol = (Q3NetworkProtocol *)p;    d->networkProtocol->setUrl( this );    connect( d->networkProtocol, SIGNAL(itemChanged(Q3NetworkOperation*)),	     this, SLOT(slotItemChanged(Q3NetworkOperation*)) );}/*!    Deletes the currently used network protocol.*/void Q3UrlOperator::deleteNetworkProtocol(){    if (d->networkProtocol) {        d->networkProtocol->deleteLater();        d->networkProtocol = 0;    }}/*!    \reimp*/void Q3UrlOperator::setPath( const QString& path ){    Q3Url::setPath( path );    if ( d->networkProtocol )	d->networkProtocol->setUrl( this );}/*!    \reimp*/void Q3UrlOperator::reset(){    Q3Url::reset();    deleteNetworkProtocol();    d->nameFilter = QLatin1String("*");}/*!    \reimp*/bool Q3UrlOperator::parse( const QString &url ){    bool b = Q3Url::parse( url );    if ( !b ) {	return b;    }    getNetworkProtocol();    return b;}/*!    Assigns \a url to this object.*/Q3UrlOperator& Q3UrlOperator::operator=( const Q3UrlOperator &url ){    deleteNetworkProtocol();    Q3Url::operator=( url );    Q3PtrDict<Q3NetworkOperation> getOpPutOpMap = d->getOpPutOpMap;    Q3PtrDict<Q3NetworkProtocol> getOpPutProtMap = d->getOpPutProtMap;    Q3PtrDict<Q3NetworkProtocol> getOpGetProtMap = d->getOpGetProtMap;    Q3PtrDict<Q3NetworkOperation> getOpRemoveOpMap = d->getOpRemoveOpMap;    *d = *url.d;    d->oldOps.setAutoDelete( false );    d->getOpPutOpMap = getOpPutOpMap;    d->getOpPutProtMap = getOpPutProtMap;    d->getOpGetProtMap = getOpGetProtMap;    d->getOpRemoveOpMap = getOpRemoveOpMap;    d->networkProtocol = 0;    getNetworkProtocol();    return *this;}/*!    Assigns \a url to this object.*/Q3UrlOperator& Q3UrlOperator::operator=( const QString &url ){    deleteNetworkProtocol();    Q3Url::operator=( url );    d->oldOps.setAutoDelete( false );    getNetworkProtocol();    return *this;}/*!    \internal*/bool Q3UrlOperator::cdUp(){    bool b = Q3Url::cdUp();    if ( d->networkProtocol )	d->networkProtocol->setUrl( this );    return b;}/*!    \internal*/bool Q3UrlOperator::checkValid(){    // ######    if ( !isValid() ) {	//emit error( ErrValid, tr( "The entered URL is not valid!" ) );	return false;    } else	return true;}/*!    \internal*/void Q3UrlOperator::copyGotData( const QByteArray &data_, Q3NetworkOperation *op ){#ifdef Q3URLOPERATOR_DEBUG    qDebug( "Q3UrlOperator: copyGotData: %d new bytes", data_.size() );#endif    Q3NetworkOperation *put = d->getOpPutOpMap[ (void*)op ];    if ( put ) {	QByteArray &s = put->raw( 1 );	int size = s.size();	s.resize( size + data_.size() );	memcpy( s.data() + size, data_.data(), data_.size() );    }    emit data( data_, op );}/*!    \internal*/void Q3UrlOperator::continueCopy( Q3NetworkOperation *op ){    if ( op->operation() != Q3NetworkProtocol::OpGet )	return;    if ( op->state()!=Q3NetworkProtocol::StDone &&  op->state()!=Q3NetworkProtocol::StFailed ) {	return;    }#ifdef Q3URLOPERATOR_DEBUG    if ( op->state() != Q3NetworkProtocol::StFailed ) {	qDebug( "Q3UrlOperator: continue copy (get finished, put will start)" );    }#endif    Q3NetworkOperation *put = d->getOpPutOpMap[ (void*)op ];    Q3NetworkProtocol *gProt = d->getOpGetProtMap[ (void*)op ];    Q3NetworkProtocol *pProt = d->getOpPutProtMap[ (void*)op ];    Q3NetworkOperation *rm = d->getOpRemoveOpMap[ (void*)op ];    d->getOpPutOpMap.take( op );    d->getOpGetProtMap.take( op );    d->getOpPutProtMap.take( op );    d->getOpRemoveOpMap.take( op );    if ( pProt )	pProt->setAutoDelete( true );    if ( put && pProt ) {	if ( op->state() != Q3NetworkProtocol::StFailed ) {	    pProt->addOperation( put );	    d->currPut = pProt;        if (rm) { // we need the result of the put operation            qApp->processEvents(); // process posted operations            if (put->state() == Q3NetworkProtocol::StFailed) {                deleteOperation( rm );                rm = 0;            }        }	} else {	    deleteOperation( put );	}    }    if ( gProt ) {	gProt->setAutoDelete( true );    }    if ( rm && gProt ) {	if ( op->state() != Q3NetworkProtocol::StFailed ) {	    gProt->addOperation( rm );	} else {	    deleteOperation( rm );	}    }    disconnect( gProt, SIGNAL(data(QByteArray,Q3NetworkOperation*)),		this, SLOT(copyGotData(QByteArray,Q3NetworkOperation*)) );    disconnect( gProt, SIGNAL(finished(Q3NetworkOperation*)),		this, SLOT(continueCopy(Q3NetworkOperation*)) );}/*!    \internal*/void Q3UrlOperator::finishedCopy(){#ifdef Q3URLOPERATOR_DEBUG    qDebug( "Q3UrlOperator: finished copy (finished putting)" );#endif    if ( d->waitingCopies.isEmpty() )	return;    QString cp = d->waitingCopies.first();    d->waitingCopies.remove( cp );    Q3PtrList<Q3NetworkOperation> lst = copy( cp, d->waitingCopiesDest, d->waitingCopiesMove );    emit startedNextCopy( lst );}/*!    Stops the current network operation and removes all this    Q3UrlOperator's waiting network operations.*/void Q3UrlOperator::stop(){    d->getOpPutOpMap.clear();    d->getOpRemoveOpMap.clear();    d->getOpGetProtMap.setAutoDelete( true );    d->getOpPutProtMap.setAutoDelete( true );    Q3PtrDictIterator<Q3NetworkProtocol> it( d->getOpPutProtMap );    for ( ; it.current(); ++it )	it.current()->stop();    d->getOpPutProtMap.clear();    it = Q3PtrDictIterator<Q3NetworkProtocol>( d->getOpGetProtMap );    for ( ; it.current(); ++it )	it.current()->stop();    d->getOpGetProtMap.clear();    if ( d->currPut ) {	d->currPut->stop();	delete (Q3NetworkProtocol *) d->currPut;	d->currPut = 0;    }    d->waitingCopies.clear();    if ( d->networkProtocol )	d->networkProtocol->stop();    getNetworkProtocol();}/*!    \internal*/void Q3UrlOperator::deleteOperation( Q3NetworkOperation *op ){    if ( op )	d->oldOps.append( op );}/*!    \internal    updates the entryMap after a network operation finished*/void Q3UrlOperator::slotItemChanged( Q3NetworkOperation *op ){    if ( !op )	return;    switch ( op->operation() ) {    case Q3NetworkProtocol::OpRename :    {	if ( op->arg( 0 ) == op->arg( 1 ) )	    return;	QMap<QString, QUrlInfo>::iterator mi = d->entryMap.find( op->arg( 0 ) );	if ( mi != d->entryMap.end() ) {	    mi.data().setName( op->arg( 1 ) );	    d->entryMap[ op->arg( 1 ) ] = mi.data();	    d->entryMap.erase( mi );	}	break;    }    case Q3NetworkProtocol::OpRemove :    {	QMap<QString, QUrlInfo>::iterator mi = d->entryMap.find( op->arg( 0 ) );	if ( mi != d->entryMap.end() )	    d->entryMap.erase( mi );	break;    }    default:	break;    }}#include "moc_q3urloperator.cpp"#endif // QT_NO_NETWORKPROTOCOL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -