/*****************************************************************************
 *
 *  job.h -- Job handler.
 *
 *  Copyright (C) 2010 Starbuck <starbuck@labdv.com>
 *  All rights reserved.
 *
 *  This file is part of the Job module of the DVDx 4 application.
 *
 *  GNU Lesser General Public License Usage
 *  This file may be used under the terms of the GNU Lesser General
 *  Public License version 2.1 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.LGPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU Lesser General Public License version 2.1 requirements
 *  will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 *
 *  GNU General Public License Usage
 *  Alternatively, this file may be used under the terms of the GNU
 *  General Public License version 3.0 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.GPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU General Public License version 3.0 requirements will be
 *  met: http://www.gnu.org/copyleft/gpl.html.
 *
 *****************************************************************************/

#ifndef JOB_H
#define JOB_H

#include "../main/macrosdev.h"
#include "task.h"
#include <QList>
#include <QString>
#include <QStringList>
#include <QTextEdit>
#include <QProcess>
#include <QObject>

class Job : public QObject
{
	Q_OBJECT

public:
	Job();

	void setTask(Task *task, const QString &jobId, const QString &jobName, const QString &jobOutput,
			QTextEdit *stdIn, QTextEdit *stdOut, QTextEdit *stdErr, QTextEdit *defLog, const int verbose,
			const int latencyStart = 0, const int latencyFinished = 0, const int latencyKill = 0);

	inline QString getId() const { return id; }; 
	inline QString getName() const { return name; }; 
	inline QString getOutput() const { return output; }; 
	inline Task *getTask() const { return task; }; 

	QList<void *> getConsoles();
	Task* getTaskToStart();
	Task::State getTaskState();

	virtual bool isFinished(); 

	virtual void updateOnTerminatedTask(Task *, bool);

signals:
	void finished();

protected:
	void printLog(const QString &, const int=VERBOSITY_NORMAL);
	void printIn(const QString &, const int=VERBOSITY_NORMAL);
	void printOut(const QString &, const int=VERBOSITY_NORMAL);
	void printErr(const QString &, const int=VERBOSITY_NORMAL);

	int verbosity;

	void clearLog();
	void clearIn();
	void clearOut();
	void clearErr();

protected:
	Task *task;
	QString id;
	QString name;
	QString output;

	QTextEdit *log;				// log application errors/warnings
	QTextEdit *standardInput;	// process stdIn
	QTextEdit *standardOutput;	// process stdOut
	QTextEdit *standardError;	// process stdErr

	// Process latency
	int LatencyStart, LatencyFinished, LatencyKill;
	enum Constants { DefaultLatencyStart = 3000, DefaultLatencyFinished = 3000, DefaultLatencyKill= 5000 };
};

#endif
