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

#include <dbsdmodule.h>
#include <LoadingError.h>

#include "dbsdkcmodule.h"

DBSDKCModule::DBSDKCModule(DBSDModule *module,
                           QWidget  *parent,
                           const char  *name,
                           __unused  const QStringList &  list)
	:	KCModule(parent, name),
	
		loadingError(NULL)
{
	this->module = module;

	layout = new QGridLayout(this);
	layout->setAutoAdd(true);

	if(module != NULL) {
		module->reparent(this, QPoint());
		module->initializeModule();
		connect(module, SIGNAL(changed(bool)), SLOT(dbsdChanged(bool)));

		int value = 0;
		if(module != NULL) {
			int supported = module->getSupportedOperations();
			if(supported & DBSDModule::Apply)  value |= Apply;
			if(supported & DBSDModule::Reset)  value |= Reset;
		}
		setButtons(value);

	} else
		loadingError = new LoadingError(this);
	
	setButtons(buttons());
}

DBSDKCModule::DBSDKCModule(QWidget  *parent,
                           const char  *name,
                           __unused  const QStringList &  list)
	:	KCModule(parent, name)
{
	layout = new QGridLayout(this);
	layout->setAutoAdd(true);
}

DBSDKCModule::~DBSDKCModule() {
}


void	DBSDKCModule::load() {
	if(module != NULL)
		module->reset();
}


void	DBSDKCModule::defaults() {
	load();
}


void	DBSDKCModule::save() {
	if(module != NULL)
		module->apply();
}


/** Emitted when the module changes. */
void	DBSDKCModule::dbsdChanged(bool  ch) {
	emit	changed(ch);
}
