/**********************************************************************
 * LeechCraft - modular cross-platform feature rich internet client.
 * Copyright (C) 2006-2014  Georg Rudoy
 *
 * Boost Software License - Version 1.0 - August 17th, 2003
 *
 * Permission is hereby granted, free of charge, to any person or organization
 * obtaining a copy of the software and accompanying documentation covered by
 * this license (the "Software") to use, reproduce, display, distribute,
 * execute, and transmit the Software, and to prepare derivative works of the
 * Software, and to permit third-parties to whom the Software is furnished to
 * do so, all subject to the following:
 *
 * The copyright notices in the Software and this entire statement, including
 * the above license grant, this restriction and the following disclaimer,
 * must be included in all copies of the Software, in whole or in part, and
 * all derivative works of the Software, unless such copies or derivative
 * works are solely in the form of machine-executable object code generated by
 * a source language processor.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 **********************************************************************/

#pragma once

#include <QtPlugin>
#include "audiostructs.h"

namespace Media
{
	/** @brief Pending tags fetch handle.
	 *
	 * Interface to a pending tags fetch job. A descendant of this class
	 * is returned from ITagsFetcher::FetchTags() method.
	 *
	 * This class has some signals (ready()), and one can use
	 * the GetQObject() method to get an object of this class as a
	 * QObject and connect to those signals.
	 *
	 * @note The object of this class should schedule its deletion (via
	 * <code>QObject::deleteLater()</code>, for example) after ready()
	 * signal is emitted. Thus the calling code should never
	 * delete it explicitly, neither it should use this object after
	 * ready() signal or connect to this signals via
	 * <code>Qt::QueuedConnection</code>.
	 *
	 * @sa ITagsFetcher
	 */
	class Q_DECL_EXPORT IPendingTagsFetch
	{
	public:
		virtual ~IPendingTagsFetch () {}

		/** @brief Returns this object as a QObject.
		 *
		 * This function can be used to connect to the signals of this
		 * class.
		 *
		 * @return This object as a QObject.
		 */
		virtual QObject* GetQObject () = 0;

		/** @brief Returns the found audio metadata.
		 *
		 * Returns the best matching audio info, if any, for the file
		 * this tags fetch job corresponds to.
		 *
		 * @return The result of the tags fetching.
		 */
		virtual AudioInfo GetResult () const = 0;
	protected:
		/** @brief Emitted when the search result if ready and fetched.
		 *
		 * The object will be invalid after this signal is emitted and
		 * the event loop is run.
		 *
		 * @param[out] filename The filename this tags fetch job
		 * corresponds to.
		 * @param[out] info The audio track metadata fetched for the
		 * filename.
		 */
		virtual void ready (const QString& filename, const Media::AudioInfo& info) = 0;
	};

	/** @brief Interface for plugins fetching tags for untagged files.
	 *
	 * If a plugin is able to fetch tags from a tags database by, for
	 * example, an audio fingerprint (like AcoustID/MusicBrainz database)
	 * it should implement this interface.
	 */
	class Q_DECL_EXPORT ITagsFetcher
	{
	public:
		virtual ~ITagsFetcher () {}

		/** @brief Requests fetching tags for the given file.
		 *
		 * This function initiates a search for tags for the given file
		 * and returns a handle that can be used to obtain the results.
		 * The handle owns itself and deletes itself after results are
		 * available — see its documentation for details.
		 *
		 * @param[in] filename The name of the file to search tags for.
		 * @return The pending tags fetch handle.
		 */
		virtual IPendingTagsFetch* FetchTags (const QString& filename) = 0;
	};
}

Q_DECLARE_INTERFACE (Media::IPendingTagsFetch, "org.LeechCraft.Media.IPendingTagsFetch/1.0")
Q_DECLARE_INTERFACE (Media::ITagsFetcher, "org.LeechCraft.Media.ITagsFetcher/1.0")
