summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/modemconfigwidget.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/modemconfigwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/modemconfigwidget.cpp187
1 files changed, 187 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/modemconfigwidget.cpp b/noncore/apps/opie-console/modemconfigwidget.cpp
new file mode 100644
index 0000000..0968f62
--- a/dev/null
+++ b/noncore/apps/opie-console/modemconfigwidget.cpp
@@ -0,0 +1,187 @@
1#include <qlabel.h>
2#include <qlayout.h>
3#include <qcombobox.h>
4#include <qlineedit.h>
5#include <qpushbutton.h>
6#include <qhbox.h>
7
8#include "iolayerbase.h"
9#include "modemconfigwidget.h"
10#include "atconfigdialog.h"
11#include "dialdialog.h"
12
13namespace {
14 void setCurrent( const QString& str, QComboBox* bo ) {
15 uint b = bo->count();
16 for (uint i = 0; i < bo->count(); i++ ) {
17 if ( bo->text(i) == str ) {
18 bo->setCurrentItem( i );
19 return;
20 }
21 }
22 bo->insertItem( str );
23 bo->setCurrentItem( b );
24 }
25}
26
27ModemConfigWidget::ModemConfigWidget( const QString& name,
28 QWidget* parent,
29 const char* na )
30 : ProfileDialogConnectionWidget( name, parent, na ) {
31
32 m_lay = new QVBoxLayout(this );
33 m_device = new QLabel(tr("Modem is attached to:"), this );
34 m_deviceCmb = new QComboBox(this );
35 m_deviceCmb->setEditable( TRUE );
36
37 QLabel* telLabel = new QLabel( this );
38 telLabel->setText( tr("Enter telefon number here:") );
39 m_telNumber = new QLineEdit( this );
40 QHBox *buttonBox = new QHBox( this );
41 QPushButton *atButton = new QPushButton( buttonBox );
42 atButton->setText( tr("AT commands") );
43 connect( atButton, SIGNAL( clicked() ), this, SLOT( slotAT() ) );
44
45 QPushButton *dialButton = new QPushButton( buttonBox );
46 dialButton->setText( tr("Enter number") );
47 connect( dialButton, SIGNAL( clicked() ), this, SLOT( slotDial() ) );
48
49
50 m_base = new IOLayerBase(this, "base");
51
52 m_lay->addWidget( m_device );
53 m_lay->addWidget( m_deviceCmb );
54 m_lay->addWidget( telLabel );
55 m_lay->addWidget( m_telNumber );
56 m_lay->addWidget( buttonBox );
57 m_lay->addWidget( m_base );
58
59 m_deviceCmb->insertItem( "/dev/ttyS0" );
60 m_deviceCmb->insertItem( "/dev/ttyS1" );
61 m_deviceCmb->insertItem( "/dev/ttyS2" );
62
63
64}
65
66ModemConfigWidget::~ModemConfigWidget() {
67
68}
69void ModemConfigWidget::load( const Profile& prof ) {
70
71 int rad_flow = prof.readNumEntry("Flow");
72 int rad_parity = prof.readNumEntry("Parity");
73 int speed = prof.readNumEntry("Speed");
74 QString number = prof.readEntry("Number");
75
76 if (!number.isEmpty() ) {
77 m_telNumber->setText( number );
78 }
79
80 if (rad_flow == 1) {
81 m_base->setFlow( IOLayerBase::Hardware );
82 } else if (rad_flow == 2) {
83 m_base->setFlow( IOLayerBase::Software );
84 } else if (rad_flow == 0) {
85 m_base->setFlow( IOLayerBase::None );
86 }
87
88 if (rad_parity == 1) {
89 m_base->setParity( IOLayerBase::Even );
90 } else {
91 m_base->setParity( IOLayerBase::Odd );
92 }
93
94 switch( speed ) {
95 case 115200:
96 m_base->setSpeed(IOLayerBase::Baud_115200 );
97 break;
98 case 57600:
99 m_base->setSpeed( IOLayerBase::Baud_57600 );
100 break;
101 case 38400:
102 m_base->setSpeed(IOLayerBase::Baud_38400 );
103 break;
104 case 19200:
105 m_base->setSpeed( IOLayerBase::Baud_19200 );
106 break;
107 case 9600:
108 default:
109 m_base->setSpeed(IOLayerBase::Baud_9600 );
110 break;
111 }
112
113 if ( prof.readEntry("Device").isEmpty() ) return;
114 setCurrent( prof.readEntry("Device"), m_deviceCmb );
115
116}
117/*
118 * save speed,
119 * flow,
120 * parity
121 */
122void ModemConfigWidget::save( Profile& prof ) {
123 int flow, parity, speed;
124 prof.writeEntry("Device", m_deviceCmb->currentText() );
125
126
127 switch( m_base->flow() ) {
128 case IOLayerBase::None:
129 flow = 0;
130 break;
131 case IOLayerBase::Software:
132 flow = 2;
133 break;
134 case IOLayerBase::Hardware:
135 flow = 1;
136 break;
137 }
138
139 switch( m_base->parity() ) {
140 case IOLayerBase::Odd:
141 parity = 2;
142 break;
143 case IOLayerBase::Even:
144 parity = 1;
145 break;
146 }
147
148 switch( m_base->speed() ) {
149 case IOLayerBase::Baud_115200:
150 speed = 115200;
151 break;
152 case IOLayerBase::Baud_57600:
153 speed = 57600;
154 break;
155 case IOLayerBase::Baud_38400:
156 speed = 38400;
157 break;
158 case IOLayerBase::Baud_19200:
159 speed = 19200;
160 break;
161 case IOLayerBase::Baud_9600:
162 speed = 9600;
163 break;
164 }
165
166 prof.writeEntry("Flow", flow);
167 prof.writeEntry("Parity", parity);
168 prof.writeEntry("Speed", speed);
169 prof.writeEntry("Number", m_telNumber->text() );
170}
171
172void ModemConfigWidget::slotAT() {
173 ATConfigDialog conf( this, "ATConfig", true );
174 conf.readConfig();
175 conf.showMaximized();
176 if ( conf.exec() == QDialog::Accepted ) {
177 conf.writeConfig();
178 }
179}
180
181void ModemConfigWidget::slotDial() {
182 DialDialog dial( this, "DialConfig", true );
183 dial.showMaximized();
184 if ( dial.exec() == QDialog::Accepted ) {
185 m_telNumber->setText( dial.number() );
186 }
187}