/***************************************************************************
 *   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 "kalvascriptcommand.h"

#include <QInputDialog>
#include <QLineEdit>
#include <KProcess>
#include <KDE/KLocale>
#include <KDebug>

namespace KalvaData {

KalvaScriptCommand::KalvaScriptCommand()
{
}

/**
 * callback function
 */
bool KalvaScriptCommand::test()
{
	kDebug() << "test()";
	bool ok;
	m_script = script();
	kDebug() << "script() = " << m_script;
	m_script = QInputDialog::getText(
		0,
		i18n("Command to run"),
		i18n("Command"),
		QLineEdit::Normal,
		m_script,
		&ok
	);
	return ok;
}

/**
 * callback function
 */
KProcess* KalvaScriptCommand::run()
{
	kDebug() << "run()";
	if ( m_script.isEmpty() ) {
		kDebug() << "script is empty!";
		return 0;
	}

	KProcess *process = new KProcess();
	process->clearProgram();
	process->setShellCommand(m_script);
	kDebug() << "Calling " << m_script << endl;
	process->start();
	return process;
}

/**
 * Command string
 */
QString KalvaScriptCommand::script() { return m_script; }

}

#include "kalvascriptcommand.moc"
