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

#include <dbsdmodule.h>
#include <dialogs.h>
#include <NotRoot.h>

#include "dbsdrootonlykcmodule.h"

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

	if(module != NULL) {
		module->reparent(this, QPoint());
		module->initializeModule();
		connect(module, SIGNAL(changed(bool)), SLOT(dbsdChanged(bool)));
	} else {
		notRoot = new NotRoot(this);
		connect(notRoot, SIGNAL(launch()), SLOT(launchRootModule()));
	}
	
	setButtons(buttons());
}

/** The module is deleted automatically here,
  * no need to do this in inherited classes.
  */
DBSDRootOnlyKCModule::~DBSDRootOnlyKCModule() {
}


void	DBSDRootOnlyKCModule::launchRootModule() {
	QProcess  process(QStringList::split(' ', "/usr/local/bin/kdesu kcmshell"));
	process.addArgument(kcmoduleName());
	
	if(!process.start())
		Dialogs::warnDlg(tr("Error:  Unable to launch the KCModule\n"
								  "(KDE-su failed)"));
}
