/**********************************************************************
 * LeechCraft - modular cross-platform feature rich internet client.
 * Copyright (C) 2013  Vladislav Tyulbashev
 *
 * 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 <QMap>
#include <interfaces/ihavetabs.h>
#include <interfaces/core/icoreproxy.h>
#include "vlcscrollbar.h"
#include "soundwidget.h"
#include "signalledwidget.h"
#include "playlistwidget.h"
#include "volumenotification.h"

class QToolBar;
class QMenu;
class QLabel;
class QTimer;
class QToolButton;
class QResizeEvent;
class QSettings;
class QDockWidget;
class QStringList;

namespace LC
{
namespace Util
{
	class ShortcutManager;
}

namespace vlc
{
	class VlcPlayer;
	class PlaylistTitleWidget;
	class VlcWidget : public QWidget
					, public ITabWidget
	{
		Q_OBJECT
		Q_INTERFACES (ITabWidget)
		
		ICoreProxy_ptr Proxy_;
		QObject *const Parent_;
		VlcPlayer *VlcPlayer_;
		PlaylistWidget *PlaylistWidget_;
		PlaylistTitleWidget *TitleWidget_;
		QToolBar *Bar_;
		QAction *Open_;
		QToolButton *OpenButton_;
		QToolButton *NextButton_;
		QToolButton *PrevButton_;
		QAction *TogglePlay_;
		QAction *Stop_;
		QAction *FullScreenAction_;
		QAction *IncreaseVolumeAction_;
		QAction *DecreaseVolumeAction_;
		QAction *Plus3Percent_;
		QAction *Minus3Percent_;
		QAction *Plus10Seconds_;
		QAction *Minus10Seconds_;
		QAction *Next_;
		QAction *Prev_;
		QPoint LastMouseEvent_;
		QDockWidget *PlaylistDock_;
		Util::ShortcutManager * const Manager_;
		
		QAction *NavigateLeft_;
		QAction *NavigateRight_;
		QAction *NavigateUp_;
		QAction *NavigateDown_;
		QAction *NavigateEnter_;
		
		VlcScrollBar *ScrollBar_;
		QLabel *TimeLeft_;
		QLabel *TimeAll_;
		
		QLabel *FullScreenTimeLeft_;
		QLabel *FullScreenTimeAll_;
		VlcScrollBar *FullScreenVlcScrollBar_;
		SignalledWidget *FullScreenPanel_;
		QTimer *TerminatePanel_;
		
		QToolButton *TogglePlayButton_;
		QToolButton *StopButton_;
		QToolButton *FullScreenButton_;
		
		bool ForbidFullScreen_;
		bool FullScreen_;
		bool AllowFullScreenPanel_;
		SignalledWidget *FullScreenWidget_;
		QTimer *InterfaceUpdater_;
		SignalledWidget *VlcMainWidget_;
		SoundWidget *SoundWidget_;
		SoundWidget *FullScreenSoundWidget_;
		VolumeNotification *VolumeNotificationWidget_;
		QMenu *ContextMenu_;
		QSettings *Settings_;
		QString VideoPath_;
		
		bool Autostart_;
		
		QTimer *DisableScreenSaver_;
		
	public:
		explicit VlcWidget (ICoreProxy_ptr proxy, Util::ShortcutManager *manager, QWidget *parent = 0);
		~VlcWidget();
		TabClassInfo GetTabClassInfo () const;
		QObject* ParentMultiTabs ();
		void Remove ();
		QToolBar* GetToolBar () const;
		static TabClassInfo GetTabInfo ();
		void TabMadeCurrent ();
		void TabLostCurrent ();
		
		void Sleep ();
		
	private:
		QString GetNewSubtitles ();
		void GenerateToolBar ();
		QMenu* GenerateMenuForOpenAction ();
		void PrepareFullScreen ();
		void ForbidFullScreen ();
		void ConnectWidgetToMe (SignalledWidget*);
		
		void InitNavigations ();
		void InitVolumeActions ();
		void InitRewindActions ();
		
		void SaveSettings ();
		void RestoreSettings ();
		void RestorePlaylist ();
		
		void ParsePath (QString);
		
	public slots:
		void autostartChanged ();
		
	private slots:
		void addFiles ();
		void addFilesWithoutClearingPlaylist ();
		void addFolder ();
		void addUrl ();
		void addDVD ();
		void addSimpleDVD ();
		void addSlave ();
		
		void updateInterface ();
		void toggleFullScreen ();
		void allowFullScreen ();
		
		void generateContextMenu (QPoint);
		void setAudioTrack (QAction*);
		void setSubtitles (QAction*);
		void setAspectRatio (QAction*);
		void setRealZoom (QAction*);
		
		void keyPressEvent (QKeyEvent*);
		void mousePressEvent (QMouseEvent*);
		void mouseDoubleClickEvent (QMouseEvent*);
		void mouseMoveEvent (QMouseEvent*);
		void wheelEvent (QWheelEvent*);
		void dropEvent (QDropEvent*);
		void dragEnterEvent (QDragEnterEvent*);
		void mainWidgetResized (QResizeEvent*);
		
		void fullScreenPanelRequested ();
		void hideFullScreenPanel ();
		
		void AllowPanel ();
		void ForbidPanel ();
		
		void disableScreenSaver ();
		
		void savePlaylist (const QueueState&);
		void savePlaylistPosition (Qt::DockWidgetArea);
		
	signals:
		void deleteMe (QWidget*);
	};
}
}
