/***************************************************************************
 *   Copyright (C) 2006 by Oscar Ljunggren   *
 *   oscar.ljunggren@gmail.com   *
 *                                                                         *
 *   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 "exercises_handler.h"
#include "kapp.h"
#include "settings.h"
#include "kpersonaltrainer_handler.h"
#include <klineedit.h>
#include <klistbox.h>


exercises_handler::exercises_handler(QWidget *parent, const char *name)
    :manageExercises(parent, name)
    	
{
	kcfg_ExercisesList->clear();
	kcfg_ExercisesList->insertStringList(Settings::exercisesList() );
}
// FINISHED: Add data to cfg-file and update the list.
void exercises_handler::newButton_clicked()
{
	
	kcfg_ExercisesList->insertItem(newEdit->text());
	//exercisesSettingsChanged();
	
}


// FINISHED: Add all exercises to a list, using insertStringList from QListBox
void exercises_handler::exercisesSettingsChanged()
{
	//Settings::setExercisesList( kcfg_exercisesList->firstItem() );
	QStringList list;
	for (int i=0; i< (kcfg_ExercisesList->numRows()); i++)
		list.append(kcfg_ExercisesList->text(i));	
	
	Settings::setExercisesList(list);
	Settings::writeConfig();
	
	kcfg_ExercisesList->clear();
	kcfg_ExercisesList->insertStringList(Settings::exercisesList() );
	
}

// TODO : Remove selected exercise and update list
void exercises_handler::removeButton_clicked()
{
	kcfg_ExercisesList->removeItem(kcfg_ExercisesList->currentItem());
	exercisesSettingsChanged();
}








#include "exercises_handler.moc"
