File indexing completed on 2025-01-19 05:20:19

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2010 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_BYTEARRAYUUENCODINGSTREAMENCODER_HPP
0010 #define KASTEN_BYTEARRAYUUENCODINGSTREAMENCODER_HPP
0011 
0012 // lib
0013 #include "abstractbytearraystreamencoder.hpp"
0014 // Okteta core
0015 #include <Okteta/OktetaCore>
0016 // Qt
0017 #include <QString>
0018 
0019 class KConfigGroup;
0020 
0021 namespace Kasten {
0022 
0023 class UuencodingStreamEncoderSettings
0024 {
0025 public:
0026     enum class EncodingType
0027     {
0028         Historical = 0,
0029         Base64 = 1
0030     };
0031 
0032 private:
0033     static inline constexpr char FileNameConfigKey[] = "FileName";
0034     static inline constexpr char EncodingTypeConfigKey[] = "EncodingType";
0035     static inline constexpr EncodingType DefaultEncodingType = EncodingType::Base64;
0036     static const QString DefaultFileName;
0037 
0038 public:
0039     UuencodingStreamEncoderSettings();
0040     UuencodingStreamEncoderSettings(const UuencodingStreamEncoderSettings&) = default;
0041 
0042     ~UuencodingStreamEncoderSettings() = default;
0043 
0044     UuencodingStreamEncoderSettings& operator=(const UuencodingStreamEncoderSettings&) = default;
0045 
0046     bool operator==(const UuencodingStreamEncoderSettings& other) const;
0047 
0048 public:
0049     void loadConfig(const KConfigGroup& configGroup);
0050     void saveConfig(KConfigGroup& configGroup) const;
0051 
0052 public:
0053     QString fileName;
0054     EncodingType encodingType = EncodingType::Base64;
0055 };
0056 
0057 class ByteArrayUuencodingStreamEncoder : public AbstractByteArrayStreamEncoder
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     enum class InputByteIndex
0063     {
0064         First = 0,
0065         Second,
0066         Third
0067     };
0068 
0069 private:
0070     static inline constexpr int defaultUuInputLineLength = 45;
0071     static inline constexpr int uuInputLineLength = defaultUuInputLineLength;
0072     static inline constexpr int uuInputGroupLength = 3;
0073     static inline constexpr int maxInputGroupsPerLine = uuInputLineLength / uuInputGroupLength;
0074 
0075     static inline constexpr char ConfigGroupId[] = "ByteArrayUuencodingStreamEncoder";
0076 
0077 public:
0078     ByteArrayUuencodingStreamEncoder();
0079     ~ByteArrayUuencodingStreamEncoder() override;
0080 
0081 public:
0082     UuencodingStreamEncoderSettings settings() const;
0083     void setSettings(const UuencodingStreamEncoderSettings& settings);
0084 
0085 protected: // AbstractByteArrayStreamEncoder API
0086     bool encodeDataToStream(QIODevice* device,
0087                             const ByteArrayView* byteArrayView,
0088                             const Okteta::AbstractByteArrayModel* byteArrayModel,
0089                             const Okteta::AddressRange& range) override;
0090 
0091 private:
0092     UuencodingStreamEncoderSettings mSettings;
0093 };
0094 
0095 inline UuencodingStreamEncoderSettings ByteArrayUuencodingStreamEncoder::settings() const { return mSettings; }
0096 
0097 }
0098 
0099 #endif