summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/serialconfigwidget.cpp
blob: 89acc985abefb0656d42021eba8c05ff61bc5eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <qlabel.h>
#include <qlayout.h>
#include <qcombobox.h>

#include "iolayerbase.h"
#include "serialconfigwidget.h"

namespace {
    void setCurrent( const QString& str, QComboBox* bo ) {
        uint b = bo->count();
        for (uint i = 0; i < bo->count(); i++ ) {
            if ( bo->text(i) == str ) {
                bo->setCurrentItem( i );
                return;
            }
        }
        bo->insertItem( str );
        bo->setCurrentItem( b );
    }


}

SerialConfigWidget::SerialConfigWidget( const QString& name,
                                        QWidget* parent,
                                        const char* na )
    : ProfileDialogConnectionWidget( name, parent, na ) {

    m_lay = new QVBoxLayout(this );
    m_device = new QLabel(tr("Device"), this );
    m_deviceCmb = new QComboBox(this );
    m_deviceCmb->setEditable( TRUE );

    m_base = new IOLayerBase(this, "base");

    m_lay->addWidget( m_device );
    m_lay->addWidget( m_deviceCmb );
    m_lay->addWidget( m_base );

    m_deviceCmb->insertItem( "/dev/ttyS0" );
    m_deviceCmb->insertItem( "/dev/ttyS1" );
    m_deviceCmb->insertItem( "/dev/ttySA0");
    m_deviceCmb->insertItem( "/dev/ttySA1");

}
SerialConfigWidget::~SerialConfigWidget() {

}
void SerialConfigWidget::load( const Profile& prof ) {
    int rad_flow = prof.readNumEntry("Flow");
    int rad_parity = prof.readNumEntry("Parity");
    int speed = prof.readNumEntry("Speed");

    if (rad_flow == 1) {
        m_base->setFlow( IOLayerBase::Hardware );
    } else if (rad_flow == 2) {
        m_base->setFlow( IOLayerBase::Software );
    } else {
         m_base->setFlow( IOLayerBase::None );
    }

    if (rad_parity == 1) {
        m_base->setParity( IOLayerBase::Even );
    } else {
        m_base->setParity( IOLayerBase::Odd );
    }

    switch( speed ) {
    case 115200:
        m_base->setSpeed(IOLayerBase::Baud_115200 );
        break;
    case 57600:
        m_base->setSpeed( IOLayerBase::Baud_57600  );
        break;
    case 38400:
        m_base->setSpeed(IOLayerBase::Baud_38400  );
        break;
    case 19200:
        m_base->setSpeed( IOLayerBase::Baud_19200  );
        break;
    case 9600:
    default:
        m_base->setSpeed(IOLayerBase::Baud_9600 );
        break;
    }

    if ( prof.readEntry("Device").isEmpty() ) return;
    setCurrent( prof.readEntry("Device"), m_deviceCmb );

}
/*
 * save speed,
 * flow,
 * parity
 */
void SerialConfigWidget::save( Profile& prof ) {
    int flow, parity, speed;
    prof.writeEntry("Device", m_deviceCmb->currentText() );

    switch( m_base->flow() ) {
    case IOLayerBase::None:
        flow = 0;
        break;
    case IOLayerBase::Software:
        flow = 2;
        break;
    case IOLayerBase::Hardware:
        flow = 1;
        break;
    }

    switch( m_base->parity() ) {
    case IOLayerBase::Odd:
        parity = 2;
        break;
    case IOLayerBase::Even:
        parity = 1;
        break;
    }

    switch( m_base->speed() ) {
    case IOLayerBase::Baud_115200:
        speed = 115200;
        break;
    case IOLayerBase::Baud_57600:
        speed = 57600;
        break;
    case IOLayerBase::Baud_38400:
        speed = 38400;
        break;
    case IOLayerBase::Baud_19200:
        speed = 19200;
        break;
    case IOLayerBase::Baud_9600:
        speed = 9600;
        break;
    }

    prof.writeEntry("Flow",  flow);
    prof.writeEntry("Parity", parity);
    prof.writeEntry("Speed",  speed);
}