/***************************************************************************
                          CdboBurnOpt.cpp  -  description
                             -------------------
    begin                : Sat May 5 2001
    copyright            : (C) 2001 by Alexy 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 <qspinbox.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qbuttongroup.h>
#include <qlineedit.h>

#include <kaboutdata.h>
#include <kcmodule.h>
#include <klocale.h>
#include <kglobal.h>
#include <dcopclient.h>
#include <kapplication.h>

#include "CdboBurnOpt.h"
#include "CdboBurnOpt.moc"

CdboBurnOpt::CdboBurnOpt( QWidget* parent,  const char* name, WFlags )
	:CdboBurnOptBase( parent, name){

	config = new KConfig("cdbakeovenrc");
	load();
	connect( useCustOptChk, SIGNAL( clicked() ), this, SLOT( useCustOptSlot() ) );
}

CdboBurnOpt::~CdboBurnOpt(){
}
void CdboBurnOpt::load(){
	////////////////////////////////////////////////////////////
	config->setGroup("Recording Options");
	ejectChk->setChecked(config->readBoolEntry("Eject Media At End", true));
	checkDriveChk->setChecked(config->readBoolEntry("Check Drive First", false));
	daoChk->setChecked(config->readBoolEntry("Disk At Once", false));
	overburnChk->setChecked(config->readBoolEntry("Overburn CD", false));
	burnProofChk->setChecked(config->readBoolEntry("Burn Proof", false));
	mcnTxt->setText(config->readEntry("Media Catalog Number", ""));
	
	useCustOptChk->setChecked(config->readBoolEntry("Use Custom Options", false));
	useCustOptSlot();
	
	///////// Custom Opt //////////////////////////////////
	fifoSizeSpn->setValue(config->readNumEntry("FIFO Size", 4));
	useInfChk->setChecked(config->readBoolEntry("Use Inf Files", false));
	ignoreInfSlot();
     defPregapSpn->setValue( config->readNumEntry("Default Pregap", 0) );
     scsiTimeOutSpn->setValue( config->readNumEntry("SCSI Time Out", 45) );
	driverNameTxt->setText(config->readEntry("Driver Name", ""));
	driverOptTxt->setText(config->readEntry("Driver Options", ""));
		
	///////////////Erase opt///////////////////////	
     config->setGroup("Erase Options");
	dummyEraseChk->setChecked(config->readBoolEntry("Dummy Erase", false));
	ejectEraseChk->setChecked(config->readBoolEntry("Eject After Erase", true));
	checkDriveEraseChk->setChecked(config->readBoolEntry("Check Drive First", false));
	
}
//-----------------------------------------------------------------------------------------------
void CdboBurnOpt::save(){
	////////////////////////////////////////////////////////////
	config->setGroup("Recording Options");
     config->writeEntry("Eject Media At End", ejectChk->isChecked());
	config->writeEntry("Check Drive First", checkDriveChk->isChecked());
	config->writeEntry("Disk At Once", daoChk->isChecked());
	config->writeEntry("Overburn CD", overburnChk->isChecked());
	config->writeEntry("Burn Proof", burnProofChk->isChecked());
	config->writeEntry("Media Catalog Number",  mcnTxt->text());	
	config->writeEntry("Use Custom Options", useCustOptChk->isChecked());
	
	///////// Special Opt //////////////////////////////////
	config->writeEntry("FIFO Size", fifoSizeSpn->value());	
	config->writeEntry("Use Inf Files", useInfChk->isChecked());
	config->writeEntry("Default Pregap", defPregapSpn->value());
	config->writeEntry("SCSI Time Out", scsiTimeOutSpn->value());
	config->writeEntry("Driver Name", driverNameTxt->text());
	config->writeEntry("Driver Options", driverOptTxt->text());
	
	///////////////////////////////////////////////////	
     config->setGroup("Erase Options");
     config->writeEntry("Dummy Erase", dummyEraseChk->isChecked());
	config->writeEntry("Eject After Erase", ejectEraseChk->isChecked());
	config->writeEntry("Check Drive First", checkDriveEraseChk->isChecked());
	config->sync();

	QByteArray data;
	if ( !kapp->dcopClient()->isAttached() )
		kapp->dcopClient()->attach();
	kapp->dcopClient()->send( "cdbakeoven*", "CDBakeOvenApp", "emitSettingsChanged()", data );
}
//----------------------------------------------------------------------------------------------
void CdboBurnOpt::defaults(){
	config->deleteGroup("Recording Options");
	config->deleteGroup("Erase Options");
	config->sync();
	load();
}
//----------------------------------------------------------------------------------------------------------
void CdboBurnOpt::ignoreInfSlot(){
   defPregapSpn->setEnabled(useInfChk->isChecked());
   defPregapLbl->setEnabled(useInfChk->isChecked());
}
//------------------------------------------------------------------------------------------
void CdboBurnOpt::useCustOptSlot(){
	custOptPnl->setEnabled(useCustOptChk->isChecked());
}
//---------------------------------------------------------------------------------------------
int CdboBurnOpt::buttons() {
	return KCModule::Default|KCModule::Apply|KCModule::Cancel|KCModule::Ok|KCModule::Help;
}
//---------------------------------------------------------------------------------------------
QString CdboBurnOpt::quickHelp() const{
	return I18N_NOOP("Recording Options.");
}
//---------------------------------------------------------------------------------------------
const KAboutData* CdboBurnOpt::aboutData() const
{

	KAboutData *myAboutData = new KAboutData(I18N_NOOP("cdbakeoven"),
					I18N_NOOP("CD Bake Oven recording options."),
                  0, 0, KAboutData::License_GPL,
                  "(c) 2001 - 2002 Alex Podolsky");

    myAboutData->addAuthor("Alex Podolsky", 0, "alexpod@users.sf.net");

    return myAboutData;
}
//---------------------------------------------------------------------------------------------
extern "C"{
    KCModule *create_cdboburnopt(QWidget *parent, const char *name){
        KGlobal::locale()->insertCatalogue("cdbakeoven");
        return new CdboBurnOpt(parent, name);
    }

}




