summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/iolayerbase.cpp
blob: ec88b49d1907c2334008a7d9eb8f551a2c481aff (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <qlabel.h>
#include <qlayout.h>
#include <qcombobox.h>
#include <qbuttongroup.h>
#include <qhbuttongroup.h>
#include <qradiobutton.h>

#include "iolayerbase.h"

namespace {
    enum ParityIds {
        id_parity_odd,
        id_parity_even
    };

    enum FlowIds {
        id_flow_hw,
        id_flow_sw,
        id_flow_none,
    };

    enum SpeedIds {
        id_baud_115200,
        id_baud_57600,
        id_baud_38400,
        id_baud_19200,
        id_baud_9600
    };

}


IOLayerBase::IOLayerBase( QWidget* par,  const char* name )
    : QWidget( par, name )
{
    m_speedLabel = new QLabel(tr("Speed"), this );
    m_speedBox = new QComboBox(this );

    m_groupFlow = new QButtonGroup(tr("Flow control"),this );
    m_flowHw = new QRadioButton(tr("Hardware"), m_groupFlow );
    m_flowSw = new QRadioButton(tr("Software"), m_groupFlow );
    m_flowNone = new QRadioButton( tr("None"), m_groupFlow );

    m_groupParity = new QButtonGroup(tr("Parity"), this );
    m_parityOdd = new QRadioButton(tr("Odd"), m_groupParity );
    m_parityEven = new QRadioButton(tr("Even"), m_groupParity );

    m_lroot = new QVBoxLayout( this );
    m_lroot->add(m_speedLabel );
    m_lroot->add(m_speedBox );
    m_lroot->setStretchFactor(m_speedLabel, 1);
    m_lroot->setStretchFactor(m_speedBox, 1 );

    m_hbox = new QHBoxLayout(m_groupFlow, 2 );
    m_hbox->add(m_flowHw );
    m_hbox->add(m_flowSw );
    m_hbox->add(m_flowNone );
    m_lroot->add(m_groupFlow );
    m_lroot->setStretchFactor(m_groupFlow, 2 );

    m_hboxPar = new QHBoxLayout( m_groupParity, 2 );
    m_hboxPar->add(m_parityOdd );
    m_hboxPar->add(m_parityEven );
    m_lroot->add(m_groupParity );
    m_lroot->setStretchFactor(m_groupParity, 2 );

    // profiles
    m_speedBox->insertItem(tr("115200 baud"), id_baud_115200 );
    m_speedBox->insertItem(tr("57600 baud"), id_baud_57600   );
    m_speedBox->insertItem(tr("38400 baud"), id_baud_38400   );
    m_speedBox->insertItem(tr("19200 baud"), id_baud_19200   );
    m_speedBox->insertItem(tr("9600 baud"), id_baud_9600     );
};
IOLayerBase::~IOLayerBase() {

}
void IOLayerBase::setFlow( Flow flo ) {
    switch ( flo ) {
    case Software:
        m_flowSw->setChecked( true );
        break;
    case Hardware:
        m_flowHw->setChecked( true );
        break;
    case None:
        m_flowNone->setChecked( true );
        break;
    }
}

void IOLayerBase::setParity( Parity par ) {
    switch( par ) {
    case Odd:
        m_parityOdd->setChecked( true );
        break;
    case Even:
        m_parityEven->setChecked( true );
        break;
    }
}
void IOLayerBase::setSpeed( Speed sp ) {
    int index;
    switch( sp ) {
    case Baud_115200:
        index = id_baud_115200;
        break;
    case Baud_57600:
        index = id_baud_57600;
        break;
    case Baud_38400:
        index = id_baud_38400;
        break;
    case Baud_19200:
        index = id_baud_19200;
        break;
    case Baud_9600:
        index = id_baud_9600;
        break;
    }
    m_speedBox->setCurrentItem(index );
}
IOLayerBase::Flow IOLayerBase::flow()const {
    if (m_flowHw->isChecked() ) {
        qWarning("Hardware flow");
        return Hardware;
    }else if( m_flowSw->isChecked() ) {
        qWarning("Software");
        return Software;
    } else {
        qWarning("None");
        return None;
    }
}
IOLayerBase::Parity IOLayerBase::parity()const {
    if (m_parityOdd->isChecked() )
        return Odd;
    else
        return Even;

}
IOLayerBase::Speed IOLayerBase::speed()const{
    switch( m_speedBox->currentItem() ) {
    case id_baud_115200:
        return Baud_115200;
        break;
    case id_baud_57600:
        return Baud_57600;
        break;
    case id_baud_38400:
        return Baud_38400;
        break;
    case id_baud_19200:
        return Baud_19200;
        break;
    case id_baud_9600:
        return Baud_9600;
        break;
    }
}