Getting the document from the cache
Andras Mantia
amantia at kde.org
Sun Jan 30 21:39:13 GMT 2005
David Faure wrote:
> Why does the method return a QString anyway?
Because we were talking about a method returning the source as a string
(John even mentioned QString) and because it looks more user friendly to
the (end) user. A QTextStream::setEncoding(QTextStream::UnicodeUTF8) is
missing after QTextStream stream( &f ), though. This combination seems to
work, at least since I started to use for text stream, I didn't get any new
complain about Quanta messing up the documents written in non-English.
> There are encoding problems
> AFAICS, it should return a QCString or QByteArray. And then the stream can
> be created on the array itself directly, no?
Do you mean something like this (untested)?
QByteArray KHTMLPart::documentSource() const
{
QByteArray sourceArray;
if ( !( m_url.isLocalFile() ) &&
KHTMLPageCache::self()->isComplete( d->m_cacheId ) )
{
QDataStream stream( sourceArray, IO_WriteOnly );
KHTMLPageCache::self()->saveData(d->m_cacheId, &stream);
} else
{
QString tmpFile;
if( KIO::NetAccess::download( m_url, tmpFile, NULL ) )
{
QFile f( tmpFile );
if ( f.open( IO_ReadOnly ) )
{
sourceArray = f.readAll();
f.close();
}
KIO::NetAccess::removeTempFile( tmpFile );
}
}
return sourceArray;
}
Andras
--
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org
More information about the kfm-devel
mailing list