File indexing completed on 2025-03-09 04:54:33
0001 /* -*- c++ -*- 0002 interfaces/htmlwriter.h 0003 0004 This file is part of KMail's plugin interface. 0005 SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include "messageviewer_export.h" 0013 0014 #include <QByteArray> 0015 #include <memory> 0016 #include <qglobal.h> 0017 class QIODevice; 0018 class QString; 0019 class QTextStream; 0020 0021 namespace MessageViewer 0022 { 0023 /** 0024 * @short An interface for HTML sinks. 0025 * @author Marc Mutz <mutz@kde.org> 0026 * 0027 */ 0028 class MESSAGEVIEWER_EXPORT HtmlWriter 0029 { 0030 public: 0031 HtmlWriter(); 0032 virtual ~HtmlWriter(); 0033 0034 /** Signal the begin of stuff to write. 0035 * Sub-classes should open device() in a writable mode here and then 0036 * call the base class. 0037 */ 0038 virtual void begin(); 0039 0040 /** Write out a chunk of text. No HTML escaping is performed. 0041 * @deprecated use stream() instead 0042 */ 0043 void write(const QString &html); 0044 0045 /** Signal the end of stuff to write. 0046 * Sub-classes should call the base class and then close device() here. 0047 */ 0048 virtual void end(); 0049 0050 /** 0051 * Stop all possibly pending processing in order to be able to 0052 * call #begin() again. 0053 * Sub-classes should call the base class and then reset device() here. 0054 */ 0055 virtual void reset(); 0056 0057 /** Returns the QIODevice backing this HtmlWriter instance. 0058 * Before writing to this directly, make sure to flush stream(). 0059 */ 0060 virtual QIODevice *device() const = 0; 0061 0062 /** Returns a QTextStream on device(). 0063 * Use this for writing QString data, rather than local string 0064 * concatenations. 0065 */ 0066 QTextStream *stream() const; 0067 0068 /** 0069 * Embed a part with Content-ID @p contentId, using url @p url. 0070 */ 0071 virtual void embedPart(const QByteArray &contentId, const QString &url) = 0; 0072 0073 virtual void setExtraHead(const QString &str) = 0; 0074 0075 virtual void setStyleBody(const QString &styleBody) = 0; 0076 0077 void setCodec(const QByteArray &codec); 0078 [[nodiscard]] QByteArray codec() const; 0079 0080 private: 0081 Q_DISABLE_COPY(HtmlWriter) 0082 QByteArray mCodec = QByteArrayLiteral("UTF-8"); 0083 mutable std::unique_ptr<QTextStream> m_stream; 0084 }; 0085 }