PageRenderTime 123ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 73ms app.codeStats 0ms

/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
 19#ifndef MUSICSCANNER_H
 20#define MUSICSCANNER_H
 21
 22#include "tomahawksettings.h"
 23#include "database/databasecommand.h"
 24
 25/* taglib */
 26#include <taglib/fileref.h>
 27#include <taglib/tag.h>
 28
 29#include <QtCore/QVariantMap>
 30#include <QtCore/QDir>
 31#include <QtCore/QFileInfo>
 32#include <QtCore/QString>
 33#include <QtCore/QDateTime>
 34#include <QtCore/QTimer>
 35#include <QtCore/QMutex>
 36#include <QtCore/QMutexLocker>
 37#include <QtCore/QWeakPointer>
 38#include <database/database.h>
 39
 40// descend dir tree comparing dir mtimes to last known mtime
 41// emit signal for any dir with new content, so we can scan it.
 42// finally, emit the list of new mtimes we observed.
 43class DirLister : public QObject
 44{
 45Q_OBJECT
 46
 47public:
 48
 49    DirLister( const QStringList& dirs )
 50        : QObject(), m_dirs( dirs ), m_opcount( 0 ), m_deleting( false )
 51    {
 52        qDebug() << Q_FUNC_INFO;
 53    }
 54
 55    ~DirLister()
 56    {
 57        qDebug() << Q_FUNC_INFO;
 58    }
 59
 60    bool isDeleting() { QMutexLocker locker( &m_deletingMutex ); return m_deleting; };
 61    void setIsDeleting() { QMutexLocker locker( &m_deletingMutex ); m_deleting = true; };
 62
 63signals:
 64    void fileToScan( QFileInfo );
 65    void finished();
 66
 67private slots:
 68    void go();
 69    void scanDir( QDir dir, int depth );
 70
 71private:
 72    QStringList m_dirs;
 73
 74    uint m_opcount;
 75    QMutex m_deletingMutex;
 76    bool m_deleting;
 77};
 78
 79
 80class MusicScanner : public QObject
 81{
 82Q_OBJECT
 83
 84public:
 85    MusicScanner( const QStringList& dirs, quint32 bs = 0 );
 86    ~MusicScanner();
 87
 88signals:
 89    //void fileScanned( QVariantMap );
 90    void finished();
 91    void batchReady( const QVariantList&, const QVariantList& );
 92
 93private:
 94    QVariant readFile( const QFileInfo& fi );
 95    void executeCommand( QSharedPointer< DatabaseCommand > cmd );
 96
 97private slots:
 98    void listerFinished();
 99    void scanFile( const QFileInfo& fi );
100    void setFileMtimes( const QMap< QString, QMap< unsigned int, unsigned int > >& m );
101    void startScan();
102    void scan();
103    void cleanup();
104    void commitBatch( const QVariantList& tracks, const QVariantList& deletethese );
105    void commandFinished();
106
107private:
108    QStringList m_dirs;
109    QMap<QString, QString> m_ext2mime; // eg: mp3 -> audio/mpeg
110    unsigned int m_scanned;
111    unsigned int m_skipped;
112
113    QList<QString> m_skippedFiles;
114    QMap<QString, QMap< unsigned int, unsigned int > > m_filemtimes;
115
116    unsigned int m_cmdQueue;
117
118    QVariantList m_scannedfiles;
119    QVariantList m_filesToDelete;
120    quint32 m_batchsize;
121
122    QWeakPointer< DirLister > m_dirLister;
123    QThread* m_dirListerThreadController;
124};
125
126#endif