1 /*
2  * DataFile.h - class for reading and writing LMMS data files
3  *
4  * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5  * Copyright (c) 2012-2013 Paul Giblock <p/at/pgiblock.net>
6  *
7  * This file is part of LMMS - https://lmms.io
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public
20  * License along with this program (see COPYING); if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301 USA.
23  *
24  */
25 
26 
27 #ifndef DATA_FILE_H
28 #define DATA_FILE_H
29 
30 #include <QDomDocument>
31 
32 #include "export.h"
33 #include "MemoryManager.h"
34 
35 class QTextStream;
36 
37 class EXPORT DataFile : public QDomDocument
38 {
39 	MM_OPERATORS
40 public:
41 	enum Types
42 	{
43 		UnknownType,
44 		SongProject,
45 		SongProjectTemplate,
46 		InstrumentTrackSettings,
47 		DragNDropData,
48 		ClipboardData,
49 		JournalData,
50 		EffectSettings,
51 		TypeCount
52 	} ;
53 	typedef Types Type;
54 
55 	DataFile( const QString& fileName );
56 	DataFile( const QByteArray& data );
57 	DataFile( Type type );
58 
59 	virtual ~DataFile();
60 
61 	///
62 	/// \brief validate
63 	/// performs basic validation, compared to file extension.
64 	///
65 	bool validate( QString extension );
66 
67 	QString nameWithExtension( const QString& fn ) const;
68 
69 	void write( QTextStream& strm );
70 	bool writeFile( const QString& fn );
71 
content()72 	QDomElement& content()
73 	{
74 		return m_content;
75 	}
76 
head()77 	QDomElement& head()
78 	{
79 		return m_head;
80 	}
81 
type()82 	Type type() const
83 	{
84 		return m_type;
85 	}
86 
87 private:
88 	static Type type( const QString& typeName );
89 	static QString typeName( Type type );
90 
91 	void cleanMetaNodes( QDomElement de );
92 
93 	// helper upgrade routines
94 	void upgrade_0_2_1_20070501();
95 	void upgrade_0_2_1_20070508();
96 	void upgrade_0_3_0_rc2();
97 	void upgrade_0_3_0();
98 	void upgrade_0_4_0_20080104();
99 	void upgrade_0_4_0_20080118();
100 	void upgrade_0_4_0_20080129();
101 	void upgrade_0_4_0_20080409();
102 	void upgrade_0_4_0_20080607();
103 	void upgrade_0_4_0_20080622();
104 	void upgrade_0_4_0_beta1();
105 	void upgrade_0_4_0_rc2();
106 	void upgrade_1_0_99();
107 	void upgrade_1_1_0();
108 	void upgrade_1_1_91();
109 	void upgrade_1_2_0_rc3();
110 	void upgrade_1_2_0_rc2_42();
111 
112 	void upgrade();
113 
114 	void loadData( const QByteArray & _data, const QString & _sourceFile );
115 
116 
117 	struct EXPORT typeDescStruct
118 	{
119 		Type m_type;
120 		QString m_name;
121 	} ;
122 	static typeDescStruct s_types[TypeCount];
123 
124 	QDomElement m_content;
125 	QDomElement m_head;
126 	Type m_type;
127 
128 } ;
129 
130 
131 const int LDF_MAJOR_VERSION = 1;
132 const int LDF_MINOR_VERSION = 0;
133 const QString LDF_VERSION_STRING = QString::number( LDF_MAJOR_VERSION ) + "." + QString::number( LDF_MINOR_VERSION );
134 
135 
136 #endif
137 
138