2 * kPPP: A front end for pppd for the KDE project
4 * Copyright (C) 1997 Bernd Johannes Wuebben
5 * wuebben@math.cornell.edu
7 * This file contributed by: Markus Wuebben, mwuebben@fiwi02.wiwi.uni-tuebingen.de
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <QVBoxLayout>
32 #include <QHBoxLayout>
33 #include <QGridLayout>
34 #include <QCloseEvent>
35 #include <QApplication>
36 #include <kwindowsystem.h>
37 #include <kmessagebox.h>
38 #include <kpushbutton.h>
39 #include "modeminfo.h"
42 #include <kiconloader.h>
44 ModemTransfer::ModemTransfer(QWidget
*parent
, const char *name
)
49 setWindowTitle(i18n("ATI Query"));
50 KWindowSystem::setIcons(winId(), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Desktop
),IconSize(KIconLoader::Desktop
)), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Small
),IconSize(KIconLoader::Small
)));
52 QVBoxLayout
*tl
= new QVBoxLayout(this);
56 progressBar
= new QProgressBar(this);
57 progressBar
->setMaximum(8);
59 statusBar
= new QLabel( this );
60 statusBar
->setObjectName( "sBar" );
61 statusBar
->setFrameStyle(QFrame::Panel
|QFrame::Sunken
);
62 statusBar
->setAlignment(Qt::AlignCenter
);
64 // This is a rather complicated case. Since we do not know which
65 // message is the widest in the national language, we'd to
66 // search all these messages. This is a little overkill, so I take
67 // the longest english message, translate it and give it additional
68 // 20 percent space. Hope this is enough.
69 statusBar
->setText(i18n("Unable to create modem lock file."));
70 statusBar
->setFixedWidth((statusBar
->sizeHint().width() * 12) / 10);
71 statusBar
->setFixedHeight(statusBar
->sizeHint().height() + 4);
74 statusBar
->setText(i18n("Looking for modem..."));
75 progressBar
->setFixedHeight(statusBar
->minimumSize().height());
76 tl
->addWidget(progressBar
);
77 tl
->addWidget(statusBar
);
79 cancel
= new KPushButton(KStandardGuiItem::cancel(), this);
81 connect(cancel
, SIGNAL(clicked()), SLOT(cancelbutton()));
83 QHBoxLayout
*l1
= new QHBoxLayout
;
86 l1
->addWidget(cancel
);
88 setFixedSize(sizeHint());
92 ////////////////////////////////////////////////
94 timeout_timer
= new QTimer(this);
95 connect(timeout_timer
, SIGNAL(timeout()), SLOT(time_out_slot()));
97 scripttimer
= new QTimer(this);
98 connect(scripttimer
, SIGNAL(timeout()), SLOT(do_script()));
100 timeout_timer
->setSingleShot(true);
101 timeout_timer
->start(15000); // 15 secs
102 QTimer::singleShot(500, this, SLOT(init()));
107 void ModemTransfer::ati_done() {
109 timeout_timer
->stop();
110 Modem::modem
->closetty();
111 Modem::modem
->unlockdevice();
114 // open the result window
115 ModemInfo
*mi
= new ModemInfo(this);
116 for(int i
= 0; i
< NUM_OF_ATI
; i
++)
117 mi
->setAtiString(i
, ati_query_strings
[i
]);
125 void ModemTransfer::time_out_slot() {
126 timeout_timer
->stop();
129 KMessageBox::error(this, i18n("Modem query timed out."));
134 void ModemTransfer::init() {
136 qApp
->processEvents();
138 int lock
= Modem::modem
->lockdevice();
141 statusBar
->setText(i18n("Modem device is locked."));
147 statusBar
->setText(i18n("Unable to create modem lock file."));
152 if(Modem::modem
->opentty()) {
153 if(Modem::modem
->hangup()) {
154 usleep(100000); // wait 0.1 secs
155 Modem::modem
->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ...
157 statusBar
->setText(i18n("Modem Ready"));
158 qApp
->processEvents();
159 usleep(100000); // wait 0.1 secs
160 qApp
->processEvents();
161 scripttimer
->start(1000); // this one does the ati query
163 // clear modem buffer
164 Modem::modem
->flush();
166 Modem::modem
->notify(this, SLOT(readChar(unsigned char)));
171 // opentty() or hangup() failed
172 statusBar
->setText(Modem::modem
->modemMessage());
173 step
= 99; // wait until cancel is pressed
174 Modem::modem
->unlockdevice();
178 void ModemTransfer::do_script() {
185 statusBar
->setText("ATI...");
186 progressBar
->setValue(progressBar
->value() + 1);
187 Modem::modem
->writeLine("ATI\n");
198 msg
.sprintf("ATI %d ...", step
);
199 query
.sprintf("ATI%d\n", step
);
200 statusBar
->setText(msg
);
201 progressBar
->setValue(progressBar
->value() + 1);
202 Modem::modem
->writeLine(query
.toLocal8Bit());
212 void ModemTransfer::readChar(unsigned char c
) {
213 if(readbuffer
.length() < 255)
217 void ModemTransfer::readtty() {
222 readbuffer
.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r
223 readbuffer
= readbuffer
.trimmed(); // strip of leading or trailing white
226 if(step
<= NUM_OF_ATI
)
227 ati_query_strings
[step
-1] = readbuffer
;
233 void ModemTransfer::cancelbutton() {
235 Modem::modem
->stop();
236 timeout_timer
->stop();
238 statusBar
->setText(i18n("One moment please..."));
239 qApp
->processEvents();
241 Modem::modem
->hangup();
243 Modem::modem
->closetty();
244 Modem::modem
->unlockdevice();
249 void ModemTransfer::closeEvent( QCloseEvent
*e
) {
255 ModemInfo::ModemInfo(QWidget
*parent
, const char* name
)
262 setWindowTitle(i18n("Modem Query Results"));
263 KWindowSystem::setIcons(winId(), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Desktop
),IconSize(KIconLoader::Desktop
)), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Small
),IconSize(KIconLoader::Small
)));
265 QVBoxLayout
*tl
= new QVBoxLayout(this);
269 QGridLayout
*l1
= new QGridLayout();
271 tl
->addLayout(l1
, 1);
272 for(int i
= 0 ; i
< NUM_OF_ATI
; i
++) {
276 label_text
.sprintf("ATI :");
278 label_text
.sprintf("ATI %d:", i
);
280 ati_label
[i
] = new QLabel(label_text
, this);
281 l1
->addWidget(ati_label
[i
], i
, 0);
283 ati_label_result
[i
] = new QLineEdit(this);
284 ati_label_result
[i
]->setMinimumWidth(fontMetrics().width('H') * 24);
285 l1
->addWidget(ati_label_result
[i
], i
, 1);
289 QHBoxLayout
*l2
= new QHBoxLayout
;
290 QPushButton
*ok
= new KPushButton(KStandardGuiItem::close(), this);
291 ok
->setDefault(true);
297 connect(ok
, SIGNAL(clicked()), SLOT(accept()));
300 setMinimumSize(sizeHint());
304 void ModemInfo::setAtiString(int i
, const QString
&s
) {
306 ati_label_result
[i
]->setText(s
);
309 #include "modeminfo.moc"