/***************************************************************************
 *   Copyright (C) 2008 by Andreas Silberstorff   *
 *   ml@andreas-silberstorff.de   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef kalvavideoplayer_H
#define kalvavideoplayer_H

#include <libkalva_export.h>

#include <QtGui/QWidget>
#include <QUrl>

#include <phonon/videoplayer.h>
#include <phonon/volumeslider.h>
#include <phonon/seekslider.h>

#include <KGuiItem>

class QAction;

class KPushButton;

namespace KalvaWidget {

/**
 * This is the video player class for kalva2.
 * It can be used by perspectives for the mainViewWidget.
 *
 * @todo make aspectRatio accessible to the user by providing Actions for this.
 * @short Video player
 * @author Andreas Silberstorff <ml@andreas-silberstorff.de>
 * @version 1.91
 */

class KALVALIB_EXPORT KalvaVideoPlayer : public QWidget
{
	Q_OBJECT
public:

	/**
	 * Default constructor
	 */
	KalvaVideoPlayer ();

	/**
	 * constructor with parent
	 */
	KalvaVideoPlayer ( QWidget* parent );

	/**
	 * Destructor
	 */
	virtual ~KalvaVideoPlayer();

signals:
	void playButtonPressed();
	void pauseButtonPressed();
	void stopButtonPressed();

public slots:

	/**
	 * Get informed when settings changed.
	 */
	void settingsChanged();

	/**
	 * Loads the video stream from the QUrl.
	 * See Phonon::VideoWidget::load( const QUrl & )
	 */
	void load( const QUrl &);

	/**
	 * Plays or continues the loaded video stream.
	 * See Phonon::VideoWidget::play()
	 */
	void play();

	/**
	 * Pauses the loaded video stream.
	 * See Phonon::VideoWidget::pause()
	 */
	void pause();

	/**
	 * Pauses the loaded video stream.
	 * See Phonon::VideoWidget::pause()
	 */
	void stop();

	/**
	 * Toggles fullscreen mode of the VideoWidget.
	 * See Phonon::VideoWidget::enterFullScreen( bool )
	 */
	void enterFullScreen( bool );

private:

	/**
	 * initializes the widget
	 */
	void init();

	/**
	 * Creates the actions.
	 */
	void createActions();

	/**
	 * Creates the widgets.
	 */
	void createWidgets();

	/**
	 * Layouts the widgets.
	 */
	void layoutWidgets();

	Phonon::VideoPlayer *player;
	Phonon::VolumeSlider *volumeSlider;
	Phonon::SeekSlider *seekSlider;
	KPushButton* playPauseButton;
	KPushButton* stopButton;
	KPushButton* fullScreenButton;
	QUrl m_url;
        int m_powerSaveCookie;

	KGuiItem playItem;
	KGuiItem pauseItem;
	KGuiItem stopItem;

	QAction *playerPlayAction;
	QAction *playerPauseAction;
	QAction *playerStopAction;
	QAction *enterFullScreenAction;

private slots:

	/**
	 * Toggles Play button and action.
	 */
	void playerPlayes();

	/**
	 * Toggles Play button and action.
	 */
	void playerPaused();

	/**
	 * Toggles Play button and action.
	 */
	void playerFinished();
};

}

#endif // kalvavideoplayer_H
