/***************************************************************************
 *   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 "playcommand.h"
#include "settings.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <QFile>
#include <QInputDialog>
#include <QLineEdit>
#include <QString>
#include <KProcess>
#include <KDE/KLocale>
#include <KDebug>
#include <kstandarddirs.h>

namespace MPlayerScriptDevice {

/**
 * A Command using MPlayer shellscripts
 *
 * @short MPlayerCommand
 * @author Andreas Silberstorff <ml@andreas-silberstorff.de>
 * @version 1.0.91
 */

PlayCommand::PlayCommand()
{
	_program = Settings::mencoder();
	_type = "dvb";
	_ovc = "copy";
	_oac = "copy";
	_of = "mpeg";
	_suffix = "mpg";
	
}

PlayCommand::~PlayCommand()
{
}

QString PlayCommand::script()
{
	QString fifoFileName = url();
        QFile* fifofile = new QFile(fifoFileName);
        if (fifofile->exists()) {
            fifofile->remove();
	}
	delete fifofile;
	mkfifo(fifoFileName.toAscii().constData(), 0666);
	QString cmd = _program;
	cmd += " \"" + _type + "://" + _channel + "\"";
	cmd += " -ovc copy -oac copy -of mpeg -o " + fifoFileName;
	return cmd;
}

QString PlayCommand::url()
{
	return KStandardDirs::locateLocal("tmp", "kalvatv_fifo." + _suffix);
}

}
