1 | /* |
2 | * kPPP: A pppd Front End for the KDE project |
3 | * |
4 | * $Id$ |
5 | * |
6 | * Copyright (C) 1997-98 Bernd Johannes Wuebben |
7 | * wuebben@math.cornell.edu |
8 | * |
9 | * This file was contributed by Harri Porten <porten@tu-harburg.de> |
10 | * |
11 | * |
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. |
16 | * |
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. |
21 | * |
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. |
25 | */ |
26 | |
27 | #include <KStandardGuiItem> |
28 | #include <kguiitem.h> |
29 | |
30 | #include "loginterm.h" |
31 | #include "main.h" |
32 | #include "modem.h" |
33 | |
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; |
42 | |
43 | LoginMultiLineEdit::LoginMultiLineEdit(QWidget *parent) |
44 | : QTextEdit(parent) |
45 | { |
46 | } |
47 | |
48 | |
49 | LoginMultiLineEdit::~LoginMultiLineEdit() { |
50 | Modem::modem->stop(); |
51 | } |
52 | |
53 | |
54 | void LoginMultiLineEdit::insertChar(unsigned char c) { |
55 | insertPlainText(QString(c)); |
56 | p_kppp->debugwindow->addChar(c); |
57 | } |
58 | |
59 | |
60 | void LoginMultiLineEdit::myreturn() { |
61 | textCursor().movePosition( QTextCursor::Start ); |
62 | } |
63 | |
64 | |
65 | void LoginMultiLineEdit::mynewline() { |
66 | textCursor().movePosition( QTextCursor::End ); |
67 | insertPlainText(QString("\n" )); |
68 | |
69 | #if 0 |
70 | Q3MultiLineEdit::end(false); |
71 | Q3MultiLineEdit::newLine(); |
72 | #endif |
73 | p_kppp->debugwindow->addChar('\n'); |
74 | } |
75 | |
76 | |
77 | void LoginMultiLineEdit::keyPressEvent(QKeyEvent *k) { |
78 | if (k->key() == 0 || k->key() == Qt::Key_unknown) return; |
79 | |
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]); |
86 | } |
87 | } |
88 | |
89 | |
90 | void LoginMultiLineEdit::readChar(unsigned char c) { |
91 | |
92 | if(((int)c != 13) && ((int)c != 10) && ((int)c != 8)) |
93 | insertChar(c); |
94 | |
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(); |
101 | } |
102 | |
103 | |
104 | LoginTerm::LoginTerm (QWidget *parent, const char *name) |
105 | : QDialog(parent) |
106 | { |
107 | setObjectName(name); |
108 | |
109 | setWindowTitle(i18n("Login Terminal Window" )); |
110 | setMinimumSize(300, 200); |
111 | setMaximumSize(600, 400); |
112 | resize(400, 300); |
113 | |
114 | QVBoxLayout *tl = new QVBoxLayout(this); |
115 | tl->setSpacing(2); |
116 | QGridLayout *vgr = new QGridLayout(); |
117 | QGridLayout *hgr = new QGridLayout(); |
118 | hgr->setMargin( 30 ); |
119 | |
120 | tl->addLayout(vgr); |
121 | vgr->addLayout(hgr, 1, 0); |
122 | vgr->setRowStretch(0, 1); |
123 | vgr->addItem(new QSpacerItem(0, 40), 1, 0); |
124 | |
125 | text_window = new LoginMultiLineEdit(this); |
126 | text_window->setObjectName("term" ); |
127 | text_window->setFocus(); |
128 | vgr->addWidget(text_window, 0, 0); |
129 | |
130 | cancel_b = new KPushButton(KStandardGuiItem::cancel(), this); |
131 | cancel_b->setFixedHeight(25); |
132 | connect(cancel_b, SIGNAL(clicked()), SLOT(cancelbutton())); |
133 | |
134 | continue_b = new KPushButton(KStandardGuiItem::cont(), this); |
135 | continue_b->setFixedHeight(25); |
136 | connect(continue_b, SIGNAL(clicked()), SLOT(continuebutton())); |
137 | |
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(); |
143 | |
144 | cancel_b->setFixedWidth(mwidth + 20); |
145 | continue_b->setFixedWidth(mwidth + 20); |
146 | |
147 | hgr->addWidget(cancel_b, 0, 0, Qt::AlignCenter); |
148 | hgr->addWidget(continue_b, 0, 1, Qt::AlignCenter); |
149 | |
150 | cont = false; |
151 | |
152 | Modem::modem->notify(text_window, SLOT(readChar(unsigned char))); |
153 | } |
154 | |
155 | |
156 | void LoginTerm::cancelbutton () { |
157 | hide(); |
158 | } |
159 | |
160 | |
161 | void LoginTerm::continuebutton() { |
162 | cont = true; |
163 | hide(); |
164 | } |
165 | |
166 | |
167 | bool LoginTerm::pressedContinue() { |
168 | return cont; |
169 | } |
170 | |
171 | |
172 | #include "loginterm.moc" |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |