/*****************************************************************************
 *
 *  jobmanagerwidget.h -- Monitor running jobs in a Widget.
 *
 *  Copyright (C) 2010 Starbuck <starbuck@labdv.com>
 *  All rights reserved.
 *
 *  This file is part of the Gui4 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 JOBMANAGERWIDGET_H
#define JOBMANAGERWIDGET_H

#include "../job/jobmanager.h"
#include "miniconsolewidget.h"
#include "consoledialog.h"
#include <QMap>
#include <QWidget>
#include <QString>
#include <QTextEdit>
#include <QLabel>
#include <QProgressBar>
#include <QIcon>
#include <QPushButton>
#include <QGroupBox>
#include <QLayout>
#include <QProcess>

#include <QDebug>

class JobManagerWidget : public QWidget
{
	Q_OBJECT

public:
	JobManagerWidget(QWidget *);
	~JobManagerWidget();

	bool isIdle();

	void abortProcesses() { jobManager->abortProcesses(); };
	void stopAllJobs();
	void reset();
	void setIdleLabel(const QString &str) { idleLabel->setText(str); };
	void setJobManager(JobManager *);
	inline void setNoMiniConsoleGroup(bool b) { noMiniConsoleGroup = b; };
	inline void setNoStateDisplay(bool b) { noStateDisplay = b; };
	void setNoConsoleButton(bool);

	void addTaskConsole(Task *);

signals:
	void guiSizeAdjustRequest();

protected:
	void synchronizeManager();
	void clearConsoleGarbage();

protected slots:
	void abortMiniConsole(MiniConsoleWidget *);
	void removeMiniConsole(MiniConsoleWidget *, bool =false);

protected:
	QList<Task *> tasks;
	QList<MiniConsoleWidget *> miniConsoles;
	QList<MiniConsoleWidget *> miniConsolesToDelete;
	
	JobManager* jobManager;

	QLabel *idleLabel;
	QMargins idleLabelMargins;
	QVBoxLayout *jobManagerWidgetLayout;

	bool noMiniConsoleGroup;
	bool noStateDisplay;
	bool noConsoleButton;
};

#endif
