summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp8
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp3
2 files changed, 8 insertions, 3 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index dab0ea3..350ab3a 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -1,1261 +1,1265 @@
1/* ------------------------------------------------------------------------ */ 1/* ------------------------------------------------------------------------ */
2/* */ 2/* */
3/* [TEWidget.C] Terminal Emulation Widget */ 3/* [TEWidget.C] Terminal Emulation Widget */
4/* */ 4/* */
5/* ------------------------------------------------------------------------ */ 5/* ------------------------------------------------------------------------ */
6/* */ 6/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */ 8/* */
9/* This file is part of Konsole - an X terminal for KDE */ 9/* This file is part of Konsole - an X terminal for KDE */
10/* */ 10/* */
11/* ------------------------------------------------------------------------ */ 11/* ------------------------------------------------------------------------ */
12/* */ 12/* */
13/* Ported Konsole to Qt/Embedded */ 13/* Ported Konsole to Qt/Embedded */
14/* */ 14/* */
15/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 15/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
16/* */ 16/* */
17/* -------------------------------------------------------------------------- */ 17/* -------------------------------------------------------------------------- */
18/*! \class TEWidget 18/*! \class TEWidget
19 19
20 \brief Visible screen contents 20 \brief Visible screen contents
21 21
22 This class is responsible to map the `image' of a terminal emulation to the 22 This class is responsible to map the `image' of a terminal emulation to the
23 display. All the dependency of the emulation to a specific GUI or toolkit is 23 display. All the dependency of the emulation to a specific GUI or toolkit is
24 localized here. Further, this widget has no knowledge about being part of an 24 localized here. Further, this widget has no knowledge about being part of an
25 emulation, it simply work within the terminal emulation framework by exposing 25 emulation, it simply work within the terminal emulation framework by exposing
26 size and key events and by being ordered to show a new image. 26 size and key events and by being ordered to show a new image.
27 27
28 <ul> 28 <ul>
29 <li> The internal image has the size of the widget (evtl. rounded up) 29 <li> The internal image has the size of the widget (evtl. rounded up)
30 <li> The external image used in setImage can have any size. 30 <li> The external image used in setImage can have any size.
31 <li> (internally) the external image is simply copied to the internal 31 <li> (internally) the external image is simply copied to the internal
32 when a setImage happens. During a resizeEvent no painting is done 32 when a setImage happens. During a resizeEvent no painting is done
33 a paintEvent is expected to follow anyway. 33 a paintEvent is expected to follow anyway.
34 </ul> 34 </ul>
35 35
36 \sa TEScreen \sa Emulation 36 \sa TEScreen \sa Emulation
37*/ 37*/
38 38
39/* FIXME: 39/* FIXME:
40 - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent 40 - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent
41 - 'font_a' not used in mouse events 41 - 'font_a' not used in mouse events
42 - add destructor 42 - add destructor
43*/ 43*/
44 44
45/* TODO 45/* TODO
46 - evtl. be sensitive to `paletteChange' while using default colors. 46 - evtl. be sensitive to `paletteChange' while using default colors.
47 - set different 'rounding' styles? I.e. have a mode to show clipped chars? 47 - set different 'rounding' styles? I.e. have a mode to show clipped chars?
48*/ 48*/
49 49
50// #include "config.h" 50// #include "config.h"
51#include "TEWidget.h" 51#include "TEWidget.h"
52#include "session.h" 52#include "session.h"
53#include <qpe/config.h> 53#include <qpe/config.h>
54 54
55#include <qcursor.h> 55#include <qcursor.h>
56#include <qregexp.h> 56#include <qregexp.h>
57#include <qpainter.h> 57#include <qpainter.h>
58#include <qclipboard.h> 58#include <qclipboard.h>
59#include <qstyle.h> 59#include <qstyle.h>
60#include <qfile.h> 60#include <qfile.h>
61#include <qdragobject.h> 61#include <qdragobject.h>
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include <stdlib.h> 64#include <stdlib.h>
65#include <unistd.h> 65#include <unistd.h>
66#include <ctype.h> 66#include <ctype.h>
67#include <sys/stat.h> 67#include <sys/stat.h>
68#include <sys/types.h> 68#include <sys/types.h>
69#include <signal.h> 69#include <signal.h>
70 70
71#include <assert.h> 71#include <assert.h>
72 72
73// #include "TEWidget.moc" 73// #include "TEWidget.moc"
74//#include <kapp.h> 74//#include <kapp.h>
75//#include <kcursor.h> 75//#include <kcursor.h>
76//#include <kurl.h> 76//#include <kurl.h>
77//#include <kdebug.h> 77//#include <kdebug.h>
78//#include <klocale.h> 78//#include <klocale.h>
79 79
80#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 80#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
81#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } 81#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }
82 82
83#define loc(X,Y) ((Y)*columns+(X)) 83#define loc(X,Y) ((Y)*columns+(X))
84 84
85//FIXME: the rim should normally be 1, 0 only when running in full screen mode. 85//FIXME: the rim should normally be 1, 0 only when running in full screen mode.
86#define rimX 0 // left/right rim width 86#define rimX 0 // left/right rim width
87#define rimY 0 // top/bottom rim high 87#define rimY 0 // top/bottom rim high
88 88
89#define SCRWIDTH 16 // width of the scrollbar 89#define SCRWIDTH 16 // width of the scrollbar
90 90
91#define yMouseScroll 1 91#define yMouseScroll 1
92// scroll increment used when dragging selection at top/bottom of window. 92// scroll increment used when dragging selection at top/bottom of window.
93 93
94/* ------------------------------------------------------------------------- */ 94/* ------------------------------------------------------------------------- */
95/* */ 95/* */
96/* Colors */ 96/* Colors */
97/* */ 97/* */
98/* ------------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------------- */
99 99
100//FIXME: the default color table is in session.C now. 100//FIXME: the default color table is in session.C now.
101// We need a way to get rid of this one, here. 101// We need a way to get rid of this one, here.
102static const ColorEntry base_color_table[TABLE_COLORS] = 102static const ColorEntry base_color_table[TABLE_COLORS] =
103// The following are almost IBM standard color codes, with some slight 103// The following are almost IBM standard color codes, with some slight
104// gamma correction for the dim colors to compensate for bright X screens. 104// gamma correction for the dim colors to compensate for bright X screens.
105// It contains the 8 ansiterm/xterm colors in 2 intensities. 105// It contains the 8 ansiterm/xterm colors in 2 intensities.
106{ 106{
107 // Fixme: could add faint colors here, also. 107 // Fixme: could add faint colors here, also.
108 // normal 108 // normal
109 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback 109 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback
110 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red 110 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
111 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow 111 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
112 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta 112 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
113 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White 113 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
114 // intensiv 114 // intensiv
115 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), 115 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),
116 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), 116 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),
117 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), 117 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),
118 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), 118 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ),
119 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) 119 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
120}; 120};
121 121
122/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) 122/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb)
123 123
124 Code 0 1 2 3 4 5 6 7 124 Code 0 1 2 3 4 5 6 7
125 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 125 ----------- ------- ------- ------- ------- ------- ------- ------- -------
126 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 126 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
127 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 127 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
128*/ 128*/
129 129
130QColor TEWidget::getDefaultBackColor() 130QColor TEWidget::getDefaultBackColor()
131{ 131{
132 return color_table[DEFAULT_BACK_COLOR].color; 132 return color_table[DEFAULT_BACK_COLOR].color;
133} 133}
134 134
135const ColorEntry* TEWidget::getColorTable() const 135const ColorEntry* TEWidget::getColorTable() const
136{ 136{
137 return color_table; 137 return color_table;
138} 138}
139 139
140const ColorEntry* TEWidget::getdefaultColorTable() const 140const ColorEntry* TEWidget::getdefaultColorTable() const
141{ 141{
142 return base_color_table; 142 return base_color_table;
143} 143}
144 144
145 145
146const QPixmap *TEWidget::backgroundPixmap() 146const QPixmap *TEWidget::backgroundPixmap()
147{ 147{
148 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 148 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
149 const QPixmap *pm = bg; 149 const QPixmap *pm = bg;
150 return pm; 150 return pm;
151} 151}
152 152
153void TEWidget::setColorTable(const ColorEntry table[]) 153void TEWidget::setColorTable(const ColorEntry table[])
154{ 154{
155 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; 155 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];
156 156
157 const QPixmap* pm = backgroundPixmap(); 157 const QPixmap* pm = backgroundPixmap();
158 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); 158 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
159 update(); 159 update();
160} 160}
161 161
162//FIXME: add backgroundPixmapChanged. 162//FIXME: add backgroundPixmapChanged.
163 163
164/* ------------------------------------------------------------------------- */ 164/* ------------------------------------------------------------------------- */
165/* */ 165/* */
166/* Font */ 166/* Font */
167/* */ 167/* */
168/* ------------------------------------------------------------------------- */ 168/* ------------------------------------------------------------------------- */
169 169
170/* 170/*
171 The VT100 has 32 special graphical characters. The usual vt100 extended 171 The VT100 has 32 special graphical characters. The usual vt100 extended
172 xterm fonts have these at 0x00..0x1f. 172 xterm fonts have these at 0x00..0x1f.
173 173
174 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals 174 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals
175 come in here as proper unicode characters. 175 come in here as proper unicode characters.
176 176
177 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping 177 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping
178 from unicode to 0x00..0x1f. The remaining translation is then left to the 178 from unicode to 0x00..0x1f. The remaining translation is then left to the
179 QCodec. 179 QCodec.
180*/ 180*/
181 181
182// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. 182// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.
183 183
184unsigned short vt100_graphics[32] = 184unsigned short vt100_graphics[32] =
185{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 185{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15
186 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 186 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
187 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 187 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
188 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 188 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
189 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 189 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
190}; 190};
191 191
192static QChar vt100extended(QChar c) 192static QChar vt100extended(QChar c)
193{ 193{
194 switch (c.unicode()) 194 switch (c.unicode())
195 { 195 {
196 case 0x25c6 : return 1; 196 case 0x25c6 : return 1;
197 case 0x2592 : return 2; 197 case 0x2592 : return 2;
198 case 0x2409 : return 3; 198 case 0x2409 : return 3;
199 case 0x240c : return 4; 199 case 0x240c : return 4;
200 case 0x240d : return 5; 200 case 0x240d : return 5;
201 case 0x240a : return 6; 201 case 0x240a : return 6;
202 case 0x00b0 : return 7; 202 case 0x00b0 : return 7;
203 case 0x00b1 : return 8; 203 case 0x00b1 : return 8;
204 case 0x2424 : return 9; 204 case 0x2424 : return 9;
205 case 0x240b : return 10; 205 case 0x240b : return 10;
206 case 0x2518 : return 11; 206 case 0x2518 : return 11;
207 case 0x2510 : return 12; 207 case 0x2510 : return 12;
208 case 0x250c : return 13; 208 case 0x250c : return 13;
209 case 0x2514 : return 14; 209 case 0x2514 : return 14;
210 case 0x253c : return 15; 210 case 0x253c : return 15;
211 case 0xf800 : return 16; 211 case 0xf800 : return 16;
212 case 0xf801 : return 17; 212 case 0xf801 : return 17;
213 case 0x2500 : return 18; 213 case 0x2500 : return 18;
214 case 0xf803 : return 19; 214 case 0xf803 : return 19;
215 case 0xf804 : return 20; 215 case 0xf804 : return 20;
216 case 0x251c : return 21; 216 case 0x251c : return 21;
217 case 0x2524 : return 22; 217 case 0x2524 : return 22;
218 case 0x2534 : return 23; 218 case 0x2534 : return 23;
219 case 0x252c : return 24; 219 case 0x252c : return 24;
220 case 0x2502 : return 25; 220 case 0x2502 : return 25;
221 case 0x2264 : return 26; 221 case 0x2264 : return 26;
222 case 0x2265 : return 27; 222 case 0x2265 : return 27;
223 case 0x03c0 : return 28; 223 case 0x03c0 : return 28;
224 case 0x2260 : return 29; 224 case 0x2260 : return 29;
225 case 0x00a3 : return 30; 225 case 0x00a3 : return 30;
226 case 0x00b7 : return 31; 226 case 0x00b7 : return 31;
227 } 227 }
228 return c; 228 return c;
229} 229}
230 230
231static QChar identicalMap(QChar c) 231static QChar identicalMap(QChar c)
232{ 232{
233 return c; 233 return c;
234} 234}
235 235
236void TEWidget::fontChange(const QFont &) 236void TEWidget::fontChange(const QFont &)
237{ 237{
238 QFontMetrics fm(font()); 238 QFontMetrics fm(font());
239 font_h = fm.height(); 239 font_h = fm.height();
240 font_w = fm.maxWidth(); 240 font_w = fm.maxWidth();
241 font_a = fm.ascent(); 241 font_a = fm.ascent();
242//printf("font_h: %d\n",font_h); 242//printf("font_h: %d\n",font_h);
243//printf("font_w: %d\n",font_w); 243//printf("font_w: %d\n",font_w);
244//printf("font_a: %d\n",font_a); 244//printf("font_a: %d\n",font_a);
245//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 245//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
246//printf("rawname: %s\n",font().rawName().ascii()); 246//printf("rawname: %s\n",font().rawName().ascii());
247 fontMap = 247 fontMap =
248#if QT_VERSION < 300 248#if QT_VERSION < 300
249 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 249 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
250 ? vt100extended 250 ? vt100extended
251 : 251 :
252#endif 252#endif
253 identicalMap; 253 identicalMap;
254 propagateSize(); 254 propagateSize();
255 update(); 255 update();
256} 256}
257 257
258void TEWidget::setVTFont(const QFont& f) 258void TEWidget::setVTFont(const QFont& f)
259{ 259{
260 QFrame::setFont(f); 260 QFrame::setFont(f);
261} 261}
262 262
263QFont TEWidget::getVTFont() { 263QFont TEWidget::getVTFont() {
264 return font(); 264 return font();
265} 265}
266 266
267void TEWidget::setFont(const QFont &) 267void TEWidget::setFont(const QFont &)
268{ 268{
269 // ignore font change request if not coming from konsole itself 269 // ignore font change request if not coming from konsole itself
270} 270}
271 271
272/* ------------------------------------------------------------------------- */ 272/* ------------------------------------------------------------------------- */
273/* */ 273/* */
274/* Constructor / Destructor */ 274/* Constructor / Destructor */
275/* */ 275/* */
276/* ------------------------------------------------------------------------- */ 276/* ------------------------------------------------------------------------- */
277 277
278TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 278TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
279{ 279{
280#ifndef QT_NO_CLIPBOARD 280#ifndef QT_NO_CLIPBOARD
281 cb = QApplication::clipboard(); 281 cb = QApplication::clipboard();
282 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 282 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
283 this, SLOT(onClearSelection()) ); 283 this, SLOT(onClearSelection()) );
284#endif 284#endif
285 285
286 scrollbar = new QScrollBar(this); 286 scrollbar = new QScrollBar(this);
287 scrollbar->setCursor( arrowCursor ); 287 scrollbar->setCursor( arrowCursor );
288 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 288 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
289 289
290 Config cfg("Konsole"); 290 Config cfg("Konsole");
291 cfg.setGroup("ScrollBar"); 291 cfg.setGroup("ScrollBar");
292 switch( cfg.readNumEntry("Position",2)){ 292 switch( cfg.readNumEntry("Position",2)){
293 case 0: 293 case 0:
294 scrollLoc = SCRNONE; 294 scrollLoc = SCRNONE;
295 break; 295 break;
296 case 1: 296 case 1:
297 scrollLoc = SCRLEFT; 297 scrollLoc = SCRLEFT;
298 break; 298 break;
299 case 2: 299 case 2:
300 scrollLoc = SCRRIGHT; 300 scrollLoc = SCRRIGHT;
301 break; 301 break;
302 }; 302 };
303 303
304 blinkT = new QTimer(this); 304 blinkT = new QTimer(this);
305 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 305 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
306 // blinking = FALSE; 306 // blinking = FALSE;
307 blinking = TRUE; 307 blinking = TRUE;
308 308
309 resizing = FALSE; 309 resizing = FALSE;
310 actSel = 0; 310 actSel = 0;
311 image = 0; 311 image = 0;
312 lines = 1; 312 lines = 1;
313 columns = 1; 313 columns = 1;
314 font_w = 1; 314 font_w = 1;
315 font_h = 1; 315 font_h = 1;
316 font_a = 1; 316 font_a = 1;
317 word_selection_mode = FALSE; 317 word_selection_mode = FALSE;
318 318
319 setMouseMarks(TRUE); 319 setMouseMarks(TRUE);
320 setVTFont( QFont("fixed") ); 320 setVTFont( QFont("fixed") );
321 setColorTable(base_color_table); // init color table 321 setColorTable(base_color_table); // init color table
322 322
323 qApp->installEventFilter( this ); //FIXME: see below 323 qApp->installEventFilter( this ); //FIXME: see below
324// KCursor::setAutoHideCursor( this, true ); 324// KCursor::setAutoHideCursor( this, true );
325 325
326 // Init DnD //////////////////////////////////////////////////////////////// 326 // Init DnD ////////////////////////////////////////////////////////////////
327 currentSession = NULL; 327 currentSession = NULL;
328// setAcceptDrops(true); // attempt 328// setAcceptDrops(true); // attempt
329// m_drop = new QPopupMenu(this); 329// m_drop = new QPopupMenu(this);
330// m_drop->insertItem( QString("Paste"), 0); 330// m_drop->insertItem( QString("Paste"), 0);
331// m_drop->insertItem( QString("cd"), 1); 331// m_drop->insertItem( QString("cd"), 1);
332// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 332// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
333 333
334 // we need focus so that the auto-hide cursor feature works 334 // we need focus so that the auto-hide cursor feature works
335 setFocus(); 335 setFocus();
336 setFocusPolicy( WheelFocus ); 336 setFocusPolicy( WheelFocus );
337} 337}
338 338
339//FIXME: make proper destructor 339//FIXME: make proper destructor
340// Here's a start (David) 340// Here's a start (David)
341TEWidget::~TEWidget() 341TEWidget::~TEWidget()
342{ 342{
343 qApp->removeEventFilter( this ); 343 qApp->removeEventFilter( this );
344 if (image) free(image); 344 if (image) free(image);
345} 345}
346 346
347/* ------------------------------------------------------------------------- */ 347/* ------------------------------------------------------------------------- */
348/* */ 348/* */
349/* Display Operations */ 349/* Display Operations */
350/* */ 350/* */
351/* ------------------------------------------------------------------------- */ 351/* ------------------------------------------------------------------------- */
352 352
353/*! 353/*!
354 attributed string draw primitive 354 attributed string draw primitive
355*/ 355*/
356 356
357void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 357void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
358 QString& str, ca attr, BOOL pm, BOOL clear) 358 QString& str, ca attr, BOOL pm, BOOL clear)
359{ 359{
360 if (pm && color_table[attr.b].transparent) 360 if (pm && color_table[attr.b].transparent)
361 { 361 {
362 paint.setBackgroundMode( TransparentMode ); 362 paint.setBackgroundMode( TransparentMode );
363 if (clear) erase(rect); 363 if (clear) erase(rect);
364 } 364 }
365 else 365 else
366 { 366 {
367 if (blinking) 367 if (blinking)
368 paint.fillRect(rect, color_table[attr.b].color); 368 paint.fillRect(rect, color_table[attr.b].color);
369 else 369 else
370 { 370 {
371 paint.setBackgroundMode( OpaqueMode ); 371 paint.setBackgroundMode( OpaqueMode );
372 paint.setBackgroundColor( color_table[attr.b].color ); 372 paint.setBackgroundColor( color_table[attr.b].color );
373 } 373 }
374 } 374 }
375 375
376 if (color_table[attr.f].bold) 376 if (color_table[attr.f].bold)
377 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 377 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
378 else 378 else
379 paint.setPen(color_table[attr.f].color); 379 paint.setPen(color_table[attr.f].color);
380 380
381 paint.drawText(rect.x(),rect.y()+font_a, str); 381 paint.drawText(rect.x(),rect.y()+font_a, str);
382 382
383 if (attr.r & RE_UNDERLINE) 383 if (attr.r & RE_UNDERLINE)
384 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); 384 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
385} 385}
386 386
387/*! 387/*!
388 The image can only be set completely. 388 The image can only be set completely.
389 389
390 The size of the new image may or may not match the size of the widget. 390 The size of the new image may or may not match the size of the widget.
391*/ 391*/
392 392
393void TEWidget::setImage(const ca* const newimg, int lines, int columns) 393void TEWidget::setImage(const ca* const newimg, int lines, int columns)
394{ int y,x,len; 394{ int y,x,len;
395 const QPixmap* pm = backgroundPixmap(); 395 const QPixmap* pm = backgroundPixmap();
396 QPainter paint; 396 QPainter paint;
397 setUpdatesEnabled(FALSE); 397 setUpdatesEnabled(FALSE);
398 paint.begin( this ); 398 paint.begin( this );
399HCNT("setImage"); 399HCNT("setImage");
400 400
401 QPoint tL = contentsRect().topLeft(); 401 QPoint tL = contentsRect().topLeft();
402 int tLx = tL.x(); 402 int tLx = tL.x();
403 int tLy = tL.y(); 403 int tLy = tL.y();
404 hasBlinker = FALSE; 404 hasBlinker = FALSE;
405 405
406 int cf = -1; // undefined 406 int cf = -1; // undefined
407 int cb = -1; // undefined 407 int cb = -1; // undefined
408 int cr = -1; // undefined 408 int cr = -1; // undefined
409 409
410 int lins = QMIN(this->lines, QMAX(0,lines )); 410 int lins = QMIN(this->lines, QMAX(0,lines ));
411 int cols = QMIN(this->columns,QMAX(0,columns)); 411 int cols = QMIN(this->columns,QMAX(0,columns));
412 QChar *disstrU = new QChar[cols]; 412 QChar *disstrU = new QChar[cols];
413 413
414//{ static int cnt = 0; printf("setImage %d\n",cnt++); } 414//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
415 for (y = 0; y < lins; y++) 415 for (y = 0; y < lins; y++)
416 { 416 {
417 const ca* lcl = &image[y*this->columns]; 417 const ca* lcl = &image[y*this->columns];
418 const ca* const ext = &newimg[y*columns]; 418 const ca* const ext = &newimg[y*columns];
419 if (!resizing) // not while resizing, we're expecting a paintEvent 419 if (!resizing) // not while resizing, we're expecting a paintEvent
420 for (x = 0; x < cols; x++) 420 for (x = 0; x < cols; x++)
421 { 421 {
422 hasBlinker |= (ext[x].r & RE_BLINK); 422 hasBlinker |= (ext[x].r & RE_BLINK);
423 if (ext[x] != lcl[x]) 423 if (ext[x] != lcl[x])
424 { 424 {
425 cr = ext[x].r; 425 cr = ext[x].r;
426 cb = ext[x].b; 426 cb = ext[x].b;
427 if (ext[x].f != cf) cf = ext[x].f; 427 if (ext[x].f != cf) cf = ext[x].f;
428 int lln = cols - x; 428 int lln = cols - x;
429 disstrU[0] = fontMap(ext[x+0].c); 429 disstrU[0] = fontMap(ext[x+0].c);
430 for (len = 1; len < lln; len++) 430 for (len = 1; len < lln; len++)
431 { 431 {
432 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || 432 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
433 ext[x+len] == lcl[x+len] ) 433 ext[x+len] == lcl[x+len] )
434 break; 434 break;
435 disstrU[len] = fontMap(ext[x+len].c); 435 disstrU[len] = fontMap(ext[x+len].c);
436 } 436 }
437 QString unistr(disstrU,len); 437 QString unistr(disstrU,len);
438 drawAttrStr(paint, 438 drawAttrStr(paint,
439 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 439 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
440 unistr, ext[x], pm != NULL, true); 440 unistr, ext[x], pm != NULL, true);
441 x += len - 1; 441 x += len - 1;
442 } 442 }
443 } 443 }
444 // finally, make `image' become `newimg'. 444 // finally, make `image' become `newimg'.
445 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 445 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
446 } 446 }
447 drawFrame( &paint ); 447 drawFrame( &paint );
448 paint.end(); 448 paint.end();
449 setUpdatesEnabled(TRUE); 449 setUpdatesEnabled(TRUE);
450 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 450 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
451 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 451 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
452 delete [] disstrU; 452 delete [] disstrU;
453} 453}
454 454
455// paint Event //////////////////////////////////////////////////// 455// paint Event ////////////////////////////////////////////////////
456 456
457/*! 457/*!
458 The difference of this routine vs. the `setImage' is, 458 The difference of this routine vs. the `setImage' is,
459 that the drawing does not include a difference analysis 459 that the drawing does not include a difference analysis
460 between the old and the new image. Instead, the internal 460 between the old and the new image. Instead, the internal
461 image is used and the painting bound by the PaintEvent box. 461 image is used and the painting bound by the PaintEvent box.
462*/ 462*/
463 463
464void TEWidget::paintEvent( QPaintEvent* pe ) 464void TEWidget::paintEvent( QPaintEvent* pe )
465{ 465{
466 466
467//{ static int cnt = 0; printf("paint %d\n",cnt++); } 467//{ static int cnt = 0; printf("paint %d\n",cnt++); }
468 const QPixmap* pm = backgroundPixmap(); 468 const QPixmap* pm = backgroundPixmap();
469 QPainter paint; 469 QPainter paint;
470 setUpdatesEnabled(FALSE); 470 setUpdatesEnabled(FALSE);
471 paint.begin( this ); 471 paint.begin( this );
472 paint.setBackgroundMode( TransparentMode ); 472 paint.setBackgroundMode( TransparentMode );
473HCNT("paintEvent"); 473HCNT("paintEvent");
474 474
475 // Note that the actual widget size can be slightly larger 475 // Note that the actual widget size can be slightly larger
476 // that the image (the size is truncated towards the smaller 476 // that the image (the size is truncated towards the smaller
477 // number of characters in `resizeEvent'. The paint rectangle 477 // number of characters in `resizeEvent'. The paint rectangle
478 // can thus be larger than the image, but less then the size 478 // can thus be larger than the image, but less then the size
479 // of one character. 479 // of one character.
480 480
481 QRect rect = pe->rect().intersect(contentsRect()); 481 QRect rect = pe->rect().intersect(contentsRect());
482 482
483 QPoint tL = contentsRect().topLeft(); 483 QPoint tL = contentsRect().topLeft();
484 int tLx = tL.x(); 484 int tLx = tL.x();
485 int tLy = tL.y(); 485 int tLy = tL.y();
486 486
487 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); 487 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
488 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); 488 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
489 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); 489 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
490 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); 490 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
491 491
492 /* 492 /*
493 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, 493 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
494 rect.left(), rect.right(), rect.top(), rect.bottom()); 494 rect.left(), rect.right(), rect.top(), rect.bottom());
495 */ 495 */
496 496
497 // if (pm != NULL && color_table[image->b].transparent) 497 // if (pm != NULL && color_table[image->b].transparent)
498 // erase(rect); 498 // erase(rect);
499 // BL: I have no idea why we need this, and it breaks the refresh. 499 // BL: I have no idea why we need this, and it breaks the refresh.
500 500
501 QChar *disstrU = new QChar[columns]; 501 QChar *disstrU = new QChar[columns];
502 for (int y = luy; y <= rly; y++) 502 for (int y = luy; y <= rly; y++)
503 for (int x = lux; x <= rlx; x++) 503 for (int x = lux; x <= rlx; x++)
504 { 504 {
505 int len = 1; 505 int len = 1;
506 disstrU[0] = fontMap(image[loc(x,y)].c); 506 disstrU[0] = fontMap(image[loc(x,y)].c);
507 int cf = image[loc(x,y)].f; 507 int cf = image[loc(x,y)].f;
508 int cb = image[loc(x,y)].b; 508 int cb = image[loc(x,y)].b;
509 int cr = image[loc(x,y)].r; 509 int cr = image[loc(x,y)].r;
510 while (x+len <= rlx && 510 while (x+len <= rlx &&
511 image[loc(x+len,y)].f == cf && 511 image[loc(x+len,y)].f == cf &&
512 image[loc(x+len,y)].b == cb && 512 image[loc(x+len,y)].b == cb &&
513 image[loc(x+len,y)].r == cr ) 513 image[loc(x+len,y)].r == cr )
514 { 514 {
515 disstrU[len] = fontMap(image[loc(x+len,y)].c); 515 disstrU[len] = fontMap(image[loc(x+len,y)].c);
516 len += 1; 516 len += 1;
517 } 517 }
518 QString unistr(disstrU,len); 518 QString unistr(disstrU,len);
519 drawAttrStr(paint, 519 drawAttrStr(paint,
520 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 520 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
521 unistr, image[loc(x,y)], pm != NULL, false); 521 unistr, image[loc(x,y)], pm != NULL, false);
522 x += len - 1; 522 x += len - 1;
523 } 523 }
524 delete [] disstrU; 524 delete [] disstrU;
525 drawFrame( &paint ); 525 drawFrame( &paint );
526 paint.end(); 526 paint.end();
527 setUpdatesEnabled(TRUE); 527 setUpdatesEnabled(TRUE);
528} 528}
529 529
530void TEWidget::blinkEvent() 530void TEWidget::blinkEvent()
531{ 531{
532 blinking = !blinking; 532 blinking = !blinking;
533 repaint(FALSE); 533 repaint(FALSE);
534} 534}
535 535
536/* ------------------------------------------------------------------------- */ 536/* ------------------------------------------------------------------------- */
537/* */ 537/* */
538/* Resizing */ 538/* Resizing */
539/* */ 539/* */
540/* ------------------------------------------------------------------------- */ 540/* ------------------------------------------------------------------------- */
541 541
542void TEWidget::resizeEvent(QResizeEvent* ev) 542void TEWidget::resizeEvent(QResizeEvent* ev)
543{ 543{
544// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 544// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
545 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); 545 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
546 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); 546 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
547 //printf("curren: %d,%d\n",width(),height()); 547 //printf("curren: %d,%d\n",width(),height());
548HCNT("resizeEvent"); 548HCNT("resizeEvent");
549 549
550 // see comment in `paintEvent' concerning the rounding. 550 // see comment in `paintEvent' concerning the rounding.
551 //FIXME: could make a routine here; check width(),height() 551 //FIXME: could make a routine here; check width(),height()
552 assert(ev->size().width() == width()); 552 assert(ev->size().width() == width());
553 assert(ev->size().height() == height()); 553 assert(ev->size().height() == height());
554 554
555 propagateSize(); 555 propagateSize();
556} 556}
557 557
558void TEWidget::propagateSize() 558void TEWidget::propagateSize()
559{ 559{
560 ca* oldimg = image; 560 ca* oldimg = image;
561 int oldlin = lines; 561 int oldlin = lines;
562 int oldcol = columns; 562 int oldcol = columns;
563 makeImage(); 563 makeImage();
564 // we copy the old image to reduce flicker 564 // we copy the old image to reduce flicker
565 int lins = QMIN(oldlin,lines); 565 int lins = QMIN(oldlin,lines);
566 int cols = QMIN(oldcol,columns); 566 int cols = QMIN(oldcol,columns);
567 if (oldimg) 567 if (oldimg)
568 { 568 {
569 for (int lin = 0; lin < lins; lin++) 569 for (int lin = 0; lin < lins; lin++)
570 memcpy((void*)&image[columns*lin], 570 memcpy((void*)&image[columns*lin],
571 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 571 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
572 free(oldimg); //FIXME: try new,delete 572 free(oldimg); //FIXME: try new,delete
573 } 573 }
574 else 574 else
575 clearImage(); 575 clearImage();
576 576
577 //NOTE: control flows from the back through the chest right into the eye. 577 //NOTE: control flows from the back through the chest right into the eye.
578 // `emu' will call back via `setImage'. 578 // `emu' will call back via `setImage'.
579 579
580 resizing = TRUE; 580 resizing = TRUE;
581 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 581 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
582 resizing = FALSE; 582 resizing = FALSE;
583} 583}
584 584
585/* ------------------------------------------------------------------------- */ 585/* ------------------------------------------------------------------------- */
586/* */ 586/* */
587/* Scrollbar */ 587/* Scrollbar */
588/* */ 588/* */
589/* ------------------------------------------------------------------------- */ 589/* ------------------------------------------------------------------------- */
590 590
591void TEWidget::scrollChanged(int) 591void TEWidget::scrollChanged(int)
592{ 592{
593 emit changedHistoryCursor(scrollbar->value()); //expose 593 emit changedHistoryCursor(scrollbar->value()); //expose
594} 594}
595 595
596void TEWidget::setScroll(int cursor, int slines) 596void TEWidget::setScroll(int cursor, int slines)
597{ 597{
598 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 598 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
599 scrollbar->setRange(0,slines); 599 scrollbar->setRange(0,slines);
600 scrollbar->setSteps(1,lines); 600 scrollbar->setSteps(1,lines);
601 scrollbar->setValue(cursor); 601 scrollbar->setValue(cursor);
602 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 602 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
603} 603}
604 604
605void TEWidget::setScrollbarLocation(int loc) 605void TEWidget::setScrollbarLocation(int loc)
606{ 606{
607 if (scrollLoc == loc) return; // quickly 607 if (scrollLoc == loc) return; // quickly
608 scrollLoc = loc; 608 scrollLoc = loc;
609 propagateSize(); 609 propagateSize();
610 update(); 610 update();
611} 611}
612 612
613/* ------------------------------------------------------------------------- */ 613/* ------------------------------------------------------------------------- */
614/* */ 614/* */
615/* Mouse */ 615/* Mouse */
616/* */ 616/* */
617/* ------------------------------------------------------------------------- */ 617/* ------------------------------------------------------------------------- */
618 618
619/*! 619/*!
620 Three different operations can be performed using the mouse, and the 620 Three different operations can be performed using the mouse, and the
621 routines in this section serve all of them: 621 routines in this section serve all of them:
622 622
623 1) The press/release events are exposed to the application 623 1) The press/release events are exposed to the application
624 2) Marking (press and move left button) and Pasting (press middle button) 624 2) Marking (press and move left button) and Pasting (press middle button)
625 3) The right mouse button is used from the configuration menu 625 3) The right mouse button is used from the configuration menu
626 626
627 NOTE: During the marking process we attempt to keep the cursor within 627 NOTE: During the marking process we attempt to keep the cursor within
628 the bounds of the text as being displayed by setting the mouse position 628 the bounds of the text as being displayed by setting the mouse position
629 whenever the mouse has left the text area. 629 whenever the mouse has left the text area.
630 630
631 Two reasons to do so: 631 Two reasons to do so:
632 1) QT does not allow the `grabMouse' to confine-to the TEWidget. 632 1) QT does not allow the `grabMouse' to confine-to the TEWidget.
633 Thus a `XGrapPointer' would have to be used instead. 633 Thus a `XGrapPointer' would have to be used instead.
634 2) Even if so, this would not help too much, since the text area 634 2) Even if so, this would not help too much, since the text area
635 of the TEWidget is normally not identical with it's bounds. 635 of the TEWidget is normally not identical with it's bounds.
636 636
637 The disadvantage of the current handling is, that the mouse can visibly 637 The disadvantage of the current handling is, that the mouse can visibly
638 leave the bounds of the widget and is then moved back. Because of the 638 leave the bounds of the widget and is then moved back. Because of the
639 current construction, and the reasons mentioned above, we cannot do better 639 current construction, and the reasons mentioned above, we cannot do better
640 without changing the overall construction. 640 without changing the overall construction.
641*/ 641*/
642 642
643/*! 643/*!
644*/ 644*/
645 645
646void TEWidget::mousePressEvent(QMouseEvent* ev) 646void TEWidget::mousePressEvent(QMouseEvent* ev)
647{ 647{
648//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 648//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
649 if ( !contentsRect().contains(ev->pos()) ) return; 649 if ( !contentsRect().contains(ev->pos()) ) return;
650 QPoint tL = contentsRect().topLeft(); 650 QPoint tL = contentsRect().topLeft();
651 int tLx = tL.x(); 651 int tLx = tL.x();
652 int tLy = tL.y(); 652 int tLy = tL.y();
653 653
654 word_selection_mode = FALSE; 654 word_selection_mode = FALSE;
655 655
656//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 656//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
657 if ( ev->button() == LeftButton) 657 if ( ev->button() == LeftButton)
658 { 658 {
659 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 659 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
660 660
661 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 661 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
662 662
663 if (mouse_marks || (ev->state() & ShiftButton)) 663 if (mouse_marks || (ev->state() & ShiftButton))
664 { 664 {
665 emit clearSelectionSignal(); 665 emit clearSelectionSignal();
666 iPntSel = pntSel = pos; 666 iPntSel = pntSel = pos;
667 actSel = 1; // left mouse button pressed but nothing selected yet. 667 actSel = 1; // left mouse button pressed but nothing selected yet.
668 grabMouse( /*crossCursor*/ ); // handle with care! 668 grabMouse( /*crossCursor*/ ); // handle with care!
669 } 669 }
670 else 670 else
671 { 671 {
672 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 672 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
673 } 673 }
674 } 674 }
675 if ( ev->button() == MidButton ) 675 if ( ev->button() == MidButton )
676 { 676 {
677 emitSelection(); 677 emitSelection();
678 } 678 }
679 if ( ev->button() == RightButton ) // Configure 679 if ( ev->button() == RightButton ) // Configure
680 { 680 {
681 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 681 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
682 } 682 }
683} 683}
684 684
685void TEWidget::mouseMoveEvent(QMouseEvent* ev) 685void TEWidget::mouseMoveEvent(QMouseEvent* ev)
686{ 686{
687 // for auto-hiding the cursor, we need mouseTracking 687 // for auto-hiding the cursor, we need mouseTracking
688 if (ev->state() == NoButton ) return; 688 if (ev->state() == NoButton ) return;
689 689
690 if (actSel == 0) return; 690 if (actSel == 0) return;
691 691
692 // don't extend selection while pasting 692 // don't extend selection while pasting
693 if (ev->state() & MidButton) return; 693 if (ev->state() & MidButton) return;
694 694
695 //if ( !contentsRect().contains(ev->pos()) ) return; 695 //if ( !contentsRect().contains(ev->pos()) ) return;
696 QPoint tL = contentsRect().topLeft(); 696 QPoint tL = contentsRect().topLeft();
697 int tLx = tL.x(); 697 int tLx = tL.x();
698 int tLy = tL.y(); 698 int tLy = tL.y();
699 int scroll = scrollbar->value(); 699 int scroll = scrollbar->value();
700 700
701 // we're in the process of moving the mouse with the left button pressed 701 // we're in the process of moving the mouse with the left button pressed
702 // the mouse cursor will kept catched within the bounds of the text in 702 // the mouse cursor will kept catched within the bounds of the text in
703 // this widget. 703 // this widget.
704 704
705 // Adjust position within text area bounds. See FIXME above. 705 // Adjust position within text area bounds. See FIXME above.
706 QPoint pos = ev->pos(); 706 QPoint pos = ev->pos();
707 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 707 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
708 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); 708 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
709 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 709 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
710 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); 710 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
711 // check if we produce a mouse move event by this 711 // check if we produce a mouse move event by this
712 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 712 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
713 713
714 if ( pos.y() == tLy+bY+lines*font_h-1 ) 714 if ( pos.y() == tLy+bY+lines*font_h-1 )
715 { 715 {
716 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 716 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
717 } 717 }
718 if ( pos.y() == tLy+bY ) 718 if ( pos.y() == tLy+bY )
719 { 719 {
720 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 720 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
721 } 721 }
722 722
723 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 723 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
724 QPoint ohere; 724 QPoint ohere;
725 bool swapping = FALSE; 725 bool swapping = FALSE;
726 726
727 if ( word_selection_mode ) 727 if ( word_selection_mode )
728 { 728 {
729 // Extend to word boundaries 729 // Extend to word boundaries
730 int i; 730 int i;
731 int selClass; 731 int selClass;
732 732
733 bool left_not_right = ( here.y() < iPntSel.y() || 733 bool left_not_right = ( here.y() < iPntSel.y() ||
734 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 734 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
735 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 735 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
736 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 736 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
737 swapping = left_not_right != old_left_not_right; 737 swapping = left_not_right != old_left_not_right;
738 738
739 // Find left (left_not_right ? from here : from start) 739 // Find left (left_not_right ? from here : from start)
740 QPoint left = left_not_right ? here : iPntSel; 740 QPoint left = left_not_right ? here : iPntSel;
741 i = loc(left.x(),left.y()); 741 i = loc(left.x(),left.y());
742 selClass = charClass(image[i].c); 742 selClass = charClass(image[i].c);
743 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 743 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
744 { i--; left.rx()--; } 744 { i--; left.rx()--; }
745 745
746 // Find left (left_not_right ? from start : from here) 746 // Find left (left_not_right ? from start : from here)
747 QPoint right = left_not_right ? iPntSel : here; 747 QPoint right = left_not_right ? iPntSel : here;
748 i = loc(right.x(),right.y()); 748 i = loc(right.x(),right.y());
749 selClass = charClass(image[i].c); 749 selClass = charClass(image[i].c);
750 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 750 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
751 { i++; right.rx()++; } 751 { i++; right.rx()++; }
752 752
753 // Pick which is start (ohere) and which is extension (here) 753 // Pick which is start (ohere) and which is extension (here)
754 if ( left_not_right ) 754 if ( left_not_right )
755 { 755 {
756 here = left; ohere = right; 756 here = left; ohere = right;
757 } 757 }
758 else 758 else
759 { 759 {
760 here = right; ohere = left; 760 here = right; ohere = left;
761 } 761 }
762 } 762 }
763 763
764 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 764 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
765 765
766 if ( word_selection_mode ) { 766 if ( word_selection_mode ) {
767 if ( actSel < 2 || swapping ) { 767 if ( actSel < 2 || swapping ) {
768 emit beginSelectionSignal( ohere.x(), ohere.y() ); 768 emit beginSelectionSignal( ohere.x(), ohere.y() );
769 } 769 }
770 } else if ( actSel < 2 ) { 770 } else if ( actSel < 2 ) {
771 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 771 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
772 } 772 }
773 773
774 actSel = 2; // within selection 774 actSel = 2; // within selection
775 pntSel = here; 775 pntSel = here;
776 emit extendSelectionSignal( here.x(), here.y() ); 776 emit extendSelectionSignal( here.x(), here.y() );
777} 777}
778 778
779void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 779void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
780{ 780{
781//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 781//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
782 if ( ev->button() == LeftButton) 782 if ( ev->button() == LeftButton)
783 { 783 {
784 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 784 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
785 preserve_line_breaks = TRUE; 785 preserve_line_breaks = TRUE;
786 actSel = 0; 786 actSel = 0;
787 787
788 //FIXME: emits a release event even if the mouse is 788 //FIXME: emits a release event even if the mouse is
789 // outside the range. The procedure used in `mouseMoveEvent' 789 // outside the range. The procedure used in `mouseMoveEvent'
790 // applies here, too. 790 // applies here, too.
791 791
792 QPoint tL = contentsRect().topLeft(); 792 QPoint tL = contentsRect().topLeft();
793 int tLx = tL.x(); 793 int tLx = tL.x();
794 int tLy = tL.y(); 794 int tLy = tL.y();
795 795
796 if (!mouse_marks && !(ev->state() & ShiftButton)) 796 if (!mouse_marks && !(ev->state() & ShiftButton))
797 emit mouseSignal( 3, // release 797 emit mouseSignal( 3, // release
798 (ev->x()-tLx-blX)/font_w + 1, 798 (ev->x()-tLx-blX)/font_w + 1,
799 (ev->y()-tLy-bY)/font_h + 1 ); 799 (ev->y()-tLy-bY)/font_h + 1 );
800 releaseMouse(); 800 releaseMouse();
801 } 801 }
802} 802}
803 803
804void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 804void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
805{ 805{
806 if ( ev->button() != LeftButton) return; 806 if ( ev->button() != LeftButton) return;
807 807
808 QPoint tL = contentsRect().topLeft(); 808 QPoint tL = contentsRect().topLeft();
809 int tLx = tL.x(); 809 int tLx = tL.x();
810 int tLy = tL.y(); 810 int tLy = tL.y();
811 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 811 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
812 812
813 // pass on double click as two clicks. 813 // pass on double click as two clicks.
814 if (!mouse_marks && !(ev->state() & ShiftButton)) 814 if (!mouse_marks && !(ev->state() & ShiftButton))
815 { 815 {
816 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 816 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
817 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 817 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
818 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 818 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
819 return; 819 return;
820 } 820 }
821 821
822 822
823 emit clearSelectionSignal(); 823 emit clearSelectionSignal();
824 QPoint bgnSel = pos; 824 QPoint bgnSel = pos;
825 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 825 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
826 int i = loc(bgnSel.x(),bgnSel.y()); 826 int i = loc(bgnSel.x(),bgnSel.y());
827 iPntSel = bgnSel; 827 iPntSel = bgnSel;
828 828
829 word_selection_mode = TRUE; 829 word_selection_mode = TRUE;
830 830
831 // find word boundaries... 831 // find word boundaries...
832 int selClass = charClass(image[i].c); 832 int selClass = charClass(image[i].c);
833 { 833 {
834 // set the start... 834 // set the start...
835 int x = bgnSel.x(); 835 int x = bgnSel.x();
836 while ( x > 0 && charClass(image[i-1].c) == selClass ) 836 while ( x > 0 && charClass(image[i-1].c) == selClass )
837 { i--; x--; } 837 { i--; x--; }
838 bgnSel.setX(x); 838 bgnSel.setX(x);
839 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 839 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
840 840
841 // set the end... 841 // set the end...
842 i = loc( endSel.x(), endSel.y() ); 842 i = loc( endSel.x(), endSel.y() );
843 x = endSel.x(); 843 x = endSel.x();
844 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 844 while( x < columns-1 && charClass(image[i+1].c) == selClass )
845 { i++; x++ ; } 845 { i++; x++ ; }
846 endSel.setX(x); 846 endSel.setX(x);
847 actSel = 2; // within selection 847 actSel = 2; // within selection
848 emit extendSelectionSignal( endSel.x(), endSel.y() ); 848 emit extendSelectionSignal( endSel.x(), endSel.y() );
849 emit endSelectionSignal(preserve_line_breaks); 849 emit endSelectionSignal(preserve_line_breaks);
850 preserve_line_breaks = TRUE; 850 preserve_line_breaks = TRUE;
851 } 851 }
852} 852}
853 853
854void TEWidget::focusInEvent( QFocusEvent * ) 854void TEWidget::focusInEvent( QFocusEvent * )
855{ 855{
856 // do nothing, to prevent repainting 856 // do nothing, to prevent repainting
857} 857}
858 858
859 859
860void TEWidget::focusOutEvent( QFocusEvent * ) 860void TEWidget::focusOutEvent( QFocusEvent * )
861{ 861{
862 // do nothing, to prevent repainting 862 // do nothing, to prevent repainting
863} 863}
864 864
865bool TEWidget::focusNextPrevChild( bool next ) 865bool TEWidget::focusNextPrevChild( bool next )
866{ 866{
867 if (next) 867 if (next)
868 return false; // This disables changing the active part in konqueror 868 return false; // This disables changing the active part in konqueror
869 // when pressing Tab 869 // when pressing Tab
870 return QFrame::focusNextPrevChild( next ); 870 return QFrame::focusNextPrevChild( next );
871} 871}
872 872
873 873
874int TEWidget::charClass(char ch) const 874int TEWidget::charClass(char ch) const
875{ 875{
876 // This might seem like overkill, but imagine if ch was a Unicode 876 // This might seem like overkill, but imagine if ch was a Unicode
877 // character (Qt 2.0 QChar) - it might then be sensible to separate 877 // character (Qt 2.0 QChar) - it might then be sensible to separate
878 // the different language ranges, etc. 878 // the different language ranges, etc.
879 879
880 if ( isspace(ch) ) return ' '; 880 if ( isspace(ch) ) return ' ';
881 881
882 static const char *word_characters = ":@-./_~"; 882 static const char *word_characters = ":@-./_~";
883 if ( isalnum(ch) || strchr(word_characters, ch) ) 883 if ( isalnum(ch) || strchr(word_characters, ch) )
884 return 'a'; 884 return 'a';
885 885
886 // Everything else is weird 886 // Everything else is weird
887 return 1; 887 return 1;
888} 888}
889 889
890void TEWidget::setMouseMarks(bool on) 890void TEWidget::setMouseMarks(bool on)
891{ 891{
892 mouse_marks = on; 892 mouse_marks = on;
893 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 893 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
894} 894}
895 895
896/* ------------------------------------------------------------------------- */ 896/* ------------------------------------------------------------------------- */
897/* */ 897/* */
898/* Clipboard */ 898/* Clipboard */
899/* */ 899/* */
900/* ------------------------------------------------------------------------- */ 900/* ------------------------------------------------------------------------- */
901 901
902#undef KeyPress 902#undef KeyPress
903 903
904void TEWidget::emitSelection() 904void TEWidget::emitSelection()
905// Paste Clipboard by simulating keypress events 905// Paste Clipboard by simulating keypress events
906{ 906{
907#ifndef QT_NO_CLIPBOARD 907#ifndef QT_NO_CLIPBOARD
908 QString text = QApplication::clipboard()->text(); 908 QString text = QApplication::clipboard()->text();
909 if ( ! text.isNull() ) 909 if ( ! text.isNull() )
910 { 910 {
911 text.replace(QRegExp("\n"), "\r"); 911 text.replace(QRegExp("\n"), "\r");
912 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 912 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
913 emit keyPressedSignal(&e); // expose as a big fat keypress event 913 emit keyPressedSignal(&e); // expose as a big fat keypress event
914 emit clearSelectionSignal(); 914 emit clearSelectionSignal();
915 } 915 }
916#endif 916#endif
917} 917}
918 918
919void TEWidget::emitText(QString text) 919void TEWidget::emitText(QString text)
920{ 920{
921 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 921 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
922 emit keyPressedSignal(&e); // expose as a big fat keypress event 922 emit keyPressedSignal(&e); // expose as a big fat keypress event
923} 923}
924 924
925void TEWidget::pasteClipboard( ) 925void TEWidget::pasteClipboard( )
926{ 926{
927 emitSelection(); 927 emitSelection();
928} 928}
929 929
930void TEWidget::setSelection(const QString& t) 930void TEWidget::setSelection(const QString& t)
931{ 931{
932#ifndef QT_NO_CLIPBOARD 932#ifndef QT_NO_CLIPBOARD
933 // Disconnect signal while WE set the clipboard 933 // Disconnect signal while WE set the clipboard
934 QObject *cb = QApplication::clipboard(); 934 QObject *cb = QApplication::clipboard();
935 QObject::disconnect( cb, SIGNAL(dataChanged()), 935 QObject::disconnect( cb, SIGNAL(dataChanged()),
936 this, SLOT(onClearSelection()) ); 936 this, SLOT(onClearSelection()) );
937 937
938 QApplication::clipboard()->setText(t); 938 QApplication::clipboard()->setText(t);
939 939
940 QObject::connect( cb, SIGNAL(dataChanged()), 940 QObject::connect( cb, SIGNAL(dataChanged()),
941 this, SLOT(onClearSelection()) ); 941 this, SLOT(onClearSelection()) );
942#endif 942#endif
943} 943}
944 944
945void TEWidget::onClearSelection() 945void TEWidget::onClearSelection()
946{ 946{
947 emit clearSelectionSignal(); 947 emit clearSelectionSignal();
948} 948}
949 949
950/* ------------------------------------------------------------------------- */ 950/* ------------------------------------------------------------------------- */
951/* */ 951/* */
952/* Keyboard */ 952/* Keyboard */
953/* */ 953/* */
954/* ------------------------------------------------------------------------- */ 954/* ------------------------------------------------------------------------- */
955 955
956//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 956//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
957// due to a bug in `QT' or the ignorance of the author to prevent 957// due to a bug in `QT' or the ignorance of the author to prevent
958// repaint events being emitted to the screen whenever one leaves 958// repaint events being emitted to the screen whenever one leaves
959// or reenters the screen to/from another application. 959// or reenters the screen to/from another application.
960// 960//
961// Troll says one needs to change focusInEvent() and focusOutEvent(), 961// Troll says one needs to change focusInEvent() and focusOutEvent(),
962// which would also let you have an in-focus cursor and an out-focus 962// which would also let you have an in-focus cursor and an out-focus
963// cursor like xterm does. 963// cursor like xterm does.
964 964
965// for the auto-hide cursor feature, I added empty focusInEvent() and 965// for the auto-hide cursor feature, I added empty focusInEvent() and
966// focusOutEvent() so that update() isn't called. 966// focusOutEvent() so that update() isn't called.
967// For auto-hide, we need to get keypress-events, but we only get them when 967// For auto-hide, we need to get keypress-events, but we only get them when
968// we have focus. 968// we have focus.
969 969
970void TEWidget::doScroll(int lines) 970void TEWidget::doScroll(int lines)
971{ 971{
972 scrollbar->setValue(scrollbar->value()+lines); 972 scrollbar->setValue(scrollbar->value()+lines);
973} 973}
974 974
975bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 975bool TEWidget::eventFilter( QObject *obj, QEvent *e )
976{ 976{
977 if ( (e->type() == QEvent::Accel || 977 if ( (e->type() == QEvent::Accel ||
978 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) 978 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this )
979 { 979 {
980 static_cast<QKeyEvent *>( e )->ignore(); 980 static_cast<QKeyEvent *>( e )->ignore();
981 return true; 981 return true;
982 } 982 }
983 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 983 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
984 return FALSE; // not us 984 return FALSE; // not us
985 if ( e->type() == QEvent::Wheel) 985 if ( e->type() == QEvent::Wheel)
986 { 986 {
987 QApplication::sendEvent(scrollbar, e); 987 QApplication::sendEvent(scrollbar, e);
988 } 988 }
989 989
990#ifdef FAKE_CTRL_AND_ALT 990#ifdef FAKE_CTRL_AND_ALT
991 static bool control = FALSE; 991 static bool control = FALSE;
992 static bool alt = FALSE; 992 static bool alt = FALSE;
993 // Has a keyboard with no CTRL and ALT keys, but we fake it: 993 qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
994 bool dele=FALSE; 994 bool dele=FALSE;
995 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 995 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
996 QKeyEvent* ke = (QKeyEvent*)e; 996 QKeyEvent* ke = (QKeyEvent*)e;
997 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 997 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
998 switch (ke->key()) { 998 switch (ke->key()) {
999 case Key_F9: // let this be "Control" 999 case Key_F9: // let this be "Control"
1000 control = keydown; 1000 control = keydown;
1001 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1001 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1002 dele=TRUE; 1002 dele=TRUE;
1003 break; 1003 break;
1004 case Key_F13: // let this be "Alt" 1004 case Key_F13: // let this be "Alt"
1005 alt = keydown; 1005 alt = keydown;
1006 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1006 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1007 dele=TRUE; 1007 dele=TRUE;
1008 break; 1008 break;
1009 default: 1009 default:
1010 if ( control ) { 1010 if ( control ) {
1011 int a = toupper(ke->ascii())-64; 1011 int a = toupper(ke->ascii())-64;
1012 if ( a >= 0 && a < ' ' ) { 1012 if ( a >= 0 && a < ' ' ) {
1013 e = new QKeyEvent(e->type(), ke->key(), 1013 e = new QKeyEvent(e->type(), ke->key(),
1014 a, ke->state()|ControlButton, QChar(a,0)); 1014 a, ke->state()|ControlButton, QChar(a,0));
1015 dele=TRUE; 1015 dele=TRUE;
1016 } 1016 }
1017 } 1017 }
1018 if ( alt ) { 1018 if ( alt ) {
1019 e = new QKeyEvent(e->type(), ke->key(), 1019 e = new QKeyEvent(e->type(), ke->key(),
1020 ke->ascii(), ke->state()|AltButton, ke->text()); 1020 ke->ascii(), ke->state()|AltButton, ke->text());
1021 dele=TRUE; 1021 dele=TRUE;
1022 } 1022 }
1023 } 1023 }
1024 } 1024 }
1025#endif 1025#endif
1026 1026
1027 if ( e->type() == QEvent::KeyPress ) 1027 if ( e->type() == QEvent::KeyPress )
1028 { 1028 {
1029 QKeyEvent* ke = (QKeyEvent*)e; 1029 QKeyEvent* ke = (QKeyEvent*)e;
1030
1031 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1030 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1032 // know where the current selection is. 1031 // know where the current selection is.
1033 1032
1033// qDebug("key pressed is 0x%x",ke->key());
1034 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
1035// qDebug("key pressed 2 is 0x%x",ke->key());
1036 emitText("\\"); // expose
1037 } else
1034 emit keyPressedSignal(ke); // expose 1038 emit keyPressedSignal(ke); // expose
1035 ke->accept(); 1039 ke->accept();
1036#ifdef FAKE_CTRL_AND_ALT 1040#ifdef FAKE_CTRL_AND_ALT
1037 if ( dele ) delete e; 1041 if ( dele ) delete e;
1038#endif 1042#endif
1039 return true; // stop the event 1043 return true; // stop the event
1040 } 1044 }
1041 if ( e->type() == QEvent::Enter ) 1045 if ( e->type() == QEvent::Enter )
1042 { 1046 {
1043 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1047 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1044 this, SLOT(onClearSelection()) ); 1048 this, SLOT(onClearSelection()) );
1045 } 1049 }
1046 if ( e->type() == QEvent::Leave ) 1050 if ( e->type() == QEvent::Leave )
1047 { 1051 {
1048 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1052 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1049 this, SLOT(onClearSelection()) ); 1053 this, SLOT(onClearSelection()) );
1050 } 1054 }
1051 return QFrame::eventFilter( obj, e ); 1055 return QFrame::eventFilter( obj, e );
1052} 1056}
1053 1057
1054/* ------------------------------------------------------------------------- */ 1058/* ------------------------------------------------------------------------- */
1055/* */ 1059/* */
1056/* Frame */ 1060/* Frame */
1057/* */ 1061/* */
1058/* ------------------------------------------------------------------------- */ 1062/* ------------------------------------------------------------------------- */
1059 1063
1060void TEWidget::frameChanged() 1064void TEWidget::frameChanged()
1061{ 1065{
1062 propagateSize(); 1066 propagateSize();
1063 update(); 1067 update();
1064} 1068}
1065 1069
1066/* ------------------------------------------------------------------------- */ 1070/* ------------------------------------------------------------------------- */
1067/* */ 1071/* */
1068/* Sound */ 1072/* Sound */
1069/* */ 1073/* */
1070/* ------------------------------------------------------------------------- */ 1074/* ------------------------------------------------------------------------- */
1071 1075
1072void TEWidget::Bell() 1076void TEWidget::Bell()
1073{ 1077{
1074 QApplication::beep(); 1078 QApplication::beep();
1075} 1079}
1076 1080
1077/* ------------------------------------------------------------------------- */ 1081/* ------------------------------------------------------------------------- */
1078/* */ 1082/* */
1079/* Auxiluary */ 1083/* Auxiluary */
1080/* */ 1084/* */
1081/* ------------------------------------------------------------------------- */ 1085/* ------------------------------------------------------------------------- */
1082 1086
1083void TEWidget::clearImage() 1087void TEWidget::clearImage()
1084// initialize the image 1088// initialize the image
1085// for internal use only 1089// for internal use only
1086{ 1090{
1087 for (int y = 0; y < lines; y++) 1091 for (int y = 0; y < lines; y++)
1088 for (int x = 0; x < columns; x++) 1092 for (int x = 0; x < columns; x++)
1089 { 1093 {
1090 image[loc(x,y)].c = 0xff; //' '; 1094 image[loc(x,y)].c = 0xff; //' ';
1091 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1095 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1092 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1096 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1093 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1097 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1094 } 1098 }
1095} 1099}
1096 1100
1097// Create Image /////////////////////////////////////////////////////// 1101// Create Image ///////////////////////////////////////////////////////
1098 1102
1099void TEWidget::calcGeometry() 1103void TEWidget::calcGeometry()
1100{ 1104{
1101 //FIXME: set rimX == rimY == 0 when running in full screen mode. 1105 //FIXME: set rimX == rimY == 0 when running in full screen mode.
1102 1106
1103 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1107 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1104 contentsRect().height()); 1108 contentsRect().height());
1105 switch(scrollLoc) 1109 switch(scrollLoc)
1106 { 1110 {
1107 case SCRNONE : 1111 case SCRNONE :
1108 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1112 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1109 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1113 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1110 brX = blX; 1114 brX = blX;
1111 scrollbar->hide(); 1115 scrollbar->hide();
1112 break; 1116 break;
1113 case SCRLEFT : 1117 case SCRLEFT :
1114 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1118 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1115 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1119 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1116 blX = brX + scrollbar->width(); 1120 blX = brX + scrollbar->width();
1117 scrollbar->move(contentsRect().topLeft()); 1121 scrollbar->move(contentsRect().topLeft());
1118 scrollbar->show(); 1122 scrollbar->show();
1119 break; 1123 break;
1120 case SCRRIGHT: 1124 case SCRRIGHT:
1121 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1125 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1122 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1126 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1123 brX = blX; 1127 brX = blX;
1124 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1128 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1125 scrollbar->show(); 1129 scrollbar->show();
1126 break; 1130 break;
1127 } 1131 }
1128 //FIXME: support 'rounding' styles 1132 //FIXME: support 'rounding' styles
1129 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1133 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1130 bY = (contentsRect().height() - (lines *font_h)) / 2; 1134 bY = (contentsRect().height() - (lines *font_h)) / 2;
1131} 1135}
1132 1136
1133void TEWidget::makeImage() 1137void TEWidget::makeImage()
1134//FIXME: rename 'calcGeometry? 1138//FIXME: rename 'calcGeometry?
1135{ 1139{
1136 calcGeometry(); 1140 calcGeometry();
1137 image = (ca*) malloc(lines*columns*sizeof(ca)); 1141 image = (ca*) malloc(lines*columns*sizeof(ca));
1138 clearImage(); 1142 clearImage();
1139} 1143}
1140 1144
1141// calculate the needed size 1145// calculate the needed size
1142QSize TEWidget::calcSize(int cols, int lins) const 1146QSize TEWidget::calcSize(int cols, int lins) const
1143{ 1147{
1144 int frw = width() - contentsRect().width(); 1148 int frw = width() - contentsRect().width();
1145 int frh = height() - contentsRect().height(); 1149 int frh = height() - contentsRect().height();
1146 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1150 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1147 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1151 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1148} 1152}
1149 1153
1150QSize TEWidget::sizeHint() const 1154QSize TEWidget::sizeHint() const
1151{ 1155{
1152 return size(); 1156 return size();
1153} 1157}
1154 1158
1155void TEWidget::styleChange(QStyle &) 1159void TEWidget::styleChange(QStyle &)
1156{ 1160{
1157 propagateSize(); 1161 propagateSize();
1158} 1162}
1159 1163
1160#ifndef QT_NO_DRAGANDDROP 1164#ifndef QT_NO_DRAGANDDROP
1161 1165
1162/* --------------------------------------------------------------------- */ 1166/* --------------------------------------------------------------------- */
1163/* */ 1167/* */
1164/* Drag & Drop */ 1168/* Drag & Drop */
1165/* */ 1169/* */
1166/* --------------------------------------------------------------------- */ 1170/* --------------------------------------------------------------------- */
1167 1171
1168 1172
1169void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1173void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1170{ 1174{
1171 e->accept(QTextDrag::canDecode(e) || 1175 e->accept(QTextDrag::canDecode(e) ||
1172 QUriDrag::canDecode(e)); 1176 QUriDrag::canDecode(e));
1173} 1177}
1174 1178
1175void TEWidget::dropEvent(QDropEvent* event) 1179void TEWidget::dropEvent(QDropEvent* event)
1176{ 1180{
1177 // The current behaviour when url(s) are dropped is 1181 // The current behaviour when url(s) are dropped is
1178 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1182 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1179 // * in all other cases, just paste 1183 // * in all other cases, just paste
1180 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1184 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1181 QStrList strlist; 1185 QStrList strlist;
1182 int file_count = 0; 1186 int file_count = 0;
1183 dropText = ""; 1187 dropText = "";
1184 bool bPopup = true; 1188 bool bPopup = true;
1185 1189
1186 if(QUriDrag::decode(event, strlist)) { 1190 if(QUriDrag::decode(event, strlist)) {
1187 if (strlist.count()) { 1191 if (strlist.count()) {
1188 for(const char* p = strlist.first(); p; p = strlist.next()) { 1192 for(const char* p = strlist.first(); p; p = strlist.next()) {
1189 if(file_count++ > 0) { 1193 if(file_count++ > 0) {
1190 dropText += " "; 1194 dropText += " ";
1191 bPopup = false; // more than one file, don't popup 1195 bPopup = false; // more than one file, don't popup
1192 } 1196 }
1193 1197
1194/* 1198/*
1195 KURL url(p); 1199 KURL url(p);
1196 if (url.isLocalFile()) { 1200 if (url.isLocalFile()) {
1197 dropText += url.path(); // local URL : remove protocol 1201 dropText += url.path(); // local URL : remove protocol
1198 } 1202 }
1199 else { 1203 else {
1200 dropText += url.prettyURL(); 1204 dropText += url.prettyURL();
1201 bPopup = false; // a non-local file, don't popup 1205 bPopup = false; // a non-local file, don't popup
1202 } 1206 }
1203*/ 1207*/
1204 1208
1205 } 1209 }
1206 1210
1207 if (bPopup) 1211 if (bPopup)
1208 // m_drop->popup(pos() + event->pos()); 1212 // m_drop->popup(pos() + event->pos());
1209 m_drop->popup(mapToGlobal(event->pos())); 1213 m_drop->popup(mapToGlobal(event->pos()));
1210 else 1214 else
1211 { 1215 {
1212 if (currentSession) { 1216 if (currentSession) {
1213 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1217 currentSession->getEmulation()->sendString(dropText.local8Bit());
1214 } 1218 }
1215// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1219// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1216 } 1220 }
1217 } 1221 }
1218 } 1222 }
1219 else if(QTextDrag::decode(event, dropText)) { 1223 else if(QTextDrag::decode(event, dropText)) {
1220// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1224// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1221 if (currentSession) { 1225 if (currentSession) {
1222 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1226 currentSession->getEmulation()->sendString(dropText.local8Bit());
1223 } 1227 }
1224 // Paste it 1228 // Paste it
1225 } 1229 }
1226} 1230}
1227#endif 1231#endif
1228 1232
1229 1233
1230void TEWidget::drop_menu_activated(int item) 1234void TEWidget::drop_menu_activated(int item)
1231{ 1235{
1232#ifndef QT_NO_DRAGANDDROP 1236#ifndef QT_NO_DRAGANDDROP
1233 switch (item) 1237 switch (item)
1234 { 1238 {
1235 case 0: // paste 1239 case 0: // paste
1236 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1240 currentSession->getEmulation()->sendString(dropText.local8Bit());
1237// KWM::activate((Window)this->winId()); 1241// KWM::activate((Window)this->winId());
1238 break; 1242 break;
1239 case 1: // cd ... 1243 case 1: // cd ...
1240 currentSession->getEmulation()->sendString("cd "); 1244 currentSession->getEmulation()->sendString("cd ");
1241 struct stat statbuf; 1245 struct stat statbuf;
1242 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1246 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1243 { 1247 {
1244 if ( !S_ISDIR(statbuf.st_mode) ) 1248 if ( !S_ISDIR(statbuf.st_mode) )
1245 { 1249 {
1246/* 1250/*
1247 KURL url; 1251 KURL url;
1248 url.setPath( dropText ); 1252 url.setPath( dropText );
1249 dropText = url.directory( true, false ); // remove filename 1253 dropText = url.directory( true, false ); // remove filename
1250*/ 1254*/
1251 } 1255 }
1252 } 1256 }
1253 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1257 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1254 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1258 currentSession->getEmulation()->sendString(dropText.local8Bit());
1255 currentSession->getEmulation()->sendString("\n"); 1259 currentSession->getEmulation()->sendString("\n");
1256// KWM::activate((Window)this->winId()); 1260// KWM::activate((Window)this->winId());
1257 break; 1261 break;
1258 } 1262 }
1259#endif 1263#endif
1260} 1264}
1261 1265
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index f13d0c9..adcfb7f 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,884 +1,885 @@
1/* ---------------------------------------------------------------------- */ 1/* ---------------------------------------------------------------------- */
2/* */ 2/* */
3/* [main.C] Konsole */ 3/* [main.C] Konsole */
4/* */ 4/* */
5/* ---------------------------------------------------------------------- */ 5/* ---------------------------------------------------------------------- */
6/* */ 6/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */ 8/* */
9/* This file is part of Konsole, an X terminal. */ 9/* This file is part of Konsole, an X terminal. */
10/* */ 10/* */
11/* The material contained in here more or less directly orginates from */ 11/* The material contained in here more or less directly orginates from */
12/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ 12/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
13/* */ 13/* */
14/* ---------------------------------------------------------------------- */ 14/* ---------------------------------------------------------------------- */
15/* */ 15/* */
16/* Ported Konsole to Qt/Embedded */ 16/* Ported Konsole to Qt/Embedded */
17/* */ 17/* */
18/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 18/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
19/* */ 19/* */
20/* -------------------------------------------------------------------------- */ 20/* -------------------------------------------------------------------------- */
21// enhancements added by L.J. Potter <ljp@llornkcor.com> 21// enhancements added by L.J. Potter <ljp@llornkcor.com>
22 22
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25#include <qdir.h> 25#include <qdir.h>
26#include <qevent.h> 26#include <qevent.h>
27#include <qdragobject.h> 27#include <qdragobject.h>
28#include <qobjectlist.h> 28#include <qobjectlist.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30#include <qpe/qpetoolbar.h> 30#include <qpe/qpetoolbar.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32#include <qfontdialog.h> 32#include <qfontdialog.h>
33#include <qglobal.h> 33#include <qglobal.h>
34#include <qpainter.h> 34#include <qpainter.h>
35#include <qpe/qpemenubar.h> 35#include <qpe/qpemenubar.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <qaction.h> 37#include <qaction.h>
38#include <qapplication.h> 38#include <qapplication.h>
39#include <qfontmetrics.h> 39#include <qfontmetrics.h>
40#include <qcombobox.h> 40#include <qcombobox.h>
41#include <qevent.h> 41#include <qevent.h>
42#include <qtabwidget.h> 42#include <qtabwidget.h>
43#include <qtabbar.h> 43#include <qtabbar.h>
44#include <qpe/config.h> 44#include <qpe/config.h>
45#include <qstringlist.h> 45#include <qstringlist.h>
46#include <qpalette.h> 46#include <qpalette.h>
47 47
48#include <sys/wait.h> 48#include <sys/wait.h>
49#include <stdio.h> 49#include <stdio.h>
50#include <stdlib.h> 50#include <stdlib.h>
51#include <assert.h> 51#include <assert.h>
52 52
53#include "konsole.h" 53#include "konsole.h"
54#include "keytrans.h" 54#include "keytrans.h"
55#include "commandeditdialog.h" 55#include "commandeditdialog.h"
56 56
57class EKNumTabBar : public QTabBar { 57class EKNumTabBar : public QTabBar {
58public: 58public:
59 void numberTabs() 59 void numberTabs()
60 { 60 {
61 // Yes, it really is this messy. QTabWidget needs functions 61 // Yes, it really is this messy. QTabWidget needs functions
62 // that provide acces to tabs in a sequential way. 62 // that provide acces to tabs in a sequential way.
63 int m=INT_MIN; 63 int m=INT_MIN;
64 for (int i=0; i<count(); i++) { 64 for (int i=0; i<count(); i++) {
65 QTab* left=0; 65 QTab* left=0;
66 QListIterator<QTab> it(*tabList()); 66 QListIterator<QTab> it(*tabList());
67 int x=INT_MAX; 67 int x=INT_MAX;
68 for( QTab* t; (t=it.current()); ++it ) { 68 for( QTab* t; (t=it.current()); ++it ) {
69 int tx = t->rect().x(); 69 int tx = t->rect().x();
70 if ( tx<x && tx>m ) { 70 if ( tx<x && tx>m ) {
71 x = tx; 71 x = tx;
72 left = t; 72 left = t;
73 } 73 }
74 } 74 }
75 if ( left ) { 75 if ( left ) {
76 left->setText(QString::number(i+1)); 76 left->setText(QString::number(i+1));
77 m = left->rect().x(); 77 m = left->rect().x();
78 } 78 }
79 } 79 }
80 } 80 }
81}; 81};
82 82
83class EKNumTabWidget : public QTabWidget { 83class EKNumTabWidget : public QTabWidget {
84public: 84public:
85 EKNumTabWidget(QWidget* parent) : QTabWidget(parent) 85 EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
86 { 86 {
87 } 87 }
88 88
89 void addTab(QWidget* w) 89 void addTab(QWidget* w)
90 { 90 {
91 QTab* t = new QTab(QString::number(tabBar()->count()+1)); 91 QTab* t = new QTab(QString::number(tabBar()->count()+1));
92 QTabWidget::addTab(w,t); 92 QTabWidget::addTab(w,t);
93 } 93 }
94 94
95 void removeTab(QWidget* w) 95 void removeTab(QWidget* w)
96 { 96 {
97 removePage(w); 97 removePage(w);
98 ((EKNumTabBar*)tabBar())->numberTabs(); 98 ((EKNumTabBar*)tabBar())->numberTabs();
99 } 99 }
100}; 100};
101 101
102// This could be configurable or dynamicly generated from the bash history 102// This could be configurable or dynamicly generated from the bash history
103// file of the user 103// file of the user
104static const char *commonCmds[] = 104static const char *commonCmds[] =
105{ 105{
106 "ls ", // I left this here, cause it looks better than the first alpha 106 "ls ", // I left this here, cause it looks better than the first alpha
107 "cardctl eject", 107 "cardctl eject",
108 "cat ", 108 "cat ",
109 "cd ", 109 "cd ",
110 "chmod ", 110 "chmod ",
111 "clear", 111 "clear",
112 "cp ", 112 "cp ",
113 "dc ", 113 "dc ",
114 "df ", 114 "df ",
115 "dmesg", 115 "dmesg",
116 "echo ", 116 "echo ",
117 "env", 117 "env",
118 "find ", 118 "find ",
119 "free", 119 "free",
120 "grep ", 120 "grep ",
121 "ifconfig ", 121 "ifconfig ",
122 "ipkg ", 122 "ipkg ",
123 "mkdir ", 123 "mkdir ",
124 "mv ", 124 "mv ",
125 "nc localhost 7776", 125 "nc localhost 7776",
126 "nc localhost 7777", 126 "nc localhost 7777",
127 "netstat ", 127 "netstat ",
128 "nslookup ", 128 "nslookup ",
129 "ping ", 129 "ping ",
130 "ps aux", 130 "ps aux",
131 "pwd ", 131 "pwd ",
132 "rm ", 132 "rm ",
133 "rmdir ", 133 "rmdir ",
134 "route ", 134 "route ",
135 "set ", 135 "set ",
136 "traceroute", 136 "traceroute",
137 137
138/* 138/*
139 "gzip", 139 "gzip",
140 "gunzip", 140 "gunzip",
141 "chgrp", 141 "chgrp",
142 "chown", 142 "chown",
143 "date", 143 "date",
144 "dd", 144 "dd",
145 "df", 145 "df",
146 "dmesg", 146 "dmesg",
147 "fuser", 147 "fuser",
148 "hostname", 148 "hostname",
149 "kill", 149 "kill",
150 "killall", 150 "killall",
151 "ln", 151 "ln",
152 "ping", 152 "ping",
153 "mount", 153 "mount",
154 "more", 154 "more",
155 "sort", 155 "sort",
156 "touch", 156 "touch",
157 "umount", 157 "umount",
158 "mknod", 158 "mknod",
159 "netstat", 159 "netstat",
160*/ 160*/
161 161
162 "exit", 162 "exit",
163 NULL 163 NULL
164}; 164};
165 165
166 166
167Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 167Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
168 QMainWindow(parent, name, fl) 168 QMainWindow(parent, name, fl)
169{ 169{
170 QStrList args; 170 QStrList args;
171 init("/bin/sh",args); 171 init("/bin/ash",args);
172// init("/bin/sh",args);
172} 173}
173 174
174Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) 175Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
175 : QMainWindow(0, name) 176 : QMainWindow(0, name)
176{ 177{
177 init(_pgm,_args); 178 init(_pgm,_args);
178} 179}
179 180
180void Konsole::initCommandList() 181void Konsole::initCommandList()
181{ 182{
182// qDebug("Konsole::initCommandList"); 183// qDebug("Konsole::initCommandList");
183 Config cfg("Konsole"); 184 Config cfg("Konsole");
184 cfg.setGroup("Commands"); 185 cfg.setGroup("Commands");
185 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 186 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
186 commonCombo->clear(); 187 commonCombo->clear();
187 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 188 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
188 for (int i = 0; commonCmds[i] != NULL; i++) { 189 for (int i = 0; commonCmds[i] != NULL; i++) {
189 commonCombo->insertItem(commonCmds[i],i); 190 commonCombo->insertItem(commonCmds[i],i);
190 } 191 }
191 } else { 192 } else {
192 for (int i = 0; i < 100; i++) { 193 for (int i = 0; i < 100; i++) {
193 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 194 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
194 commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); 195 commonCombo->insertItem((cfg.readEntry( QString::number(i),"")));
195 } 196 }
196 } 197 }
197 198
198} 199}
199 200
200void Konsole::init(const char* _pgm, QStrList & _args) 201void Konsole::init(const char* _pgm, QStrList & _args)
201{ 202{
202 b_scroll = TRUE; // histon; 203 b_scroll = TRUE; // histon;
203 n_keytab = 0; 204 n_keytab = 0;
204 n_render = 0; 205 n_render = 0;
205 startUp=0; 206 startUp=0;
206 setCaption( tr("Terminal") ); 207 setCaption( tr("Terminal") );
207 setIcon( Resource::loadPixmap( "konsole" ) ); 208 setIcon( Resource::loadPixmap( "konsole" ) );
208 209
209 Config cfg("Konsole"); 210 Config cfg("Konsole");
210 cfg.setGroup("Konsole"); 211 cfg.setGroup("Konsole");
211 QString tmp; 212 QString tmp;
212 // initialize the list of allowed fonts /////////////////////////////////// 213 // initialize the list of allowed fonts ///////////////////////////////////
213 cfont = cfg.readNumEntry("FontID", 1); 214 cfont = cfg.readNumEntry("FontID", 1);
214 QFont f = QFont("Micro", 4, QFont::Normal); 215 QFont f = QFont("Micro", 4, QFont::Normal);
215 f.setFixedPitch(TRUE); 216 f.setFixedPitch(TRUE);
216 fonts.append(new VTFont(tr("Micro"), f)); 217 fonts.append(new VTFont(tr("Micro"), f));
217 218
218 f = QFont("Fixed", 7, QFont::Normal); 219 f = QFont("Fixed", 7, QFont::Normal);
219 f.setFixedPitch(TRUE); 220 f.setFixedPitch(TRUE);
220 fonts.append(new VTFont(tr("Small Fixed"), f)); 221 fonts.append(new VTFont(tr("Small Fixed"), f));
221 222
222 f = QFont("Fixed", 12, QFont::Normal); 223 f = QFont("Fixed", 12, QFont::Normal);
223 f.setFixedPitch(TRUE); 224 f.setFixedPitch(TRUE);
224 fonts.append(new VTFont(tr("Medium Fixed"), f)); 225 fonts.append(new VTFont(tr("Medium Fixed"), f));
225 226
226 // create terminal emulation framework //////////////////////////////////// 227 // create terminal emulation framework ////////////////////////////////////
227 nsessions = 0; 228 nsessions = 0;
228 229
229 tab = new EKNumTabWidget(this); 230 tab = new EKNumTabWidget(this);
230 231
231 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); 232 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
232 233
233 // create terminal toolbar //////////////////////////////////////////////// 234 // create terminal toolbar ////////////////////////////////////////////////
234 setToolBarsMovable( FALSE ); 235 setToolBarsMovable( FALSE );
235 QPEToolBar *menuToolBar = new QPEToolBar( this ); 236 QPEToolBar *menuToolBar = new QPEToolBar( this );
236 menuToolBar->setHorizontalStretchable( TRUE ); 237 menuToolBar->setHorizontalStretchable( TRUE );
237 238
238 QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); 239 QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar );
239 240
240 fontList = new QPopupMenu( this ); 241 fontList = new QPopupMenu( this );
241 for(uint i = 0; i < fonts.count(); i++) { 242 for(uint i = 0; i < fonts.count(); i++) {
242 VTFont *fnt = fonts.at(i); 243 VTFont *fnt = fonts.at(i);
243 fontList->insertItem(fnt->getName(), i); 244 fontList->insertItem(fnt->getName(), i);
244 } 245 }
245 fontChanged(cfont); 246 fontChanged(cfont);
246 247
247 configMenu = new QPopupMenu( this); 248 configMenu = new QPopupMenu( this);
248 colorMenu = new QPopupMenu( this); 249 colorMenu = new QPopupMenu( this);
249 scrollMenu = new QPopupMenu( this); 250 scrollMenu = new QPopupMenu( this);
250 editCommandListMenu = new QPopupMenu( this); 251 editCommandListMenu = new QPopupMenu( this);
251 252
252 configMenu->insertItem("Command List",editCommandListMenu); 253 configMenu->insertItem("Command List",editCommandListMenu);
253 254
254 bool listHidden; 255 bool listHidden;
255 cfg.setGroup("Menubar"); 256 cfg.setGroup("Menubar");
256 if( cfg.readEntry("Hidden","FALSE") == "TRUE") { 257 if( cfg.readEntry("Hidden","FALSE") == "TRUE") {
257 editCommandListMenu->insertItem( tr( "Show command list" )); 258 editCommandListMenu->insertItem( tr( "Show command list" ));
258 listHidden=TRUE; 259 listHidden=TRUE;
259 } else { 260 } else {
260 editCommandListMenu->insertItem( tr( "Hide command list" )); 261 editCommandListMenu->insertItem( tr( "Hide command list" ));
261 listHidden=FALSE; 262 listHidden=FALSE;
262 } 263 }
263 264
264 cfg.setGroup("Tabs"); 265 cfg.setGroup("Tabs");
265 tmp=cfg.readEntry("Position","Bottom"); 266 tmp=cfg.readEntry("Position","Bottom");
266 if(tmp=="Top") { 267 if(tmp=="Top") {
267 tab->setTabPosition(QTabWidget::Top); 268 tab->setTabPosition(QTabWidget::Top);
268 configMenu->insertItem( tr( "Tabs on Bottom" ) ); 269 configMenu->insertItem( tr( "Tabs on Bottom" ) );
269 } else { 270 } else {
270 tab->setTabPosition(QTabWidget::Bottom); 271 tab->setTabPosition(QTabWidget::Bottom);
271 configMenu->insertItem("Tabs on Top"); 272 configMenu->insertItem("Tabs on Top");
272 } 273 }
273 configMenu->insertSeparator(2); 274 configMenu->insertSeparator(2);
274 275
275 colorMenu->insertItem(tr( "Green on Black")); 276 colorMenu->insertItem(tr( "Green on Black"));
276 colorMenu->insertItem(tr( "Black on White")); 277 colorMenu->insertItem(tr( "Black on White"));
277 colorMenu->insertItem(tr( "White on Black")); 278 colorMenu->insertItem(tr( "White on Black"));
278 colorMenu->insertItem(tr( "Black on Transparent")); 279 colorMenu->insertItem(tr( "Black on Transparent"));
279 colorMenu->insertItem(tr( "Black on Red")); 280 colorMenu->insertItem(tr( "Black on Red"));
280 colorMenu->insertItem(tr( "Red on Black")); 281 colorMenu->insertItem(tr( "Red on Black"));
281 colorMenu->insertItem(tr( "Green on Yellow")); 282 colorMenu->insertItem(tr( "Green on Yellow"));
282 colorMenu->insertItem(tr( "Blue on Magenta")); 283 colorMenu->insertItem(tr( "Blue on Magenta"));
283 colorMenu->insertItem(tr( "Magenta on Blue")); 284 colorMenu->insertItem(tr( "Magenta on Blue"));
284 colorMenu->insertItem(tr( "Cyan on White")); 285 colorMenu->insertItem(tr( "Cyan on White"));
285 colorMenu->insertItem(tr( "White on Cyan")); 286 colorMenu->insertItem(tr( "White on Cyan"));
286 colorMenu->insertItem(tr( "Blue on Black")); 287 colorMenu->insertItem(tr( "Blue on Black"));
287 colorMenu->insertItem(tr( "Amber on Black")); 288 colorMenu->insertItem(tr( "Amber on Black"));
288 configMenu->insertItem(tr( "Colors") ,colorMenu); 289 configMenu->insertItem(tr( "Colors") ,colorMenu);
289 290
290 connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); 291 connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
291 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); 292 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
292 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuSelected(int) )); 293 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuSelected(int) ));
293 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); 294 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int)));
294 connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); 295 connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int)));
295 menuBar->insertItem( tr("Font"), fontList ); 296 menuBar->insertItem( tr("Font"), fontList );
296 menuBar->insertItem( tr("Options"), configMenu ); 297 menuBar->insertItem( tr("Options"), configMenu );
297 298
298 QPEToolBar *toolbar = new QPEToolBar( this ); 299 QPEToolBar *toolbar = new QPEToolBar( this );
299 300
300 QAction *a; 301 QAction *a;
301 302
302 // Button Commands 303 // Button Commands
303 a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); 304 a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 );
304 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); 305 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar );
305 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); 306 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 );
306 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); 307 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar );
307 a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 ); 308 a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 );
308 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); 309 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar );
309 a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 ); 310 a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 );
310 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); 311 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar );
311 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); 312 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 );
312 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); 313 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
313 a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 ); 314 a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 );
314 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); 315 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
315 a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 316 a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
316 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar ); 317 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar );
317/* 318/*
318 a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); 319 a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
319 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); 320 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
320 a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); 321 a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
321 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); 322 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
322*/ 323*/
323 324
324 secondToolBar = new QPEToolBar( this ); 325 secondToolBar = new QPEToolBar( this );
325 secondToolBar->setHorizontalStretchable( TRUE ); 326 secondToolBar->setHorizontalStretchable( TRUE );
326 327
327 commonCombo = new QComboBox( secondToolBar ); 328 commonCombo = new QComboBox( secondToolBar );
328 commonCombo->setMaximumWidth(236); 329 commonCombo->setMaximumWidth(236);
329 330
330 editCommandListMenu->insertItem( tr( "Quick Edit" ) ); 331 editCommandListMenu->insertItem( tr( "Quick Edit" ) );
331 if( listHidden) { 332 if( listHidden) {
332 secondToolBar->hide(); 333 secondToolBar->hide();
333 editCommandListMenu->setItemEnabled(-22 ,FALSE); 334 editCommandListMenu->setItemEnabled(-22 ,FALSE);
334 } 335 }
335 editCommandListMenu->insertItem(tr( "Edit" ) ); 336 editCommandListMenu->insertItem(tr( "Edit" ) );
336 337
337 cfg.setGroup("Commands"); 338 cfg.setGroup("Commands");
338 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 339 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
339 340
340 initCommandList(); 341 initCommandList();
341// for (int i = 0; commonCmds[i] != NULL; i++) { 342// for (int i = 0; commonCmds[i] != NULL; i++) {
342// commonCombo->insertItem( commonCmds[i], i ); 343// commonCombo->insertItem( commonCmds[i], i );
343// tmp = cfg.readEntry( QString::number(i),""); 344// tmp = cfg.readEntry( QString::number(i),"");
344// if(tmp != "") 345// if(tmp != "")
345// commonCombo->changeItem( tmp,i ); 346// commonCombo->changeItem( tmp,i );
346// } 347// }
347 348
348 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); 349 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
349 350
350 scrollMenu->insertItem(tr( "None" )); 351 scrollMenu->insertItem(tr( "None" ));
351 scrollMenu->insertItem(tr( "Left" )); 352 scrollMenu->insertItem(tr( "Left" ));
352 scrollMenu->insertItem(tr( "Right" )); 353 scrollMenu->insertItem(tr( "Right" ));
353 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); 354 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
354 355
355 // create applications ///////////////////////////////////////////////////// 356 // create applications /////////////////////////////////////////////////////
356 setCentralWidget(tab); 357 setCentralWidget(tab);
357 358
358 // load keymaps //////////////////////////////////////////////////////////// 359 // load keymaps ////////////////////////////////////////////////////////////
359 KeyTrans::loadAll(); 360 KeyTrans::loadAll();
360 for (int i = 0; i < KeyTrans::count(); i++) 361 for (int i = 0; i < KeyTrans::count(); i++)
361 { KeyTrans* s = KeyTrans::find(i); 362 { KeyTrans* s = KeyTrans::find(i);
362 assert( s ); 363 assert( s );
363 } 364 }
364 365
365 se_pgm = _pgm; 366 se_pgm = _pgm;
366 se_args = _args; 367 se_args = _args;
367 368
368parseCommandLine(); 369parseCommandLine();
369 // read and apply default values /////////////////////////////////////////// 370 // read and apply default values ///////////////////////////////////////////
370 resize(321, 321); // Dummy. 371 resize(321, 321); // Dummy.
371 QSize currentSize = size(); 372 QSize currentSize = size();
372 if (currentSize != size()) 373 if (currentSize != size())
373 defaultSize = size(); 374 defaultSize = size();
374} 375}
375 376
376void Konsole::show() 377void Konsole::show()
377{ 378{
378 if ( !nsessions ) { 379 if ( !nsessions ) {
379 newSession(); 380 newSession();
380 } 381 }
381 QMainWindow::show(); 382 QMainWindow::show();
382} 383}
383 384
384void Konsole::initSession(const char*, QStrList &) 385void Konsole::initSession(const char*, QStrList &)
385{ 386{
386 QMainWindow::show(); 387 QMainWindow::show();
387} 388}
388 389
389Konsole::~Konsole() 390Konsole::~Konsole()
390{ 391{
391 while (nsessions > 0) { 392 while (nsessions > 0) {
392 doneSession(getTe()->currentSession, 0); 393 doneSession(getTe()->currentSession, 0);
393 } 394 }
394 395
395 Config cfg("Konsole"); 396 Config cfg("Konsole");
396 cfg.setGroup("Konsole"); 397 cfg.setGroup("Konsole");
397 cfg.writeEntry("FontID", cfont); 398 cfg.writeEntry("FontID", cfont);
398} 399}
399 400
400void Konsole::fontChanged(int f) 401void Konsole::fontChanged(int f)
401{ 402{
402 VTFont* font = fonts.at(f); 403 VTFont* font = fonts.at(f);
403 if (font != 0) { 404 if (font != 0) {
404 for(uint i = 0; i < fonts.count(); i++) { 405 for(uint i = 0; i < fonts.count(); i++) {
405 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); 406 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
406 } 407 }
407 408
408 cfont = f; 409 cfont = f;
409 410
410 TEWidget* te = getTe(); 411 TEWidget* te = getTe();
411 if (te != 0) { 412 if (te != 0) {
412 te->setVTFont(font->getFont()); 413 te->setVTFont(font->getFont());
413 } 414 }
414 } 415 }
415} 416}
416 417
417 418
418void Konsole::enterCommand(int c) 419void Konsole::enterCommand(int c)
419{ 420{
420 TEWidget* te = getTe(); 421 TEWidget* te = getTe();
421 if (te != 0) { 422 if (te != 0) {
422 if(!commonCombo->editable()) { 423 if(!commonCombo->editable()) {
423 QString text = commonCombo->text(c); //commonCmds[c]; 424 QString text = commonCombo->text(c); //commonCmds[c];
424 te->emitText(text); 425 te->emitText(text);
425 } else { 426 } else {
426 changeCommand( commonCombo->text(c), c); 427 changeCommand( commonCombo->text(c), c);
427 } 428 }
428 } 429 }
429} 430}
430 431
431void Konsole::hitEnter() 432void Konsole::hitEnter()
432{ 433{
433 TEWidget* te = getTe(); 434 TEWidget* te = getTe();
434 if (te != 0) { 435 if (te != 0) {
435 te->emitText(QString("\r")); 436 te->emitText(QString("\r"));
436 } 437 }
437} 438}
438 439
439void Konsole::hitSpace() 440void Konsole::hitSpace()
440{ 441{
441 TEWidget* te = getTe(); 442 TEWidget* te = getTe();
442 if (te != 0) { 443 if (te != 0) {
443 te->emitText(QString(" ")); 444 te->emitText(QString(" "));
444 } 445 }
445} 446}
446 447
447void Konsole::hitTab() 448void Konsole::hitTab()
448{ 449{
449 TEWidget* te = getTe(); 450 TEWidget* te = getTe();
450 if (te != 0) { 451 if (te != 0) {
451 te->emitText(QString("\t")); 452 te->emitText(QString("\t"));
452 } 453 }
453} 454}
454 455
455void Konsole::hitPaste() 456void Konsole::hitPaste()
456{ 457{
457 TEWidget* te = getTe(); 458 TEWidget* te = getTe();
458 if (te != 0) { 459 if (te != 0) {
459 te->pasteClipboard(); 460 te->pasteClipboard();
460 } 461 }
461} 462}
462 463
463void Konsole::hitUp() 464void Konsole::hitUp()
464{ 465{
465 TEWidget* te = getTe(); 466 TEWidget* te = getTe();
466 if (te != 0) { 467 if (te != 0) {
467 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); 468 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
468 QApplication::sendEvent( te, &ke ); 469 QApplication::sendEvent( te, &ke );
469 } 470 }
470} 471}
471 472
472void Konsole::hitDown() 473void Konsole::hitDown()
473{ 474{
474 TEWidget* te = getTe(); 475 TEWidget* te = getTe();
475 if (te != 0) { 476 if (te != 0) {
476 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); 477 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
477 QApplication::sendEvent( te, &ke ); 478 QApplication::sendEvent( te, &ke );
478 } 479 }
479} 480}
480 481
481/** 482/**
482 This function calculates the size of the external widget 483 This function calculates the size of the external widget
483 needed for the internal widget to be 484 needed for the internal widget to be
484 */ 485 */
485QSize Konsole::calcSize(int columns, int lines) { 486QSize Konsole::calcSize(int columns, int lines) {
486 TEWidget* te = getTe(); 487 TEWidget* te = getTe();
487 if (te != 0) { 488 if (te != 0) {
488 QSize size = te->calcSize(columns, lines); 489 QSize size = te->calcSize(columns, lines);
489 return size; 490 return size;
490 } else { 491 } else {
491 QSize size; 492 QSize size;
492 return size; 493 return size;
493 } 494 }
494} 495}
495 496
496/** 497/**
497 sets application window to a size based on columns X lines of the te 498 sets application window to a size based on columns X lines of the te
498 guest widget. Call with (0,0) for setting default size. 499 guest widget. Call with (0,0) for setting default size.
499*/ 500*/
500 501
501void Konsole::setColLin(int columns, int lines) 502void Konsole::setColLin(int columns, int lines)
502{ 503{
503 if ((columns==0) || (lines==0)) 504 if ((columns==0) || (lines==0))
504 { 505 {
505 if (defaultSize.isEmpty()) // not in config file : set default value 506 if (defaultSize.isEmpty()) // not in config file : set default value
506 { 507 {
507 defaultSize = calcSize(80,24); 508 defaultSize = calcSize(80,24);
508 // notifySize(24,80); // set menu items (strange arg order !) 509 // notifySize(24,80); // set menu items (strange arg order !)
509 } 510 }
510 resize(defaultSize); 511 resize(defaultSize);
511 } else { 512 } else {
512 resize(calcSize(columns, lines)); 513 resize(calcSize(columns, lines));
513 // notifySize(lines,columns); // set menu items (strange arg order !) 514 // notifySize(lines,columns); // set menu items (strange arg order !)
514 } 515 }
515} 516}
516 517
517/* 518/*
518void Konsole::setFont(int fontno) 519void Konsole::setFont(int fontno)
519{ 520{
520 QFont f; 521 QFont f;
521 if (fontno == 0) 522 if (fontno == 0)
522 f = defaultFont = QFont( "Helvetica", 12 ); 523 f = defaultFont = QFont( "Helvetica", 12 );
523 else 524 else
524 if (fonts[fontno][0] == '-') 525 if (fonts[fontno][0] == '-')
525 f.setRawName( fonts[fontno] ); 526 f.setRawName( fonts[fontno] );
526 else 527 else
527 { 528 {
528 f.setFamily(fonts[fontno]); 529 f.setFamily(fonts[fontno]);
529 f.setRawMode( TRUE ); 530 f.setRawMode( TRUE );
530 } 531 }
531 if ( !f.exactMatch() && fontno != 0) 532 if ( !f.exactMatch() && fontno != 0)
532 { 533 {
533 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); 534 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
534 QMessageBox(this, msg); 535 QMessageBox(this, msg);
535 return; 536 return;
536 } 537 }
537 if (se) se->setFontNo(fontno); 538 if (se) se->setFontNo(fontno);
538 te->setVTFont(f); 539 te->setVTFont(f);
539 n_font = fontno; 540 n_font = fontno;
540} 541}
541*/ 542*/
542 543
543// --| color selection |------------------------------------------------------- 544// --| color selection |-------------------------------------------------------
544 545
545void Konsole::changeColumns(int columns) 546void Konsole::changeColumns(int columns)
546{ 547{
547 TEWidget* te = getTe(); 548 TEWidget* te = getTe();
548 if (te != 0) { 549 if (te != 0) {
549 setColLin(columns,te->Lines()); 550 setColLin(columns,te->Lines());
550 te->update(); 551 te->update();
551 } 552 }
552} 553}
553 554
554//FIXME: If a child dies during session swap, 555//FIXME: If a child dies during session swap,
555// this routine might be called before 556// this routine might be called before
556// session swap is completed. 557// session swap is completed.
557 558
558void Konsole::doneSession(TESession*, int ) 559void Konsole::doneSession(TESession*, int )
559{ 560{
560 TEWidget *te = getTe(); 561 TEWidget *te = getTe();
561 if (te != 0) { 562 if (te != 0) {
562 te->currentSession->setConnect(FALSE); 563 te->currentSession->setConnect(FALSE);
563 tab->removeTab(te); 564 tab->removeTab(te);
564 delete te->currentSession; 565 delete te->currentSession;
565 delete te; 566 delete te;
566 nsessions--; 567 nsessions--;
567 } 568 }
568 569
569 if (nsessions == 0) { 570 if (nsessions == 0) {
570 close(); 571 close();
571 } 572 }
572} 573}
573 574
574void Konsole::newSession() { 575void Konsole::newSession() {
575 if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? 576 if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory?
576 TEWidget* te = new TEWidget(tab); 577 TEWidget* te = new TEWidget(tab);
577// te->setBackgroundMode(PaletteBase); //we want transparent!! 578// te->setBackgroundMode(PaletteBase); //we want transparent!!
578 te->setVTFont(fonts.at(cfont)->getFont()); 579 te->setVTFont(fonts.at(cfont)->getFont());
579 tab->addTab(te); 580 tab->addTab(te);
580 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); 581 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm");
581 te->currentSession = se; 582 te->currentSession = se;
582 connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); 583 connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) );
583 se->run(); 584 se->run();
584 se->setConnect(TRUE); 585 se->setConnect(TRUE);
585 se->setHistory(b_scroll); 586 se->setHistory(b_scroll);
586 tab->setCurrentPage(nsessions); 587 tab->setCurrentPage(nsessions);
587 nsessions++; 588 nsessions++;
588 setColor(); 589 setColor();
589 } 590 }
590} 591}
591 592
592TEWidget* Konsole::getTe() { 593TEWidget* Konsole::getTe() {
593 if (nsessions) { 594 if (nsessions) {
594 return (TEWidget *) tab->currentPage(); 595 return (TEWidget *) tab->currentPage();
595 } else { 596 } else {
596 return 0; 597 return 0;
597 } 598 }
598} 599}
599 600
600void Konsole::switchSession(QWidget* w) { 601void Konsole::switchSession(QWidget* w) {
601 TEWidget* te = (TEWidget *) w; 602 TEWidget* te = (TEWidget *) w;
602 603
603 QFont teFnt = te->getVTFont(); 604 QFont teFnt = te->getVTFont();
604 for(uint i = 0; i < fonts.count(); i++) { 605 for(uint i = 0; i < fonts.count(); i++) {
605 VTFont *fnt = fonts.at(i); 606 VTFont *fnt = fonts.at(i);
606 bool cf = fnt->getFont() == teFnt; 607 bool cf = fnt->getFont() == teFnt;
607 fontList->setItemChecked(i, cf); 608 fontList->setItemChecked(i, cf);
608 if (cf) { 609 if (cf) {
609 cfont = i; 610 cfont = i;
610 } 611 }
611 } 612 }
612} 613}
613 614
614/// ------------------------------- some new stuff by L.J. Potter 615/// ------------------------------- some new stuff by L.J. Potter
615void Konsole::colorMenuSelected(int iD) 616void Konsole::colorMenuSelected(int iD)
616{ // this is NOT pretty, elegant or anything else besides functional 617{ // this is NOT pretty, elegant or anything else besides functional
617// QString temp; 618// QString temp;
618// qDebug( temp.sprintf("colormenu %d", iD)); 619// qDebug( temp.sprintf("colormenu %d", iD));
619 TEWidget* te = getTe(); 620 TEWidget* te = getTe();
620 Config cfg("Konsole"); 621 Config cfg("Konsole");
621 cfg.setGroup("Colors"); 622 cfg.setGroup("Colors");
622 QColor foreground; 623 QColor foreground;
623 QColor background; 624 QColor background;
624 colorMenu->setItemChecked(lastSelectedMenu,FALSE); 625 colorMenu->setItemChecked(lastSelectedMenu,FALSE);
625 ColorEntry m_table[TABLE_COLORS]; 626 ColorEntry m_table[TABLE_COLORS];
626 const ColorEntry * defaultCt=te->getdefaultColorTable(); 627 const ColorEntry * defaultCt=te->getdefaultColorTable();
627 /////////// fore back 628 /////////// fore back
628 int i; 629 int i;
629 if(iD==-9) { // default default 630 if(iD==-9) { // default default
630 for (i = 0; i < TABLE_COLORS; i++) { 631 for (i = 0; i < TABLE_COLORS; i++) {
631 m_table[i].color = defaultCt[i].color; 632 m_table[i].color = defaultCt[i].color;
632 if(i==1 || i == 11) 633 if(i==1 || i == 11)
633 m_table[i].transparent=1; 634 m_table[i].transparent=1;
634 cfg.writeEntry("Schema","98"); 635 cfg.writeEntry("Schema","98");
635 colorMenu->setItemChecked(-9,TRUE); 636 colorMenu->setItemChecked(-9,TRUE);
636 } 637 }
637 } else { 638 } else {
638 if(iD==-6) { // green black 639 if(iD==-6) { // green black
639 foreground.setRgb(0x18,255,0x18); 640 foreground.setRgb(0x18,255,0x18);
640 background.setRgb(0x00,0x00,0x00); 641 background.setRgb(0x00,0x00,0x00);
641 cfg.writeEntry("Schema","6"); 642 cfg.writeEntry("Schema","6");
642 colorMenu->setItemChecked(-6,TRUE); 643 colorMenu->setItemChecked(-6,TRUE);
643 } 644 }
644 if(iD==-7) { // black white 645 if(iD==-7) { // black white
645 foreground.setRgb(0x00,0x00,0x00); 646 foreground.setRgb(0x00,0x00,0x00);
646 background.setRgb(0xFF,0xFF,0xFF); 647 background.setRgb(0xFF,0xFF,0xFF);
647 cfg.writeEntry("Schema","7"); 648 cfg.writeEntry("Schema","7");
648 colorMenu->setItemChecked(-7,TRUE); 649 colorMenu->setItemChecked(-7,TRUE);
649 } 650 }
650 if(iD==-8) { // white black 651 if(iD==-8) { // white black
651 foreground.setRgb(0xFF,0xFF,0xFF); 652 foreground.setRgb(0xFF,0xFF,0xFF);
652 background.setRgb(0x00,0x00,0x00); 653 background.setRgb(0x00,0x00,0x00);
653 cfg.writeEntry("Schema","8"); 654 cfg.writeEntry("Schema","8");
654 colorMenu->setItemChecked(-8,TRUE); 655 colorMenu->setItemChecked(-8,TRUE);
655 } 656 }
656 if(iD==-10) {// Black, Red 657 if(iD==-10) {// Black, Red
657 foreground.setRgb(0x00,0x00,0x00); 658 foreground.setRgb(0x00,0x00,0x00);
658 background.setRgb(0xB2,0x18,0x18); 659 background.setRgb(0xB2,0x18,0x18);
659 cfg.writeEntry("Schema","10"); 660 cfg.writeEntry("Schema","10");
660 colorMenu->setItemChecked(-10,TRUE); 661 colorMenu->setItemChecked(-10,TRUE);
661 } 662 }
662 if(iD==-11) {// Red, Black 663 if(iD==-11) {// Red, Black
663 foreground.setRgb(230,31,31); //0xB2,0x18,0x18 664 foreground.setRgb(230,31,31); //0xB2,0x18,0x18
664 background.setRgb(0x00,0x00,0x00); 665 background.setRgb(0x00,0x00,0x00);
665 cfg.writeEntry("Schema","11"); 666 cfg.writeEntry("Schema","11");
666 colorMenu->setItemChecked(-11,TRUE); 667 colorMenu->setItemChecked(-11,TRUE);
667 } 668 }
668 if(iD==-12) {// Green, Yellow - is ugly 669 if(iD==-12) {// Green, Yellow - is ugly
669// foreground.setRgb(0x18,0xB2,0x18); 670// foreground.setRgb(0x18,0xB2,0x18);
670 foreground.setRgb(36,139,10); 671 foreground.setRgb(36,139,10);
671// background.setRgb(0xB2,0x68,0x18); 672// background.setRgb(0xB2,0x68,0x18);
672 background.setRgb(255,255,0); 673 background.setRgb(255,255,0);
673 cfg.writeEntry("Schema","12"); 674 cfg.writeEntry("Schema","12");
674 colorMenu->setItemChecked(-12,TRUE); 675 colorMenu->setItemChecked(-12,TRUE);
675 } 676 }
676 if(iD==-13) {// Blue, Magenta 677 if(iD==-13) {// Blue, Magenta
677 foreground.setRgb(0x18,0xB2,0xB2); 678 foreground.setRgb(0x18,0xB2,0xB2);
678 background.setRgb(0x18,0x18,0xB2); 679 background.setRgb(0x18,0x18,0xB2);
679 cfg.writeEntry("Schema","13"); 680 cfg.writeEntry("Schema","13");
680 colorMenu->setItemChecked(-13,TRUE); 681 colorMenu->setItemChecked(-13,TRUE);
681 } 682 }
682 if(iD==-14) {// Magenta, Blue 683 if(iD==-14) {// Magenta, Blue
683 foreground.setRgb(0x18,0x18,0xB2); 684 foreground.setRgb(0x18,0x18,0xB2);
684 background.setRgb(0x18,0xB2,0xB2); 685 background.setRgb(0x18,0xB2,0xB2);
685 cfg.writeEntry("Schema","14"); 686 cfg.writeEntry("Schema","14");
686 colorMenu->setItemChecked(-14,TRUE); 687 colorMenu->setItemChecked(-14,TRUE);
687 } 688 }
688 if(iD==-15) {// Cyan, White 689 if(iD==-15) {// Cyan, White
689 foreground.setRgb(0x18,0xB2,0xB2); 690 foreground.setRgb(0x18,0xB2,0xB2);
690 background.setRgb(0xFF,0xFF,0xFF); 691 background.setRgb(0xFF,0xFF,0xFF);
691 cfg.writeEntry("Schema","15"); 692 cfg.writeEntry("Schema","15");
692 colorMenu->setItemChecked(-15,TRUE); 693 colorMenu->setItemChecked(-15,TRUE);
693 } 694 }
694 if(iD==-16) {// White, Cyan 695 if(iD==-16) {// White, Cyan
695 background.setRgb(0x18,0xB2,0xB2); 696 background.setRgb(0x18,0xB2,0xB2);
696 foreground.setRgb(0xFF,0xFF,0xFF); 697 foreground.setRgb(0xFF,0xFF,0xFF);
697 cfg.writeEntry("Schema","16"); 698 cfg.writeEntry("Schema","16");
698 colorMenu->setItemChecked(-16,TRUE); 699 colorMenu->setItemChecked(-16,TRUE);
699 } 700 }
700 if(iD==-17) {// Black, Blue 701 if(iD==-17) {// Black, Blue
701 background.setRgb(0x00,0x00,0x00); 702 background.setRgb(0x00,0x00,0x00);
702 foreground.setRgb(0x18,0xB2,0xB2); 703 foreground.setRgb(0x18,0xB2,0xB2);
703 cfg.writeEntry("Schema","17"); 704 cfg.writeEntry("Schema","17");
704 colorMenu->setItemChecked(-17,TRUE); 705 colorMenu->setItemChecked(-17,TRUE);
705 } 706 }
706 if(iD==-18) {// Black, Gold 707 if(iD==-18) {// Black, Gold
707 background.setRgb(0x00,0x00,0x00); 708 background.setRgb(0x00,0x00,0x00);
708 foreground.setRgb(255,215,0); 709 foreground.setRgb(255,215,0);
709 cfg.writeEntry("Schema","18"); 710 cfg.writeEntry("Schema","18");
710 colorMenu->setItemChecked(-18,TRUE); 711 colorMenu->setItemChecked(-18,TRUE);
711 } 712 }
712 713
713 for (i = 0; i < TABLE_COLORS; i++) { 714 for (i = 0; i < TABLE_COLORS; i++) {
714 if(i==0 || i == 10) { 715 if(i==0 || i == 10) {
715 m_table[i].color = foreground; 716 m_table[i].color = foreground;
716 } 717 }
717 else if(i==1 || i == 11) { 718 else if(i==1 || i == 11) {
718 m_table[i].color = background; m_table[i].transparent=0; 719 m_table[i].color = background; m_table[i].transparent=0;
719 } 720 }
720 else 721 else
721 m_table[i].color = defaultCt[i].color; 722 m_table[i].color = defaultCt[i].color;
722 } 723 }
723 } 724 }
724 lastSelectedMenu = iD; 725 lastSelectedMenu = iD;
725 te->setColorTable(m_table); 726 te->setColorTable(m_table);
726 update(); 727 update();
727} 728}
728 729
729void Konsole::configMenuSelected(int iD) 730void Konsole::configMenuSelected(int iD)
730{ 731{
731// QString temp; 732// QString temp;
732// qDebug( temp.sprintf("configmenu %d",iD)); 733// qDebug( temp.sprintf("configmenu %d",iD));
733 TEWidget* te = getTe(); 734 TEWidget* te = getTe();
734 Config cfg("Konsole"); 735 Config cfg("Konsole");
735 cfg.setGroup("Menubar"); 736 cfg.setGroup("Menubar");
736 if( iD == -4) { 737 if( iD == -4) {
737 cfg.setGroup("Tabs"); 738 cfg.setGroup("Tabs");
738 QString tmp=cfg.readEntry("Position","Bottom"); 739 QString tmp=cfg.readEntry("Position","Bottom");
739 740
740 if(tmp=="Top") { 741 if(tmp=="Top") {
741 tab->setTabPosition(QTabWidget::Bottom); 742 tab->setTabPosition(QTabWidget::Bottom);
742 configMenu->changeItem( iD,"Tabs on Top"); 743 configMenu->changeItem( iD,"Tabs on Top");
743 cfg.writeEntry("Position","Bottom"); 744 cfg.writeEntry("Position","Bottom");
744 } else { 745 } else {
745 tab->setTabPosition(QTabWidget::Top); 746 tab->setTabPosition(QTabWidget::Top);
746 configMenu->changeItem( iD,"Tabs on Bottom"); 747 configMenu->changeItem( iD,"Tabs on Bottom");
747 cfg.writeEntry("Position","Top"); 748 cfg.writeEntry("Position","Top");
748 } 749 }
749 } 750 }
750} 751}
751 752
752void Konsole::changeCommand(const QString &text, int c) 753void Konsole::changeCommand(const QString &text, int c)
753{ 754{
754 Config cfg("Konsole"); 755 Config cfg("Konsole");
755 cfg.setGroup("Commands"); 756 cfg.setGroup("Commands");
756 if(commonCmds[c] != text) { 757 if(commonCmds[c] != text) {
757 cfg.writeEntry(QString::number(c),text); 758 cfg.writeEntry(QString::number(c),text);
758 commonCombo->clearEdit(); 759 commonCombo->clearEdit();
759 commonCombo->setCurrentItem(c); 760 commonCombo->setCurrentItem(c);
760 } 761 }
761} 762}
762 763
763void Konsole::setColor() 764void Konsole::setColor()
764{ 765{
765 Config cfg("Konsole"); 766 Config cfg("Konsole");
766 cfg.setGroup("Colors"); 767 cfg.setGroup("Colors");
767 int scheme = cfg.readNumEntry("Schema",1); 768 int scheme = cfg.readNumEntry("Schema",1);
768 if(scheme != 1) colorMenuSelected( -scheme); 769 if(scheme != 1) colorMenuSelected( -scheme);
769} 770}
770 771
771void Konsole::scrollMenuSelected(int index) 772void Konsole::scrollMenuSelected(int index)
772{ 773{
773// QString temp; 774// QString temp;
774// qDebug( temp.sprintf("scrollbar menu %d",index)); 775// qDebug( temp.sprintf("scrollbar menu %d",index));
775 TEWidget* te = getTe(); 776 TEWidget* te = getTe();
776 Config cfg("Konsole"); 777 Config cfg("Konsole");
777 cfg.setGroup("Scrollbar"); 778 cfg.setGroup("Scrollbar");
778 switch( index){ 779 switch( index){
779 case -24: 780 case -24:
780 te->setScrollbarLocation(0); 781 te->setScrollbarLocation(0);
781 cfg.writeEntry("Position",0); 782 cfg.writeEntry("Position",0);
782 break; 783 break;
783 case -25: 784 case -25:
784 te->setScrollbarLocation(1); 785 te->setScrollbarLocation(1);
785 cfg.writeEntry("Position",1); 786 cfg.writeEntry("Position",1);
786 break; 787 break;
787 case -26: 788 case -26:
788 te->setScrollbarLocation(2); 789 te->setScrollbarLocation(2);
789 cfg.writeEntry("Position",2); 790 cfg.writeEntry("Position",2);
790 break; 791 break;
791 }; 792 };
792 793
793} 794}
794 795
795void Konsole::editCommandListMenuSelected(int iD) 796void Konsole::editCommandListMenuSelected(int iD)
796{ 797{
797// QString temp; 798// QString temp;
798// qDebug( temp.sprintf("edit command list %d",iD)); 799// qDebug( temp.sprintf("edit command list %d",iD));
799 TEWidget* te = getTe(); 800 TEWidget* te = getTe();
800 Config cfg("Konsole"); 801 Config cfg("Konsole");
801 cfg.setGroup("Menubar"); 802 cfg.setGroup("Menubar");
802 if( iD == -3) { 803 if( iD == -3) {
803 if(!secondToolBar->isHidden()) { 804 if(!secondToolBar->isHidden()) {
804 secondToolBar->hide(); 805 secondToolBar->hide();
805 configMenu->changeItem( iD,tr( "Show Command List" )); 806 configMenu->changeItem( iD,tr( "Show Command List" ));
806 cfg.writeEntry("Hidden","TRUE"); 807 cfg.writeEntry("Hidden","TRUE");
807 configMenu->setItemEnabled(-22 ,FALSE); 808 configMenu->setItemEnabled(-22 ,FALSE);
808 } else { 809 } else {
809 secondToolBar->show(); 810 secondToolBar->show();
810 configMenu->changeItem( iD,tr( "Hide Command List" )); 811 configMenu->changeItem( iD,tr( "Hide Command List" ));
811 cfg.writeEntry("Hidden","FALSE"); 812 cfg.writeEntry("Hidden","FALSE");
812 configMenu->setItemEnabled(-22 ,TRUE); 813 configMenu->setItemEnabled(-22 ,TRUE);
813 814
814 if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { 815 if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") {
815 configMenu->setItemChecked(-22,TRUE); 816 configMenu->setItemChecked(-22,TRUE);
816 commonCombo->setEditable( TRUE ); 817 commonCombo->setEditable( TRUE );
817 } else { 818 } else {
818 configMenu->setItemChecked(-22,FALSE); 819 configMenu->setItemChecked(-22,FALSE);
819 commonCombo->setEditable( FALSE ); 820 commonCombo->setEditable( FALSE );
820 } 821 }
821 } 822 }
822 } 823 }
823 if( iD == -22) { 824 if( iD == -22) {
824 cfg.setGroup("Commands"); 825 cfg.setGroup("Commands");
825// qDebug("enableCommandEdit"); 826// qDebug("enableCommandEdit");
826 if( !configMenu->isItemChecked(iD) ) { 827 if( !configMenu->isItemChecked(iD) ) {
827 commonCombo->setEditable( TRUE ); 828 commonCombo->setEditable( TRUE );
828 configMenu->setItemChecked(iD,TRUE); 829 configMenu->setItemChecked(iD,TRUE);
829 commonCombo->setCurrentItem(0); 830 commonCombo->setCurrentItem(0);
830 cfg.writeEntry("EditEnabled","TRUE"); 831 cfg.writeEntry("EditEnabled","TRUE");
831 } else { 832 } else {
832 commonCombo->setEditable( FALSE ); 833 commonCombo->setEditable( FALSE );
833 configMenu->setItemChecked(iD,FALSE); 834 configMenu->setItemChecked(iD,FALSE);
834 cfg.writeEntry("EditEnabled","FALSE"); 835 cfg.writeEntry("EditEnabled","FALSE");
835 commonCombo->setFocusPolicy(QWidget::NoFocus); 836 commonCombo->setFocusPolicy(QWidget::NoFocus);
836 te->setFocus(); 837 te->setFocus();
837 } 838 }
838 } 839 }
839 if(iD == -23) { 840 if(iD == -23) {
840 // "edit commands" 841 // "edit commands"
841 CommandEditDialog *m = new CommandEditDialog(this); 842 CommandEditDialog *m = new CommandEditDialog(this);
842 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); 843 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList()));
843 m->showMaximized(); 844 m->showMaximized();
844 } 845 }
845 846
846} 847}
847 848
848// $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' 849// $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V'
849void Konsole::setDocument( const QString &cmd) { 850void Konsole::setDocument( const QString &cmd) {
850 newSession(); 851 newSession();
851 TEWidget* te = getTe(); 852 TEWidget* te = getTe();
852 if(cmd.find("-e", 0, TRUE) != -1) { 853 if(cmd.find("-e", 0, TRUE) != -1) {
853 QString cmd2; 854 QString cmd2;
854 cmd2=cmd.right(cmd.length()-3)+" &"; 855 cmd2=cmd.right(cmd.length()-3)+" &";
855 system(cmd2.latin1()); 856 system(cmd2.latin1());
856 if(startUp <= 1 && nsessions < 2) { 857 if(startUp <= 1 && nsessions < 2) {
857 doneSession(getTe()->currentSession, 0); 858 doneSession(getTe()->currentSession, 0);
858 exit(0); 859 exit(0);
859 } else 860 } else
860 doneSession(getTe()->currentSession, 0); 861 doneSession(getTe()->currentSession, 0);
861 } else { 862 } else {
862 if (te != 0) { 863 if (te != 0) {
863 te->emitText(cmd+"\r"); 864 te->emitText(cmd+"\r");
864 } 865 }
865 } 866 }
866 startUp++; 867 startUp++;
867} 868}
868 869
869void Konsole::parseCommandLine() { 870void Konsole::parseCommandLine() {
870 QString cmd; 871 QString cmd;
871 // newSession(); 872 // newSession();
872 for (int i=1;i< qApp->argc();i++) { 873 for (int i=1;i< qApp->argc();i++) {
873 if( QString(qApp->argv()[i]) == "-e") { 874 if( QString(qApp->argv()[i]) == "-e") {
874 i++; 875 i++;
875 for ( int j=i;j< qApp->argc();j++) { 876 for ( int j=i;j< qApp->argc();j++) {
876 cmd+=QString(qApp->argv()[j])+" "; 877 cmd+=QString(qApp->argv()[j])+" ";
877 } 878 }
878 cmd.stripWhiteSpace(); 879 cmd.stripWhiteSpace();
879 system(cmd.latin1()); 880 system(cmd.latin1());
880 exit(0);//close(); 881 exit(0);//close();
881 } // end -e switch 882 } // end -e switch
882 } 883 }
883 startUp++; 884 startUp++;
884} 885}