ImportFilter.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * ImportFilter.h - declaration of class ImportFilter, the base-class for all
  3. * file import filters
  4. *
  5. * Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.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 IMPORT_FILTER_H
  26. #define IMPORT_FILTER_H
  27. #include <QtCore/QFile>
  28. #include "Plugin.h"
  29. class TrackContainer;
  30. class LMMS_EXPORT ImportFilter : public Plugin
  31. {
  32. public:
  33. ImportFilter( const QString & _file_name,
  34. const Descriptor * _descriptor );
  35. virtual ~ImportFilter();
  36. // tries to import given file to given track-container by having all
  37. // available import-filters to try to import the file
  38. static void import( const QString & _file_to_import,
  39. TrackContainer* tc );
  40. protected:
  41. virtual bool tryImport( TrackContainer* tc ) = 0;
  42. const QFile & file() const
  43. {
  44. return m_file;
  45. }
  46. bool openFile();
  47. inline void closeFile()
  48. {
  49. m_file.close();
  50. }
  51. inline int readByte()
  52. {
  53. unsigned char c;
  54. if( m_file.getChar( (char*) &c ) )
  55. {
  56. return static_cast<int>( c );
  57. }
  58. return -1;
  59. }
  60. inline int readBlock( char * _data, int _len )
  61. {
  62. return m_file.read( _data, _len );
  63. }
  64. inline QByteArray readAllData()
  65. {
  66. m_file.seek(0);
  67. return m_file.readAll();
  68. }
  69. inline void ungetChar( char _ch )
  70. {
  71. m_file.ungetChar( _ch );
  72. }
  73. void saveSettings( QDomDocument &, QDomElement & ) override
  74. {
  75. }
  76. void loadSettings( const QDomElement & ) override
  77. {
  78. }
  79. QString nodeName() const override
  80. {
  81. return "import_filter";
  82. }
  83. private:
  84. QFile m_file;
  85. } ;
  86. #endif