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

#include "batterysettings.h"

#include <dialogs.h>

#include <qcheckbox.h>
#include <qspinbox.h>

FrmConfig::FrmConfig(QWidget* parent, const char* name, bool modal, WFlags fl)
: uiFrmConfig(parent,name, modal,fl)
{
	BatterySettings s;

	bool lowWarningEnabled = s.isLowWarningEnabled();
	chkLowWarning->setChecked(lowWarningEnabled);
	spinLowWarning->setValue(s.getLowWarningAt());
	spinLowWarning->setEnabled(lowWarningEnabled);

	bool criticalWarningEnabled = s.isCriticalWarningEnabled();
	chkCriticalWarning->setChecked(criticalWarningEnabled);
	spinCriticalWarning->setValue(s.getCriticalWarningAt());
	spinCriticalWarning->setEnabled(criticalWarningEnabled);
}


void FrmConfig::accept() {
	bool lowOn, criticalOn;
	int low, critical;

	low = spinLowWarning->value();
	lowOn = chkLowWarning->isOn();
	critical = spinCriticalWarning->value();
	criticalOn = chkCriticalWarning->isOn();

	if (lowOn && criticalOn && critical >= low)
	{
		Dialogs::warnDlg(tr("The threshold for critical alerts must be below the threshold for low alerts."));
		return;
	}

	BatterySettings s;
	s.setLowWarningEnabled(lowOn);
	s.setLowWarningAt(low);
	s.setCriticalWarningEnabled(criticalOn);
	s.setCriticalWarningAt(critical);

	uiFrmConfig::accept();
}

