Diffstat (limited to 'noncore/apps/opie-console/btconfigwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/btconfigwidget.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/btconfigwidget.cpp b/noncore/apps/opie-console/btconfigwidget.cpp new file mode 100644 index 0000000..acc4811 --- a/dev/null +++ b/noncore/apps/opie-console/btconfigwidget.cpp | |||
@@ -0,0 +1,140 @@ | |||
1 | #include <qlabel.h> | ||
2 | #include <qlayout.h> | ||
3 | #include <qcombobox.h> | ||
4 | |||
5 | #include "iolayerbase.h" | ||
6 | #include "btconfigwidget.h" | ||
7 | |||
8 | namespace { | ||
9 | void setCurrent( const QString& str, QComboBox* bo ) { | ||
10 | uint b = bo->count(); | ||
11 | for (uint i = 0; i < bo->count(); i++ ) { | ||
12 | if ( bo->text(i) == str ) { | ||
13 | bo->setCurrentItem( i ); | ||
14 | return; | ||
15 | } | ||
16 | } | ||
17 | bo->insertItem( str ); | ||
18 | bo->setCurrentItem( b ); | ||
19 | } | ||
20 | } | ||
21 | |||
22 | BTConfigWidget::BTConfigWidget( const QString& name, | ||
23 | QWidget* parent, | ||
24 | const char* na ) | ||
25 | : ProfileDialogConnectionWidget( name, parent, na ) { | ||
26 | |||
27 | m_lay = new QVBoxLayout(this ); | ||
28 | m_device = new QLabel(tr("Device"), this ); | ||
29 | m_deviceCmb = new QComboBox(this ); | ||
30 | m_deviceCmb->setEditable( TRUE ); | ||
31 | |||
32 | m_base = new IOLayerBase(this, "base"); | ||
33 | |||
34 | m_lay->addWidget( m_device ); | ||
35 | m_lay->addWidget( m_deviceCmb ); | ||
36 | m_lay->addWidget( m_base ); | ||
37 | |||
38 | m_deviceCmb->insertItem( "/dev/ttyU0" ); | ||
39 | m_deviceCmb->insertItem( "/dev/ttyU1" ); | ||
40 | } | ||
41 | |||
42 | BTConfigWidget::~BTConfigWidget() { | ||
43 | |||
44 | } | ||
45 | void BTConfigWidget::load( const Profile& prof ) { | ||
46 | int rad_flow = prof.readNumEntry("Flow"); | ||
47 | int rad_parity = prof.readNumEntry("Parity"); | ||
48 | int speed = prof.readNumEntry("Speed"); | ||
49 | |||
50 | |||
51 | if (rad_flow == 1) { | ||
52 | m_base->setFlow( IOLayerBase::Hardware ); | ||
53 | } else if (rad_flow == 2) { | ||
54 | m_base->setFlow( IOLayerBase::Software ); | ||
55 | } else if (rad_flow == 0) { | ||
56 | m_base->setFlow( IOLayerBase::None ); | ||
57 | } | ||
58 | |||
59 | if (rad_parity == 1) { | ||
60 | m_base->setParity( IOLayerBase::Even ); | ||
61 | } else { | ||
62 | m_base->setParity( IOLayerBase::Odd ); | ||
63 | } | ||
64 | |||
65 | switch( speed ) { | ||
66 | case 115200: | ||
67 | m_base->setSpeed(IOLayerBase::Baud_115200 ); | ||
68 | break; | ||
69 | case 57600: | ||
70 | m_base->setSpeed( IOLayerBase::Baud_57600 ); | ||
71 | break; | ||
72 | case 38400: | ||
73 | m_base->setSpeed(IOLayerBase::Baud_38400 ); | ||
74 | break; | ||
75 | case 19200: | ||
76 | m_base->setSpeed( IOLayerBase::Baud_19200 ); | ||
77 | break; | ||
78 | case 9600: | ||
79 | default: | ||
80 | m_base->setSpeed(IOLayerBase::Baud_9600 ); | ||
81 | break; | ||
82 | } | ||
83 | |||
84 | if ( prof.readEntry("Device").isEmpty() ) return; | ||
85 | setCurrent( prof.readEntry("Device"), m_deviceCmb ); | ||
86 | |||
87 | } | ||
88 | /* | ||
89 | * save speed, | ||
90 | * flow, | ||
91 | * parity | ||
92 | */ | ||
93 | void BTConfigWidget::save( Profile& prof ) { | ||
94 | int flow, parity, speed; | ||
95 | prof.writeEntry("Device", m_deviceCmb->currentText() ); | ||
96 | |||
97 | |||
98 | switch( m_base->flow() ) { | ||
99 | case IOLayerBase::None: | ||
100 | flow = 0; | ||
101 | break; | ||
102 | case IOLayerBase::Software: | ||
103 | flow = 2; | ||
104 | break; | ||
105 | case IOLayerBase::Hardware: | ||
106 | flow = 1; | ||
107 | break; | ||
108 | } | ||
109 | |||
110 | switch( m_base->parity() ) { | ||
111 | case IOLayerBase::Odd: | ||
112 | parity = 2; | ||
113 | break; | ||
114 | case IOLayerBase::Even: | ||
115 | parity = 1; | ||
116 | break; | ||
117 | } | ||
118 | |||
119 | switch( m_base->speed() ) { | ||
120 | case IOLayerBase::Baud_115200: | ||
121 | speed = 115200; | ||
122 | break; | ||
123 | case IOLayerBase::Baud_57600: | ||
124 | speed = 57600; | ||
125 | break; | ||
126 | case IOLayerBase::Baud_38400: | ||
127 | speed = 38400; | ||
128 | break; | ||
129 | case IOLayerBase::Baud_19200: | ||
130 | speed = 19200; | ||
131 | break; | ||
132 | case IOLayerBase::Baud_9600: | ||
133 | speed = 9600; | ||
134 | break; | ||
135 | } | ||
136 | |||
137 | prof.writeEntry("Flow", flow); | ||
138 | prof.writeEntry("Parity", parity); | ||
139 | prof.writeEntry("Speed", speed); | ||
140 | } | ||