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(QString sFilenNme);
43  Status save(const Object*, 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  void unzip(const QString& strZipFile, const QString& strUnzipTarget);
59 
60  bool loadObject(Object*, const QDomElement& root);
61  bool loadObjectOldWay(Object*, const QDomElement& root);
62  bool isOldForamt(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& mainXml, QStringList& filesWritten);
66  Status writePalette(const Object* obj, const QString& dataFolder, QStringList& filesWritten);
67 
68  ObjectData* loadProjectData(const QDomElement& element);
69  QDomElement saveProjectData(ObjectData*, QDomDocument& xmlDoc);
70 
71  void extractProjectData(const QDomElement& element, ObjectData* data);
72  Object* cleanUpWithErrorCode(Status);
73 
74  QString backupPreviousFile(const QString& fileName);
75  void deleteBackupFile(const QString& fileName);
76 
77  void progressForward();
78 
79 private: // Project recovery
80  bool isProjectRecoverable(const QString& projectFolder);
81  Status recoverObject(Object* object);
82  Status rebuildMainXML(Object* object);
84  const int layerIndex, const QStringList& frames);
85  QString recoverLayerName(Layer::LAYER_TYPE, int index);
86  int layerIndexFromFilename(const QString& filename);
87  int framePosFromFilename(const QString& filename);
88 
89 private:
90  Status mError = Status::OK;
91  QString mstrLastTempFolder;
92 
93  int mCurrentProgress = 0;
94  int mMaxProgressValue = 100;
95 };
96 
97 #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:54
Status rebuildMainXML(Object *object)
Create a new main.xml based on the png/vec filenames left in the data folder.
QObject * parent() const const