Make HtmlWriter compatible with Grantlee::OutputStream
ClosedPublic

Authored by vkrause on Oct 1 2017, 2:08 PM.

Details

Summary

For that we need a QTextStream backed by a QIODevice. We have two
implementation, one backed by a QBuffer and one by a QFile, rplacing
most of the various sub-classes we had previously.

This means that the internal buffer is now a QByteArray rather than a
QString. That however turns out to not be a problem at all, as
QWebEnginePage::setHtml() basically just calls setContent(html.toUtf8()),
ie. we need a QByteArray in the end anyway.

Another side-effect of the QIODevice usage is that this now becomes a lot
more sensitive to being in the correct state, therefore also the test code
needs to properly call begin/end now.

In order to employ this to the full extend the next step is passing this
along to all render methods and writing into it directly rather than using
intermediate buffers, as well as adding a custom Grantlee item for nested
templates so we can do this with streaming too.

Diff Detail

Repository
R94 PIM: Message Library
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
vkrause created this revision.Oct 1 2017, 2:08 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptOct 1 2017, 2:08 PM
Restricted Application added a subscriber: KDE PIM. · View Herald Transcript
knauss added a comment.Oct 1 2017, 2:47 PM

and bump mimetreeparser version :D

messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
348

should this be flush() instead of end, because there is no rule not adding antoher thing after reading.

955–956

this looks very implictit and hard to understand what is going on, maybe a function to HtmlWriter to handle this directly, because we'll use this all over the place, but the disadvante is that we add Grantlee dependes to mimetreeparser, so it's a no-go

htmlWriter->addGrantleeOutput(t, &c);

so maybe better add a util method:

AddGrantlleOutputToHtmlWriter(t, &c, htmlWriter);
mimetreeparser/src/htmlwriter/filehtmlwriter.cpp
59

shouldn't we still flush, at the end?

mimetreeparser/src/interfaces/htmlwriter.h
82

you removed everywhere the flush but add in the docu, that it needs to be flushed, that sounds wired

Version bump will be done once the entire patch series is in, we don't have enough numbers to do that after every single commit ;-)

messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
348

Theoretically, yes. However that makes no sense semantically, as you would duplicate the first part of the output.

955–956

Just to save one line of code? And I don't see how that makes anything clearer, "OutputStream" looks pretty self-explanatory to me.

mimetreeparser/src/htmlwriter/filehtmlwriter.cpp
59

HtmlWriter::end() flushes the stream, closing the file flushes the device, so that's all covered.

mimetreeparser/src/interfaces/htmlwriter.h
82

That's referring to QTextStream::flush() that you can call on stream() directly. For normal QString output you wont need that, just for raw device access.

knauss added a comment.Oct 1 2017, 3:45 PM

Version bump will be done once the entire patch series is in, we don't have enough numbers to do that after every single commit ;-)

fair enough, but i know from mathematics that there are enough numbers :D

messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
955–956

well for me it is much more obvious what is going on and i think a extra function would help understanding the code faster. and i think the compiler will mark this function as inline, so no overhead.
I also have in mind, that we may need to adjust this in future, or anything like that.
What about, that the whole block with isAttachment put in one function?

fair enough, but i know from mathematics that there are enough numbers :D

There is a fairly hard limit with the number reserved for the first beta release, not sure if that's 50, 70 or 80.

messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
955–956

Factoring out the whole attachment block seems more useful indeed. But that's IMHO out of scope for this commit. Let's revisit cleaning up the render implementation once we have the API sorted out.

80 is the first beta
90 rc

knauss accepted this revision.Oct 1 2017, 5:29 PM
knauss added inline comments.
messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
955–956

fair enough.

This revision is now accepted and ready to land.Oct 1 2017, 5:30 PM
This revision was automatically updated to reflect the committed changes.