File indexing completed on 2024-04-28 16:08:39

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2014 by Linuxstopmotion contributors;              *
0003  *   see the AUTHORS file for details.                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef PROJECTSERIALIZER_H
0022 #define PROJECTSERIALIZER_H
0023 
0024 #include <libxml/tree.h>
0025 
0026 #include <exception>
0027 #include <vector>
0028 
0029 class AnimationImpl;
0030 class Scene;
0031 class Frontend;
0032 
0033 class FileException : public std::exception {
0034     char buffer[100];
0035 public:
0036     FileException(const char* functionName, int errorno);
0037     const char* what() const throw();
0038 };
0039 
0040 /**
0041  * Class for serializing the project.
0042  */
0043 class ProjectSerializer {
0044 public:
0045     ProjectSerializer();
0046     ~ProjectSerializer();
0047 
0048     /**
0049      * Opens the project's model ({@c .dat}) file.
0050      * @param [out] out A vector to be filled with the scenes stored in the
0051      * project file, if the function is successful.
0052      * @param filename The model file.
0053      * @return {@c true} if successful, {@c false} otherwise.
0054      */
0055     static bool openDat(std::vector<Scene*>& out, const char* filename);
0056 
0057     /**
0058      * Creates necessary project paths and opens the project ({@c .sto}) file.
0059      * @param filename The project file
0060      * @return A vector containing the scenes stored in the project file.
0061      */
0062     std::vector<Scene*> openSto(const char *filename);
0063 
0064     /**
0065      * Saves the files in a tarball with the name {@a filename} plus the
0066      * {@c .sto} extension.
0067      * @param filename the project file to store the files within
0068      * @param scenes the scenes to be saved
0069      * @param frontend the frontend to display progress to
0070      */
0071     void save(const char *filename, const AnimationImpl& scenes,
0072             Frontend *frontend);
0073 
0074     /**
0075      * Retrieves the project file.
0076      * @return the project path if it exist, NULL otherwise. Ownership is not
0077      * returned.
0078      */
0079     const char* getProjectFile();
0080 
0081     /**
0082      * After this call (and until a subsequent call to {@ref save} or
0083      * {@ref openSto}) {@ref getProjectFile} will return a null pointer.
0084      */
0085     void resetProjectFile();
0086 
0087     /**
0088      * After this call (and until a subsequent call to {@ref save} or
0089      * {@ref openSto}) {@ref getProjectFile} will return a string equal to
0090      * {@a filename}.
0091      * @param filename The new file name to set. Ownership is not passed. A
0092      * copy is taken, so the contents of the string need not be preserved. If
0093      * null is passed, {@ref getProjectFile} will subsequently return null.
0094      */
0095     void resetProjectFile(const char* filename);
0096 
0097 private:
0098     char* projectFile;
0099     void setAttributes(xmlNodePtr rootNode,
0100             const AnimationImpl& anim, Frontend *frontend);
0101     static void getAttributes(xmlNodePtr node, std::vector<Scene*>& scenes);
0102     void saveDOMToFile(xmlDocPtr doc, const char* filename);
0103     void setProjectFile(const char *filename);
0104 };
0105 
0106 #endif