File indexing completed on 2024-04-28 04:57:30
0001 /*************************************************************************** 0002 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0018 ***************************************************************************/ 0019 0020 #ifndef CHECKSUMSEARCH_H 0021 #define CHECKSUMSEARCH_H 0022 0023 #include <QObject> 0024 0025 #include <KIO/TransferJob> 0026 0027 #include <QUrl> 0028 0029 class ChecksumSearch : public QObject 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 ChecksumSearch(const QList<QUrl> &srcs, const QString &fileName, const QStringList &types, QObject *parent = nullptr); 0035 ~ChecksumSearch() override; 0036 0037 /** 0038 * Used to define in whiche way the url should be changed to try and find 0039 * Checksums 0040 */ 0041 enum UrlChangeMode { 0042 kg_Append, /// Appends the QString to the Url --> "http://test.com/aFile.zip"; ".md5" "http://test.com/aFile.zip.md5" 0043 kg_ReplaceFile, /// Replaces the file of the Url with QString --> "http://test.com/aFile.zip"; "MD5SUMS" "http://test.com/MD5SUMS" 0044 kg_ReplaceEnding /// Only replaces the file ending of the Url with QString --> "http://test.com/aFile.zip"; "-CHECKSUM" "http://test.com/aFile-CHECKSUM" 0045 }; 0046 0047 /** 0048 * Returns the available mode-names. The order of the Stringlist is the same as in the enum 0049 */ 0050 static QStringList urlChangeModes() 0051 { 0052 return URLCHANGEMODES; 0053 } 0054 0055 /** 0056 * Returns a modified url according to the parameters 0057 * @param src the url to modify 0058 * @param change the string containing the change e.g. ".md5" 0059 * @param mode the mode of the change e.g. Append 0060 */ 0061 static QUrl createUrl(const QUrl &src, const QString &change, UrlChangeMode mode); 0062 0063 Q_SIGNALS: 0064 void data(QString type, QString checksum); 0065 0066 private Q_SLOTS: 0067 void slotResult(KJob *job); 0068 void slotData(KIO::Job *job, const QByteArray &data); 0069 0070 private: 0071 /** 0072 * Creates a download 0073 */ 0074 void createDownload(); 0075 0076 /** 0077 * Parses the download 0078 */ 0079 void parseDownload(); 0080 0081 /** 0082 * Parses the download when no type has been specified 0083 */ 0084 void parseDownloadEmpty(); 0085 0086 private: 0087 KIO::TransferJob *m_copyJob; 0088 QUrl m_src; 0089 QList<QUrl> m_srcs; 0090 QString m_fileName; 0091 QString m_type; 0092 QStringList m_types; 0093 QByteArray m_dataBA; 0094 QString m_data; 0095 bool m_isEmpty; 0096 static const QStringList URLCHANGEMODES; 0097 }; 0098 0099 #endif