Contact cannot be a null ptr, and it is accessed before anyway. Disscussed with kedge.
[kdenetwork.git] / kppp / loginterm.cpp
blobc93392c8c2090bdaa3a5cd1488efee9b4f89156c
1 /*
2 * kPPP: A pppd Front End for the KDE project
4 * $Id$
6 * Copyright (C) 1997-98 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
9 * This file was contributed by Harri Porten <porten@tu-harburg.de>
12 * This program 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.
17 * This program 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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <KStandardGuiItem>
28 #include <kguiitem.h>
30 #include "loginterm.h"
31 #include "main.h"
32 #include "modem.h"
34 #include <stdio.h>
35 #include <klocale.h>
36 //Added by qt3to4:
37 #include <QVBoxLayout>
38 #include <QGridLayout>
39 #include <QKeyEvent>
40 #include <QTextCursor>
41 extern KPPPWidget *p_kppp;
43 LoginMultiLineEdit::LoginMultiLineEdit(QWidget *parent)
44 : QTextEdit(parent)
49 LoginMultiLineEdit::~LoginMultiLineEdit() {
50 Modem::modem->stop();
54 void LoginMultiLineEdit::insertChar(unsigned char c) {
55 insertPlainText(QString(c));
56 p_kppp->debugwindow->addChar(c);
60 void LoginMultiLineEdit::myreturn() {
61 textCursor().movePosition( QTextCursor::Start );
65 void LoginMultiLineEdit::mynewline() {
66 textCursor().movePosition( QTextCursor::End );
67 insertPlainText(QString("\n"));
69 #if 0
70 Q3MultiLineEdit::end(false);
71 Q3MultiLineEdit::newLine();
72 #endif
73 p_kppp->debugwindow->addChar('\n');
77 void LoginMultiLineEdit::keyPressEvent(QKeyEvent *k) {
78 if (k->key() == 0 || k->key() == Qt::Key_unknown) return;
80 if(k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return)
81 Modem::modem->writeLine("");
82 else {
83 QByteArray ascii = k->text().toAscii();
84 if (ascii.size() > 0)
85 Modem::modem->writeChar(ascii[0]);
90 void LoginMultiLineEdit::readChar(unsigned char c) {
92 if(((int)c != 13) && ((int)c != 10) && ((int)c != 8))
93 insertChar(c);
95 if((int)c == 8 || ( int )c == 127)
96 textCursor().deleteChar ();
97 else if((int)c == 10)
98 mynewline();
99 else if((int)c == 13)
100 myreturn();
104 LoginTerm::LoginTerm (QWidget *parent, const char *name)
105 : QDialog(parent)
107 setObjectName(name);
109 setWindowTitle(i18n("Login Terminal Window"));
110 setMinimumSize(300, 200);
111 setMaximumSize(600, 400);
112 resize(400, 300);
114 QVBoxLayout *tl = new QVBoxLayout(this);
115 tl->setSpacing(2);
116 QGridLayout *vgr = new QGridLayout();
117 QGridLayout *hgr = new QGridLayout();
118 hgr->setMargin( 30 );
120 tl->addLayout(vgr);
121 vgr->addLayout(hgr, 1, 0);
122 vgr->setRowStretch(0, 1);
123 vgr->addItem(new QSpacerItem(0, 40), 1, 0);
125 text_window = new LoginMultiLineEdit(this);
126 text_window->setObjectName("term");
127 text_window->setFocus();
128 vgr->addWidget(text_window, 0, 0);
130 cancel_b = new KPushButton(KStandardGuiItem::cancel(), this);
131 cancel_b->setFixedHeight(25);
132 connect(cancel_b, SIGNAL(clicked()), SLOT(cancelbutton()));
134 continue_b = new KPushButton(KStandardGuiItem::cont(), this);
135 continue_b->setFixedHeight(25);
136 connect(continue_b, SIGNAL(clicked()), SLOT(continuebutton()));
138 int mwidth;
139 if (cancel_b->sizeHint().width() > continue_b->sizeHint().width())
140 mwidth = cancel_b->sizeHint().width();
141 else
142 mwidth = continue_b->sizeHint().width();
144 cancel_b->setFixedWidth(mwidth + 20);
145 continue_b->setFixedWidth(mwidth + 20);
147 hgr->addWidget(cancel_b, 0, 0, Qt::AlignCenter);
148 hgr->addWidget(continue_b, 0, 1, Qt::AlignCenter);
150 cont = false;
152 Modem::modem->notify(text_window, SLOT(readChar(unsigned char)));
156 void LoginTerm::cancelbutton () {
157 hide();
161 void LoginTerm::continuebutton() {
162 cont = true;
163 hide();
167 bool LoginTerm::pressedContinue() {
168 return cont;
172 #include "loginterm.moc"