/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *         (C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#ifndef __FRMPKGUPGRADECONTROLLER_H
#define __FRMPKGUPGRADECONTROLLER_H

#include "uifrmpkgupgradecontroller.h"

#include <kparts/part.h>
#include <qpixmap.h>

class KProcess;
class QStrList;
class ExtTerminalInterface;
class PkgUpgradeController;
class PkgUpgradeEngine;
class UnixProcess;

class FrmPkgUpgradeController : public uiFrmPkgUpgradeController
{
  Q_OBJECT

public:
	FrmPkgUpgradeController(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );

	void setInstallEngine(PkgUpgradeEngine *);
	void setUpgradeEngine(PkgUpgradeEngine *);
	
	PkgUpgradeController *getController();
	virtual void polish();
	
	enum Status {
		Undefined,
		Running,
		FinishedNormal,
		FinishedAborted,
		Canceled
	};
	
	enum Program {
		NoProgram,
		Portupgrade,
      Portinstall,
		PkgDb
	};
	
	Status getStatus();

protected slots:
	virtual void progressMessage(const QString &);
	virtual void warningMessage(const QString &);
	virtual void informationMessage(const QString &);
	virtual void userInputRequired(const QString &);

	virtual void overallProgressChanged(int percent);
	virtual void operationProgressChanged(int percent);
	virtual void moveBusyIndicator();

	virtual void processExited(KProcess *);
	
	virtual void fixPkgdb();

protected:
	enum MessageType {
		None,
		Progress,
		Warning,
		Information,
		UserInput
	};

	void message(MessageType, const QString &);

	virtual void closeEvent(QCloseEvent *);

private:
	void startProcess(const UnixProcess &);
	
	QTimer* busyIndicatorTimer;
	void enableBusyIndicatorTimer(bool);

	KParts::Part *terminalPart;
	ExtTerminalInterface *terminalInterface;

	PkgUpgradeEngine *installEngine;
	PkgUpgradeEngine *upgradeEngine;
	PkgUpgradeController *controller;

	int currentMessageType;
	QPixmap pmProgress, pmWarning, pmInfo, pmNone, pmClose, pmUserInput;

	int exitCode;
	Status status;
	Program program;
};

#endif /* __FRMPKGUPGRADECONTROLLER_H */
