/*
 * 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
 *
 */

#include <dbsdglobal.h>
#include <dbsdiconloader.h>
#include <dialogs.h>

void  frmTerminalDisplay::init() {
	canceled = false;
	finished = false;

	initGraphics();
}


bool frmTerminalDisplay::wasCanceled() {
	return canceled;
}

/** exec() returns Rejected when the user
  * pressed cancel or Accepted when
  * all actions were done and the user
  * clicked 'Close'
  */
void frmTerminalDisplay::closeEvent(QCloseEvent *e) {
	if(!finished && !Dialogs::question(tr("Are you sure?"))) {
		e->ignore();
	} else {
		canceled = !finished;
		if(finished)
			setResult(Accepted);
		else
			setResult(Rejected);

		e->accept();
	}
}



/** Tells the dialog that all actions were
  * done and replaces 'Cancel' with 'Close'.
  */
void frmTerminalDisplay::setFinished(bool fin) {
	canceled = !finished;
	finished = fin;

	if(fin) {
		btnCancel->setText(tr("Close"));
		btnCancel->setIconSet(DBSDGlobal::getIconLoader()->loadIcon("fileclose",
																						DBSDIconLoader::Button));
	} else {
		btnCancel->setText(tr("Cancel"));
		btnCancel->setIconSet(DBSDGlobal::getIconLoader()->loadIcon("button_cancel",
																						DBSDIconLoader::Button));
	}
}


TerminalDisplay * frmTerminalDisplay::getTerminalDisplay() {
	return terminalDisplay;
}


void frmTerminalDisplay::initGraphics() {
	DBSDIconLoader *iloader = DBSDGlobal::getIconLoader();
	btnCancel->setIconSet(iloader->loadIcon("button_cancel", DBSDIconLoader::Button));
}


void frmTerminalDisplay::setCancelEnabled(bool enabled) {
	if(enabled)
		btnCancel->show();
	else
		btnCancel->hide();
}
