All Classes Namespaces Functions Variables Enumerations Properties Pages
filemanager.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #ifndef OBJECTSAVELOADER_H
19 #define OBJECTSAVELOADER_H
20 
21 
22 #include <QObject>
23 #include <QString>
24 #include <QDomElement>
25 #include "log.h"
26 #include "pencildef.h"
27 #include "pencilerror.h"
28 #include "colorref.h"
29 #include "layer.h"
30 
31 class Object;
32 class ObjectData;
33 
34 
35 class FileManager : public QObject
36 {
37  Q_OBJECT
38 
39 public:
41 
42  Object* load(const QString& sFilenNme);
43  Status save(const Object*, const QString& sFileName);
44  Status writeToWorkingFolder(const Object*);
45 
46  QList<ColorRef> loadPaletteFile(QString strFilename);
47  Status error() const { return mError; }
48  Status verifyObject(Object* obj);
49 
50  QStringList searchForUnsavedProjects();
51  Object* recoverUnsavedProject(QString projectIntermediatePath);
52 
53 signals:
54  void progressChanged(int progress);
55  void progressRangeChanged(int maxValue);
56 
57 private:
58  Status unzip(const QString& strZipFile, const QString& strUnzipTarget);
59 
60  bool loadObject(Object*, const QDomElement& root);
61  bool loadObjectOldWay(Object*, const QDomElement& root);
62  bool isArchiveFormat(const QString& fileName) const;
63  bool loadPalette(Object*);
64  Status writeKeyFrameFiles(const Object* obj, const QString& dataFolder, QStringList& filesWritten);
65  Status writeMainXml(const Object* obj, const QString& mainXmlPath, QStringList& filesWritten);
66  Status writePalette(const Object* obj, const QString& dataFolder, QStringList& filesWritten);
67 
68  ObjectData loadProjectData(const QDomElement& element);
69  QDomElement saveProjectData(const ObjectData*, QDomDocument& xmlDoc);
70 
71  void extractProjectData(const QDomElement& element, ObjectData& data);
72  void handleOpenProjectError(Status::ErrorCode, const DebugDetails&);
73 
74  QString backupPreviousFile(const QString& fileName);
75  void deleteBackupFile(const QString& fileName);
76  int countExistingBackups(const QString& fileName) const;
77 
78  void progressForward();
79 
80 private: // Project recovery
81  bool isProjectRecoverable(const QString& projectFolder);
82  Status recoverObject(Object* object);
83  Status rebuildMainXML(Object* object);
85  const int layerIndex, const QStringList& frames);
86  QString recoverLayerName(Layer::LAYER_TYPE, int index);
87  int layerIndexFromFilename(const QString& filename);
88  int framePosFromFilename(const QString& filename);
89 
90 private:
91  Status mError = Status::OK;
92  QString mstrLastTempFolder;
93 
94  int mCurrentProgress = 0;
95  int mMaxProgressValue = 100;
96 };
97 
98 #endif // OBJECTSAVELOADER_H
Q_OBJECTQ_OBJECT
Status rebuildLayerXmlTag(QDomDocument &doc, QDomElement &elemObject, const int layerIndex, const QStringList &frames)
Rebuild a layer xml tag.
Definition: object.h:41
Status rebuildMainXML(Object *object)
Create a new main.xml based on the png/vec filenames left in the data folder.
QObject * parent() const const