Subversion Repositories Projects

Rev

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

/***************************************************************************
 *   Copyright (C) 2008 by Manuel Schrape                                  *
 *   manuel.schrape@gmx.de                                                 *
 *                                                                         *
 *   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.        *
 *                                                                         *
 *   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 <QSettings>
#include <QDir>

#include "cSettings.h"

cSettings::cSettings()
{
    Settings_ID = 1;

    read_Settings();
}

void cSettings::read_Settings()
{
    QSettings Setting("QMK", QA_NAME);

    Setting.beginGroup("Global");
        Settings_ID  = Setting.value("Settings ID", Settings_ID).toInt();
    Setting.endGroup();

    Setting.beginGroup("SERVER");
        SERVER.TCP_PORT = Setting.value("TCP-PORT", DEV_IP_PORT).toInt();
        SERVER.UDP_PORT = Setting.value("UDP-PORT", DEV_IP_PORT).toInt();
        SERVER.Password = Setting.value("Password", QString("")).toString();
    Setting.endGroup();

    Setting.beginGroup("CLIENT");
        CLIENT.TTY_MAX = Setting.value("TTY_MAX", 1).toInt();
        CLIENT.TTY_ID  = Setting.value("TTY_ID",  0).toInt();

        for (int z = 0; z < CLIENT.TTY_MAX; z++)
        {
            CLIENT.TTY_DEVICES[z] = Setting.value("TTY_DEVICE_" + QString("%1").arg(z), QString("/dev/ttyS3")).toString();
        }
        CLIENT.TCP_MAX      = Setting.value("TCP_MAX", 1).toInt();
        CLIENT.TCP_ID       = Setting.value("TCP_ID",  0).toInt();
        CLIENT.TCP_Password = Setting.value("Password", QString("")).toString();

        for (int z = 0; z < CLIENT.TCP_MAX; z++)
        {
            CLIENT.TCP_SERVER[z] = Setting.value("TCP_SERVER_" + QString("%1").arg(z), QString("127.0.0.1:64400")).toString();
        }
    Setting.endGroup();

    Setting.beginGroup("GUI");
        GUI.isMax       = Setting.value("IsMax",false).toBool();
        GUI.Size        = Setting.value("Size", QSize(500, 350)).toSize();
        GUI.Point       = Setting.value("Point",QPoint(1,1)).toPoint();
    Setting.endGroup();
}

void cSettings::write_Settings()
{
    QSettings Setting("QMK", QA_NAME);

    Setting.beginGroup("Global");
        Setting.setValue("Settings ID", Settings_ID);
    Setting.endGroup();

    Setting.beginGroup("SERVER");
        Setting.setValue("TCP-PORT", SERVER.TCP_PORT);
        Setting.setValue("UDP-PORT", SERVER.UDP_PORT);
        Setting.setValue("Password", SERVER.Password);
    Setting.endGroup();

    Setting.beginGroup("CLIENT");
        Setting.setValue("TTY_MAX", CLIENT.TTY_MAX);
        Setting.setValue("TTY_ID",  CLIENT.TTY_ID);
        Setting.setValue("Password", CLIENT.TCP_Password);

        for (int z = 0; z < CLIENT.TTY_MAX; z++)
        {
            Setting.setValue("TTY_DEVICE_" + QString("%1").arg(z), CLIENT.TTY_DEVICES[z]);
        }

        Setting.setValue("TCP_MAX", CLIENT.TCP_MAX);
        Setting.setValue("TCP_ID",  CLIENT.TCP_ID);

        for (int z = 0; z < CLIENT.TCP_MAX; z++)
        {
            Setting.setValue("TCP_SERVER_" + QString("%1").arg(z), CLIENT.TCP_SERVER[z]);
        }
    Setting.endGroup();

    Setting.beginGroup("GUI");
        Setting.setValue("IsMax", GUI.isMax);
        Setting.setValue("Size", GUI.Size);
        Setting.setValue("Point", GUI.Point);
    Setting.endGroup();

}