does not need DQT3_SUPPORT
[kdenetwork.git] / kppp / loginterm.cpp
blob070aa6e8d4bcc7fbf048dc8ab5084a274297a736
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 unsigned char c = (unsigned char) k->ascii();
80 if ((int)c == 0) return;
82 if((int)c == 13)
83 Modem::modem->writeLine("");
84 else
85 Modem::modem->writeChar(c);
89 void LoginMultiLineEdit::readChar(unsigned char c) {
91 if(((int)c != 13) && ((int)c != 10) && ((int)c != 8))
92 insertChar(c);
94 if((int)c == 8 || ( int )c == 127)
95 textCursor().deleteChar ();
96 else if((int)c == 10)
97 mynewline();
98 else if((int)c == 13)
99 myreturn();
103 LoginTerm::LoginTerm (QWidget *parent, const char *name)
104 : QDialog(parent)
106 setObjectName(name);
108 setWindowTitle(i18n("Login Terminal Window"));
109 setMinimumSize(300, 200);
110 setMaximumSize(600, 400);
111 resize(400, 300);
113 QVBoxLayout *tl = new QVBoxLayout(this);
114 tl->setSpacing(2);
115 QGridLayout *vgr = new QGridLayout();
116 QGridLayout *hgr = new QGridLayout();
117 hgr->setMargin( 30 );
119 tl->addLayout(vgr);
120 vgr->addLayout(hgr, 1, 0);
121 vgr->setRowStretch(0, 1);
122 vgr->addItem(new QSpacerItem(0, 40), 1, 0);
124 text_window = new LoginMultiLineEdit(this);
125 text_window->setObjectName("term");
126 text_window->setFocus();
127 vgr->addWidget(text_window, 0, 0);
129 cancel_b = new KPushButton(KStandardGuiItem::cancel(), this);
130 cancel_b->setFixedHeight(25);
131 connect(cancel_b, SIGNAL(clicked()), SLOT(cancelbutton()));
133 continue_b = new KPushButton(KStandardGuiItem::cont(), this);
134 continue_b->setFixedHeight(25);
135 connect(continue_b, SIGNAL(clicked()), SLOT(continuebutton()));
137 int mwidth;
138 if (cancel_b->sizeHint().width() > continue_b->sizeHint().width())
139 mwidth = cancel_b->sizeHint().width();
140 else
141 mwidth = continue_b->sizeHint().width();
143 cancel_b->setFixedWidth(mwidth + 20);
144 continue_b->setFixedWidth(mwidth + 20);
146 hgr->addWidget(cancel_b, 0, 0, Qt::AlignCenter);
147 hgr->addWidget(continue_b, 0, 1, Qt::AlignCenter);
149 cont = false;
151 Modem::modem->notify(text_window, SLOT(readChar(unsigned char)));
155 void LoginTerm::cancelbutton () {
156 hide();
160 void LoginTerm::continuebutton() {
161 cont = true;
162 hide();
166 bool LoginTerm::pressedContinue() {
167 return cont;
171 #include "loginterm.moc"