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 setWindowFlags(Qt::WStyle_Customize
|Qt::WStyle_NormalBorder
);
50 setWindowTitle(i18n("ATI Query"));
51 KWindowSystem::setIcons(winId(), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Desktop
),IconSize(KIconLoader::Desktop
)), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Small
),IconSize(KIconLoader::Small
)));
53 QVBoxLayout
*tl
= new QVBoxLayout(this);
57 progressBar
= new QProgressBar(this);
58 progressBar
->setMaximum(8);
60 statusBar
= new QLabel( this );
61 statusBar
->setObjectName( "sBar" );
62 statusBar
->setFrameStyle(QFrame::Panel
|QFrame::Sunken
);
63 statusBar
->setAlignment(Qt::AlignCenter
);
65 // This is a rather complicated case. Since we do not know which
66 // message is the widest in the national language, we'd to
67 // search all these messages. This is a little overkill, so I take
68 // the longest english message, translate it and give it additional
69 // 20 percent space. Hope this is enough.
70 statusBar
->setText(i18n("Unable to create modem lock file."));
71 statusBar
->setFixedWidth((statusBar
->sizeHint().width() * 12) / 10);
72 statusBar
->setFixedHeight(statusBar
->sizeHint().height() + 4);
75 statusBar
->setText(i18n("Looking for modem..."));
76 progressBar
->setFixedHeight(statusBar
->minimumSize().height());
77 tl
->addWidget(progressBar
);
78 tl
->addWidget(statusBar
);
80 cancel
= new KPushButton(KStandardGuiItem::cancel(), this);
82 connect(cancel
, SIGNAL(clicked()), SLOT(cancelbutton()));
84 QHBoxLayout
*l1
= new QHBoxLayout
;
87 l1
->addWidget(cancel
);
89 setFixedSize(sizeHint());
93 ////////////////////////////////////////////////
95 timeout_timer
= new QTimer(this);
96 connect(timeout_timer
, SIGNAL(timeout()), SLOT(time_out_slot()));
98 scripttimer
= new QTimer(this);
99 connect(scripttimer
, SIGNAL(timeout()), SLOT(do_script()));
101 timeout_timer
->setSingleShot(true);
102 timeout_timer
->start(15000); // 15 secs
103 QTimer::singleShot(500, this, SLOT(init()));
108 void ModemTransfer::ati_done() {
110 timeout_timer
->stop();
111 Modem::modem
->closetty();
112 Modem::modem
->unlockdevice();
115 // open the result window
116 ModemInfo
*mi
= new ModemInfo(this);
117 for(int i
= 0; i
< NUM_OF_ATI
; i
++)
118 mi
->setAtiString(i
, ati_query_strings
[i
]);
126 void ModemTransfer::time_out_slot() {
127 timeout_timer
->stop();
130 KMessageBox::error(this, i18n("Modem query timed out."));
135 void ModemTransfer::init() {
137 qApp
->processEvents();
139 int lock
= Modem::modem
->lockdevice();
142 statusBar
->setText(i18n("Modem device is locked."));
148 statusBar
->setText(i18n("Unable to create modem lock file."));
153 if(Modem::modem
->opentty()) {
154 if(Modem::modem
->hangup()) {
155 usleep(100000); // wait 0.1 secs
156 Modem::modem
->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ...
158 statusBar
->setText(i18n("Modem Ready"));
159 qApp
->processEvents();
160 usleep(100000); // wait 0.1 secs
161 qApp
->processEvents();
162 scripttimer
->start(1000); // this one does the ati query
164 // clear modem buffer
165 Modem::modem
->flush();
167 Modem::modem
->notify(this, SLOT(readChar(unsigned char)));
172 // opentty() or hangup() failed
173 statusBar
->setText(Modem::modem
->modemMessage());
174 step
= 99; // wait until cancel is pressed
175 Modem::modem
->unlockdevice();
179 void ModemTransfer::do_script() {
186 statusBar
->setText("ATI...");
187 progressBar
->setValue(progressBar
->value() + 1);
188 Modem::modem
->writeLine("ATI\n");
199 msg
.sprintf("ATI %d ...", step
);
200 query
.sprintf("ATI%d\n", step
);
201 statusBar
->setText(msg
);
202 progressBar
->setValue(progressBar
->value() + 1);
203 Modem::modem
->writeLine(query
.toLocal8Bit());
213 void ModemTransfer::readChar(unsigned char c
) {
214 if(readbuffer
.length() < 255)
218 void ModemTransfer::readtty() {
223 readbuffer
.replace(QRegExp("[\n\r]")," "); // remove stray \n and \r
224 readbuffer
= readbuffer
.trimmed(); // strip of leading or trailing white
227 if(step
<= NUM_OF_ATI
)
228 ati_query_strings
[step
-1] = readbuffer
;
234 void ModemTransfer::cancelbutton() {
236 Modem::modem
->stop();
237 timeout_timer
->stop();
239 statusBar
->setText(i18n("One moment please..."));
240 qApp
->processEvents();
242 Modem::modem
->hangup();
244 Modem::modem
->closetty();
245 Modem::modem
->unlockdevice();
250 void ModemTransfer::closeEvent( QCloseEvent
*e
) {
256 ModemInfo::ModemInfo(QWidget
*parent
, const char* name
)
261 setWindowFlags(Qt::WStyle_Customize
|Qt::WStyle_NormalBorder
);
264 setWindowTitle(i18n("Modem Query Results"));
265 KWindowSystem::setIcons(winId(), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Desktop
),IconSize(KIconLoader::Desktop
)), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Small
),IconSize(KIconLoader::Small
)));
267 QVBoxLayout
*tl
= new QVBoxLayout(this);
271 QGridLayout
*l1
= new QGridLayout();
273 tl
->addLayout(l1
, 1);
274 for(int i
= 0 ; i
< NUM_OF_ATI
; i
++) {
278 label_text
.sprintf("ATI :");
280 label_text
.sprintf("ATI %d:", i
);
282 ati_label
[i
] = new QLabel(label_text
, this);
283 l1
->addWidget(ati_label
[i
], i
, 0);
285 ati_label_result
[i
] = new QLineEdit(this);
286 ati_label_result
[i
]->setMinimumWidth(fontMetrics().width('H') * 24);
287 l1
->addWidget(ati_label_result
[i
], i
, 1);
291 QHBoxLayout
*l2
= new QHBoxLayout
;
292 QPushButton
*ok
= new KPushButton(KStandardGuiItem::close(), this);
293 ok
->setDefault(true);
299 connect(ok
, SIGNAL(clicked()), SLOT(accept()));
302 setMinimumSize(sizeHint());
306 void ModemInfo::setAtiString(int i
, const QString
&s
) {
308 ati_label_result
[i
]->setText(s
);
311 #include "modeminfo.moc"