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

QIODevice * QNetworkDiskCache::data ( const QUrl url ) [virtual]

Implements QAbstractNetworkCache.

Definition at line 355 of file qnetworkdiskcache.cpp.

References QFile::close(), QUrl::isValid(), QFile::map(), QFile::open(), QBuffer::open(), QFile::pos(), QIODevice::readAll(), QBuffer::setData(), QObject::setParent(), and QFile::size().

Referenced by updateMetaData().

{
#if defined(QNETWORKDISKCACHE_DEBUG)
    qDebug() << "QNetworkDiskCache::data()" << url;
#endif
    Q_D(QNetworkDiskCache);
    QBuffer *buffer = 0;
    if (!url.isValid())
        return buffer;
    if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) {
        buffer = new QBuffer;
        buffer->setData(d->lastItem.data.data());
    } else {
        QFile *file = new QFile(d->cacheFileName(url));
        if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered)) {
            delete file;
            return 0;
        }
        if (!d->lastItem.read(file, true)) {
            file->close();
            remove(url);
            delete file;
            return 0;
        }
        if (d->lastItem.data.isOpen()) {
            // compressed
            buffer = new QBuffer;
            buffer->setData(d->lastItem.data.data());
            delete file;
        } else {
            buffer = new QBuffer;
            // ### verify that QFile uses the fd size and not the file name
            qint64 size = file->size() - file->pos();
            const uchar *p = 0;
#ifndef Q_OS_WINCE
            p = file->map(file->pos(), size);
#endif
            if (p) {
                file->setParent(buffer);
                buffer->setData((const char *)p, size);
            } else {
                buffer->setData(file->readAll());
                delete file;
            }
        }
    }
    buffer->open(QBuffer::ReadOnly);
    return buffer;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index