// Copyright (c) 2003,2004 Charles Samuels <charles@kde.org>
// See the file COPYING for redistribution terms.

#ifndef OBLIQUE_H
#define OBLIQUE_H

#include <noatun/playlist.h>
#include <noatun/plugin.h>
#include "query.h"
#include "kdatacollection.h"

class View;
class Tree;
class Base;
class Selector;
class TreeItem;

class Oblique : public Playlist, public Plugin
{
Q_OBJECT
	View *mView;
	Base *mBase;
	Selector *mSelector;
	KDataCollection mSchemaCollection;

public:
	Oblique();
	~Oblique();

	Base *base() { return mBase; }

	QStringList schemaNames() const { return mSchemaCollection.names(); }
	QString loadSchema(Query &q, const QString &name)
	{
		QString t = q.load(mSchemaCollection.file(name));
		if (t.length())
			q.setName(name);
		return t;
	}
	
	void saveSchema(Query &q, const QString &name, const QString &title)
	{
		q.save(title, mSchemaCollection.saveFile(name));
	}
	
	void removeSchema(const QString &name)
	{
		mSchemaCollection.remove(name);
	}

	virtual void reset();
	virtual void clear();
	virtual void addFile(const KURL&, bool play=false);
	virtual PlaylistItem next();
	virtual PlaylistItem previous();
	virtual PlaylistItem current();
	virtual void setCurrent(const PlaylistItem &);
	virtual PlaylistItem getFirst() const;
	virtual PlaylistItem getAfter(const PlaylistItem &item) const;
	virtual bool listVisible() const;
	virtual void showList();
	virtual void hideList();

	virtual Playlist *playlist() { return this; }

public slots:
	void selected(TreeItem *cur);

private slots:
	void loopTypeChange(int i);
};

/**
 * loads the database into a Tree
 **/
class Loader : public QObject
{
Q_OBJECT
	// the id of the next file to load
	FileId mDeferredLoaderAt;
	Tree *mTree;
	Base *mBase;

public:
	Loader(Tree *into);

signals:
	void finished();

private slots:
	void loadItemsDeferred();
};


#endif
