Getting the document from the cache
Andras Mantia
amantia at kde.org
Mon Jan 31 22:56:21 GMT 2005
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
--
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org
More information about the kfm-devel
mailing list