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"
|
2014-10-07 00:23:28 +02:00
|
|
|
#include "playlist/playlist.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
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-08-13 07:22:05 +02:00
|
|
|
ParserBase(LibraryBackendInterface* library, QObject* parent = nullptr);
|
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
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Loads all songs from playlist found at path 'playlist_path' in directory
|
|
|
|
// 'dir'.
|
2011-02-03 23:21:15 +01:00
|
|
|
// The 'device' argument is an opened and ready to read from represantation of
|
|
|
|
// this playlist.
|
2014-02-07 16:34:20 +01:00
|
|
|
// This method might not return all of the songs found in the playlist. Any
|
|
|
|
// playlist
|
|
|
|
// parser may decide to leave out some entries if it finds them incomplete or
|
|
|
|
// invalid.
|
|
|
|
// This means that the final resulting SongList should be considered valid (at
|
|
|
|
// least
|
2011-02-03 23:21:15 +01:00
|
|
|
// from the parser's point of view).
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual SongList Load(QIODevice* device, const QString& playlist_path = "",
|
|
|
|
const QDir& dir = QDir()) const = 0;
|
2014-10-15 21:57:57 +02:00
|
|
|
virtual void Save(
|
|
|
|
const SongList& songs, QIODevice* device, const QDir& dir = QDir(),
|
|
|
|
Playlist::Path path_type = Playlist::Path_Automatic) const = 0;
|
2010-05-22 23:11:22 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2011-04-28 14:27:53 +02:00
|
|
|
// Loads a song. If filename_or_url is a URL (with a scheme other than
|
|
|
|
// "file") then it is set on the song and the song marked as a stream.
|
|
|
|
// If it is a filename or a file:// URL then it is made absolute and canonical
|
|
|
|
// and set as a file:// url on the song. Also sets the song's metadata by
|
|
|
|
// searching in the Library, or loading from the file as a fallback.
|
|
|
|
// This function should always be used when loading a playlist.
|
2014-02-07 16:34:20 +01:00
|
|
|
Song LoadSong(const QString& filename_or_url, qint64 beginning,
|
|
|
|
const QDir& dir) const;
|
|
|
|
void LoadSong(const QString& filename_or_url, qint64 beginning,
|
|
|
|
const QDir& dir, Song* song) const;
|
2011-04-28 14:27:53 +02:00
|
|
|
|
2014-10-07 00:23:28 +02:00
|
|
|
// If the URL is a file:// URL then returns its path, absolute or relative to
|
|
|
|
// the directory depending on the path_type option.
|
|
|
|
// Otherwise returns the URL as is.
|
2011-04-28 14:27:53 +02:00
|
|
|
// This function should always be used when saving a playlist.
|
2014-10-07 00:23:28 +02:00
|
|
|
QString URLOrFilename(const QUrl& url, const QDir& dir,
|
|
|
|
Playlist::Path path_type) const;
|
2010-12-11 11:35:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-12-11 11:35:07 +01:00
|
|
|
LibraryBackendInterface* library_;
|
2010-03-09 18:17:32 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // PARSERBASE_H
|