/*****************************************************************************
 *
 *  console.cpp -- Class for console IO.
 *
 *  Copyright (C) 2010 Starbuck <starbuck@labdv.com>
 *  All rights reserved.
 *
 *  This file is part of the JobManager 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.
 *
 *****************************************************************************/

#include "console.h"
#include <QDebug>

Console::Console()
{
	m_stdIn = 0;
	m_stdOut = 0;
	m_stdErr = 0;

	m_log = 0;

	m_verbose = Default;
}

void Console::clearLog()
{
	if (m_log != 0) m_log->clear();
}

void Console::clearStdErr()
{
	if (m_stdErr != 0) m_stdErr->clear();
}

void Console::clearStdIn()
{
	if (m_stdIn != 0) m_stdIn->clear();
}

void Console::clearStdOut()
{
	if (m_stdOut != 0) m_stdOut->clear();
}

void Console::log(const QString &message)
{
	log(Default, message);
}

void Console::log(const int verbose, const QString &message)
{
	if (m_log == 0 ) qDebug() << "Console Log:" << message;
	else if (verbose <= m_verbose) m_log->append(message);
}

void Console::setVerbose(const int verbose)
{
	m_verbose = verbose;
}

void Console::start(QTextEdit *stdIn, QTextEdit *stdOut, QTextEdit *stdErr, QTextEdit *log)
{
	m_stdIn = stdIn;
	m_stdOut = stdOut;
	m_stdErr = stdErr;

	m_log = log;
}

void Console::stdErr(const QString &message)
{
	stdErr(Default, message);
}

void Console::stdErr(const int verbose, const QString &message)
{
	if (m_stdErr == 0) qDebug() << "Console stdErr:" << message;
	else if (verbose <= m_verbose) m_stdErr->append(message);
}

void Console::stdIn(const QString &message)
{
	stdIn(Default, message);
}

void Console::stdIn(const int verbose, const QString &message)
{
	if (m_stdIn == 0) qDebug() << "Console stdIn:" << message;
	else if (verbose <= m_verbose) m_stdIn->append(message);
}

void Console::stdOut(const QString &message)
{
	stdOut(Default, message);
}

void Console::stdOut(const int verbose, const QString &message)
{
	if (m_stdOut == 0) qDebug() << "Console stdOut:" << message;
	else if (verbose <= m_verbose) m_stdOut->append(message);
}
