Messagelib

htmlwriter.h
1 /* -*- c++ -*-
2  interfaces/htmlwriter.h
3 
4  This file is part of KMail's plugin interface.
5  SPDX-FileCopyrightText: 2003 Marc Mutz <[email protected]>
6 
7  SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include "messageviewer_export.h"
13 
14 #include <QByteArray>
15 #include <memory>
16 #include <qglobal.h>
17 class QIODevice;
18 class QString;
19 class QTextStream;
20 
21 namespace MessageViewer
22 {
23 /**
24  * @short An interface for HTML sinks.
25  * @author Marc Mutz <[email protected]>
26  *
27  */
28 class MESSAGEVIEWER_EXPORT HtmlWriter
29 {
30 public:
31  HtmlWriter();
32  virtual ~HtmlWriter();
33 
34  /** Signal the begin of stuff to write.
35  * Sub-classes should open device() in a writable mode here and then
36  * call the base class.
37  */
38  virtual void begin();
39 
40  /** Write out a chunk of text. No HTML escaping is performed.
41  * @deprecated use stream() instead
42  */
43  void write(const QString &html);
44 
45  /** Signal the end of stuff to write.
46  * Sub-classes should call the base class and then close device() here.
47  */
48  virtual void end();
49 
50  /**
51  * Stop all possibly pending processing in order to be able to
52  * call #begin() again.
53  * Sub-classes should call the base class and then reset device() here.
54  */
55  virtual void reset();
56 
57  /** Returns the QIODevice backing this HtmlWriter instance.
58  * Before writing to this directly, make sure to flush stream().
59  */
60  virtual QIODevice *device() const = 0;
61 
62  /** Returns a QTextStream on device().
63  * Use this for writing QString data, rather than local string
64  * concatenations.
65  */
66  QTextStream *stream() const;
67 
68  /**
69  * Embed a part with Content-ID @p contentId, using url @p url.
70  */
71  virtual void embedPart(const QByteArray &contentId, const QString &url) = 0;
72 
73  virtual void setExtraHead(const QString &str) = 0;
74 
75  virtual void setStyleBody(const QString &styleBody) = 0;
76 
77  void setCodec(const QByteArray &codec);
78  Q_REQUIRED_RESULT QByteArray codec() const;
79 
80 private:
81  Q_DISABLE_COPY(HtmlWriter)
82  QByteArray mCodec = QByteArrayLiteral("UTF-8");
83  mutable std::unique_ptr<QTextStream> m_stream;
84 };
85 }
86 
An interface for HTML sinks.
Definition: htmlwriter.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.