File indexing completed on 2022-12-06 19:55:48

0001 /**
0002  * Copyright (C) 2003 Frerich Raabe <raabe@kde.org>
0003  *
0004  * This program is free software; you can redistribute it and/or modify it under
0005  * the terms of the GNU General Public License as published by the Free Software
0006  * Foundation; either version 2 of the License, or (at your option) any later
0007  * version.
0008  *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0012  *
0013  * You should have received a copy of the GNU General Public License along with
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.
0015  */
0016 
0017 #ifndef TAGGUESSER_H
0018 #define TAGGUESSER_H
0019 
0020 #include <QString>
0021 #include <QRegExp>
0022 #include <QList>
0023 
0024 class FileNameScheme
0025 {
0026     public:
0027         typedef QList<FileNameScheme> List;
0028 
0029         FileNameScheme() { }
0030         explicit FileNameScheme(const QString &s);
0031 
0032         bool matches(const QString &s) const;
0033 
0034         QString title() const;
0035         QString artist() const;
0036         QString album() const;
0037         QString track() const;
0038         QString comment() const;
0039 
0040     private:
0041         QString composeRegExp(const QString &s) const;
0042 
0043         mutable QRegExp m_regExp;
0044         int m_titleField;
0045         int m_artistField;
0046         int m_albumField;
0047         int m_trackField;
0048         int m_commentField;
0049 };
0050 
0051 class TagGuesser
0052 {
0053     public:
0054 
0055         enum Type { FileName = 0, MusicBrainz = 1 };
0056 
0057         static QStringList schemeStrings();
0058         static void setSchemeStrings(const QStringList &schemes);
0059 
0060         TagGuesser();
0061         explicit TagGuesser(const QString &absFileName);
0062 
0063         void guess(const QString &absFileName);
0064 
0065         QString title() const { return m_title; }
0066         QString artist() const { return m_artist; }
0067         QString album() const { return m_album; }
0068         QString track() const { return m_track; }
0069         QString comment() const { return m_comment; }
0070 
0071     private:
0072         void loadSchemes();
0073         QString capitalizeWords(const QString &s);
0074 
0075         FileNameScheme::List m_schemes;
0076         QString m_title;
0077         QString m_artist;
0078         QString m_album;
0079         QString m_track;
0080         QString m_comment;
0081 };
0082 
0083 #endif // TAGGUESSER_H
0084 
0085 // vim: set et sw=4 tw=0 sta: