2010-10-24 17:38:12 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-24 17:38:12 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYLISTGENERATOR_H
|
|
|
|
#define PLAYLISTGENERATOR_H
|
|
|
|
|
|
|
|
#include "playlist/playlistitem.h"
|
|
|
|
|
|
|
|
#include <boost/enable_shared_from_this.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
|
|
class LibraryBackend;
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
namespace smart_playlists {
|
|
|
|
|
|
|
|
class Generator : public QObject, public boost::enable_shared_from_this<Generator> {
|
2010-10-24 17:38:12 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-11-18 21:19:33 +01:00
|
|
|
Generator();
|
2010-10-24 17:38:12 +02:00
|
|
|
|
|
|
|
static const int kDefaultLimit;
|
2011-05-14 15:44:10 +02:00
|
|
|
static const int kDefaultDynamicHistory;
|
|
|
|
static const int kDefaultDynamicFuture;
|
2010-11-20 19:49:54 +01:00
|
|
|
|
|
|
|
// Creates a new Generator of the given type
|
2010-11-18 21:19:33 +01:00
|
|
|
static boost::shared_ptr<Generator> Create(const QString& type);
|
2010-10-24 17:38:12 +02:00
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
// Should be called before Load on a new Generator
|
2010-10-24 17:38:12 +02:00
|
|
|
void set_library(LibraryBackend* backend) { backend_ = backend; }
|
2010-11-17 21:21:04 +01:00
|
|
|
void set_name(const QString& name) { name_ = name; }
|
2010-11-27 20:11:36 +01:00
|
|
|
LibraryBackend* library() const { return backend_; }
|
2010-11-20 19:49:54 +01:00
|
|
|
QString name() const { return name_; }
|
2010-11-17 21:21:04 +01:00
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
// Name of the subclass
|
2010-11-17 21:21:04 +01:00
|
|
|
virtual QString type() const = 0;
|
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
// Serialises the Generator's settings
|
2010-11-26 16:16:48 +01:00
|
|
|
// Called on UI-thread.
|
2010-11-17 21:21:04 +01:00
|
|
|
virtual void Load(const QByteArray& data) = 0;
|
2010-11-26 16:16:48 +01:00
|
|
|
// Called on UI-thread.
|
2010-11-17 21:21:04 +01:00
|
|
|
virtual QByteArray Save() const = 0;
|
2010-10-24 17:38:12 +02:00
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
// Creates and returns a playlist
|
2010-11-26 16:16:48 +01:00
|
|
|
// Called from non-UI thread.
|
2010-10-24 17:38:12 +02:00
|
|
|
virtual PlaylistItemList Generate() = 0;
|
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
// If the generator can be used as a dynamic playlist then GenerateMore
|
|
|
|
// should return the next tracks in the sequence. The subclass should
|
2011-05-14 15:44:10 +02:00
|
|
|
// remember the last GetDynamicHistory() + GetDynamicFuture() tracks and ensure that
|
2010-11-20 19:49:54 +01:00
|
|
|
// the tracks returned from this method are not in that set.
|
|
|
|
virtual bool is_dynamic() const { return false; }
|
|
|
|
virtual void set_dynamic(bool dynamic) {}
|
2010-11-26 16:16:48 +01:00
|
|
|
// Called from non-UI thread.
|
2010-11-20 19:49:54 +01:00
|
|
|
virtual PlaylistItemList GenerateMore(int count) { return PlaylistItemList(); }
|
|
|
|
|
2011-05-14 15:44:10 +02:00
|
|
|
virtual int GetDynamicHistory () { return kDefaultDynamicHistory; }
|
|
|
|
virtual int GetDynamicFuture () { return kDefaultDynamicFuture; }
|
2010-10-24 17:38:12 +02:00
|
|
|
signals:
|
|
|
|
void Error(const QString& message);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LibraryBackend* backend_;
|
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
private:
|
2010-10-24 17:38:12 +02:00
|
|
|
QString name_;
|
|
|
|
};
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "generator_fwd.h"
|
2010-10-24 17:38:12 +02:00
|
|
|
|
|
|
|
#endif // PLAYLISTGENERATOR_H
|