File indexing completed on 2024-05-26 05:56:37

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2007-2008 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_STRINGSEXTRACTTOOL_HPP
0010 #define KASTEN_STRINGSEXTRACTTOOL_HPP
0011 
0012 // tool
0013 #include "containedstring.hpp"
0014 // Kasten core
0015 #include <Kasten/AbstractTool>
0016 // Okteta core
0017 #include <Okteta/AddressRange>
0018 // Qt
0019 #include <QList>
0020 
0021 namespace Okteta {
0022 class AbstractByteArrayModel;
0023 class CharCodec;
0024 }
0025 
0026 namespace Kasten {
0027 
0028 class ByteArrayView;
0029 
0030 /**
0031  */
0032 class StringsExtractTool : public AbstractTool
0033 {
0034     Q_OBJECT
0035 
0036 private:
0037     static inline constexpr int DefaultMinLength = 3;
0038 
0039     static inline constexpr char ConfigGroupId[] = "StringsExtractTool";
0040     static inline constexpr char MinimumLengthConfigKey[] = "MinimumLength";
0041 
0042 public:
0043     StringsExtractTool();
0044     ~StringsExtractTool() override;
0045 
0046 public: // AbstractTool API
0047 //     virtual AbstractModel* targetModel() const;
0048     QString title() const override;
0049 
0050     void setTargetModel(AbstractModel* model) override;
0051 
0052 public: // status
0053     const QList<ContainedString>* containedStringList() const;
0054     int minLength() const;
0055     bool isApplyable() const; // candidate for AbstractTool API
0056     bool isUptodate() const;
0057     bool canHighlightString() const;
0058     int offsetCoding() const;
0059 
0060 public Q_SLOTS: // settings
0061     void setMinLength(int minLength);
0062     void markString(int stringId);
0063     void unmarkString();
0064 
0065 public Q_SLOTS: // actions
0066     void extractStrings();
0067 
0068 Q_SIGNALS:
0069     void uptodateChanged(bool isUptodate);
0070     void isApplyableChanged(bool isApplyable);    // candidate for AbstractTool API
0071     void canHighlightStringChanged(bool canHighlightString);
0072     void offsetCodingChanged(int offsetCoding);
0073 
0074 private:
0075     void checkUptoDate();
0076 
0077 private Q_SLOTS:
0078     void onSelectionChanged();
0079     void onSourceChanged();
0080     void onSourceDestroyed();
0081     void onSourceViewDestroyed();
0082 
0083 private: // created data
0084     QList<ContainedString> mContainedStringList;
0085     bool mExtractedStringsUptodate : 1;
0086     bool mSourceByteArrayModelUptodate : 1;
0087 
0088 private: // settings
0089     int mMinLength;
0090 
0091 private: // sources
0092     ByteArrayView* mByteArrayView = nullptr;
0093     // current
0094     Okteta::AbstractByteArrayModel* mByteArrayModel = nullptr;
0095 
0096     // marked view
0097     ByteArrayView* mSourceByteArrayView = nullptr;
0098     // selection source
0099     Okteta::AddressRange mSourceSelection;
0100     // source of strings
0101     Okteta::AbstractByteArrayModel* mSourceByteArrayModel = nullptr;
0102     // minLength source
0103     int mSourceMinLength = 0;
0104 };
0105 
0106 inline const QList<ContainedString>* StringsExtractTool::containedStringList() const { return &mContainedStringList; }
0107 inline int StringsExtractTool::minLength()     const { return mMinLength; }
0108 inline bool StringsExtractTool::isUptodate()   const { return mExtractedStringsUptodate; }
0109 
0110 }
0111 
0112 #endif