Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

void Q3LocalFs::operationGet ( Q3NetworkOperation op ) [protected, virtual]

Reimplemented from Q3NetworkProtocol.

Definition at line 258 of file q3localfs.cpp.

References Q3NetworkOperation::arg(), QFile::close(), Q3NetworkProtocol::data(), Q3NetworkProtocol::dataTransferProgress(), Q3NetworkProtocol::finished(), QFile::open(), Q3NetworkProtocol::operationInProgress(), QByteArray::resize(), Q3NetworkOperation::setErrorCode(), Q3NetworkOperation::setProtocolDetail(), Q3NetworkOperation::setState(), and QFile::size().

{
#ifdef QLOCALFS_DEBUG
    qDebug( "Q3LocalFs: operationGet" );
#endif
    op->setState( StInProgress );
    QString from = Q3Url( op->arg( 0 ) ).path();

    QFile f( from );
    if ( !f.open( IO_ReadOnly ) ) {
#ifdef QLOCALFS_DEBUG
      qDebug( "Q3LocalFs: could not open %s", from.latin1() );
#endif
      QString msg = tr( "Could not open\n%1" ).arg( from );
      op->setState( StFailed );
      op->setProtocolDetail( msg );
      op->setErrorCode( (int)ErrGet );
      emit finished( op );
      return;
    }

    QByteArray s;
    emit dataTransferProgress( 0, f.size(), op );
    if ( f.size() != 0 ) {
      int blockSize = calcBlockSize( f.size() );
      if ( (int)f.size() < blockSize ) {
          s.resize( f.size() );
          f.readBlock( s.data(), f.size() );
          emit data( s, op );
          emit dataTransferProgress( f.size(), f.size(), op );
#ifdef QLOCALFS_DEBUG
          qDebug( "Q3LocalFs: got all %d bytes at once", f.size() );
#endif
      } else {
          s.resize( blockSize );
          int remaining = f.size();
          QPointer<QObject> that = this;
          while ( that && remaining > 0 ) {
            if ( operationInProgress() != op )
                return;
            if ( remaining >= blockSize ) {
                f.readBlock( s.data(), blockSize );
                emit data( s, op );
                emit dataTransferProgress( f.size() - remaining, f.size(), op );
                remaining -= blockSize;
            } else {
                s.resize( remaining );
                f.readBlock( s.data(), remaining );
                emit data( s, op );
                emit dataTransferProgress( f.size() - remaining, f.size(), op );
                remaining -= remaining;
            }
                qApp->processEvents();
          }
          if ( !that )
              return;
#ifdef QLOCALFS_DEBUG
          qDebug( "Q3LocalFs: got all %d bytes step by step", f.size() );
#endif
          emit dataTransferProgress( f.size(), f.size(), op );
      }
    }
    op->setState( StDone );
    f.close();
    emit finished( op );
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index