Getting the document from the cache
John Tapsell
john at geola.co.uk
Tue Feb 1 10:41:26 GMT 2005
It looks good.
One question though - what if the file is an XML file and not an html file?
I've never been clear on whether it's still rendered in KHTMLPart - I think it
is. I guess encoding() will still be correct, right?
JohnFlux
On Monday 31 January 2005 22:56, Andras Mantia wrote:
> John Tapsell wrote:
> > What did you use in the end?
>
> As we discussed with David, returning a QString and using the encoding of
> the rendered document. The conversion of QDataStream->QString is with the
> help of a QTextStream and QByteArray instead of a temp file. But here is
> the diff from kde-cvs:
>
> +QString KHTMLPart::documentSource() const
> +{
> + QString sourceStr;
> + if ( !( m_url.isLocalFile() ) &&
> KHTMLPageCache::self()->isComplete( d->m_cacheId ) )
> + {
> + QByteArray sourceArray;
> + QDataStream dataStream( sourceArray, IO_WriteOnly );
> + KHTMLPageCache::self()->saveData( d->m_cacheId, &dataStream );
> + QTextStream stream( sourceArray, IO_ReadOnly );
> + stream.setCodec( QTextCodec::codecForName( encoding().latin1() ) );
> + sourceStr = stream.read();
> + } else
> + {
> + QString tmpFile;
> + if( KIO::NetAccess::download( m_url, tmpFile, NULL ) )
> + {
> + QFile f( tmpFile );
> + if ( f.open( IO_ReadOnly ) )
> + {
> + QTextStream stream( &f );
> + stream.setCodec( QTextCodec::codecForName( encoding().latin1() )
> ); + sourceStr = stream.read();
> + f.close();
> + }
> + KIO::NetAccess::removeTempFile( tmpFile );
> + }
> + }
> +
> + return sourceStr;
> +}
>
> Andras
More information about the kfm-devel
mailing list