Subversion Repositories public

Rev

Rev 100 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/***************************************************************************
 *   Copyright (C) 2008 by Andreas Theofilu                                *
 *   andreas@theosys.at                                                    *
 *                                                                         *
 *   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 version 3 of the License.                *
 *                                                                         *
 *   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 "settingswidget.h"
#include <ksimpleconfig.h>
#include <knuminput.h>
#include <kcombobox.h>
#include <kurlrequester.h>
#include <klineedit.h>
#include <qdir.h>

settingsWidget::settingsWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
                : settingsWidgetBase ( parent,name, modal,fl )
{
KComboBox *cb;
QDir dir = QDir::home();
QString path = dir.absPath();

        // Load the config parameters
        cbDevice->setShowLocalProtocol(false);
        cb = cbDevice->comboBox();
        cb->insertURL(KURL("/dev/ttyUSB0"));
        cb->insertURL(KURL("/dev/ttyS0"));
        cb->insertURL(KURL("/dev/ttyS1"));
        KSimpleConfig *cfg = new KSimpleConfig(QString("sportwatcher.rc"), true);
        cfg->setGroup(QString("SportWatcher"));
        intLower1->setValue(cfg->readNumEntry("lower1"));
        intLower2->setValue(cfg->readNumEntry("lower2"));
        intLower3->setValue(cfg->readNumEntry("lower3"));
        intUpper1->setValue(cfg->readNumEntry("upper1"));
        intUpper2->setValue(cfg->readNumEntry("upper2"));
        intUpper3->setValue(cfg->readNumEntry("upper3"));
        intMaxHr->setValue(cfg->readNumEntry("maxHr"));
        intRestHr->setValue(cfg->readNumEntry("restHr"));
        intVO2max->setValue(cfg->readNumEntry("vo2max"));
        intWeight->setValue(cfg->readNumEntry("weight"));
        cbSampleTime->setCurrentItem(cfg->readNumEntry("seconds"));
        cb->insertItem(cfg->readEntry("Device"));
        lnData->setURL(cfg->readEntry("Data", path + "/.sportwatcher"));
        lnHRM->setURL(cfg->readEntry("HRM", path + "/polar"));
        delete cfg;
}

settingsWidget::~settingsWidget()
{
}

/*$SPECIALIZATION$*/
void settingsWidget::btCancelSlot()
{
        done(QDialog::Rejected);
}

void settingsWidget::btSaveSlot()
{
        KSimpleConfig *cfg = new KSimpleConfig(QString("sportwatcher.rc"));
        cfg->setGroup(QString("SportWatcher"));
        // Put the data into the config file
        cfg->writeEntry("lower1", intLower1->value());
        cfg->writeEntry("lower2", intLower2->value());
        cfg->writeEntry("lower3", intLower3->value());
        cfg->writeEntry("upper1", intUpper1->value());
        cfg->writeEntry("upper2", intUpper2->value());
        cfg->writeEntry("upper3", intUpper3->value());
        cfg->writeEntry("maxHr", intMaxHr->value());
        cfg->writeEntry("restHr", intRestHr->value());
        cfg->writeEntry("vo2max", intVO2max->value());
        cfg->writeEntry("weight", intWeight->value());
        cfg->writeEntry("seconds", cbSampleTime->currentItem());
        cfg->writeEntry("Device", cbDevice->comboBox()->currentText());
        cfg->writeEntry("Data", lnData->lineEdit()->text());
        cfg->writeEntry("HRM", lnHRM->lineEdit()->text());
        cfg->sync();
        delete cfg;
        done(QDialog::Accepted);
}



#include "settingswidget.moc"