/***************************************************************************
                          CdboAudioOpt.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 <iostream.h>

#include <qspinbox.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qbuttongroup.h>
#include <qradiobutton.h>
#include <qcombobox.h>
#include <qlineedit.h>

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

#include "CdboAudioOpt.h"
#include "CdboAudioOpt.moc"

CdboAudioOpt::CdboAudioOpt( QWidget* parent,  const char* name, WFlags  )
    		: CdboAudioOptBase( parent, name ){
    	
	config = new KConfig("cdbakeovenrc");
    	load();
}
//--------------------------------------------------------------------------------
CdboAudioOpt::~CdboAudioOpt(){
}
//---------------------------------------------------------------------------------------------
void CdboAudioOpt::load(){
	config->setGroup("Audio Read Options");
	bool  bBuff= config->readBoolEntry("Use cdda2wav", true);
	if(bBuff){
		cdda2wavRBtn->setChecked(true);
		cdda2wavSlot();
	}
	else{
		cdparanoiaRBtn->setChecked(true);
		cdparanoiaSlot();
	}
	abortOnSkpChk->setChecked(config->readBoolEntry("Auto Correction", true));

	splitOutChk->setChecked(config->readBoolEntry("Split Output", true));
	echoChk->setChecked(config->readBoolEntry("Echo", false));
	cddbLookupChk->setChecked(config->readBoolEntry("Perform CDDB Lookup", true));
	
	cdromSpeedSpn->setValue(config->readNumEntry("CD-Rom Speed", 0));
	

	cdromIndSpn->setCurrentItem(config->readNumEntry("CD-Rom Indianess", 0));
	outputIndSpn->setCurrentItem(config->readNumEntry("Output Indianess", 0));
	
	switch(config->readNumEntry("CD Type", 0)){
		case 0: maxQRBtn->setChecked(true); break;
		case 1: stereoRBtn->setChecked(true); break;
		case 2: monoRBtn->setChecked(true); break;
		default: stereoCSRBtn->setChecked(true); break;
	}
}
//-----------------------------------------------------------------------------------------------
void CdboAudioOpt::save(){
	config->setGroup("Audio Read Options");
	config->writeEntry("Use cdda2wav", cdda2wavRBtn->isChecked());
	config->writeEntry("Auto Correction", abortOnSkpChk->isChecked());

	config->writeEntry("Echo", echoChk->isChecked());
	config->writeEntry("Split Output", splitOutChk->isChecked());
	config->writeEntry("Perform CDDB Lookup", cddbLookupChk->isChecked());
	
	if(maxQRBtn->isChecked())
		config->writeEntry("CD Type", 0);
	else if(stereoRBtn->isChecked())
		config->writeEntry("CD Type", 1);
	else if(monoRBtn->isChecked())
		config->writeEntry("CD Type", 2);
	else
		config->writeEntry("CD Type", 3);
	
	config->writeEntry("CD-Rom Speed", cdromSpeedSpn->value());
	
	config->writeEntry("CD-Rom Indianess", cdromIndSpn->currentItem());
	config->writeEntry("Output Indianess", outputIndSpn->currentItem());
	
	
	config->sync();

	QByteArray data;
	if ( !kapp->dcopClient()->isAttached() )
		kapp->dcopClient()->attach();
	kapp->dcopClient()->send( "cdbakeoven*", "CDBakeOvenApp", "emitSettingsChanged()", data );
}
//-----------------------------------------------------------------------------------------------
void CdboAudioOpt::defaults(){
	config->deleteGroup("Audio Read Options");
	config->sync();
	load();
}
//-----------------------------------------------------------------------------------------------
void CdboAudioOpt::cdda2wavSlot(){
	cdda2wavPnl->setEnabled(true);
	cdparanoiaPnl->setEnabled(false);
}
//-----------------------------------------------------------------------------------------------
void CdboAudioOpt::cdparanoiaSlot(){
	cdda2wavPnl->setEnabled(false);
	cdparanoiaPnl->setEnabled(true);
}
//---------------------------------------------------------------------------------------------
int CdboAudioOpt::buttons() {
	return KCModule::Default|KCModule::Apply|KCModule::Cancel|KCModule::Ok|KCModule::Help;
}
//---------------------------------------------------------------------------------------------
QString CdboAudioOpt::quickHelp() const{
	return I18N_NOOP("Audio Copy Settings.");
}
//---------------------------------------------------------------------------------------------
const KAboutData* CdboAudioOpt::aboutData() const
{

	KAboutData *myAboutData = new KAboutData(I18N_NOOP("cdbakeoven"),
					I18N_NOOP("Audio copy options for CD Bake Oven - CD creation tool for KDE."),
                  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_cdboaudioopt(QWidget *parent, const char *name){
        KGlobal::locale()->insertCatalogue("cdbakeoven");
        return new CdboAudioOpt(parent, name);
    }

}
