File indexing completed on 2024-09-29 13:18:15
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2006 by Sébastien Laoût <slaout@linux62.org> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef ARCHIVE_H 0007 #define ARCHIVE_H 0008 0009 #include "basket_export.h" 0010 0011 #include <QtCore/QList> 0012 #include <QtCore/QMap> 0013 0014 class BasketScene; 0015 class Tag; 0016 0017 class QString; 0018 class QStringList; 0019 class QDomNode; 0020 class QProgressDialog; 0021 class QDomElement; 0022 0023 class KTar; 0024 class KProgress; 0025 0026 /** 0027 * @author Sébastien Laoût <slaout@linux62.org> 0028 */ 0029 class Archive 0030 { 0031 public: 0032 static void save(BasketScene *basket, bool withSubBaskets, const QString &destination); 0033 static void open(const QString &path); 0034 0035 /** 0036 * @brief The IOErrorCode enum granularly indicates whether encoding or decoding of baskets archive succeded 0037 */ 0038 enum class IOErrorCode : quint8 { 0039 NoError, 0040 NotABasketArchive, 0041 CorruptedBasketArchive, 0042 DestinationExists, 0043 IncompatibleBasketVersion, 0044 PossiblyCompatibleBasketVersion, 0045 FailedToOpenResource, 0046 }; 0047 0048 /** 0049 * @brief extractArchive decodes .baskets files 0050 * @param path to the .baskets file 0051 * @param destination into which the basket archive should be extracted 0052 * @param protectDestination decides whether the destination will be replaced if it has been present 0053 * \todo protectDestination likely should be an enum, too, to be more descriptive 0054 * @return NoError indicates a sucessful extraction. All other enum states indicate something went wrong 0055 */ 0056 BASKET_EXPORT static IOErrorCode extractArchive(const QString &path, const QString &destination, const bool protectDestination = true); 0057 0058 /** 0059 * @brief createArchiveFromSource encodes a basket directory into a .baskets file 0060 * 0061 * Be aware, this function currently does not validate the sourcePath's structure. The caller of this function needs to make sure the basket directory is a valid source. 0062 * 0063 * @param sourcePath specifies the directory to be encoded 0064 * @param previewImage specifies an optional .png image 0065 * @param destination specifies where the encoded .basket file should be saved 0066 * @param protectDestination decides whether the destination will be replaced if it has been present 0067 * @return NoError indicates a sucessful extraction. All other enum states indicate something went wrong 0068 */ 0069 BASKET_EXPORT static IOErrorCode createArchiveFromSource(const QString &sourcePath, const QString &previewImage, const QString &destination = QString(), const bool protectDestination = true); 0070 0071 private: 0072 // Convenient Methods for Saving: 0073 static void saveBasketToArchive(BasketScene *basket, bool recursive, KTar *tar, QStringList &backgrounds, const QString &tempFolder, QProgressDialog *progress); 0074 static void listUsedTags(BasketScene *basket, bool recursive, QList<Tag *> &list); 0075 // Convenient Methods for Loading: 0076 static void renameBasketFolders(const QString &extractionFolder, QMap<QString, QString> &mergedStates); 0077 static void renameBasketFolder(const QString &extractionFolder, QDomNode &basketNode, QMap<QString, QString> &folderMap, QMap<QString, QString> &mergedStates); 0078 static void renameMergedStatesAndBasketIcon(const QString &fullPath, QMap<QString, QString> &mergedStates, const QString &extractionFolder); 0079 static void renameMergedStates(QDomNode notes, QMap<QString, QString> &mergedStates); 0080 static void importBasketIcon(QDomElement properties, const QString &extractionFolder); 0081 static void loadExtractedBaskets(const QString &extractionFolder, QDomNode &basketNode, QMap<QString, QString> &folderMap, BasketScene *parent); 0082 static void importTagEmblems(const QString &extractionFolder); 0083 static void importArchivedBackgroundImages(const QString &extractionFolder); 0084 }; 0085 0086 #endif