Diffstat (limited to 'noncore/settings/networksettings/ppp/modeminfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/modeminfo.cpp | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/ppp/modeminfo.cpp b/noncore/settings/networksettings/ppp/modeminfo.cpp new file mode 100644 index 0000000..8c81e67 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/modeminfo.cpp | |||
@@ -0,0 +1,294 @@ | |||
1 | /* | ||
2 | * kPPP: A front end for pppd for the KDE project | ||
3 | * | ||
4 | * $Id$ | ||
5 | * | ||
6 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
7 | * wuebben@math.cornell.edu | ||
8 | * | ||
9 | * This file contributed by: Markus Wuebben, mwuebben@fiwi02.wiwi.uni-tuebingen.de | ||
10 | * | ||
11 | * | ||
12 | * This library is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU Library General Public | ||
14 | * License as published by the Free Software Foundation; either | ||
15 | * version 2 of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This library is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
20 | * Library General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU Library General Public | ||
23 | * License along with this program; if not, write to the Free | ||
24 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | */ | ||
26 | |||
27 | #include <unistd.h> | ||
28 | #include <qregexp.h> | ||
29 | #include <qlayout.h> | ||
30 | // #include <kwin.h> | ||
31 | // #include <kmessagebox.h> | ||
32 | // #include <kapplication.h> | ||
33 | #include <qmessagebox.h> | ||
34 | #include <qapplication.h> | ||
35 | #include "modeminfo.h" | ||
36 | #include "modem.h" | ||
37 | //#include <klocale.h> | ||
38 | #define i18n QObject::tr | ||
39 | |||
40 | ModemTransfer::ModemTransfer(QWidget *parent, const char *name) | ||
41 | : QDialog(parent, name,TRUE, WStyle_Customize|WStyle_NormalBorder) | ||
42 | { | ||
43 | setCaption(i18n("ATI Query")); | ||
44 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
45 | |||
46 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); | ||
47 | |||
48 | progressBar = new QProgressBar(this, "bar"); | ||
49 | progressBar->setTotalSteps(8); | ||
50 | |||
51 | statusBar = new QLabel(this,"sBar"); | ||
52 | statusBar->setFrameStyle(QFrame::Panel|QFrame::Sunken); | ||
53 | statusBar->setAlignment(AlignCenter); | ||
54 | |||
55 | // This is a rather complicated case. Since we do not know which | ||
56 | // message is the widest in the national language, we'd to | ||
57 | // search all these messages. This is a little overkill, so I take | ||
58 | // the longest english message, translate it and give it additional | ||
59 | // 20 percent space. Hope this is enough. | ||
60 | statusBar->setText(i18n("Unable to create modem lock file.")); | ||
61 | statusBar->setFixedWidth((statusBar->sizeHint().width() * 12) / 10); | ||
62 | statusBar->setFixedHeight(statusBar->sizeHint().height() + 4); | ||
63 | |||
64 | // set original text | ||
65 | statusBar->setText(i18n("Looking for modem...")); | ||
66 | progressBar->setFixedHeight(statusBar->minimumSize().height()); | ||
67 | tl->addWidget(progressBar); | ||
68 | tl->addWidget(statusBar); | ||
69 | |||
70 | cancel = new QPushButton(i18n("Cancel"), this); | ||
71 | cancel->setFocus(); | ||
72 | connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); | ||
73 | |||
74 | QHBoxLayout *l1 = new QHBoxLayout; | ||
75 | tl->addLayout(l1); | ||
76 | l1->addStretch(1); | ||
77 | l1->addWidget(cancel); | ||
78 | |||
79 | setFixedSize(sizeHint()); | ||
80 | |||
81 | step = 0; | ||
82 | |||
83 | //////////////////////////////////////////////// | ||
84 | |||
85 | timeout_timer = new QTimer(this); | ||
86 | connect(timeout_timer, SIGNAL(timeout()), SLOT(time_out_slot())); | ||
87 | |||
88 | scripttimer = new QTimer(this); | ||
89 | connect(scripttimer, SIGNAL(timeout()), SLOT(do_script())); | ||
90 | |||
91 | timeout_timer->start(15000,TRUE); // 15 secs single shot | ||
92 | QTimer::singleShot(500, this, SLOT(init())); | ||
93 | |||
94 | } | ||
95 | |||
96 | |||
97 | void ModemTransfer::ati_done() { | ||
98 | scripttimer->stop(); | ||
99 | timeout_timer->stop(); | ||
100 | Modem::modem->closetty(); | ||
101 | Modem::modem->unlockdevice(); | ||
102 | hide(); | ||
103 | |||
104 | // open the result window | ||
105 | ModemInfo *mi = new ModemInfo(this); | ||
106 | for(int i = 0; i < NUM_OF_ATI; i++) | ||
107 | mi->setAtiString(i, ati_query_strings[i]); | ||
108 | mi->exec(); | ||
109 | delete mi; | ||
110 | |||
111 | accept(); | ||
112 | } | ||
113 | |||
114 | |||
115 | void ModemTransfer::time_out_slot() { | ||
116 | timeout_timer->stop(); | ||
117 | scripttimer->stop(); | ||
118 | |||
119 | QMessageBox::warning(this, tr("Error"), i18n("Modem Query timed out.")); | ||
120 | reject(); | ||
121 | } | ||
122 | |||
123 | |||
124 | void ModemTransfer::init() { | ||
125 | |||
126 | qApp->processEvents(); | ||
127 | |||
128 | int lock = Modem::modem->lockdevice(); | ||
129 | if (lock == 1) { | ||
130 | |||
131 | statusBar->setText(i18n("Modem device is locked.")); | ||
132 | return; | ||
133 | } | ||
134 | |||
135 | if (lock == -1) { | ||
136 | |||
137 | statusBar->setText(i18n("Unable to create modem lock file.")); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | |||
142 | if(Modem::modem->opentty()) { | ||
143 | if(Modem::modem->hangup()) { | ||
144 | usleep(100000); // wait 0.1 secs | ||
145 | Modem::modem->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ... | ||
146 | |||
147 | statusBar->setText(i18n("Modem Ready")); | ||
148 | qApp->processEvents(); | ||
149 | usleep(100000); // wait 0.1 secs | ||
150 | qApp->processEvents(); | ||
151 | scripttimer->start(1000); // this one does the ati query | ||
152 | |||
153 | // clear modem buffer | ||
154 | Modem::modem->flush(); | ||
155 | |||
156 | Modem::modem->notify(this, SLOT(readChar(unsigned char))); | ||
157 | return; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | // opentty() or hangup() failed | ||
162 | statusBar->setText(Modem::modem->modemMessage()); | ||
163 | step = 99; // wait until cancel is pressed | ||
164 | Modem::modem->unlockdevice(); | ||
165 | } | ||
166 | |||
167 | |||
168 | void ModemTransfer::do_script() { | ||
169 | QString msg; | ||
170 | QString query; | ||
171 | |||
172 | switch(step) { | ||
173 | case 0: | ||
174 | readtty(); | ||
175 | statusBar->setText("ATI..."); | ||
176 | progressBar->setProgress( progressBar->progress() + 1); | ||
177 | Modem::modem->writeLine("ATI\n"); | ||
178 | break; | ||
179 | |||
180 | case 1: | ||
181 | case 2: | ||
182 | case 3: | ||
183 | case 4: | ||
184 | case 5: | ||
185 | case 6: | ||
186 | case 7: | ||
187 | readtty(); | ||
188 | msg.sprintf("ATI %d ...", step); | ||
189 | query.sprintf("ATI%d\n", step); | ||
190 | statusBar->setText(msg); | ||
191 | progressBar->setProgress( progressBar->progress() + 1); | ||
192 | Modem::modem->writeLine(query.local8Bit()); | ||
193 | break; | ||
194 | |||
195 | default: | ||
196 | readtty(); | ||
197 | ati_done(); | ||
198 | } | ||
199 | step++; | ||
200 | } | ||
201 | |||
202 | void ModemTransfer::readChar(unsigned char c) { | ||
203 | if(readbuffer.length() < 255) | ||
204 | readbuffer += c; | ||
205 | } | ||
206 | |||
207 | void ModemTransfer::readtty() { | ||
208 | |||
209 | if (step == 0) | ||
210 | return; | ||
211 | |||
212 | readbuffer.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r | ||
213 | readbuffer = readbuffer.stripWhiteSpace(); // strip of leading or trailing white | ||
214 | // space | ||
215 | |||
216 | if(step <= NUM_OF_ATI) | ||
217 | ati_query_strings[step-1] = readbuffer.copy(); | ||
218 | |||
219 | readbuffer = ""; | ||
220 | } | ||
221 | |||
222 | |||
223 | void ModemTransfer::cancelbutton() { | ||
224 | scripttimer->stop(); | ||
225 | Modem::modem->stop(); | ||
226 | timeout_timer->stop(); | ||
227 | |||
228 | statusBar->setText(i18n("One moment please...")); | ||
229 | qApp->processEvents(); | ||
230 | |||
231 | Modem::modem->hangup(); | ||
232 | |||
233 | Modem::modem->closetty(); | ||
234 | Modem::modem->unlockdevice(); | ||
235 | reject(); | ||
236 | } | ||
237 | |||
238 | |||
239 | void ModemTransfer::closeEvent( QCloseEvent *e ) { | ||
240 | cancelbutton(); | ||
241 | e->accept(); | ||
242 | } | ||
243 | |||
244 | |||
245 | ModemInfo::ModemInfo(QWidget *parent, const char* name) | ||
246 | : QDialog(parent, name, TRUE, WStyle_Customize|WStyle_NormalBorder) | ||
247 | { | ||
248 | QString label_text; | ||
249 | |||
250 | setCaption(i18n("Modem Query Results")); | ||
251 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
252 | |||
253 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); | ||
254 | |||
255 | QGridLayout *l1 = new QGridLayout(NUM_OF_ATI, 2, 5); | ||
256 | tl->addLayout(l1, 1); | ||
257 | for(int i = 0 ; i < NUM_OF_ATI ; i++) { | ||
258 | |||
259 | label_text = ""; | ||
260 | if ( i == 0) | ||
261 | label_text.sprintf("ATI :"); | ||
262 | else | ||
263 | label_text.sprintf("ATI %d:", i ); | ||
264 | |||
265 | ati_label[i] = new QLabel(label_text, this); | ||
266 | l1->addWidget(ati_label[i], i, 0); | ||
267 | |||
268 | ati_label_result[i] = new QLineEdit(this); | ||
269 | ati_label_result[i]->setMinimumWidth(fontMetrics().width('H') * 24); | ||
270 | l1->addWidget(ati_label_result[i], i, 1); | ||
271 | } | ||
272 | //tl->addSpacing(1); | ||
273 | |||
274 | QHBoxLayout *l2 = new QHBoxLayout; | ||
275 | QPushButton *ok = new QPushButton(i18n("Close"), this); | ||
276 | ok->setDefault(TRUE); | ||
277 | ok->setFocus(); | ||
278 | |||
279 | tl->addLayout(l2); | ||
280 | l2->addStretch(1); | ||
281 | |||
282 | connect(ok, SIGNAL(clicked()), SLOT(accept())); | ||
283 | l2->addWidget(ok); | ||
284 | |||
285 | setMinimumSize(sizeHint()); | ||
286 | } | ||
287 | |||
288 | |||
289 | void ModemInfo::setAtiString(int i, QString s) { | ||
290 | if(i < NUM_OF_ATI) | ||
291 | ati_label_result[i]->setText(s); | ||
292 | } | ||
293 | |||
294 | //#include "modeminfo.moc" | ||