2 * kPPP: A front end for pppd for the KDE project
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
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.
26 #include <sys/ioctl.h>
28 #include <sys/types.h>
29 #include <kwindowsystem.h>
30 #include <khelpmenu.h>
31 #include <kiconloader.h>
37 #include <kglobalsettings.h>
40 #include <KStandardGuiItem>
41 #include <kapplication.h>
48 #include <QVBoxLayout>
51 #include <QCloseEvent>
52 #include <ktoolinvocation.h>
55 extern PPPData gpppdata
;
57 MiniTerm::MiniTerm(QWidget
*parent
, const char *name
)
62 setWindowTitle(i18n("Kppp Mini-Terminal"));
63 KWindowSystem::setIcons(winId(), qApp
->windowIcon().pixmap(IconSize(K3Icon::Desktop
),IconSize(K3Icon::Desktop
)), qApp
->windowIcon().pixmap(IconSize(K3Icon::Small
),IconSize(K3Icon::Small
)));
65 m_file
= new QMenu(this);
66 m_file
->addAction( SmallIcon("window-close"), i18n("&Close"), this, SLOT(cancelbutton()) );
67 m_options
= new QMenu(this);
68 m_options
->addAction(i18n("&Reset Modem"),this,SLOT(resetModem()));
71 i18n("MiniTerm - A terminal emulation for KPPP\n\n"
72 "(c) 1997 Bernd Johannes Wuebben <wuebben@kde.org>\n"
73 "(c) 1998 Harri Porten <porten@kde.org>\n"
74 "(c) 1998 Mario Weilguni <mweilguni@kde.org>\n\n"
75 "This program is published under the GNU GPL\n"
76 "(GNU General Public License)"
79 menubar
= new KMenuBar(this);
80 m_file
->setTitle(i18n("&File"));
81 menubar
->addMenu( m_file
);
82 m_options
->setTitle(i18n("&Modem"));
83 menubar
->addMenu( m_options
);
84 m_help
->menu()->setTitle(KStandardGuiItem::help().text());
85 menubar
->addMenu( m_help
->menu());
87 statusbar
= new QLabel(this);
88 statusbar
->setFrameStyle(Q3Frame::Panel
| Q3Frame::Sunken
);
90 terminal
= new MyTerm(this, "term");
94 QVBoxLayout
*layout
=new QVBoxLayout(this);
95 layout
->addWidget(menubar
);
96 layout
->addWidget(toolbar
);
97 layout
->addWidget(terminal
);
98 layout
->addWidget(statusbar
);
100 inittimer
= new QTimer(this);
101 connect(inittimer
,SIGNAL(timeout()),this,SLOT(init()));
102 inittimer
->start(500);
108 MiniTerm::~MiniTerm() {
114 void MiniTerm::setupToolbar() {
115 toolbar
= new KToolBar( this );
117 toolbar
->addAction( KIcon("application-exit"), i18n("Close MiniTerm"), this, SLOT(cancelbutton()));
118 toolbar
->addAction( KIcon("go-previous"), i18n("Reset Modem"), this, SLOT(resetModem()));
119 toolbar
->addAction( KIcon("help-contents"), i18n("Help"), this, SLOT(help()));
121 toolbar
->setMovable(false);
125 void MiniTerm::init() {
127 statusbar
->setText(i18n("Initializing Modem"));
128 qApp
->processEvents();
130 int lock
= Modem::modem
->lockdevice();
132 statusbar
->setText(i18n("Modem device is locked."));
137 statusbar
->setText(i18n("Unable to create modem lock file."));
141 if(Modem::modem
->opentty()) {
142 if(Modem::modem
->hangup()) {
143 // send a carriage return and then wait a bit so that the modem will
144 // let us issue commands.
145 if(gpppdata
.modemPreInitDelay() > 0) {
146 usleep(gpppdata
.modemPreInitDelay() * 5000);
147 Modem::modem
->writeLine("");
148 usleep(gpppdata
.modemPreInitDelay() * 5000);
150 Modem::modem
->writeLine(gpppdata
.modemInitStr(0).toLocal8Bit());
151 usleep(gpppdata
.modemInitDelay() * 10000);
153 statusbar
->setText(i18n("Modem Ready"));
154 terminal
->setFocus();
156 qApp
->processEvents();
157 qApp
->processEvents();
159 Modem::modem
->notify(this, SLOT(readChar(unsigned char)));
164 // opentty() or hangup() failed
165 statusbar
->setText(Modem::modem
->modemMessage());
166 Modem::modem
->unlockdevice();
170 void MiniTerm::readChar(unsigned char c
) {
174 terminal
->backspace();
177 terminal
->mynewline();
180 terminal
->myreturn();
183 terminal
->backspace();
186 terminal
->insertChar(c
);
191 void MiniTerm::cancelbutton() {
192 Modem::modem
->stop();
194 statusbar
->setText(i18n("Hanging up..."));
195 qApp
->processEvents();
196 KApplication::flush();
198 Modem::modem
->hangup();
200 Modem::modem
->closetty();
201 Modem::modem
->unlockdevice();
207 void MiniTerm::resetModem() {
208 statusbar
->setText(i18n("Resetting Modem"));
210 qApp
->processEvents();
211 KApplication::flush();
213 Modem::modem
->hangup();
215 statusbar
->setText(i18n("Modem Ready"));
219 void MiniTerm::closeEvent( QCloseEvent
*e
) {
225 void MiniTerm::help() {
226 KToolInvocation::invokeHelp();
230 MyTerm::MyTerm(QWidget
*parent
, const char* name
)
231 : Q3MultiLineEdit(parent
, name
)
233 setFont(KGlobalSettings::fixedFont());
236 void MyTerm::keyPressEvent(QKeyEvent
*k
) {
244 Modem::modem
->writeChar((unsigned char) k
->ascii());
248 void MyTerm::insertChar(unsigned char c
) {
249 Q3MultiLineEdit::insert(QString(c
));
253 void MyTerm::newLine() {
254 Q3MultiLineEdit::newLine();
259 Q3MultiLineEdit::del();
263 void MyTerm::backspace() {
264 Q3MultiLineEdit::backspace();
268 void MyTerm::myreturn() {
272 getCursorPosition(&line
,&column
);
273 for (int i
= 0; i
< column
;i
++)
274 Q3MultiLineEdit::cursorLeft();
278 void MyTerm::mynewline() {
279 Q3MultiLineEdit::end(false);
280 Q3MultiLineEdit::newLine();
283 #include "miniterm.moc"