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: 2009 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_CHECKSUMTOOL_HPP 0010 #define KASTEN_CHECKSUMTOOL_HPP 0011 0012 // Kasten core 0013 #include <Kasten/AbstractTool> 0014 // Okteta core 0015 #include <Okteta/AddressRange> 0016 // Qt 0017 #include <QVector> 0018 0019 class AbstractByteArrayChecksumParameterSet; 0020 class AbstractByteArrayChecksumAlgorithm; 0021 0022 namespace Okteta { 0023 class AbstractByteArrayModel; 0024 } 0025 0026 namespace Kasten { 0027 0028 class ByteArrayView; 0029 0030 class ChecksumTool : public AbstractTool 0031 { 0032 Q_OBJECT 0033 0034 private: 0035 static inline constexpr char ConfigGroupId[] = "ChecksumTool"; 0036 static inline constexpr char AlgorithmConfigKey[] = "Algorithm"; 0037 0038 public: 0039 ChecksumTool(); 0040 ~ChecksumTool() override; 0041 0042 public: // AbstractTool API 0043 // virtual AbstractModel* targetModel() const; 0044 QString title() const override; 0045 0046 void setTargetModel(AbstractModel* model) override; 0047 0048 public: // status 0049 QString checkSum() const; 0050 int algorithmId() const; 0051 bool isApplyable() const; // candidate for AbstractTool API 0052 bool isUptodate() const; 0053 0054 QVector<AbstractByteArrayChecksumAlgorithm*> algorithmList() const; 0055 0056 public: 0057 AbstractByteArrayChecksumParameterSet* parameterSet(); 0058 0059 public Q_SLOTS: // actions 0060 void calculateChecksum(); 0061 0062 void setAlgorithm(int algorithmId); 0063 // TODO: hack, see checksum source 0064 void resetSourceTool(); 0065 0066 Q_SIGNALS: 0067 void algorithmChanged(int algorithmId); 0068 void checksumChanged(const QString& checksum); 0069 void uptodateChanged(bool isUptodate); 0070 void isApplyableChanged(bool isApplyable); // candidate for AbstractTool API 0071 0072 private: 0073 void checkUptoDate(); 0074 0075 private Q_SLOTS: 0076 void onSelectionChanged(); 0077 void onSourceChanged(); 0078 void onSourceDestroyed(); 0079 0080 private: // created data 0081 QString mCheckSum; 0082 bool mChecksumUptodate : 1; 0083 bool mSourceByteArrayModelUptodate : 1; 0084 0085 private: // settings 0086 QVector<AbstractByteArrayChecksumAlgorithm*> mAlgorithmList; 0087 int mAlgorithmId = 0; 0088 0089 private: // sources 0090 ByteArrayView* mByteArrayView = nullptr; 0091 // current 0092 Okteta::AbstractByteArrayModel* mByteArrayModel = nullptr; 0093 0094 int mSourceAlgorithmId = -1; 0095 Okteta::AddressRange mSourceSelection; 0096 Okteta::AbstractByteArrayModel* mSourceByteArrayModel = nullptr; 0097 }; 0098 0099 inline int ChecksumTool::algorithmId() const { return mAlgorithmId; } 0100 inline QString ChecksumTool::checkSum() const { return mCheckSum; } 0101 inline bool ChecksumTool::isUptodate() const { return mChecksumUptodate; } 0102 0103 } 0104 0105 #endif