/***************************************************************************
                          CdboDialogActionFactory.cpp  -  description
                             -------------------
    begin                : Wed Jul 18 2001
    copyright            : (C) 2001 by Alex Podolsky
    email                : alexpod@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include <iostream.h>

#include <qobject.h>
#include <qdir.h>
#include <qapp.h>
#include <qstringlist.h>
#include <qregexp.h>
#include <qstrlist.h>
#include <qvaluelist.h>

#include <kapplication.h>
#include <kconfig.h>
#include <kprocess.h>
#include <kmessagebox.h>
#include <kmimemagic.h>
#include <kmimetype.h>
#include <kfilemetainfo.h>
#include <klocale.h>
#include <krun.h>

#include "CdboDialogBase.h"
#include "CdboDialogActionFactory.h"
#include "CdboDialogActionFactory.moc"
#include "SessionTypeDialog.h"

#include "../cdbosettings/CdboConfigManager.h"

CdboDialogActionFactory::CdboDialogActionFactory( CdboDialogBase* d, const char* name) :
	QObject(0, name){
	//////////
	user = d;
	config = new KConfig("cdbakeovenrc");
	DEBUG_COMMANDS = false;
	checkingDrive = false;
	burning = false;
	erasing = false;
	readingData = false;
	readingAudio = false;
	creatingISO = false;
	creatingCdOnTheFly = false;
	fixating = false;
	unfixated = false;
	decompressingAudio = false;
	resetSessionType();
}
CdboDialogActionFactory::~CdboDialogActionFactory(){

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// PUBLIC INTERFACE    /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::checkDrive(){
	checkingDrive = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	initDriveCheckProcess();
	lunchProcess(cdboProc);
	
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::fixate(){
	fixating = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	initFixateProcess();
	lunchProcess(cdboShellProc);
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::erase(){
	if(user->getType() != CdboDialogBase::EraseDialogType){
		emit processDone(false);
		return;
	}
	erasing = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	initEraseProcess();
	lunchProcess(cdboProc);
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::burn(QString image, bool audio ){
	burning = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	initBurnProcess(image, audio);
	lunchProcess(cdboShellProc);
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::readData(QString in, QString *out){
	readingData = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	initReadDataProcess(in,out);
	lunchProcess(cdboProc);
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::createISO(QStringList *flist, QString imageName){

	creatingISO = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	isoImageName = imageName;
	this->flist = flist;
	isoFileMappings = 0;
	//preparedBootFiles = false;
	if(initCreateISOProcess())
		lunchProcess(cdboShellProc);

}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::createISO(QString *mappings, QString imageName){

	creatingISO = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	isoImageName = imageName;
	this->flist = 0;
	isoFileMappings = mappings;
	//preparedBootFiles = false;

	if(initCreateISOProcess())
		lunchProcess(cdboShellProc);

}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::createCdOnTheFly(QStringList *flist){
	creatingCdOnTheFly = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	isoImageName = "|";
	this->flist = flist;
	isoFileMappings = 0;
	//preparedBootFiles = false;

	if(!initCreateISOProcess())
		return;

	initBurnProcess("-", false);
	lunchProcess(cdboShellProc);
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::createCdOnTheFly(QString *mappings){
	creatingCdOnTheFly = true;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	isoImageName = "|";
	this->flist = 0;
	isoFileMappings = mappings;
	//preparedBootFiles = false;

	if(!initCreateISOProcess())
		return;

	initBurnProcess("-", false);
	lunchProcess(cdboShellProc);
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::readAudio(QString in, QStringList* tracks, QStringList *tmpList){
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");

	this->tmpList = tmpList;
	drName = in;
	tracksDone = 0;
	readingAudio = true;
	user->blockBtns(true);
	
	if(!tracks || tracks->count() == 0){
		///////////////////////////////////////////////////////
		countAudioTracks();
		return;
	}
	totalTracks = tracks->count();
	user->setTotalProcesses( totalTracks);
	tracksList = tracks;
	config->setGroup("Audio Read Options");
	
	if(config->readBoolEntry("Use cdda2wav", true)){
		tracksToCopy = " -t " + (*tracksList)[tracksDone] + "+" + (*tracksList)[tracksDone];
		initCdda2wavProcess();
		tracksDone++;
	}
	else{
		tracksToCopy = (*tracksList)[tracksDone];
		tracksToCopy = (*tracksList)[tracksDone] + "-" + (*tracksList)[tracksDone];
		initCdparanoiaProcess();
		tracksDone++;
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::decompressAudio(QStringList *flist, QStringList *tracksList, QStringList *tmpList){
	if(!flist || flist->count() == 0)
		return;
	if(config)
 		delete config;
	config = new KConfig("cdbakeovenrc");
	user->setProcessType(CdboDialogBase::oggMp3Process);
	
	decompressingAudio = true;
	tracksDone = 0;
	totalTracks = flist->count();
	//user->setTotalProcesses(totalTracks);
	
	this->tmpList = tmpList;
	int mp3 = 0, ogg = 0;
	for(unsigned int i = 0; i < flist->count(); i++){
		KMimeType::Ptr mimetype = KMimeType::findByPath((*flist)[i]);
		QString mType = mimetype->name().latin1();
		if(mType.find("x-mp3") != -1){
			mp3++;
			continue;
		}
		if(mType.find("x-ogg") != -1){
			ogg++;
			continue;
		}
	}
	user->setTotalProcesses(mp3 + ogg);
	
	user->output(CdboDialogBase::InfoMessage,
		i18n("Compilation list contains %n file.","Compilation list contains %n files.",totalTracks));
	user->output(CdboDialogBase::InfoMessage,
		i18n("Of those, %1 MP3 and %2 Ogg Vorbis file(s) will be decompressed.")
			.arg(QString::number(mp3)).arg(QString::number(ogg)));
	this->tracksList = tracksList;
	this->flist = flist;
	while(!initDecompressAudioProcess((*flist)[tracksDone])){
		if(tracksDone == totalTracks){
			emit processDone(true);
			return;
		}
	}
	
	lunchProcess(cdboShellProc);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// PROCESS INIT    /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initDriveCheckProcess(){
	cdboProc = new KProcess();
	*cdboProc << "cdrecord";
	///
	*cdboProc  << "-v";
	
	*cdboProc  << "-checkdrive";
	*cdboProc  << "driveropts=help";
	*cdboProc  << "dev=" + user->getScsiDevice();
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initEraseProcess(){
	
	cdboProc = new KProcess();
	user->status(i18n("Erasing..."));
	*cdboProc << "cdrecord";
	config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			*cdboProc  << "-v"; break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboProc  << "-s"; break;
				case 1:	 *cdboProc  << "-v"; break;
				case 2:	 *cdboProc  << "-V"; break;
				case 3: *cdboProc  << "-VV"; break;
			}
			if(config->readBoolEntry("Show Debug Info", false))
				*cdboProc  << "-d";
			break;
		}
		default:{
			*cdboProc  << "-s"; break;
		}
	}
	config->setGroup("Erase Options");
     	if(config->readBoolEntry("Dummy Erase", false)){
		user->status(i18n("Erasing (dummy)..."));
		*cdboProc  << "-dummy";
	}
	
     if(config->readBoolEntry("Eject After Erase", true))
		*cdboProc  << "-eject";
	
	if(config->readBoolEntry("Force Blank", true))
		*cdboProc  << "-force";
				
	*cdboProc  << "blank=" + user->getActionType();
	*cdboProc  << "speed=" + user->getSpeed();
	*cdboProc  << "dev=" + user->getScsiDevice();
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initFixateProcess(){
	
	user->status(i18n("Fixating..."));
	////////////////////////////////////////////////////////////
	
	cdboShellProc = new KShellProcess();	
	
	*cdboShellProc << "cdrecord";
	config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			*cdboShellProc  << "-v"; break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboShellProc  << "-s"; break;
				case 1:	 *cdboShellProc  << "-v"; break;
				case 2:	 *cdboShellProc  << "-V"; break;
				case 3: *cdboShellProc  << "-VV"; break;
			}
			if(config->readBoolEntry("Show Debug Info", false))
				*cdboShellProc  << "-d";
			break;
		}
		default:{
			*cdboShellProc  << "-s"; break;
		}
	}
	config->setGroup("Recording Options");
	///// eject or not
	if(config->readBoolEntry("Eject Media At End", true))
		*cdboShellProc  << "-eject";
		
	//////// speed
	*cdboShellProc  << "speed="  + user->getSpeed();
	
	//////// dummy
	if(user->getActionType() == "dummy"){
		user->status(i18n("Fixating (dummy)..."));
		*cdboShellProc  << "-dummy";
	}
	
	//////////// fixate
	*cdboShellProc  << "-fix";
	
	
	if(config->readBoolEntry("Burn Proof", false))
		*cdboShellProc  << "driveropts=burnproof";
	
	
	if(config->readBoolEntry("Use Custom Options", false))
		addCustomBurnOpt();
	
	//////////// device
	*cdboShellProc  << "dev=" + user->getScsiDevice();
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initReadDataProcess(QString in, QString *out){
	user->status(i18n("Reading CDROM..."));
	*out += ".iso";
	cdboProc = new KProcess();	
	*cdboProc << "dd";
	*cdboProc << "if=" + in;
	*cdboProc << "of=" + *out + "";
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initBurnProcess(QString image, bool audio ){
		user->setProcessType(CdboDialogBase::cdrecordProcess);
		user->setTotalProcesses(1);
		user->status(i18n("Writing..."));
	////////////////////////////////////////////////////////////
	
	if(image != "-")
		cdboShellProc = new KShellProcess();	
	
	*cdboShellProc << "cdrecord";
	config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			*cdboShellProc  << "-v"; break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboShellProc  << "-s"; break;
				case 1:	 *cdboShellProc  << "-v"; break;
				case 2:	 *cdboShellProc  << "-V"; break;
				case 3: *cdboShellProc  << "-VV"; break;
			}
			if(config->readBoolEntry("Show Debug Info", false))
				*cdboShellProc  << "-d";
			break;
		}
		default:{
			*cdboShellProc  << "-s"; break;
		}
	}
	config->setGroup("Recording Options");
	///// eject or not
	if(config->readBoolEntry("Eject Media At End", true))
		*cdboShellProc  << "-eject";
		
	//////// speed
	*cdboShellProc  << "speed="  + user->getSpeed();
	
	//////// dummy
	if(user->getActionType() == "dummy"){
		user->status(i18n("Writing (dummy)..."));
		*cdboShellProc  << "-dummy";
	}
	
	/////////////////////////////////////////////////////////////////+++++++++++
	config->setGroup("ISO Settings");	
	
	bool ms = config->readEntry("Session Type", "Single") ==  "Multi-Session";
	if(ms){
		if(user->getType() == CdboDialogBase::NewCdDialogType &&
				sessionType != SessionTypeDialog::finalSession &&
				sessionType != SessionTypeDialog::invalidSession){
			*cdboShellProc  << "-multi";
		}
		if(creatingCdOnTheFly)
			*cdboShellProc  << "-waiti";
	}
	/////////////////////////////////////////////////////////////////+++++++++++
	config->setGroup("Recording Options");
	if(user->getActionType().find("append") != -1){
		ms = true;
		if(sessionType == SessionTypeDialog::firstSession || sessionType == SessionTypeDialog::middleSession)
			*cdboShellProc  << "-multi";
		else if(sessionType == SessionTypeDialog::invalidSession){
			int result = KMessageBox::questionYesNo(0,
					"Will this be the final session on this CD?",
        				"Final session?",
        				QString("&Yes"),
        				QString("&No"));
			switch(result) {
    				case KMessageBox::No:{
					sessionType = SessionTypeDialog::middleSession;
					*cdboShellProc  << "-multi";
				}
				case KMessageBox::Yes:{
					sessionType = SessionTypeDialog::finalSession;
				}
			}
		}
		if(user->getActionType() == "dummy append"){
			user->status(i18n("Appending (dummy)..."));
			*cdboShellProc  << "-dummy";
		}
		else
			user->status(i18n("Appending..."));
	}
		
	if(config->readBoolEntry("Disk At Once", false) && !ms)
		*cdboShellProc  << "-dao";
	
	if(config->readBoolEntry("Overburn CD", false))
		*cdboShellProc  << "-overburn";
	
	if(config->readBoolEntry("Burn Proof", false))
		*cdboShellProc  << "driveropts=burnproof";
	
	QString strBuff = config->readEntry("Media Catalog Number", "");
	if(strBuff != "")
		*cdboShellProc  << "mcn=" + strBuff;
	
	if(config->readBoolEntry("Use Custom Options", false))
		addCustomBurnOpt();
	
	//////////// device
	*cdboShellProc  << "dev=" + user->getScsiDevice();
	
	if(audio){
		if(!config->readBoolEntry("Fixate CD", true)){
			unfixated = true;
			*cdboShellProc  << "-nofix";
		}
		*cdboShellProc  << "-audio -pad" ;
	}
	else
		*cdboShellProc  << "-data" ;
	
	//////////// image
	/*
	strBuff = imageAddr.right(imageAddr.length() - imageAddr.findRev("/") - 1);
	//cerr << "Filter: " << filter << endl;
	QDir tempDir(tmpLbl->text(), strBuff);
	
	QStringList flist = tempDir.entryList();
	strBuff = flist.join("' '" + tmpLbl->text());
	strBuff.prepend("'" + tmpLbl->text());
	strBuff.append("'");
	*cdboShellProc << strBuff;*/
	
	if(image == "-")
		*cdboShellProc  << " - ";
	else if(image.left(1) == "'")
		*cdboShellProc  << " " + image + " ";
	else{
		KRun::shellQuote(image);
		*cdboShellProc  << image;
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::addCustomBurnOpt(){
	////////////////////////////////////////////////////////////
	config->setGroup("Recording Options");
	
	int iBuff = config->readNumEntry("FIFO Size", 4);
	if(iBuff > 4)
		*cdboShellProc  << "fs=" + QString::number(iBuff) + "m";
		
	if(config->readBoolEntry("Use Inf Files", false))
		*cdboShellProc  << "-useinfo";
	
	iBuff = config->readNumEntry("Default Pregap", 0);
	*cdboShellProc  << "defpregap=" + QString::number(iBuff);

	iBuff = config->readNumEntry("SCSI Time Out", 0);
	*cdboShellProc  << "timeout=" + QString::number(iBuff);

	QString strBuff = config->readEntry("Driver Name", "");
	if(strBuff != "")
		*cdboShellProc  << "driver=" + strBuff;
	strBuff = config->readEntry("Driver Options", "");
	if(strBuff != "")
		*cdboShellProc  << "driveropts=" + strBuff;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initCdda2wavProcess(){
	user->setProcessType(CdboDialogBase::cdda2wavProcess);
	
	readingAudio = true;
	
	cdboShellProc = new KShellProcess();	
	*cdboShellProc << "cdda2wav" << "-g";
	////////////////////////////
    	config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboShellProc  << "--quiet Q"; break;
				case 1:	 break;
				case 2:	 *cdboShellProc  << "-v 2"; break;
				case 3: *cdboShellProc  << "-v 64"; break;
			}
			if(config->readBoolEntry("Show Debug Info", false))
				*cdboShellProc  << "-V";
			break;
		}
		default:{
			*cdboShellProc  << "--quiet -Q"; break;
		}
	}
	
	///////////////////////////////////////////////////////
	config->setGroup("Audio Read Options");
	
	*cdboShellProc << "-D" << drName;
	
	int iBuff = config->readNumEntry("CD-Rom Speed", 0);
	if(iBuff > 0)
		*cdboShellProc << "-S " + QString::number(iBuff);
		
	//if(config->readBoolEntry("Wait For Signal", false))
		//*cdboShellProc << "-w";
	
	switch(config->readNumEntry("CD Type", 0)){
		case 0: *cdboShellProc << "-x"; break;
		case 1: *cdboShellProc << "-c 2"; break;
		case 2: *cdboShellProc << "-c 1"; break;
		case 3: *cdboShellProc << "-c s"; break;
	}		
	if(config->readBoolEntry("Echo", false))
		*cdboShellProc << "-e";
	
	if(config->readBoolEntry("Perform CDDB Lookup", true))
		*cdboShellProc << "-L";

	if(config->readBoolEntry("Split Output", false))
		*cdboShellProc << "-B";

	/////////////////////////////////////////////////
	*cdboShellProc << tracksToCopy;//"-t " + fromTrack + "+" + toTrack;
	////////////////////////////////////
	
	/*switch(config->readNumEntry("Output Type", 0)){
		case 0:{*/
			*cdboShellProc << "-Owav" ;
			//*imageAddr += ".wav";
			/*break;
		}
		case 1:{
			*cdboShellProc << "-Oaiff";
			*imageAddr += ".aiff";
			break;
		}
		case 2:{
			*cdboShellProc << "-Oaifc";
			*imageAddr += ".aifc";
			break;
		}
		case 4:{
			*cdboShellProc << "-Oau";
			*imageAddr += ".au";
			break;
		}
		case 3:{
			*cdboShellProc << "-Ocdr";
			*imageAddr += ".cdr";
			break;
		}
		default:{
			*cdboShellProc << "-Owav" ;
			*imageAddr += ".wav";
			break;
		}
	}*/
	switch(config->readNumEntry("CD-Rom Indianess", 0)){
		case 1: *cdboShellProc << "-C big"; break;
		case 2: *cdboShellProc << "-C little"; break;
	}
	switch(config->readNumEntry("Output Indianess", 0)){
		case 1: *cdboShellProc << "-E big"; break;
		case 2: *cdboShellProc << "-E little"; break;
	}
	QDate today = QDate::currentDate();
	QTime now = QTime::currentTime();
	QString timeStamp = QString::number(today.month()) +
       		 		"_" + QString::number(today.day()) +
       		 		"_" + QString::number(now.hour()) +
       		 		"_" + QString::number(now.minute()) +
       		 		"_" + QString::number(now.second());
	config->setGroup("Default Settings");
	QString outName = config->readEntry("Tmp Dir", "/tmp/") + "cdbo_audio_" + timeStamp + "_" +
																(*tracksList)[tracksDone] + ".wav";

	tmpList->append(outName);
	KRun::shellQuote(outName);
	*cdboShellProc << outName;
	
	//if(config->readBoolEntry("Split Output", false))
	//	imageAddr->insert(imageAddr->findRev("."), "*");
	lunchProcess(cdboShellProc);
}	
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initCdparanoiaProcess(){
	user->setProcessType(CdboDialogBase::cdparanoiaProcess);////////////////////////////////////
	
	readingAudio = true;
	
	cdboShellProc = new KShellProcess();	
	*cdboShellProc << "cdparanoia";
	
	////////////////////////////
    	config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboShellProc  << "--quiet"; break;
				case 1:	 break;
				case 2:	 *cdboShellProc  << "-v"; break;
				case 3: *cdboShellProc  << "-v"; break;
			}
			break;
		}
		default:{
			*cdboShellProc  << "--quiet"; break;
		}
	}
	
	///////////////////////////////////////////////////////
	config->setGroup("Audio Read Options");
	*cdboShellProc << "-d" << drName;
	
	int iBuff = config->readNumEntry("CD-Rom Speed", 0);
	if(iBuff > 0)
		*cdboShellProc << "-S " + QString::number(iBuff);
	
	if(!config->readBoolEntry("Auto Correction", true))
	 	*cdboShellProc << "-X";
	
	//if(config->readBoolEntry("Split Output", false))
	//	*cdboShellProc << "-B";
	
	switch(config->readNumEntry("CD-Rom Indianess", 0)){
		case 1: *cdboShellProc << "-C"; break;
		case 2: *cdboShellProc << "-c"; break;
	}

	/*switch(config->readNumEntry("Output Type", 0)){
		case 0:{*/
			*cdboShellProc << "-w" ;
			//*imageAddr += ".wav";
			/*break;
		}
		case 1:{
			*cdboShellProc << "-f";
			*imageAddr += ".aiff";
			break;
		}
		case 2:{
			*cdboShellProc << "-a";
			*imageAddr += ".aifc";
			break;
		}
		case 3:{
			if(config->readNumEntry("Output Indianess", 0) == 2){
				*cdboShellProc << "-r";
				*imageAddr += ".cdr";
			}
			else{
				*cdboShellProc << "-R";
				*imageAddr += ".cdr";
			}
			break;
		}
		default:{
			*cdboShellProc << "-w" ;
			*imageAddr += ".wav";
			break;
		}
	}*/
	
	*cdboShellProc << tracksToCopy;
	QDate today = QDate::currentDate();
	QTime now = QTime::currentTime();
	QString timeStamp = QString::number(today.month()) +
       		 		"_" + QString::number(today.day()) +
       		 		"_" + QString::number(now.hour()) +
       		 		"_" + QString::number(now.minute()) +
       		 		"_" + QString::number(now.second());
	config->setGroup("Default Settings");
	QString outName = config->readEntry("Tmp Dir", "/tmp/") + "cdbo_audio_" + timeStamp + "_" +
																(*tracksList)[tracksDone] + ".wav";

	tmpList->append(outName);
	KRun::shellQuote(outName);
	*cdboShellProc << outName;
	
	/*if(config->readBoolEntry("Split Output", false))
		imageAddr->insert(imageAddr->findRev("/") + 1, "*");
	*/
	lunchProcess(cdboShellProc);
}
//---------------------------------------------------------------------------------------------
bool CdboDialogActionFactory::initCreateISOProcess(){
	config->setGroup("ISO Settings");
	if(config->readBoolEntry("Bootable", false)/* && !preparedBootFiles*/){
		if(!prepareBootFiles())
			return false;
	}
	user->setProcessType(CdboDialogBase::mkisofsProcess);
	user->setTotalProcesses(1);
	cdboShellProc = new KShellProcess();
	
	*cdboShellProc << "mkisofs";
	////////////////////////////
	config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			*cdboShellProc  << "-v"; break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboShellProc  << "-quiet"; break;
				case 1:	 *cdboShellProc  << "-v"; break;
				case 2:	 *cdboShellProc  << "-vv"; break;
				case 3: *cdboShellProc  << "-vv"; break;
			}
			break;
		}
		default:{
			*cdboShellProc  << "-quiet"; break;
		}
	}
	*cdboShellProc  << "-gui";

	config->setGroup("ISO Settings");
	if(config->readEntry("Session Type", "Single") == "Multi-Session"  &&
		sessionType == SessionTypeDialog::invalidSession){

		SessionTypeDialog *std = new SessionTypeDialog(&sessionType, dynamic_cast<QWidget *> (user), "std", true);
		std->exec();
		delete std;
		switch(sessionType){
			case SessionTypeDialog::firstSession: {
				initStdISOProcess();
				return true;
			}
			case SessionTypeDialog::middleSession:{
				if(config->readBoolEntry("Check old sessions", false))
					checkLastSessions();
				else
					fetchLastSession();
				return false;
			}
			case SessionTypeDialog::finalSession:	{
				if(config->readBoolEntry("Check old sessions", false))
					checkLastSessions();
				else
					fetchLastSession();
				return false;
			}
			default:{
				delete cdboShellProc;
				resetSessionType();
				creatingISO = false;
				creatingCdOnTheFly = false;
				user->output(CdboDialogBase::ErrorMessage,
				 	i18n("Process canceled by user."));
				user->blockBtns(false);
				currentProc = 0;
				user->status(i18n("Ready"));
				emit processCancelled();
				return false;
			}
		}
	}
	else
		initStdISOProcess();
	return true;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initStdISOProcess(){
	//////////////////////////////////////////////
    	config->setGroup("ISO Settings");

	int type = config->readNumEntry("ISO Type", CdboConfigManager::LinWinISO);

	switch(type){
		case CdboConfigManager::LinuxISO:{
			*cdboShellProc << "-r -L -l -allow-multidot -allow-lowercase";
			//cerr << "CdboConfigManager::LinuxISO type\n";
			break;
		}
		case CdboConfigManager::LinWinISO:{
			*cdboShellProc << "-r -J -D";
			//cerr << "CdboConfigManager::LinWinISO type\n";
			break;
		}
		default:{
			initCustomISOProcess();
			//cerr << "Custom type\n";
			break;
		}
	}

	if(config->readBoolEntry("Bootable", false))
		addBootOptions();

	if(config->readBoolEntry("Hybrid", false))
		addHybridOptions();

	if(config->readBoolEntry("Multivolumed Set", false)){
		*cdboShellProc << "-volset-size " + config->readEntry("Volume Set Size", "0");
		*cdboShellProc << "-volset-seqno " + config->readEntry("Volume Set Sequence", "0");
	}


	if(config->readBoolEntry("Follow Sym Links", false))
		*cdboShellProc << "-f";
	if(config->readBoolEntry("Generate Tbl", false))
		*cdboShellProc << " -T";
	if(config->readBoolEntry("Omit Version", false))
		*cdboShellProc << "-N";
	if(config->readBoolEntry("Hide RR", false))
		*cdboShellProc << "-hide-rr-moved";

	/////////////// labels
	QString strBuff  = config->readEntry("Application ID");
	if(strBuff != "")
		*cdboShellProc << "-A '" + strBuff + "'";

	strBuff  = config->readEntry("Copyright");
	if(strBuff != "")
		*cdboShellProc << "-copyright '" + strBuff + "'";

	strBuff  = config->readEntry("Volume ID");
	if(strBuff != "")
		*cdboShellProc << "-V '" + strBuff + "'";

	strBuff  = config->readEntry("Volume Set Name");
	if(strBuff != "")
		*cdboShellProc << "-V '" + strBuff + "'";

	strBuff  = config->readEntry("Publisher ID");
	if(strBuff != "")
		*cdboShellProc << "-P '" + strBuff + "'";

	strBuff  = config->readEntry("Preparer ID");
	if(strBuff != "")
		*cdboShellProc << "-p '" + strBuff + "'";


	strBuff  = config->readEntry("Custom ISO Options");
	if(strBuff != "")
		*cdboShellProc << strBuff;
/////////////////////////////////////////////////////////////////////////
	if(isoImageName == "|"){
		if(!flist){
			*cdboShellProc << "-graft-points";
			if(config->readBoolEntry("Bootable", false))
				*cdboShellProc << bootDir;
			*cdboShellProc << *isoFileMappings;
		}
		else{
			if(config->readBoolEntry("Bootable", false))
				*cdboShellProc << bootDir;
			*cdboShellProc << createFileListString(flist);
		}
		*cdboShellProc << " | ";
	}
	else{
		KRun::shellQuote(isoImageName);
		*cdboShellProc << "-o " + isoImageName + "";
		if(!flist){
			*cdboShellProc << "-graft-points";
			if(config->readBoolEntry("Bootable", false))
				*cdboShellProc << bootDir;
			*cdboShellProc << isoFileMappings->stripWhiteSpace();
		}
		else{
			if(config->readBoolEntry("Bootable", false))
				*cdboShellProc << bootDir;
			*cdboShellProc << createFileListString(flist);
		}
	}

}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::initCustomISOProcess(){

	if(config->readBoolEntry("Rock Ridge", false))
		*cdboShellProc  << "-r";
	if(config->readBoolEntry("Joliet", false))
		*cdboShellProc  << "-J";
	// filenames
	if(config->readBoolEntry("Untrans File Names", false)){
		*cdboShellProc  << "-U";
	}	
	else if(config->readBoolEntry("Relaxed File Names", false)){
		*cdboShellProc  << "-L -l -allow-multidot -allow-lowercase";
		if(!config->readBoolEntry("Do Not Omit Trailing Period", false))
			*cdboShellProc  << "-d";
	}
	else{
        	if(config->readBoolEntry("Begin Period File", false))
        		*cdboShellProc  << "-L";
        	if(config->readBoolEntry("Long File Names", false))
        		*cdboShellProc  << "-l";
        	if(config->readBoolEntry("Multidot File Names", false))
        		*cdboShellProc  << "-allow-multidot";
        	if(config->readBoolEntry("Lower Case File Names", false))	
        		*cdboShellProc  << "-allow-lowercase";
        	if(!config->readBoolEntry("Do Not Omit Trailing Period", false))
			*cdboShellProc  << "-d";
	}
	
	if(config->readBoolEntry("Deep Dir Relocation", false))
		*cdboShellProc  << "-D";
}
//==========================================
QString CdboDialogActionFactory::createFileListString(QStringList *fileList){
	QStringList flist = *fileList;
	QString fnames = "-graft-points", buff = "";
	QFileInfo *d;
	//qApp->processEvents();
	for(int i = 0; i < (int)flist.count(); i++){
		
		d = new QFileInfo( flist[i] );
		if ( !d->exists()){
			delete d;
 			continue;
 		}
 		if(d->isDir()){
			
			buff = "/" + d->fileName() + "/";
			KRun::shellQuote(buff);
			fnames += " " + buff + "=";
			buff = flist[i] + "/";
			KRun::shellQuote(buff);
			fnames += buff;
 			//fnames += " '/" + d->fileName() + "/'='" +  flist[i] + "/' ";
 		}
		else{
			buff = "/" + d->fileName();
			KRun::shellQuote(buff);
			fnames += " " + buff + "=";
			buff = flist[i];
			KRun::shellQuote(buff);
			fnames += buff;
			//fnames += " '/" + d->fileName() + "'='" +  flist[i] + "' ";
		}
	}
	return fnames;
	/*
	QString namesToRemove;
	QString fnames = " ";
	QDir dir;
	QFileInfo *d;
	
	for(int i = 0; i < (int)flist.count(); i++){
		
		d = new QFileInfo( flist[i] );
		if ( !d->exists()){
			delete d;
 			continue;
 		}
 		if(namesToRemove.find(" -x \"" + flist[i] + "\" ") != -1)
   			namesToRemove.replace(QRegExp(" -x \"" + flist[i]  + "\" "), "");
   		else	
   			//cerr << "' -x \"" + flist[i] + "\" '" << " not present in '" << namesToRemove << "'\n";
 		
 		if(d->isFile() || flist[i] == "/"){
 			if(!fnames.contains(" \"" + flist[i] + "\" "))
 				fnames = fnames + " \"" + flist[i] + "\" ";
 			delete d;
 			continue;
 		}	
		else{
			
          		QString buff = d->fileName();
         		
          		dir = d->dir();
          		bool root = dir.isRoot();
          		dir.setFilter(QDir::All|QDir::Hidden);
          		QStringList list = dir.entryList();	
          		list.remove(".");
          		list.remove("..");
          		list.remove(buff);
           		
          		buff = d->dirPath(true);
          		
          		if(!root)
          			buff = buff + "/";
          		
          		for(int y = 0; y < (int)list.count(); y++){
          			if(namesToRemove.find(" -x \"" +buff + list[y] + "\" ") != -1){
          				//cerr << "' -x \"" + buff + list[y] + " '" << "\" present in '" << namesToRemove << "'\n";
          				//namesToRemove.replace(QRegExp(" -x " + buff + list[y]  + " "), "");
          				break;
          			}
          			else{
          				//cerr << "' -x \"" + buff + list[y] + "\" '" << " not present in '" << namesToRemove << "'\n";
          				namesToRemove = namesToRemove + " -x \"" + buff + list[y] + "\" ";
          			}
          		}
          		if(!fnames.contains(buff))
          			fnames = fnames + " \"" + buff + "\" ";
           	
           	delete d;
           	
   		}
	}
	return namesToRemove + fnames;*/
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::addBootOptions(){
	
	/*QString bootCatalog = config->readEntry("Boot Catalog", "");
	QString bootImage = config->readEntry("Boot Image", "");
	if(bootCatalog != "" && bootImage != ""){
		*cdboShellProc  << "-c " + bootCatalog;
		*cdboShellProc  << "-b " + bootImage;
	}*/
	*cdboShellProc  << "-c Boot/boot.cat";
	*cdboShellProc  << "-b Boot/cdrom.img";
	switch(config->readNumEntry("Boot Image Index", 0)){
		case 0: break;
		case 1: *cdboShellProc  << "-hard-disk-boot"; break;
		case 2: *cdboShellProc  << "-no-emul-boot"; break;
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::addHybridOptions(){
	if(config->readBoolEntry("Apple", false))
		*cdboShellProc  << "-apple";
	
	if(config->readBoolEntry("HFS", false) && config->readBoolEntry("Probe", false))
		*cdboShellProc  << "-hfs -probe";
}
//---------------------------------------------------------------------------------------------
bool CdboDialogActionFactory::initDecompressAudioProcess(QString file){
	cdboShellProc = new KShellProcess();	

	KMimeType::Ptr mimetype = KMimeType::findByPath(file);
	QString mType = mimetype->name().latin1();
	tracksDone++;
	QDate today = QDate::currentDate();
      QTime now = QTime::currentTime();
       		
      QString timeStamp = QString::number(today.month()) +
       		 		"_" + QString::number(today.day()) +
       		 		"_" + QString::number(now.hour()) +
       		 		"_" + QString::number(now.minute()) +
       		 		"_" + QString::number(now.second());
	config->setGroup("Default Settings");
	QString outName = config->readEntry("Tmp Dir", "/tmp/") + "cdbo_audio_" + timeStamp + ".wav";
	KRun::shellQuote( file );
	KRun::shellQuote(outName);
	if(mType.find("x-mp3") != -1){
		*cdboShellProc << "mpg123 -v -s " + file + " > " + outName;
		tmpList->append(outName);
		tracksList->append(outName);
		return true;
	}
	else if(mType.find("x-ogg") != -1){	
		*cdboShellProc << "ogg123 -v -d wav -f " + outName + " " + file;
		tracksList->append(outName);
		tmpList->append(outName);
		return true;
	}
	else{
		tracksList->append(file);
		return false;
	}
	////////////////////////////
    	/*config->setGroup("Default Settings");	
	switch(config->readNumEntry("Level Of Output", CdboConfigManager::StandartOutput)){
		case CdboConfigManager::StandartOutput:{
			*cdboShellProc  << "-v"; break;
		}
		case CdboConfigManager::CustomOutput:{
			switch(config->readNumEntry("Custom Level Of Output", 1)){
				case 0:	 *cdboShellProc  << "-quiet"; break;
				case 1:	 break;
				case 2:	 *cdboShellProc  << "-v"; break;
				case 3: *cdboShellProc  << "-v"; break;
			}
			break;
		}
		default:{
			*cdboShellProc  << "-quiet"; break;
		}
	}
	*cdboShellProc << "mpg123 -s ";*/
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// PROCESS LUNCH    ////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::lunchProcess(KProcess *proc){
	config->setGroup("Default Settings");
	proc->setWorkingDirectory(config->readEntry("Tmp Dir", "/tmp/"));

	connect(proc, SIGNAL(processExited(KProcess *)),
		this, SLOT(processDoneSlot(KProcess *)));
	
	connect(proc, SIGNAL(receivedStdout (KProcess *, char *, int)),
		this, SLOT(receivedMessageSlot(KProcess *, char *, int)));
	
	connect(proc, SIGNAL(receivedStderr (KProcess *, char *, int)),
		this, SLOT(receivedErrMessageSlot(KProcess *, char *, int )));
	
	///////////////////////////////////////////////////////
	if(DEBUG_COMMANDS){
		cerr << "\n\n==============DEBUG_COMMANDS==================================\n";
		QValueList<QCString> list = proc->args();
		for(int i = 0; i < (int)list.count(); i++)	
			cerr << " " << list[i];	
		cerr << "\n\n===============DEBUG_COMMANDS=================================\n";
	}
	//return;//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//////////////////////////////////////////////////////////////////
		
	if(proc->start(KProcess::NotifyOnExit, KProcess::AllOutput)){
		currentProc = proc;
		user->blockBtns(true);
		if(checkingDrive){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Checking recording device!"));
			user->status(i18n("Checking device..."));
		}
		if(erasing){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Starting erase process!"));
			//user->status(i18n("Erase in process...."));
		}
		if(fixating){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Starting fixate CD process!"));
			user->status(i18n("Fixating CD...."));
		}
		if(burning){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Starting burn process!"));
			
		}
		if(readingData){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Starting read process!"));
			user->status(i18n("Reading data CD..."));
		}
		if(readingAudio){
			if(tracksDone == 0){
				user->output(CdboDialogBase::StatusOkMessage, i18n("Starting read process!"));
				user->status(i18n("Reading audio CD..."));
			}
		}
		if(creatingISO){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Starting ISO creation process!"));
			user->status(i18n("Creating ISO Image..."));
		}
		if(creatingCdOnTheFly){
			user->output(CdboDialogBase::StatusOkMessage, i18n("Starting 'On-the-fly' CD creation process!"));
			user->status(i18n("Creating CD 'On-the-fly'..."));
		}
		if(decompressingAudio){
			if(tmpList->count() == 1){
				user->output(CdboDialogBase::StatusOkMessage, i18n("Starting to decompress MP3/Ogg Vorbis file(s)!"));
				user->status(i18n("Decompressing Audio..."));
			}
		}	
	}
	else{
		if(checkingDrive){
			checkingDrive = false;
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Device check failed! Make sure you have enough privileges."));
		}
		if(erasing){
			erasing = false;
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Erase process failed to start! Make sure you have enough privileges."));
		}
		if(fixating){
			fixating = false;
			user->output(CdboDialogBase::ErrorMessage,
				i18n("CD fixate process failed to start! Make sure you have enough privileges."));
		}
		if(burning){
			burning = false;
			unfixated = false;
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Burn process failed to start! Make sure you have enough privileges."));
		}
		if(readingData){
			readingData = false;
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Read process failed to start! Make sure you have enough privileges."));
		}
		if(readingAudio){
			readingAudio = false;
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Read process failed to start! Make sure you have enough privileges."));
		}
		if(creatingISO){
			creatingISO = false;
			config->setGroup("ISO Settings");
			if(config->readBoolEntry("Bootable", false))
				removeBootFiles();
			user->output(CdboDialogBase::ErrorMessage,
				i18n("ISO creation process failed to start! Make sure you have enough privileges."));
		}
		if(creatingCdOnTheFly){
			creatingCdOnTheFly = false;
			config->setGroup("ISO Settings");
			if(config->readBoolEntry("Bootable", false))
				removeBootFiles();
			user->output(CdboDialogBase::ErrorMessage,
				 i18n("'On-the-fly' CD creation process failed to start! Make sure you have enough privileges."));
		}
		if(decompressingAudio){
			decompressingAudio = false;
			user->output(CdboDialogBase::ErrorMessage,
				 i18n("Audio decompression failed to start! Make sure you have enough privileges."));
		}
		
		delete proc;
		currentProc = 0;
		resetSessionType();
		user->status(i18n("Ready"));
		emit failedToLunchProcess();
	}	
}	
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::processDoneSlot(KProcess *proc){
	if(proc->normalExit() && proc->exitStatus() == 0){
		if(checkingDrive){
			checkingDrive = false;
			user->output(CdboDialogBase::StatusOkMessage, i18n("Driver for the current drive is present and valid!"));
		}
		if(erasing){
			erasing = false;
			user->output(CdboDialogBase::StatusOkMessage, i18n("Erase completed successfully!"));
			user->status(i18n("Ready"));
			user->blockBtns(false);
		}
		if(fixating){
			fixating = false;
			user->output(CdboDialogBase::StatusOkMessage, i18n("CD fixated successfully!"));
				
		}
		if(decompressingAudio){
			delete proc;
			currentProc = 0;
			if(tracksDone < totalTracks){
				while(!initDecompressAudioProcess((*flist)[tracksDone])){
					if(tracksDone == totalTracks){
						decompressingAudio = false;
						user->output(CdboDialogBase::StatusOkMessage, i18n("MP3/Ogg Vorbis file(s) decompressed successfully!"));
						emit processDone(true);
						return;
					}
				}
				lunchProcess(cdboShellProc);
				return;
			}
			decompressingAudio = false;
			user->output(CdboDialogBase::StatusOkMessage,i18n("MP3/Ogg Vorbis file(s) decompressed successfully!"));
			emit processDone(true);
			return;
		}
		if(burning){
			burning = false;
			user->output(CdboDialogBase::StatusOkMessage, i18n("Burn completed successfully!"));
			if(unfixated){
				unfixated = false;
				user->output(CdboDialogBase::InfoMessage, i18n("This CD was not fxated."));
			}
		}
		if(readingData){
			readingData = false;
			user->output(CdboDialogBase::StatusOkMessage, i18n("Read completed successfully!"));
		}
		if(readingAudio){
			if(tracksDone < totalTracks){
				delete proc;
				currentProc = 0;
				if(config->readBoolEntry("Use cdda2wav", true)){
					tracksToCopy = " -t " + (*tracksList)[tracksDone] + "+" + (*tracksList)[tracksDone];
					initCdda2wavProcess();
					tracksDone++;
				}
				else{
				tracksToCopy = (*tracksList)[tracksDone];
					tracksToCopy = (*tracksList)[tracksDone] + "-" + (*tracksList)[tracksDone];
					initCdparanoiaProcess();
					tracksDone++;
				}
				return;
			}
			readingAudio = false;
			user->output(CdboDialogBase::StatusOkMessage,i18n("Read completed successfully!"));
		}
		if(creatingISO){
			creatingISO = false;
			config->setGroup("ISO Settings");
			if(config->readBoolEntry("Bootable", false))
				removeBootFiles();
			if(!creatingCdOnTheFly)
				user->output(CdboDialogBase::StatusOkMessage,i18n("ISO image created successfully!"));
		}
		if(creatingCdOnTheFly){
			creatingCdOnTheFly = false;
			config->setGroup("ISO Settings");
			if(config->readBoolEntry("Bootable", false))
				removeBootFiles();
			user->output(CdboDialogBase::StatusOkMessage, i18n("'On-the-fly' CD creation process completed successfully!"));
			if(unfixated){
				unfixated = false;
				user->output(CdboDialogBase::InfoMessage, i18n("This CD was not fxated."));
			}
		}
		delete proc;
		currentProc = 0;
		emit processDone(true);
	}
	else{
		if(checkingDrive){
			checkingDrive = false;
			user->output(CdboDialogBase::StatusNotOkMessage, i18n("Not a valid device!"));
		}
		if(erasing){
			erasing = false;
			user->output(CdboDialogBase::StatusNotOkMessage, i18n("Erase failed!"));
		}
		if(fixating){
			fixating = false;
			user->output(CdboDialogBase::StatusNotOkMessage, i18n("Failed to fixate this CD!"));
				
		}
		if(burning){
			burning = false;
			unfixated = false;
			user->output(CdboDialogBase::StatusNotOkMessage, i18n("Burn failed!"));
		}
		if(readingData){
			readingData = false;
			user->output(CdboDialogBase::StatusNotOkMessage, i18n("Read of data CD failed"));
		}
		if(readingAudio){
			readingAudio = false;
			user->output(CdboDialogBase::StatusNotOkMessage,i18n("Read of audio CD failed!"));
		}
		if(decompressingAudio){
			decompressingAudio = false;
			user->output(CdboDialogBase::StatusNotOkMessage,i18n("Failed to decompress MP3/Ogg Vorbis files!"));
		}
		if(creatingISO){
			config->setGroup("ISO Settings");
			if(config->readBoolEntry("Bootable", false))
				removeBootFiles();
			creatingISO = false;
			user->output(CdboDialogBase::StatusNotOkMessage,i18n("Failed to create ISO image!"));
		}
		if(creatingCdOnTheFly){
			config->setGroup("ISO Settings");
			if(config->readBoolEntry("Bootable", false))
				removeBootFiles();
			creatingCdOnTheFly = false;
			user->output(CdboDialogBase::StatusNotOkMessage, i18n("Failed to create CD 'On-the-fly'!"));
		}
		delete proc;
		currentProc = 0;
		resetSessionType();
		user->status(i18n("Ready"));
		qApp->processEvents();
		user->blockBtns(false);
		emit processDone(false);
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::receivedMessageSlot(KProcess *, char *buffer, int buflen){	
	if(buflen > 0){
		
		QString buff(buffer);
		buff = buff.left(buflen);
		
		//cerr << "\n++++++++++++" << buff;
		user->output(CdboDialogBase::InfoMessage, buff);
 	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::receivedErrMessageSlot(KProcess *, char *buffer, int buflen){
	if(buflen > 0){
		QString buff(buffer);
		buff = buff.left(buflen);
		//cerr << "\n+++++++++" << buff;
		user->output(CdboDialogBase::ProcessMessage, buff);
 	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::killCurrentTask(){
	if(currentProc){
		if(currentProc->isRunning()){
			currentProc->kill();
			delete currentProc;
		}
	}
	if(creatingCdOnTheFly || creatingISO){
		config->setGroup("ISO Settings");
		if(config->readBoolEntry("Bootable", false))
			removeBootFiles();
	}
	checkingDrive = false;
	burning = false;
	erasing = false;
	readingData = false;
	readingAudio = false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// REMOVE     /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::removeTmpImage(QString image, QString dirName){
	if(!image) return;
	
	QString filter = image.left(image.findRev(".")) + "*";
	filter = filter.right(filter.length() - filter.findRev("/") - 1);
	//cerr << "Filter: " << filter << endl;
	QDir tempDir(dirName, filter);
	
	QStringList flist = tempDir.entryList();
		
	for(int i = 0; i < (int)flist.count(); i++){
	//cerr << "Removing: " + tmpLbl->text() + flist[i] << endl;
		if(!QFile::remove(dirName + "/" + flist[i])){
			user->output(CdboDialogBase::ErrorMessage, i18n("Failed to remove ") + (dirName +"/" + flist[i]) + "!");
		}
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::removeOneFile(QString fileName){
	if(!fileName) return;
	
	if(!QFile::remove(fileName))
		user->output(CdboDialogBase::ErrorMessage, i18n("Failed to remove ") + fileName + "!");
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::removeOneDir(QString dirName){
	if(!dirName) return;
	QDir dirToRem(dirName);
	if(!dirToRem.rmdir(dirName,true))
		user->output(CdboDialogBase::ErrorMessage, i18n("Failed to remove ") + dirName + "!");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// UTILITIES    /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------------------
bool CdboDialogActionFactory::checkTmp(QString tempDir, int minSize){
	minTmpSize = minSize;
	tempDirName = tempDir;
	QDir dir(tempDirName);
	if(!dir.exists()) return false;
	
	user->status(i18n("Checking temporary directory size..."));
	
	cdboProc = new KProcess();
	
	*cdboProc << "df" << "-m" << tempDir;/////////////////////////////////////////////////////////////////////////////////////

	QApplication::connect(cdboProc, SIGNAL(processExited(KProcess *)),
      			this, SLOT(sizeCheckProcessDoneSlot(KProcess *)));
 	QApplication::connect(cdboProc, SIGNAL(receivedStdout (KProcess *, char *, int)),
		this, SLOT(receivedSizeMessageSlot(KProcess *, char *, int)));
	
	
	if(!cdboProc->start(KProcess::NotifyOnExit, KProcess::AllOutput)){
		delete cdboProc;
		user->output(CdboDialogBase::ErrorMessage,
				i18n("Temporary directory check failed! Make sure you have enough privileges."));
		user->status(i18n("Ready"));
	}
	return true;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::receivedSizeMessageSlot(KProcess *, char *buffer, int buflen){	
	if(buflen > 0){
		QString buff(buffer);
		buff = buff.left(buflen);
		
		QStringList comOutput(QStringList::split("\n",buff));
		comOutput = QStringList::split(" ", comOutput[1]);
		buff = comOutput[3].simplifyWhiteSpace();
		
		if(buff.toInt() > minTmpSize)
			hasSpase = true;
		else
			hasSpase = false;
		if(config)
 			delete config;
		config = new KConfig("cdbakeovenrc");
		config->setGroup("Default Settings");	
		config->writeEntry("tmp Size", buff.toInt());
		user->output(CdboDialogBase::InfoMessage,
			i18n("Directory '")  + tempDirName + i18n("' has ") +  buff + i18n("MB available."));
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::sizeCheckProcessDoneSlot(KProcess *proc){
	delete proc;
	user->status(i18n("Ready"));
	if(!hasSpase)
		emit tmpCheckProcessDone(false);
	else
		emit tmpCheckProcessDone(true);
}
//===================================================
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::countAudioTracks(){
	gotAnswer = false;
	user->status(i18n("Counting audio tracks..."));
	user->output(CdboDialogBase::InfoMessage, i18n("Counting audio tracks..."));
	cdboProc = new KProcess();
	*cdboProc << "cdda2wav" << "-J" << "-g" << "-D" << drName;

	QApplication::connect(cdboProc, SIGNAL(processExited(KProcess *)),
      			this, SLOT(countAudioProcessDoneSlot(KProcess *)));
 	QApplication::connect(cdboProc, SIGNAL(receivedStdout (KProcess *, char *, int)),
		this, SLOT(receivedCountAudioMessageSlot(KProcess *, char *, int)));
	QApplication::connect(cdboProc, SIGNAL(receivedStderr (KProcess *, char *, int)),
		this, SLOT(receivedCountAudioMessageSlot(KProcess *, char *, int)));
		
	if(!cdboProc->start(KProcess::NotifyOnExit, KProcess::AllOutput)){
		user->output(CdboDialogBase::ErrorMessage, i18n("Failed to count number of tracks! "\
				"Make sure you have enough privileges."));
		delete cdboProc;
		user->blockBtns(false);
		user->status(i18n("Ready"));
		emit failedToLunchProcess();
	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::receivedCountAudioMessageSlot(KProcess *, char *buffer, int buflen){	
	if(gotAnswer)
		return;
	//cerr << "Counting audio tracks...\n";
	if(buflen > 0){
		QString buff(buffer);
		//cerr << buff;
		//cerr << "\n";
		if(buff.contains("Permission denied")) {
			gotAnswer = true;
			user->output(CdboDialogBase::ErrorMessage, i18n("Failed to count number of tracks! "\
				"Make sure you have enough privileges."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit processDone(false);
			killCurrentTask();
			return;
		}
		if(buff.contains("Inquiry command failed") || buff.contains("error") || buff.contains("load cdrom please") ||
				buff.contains("Invalid argument") || buff.contains("No medium found")) {
			gotAnswer = true;
			user->output(CdboDialogBase::ErrorMessage, i18n("Failed to count number of tracks! "\
				"This device does not seem to contain a valid audio CD."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit processDone(false);
			killCurrentTask();
			return;
		}
		
		buff = buff.left(buflen);
		buff = buff.replace(QRegExp("\n")," ");
		int pos = buff.find("Tracks:");
		if(pos != -1){
			gotAnswer = true;
			pos += 7;
			buff = buff.right(buff.length() - pos);
			buff = buff.left(buff.find("."));
			
			toTrack = buff.left(buff.find(" "));

			QString totTime = buff.right(buff.length() - buff.find(" "));
			user->output(CdboDialogBase::InfoMessage, i18n("Reading all tracks from Audio CD"));
			user->output(CdboDialogBase::InfoMessage, i18n("Total Tracks: ") + toTrack + i18n(",  Total Time: ") + totTime);
			user->setTotalProcesses( (toTrack.stripWhiteSpace()).toInt() );
			fromTrack = "1";
			killCurrentTask();
			if(config)
 				delete config;
			config = new KConfig("cdbakeovenrc");
			config->setGroup("Audio Read Options");
			if(config->readBoolEntry("Use cdda2wav", true)){
				tracksToCopy = "-t " + fromTrack + "+" + toTrack;
				initCdda2wavProcess();
			}
			else{
				tracksToCopy = fromTrack + "-" + toTrack;
				initCdparanoiaProcess();
			}
		}	
 	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::countAudioProcessDoneSlot(KProcess *proc){
	delete proc;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::fetchLastSession(){

	user->status(i18n("Fetching session info..."));
	//if(cdboProc != 0)
	//	delete cdboProc;
	cdboProc = new KShellProcess();
	
	*cdboProc << "cdrecord";
	*cdboProc << "-msinfo";
	*cdboProc <<  "dev=" + user->getScsiDevice();
	
	if(DEBUG_COMMANDS){
		cerr << "\n\n\n";
		QValueList<QCString> list = cdboProc->args();
		for(int i = 0; i < (int)list.count(); i++)	
			cerr << list[i];	
		cerr << "\n\n\n";
	}
	
	
	QApplication::connect(cdboProc, SIGNAL(processExited(KProcess *)),
      			this, SLOT(fetchLastSessionDoneSlot(KProcess *)));
 	QApplication::connect(cdboProc, SIGNAL(receivedStdout (KProcess *, char *, int)),
		this, SLOT(receivedFetchLastSessionMessageSlot(KProcess *, char *, int)));
	QApplication::connect(cdboProc, SIGNAL(receivedStderr (KProcess *, char *, int)),
		this, SLOT(receivedFetchLastSessionMessageSlot(KProcess *, char *, int)));
		
	if(!cdboProc->start(KProcess::NotifyOnExit, KProcess::AllOutput)){
		user->output(CdboDialogBase::ErrorMessage, i18n("'Fetch last session info' process failed to start! "\
				"Make sure you have enough privileges."));
		delete cdboProc;
		if(cdboShellProc != 0)
			delete cdboShellProc;
			
		user->blockBtns(false);
		user->status(i18n("Ready"));
		emit failedToLunchProcess();
	}
	else
		user->output(CdboDialogBase::InfoMessage, i18n("Fetching last session info, please wait."));
}

//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::receivedFetchLastSessionMessageSlot(KProcess *proc, char *buffer, int buflen){
	if(buflen > 0){

		QString buff(buffer);
		buff = buff.left(buflen);
		//cerr << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
		//cerr << "*buffer = " << buff << endl;
		//cerr << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;

		if(buff.contains("cdrecord: Drive needs to reload the media to return to proper status.")){
			user->output(CdboDialogBase::ProcessMessage, i18n("Drive needs to reload the media to return to proper status."));
			return;
		}
		if(buff.contains("Permission denied")) {
			proc->kill();
			user->output(CdboDialogBase::ErrorMessage,i18n( "Failed to fetch last session info! "\
				"Make sure you have enough privileges."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit failedToLunchProcess();
			resetSessionType();
			creatingISO = false;
			creatingCdOnTheFly = false;
			delete cdboShellProc;
			return;
		}
		if(buff.contains("Usage:")) {
			proc->kill();
			user->output(CdboDialogBase::ErrorMessage, i18n("The combination of options could not be interpreted."));
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Please submit this as a bug to the email address located in the Help->About dialog."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit failedToLunchProcess();
			resetSessionType();
			creatingISO = false;
			creatingCdOnTheFly = false;
			delete cdboShellProc;
			return;
		}

		if(buff.contains("error")) {
			//cerr << "---------------------------------------------------------------------------------" << endl;
			//cerr << "buff = " << buff << endl;
			proc->kill();
			user->output(CdboDialogBase::ErrorMessage, i18n("This CD does not seem to contain a valid session!"));
			user->output(CdboDialogBase::ProcessMessage, buff);
			user->output(CdboDialogBase::ErrorMessage, i18n("Failed to fetch last session info."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit failedToLunchProcess();
			resetSessionType();
			creatingISO = false;
			creatingCdOnTheFly = false;
			delete cdboShellProc;
			return;
		}

		
		buff = buff.replace(QRegExp("\n"), "");

		//cerr << "============= " << buff << "===========" << endl;


		*cdboShellProc << "-C " + buff;
		*cdboShellProc << "-M " + user->getScsiDevice();
		if(config)
 			delete config;
		config = new KConfig("cdbakeovenrc");
		config->setGroup("ISO Settings");
		if(config->readBoolEntry("Check old sessions names", false))
			*cdboShellProc << "-check-oldnames ";
     		if(config->readBoolEntry("Force Rock Ridge", false))
			*cdboShellProc << "-force-rr -no-rr";


		if(creatingISO == true){
			initStdISOProcess();
			lunchProcess(cdboShellProc);
		}
		else{
			initStdISOProcess();
			initBurnProcess("-", false);
			lunchProcess(cdboShellProc);
		}
		//isoImageName = "";
 	}
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::fetchLastSessionDoneSlot(KProcess *proc){
	delete proc;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::checkLastSessions(){
	gotAnswer = false;
	user->status(i18n("Checking previous sessions..."));
	user->blockBtns(true);
	cdboProc = new KShellProcess();
	*cdboProc << "mkisofs";
	*cdboProc << "-check-session " + user->getScsiDevice();
	
	
	if(DEBUG_COMMANDS){
		cerr << "\n\n\n";
		QValueList<QCString> list = cdboProc->args();
		for(int i = 0; i < (int)list.count(); i++)	
			cerr << list[i];	
		cerr << "\n\n\n";
	}
	
	
	QApplication::connect(cdboProc, SIGNAL(processExited(KProcess *)),
      			this, SLOT(fetchLastSessionDoneSlot(KProcess *)));
 	QApplication::connect(cdboProc, SIGNAL(receivedStdout (KProcess *, char *, int)),
		this, SLOT(receivedCheckLastSessionsMessageSlot(KProcess *, char *, int)));
	QApplication::connect(cdboProc, SIGNAL(receivedStderr (KProcess *, char *, int)),
		this, SLOT(receivedCheckLastSessionsMessageSlot(KProcess *, char *, int)));
		
	if(!cdboProc->start(KProcess::NotifyOnExit, KProcess::AllOutput)){
		user->output(CdboDialogBase::ErrorMessage, i18n("'Check previous sessions' process failed to start! "\
				"Make sure you have enough privileges."));
		delete cdboProc;
		if(cdboShellProc != 0)
			delete cdboShellProc;
			
		user->blockBtns(false);
		user->status(i18n("Ready"));
		emit failedToLunchProcess();
	}
	else
		user->output(CdboDialogBase::InfoMessage, i18n("Checking previous sessions, please wait."));
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::receivedCheckLastSessionsMessageSlot(KProcess *, char *buffer, int buflen){
	if(gotAnswer)
		return;
	if(buflen > 0){

		QString buff(buffer);
		//cerr << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
		//cerr << "*buffer = " << buff << endl;
		//cerr << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;


		if(buff.contains("Permission denied")) {
			gotAnswer = true;
			user->output(CdboDialogBase::ErrorMessage, i18n("Failed to fetch last session info! "\
				"Make sure you have enough privileges."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit failedToLunchProcess();
			resetSessionType();
			creatingISO = false;
			creatingCdOnTheFly = false;
			delete cdboShellProc;
			return;
		}
		if(buff.contains("Usage:")) {
			gotAnswer = true;
			user->output(CdboDialogBase::ErrorMessage, i18n("The combination of options could not be interpreted."));
			user->output(CdboDialogBase::ErrorMessage,
				i18n("Please submit this as a bug to the email address located in the Help->About dialog."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit failedToLunchProcess();
			resetSessionType();
			creatingISO = false;
			creatingCdOnTheFly = false;
			delete cdboShellProc;
			return;
		}
		if(buff.contains("error")) {
			gotAnswer = true;
			user->output(CdboDialogBase::ErrorMessage, i18n("This CD does not seem to contain a valid session."));
			user->blockBtns(false);
			user->status(i18n("Ready"));
			emit failedToLunchProcess();
			resetSessionType();
			creatingISO = false;
			creatingCdOnTheFly = false;
			delete cdboShellProc;
			return;
		}
		if(buff.contains("NO Rock Ridge present")) {
			gotAnswer = true;
			user->output(CdboDialogBase::StatusNotOkMessage,
						i18n("Neither Rock Ridge nor TRANS.TBL name translations were found on previous sessions!"));
			int result = KMessageBox::warningYesNo(0,
					i18n("Neither Rock Ridge nor TRANS.TBL name translations were found on previous sessions! "\
					"Would you like to continue anyway?"),
        				i18n("No Rock Ridge present"),
        				i18n("&Yes"),
        				i18n("&Cancel"));
        				
			switch(result){
				case KMessageBox::Yes:{
					fetchLastSession();
					return;
				}
       			case KMessageBox::No:{
       				user->output(CdboDialogBase::ErrorMessage, i18n("Process canceled by user."));
					user->blockBtns(false);
					user->status(i18n("Ready"));
					emit failedToLunchProcess();
					resetSessionType();
					creatingISO = false;
					creatingCdOnTheFly = false;
					delete cdboShellProc;
					return;
				}
			}	
		}
		else{// if(buff.contains("Rock Ridge signatures found")) {
		
			gotAnswer = true;
			user->output(CdboDialogBase::StatusOkMessage, i18n("Previous sessions seem to be valid."));
			qApp->processEvents();
			fetchLastSession();
		}
 	}
}
//---------------------------------------------------------------------------------------------
bool CdboDialogActionFactory::prepareBootFiles(){
	QString bootCatalog = config->readEntry("Boot Catalog", "");
	QString bootImage = config->readEntry("Boot Image", "");
	if(bootCatalog == ""){
		user->output(CdboDialogBase::ErrorMessage,
			i18n("You did not specify the 'Boot Catalog' location, which is required to make a bootable CD."));
		user->output(CdboDialogBase::ErrorMessage,
			i18n("If this is not an attempt to make a bootable CD, please unselect this option."));
		return false;
	}
	if( bootImage == ""){
		user->output(CdboDialogBase::ErrorMessage,
			i18n("You did not specify the 'Boot Image' location, which is required to make a bootable CD."));
		user->output(CdboDialogBase::ErrorMessage,
			i18n("If this is not an attempt to make a bootable CD, please unselect this option."));
		return false;
	}


	config->setGroup("Default Settings");
	bootDir = config->readEntry("Tmp Dir", "/tmp/")  + "cdbo_boot_tmp";
//cerr << "Creating " + bootDir + " \n";
	curJobStillRunning = true;
	curJob = KIO::mkdir(KURL(bootDir));
	connect( curJob, SIGNAL(result( KIO::Job * )), this, SLOT( curJobDone( KIO::Job *)) );
	while(curJobStillRunning)
		qApp->processEvents(1);
//cerr << "Done...... \n";


	//bootDir = bootDir  + "/Boot";
//cerr << "Creating " + bootDir + "/Boot \n";
	curJobStillRunning = true;
	curJob = KIO::mkdir(KURL(bootDir + "/Boot"));
	connect( curJob, SIGNAL(result( KIO::Job * )), this, SLOT( curJobDone( KIO::Job *)) );
	while(curJobStillRunning)
		qApp->processEvents(1);
//cerr << "Done...... \n";


//cerr << "Coppy  " + bootDir + "/Boot/boot.cat \n";
	curJobStillRunning = true;
	curJob = KIO::copy( KURL(bootCatalog), "file:" + bootDir + "/Boot/boot.cat", false );
	connect( curJob, SIGNAL(result( KIO::Job * )), this, SLOT( curJobDone( KIO::Job *)) );
	while(curJobStillRunning)
		qApp->processEvents(1);
//cerr << "Done...... \n";
//cerr << "Coppy  " + bootDir + "/Boot/cdrom.img \n";
	curJobStillRunning = true;
	curJob = KIO::copy( KURL(bootImage), "file:" + bootDir + "/Boot/cdrom.img", false );
	connect( curJob, SIGNAL(result( KIO::Job * )), this, SLOT( curJobDone( KIO::Job *)) );
	while(curJobStillRunning)
		qApp->processEvents(1);

//cerr << "Done...... \n";

	/*connect( curJob, SIGNAL(canceled( KIO::Job * )), this, SLOT( rippCanceled( KIO::Job *)) );
	
	connect( curJob, SIGNAL(infoMessage( KIO::Job *, const QString &)),
			this, SLOT( rippMessage( KIO::Job *,const QString &)) );
	
	connect( curJob, SIGNAL(percent( KIO::Job *,unsigned long)),
			this, SLOT( rippPercent( KIO::Job *,unsigned long)) );
	
	//connect( curJob, SIGNAL(processedFiles( KIO::Job *,unsigned long)),
		//	this, SLOT( rippProcessedFiles( KIO::Job *,unsigned long)) );
	connect( curJob, SIGNAL(copyingDone ( KIO::Job *, const KURL &, const KURL &, bool, bool)),
			this, SLOT( rippedFile( KIO::Job *, const KURL &, const KURL &, bool, bool )) );*/
	
	

	//preparedBootFiles = true;
	return true;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::curJobDone( KIO::Job *j){
	curJobStillRunning = false;
	//delete j;
}
//---------------------------------------------------------------------------------------------
void CdboDialogActionFactory::removeBootFiles(){
	curJob = KIO::rmdir(KURL(bootDir));
	connect( curJob, SIGNAL(result( KIO::Job * )), this, SLOT( curJobDone( KIO::Job *)) );
	removeOneFile(bootDir + "/Boot/cdrom.img");
	removeOneFile(bootDir + "/Boot/boot.cat");
	removeOneDir(bootDir + "/Boot");
	removeOneDir(bootDir);
}


