summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/MyPty.cpp10
-rw-r--r--core/apps/embeddedkonsole/TEHistory.cpp275
-rw-r--r--core/apps/embeddedkonsole/TEHistory.h50
-rw-r--r--core/apps/embeddedkonsole/TEScreen.cpp18
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp148
-rw-r--r--core/apps/embeddedkonsole/TEWidget.h16
-rw-r--r--core/apps/embeddedkonsole/TEmulation.cpp1
-rw-r--r--core/apps/embeddedkonsole/commandeditdialog.cpp4
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp2214
-rw-r--r--core/apps/embeddedkonsole/konsole.h224
-rw-r--r--core/apps/embeddedkonsole/main.cpp1
-rw-r--r--core/apps/embeddedkonsole/session.cpp20
-rw-r--r--core/apps/embeddedkonsole/session.h5
13 files changed, 1941 insertions, 1045 deletions
diff --git a/core/apps/embeddedkonsole/MyPty.cpp b/core/apps/embeddedkonsole/MyPty.cpp
index 7e820ad..e7d8274 100644
--- a/core/apps/embeddedkonsole/MyPty.cpp
+++ b/core/apps/embeddedkonsole/MyPty.cpp
@@ -1,284 +1,290 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2/* */ 2/* */
3/* [MyPty.C] Pseudo Terminal Device */ 3/* [MyPty.C] Pseudo Terminal Device */
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/* Ported Konsole to Qt/Embedded */ 12/* Ported Konsole to Qt/Embedded */
13/* */ 13/* */
14/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 14/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
15/* */ 15/* */
16/* -------------------------------------------------------------------------- */ 16/* -------------------------------------------------------------------------- */
17 17
18/* If you're compiling konsole on non-Linux platforms and find 18/* If you're compiling konsole on non-Linux platforms and find
19 problems that you can track down to this file, please have 19 problems that you can track down to this file, please have
20 a look into ../README.ports, too. 20 a look into ../README.ports, too.
21*/ 21*/
22 22
23/*! \file 23/*! \file
24*/ 24*/
25 25
26/*! \class TEPty 26/*! \class TEPty
27 27
28 \brief Ptys provide a pseudo terminal connection to a program. 28 \brief Ptys provide a pseudo terminal connection to a program.
29 29
30 Although closely related to pipes, these pseudo terminal connections have 30 Although closely related to pipes, these pseudo terminal connections have
31 some ability, that makes it nessesary to uses them. Most importent, they 31 some ability, that makes it nessesary to uses them. Most importent, they
32 know about changing screen sizes and UNIX job control. 32 know about changing screen sizes and UNIX job control.
33 33
34 Within the terminal emulation framework, this class represents the 34 Within the terminal emulation framework, this class represents the
35 host side of the terminal together with the connecting serial line. 35 host side of the terminal together with the connecting serial line.
36 36
37 One can create many instances of this class within a program. 37 One can create many instances of this class within a program.
38 As a side effect of using this class, a signal(2) handler is 38 As a side effect of using this class, a signal(2) handler is
39 installed on SIGCHLD. 39 installed on SIGCHLD.
40 40
41 \par FIXME 41 \par FIXME
42 42
43 [NOTE: much of the technical stuff below will be replaced by forkpty.] 43 [NOTE: much of the technical stuff below will be replaced by forkpty.]
44 44
45 publish the SIGCHLD signal if not related to an instance. 45 publish the SIGCHLD signal if not related to an instance.
46 46
47 clearify TEPty::done vs. TEPty::~TEPty semantics. 47 clearify TEPty::done vs. TEPty::~TEPty semantics.
48 check if pty is restartable via run after done. 48 check if pty is restartable via run after done.
49 49
50 \par Pseudo terminals 50 \par Pseudo terminals
51 51
52 Pseudo terminals are a unique feature of UNIX, and always come in form of 52 Pseudo terminals are a unique feature of UNIX, and always come in form of
53 pairs of devices (/dev/ptyXX and /dev/ttyXX), which are connected to each 53 pairs of devices (/dev/ptyXX and /dev/ttyXX), which are connected to each
54 other by the operating system. One may think of them as two serial devices 54 other by the operating system. One may think of them as two serial devices
55 linked by a null-modem cable. Being based on devices the number of 55 linked by a null-modem cable. Being based on devices the number of
56 simultanous instances of this class is (globally) limited by the number of 56 simultanous instances of this class is (globally) limited by the number of
57 those device pairs, which is 256. 57 those device pairs, which is 256.
58 58
59 Another technic are UNIX 98 PTY's. These are supported also, and prefered 59 Another technic are UNIX 98 PTY's. These are supported also, and prefered
60 over the (obsolete) predecessor. 60 over the (obsolete) predecessor.
61 61
62 There's a sinister ioctl(2), signal(2) and job control stuff 62 There's a sinister ioctl(2), signal(2) and job control stuff
63 nessesary to make everything work as it should. 63 nessesary to make everything work as it should.
64*/ 64*/
65 65
66 66
67#include <qfileinfo.h> 67#include <qfileinfo.h>
68#include <qapplication.h> 68#include <qapplication.h>
69#include <qsocketnotifier.h> 69#include <qsocketnotifier.h>
70#include <qstring.h> 70#include <qstring.h>
71 71
72#include <stdlib.h> 72#include <stdlib.h>
73#include <stdio.h> 73#include <stdio.h>
74#include <signal.h> 74#include <signal.h>
75#include <fcntl.h> 75#include <fcntl.h>
76#include <unistd.h> 76#include <unistd.h>
77#include <termios.h> 77#include <termios.h>
78#include <sys/types.h> 78#include <sys/types.h>
79#include <sys/ioctl.h> 79#include <sys/ioctl.h>
80#include <sys/wait.h> 80#include <sys/wait.h>
81 81
82#undef HAVE_OPENPTY
82#ifdef HAVE_OPENPTY 83#ifdef HAVE_OPENPTY
83#include <pty.h> 84#include <pty.h>
84#endif 85#endif
85 86
86#include "MyPty.h" 87#include "MyPty.h"
87 88
88 89
89#undef VERBOSE_DEBUG 90#undef VERBOSE_DEBUG
90 91
91 92
92/* -------------------------------------------------------------------------- */ 93/* -------------------------------------------------------------------------- */
93 94
94/*! 95/*!
95 Informs the client program about the 96 Informs the client program about the
96 actual size of the window. 97 actual size of the window.
97*/ 98*/
98 99
99void MyPty::setSize(int lines, int columns) 100void MyPty::setSize(int lines, int columns)
100{ 101{
101 struct winsize wsize; 102 struct winsize wsize;
102 wsize.ws_row = (unsigned short)lines; 103 wsize.ws_row = (unsigned short)lines;
103 wsize.ws_col = (unsigned short)columns; 104 wsize.ws_col = (unsigned short)columns;
104 if(fd < 0) return; 105 if(fd < 0) return;
105 ioctl(fd,TIOCSWINSZ,(char *)&wsize); 106 ioctl(fd,TIOCSWINSZ,(char *)&wsize);
106} 107}
107 108
108 109
109void MyPty::donePty() 110void MyPty::donePty()
110{ 111{
111 // This is code from the Qt DumbTerminal example 112 // This is code from the Qt DumbTerminal example
112 int status = 0; 113 int status = 0;
113 114
114 ::close(fd); 115 ::close(fd);
115 116
116 if (cpid) { 117 if (cpid) {
117 kill(cpid, SIGHUP); 118 kill(cpid, SIGHUP);
118 waitpid(cpid, &status, 0); 119 waitpid(cpid, &status, 0);
119 } 120 }
120 121
121 emit done(status); 122 emit done(status);
122} 123}
123 124
124 125
125const char* MyPty::deviceName() 126const char* MyPty::deviceName()
126{ 127{
127 return ttynam; 128 return ttynam;
128} 129}
129 130
130 131
131void MyPty::error() 132void MyPty::error()
132{ 133{
133 // This is code from the Qt DumbTerminal example 134 // This is code from the Qt DumbTerminal example
134 donePty(); 135 donePty();
135} 136}
136 137
137 138
138/*! 139/*!
139 start the client program. 140 start the client program.
140*/ 141*/
141int MyPty::run(const char* cmd, QStrList &, const char*, int) 142int MyPty::run(const char* cmd, QStrList &, const char*, int)
142{ 143{
143 // This is code from the Qt DumbTerminal example 144 // This is code from the Qt DumbTerminal example
144 cpid = fork(); 145 cpid = fork();
145 146
146 if ( !cpid ) { 147 if ( !cpid ) {
147 // child - exec shell on tty 148 // child - exec shell on tty
148 for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); 149 for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL);
150
151 // attempt to keep apm driver from killing us on power on/off
152 signal(SIGSTOP, SIG_IGN);
153 signal(SIGCONT, SIG_IGN);
154 signal(SIGTSTP, SIG_IGN);
155
149 int ttyfd = open(ttynam, O_RDWR); 156 int ttyfd = open(ttynam, O_RDWR);
150 dup2(ttyfd, STDIN_FILENO); 157 dup2(ttyfd, STDIN_FILENO);
151 dup2(ttyfd, STDOUT_FILENO); 158 dup2(ttyfd, STDOUT_FILENO);
152 dup2(ttyfd, STDERR_FILENO); 159 dup2(ttyfd, STDERR_FILENO);
153 // should be done with tty, so close it 160 // should be done with tty, so close it
154 close(ttyfd); 161 close(ttyfd);
155 static struct termios ttmode; 162 static struct termios ttmode;
156 if ( setsid() < 0 ) 163 if ( setsid() < 0 )
157 perror( "failed to set process group" ); 164 perror( "failed to set process group" );
158#if defined (TIOCSCTTY) 165#if defined (TIOCSCTTY)
159 // grabbed from APUE by Stevens 166 // grabbed from APUE by Stevens
160 ioctl(STDIN_FILENO, TIOCSCTTY, 0); 167 ioctl(STDIN_FILENO, TIOCSCTTY, 0);
161#endif 168#endif
162 tcgetattr( STDIN_FILENO, &ttmode ); 169 tcgetattr( STDIN_FILENO, &ttmode );
163 ttmode.c_cc[VINTR] = 3; 170 ttmode.c_cc[VINTR] = 3;
164 ttmode.c_cc[VERASE] = 8; 171 ttmode.c_cc[VERASE] = 8;
165 tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); 172 tcsetattr( STDIN_FILENO, TCSANOW, &ttmode );
166 if(strlen(getenv("TERM"))<=0) 173 setenv("TERM","vt100",1);
167 setenv("TERM","vt100",1);
168 setenv("COLORTERM","0",1); 174 setenv("COLORTERM","0",1);
169 175
170 if (getuid() == 0) { 176 if (getuid() == 0) {
171 char msg[] = "WARNING: You are running this shell as root!\n"; 177 char msg[] = "WARNING: You are running this shell as root!\n";
172 write(ttyfd, msg, sizeof(msg)); 178 write(ttyfd, msg, sizeof(msg));
173 } 179 }
174 180
175 QString ccmd = "-"+QFileInfo(cmd).fileName(); //creates a login shell 181 QString ccmd = "-"+QFileInfo(cmd).fileName(); //creates a login shell
176 182
177 execl(cmd, ccmd.latin1(), 0); 183 execl(cmd, ccmd.latin1(), 0);
178 184
179 donePty(); 185 donePty();
180 exit(-1); 186 exit(-1);
181 } 187 }
182 188
183 // parent - continue as a widget 189 // parent - continue as a widget
184 QSocketNotifier* sn_r = new QSocketNotifier(fd,QSocketNotifier::Read,this); 190 QSocketNotifier* sn_r = new QSocketNotifier(fd,QSocketNotifier::Read,this);
185 QSocketNotifier* sn_e = new QSocketNotifier(fd,QSocketNotifier::Exception,this); 191 QSocketNotifier* sn_e = new QSocketNotifier(fd,QSocketNotifier::Exception,this);
186 connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); 192 connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
187 connect(sn_e,SIGNAL(activated(int)),this,SLOT(error())); 193 connect(sn_e,SIGNAL(activated(int)),this,SLOT(error()));
188 194
189 return 0; 195 return 0;
190} 196}
191 197
192int MyPty::openPty() 198int MyPty::openPty()
193{ 199{
194 // This is code from the Qt DumbTerminal example 200 // This is code from the Qt DumbTerminal example
195 int ptyfd = -1; 201 int ptyfd = -1;
196 202
197#ifdef HAVE_OPENPTY 203#ifdef HAVE_OPENPTY
198 int ttyfd; 204 int ttyfd;
199 if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) 205 if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) )
200 ptyfd = -1; 206 ptyfd = -1;
201 else 207 else
202 close(ttyfd); // we open the ttynam ourselves. 208 close(ttyfd); // we open the ttynam ourselves.
203#else 209#else
204 for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) { 210 for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) {
205 for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) { 211 for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) {
206 sprintf(ptynam,"/dev/pty%c%c",*c0,*c1); 212 sprintf(ptynam,"/dev/pty%c%c",*c0,*c1);
207 sprintf(ttynam,"/dev/tty%c%c",*c0,*c1); 213 sprintf(ttynam,"/dev/tty%c%c",*c0,*c1);
208 if ((ptyfd = ::open(ptynam,O_RDWR)) >= 0) { 214 if ((ptyfd = ::open(ptynam,O_RDWR)) >= 0) {
209 if (geteuid() != 0 && !access(ttynam,R_OK|W_OK) == 0) { 215 if (geteuid() != 0 && !access(ttynam,R_OK|W_OK) == 0) {
210 ::close(ptyfd); 216 ::close(ptyfd);
211 ptyfd = -1; 217 ptyfd = -1;
212 } 218 }
213 } 219 }
214 } 220 }
215 } 221 }
216#endif 222#endif
217 223
218 if ( ptyfd < 0 ) { 224 if ( ptyfd < 0 ) {
219 qApp->exit(1); 225 qApp->exit(1);
220 return -1; 226 return -1;
221 } 227 }
222 228
223 return ptyfd; 229 return ptyfd;
224} 230}
225 231
226/*! 232/*!
227 Create an instance. 233 Create an instance.
228*/ 234*/
229MyPty::MyPty() : cpid(0) 235MyPty::MyPty() : cpid(0)
230{ 236{
231 fd = openPty(); 237 fd = openPty();
232} 238}
233 239
234/*! 240/*!
235 Destructor. 241 Destructor.
236 Note that the related client program is not killed 242 Note that the related client program is not killed
237 (yet) when a instance is deleted. 243 (yet) when a instance is deleted.
238*/ 244*/
239MyPty::~MyPty() 245MyPty::~MyPty()
240{ 246{
241 donePty(); 247 donePty();
242} 248}
243 249
244 250
245/*! sends len bytes through the line */ 251/*! sends len bytes through the line */
246void MyPty::send_bytes(const char* s, int len) 252void MyPty::send_bytes(const char* s, int len)
247{ 253{
248 254
249#ifdef VERBOSE_DEBUG 255#ifdef VERBOSE_DEBUG
250 // verbose debug 256 // verbose debug
251 printf("sending bytes:\n"); 257 printf("sending bytes:\n");
252 for (int i = 0; i < len; i++) 258 for (int i = 0; i < len; i++)
253 printf("%c", s[i]); 259 printf("%c", s[i]);
254 printf("\n"); 260 printf("\n");
255#endif 261#endif
256 262
257 ::write(fd, s, len); 263 ::write(fd, s, len);
258} 264}
259 265
260/*! indicates that a block of data is received */ 266/*! indicates that a block of data is received */
261void MyPty::readPty() 267void MyPty::readPty()
262{ 268{
263 char buf[4096]; 269 char buf[4096];
264 270
265 int len = ::read( fd, buf, 4096 ); 271 int len = ::read( fd, buf, 4096 );
266 272
267 if (len == -1) 273 if (len == -1)
268 donePty(); 274 donePty();
269 275
270 if (len < 0) 276 if (len < 0)
271 return; 277 return;
272 278
273 emit block_in(buf,len); 279 emit block_in(buf,len);
274 280
275#ifdef VERBOSE_DEBUG 281#ifdef VERBOSE_DEBUG
276 // verbose debug 282 // verbose debug
277 printf("read bytes:\n"); 283 printf("read bytes:\n");
278 for (int i = 0; i < len; i++) 284 for (int i = 0; i < len; i++)
279 printf("%c", buf[i]); 285 printf("%c", buf[i]);
280 printf("\n"); 286 printf("\n");
281#endif 287#endif
282 288
283} 289}
284 290
diff --git a/core/apps/embeddedkonsole/TEHistory.cpp b/core/apps/embeddedkonsole/TEHistory.cpp
index db9d10c..504cd13 100644
--- a/core/apps/embeddedkonsole/TEHistory.cpp
+++ b/core/apps/embeddedkonsole/TEHistory.cpp
@@ -1,219 +1,230 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2/* */ 2/* */
3/* [TEHistory.C] History Buffer */ 3/* [TEHistory.C] History Buffer */
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 Qkonsole - an X terminal for KDE */
10/* */ 10/* */
11/* -------------------------------------------------------------------------- */ 11/* -------------------------------------------------------------------------- */
12/* */ 12/* */
13/* Ported Konsole to Qt/Embedded */ 13/* Ported Qkonsole 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 18
19#include "TEHistory.h" 19#include "TEHistory.h"
20#include <stdlib.h> 20#include <stdlib.h>
21#include <assert.h> 21#include <assert.h>
22#include <stdio.h> 22#include <stdio.h>
23#include <sys/types.h> 23#include <sys/types.h>
24#include <unistd.h> 24#include <unistd.h>
25#include <errno.h> 25#include <errno.h>
26 26
27#include <qpe/config.h>
28
27#define HERE printf("%s(%d): here\n",__FILE__,__LINE__) 29#define HERE printf("%s(%d): here\n",__FILE__,__LINE__)
28 30
29/* 31/*
30 An arbitrary long scroll. 32 An arbitrary long scroll.
31 33
32 One can modify the scroll only by adding either cells 34 One can modify the scroll only by adding either cells
33 or newlines, but access it randomly. 35 or newlines, but access it randomly.
34 36
35 The model is that of an arbitrary wide typewriter scroll 37 The model is that of an arbitrary wide typewriter scroll
36 in that the scroll is a serie of lines and each line is 38 in that the scroll is a serie of lines and each line is
37 a serie of cells with no overwriting permitted. 39 a serie of cells with no overwriting permitted.
38 40
39 The implementation provides arbitrary length and numbers 41 The implementation provides arbitrary length and numbers
40 of cells and line/column indexed read access to the scroll 42 of cells and line/column indexed read access to the scroll
41 at constant costs. 43 at constant costs.
42 44
43FIXME: some complain about the history buffer comsuming the
44 memory of their machines. This problem is critical
45 since the history does not behave gracefully in cases
46 where the memory is used up completely.
47
48 I put in a workaround that should handle it problem
49 now gracefully. I'm not satisfied with the solution.
50
51FIXME: Terminating the history is not properly indicated
52 in the menu. We should throw a signal.
53
54FIXME: There is noticable decrease in speed, also. Perhaps,
55 there whole feature needs to be revisited therefore.
56 Disadvantage of a more elaborated, say block-oriented
57 scheme with wrap around would be it's complexity.
58*/ 45*/
59 46
60//FIXME: tempory replacement for tmpfile
61// this is here one for debugging purpose.
62
63//#define tmpfile xTmpFile
64
65FILE* xTmpFile()
66{
67 static int fid = 0;
68 char fname[80];
69 sprintf(fname,"TmpFile.%d",fid++);
70 return fopen(fname,"w");
71}
72
73 47
74// History Buffer /////////////////////////////////////////// 48HistoryScroll::HistoryScroll()
75
76/*
77 A Row(X) data type which allows adding elements to the end.
78*/
79
80HistoryBuffer::HistoryBuffer()
81{ 49{
82 ion = -1; 50 m_lines = NULL;
83 length = 0; 51 m_max_lines = 0;
52 m_cells = NULL;
53 m_max_cells = 0;
54 m_num_lines = 0;
55 m_first_line = 0;
56 m_last_cell = 0;
57 m_start_line = 0;
84} 58}
85 59
86HistoryBuffer::~HistoryBuffer() 60HistoryScroll::~HistoryScroll()
87{ 61{
88 setScroll(FALSE); 62 setSize(0,0);
89} 63}
90 64
91void HistoryBuffer::setScroll(bool on) 65void HistoryScroll::setSize(int lines, int cells)
92{ 66{
93 if (on == hasScroll()) return; 67 // could try to preserve the existing data...
94 68 // printf("setSize(%d,%d)\n", lines, cells);
95 if (on) 69 if (m_lines) {
96 { 70 delete m_lines;
97 assert( ion < 0 ); 71 m_lines = NULL;
98 assert( length == 0);
99 FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); return; }
100 ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp file.\n");
101 fclose(tmp);
102 } 72 }
103 else 73 if (m_cells) {
104 { 74 delete m_cells;
105 assert( ion >= 0 ); 75 m_cells = NULL;
106 close(ion);
107 ion = -1;
108 length = 0;
109 } 76 }
77 m_max_lines = m_max_cells = 0;
78 if (lines > 0 && cells > 0) {
79 m_max_lines = lines;
80 m_lines = new int[m_max_lines];
81 m_lines[0] = 0;
82 m_max_cells = cells;
83 m_cells = new ca[m_max_cells];
84 }
85 m_first_line = 0;
86 m_num_lines = 0;
87 m_last_cell = 0;
88 m_start_line = 0;
110} 89}
111 90
112bool HistoryBuffer::hasScroll()
113{
114 return ion >= 0;
115}
116
117void HistoryBuffer::add(const unsigned char* bytes, int len)
118{ int rc;
119 assert(hasScroll());
120 rc = lseek( ion, length, SEEK_SET);
121 if (rc < 0) { perror("HistoryBuffer::add.seek"); setScroll(FALSE); return; }
122 rc = write( ion, bytes, len);
123 if (rc < 0) { perror("HistoryBuffer::add.write"); setScroll(FALSE); return; }
124 length += rc;
125}
126
127void HistoryBuffer::get(unsigned char* bytes, int len, int loc) {
128 int rc;
129 assert(hasScroll());
130// qDebug("history get len %d, loc %d, length %d", len, loc, length);
131 if (loc < 0 || len < 0 || loc + len > length)
132 fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc);
133
134 rc = lseek( ion, loc, SEEK_SET);
135 if (rc < 0) { perror("HistoryBuffer::get.seek"); setScroll(FALSE); return; }
136 rc = read( ion, bytes, len);
137 if (rc < 0) { perror("HistoryBuffer::get.read"); setScroll(FALSE); return; }
138}
139
140int HistoryBuffer::len()
141{
142 return length;
143}
144
145// History Scroll //////////////////////////////////////
146
147/*
148 The history scroll makes a Row(Row(Cell)) from
149 two history buffers. The index buffer contains
150 start of line positions which refere to the cells
151 buffer.
152
153 Note that index[0] addresses the second line
154 (line #1), while the first line (line #0) starts
155 at 0 in cells.
156*/
157
158HistoryScroll::HistoryScroll()
159{
160}
161
162HistoryScroll::~HistoryScroll()
163{
164}
165
166void HistoryScroll::setScroll(bool on) 91void HistoryScroll::setScroll(bool on)
167{ 92{
168 index.setScroll(on); 93 Config cfg("Qkonsole");
169 cells.setScroll(on); 94 cfg.setGroup("History");
95 // printf("setScroll(%d)\n", on);
96 if (on) {
97 int lines = cfg.readNumEntry("history_lines",300);
98 int avg_line = cfg.readNumEntry("avg_line_length",60);
99 int cells = lines * avg_line;
100 setSize(lines,cells);
101 } else {
102 setSize(0,0);
103 }
170} 104}
171 105
172bool HistoryScroll::hasScroll() 106bool HistoryScroll::hasScroll()
173{ 107{
174 return index.hasScroll() && cells.hasScroll(); 108 return (m_max_lines > 0);
175} 109}
176 110
177int HistoryScroll::getLines() 111int HistoryScroll::getLines()
178{ 112{
179 if (!hasScroll()) return 0; 113 return(m_num_lines);
180 return index.len() / sizeof(int);
181} 114}
182 115
183int HistoryScroll::getLineLen(int lineno) 116int HistoryScroll::getLineLen(int lineno)
184{ 117{
185 if (!hasScroll()) return 0; 118 if (!hasScroll()) return 0;
186 return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(ca); 119 if (lineno >= m_num_lines) {
120 // printf("getLineLen(%d) out of range %d\n", lineno, m_num_lines);
121 return(0);
122 }
123 int len = startOfLine(lineno+1) - startOfLine(lineno);
124 if (len < 0) {
125 len += m_max_cells;
126 }
127 // printf("getLineLen(%d) = %d\n", lineno, len);
128 return(len);
187} 129}
188 130
189int HistoryScroll::startOfLine(int lineno) 131int HistoryScroll::startOfLine(int lineno)
190{ 132{
191 if (lineno <= 0) return 0; 133 // printf("startOfLine(%d) =", lineno);
192 if (!hasScroll()) return 0; 134 if (!hasScroll()) return 0;
193 if (lineno <= getLines()) 135 assert(lineno >= 0 && lineno <= m_num_lines);
194 { int res; 136 if (lineno < m_num_lines) {
195 index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int)); 137 int index = lineno + m_first_line;
196 return res; 138 if (index >= m_max_lines)
139 index -= m_max_lines;
140 // printf("%d\n", m_lines[index]);
141 return(m_lines[index]);
142 } else {
143 // printf("last %d\n", m_last_cell);
144 return(m_last_cell);
197 } 145 }
198 return cells.len();
199} 146}
200 147
201void HistoryScroll::getCells(int lineno, int colno, int count, ca res[]) 148void HistoryScroll::getCells(int lineno, int colno, int count, ca *res)
202{ 149{
150 // printf("getCells(%d,%d,%d) num_lines=%d\n", lineno, colno, count, m_num_lines);
203 assert(hasScroll()); 151 assert(hasScroll());
204//get(unsigned char* bytes, int len, int loc) 152 assert(lineno >= 0 && lineno < m_num_lines);
205 cells.get( (unsigned char*)res, count * sizeof(ca), startOfLine( lineno) + colno * sizeof(ca) ); 153 int index = lineno + m_first_line;
154 if (index >= m_max_lines)
155 index -= m_max_lines;
156 assert(index >= 0 && index < m_max_lines);
157 index = m_lines[index] + colno;
158 assert(index >= 0 && index < m_max_cells);
159 while(count-- > 0) {
160 *res++ = m_cells[index];
161 if (++index >= m_max_cells) {
162 index = 0;
163 }
164 }
206} 165}
207 166
208void HistoryScroll::addCells(ca text[], int count) 167void HistoryScroll::addCells(ca *text, int count)
209{ 168{
210 if (!hasScroll()) return; 169 if (!hasScroll()) return;
211 cells.add((unsigned char*)text,count*sizeof(ca)); 170 int start_cell = m_last_cell;
171 // printf("addCells count=%d start=%d first_line=%d first_cell=%d lines=%d\n",
172 // count, start_cell, m_first_line, m_lines[m_first_line], m_num_lines);
173 if (count <= 0) {
174 return;
175 }
176 while(count-- > 0) {
177 assert (m_last_cell >= 0 && m_last_cell < m_max_cells );
178 m_cells[m_last_cell] = *text++;
179 if (++m_last_cell >= m_max_cells) {
180 m_last_cell = 0;
181 }
182 }
183 if (m_num_lines > 1) {
184 if (m_last_cell > start_cell) {
185 while(m_num_lines > 0
186 && m_lines[m_first_line] >= start_cell
187 && m_lines[m_first_line] < m_last_cell) {
188 // printf("A remove %d>%d && %d<%d first_line=%d num_lines=%d\n",
189 // m_lines[m_first_line], start_cell, m_lines[m_first_line], m_last_cell,
190 // m_first_line, m_num_lines);
191 if (++m_first_line >= m_max_lines) {
192 m_first_line = 0;
193 }
194 m_num_lines--;
195 }
196 } else {
197 while(m_num_lines > 0
198 && (m_lines[m_first_line] >= start_cell
199 || m_lines[m_first_line] < m_last_cell)) {
200 // printf("B remove %d>%d || %d<%d first_line=%d num_lines=%d\n",
201 // m_lines[m_first_line], start_cell, m_lines[m_first_line], m_last_cell,
202 // m_first_line, m_num_lines);
203 if (++m_first_line >= m_max_lines) {
204 m_first_line = 0;
205 }
206 m_num_lines--;
207 }
208 }
209 }
212} 210}
213 211
214void HistoryScroll::addLine() 212void HistoryScroll::addLine()
215{ 213{
216 if (!hasScroll()) return; 214 if (!hasScroll()) return;
217 int locn = cells.len(); 215 int index = m_first_line + m_num_lines;
218 index.add((unsigned char*)&locn,sizeof(int)); 216 if (index >= m_max_lines) {
217 index -= m_max_lines;
218 }
219 // printf("addLine line=%d cell=%d\n", index, m_last_cell);
220 assert(index >= 0 && index < m_max_lines);
221 m_lines[index] = m_start_line;
222 m_start_line = m_last_cell;
223 if (m_num_lines >= m_max_lines) {
224 if (++m_first_line >= m_num_lines) {
225 m_first_line = 0;
226 }
227 } else {
228 m_num_lines++;
229 }
219} 230}
diff --git a/core/apps/embeddedkonsole/TEHistory.h b/core/apps/embeddedkonsole/TEHistory.h
index 11eb150..fcf6496 100644
--- a/core/apps/embeddedkonsole/TEHistory.h
+++ b/core/apps/embeddedkonsole/TEHistory.h
@@ -1,75 +1,57 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2/* */ 2/* */
3/* [TEHistory.H] History Buffer */ 3/* [TEHistory.H] History Buffer */
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 18
19#ifndef TEHISTORY_H 19#ifndef TEHISTORY_H
20#define TEHISTORY_H 20#define TEHISTORY_H
21 21
22#include "TECommon.h" 22#include "TECommon.h"
23 23
24/*
25 An extendable tmpfile(1) based buffer.
26*/
27class HistoryBuffer
28{
29public:
30 HistoryBuffer();
31 ~HistoryBuffer();
32
33public:
34 void setScroll(bool on);
35 bool hasScroll();
36
37public:
38 void add(const unsigned char* bytes, int len);
39 void get(unsigned char* bytes, int len, int loc);
40 int len();
41
42private:
43 int ion;
44 int length;
45};
46
47class HistoryScroll 24class HistoryScroll
48{ 25{
49public: 26public:
50 HistoryScroll(); 27 HistoryScroll();
51 ~HistoryScroll(); 28 ~HistoryScroll();
52 29
53public: 30public:
54 void setScroll(bool on); 31 void setSize(int lines, int cells);
55 bool hasScroll(); 32 void setScroll(bool on);
33 bool hasScroll();
56 34
57public: // access to history 35 int getLines();
58 int getLines(); 36 int getLineLen(int lineno);
59 int getLineLen(int lineno); 37 void getCells(int lineno, int colno, int count, ca *res);
60 void getCells(int lineno, int colno, int count, ca res[]);
61 38
62public: // backward compatibility (obsolete)
63 ca getCell(int lineno, int colno) { ca res; getCells(lineno,colno,1,&res); return res; } 39 ca getCell(int lineno, int colno) { ca res; getCells(lineno,colno,1,&res); return res; }
64 40
65public: // adding lines. 41 void addCells(ca *text, int count);
66 void addCells(ca a[], int count);
67 void addLine(); 42 void addLine();
68 43
69private: 44private:
70 int startOfLine(int lineno); 45 int startOfLine(int lineno);
71 HistoryBuffer index; // lines Row(int) 46
72 HistoryBuffer cells; // text Row(ca) 47 int m_max_lines;
48 int *m_lines;
49 int m_max_cells;
50 ca *m_cells;
51 int m_first_line;
52 int m_last_cell;
53 int m_num_lines;
54 int m_start_line;
73}; 55};
74 56
75#endif // TEHISTORY_H 57#endif // TEHISTORY_H
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp
index a6cf6a1..4ebc28e 100644
--- a/core/apps/embeddedkonsole/TEScreen.cpp
+++ b/core/apps/embeddedkonsole/TEScreen.cpp
@@ -129,1092 +129,1108 @@ void TEScreen::cursorUp(int n)
129 The cursor will not be moved beyond the bottom margin. 129 The cursor will not be moved beyond the bottom margin.
130*/ 130*/
131 131
132void TEScreen::cursorDown(int n) 132void TEScreen::cursorDown(int n)
133//=CUD 133//=CUD
134{ 134{
135 if (n == 0) n = 1; // Default 135 if (n == 0) n = 1; // Default
136 int stop = cuY > bmargin ? lines-1 : bmargin; 136 int stop = cuY > bmargin ? lines-1 : bmargin;
137 cuX = QMIN(columns-1,cuX); // nowrap! 137 cuX = QMIN(columns-1,cuX); // nowrap!
138 cuY = QMIN(stop,cuY+n); 138 cuY = QMIN(stop,cuY+n);
139} 139}
140 140
141/*! 141/*!
142 Move the cursor left. 142 Move the cursor left.
143 143
144 The cursor will not move beyond the first column. 144 The cursor will not move beyond the first column.
145*/ 145*/
146 146
147void TEScreen::cursorLeft(int n) 147void TEScreen::cursorLeft(int n)
148//=CUB 148//=CUB
149{ 149{
150 if (n == 0) n = 1; // Default 150 if (n == 0) n = 1; // Default
151 cuX = QMIN(columns-1,cuX); // nowrap! 151 cuX = QMIN(columns-1,cuX); // nowrap!
152 cuX = QMAX(0,cuX-n); 152 cuX = QMAX(0,cuX-n);
153} 153}
154 154
155/*! 155/*!
156 Move the cursor left. 156 Move the cursor left.
157 157
158 The cursor will not move beyond the rightmost column. 158 The cursor will not move beyond the rightmost column.
159*/ 159*/
160 160
161void TEScreen::cursorRight(int n) 161void TEScreen::cursorRight(int n)
162//=CUF 162//=CUF
163{ 163{
164 if (n == 0) n = 1; // Default 164 if (n == 0) n = 1; // Default
165 cuX = QMIN(columns-1,cuX+n); 165 cuX = QMIN(columns-1,cuX+n);
166} 166}
167 167
168/*! 168/*!
169 Set top and bottom margin. 169 Set top and bottom margin.
170*/ 170*/
171 171
172void TEScreen::setMargins(int top, int bot) 172void TEScreen::setMargins(int top, int bot)
173//=STBM 173//=STBM
174{ 174{
175 if (top == 0) top = 1; // Default 175 if (top == 0) top = 1; // Default
176 if (bot == 0) bot = lines; // Default 176 if (bot == 0) bot = lines; // Default
177 top = top - 1; // Adjust to internal lineno 177 top = top - 1; // Adjust to internal lineno
178 bot = bot - 1; // Adjust to internal lineno 178 bot = bot - 1; // Adjust to internal lineno
179 if ( !( 0 <= top && top < bot && bot < lines ) ) 179 if ( !( 0 <= top && top < bot && bot < lines ) )
180 { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n", 180 { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n",
181 __FILE__,__LINE__,top,bot); 181 __FILE__,__LINE__,top,bot);
182 return; // Default error action: ignore 182 return; // Default error action: ignore
183 } 183 }
184 tmargin = top; 184 tmargin = top;
185 bmargin = bot; 185 bmargin = bot;
186 cuX = 0; 186 cuX = 0;
187 cuY = getMode(MODE_Origin) ? top : 0; 187 cuY = getMode(MODE_Origin) ? top : 0;
188} 188}
189 189
190/*! 190/*!
191 Move the cursor down one line. 191 Move the cursor down one line.
192 192
193 If cursor is on bottom margin, the region between the 193 If cursor is on bottom margin, the region between the
194 actual top and bottom margin is scrolled up instead. 194 actual top and bottom margin is scrolled up instead.
195*/ 195*/
196 196
197void TEScreen::index() 197void TEScreen::index()
198//=IND 198//=IND
199{ 199{
200 if (cuY == bmargin) 200 if (cuY == bmargin)
201 { 201 {
202 if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history 202 if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history
203 scrollUp(tmargin,1); 203 scrollUp(tmargin,1);
204 } 204 }
205 else if (cuY < lines-1) 205 else if (cuY < lines-1)
206 cuY += 1; 206 cuY += 1;
207} 207}
208 208
209/*! 209/*!
210 Move the cursor up one line. 210 Move the cursor up one line.
211 211
212 If cursor is on the top margin, the region between the 212 If cursor is on the top margin, the region between the
213 actual top and bottom margin is scrolled down instead. 213 actual top and bottom margin is scrolled down instead.
214*/ 214*/
215 215
216void TEScreen::reverseIndex() 216void TEScreen::reverseIndex()
217//=RI 217//=RI
218{ 218{
219 if (cuY == tmargin) 219 if (cuY == tmargin)
220 scrollDown(tmargin,1); 220 scrollDown(tmargin,1);
221 else if (cuY > 0) 221 else if (cuY > 0)
222 cuY -= 1; 222 cuY -= 1;
223} 223}
224 224
225/*! 225/*!
226 Move the cursor to the begin of the next line. 226 Move the cursor to the begin of the next line.
227 227
228 If cursor is on bottom margin, the region between the 228 If cursor is on bottom margin, the region between the
229 actual top and bottom margin is scrolled up. 229 actual top and bottom margin is scrolled up.
230*/ 230*/
231 231
232void TEScreen::NextLine() 232void TEScreen::NextLine()
233//=NEL 233//=NEL
234{ 234{
235 Return(); index(); 235 Return(); index();
236} 236}
237 237
238// Line Editing ---------------------------------------------------------------- 238// Line Editing ----------------------------------------------------------------
239 239
240/*! \section inserting / deleting characters 240/*! \section inserting / deleting characters
241*/ 241*/
242 242
243/*! erase `n' characters starting from (including) the cursor position. 243/*! erase `n' characters starting from (including) the cursor position.
244 244
245 The line is filled in from the right with spaces. 245 The line is filled in from the right with spaces.
246*/ 246*/
247 247
248void TEScreen::eraseChars(int n) 248void TEScreen::eraseChars(int n)
249{ 249{
250 if (n == 0) n = 1; // Default 250 if (n == 0) n = 1; // Default
251 int p = QMAX(0,QMIN(cuX+n-1,columns-1)); 251 int p = QMAX(0,QMIN(cuX+n-1,columns-1));
252 clearImage(loc(cuX,cuY),loc(p,cuY),' '); 252 clearImage(loc(cuX,cuY),loc(p,cuY),' ');
253} 253}
254 254
255/*! delete `n' characters starting from (including) the cursor position. 255/*! delete `n' characters starting from (including) the cursor position.
256 256
257 The line is filled in from the right with spaces. 257 The line is filled in from the right with spaces.
258*/ 258*/
259 259
260void TEScreen::deleteChars(int n) 260void TEScreen::deleteChars(int n)
261{ 261{
262 if (n == 0) n = 1; // Default 262 if (n == 0) n = 1; // Default
263 int p = QMAX(0,QMIN(cuX+n,columns-1)); 263 int p = QMAX(0,QMIN(cuX+n,columns-1));
264 moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY)); 264 moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY));
265 clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' '); 265 clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' ');
266} 266}
267 267
268/*! insert `n' spaces at the cursor position. 268/*! insert `n' spaces at the cursor position.
269 269
270 The cursor is not moved by the operation. 270 The cursor is not moved by the operation.
271*/ 271*/
272 272
273void TEScreen::insertChars(int n) 273void TEScreen::insertChars(int n)
274{ 274{
275 if (n == 0) n = 1; // Default 275 if (n == 0) n = 1; // Default
276 int p = QMAX(0,QMIN(columns-1-n,columns-1)); 276 int p = QMAX(0,QMIN(columns-1-n,columns-1));
277 int q = QMAX(0,QMIN(cuX+n,columns-1)); 277 int q = QMAX(0,QMIN(cuX+n,columns-1));
278 moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY)); 278 moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY));
279 clearImage(loc(cuX,cuY),loc(q-1,cuY),' '); 279 clearImage(loc(cuX,cuY),loc(q-1,cuY),' ');
280} 280}
281 281
282/*! delete `n' lines starting from (including) the cursor position. 282/*! delete `n' lines starting from (including) the cursor position.
283 283
284 The cursor is not moved by the operation. 284 The cursor is not moved by the operation.
285*/ 285*/
286 286
287void TEScreen::deleteLines(int n) 287void TEScreen::deleteLines(int n)
288{ 288{
289 if (n == 0) n = 1; // Default 289 if (n == 0) n = 1; // Default
290 scrollUp(cuY,n); 290 scrollUp(cuY,n);
291} 291}
292 292
293/*! insert `n' lines at the cursor position. 293/*! insert `n' lines at the cursor position.
294 294
295 The cursor is not moved by the operation. 295 The cursor is not moved by the operation.
296*/ 296*/
297 297
298void TEScreen::insertLines(int n) 298void TEScreen::insertLines(int n)
299{ 299{
300 if (n == 0) n = 1; // Default 300 if (n == 0) n = 1; // Default
301 scrollDown(cuY,n); 301 scrollDown(cuY,n);
302} 302}
303 303
304// Mode Operations ----------------------------------------------------------- 304// Mode Operations -----------------------------------------------------------
305 305
306/*! Set a specific mode. */ 306/*! Set a specific mode. */
307 307
308void TEScreen::setMode(int m) 308void TEScreen::setMode(int m)
309{ 309{
310 currParm.mode[m] = TRUE; 310 currParm.mode[m] = TRUE;
311 switch(m) 311 switch(m)
312 { 312 {
313 case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home 313 case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home
314 } 314 }
315} 315}
316 316
317/*! Reset a specific mode. */ 317/*! Reset a specific mode. */
318 318
319void TEScreen::resetMode(int m) 319void TEScreen::resetMode(int m)
320{ 320{
321 currParm.mode[m] = FALSE; 321 currParm.mode[m] = FALSE;
322 switch(m) 322 switch(m)
323 { 323 {
324 case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home 324 case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home
325 } 325 }
326} 326}
327 327
328/*! Save a specific mode. */ 328/*! Save a specific mode. */
329 329
330void TEScreen::saveMode(int m) 330void TEScreen::saveMode(int m)
331{ 331{
332 saveParm.mode[m] = currParm.mode[m]; 332 saveParm.mode[m] = currParm.mode[m];
333} 333}
334 334
335/*! Restore a specific mode. */ 335/*! Restore a specific mode. */
336 336
337void TEScreen::restoreMode(int m) 337void TEScreen::restoreMode(int m)
338{ 338{
339 currParm.mode[m] = saveParm.mode[m]; 339 currParm.mode[m] = saveParm.mode[m];
340} 340}
341 341
342//NOTE: this is a helper function 342//NOTE: this is a helper function
343/*! Return the setting a specific mode. */ 343/*! Return the setting a specific mode. */
344BOOL TEScreen::getMode(int m) 344BOOL TEScreen::getMode(int m)
345{ 345{
346 return currParm.mode[m]; 346 return currParm.mode[m];
347} 347}
348 348
349/*! Save the cursor position and the rendition attribute settings. */ 349/*! Save the cursor position and the rendition attribute settings. */
350 350
351void TEScreen::saveCursor() 351void TEScreen::saveCursor()
352{ 352{
353 sa_cuX = cuX; 353 sa_cuX = cuX;
354 sa_cuY = cuY; 354 sa_cuY = cuY;
355 sa_cu_re = cu_re; 355 sa_cu_re = cu_re;
356 sa_cu_fg = cu_fg; 356 sa_cu_fg = cu_fg;
357 sa_cu_bg = cu_bg; 357 sa_cu_bg = cu_bg;
358} 358}
359 359
360/*! Restore the cursor position and the rendition attribute settings. */ 360/*! Restore the cursor position and the rendition attribute settings. */
361 361
362void TEScreen::restoreCursor() 362void TEScreen::restoreCursor()
363{ 363{
364 cuX = QMIN(sa_cuX,columns-1); 364 cuX = QMIN(sa_cuX,columns-1);
365 cuY = QMIN(sa_cuY,lines-1); 365 cuY = QMIN(sa_cuY,lines-1);
366 cu_re = sa_cu_re; 366 cu_re = sa_cu_re;
367 cu_fg = sa_cu_fg; 367 cu_fg = sa_cu_fg;
368 cu_bg = sa_cu_bg; 368 cu_bg = sa_cu_bg;
369 effectiveRendition(); 369 effectiveRendition();
370} 370}
371 371
372/* ------------------------------------------------------------------------- */ 372/* ------------------------------------------------------------------------- */
373/* */ 373/* */
374/* Screen Operations */ 374/* Screen Operations */
375/* */ 375/* */
376/* ------------------------------------------------------------------------- */ 376/* ------------------------------------------------------------------------- */
377 377
378/*! Assing a new size to the screen. 378/*! Assing a new size to the screen.
379 379
380 The topmost left position is maintained, while lower lines 380 The topmost left position is maintained, while lower lines
381 or right hand side columns might be removed or filled with 381 or right hand side columns might be removed or filled with
382 spaces to fit the new size. 382 spaces to fit the new size.
383 383
384 The region setting is reset to the whole screen and the 384 The region setting is reset to the whole screen and the
385 tab positions reinitialized. 385 tab positions reinitialized.
386*/ 386*/
387 387
388void TEScreen::resizeImage(int new_lines, int new_columns) 388void TEScreen::resizeImage(int new_lines, int new_columns)
389{ 389{
390 if (cuY > new_lines-1) { 390 if (cuY > new_lines-1) {
391// attempt to preserve focus and lines 391// attempt to preserve focus and lines
392 bmargin = lines-1; //FIXME: margin lost 392 bmargin = lines-1; //FIXME: margin lost
393 for (int i = 0; i < cuY-(new_lines-1); i++) { 393 for (int i = 0; i < cuY-(new_lines-1); i++) {
394 addHistLine(); scrollUp(horzCursor,1); 394 addHistLine(); scrollUp(horzCursor,1);
395 } 395 }
396 } 396 }
397 397
398 // make new image 398 // make new image
399 ca* newimg = (ca*)malloc( new_lines * new_columns * sizeof( ca)); 399 ca* newimg = (ca*)malloc( new_lines * new_columns * sizeof( ca));
400 400
401 clearSelection(); 401 clearSelection();
402 402
403 // clear new image 403 // clear new image
404 for (int y = 0; y < new_lines; y++) 404 for (int y = 0; y < new_lines; y++)
405 for (int x = 0; x < new_columns; x++) { 405 for (int x = 0; x < new_columns; x++) {
406 newimg[y*new_columns+x].c = ' '; 406 newimg[y*new_columns+x].c = ' ';
407 newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; 407 newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR;
408 newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; 408 newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR;
409 newimg[y*new_columns+x].r = DEFAULT_RENDITION; 409 newimg[y*new_columns+x].r = DEFAULT_RENDITION;
410 } 410 }
411 int cpy_lines = QMIN(new_lines, lines); 411 int cpy_lines = QMIN(new_lines, lines);
412 int cpy_columns = QMIN(new_columns,columns); 412 int cpy_columns = QMIN(new_columns,columns);
413 // copy to new image 413 // copy to new image
414 for (int y = 0; y < cpy_lines; y++) 414 for (int y = 0; y < cpy_lines; y++)
415 for (int x = 0; x < cpy_columns; x++) { 415 for (int x = 0; x < cpy_columns; x++) {
416 newimg[y*new_columns+x].c = image[loc(x,y)].c; 416 newimg[y*new_columns+x].c = image[loc(x,y)].c;
417 newimg[y*new_columns+x].f = image[loc(x,y)].f; 417 newimg[y*new_columns+x].f = image[loc(x,y)].f;
418 newimg[y*new_columns+x].b = image[loc(x,y)].b; 418 newimg[y*new_columns+x].b = image[loc(x,y)].b;
419 newimg[y*new_columns+x].r = image[loc(x,y)].r; 419 newimg[y*new_columns+x].r = image[loc(x,y)].r;
420 } 420 }
421 free(image); 421 free(image);
422 image = newimg; 422 image = newimg;
423 lines = new_lines; 423 lines = new_lines;
424 columns = new_columns; 424 columns = new_columns;
425 cuX = QMIN(cuX,columns-1); 425 cuX = QMIN(cuX,columns-1);
426 cuY = QMIN(cuY,lines-1); 426 cuY = QMIN(cuY,lines-1);
427 427
428 // FIXME: try to keep values, evtl. 428 // FIXME: try to keep values, evtl.
429 tmargin=0; 429 tmargin=0;
430 bmargin=lines-1; 430 bmargin=lines-1;
431 initTabStops(); 431 initTabStops();
432 clearSelection(); 432 clearSelection();
433} 433}
434 434
435/* 435/*
436 Clarifying rendition here and in TEWidget. 436 Clarifying rendition here and in TEWidget.
437 437
438 currently, TEWidget's color table is 438 currently, TEWidget's color table is
439 0 1 2 .. 9 10 .. 17 439 0 1 2 .. 9 10 .. 17
440 dft_fg, dft_bg, dim 0..7, intensive 0..7 440 dft_fg, dft_bg, dim 0..7, intensive 0..7
441 441
442 cu_fg, cu_bg contain values 0..8; 442 cu_fg, cu_bg contain values 0..8;
443 - 0 = default color 443 - 0 = default color
444 - 1..8 = ansi specified color 444 - 1..8 = ansi specified color
445 445
446 re_fg, re_bg contain values 0..17 446 re_fg, re_bg contain values 0..17
447 due to the TEWidget's color table 447 due to the TEWidget's color table
448 448
449 rendition attributes are 449 rendition attributes are
450 450
451 attr widget screen 451 attr widget screen
452 -------------- ------ ------ 452 -------------- ------ ------
453 RE_UNDERLINE XX XX affects foreground only 453 RE_UNDERLINE XX XX affects foreground only
454 RE_BLINK XX XX affects foreground only 454 RE_BLINK XX XX affects foreground only
455 RE_BOLD XX XX affects foreground only 455 RE_BOLD XX XX affects foreground only
456 RE_REVERSE -- XX 456 RE_REVERSE -- XX
457 RE_TRANSPARENT XX -- affects background only 457 RE_TRANSPARENT XX -- affects background only
458 RE_INTENSIVE XX -- affects foreground only 458 RE_INTENSIVE XX -- affects foreground only
459 459
460 Note that RE_BOLD is used in both widget 460 Note that RE_BOLD is used in both widget
461 and screen rendition. Since xterm/vt102 461 and screen rendition. Since xterm/vt102
462 is to poor to distinguish between bold 462 is to poor to distinguish between bold
463 (which is a font attribute) and intensive 463 (which is a font attribute) and intensive
464 (which is a color attribute), we translate 464 (which is a color attribute), we translate
465 this and RE_BOLD in falls eventually appart 465 this and RE_BOLD in falls eventually appart
466 into RE_BOLD and RE_INTENSIVE. 466 into RE_BOLD and RE_INTENSIVE.
467*/ 467*/
468 468
469void TEScreen::reverseRendition(ca* p) 469void TEScreen::reverseRendition(ca* p)
470{ UINT8 f = p->f; UINT8 b = p->b; 470{ UINT8 f = p->f; UINT8 b = p->b;
471 p->f = b; p->b = f; //p->r &= ~RE_TRANSPARENT; 471 p->f = b; p->b = f; //p->r &= ~RE_TRANSPARENT;
472} 472}
473 473
474void TEScreen::effectiveRendition() 474void TEScreen::effectiveRendition()
475// calculate rendition 475// calculate rendition
476{ 476{
477 ef_re = cu_re & (RE_UNDERLINE | RE_BLINK); 477 ef_re = cu_re & (RE_UNDERLINE | RE_BLINK);
478 if (cu_re & RE_REVERSE) 478 if (cu_re & RE_REVERSE)
479 { 479 {
480 ef_fg = cu_bg; 480 ef_fg = cu_bg;
481 ef_bg = cu_fg; 481 ef_bg = cu_fg;
482 } 482 }
483 else 483 else
484 { 484 {
485 ef_fg = cu_fg; 485 ef_fg = cu_fg;
486 ef_bg = cu_bg; 486 ef_bg = cu_bg;
487 } 487 }
488 if (cu_re & RE_BOLD) 488 if (cu_re & RE_BOLD)
489 { 489 {
490 if (ef_fg < BASE_COLORS) 490 if (ef_fg < BASE_COLORS)
491 ef_fg += BASE_COLORS; 491 ef_fg += BASE_COLORS;
492 else 492 else
493 ef_fg -= BASE_COLORS; 493 ef_fg -= BASE_COLORS;
494 } 494 }
495} 495}
496 496
497/*! 497/*!
498 returns the image. 498 returns the image.
499 499
500 Get the size of the image by \sa getLines and \sa getColumns. 500 Get the size of the image by \sa getLines and \sa getColumns.
501 501
502 NOTE that the image returned by this function must later be 502 NOTE that the image returned by this function must later be
503 freed. 503 freed.
504 504
505*/ 505*/
506 506
507ca* TEScreen::getCookedImage() 507ca* TEScreen::getCookedImage()
508{ 508{
509 int x,y; 509 int x,y;
510 ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); 510 ca* merged = (ca*)malloc(lines*columns*sizeof(ca));
511 ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); 511 ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION);
512 512
513 if (histCursor > hist.getLines()) {
514 histCursor = hist.getLines();
515 }
516
513 for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) 517 for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++)
514 { 518 {
515 int len = QMIN(columns,hist.getLineLen(y+histCursor)); 519 int len = QMIN(columns,hist.getLineLen(y+histCursor));
516 int yp = y*columns; 520 int yp = y*columns;
517 int yq = (y+histCursor)*columns; 521 int yq = (y+histCursor)*columns;
518 522
519 hist.getCells(y+histCursor,0,len,merged+yp); 523 hist.getCells(y+histCursor,0,len,merged+yp);
520 for (x = len; x < columns; x++) merged[yp+x] = dft; 524 for (x = len; x < columns; x++) merged[yp+x] = dft;
521 for (x = 0; x < columns; x++) 525 for (x = 0; x < columns; x++)
522 { int p=x + yp; int q=x + yq; 526 { int p=x + yp; int q=x + yq;
523 if ( ( q >= sel_TL ) && ( q <= sel_BR ) ) 527 if ( ( q >= sel_TL ) && ( q <= sel_BR ) )
524 reverseRendition(&merged[p]); // for selection 528 reverseRendition(&merged[p]); // for selection
525 } 529 }
526 } 530 }
527 if (lines >= hist.getLines()-histCursor) 531 if (lines >= hist.getLines()-histCursor)
528 { 532 {
529 for (y = (hist.getLines()-histCursor); y < lines ; y++) 533 for (y = (hist.getLines()-histCursor); y < lines ; y++)
530 { 534 {
531 int yp = y*columns; 535 int yp = y*columns;
532 int yq = (y+histCursor)*columns; 536 int yq = (y+histCursor)*columns;
533 int yr = (y-hist.getLines()+histCursor)*columns; 537 int yr = (y-hist.getLines()+histCursor)*columns;
534 for (x = 0; x < columns; x++) 538 for (x = 0; x < columns; x++)
535 { int p = x + yp; int q = x + yq; int r = x + yr; 539 { int p = x + yp; int q = x + yq; int r = x + yr;
536 merged[p] = image[r]; 540 merged[p] = image[r];
537 if ( q >= sel_TL && q <= sel_BR ) 541 if ( q >= sel_TL && q <= sel_BR )
538 reverseRendition(&merged[p]); // for selection 542 reverseRendition(&merged[p]); // for selection
539 } 543 }
540 544
541 } 545 }
542 } 546 }
543 // evtl. inverse display 547 // evtl. inverse display
544 if (getMode(MODE_Screen)) 548 if (getMode(MODE_Screen))
545 { int i,n = lines*columns; 549 { int i,n = lines*columns;
546 for (i = 0; i < n; i++) 550 for (i = 0; i < n; i++)
547 reverseRendition(&merged[i]); // for reverse display 551 reverseRendition(&merged[i]); // for reverse display
548 } 552 }
549 if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible 553 if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible
550 reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); 554 reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]);
551 return merged; 555 return merged;
552 556
553} 557}
554 558
555 559
556/*! 560/*!
557*/ 561*/
558 562
559void TEScreen::reset() 563void TEScreen::reset()
560{ 564{
561 Config cfg("Konsole"); 565 Config cfg("Qkonsole");
562 cfg.setGroup("ScrollBar"); 566 cfg.setGroup("ScrollBar");
563 if( !cfg.readBoolEntry("HorzScroll",0) ) 567 if( !cfg.readBoolEntry("HorzScroll",0) )
564 setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin 568 setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin
565 569
566 570
567 resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1] 571 resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1]
568 resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke 572 resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke
569 setMode(MODE_Cursor); // cursor visible 573 setMode(MODE_Cursor); // cursor visible
570 resetMode(MODE_Screen); // screen not inverse 574 resetMode(MODE_Screen); // screen not inverse
571 resetMode(MODE_NewLine); 575 resetMode(MODE_NewLine);
572 576
573 tmargin=0; 577 tmargin=0;
574 bmargin=lines-1; 578 bmargin=lines-1;
575 579
576 setDefaultRendition(); 580 setDefaultRendition();
577 saveCursor(); 581 saveCursor();
578 582
579 clear(); 583 clear();
580} 584}
581 585
582/*! Clear the entire screen and home the cursor. 586/*! Clear the entire screen and home the cursor.
583*/ 587*/
584 588
585void TEScreen::clear() 589void TEScreen::clear()
586{ 590{
587 clearEntireScreen(); 591 clearEntireScreen();
588 home(); 592 home();
589} 593}
590 594
591/*! Moves the cursor left one column. 595/*! Moves the cursor left one column.
592*/ 596*/
593 597
594void TEScreen::BackSpace() 598void TEScreen::BackSpace()
595{ 599{
596 cuX = QMAX(0,cuX-1); 600 cuX = QMAX(0,cuX-1);
597 if (BS_CLEARS) image[loc(cuX,cuY)].c = ' '; 601 if (BS_CLEARS) image[loc(cuX,cuY)].c = ' ';
598} 602}
599 603
600/*! 604/*!
601*/ 605*/
602 606
603void TEScreen::Tabulate() 607void TEScreen::Tabulate()
604{ 608{
605 // note that TAB is a format effector (does not write ' '); 609 // note that TAB is a format effector (does not write ' ');
606 cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1); 610 cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1);
607} 611}
608 612
609void TEScreen::clearTabStops() 613void TEScreen::clearTabStops()
610{ 614{
611 for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; 615 for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE;
612} 616}
613 617
614void TEScreen::changeTabStop(bool set) 618void TEScreen::changeTabStop(bool set)
615{ 619{
616 if (cuX >= columns) return; 620 if (cuX >= columns) return;
617 tabstops[cuX] = set; 621 tabstops[cuX] = set;
618} 622}
619 623
620void TEScreen::initTabStops() 624void TEScreen::initTabStops()
621{ 625{
622 if (tabstops) free(tabstops); 626 if (tabstops) free(tabstops);
623 tabstops = (bool*)malloc(columns*sizeof(bool)); 627 tabstops = (bool*)malloc(columns*sizeof(bool));
624 // Arrg! The 1st tabstop has to be one longer than the other. 628 // Arrg! The 1st tabstop has to be one longer than the other.
625 // i.e. the kids start counting from 0 instead of 1. 629 // i.e. the kids start counting from 0 instead of 1.
626 // Other programs might behave correctly. Be aware. 630 // Other programs might behave correctly. Be aware.
627 for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); 631 for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0);
628} 632}
629 633
630/*! 634/*!
631 This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) 635 This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine)
632 depending on the NewLine Mode (LNM). This mode also 636 depending on the NewLine Mode (LNM). This mode also
633 affects the key sequence returned for newline ([CR]LF). 637 affects the key sequence returned for newline ([CR]LF).
634*/ 638*/
635 639
636void TEScreen::NewLine() 640void TEScreen::NewLine()
637{ 641{
638 if (getMode(MODE_NewLine)) Return(); 642 if (getMode(MODE_NewLine)) Return();
639 index(); 643 index();
640} 644}
641 645
642/*! put `c' literally onto the screen at the current cursor position. 646/*! put `c' literally onto the screen at the current cursor position.
643 647
644 VT100 uses the convention to produce an automatic newline (am) 648 VT100 uses the convention to produce an automatic newline (am)
645 with the *first* character that would fall onto the next line (xenl). 649 with the *first* character that would fall onto the next line (xenl).
646*/ 650*/
647 651
648void TEScreen::checkSelection(int from, int to) 652void TEScreen::checkSelection(int from, int to)
649{ 653{
650 if (sel_begin == -1) return; 654 if (sel_begin == -1) return;
651 int scr_TL = loc(0, hist.getLines()); 655 int scr_TL = loc(0, hist.getLines());
652 //Clear entire selection if it overlaps region [from, to] 656 //Clear entire selection if it overlaps region [from, to]
653 if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) 657 if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) )
654 { 658 {
655 clearSelection(); 659 clearSelection();
656 } 660 }
657} 661}
658 662
659void TEScreen::ShowCharacter(unsigned short c) 663void TEScreen::ShowCharacter(unsigned short c)
660{ 664{
661 // Note that VT100 does wrapping BEFORE putting the character. 665 // Note that VT100 does wrapping BEFORE putting the character.
662 // This has impact on the assumption of valid cursor positions. 666 // This has impact on the assumption of valid cursor positions.
663 // We indicate the fact that a newline has to be triggered by 667 // We indicate the fact that a newline has to be triggered by
664 // putting the cursor one right to the last column of the screen. 668 // putting the cursor one right to the last column of the screen.
665 669
666 if (cuX >= columns) 670 if (cuX >= columns)
667 { 671 {
668 if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1; 672 if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1;
669 // comment out for no wrap 673 // comment out for no wrap
670 } 674 }
671 675
672 if (getMode(MODE_Insert)) insertChars(1); 676 if (getMode(MODE_Insert)) insertChars(1);
673 677
674 int i = loc( cuX, cuY); 678 int i = loc( cuX, cuY);
675 679
676 checkSelection(i, i); // check if selection is still valid. 680 checkSelection(i, i); // check if selection is still valid.
677 681
678 image[i].c = c; 682 image[i].c = c;
679 image[i].f = ef_fg; 683 image[i].f = ef_fg;
680 image[i].b = ef_bg; 684 image[i].b = ef_bg;
681 image[i].r = ef_re; 685 image[i].r = ef_re;
682 686
683 cuX += 1; 687 cuX += 1;
684} 688}
685 689
686// Region commands ------------------------------------------------------------- 690// Region commands -------------------------------------------------------------
687 691
688 692
689/*! scroll up `n' lines within current region. 693/*! scroll up `n' lines within current region.
690 The `n' new lines are cleared. 694 The `n' new lines are cleared.
691 \sa setRegion \sa scrollDown 695 \sa setRegion \sa scrollDown
692*/ 696*/
693 697
694void TEScreen::scrollUp(int from, int n) 698void TEScreen::scrollUp(int from, int n)
695{ 699{
696 if (n <= 0 || from + n > bmargin) return; 700 if (n <= 0 || from + n > bmargin) return;
697 //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. 701 //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds.
698 702
699 moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin)); 703 moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin));
700 clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' '); 704 clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' ');
701} 705}
702 706
703/*! scroll down `n' lines within current region. 707/*! scroll down `n' lines within current region.
704 The `n' new lines are cleared. 708 The `n' new lines are cleared.
705 \sa setRegion \sa scrollUp 709 \sa setRegion \sa scrollUp
706*/ 710*/
707 711
708void TEScreen::scrollDown(int from, int n) 712void TEScreen::scrollDown(int from, int n)
709{ 713{
710 714
711//FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. 715//FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds.
712 if (n <= 0) return; 716 if (n <= 0) return;
713 if (from > bmargin) return; 717 if (from > bmargin) return;
714 if (from + n > bmargin) n = bmargin - from; 718 if (from + n > bmargin) n = bmargin - from;
715 719
716 moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n)); 720 moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n));
717 clearImage(loc(0,from),loc(columns-1,from+n-1),' '); 721 clearImage(loc(0,from),loc(columns-1,from+n-1),' ');
718} 722}
719 723
720 724
721 725
722/*! position the cursor to a specific line and column. */ 726/*! position the cursor to a specific line and column. */
723void TEScreen::setCursorYX(int y, int x) 727void TEScreen::setCursorYX(int y, int x)
724{ 728{
725 setCursorY(y); setCursorX(x); 729 setCursorY(y); setCursorX(x);
726} 730}
727 731
728/*! Set the cursor to x-th line. */ 732/*! Set the cursor to x-th line. */
729 733
730void TEScreen::setCursorX(int x) 734void TEScreen::setCursorX(int x)
731{ 735{
732 if (x == 0) x = 1; // Default 736 if (x == 0) x = 1; // Default
733 x -= 1; // Adjust 737 x -= 1; // Adjust
734 cuX = QMAX(0,QMIN(columns-1, x)); 738 cuX = QMAX(0,QMIN(columns-1, x));
735} 739}
736 740
737/*! Set the cursor to y-th line. */ 741/*! Set the cursor to y-th line. */
738 742
739void TEScreen::setCursorY(int y) 743void TEScreen::setCursorY(int y)
740{ 744{
741 if (y == 0) y = 1; // Default 745 if (y == 0) y = 1; // Default
742 y -= 1; // Adjust 746 y -= 1; // Adjust
743 cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); 747 cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) ));
744} 748}
745 749
746/*! set cursor to the `left upper' corner of the screen (1,1). 750/*! set cursor to the `left upper' corner of the screen (1,1).
747*/ 751*/
748 752
749void TEScreen::home() 753void TEScreen::home()
750{ 754{
751 cuX = 0; 755 cuX = 0;
752 cuY = 0; 756 cuY = 0;
753} 757}
754 758
755/*! set cursor to the begin of the current line. 759/*! set cursor to the begin of the current line.
756*/ 760*/
757 761
758void TEScreen::Return() 762void TEScreen::Return()
759{ 763{
760 cuX = 0; 764 cuX = 0;
761} 765}
762 766
763/*! returns the current cursor columns. 767/*! returns the current cursor columns.
764*/ 768*/
765 769
766int TEScreen::getCursorX() 770int TEScreen::getCursorX()
767{ 771{
768 return cuX; 772 return cuX;
769} 773}
770 774
771/*! returns the current cursor line. 775/*! returns the current cursor line.
772*/ 776*/
773 777
774int TEScreen::getCursorY() 778int TEScreen::getCursorY()
775{ 779{
776 return cuY; 780 return cuY;
777} 781}
778 782
779// Erasing --------------------------------------------------------------------- 783// Erasing ---------------------------------------------------------------------
780 784
781/*! \section Erasing 785/*! \section Erasing
782 786
783 This group of operations erase parts of the screen contents by filling 787 This group of operations erase parts of the screen contents by filling
784 it with spaces colored due to the current rendition settings. 788 it with spaces colored due to the current rendition settings.
785 789
786 Althought the cursor position is involved in most of these operations, 790 Althought the cursor position is involved in most of these operations,
787 it is never modified by them. 791 it is never modified by them.
788*/ 792*/
789 793
790/*! fill screen between (including) `loca' and `loce' with spaces. 794/*! fill screen between (including) `loca' and `loce' with spaces.
791 795
792 This is an internal helper functions. The parameter types are internal 796 This is an internal helper functions. The parameter types are internal
793 addresses of within the screen image and make use of the way how the 797 addresses of within the screen image and make use of the way how the
794 screen matrix is mapped to the image vector. 798 screen matrix is mapped to the image vector.
795*/ 799*/
796 800
797void TEScreen::clearImage(int loca, int loce, char c) 801void TEScreen::clearImage(int loca, int loce, char c)
798{ int i; 802{ int i;
799 int scr_TL=loc(0,hist.getLines()); 803 int scr_TL=loc(0,hist.getLines());
800 //FIXME: check positions 804 //FIXME: check positions
801 805
802 //Clear entire selection if it overlaps region to be moved... 806 //Clear entire selection if it overlaps region to be moved...
803 if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) 807 if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) )
804 { 808 {
805 clearSelection(); 809 clearSelection();
806 } 810 }
807 for (i = loca; i <= loce; i++) 811 for (i = loca; i <= loce; i++)
808 { 812 {
809 image[i].c = c; 813 image[i].c = c;
810 image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi 814 image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi
811 image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different 815 image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different
812 image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. 816 image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here.
813 } 817 }
814} 818}
815 819
816/*! move image between (including) `loca' and `loce' to 'dst'. 820/*! move image between (including) `loca' and `loce' to 'dst'.
817 821
818 This is an internal helper functions. The parameter types are internal 822 This is an internal helper functions. The parameter types are internal
819 addresses of within the screen image and make use of the way how the 823 addresses of within the screen image and make use of the way how the
820 screen matrix is mapped to the image vector. 824 screen matrix is mapped to the image vector.
821*/ 825*/
822 826
823void TEScreen::moveImage(int dst, int loca, int loce) 827void TEScreen::moveImage(int dst, int loca, int loce)
824{ 828{
825//FIXME: check positions 829//FIXME: check positions
826 if (loce < loca) { 830 if (loce < loca) {
827 // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; 831 // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl;
828 return; 832 return;
829 } 833 }
830 memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); 834 memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca));
831} 835}
832 836
833/*! clear from (including) current cursor position to end of screen. 837/*! clear from (including) current cursor position to end of screen.
834*/ 838*/
835 839
836void TEScreen::clearToEndOfScreen() 840void TEScreen::clearToEndOfScreen()
837{ 841{
838 clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); 842 clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' ');
839} 843}
840 844
841/*! clear from begin of screen to (including) current cursor position. 845/*! clear from begin of screen to (including) current cursor position.
842*/ 846*/
843 847
844void TEScreen::clearToBeginOfScreen() 848void TEScreen::clearToBeginOfScreen()
845{ 849{
846 clearImage(loc(0,0),loc(cuX,cuY),' '); 850 clearImage(loc(0,0),loc(cuX,cuY),' ');
847} 851}
848 852
849/*! clear the entire screen. 853/*! clear the entire screen.
850*/ 854*/
851 855
852void TEScreen::clearEntireScreen() 856void TEScreen::clearEntireScreen()
853{ 857{
854 clearImage(loc(0,0),loc(columns-1,lines-1),' '); 858 clearImage(loc(0,0),loc(columns-1,lines-1),' ');
855} 859}
856 860
857/*! fill screen with 'E' 861/*! fill screen with 'E'
858 This is to aid screen alignment 862 This is to aid screen alignment
859*/ 863*/
860 864
861void TEScreen::helpAlign() 865void TEScreen::helpAlign()
862{ 866{
863 clearImage(loc(0,0),loc(columns-1,lines-1),'E'); 867 clearImage(loc(0,0),loc(columns-1,lines-1),'E');
864} 868}
865 869
866/*! clear from (including) current cursor position to end of current cursor line. 870/*! clear from (including) current cursor position to end of current cursor line.
867*/ 871*/
868 872
869void TEScreen::clearToEndOfLine() 873void TEScreen::clearToEndOfLine()
870{ 874{
871 clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); 875 clearImage(loc(cuX,cuY),loc(columns-1,cuY),' ');
872} 876}
873 877
874/*! clear from begin of current cursor line to (including) current cursor position. 878/*! clear from begin of current cursor line to (including) current cursor position.
875*/ 879*/
876 880
877void TEScreen::clearToBeginOfLine() 881void TEScreen::clearToBeginOfLine()
878{ 882{
879 clearImage(loc(0,cuY),loc(cuX,cuY),' '); 883 clearImage(loc(0,cuY),loc(cuX,cuY),' ');
880} 884}
881 885
882/*! clears entire current cursor line 886/*! clears entire current cursor line
883*/ 887*/
884 888
885void TEScreen::clearEntireLine() 889void TEScreen::clearEntireLine()
886{ 890{
887 clearImage( loc( 0, cuY),loc( columns - 1, cuY),' '); 891 clearImage( loc( 0, cuY),loc( columns - 1, cuY),' ');
888} 892}
889 893
890// Rendition ------------------------------------------------------------------ 894// Rendition ------------------------------------------------------------------
891 895
892/*! 896/*!
893 set rendition mode 897 set rendition mode
894*/ 898*/
895 899
896void TEScreen::setRendition(int re) 900void TEScreen::setRendition(int re)
897{ 901{
898 cu_re |= re; 902 cu_re |= re;
899 effectiveRendition(); 903 effectiveRendition();
900} 904}
901 905
902/*! 906/*!
903 reset rendition mode 907 reset rendition mode
904*/ 908*/
905 909
906void TEScreen::resetRendition(int re) 910void TEScreen::resetRendition(int re)
907{ 911{
908 cu_re &= ~re; 912 cu_re &= ~re;
909 effectiveRendition(); 913 effectiveRendition();
910} 914}
911 915
912/*! 916/*!
913*/ 917*/
914 918
915void TEScreen::setDefaultRendition() 919void TEScreen::setDefaultRendition()
916{ 920{
917 setForeColorToDefault(); 921 setForeColorToDefault();
918 setBackColorToDefault(); 922 setBackColorToDefault();
919 cu_re = DEFAULT_RENDITION; 923 cu_re = DEFAULT_RENDITION;
920 effectiveRendition(); 924 effectiveRendition();
921} 925}
922 926
923/*! 927/*!
924*/ 928*/
925 929
926void TEScreen::setForeColor(int fgcolor) 930void TEScreen::setForeColor(int fgcolor)
927{ 931{
928 cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); 932 cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2);
929 effectiveRendition(); 933 effectiveRendition();
930} 934}
931 935
932/*! 936/*!
933*/ 937*/
934 938
935void TEScreen::setBackColor(int bgcolor) 939void TEScreen::setBackColor(int bgcolor)
936{ 940{
937 cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); 941 cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2);
938 effectiveRendition(); 942 effectiveRendition();
939} 943}
940 944
941/*! 945/*!
942*/ 946*/
943 947
944void TEScreen::setBackColorToDefault() 948void TEScreen::setBackColorToDefault()
945{ 949{
946 cu_bg = DEFAULT_BACK_COLOR; 950 cu_bg = DEFAULT_BACK_COLOR;
947 effectiveRendition(); 951 effectiveRendition();
948} 952}
949 953
950/*! 954/*!
951*/ 955*/
952 956
953void TEScreen::setForeColorToDefault() 957void TEScreen::setForeColorToDefault()
954{ 958{
955 cu_fg = DEFAULT_FORE_COLOR; 959 cu_fg = DEFAULT_FORE_COLOR;
956 effectiveRendition(); 960 effectiveRendition();
957} 961}
958 962
959/* ------------------------------------------------------------------------- */ 963/* ------------------------------------------------------------------------- */
960/* */ 964/* */
961/* Marking & Selection */ 965/* Marking & Selection */
962/* */ 966/* */
963/* ------------------------------------------------------------------------- */ 967/* ------------------------------------------------------------------------- */
964 968
965void TEScreen::clearSelection() 969void TEScreen::clearSelection()
966{ 970{
967 sel_BR = -1; 971 sel_BR = -1;
968 sel_TL = -1; 972 sel_TL = -1;
969 sel_begin = -1; 973 sel_begin = -1;
970} 974}
971 975
972void TEScreen::setSelBeginXY(const int x, const int y) 976void TEScreen::setSelBeginXY(const int x, const int y)
973{ 977{
978 if (histCursor > hist.getLines()) {
979 histCursor = hist.getLines();
980 }
974 sel_begin = loc(x,y+histCursor) ; 981 sel_begin = loc(x,y+histCursor) ;
975 sel_BR = sel_begin; 982 sel_BR = sel_begin;
976 sel_TL = sel_begin; 983 sel_TL = sel_begin;
977} 984}
978 985
979void TEScreen::setSelExtentXY(const int x, const int y) 986void TEScreen::setSelExtentXY(const int x, const int y)
980{ 987{
981 if (sel_begin == -1) return; 988 if (sel_begin == -1) return;
989 if (histCursor > hist.getLines()) {
990 histCursor = hist.getLines();
991 }
982 int l = loc(x,y + histCursor); 992 int l = loc(x,y + histCursor);
983 993
984 if (l < sel_begin) 994 if (l < sel_begin)
985 { 995 {
986 sel_TL = l; 996 sel_TL = l;
987 sel_BR = sel_begin; 997 sel_BR = sel_begin;
988 } 998 }
989 else 999 else
990 { 1000 {
991 /* FIXME, HACK to correct for x too far to the right... */ 1001 /* FIXME, HACK to correct for x too far to the right... */
992 if (( x == columns )|| (x == 0)) l--; 1002 if (( x == columns )|| (x == 0)) l--;
993 1003
994 sel_TL = sel_begin; 1004 sel_TL = sel_begin;
995 sel_BR = l; 1005 sel_BR = l;
996 } 1006 }
997} 1007}
998 1008
999QString TEScreen::getSelText(const BOOL preserve_line_breaks) 1009QString TEScreen::getSelText(const BOOL preserve_line_breaks)
1000{ 1010{
1001 if (sel_begin == -1) 1011 if (sel_begin == -1)
1002 return QString::null; // Selection got clear while selecting. 1012 return QString::null; // Selection got clear while selecting.
1003 1013
1004 int *m; // buffer to fill. 1014 int *m; // buffer to fill.
1005 int s, d; // source index, dest. index. 1015 int s, d; // source index, dest. index.
1006 int hist_BR = loc(0, hist.getLines()); 1016 int hist_BR = loc(0, hist.getLines());
1007 int hY = sel_TL / columns; 1017 int hY = sel_TL / columns;
1008 int hX = sel_TL % columns; 1018 int hX = sel_TL % columns;
1009 int eol; // end of line 1019 int eol; // end of line
1010 1020
1011 s = sel_TL; // tracks copy in source. 1021 s = sel_TL; // tracks copy in source.
1012 1022
1013 // allocate buffer for maximum 1023 // allocate buffer for maximum
1014 // possible size... 1024 // possible size...
1015 d = (sel_BR - sel_TL) / columns + 1; 1025 d = (sel_BR - sel_TL) / columns + 1;
1016 m = new int[d * (columns + 1) + 2]; 1026 m = new int[d * (columns + 1) + 2];
1017 d = 0; 1027 d = 0;
1018 1028
1019 while (s <= sel_BR) 1029 while (s <= sel_BR)
1020 { 1030 {
1021 if (s < hist_BR) 1031 if (s < hist_BR)
1022 { // get lines from hist.history 1032 { // get lines from hist.history
1023 // buffer. 1033 // buffer.
1024 eol = hist.getLineLen(hY); 1034 eol = hist.getLineLen(hY);
1025 1035
1026 if ((hY == (sel_BR / columns)) && 1036 if ((hY == (sel_BR / columns)) &&
1027 (eol >= (sel_BR % columns))) 1037 (eol >= (sel_BR % columns)))
1028 { 1038 {
1029 eol = sel_BR % columns + 1; 1039 eol = sel_BR % columns + 1;
1030 } 1040 }
1031 1041
1032 while (hX < eol) 1042 while (hX < eol)
1033 { 1043 {
1034 m[d++] = hist.getCell(hY, hX++).c; 1044 m[d++] = hist.getCell(hY, hX++).c;
1035 s++; 1045 s++;
1036 } 1046 }
1037 1047
1038 if (s <= sel_BR) 1048 if (s <= sel_BR)
1039 { 1049 {
1040 // The line break handling 1050 // The line break handling
1041 // It's different from the screen 1051 // It's different from the screen
1042 // image case! 1052 // image case!
1043 if (eol % columns == 0) 1053 if (eol % columns == 0)
1044 { 1054 {
1045 // That's either a completely filled 1055 // That's either a completely filled
1046 // line or an empty line 1056 // line or an empty line
1047 if (eol == 0) 1057 if (eol == 0)
1048 { 1058 {
1049 m[d++] = '\n'; 1059 m[d++] = '\n';
1050 } 1060 }
1051 else 1061 else
1052 { 1062 {
1053 // We have a full line. 1063 // We have a full line.
1054 // FIXME: How can we handle newlines 1064 // FIXME: How can we handle newlines
1055 // at this position?! 1065 // at this position?!
1056 } 1066 }
1057 } 1067 }
1058 else if ((eol + 1) % columns == 0) 1068 else if ((eol + 1) % columns == 0)
1059 { 1069 {
1060 // FIXME: We don't know if this was a 1070 // FIXME: We don't know if this was a
1061 // space at the last position or a 1071 // space at the last position or a
1062 // short line!! 1072 // short line!!
1063 m[d++] = ' '; 1073 m[d++] = ' ';
1064 } 1074 }
1065 else 1075 else
1066 { 1076 {
1067 // We have a short line here. Put a 1077 // We have a short line here. Put a
1068 // newline or a space into the 1078 // newline or a space into the
1069 // buffer. 1079 // buffer.
1070 m[d++] = preserve_line_breaks ? '\n' : ' '; 1080 m[d++] = preserve_line_breaks ? '\n' : ' ';
1071 } 1081 }
1072 } 1082 }
1073 1083
1074 hY++; 1084 hY++;
1075 hX = 0; 1085 hX = 0;
1076 s = hY * columns; 1086 s = hY * columns;
1077 } 1087 }
1078 else 1088 else
1079 { // or from screen image. 1089 { // or from screen image.
1080 eol = (s / columns + 1) * columns - 1; 1090 eol = (s / columns + 1) * columns - 1;
1081 1091
1082 if (eol < sel_BR) 1092 if (eol < sel_BR)
1083 { 1093 {
1084 while ((eol > s) && 1094 while ((eol > s) &&
1085 isspace(image[eol - hist_BR].c)) 1095 isspace(image[eol - hist_BR].c))
1086 { 1096 {
1087 eol--; 1097 eol--;
1088 } 1098 }
1089 } 1099 }
1090 else 1100 else
1091 { 1101 {
1092 eol = sel_BR; 1102 eol = sel_BR;
1093 } 1103 }
1094 1104
1095 while (s <= eol) 1105 while (s <= eol)
1096 { 1106 {
1097 m[d++] = image[s++ - hist_BR].c; 1107 m[d++] = image[s++ - hist_BR].c;
1098 } 1108 }
1099 1109
1100 if (eol < sel_BR) 1110 if (eol < sel_BR)
1101 { 1111 {
1102 // eol processing see below ... 1112 // eol processing see below ...
1103 if ((eol + 1) % columns == 0) 1113 if ((eol + 1) % columns == 0)
1104 { 1114 {
1105 if (image[eol - hist_BR].c == ' ') 1115 if (image[eol - hist_BR].c == ' ')
1106 { 1116 {
1107 m[d++] = ' '; 1117 m[d++] = ' ';
1108 } 1118 }
1109 } 1119 }
1110 else 1120 else
1111 { 1121 {
1112 m[d++] = ((preserve_line_breaks || 1122 m[d++] = ((preserve_line_breaks ||
1113 ((eol % columns) == 0)) ? 1123 ((eol % columns) == 0)) ?
1114 '\n' : ' '); 1124 '\n' : ' ');
1115 } 1125 }
1116 } 1126 }
1117 1127
1118 s = (eol / columns + 1) * columns; 1128 s = (eol / columns + 1) * columns;
1119 } 1129 }
1120 } 1130 }
1121 1131
1122 QChar* qc = new QChar[d]; 1132 QChar* qc = new QChar[d];
1123 1133
1124 for (int i = 0; i < d; i++) 1134 for (int i = 0; i < d; i++)
1125 { 1135 {
1126 qc[i] = m[i]; 1136 qc[i] = m[i];
1127 } 1137 }
1128 1138
1129 QString res(qc, d); 1139 QString res(qc, d);
1130 1140
1131 delete m; 1141 delete m;
1132 delete qc; 1142 delete qc;
1133 1143
1134 return res; 1144 return res;
1135} 1145}
1136/* above ... end of line processing for selection -- psilva 1146/* above ... end of line processing for selection -- psilva
1137cases: 1147cases:
1138 1148
11391) (eol+1)%columns == 0 --> the whole line is filled. 11491) (eol+1)%columns == 0 --> the whole line is filled.
1140 If the last char is a space, insert (preserve) space. otherwise 1150 If the last char is a space, insert (preserve) space. otherwise
1141 leave the text alone, so that words that are broken by linewrap 1151 leave the text alone, so that words that are broken by linewrap
1142 are preserved. 1152 are preserved.
1143 1153
1144FIXME: 1154FIXME:
1145 * this suppresses \n for command output that is 1155 * this suppresses \n for command output that is
1146 sized to the exact column width of the screen. 1156 sized to the exact column width of the screen.
1147 1157
11482) eol%columns == 0 --> blank line. 11582) eol%columns == 0 --> blank line.
1149 insert a \n unconditionally. 1159 insert a \n unconditionally.
1150 Do it either you would because you are in preserve_line_break mode, 1160 Do it either you would because you are in preserve_line_break mode,
1151 or because it's an ASCII paragraph delimiter, so even when 1161 or because it's an ASCII paragraph delimiter, so even when
1152 not preserving line_breaks, you want to preserve paragraph breaks. 1162 not preserving line_breaks, you want to preserve paragraph breaks.
1153 1163
11543) else --> partially filled line 11643) else --> partially filled line
1155 insert a \n in preserve line break mode, else a space 1165 insert a \n in preserve line break mode, else a space
1156 The space prevents concatenation of the last word of one 1166 The space prevents concatenation of the last word of one
1157 line with the first of the next. 1167 line with the first of the next.
1158 1168
1159*/ 1169*/
1160 1170
1161void TEScreen::addHistLine() 1171void TEScreen::addHistLine()
1162{ 1172{
1163 assert(hasScroll() || histCursor == 0); 1173 assert(hasScroll() || histCursor == 0);
1164 1174
1165 // add to hist buffer 1175 // add to hist buffer
1166 // we have to take care about scrolling, too... 1176 // we have to take care about scrolling, too...
1167 1177
1168 if (hasScroll()){ 1178 if (hasScroll()){
1169 ca dft; 1179 ca dft;
1170 1180
1171 int end = columns - 1; 1181 int end = columns - 1;
1172 while (end >= 0 && image[end] == dft) 1182 while (end >= 0 && image[end] == dft)
1173 end -= 1; 1183 end -= 1;
1174 1184
1175 hist.addCells( image, end + 1); 1185 hist.addCells( image, end + 1);
1176 hist.addLine(); 1186 hist.addLine();
1177 1187
1178 // adjust history cursor 1188 // adjust history cursor
1179 histCursor += ( hist.getLines() - 1 == histCursor); 1189 histCursor += ( hist.getLines() - 1 == histCursor);
1180 } 1190 }
1181 1191
1182 if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround 1192 if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround
1183} 1193}
1184 1194
1185void TEScreen::setHistCursor(int cursor) 1195void TEScreen::setHistCursor(int cursor)
1186{ 1196{
1187 histCursor = cursor; //FIXME:rangecheck 1197 histCursor = cursor; //FIXME:rangecheck
1198 if (histCursor > hist.getLines()) {
1199 histCursor = hist.getLines();
1200 }
1201 if (histCursor < 0) {
1202 histCursor = 0;
1203 }
1188} 1204}
1189 1205
1190void TEScreen::setHorzCursor(int cursor) 1206void TEScreen::setHorzCursor(int cursor)
1191{ 1207{
1192 horzCursor = cursor; 1208 horzCursor = cursor;
1193} 1209}
1194 1210
1195int TEScreen::getHistCursor() 1211int TEScreen::getHistCursor()
1196{ 1212{
1197 return histCursor; 1213 return histCursor;
1198} 1214}
1199 1215
1200int TEScreen::getHorzCursor() 1216int TEScreen::getHorzCursor()
1201{ 1217{
1202 return horzCursor; 1218 return horzCursor;
1203} 1219}
1204 1220
1205int TEScreen::getHistLines() 1221int TEScreen::getHistLines()
1206{ 1222{
1207 return hist.getLines(); 1223 return hist.getLines();
1208} 1224}
1209 1225
1210void TEScreen::setScroll(bool on) 1226void TEScreen::setScroll(bool on)
1211{ 1227{
1212 histCursor = 0; 1228 histCursor = 0;
1213 clearSelection(); 1229 clearSelection();
1214 hist.setScroll(on); 1230 hist.setScroll(on);
1215} 1231}
1216 1232
1217bool TEScreen::hasScroll() 1233bool TEScreen::hasScroll()
1218{ 1234{
1219 return hist.hasScroll(); 1235 return hist.hasScroll();
1220} 1236}
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index ec1b30c..98c3cdf 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -1,1373 +1,1433 @@
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 <qpe/resource.h> 55#include <qpe/resource.h>
56#include <qpe/sound.h> 56#include <qpe/sound.h>
57 57
58#if !(QT_NO_COP) 58#if !(QT_NO_COP)
59#include <qpe/qcopenvelope_qws.h> 59#include <qpe/qcopenvelope_qws.h>
60#endif 60#endif
61 61
62#include <qcursor.h> 62#include <qcursor.h>
63#include <qregexp.h> 63#include <qregexp.h>
64#include <qpainter.h> 64#include <qpainter.h>
65#include <qclipboard.h> 65#include <qclipboard.h>
66#include <qstyle.h> 66#include <qstyle.h>
67#include <qfile.h> 67#include <qfile.h>
68#include <qdragobject.h> 68#include <qdragobject.h>
69#include <qnamespace.h>
69 70
70#include <stdio.h> 71#include <stdio.h>
71#include <stdlib.h> 72#include <stdlib.h>
72#include <unistd.h> 73#include <unistd.h>
73#include <ctype.h> 74#include <ctype.h>
74#include <sys/stat.h> 75#include <sys/stat.h>
75#include <sys/types.h> 76#include <sys/types.h>
76#include <signal.h> 77#include <signal.h>
77 78
78#include <assert.h> 79#include <assert.h>
79 80
80// #include "TEWidget.moc" 81// #include "TEWidget.moc"
81//#include <kapp.h> 82//#include <kapp.h>
82//#include <kcursor.h> 83//#include <kcursor.h>
83//#include <kurl.h> 84//#include <kurl.h>
84//#include <kdebug.h> 85//#include <kdebug.h>
85//#include <klocale.h> 86//#include <klocale.h>
86 87
87#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 88#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
88#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } 89#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }
89 90
90#define loc(X,Y) ((Y)*columns+(X)) 91#define loc(X,Y) ((Y)*columns+(X))
91 92
92//FIXME: the rim should normally be 1, 0 only when running in full screen mode. 93//FIXME: the rim should normally be 1, 0 only when running in full screen mode.
93#define rimX 0 // left/right rim width 94#define rimX 0 // left/right rim width
94#define rimY 0 // top/bottom rim high 95#define rimY 0 // top/bottom rim high
95 96
96#define SCRWIDTH 16 // width of the scrollbar 97#define SCRWIDTH 16 // width of the scrollbar
97 98
98#define yMouseScroll 1 99#define yMouseScroll 1
99// scroll increment used when dragging selection at top/bottom of window. 100// scroll increment used when dragging selection at top/bottom of window.
100 101
101/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
102/* */ 103/* */
103/* Colors */ 104/* Colors */
104/* */ 105/* */
105/* ------------------------------------------------------------------------- */ 106/* ------------------------------------------------------------------------- */
106 107
107//FIXME: the default color table is in session.C now. 108//FIXME: the default color table is in session.C now.
108// We need a way to get rid of this one, here. 109// We need a way to get rid of this one, here.
109static const ColorEntry base_color_table[TABLE_COLORS] = 110static const ColorEntry base_color_table[TABLE_COLORS] =
110// The following are almost IBM standard color codes, with some slight 111// The following are almost IBM standard color codes, with some slight
111// gamma correction for the dim colors to compensate for bright X screens. 112// gamma correction for the dim colors to compensate for bright X screens.
112// It contains the 8 ansiterm/xterm colors in 2 intensities. 113// It contains the 8 ansiterm/xterm colors in 2 intensities.
113{ 114{
114 // Fixme: could add faint colors here, also. 115 // Fixme: could add faint colors here, also.
115 // normal 116 // normal
116 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback 117 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback
117 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red 118 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
118 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow 119 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
119 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta 120 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
120 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White 121 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
121 // intensiv 122 // intensiv
122 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), 123 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),
123 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), 124 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),
124 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), 125 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),
125 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), 126 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ),
126 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) 127 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
127}; 128};
128 129
129/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) 130/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb)
130 131
131 Code 0 1 2 3 4 5 6 7 132 Code 0 1 2 3 4 5 6 7
132 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 133 ----------- ------- ------- ------- ------- ------- ------- ------- -------
133 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 134 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
134 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 135 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
135*/ 136*/
136 137
137QColor TEWidget::getDefaultBackColor() 138QColor TEWidget::getDefaultBackColor()
138{ 139{
139 return color_table[DEFAULT_BACK_COLOR].color; 140 return color_table[DEFAULT_BACK_COLOR].color;
140} 141}
141 142
142const ColorEntry* TEWidget::getColorTable() const 143const ColorEntry* TEWidget::getColorTable() const
143{ 144{
144 return color_table; 145 return color_table;
145} 146}
146 147
147const ColorEntry* TEWidget::getdefaultColorTable() const 148const ColorEntry* TEWidget::getdefaultColorTable() const
148{ 149{
149 return base_color_table; 150 return base_color_table;
150} 151}
151 152
152 153
153const QPixmap *TEWidget::backgroundPixmap() 154const QPixmap *TEWidget::backgroundPixmap()
154{ 155{
155 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 156 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
156 const QPixmap *pm = bg; 157 const QPixmap *pm = bg;
157 return pm; 158 return pm;
158} 159}
159 160
160void TEWidget::setColorTable(const ColorEntry table[]) 161void TEWidget::setColorTable(const ColorEntry table[])
161{ 162{
162 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; 163 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];
163 164
164 const QPixmap* pm = backgroundPixmap(); 165 const QPixmap* pm = backgroundPixmap();
165 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); 166 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
166 update(); 167 update();
167} 168}
168 169
169//FIXME: add backgroundPixmapChanged. 170//FIXME: add backgroundPixmapChanged.
170 171
171/* ------------------------------------------------------------------------- */ 172/* ------------------------------------------------------------------------- */
172/* */ 173/* */
173/* Font */ 174/* Font */
174/* */ 175/* */
175/* ------------------------------------------------------------------------- */ 176/* ------------------------------------------------------------------------- */
176 177
177/* 178/*
178 The VT100 has 32 special graphical characters. The usual vt100 extended 179 The VT100 has 32 special graphical characters. The usual vt100 extended
179 xterm fonts have these at 0x00..0x1f. 180 xterm fonts have these at 0x00..0x1f.
180 181
181 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals 182 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals
182 come in here as proper unicode characters. 183 come in here as proper unicode characters.
183 184
184 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping 185 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping
185 from unicode to 0x00..0x1f. The remaining translation is then left to the 186 from unicode to 0x00..0x1f. The remaining translation is then left to the
186 QCodec. 187 QCodec.
187*/ 188*/
188 189
189// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. 190// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.
190 191
191unsigned short vt100_graphics[32] = 192unsigned short vt100_graphics[32] =
192{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 193{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15
193 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 194 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
194 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 195 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
195 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 196 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
196 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 197 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
197}; 198};
198 199
199static QChar vt100extended(QChar c) 200static QChar vt100extended(QChar c)
200{ 201{
201 switch (c.unicode()) 202 switch (c.unicode())
202 { 203 {
203 case 0x25c6 : return 1; 204 case 0x25c6 : return 1;
204 case 0x2592 : return 2; 205 case 0x2592 : return 2;
205 case 0x2409 : return 3; 206 case 0x2409 : return 3;
206 case 0x240c : return 4; 207 case 0x240c : return 4;
207 case 0x240d : return 5; 208 case 0x240d : return 5;
208 case 0x240a : return 6; 209 case 0x240a : return 6;
209 case 0x00b0 : return 7; 210 case 0x00b0 : return 7;
210 case 0x00b1 : return 8; 211 case 0x00b1 : return 8;
211 case 0x2424 : return 9; 212 case 0x2424 : return 9;
212 case 0x240b : return 10; 213 case 0x240b : return 10;
213 case 0x2518 : return 11; 214 case 0x2518 : return 11;
214 case 0x2510 : return 12; 215 case 0x2510 : return 12;
215 case 0x250c : return 13; 216 case 0x250c : return 13;
216 case 0x2514 : return 14; 217 case 0x2514 : return 14;
217 case 0x253c : return 15; 218 case 0x253c : return 15;
218 case 0xf800 : return 16; 219 case 0xf800 : return 16;
219 case 0xf801 : return 17; 220 case 0xf801 : return 17;
220 case 0x2500 : return 18; 221 case 0x2500 : return 18;
221 case 0xf803 : return 19; 222 case 0xf803 : return 19;
222 case 0xf804 : return 20; 223 case 0xf804 : return 20;
223 case 0x251c : return 21; 224 case 0x251c : return 21;
224 case 0x2524 : return 22; 225 case 0x2524 : return 22;
225 case 0x2534 : return 23; 226 case 0x2534 : return 23;
226 case 0x252c : return 24; 227 case 0x252c : return 24;
227 case 0x2502 : return 25; 228 case 0x2502 : return 25;
228 case 0x2264 : return 26; 229 case 0x2264 : return 26;
229 case 0x2265 : return 27; 230 case 0x2265 : return 27;
230 case 0x03c0 : return 28; 231 case 0x03c0 : return 28;
231 case 0x2260 : return 29; 232 case 0x2260 : return 29;
232 case 0x00a3 : return 30; 233 case 0x00a3 : return 30;
233 case 0x00b7 : return 31; 234 case 0x00b7 : return 31;
234 } 235 }
235 return c; 236 return c;
236} 237}
237 238
238static QChar identicalMap(QChar c) 239static QChar identicalMap(QChar c)
239{ 240{
240 return c; 241 return c;
241} 242}
242 243
243void TEWidget::fontChange(const QFont &) 244void TEWidget::fontChange(const QFont &)
244{ 245{
245 QFontMetrics fm(font()); 246 QFontMetrics fm(font());
246 font_h = fm.height(); 247 font_h = fm.height();
247 248 // font_w = fm.maxWidth();
248 // font_w = max width of ASCII chars (U.B.) 249 font_w = fm.width("m");
249 font_w = 0; 250 font_a = fm.ascent();
250 int fw; 251 printf("font h=%d max_width=%d width_m=%d assent=%d\n", font_h,
251 for (int i = 0x20; i < 0x80; i++) { 252 fm.maxWidth(), font_w, font_a);
252 if (isprint(i) && font_w < (fw = fm.width(i))) { 253
253 font_w = fw; 254 //printf("font_h: %d\n",font_h);
254 } 255 //printf("font_w: %d\n",font_w);
255 } 256 //printf("font_a: %d\n",font_a);
256 //font_w = fm.maxWidth(); 257 //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
257 258 //printf("rawname: %s\n",font().rawName().ascii());
258 font_a = fm.ascent();
259//printf("font_h: %d\n",font_h);
260//printf("font_w: %d\n",font_w);
261//printf("font_a: %d\n",font_a);
262//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
263//printf("rawname: %s\n",font().rawName().ascii());
264 fontMap = 259 fontMap =
265#if QT_VERSION < 300 260#if QT_VERSION < 300
266 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 261 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
267 ? vt100extended 262 ? vt100extended
268 : 263 :
269#endif 264#endif
270 identicalMap; 265 identicalMap;
271 propagateSize(); 266 propagateSize();
272 update(); 267 update();
273} 268}
274 269
275void TEWidget::setVTFont(const QFont& f) 270void TEWidget::setVTFont(const QFont& f)
276{ 271{
277 QFrame::setFont(f); 272 QFrame::setFont(f);
278} 273}
279 274
280QFont TEWidget::getVTFont() { 275QFont TEWidget::getVTFont() {
281 return font(); 276 return font();
282} 277}
283 278
284void TEWidget::setFont(const QFont &) 279void TEWidget::setFont(const QFont &)
285{ 280{
286 // ignore font change request if not coming from konsole itself 281 // ignore font change request if not coming from konsole itself
287} 282}
288 283
289/* ------------------------------------------------------------------------- */ 284/* ------------------------------------------------------------------------- */
290/* */ 285/* */
291/* Constructor / Destructor */ 286/* Constructor / Destructor */
292/* */ 287/* */
293/* ------------------------------------------------------------------------- */ 288/* ------------------------------------------------------------------------- */
294 289
295TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 290TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
296{ 291{
297#ifndef QT_NO_CLIPBOARD 292#ifndef QT_NO_CLIPBOARD
298 cb = QApplication::clipboard(); 293 cb = QApplication::clipboard();
299 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 294 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
300 this, SLOT(onClearSelection()) ); 295 this, SLOT(onClearSelection()) );
301#endif 296#endif
302 297
303 scrollbar = new QScrollBar(this); 298 scrollbar = new QScrollBar(this);
304 scrollbar->setCursor( arrowCursor ); 299 scrollbar->setCursor( arrowCursor );
305 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 300 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
306 301
307 hScrollbar = new QScrollBar(this); 302 hScrollbar = new QScrollBar(this);
308 hScrollbar->setCursor( arrowCursor ); 303 hScrollbar->setCursor( arrowCursor );
309 hScrollbar->setOrientation(QScrollBar::Horizontal); 304 hScrollbar->setOrientation(QScrollBar::Horizontal);
310 hScrollbar->setMaximumHeight(16); 305 // hScrollbar->setMaximumHeight(16);
311 306
312 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); 307 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int)));
313 308
314 Config cfg("Konsole"); 309 Config cfg("Qkonsole");
315 cfg.setGroup("ScrollBar"); 310 cfg.setGroup("ScrollBar");
316 switch( cfg.readNumEntry("Position",2)){ 311 switch( cfg.readNumEntry("Position",2)){
317 case 0: 312 case 0:
318 scrollLoc = SCRNONE; 313 scrollLoc = SCRNONE;
319 break; 314 break;
320 case 1: 315 case 1:
321 scrollLoc = SCRLEFT; 316 scrollLoc = SCRLEFT;
322 break; 317 break;
323 case 2: 318 case 2:
324 scrollLoc = SCRRIGHT; 319 scrollLoc = SCRRIGHT;
325 break; 320 break;
326 }; 321 };
327 322
328 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 323 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
329 324
330 blinkT = new QTimer(this); 325 blinkT = new QTimer(this);
331 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 326 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
332 // blinking = FALSE; 327 // blinking = FALSE;
333 blinking = TRUE; 328 blinking = TRUE;
334 329
335 resizing = FALSE; 330 resizing = FALSE;
336 actSel = 0; 331 actSel = 0;
337 image = 0; 332 image = 0;
338 lines = 1; 333 lines = 1;
339 columns = 1; 334 columns = 1;
340 font_w = 1; 335 font_w = 1;
341 font_h = 1; 336 font_h = 1;
342 font_a = 1; 337 font_a = 1;
343 word_selection_mode = FALSE; 338 word_selection_mode = FALSE;
344 hposition = 0; 339 hposition = 0;
345 vcolumns = 0; 340 vcolumns = 0;
346 useBeep = true; 341 useBeep = true;
347 342
348 setMouseMarks(TRUE); 343 setMouseMarks(TRUE);
349 setVTFont( QFont("fixed") ); 344 setVTFont( QFont("fixed") );
350 setColorTable(base_color_table); // init color table 345 setColorTable(base_color_table); // init color table
351 346
352 qApp->installEventFilter( this ); //FIXME: see below 347 qApp->installEventFilter( this ); //FIXME: see below
353// KCursor::setAutoHideCursor( this, true ); 348// KCursor::setAutoHideCursor( this, true );
354 349
355 // Init DnD //////////////////////////////////////////////////////////////// 350 // Init DnD ////////////////////////////////////////////////////////////////
356 currentSession = NULL; 351 currentSession = NULL;
357// setAcceptDrops(true); // attempt 352// setAcceptDrops(true); // attempt
358// m_drop = new QPopupMenu(this); 353// m_drop = new QPopupMenu(this);
359// m_drop->insertItem( QString("Paste"), 0); 354// m_drop->insertItem( QString("Paste"), 0);
360// m_drop->insertItem( QString("cd"), 1); 355// m_drop->insertItem( QString("cd"), 1);
361// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 356// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
362 357
363 // we need focus so that the auto-hide cursor feature works 358 // we need focus so that the auto-hide cursor feature works
364 setFocus(); 359 setFocus();
365 setFocusPolicy( WheelFocus ); 360 setFocusPolicy( WheelFocus );
366} 361}
367 362
368//FIXME: make proper destructor 363//FIXME: make proper destructor
369// Here's a start (David) 364// Here's a start (David)
370TEWidget::~TEWidget() 365TEWidget::~TEWidget()
371{ 366{
372 qApp->removeEventFilter( this ); 367 qApp->removeEventFilter( this );
373 if (image) free(image); 368 if (image) free(image);
374} 369}
375 370
376/* ------------------------------------------------------------------------- */ 371/* ------------------------------------------------------------------------- */
377/* */ 372/* */
378/* Display Operations */ 373/* Display Operations */
379/* */ 374/* */
380/* ------------------------------------------------------------------------- */ 375/* ------------------------------------------------------------------------- */
381 376
382/*! 377/*!
383 attributed string draw primitive 378 attributed string draw primitive
384*/ 379*/
385 380
386void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 381void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
387 QString& str, ca attr, BOOL pm, BOOL clear) 382 QString& str, ca attr, BOOL pm, BOOL clear)
388{ 383{
389 if (pm && color_table[attr.b].transparent) 384 if (pm && color_table[attr.b].transparent)
390 { 385 {
391 paint.setBackgroundMode( TransparentMode ); 386 paint.setBackgroundMode( TransparentMode );
392 if (clear) erase(rect); 387 if (clear) erase(rect);
393 } 388 }
394 else 389 else
395 { 390 {
396 if (blinking) 391 if (blinking)
397 paint.fillRect(rect, color_table[attr.b].color); 392 paint.fillRect(rect, color_table[attr.b].color);
398 else 393 else
399 { 394 {
400 paint.setBackgroundMode( OpaqueMode ); 395 paint.setBackgroundMode( OpaqueMode );
401 paint.setBackgroundColor( color_table[attr.b].color ); 396 paint.setBackgroundColor( color_table[attr.b].color );
402 } 397 }
403 } 398 }
404 399
405 if (color_table[attr.f].bold) 400 if (color_table[attr.f].bold)
406 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 401 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
407 else 402 else
408 paint.setPen(color_table[attr.f].color); 403 paint.setPen(color_table[attr.f].color);
409 404
410 paint.drawText(rect.x(),rect.y()+font_a, str); 405 paint.drawText(rect.x(),rect.y()+font_a, str);
411 406
412 if (attr.r & RE_UNDERLINE) 407 if (attr.r & RE_UNDERLINE)
413 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); 408 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
414} 409}
415 410
416/*! 411/*!
417 The image can only be set completely. 412 The image can only be set completely.
418 413
419 The size of the new image may or may not match the size of the widget. 414 The size of the new image may or may not match the size of the widget.
420*/ 415*/
421 416
422void TEWidget::setImage(const ca* const newimg, int lines, int columns) 417void TEWidget::setImage(const ca* const newimg, int lines, int columns)
423{ int y,x,len; 418{ int y,x,len;
424 const QPixmap* pm = backgroundPixmap(); 419 const QPixmap* pm = backgroundPixmap();
425 QPainter paint; 420 QPainter paint;
426 setUpdatesEnabled(FALSE); 421 setUpdatesEnabled(FALSE);
427 paint.begin( this ); 422 paint.begin( this );
428HCNT("setImage"); 423HCNT("setImage");
429 424
430 QPoint tL = contentsRect().topLeft(); 425 QPoint tL = contentsRect().topLeft();
431 int tLx = tL.x(); 426 int tLx = tL.x();
432 int tLy = tL.y(); 427 int tLy = tL.y();
433 hasBlinker = FALSE; 428 hasBlinker = FALSE;
434 429
435 int cf = -1; // undefined 430 int cf = -1; // undefined
436 int cb = -1; // undefined 431 int cb = -1; // undefined
437 int cr = -1; // undefined 432 int cr = -1; // undefined
438 433
439 int lins = QMIN(this->lines, QMAX(0,lines )); 434 int lins = QMIN(this->lines, QMAX(0,lines ));
440 int cols = QMIN(this->columns,QMAX(0,columns)); 435 int cols = QMIN(this->columns,QMAX(0,columns));
441 QChar *disstrU = new QChar[cols]; 436 QChar *disstrU = new QChar[cols];
442 for (y = 0; y < lins; y++) { 437 for (y = 0; y < lins; y++) {
443 const ca* lcl = &image[y*this->columns]; 438 const ca* lcl = &image[y*this->columns];
444 const ca* const ext = &newimg[y*columns]; 439 const ca* const ext = &newimg[y*columns];
445 if (!resizing) // not while resizing, we're expecting a paintEvent 440 if (!resizing) // not while resizing, we're expecting a paintEvent
446 for (x = 0; x < cols; x++) 441 for (x = 0; x < cols; x++)
447 { 442 {
448 hasBlinker |= (ext[x].r & RE_BLINK); 443 hasBlinker |= (ext[x].r & RE_BLINK);
449 if (ext[x] != lcl[x]) 444 if (ext[x] != lcl[x])
450 { 445 {
451 cr = ext[x].r; 446 cr = ext[x].r;
452 cb = ext[x].b; 447 cb = ext[x].b;
453 if (ext[x].f != cf) cf = ext[x].f; 448 if (ext[x].f != cf) cf = ext[x].f;
454 int lln = cols - x; 449 int lln = cols - x;
455 disstrU[0] = fontMap(ext[x+0].c); 450 disstrU[0] = fontMap(ext[x+0].c);
456 for (len = 1; len < lln; len++) 451 for (len = 1; len < lln; len++)
457 { 452 {
458 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || 453 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
459 ext[x+len] == lcl[x+len] ) 454 ext[x+len] == lcl[x+len] )
460 break; 455 break;
461 disstrU[len] = fontMap(ext[x+len].c); 456 disstrU[len] = fontMap(ext[x+len].c);
462 } 457 }
463 QString unistr(disstrU,len); 458 QString unistr(disstrU,len);
464 drawAttrStr(paint, 459 drawAttrStr(paint,
465 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 460 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
466 unistr, ext[x], pm != NULL, true); 461 unistr, ext[x], pm != NULL, true);
467 x += len - 1; 462 x += len - 1;
468 } 463 }
469 } 464 }
470 // finally, make `image' become `newimg'. 465 // finally, make `image' become `newimg'.
471 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 466 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
472 } 467 }
473 drawFrame( &paint ); 468 drawFrame( &paint );
474 paint.end(); 469 paint.end();
475 setUpdatesEnabled(TRUE); 470 setUpdatesEnabled(TRUE);
476 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 471 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
477 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 472 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
478 delete [] disstrU; 473 delete [] disstrU;
479} 474}
480 475
481// paint Event //////////////////////////////////////////////////// 476// paint Event ////////////////////////////////////////////////////
482 477
483/*! 478/*!
484 The difference of this routine vs. the `setImage' is, 479 The difference of this routine vs. the `setImage' is,
485 that the drawing does not include a difference analysis 480 that the drawing does not include a difference analysis
486 between the old and the new image. Instead, the internal 481 between the old and the new image. Instead, the internal
487 image is used and the painting bound by the PaintEvent box. 482 image is used and the painting bound by the PaintEvent box.
488*/ 483*/
489 484
490void TEWidget::paintEvent( QPaintEvent* pe ) 485void TEWidget::paintEvent( QPaintEvent* pe )
491{ 486{
492 487
493//{ static int cnt = 0; printf("paint %d\n",cnt++); } 488//{ static int cnt = 0; printf("paint %d\n",cnt++); }
494 const QPixmap* pm = backgroundPixmap(); 489 const QPixmap* pm = backgroundPixmap();
495 QPainter paint; 490 QPainter paint;
496 setUpdatesEnabled(FALSE); 491 setUpdatesEnabled(FALSE);
497 paint.begin( this ); 492 paint.begin( this );
498 paint.setBackgroundMode( TransparentMode ); 493 paint.setBackgroundMode( TransparentMode );
499HCNT("paintEvent"); 494HCNT("paintEvent");
500 495
501 // Note that the actual widget size can be slightly larger 496 // Note that the actual widget size can be slightly larger
502 // that the image (the size is truncated towards the smaller 497 // that the image (the size is truncated towards the smaller
503 // number of characters in `resizeEvent'. The paint rectangle 498 // number of characters in `resizeEvent'. The paint rectangle
504 // can thus be larger than the image, but less then the size 499 // can thus be larger than the image, but less then the size
505 // of one character. 500 // of one character.
506 501
507 QRect rect = pe->rect().intersect(contentsRect()); 502 QRect rect = pe->rect().intersect(contentsRect());
508 503
509 QPoint tL = contentsRect().topLeft(); 504 QPoint tL = contentsRect().topLeft();
510 int tLx = tL.x(); 505 int tLx = tL.x();
511 int tLy = tL.y(); 506 int tLy = tL.y();
512 507
513 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); 508 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
514 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); 509 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
515 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); 510 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
516 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); 511 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
517 512
518 /* 513 /*
519 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, 514 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
520 rect.left(), rect.right(), rect.top(), rect.bottom()); 515 rect.left(), rect.right(), rect.top(), rect.bottom());
521 */ 516 */
522 517
523 // if (pm != NULL && color_table[image->b].transparent) 518 // if (pm != NULL && color_table[image->b].transparent)
524 // erase(rect); 519 // erase(rect);
525 // BL: I have no idea why we need this, and it breaks the refresh. 520 // BL: I have no idea why we need this, and it breaks the refresh.
526 521
527 QChar *disstrU = new QChar[columns]; 522 QChar *disstrU = new QChar[columns];
528 for (int y = luy; y <= rly; y++) 523 for (int y = luy; y <= rly; y++)
529 for (int x = lux; x <= rlx; x++) 524 for (int x = lux; x <= rlx; x++)
530 { 525 {
531 int len = 1; 526 int len = 1;
532 disstrU[0] = fontMap(image[loc(x,y)].c); 527 disstrU[0] = fontMap(image[loc(x,y)].c);
533 int cf = image[loc(x,y)].f; 528 int cf = image[loc(x,y)].f;
534 int cb = image[loc(x,y)].b; 529 int cb = image[loc(x,y)].b;
535 int cr = image[loc(x,y)].r; 530 int cr = image[loc(x,y)].r;
536 while (x+len <= rlx && 531 while (x+len <= rlx &&
537 image[loc(x+len,y)].f == cf && 532 image[loc(x+len,y)].f == cf &&
538 image[loc(x+len,y)].b == cb && 533 image[loc(x+len,y)].b == cb &&
539 image[loc(x+len,y)].r == cr ) 534 image[loc(x+len,y)].r == cr )
540 { 535 {
541 disstrU[len] = fontMap(image[loc(x+len,y)].c); 536 disstrU[len] = fontMap(image[loc(x+len,y)].c);
542 len += 1; 537 len += 1;
543 } 538 }
544 QString unistr(disstrU,len); 539 QString unistr(disstrU,len);
545 drawAttrStr(paint, 540 drawAttrStr(paint,
546 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 541 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
547 unistr, image[loc(x,y)], pm != NULL, false); 542 unistr, image[loc(x,y)], pm != NULL, false);
548 x += len - 1; 543 x += len - 1;
549 } 544 }
550 delete [] disstrU; 545 delete [] disstrU;
551 drawFrame( &paint ); 546 drawFrame( &paint );
552 paint.end(); 547 paint.end();
553 setUpdatesEnabled(TRUE); 548 setUpdatesEnabled(TRUE);
554} 549}
555 550
556void TEWidget::blinkEvent() 551void TEWidget::blinkEvent()
557{ 552{
558 blinking = !blinking; 553 blinking = !blinking;
559 repaint(FALSE); 554 repaint(FALSE);
560} 555}
561 556
562/* ------------------------------------------------------------------------- */ 557/* ------------------------------------------------------------------------- */
563/* */ 558/* */
564/* Resizing */ 559/* Resizing */
565/* */ 560/* */
566/* ------------------------------------------------------------------------- */ 561/* ------------------------------------------------------------------------- */
567 562
568void TEWidget::resizeEvent(QResizeEvent* ev) 563void TEWidget::resizeEvent(QResizeEvent* ev)
569{ 564{
570// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 565// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
571 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); 566 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
572 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); 567 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
573 //printf("curren: %d,%d\n",width(),height()); 568 //printf("curren: %d,%d\n",width(),height());
574HCNT("resizeEvent"); 569HCNT("resizeEvent");
575 570
576 // see comment in `paintEvent' concerning the rounding. 571 // see comment in `paintEvent' concerning the rounding.
577 //FIXME: could make a routine here; check width(),height() 572 //FIXME: could make a routine here; check width(),height()
578 assert(ev->size().width() == width()); 573 assert(ev->size().width() == width());
579 assert(ev->size().height() == height()); 574 assert(ev->size().height() == height());
580 575
581 propagateSize(); 576 propagateSize();
582} 577}
583 578
584void TEWidget::propagateSize() 579void TEWidget::propagateSize()
585{ 580{
586 ca* oldimg = image; 581 ca* oldimg = image;
587 int oldlin = lines; 582 int oldlin = lines;
588 int oldcol = columns; 583 int oldcol = columns;
589 makeImage(); 584 makeImage();
590 // we copy the old image to reduce flicker 585 // we copy the old image to reduce flicker
591 int lins = QMIN(oldlin,lines); 586 int lins = QMIN(oldlin,lines);
592 int cols = QMIN(oldcol,columns); 587 int cols = QMIN(oldcol,columns);
593 if (oldimg) 588 if (oldimg)
594 { 589 {
595 for (int lin = 0; lin < lins; lin++) 590 for (int lin = 0; lin < lins; lin++)
596 memcpy((void*)&image[columns*lin], 591 memcpy((void*)&image[columns*lin],
597 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 592 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
598 free(oldimg); //FIXME: try new,delete 593 free(oldimg); //FIXME: try new,delete
599 } 594 }
600 else 595 else
601 clearImage(); 596 clearImage();
602 597
603 //NOTE: control flows from the back through the chest right into the eye. 598 //NOTE: control flows from the back through the chest right into the eye.
604 // `emu' will call back via `setImage'. 599 // `emu' will call back via `setImage'.
605 600
606 resizing = TRUE; 601 resizing = TRUE;
607 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 602 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
608 resizing = FALSE; 603 resizing = FALSE;
609} 604}
610 605
611/* ------------------------------------------------------------------------- */ 606/* ------------------------------------------------------------------------- */
612/* */ 607/* */
613/* Scrollbar */ 608/* Scrollbar */
614/* */ 609/* */
615/* ------------------------------------------------------------------------- */ 610/* ------------------------------------------------------------------------- */
616 611
617void TEWidget::scrollChanged(int) { 612void TEWidget::scrollChanged(int) {
618 emit changedHistoryCursor(scrollbar->value()); //expose 613 emit changedHistoryCursor(scrollbar->value()); //expose
619} 614}
620 615
621void TEWidget::hScrollChanged(int loc) { 616void TEWidget::hScrollChanged(int loc) {
622 hposition = loc; 617 hposition = loc;
623 propagateSize(); 618 propagateSize();
624 update(); 619 update();
625 620
626// emit changedHorzCursor( hScrollbar->value()); //expose 621// emit changedHorzCursor( hScrollbar->value()); //expose
627} 622}
628 623
629void TEWidget::setScroll(int cursor, int slines) 624void TEWidget::setScroll(int cursor, int slines)
630{ 625{
631 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 626 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
632 scrollbar->setRange(0,slines); 627 scrollbar->setRange(0,slines);
633 scrollbar->setSteps(1,lines); 628 scrollbar->setSteps(1,lines);
634 scrollbar->setValue(cursor); 629 scrollbar->setValue(cursor);
635 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 630 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
636} 631}
637 632
638void TEWidget::setScrollbarLocation(int loc) 633void TEWidget::setScrollbarLocation(int loc)
639{ 634{
640 if (scrollLoc == loc) return; // quickly 635 if (scrollLoc == loc) return; // quickly
641 scrollLoc = loc; 636 scrollLoc = loc;
642 propagateSize(); 637 propagateSize();
643 update(); 638 update();
644} 639}
645 640
646/* ------------------------------------------------------------------------- */ 641/* ------------------------------------------------------------------------- */
647/* */ 642/* */
648/* Mouse */ 643/* Mouse */
649/* */ 644/* */
650/* ------------------------------------------------------------------------- */ 645/* ------------------------------------------------------------------------- */
651 646
652/*! 647/*!
653 Three different operations can be performed using the mouse, and the 648 Three different operations can be performed using the mouse, and the
654 routines in this section serve all of them: 649 routines in this section serve all of them:
655 650
656 1) The press/release events are exposed to the application 651 1) The press/release events are exposed to the application
657 2) Marking (press and move left button) and Pasting (press middle button) 652 2) Marking (press and move left button) and Pasting (press middle button)
658 3) The right mouse button is used from the configuration menu 653 3) The right mouse button is used from the configuration menu
659 654
660 NOTE: During the marking process we attempt to keep the cursor within 655 NOTE: During the marking process we attempt to keep the cursor within
661 the bounds of the text as being displayed by setting the mouse position 656 the bounds of the text as being displayed by setting the mouse position
662 whenever the mouse has left the text area. 657 whenever the mouse has left the text area.
663 658
664 Two reasons to do so: 659 Two reasons to do so:
665 1) QT does not allow the `grabMouse' to confine-to the TEWidget. 660 1) QT does not allow the `grabMouse' to confine-to the TEWidget.
666 Thus a `XGrapPointer' would have to be used instead. 661 Thus a `XGrapPointer' would have to be used instead.
667 2) Even if so, this would not help too much, since the text area 662 2) Even if so, this would not help too much, since the text area
668 of the TEWidget is normally not identical with it's bounds. 663 of the TEWidget is normally not identical with it's bounds.
669 664
670 The disadvantage of the current handling is, that the mouse can visibly 665 The disadvantage of the current handling is, that the mouse can visibly
671 leave the bounds of the widget and is then moved back. Because of the 666 leave the bounds of the widget and is then moved back. Because of the
672 current construction, and the reasons mentioned above, we cannot do better 667 current construction, and the reasons mentioned above, we cannot do better
673 without changing the overall construction. 668 without changing the overall construction.
674*/ 669*/
675 670
676/*! 671/*!
677*/ 672*/
678 673
679void TEWidget::mousePressEvent(QMouseEvent* ev) 674void TEWidget::mousePressEvent(QMouseEvent* ev)
680{ 675{
681//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 676//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
682 if ( !contentsRect().contains(ev->pos()) ) return; 677 if ( !contentsRect().contains(ev->pos()) ) return;
683 QPoint tL = contentsRect().topLeft(); 678 QPoint tL = contentsRect().topLeft();
684 int tLx = tL.x(); 679 int tLx = tL.x();
685 int tLy = tL.y(); 680 int tLy = tL.y();
686 681
687 word_selection_mode = FALSE; 682 mouse_down_x = ev->x();
683 mouse_down_y = ev->y();
688 684
689//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 685//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
690 if ( ev->button() == LeftButton) 686 if ( ev->button() == LeftButton)
691 { 687 {
692 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 688 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
693 689
690 word_selection_mode = (ev->state() & ShiftButton);
691
694 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 692 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
695 693
696 if (mouse_marks || (ev->state() & ShiftButton)) 694 if (mouse_marks || (ev->state() & ShiftButton))
697 { 695 {
698 emit clearSelectionSignal(); 696 emit clearSelectionSignal();
699 iPntSel = pntSel = pos; 697 iPntSel = pntSel = pos;
700 actSel = 1; // left mouse button pressed but nothing selected yet. 698 actSel = 1; // left mouse button pressed but nothing selected yet.
701 grabMouse( /*crossCursor*/ ); // handle with care! 699 grabMouse( /*crossCursor*/ ); // handle with care!
702 } 700 }
703 else 701 else
704 { 702 {
705 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 703 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
706 } 704 }
707 } 705 }
708 if ( ev->button() == MidButton ) 706 if ( ev->button() == MidButton )
709 { 707 {
710 emitSelection(); 708 emitSelection();
711 } 709 }
712 if ( ev->button() == RightButton ) // Configure 710 if ( ev->button() == RightButton ) // Configure
713 { 711 {
714 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 712 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
715 } 713 }
716} 714}
717 715
718void TEWidget::mouseMoveEvent(QMouseEvent* ev) 716void TEWidget::mouseMoveEvent(QMouseEvent* ev)
719{ 717{
720 // for auto-hiding the cursor, we need mouseTracking 718 // for auto-hiding the cursor, we need mouseTracking
721 if (ev->state() == NoButton ) return; 719 if (ev->state() == NoButton ) return;
722 720
723 if (actSel == 0) return; 721 if (actSel == 0) return;
724 722
725 // don't extend selection while pasting 723 // don't extend selection while pasting
726 if (ev->state() & MidButton) return; 724 if (ev->state() & MidButton) return;
727 725
728 //if ( !contentsRect().contains(ev->pos()) ) return; 726 //if ( !contentsRect().contains(ev->pos()) ) return;
729 QPoint tL = contentsRect().topLeft(); 727 QPoint tL = contentsRect().topLeft();
730 int tLx = tL.x(); 728 int tLx = tL.x();
731 int tLy = tL.y(); 729 int tLy = tL.y();
732 int scroll = scrollbar->value(); 730 int scroll = scrollbar->value();
733// int hScroll = hScrollbar->value(); 731// int hScroll = hScrollbar->value();
734 732
735 // we're in the process of moving the mouse with the left button pressed 733 // we're in the process of moving the mouse with the left button pressed
736 // the mouse cursor will kept catched within the bounds of the text in 734 // the mouse cursor will kept catched within the bounds of the text in
737 // this widget. 735 // this widget.
738 736
739 // Adjust position within text area bounds. See FIXME above. 737 // Adjust position within text area bounds. See FIXME above.
740 QPoint pos = ev->pos(); 738 QPoint pos = ev->pos();
741 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 739 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
742 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); 740 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
743 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 741 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
744 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); 742 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
745 // check if we produce a mouse move event by this 743 // check if we produce a mouse move event by this
746 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 744 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
747 745
748 if ( pos.y() == tLy+bY+lines*font_h-1 ) 746 if ( pos.y() == tLy+bY+lines*font_h-1 )
749 { 747 {
750 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 748 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
751 } 749 }
752 if ( pos.y() == tLy+bY ) 750 if ( pos.y() == tLy+bY )
753 { 751 {
754 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 752 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
755 } 753 }
756 754
757 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 755 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
758 QPoint ohere; 756 QPoint ohere;
759 bool swapping = FALSE; 757 bool swapping = FALSE;
760 758
761 if ( word_selection_mode ) 759 if ( word_selection_mode )
762 { 760 {
763 // Extend to word boundaries 761 // Extend to word boundaries
764 int i; 762 int i;
765 int selClass; 763 int selClass;
766 764
767 bool left_not_right = ( here.y() < iPntSel.y() || 765 bool left_not_right = ( here.y() < iPntSel.y() ||
768 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 766 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
769 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 767 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
770 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 768 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
771 swapping = left_not_right != old_left_not_right; 769 swapping = left_not_right != old_left_not_right;
772 770
773 // Find left (left_not_right ? from here : from start) 771 // Find left (left_not_right ? from here : from start)
774 QPoint left = left_not_right ? here : iPntSel; 772 QPoint left = left_not_right ? here : iPntSel;
775 i = loc(left.x(),left.y()); 773 i = loc(left.x(),left.y());
776 selClass = charClass(image[i].c); 774 selClass = charClass(image[i].c);
777 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 775 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
778 { i--; left.rx()--; } 776 { i--; left.rx()--; }
779 777
780 // Find left (left_not_right ? from start : from here) 778 // Find left (left_not_right ? from start : from here)
781 QPoint right = left_not_right ? iPntSel : here; 779 QPoint right = left_not_right ? iPntSel : here;
782 i = loc(right.x(),right.y()); 780 i = loc(right.x(),right.y());
783 selClass = charClass(image[i].c); 781 selClass = charClass(image[i].c);
784 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 782 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
785 { i++; right.rx()++; } 783 { i++; right.rx()++; }
786 784
787 // Pick which is start (ohere) and which is extension (here) 785 // Pick which is start (ohere) and which is extension (here)
788 if ( left_not_right ) 786 if ( left_not_right )
789 { 787 {
790 here = left; ohere = right; 788 here = left; ohere = right;
791 } 789 }
792 else 790 else
793 { 791 {
794 here = right; ohere = left; 792 here = right; ohere = left;
795 } 793 }
796 } 794 }
797 795
798 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 796 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
799 797
800 if ( word_selection_mode ) { 798 if ( word_selection_mode ) {
801 if ( actSel < 2 || swapping ) { 799 if ( actSel < 2 || swapping ) {
802 emit beginSelectionSignal( ohere.x(), ohere.y() ); 800 emit beginSelectionSignal( ohere.x(), ohere.y() );
803 } 801 }
804 } else if ( actSel < 2 ) { 802 } else if ( actSel < 2 ) {
805 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 803 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
806 } 804 }
807 805
808 actSel = 2; // within selection 806 actSel = 2; // within selection
809 pntSel = here; 807 pntSel = here;
810 emit extendSelectionSignal( here.x(), here.y() ); 808 emit extendSelectionSignal( here.x(), here.y() );
811} 809}
812 810
813void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 811void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
814{ 812{
815//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 813//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
816 if ( ev->button() == LeftButton) 814 if ( ev->button() == LeftButton)
817 { 815 {
816 if (QABS(ev->x() - mouse_down_x) < 3
817 && QABS(ev->y() - mouse_down_y) < 3
818 && ev->y() < qApp->desktop()->height()/8) {
819 emit setFullScreen(false);
820 }
821
818 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 822 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
819 preserve_line_breaks = TRUE; 823 preserve_line_breaks = TRUE;
820 actSel = 0; 824 actSel = 0;
821 825
822 //FIXME: emits a release event even if the mouse is 826 //FIXME: emits a release event even if the mouse is
823 // outside the range. The procedure used in `mouseMoveEvent' 827 // outside the range. The procedure used in `mouseMoveEvent'
824 // applies here, too. 828 // applies here, too.
825 829
826 QPoint tL = contentsRect().topLeft(); 830 QPoint tL = contentsRect().topLeft();
827 int tLx = tL.x(); 831 int tLx = tL.x();
828 int tLy = tL.y(); 832 int tLy = tL.y();
829 833
830 if (!mouse_marks && !(ev->state() & ShiftButton)) 834 if (!mouse_marks && !(ev->state() & ShiftButton))
831 emit mouseSignal( 3, // release 835 emit mouseSignal( 3, // release
832 (ev->x()-tLx-blX)/font_w + 1, 836 (ev->x()-tLx-blX)/font_w + 1,
833 (ev->y()-tLy-bY)/font_h + 1 ); 837 (ev->y()-tLy-bY)/font_h + 1 );
834 releaseMouse(); 838 releaseMouse();
835 } 839 }
836} 840}
837 841
838void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 842void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
839{ 843{
840 if ( ev->button() != LeftButton) return; 844 if ( ev->button() != LeftButton) return;
841 845
842 QPoint tL = contentsRect().topLeft(); 846 QPoint tL = contentsRect().topLeft();
843 int tLx = tL.x(); 847 int tLx = tL.x();
844 int tLy = tL.y(); 848 int tLy = tL.y();
845 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 849 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
846 850
847 // pass on double click as two clicks. 851 // pass on double click as two clicks.
848 if (!mouse_marks && !(ev->state() & ShiftButton)) 852 if (!mouse_marks && !(ev->state() & ShiftButton))
849 { 853 {
850 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 854 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
851 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 855 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
852 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 856 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
853 return; 857 return;
854 } 858 }
855 859
856 860
857 emit clearSelectionSignal(); 861 emit clearSelectionSignal();
858 QPoint bgnSel = pos; 862 QPoint bgnSel = pos;
859 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 863 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
860 int i = loc(bgnSel.x(),bgnSel.y()); 864 int i = loc(bgnSel.x(),bgnSel.y());
861 iPntSel = bgnSel; 865 iPntSel = bgnSel;
862 866
863 word_selection_mode = TRUE; 867 word_selection_mode = TRUE;
864 868
865 // find word boundaries... 869 // find word boundaries...
866 int selClass = charClass(image[i].c); 870 int selClass = charClass(image[i].c);
867 { 871 {
868 // set the start... 872 // set the start...
869 int x = bgnSel.x(); 873 int x = bgnSel.x();
870 while ( x > 0 && charClass(image[i-1].c) == selClass ) 874 while ( x > 0 && charClass(image[i-1].c) == selClass )
871 { i--; x--; } 875 { i--; x--; }
872 bgnSel.setX(x); 876 bgnSel.setX(x);
873 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 877 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
874 878
875 // set the end... 879 // set the end...
876 i = loc( endSel.x(), endSel.y() ); 880 i = loc( endSel.x(), endSel.y() );
877 x = endSel.x(); 881 x = endSel.x();
878 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 882 while( x < columns-1 && charClass(image[i+1].c) == selClass )
879 { i++; x++ ; } 883 { i++; x++ ; }
880 endSel.setX(x); 884 endSel.setX(x);
881 actSel = 2; // within selection 885 actSel = 2; // within selection
882 emit extendSelectionSignal( endSel.x(), endSel.y() ); 886 emit extendSelectionSignal( endSel.x(), endSel.y() );
883 emit endSelectionSignal(preserve_line_breaks); 887 emit endSelectionSignal(preserve_line_breaks);
884 preserve_line_breaks = TRUE; 888 preserve_line_breaks = TRUE;
885 } 889 }
886} 890}
887 891
888void TEWidget::focusInEvent( QFocusEvent * ) 892void TEWidget::focusInEvent( QFocusEvent * )
889{ 893{
890 894
891 // do nothing, to prevent repainting 895 // do nothing, to prevent repainting
892} 896}
893 897
894 898
895void TEWidget::focusOutEvent( QFocusEvent * ) 899void TEWidget::focusOutEvent( QFocusEvent * )
896{ 900{
897 // do nothing, to prevent repainting 901 // do nothing, to prevent repainting
898} 902}
899 903
900bool TEWidget::focusNextPrevChild( bool next ) 904bool TEWidget::focusNextPrevChild( bool next )
901{ 905{
902 if (next) 906 if (next)
903 return false; // This disables changing the active part in konqueror 907 return false; // This disables changing the active part in konqueror
904 // when pressing Tab 908 // when pressing Tab
905 return QFrame::focusNextPrevChild( next ); 909 return QFrame::focusNextPrevChild( next );
906} 910}
907 911
908 912
909int TEWidget::charClass(char ch) const 913int TEWidget::charClass(char ch) const
910{ 914{
911 // This might seem like overkill, but imagine if ch was a Unicode 915 // This might seem like overkill, but imagine if ch was a Unicode
912 // character (Qt 2.0 QChar) - it might then be sensible to separate 916 // character (Qt 2.0 QChar) - it might then be sensible to separate
913 // the different language ranges, etc. 917 // the different language ranges, etc.
914 918
915 if ( isspace(ch) ) return ' '; 919 if ( isspace(ch) ) return ' ';
916 920
917 static const char *word_characters = ":@-./_~"; 921 static const char *word_characters = ":@-./_~";
918 if ( isalnum(ch) || strchr(word_characters, ch) ) 922 if ( isalnum(ch) || strchr(word_characters, ch) )
919 return 'a'; 923 return 'a';
920 924
921 // Everything else is weird 925 // Everything else is weird
922 return 1; 926 return 1;
923} 927}
924 928
925void TEWidget::setMouseMarks(bool on) 929void TEWidget::setMouseMarks(bool on)
926{ 930{
927 mouse_marks = on; 931 mouse_marks = on;
928 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 932 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
929} 933}
930 934
931/* ------------------------------------------------------------------------- */ 935/* ------------------------------------------------------------------------- */
932/* */ 936/* */
933/* Clipboard */ 937/* Clipboard */
934/* */ 938/* */
935/* ------------------------------------------------------------------------- */ 939/* ------------------------------------------------------------------------- */
936 940
937#undef KeyPress 941#undef KeyPress
938 942
939void TEWidget::emitSelection() 943void TEWidget::emitSelection()
940// Paste Clipboard by simulating keypress events 944// Paste Clipboard by simulating keypress events
941{ 945{
942#ifndef QT_NO_CLIPBOARD 946#ifndef QT_NO_CLIPBOARD
943 QString text = QApplication::clipboard()->text(); 947 QString text = QApplication::clipboard()->text();
944 //qDebug(text); 948 //qDebug(text);
945 if ( ! text.isNull()) 949 if ( ! text.isNull())
946 { 950 {
947 text.replace(QRegExp("\n"), "\r"); 951 text.replace(QRegExp("\n"), "\r");
948 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 952 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
949 emit keyPressedSignal(&e); // expose as a big fat keypress event 953 emit keyPressedSignal(&e); // expose as a big fat keypress event
950 emit clearSelectionSignal(); 954 emit clearSelectionSignal();
951 } 955 }
952#endif 956#endif
953} 957}
954 958
955void TEWidget::emitText(QString text) 959void TEWidget::emitText(QString text)
956{ 960{
957 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 961 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
958 emit keyPressedSignal(&e); // expose as a big fat keypress event 962 emit keyPressedSignal(&e); // expose as a big fat keypress event
959} 963}
960 964
961void TEWidget::pasteClipboard( ) 965void TEWidget::pasteClipboard( )
962{ 966{
963 emitSelection(); 967 emitSelection();
964} 968}
965 969
966void TEWidget::setSelection(const QString& t) 970void TEWidget::setSelection(const QString& t)
967{ 971{
968#ifndef QT_NO_CLIPBOARD 972#ifndef QT_NO_CLIPBOARD
969 // Disconnect signal while WE set the clipboard 973 // Disconnect signal while WE set the clipboard
970 QObject *cb = QApplication::clipboard(); 974 QObject *cb = QApplication::clipboard();
971 QObject::disconnect( cb, SIGNAL(dataChanged()), 975 QObject::disconnect( cb, SIGNAL(dataChanged()),
972 this, SLOT(onClearSelection()) ); 976 this, SLOT(onClearSelection()) );
973 977
974 QApplication::clipboard()->setText(t); 978 QApplication::clipboard()->setText(t);
975 979
976 QObject::connect( cb, SIGNAL(dataChanged()), 980 QObject::connect( cb, SIGNAL(dataChanged()),
977 this, SLOT(onClearSelection()) ); 981 this, SLOT(onClearSelection()) );
978#endif 982#endif
979} 983}
980 984
981void TEWidget::onClearSelection() 985void TEWidget::onClearSelection()
982{ 986{
983 emit clearSelectionSignal(); 987 emit clearSelectionSignal();
984} 988}
985 989
986/* ------------------------------------------------------------------------- */ 990/* ------------------------------------------------------------------------- */
987/* */ 991/* */
988/* Keyboard */ 992/* Keyboard */
989/* */ 993/* */
990/* ------------------------------------------------------------------------- */ 994/* ------------------------------------------------------------------------- */
991 995
992//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 996//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
993// due to a bug in `QT' or the ignorance of the author to prevent 997// due to a bug in `QT' or the ignorance of the author to prevent
994// repaint events being emitted to the screen whenever one leaves 998// repaint events being emitted to the screen whenever one leaves
995// or reenters the screen to/from another application. 999// or reenters the screen to/from another application.
996// 1000//
997// Troll says one needs to change focusInEvent() and focusOutEvent(), 1001// Troll says one needs to change focusInEvent() and focusOutEvent(),
998// which would also let you have an in-focus cursor and an out-focus 1002// which would also let you have an in-focus cursor and an out-focus
999// cursor like xterm does. 1003// cursor like xterm does.
1000 1004
1001// for the auto-hide cursor feature, I added empty focusInEvent() and 1005// for the auto-hide cursor feature, I added empty focusInEvent() and
1002// focusOutEvent() so that update() isn't called. 1006// focusOutEvent() so that update() isn't called.
1003// For auto-hide, we need to get keypress-events, but we only get them when 1007// For auto-hide, we need to get keypress-events, but we only get them when
1004// we have focus. 1008// we have focus.
1005 1009
1006void TEWidget::doScroll(int lines) 1010void TEWidget::doScroll(int lines)
1007{ 1011{
1008 scrollbar->setValue(scrollbar->value()+lines); 1012 scrollbar->setValue(scrollbar->value()+lines);
1009} 1013}
1010 1014
1011void TEWidget::doHScroll(int lines) { 1015void TEWidget::doHScroll(int lines) {
1012 hScrollbar->setValue( hScrollbar->value()+lines); 1016 hScrollbar->setValue( hScrollbar->value()+lines);
1013} 1017}
1014 1018
1015bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1019bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1016{ 1020{
1017 if ( (e->type() == QEvent::Accel || 1021 if ( (e->type() == QEvent::Accel ||
1018 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1022 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1019 static_cast<QKeyEvent *>( e )->ignore(); 1023 static_cast<QKeyEvent *>( e )->ignore();
1020 return true; 1024 return true;
1021 } 1025 }
1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1026 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1023 return FALSE; // not us 1027 return FALSE; // not us
1024 if ( e->type() == QEvent::Wheel) { 1028 if ( e->type() == QEvent::Wheel) {
1025 QApplication::sendEvent(scrollbar, e); 1029 QApplication::sendEvent(scrollbar, e);
1026 } 1030 }
1027 1031
1028#ifdef FAKE_CTRL_AND_ALT 1032#ifdef FAKE_CTRL_AND_ALT
1029 static bool control = FALSE; 1033 static bool control = FALSE;
1030 static bool alt = FALSE; 1034 static bool alt = FALSE;
1031// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 1035// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
1032 bool dele=FALSE; 1036 bool dele=FALSE;
1033
1034 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1037 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1035 QKeyEvent* ke = (QKeyEvent*)e; 1038 QKeyEvent* ke = (QKeyEvent*)e;
1036 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1039 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1037 switch (ke->key()) { 1040 switch (ke->key()) {
1038 case Key_F9: // let this be "Control" 1041 case Key_F9: // let this be "Control"
1039 control = keydown; 1042 control = keydown;
1040 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1043 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1041 dele=TRUE; 1044 dele=TRUE;
1042 break; 1045 break;
1043 case Key_F13: // let this be "Alt" 1046 case Key_F13: // let this be "Alt"
1044 alt = keydown; 1047 alt = keydown;
1045 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1048 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1046 dele=TRUE; 1049 dele=TRUE;
1047 break; 1050 break;
1048 default: 1051 default:
1049 if ( control ) { 1052 if ( control ) {
1050 int a = toupper(ke->ascii())-64; 1053 int a = toupper(ke->ascii())-64;
1051 if ( a >= 0 && a < ' ' ) { 1054 if ( a >= 0 && a < ' ' ) {
1052 e = new QKeyEvent(e->type(), ke->key(), 1055 e = new QKeyEvent(e->type(), ke->key(),
1053 a, ke->state()|ControlButton, QChar(a,0)); 1056 a, ke->state()|ControlButton, QChar(a,0));
1054 dele=TRUE; 1057 dele=TRUE;
1055 } 1058 }
1056 } 1059 }
1057 if ( alt ) { 1060 if ( alt ) {
1058 e = new QKeyEvent(e->type(), ke->key(), 1061 e = new QKeyEvent(e->type(), ke->key(),
1059 ke->ascii(), ke->state()|AltButton, ke->text()); 1062 ke->ascii(), ke->state()|AltButton, ke->text());
1060 dele=TRUE; 1063 dele=TRUE;
1061 } 1064 }
1062 } 1065 }
1063 } 1066 }
1064#endif 1067#endif
1065 1068
1066 if ( e->type() == QEvent::KeyPress ) { 1069 if ( e->type() == QEvent::KeyPress ) {
1067 QKeyEvent* ke = (QKeyEvent*)e; 1070 QKeyEvent* ke = (QKeyEvent*)e;
1068 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1071 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1069 // know where the current selection is. 1072 // know where the current selection is.
1070 1073
1071// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); 1074// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state());
1072 if(ke->key() == Key_Escape) { 1075
1073 qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); 1076 bool special_function = true;
1074 1077 switch(ke->key()) {
1075 } 1078 //case 0x201b: // fn-5
1076 1079 //case Key_F1:
1077 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { 1080 // switch sessions (?)
1078 //lets hardcode this sucker 1081 // emitText("\\"); // expose (??)
1079 1082 // break;
1080// qDebug("key pressed 2 is 0x%x", ke->key()); 1083
1081 emitText("\\"); // expose 1084 case 0x2016: // fn-p
1082 } 1085 case Key_F2:
1083 else if( ke->state() == ControlButton && ke->key() == Key_V) { 1086 pasteClipboard();
1084 pasteClipboard(); 1087 break;
1085 } 1088
1086// else if( ke->state() == ControlButton && ke->key() == Key_C) { 1089 case 0x2018: // fn-S
1087// pasteClipboard(); 1090 case Key_F3:
1088// } 1091 emit changeSession(1);
1089 else 1092 break;
1090 emit keyPressedSignal(ke); // expose 1093
1094 case 0x2019: // fn-n
1095 emit newSession();
1096 break;
1097
1098 case Qt::Key_Tab:
1099 if (ke->state() == ControlButton) {
1100 emit changeSession(1);
1101 } else {
1102 special_function = false;
1103 }
1104 break;
1105
1106#if 0
1107 case Qt::Key_Left:
1108 if (vcolumns == 0) {
1109 emit changeSession(-1);
1110 } else {
1111 special_function = false;
1112 }
1113 break;
1114
1115 case Qt::Key_Right:
1116 if (vcolumns == 0) {
1117 emit changeSession(1);
1118 } else {
1119 special_function = false;
1120 }
1121 break;
1122#endif
1123
1124 case 0x201b: // fn-5
1125 case Key_F4:
1126 emit toggleFullScreen();
1127 break;
1128
1129 case 0x200f: // fn-1 magnify minus
1130 case Key_F5:
1131 emit changeFontSize(-1);
1132 break;
1133
1134 case 0x2010: // fn-2 magnify plus
1135 case Key_F6:
1136 emit changeFontSize(1);
1137 break;
1138
1139 default:
1140 special_function = false;
1141 }
1142 if (special_function) {
1143 return true;
1144 }
1145 // else if( ke->state() == ControlButton && ke->key() == Key_V) {
1146 // pasteClipboard();
1147 // }
1148 // else if( ke->state() == ControlButton && ke->key() == Key_C) {
1149 // pasteClipboard();
1150 // }
1151 emit keyPressedSignal(ke); // expose
1091 ke->accept(); 1152 ke->accept();
1092#ifdef FAKE_CTRL_AND_ALT 1153#ifdef FAKE_CTRL_AND_ALT
1093 if ( dele ) delete e; 1154 if ( dele ) delete e;
1094#endif 1155#endif
1095 return true; // stop the event 1156 return true; // stop the event
1096 } 1157 }
1097 if ( e->type() == QEvent::Enter ) { 1158 if ( e->type() == QEvent::Enter ) {
1098 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1159 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1099 this, SLOT(onClearSelection()) ); 1160 this, SLOT(onClearSelection()) );
1100 } 1161 }
1101 if ( e->type() == QEvent::Leave ) { 1162 if ( e->type() == QEvent::Leave ) {
1102 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1163 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1103 this, SLOT(onClearSelection()) ); 1164 this, SLOT(onClearSelection()) );
1104 } 1165 }
1105 return QFrame::eventFilter( obj, e ); 1166 return QFrame::eventFilter( obj, e );
1106} 1167}
1107 1168
1108/* ------------------------------------------------------------------------- */ 1169/* ------------------------------------------------------------------------- */
1109/* */ 1170/* */
1110/* Frame */ 1171/* Frame */
1111/* */ 1172/* */
1112/* ------------------------------------------------------------------------- */ 1173/* ------------------------------------------------------------------------- */
1113 1174
1114void TEWidget::frameChanged() 1175void TEWidget::frameChanged()
1115{ 1176{
1116 propagateSize(); 1177 propagateSize();
1117 update(); 1178 update();
1118} 1179}
1119
1120/* ------------------------------------------------------------------------- */ 1180/* ------------------------------------------------------------------------- */
1121/* */ 1181/* */
1122/* Sound */ 1182/* Sound */
1123/* */ 1183/* */
1124/* ------------------------------------------------------------------------- */ 1184/* ------------------------------------------------------------------------- */
1125 1185
1126void TEWidget::Bell() 1186void TEWidget::Bell()
1127{ 1187{
1128//#ifdef QT_QWS_SL5XXX 1188//#ifdef QT_QWS_SL5XXX
1129//# ifndef QT_NO_COP 1189//# ifndef QT_NO_COP
1130 if(useBeep) 1190 if(useBeep)
1131 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 1191 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
1132 1192
1133//# endif 1193//# endif
1134//#else 1194//#else
1135//# ifndef QT_NO_SOUND 1195//# ifndef QT_NO_SOUND
1136// QSound::play(Resource::findSound("alarm")); 1196// QSound::play(Resource::findSound("alarm"));
1137//# endif 1197//# endif
1138//#endif 1198//#endif
1139 1199
1140// QApplication::beep(); 1200// QApplication::beep();
1141} 1201}
1142 1202
1143/* ------------------------------------------------------------------------- */ 1203/* ------------------------------------------------------------------------- */
1144/* */ 1204/* */
1145/* Auxiluary */ 1205/* Auxiluary */
1146/* */ 1206/* */
1147/* ------------------------------------------------------------------------- */ 1207/* ------------------------------------------------------------------------- */
1148 1208
1149void TEWidget::clearImage() 1209void TEWidget::clearImage()
1150// initialize the image 1210// initialize the image
1151// for internal use only 1211// for internal use only
1152{ 1212{
1153 for (int y = 0; y < lines; y++) 1213 for (int y = 0; y < lines; y++)
1154 for (int x = 0; x < columns; x++) 1214 for (int x = 0; x < columns; x++)
1155 { 1215 {
1156 image[loc(x,y)].c = 0xff; //' '; 1216 image[loc(x,y)].c = 0xff; //' ';
1157 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1217 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1158 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1218 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1159 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1219 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1160 } 1220 }
1161} 1221}
1162 1222
1163// Create Image /////////////////////////////////////////////////////// 1223// Create Image ///////////////////////////////////////////////////////
1164 1224
1165void TEWidget::calcGeometry() 1225void TEWidget::calcGeometry()
1166{ 1226{
1167 int showhscrollbar = 1; 1227 int showhscrollbar = 1;
1168 int hwidth = 0; 1228 int hwidth = 0;
1169 int dcolumns; 1229 int dcolumns;
1170 Config cfg("Konsole"); 1230 Config cfg("Qkonsole");
1171 cfg.setGroup("ScrollBar"); 1231 cfg.setGroup("ScrollBar");
1172 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 1232 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
1173 1233
1174 if(vcolumns == 0) showhscrollbar = 0; 1234 if(vcolumns == 0) showhscrollbar = 0;
1175 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1235 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1176 1236
1177 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1237 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1178 contentsRect().height() - hwidth); 1238 contentsRect().height() - hwidth);
1179 1239
1180 switch(scrollLoc) { 1240 switch(scrollLoc) {
1181 case SCRNONE : 1241 case SCRNONE :
1182 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1242 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1183 dcolumns = columns; 1243 dcolumns = columns;
1184 if(vcolumns) columns = vcolumns; 1244 if(vcolumns) columns = vcolumns;
1185 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1245 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1186 if(showhscrollbar) 1246 if(showhscrollbar)
1187 blX = -hposition * font_w; 1247 blX = -hposition * font_w;
1188 brX = blX; 1248 brX = blX;
1189 scrollbar->hide(); 1249 scrollbar->hide();
1190 break; 1250 break;
1191 case SCRLEFT : 1251 case SCRLEFT :
1192 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1252 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1193 dcolumns = columns; 1253 dcolumns = columns;
1194 if(vcolumns) columns = vcolumns; 1254 if(vcolumns) columns = vcolumns;
1195 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1255 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1196 if(showhscrollbar) 1256 if(showhscrollbar)
1197 brX = -hposition * font_w; 1257 brX = -hposition * font_w;
1198 blX = brX + scrollbar->width(); 1258 blX = brX + scrollbar->width();
1199 scrollbar->move(contentsRect().topLeft()); 1259 scrollbar->move(contentsRect().topLeft());
1200 scrollbar->show(); 1260 scrollbar->show();
1201 break; 1261 break;
1202 case SCRRIGHT: 1262 case SCRRIGHT:
1203 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1263 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1204 dcolumns = columns; 1264 dcolumns = columns;
1205 if(vcolumns) columns = vcolumns; 1265 if(vcolumns) columns = vcolumns;
1206 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1266 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1207 if(showhscrollbar) 1267 if(showhscrollbar)
1208 blX = -hposition * font_w; 1268 blX = -hposition * font_w;
1209 brX = blX; 1269 brX = blX;
1210 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1270 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1211 scrollbar->show(); 1271 scrollbar->show();
1212 break; 1272 break;
1213 } 1273 }
1214 //FIXME: support 'rounding' styles 1274 //FIXME: support 'rounding' styles
1215 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1275 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1216 bY = (contentsRect().height() - (lines *font_h)) / 2; 1276 bY = (contentsRect().height() - (lines *font_h)) / 2;
1217 1277
1218 if(showhscrollbar == 1) { 1278 if(showhscrollbar == 1) {
1219 hScrollbar->resize(contentsRect().width() - hwidth, hwidth); 1279 hScrollbar->resize(contentsRect().width() - hwidth, hwidth);
1220 hScrollbar->setRange(0, vcolumns - dcolumns); 1280 hScrollbar->setRange(0, vcolumns - dcolumns);
1221 1281
1222 QPoint p = contentsRect().bottomLeft(); 1282 QPoint p = contentsRect().bottomLeft();
1223 if(scrollLoc == SCRLEFT) 1283 if(scrollLoc == SCRLEFT)
1224 hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth)); 1284 hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth));
1225 else 1285 else
1226 hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); 1286 hScrollbar->move(QPoint(p.x(), p.y() - hwidth));
1227 1287
1228 hScrollbar->show(); 1288 hScrollbar->show();
1229 } 1289 }
1230 else hScrollbar->hide(); 1290 else hScrollbar->hide();
1231 1291
1232 if(showhscrollbar == 1) { 1292 if(showhscrollbar == 1) {
1233 lines = lines - (hwidth / font_h) - 1; 1293 lines = lines - (hwidth / font_h) - 1;
1234 if(lines < 1) lines = 1; 1294 if(lines < 1) lines = 1;
1235 } 1295 }
1236 //FIXME: support 'rounding' styles 1296 //FIXME: support 'rounding' styles
1237} 1297}
1238 1298
1239void TEWidget::makeImage() 1299void TEWidget::makeImage()
1240//FIXME: rename 'calcGeometry? 1300//FIXME: rename 'calcGeometry?
1241{ 1301{
1242 calcGeometry(); 1302 calcGeometry();
1243 image = (ca*) malloc(lines*columns*sizeof(ca)); 1303 image = (ca*) malloc(lines*columns*sizeof(ca));
1244 clearImage(); 1304 clearImage();
1245} 1305}
1246 1306
1247// calculate the needed size 1307// calculate the needed size
1248QSize TEWidget::calcSize(int cols, int lins) const 1308QSize TEWidget::calcSize(int cols, int lins) const
1249{ 1309{
1250 int frw = width() - contentsRect().width(); 1310 int frw = width() - contentsRect().width();
1251 int frh = height() - contentsRect().height(); 1311 int frh = height() - contentsRect().height();
1252 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1312 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1253 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1313 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1254} 1314}
1255 1315
1256QSize TEWidget::sizeHint() const 1316QSize TEWidget::sizeHint() const
1257{ 1317{
1258 return size(); 1318 return size();
1259} 1319}
1260 1320
1261void TEWidget::styleChange(QStyle &) 1321void TEWidget::styleChange(QStyle &)
1262{ 1322{
1263 propagateSize(); 1323 propagateSize();
1264} 1324}
1265 1325
1266#ifndef QT_NO_DRAGANDDROP 1326#ifndef QT_NO_DRAGANDDROP
1267 1327
1268/* --------------------------------------------------------------------- */ 1328/* --------------------------------------------------------------------- */
1269/* */ 1329/* */
1270/* Drag & Drop */ 1330/* Drag & Drop */
1271/* */ 1331/* */
1272/* --------------------------------------------------------------------- */ 1332/* --------------------------------------------------------------------- */
1273 1333
1274 1334
1275void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1335void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1276{ 1336{
1277 e->accept(QTextDrag::canDecode(e) || 1337 e->accept(QTextDrag::canDecode(e) ||
1278 QUriDrag::canDecode(e)); 1338 QUriDrag::canDecode(e));
1279} 1339}
1280 1340
1281void TEWidget::dropEvent(QDropEvent* event) 1341void TEWidget::dropEvent(QDropEvent* event)
1282{ 1342{
1283 // The current behaviour when url(s) are dropped is 1343 // The current behaviour when url(s) are dropped is
1284 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1344 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1285 // * in all other cases, just paste 1345 // * in all other cases, just paste
1286 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1346 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1287 QStrList strlist; 1347 QStrList strlist;
1288 int file_count = 0; 1348 int file_count = 0;
1289 dropText = ""; 1349 dropText = "";
1290 bool bPopup = true; 1350 bool bPopup = true;
1291 1351
1292 if(QUriDrag::decode(event, strlist)) { 1352 if(QUriDrag::decode(event, strlist)) {
1293 if (strlist.count()) { 1353 if (strlist.count()) {
1294 for(const char* p = strlist.first(); p; p = strlist.next()) { 1354 for(const char* p = strlist.first(); p; p = strlist.next()) {
1295 if(file_count++ > 0) { 1355 if(file_count++ > 0) {
1296 dropText += " "; 1356 dropText += " ";
1297 bPopup = false; // more than one file, don't popup 1357 bPopup = false; // more than one file, don't popup
1298 } 1358 }
1299 1359
1300/* 1360/*
1301 KURL url(p); 1361 KURL url(p);
1302 if (url.isLocalFile()) { 1362 if (url.isLocalFile()) {
1303 dropText += url.path(); // local URL : remove protocol 1363 dropText += url.path(); // local URL : remove protocol
1304 } 1364 }
1305 else { 1365 else {
1306 dropText += url.prettyURL(); 1366 dropText += url.prettyURL();
1307 bPopup = false; // a non-local file, don't popup 1367 bPopup = false; // a non-local file, don't popup
1308 } 1368 }
1309*/ 1369*/
1310 1370
1311 } 1371 }
1312 1372
1313 if (bPopup) 1373 if (bPopup)
1314 // m_drop->popup(pos() + event->pos()); 1374 // m_drop->popup(pos() + event->pos());
1315 m_drop->popup(mapToGlobal(event->pos())); 1375 m_drop->popup(mapToGlobal(event->pos()));
1316 else 1376 else
1317 { 1377 {
1318 if (currentSession) { 1378 if (currentSession) {
1319 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1379 currentSession->getEmulation()->sendString(dropText.local8Bit());
1320 } 1380 }
1321// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1381// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1322 } 1382 }
1323 } 1383 }
1324 } 1384 }
1325 else if(QTextDrag::decode(event, dropText)) { 1385 else if(QTextDrag::decode(event, dropText)) {
1326// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1386// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1327 if (currentSession) { 1387 if (currentSession) {
1328 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1388 currentSession->getEmulation()->sendString(dropText.local8Bit());
1329 } 1389 }
1330 // Paste it 1390 // Paste it
1331 } 1391 }
1332} 1392}
1333#endif 1393#endif
1334 1394
1335 1395
1336void TEWidget::drop_menu_activated(int item) 1396void TEWidget::drop_menu_activated(int item)
1337{ 1397{
1338#ifndef QT_NO_DRAGANDDROP 1398#ifndef QT_NO_DRAGANDDROP
1339 switch (item) 1399 switch (item)
1340 { 1400 {
1341 case 0: // paste 1401 case 0: // paste
1342 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1402 currentSession->getEmulation()->sendString(dropText.local8Bit());
1343// KWM::activate((Window)this->winId()); 1403// KWM::activate((Window)this->winId());
1344 break; 1404 break;
1345 case 1: // cd ... 1405 case 1: // cd ...
1346 currentSession->getEmulation()->sendString("cd "); 1406 currentSession->getEmulation()->sendString("cd ");
1347 struct stat statbuf; 1407 struct stat statbuf;
1348 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1408 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1349 { 1409 {
1350 if ( !S_ISDIR(statbuf.st_mode) ) 1410 if ( !S_ISDIR(statbuf.st_mode) )
1351 { 1411 {
1352/* 1412/*
1353 KURL url; 1413 KURL url;
1354 url.setPath( dropText ); 1414 url.setPath( dropText );
1355 dropText = url.directory( true, false ); // remove filename 1415 dropText = url.directory( true, false ); // remove filename
1356*/ 1416*/
1357 } 1417 }
1358 } 1418 }
1359 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1419 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1360 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1420 currentSession->getEmulation()->sendString(dropText.local8Bit());
1361 currentSession->getEmulation()->sendString("\n"); 1421 currentSession->getEmulation()->sendString("\n");
1362// KWM::activate((Window)this->winId()); 1422// KWM::activate((Window)this->winId());
1363 break; 1423 break;
1364 } 1424 }
1365#endif 1425#endif
1366} 1426}
1367 1427
1368void TEWidget::setWrapAt(int columns) 1428void TEWidget::setWrapAt(int columns)
1369{ 1429{
1370 vcolumns = columns; 1430 vcolumns = columns;
1371 propagateSize(); 1431 propagateSize();
1372 update(); 1432 update();
1373} 1433}
diff --git a/core/apps/embeddedkonsole/TEWidget.h b/core/apps/embeddedkonsole/TEWidget.h
index 5597f27..792b109 100644
--- a/core/apps/embeddedkonsole/TEWidget.h
+++ b/core/apps/embeddedkonsole/TEWidget.h
@@ -1,204 +1,214 @@
1/* ----------------------------------------------------------------------- */ 1/* ----------------------------------------------------------------------- */
2/* */ 2/* */
3/* [te_widget.h] Terminal Emulation Widget */ 3/* [te_widget.h] 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#ifndef TE_WIDGET_H 18#ifndef TE_WIDGET_H
19#define TE_WIDGET_H 19#define TE_WIDGET_H
20 20
21#include <qwidget.h> 21#include <qwidget.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qtimer.h> 23#include <qtimer.h>
24#include <qcolor.h> 24#include <qcolor.h>
25#include <qkeycode.h> 25#include <qkeycode.h>
26#include <qscrollbar.h> 26#include <qscrollbar.h>
27 27
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29 29
30#include "TECommon.h" 30#include "TECommon.h"
31 31
32extern unsigned short vt100_graphics[32]; 32extern unsigned short vt100_graphics[32];
33 33
34class TESession; 34class TESession;
35 35
36// class Konsole; 36// class Konsole;
37 37
38class TEWidget : public QFrame 38class TEWidget : public QFrame
39// a widget representing attributed text 39// a widget representing attributed text
40{ Q_OBJECT 40{
41 Q_OBJECT
41 42
42// friend class Konsole; 43// friend class Konsole;
43 44
44public: 45public:
45 46
46 TEWidget(QWidget *parent=0, const char *name=0); 47 TEWidget(QWidget *parent=0, const char *name=0);
47 virtual ~TEWidget(); 48 virtual ~TEWidget();
48 49
49public: 50public:
50 51
51 QColor getDefaultBackColor(); 52 QColor getDefaultBackColor();
52 53
53 const ColorEntry* getColorTable() const; 54 const ColorEntry* getColorTable() const;
54 const ColorEntry* getdefaultColorTable() const; 55 const ColorEntry* getdefaultColorTable() const;
55 void setColorTable(const ColorEntry table[]); 56 void setColorTable(const ColorEntry table[]);
56 void setScrollbarLocation(int loc); 57 void setScrollbarLocation(int loc);
57 enum { SCRNONE=0, SCRLEFT=1, SCRRIGHT=2 }; 58 enum { SCRNONE=0, SCRLEFT=1, SCRRIGHT=2 };
58 void setScroll(int cursor, int lines); 59 void setScroll(int cursor, int lines);
59 void doScroll(int lines); 60 void doScroll(int lines);
60 void doHScroll(int lines); 61 void doHScroll(int lines);
61 void emitSelection(); 62 void emitSelection();
62 void setWrapAt(int columns); 63 void setWrapAt(int columns);
63 64
64 void setImage(const ca* const newimg, int lines, int columns); 65 void setImage(const ca* const newimg, int lines, int columns);
65 66
66 int Lines() { return lines; } 67 int Lines() { return lines; }
67 int Columns() { return columns; } 68 int Columns() { return columns; }
68 69
69 void calcGeometry(); 70 void calcGeometry();
70 void propagateSize(); 71 void propagateSize();
71 QSize calcSize(int cols, int lins) const; 72 QSize calcSize(int cols, int lins) const;
72 73
73 QSize sizeHint() const; 74 QSize sizeHint() const;
74 75
75 bool useHorzScroll; 76 bool useHorzScroll;
76 bool useBeep; 77 bool useBeep;
78 int color_menu_item;
77 79
78 void Bell(); 80 void Bell();
79 void emitText(QString text); 81 void emitText(QString text);
80 void pasteClipboard(); 82 void pasteClipboard();
81 83
82signals: 84signals:
83 85
84 void keyPressedSignal(QKeyEvent *e); 86 void keyPressedSignal(QKeyEvent *e);
85 void mouseSignal(int cb, int cx, int cy); 87 void mouseSignal(int cb, int cx, int cy);
86 void changedImageSizeSignal(int lines, int columns); 88 void changedImageSizeSignal(int lines, int columns);
87 void changedHistoryCursor(int value); 89 void changedHistoryCursor(int value);
88 void changedHorzCursor(int value); 90 void changedHorzCursor(int value);
89 void configureRequest( TEWidget*, int state, int x, int y ); 91 void configureRequest( TEWidget*, int state, int x, int y );
90 92
91 void clearSelectionSignal(); 93 void clearSelectionSignal();
92 void beginSelectionSignal( const int x, const int y ); 94 void beginSelectionSignal( const int x, const int y );
93 void extendSelectionSignal( const int x, const int y ); 95 void extendSelectionSignal( const int x, const int y );
94 void endSelectionSignal(const BOOL preserve_line_breaks); 96 void endSelectionSignal(const BOOL preserve_line_breaks);
95 97
98 void changeFontSize(int);
99 void toggleFullScreen();
100 void setFullScreen(bool);
101 void changeSession(int);
102 void newSession();
96 103
97protected: 104protected:
98 virtual void styleChange( QStyle& ); 105 virtual void styleChange( QStyle& );
99 106
100 bool eventFilter( QObject *, QEvent * ); 107 bool eventFilter( QObject *, QEvent * );
101 108
102 void drawAttrStr(QPainter &paint, QRect rect, 109 void drawAttrStr(QPainter &paint, QRect rect,
103 QString& str, ca attr, BOOL pm, BOOL clear); 110 QString& str, ca attr, BOOL pm, BOOL clear);
104 void paintEvent( QPaintEvent * ); 111 void paintEvent( QPaintEvent * );
105 112
106 void resizeEvent(QResizeEvent*); 113 void resizeEvent(QResizeEvent*);
107 114
108 void fontChange(const QFont &font); 115 void fontChange(const QFont &font);
109 void frameChanged(); 116 void frameChanged();
110 117
111 void mouseDoubleClickEvent(QMouseEvent* ev); 118 void mouseDoubleClickEvent(QMouseEvent* ev);
112 void mousePressEvent( QMouseEvent* ); 119 void mousePressEvent( QMouseEvent* );
113 void mouseReleaseEvent( QMouseEvent* ); 120 void mouseReleaseEvent( QMouseEvent* );
114 void mouseMoveEvent( QMouseEvent* ); 121 void mouseMoveEvent( QMouseEvent* );
115 122
116 void focusInEvent( QFocusEvent * ); 123 void focusInEvent( QFocusEvent * );
117 void focusOutEvent( QFocusEvent * ); 124 void focusOutEvent( QFocusEvent * );
118 bool focusNextPrevChild( bool next ); 125 bool focusNextPrevChild( bool next );
119 126
120#ifndef QT_NO_DRAGANDDROP 127#ifndef QT_NO_DRAGANDDROP
121 // Dnd 128 // Dnd
122 void dragEnterEvent(QDragEnterEvent* event); 129 void dragEnterEvent(QDragEnterEvent* event);
123 void dropEvent(QDropEvent* event); 130 void dropEvent(QDropEvent* event);
124#endif 131#endif
125 132
126 virtual int charClass(char) const; 133 virtual int charClass(char) const;
127 134
128 void clearImage(); 135 void clearImage();
129 136
130public: 137public:
131 const QPixmap *backgroundPixmap(); 138 const QPixmap *backgroundPixmap();
132 139
133 void setSelection(const QString &t); 140 void setSelection(const QString &t);
134 141
135 virtual void setFont(const QFont &); 142 virtual void setFont(const QFont &);
136 void setVTFont(const QFont &); 143 void setVTFont(const QFont &);
137 QFont getVTFont(); 144 QFont getVTFont();
138 145
139 void setMouseMarks(bool on); 146 void setMouseMarks(bool on);
140 147
141public slots: 148public slots:
142 149
143 void onClearSelection(); 150 void onClearSelection();
144 151
145protected slots: 152protected slots:
146 153
147 void scrollChanged(int value); 154 void scrollChanged(int value);
148 void hScrollChanged(int value); 155 void hScrollChanged(int value);
149 void blinkEvent(); 156 void blinkEvent();
150 157
151private: 158private:
152 159
153 QChar (*fontMap)(QChar); // possible vt100 font extention 160 QChar (*fontMap)(QChar); // possible vt100 font extention
154 161
155 bool fixed_font; // has fixed pitch 162 // bool fixed_font; // has fixed pitch
156 int font_h; // height 163 int font_h; // height
157 int font_w; // width 164 int font_w; // width
158 int font_a; // ascend 165 int font_a; // ascend
159 166
160 int blX; // actual offset (left) 167 int blX; // actual offset (left)
161 int brX; // actual offset (right) 168 int brX; // actual offset (right)
162 int bY; // actual offset 169 int bY; // actual offset
163 170
164 int lines; 171 int lines;
165 int columns; 172 int columns;
166 ca *image; // [lines][columns] 173 ca *image; // [lines][columns]
167 174
168 ColorEntry color_table[TABLE_COLORS]; 175 ColorEntry color_table[TABLE_COLORS];
169 176
170 BOOL resizing; 177 BOOL resizing;
171 bool mouse_marks; 178 bool mouse_marks;
172 179
173 void makeImage(); 180 void makeImage();
174 181
175 QPoint iPntSel; // initial selection point 182 QPoint iPntSel; // initial selection point
176 QPoint pntSel; // current selection point 183 QPoint pntSel; // current selection point
177 int actSel; // selection state 184 int actSel; // selection state
178 BOOL word_selection_mode; 185 BOOL word_selection_mode;
179 BOOL preserve_line_breaks; 186 BOOL preserve_line_breaks;
180 187
181 QClipboard* cb; 188 QClipboard* cb;
182 QScrollBar* scrollbar, *hScrollbar; 189 QScrollBar* scrollbar, *hScrollbar;
183 190
184 int scrollLoc, hScrollLoc; 191 int scrollLoc, hScrollLoc;
185 int hposition, vcolumns; 192 int hposition, vcolumns;
186 193
194 int mouse_down_x, mouse_down_y;
187 195
188//#define SCRNONE 0 196//#define SCRNONE 0
189//#define SCRLEFT 1 197//#define SCRLEFT 1
190//#define SCRRIGHT 2 198//#define SCRRIGHT 2
191 199
192 BOOL blinking; // hide text in paintEvent 200 BOOL blinking; // hide text in paintEvent
193 BOOL hasBlinker; // has characters to blink 201 BOOL hasBlinker; // has characters to blink
194 QTimer* blinkT; // active when hasBlinker 202 QTimer* blinkT; // active when hasBlinker
195 QPopupMenu* m_drop; 203 QPopupMenu* m_drop;
196 QString dropText; 204 QString dropText;
205
197 public: 206 public:
198 // current session in this widget 207 // current session in this widget
199 TESession *currentSession; 208 TESession *currentSession;
209
200private slots: 210private slots:
201 void drop_menu_activated(int item); 211 void drop_menu_activated(int item);
202}; 212};
203 213
204#endif // TE_WIDGET_H 214#endif // TE_WIDGET_H
diff --git a/core/apps/embeddedkonsole/TEmulation.cpp b/core/apps/embeddedkonsole/TEmulation.cpp
index c19f2a1..a539757 100644
--- a/core/apps/embeddedkonsole/TEmulation.cpp
+++ b/core/apps/embeddedkonsole/TEmulation.cpp
@@ -1,378 +1,379 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2/* */ 2/* */
3/* [TEmulation.cpp] Terminal Emulation Decoder */ 3/* [TEmulation.cpp] Terminal Emulation Decoder */
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 18
19/*! \class TEmulation 19/*! \class TEmulation
20 20
21 \brief Mediator between TEWidget and TEScreen. 21 \brief Mediator between TEWidget and TEScreen.
22 22
23 This class is responsible to scan the escapes sequences of the terminal 23 This class is responsible to scan the escapes sequences of the terminal
24 emulation and to map it to their corresponding semantic complements. 24 emulation and to map it to their corresponding semantic complements.
25 Thus this module knows mainly about decoding escapes sequences and 25 Thus this module knows mainly about decoding escapes sequences and
26 is a stateless device w.r.t. the semantics. 26 is a stateless device w.r.t. the semantics.
27 27
28 It is also responsible to refresh the TEWidget by certain rules. 28 It is also responsible to refresh the TEWidget by certain rules.
29 29
30 \sa TEWidget \sa TEScreen 30 \sa TEWidget \sa TEScreen
31 31
32 \par A note on refreshing 32 \par A note on refreshing
33 33
34 Although the modifications to the current screen image could immediately 34 Although the modifications to the current screen image could immediately
35 be propagated via `TEWidget' to the graphical surface, we have chosen 35 be propagated via `TEWidget' to the graphical surface, we have chosen
36 another way here. 36 another way here.
37 37
38 The reason for doing so is twofold. 38 The reason for doing so is twofold.
39 39
40 First, experiments show that directly displaying the operation results 40 First, experiments show that directly displaying the operation results
41 in slowing down the overall performance of emulations. Displaying 41 in slowing down the overall performance of emulations. Displaying
42 individual characters using X11 creates a lot of overhead. 42 individual characters using X11 creates a lot of overhead.
43 43
44 Second, by using the following refreshing method, the screen operations 44 Second, by using the following refreshing method, the screen operations
45 can be completely separated from the displaying. This greatly simplifies 45 can be completely separated from the displaying. This greatly simplifies
46 the programmer's task of coding and maintaining the screen operations, 46 the programmer's task of coding and maintaining the screen operations,
47 since one need not worry about differential modifications on the 47 since one need not worry about differential modifications on the
48 display affecting the operation of concern. 48 display affecting the operation of concern.
49 49
50 We use a refreshing algorithm here that has been adoped from rxvt/kvt. 50 We use a refreshing algorithm here that has been adoped from rxvt/kvt.
51 51
52 By this, refreshing is driven by a timer, which is (re)started whenever 52 By this, refreshing is driven by a timer, which is (re)started whenever
53 a new bunch of data to be interpreted by the emulation arives at `onRcvBlock'. 53 a new bunch of data to be interpreted by the emulation arives at `onRcvBlock'.
54 As soon as no more data arrive for `BULK_TIMEOUT' milliseconds, we trigger 54 As soon as no more data arrive for `BULK_TIMEOUT' milliseconds, we trigger
55 refresh. This rule suits both bulk display operation as done by curses as 55 refresh. This rule suits both bulk display operation as done by curses as
56 well as individual characters typed. 56 well as individual characters typed.
57 (BULK_TIMEOUT < 1000 / max characters received from keyboard per second). 57 (BULK_TIMEOUT < 1000 / max characters received from keyboard per second).
58 58
59 Additionally, we trigger refreshing by newlines comming in to make visual 59 Additionally, we trigger refreshing by newlines comming in to make visual
60 snapshots of lists as produced by `cat', `ls' and likely programs, thereby 60 snapshots of lists as produced by `cat', `ls' and likely programs, thereby
61 producing the illusion of a permanent and immediate display operation. 61 producing the illusion of a permanent and immediate display operation.
62 62
63 As a sort of catch-all needed for cases where none of the above 63 As a sort of catch-all needed for cases where none of the above
64 conditions catch, the screen refresh is also triggered by a count 64 conditions catch, the screen refresh is also triggered by a count
65 of incoming bulks (`bulk_incnt'). 65 of incoming bulks (`bulk_incnt').
66*/ 66*/
67 67
68/* FIXME 68/* FIXME
69 - evtl. the bulk operations could be made more transparent. 69 - evtl. the bulk operations could be made more transparent.
70*/ 70*/
71 71
72#include "TEmulation.h" 72#include "TEmulation.h"
73#include "TEWidget.h" 73#include "TEWidget.h"
74#include "TEScreen.h" 74#include "TEScreen.h"
75#include <stdio.h> 75#include <stdio.h>
76#include <stdlib.h> 76#include <stdlib.h>
77#include <unistd.h> 77#include <unistd.h>
78#include <qkeycode.h> 78#include <qkeycode.h>
79 79
80 80
81/* ------------------------------------------------------------------------- */ 81/* ------------------------------------------------------------------------- */
82/* */ 82/* */
83/* TEmulation */ 83/* TEmulation */
84/* */ 84/* */
85/* ------------------------------------------------------------------------- */ 85/* ------------------------------------------------------------------------- */
86 86
87#define CNTL(c) ((c)-'@') 87#define CNTL(c) ((c)-'@')
88 88
89/*! 89/*!
90*/ 90*/
91 91
92TEmulation::TEmulation(TEWidget* gui) 92TEmulation::TEmulation(TEWidget* gui)
93: decoder((QTextDecoder*)NULL) 93: decoder((QTextDecoder*)NULL)
94{ 94{
95 this->gui = gui; 95 this->gui = gui;
96 96
97 screen[0] = new TEScreen(gui->Lines(),gui->Columns()); 97 screen[0] = new TEScreen(gui->Lines(),gui->Columns());
98 screen[1] = new TEScreen(gui->Lines(),gui->Columns()); 98 screen[1] = new TEScreen(gui->Lines(),gui->Columns());
99 scr = screen[0]; 99 scr = screen[0];
100 100
101 bulk_nlcnt = 0; // reset bulk newline counter 101 bulk_nlcnt = 0; // reset bulk newline counter
102 bulk_incnt = 0; // reset bulk counter 102 bulk_incnt = 0; // reset bulk counter
103 connected = FALSE; 103 connected = FALSE;
104 104
105 QObject::connect(&bulk_timer, SIGNAL(timeout()), this, SLOT(showBulk()) ); 105 QObject::connect(&bulk_timer, SIGNAL(timeout()), this, SLOT(showBulk()) );
106 106
107 QObject::connect(gui,SIGNAL(changedImageSizeSignal(int,int)), 107 QObject::connect(gui,SIGNAL(changedImageSizeSignal(int,int)),
108 this,SLOT(onImageSizeChange(int,int))); 108 this,SLOT(onImageSizeChange(int,int)));
109 109
110 QObject::connect(gui,SIGNAL(changedHistoryCursor(int)), 110 QObject::connect(gui,SIGNAL(changedHistoryCursor(int)),
111 this,SLOT(onHistoryCursorChange(int))); 111 this,SLOT(onHistoryCursorChange(int)));
112 112
113 QObject::connect(gui,SIGNAL(changedHorzCursor(int)), 113 QObject::connect(gui,SIGNAL(changedHorzCursor(int)),
114 this,SLOT(onHorzCursorChange(int))); 114 this,SLOT(onHorzCursorChange(int)));
115 115
116 QObject::connect(gui,SIGNAL(keyPressedSignal(QKeyEvent*)), 116 QObject::connect(gui,SIGNAL(keyPressedSignal(QKeyEvent*)),
117 this,SLOT(onKeyPress(QKeyEvent*))); 117 this,SLOT(onKeyPress(QKeyEvent*)));
118 118
119 QObject::connect(gui,SIGNAL(beginSelectionSignal(const int,const int)), 119 QObject::connect(gui,SIGNAL(beginSelectionSignal(const int,const int)),
120 this,SLOT(onSelectionBegin(const int,const int)) ); 120 this,SLOT(onSelectionBegin(const int,const int)) );
121 121
122 QObject::connect(gui,SIGNAL(extendSelectionSignal(const int,const int)), 122 QObject::connect(gui,SIGNAL(extendSelectionSignal(const int,const int)),
123 this,SLOT(onSelectionExtend(const int,const int)) ); 123 this,SLOT(onSelectionExtend(const int,const int)) );
124 124
125 QObject::connect(gui,SIGNAL(endSelectionSignal(const BOOL)), 125 QObject::connect(gui,SIGNAL(endSelectionSignal(const BOOL)),
126 this,SLOT(setSelection(const BOOL)) ); 126 this,SLOT(setSelection(const BOOL)) );
127 127
128 QObject::connect(gui,SIGNAL(clearSelectionSignal()), 128 QObject::connect(gui,SIGNAL(clearSelectionSignal()),
129 this,SLOT(clearSelection()) ); 129 this,SLOT(clearSelection()) );
130} 130}
131 131
132/*! 132/*!
133*/ 133*/
134 134
135TEmulation::~TEmulation() 135TEmulation::~TEmulation()
136{ 136{
137 delete screen[0]; 137 delete screen[0];
138 delete screen[1]; 138 delete screen[1];
139 bulk_timer.stop(); 139 bulk_timer.stop();
140} 140}
141 141
142/*! change between primary and alternate screen 142/*! change between primary and alternate screen
143*/ 143*/
144 144
145void TEmulation::setScreen(int n) 145void TEmulation::setScreen(int n)
146{ 146{
147 scr = screen[n&1]; 147 scr = screen[n&1];
148} 148}
149 149
150void TEmulation::setHistory(bool on) 150void TEmulation::setHistory(bool on)
151{ 151{
152 screen[0]->setScroll(on); 152 screen[0]->setScroll(on);
153 if (!connected) return; 153 if (!connected) return;
154 showBulk(); 154 showBulk();
155} 155}
156 156
157bool TEmulation::history() 157bool TEmulation::history()
158{ 158{
159 return screen[0]->hasScroll(); 159 return screen[0]->hasScroll();
160} 160}
161 161
162void TEmulation::setCodec(int c) 162void TEmulation::setCodec(int c)
163{ 163{
164 //FIXME: check whether we have to free codec 164 //FIXME: check whether we have to free codec
165 codec = c ? QTextCodec::codecForName("utf8") 165 codec = c ? QTextCodec::codecForName("utf8")
166 : QTextCodec::codecForLocale(); 166 : QTextCodec::codecForLocale();
167 if (decoder) delete decoder; 167 if (decoder) delete decoder;
168 decoder = codec->makeDecoder(); 168 decoder = codec->makeDecoder();
169} 169}
170 170
171void TEmulation::setKeytrans(int no) 171void TEmulation::setKeytrans(int no)
172{ 172{
173 keytrans = KeyTrans::find(no); 173 keytrans = KeyTrans::find(no);
174} 174}
175 175
176void TEmulation::setKeytrans(const char * no) 176void TEmulation::setKeytrans(const char * no)
177{ 177{
178 keytrans = KeyTrans::find(no); 178 keytrans = KeyTrans::find(no);
179} 179}
180 180
181// Interpreting Codes --------------------------------------------------------- 181// Interpreting Codes ---------------------------------------------------------
182 182
183/* 183/*
184 This section deals with decoding the incoming character stream. 184 This section deals with decoding the incoming character stream.
185 Decoding means here, that the stream is first seperated into `tokens' 185 Decoding means here, that the stream is first seperated into `tokens'
186 which are then mapped to a `meaning' provided as operations by the 186 which are then mapped to a `meaning' provided as operations by the
187 `Screen' class. 187 `Screen' class.
188*/ 188*/
189 189
190/*! 190/*!
191*/ 191*/
192 192
193void TEmulation::onRcvChar(int c) 193void TEmulation::onRcvChar(int c)
194// process application unicode input to terminal 194// process application unicode input to terminal
195// this is a trivial scanner 195// this is a trivial scanner
196{ 196{
197 c &= 0xff; 197 c &= 0xff;
198
198 switch (c) 199 switch (c)
199 { 200 {
200 case '\b' : scr->BackSpace(); break; 201 case '\b' : scr->BackSpace(); break;
201 case '\t' : scr->Tabulate(); break; 202 case '\t' : scr->Tabulate(); break;
202 case '\n' : scr->NewLine(); break; 203 case '\n' : scr->NewLine(); break;
203 case '\r' : scr->Return(); break; 204 case '\r' : scr->Return(); break;
204 case 0x07 : gui->Bell(); break; 205 case 0x07 : gui->Bell(); break;
205 default : scr->ShowCharacter(c); break; 206 default : scr->ShowCharacter(c); break;
206 }; 207 };
207} 208}
208 209
209/* ------------------------------------------------------------------------- */ 210/* ------------------------------------------------------------------------- */
210/* */ 211/* */
211/* Keyboard Handling */ 212/* Keyboard Handling */
212/* */ 213/* */
213/* ------------------------------------------------------------------------- */ 214/* ------------------------------------------------------------------------- */
214 215
215/*! 216/*!
216*/ 217*/
217 218
218void TEmulation::onKeyPress( QKeyEvent* ev ) 219void TEmulation::onKeyPress( QKeyEvent* ev )
219{ 220{
220 if (!connected) return; // someone else gets the keys 221 if (!connected) return; // someone else gets the keys
221 if (scr->getHistCursor() != scr->getHistLines()); 222 if (scr->getHistCursor() != scr->getHistLines());
222 scr->setHistCursor(scr->getHistLines()); 223 scr->setHistCursor(scr->getHistLines());
223 if (!ev->text().isEmpty()) 224 if (!ev->text().isEmpty())
224 { // A block of text 225 { // A block of text
225 // Note that the text is proper unicode. 226 // Note that the text is proper unicode.
226 // We should do a conversion here, but since this 227 // We should do a conversion here, but since this
227 // routine will never be used, we simply emit plain ascii. 228 // routine will never be used, we simply emit plain ascii.
228 emit sndBlock(ev->text().ascii(),ev->text().length()); 229 emit sndBlock(ev->text().ascii(),ev->text().length());
229 } 230 }
230 else if (ev->ascii()>0) 231 else if (ev->ascii()>0)
231 { unsigned char c[1]; 232 { unsigned char c[1];
232 c[0] = ev->ascii(); 233 c[0] = ev->ascii();
233 emit sndBlock((char*)c,1); 234 emit sndBlock((char*)c,1);
234 } 235 }
235} 236}
236 237
237// Unblocking, Byte to Unicode translation --------------------------------- -- 238// Unblocking, Byte to Unicode translation --------------------------------- --
238 239
239/* 240/*
240 We are doing code conversion from locale to unicode first. 241 We are doing code conversion from locale to unicode first.
241*/ 242*/
242 243
243void TEmulation::onRcvBlock(const char *s, int len) 244void TEmulation::onRcvBlock(const char *s, int len)
244{ 245{
245 bulkStart(); 246 bulkStart();
246 bulk_incnt += 1; 247 bulk_incnt += 1;
247 for (int i = 0; i < len; i++) 248 for (int i = 0; i < len; i++)
248 { 249 {
249 QString result = decoder->toUnicode(&s[i],1); 250 QString result = decoder->toUnicode(&s[i],1);
250 int reslen = result.length(); 251 int reslen = result.length();
251 for (int j = 0; j < reslen; j++) 252 for (int j = 0; j < reslen; j++)
252 onRcvChar(result[j].unicode()); 253 onRcvChar(result[j].unicode());
253 if (s[i] == '\n') bulkNewline(); 254 if (s[i] == '\n') bulkNewline();
254 } 255 }
255 bulkEnd(); 256 bulkEnd();
256} 257}
257 258
258// Selection --------------------------------------------------------------- -- 259// Selection --------------------------------------------------------------- --
259 260
260void TEmulation::onSelectionBegin(const int x, const int y) { 261void TEmulation::onSelectionBegin(const int x, const int y) {
261 if (!connected) return; 262 if (!connected) return;
262 scr->setSelBeginXY(x,y); 263 scr->setSelBeginXY(x,y);
263 showBulk(); 264 showBulk();
264} 265}
265 266
266void TEmulation::onSelectionExtend(const int x, const int y) { 267void TEmulation::onSelectionExtend(const int x, const int y) {
267 if (!connected) return; 268 if (!connected) return;
268 scr->setSelExtentXY(x,y); 269 scr->setSelExtentXY(x,y);
269 showBulk(); 270 showBulk();
270} 271}
271 272
272void TEmulation::setSelection(const BOOL preserve_line_breaks) { 273void TEmulation::setSelection(const BOOL preserve_line_breaks) {
273 if (!connected) return; 274 if (!connected) return;
274 QString t = scr->getSelText(preserve_line_breaks); 275 QString t = scr->getSelText(preserve_line_breaks);
275 if (!t.isNull()) gui->setSelection(t); 276 if (!t.isNull()) gui->setSelection(t);
276} 277}
277 278
278void TEmulation::clearSelection() { 279void TEmulation::clearSelection() {
279 if (!connected) return; 280 if (!connected) return;
280 scr->clearSelection(); 281 scr->clearSelection();
281 showBulk(); 282 showBulk();
282} 283}
283 284
284// Refreshing -------------------------------------------------------------- -- 285// Refreshing -------------------------------------------------------------- --
285 286
286#define BULK_TIMEOUT 20 287#define BULK_TIMEOUT 20
287 288
288/*! 289/*!
289 called when \n comes in. Evtl. triggers showBulk at endBulk 290 called when \n comes in. Evtl. triggers showBulk at endBulk
290*/ 291*/
291 292
292void TEmulation::bulkNewline() 293void TEmulation::bulkNewline()
293{ 294{
294 bulk_nlcnt += 1; 295 bulk_nlcnt += 1;
295 bulk_incnt = 0; // reset bulk counter since `nl' rule applies 296 bulk_incnt = 0; // reset bulk counter since `nl' rule applies
296} 297}
297 298
298/*! 299/*!
299*/ 300*/
300 301
301void TEmulation::showBulk() 302void TEmulation::showBulk()
302{ 303{
303 bulk_nlcnt = 0; // reset bulk newline counter 304 bulk_nlcnt = 0; // reset bulk newline counter
304 bulk_incnt = 0; // reset bulk counter 305 bulk_incnt = 0; // reset bulk counter
305 if (connected) 306 if (connected)
306 { 307 {
307 ca* image = scr->getCookedImage(); // get the image 308 ca* image = scr->getCookedImage(); // get the image
308 gui->setImage(image, 309 gui->setImage(image,
309 scr->getLines(), 310 scr->getLines(),
310 scr->getColumns()); // actual refresh 311 scr->getColumns()); // actual refresh
311 free(image); 312 free(image);
312 313
313 //FIXME: check that we do not trigger other draw event here. 314 //FIXME: check that we do not trigger other draw event here.
314 gui->setScroll(scr->getHistCursor(),scr->getHistLines()); 315 gui->setScroll(scr->getHistCursor(),scr->getHistLines());
315 316
316 } 317 }
317} 318}
318 319
319void TEmulation::bulkStart() 320void TEmulation::bulkStart()
320{ 321{
321 if (bulk_timer.isActive()) bulk_timer.stop(); 322 if (bulk_timer.isActive()) bulk_timer.stop();
322} 323}
323 324
324void TEmulation::bulkEnd() 325void TEmulation::bulkEnd()
325{ 326{
326 if ( bulk_nlcnt > gui->Lines() || bulk_incnt > 20 ) 327 if ( bulk_nlcnt > gui->Lines() || bulk_incnt > 20 )
327 showBulk(); // resets bulk_??cnt to 0, too. 328 showBulk(); // resets bulk_??cnt to 0, too.
328 else 329 else
329 bulk_timer.start(BULK_TIMEOUT,TRUE); 330 bulk_timer.start(BULK_TIMEOUT,TRUE);
330} 331}
331 332
332void TEmulation::setConnect(bool c) 333void TEmulation::setConnect(bool c)
333{ 334{
334 connected = c; 335 connected = c;
335 if ( connected) 336 if ( connected)
336 { 337 {
337 onImageSizeChange(gui->Lines(), gui->Columns()); 338 onImageSizeChange(gui->Lines(), gui->Columns());
338 showBulk(); 339 showBulk();
339 } 340 }
340 else 341 else
341 { 342 {
342 scr->clearSelection(); 343 scr->clearSelection();
343 } 344 }
344} 345}
345 346
346// --------------------------------------------------------------------------- 347// ---------------------------------------------------------------------------
347 348
348/*! triggered by image size change of the TEWidget `gui'. 349/*! triggered by image size change of the TEWidget `gui'.
349 350
350 This event is simply propagated to the attached screens 351 This event is simply propagated to the attached screens
351 and to the related serial line. 352 and to the related serial line.
352*/ 353*/
353 354
354void TEmulation::onImageSizeChange(int lines, int columns) { 355void TEmulation::onImageSizeChange(int lines, int columns) {
355 if (!connected) return; 356 if (!connected) return;
356 screen[0]->resizeImage(lines,columns); 357 screen[0]->resizeImage(lines,columns);
357 screen[1]->resizeImage(lines,columns); 358 screen[1]->resizeImage(lines,columns);
358 showBulk(); 359 showBulk();
359 emit ImageSizeChanged(lines,columns); // propagate event to serial line 360 emit ImageSizeChanged(lines,columns); // propagate event to serial line
360} 361}
361 362
362void TEmulation::onHistoryCursorChange(int cursor) { 363void TEmulation::onHistoryCursorChange(int cursor) {
363 if (!connected) return; 364 if (!connected) return;
364 scr->setHistCursor(cursor); 365 scr->setHistCursor(cursor);
365 showBulk(); 366 showBulk();
366} 367}
367 368
368void TEmulation::onHorzCursorChange(int cursor) { 369void TEmulation::onHorzCursorChange(int cursor) {
369 if (!connected) return; 370 if (!connected) return;
370 scr->setHorzCursor(cursor); 371 scr->setHorzCursor(cursor);
371 showBulk(); 372 showBulk();
372} 373}
373 374
374void TEmulation::setColumns(int columns) { 375void TEmulation::setColumns(int columns) {
375 //FIXME: this goes strange ways. 376 //FIXME: this goes strange ways.
376 // Can we put this straight or explain it at least? 377 // Can we put this straight or explain it at least?
377 emit changeColumns(columns); 378 emit changeColumns(columns);
378} 379}
diff --git a/core/apps/embeddedkonsole/commandeditdialog.cpp b/core/apps/embeddedkonsole/commandeditdialog.cpp
index dd35466..03cba87 100644
--- a/core/apps/embeddedkonsole/commandeditdialog.cpp
+++ b/core/apps/embeddedkonsole/commandeditdialog.cpp
@@ -1,199 +1,199 @@
1//comandeditdialog.cpp 1//comandeditdialog.cpp
2 2
3#include "commandeditdialog.h" 3#include "commandeditdialog.h"
4#include "playlistselection.h" 4#include "playlistselection.h"
5#include <qstring.h> 5#include <qstring.h>
6#include <qpe/config.h> 6#include <qpe/config.h>
7#include <qtoolbar.h> 7#include <qtoolbar.h>
8#include <qwidget.h> 8#include <qwidget.h>
9#include <qmenubar.h> 9#include <qmenubar.h>
10#include <qpe/resource.h> 10#include <qpe/resource.h>
11#include <qlist.h> 11#include <qlist.h>
12#include <qtoolbutton.h> 12#include <qtoolbutton.h>
13#include <qvbox.h> 13#include <qvbox.h>
14#include <qlistview.h> 14#include <qlistview.h>
15#include <qlineedit.h> 15#include <qlineedit.h>
16#include <qheader.h> 16#include <qheader.h>
17#include <qlabel.h> 17#include <qlabel.h>
18#include <qmessagebox.h> 18#include <qmessagebox.h>
19#include "smallcommandeditdialogbase.h" 19#include "smallcommandeditdialogbase.h"
20 20
21CommandEditDialog::CommandEditDialog(QWidget *parent, const char* name, WFlags fl ) 21CommandEditDialog::CommandEditDialog(QWidget *parent, const char* name, WFlags fl )
22 : CommandEditDialogBase(parent, name, TRUE, fl) 22 : CommandEditDialogBase(parent, name, TRUE, fl)
23 23
24{ 24{
25 m_SuggestedCommandList->addColumn( tr("Command Selection") ); 25 m_SuggestedCommandList->addColumn( tr("Command Selection") );
26 m_SuggestedCommandList->header()->hide(); 26 m_SuggestedCommandList->header()->hide();
27 m_SuggestedCommandList->setSorting(-1,FALSE); 27 m_SuggestedCommandList->setSorting(-1,FALSE);
28 m_SuggestedCommandList->clearSelection(); 28 m_SuggestedCommandList->clearSelection();
29 m_SuggestedCommandList->setSorting(0,TRUE); 29 m_SuggestedCommandList->setSorting(0,TRUE);
30 QListViewItem *item; 30 QListViewItem *item;
31 item = new QListViewItem( m_SuggestedCommandList,"export "); 31 item = new QListViewItem( m_SuggestedCommandList,"export ");
32 item = new QListViewItem( m_SuggestedCommandList,"ifconfig "); 32 item = new QListViewItem( m_SuggestedCommandList,"ifconfig ");
33 item = new QListViewItem( m_SuggestedCommandList,"ipkg "); 33 item = new QListViewItem( m_SuggestedCommandList,"ipkg ");
34 item = new QListViewItem( m_SuggestedCommandList,"gzip "); 34 item = new QListViewItem( m_SuggestedCommandList,"gzip ");
35 item = new QListViewItem( m_SuggestedCommandList,"gunzip "); 35 item = new QListViewItem( m_SuggestedCommandList,"gunzip ");
36 item = new QListViewItem( m_SuggestedCommandList,"chgrp "); 36 item = new QListViewItem( m_SuggestedCommandList,"chgrp ");
37 item = new QListViewItem( m_SuggestedCommandList,"chown "); 37 item = new QListViewItem( m_SuggestedCommandList,"chown ");
38 item = new QListViewItem( m_SuggestedCommandList,"date "); 38 item = new QListViewItem( m_SuggestedCommandList,"date ");
39 item = new QListViewItem( m_SuggestedCommandList,"dd "); 39 item = new QListViewItem( m_SuggestedCommandList,"dd ");
40 item = new QListViewItem( m_SuggestedCommandList,"dmesg "); 40 item = new QListViewItem( m_SuggestedCommandList,"dmesg ");
41 item = new QListViewItem( m_SuggestedCommandList,"fuser "); 41 item = new QListViewItem( m_SuggestedCommandList,"fuser ");
42 item = new QListViewItem( m_SuggestedCommandList,"hostname "); 42 item = new QListViewItem( m_SuggestedCommandList,"hostname ");
43 item = new QListViewItem( m_SuggestedCommandList,"kill "); 43 item = new QListViewItem( m_SuggestedCommandList,"kill ");
44 item = new QListViewItem( m_SuggestedCommandList,"killall "); 44 item = new QListViewItem( m_SuggestedCommandList,"killall ");
45 item = new QListViewItem( m_SuggestedCommandList,"ln "); 45 item = new QListViewItem( m_SuggestedCommandList,"ln ");
46 item = new QListViewItem( m_SuggestedCommandList,"ln -s "); 46 item = new QListViewItem( m_SuggestedCommandList,"ln -s ");
47 item = new QListViewItem( m_SuggestedCommandList,"lsmod"); 47 item = new QListViewItem( m_SuggestedCommandList,"lsmod");
48 item = new QListViewItem( m_SuggestedCommandList,"depmod -a"); 48 item = new QListViewItem( m_SuggestedCommandList,"depmod -a");
49 item = new QListViewItem( m_SuggestedCommandList,"modprobe "); 49 item = new QListViewItem( m_SuggestedCommandList,"modprobe ");
50 item = new QListViewItem( m_SuggestedCommandList,"mount "); 50 item = new QListViewItem( m_SuggestedCommandList,"mount ");
51 item = new QListViewItem( m_SuggestedCommandList,"more "); 51 item = new QListViewItem( m_SuggestedCommandList,"more ");
52 item = new QListViewItem( m_SuggestedCommandList,"sort "); 52 item = new QListViewItem( m_SuggestedCommandList,"sort ");
53 item = new QListViewItem( m_SuggestedCommandList,"touch "); 53 item = new QListViewItem( m_SuggestedCommandList,"touch ");
54 item = new QListViewItem( m_SuggestedCommandList,"umount "); 54 item = new QListViewItem( m_SuggestedCommandList,"umount ");
55 item = new QListViewItem( m_SuggestedCommandList,"mknod "); 55 item = new QListViewItem( m_SuggestedCommandList,"mknod ");
56 item = new QListViewItem( m_SuggestedCommandList,"netstat "); 56 item = new QListViewItem( m_SuggestedCommandList,"netstat ");
57 item = new QListViewItem( m_SuggestedCommandList,"route "); 57 item = new QListViewItem( m_SuggestedCommandList,"route ");
58 item = new QListViewItem( m_SuggestedCommandList,"cardctl eject "); 58 item = new QListViewItem( m_SuggestedCommandList,"cardctl eject ");
59 m_SuggestedCommandList->setSelected(m_SuggestedCommandList->firstChild(),TRUE); 59 m_SuggestedCommandList->setSelected(m_SuggestedCommandList->firstChild(),TRUE);
60 m_SuggestedCommandList->sort(); 60 m_SuggestedCommandList->sort();
61 61
62 connect( m_SuggestedCommandList, SIGNAL( clicked( QListViewItem * ) ), m_PlayListSelection, SLOT( addToSelection( QListViewItem *) ) ); 62 connect( m_SuggestedCommandList, SIGNAL( clicked( QListViewItem * ) ), m_PlayListSelection, SLOT( addToSelection( QListViewItem *) ) );
63 63
64 64
65 65
66 ToolButton1->setTextLabel("new"); 66 ToolButton1->setTextLabel("new");
67 ToolButton1->setPixmap(Resource::loadPixmap("new")); 67 ToolButton1->setPixmap(Resource::loadPixmap("new"));
68 ToolButton1->setAutoRaise(TRUE); 68 ToolButton1->setAutoRaise(TRUE);
69 ToolButton1->setFocusPolicy(QWidget::NoFocus); 69 ToolButton1->setFocusPolicy(QWidget::NoFocus);
70 connect(ToolButton1,SIGNAL(clicked()),this,SLOT(showAddDialog())); 70 connect(ToolButton1,SIGNAL(clicked()),this,SLOT(showAddDialog()));
71 71
72 ToolButton2->setTextLabel("edit"); 72 ToolButton2->setTextLabel("edit");
73 ToolButton2->setPixmap(Resource::loadPixmap("edit")); 73 ToolButton2->setPixmap(Resource::loadPixmap("edit"));
74 ToolButton2->setAutoRaise(TRUE); 74 ToolButton2->setAutoRaise(TRUE);
75 ToolButton2->setFocusPolicy(QWidget::NoFocus); 75 ToolButton2->setFocusPolicy(QWidget::NoFocus);
76 connect(ToolButton2,SIGNAL(clicked()),this,SLOT(showEditDialog())); 76 connect(ToolButton2,SIGNAL(clicked()),this,SLOT(showEditDialog()));
77 77
78 ToolButton3->setTextLabel("delete"); 78 ToolButton3->setTextLabel("delete");
79 ToolButton3->setPixmap(Resource::loadPixmap("editdelete")); 79 ToolButton3->setPixmap(Resource::loadPixmap("editdelete"));
80 ToolButton3->setAutoRaise(TRUE); 80 ToolButton3->setAutoRaise(TRUE);
81 ToolButton3->setFocusPolicy(QWidget::NoFocus); 81 ToolButton3->setFocusPolicy(QWidget::NoFocus);
82 connect(ToolButton3,SIGNAL(clicked()),m_PlayListSelection,SLOT(removeSelected())); 82 connect(ToolButton3,SIGNAL(clicked()),m_PlayListSelection,SLOT(removeSelected()));
83 83
84 ToolButton4->setTextLabel("up"); 84 ToolButton4->setTextLabel("up");
85 ToolButton4->setPixmap(Resource::loadPixmap("up")); 85 ToolButton4->setPixmap(Resource::loadPixmap("up"));
86 ToolButton4->setAutoRaise(TRUE); 86 ToolButton4->setAutoRaise(TRUE);
87 ToolButton4->setFocusPolicy(QWidget::NoFocus); 87 ToolButton4->setFocusPolicy(QWidget::NoFocus);
88 connect(ToolButton4,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedUp())); 88 connect(ToolButton4,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedUp()));
89 89
90 ToolButton5->setTextLabel("down"); 90 ToolButton5->setTextLabel("down");
91 ToolButton5->setPixmap(Resource::loadPixmap("down")); 91 ToolButton5->setPixmap(Resource::loadPixmap("down"));
92 ToolButton5->setAutoRaise(TRUE); 92 ToolButton5->setAutoRaise(TRUE);
93 ToolButton5->setFocusPolicy(QWidget::NoFocus); 93 ToolButton5->setFocusPolicy(QWidget::NoFocus);
94 94
95connect(ToolButton5,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedDown())); 95connect(ToolButton5,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedDown()));
96 96
97 97
98 98
99 99
100 QListViewItem *current = m_SuggestedCommandList->selectedItem(); 100 QListViewItem *current = m_SuggestedCommandList->selectedItem();
101 if ( current ) 101 if ( current )
102 item->moveItem( current ); 102 item->moveItem( current );
103 m_SuggestedCommandList->setSelected( item, TRUE ); 103 m_SuggestedCommandList->setSelected( item, TRUE );
104 m_SuggestedCommandList->ensureItemVisible( m_SuggestedCommandList->selectedItem() ); 104 m_SuggestedCommandList->ensureItemVisible( m_SuggestedCommandList->selectedItem() );
105 Config cfg("Konsole"); 105 Config cfg("Qkonsole");
106 cfg.setGroup("Commands"); 106 cfg.setGroup("Commands");
107 if (cfg.readEntry("Commands Set","FALSE") == "TRUE") { 107 if (cfg.readEntry("Commands Set","FALSE") == "TRUE") {
108 for (int i = 0; i < 100; i++) { 108 for (int i = 0; i < 100; i++) {
109 QString tmp; 109 QString tmp;
110 tmp = cfg.readEntry( QString::number(i),""); 110 tmp = cfg.readEntry( QString::number(i),"");
111 if (!tmp.isEmpty()) 111 if (!tmp.isEmpty())
112 m_PlayListSelection->addStringToSelection(tmp); 112 m_PlayListSelection->addStringToSelection(tmp);
113 } 113 }
114 } else { 114 } else {
115 115
116m_PlayListSelection->addStringToSelection("ls "); 116m_PlayListSelection->addStringToSelection("ls ");
117m_PlayListSelection->addStringToSelection("cardctl eject"); 117m_PlayListSelection->addStringToSelection("cardctl eject");
118m_PlayListSelection->addStringToSelection("cat "); 118m_PlayListSelection->addStringToSelection("cat ");
119m_PlayListSelection->addStringToSelection("cd "); 119m_PlayListSelection->addStringToSelection("cd ");
120m_PlayListSelection->addStringToSelection("chmod "); 120m_PlayListSelection->addStringToSelection("chmod ");
121m_PlayListSelection->addStringToSelection("cp "); 121m_PlayListSelection->addStringToSelection("cp ");
122m_PlayListSelection->addStringToSelection("dc "); 122m_PlayListSelection->addStringToSelection("dc ");
123m_PlayListSelection->addStringToSelection("df "); 123m_PlayListSelection->addStringToSelection("df ");
124m_PlayListSelection->addStringToSelection("dmesg"); 124m_PlayListSelection->addStringToSelection("dmesg");
125m_PlayListSelection->addStringToSelection("echo "); 125m_PlayListSelection->addStringToSelection("echo ");
126m_PlayListSelection->addStringToSelection("env"); 126m_PlayListSelection->addStringToSelection("env");
127m_PlayListSelection->addStringToSelection("find "); 127m_PlayListSelection->addStringToSelection("find ");
128m_PlayListSelection->addStringToSelection("free"); 128m_PlayListSelection->addStringToSelection("free");
129m_PlayListSelection->addStringToSelection("grep "); 129m_PlayListSelection->addStringToSelection("grep ");
130m_PlayListSelection->addStringToSelection("ifconfig "); 130m_PlayListSelection->addStringToSelection("ifconfig ");
131m_PlayListSelection->addStringToSelection("ipkg "); 131m_PlayListSelection->addStringToSelection("ipkg ");
132m_PlayListSelection->addStringToSelection("mkdir "); 132m_PlayListSelection->addStringToSelection("mkdir ");
133m_PlayListSelection->addStringToSelection("mv "); 133m_PlayListSelection->addStringToSelection("mv ");
134m_PlayListSelection->addStringToSelection("nc localhost 7776"); 134m_PlayListSelection->addStringToSelection("nc localhost 7776");
135m_PlayListSelection->addStringToSelection("nc localhost 7777"); 135m_PlayListSelection->addStringToSelection("nc localhost 7777");
136m_PlayListSelection->addStringToSelection("nslookup "); 136m_PlayListSelection->addStringToSelection("nslookup ");
137m_PlayListSelection->addStringToSelection("ping "); 137m_PlayListSelection->addStringToSelection("ping ");
138m_PlayListSelection->addStringToSelection("ps aux"); 138m_PlayListSelection->addStringToSelection("ps aux");
139m_PlayListSelection->addStringToSelection("pwd "); 139m_PlayListSelection->addStringToSelection("pwd ");
140m_PlayListSelection->addStringToSelection("rm "); 140m_PlayListSelection->addStringToSelection("rm ");
141m_PlayListSelection->addStringToSelection("rmdir "); 141m_PlayListSelection->addStringToSelection("rmdir ");
142m_PlayListSelection->addStringToSelection("route "); 142m_PlayListSelection->addStringToSelection("route ");
143m_PlayListSelection->addStringToSelection("set "); 143m_PlayListSelection->addStringToSelection("set ");
144m_PlayListSelection->addStringToSelection("traceroute"); 144m_PlayListSelection->addStringToSelection("traceroute");
145 145
146} 146}
147} 147}
148CommandEditDialog::~CommandEditDialog() 148CommandEditDialog::~CommandEditDialog()
149{ 149{
150} 150}
151 151
152void CommandEditDialog::accept() 152void CommandEditDialog::accept()
153{ 153{
154int i = 0; 154int i = 0;
155 Config *cfg = new Config("Konsole"); 155 Config *cfg = new Config("Qkonsole");
156 cfg->setGroup("Commands"); 156 cfg->setGroup("Commands");
157 cfg->clearGroup(); 157 cfg->clearGroup();
158 158
159 QListViewItemIterator it( m_PlayListSelection ); 159 QListViewItemIterator it( m_PlayListSelection );
160 160
161 for ( ; it.current(); ++it ) { 161 for ( ; it.current(); ++it ) {
162// qDebug(it.current()->text(0)); 162// qDebug(it.current()->text(0));
163 cfg->writeEntry(QString::number(i),it.current()->text(0)); 163 cfg->writeEntry(QString::number(i),it.current()->text(0));
164 i++; 164 i++;
165 165
166 } 166 }
167 cfg->writeEntry("Commands Set","TRUE"); 167 cfg->writeEntry("Commands Set","TRUE");
168// qDebug("CommandEditDialog::accept() - written"); 168// qDebug("CommandEditDialog::accept() - written");
169 delete cfg; 169 delete cfg;
170 emit commandsEdited(); 170 emit commandsEdited();
171 close(); 171 close();
172 172
173 173
174 174
175 175
176 176
177} 177}
178 178
179void CommandEditDialog::showEditDialog() 179void CommandEditDialog::showEditDialog()
180{ 180{
181editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE); 181editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE);
182d->setCaption("Edit command"); 182d->setCaption("Edit command");
183d->TextLabel->setText("Edit command:"); 183d->TextLabel->setText("Edit command:");
184d->commandEdit->setText(m_PlayListSelection->currentItem()->text(0)); 184d->commandEdit->setText(m_PlayListSelection->currentItem()->text(0));
185int i = d->exec(); 185int i = d->exec();
186if ((i==1) && (!(d->commandEdit->text()).isEmpty())) 186if ((i==1) && (!(d->commandEdit->text()).isEmpty()))
187 m_PlayListSelection->currentItem()->setText(0,(d->commandEdit->text())); 187 m_PlayListSelection->currentItem()->setText(0,(d->commandEdit->text()));
188} 188}
189 189
190void CommandEditDialog::showAddDialog() 190void CommandEditDialog::showAddDialog()
191{ 191{
192 192
193editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE); 193editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE);
194int i = d->exec(); 194int i = d->exec();
195if ((i==1) && (!(d->commandEdit->text()).isEmpty())) 195if ((i==1) && (!(d->commandEdit->text()).isEmpty()))
196m_PlayListSelection->addStringToSelection(d->commandEdit->text()); 196m_PlayListSelection->addStringToSelection(d->commandEdit->text());
197 197
198} 198}
199 199
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index ce8fb6b..d10b66d 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,1176 +1,1918 @@
1
1/* ---------------------------------------------------------------------- */ 2/* ---------------------------------------------------------------------- */
2/* */ 3/* */
3/* [main.C] Konsole */ 4/* [main.C] Konsole */
4/* */ 5/* */
5/* ---------------------------------------------------------------------- */ 6/* ---------------------------------------------------------------------- */
6/* */ 7/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 8/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */ 9/* */
9/* This file is part of Konsole, an X terminal. */ 10/* This file is part of Konsole, an X terminal. */
10/* */ 11/* */
11/* The material contained in here more or less directly orginates from */ 12/* The material contained in here more or less directly orginates from */
12/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ 13/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
13/* */ 14/* */
14/* ---------------------------------------------------------------------- */ 15/* ---------------------------------------------------------------------- */
15/* */ 16/* */
16/* Ported Konsole to Qt/Embedded */ 17/* Ported Konsole to Qt/Embedded */
17/* */ 18/* */
18/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 19/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
19/* */ 20/* */
20/* -------------------------------------------------------------------------- */ 21/* -------------------------------------------------------------------------- */
21// enhancements added by L.J. Potter <ljp@llornkcor.com> 22// enhancements added by L.J. Potter <ljp@llornkcor.com>
22//#define QT_QWS_OPIE 23//#define QT_QWS_OPIE
23 24
24#include "signal.h" 25#include <stdlib.h>
25 26
26#include <qpe/resource.h> 27#include <qpe/resource.h>
27 28
28#include <qdir.h> 29#include <qdir.h>
29#include <qevent.h> 30#include <qevent.h>
30#include <qdragobject.h> 31#include <qdragobject.h>
31#include <qobjectlist.h> 32#include <qobjectlist.h>
32#include <qtoolbutton.h> 33#include <qtoolbutton.h>
33#include <qtoolbar.h> 34#include <qtoolbar.h>
34#include <qpushbutton.h> 35#include <qpushbutton.h>
35#include <qfontdialog.h> 36#include <qfontdialog.h>
36#include <qglobal.h> 37#include <qglobal.h>
37#include <qpainter.h> 38#include <qpainter.h>
38#include <qmenubar.h> 39#include <qmenubar.h>
39#include <qmessagebox.h> 40#include <qmessagebox.h>
40#include <qaction.h> 41#include <qaction.h>
41#include <qapplication.h> 42#include <qapplication.h>
42#include <qfontmetrics.h> 43#include <qfontmetrics.h>
43#include <qcombobox.h> 44#include <qcombobox.h>
44#include <qevent.h> 45#include <qevent.h>
45#include <qtabwidget.h> 46#include <qtabwidget.h>
46#include <qtabbar.h> 47#include <qtabbar.h>
48#include <qpe/config.h>
47#include <qstringlist.h> 49#include <qstringlist.h>
48#include <qpalette.h> 50#include <qpalette.h>
49#include <qpe/config.h> 51#include <qfontdatabase.h>
50#include <qpe/qpeapplication.h> 52#include <qfile.h>
53#include <qspinbox.h>
54#include <qlayout.h>
55#include <qvbox.h>
51 56
52#include <unistd.h> 57#include <sys/wait.h>
53#include <pwd.h>
54#include <sys/types.h>
55//#include <sys/wait.h>
56#include <stdio.h> 58#include <stdio.h>
57#include <stdlib.h> 59#include <stdlib.h>
58#include <assert.h> 60#include <assert.h>
59 61
60#include "konsole.h" 62#include "konsole.h"
61#include "keytrans.h" 63#include "keytrans.h"
62#include "commandeditdialog.h" 64#include "commandeditdialog.h"
63 65
64#ifdef QT_QWS_OPIE 66#ifdef QT_QWS_OPIE
65#include <opie/colorpopupmenu.h> 67#include <opie/colorpopupmenu.h>
66#endif 68#endif
67 69
68 #include <qfontdatabase.h>// U.B. 70class EKNumTabBar : public QTabBar
69 #include <qstringlist.h>// U.B. 71{
70 #include <qvaluelist.h> // U.B.
71
72class EKNumTabBar : public QTabBar {
73public: 72public:
73 EKNumTabBar(QWidget *parent = 0, const char *name = 0) :
74 QTabBar(parent, name)
75 {}
76
77 // QList<QTab> *getTabList() { return(tabList()); }
78
74 void numberTabs() 79 void numberTabs()
75 { 80 {
76 // Yes, it really is this messy. QTabWidget needs functions 81 // Yes, it really is this messy. QTabWidget needs functions
77 // that provide acces to tabs in a sequential way. 82 // that provide acces to tabs in a sequential way.
78 int m=INT_MIN; 83 int m=INT_MIN;
79 for (int i=0; i<count(); i++) { 84 for (int i=0; i<count(); i++)
80 QTab* left=0; 85 {
81 QListIterator<QTab> it(*tabList()); 86 QTab* left=0;
82 int x=INT_MAX; 87 QListIterator<QTab> it(*tabList());
83 for( QTab* t; (t=it.current()); ++it ) { 88 int x=INT_MAX;
84 int tx = t->rect().x(); 89 for( QTab* t; (t=it.current()); ++it )
85 if ( tx<x && tx>m ) { 90 {
86 x = tx; 91 int tx = t->rect().x();
87 left = t; 92 if ( tx<x && tx>m )
88 } 93 {
89 } 94 x = tx;
90 if ( left ) { 95 left = t;
91 left->setText(QString::number(i+1)); 96 }
92 m = left->rect().x(); 97 }
93 } 98 if ( left )
94 } 99 {
100 left->setText(QString::number(i+1));
101 m = left->rect().x();
102 }
103 }
95 } 104 }
105
106 virtual QSize sizeHint() const
107 {
108 if (isHidden())
109 {
110 return(QSize(0,0));
111 }
112 else
113 {
114 QSize size = QTabBar::sizeHint();
115 int shrink = 5;
116 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600)
117 {
118 shrink = 10;
119 }
120 size.setHeight(size.height() - shrink);
121 return(size);
122 }
123 }
124
96}; 125};
97 126
98class EKNumTabWidget : public QTabWidget { 127class EKNumTabWidget : public QTabWidget
128{
99public: 129public:
100 EKNumTabWidget(QWidget* parent) : QTabWidget(parent) 130 EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
101 { 131 {
132 setTabBar(new EKNumTabBar(parent,"EKTabBar"));
133 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
102 } 134 }
103 135
136 EKNumTabBar *getTabBar() const
137 {
138 return ((EKNumTabBar*)tabBar());
139 }
140
141
104 void addTab(QWidget* w) 142 void addTab(QWidget* w)
105 { 143 {
106 QTab* t = new QTab(QString::number(tabBar()->count()+1)); 144 QTab* t = new QTab(QString::number(tabBar()->count()+1));
107 QTabWidget::addTab(w,t); 145 QTabWidget::addTab(w,t);
108 } 146 }
109 147
110 void removeTab(QWidget* w) 148 void removeTab(QWidget* w)
111 { 149 {
112 removePage(w); 150 removePage(w);
113 ((EKNumTabBar*)tabBar())->numberTabs(); 151 ((EKNumTabBar*)tabBar())->numberTabs();
114 } 152 }
115}; 153};
116 154
117// This could be configurable or dynamicly generated from the bash history 155// This could be configurable or dynamicly generated from the bash history
118// file of the user 156// file of the user
119static const char *commonCmds[] = 157static const char *commonCmds[] =
120{ 158 {
121 "ls ", // I left this here, cause it looks better than the first alpha 159 "ls ", // I left this here, cause it looks better than the first alpha
122 "cardctl eject", 160 "cardctl eject",
123 "cat ", 161 "cat ",
124 "cd ", 162 "cd ",
125 "chmod ", 163 "chmod ",
126 "clear", 164 "clear",
127 "cp ", 165 "cp ",
128 "dc ", 166 "dc ",
129 "df ", 167 "df ",
130 "dmesg", 168 "dmesg",
131 "echo ", 169 "echo ",
132 "env", 170 "env",
133 "find ", 171 "find ",
134 "free", 172 "free",
135 "grep ", 173 "grep ",
136 "ifconfig ", 174 "ifconfig ",
137 "ipkg ", 175 "ipkg ",
138 "mkdir ", 176 "mkdir ",
139 "mv ", 177 "mv ",
140 "nc localhost 7776", 178 "nc localhost 7776",
141 "nc localhost 7777", 179 "nc localhost 7777",
142 "netstat ", 180 "netstat ",
143 "nslookup ", 181 "nslookup ",
144 "ping ", 182 "ping ",
145 "ps aux", 183 "ps aux",
146 "pwd ", 184 "pwd ",
147 "qcop QPE/System 'linkChanged(QString)' ''", 185 "qcop QPE/System 'linkChanged(QString)' ''",
148 "qcop QPE/System 'restart()'", 186 "qcop QPE/System 'restart()'",
149 "qcop QPE/System 'quit()'", 187 "qcop QPE/System 'quit()'",
150 "rm ", 188 "rm ",
151 "rmdir ", 189 "rmdir ",
152 "route ", 190 "route ",
153 "set ", 191 "set ",
154 "traceroute", 192 "traceroute",
155 193
156/* 194 /*
157 "gzip", 195 "gzip",
158 "gunzip", 196 "gunzip",
159 "chgrp", 197 "chgrp",
160 "chown", 198 "chown",
161 "date", 199 "date",
162 "dd", 200 "dd",
163 "df", 201 "df",
164 "dmesg", 202 "dmesg",
165 "fuser", 203 "fuser",
166 "hostname", 204 "hostname",
167 "kill", 205 "kill",
168 "killall", 206 "killall",
169 "ln", 207 "ln",
170 "ping", 208 "ping",
171 "mount", 209 "mount",
172 "more", 210 "more",
173 "sort", 211 "sort",
174 "touch", 212 "touch",
175 "umount", 213 "umount",
176 "mknod", 214 "mknod",
177 "netstat", 215 "netstat",
178*/ 216 */
217
218 "exit",
219 NULL
220 };
179 221
180 "exit",
181 NULL
182};
183 222
184static void konsoleInit(const char** shell) { 223Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
185 if(setuid(getuid()) !=0) qDebug("setuid failed"); 224 QMainWindow(parent, name, fl)
186 if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges 225{
226 QStrList args;
227 init("/bin/bash",args);
228}
187 229
188 // signal (SIGSTOP, SIG_IGN); 230Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
189 231 : QMainWindow(0, name)
190// QPEApplication::grabKeyboard(); // for CTRL and ALT 232{
233 init(_pgm,_args);
234}
191 235
192// qDebug("keyboard grabbed"); 236struct HistoryItem
193#ifdef FAKE_CTRL_AND_ALT 237{
194 qDebug("Fake Ctrl and Alt defined"); 238 HistoryItem(int c, const QString &l)
195 QPEApplication::grabKeyboard(); // for CTRL and ALT 239 {
196#endif 240 count = c;
241 line = l;
242 }
243 int count;
244 QString line;
245};
197 246
198 *shell = getenv("SHELL"); 247class HistoryList : public QList<HistoryItem>
199// qWarning("SHell initially is %s", *shell ); 248{
249 virtual int compareItems( QCollection::Item item1, QCollection::Item item2)
250 {
251 int c1 = ((HistoryItem*)item1)->count;
252 int c2 = ((HistoryItem*)item2)->count;
253 if (c1 > c2)
254 return(1);
255 if (c1 < c2)
256 return(-1);
257 return(0);
258 }
259};
200 260
201 if (shell == NULL || *shell == '\0') { 261void Konsole::initCommandList()
202 struct passwd *ent = 0; 262{
203 uid_t me = getuid(); 263 // qDebug("Konsole::initCommandList");
204 *shell = "/bin/sh"; 264 Config cfg("Qkonsole");
265 cfg.setGroup("Commands");
266 // commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
267 commonCombo->clear();
205 268
206 while ( (ent = getpwent()) != 0 ) { 269 if (cfg.readEntry("ShellHistory","TRUE") == "TRUE")
207 if (ent->pw_uid == me) { 270 {
208 if (ent->pw_shell != "") 271 QString histfilename = QString(getenv("HOME")) + "/.bash_history";
209 *shell = ent->pw_shell; 272 histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
210 break; 273 QFile histfile(histfilename);
274 // note: compiler barfed on:
275 // QFile histfile(QString(getenv("HOME")) + "/.bash_history");
276 if (histfile.open( IO_ReadOnly ))
277 {
278 QString line;
279 uint i;
280 HistoryList items;
281
282 int lineno = 0;
283 while(!histfile.atEnd())
284 {
285 if (histfile.readLine(line, 200) < 0)
286 {
287 break;
288 }
289 line = line.left(line.length()-1);
290 lineno++;
291
292 for(i=0; i<items.count(); i++)
293 {
294 if (line == items.at(i)->line)
295 {
296 // weight recent commands & repeated commands more
297 // by adding up the index of each command
298 items.at(i)->count += lineno;
299 break;
300 }
301 }
302 if (i >= items.count())
303 {
304 items.append(new HistoryItem(lineno, line));
305 }
306 }
307 items.sort();
308 int n = items.count();
309 if (n > 40)
310 {
311 n = 40;
211 } 312 }
313 for(int i=0; i<n; i++)
314 {
315 // should insert start of command, but keep whole thing
316 if (items.at(items.count()-i-1)->line.length() < 30)
317 {
318 commonCombo->insertItem(items.at(items.count()-i-1)->line);
319 }
320 }
321 histfile.close();
322 }
323 }
324 if (cfg.readEntry("Commands Set","FALSE") == "FALSE")
325 {
326 for (int i = 0; commonCmds[i] != NULL; i++)
327 {
328 commonCombo->insertItem(commonCmds[i]);
329 }
330 }
331 else
332 {
333 for (int i = 0; i < 100; i++)
334 {
335 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
336 commonCombo->insertItem(cfg.readEntry( QString::number(i),""));
212 } 337 }
213 endpwent();
214 } 338 }
215 339
216// qWarning("SHELL now is %s", *shell );
217 340
218 if( putenv((char*)"COLORTERM=") !=0)
219 qDebug("putenv failed"); // to trigger mc's color detection
220} 341}
221 342
222Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 343static void sig_handler(int x)
223 QMainWindow(parent, name, fl)
224{ 344{
225 QStrList tmp; const char* shell; 345 printf("got signal %d\n",x);
226
227 setCaption( tr("Terminal") );
228
229 konsoleInit( &shell);
230// qWarning("Using shell %s", shell);
231 init(shell,tmp);
232} 346}
233 347
234 348void Konsole::init(const char* _pgm, QStrList & _args)
235
236void Konsole::initCommandList()
237{ 349{
238// qDebug("Konsole::initCommandList"); 350
239 Config cfg("Konsole"); 351#if 0
240 cfg.setGroup("Commands"); 352 for(int i=1; i<=31; i++)
241 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 353 {
242 commonCombo->clear(); 354 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV
243 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 355 && i != SIGINT && i != SIGILL && i != SIGTERM
244 for (int i = 0; commonCmds[i] != NULL; i++) { 356 && i != SIGBUS)
245 commonCombo->insertItem(commonCmds[i],i); 357 signal(i,sig_handler);
358 }
359#endif
360 signal(SIGSTOP, sig_handler);
361 signal(SIGCONT, sig_handler);
362 signal(SIGTSTP, sig_handler);
363
364 b_scroll = TRUE; // histon;
365 n_keytab = 0;
366 n_render = 0;
367 startUp=0;
368 fromMenu = FALSE;
369 fullscreen = false;
370
371 setCaption( "Qkonsole" );
372 setIcon( Resource::loadPixmap( "qkonsole/qkonsole" ) );
373
374 Config cfg("Qkonsole");
375 cfg.setGroup("Font");
376 QString tmp;
377
378 // initialize the list of allowed fonts ///////////////////////////////////
379
380 QString cfgFontName = cfg.readEntry("FontName","Lcfont");
381 int cfgFontSize = cfg.readNumEntry("FontSize",18);
382
383 cfont = -1;
384
385 // this code causes repeated access to all the font files
386 // which does slow down startup
387 QFontDatabase fontDB;
388 QStringList familyNames;
389 familyNames = fontDB.families( FALSE );
390 QString s;
391 int fontIndex = 0;
392 int familyNum = 0;
393 fontList = new QPopupMenu( this );
394
395 for(uint j = 0; j < (uint)familyNames.count(); j++)
396 {
397 s = familyNames[j];
398 if ( s.contains('-') )
399 {
400 int i = s.find('-');
401 s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]";
246 } 402 }
247 } else { 403 s[0] = s[0].upper();
248 for (int i = 0; i < 100; i++) { 404
249 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 405 QValueList<int> sizes = fontDB.pointSizes( familyNames[j] );
250 commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); 406
407 printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(),
408 sizes.count());
409
410 if (sizes.count() > 0)
411 {
412 QPopupMenu *sizeMenu;
413 QFont f;
414 int last_width = -1;
415 sizeMenu = NULL;
416
417 for(uint i = 0; i < (uint)sizes.count() + 4; i++)
418 {
419 // printf("family %s size %d ", familyNames[j].latin1(), sizes[i]);
420 // need to divide by 10 on the Z, but not otherwise
421 int size;
422
423 if (i >= (uint)sizes.count())
424 {
425 // try for expandable fonts
426 size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1);
427 }
428 else
429 {
430 printf("sizes[%d] = %d\n", i, sizes[i]);
431 size = sizes[i];
432 }
433#ifndef __i386__
434 // a hack, sizes on Z seem to be points*10
435 size /= 10;
436#endif
437
438 f = QFont(familyNames[j], size);
439 f.setFixedPitch(true);
440 QFontMetrics fm(f);
441 // don't trust f.fixedPitch() or f.exactMatch(), they lie!!
442 if (fm.width("l") == fm.width("m")
443 && (i < (uint)sizes.count()
444 || fm.width("m") > last_width))
445 {
446 if (i < (uint)sizes.count())
447 {
448 last_width = fm.width("m");
449 }
450 if (sizeMenu == NULL)
451 {
452 sizeMenu = new QPopupMenu();
453 }
454 int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex);
455 sizeMenu->setItemParameter(id, fontIndex);
456 sizeMenu->connectItem(id, this, SLOT(setFont(int)));
457 QString name = s + " " + QString::number(size);
458 fonts.append(new VTFont(name, f, familyNames[j], familyNum, size));
459 if (familyNames[j] == cfgFontName && size == cfgFontSize)
460 {
461 cfont = fontIndex;
462 }
463 printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size);
464 fontIndex++;
465 }
466 }
467 if (sizeMenu)
468 {
469 fontList->insertItem(s, sizeMenu, familyNum + 1000);
470
471 familyNum++;
472 }
251 } 473 }
474
252 } 475 }
253 476
254} 477 if (cfont < 0 || cfont >= (int)fonts.count())
478 {
479 cfont = 0;
480 }
255 481
256void Konsole::init(const char* _pgm, QStrList & _args) 482 // create terminal emulation framework ////////////////////////////////////
257{ 483 nsessions = 0;
258 b_scroll = TRUE; // histon;
259 n_keytab = 0;
260 n_render = 0;
261 startUp=0;
262 fromMenu = FALSE;
263
264 setCaption( tr("Terminal") );
265 setIcon( Resource::loadPixmap( "konsole" ) );
266
267 Config cfg("Konsole");
268 cfg.setGroup("Konsole");
269 QString tmp;
270 // initialize the list of allowed fonts ///////////////////////////////////
271 cfont = cfg.readNumEntry("FontID", 1);
272
273 QFont f = QFont("Micro", 4, QFont::Normal);
274 f.setFixedPitch(TRUE);
275 fonts.append(new VTFont(tr("Micro"), f));
276
277 f = QFont("Fixed", 7, QFont::Normal);
278 f.setFixedPitch(TRUE);
279 fonts.append(new VTFont(tr("Small Fixed"), f));
280
281 f = QFont("Fixed", 12, QFont::Normal);
282 f.setFixedPitch(TRUE);
283 fonts.append(new VTFont(tr("Medium Fixed"), f));
284
285// NEW STUFF
286
287 QStringList ignfont = cfg.readListEntry("IgnFont", ',');
288 /* If there is no "IgnFont = ..." entry in "myonsole.conf",
289 * put some Japanese fonts of the SL-C7x0 to "ignfont". */
290
291 if (ignfont.isEmpty()) {
292 ignfont = QStringList::split (',',"jisupasp,mmkjg1,mmkjg4,mmkjg5");
293 }
294
295 //QFont
296 f = QFont("Fixed", 16, QFont::Normal);
297 f.setFixedPitch(true);
298 fonts.append(new VTFont(tr("Default"), f));
299
300 int fcount = 1;
301
302 f.setCharSet(QFont::AnyCharSet);
303 f.setStyleHint(QFont::TypeWriter, QFont::PreferMatch);
304// f.setWeight(QFont::Normal);
305 484
306 /* 485 tab = new EKNumTabWidget(this);
307 * Look for installed font families. If the family is not in 486 // tab->setMargin(tab->margin()-5);
308 * the "ignfont" list, look for available sizes. 487 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
309 * If it is fixed pitch font, put the font and the size
310 * to the fontlist.
311 */
312 QFontDatabase fdb;
313 QStringList ff = fdb.families(false);
314
315 for (QStringList::Iterator it = ff.begin(); it != ff.end(); ++it ) {
316 QString fit = *it;
317
318 if( fit != "fixed" && fit != "micro" ) {
319 if ( ignfont.contains(*it) == 0) {
320 QValueList<int> pt = fdb.pointSizes(*it);
321
322 for (QValueList<int>::Iterator itv = pt.begin();
323 itv != pt.end(); ++itv ) {
324 int size = (*itv)/10;
325 if(size > 0) {
326 f.setFamily(*it);
327 f.setPointSize(size);
328 }
329
330 QFontMetrics fm(f);
331
332//qDebug("%s %d:\twidth('i')=%d, width('w')=%d", (*it).latin1(), (*itv)/10, fm.width('i'), fm.width('w'));
333
334 if (fm.width('i') == fm.width('w') ) {
335 qDebug((*it));
336 f.setFixedPitch(true);
337 fonts.append(new VTFont(*it + ' ' + QString::number(size), f));
338 fcount++;
339 }
340 }
341 }
342 }
343 }
344
345// END NEW STUFF
346
347
348// create terminal emulation framework ////////////////////////////////////
349 nsessions = 0;
350
351 tab = new EKNumTabWidget(this);
352
353 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
354
355 // create terminal toolbar ////////////////////////////////////////////////
356 setToolBarsMovable( FALSE );
357 QToolBar *menuToolBar = new QToolBar( this );
358 menuToolBar->setHorizontalStretchable( TRUE );
359
360 QMenuBar *menuBar = new QMenuBar( menuToolBar );
361
362 fontList = new QPopupMenu( this );
363 for(uint i = 0; i < fonts.count(); i++) {
364 VTFont *fnt = fonts.at(i);
365 fontList->insertItem(fnt->getName(), i);
366 }
367 488
368 fontChanged(cfont); 489 // create terminal toolbar ////////////////////////////////////////////////
490 setToolBarsMovable( FALSE );
491 menuToolBar = new QToolBar( this );
492 menuToolBar->setHorizontalStretchable( TRUE );
369 493
370 configMenu = new QPopupMenu( this); 494 QMenuBar *menuBar = new QMenuBar( menuToolBar );
371 colorMenu = new QPopupMenu( this);
372 scrollMenu = new QPopupMenu( this);
373 editCommandListMenu = new QPopupMenu( this);
374 495
375 configMenu->insertItem(tr("Command List"), editCommandListMenu); 496 bool c7xx = false;
497 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600)
498 {
499 c7xx = true;
500 }
501 QFont menuFont;
502 menuFont.setPointSize(c7xx? 18 : 10);
503 qApp->setFont(menuFont, true);
376 504
377 bool listHidden; 505 setFont(cfont);
378 cfg.setGroup("Menubar");
379 if( cfg.readEntry("Hidden","FALSE") == "TRUE") {
380 editCommandListMenu->insertItem( tr( "Show command list" ));
381 listHidden=TRUE;
382 } else {
383 editCommandListMenu->insertItem( tr( "Hide command list" ));
384 listHidden=FALSE;
385 }
386 506
387 cfg.setGroup("Tabs"); 507 configMenu = new QPopupMenu( this);
388 tmp=cfg.readEntry("Position","Bottom"); 508 colorMenu = new QPopupMenu( this);
389 if(tmp=="Top") { 509 scrollMenu = new QPopupMenu( this);
390 tab->setTabPosition(QTabWidget::Top); 510 editCommandListMenu = new QPopupMenu( this);
391 configMenu->insertItem( tr( "Tabs on Bottom" ) ); 511
392 } else { 512 configMenu->insertItem(tr("Command List"), editCommandListMenu);
393 tab->setTabPosition(QTabWidget::Bottom); 513
394 configMenu->insertItem(tr("Tabs on Top")); 514 bool listHidden;
395 } 515 cfg.setGroup("Menubar");
396 configMenu->insertSeparator(2); 516 if( cfg.readEntry("Hidden","FALSE") == "TRUE")
397 517 {
398 colorMenu->insertItem(tr( "Green on Black")); 518 ec_cmdlist = editCommandListMenu->insertItem( tr( "Show command list" ));
399 colorMenu->insertItem(tr( "Black on White")); 519 listHidden=TRUE;
400 colorMenu->insertItem(tr( "White on Black")); 520 }
401 colorMenu->insertItem(tr( "Black on Transparent")); 521 else
402 colorMenu->insertItem(tr( "Black on Red")); 522 {
403 colorMenu->insertItem(tr( "Red on Black")); 523 ec_cmdlist = editCommandListMenu->insertItem( tr( "Hide command list" ));
404 colorMenu->insertItem(tr( "Green on Yellow")); 524 listHidden=FALSE;
405 colorMenu->insertItem(tr( "Blue on Magenta")); 525 }
406 colorMenu->insertItem(tr( "Magenta on Blue")); 526
407 colorMenu->insertItem(tr( "Cyan on White")); 527 cfg.setGroup("Tabs");
408 colorMenu->insertItem(tr( "White on Cyan")); 528
409 colorMenu->insertItem(tr( "Blue on Black")); 529 tabMenu = new QPopupMenu(this);
410 colorMenu->insertItem(tr( "Amber on Black")); 530 tm_bottom = tabMenu->insertItem(tr("Bottom" ));
531 tm_top = tabMenu->insertItem(tr("Top"));
532 tm_hidden = tabMenu->insertItem(tr("Hidden"));
533
534 configMenu->insertItem(tr("Tabs"), tabMenu);
535
536 tmp=cfg.readEntry("Position","Top");
537 if(tmp=="Top")
538 {
539 tab->setTabPosition(QTabWidget::Top);
540 tab->getTabBar()->show();
541 tabPos = tm_top;
542 }
543 else if (tmp=="Bottom")
544 {
545 tab->setTabPosition(QTabWidget::Bottom);
546 tab->getTabBar()->show();
547 tabPos = tm_bottom;
548 }
549 else
550 {
551 tab->getTabBar()->hide();
552 tab->setMargin(tab->margin());
553 tabPos = tm_hidden;
554 }
555
556 cm_bw = colorMenu->insertItem(tr( "Black on White"));
557 cm_wb = colorMenu->insertItem(tr( "White on Black"));
558 cm_gb = colorMenu->insertItem(tr( "Green on Black"));
559 // cm_bt = colorMenu->insertItem(tr( "Black on Transparent"));
560 cm_br = colorMenu->insertItem(tr( "Black on Pink"));
561 cm_rb = colorMenu->insertItem(tr( "Pink on Black"));
562 cm_gy = colorMenu->insertItem(tr( "Green on Yellow"));
563 cm_bm = colorMenu->insertItem(tr( "Blue on Magenta"));
564 cm_mb = colorMenu->insertItem(tr( "Magenta on Blue"));
565 cm_cw = colorMenu->insertItem(tr( "Cyan on White"));
566 cm_wc = colorMenu->insertItem(tr( "White on Cyan"));
567 cm_bb = colorMenu->insertItem(tr( "Blue on Black"));
568 cm_ab = colorMenu->insertItem(tr( "Amber on Black"));
569 cm_default = colorMenu->insertItem(tr("default"));
411 570
412#ifdef QT_QWS_OPIE 571#ifdef QT_QWS_OPIE
413 colorMenu->insertItem(tr( "Custom")); 572
573 colorMenu->insertItem(tr( "Custom"));
414#endif 574#endif
415 575
416 configMenu->insertItem( tr("Font"), fontList ); 576 configMenu->insertItem(tr( "Colors") ,colorMenu);
417 configMenu->insertItem(tr( "Colors") ,colorMenu);
418
419 connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
420 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
421 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) ));
422 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int)));
423 connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int)));
424
425 menuBar->insertItem( tr("Options"), configMenu );
426
427 QToolBar *toolbar = new QToolBar( this );
428
429 QAction *a;
430
431 // Button Commands
432 a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 );
433 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar );
434 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 );
435 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar );
436 a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 );
437 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar );
438 a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 );
439 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar );
440 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 );
441 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
442 a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 );
443 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
444 a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
445 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar );
446/*
447 a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
448 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
449 a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
450 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
451*/
452 577
453 secondToolBar = new QToolBar( this ); 578 sessionList = new QPopupMenu(this);
454 secondToolBar->setHorizontalStretchable( TRUE ); 579 sessionList-> insertItem ( Resource::loadPixmap ( "qkonsole/qkonsole" ), tr( "new session" ), this,
580 SLOT(newSession()) );
455 581
456 commonCombo = new QComboBox( secondToolBar ); 582 // connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
457 commonCombo->setMaximumWidth(236); 583 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
584 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) ));
585 connect( tabMenu, SIGNAL( activated(int) ), this, SLOT( tabMenuSelected(int) ));
586 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int)));
587 connect( editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int)));
588 connect( sessionList, SIGNAL(activated(int)), this, SLOT( sessionListSelected(int) ) );
458 589
459 editCommandListMenu->insertItem( tr( "Quick Edit" ) ); 590 menuBar->insertItem( tr("View"), configMenu );
460 if( listHidden) { 591 menuBar->insertItem( tr("Fonts"), fontList );
461 secondToolBar->hide(); 592 menuBar->insertItem( tr("Sessions"), sessionList );
462 editCommandListMenu->setItemEnabled(-23 ,FALSE); 593
463 } 594 toolBar = new QToolBar( this );
464 editCommandListMenu->insertItem(tr( "Edit" ) );
465 595
466 cfg.setGroup("Commands"); 596 QAction *a;
467 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
468 597
469 initCommandList(); 598 // Button Commands
470// for (int i = 0; commonCmds[i] != NULL; i++) { 599 a = new QAction( tr("New"), Resource::loadPixmap( "konsole/Terminal" ), QString::null, 0, this, 0 );
471// commonCombo->insertItem( commonCmds[i], i ); 600 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) );
472// tmp = cfg.readEntry( QString::number(i),""); 601 a->addTo( toolBar );
473// if(tmp != "")
474// commonCombo->changeItem( tmp,i );
475// }
476 602
477 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); 603 a = new QAction( tr("Full Screen"), Resource::loadPixmap( "fullscreen" ), QString::null, 0, this, 0 );
604 connect( a, SIGNAL( activated() ), this, SLOT( toggleFullScreen() ) );
605 a->addTo( toolBar );
478 606
479 scrollMenu->insertItem(tr( "None" )); 607 a = new QAction( tr("Zoom"), Resource::loadPixmap( "zoom" ), QString::null, 0, this, 0 );
480 scrollMenu->insertItem(tr( "Left" )); 608 connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) );
481 scrollMenu->insertItem(tr( "Right" )); 609 a->addTo( toolBar );
482// scrollMenu->insertSeparator(4);
483// scrollMenu->insertItem(tr( "Horizontal" ));
484 610
485 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
486 611
487 int jut = configMenu->insertItem(tr( "Wrap" )); 612 /*
613 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 );
614 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolBar );
615 a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 );
616 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolBar );
617 a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 );
618 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolBar );
619 */
620 /*
621 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 );
622 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolBar );
623 a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 );
624 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolBar );
625 */
626 a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
627 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) );
628 a->addTo( toolBar );
629
630 secondToolBar = new QToolBar( this );
631 secondToolBar->setHorizontalStretchable( TRUE );
632
633 commonCombo = new QComboBox( secondToolBar );
634 // commonCombo->setMaximumWidth(236);
635
636 ec_quick = editCommandListMenu->insertItem( tr( "Quick Edit" ) );
637 if( listHidden)
638 {
639 secondToolBar->hide();
640 editCommandListMenu->setItemEnabled(ec_quick ,FALSE);
641 }
642 ec_edit = editCommandListMenu->insertItem(tr( "Edit" ) );
643
644 cfg.setGroup("Commands");
645 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
646
647 initCommandList();
648 // for (int i = 0; commonCmds[i] != NULL; i++) {
649 // commonCombo->insertItem( commonCmds[i], i );
650 // tmp = cfg.readEntry( QString::number(i),"");
651 // if(tmp != "")
652 // commonCombo->changeItem( tmp,i );
653 // }
654
655 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
656
657 sm_none = scrollMenu->insertItem(tr( "None" ));
658 sm_left = scrollMenu->insertItem(tr( "Left" ));
659 sm_right = scrollMenu->insertItem(tr( "Right" ));
660 // scrollMenu->insertSeparator(4);
661 // scrollMenu->insertItem(tr( "Horizontal" ));
662
663 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
664
665 configMenu->insertItem(tr( "History" ), this, SLOT(historyDialog()));
666
667 cm_wrap = configMenu->insertItem(tr( "Wrap" ));
488 cfg.setGroup("ScrollBar"); 668 cfg.setGroup("ScrollBar");
489 configMenu->setItemChecked(jut, cfg.readBoolEntry("HorzScroll",0)); 669 configMenu->setItemChecked(cm_wrap, cfg.readBoolEntry("HorzScroll",0));
490 670
491 jut = configMenu->insertItem(tr( "Use Beep" )); 671 cm_beep = configMenu->insertItem(tr( "Use Beep" ));
492 cfg.setGroup("Menubar"); 672 cfg.setGroup("Menubar");
493 673 configMenu->setItemChecked(cm_beep, cfg.readBoolEntry("useBeep",0));
494 configMenu->setItemChecked(jut, cfg.readBoolEntry("useBeep",0)); 674
495 675 fullscreen_msg = new QLabel(this);
496 676 fullscreen_msg-> setAlignment ( AlignCenter | SingleLine );
497//scrollMenuSelected(-29); 677 fullscreen_msg-> hide();
498// cfg.setGroup("ScrollBar"); 678 fullscreen_msg-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ));
499// if(cfg.readBoolEntry("HorzScroll",0)) { 679 fullscreen_msg-> setAutoResize(true);
500// if(cfg.readNumEntry("Position",2) == 0) 680 fullscreen_msg-> setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
501// te->setScrollbarLocation(1); 681 fullscreen_msg-> setText(tr("To exit fullscreen, tap here."));
502// else 682
503// te->setScrollbarLocation(0); 683 fullscreen_timer = new QTimer(this);
504// te->setScrollbarLocation( cfg.readNumEntry("Position",2)); 684 connect(fullscreen_timer, SIGNAL(timeout()),
505// te->setWrapAt(120); 685 this, SLOT(fullscreenTimeout()));
506// } 686 show_fullscreen_msg = true;
507 // create applications ///////////////////////////////////////////////////// 687
508 setCentralWidget(tab); 688 //scrollMenuSelected(-29);
509 689 // cfg.setGroup("ScrollBar");
510 // load keymaps //////////////////////////////////////////////////////////// 690 // if(cfg.readBoolEntry("HorzScroll",0)) {
511 KeyTrans::loadAll(); 691 // if(cfg.readNumEntry("Position",2) == 0)
512 for (int i = 0; i < KeyTrans::count(); i++) 692 // te->setScrollbarLocation(1);
513 { KeyTrans* s = KeyTrans::find(i); 693 // else
514 assert( s ); 694 // te->setScrollbarLocation(0);
515 } 695 // te->setScrollbarLocation( cfg.readNumEntry("Position",2));
696 // te->setWrapAt(120);
697 // }
698 // create applications /////////////////////////////////////////////////////
699 setCentralWidget(tab);
700
701 // load keymaps ////////////////////////////////////////////////////////////
702 KeyTrans::loadAll();
703 for (int i = 0; i < KeyTrans::count(); i++)
704 {
705 KeyTrans* s = KeyTrans::find(i);
706 assert( s );
707 }
708
709 se_pgm = _pgm;
710 se_args = _args;
711
712 cfg.setGroup("CommandLine");
516 713
517 se_pgm = _pgm; 714 if (cfg.hasKey("shell_args"))
518 se_args = _args; 715 {
519 se_args.prepend("--login"); 716 QStringList se_args_list = cfg.readListEntry("shell_args",'|');
520parseCommandLine(); 717 for(uint i = 0; i < se_args_list.count(); i++)
521 // read and apply default values /////////////////////////////////////////// 718 {
522 resize(321, 321); // Dummy. 719 se_args.prepend(se_args_list[se_args_list.count() - i - 1].latin1());
523 QSize currentSize = size(); 720 }
524 if (currentSize != size()) 721 }
525 defaultSize = size(); 722 else
723 {
724 se_args.prepend("--login");
725 }
726
727 se_pgm = cfg.readEntry("shell_bin", QString(se_pgm));
728
729 // this is the "documentation" for those who know to look
730 if (! cfg.hasKey("shell_args"))
731 {
732 cfg.writeEntry("shell_args",QStringList::fromStrList(se_args),'|');
733 }
734 if (! cfg.hasKey("shell_bin"))
735 {
736 cfg.writeEntry("shell_bin",QString(se_pgm));
737 }
738
739 parseCommandLine();
740
741 // read and apply default values ///////////////////////////////////////////
742 resize(321, 321); // Dummy.
743 QSize currentSize = size();
744 if (currentSize != size())
745 defaultSize = size();
746
747
748 /* allows us to catch cancel/escape */
749 reparent ( 0, WStyle_Customize | WStyle_NoBorder,
750 QPoint ( 0, 0 ));
526} 751}
527 752
528void Konsole::show() 753void Konsole::show()
529{ 754{
530 if ( !nsessions ) { 755 if ( !nsessions )
531 newSession(); 756 {
532 } 757 newSession();
533 QMainWindow::show(); 758 }
759 QMainWindow::show();
534 760
535} 761}
536 762
537void Konsole::initSession(const char*, QStrList &) 763void Konsole::initSession(const char*, QStrList &)
538{ 764{
539 QMainWindow::show(); 765 QMainWindow::show();
540} 766}
541 767
542Konsole::~Konsole() 768Konsole::~Konsole()
543{ 769{
544 while (nsessions > 0) { 770 while (nsessions > 0)
545 doneSession(getTe()->currentSession, 0); 771 {
546 } 772 doneSession(getTe(), 0);
773 }
774}
775
776void
777Konsole::historyDialog()
778{
779 QDialog *d = new QDialog ( this, "histdlg", true );
780 // d-> setCaption ( tr( "History" ));
781
782 QBoxLayout *lay = new QVBoxLayout ( d, 4, 4 );
783
784 QLabel *l = new QLabel ( tr( "History Lines:" ), d );
785 lay-> addWidget ( l );
786
787 Config cfg("Qkonsole");
788 cfg.setGroup("History");
789 int hist = cfg.readNumEntry("history_lines",300);
790 int avg_line = cfg.readNumEntry("avg_line_length",60);
791
792 QSpinBox *spin = new QSpinBox ( 1, 100000, 20, d );
793 spin-> setValue ( hist );
794 spin-> setWrapping ( true );
795 spin-> setButtonSymbols ( QSpinBox::PlusMinus );
796 lay-> addWidget ( spin );
797
798 if ( d-> exec ( ) == QDialog::Accepted )
799 {
800 cfg.writeEntry("history_lines", spin->value());
801 cfg.writeEntry("avg_line_length", avg_line);
802 if (getTe() != NULL)
803 {
804 getTe()->currentSession->setHistory(true);
805 }
806 }
807
808 delete d;
809}
810
811
812void Konsole::cycleZoom()
813{
814 TEWidget* te = getTe();
815 QFont font = te->getVTFont();
816 int size = font.pointSize();
817 changeFontSize(1);
818 font = te->getVTFont();
819 if (font.pointSize() <= size)
820 {
821 do
822 {
823 font = te->getVTFont();
824 size = font.pointSize();
825 changeFontSize(-1);
826 font = te->getVTFont();
827 }
828 while (font.pointSize() < size);
829 }
830}
831
832void Konsole::changeFontSize(int delta)
833{
834 // printf("delta font size %d\n", delta);
835 TEWidget* te = getTe();
836 QFont font = te->getVTFont();
837 int size = font.pointSize();
838 int closest = delta > 0? 10000 : -10000;
839 int closest_font = -1;
840 for(uint i = 0; i < fonts.count(); i++)
841 {
842 if (fonts.at(i)->getFont() == font)
843 {
844 if (delta > 0)
845 {
846 if (i+1 < fonts.count()
847 && fonts.at(i+1)->getFamilyNum() == fonts.at(i)->getFamilyNum())
848 {
849 setFont(i+1);
850 printf("font %d\n", i+1);
851 return;
852 }
853 }
854 else if (delta < 0)
855 {
856 if (i > 0
857 && fonts.at(i-1)->getFamilyNum() == fonts.at(i)->getFamilyNum())
858 {
859 setFont(i-1);
860 printf("font %d\n", i-1);
861 return;
862 }
863 }
864 }
865 int fsize = fonts.at(i)->getSize();
866 printf("%d size=%d fsize=%d closest=%d\n", i, size, fsize, closest);
867 if ((delta > 0 && fsize > size && fsize < closest)
868 || (delta < 0 && fsize < size && fsize > closest))
869 {
870 closest = fsize;
871 closest_font = i;
872 }
873 }
874 if (closest_font >= 0)
875 {
876 printf("font closest %d (%d)\n", closest_font, closest);
877 setFont(closest_font);
878 }
879}
880
881int Konsole::findFont(QString name, int size, bool exactMatch)
882{
883 for(uint i = 0; i < fonts.count(); i++)
884 {
885 if (fonts.at(i)->getName() == name
886 && fonts.at(i)->getSize() == size)
887 {
888 return(i);
889 }
890 }
891 if (exactMatch)
892 {
893 return(-1);
894 }
895 for(uint i = 0; i < fonts.count(); i++)
896 {
897 if (fonts.at(i)->getSize() == size)
898 {
899 return(i);
900 }
901 }
902 return(-1);
903}
547 904
548 Config cfg("Konsole"); 905void Konsole::setFont(int f)
549 cfg.setGroup("Konsole"); 906{
550 cfg.writeEntry("FontID", cfont); 907 VTFont* font = fonts.at(f);
908 if (font)
909 {
910 TEWidget* te = getTe();
911 if (te != 0)
912 {
913 te->setVTFont(font->getFont());
914 }
915 cfont = f;
916
917 int familyNum = font->getFamilyNum();
918 int size = font->getSize();
919 printf("familyNum = %d size = %d count=%d\n", familyNum, size,
920 fontList->count());
921 for(int i = 0; i < (int)fontList->count(); i++)
922 {
923 fontList->setItemChecked(i + 1000, i == familyNum);
924 }
925 for(int i = 0; i < (int)fonts.count(); i++)
926 {
927 fontList->setItemChecked(i, fonts.at(i)->getFamilyNum() == familyNum
928 && fonts.at(i)->getSize() == size);
929 }
930 Config cfg("Qkonsole");
931 cfg.setGroup("Font");
932 QString ss = "Session"+ QString::number(tab->currentPageIndex()+1);
933 if (tab->currentPageIndex() == 0)
934 {
935 cfg.writeEntry("FontName", fonts.at(cfont)->getFamily());
936 cfg.writeEntry("FontSize", fonts.at(cfont)->getSize());
937 }
938 cfg.writeEntry("FontName"+ss, fonts.at(cfont)->getFamily());
939 cfg.writeEntry("FontSize"+ss, fonts.at(cfont)->getSize());
940 }
551} 941}
552 942
943#if 0
553void Konsole::fontChanged(int f) 944void Konsole::fontChanged(int f)
554{ 945{
555 VTFont* font = fonts.at(f); 946 VTFont* font = fonts.at(f);
556 if (font != 0) { 947 if (font != 0)
557 for(uint i = 0; i < fonts.count(); i++) { 948 {
949 for(uint i = 0; i < fonts.count(); i++)
950 {
558 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); 951 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
559 } 952 }
560 953
561 cfont = f; 954 cfont = f;
562 955
563 TEWidget* te = getTe(); 956 TEWidget* te = getTe();
564 if (te != 0) { 957 if (te != 0)
958 {
565 te->setVTFont(font->getFont()); 959 te->setVTFont(font->getFont());
566 } 960 }
567 } 961 }
568} 962}
963#endif
569 964
570 965
571void Konsole::enterCommand(int c) 966void Konsole::enterCommand(int c)
572{ 967{
573 TEWidget* te = getTe(); 968 TEWidget* te = getTe();
574 if (te != 0) { 969 if (te != 0)
575 if(!commonCombo->editable()) { 970 {
971 if(!commonCombo->editable())
972 {
576 QString text = commonCombo->text(c); //commonCmds[c]; 973 QString text = commonCombo->text(c); //commonCmds[c];
577 te->emitText(text); 974 te->emitText(text);
578 } else { 975 }
976 else
977 {
579 changeCommand( commonCombo->text(c), c); 978 changeCommand( commonCombo->text(c), c);
580 } 979 }
581 } 980 }
582} 981}
583 982
584void Konsole::hitEnter() 983void Konsole::hitEnter()
585{ 984{
586 TEWidget* te = getTe(); 985 TEWidget* te = getTe();
587 if (te != 0) { 986 if (te != 0)
588 te->emitText(QString("\r")); 987 {
988 te->emitText(QString("\r"));
589 } 989 }
590} 990}
591 991
592void Konsole::hitSpace() 992void Konsole::hitSpace()
593{ 993{
594 TEWidget* te = getTe(); 994 TEWidget* te = getTe();
595 if (te != 0) { 995 if (te != 0)
596 te->emitText(QString(" ")); 996 {
997 te->emitText(QString(" "));
597 } 998 }
598} 999}
599 1000
600void Konsole::hitTab() 1001void Konsole::hitTab()
601{ 1002{
602 TEWidget* te = getTe(); 1003 TEWidget* te = getTe();
603 if (te != 0) { 1004 if (te != 0)
604 te->emitText(QString("\t")); 1005 {
1006 te->emitText(QString("\t"));
605 } 1007 }
606} 1008}
607 1009
608void Konsole::hitPaste() 1010void Konsole::hitPaste()
609{ 1011{
610 TEWidget* te = getTe(); 1012 TEWidget* te = getTe();
611 if (te != 0) { 1013 if (te != 0)
612 te->pasteClipboard(); 1014 {
1015 te->pasteClipboard();
613 } 1016 }
614} 1017}
615 1018
616void Konsole::hitUp() 1019void Konsole::hitUp()
617{ 1020{
618 TEWidget* te = getTe(); 1021 TEWidget* te = getTe();
619 if (te != 0) { 1022 if (te != 0)
620 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); 1023 {
621 QApplication::sendEvent( te, &ke ); 1024 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
1025 QApplication::sendEvent( te, &ke );
622 } 1026 }
623} 1027}
624 1028
625void Konsole::hitDown() 1029void Konsole::hitDown()
626{ 1030{
627 TEWidget* te = getTe(); 1031 TEWidget* te = getTe();
628 if (te != 0) { 1032 if (te != 0)
629 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); 1033 {
630 QApplication::sendEvent( te, &ke ); 1034 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
1035 QApplication::sendEvent( te, &ke );
631 } 1036 }
632} 1037}
633 1038
634/** 1039/**
635 This function calculates the size of the external widget 1040 This function calculates the size of the external widget
636 needed for the internal widget to be 1041 needed for the internal widget to be
637 */ 1042 */
638QSize Konsole::calcSize(int columns, int lines) { 1043QSize Konsole::calcSize(int columns, int lines)
1044{
639 TEWidget* te = getTe(); 1045 TEWidget* te = getTe();
640 if (te != 0) { 1046 if (te != 0)
641 QSize size = te->calcSize(columns, lines); 1047 {
642 return size; 1048 QSize size = te->calcSize(columns, lines);
643 } else { 1049 return size;
644 QSize size; 1050 }
645 return size; 1051 else
1052 {
1053 QSize size;
1054 return size;
646 } 1055 }
647} 1056}
648 1057
649/** 1058/**
650 sets application window to a size based on columns X lines of the te 1059 sets application window to a size based on columns X lines of the te
651 guest widget. Call with (0,0) for setting default size. 1060 guest widget. Call with (0,0) for setting default size.
652*/ 1061*/
653 1062
654void Konsole::setColLin(int columns, int lines) 1063void Konsole::setColLin(int columns, int lines)
655{ 1064{
656 qDebug("konsole::setColLin:: Columns %d", columns); 1065 qDebug("konsole::setColLin:: Columns %d", columns);
657 1066
658 if ((columns==0) || (lines==0)) 1067 if ((columns==0) || (lines==0))
659 {
660 if (defaultSize.isEmpty()) // not in config file : set default value
661 { 1068 {
662 defaultSize = calcSize(80,24); 1069 if (defaultSize.isEmpty()) // not in config file : set default value
663 // notifySize(24,80); // set menu items (strange arg order !) 1070 {
1071 defaultSize = calcSize(80,24);
1072 // notifySize(24,80); // set menu items (strange arg order !)
1073 }
1074 resize(defaultSize);
1075 }
1076 else
1077 {
1078 resize(calcSize(columns, lines));
1079 // notifySize(lines,columns); // set menu items (strange arg order !)
664 } 1080 }
665 resize(defaultSize);
666 } else {
667 resize(calcSize(columns, lines));
668 // notifySize(lines,columns); // set menu items (strange arg order !)
669 }
670} 1081}
671 1082
672/* 1083/*
673void Konsole::setFont(int fontno) 1084void Konsole::setFont(int fontno)
674{ 1085{
675 QFont f; 1086 QFont f;
676 if (fontno == 0) 1087 if (fontno == 0)
677 f = defaultFont = QFont( "Helvetica", 12 ); 1088 f = defaultFont = QFont( "Helvetica", 12 );
678 else 1089 else
679 if (fonts[fontno][0] == '-') 1090 if (fonts[fontno][0] == '-')
680 f.setRawName( fonts[fontno] ); 1091 f.setRawName( fonts[fontno] );
681 else 1092 else
682 { 1093 {
683 f.setFamily(fonts[fontno]); 1094 f.setFamily(fonts[fontno]);
684 f.setRawMode( TRUE ); 1095 f.setRawMode( TRUE );
685 } 1096 }
686 if ( !f.exactMatch() && fontno != 0) 1097 if ( !f.exactMatch() && fontno != 0)
687 { 1098 {
688 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); 1099 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
689 QMessageBox(this, msg); 1100 QMessageBox(this, msg);
690 return; 1101 return;
691 } 1102 }
692 if (se) se->setFontNo(fontno); 1103 if (se) se->setFontNo(fontno);
693 te->setVTFont(f); 1104 te->setVTFont(f);
694 n_font = fontno; 1105 n_font = fontno;
695} 1106}
696*/ 1107*/
697 1108
698// --| color selection |------------------------------------------------------- 1109// --| color selection |-------------------------------------------------------
699 1110
700void Konsole::changeColumns(int columns) 1111void Konsole::changeColumns(int /*columns*/)
701{ 1112{ //FIXME this seems to cause silliness when reset command is executed
702 //FIXME this seems to cause silliness when reset command is executed 1113 // qDebug("change columns");
703 // qDebug("change columns"); 1114 // TEWidget* te = getTe();
704 // TEWidget* te = getTe(); 1115 // if (te != 0) {
705 // if (te != 0) { 1116 // setColLin(columns,te->Lines());
706 // setColLin(columns,te->Lines()); 1117 // te->update();
707 // te->update(); 1118 // }
708 // }
709} 1119}
710 1120
711//FIXME: If a child dies during session swap, 1121//FIXME: If a child dies during session swap,
712// this routine might be called before 1122// this routine might be called before
713// session swap is completed. 1123// session swap is completed.
714 1124
715void Konsole::doneSession(TESession*, int ) 1125void Konsole::doneSession(TEWidget* te, int )
716{ 1126{
717 TEWidget *te = getTe(); 1127 // TEWidget *te = NULL;
718 if (te != 0) { 1128 // if (sess->currentSession == tab->currentPage()) {
719 te->currentSession->setConnect(FALSE); 1129 // printf("done current session\n");
720 tab->removeTab(te); 1130 // te = getTe();
721 delete te->currentSession; 1131 // } else {
722 delete te; 1132 // int currentPage = tab->currentPageIndex();
723 nsessions--; 1133 // printf("done not current session\n");
724 } 1134 // for(int i = 0; i < nsessions; i++) {
1135 // tab->setCurrentPage(i);
1136 // printf("find session %d tab page %x session %x\n",
1137 // i, tab->currentPage(), sess->currentSession);
1138 // if (tab->currentPage() == sess->currentSession) {
1139 // printf("found session %d\n", i);
1140 // te = tab->currentPage();
1141 // break;
1142 // }
1143 // }
1144 // tab->setCurrentPage(currentPage);
1145 // }
1146 if (te != 0)
1147 {
1148 te->currentSession->setConnect(FALSE);
1149 tab->removeTab(te);
1150 delete te->currentSession;
1151 delete te;
1152 sessionList->removeItem(nsessions);
1153 nsessions--;
1154 }
1155 if (nsessions == 0)
1156 {
1157 close();
1158 }
1159}
725 1160
726 if (nsessions == 0) { 1161void Konsole::changeTitle(TEWidget* te, QString newTitle )
727 close(); 1162{
728 } 1163 if (te == getTe())
1164 {
1165 setCaption(newTitle + " - QKonsole");
1166 }
729} 1167}
730 1168
731void Konsole::newSession() {
732 if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory?
733 TEWidget* te = new TEWidget(tab);
734 Config c("Konsole");
735 c.setGroup("Menubar");
736 te->useBeep=c.readBoolEntry("useBeep",0);
737 1169
738// te->setBackgroundMode(PaletteBase); //we want transparent!! 1170void Konsole::newSession()
1171{
1172 if(nsessions < 15)
1173 { // seems to be something weird about 16 tabs on the Zaurus.... memory?
1174 TEWidget* te = new TEWidget(tab);
1175 Config cfg("Qkonsole");
1176 cfg.setGroup("Menubar");
1177
1178 // FIXME use more defaults from config file
1179 te->useBeep=cfg.readBoolEntry("useBeep",0);
1180
1181 // te->setBackgroundMode(PaletteBase); //we want transparent!!
1182
1183 cfg.setGroup("Font");
1184 QString sn = "Session" + QString::number(nsessions+1);
1185 printf("read font session %s\n", sn.latin1());
1186 QString fontName = cfg.readEntry("FontName"+sn,
1187 cfg.readEntry("FontName",
1188 fonts.at(cfont)->getFamily()));
1189 int fontSize = cfg.readNumEntry("FontSize"+sn,
1190 cfg.readNumEntry("FontSize",
1191 fonts.at(cfont)->getSize()));
1192 cfont = findFont(fontName, fontSize, false);
1193 printf("lookup font %s size %d got %d\n", fontName.latin1(), fontSize, cfont);
1194 if (cfont < 0)
1195 cfont = 0;
739 te->setVTFont(fonts.at(cfont)->getFont()); 1196 te->setVTFont(fonts.at(cfont)->getFont());
1197
740 tab->addTab(te); 1198 tab->addTab(te);
741 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); 1199 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm");
742 te->currentSession = se; 1200 te->currentSession = se;
743 connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); 1201 connect( se, SIGNAL(done(TEWidget*,int)), this, SLOT(doneSession(TEWidget*,int)) );
1202 connect( se, SIGNAL(changeTitle(TEWidget*,QString)), this,
1203 SLOT(changeTitle(TEWidget*,QString)) );
1204 connect(te, SIGNAL(changeFontSize(int)), this, SLOT(changeFontSize(int)));
1205 connect(te, SIGNAL(changeSession(int)), this, SLOT(changeSession(int)));
1206 connect(te, SIGNAL(newSession()), this, SLOT(newSession()));
1207 connect(te, SIGNAL(toggleFullScreen()), this, SLOT(toggleFullScreen()));
1208 connect(te, SIGNAL(setFullScreen(bool)), this, SLOT(setFullScreen(bool)));
744 se->run(); 1209 se->run();
745 se->setConnect(TRUE); 1210 se->setConnect(TRUE);
746 se->setHistory(b_scroll); 1211 se->setHistory(b_scroll);
747 tab->setCurrentPage(nsessions);
748 nsessions++; 1212 nsessions++;
1213 sessionList->insertItem(QString::number(nsessions), nsessions);
1214 sessionListSelected(nsessions);
749 doWrap(); 1215 doWrap();
750 setColor(); 1216 setColor(nsessions-1);
751 } 1217 }
752} 1218}
753 1219
754TEWidget* Konsole::getTe() { 1220TEWidget* Konsole::getTe()
755 if (nsessions) { 1221{
756 return (TEWidget *) tab->currentPage(); 1222 if (nsessions)
757 } else { 1223 {
758 return 0; 1224 return (TEWidget *) tab->currentPage();
759 } 1225 }
1226 else
1227 {
1228 return 0;
1229 }
760} 1230}
761 1231
762void Konsole::switchSession(QWidget* w) { 1232void Konsole::sessionListSelected(int id)
763 TEWidget* te = (TEWidget *) w; 1233{
1234 if (id < 0)
1235 {
1236 return;
1237 }
1238 QString selected = sessionList->text(id);
1239 EKNumTabBar *tabBar = tab->getTabBar();
764 1240
765 QFont teFnt = te->getVTFont(); 1241 int n = 0;
766 for(uint i = 0; i < fonts.count(); i++) { 1242 for(int i = 0; n < tabBar->count(); i++)
767 VTFont *fnt = fonts.at(i); 1243 {
768 bool cf = fnt->getFont() == teFnt; 1244 if (tabBar->tab(i))
769 fontList->setItemChecked(i, cf); 1245 {
770 if (cf) { 1246 // printf("selected = %s tab %d = %s\n", selected.latin1(),
771 cfont = i; 1247 // i, tabBar->tab(i)->text().latin1());
1248 if (tabBar->tab(i)->text() == selected)
1249 {
1250 tab->setCurrentPage(i);
1251 break;
1252 }
1253 n++;
1254 }
772 } 1255 }
773 }
774} 1256}
775 1257
776void Konsole::colorMenuIsSelected(int iD) { 1258
1259void Konsole::changeSession(int delta)
1260{
1261 printf("delta session %d\n", delta);
1262 QTabBar *tabBar = tab->getTabBar();
1263 int i = tabBar->tab(tabBar->currentTab())->text().toInt() - 1;
1264 i += delta;
1265 if (i < 0)
1266 i += tabBar->count();
1267 if (i >= tabBar->count())
1268 i -= tabBar->count();
1269
1270 QString selected = QString::number(i+1);
1271 int n = 0;
1272 for(int i = 0; n < tabBar->count(); i++)
1273 {
1274 if (tabBar->tab(i))
1275 {
1276 printf("selected = %s tab %d = %s\n", selected.latin1(),
1277 i, tabBar->tab(i)->text().latin1());
1278 if (tabBar->tab(i)->text() == selected)
1279 {
1280 tab->setCurrentPage(i);
1281 break;
1282 }
1283 n++;
1284 }
1285 }
1286}
1287
1288void Konsole::switchSession(QWidget* w)
1289{
1290 TEWidget* te = (TEWidget *) w;
1291 QFont teFnt = te->getVTFont();
1292 int familyNum = -1;
1293
1294 for(uint i = 0; i < fonts.count(); i++)
1295 {
1296 VTFont *fnt = fonts.at(i);
1297 bool cf = fnt->getFont() == teFnt;
1298 fontList->setItemChecked(i, cf);
1299 if (cf)
1300 {
1301 cfont = i;
1302 familyNum = fnt->getFamilyNum();
1303 }
1304 }
1305 for(int i = 0; i < (int)fontList->count(); i++)
1306 {
1307 fontList->setItemChecked(i + 1000, i == familyNum);
1308 }
1309 if (! te->currentSession->Title().isEmpty() )
1310 {
1311 setCaption(te->currentSession->Title() + " - QKonsole");
1312 }
1313 else
1314 {
1315 setCaption( "Qkonsole" );
1316 }
1317 // colorMenuSelected(te->color_menu_item);
1318}
1319
1320
1321void Konsole::toggleFullScreen()
1322{
1323 setFullScreen(! fullscreen);
1324}
1325
1326void Konsole::setFullScreen ( bool b )
1327{
1328 static QSize normalsize;
1329 static bool listHidden;
1330
1331 if (b == fullscreen)
1332 {
1333 return;
1334 }
1335
1336 fullscreen = b;
1337
1338 if ( b )
1339 {
1340 if ( !normalsize. isValid ( ))
1341 {
1342 normalsize = size ( );
1343 }
1344
1345 setFixedSize ( qApp-> desktop ( )-> size ( ));
1346 showNormal ( );
1347 reparent ( 0, WStyle_Customize | WStyle_NoBorder,
1348 QPoint ( 0, 0 ));
1349 showFullScreen ( );
1350
1351 menuToolBar->hide();
1352 toolBar->hide();
1353 listHidden = secondToolBar->isHidden();
1354 secondToolBar->hide();
1355 // commonCombo->hide();
1356 tab->getTabBar()->hide();
1357 tab->setMargin(tab->margin());
1358
1359 if (show_fullscreen_msg)
1360 {
1361 fullscreen_msg-> move(tab->x() + tab->width()/2 - fullscreen_msg->width()/2,
1362 qApp->desktop()->height()/16 - fullscreen_msg->height()/2);
1363 fullscreen_msg->show();
1364 fullscreen_timer->start(3000, true);
1365 show_fullscreen_msg = false;
1366 }
1367 }
1368 else
1369 {
1370 showNormal ( );
1371 reparent ( 0, WStyle_Customize, QPoint ( 0, 0 ));
1372 resize ( normalsize );
1373 showMaximized ( );
1374 normalsize = QSize ( );
1375
1376 menuToolBar->show();
1377 toolBar->show();
1378 if(! listHidden)
1379 {
1380 secondToolBar->show();
1381 }
1382 // commonCombo->show();
1383 menuToolBar->show();
1384 if (tabPos != tm_hidden)
1385 {
1386 tab->getTabBar()->show();
1387 }
1388 }
1389 tab->setMargin(tab->margin()); // cause setup to run
1390}
1391
1392
1393void Konsole::fullscreenTimeout()
1394{
1395 fullscreen_msg->hide();
1396}
1397
1398void Konsole::colorMenuIsSelected(int iD)
1399{
777 fromMenu = TRUE; 1400 fromMenu = TRUE;
778 colorMenuSelected(iD); 1401 colorMenuSelected(iD);
779} 1402}
780 1403
781/// ------------------------------- some new stuff by L.J. Potter 1404/// ------------------------------- some new stuff by L.J. Potter
1405
1406
782void Konsole::colorMenuSelected(int iD) 1407void Konsole::colorMenuSelected(int iD)
783{ // this is NOT pretty, elegant or anything else besides functional 1408{
784// QString temp; 1409 // this is NOT pretty, elegant or anything else besides functional
785// qDebug( temp.sprintf("colormenu %d", iD)); 1410 // QString temp;
1411 // qDebug( temp.sprintf("colormenu %d", iD));
786 1412
787 TEWidget* te = getTe(); 1413 TEWidget* te = getTe();
788 Config cfg("Konsole"); 1414 Config cfg("Qkonsole");
789 cfg.setGroup("Colors"); 1415 cfg.setGroup("Colors");
790// QColor foreground; 1416
791// QColor background;
792 colorMenu->setItemChecked(lastSelectedMenu,FALSE);
793 ColorEntry m_table[TABLE_COLORS]; 1417 ColorEntry m_table[TABLE_COLORS];
794 const ColorEntry * defaultCt=te->getdefaultColorTable(); 1418 const ColorEntry * defaultCt=te->getdefaultColorTable();
795 /////////// fore back 1419
796 int i; 1420 int i;
797 if(iD==-9) { // default default 1421
798 for (i = 0; i < TABLE_COLORS; i++) { 1422 // te->color_menu_item = iD;
1423
1424 colorMenu->setItemChecked(cm_ab,FALSE);
1425 colorMenu->setItemChecked(cm_bb,FALSE);
1426 colorMenu->setItemChecked(cm_wc,FALSE);
1427 colorMenu->setItemChecked(cm_cw,FALSE);
1428 colorMenu->setItemChecked(cm_mb,FALSE);
1429 colorMenu->setItemChecked(cm_bm,FALSE);
1430 colorMenu->setItemChecked(cm_gy,FALSE);
1431 colorMenu->setItemChecked(cm_rb,FALSE);
1432 colorMenu->setItemChecked(cm_br,FALSE);
1433 colorMenu->setItemChecked(cm_wb,FALSE);
1434 colorMenu->setItemChecked(cm_bw,FALSE);
1435 colorMenu->setItemChecked(cm_gb,FALSE);
1436
1437 if(iD==cm_default)
1438 { // default default
1439 printf("default colors\n");
1440 for (i = 0; i < TABLE_COLORS; i++)
1441 {
799 m_table[i].color = defaultCt[i].color; 1442 m_table[i].color = defaultCt[i].color;
800 if(i==1 || i == 11) 1443 if(i==1 || i == 11)
801 m_table[i].transparent=1; 1444 m_table[i].transparent=1;
802 cfg.writeEntry("Schema","9"); 1445 colorMenu->setItemChecked(cm_default,TRUE);
803 colorMenu->setItemChecked(-9,TRUE);
804 }
805 } else {
806 if(iD==-6) { // green black
807 foreground.setRgb(0x18,255,0x18);
808 background.setRgb(0x00,0x00,0x00);
809 cfg.writeEntry("Schema","6");
810 colorMenu->setItemChecked(-6,TRUE);
811 }
812 if(iD==-7) { // black white
813 foreground.setRgb(0x00,0x00,0x00);
814 background.setRgb(0xFF,0xFF,0xFF);
815 cfg.writeEntry("Schema","7");
816 colorMenu->setItemChecked(-7,TRUE);
817 }
818 if(iD==-8) { // white black
819 foreground.setRgb(0xFF,0xFF,0xFF);
820 background.setRgb(0x00,0x00,0x00);
821 cfg.writeEntry("Schema","8");
822 colorMenu->setItemChecked(-8,TRUE);
823 }
824 if(iD==-10) {// Black, Red
825 foreground.setRgb(0x00,0x00,0x00);
826 background.setRgb(0xB2,0x18,0x18);
827 cfg.writeEntry("Schema","10");
828 colorMenu->setItemChecked(-10,TRUE);
829 }
830 if(iD==-11) {// Red, Black
831 foreground.setRgb(230,31,31); //0xB2,0x18,0x18
832 background.setRgb(0x00,0x00,0x00);
833 cfg.writeEntry("Schema","11");
834 colorMenu->setItemChecked(-11,TRUE);
835 }
836 if(iD==-12) {// Green, Yellow - is ugly
837// foreground.setRgb(0x18,0xB2,0x18);
838 foreground.setRgb(36,139,10);
839// background.setRgb(0xB2,0x68,0x18);
840 background.setRgb(255,255,0);
841 cfg.writeEntry("Schema","12");
842 colorMenu->setItemChecked(-12,TRUE);
843 }
844 if(iD==-13) {// Blue, Magenta
845 foreground.setRgb(0x18,0xB2,0xB2);
846 background.setRgb(0x18,0x18,0xB2);
847 cfg.writeEntry("Schema","13");
848 colorMenu->setItemChecked(-13,TRUE);
849 }
850 if(iD==-14) {// Magenta, Blue
851 foreground.setRgb(0x18,0x18,0xB2);
852 background.setRgb(0x18,0xB2,0xB2);
853 cfg.writeEntry("Schema","14");
854 colorMenu->setItemChecked(-14,TRUE);
855 }
856 if(iD==-15) {// Cyan, White
857 foreground.setRgb(0x18,0xB2,0xB2);
858 background.setRgb(0xFF,0xFF,0xFF);
859 cfg.writeEntry("Schema","15");
860 colorMenu->setItemChecked(-15,TRUE);
861 }
862 if(iD==-16) {// White, Cyan
863 background.setRgb(0x18,0xB2,0xB2);
864 foreground.setRgb(0xFF,0xFF,0xFF);
865 cfg.writeEntry("Schema","16");
866 colorMenu->setItemChecked(-16,TRUE);
867 }
868 if(iD==-17) {// Black, Blue
869 background.setRgb(0x00,0x00,0x00);
870 foreground.setRgb(0x18,0xB2,0xB2);
871 cfg.writeEntry("Schema","17");
872 colorMenu->setItemChecked(-17,TRUE);
873 }
874 if(iD==-18) {// Black, Gold
875 background.setRgb(0x00,0x00,0x00);
876 foreground.setRgb(255,215,0);
877 cfg.writeEntry("Schema","18");
878 colorMenu->setItemChecked(-18,TRUE);
879 } 1446 }
1447 te->setColorTable(m_table);
1448 }
1449 if(iD==cm_gb)
1450 { // green black
1451 foreground.setRgb(100,255,100); // (0x18,255,0x18);
1452 background.setRgb(0x00,0x00,0x00);
1453 colorMenu->setItemChecked(cm_gb,TRUE);
1454 }
1455 if(iD==cm_bw)
1456 { // black white
1457 foreground.setRgb(0x00,0x00,0x00);
1458 background.setRgb(0xFF,0xFF,0xFF);
1459 colorMenu->setItemChecked(cm_bw,TRUE);
1460 }
1461 if(iD==cm_wb)
1462 { // white black
1463 foreground.setRgb(0xFF,0xFF,0xFF);
1464 background.setRgb(0x00,0x00,0x00);
1465 colorMenu->setItemChecked(cm_wb,TRUE);
1466 }
1467 if(iD==cm_br)
1468 {// Black, Red
1469 foreground.setRgb(0x00,0x00,0x00);
1470 background.setRgb(255,85,85); //(0xB2,0x18,0x18);
1471 colorMenu->setItemChecked(cm_br,TRUE);
1472 }
1473 if(iD==cm_rb)
1474 {// Red, Black
1475 foreground.setRgb(255,85,85);
1476 background.setRgb(0x00,0x00,0x00);
1477 colorMenu->setItemChecked(cm_rb,TRUE);
1478 }
1479 if(iD==cm_gy)
1480 {// Green, Yellow - is ugly
1481 // foreground.setRgb(0x18,0xB2,0x18);
1482 foreground.setRgb(15,115,0);
1483 // background.setRgb(0xB2,0x68,0x18);
1484 background.setRgb(255,255,0);
1485 colorMenu->setItemChecked(cm_gy,TRUE);
1486 }
1487 if(iD==cm_bm)
1488 {// Blue, Magenta
1489 foreground.setRgb(3,24,132);
1490 background.setRgb(225,2,255);
1491 colorMenu->setItemChecked(cm_bm,TRUE);
1492 }
1493 if(iD==cm_mb)
1494 {// Magenta, Blue
1495 foreground.setRgb(225,2,255);
1496 background.setRgb(3,24,132);
1497 colorMenu->setItemChecked(cm_mb,TRUE);
1498 }
1499 if(iD==cm_cw)
1500 {// Cyan, White
1501 foreground.setRgb(8,91,129);
1502 background.setRgb(0xFF,0xFF,0xFF);
1503 colorMenu->setItemChecked(cm_cw,TRUE);
1504 }
1505 if(iD==cm_wc)
1506 {// White, Cyan
1507 background.setRgb(8,91,129);
1508 foreground.setRgb(0xFF,0xFF,0xFF);
1509 colorMenu->setItemChecked(cm_wc,TRUE);
1510 }
1511 if(iD==cm_bb)
1512 {// Black, Blue
1513 background.setRgb(0x00,0x00,0x00);
1514 foreground.setRgb(127,147,225);
1515 colorMenu->setItemChecked(cm_bb,TRUE);
1516 }
1517 if(iD==cm_ab)
1518 {// Black, Gold
1519 background.setRgb(0x00,0x00,0x00);
1520 foreground.setRgb(255,215,105);
1521 colorMenu->setItemChecked(cm_ab,TRUE);
1522 }
880#ifdef QT_QWS_OPIE 1523#ifdef QT_QWS_OPIE
881 if(iD==-19) { 1524 if(iD==-19)
882// Custom 1525 {
883 qDebug("do custom"); 1526 // Custom
884 if(fromMenu) { 1527 qDebug("do custom");
1528 if(fromMenu)
1529 {
885 OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, this, "foreground color"); 1530 OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, this, "foreground color");
886 connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, 1531 connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this,
887 SLOT(changeForegroundColor(const QColor&))); 1532 SLOT(changeForegroundColor(const QColor&)));
888 penColorPopupMenu->exec(); 1533 penColorPopupMenu->exec();
889 }
890 cfg.writeEntry("Schema","19");
891 if(!fromMenu) {
892 foreground.setNamedColor(cfg.readEntry("foreground",""));
893 background.setNamedColor(cfg.readEntry("background",""));
894 }
895 fromMenu=FALSE;
896 colorMenu->setItemChecked(-19,TRUE);
897 } 1534 }
898#endif 1535 if(!fromMenu)
899 for (i = 0; i < TABLE_COLORS; i++) { 1536 {
900 if(i==0 || i == 10) { 1537 foreground.setNamedColor(cfg.readEntry("foreground",""));
901 m_table[i].color = foreground; 1538 background.setNamedColor(cfg.readEntry("background",""));
902 }
903 else if(i==1 || i == 11) {
904 m_table[i].color = background; m_table[i].transparent=0;
905 }
906 else
907 m_table[i].color = defaultCt[i].color;
908 } 1539 }
1540 fromMenu=FALSE;
1541 colorMenu->setItemChecked(-19,TRUE);
909 } 1542 }
1543#endif
1544
910 lastSelectedMenu = iD; 1545 lastSelectedMenu = iD;
911 te->setColorTable(m_table); 1546
1547 setColors(foreground, background);
1548
1549 QTabBar *tabBar = tab->getTabBar();
1550 QString ss = QString("Session%1").arg(tabBar->currentTab());
1551 // printf("current tab = %d\n", tabBar->currentTab());
1552
1553 if (tabBar->currentTab() == 0)
1554 {
1555 cfg.writeEntry("foregroundRed",QString::number(foreground.red()));
1556 cfg.writeEntry("foregroundGreen",QString::number(foreground.green()));
1557 cfg.writeEntry("foregroundBlue",QString::number(foreground.blue()));
1558 cfg.writeEntry("backgroundRed",QString::number(background.red()));
1559 cfg.writeEntry("backgroundGreen",QString::number(background.green()));
1560 cfg.writeEntry("backgroundBlue",QString::number(background.blue()));
1561 }
1562 cfg.writeEntry("foregroundRed"+ss,QString::number(foreground.red()));
1563 cfg.writeEntry("foregroundGreen"+ss,QString::number(foreground.green()));
1564 cfg.writeEntry("foregroundBlue"+ss,QString::number(foreground.blue()));
1565 cfg.writeEntry("backgroundRed"+ss,QString::number(background.red()));
1566 cfg.writeEntry("backgroundGreen"+ss,QString::number(background.green()));
1567 cfg.writeEntry("backgroundBlue"+ss,QString::number(background.blue()));
1568
912 update(); 1569 update();
1570}
913 1571
1572void Konsole::setColors(QColor foreground, QColor background)
1573{
1574 int i;
1575 ColorEntry m_table[TABLE_COLORS];
1576 TEWidget* te = getTe();
1577 const ColorEntry * defaultCt=te->getdefaultColorTable();
1578
1579 for (i = 0; i < TABLE_COLORS; i++)
1580 {
1581 if(i==0 || i == 10)
1582 {
1583 m_table[i].color = foreground;
1584 }
1585 else if(i==1 || i == 11)
1586 {
1587 m_table[i].color = background;
1588 m_table[i].transparent=0;
1589 }
1590 else
1591 m_table[i].color = defaultCt[i].color;
1592 }
1593 te->setColorTable(m_table);
914} 1594}
915 1595
1596void Konsole::tabMenuSelected(int id)
1597{
1598 Config cfg("Qkonsole");
1599 cfg.setGroup("Tabs");
1600 tabMenu->setItemChecked(tabPos, false);
1601 if (id == tm_bottom)
1602 {
1603 printf("set bottom tab\n");
1604 tab->getTabBar()->show();
1605 tab->setTabPosition(QTabWidget::Bottom);
1606 tab->getTabBar()->show();
1607 cfg.writeEntry("Position","Bottom");
1608 }
1609 else if (id == tm_top)
1610 {
1611 printf("set top tab\n");
1612 tab->getTabBar()->show();
1613 tab->setTabPosition(QTabWidget::Bottom);
1614 tab->setTabPosition(QTabWidget::Top);
1615 tab->getTabBar()->show();
1616 cfg.writeEntry("Position","Top");
1617 }
1618 else if (id == tm_hidden)
1619 {
1620 tab->getTabBar()->hide();
1621 tab->setMargin(tab->margin());
1622 cfg.writeEntry("Position","Hidden");
1623 }
1624 tabMenu->setItemChecked(id, true);
1625 tabPos = id;
1626}
1627
1628
916void Konsole::configMenuSelected(int iD) 1629void Konsole::configMenuSelected(int iD)
917{ 1630{
918// QString temp; 1631 // QString temp;
919// qDebug( temp.sprintf("configmenu %d",iD)); 1632 // qDebug( temp.sprintf("configmenu %d",iD));
920 1633
921 TEWidget* te = getTe(); 1634 TEWidget* te = getTe();
922 Config cfg("Konsole"); 1635 Config cfg("Qkonsole");
923 cfg.setGroup("Menubar"); 1636 cfg.setGroup("Menubar");
924 int i,j; 1637 if(iD == cm_wrap)
925#ifdef QT_QWS_OPIE 1638 {
926 i=-29;j=-30; 1639 cfg.setGroup("ScrollBar");
927#else 1640 bool b=cfg.readBoolEntry("HorzScroll",0);
928 i=-28;j=-29; 1641 b=!b;
929#endif 1642 cfg.writeEntry("HorzScroll", b );
930 1643 cfg.write();
931 if(iD == -4) { 1644 doWrap();
932 cfg.setGroup("Tabs"); 1645 if(cfg.readNumEntry("Position",2) == 0)
933 QString tmp=cfg.readEntry("Position","Bottom"); 1646 {
934 1647 te->setScrollbarLocation(1);
935 if(tmp=="Top") { 1648 }
936 tab->setTabPosition(QTabWidget::Bottom); 1649 else
937 configMenu->changeItem( iD, tr("Tabs on Top")); 1650 {
938 cfg.writeEntry("Position","Bottom"); 1651 te->setScrollbarLocation(0);
939 } else { 1652 }
940 tab->setTabPosition(QTabWidget::Top); 1653 te->setScrollbarLocation( cfg.readNumEntry("Position",2));
941 configMenu->changeItem( iD, tr("Tabs on Bottom")); 1654 }
942 cfg.writeEntry("Position","Top"); 1655 if(iD == cm_beep)
943 } 1656 {
944 } 1657 cfg.setGroup("Menubar");
945 if(iD == i) { 1658 bool b=cfg.readBoolEntry("useBeep",0);
946 cfg.setGroup("ScrollBar"); 1659 b=!b;
947 bool b=cfg.readBoolEntry("HorzScroll",0); 1660 cfg.writeEntry("useBeep", b );
948 b=!b; 1661 cfg.write();
949 cfg.writeEntry("HorzScroll", b ); 1662 configMenu->setItemChecked(cm_beep,b);
950 cfg.write(); 1663 te->useBeep=b;
951 doWrap(); 1664 }
952 if(cfg.readNumEntry("Position",2) == 0) {
953 te->setScrollbarLocation(1);
954 } else {
955 te->setScrollbarLocation(0);
956 }
957 te->setScrollbarLocation( cfg.readNumEntry("Position",2));
958 }
959 if(iD == j) {
960 cfg.setGroup("Menubar");
961 bool b=cfg.readBoolEntry("useBeep",0);
962 b=!b;
963 cfg.writeEntry("useBeep", b );
964 cfg.write();
965 configMenu->setItemChecked(j,b);
966 te->useBeep=b;
967 }
968} 1665}
969 1666
970void Konsole::changeCommand(const QString &text, int c) 1667void Konsole::changeCommand(const QString &text, int c)
971{ 1668{
972 Config cfg("Konsole"); 1669 Config cfg("Qkonsole");
973 cfg.setGroup("Commands"); 1670 cfg.setGroup("Commands");
974 if(commonCmds[c] != text) { 1671 if(commonCmds[c] != text)
1672 {
975 cfg.writeEntry(QString::number(c),text); 1673 cfg.writeEntry(QString::number(c),text);
976 commonCombo->clearEdit(); 1674 commonCombo->clearEdit();
977 commonCombo->setCurrentItem(c); 1675 commonCombo->setCurrentItem(c);
978 } 1676 }
979} 1677}
980 1678
981void Konsole::setColor() 1679void Konsole::setColor(int sess)
982{ 1680{
983 Config cfg("Konsole"); 1681 Config cfg("Qkonsole");
984 cfg.setGroup("Colors"); 1682 cfg.setGroup("Colors");
985 int scheme = cfg.readNumEntry("Schema",1); 1683 QColor foreground, background;
986 if(scheme != 1) colorMenuSelected( -scheme); 1684 QString ss = QString("Session") + QString::number(sess);
1685 foreground.setRgb(cfg.readNumEntry("foregroundRed"+ss,
1686 cfg.readNumEntry("foregroundRed",0xff)),
1687 cfg.readNumEntry("foregroundGreen"+ss,
1688 cfg.readNumEntry("foregroundGreen",0xff)),
1689 cfg.readNumEntry("foregroundBlue"+ss,
1690 cfg.readNumEntry("foregroundBlue",0xff)));
1691 background.setRgb(cfg.readNumEntry("backgroundRed"+ss,
1692 cfg.readNumEntry("backgroundRed",0)),
1693 cfg.readNumEntry("backgroundGreen"+ss,
1694 cfg.readNumEntry("backgroundGreen",0)),
1695 cfg.readNumEntry("backgroundBlue"+ss,
1696 cfg.readNumEntry("backgroundBlue",0)));
1697 setColors(foreground, background);
987} 1698}
988 1699
989void Konsole::scrollMenuSelected(int index) 1700void Konsole::scrollMenuSelected(int index)
990{ 1701{
991// qDebug( "scrollbar menu %d",index); 1702 // qDebug( "scrollbar menu %d",index);
992 1703
993 TEWidget* te = getTe(); 1704 TEWidget* te = getTe();
994 Config cfg("Konsole"); 1705 Config cfg("Qkonsole");
995 cfg.setGroup("ScrollBar"); 1706 cfg.setGroup("ScrollBar");
996 int i,j,k;
997#ifdef QT_QWS_OPIE
998i=-25;j=-26;k=-27;
999#else
1000i=-24;j=-25;k=-26;
1001#endif
1002 if(index == i) {
1003
1004 te->setScrollbarLocation(0);
1005 cfg.writeEntry("Position",0);
1006 } else if(index == j) {
1007
1008 te->setScrollbarLocation(1);
1009 cfg.writeEntry("Position",1);
1010 } else if(index == k) {
1011 1707
1012 te->setScrollbarLocation(2); 1708 if(index == sm_none)
1013 cfg.writeEntry("Position",2); 1709 {
1014 } 1710 te->setScrollbarLocation(0);
1711 cfg.writeEntry("Position",0);
1712 }
1713 else if(index == sm_left)
1714 {
1715 te->setScrollbarLocation(1);
1716 cfg.writeEntry("Position",1);
1717 }
1718 else if(index == sm_right)
1719 {
1720 te->setScrollbarLocation(2);
1721 cfg.writeEntry("Position",2);
1722 }
1723 scrollMenu->setItemChecked(sm_none, index == sm_none);
1724 scrollMenu->setItemChecked(sm_left, index == sm_left);
1725 scrollMenu->setItemChecked(sm_right, index == sm_right);
1726}
1015 1727
1016// case -29: { 1728// case -29: {
1017// bool b=cfg.readBoolEntry("HorzScroll",0); 1729// bool b=cfg.readBoolEntry("HorzScroll",0);
1018// cfg.writeEntry("HorzScroll", !b ); 1730// cfg.writeEntry("HorzScroll", !b );
1019// cfg.write(); 1731// cfg.write();
1020// if(cfg.readNumEntry("Position",2) == 0) { 1732// if(cfg.readNumEntry("Position",2) == 0) {
1021// te->setScrollbarLocation(1); 1733// te->setScrollbarLocation(1);
1022// te->setWrapAt(0); 1734// te->setWrapAt(0);
1023// } else { 1735// } else {
1024// te->setScrollbarLocation(0); 1736// te->setScrollbarLocation(0);
1025// te->setWrapAt(120); 1737// te->setWrapAt(120);
1026// } 1738// }
1027// te->setScrollbarLocation( cfg.readNumEntry("Position",2)); 1739// te->setScrollbarLocation( cfg.readNumEntry("Position",2));
1028// } 1740// }
1029// break; 1741// break;
1030}
1031 1742
1032void Konsole::editCommandListMenuSelected(int iD) 1743void Konsole::editCommandListMenuSelected(int iD)
1033{ 1744{
1034// QString temp; 1745 // QString temp;
1035// qDebug( temp.sprintf("edit command list %d",iD)); 1746 // qDebug( temp.sprintf("edit command list %d",iD));
1747
1748 // FIXME: more cleanup needed here
1749
1750
1036 TEWidget* te = getTe(); 1751 TEWidget* te = getTe();
1037 Config cfg("Konsole"); 1752 Config cfg("Qkonsole");
1038 cfg.setGroup("Menubar"); 1753 cfg.setGroup("Menubar");
1039 if( iD == -3) { 1754 if( iD == ec_cmdlist)
1040 if(!secondToolBar->isHidden()) { 1755 {
1756 if(!secondToolBar->isHidden())
1757 {
1041 secondToolBar->hide(); 1758 secondToolBar->hide();
1042 configMenu->changeItem( iD,tr( "Show Command List" )); 1759 configMenu->changeItem( iD,tr( "Show Command List" ));
1043 cfg.writeEntry("Hidden","TRUE"); 1760 cfg.writeEntry("Hidden","TRUE");
1044 configMenu->setItemEnabled(-23 ,FALSE); 1761 configMenu->setItemEnabled(ec_edit ,FALSE);
1045 } else { 1762 configMenu->setItemEnabled(ec_quick ,FALSE);
1763 }
1764 else
1765 {
1046 secondToolBar->show(); 1766 secondToolBar->show();
1047 configMenu->changeItem( iD,tr( "Hide Command List" )); 1767 configMenu->changeItem( iD,tr( "Hide Command List" ));
1048 cfg.writeEntry("Hidden","FALSE"); 1768 cfg.writeEntry("Hidden","FALSE");
1049 configMenu->setItemEnabled(-23 ,TRUE); 1769 configMenu->setItemEnabled(ec_edit ,TRUE);
1770 configMenu->setItemEnabled(ec_quick ,TRUE);
1050 1771
1051 if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { 1772 if(cfg.readEntry("EditEnabled","FALSE")=="TRUE")
1052 configMenu->setItemChecked(-23,TRUE); 1773 {
1774 configMenu->setItemChecked(ec_edit,TRUE);
1053 commonCombo->setEditable( TRUE ); 1775 commonCombo->setEditable( TRUE );
1054 } else { 1776 }
1055 configMenu->setItemChecked(-23,FALSE); 1777 else
1778 {
1779 configMenu->setItemChecked(ec_edit,FALSE);
1056 commonCombo->setEditable( FALSE ); 1780 commonCombo->setEditable( FALSE );
1057 } 1781 }
1058 } 1782 }
1059 } 1783 }
1060 if( iD == -23) { 1784 if( iD == ec_quick)
1785 {
1061 cfg.setGroup("Commands"); 1786 cfg.setGroup("Commands");
1062// qDebug("enableCommandEdit"); 1787 // qDebug("enableCommandEdit");
1063 if( !configMenu->isItemChecked(iD) ) { 1788 if( !configMenu->isItemChecked(iD) )
1789 {
1064 commonCombo->setEditable( TRUE ); 1790 commonCombo->setEditable( TRUE );
1065 configMenu->setItemChecked(iD,TRUE); 1791 configMenu->setItemChecked(iD,TRUE);
1066 commonCombo->setCurrentItem(0); 1792 commonCombo->setCurrentItem(0);
1067 cfg.writeEntry("EditEnabled","TRUE"); 1793 cfg.writeEntry("EditEnabled","TRUE");
1068 } else { 1794 }
1795 else
1796 {
1069 commonCombo->setEditable( FALSE ); 1797 commonCombo->setEditable( FALSE );
1070 configMenu->setItemChecked(iD,FALSE); 1798 configMenu->setItemChecked(iD,FALSE);
1071 cfg.writeEntry("EditEnabled","FALSE"); 1799 cfg.writeEntry("EditEnabled","FALSE");
1072 commonCombo->setFocusPolicy(QWidget::NoFocus); 1800 commonCombo->setFocusPolicy(QWidget::NoFocus);
1073 te->setFocus(); 1801 te->setFocus();
1074 } 1802 }
1075 } 1803 }
1076 if(iD == -24) { 1804 if(iD == ec_edit)
1077 // "edit commands" 1805 {
1078 CommandEditDialog *m = new CommandEditDialog(this); 1806 // "edit commands"
1079 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); 1807 CommandEditDialog *m = new CommandEditDialog(this);
1080 QPEApplication::showDialog( m ); 1808 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList()));
1809 m->showMaximized();
1081 } 1810 }
1082 1811
1083} 1812}
1084 1813
1085// $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' 1814// $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V'
1086void Konsole::setDocument( const QString &cmd) { 1815void Konsole::setDocument( const QString &cmd)
1816{
1087 newSession(); 1817 newSession();
1088 TEWidget* te = getTe(); 1818 TEWidget* te = getTe();
1089 if(cmd.find("-e", 0, TRUE) != -1) { 1819 if(cmd.find("-e", 0, TRUE) != -1)
1820 {
1090 QString cmd2; 1821 QString cmd2;
1091 cmd2=cmd.right(cmd.length()-3)+" &"; 1822 cmd2=cmd.right(cmd.length()-3)+" &";
1092 system(cmd2.latin1()); 1823 system(cmd2.latin1());
1093 if(startUp <= 1 && nsessions < 2) { 1824 if(startUp <= 1 && nsessions < 2)
1094 doneSession(getTe()->currentSession, 0); 1825 {
1826 doneSession(getTe(), 0);
1095 exit(0); 1827 exit(0);
1096 } else 1828 }
1097 doneSession(getTe()->currentSession, 0); 1829 else
1098 } else { 1830 doneSession(getTe(), 0);
1099 if (te != 0) { 1831 }
1832 else
1833 {
1834 if (te != 0)
1835 {
1100 te->emitText(cmd+"\r"); 1836 te->emitText(cmd+"\r");
1101 } 1837 }
1102 } 1838 }
1103 startUp++; 1839 startUp++;
1104} 1840}
1105 1841
1106void Konsole::parseCommandLine() { 1842
1843// what is the point of this when you can just
1844// run commands by using the shell directly??
1845void Konsole::parseCommandLine()
1846{
1107 QString cmd; 1847 QString cmd;
1108 // newSession(); 1848 // newSession();
1109 for (int i=1;i< qApp->argc();i++) { 1849 for (int i=1;i< qApp->argc();i++)
1110 if( QString(qApp->argv()[i]) == "-e") { 1850 {
1851 if( QString(qApp->argv()[i]) == "-e")
1852 {
1111 i++; 1853 i++;
1112 for ( int j=i;j< qApp->argc();j++) { 1854 for ( int j=i;j< qApp->argc();j++)
1855 {
1113 cmd+=QString(qApp->argv()[j])+" "; 1856 cmd+=QString(qApp->argv()[j])+" ";
1114 } 1857 }
1115 cmd.stripWhiteSpace(); 1858 cmd.stripWhiteSpace();
1116 system(cmd.latin1()); 1859 system(cmd.latin1());
1117 exit(0);//close(); 1860 exit(0);//close();
1118 } // end -e switch 1861 } // end -e switch
1119 } 1862 }
1120 startUp++; 1863 startUp++;
1121} 1864}
1122 1865
1123void Konsole::changeForegroundColor(const QColor &color) { 1866void Konsole::changeForegroundColor(const QColor &color)
1124 Config cfg("Konsole"); 1867{
1868 Config cfg("Qkonsole");
1125 cfg.setGroup("Colors"); 1869 cfg.setGroup("Colors");
1126 int r, g, b; 1870 int r, g, b;
1127 color.rgb(&r,&g,&b); 1871 color.rgb(&r,&g,&b);
1128 foreground.setRgb(r,g,b); 1872 foreground.setRgb(r,g,b);
1129 1873
1130 cfg.writeEntry("foreground",color.name()); 1874 cfg.writeEntry("foreground",color.name());
1131 qDebug("foreground "+color.name()); 1875 qDebug("foreground "+color.name());
1132 cfg.write(); 1876 cfg.write();
1133 1877
1134qDebug("do other dialog"); 1878 qDebug("do other dialog");
1135#ifdef QT_QWS_OPIE 1879#ifdef QT_QWS_OPIE
1136 1880
1137 OColorPopupMenu* penColorPopupMenu2 = new OColorPopupMenu(Qt::black, this,"background color"); 1881 OColorPopupMenu* penColorPopupMenu2 = new OColorPopupMenu(Qt::black, this,"background color");
1138 connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, 1882 connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this,
1139 SLOT(changeBackgroundColor(const QColor&))); 1883 SLOT(changeBackgroundColor(const QColor&)));
1140 penColorPopupMenu2->exec(); 1884 penColorPopupMenu2->exec();
1141#endif 1885#endif
1142} 1886}
1143 1887
1144void Konsole::changeBackgroundColor(const QColor &color) { 1888void Konsole::changeBackgroundColor(const QColor &color)
1889{
1145 1890
1146 qDebug("Change background"); 1891 qDebug("Change background");
1147 Config cfg("Konsole"); 1892 Config cfg("Qkonsole");
1148 cfg.setGroup("Colors"); 1893 cfg.setGroup("Colors");
1149 int r, g, b; 1894 int r, g, b;
1150 color.rgb(&r,&g,&b); 1895 color.rgb(&r,&g,&b);
1151 background.setRgb(r,g,b); 1896 background.setRgb(r,g,b);
1152 cfg.writeEntry("background",color.name()); 1897 cfg.writeEntry("background",color.name());
1153 qDebug("background "+color.name()); 1898 qDebug("background "+color.name());
1154 cfg.write(); 1899 cfg.write();
1155} 1900}
1156 1901
1157void Konsole::doWrap() { 1902void Konsole::doWrap()
1158int i; 1903{
1159#ifdef QT_QWS_OPIE 1904 Config cfg("Qkonsole");
1160i=-29;
1161#else
1162i=-28;
1163#endif
1164
1165 Config cfg("Konsole");
1166 cfg.setGroup("ScrollBar"); 1905 cfg.setGroup("ScrollBar");
1167 TEWidget* te = getTe(); 1906 TEWidget* te = getTe();
1168 if( !cfg.readBoolEntry("HorzScroll",0)) { 1907 if( !cfg.readBoolEntry("HorzScroll",0))
1908 {
1169 te->setWrapAt(0); 1909 te->setWrapAt(0);
1170 configMenu->setItemChecked( i,TRUE); 1910 configMenu->setItemChecked( cm_wrap,TRUE);
1171 } else { 1911 }
1172// te->setWrapAt(90); 1912 else
1913 {
1914 // te->setWrapAt(90);
1173 te->setWrapAt(120); 1915 te->setWrapAt(120);
1174 configMenu->setItemChecked( i,FALSE); 1916 configMenu->setItemChecked( cm_wrap,FALSE);
1175 } 1917 }
1176} 1918}
diff --git a/core/apps/embeddedkonsole/konsole.h b/core/apps/embeddedkonsole/konsole.h
index 7d5a908..37babbb 100644
--- a/core/apps/embeddedkonsole/konsole.h
+++ b/core/apps/embeddedkonsole/konsole.h
@@ -1,144 +1,206 @@
1/* ----------------------------------------------------------------------- */ 1/* ----------------------------------------------------------------------- */
2/* */ 2/* */
3/* [konsole.h] Konsole */ 3/* [konsole.h] 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 21
22#ifndef KONSOLE_H 22#ifndef KONSOLE_H
23#define KONSOLE_H 23#define KONSOLE_H
24 24
25 25
26#include <qmainwindow.h> 26#include <qmainwindow.h>
27#include <qaction.h> 27#include <qaction.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include <qstrlist.h> 29#include <qstrlist.h>
30#include <qintdict.h> 30#include <qintdict.h>
31#include <qptrdict.h> 31#include <qptrdict.h>
32#include <qtabwidget.h> 32#include <qtabwidget.h>
33#include <qtoolbar.h> 33#include <qtoolbar.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qcolor.h> 35#include <qcolor.h>
36 36
37#include "MyPty.h" 37#include "MyPty.h"
38#include "TEWidget.h" 38#include "TEWidget.h"
39#include "TEmuVt102.h" 39#include "TEmuVt102.h"
40#include "session.h" 40#include "session.h"
41 41
42class EKNumTabWidget; 42class EKNumTabWidget;
43 43
44class Konsole : public QMainWindow 44class Konsole : public QMainWindow
45{ 45{
46 Q_OBJECT 46 Q_OBJECT
47 47
48public: 48public:
49 static QString appName() { return QString::fromLatin1("embeddedkonsole"); } 49
50 50 static QString appName()
51 Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); 51 {
52 ~Konsole(); 52 return QString::fromLatin1("embeddedkonsole");
53 void setColLin(int columns, int lines); 53 }
54 QToolBar *secondToolBar; 54
55 void show(); 55 Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
56 void setColor(); 56 Konsole(const char * name, const char* pgm, QStrList & _args, int histon);
57 int lastSelectedMenu; 57 ~Konsole();
58 int startUp; 58 void setColLin(int columns, int lines);
59 QToolBar *secondToolBar;
60 void show();
61 void setColor(int);
62 int lastSelectedMenu;
63 int startUp;
64
65public slots:
66 void changeFontSize(int);
67 void toggleFullScreen();
68 void setFullScreen(bool);
69 void changeSession(int);
70 void cycleZoom();
71 void newSession();
72
59private slots: 73private slots:
60 void setDocument(const QString &); 74 void setDocument(const QString &);
61 void doneSession(TESession*,int); 75 void doneSession(TEWidget*,int);
62 void changeColumns(int); 76 void changeTitle(TEWidget*,QString);
63 void fontChanged(int); 77 void changeColumns(int);
64 void configMenuSelected(int ); 78 void setFont(int);
65 void colorMenuSelected(int); 79 // void fontChanged(int);
66 void colorMenuIsSelected(int); 80 void configMenuSelected(int );
67 void enterCommand(int); 81 void colorMenuSelected(int);
68 void hitEnter(); 82 void colorMenuIsSelected(int);
69 void hitSpace(); 83 void tabMenuSelected(int);
70 void hitTab(); 84 void sessionListSelected(int);
71 void hitPaste(); 85
72 void hitUp(); 86 void enterCommand(int);
73 void hitDown(); 87 void hitEnter();
74 void switchSession(QWidget *); 88 void hitSpace();
75 void newSession(); 89 void hitTab();
76 void changeCommand(const QString &, int); 90 void hitPaste();
77 void initCommandList(); 91 void hitUp();
78 void scrollMenuSelected(int); 92 void hitDown();
79 void editCommandListMenuSelected(int); 93 void switchSession(QWidget *);
80 void parseCommandLine(); 94 void changeCommand(const QString &, int);
95 void initCommandList();
96 void scrollMenuSelected(int);
97 void editCommandListMenuSelected(int);
98 void parseCommandLine();
81 void changeForegroundColor(const QColor &); 99 void changeForegroundColor(const QColor &);
82 void changeBackgroundColor(const QColor &); 100 void changeBackgroundColor(const QColor &);
101
102 void historyDialog();
103 void fullscreenTimeout();
104
83private: 105private:
84 void doWrap(); 106 void doWrap();
85 void init(const char* _pgm, QStrList & _args); 107 void init(const char* _pgm, QStrList & _args);
86 void initSession(const char* _pgm, QStrList & _args); 108 void initSession(const char* _pgm, QStrList & _args);
87 void runSession(TESession* s); 109 void runSession(TESession* s);
88 void setColorPixmaps(); 110 void setColorPixmaps();
89 void setHistory(bool); 111 void setHistory(bool);
90 QSize calcSize(int columns, int lines); 112 void setColors(QColor foreground, QColor background);
91 TEWidget* getTe(); 113 int findFont(QString name, int size, bool exact = false);
92 QStringList commands; 114 QSize calcSize(int columns, int lines);
93 QLabel * msgLabel; 115 TEWidget* getTe();
94 QColor foreground, background; 116 QStringList commands;
95bool fromMenu; 117 QLabel * msgLabel;
96private: 118 QColor foreground, background;
97 class VTFont 119 bool fromMenu;
98 { 120
99 public: 121 bool fullscreen;
100 VTFont(QString name, QFont& font)
101 {
102 this->name = name;
103 this->font = font;
104 }
105
106 QFont& getFont()
107 {
108 return font;
109 }
110 122
111 QString getName() 123private:
124 class VTFont
112 { 125 {
113 return name; 126 public:
114 } 127 VTFont(QString name, QFont& font, QString family, int familyNum, int size)
115 128 {
116 private: 129 this->name = name;
117 QString name; 130 this->font = font;
118 QFont font; 131 this->family = family;
119 }; 132 this->size = size;
133 this->familyNum = familyNum;
134 }
135
136 QFont& getFont()
137 {
138 return font;
139 }
140 QString getName()
141 {
142 return name;
143 }
144 int getSize()
145 {
146 return(size);
147 }
148 QString getFamily()
149 {
150 return(family);
151 }
152 int getFamilyNum()
153 {
154 return(familyNum);
155 }
156
157 private:
158 QFont font;
159 QString name;
160 QString family;
161 int familyNum;
162 int size;
163 };
164
165 EKNumTabWidget* tab;
166 int tabPos;
167 int nsessions;
168 QList<VTFont> fonts;
169 int cfont;
170 QCString se_pgm;
171 QStrList se_args;
172
173 QToolBar *menuToolBar;
174 QToolBar *toolBar;
175 QComboBox *commonCombo;
176
177 QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu;
178 QPopupMenu *sessionList, *tabMenu;
179
180 int sm_none, sm_left, sm_right;
181 int cm_beep, cm_wrap;
182 int cm_default;
183 int cm_bw, cm_wb, cm_gb, cm_bt, cm_br, cm_rb, cm_gy, cm_bm, cm_mb, cm_cw, cm_wc, cm_bb, cm_ab;
184 int tm_top, tm_bottom, tm_hidden;
185 int ec_edit, ec_cmdlist, ec_quick;
186
187 bool show_fullscreen_msg;
188 QTimer *fullscreen_timer;
189 QLabel *fullscreen_msg;
120 190
121 EKNumTabWidget* tab;
122 int nsessions;
123 QList<VTFont> fonts;
124 int cfont;
125 QCString se_pgm;
126 QStrList se_args;
127 191
128 QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu;
129 QComboBox *commonCombo;
130 // history scrolling I think 192 // history scrolling I think
131 bool b_scroll; 193 bool b_scroll;
132 194
133 int n_keytab; 195 int n_keytab;
134 int n_scroll; 196 int n_scroll;
135 int n_render; 197 int n_render;
136 QString pmPath; // pixmap path 198 QString pmPath; // pixmap path
137 QString dropText; 199 QString dropText;
138 QFont defaultFont; 200 QFont defaultFont;
139 QSize defaultSize; 201 QSize defaultSize;
140 202
141}; 203};
142 204
143#endif 205#endif
144 206
diff --git a/core/apps/embeddedkonsole/main.cpp b/core/apps/embeddedkonsole/main.cpp
index f77fe24..a6a079c 100644
--- a/core/apps/embeddedkonsole/main.cpp
+++ b/core/apps/embeddedkonsole/main.cpp
@@ -1,38 +1,39 @@
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 21
22#include "konsole.h" 22#include "konsole.h"
23 23
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <opie/oapplicationfactory.h> 25#include <opie/oapplicationfactory.h>
26 26
27#include <qfile.h> 27#include <qfile.h>
28 28
29#include <unistd.h> 29#include <unistd.h>
30#include <stdio.h> 30#include <stdio.h>
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <pwd.h> 33#include <pwd.h>
34#include <sys/types.h> 34#include <sys/types.h>
35 35
36 36
37/* --| main |------------------------------------------------------ */ 37/* --| main |------------------------------------------------------ */
38OPIE_EXPORT_APP( OApplicationFactory<Konsole> ) 38OPIE_EXPORT_APP( OApplicationFactory<Konsole> )
39
diff --git a/core/apps/embeddedkonsole/session.cpp b/core/apps/embeddedkonsole/session.cpp
index 520af86..17acb8c 100644
--- a/core/apps/embeddedkonsole/session.cpp
+++ b/core/apps/embeddedkonsole/session.cpp
@@ -1,157 +1,161 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2 /* */ 2 /* */
3/* Ported Konsole to Qt/Embedded */ 3/* Ported Konsole to Qt/Embedded */
4 /* */ 4 /* */
5/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 5/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
6 /* */ 6 /* */
7/* -------------------------------------------------------------------------- */ 7/* -------------------------------------------------------------------------- */
8#include "session.h" 8#include "session.h"
9#include <qpushbutton.h> 9#include <qpushbutton.h>
10// #include <kdebug.h> 10// #include <kdebug.h>
11 11
12#include <stdlib.h> 12#include <stdlib.h>
13 13
14#define HERE fprintf(stderr,"%s(%d): here\n",__FILE__,__LINE__) 14#define HERE fprintf(stderr,"%s(%d): here\n",__FILE__,__LINE__)
15 15
16/*! \class TESession 16/*! \class TESession
17 17
18 Sessions are combinations of TEPTy and Emulations. 18 Sessions are combinations of TEPTy and Emulations.
19 19
20 The stuff in here does not belong to the terminal emulation framework, 20 The stuff in here does not belong to the terminal emulation framework,
21 but to main.C. It serves it's duty by providing a single reference 21 but to main.C. It serves it's duty by providing a single reference
22 to TEPTy/Emulation pairs. In fact, it is only there to demonstrate one 22 to TEPTy/Emulation pairs. In fact, it is only there to demonstrate one
23 of the abilities of the framework - multible sessions. 23 of the abilities of the framework - multible sessions.
24*/ 24*/
25 25
26TESession::TESession(QMainWindow* main, TEWidget* te, const char* _pgm, QStrList & _args, const char *_term) : schema_no(0), font_no(3), pgm(_pgm), args(_args) 26TESession::TESession(QMainWindow* main, TEWidget* _te, const char* _pgm, QStrList & _args, const char *_term) : schema_no(0), font_no(3), pgm(_pgm), args(_args)
27{ 27{
28 te = _te;
29 term = _term;
30
28 // sh = new TEPty(); 31 // sh = new TEPty();
29 sh = new MyPty(); 32 sh = new MyPty();
30 em = new TEmuVt102(te); 33 em = new TEmuVt102(te);
31 34
32 term = _term;
33
34 sh->setSize(te->Lines(),te->Columns()); // not absolutely nessesary 35 sh->setSize(te->Lines(),te->Columns()); // not absolutely nessesary
35 QObject::connect( sh,SIGNAL(block_in(const char*,int)), 36 QObject::connect( sh,SIGNAL(block_in(const char*,int)),
36 em,SLOT(onRcvBlock(const char*,int)) ); 37 em,SLOT(onRcvBlock(const char*,int)) );
37 QObject::connect( em,SIGNAL(ImageSizeChanged(int,int)), 38 QObject::connect( em,SIGNAL(ImageSizeChanged(int,int)),
38 sh,SLOT(setSize(int,int))); 39 sh,SLOT(setSize(int,int)));
39 40
40 // 'main' should do those connects itself, somehow. 41 // 'main' should do those connects itself, somehow.
41 // These aren't KTMW's slots, but konsole's.(David) 42 // These aren't KTMW's slots, but konsole's.(David)
42 43
43/* 44/*
44 QObject::connect( em,SIGNAL(ImageSizeChanged(int,int)), 45 QObject::connect( em,SIGNAL(ImageSizeChanged(int,int)),
45 main,SLOT(notifySize(int,int))); 46 main,SLOT(notifySize(int,int)));
46*/ 47*/
47 QObject::connect( em,SIGNAL(sndBlock(const char*,int)), 48 QObject::connect( em,SIGNAL(sndBlock(const char*,int)),
48 sh,SLOT(send_bytes(const char*,int)) ); 49 sh,SLOT(send_bytes(const char*,int)) );
49 QObject::connect( em,SIGNAL(changeColumns(int)), 50 QObject::connect( em,SIGNAL(changeColumns(int)),
50 main,SLOT(changeColumns(int)) ); 51 main,SLOT(changeColumns(int)) );
51/* 52
53
54
52 QObject::connect( em,SIGNAL(changeTitle(int, const QString&)), 55 QObject::connect( em,SIGNAL(changeTitle(int, const QString&)),
53 main,SLOT(changeTitle(int, const QString&)) ); 56 this,SLOT(changeTitle(int, const QString&)) );
54*/ 57
55 QObject::connect( sh,SIGNAL(done(int)), this,SLOT(done(int)) ); 58 QObject::connect( sh,SIGNAL(done(int)), this,SLOT(done(int)) );
56} 59}
57 60
58 61
59 62
60void TESession::run() 63void TESession::run()
61{ 64{
62 //kdDebug() << "Running the session!" << pgm << "\n"; 65 //kdDebug() << "Running the session!" << pgm << "\n";
63 sh->run(pgm,args,term.data(),FALSE); 66 sh->run(pgm,args,term.data(),FALSE);
64} 67}
65 68
66void TESession::kill(int ) // signal) 69void TESession::kill(int ) // signal)
67{ 70{
68// sh->kill(signal); 71// sh->kill(signal);
69} 72}
70 73
71TESession::~TESession() 74TESession::~TESession()
72{ 75{
73 QObject::disconnect( sh, SIGNAL( done( int ) ), 76 QObject::disconnect( sh, SIGNAL( done( int ) ),
74 this, SLOT( done( int ) ) ); 77 this, SLOT( done( int ) ) );
75 delete em; 78 delete em;
76 delete sh; 79 delete sh;
77} 80}
78 81
79void TESession::setConnect(bool c) 82void TESession::setConnect(bool c)
80{ 83{
81 em->setConnect(c); 84 em->setConnect(c);
82} 85}
83 86
84void TESession::done(int status) 87void TESession::done(int status)
85{ 88{
86 emit done(this,status); 89 emit done(te,status);
87} 90}
88 91
89void TESession::terminate() 92void TESession::terminate()
90{ 93{
91 delete this; 94 delete this;
92} 95}
93 96
94TEmulation* TESession::getEmulation() 97TEmulation* TESession::getEmulation()
95{ 98{
96 return em; 99 return em;
97} 100}
98 101
99// following interfaces might be misplaced /// 102// following interfaces might be misplaced ///
100 103
101int TESession::schemaNo() 104int TESession::schemaNo()
102{ 105{
103 return schema_no; 106 return schema_no;
104} 107}
105 108
106int TESession::keymap() 109int TESession::keymap()
107{ 110{
108 return keymap_no; 111 return keymap_no;
109} 112}
110 113
111int TESession::fontNo() 114int TESession::fontNo()
112{ 115{
113 return font_no; 116 return font_no;
114} 117}
115 118
116const char* TESession::emuName() 119const char* TESession::emuName()
117{ 120{
118 return term.data(); 121 return term.data();
119} 122}
120 123
121void TESession::setSchemaNo(int sn) 124void TESession::setSchemaNo(int sn)
122{ 125{
123 schema_no = sn; 126 schema_no = sn;
124} 127}
125 128
126void TESession::setKeymapNo(int kn) 129void TESession::setKeymapNo(int kn)
127{ 130{
128 keymap_no = kn; 131 keymap_no = kn;
129 em->setKeytrans(kn); 132 em->setKeytrans(kn);
130} 133}
131 134
132void TESession::setFontNo(int fn) 135void TESession::setFontNo(int fn)
133{ 136{
134 font_no = fn; 137 font_no = fn;
135} 138}
136 139
137void TESession::setTitle(const QString& title) 140void TESession::changeTitle(int, const QString& title)
138{ 141{
139 this->title = title; 142 this->title = title;
143 emit changeTitle(te, title);
140} 144}
141 145
142const QString& TESession::Title() 146const QString& TESession::Title()
143{ 147{
144 return title; 148 return title;
145} 149}
146 150
147void TESession::setHistory(bool on) 151void TESession::setHistory(bool on)
148{ 152{
149 em->setHistory( on ); 153 em->setHistory( on );
150} 154}
151 155
152bool TESession::history() 156bool TESession::history()
153{ 157{
154 return em->history(); 158 return em->history();
155} 159}
156 160
157// #include "session.moc" 161// #include "session.moc"
diff --git a/core/apps/embeddedkonsole/session.h b/core/apps/embeddedkonsole/session.h
index 4a61569..f399e96 100644
--- a/core/apps/embeddedkonsole/session.h
+++ b/core/apps/embeddedkonsole/session.h
@@ -1,93 +1,94 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2/* */ 2/* */
3/* [session.h] Testbed for TE framework */ 3/* [session.h] Testbed for TE framework */
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/* -------------------------------------------------------------------------- */ 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 18
19#ifndef SESSION_H 19#ifndef SESSION_H
20#define SESSION_H 20#define SESSION_H
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qmainwindow.h> 23#include <qmainwindow.h>
24#include <qstrlist.h> 24#include <qstrlist.h>
25 25
26#include "MyPty.h" 26#include "MyPty.h"
27#include "TEWidget.h" 27#include "TEWidget.h"
28#include "TEmuVt102.h" 28#include "TEmuVt102.h"
29 29
30class TESession : public QObject 30class TESession : public QObject
31{ Q_OBJECT 31{ Q_OBJECT
32 32
33public: 33public:
34 34
35 TESession(QMainWindow* main, TEWidget* w, 35 TESession(QMainWindow* main, TEWidget* w,
36 const char* pgm, QStrList & _args, 36 const char* pgm, QStrList & _args,
37 const char* term); 37 const char* term);
38 ~TESession(); 38 ~TESession();
39 39
40public: 40public:
41 41
42 void setConnect(bool r); 42 void setConnect(bool r);
43 TEmulation* getEmulation(); // to control emulation 43 TEmulation* getEmulation(); // to control emulation
44 bool isSecure(); 44 bool isSecure();
45 45
46public: 46public:
47 47
48 int schemaNo(); 48 int schemaNo();
49 int fontNo(); 49 int fontNo();
50 const char* emuName(); 50 const char* emuName();
51 const QString& Title(); 51 const QString& Title();
52 bool history(); 52 bool history();
53 int keymap(); 53 int keymap();
54 54
55 void setHistory(bool on); 55 void setHistory(bool on);
56 void setSchemaNo(int sn); 56 void setSchemaNo(int sn);
57 void setKeymapNo(int kn); 57 void setKeymapNo(int kn);
58 void setFontNo(int fn); 58 void setFontNo(int fn);
59 void setTitle(const QString& title);
60 void kill(int signal); 59 void kill(int signal);
61 60
62public slots: 61public slots:
63 62
64 void run(); 63 void run();
65 void done(int status); 64 void done(int status);
66 void terminate(); 65 void terminate();
66 void changeTitle(int, const QString& title);
67 67
68signals: 68signals:
69 69
70 void done(TESession*, int); 70 void done(TEWidget*, int);
71 void changeTitle(TEWidget*, QString);
71 72
72private: 73private:
73 74
74 // TEPty* sh; 75 // TEPty* sh;
75 MyPty* sh; 76 MyPty* sh;
76 TEWidget* te; 77 TEWidget* te;
77 TEmulation* em; 78 TEmulation* em;
78 79
79 //FIXME: using the indices here 80 //FIXME: using the indices here
80 // is propably very bad. We should 81 // is propably very bad. We should
81 // use a persistent reference instead. 82 // use a persistent reference instead.
82 int schema_no; 83 int schema_no;
83 int font_no; 84 int font_no;
84 int keymap_no; 85 int keymap_no;
85 QString title; 86 QString title;
86 87
87 const char* pgm; 88 const char* pgm;
88 QStrList args; 89 QStrList args;
89 90
90 QCString term; 91 QCString term;
91}; 92};
92 93
93#endif 94#endif