2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
#ifndef PARSERBASE_H
|
|
|
|
#define PARSERBASE_H
|
2010-03-09 18:17:32 +01:00
|
|
|
|
|
|
|
#include <QObject>
|
2010-05-22 22:06:19 +02:00
|
|
|
#include <QDir>
|
2010-03-09 18:17:32 +01:00
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
#include "core/song.h"
|
2010-03-09 18:17:32 +01:00
|
|
|
|
2010-12-11 11:35:07 +01:00
|
|
|
class LibraryBackendInterface;
|
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
class ParserBase : public QObject {
|
2010-03-09 18:17:32 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
public:
|
2010-12-11 11:35:07 +01:00
|
|
|
ParserBase(LibraryBackendInterface* library, QObject *parent = 0);
|
2010-03-09 18:17:32 +01:00
|
|
|
|
2010-05-23 00:29:52 +02:00
|
|
|
virtual QString name() const = 0;
|
2010-05-22 22:06:19 +02:00
|
|
|
virtual QStringList file_extensions() const = 0;
|
2010-06-15 15:24:17 +02:00
|
|
|
virtual QString mime_type() const { return QString(); }
|
|
|
|
|
|
|
|
virtual bool TryMagic(const QByteArray& data) const = 0;
|
2010-03-09 18:17:32 +01:00
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
virtual SongList Load(QIODevice* device, const QDir& dir = QDir()) const = 0;
|
|
|
|
virtual void Save(const SongList& songs, QIODevice* device, const QDir& dir = QDir()) const = 0;
|
2010-05-22 23:11:22 +02:00
|
|
|
|
|
|
|
protected:
|
2010-05-23 00:20:00 +02:00
|
|
|
// Takes a URL, relative path or absolute path, and returns an absolute path.
|
|
|
|
// Resolves relative paths to "dir".
|
2010-05-22 23:11:22 +02:00
|
|
|
bool ParseTrackLocation(const QString& filename_or_url, const QDir& dir,
|
|
|
|
Song* song) const;
|
2010-05-23 00:20:00 +02:00
|
|
|
|
|
|
|
// Takes a URL, relative path or absolute path, and in the case of absolute
|
|
|
|
// paths makes them relative to dir if they are subdirectories.
|
|
|
|
QString MakeRelativeTo(const QString& filename_or_url, const QDir& dir) const;
|
2010-12-11 11:35:07 +01:00
|
|
|
|
|
|
|
// Takes a URL or absolute path and returns a URL
|
|
|
|
QString MakeUrl(const QString& filename_or_url) const;
|
|
|
|
|
|
|
|
// Converts the URL or path to a canonical path and searches the library for
|
|
|
|
// a song with that path. If one is found, returns it, otherwise returns an
|
|
|
|
// invalid song.
|
|
|
|
Song LoadLibrarySong(const QString& filename_or_url) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
LibraryBackendInterface* library_;
|
2010-03-09 18:17:32 +01:00
|
|
|
};
|
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
#endif // PARSERBASE_H
|