File indexing completed on 2024-05-12 15:55:23

0001 // SPDX-FileCopyrightText: 2006-2013 Jesper K. Pedersen <jesper.pedersen@kdab.com>
0002 // SPDX-FileCopyrightText: 2007 Dirk Mueller <mueller@kde.org>
0003 // SPDX-FileCopyrightText: 2008 Jan Kundrát <jkt@flaska.net>
0004 // SPDX-FileCopyrightText: 2009 Henner Zeller <h.zeller@acm.org>
0005 // SPDX-FileCopyrightText: 2013-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0006 // SPDX-FileCopyrightText: 2014-2015 Tobias Leupold <tl@stonemx.de>
0007 //
0008 // SPDX-License-Identifier: GPL-2.0-or-later
0009 
0010 #ifndef XMLDB_FILEREADER_H
0011 #define XMLDB_FILEREADER_H
0012 
0013 #include "XmlReader.h"
0014 
0015 #include <DB/ImageInfo.h>
0016 #include <DB/ImageInfoPtr.h>
0017 
0018 #include <QSharedPointer>
0019 
0020 class QXmlStreamReader;
0021 
0022 namespace DB
0023 {
0024 class ImageDB;
0025 
0026 class FileReader
0027 {
0028 
0029 public:
0030     FileReader(DB::ImageDB *db)
0031         : m_db(db)
0032         , m_fileVersion(0)
0033         , m_nextStackId(1)
0034     {
0035     }
0036     void read(const QString &configFile);
0037     static QString unescape(const QString &);
0038     DB::StackID nextStackId() const { return m_nextStackId; }
0039 
0040 protected:
0041     void loadCategories(ReaderPtr reader);
0042     void loadImages(ReaderPtr reader);
0043     void loadBlockList(ReaderPtr reader);
0044     void loadMemberGroups(ReaderPtr reader);
0045     // void loadSettings(ReaderPtr reader);
0046     void loadGlobalSortOrder(ReaderPtr reader);
0047 
0048     DB::ImageInfoPtr load(const DB::FileName &filename, ReaderPtr reader);
0049     ReaderPtr readConfigFile(const QString &configFile);
0050 
0051     void createSpecialCategories();
0052 
0053     void checkIfImagesAreSorted();
0054     void checkIfAllImagesHaveSizeAttributes();
0055 
0056     /**
0057      * @brief Repair the database if an issue was flagged for repair.
0058      * DB repairs that only require local knowledge are usually done in the respective
0059      * load* method. This method is called after the database file was loaded.
0060      *
0061      * Currently, this tries to fix the following issues:
0062      *
0063      * - Bug #415415 - Renaming tag groups can produce tags with id=0
0064      */
0065     void repairDB();
0066 
0067 private:
0068     DB::ImageDB *const m_db;
0069     int m_fileVersion;
0070     DB::StackID m_nextStackId;
0071 
0072     // During profilation I found that it was rather expensive to look this up over and over again (once for each image)
0073     DB::CategoryPtr m_folderCategory;
0074     /// Flag indicating that repair is necessary
0075     bool m_repairTagsWithNullIds = false;
0076 };
0077 
0078 }
0079 
0080 #endif /* XMLDB_FILEREADER_H */
0081 
0082 // vi:expandtab:tabstop=4 shiftwidth=4: