File indexing completed on 2024-05-05 04:49:51

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2010 Mark Kretschmann <kretschmann@kde.org>        *
0003  *             (C) 2008 Dan Meltzer <parallelgrapefruit@gmail.com>         *
0004  *             (C) 2008-2009 Jeff Mitchell <mitchell@kde.org>              *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, write to the                         *
0018  *   Free Software Foundation, Inc.,                                       *
0019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0020  ***************************************************************************/
0021 
0022 #ifndef COLLECTIONSCANNER_H
0023 #define COLLECTIONSCANNER_H
0024 
0025 #include "collectionscanner/ScanningState.h"
0026 
0027 #include <QCoreApplication>
0028 #include <QHash>
0029 #include <QSet>
0030 #include <QStringList>
0031 #include <QXmlStreamWriter>
0032 
0033 namespace CollectionScanner
0034 {
0035 
0036 /**
0037  * @class Scanner
0038  * @short Scans directories and builds the Collection
0039  */
0040 class Scanner : public QCoreApplication
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     Scanner( int &argc, char **argv );
0046     ~Scanner() override;
0047 
0048     /** Reads the batch file and adds the content to m_folders and m_Times */
0049     void readBatchFile( const QString &path );
0050 
0051     /** Get's the modified time from the given file and set's m_newerTime according */
0052     void readNewerTime( const QString &path );
0053 
0054 private Q_SLOTS:
0055     void doJob();
0056 
0057 private:
0058     void addDir( const QString& dir, QSet<QString> *entries );
0059 
0060     /** Returns true if the track is modified.
0061      *  Modification is determined first by m_mTimes and (if not found)
0062      *  then by m_newerTime
0063      */
0064     bool isModified( const QString& dir );
0065 
0066     void readArgs();
0067 
0068     /** Displays the error message and exits */
0069     void error( const QString &str );
0070 
0071     /** Displays the version and exits */
0072     void displayVersion();
0073 
0074     /** Displays the help and an optional error message and exits */
0075     void displayHelp( const QString &error = QString() );
0076 
0077     bool                  m_charset;
0078     QStringList           m_folders;
0079 
0080     uint                  m_newerTime;
0081     QHash<QString, uint>  m_mTimes;
0082 
0083     bool                  m_incremental;
0084     bool                  m_recursively;
0085     bool                  m_restart;
0086     bool                  m_idlePriority;
0087 
0088     QString               m_mtimeFile;
0089     ScanningState         m_scanningState;
0090 
0091 
0092     // Disable copy constructor and assignment
0093     Scanner( const Scanner& );
0094     Scanner& operator= ( const Scanner& );
0095 };
0096 
0097 }
0098 
0099 #endif // COLLECTIONSCANNER_H