Commit acc14b82 authored by Sandro Knauß's avatar Sandro Knauß

refactor HTMLBlocks so they can be used without HtmlWriter

parent a675d7f5
......@@ -28,6 +28,11 @@
using namespace MimeTreeParser;
HTMLBlock::HTMLBlock()
: entered(false)
{
}
HTMLBlock::~HTMLBlock()
{
}
......@@ -37,6 +42,24 @@ QString HTMLBlock::dir() const
return QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr");
}
QString HTMLBlock::enter()
{
if(!entered) {
entered = true;
return enterString();
}
return QString();
}
QString HTMLBlock::exit()
{
if (entered) {
entered = false;
return exitString();
}
return QString();
}
AttachmentMarkBlock::AttachmentMarkBlock(MimeTreeParser::HtmlWriter *writer, KMime::Content *node)
: mNode(node)
, mWriter(writer)
......@@ -51,22 +74,28 @@ AttachmentMarkBlock::~AttachmentMarkBlock()
void AttachmentMarkBlock::internalEnter()
{
if (mWriter && !entered) {
const QString index = mNode->index().toString();
mWriter->queue(QStringLiteral("<a name=\"att%1\"></a>").arg(index));
mWriter->queue(QStringLiteral("<div id=\"attachmentDiv%1\">\n").arg(index));
entered = true;
if (mWriter) {
mWriter->queue(enter());
}
}
void AttachmentMarkBlock::internalExit()
{
if (!entered) {
return;
if (mWriter) {
mWriter->queue(exit());
}
}
QString AttachmentMarkBlock::enterString() const
{
const QString index = mNode->index().toString();
return QStringLiteral("<a name=\"att%1\"></a>").arg(index)
+ QStringLiteral("<div id=\"attachmentDiv%1\">\n").arg(index);
}
mWriter->queue(QStringLiteral("</div>"));
entered = false;
QString AttachmentMarkBlock::exitString() const
{
return QStringLiteral("</div>");
}
RootBlock::RootBlock(HtmlWriter *writer)
......@@ -83,21 +112,24 @@ RootBlock::~RootBlock()
void RootBlock::internalEnter()
{
if (!mWriter || entered) {
return;
if (mWriter) {
mWriter->queue(enter());
}
entered = true;
mWriter->queue(QStringLiteral("<div style=\"position: relative; word-wrap: break-word\">\n"));
}
void RootBlock::internalExit()
{
if (!entered) {
return;
if (mWriter) {
mWriter->queue(exit());
}
}
entered = false;
QString RootBlock::enterString() const
{
return QStringLiteral("<div style=\"position: relative; word-wrap: break-word\">\n");
}
mWriter->queue(QStringLiteral("</div>\n"));
}
\ No newline at end of file
QString RootBlock::exitString() const
{
return QStringLiteral("</div>\n");
}
......@@ -38,14 +38,18 @@ class HTMLBlock
public:
typedef QSharedPointer<HTMLBlock> Ptr;
HTMLBlock()
: entered(false)
{ }
HTMLBlock();
virtual ~HTMLBlock();
QString enter();
QString exit();
protected:
QString dir() const;
virtual QString enterString() const = 0;
virtual QString exitString() const = 0;
private:
bool entered;
};
......@@ -58,6 +62,10 @@ public:
AttachmentMarkBlock(MimeTreeParser::HtmlWriter *writer, KMime::Content *node);
virtual ~AttachmentMarkBlock();
protected:
QString enterString() const Q_DECL_OVERRIDE;
QString exitString() const Q_DECL_OVERRIDE;
private:
void internalEnter();
void internalExit();
......@@ -75,6 +83,10 @@ public:
RootBlock(MimeTreeParser::HtmlWriter *writer);
virtual ~RootBlock();
protected:
QString enterString() const Q_DECL_OVERRIDE;
QString exitString() const Q_DECL_OVERRIDE;
private:
void internalEnter();
void internalExit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment