Blame synfig-core/src/synfig/filesystemtemporary.h

a61c48
/* === S Y N F I G ========================================================= */
a61c48
/*!	\file filesystemtemporary.h
a61c48
**	\brief FileSystemTemporary Header
a61c48
**
a61c48
**	$Id$
a61c48
**
a61c48
**	\legal
a61c48
**	......... ... 2016 Ivan Mahonin
a61c48
**
a61c48
**	This package is free software; you can redistribute it and/or
a61c48
**	modify it under the terms of the GNU General Public License as
a61c48
**	published by the Free Software Foundation; either version 2 of
a61c48
**	the License, or (at your option) any later version.
a61c48
**
a61c48
**	This package is distributed in the hope that it will be useful,
a61c48
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
a61c48
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a61c48
**	General Public License for more details.
a61c48
**	\endlegal
a61c48
*/
a61c48
/* ========================================================================= */
a61c48
a61c48
/* === S T A R T =========================================================== */
a61c48
a61c48
#ifndef __SYNFIG_FILESYSTEMTEMPORARY_H
a61c48
#define __SYNFIG_FILESYSTEMTEMPORARY_H
a61c48
a61c48
/* === H E A D E R S ======================================================= */
a61c48
a61c48
#include <map></map>
a61c48
#include <set></set>
a61c48
a61c48
#include "filesystemnative.h"
a61c48
a61c48
/* === M A C R O S ========================================================= */
a61c48
a61c48
/* === T Y P E D E F S ===================================================== */
a61c48
a61c48
/* === C L A S S E S & S T R U C T S ======================================= */
a61c48
a61c48
namespace xmlpp { class Node; }
a61c48
a61c48
namespace synfig
a61c48
{
a61c48
a61c48
	class FileSystemTemporary: public FileSystem
a61c48
	{
a61c48
	public:
a61c48
		typedef etl::handle<filesystemtemporary> Handle;</filesystemtemporary>
a61c48
a61c48
	private:
a61c48
		struct FileInfo
a61c48
		{
a61c48
			String name;
a61c48
			String tmp_filename;
a61c48
			bool is_directory;
a61c48
			bool is_removed;
a61c48
a61c48
			inline FileInfo(): is_directory(false), is_removed(false) { }
a61c48
		};
a61c48
a61c48
		typedef std::map<string, fileinfo=""> FileMap;</string,>
a61c48
a61c48
		FileMap files;
a61c48
a61c48
		FileSystemNative::Handle file_system;
a61c48
		FileSystem::Handle sub_file_system;
a61c48
0dde72
		String tag;
0dde72
		String temporary_directory;
a61c48
		String temporary_filename_base;
a61c48
a61c48
		std::map<string, string=""> meta;</string,>
a61c48
e03d87
		bool keep_files_when_destroyed;
a61c48
		bool autosave;
a61c48
a61c48
		static bool save_changes(
a61c48
			const FileSystemNative::Handle &file_system,
a61c48
			const FileSystem::Handle &target_file_system,
a61c48
			FileMap &files,
a61c48
			bool remove_files);
a61c48
0dde72
		bool create_temporary_directory() const;
a61c48
		bool autosave_temporary() const;
a61c48
a61c48
		static String get_xml_node_text(xmlpp::Node *node);
a61c48
a61c48
	public:
0dde72
		explicit FileSystemTemporary(const String &tag, const String &temporary_directory = String(), const FileSystem::Handle &sub_file_system = FileSystem::Handle());
a61c48
		~FileSystemTemporary();
a61c48
a61c48
		virtual bool is_file(const String &filename);
a61c48
		virtual bool is_directory(const String &filename);
a61c48
a61c48
		virtual bool directory_create(const String &dirname);
a61c48
		virtual bool directory_scan(const String &dirname, FileList &out_files);
a61c48
a61c48
		virtual bool file_remove(const String &filename);
a61c48
		virtual FileSystem::ReadStream::Handle get_read_stream(const String &filename);
a61c48
		virtual FileSystem::WriteStream::Handle get_write_stream(const String &filename);
a61c48
		virtual String get_real_uri(const String &filename);
a61c48
a61c48
		const FileSystem::Handle& get_sub_file_system() const
0a453e
			{ return sub_file_system; }
a61c48
		void set_sub_file_system(const FileSystem::Handle &file_system)
0a453e
			{ this->sub_file_system = file_system; }
a61c48
0dde72
		bool empty() const { return files.empty(); }
a61c48
a61c48
		bool save_changes(const FileSystem::Handle &sub_file_system, bool as_copy);
a61c48
		bool save_changes_copy(const FileSystem::Handle &sub_file_system) const;
a61c48
		bool save_changes();
a61c48
		void discard_changes();
a61c48
0dde72
		const String& get_tag() const { return tag; }
0dde72
		const String& get_temporary_directory() const { return temporary_directory; }
a61c48
		const String& get_temporary_filename_base() const { return temporary_filename_base; }
0dde72
		void reset_temporary_filename_base() { reset_temporary_filename_base(get_tag(), get_temporary_directory()); }
0dde72
		void reset_temporary_filename_base(const String &tag, const String &temporary_directory);
a61c48
a61c48
		String get_meta(const String &key) const;
0a453e
		void set_meta(const String &key, const String &value);
a61c48
		void clear_meta();
a61c48
a61c48
		const std::map<string, string="">& get_metadata() const;</string,>
a61c48
		void set_metadata(const std::map<string, string=""> &data);</string,>
a61c48
e03d87
		void set_keep_files_when_destroyed(bool value)
e03d87
			{ keep_files_when_destroyed = value; }
a61c48
		bool get_autosave() const
a61c48
			{ return autosave; }
a61c48
		void set_autosave(bool value)
a61c48
			{ autosave = value; }
a61c48
a61c48
		bool save_temporary() const;
0dde72
		bool open_temporary(const String &filename);
a61c48
0dde72
		static String get_system_temporary_directory();
0dde72
		static String generate_temporary_filename_base(const String &tag);
0dde72
		static String generate_system_temporary_filename(const String &tag);
a61c48
		static String generate_indexed_temporary_filename(const FileSystem::Handle &fs, const String &filename);
0dde72
		static bool scan_temporary_directory(const String &tag, FileList &out_files, const String &dirname = String());
a61c48
	};
a61c48
a61c48
}
a61c48
a61c48
/* === E N D =============================================================== */
a61c48
a61c48
#endif