/***************************************************************************
 *   Copyright (C) 2008 by Andreas Silberstorff   *
 *   taki@Rivendell   *
 *                                                                         *
 *   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.             *
 ***************************************************************************/

#include "mplayerscriptdevice.h"
#include "recordcommand.h"
#include "playcommand.h"
#include "generalsettingspage.h"
#include "settings.h"
#include <QtGui>
#include <QTime>
#include <phonon/mediasource.h>
#include <phonon/mediaobject.h>
#include <phonon/volumeslider.h>
#include <phonon/seekslider.h>
#include <phonon/videoplayer.h>
#include <phonon/videowidget.h>
#include <phonon/backendcapabilities.h>
#include <KDE/KLocale>
#include <KDebug>

namespace MPlayerScriptDevice {

Plugin::Plugin()
	: _mediaObject(0), _videoWidget(0)
{
}

Plugin::~Plugin()
{
	delete _mediaObject;
	delete _videoWidget;
	delete _channel;
}

/**
 * @see KalvaPlugin::PluginInterface
 */
void Plugin::addToConfigDialog( KConfigDialog *dialog )
{
	kDebug() << "addToConfigDialog()" << endl;

	dialog->addPage(new GeneralSettingsPage(), Settings::self(), i18n("MPlayer general settings"), "mplayerdevice_generalsetting");
}

/**
 * Implementing plugins must overwrite this to allow
 * recording of the tv stream.
 *
 * The managing perspective must have set the video widget
 * before this function can be called!
 */
KalvaData::KalvaScriptCommand* Plugin::createRecordCommand( QString titel, QTime duration )
{
	kDebug() << "createRecordCommand()";
	RecordCommand* command  = new MPlayerScriptDevice::RecordCommand();
	kDebug() << "channel = " << _channel->station();
	command->setChannel( _channel->station() );
	command->setTitel(titel);
	command->setDuration(duration);
	command->setCollectionpath( "/media/disk/Video" );
	
	command->setCollectionpath( _kalvaGeneralSettings->collectionRoot() );
	return command;	
}

/**
 * Implementing plugins must overwrite this to allow
 * recording of the tv stream.
 *
 * The managing perspective must have set the video widget
 * and the channellist and a station has to be selected
 * before this function can be called!
 */
KalvaData::KalvaScriptCommand* Plugin::createPlayCommand()
{
	kDebug() << "createPlayCommand()" << endl;

	PlayCommand* command  = new MPlayerScriptDevice::PlayCommand();
	command->setChannel( _channel->channel() );
	return command;	
}

void Plugin::setKalvaGeneralSettings( KalvaData::KalvaGeneralSettings * kalvaGeneralSettings )
{
  _kalvaGeneralSettings = kalvaGeneralSettings;
}

/**
 * @see KalvaPlugin::PluginInterface
 */
void Plugin::settingsChanged()
{
	kDebug() << "settingsChanged()" << endl;
}

}

Q_EXPORT_PLUGIN2( kalva2_mplayerscript_device, MPlayerScriptDevice::Plugin )

#include "mplayerscriptdevice.moc"