/***************************************************************************
 *   Copyright (C) 2004 by Judd Baileys                                    *
 *   jbaileys@bigpond.net.au                                               *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "prefadvanced.h"
#include <qdatetime.h>
#include "prefdialog.h"
#include "prefadvancedlayout.h"
PrefAdvanced::PrefAdvanced(QWidget *parent, const char *name, WFlags f)
 : PrefAdvancedLayout(parent, name, f)
{
    autoConnectCheckBox->setChecked(gpppdata.storeAutoStartScheduler());
    disconCheckBox->setChecked(gpppdata.storeAutoStopScheduler());
    disconTimeWidget->setTime(QTime::fromString(gpppdata.autoStopTime()));
    conTimeWidget->setTime(QTime::fromString(gpppdata.autoStartTime()));
    connect(autoConnectCheckBox , SIGNAL( toggled(bool) ), this, SLOT( widgetState(bool) ) );    
}


PrefAdvanced::~PrefAdvanced()
{
}

bool PrefAdvanced::widgetState(bool)
{
    if(autoConnectCheckBox->isChecked() )
    {
        if(disconCheckBox->isChecked() ) {
            disconTimeWidget->setEnabled(FALSE);
	    textLabel1_2_2->setEnabled(FALSE);
	    }    
        else { 
            disconTimeWidget->setEnabled(TRUE);
	    textLabel1_2_2->setEnabled(TRUE); 
    	}
    }
    else
    {
            disconTimeWidget->setEnabled(FALSE);    
	    textLabel1_2_2->setEnabled(FALSE); 
    }
 }

void PrefAdvanced::applyTask() {

    gpppdata.setStoreAutoStartScheduler(autoConnectCheckBox->isChecked());
            
    if(autoConnectCheckBox->isChecked()) {
    gpppdata.setStoreAutoStartScheduler(autoConnectCheckBox->isChecked());
    gpppdata.setAutoStartTime(conTimeWidget->time().toString());
    }
    
    if(!disconCheckBox->isChecked()) {
    gpppdata.setStoreAutoStopScheduler(disconCheckBox->isChecked());
    gpppdata.setAutoStopTime(disconTimeWidget->time().toString());
    }
    else {
    gpppdata.setAutoStopTime("Never");
    gpppdata.setStoreAutoStopScheduler(disconCheckBox->isChecked());

    }
}