summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/iolayerbase.cpp
blob: 1e164fec3f5f0d4639abcdc4abb4048f74fa3a50 (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
#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
    };

    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") );
    m_flowHw = new QRadioButton(tr("Hardware"), m_groupFlow );
    m_flowSw = new QRadioButton(tr("Software"), 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_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;
    }
}
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 {
    return Hardware;
}
IOLayerBase::Parity IOLayerBase::parity()const {
    return Odd;
}
IOLayerBase::Speed IOLayerBase::speed()const{
    return Baud_9600;
}