/**********************************************************************
 * LeechCraft - modular cross-platform feature rich internet client.
 * Copyright (C) 2011-2012  Minh Ngo
 * Copyright (C) 2006-2013  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 <QWidget>
#include <interfaces/core/icoreproxy.h>
#include <interfaces/structures.h>
#include "playlistview.h"

class QDockWidget;
class QGridLayout;
class QStandardItemModel;
class QStandardItem;

namespace LeechCraft
{
namespace Laure
{
	class PlayListView;
	
	/** @brief Provides a playlist widget with control tool buttons.
	 * 
	 * @author Minh Ngo <nlminhtl@gmail.com>
	 */
	class PlayListWidget : public QWidget
	{
		Q_OBJECT
		
		QGridLayout *GridLayout_;
		QStandardItemModel *PlayListModel_;
		PlayListView *PlayListView_;
		QToolBar *ActionBar_;
		std::shared_ptr<VLCWrapper> VLCWrapper_;
	public:
		/** @brief Constructs a new PlayListWidget class
		 * with the given parent.
		 */
		PlayListWidget (QWidget* = 0);

		void Init (std::shared_ptr<VLCWrapper> wrapper);
	public slots:
		/** @brief Is called when the media file has added to
		 * VLCWrapper.
		 * 
		 * @param[in] meta Media meta info.
		 * @param[in] fileName Media file location.
		 * 
		 * @sa VLCWrapper
		 * @sa MediaMeta
		 */
		void handleItemAdded (const MediaMeta& meta, const QString& fileName);
		
		/** @brief Is called when the media item has played
		 * in VLCWrapper.
		 * 
		 * @param[in] row Item index.
		 * 
		 * @sa VLCWrapper
		 */
		void handleItemPlayed (int row);
	private slots:
		void handleExportPlayList ();
		void handleItemChanged (QStandardItem*);
	signals:
		/** @brief Notifies that the media file needs to be
		 * added to VLCWrapper.
		 * 
		 * @param[out] location Media file location.
		 * 
		 * @sa VLCWrapper
		 */
		void itemAddedRequest (const QString& location);
		
		/** @brief Notifies that the media meta needs to be changed.
		 * 
		 * @param[in] type Media type.
		 * @param[in] value New media meta info.
		 * @param[in] index Playlist item index.
		 */
		void metaChangedRequest (libvlc_meta_t type, const QString& value,
				int index);

		void gotEntity (const LeechCraft::Entity&);
		void delegateEntity (const LeechCraft::Entity&, int*, QObject**);
		
		/** @brief Is emitted when the playback mode is changed.
		 * 
		 * @param[out] mode New playback mode.
		 * 
		 * @sa PlaybackMode
		 */
		void playbackModeChanged (PlaybackMode mode);
		void doubleClicked ();
	};
}
}
