/**********************************************************************
 * 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 <memory>
#include <QtPlugin>

class QUrl;

namespace Media
{
	struct AudioInfo;

	/** @brief Describes a single radio station.
	 *
	 * Radio stations can be either single-stream or multistream.
	 * Single-stream stations have only one continuous stream of music
	 * like an Icecast/Shoutcast broadcasting. Multistream radio stations
	 * announce tracks one by one, like Last.FM radio. The difference is
	 * that it makes sense to skip a track in multistream radios, while
	 * there is nothing to skip in single-stream ones.
	 *
	 * Multistream radio stations will typically emit gotNewStream()
	 * signals from time to time and as a response to RequestNewStream(),
	 * while single-stream radio stations will emit gotPlaylist() once.
	 *
	 * This class has some signals (gotNewStream(), gotPlaylist() and
	 * gotError()), and one can use the GetQObject() method to get an
	 * object of this class as a QObject and connect to those signals.
	 *
	 * Ownership of this class is either passed to the caller or remains
	 * belonging to the returning plugin, this class never deletes itself.
	 *
	 * @sa IRadioStationProvider
	 * @sa IModifiableRadioStation
	 */
	class Q_DECL_EXPORT IRadioStation
	{
	public:
		virtual ~IRadioStation () {}

		/** @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 Request a new stream if this is a multistream radio.
		 *
		 * Otherwise, this function does nothing.
		 */
		virtual void RequestNewStream () = 0;

		/** @brief Returns the human-readable name of this radio station.
		 *
		 * @return The human-readable name of this radio station.
		 */
		virtual QString GetRadioName () const = 0;
	protected:
		/** @brief Emitted when there is a new audio stream available.
		 *
		 * @param[out] url The URL of the stream.
		 * @param[out] info The track metadata.
		 */
		virtual void gotNewStream (const QUrl& url, const AudioInfo& info) = 0;

		/** @brief Emitted when a playlist for this radio is fetched.
		 *
		 * Ownership of the playlist is passed to the owner of this radio
		 * station, and it is responsible for deleting the playlist file
		 * after it is not needed.
		 *
		 * Playlist format is passed in the format parameter, and it can
		 * be one of:
		 * - m3u8
		 * - m3u
		 * - pls
		 * - xspf
		 *
		 * @param[out] filename The local path to the playlist.
		 * @param[out] format The format of the playlist.
		 */
		virtual void gotPlaylist (const QString& filename, const QString& format) = 0;

		/** @brief Emitted when just a set of audio infos is available.
		 *
		 * This signal can be used by radio stations that get audio
		 * streams in a form different of a playlist file.
		 *
		 * The audio infos in the \em infos list must contain the URL
		 * field.
		 *
		 * @param[out] infos The infos corresponding to this radio station.
		 */
		virtual void gotAudioInfos (const QList<AudioInfo>& infos) = 0;

		/** @brief Emitted when there is an error.
		 *
		 * @param[out] error The human-readable error text.
		 */
		virtual void gotError (const QString& error) = 0;
	};

	/** @brief A pointer to a shared instance of a IRadioStation.
	 */
	typedef std::shared_ptr<IRadioStation> IRadioStation_ptr;
}

Q_DECLARE_INTERFACE (Media::IRadioStation, "org.LeechCraft.Media.IRadioStation/1.0");
