summaryrefslogtreecommitdiffstats
path: root/kppp/loginterm.cpp
blob: fd544486d60a3de8a048a69b2b74a797a34e0ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *              kPPP: A pppd Front End for the KDE project
 *
 * $Id$
 *
 *              Copyright (C) 1997-98 Bernd Johannes Wuebben
 *                      [email protected]
 *
 * This file was contributed by Harri Porten <[email protected]>
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "kstdguiitem.h"

#include "loginterm.h"
#include "main.h"
#include "modem.h"

#include <stdio.h>
#include <klocale.h>

extern KPPPWidget *p_kppp;

LoginMultiLineEdit::LoginMultiLineEdit(TQWidget *parent, const char *name)
  : TQMultiLineEdit(parent, name)
{
}


LoginMultiLineEdit::~LoginMultiLineEdit() {
  Modem::modem->stop();
}


void LoginMultiLineEdit::insertChar(unsigned char c) {
  TQMultiLineEdit::insert(TQChar(c));
  p_kppp->debugwindow->addChar(c);
}


void LoginMultiLineEdit::myreturn() {
  TQMultiLineEdit::home();
}


void LoginMultiLineEdit::mynewline() {
  TQMultiLineEdit::end(FALSE);
  TQMultiLineEdit::newLine();

    p_kppp->debugwindow->addChar('\n');
}


void LoginMultiLineEdit::keyPressEvent(TQKeyEvent *k) {
  unsigned char c = (unsigned char) k->ascii();

  if ((int)c == 0) return;

  if((int)c == 13)
    Modem::modem->writeLine("");
  else
    Modem::modem->writeChar(c);
}


void LoginMultiLineEdit::readChar(unsigned char c) {

  if(((int)c != 13) && ((int)c != 10) && ((int)c != 8))
    insertChar(c);

  if((int)c == 8)
    backspace();
  if((int)c == 127)
    backspace();
  if((int)c == 10)
    mynewline();
  if((int)c == 13)
    myreturn();
}


LoginTerm::LoginTerm (TQWidget *parent, const char *name)
  : TQDialog(parent, name, FALSE)
{
  setCaption(i18n("Login Terminal Window"));
  setMinimumSize(300, 200);
  setMaximumSize(600, 400);
  resize(400, 300);

  TQVBoxLayout *tl = new TQVBoxLayout(this, 2);
  TQGridLayout *vgr = new TQGridLayout(2, 1);
  TQGridLayout *hgr = new TQGridLayout(1, 2, 30);

  tl->addLayout(vgr);
  vgr->addLayout(hgr, 1, 0);
  vgr->setRowStretch(0, 1);
  vgr->addRowSpacing(1, 40);

  text_window = new LoginMultiLineEdit(this, "term");
  text_window->setFocus();
  vgr->addWidget(text_window, 0, 0);

  cancel_b = new KPushButton(KStdGuiItem::cancel(), this, "cancel");
  cancel_b->setFixedHeight(25);
  connect(cancel_b, TQT_SIGNAL(clicked()), TQT_SLOT(cancelbutton()));

  continue_b = new KPushButton(KStdGuiItem::cont(), this, "continue");
  continue_b->setFixedHeight(25);
  connect(continue_b, TQT_SIGNAL(clicked()), TQT_SLOT(continuebutton()));

  int mwidth;
  if (cancel_b->sizeHint().width() > continue_b->sizeHint().width())
    mwidth = cancel_b->sizeHint().width();
  else
    mwidth = continue_b->sizeHint().width();

  cancel_b->setFixedWidth(mwidth + 20);
  continue_b->setFixedWidth(mwidth + 20);

  hgr->addWidget(cancel_b, 0, 0, AlignCenter);
  hgr->addWidget(continue_b, 0, 1, AlignCenter);

  cont = false;

  Modem::modem->notify(TQT_TQOBJECT(text_window), TQT_SLOT(readChar(unsigned char)));
}


void LoginTerm::cancelbutton () {
  hide();
}


void LoginTerm::continuebutton() {
  cont = true;
  hide();
}


bool LoginTerm::pressedContinue() {
  return cont;
}


#include "loginterm.moc"