File indexing completed on 2024-05-19 05:50:49
0001 /* 0002 SPDX-FileCopyrightText: 2011 Raphael Kubo da Costa <rakuco@FreeBSD.org> 0003 0004 SPDX-License-Identifier: BSD-2-Clause 0005 */ 0006 0007 #ifndef JSONPARSER_H 0008 #define JSONPARSER_H 0009 0010 #include "archiveentry.h" 0011 0012 #include <QIODevice> 0013 #include <QMap> 0014 0015 /** 0016 * Simple parser which reads JSON files and creates @c ArchiveEntry objects 0017 * from it. 0018 * 0019 * The JSON file is expected to follow a specific format that describes an 0020 * archive read by Kerfuffle. 0021 * 0022 * The format consists of a list of dictionaries whose keys are values from the 0023 * EntryMetaDataType enum. The only required key for each entry is FileName; 0024 * other values which are omitted for each entry are assumed to be 0 or false. 0025 * 0026 * Example file: 0027 * @code 0028 * [ 0029 * { "fullPath": "foo", "IsPasswordProtected": true }, 0030 * { "fullPath": "aDir/", "IsDirectory": true } 0031 * ] 0032 * @endcode 0033 * 0034 * @author Raphael Kubo da Costa <rakuco@FreeBSD.org> 0035 */ 0036 class JSONParser 0037 { 0038 public: 0039 typedef QMap<QString, Kerfuffle::Archive::Entry *> JSONArchive; 0040 0041 ~JSONParser(); 0042 0043 static JSONArchive parse(QIODevice *json); 0044 0045 private: 0046 JSONParser(); 0047 0048 /** 0049 * Parses each entry in the QVariant obtained from parsing a JSON file and 0050 * creates a @c JSONArchive from them. 0051 * 0052 * If an entry does not have a "fullPath" key, it is ignored. Keys which do 0053 * not correspond to a value in the EntryMetaDataType enum are ignored. 0054 * 0055 * @return A new @c JSONArchive corresponding to the parsed JSON file. If a 0056 * parsing error occurs, it is empty. 0057 */ 0058 static JSONArchive createJSONArchive(const QVariant &json); 0059 }; 0060 0061 #endif // JSONPARSER_H