File indexing completed on 2024-06-16 05:24:49
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2011 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_CHARSETCONVERSIONTOOL_HPP 0010 #define KASTEN_CHARSETCONVERSIONTOOL_HPP 0011 0012 // Kasten core 0013 #include <Kasten/AbstractTool> 0014 // Okteta core 0015 #include <Okteta/Byte> 0016 0017 namespace Okteta { 0018 class AbstractByteArrayModel; 0019 class CharCodec; 0020 } 0021 template <class Key, class T> class QMap; 0022 0023 namespace Kasten { 0024 0025 class ByteArrayView; 0026 0027 /** 0028 */ 0029 class CharsetConversionTool : public AbstractTool 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 enum ConversionDirection 0035 { 0036 ConvertFrom, 0037 ConvertTo 0038 }; 0039 0040 private: 0041 static inline constexpr char ConfigGroupId[] = "CharsetConversionTool"; 0042 static inline constexpr char OtherCharCodecNameConfigKey[] = "OtherCharCodecName"; 0043 static inline constexpr char ConversionDirectionConfigKey[] = "ConversionDirection"; 0044 static inline constexpr char SubstituteMissingCharsConfigKey[] = "SubstituteMissingChars"; 0045 static inline constexpr char SubstituteByteConfigKey[] = "SubstituteByte"; 0046 0047 static inline constexpr bool DefaultSubstituteMissingChars = false; 0048 static inline constexpr Okteta::Byte DefaultSubstituteByte = 0; 0049 static inline constexpr ConversionDirection DefaultConversionDirection = ConvertFrom; 0050 0051 public: 0052 CharsetConversionTool(); 0053 ~CharsetConversionTool() override; 0054 0055 public: // AbstractTool API 0056 // virtual AbstractModel* targetModel() const; 0057 QString title() const override; 0058 0059 void setTargetModel(AbstractModel* model) override; 0060 0061 public: // status 0062 bool isApplyable() const; // candidate for AbstractTool API 0063 0064 QString otherCharCodecName() const; 0065 ConversionDirection conversionDirection() const; 0066 bool isSubstitutingMissingChars() const; 0067 Okteta::Byte substituteByte() const; 0068 0069 public Q_SLOTS: // settings 0070 void setConversionDirection(int conversionDirection); 0071 void setOtherCharCodecName(const QString& codecName); 0072 void setSubstitutingMissingChars(bool isSubstitutingMissingChars); 0073 void setSubstituteByte(int byte); 0074 0075 public Q_SLOTS: // actions 0076 void convertChars(); 0077 0078 Q_SIGNALS: 0079 void isApplyableChanged(bool isApplyable); // candidate for AbstractTool API 0080 void conversionDone(bool success, int convertedBytesCount, 0081 const QMap<Okteta::Byte, int>& failedPerByteCount); 0082 0083 private Q_SLOTS: 0084 void onViewChanged(); 0085 0086 private: // settings 0087 QString mOtherCharCodecName; 0088 ConversionDirection mConversionDirection = ConvertFrom; 0089 bool mSubstitutingMissingChars = false; 0090 Okteta::Byte mSubstituteByte = 0; 0091 0092 private: // sources 0093 ByteArrayView* mByteArrayView = nullptr; 0094 Okteta::AbstractByteArrayModel* mByteArrayModel = nullptr; 0095 }; 0096 0097 } 0098 0099 #endif