/src/musicscanner.h

http://github.com/tomahawk-player/tomahawk · C Header · 126 lines · 79 code · 25 blank · 22 comment · 0 complexity · f4dd48ad42221a01d4594727d6132e3d MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef MUSICSCANNER_H
  19. #define MUSICSCANNER_H
  20. #include "tomahawksettings.h"
  21. #include "database/databasecommand.h"
  22. /* taglib */
  23. #include <taglib/fileref.h>
  24. #include <taglib/tag.h>
  25. #include <QtCore/QVariantMap>
  26. #include <QtCore/QDir>
  27. #include <QtCore/QFileInfo>
  28. #include <QtCore/QString>
  29. #include <QtCore/QDateTime>
  30. #include <QtCore/QTimer>
  31. #include <QtCore/QMutex>
  32. #include <QtCore/QMutexLocker>
  33. #include <QtCore/QWeakPointer>
  34. #include <database/database.h>
  35. // descend dir tree comparing dir mtimes to last known mtime
  36. // emit signal for any dir with new content, so we can scan it.
  37. // finally, emit the list of new mtimes we observed.
  38. class DirLister : public QObject
  39. {
  40. Q_OBJECT
  41. public:
  42. DirLister( const QStringList& dirs )
  43. : QObject(), m_dirs( dirs ), m_opcount( 0 ), m_deleting( false )
  44. {
  45. qDebug() << Q_FUNC_INFO;
  46. }
  47. ~DirLister()
  48. {
  49. qDebug() << Q_FUNC_INFO;
  50. }
  51. bool isDeleting() { QMutexLocker locker( &m_deletingMutex ); return m_deleting; };
  52. void setIsDeleting() { QMutexLocker locker( &m_deletingMutex ); m_deleting = true; };
  53. signals:
  54. void fileToScan( QFileInfo );
  55. void finished();
  56. private slots:
  57. void go();
  58. void scanDir( QDir dir, int depth );
  59. private:
  60. QStringList m_dirs;
  61. uint m_opcount;
  62. QMutex m_deletingMutex;
  63. bool m_deleting;
  64. };
  65. class MusicScanner : public QObject
  66. {
  67. Q_OBJECT
  68. public:
  69. MusicScanner( const QStringList& dirs, quint32 bs = 0 );
  70. ~MusicScanner();
  71. signals:
  72. //void fileScanned( QVariantMap );
  73. void finished();
  74. void batchReady( const QVariantList&, const QVariantList& );
  75. private:
  76. QVariant readFile( const QFileInfo& fi );
  77. void executeCommand( QSharedPointer< DatabaseCommand > cmd );
  78. private slots:
  79. void listerFinished();
  80. void scanFile( const QFileInfo& fi );
  81. void setFileMtimes( const QMap< QString, QMap< unsigned int, unsigned int > >& m );
  82. void startScan();
  83. void scan();
  84. void cleanup();
  85. void commitBatch( const QVariantList& tracks, const QVariantList& deletethese );
  86. void commandFinished();
  87. private:
  88. QStringList m_dirs;
  89. QMap<QString, QString> m_ext2mime; // eg: mp3 -> audio/mpeg
  90. unsigned int m_scanned;
  91. unsigned int m_skipped;
  92. QList<QString> m_skippedFiles;
  93. QMap<QString, QMap< unsigned int, unsigned int > > m_filemtimes;
  94. unsigned int m_cmdQueue;
  95. QVariantList m_scannedfiles;
  96. QVariantList m_filesToDelete;
  97. quint32 m_batchsize;
  98. QWeakPointer< DirLister > m_dirLister;
  99. QThread* m_dirListerThreadController;
  100. };
  101. #endif