Revert previous commit, was incorrect
[amarok.git] / src / collectionscanner / collectionscanner.h
blob5b57e14807a2157232f0d79c6a8d1e86e854068d
1 /***************************************************************************
2 * Copyright (C) 2003-2005 by The Amarok Developers *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #ifndef COLLECTIONSCANNER_H
21 #define COLLECTIONSCANNER_H
23 #include "metabundle.h"
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
29 #include <QMap>
30 #include <QStringList>
31 #include <QVector>
33 #include <kapplication.h>
34 #include <amarok_collection_interface.h>
36 typedef QMap<QString, QString> AttributeMap;
39 /**
40 * @class CollectionScanner
41 * @short Scans directories and builds the Collection
44 class CollectionScanner : public KApplication
46 Q_OBJECT
48 public:
49 CollectionScanner( const QStringList& folders,
50 bool recursive,
51 bool incremental,
52 bool importPlaylists,
53 bool restart );
55 ~CollectionScanner();
56 int newInstance() { return 0; }
58 private slots:
59 void doJob();
61 private:
62 void readDir( const QString& dir, QStringList& entries );
63 void scanFiles( const QStringList& entries );
65 /**
66 * Read metadata tags of a given file.
67 * @mb MetaBundle for the file.
68 * @return QMap containing tags, or empty QMap on failure.
70 AttributeMap readTags( const MetaBundle& mb );
72 /**
73 * Helper method for writing XML elements to stdout.
74 * @name Name of the element.
75 * @attributes Key/value map of attributes.
77 void writeElement( const QString& name, const AttributeMap& attributes );
80 /**
81 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none
83 inline QString extension( const QString &fileName )
85 return fileName.contains( '.' ) ? fileName.mid( fileName.lastIndexOf( '.' ) + 1 ).toLower() : "";
88 /**
89 * @return the last directory in @param fileName
91 inline QString directory( const QString &fileName )
93 return fileName.section( '/', 0, -2 );
97 const bool m_importPlaylists;
98 QStringList m_folders;
99 const bool m_recursively;
100 const bool m_incremental;
101 const bool m_restart;
102 const QString m_logfile;
103 QStringList m_scannedFolders;
105 OrgKdeAmarokCollectionInterface *amarokCollectionInterface;
109 #endif // COLLECTIONSCANNER_H