/**********************************************************************
 * 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 <memory>
#include <QWidget>
#include <interfaces/ihavetabs.h>
#include <interfaces/iinfo.h>
#include "ui_laurewidget.h"

class QToolBar;
class QUrl;
class QMenu;

namespace LeechCraft
{
namespace Laure
{
	class Player;
	class PlayListWidget;
	class PlayPauseAction;
	class SeparatePlayer;

	/** @brief Represents a tab in LeechCraft tabs system.
	 *
	 * @author Minh Ngo <nlminhtl@gmail.com>
	 *
	 * @sa ITabWidget
	 */
	class LaureWidget : public QWidget
				, public ITabWidget
	{
		Q_OBJECT
		Q_INTERFACES (ITabWidget)

		static QObject *S_ParentMultiTabs_;

		QToolBar *ToolBar_;
		Ui::LaureWidget Ui_;
		std::shared_ptr<VLCWrapper> VLCWrapper_;
		std::shared_ptr<SeparatePlayer> SeparatePlayer_;
		QAction *DetachedVideo_;
		QAction *PlayListAction_;
		QAction *SubtitleAction_;
		QMenu *SubtitleMenu_;
		PlayPauseAction *ActionPlay_;

		bool InMove_;
	public:
		/** @brief Constructs a new LaureWidget tab
		 * with the given parent and flags.
		 */
		LaureWidget (QWidget *parent = 0, Qt::WindowFlags f = 0);
		~LaureWidget ();

		static void SetParentMultiTabs (QObject*);
		TabClassInfo GetTabClassInfo () const;
		QObject* ParentMultiTabs ();
		void Remove ();
		QToolBar* GetToolBar () const;

	protected:
		void keyPressEvent (QKeyEvent*);
	private:
		void InitCommandFrame ();
		void InitToolBar ();
		void InitShortcuts ();
	signals:
		/** @brief Is emitted to notify the Core that this tab needs to
		 * be closed.
		 */
		void needToClose ();

		/** @brief Is emitted when the PlayPauseAction is clicked.
		 */
		void playPause ();

		/** @brief Is emitted when the media item needs to be added to
		 * the playlist.
		 *
		 * @param[out] location Media file location.
		 */
		void addItem (const QString& location);

		void gotEntity (const LeechCraft::Entity&);
		void delegateEntity (const LeechCraft::Entity&, int*, QObject**);
	public slots:
		/** @brief Is called for adding media files to the playlist.
		 *
		 * @param[in] location Media file location.
		 */
		void handleOpenMediaContent (const QString& location);

		void updateSubtitleMenu (const MediaMeta& meta);
	private slots:
		void handleOpenFile ();
		void handleOpenURL ();
		void updateInterface ();
		void handleVideoMode (bool);
		void handleDetachPlayer (bool);
		void handleSeparatePlayerClosed ();
		void subtitleDialog ();
		void showSubtitleMenu ();
		void handlePlayListWidgetDoubleClicked ();
		void handleSplitterMoved ();

		void handleSliderReleased ();
		void handleSliderMoved (int pos);
		void handleDetachPlayer ();
	};
}
}