Getting the document from the cache

Andras Mantia amantia at kde.org
Mon Jan 31 08:20:16 GMT 2005


David Faure wrote:

> I can't see how it would work with e.g. russian or chinese web pages. The
> source is certainly not in UTF-8. Heck, most french pages aren't either :)

I think it works because it autodetects the if the file is in local
encoding. On the Quanta user lists there are reports about using Quanta do
develop Japanese pages...

>> QByteArray KHTMLPart::documentSource() const
> 
> That version looks much safer encoding-wise, but you're right that the
> caller of the method won't know what to do with it...
> I guess "view document source" works because kate autodetects the
> encoding?

As I see it does something based on KIO::Job:

QString metaDataCharset = job->queryMetaData("charset");
   if (!metaDataCharset.isEmpty () && (!m_config->isSetEncoding() ||
m_config->encoding().isEmpty()
      setEncoding (metaDataCharset);

There are several possibilities that come into my mind how to deal with
encodings:
1) provide a method that returns a path to a temporary file holding the
source. The user can do whatever he wants with the temporary file.
2) use the KHTMLPart::encoding() and give back the source in QString, but
using this encoding information. I must verify this, maybe it's not
possible to directly use QTextStream::setEncoding(encoding()) but I should
use QTextStream::setCodec(QTextCodec::codecForName(encoding()))

Which one makes more sense? Maybe the second?
Andras

-- 
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org





More information about the kfm-devel mailing list