Subversion Repositories public

Rev

Rev 168 | 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>
#include <qcheckbox.h>
#include <qradiobutton.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/ttyUSB1"));
        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"));
        // If serial device is selected, activate the radio buttons
        // to select the type of Forerunner used.
        cbSerial->setChecked(cfg->readBoolEntry("Serial", false));

        if (cfg->readBoolEntry("Serial", false))
        {
           rbFr50->setEnabled (true);
//         rbFr405->setEnabled (true);
           cbDevice->setEnabled (true);

           // If "Forerunner" == false, Forerunner 405 is set.
           if (cfg->readBoolEntry("Forerunner", false))
           {
              rbFr50->setChecked(false);
              rbFr405->setChecked(true);
           }
           else
           {
              rbFr50->setChecked(true);
              rbFr405->setChecked(false);
           }
        }
        else
        {
           rbFr50->setEnabled (false);
           rbFr405->setEnabled (false);
           cbDevice->setEnabled (false);
        }

        cbContour->setChecked(cfg->readBoolEntry("Contour", false));
        cbDevice->setURL(cfg->readEntry("Device"));
        lnData->setURL(cfg->readEntry("Data", path + "/.sportwatcher"));
        lnHRM->setURL(cfg->readEntry("HRM", path + "/polar"));
        lnMapFile->setURL(cfg->readEntry("MAP", cfg->readEntry("Data", path + "/.sportwatcher/track.wms")));
        cbUnit->setCurrentItem(cfg->readNumEntry("Units", 0));
        cbMapType->setCurrentItem(cfg->readNumEntry("MapType", 7));
        delete cfg;
}

settingsWidget::~settingsWidget()
{
}

/*$SPECIALIZATION$*/
void settingsWidget::cbSerialSlot (bool state)
{
        if (state)
        {
           rbFr50->setEnabled (true);
//         rbFr405->setEnabled (true);
           cbDevice->setEnabled (true);
        }
        else
        {
           rbFr50->setEnabled (false);
           rbFr405->setEnabled (false);
           cbDevice->setEnabled (false);
        }
}

void settingsWidget::rbFr50Slot (bool state)
{
        if (state && rbFr405->isChecked())
           rbFr405->setChecked(false);
        else
           rbFr405->setChecked(true);
}

void settingsWidget::rbFr405Slot (bool state)
{
        if (state && rbFr50->isChecked())
           rbFr50->setChecked(false);
        else
           rbFr50->setChecked(true);
}

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("Serial", cbSerial->isChecked());
        cfg->writeEntry("Contour", cbContour->isChecked());
        cfg->writeEntry("Device", cbDevice->url());
        cfg->writeEntry("Data", lnData->lineEdit()->text());
        cfg->writeEntry("HRM", lnHRM->lineEdit()->text());
        cfg->writeEntry("MAP", lnMapFile->lineEdit()->text());
        cfg->writeEntry("Units", cbUnit->currentItem());
        cfg->writeEntry("MapType", cbMapType->currentItem());
        cfg->writeEntry("Forerunner", rbFr50->isChecked());
        cfg->sync();
        delete cfg;
        done(QDialog::Accepted);
}



#include "settingswidget.moc"