File indexing completed on 2025-03-09 04:54:40

0001 /*
0002   SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "messagedisplayformatattribute.h"
0009 #include <QByteArray>
0010 #include <QDataStream>
0011 #include <QIODevice>
0012 
0013 using namespace MessageViewer;
0014 
0015 class MessageViewer::MessageDisplayFormatAttributePrivate
0016 {
0017 public:
0018     MessageDisplayFormatAttributePrivate() = default;
0019 
0020     Viewer::DisplayFormatMessage messageFormat = Viewer::UseGlobalSetting;
0021     bool remoteContent = false;
0022 };
0023 
0024 MessageDisplayFormatAttribute::MessageDisplayFormatAttribute()
0025     : d(new MessageDisplayFormatAttributePrivate)
0026 {
0027 }
0028 
0029 MessageDisplayFormatAttribute::~MessageDisplayFormatAttribute() = default;
0030 
0031 MessageDisplayFormatAttribute *MessageDisplayFormatAttribute::clone() const
0032 {
0033     auto messageDisplayFormatAttr = new MessageDisplayFormatAttribute();
0034     messageDisplayFormatAttr->setMessageFormat(messageFormat());
0035     messageDisplayFormatAttr->setRemoteContent(remoteContent());
0036     return messageDisplayFormatAttr;
0037 }
0038 
0039 QByteArray MessageDisplayFormatAttribute::type() const
0040 {
0041     static const QByteArray sType("MessageDisplayFormatAttribute");
0042     return sType;
0043 }
0044 
0045 QByteArray MessageDisplayFormatAttribute::serialized() const
0046 {
0047     QByteArray result;
0048     QDataStream s(&result, QIODevice::WriteOnly);
0049     s.setVersion(QDataStream::Qt_5_15);
0050     s << messageFormat();
0051     s << remoteContent();
0052 
0053     return result;
0054 }
0055 
0056 void MessageDisplayFormatAttribute::setMessageFormat(Viewer::DisplayFormatMessage format)
0057 {
0058     d->messageFormat = format;
0059 }
0060 
0061 void MessageDisplayFormatAttribute::setRemoteContent(bool remote)
0062 {
0063     d->remoteContent = remote;
0064 }
0065 
0066 bool MessageDisplayFormatAttribute::remoteContent() const
0067 {
0068     return d->remoteContent;
0069 }
0070 
0071 bool MessageDisplayFormatAttribute::operator==(const MessageDisplayFormatAttribute &other) const
0072 {
0073     return (d->messageFormat == other.messageFormat()) && (d->remoteContent == other.remoteContent());
0074 }
0075 
0076 Viewer::DisplayFormatMessage MessageDisplayFormatAttribute::messageFormat() const
0077 {
0078     return d->messageFormat;
0079 }
0080 
0081 void MessageDisplayFormatAttribute::deserialize(const QByteArray &data)
0082 {
0083     QDataStream s(data);
0084     s.setVersion(QDataStream::Qt_5_15);
0085     int value = 0;
0086     s >> value;
0087     d->messageFormat = static_cast<Viewer::DisplayFormatMessage>(value);
0088     s >> d->remoteContent;
0089 }