DataFile.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef DATA_FILE_H
  26. #define DATA_FILE_H
  27. #include <QDomDocument>
  28. #include "lmms_export.h"
  29. #include "MemoryManager.h"
  30. class QTextStream;
  31. class LMMS_EXPORT DataFile : public QDomDocument
  32. {
  33. MM_OPERATORS
  34. public:
  35. enum Types
  36. {
  37. UnknownType,
  38. SongProject,
  39. SongProjectTemplate,
  40. InstrumentTrackSettings,
  41. DragNDropData,
  42. ClipboardData,
  43. JournalData,
  44. EffectSettings,
  45. TypeCount
  46. } ;
  47. typedef Types Type;
  48. DataFile( const QString& fileName );
  49. DataFile( const QByteArray& data );
  50. DataFile( Type type );
  51. virtual ~DataFile();
  52. ///
  53. /// \brief validate
  54. /// performs basic validation, compared to file extension.
  55. ///
  56. bool validate( QString extension );
  57. QString nameWithExtension( const QString& fn ) const;
  58. void write( QTextStream& strm );
  59. bool writeFile( const QString& fn );
  60. QDomElement& content()
  61. {
  62. return m_content;
  63. }
  64. QDomElement& head()
  65. {
  66. return m_head;
  67. }
  68. Type type() const
  69. {
  70. return m_type;
  71. }
  72. private:
  73. static Type type( const QString& typeName );
  74. static QString typeName( Type type );
  75. void cleanMetaNodes( QDomElement de );
  76. // helper upgrade routines
  77. void upgrade_0_2_1_20070501();
  78. void upgrade_0_2_1_20070508();
  79. void upgrade_0_3_0_rc2();
  80. void upgrade_0_3_0();
  81. void upgrade_0_4_0_20080104();
  82. void upgrade_0_4_0_20080118();
  83. void upgrade_0_4_0_20080129();
  84. void upgrade_0_4_0_20080409();
  85. void upgrade_0_4_0_20080607();
  86. void upgrade_0_4_0_20080622();
  87. void upgrade_0_4_0_beta1();
  88. void upgrade_0_4_0_rc2();
  89. void upgrade_1_0_99();
  90. void upgrade_1_1_0();
  91. void upgrade_1_1_91();
  92. void upgrade_1_2_0_rc3();
  93. void upgrade_1_2_0_rc2_42();
  94. void upgrade_1_3_0();
  95. void upgrade();
  96. void loadData( const QByteArray & _data, const QString & _sourceFile );
  97. struct LMMS_EXPORT typeDescStruct
  98. {
  99. Type m_type;
  100. QString m_name;
  101. } ;
  102. static typeDescStruct s_types[TypeCount];
  103. QDomElement m_content;
  104. QDomElement m_head;
  105. Type m_type;
  106. } ;
  107. const int LDF_MAJOR_VERSION = 1;
  108. const int LDF_MINOR_VERSION = 0;
  109. const QString LDF_VERSION_STRING = QString::number( LDF_MAJOR_VERSION ) + "." + QString::number( LDF_MINOR_VERSION );
  110. #endif