summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index 653652a..1016885 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,620 +1,621 @@
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 <qpe/resource.h> 22#include <qpe/resource.h>
23 23
24#include <qdir.h> 24#include <qdir.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qobjectlist.h> 27#include <qobjectlist.h>
28#include <qtoolbutton.h> 28#include <qtoolbutton.h>
29#include <qpe/qpetoolbar.h> 29#include <qpe/qpetoolbar.h>
30#include <qpushbutton.h> 30#include <qpushbutton.h>
31#include <qfontdialog.h> 31#include <qfontdialog.h>
32#include <qglobal.h> 32#include <qglobal.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qpe/qpemenubar.h> 34#include <qpe/qpemenubar.h>
35#include <qmessagebox.h> 35#include <qmessagebox.h>
36#include <qaction.h> 36#include <qaction.h>
37#include <qapplication.h> 37#include <qapplication.h>
38#include <qfontmetrics.h> 38#include <qfontmetrics.h>
39#include <qcombobox.h> 39#include <qcombobox.h>
40#include <qevent.h> 40#include <qevent.h>
41#include <qtabwidget.h> 41#include <qtabwidget.h>
42#include <qtabbar.h> 42#include <qtabbar.h>
43#include <qpe/config.h> 43#include <qpe/config.h>
44#include <qstringlist.h> 44#include <qstringlist.h>
45#include <qpalette.h> 45#include <qpalette.h>
46 46
47#include <sys/wait.h> 47#include <sys/wait.h>
48#include <stdio.h> 48#include <stdio.h>
49#include <stdlib.h> 49#include <stdlib.h>
50#include <assert.h> 50#include <assert.h>
51 51
52#include "konsole.h" 52#include "konsole.h"
53#include "keytrans.h" 53#include "keytrans.h"
54 54
55class EKNumTabBar : public QTabBar { 55class EKNumTabBar : public QTabBar {
56public: 56public:
57 void numberTabs() 57 void numberTabs()
58 { 58 {
59 // Yes, it really is this messy. QTabWidget needs functions 59 // Yes, it really is this messy. QTabWidget needs functions
60 // that provide acces to tabs in a sequential way. 60 // that provide acces to tabs in a sequential way.
61 int m=INT_MIN; 61 int m=INT_MIN;
62 for (int i=0; i<count(); i++) { 62 for (int i=0; i<count(); i++) {
63 QTab* left=0; 63 QTab* left=0;
64 QListIterator<QTab> it(*tabList()); 64 QListIterator<QTab> it(*tabList());
65 int x=INT_MAX; 65 int x=INT_MAX;
66 for( QTab* t; (t=it.current()); ++it ) { 66 for( QTab* t; (t=it.current()); ++it ) {
67 int tx = t->rect().x(); 67 int tx = t->rect().x();
68 if ( tx<x && tx>m ) { 68 if ( tx<x && tx>m ) {
69 x = tx; 69 x = tx;
70 left = t; 70 left = t;
71 } 71 }
72 } 72 }
73 if ( left ) { 73 if ( left ) {
74 left->setText(QString::number(i+1)); 74 left->setText(QString::number(i+1));
75 m = left->rect().x(); 75 m = left->rect().x();
76 } 76 }
77 } 77 }
78 } 78 }
79}; 79};
80 80
81class EKNumTabWidget : public QTabWidget { 81class EKNumTabWidget : public QTabWidget {
82public: 82public:
83 EKNumTabWidget(QWidget* parent) : QTabWidget(parent) 83 EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
84 { 84 {
85 } 85 }
86 86
87 void addTab(QWidget* w) 87 void addTab(QWidget* w)
88 { 88 {
89 QTab* t = new QTab(QString::number(tabBar()->count()+1)); 89 QTab* t = new QTab(QString::number(tabBar()->count()+1));
90 QTabWidget::addTab(w,t); 90 QTabWidget::addTab(w,t);
91 } 91 }
92 92
93 void removeTab(QWidget* w) 93 void removeTab(QWidget* w)
94 { 94 {
95 removePage(w); 95 removePage(w);
96 ((EKNumTabBar*)tabBar())->numberTabs(); 96 ((EKNumTabBar*)tabBar())->numberTabs();
97 } 97 }
98}; 98};
99 99
100// This could be configurable or dynamicly generated from the bash history 100// This could be configurable or dynamicly generated from the bash history
101// file of the user 101// file of the user
102static const char *commonCmds[] = 102static const char *commonCmds[] =
103{ 103{
104 "ls ", // I left this here, cause it looks better than the first alpha 104 "ls ", // I left this here, cause it looks better than the first alpha
105 "cardctl eject", 105 "cardctl eject",
106 "cat ", 106 "cat ",
107 "cd ", 107 "cd ",
108 "chmod ", 108 "chmod ",
109 "clear",
109 "cp ", 110 "cp ",
110 "dc ", 111 "dc ",
111 "df ", 112 "df ",
112 "dmesg", 113 "dmesg",
113 "echo ", 114 "echo ",
114 "env", 115 "env",
115 "find ", 116 "find ",
116 "free", 117 "free",
117 "grep ", 118 "grep ",
118 "ifconfig ", 119 "ifconfig ",
119 "ipkg ", 120 "ipkg ",
120 "mkdir ", 121 "mkdir ",
121 "mv ", 122 "mv ",
122 "nc localhost 7776", 123 "nc localhost 7776",
123 "nc localhost 7777", 124 "nc localhost 7777",
124 "nslookup ", 125 "nslookup ",
125 "ping ", 126 "ping ",
126 "ps aux", 127 "ps aux",
127 "pwd ", 128 "pwd ",
128 "rm ", 129 "rm ",
129 "rmdir ", 130 "rmdir ",
130 "route ", 131 "route ",
131 "set ", 132 "set ",
132 "traceroute", 133 "traceroute",
133 134
134/* 135/*
135 "gzip", 136 "gzip",
136 "gunzip", 137 "gunzip",
137 "chgrp", 138 "chgrp",
138 "chown", 139 "chown",
139 "date", 140 "date",
140 "dd", 141 "dd",
141 "df", 142 "df",
142 "dmesg", 143 "dmesg",
143 "fuser", 144 "fuser",
144 "hostname", 145 "hostname",
145 "kill", 146 "kill",
146 "killall", 147 "killall",
147 "ln", 148 "ln",
148 "ping", 149 "ping",
149 "mount", 150 "mount",
150 "more", 151 "more",
151 "sort", 152 "sort",
152 "touch", 153 "touch",
153 "umount", 154 "umount",
154 "mknod", 155 "mknod",
155 "netstat", 156 "netstat",
156*/ 157*/
157 158
158 "exit", 159 "exit",
159 NULL 160 NULL
160}; 161};
161 162
162 163
163Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 164Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
164 QMainWindow(parent, name, fl) 165 QMainWindow(parent, name, fl)
165{ 166{
166 QStrList args; 167 QStrList args;
167 init("/bin/sh",args); 168 init("/bin/sh",args);
168} 169}
169 170
170Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) 171Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
171 : QMainWindow(0, name) 172 : QMainWindow(0, name)
172{ 173{
173 init(_pgm,_args); 174 init(_pgm,_args);
174} 175}
175 176
176void Konsole::init(const char* _pgm, QStrList & _args) 177void Konsole::init(const char* _pgm, QStrList & _args)
177{ 178{
178 b_scroll = TRUE; // histon; 179 b_scroll = TRUE; // histon;
179 n_keytab = 0; 180 n_keytab = 0;
180 n_render = 0; 181 n_render = 0;
181 182
182 setCaption( tr("Terminal") ); 183 setCaption( tr("Terminal") );
183 setIcon( Resource::loadPixmap( "konsole" ) ); 184 setIcon( Resource::loadPixmap( "konsole" ) );
184 185
185 Config cfg("Konsole"); 186 Config cfg("Konsole");
186 cfg.setGroup("Konsole"); 187 cfg.setGroup("Konsole");
187 QString tmp; 188 QString tmp;
188 // initialize the list of allowed fonts /////////////////////////////////// 189 // initialize the list of allowed fonts ///////////////////////////////////
189 cfont = cfg.readNumEntry("FontID", 1); 190 cfont = cfg.readNumEntry("FontID", 1);
190 QFont f = QFont("Micro", 4, QFont::Normal); 191 QFont f = QFont("Micro", 4, QFont::Normal);
191 f.setFixedPitch(TRUE); 192 f.setFixedPitch(TRUE);
192 fonts.append(new VTFont(tr("Micro"), f)); 193 fonts.append(new VTFont(tr("Micro"), f));
193 194
194 f = QFont("Fixed", 7, QFont::Normal); 195 f = QFont("Fixed", 7, QFont::Normal);
195 f.setFixedPitch(TRUE); 196 f.setFixedPitch(TRUE);
196 fonts.append(new VTFont(tr("Small Fixed"), f)); 197 fonts.append(new VTFont(tr("Small Fixed"), f));
197 198
198 f = QFont("Fixed", 12, QFont::Normal); 199 f = QFont("Fixed", 12, QFont::Normal);
199 f.setFixedPitch(TRUE); 200 f.setFixedPitch(TRUE);
200 fonts.append(new VTFont(tr("Medium Fixed"), f)); 201 fonts.append(new VTFont(tr("Medium Fixed"), f));
201 202
202 // create terminal emulation framework //////////////////////////////////// 203 // create terminal emulation framework ////////////////////////////////////
203 nsessions = 0; 204 nsessions = 0;
204 205
205 tab = new EKNumTabWidget(this); 206 tab = new EKNumTabWidget(this);
206 207
207 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); 208 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
208 209
209 // create terminal toolbar //////////////////////////////////////////////// 210 // create terminal toolbar ////////////////////////////////////////////////
210 setToolBarsMovable( FALSE ); 211 setToolBarsMovable( FALSE );
211 QPEToolBar *menuToolBar = new QPEToolBar( this ); 212 QPEToolBar *menuToolBar = new QPEToolBar( this );
212 menuToolBar->setHorizontalStretchable( TRUE ); 213 menuToolBar->setHorizontalStretchable( TRUE );
213 214
214 QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); 215 QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar );
215 216
216 fontList = new QPopupMenu( this ); 217 fontList = new QPopupMenu( this );
217 for(uint i = 0; i < fonts.count(); i++) { 218 for(uint i = 0; i < fonts.count(); i++) {
218 VTFont *fnt = fonts.at(i); 219 VTFont *fnt = fonts.at(i);
219 fontList->insertItem(fnt->getName(), i); 220 fontList->insertItem(fnt->getName(), i);
220 } 221 }
221 fontChanged(cfont); 222 fontChanged(cfont);
222 223
223 configMenu = new QPopupMenu( this); 224 configMenu = new QPopupMenu( this);
224 colorMenu = new QPopupMenu( this); 225 colorMenu = new QPopupMenu( this);
225 226
226 bool listHidden; 227 bool listHidden;
227 cfg.setGroup("Menubar"); 228 cfg.setGroup("Menubar");
228 if( cfg.readEntry("Hidden","FALSE") == "TRUE") { 229 if( cfg.readEntry("Hidden","FALSE") == "TRUE") {
229 configMenu->insertItem("Show command list"); 230 configMenu->insertItem("Show command list");
230 listHidden=TRUE; 231 listHidden=TRUE;
231 } else { 232 } else {
232 configMenu->insertItem("Hide command list"); 233 configMenu->insertItem("Hide command list");
233 listHidden=FALSE; 234 listHidden=FALSE;
234 } 235 }
235 236
236 cfg.setGroup("Tabs"); 237 cfg.setGroup("Tabs");
237 tmp=cfg.readEntry("Position","Bottom"); 238 tmp=cfg.readEntry("Position","Bottom");
238 if(tmp=="Top") { 239 if(tmp=="Top") {
239 tab->setTabPosition(QTabWidget::Top); 240 tab->setTabPosition(QTabWidget::Top);
240 configMenu->insertItem("Tabs on Bottom"); 241 configMenu->insertItem("Tabs on Bottom");
241 } else { 242 } else {
242 tab->setTabPosition(QTabWidget::Bottom); 243 tab->setTabPosition(QTabWidget::Bottom);
243 configMenu->insertItem("Tabs on Top"); 244 configMenu->insertItem("Tabs on Top");
244 } 245 }
245 configMenu->insertSeparator(2); 246 configMenu->insertSeparator(2);
246 247
247 colorMenu->insertItem("Green on Black"); 248 colorMenu->insertItem("Green on Black");
248 colorMenu->insertItem("Black on White"); 249 colorMenu->insertItem("Black on White");
249 colorMenu->insertItem("White on Black"); 250 colorMenu->insertItem("White on Black");
250 colorMenu->insertItem("Black on Transparent"); 251 colorMenu->insertItem("Black on Transparent");
251 colorMenu->insertItem("Black on Red"); 252 colorMenu->insertItem("Black on Red");
252 colorMenu->insertItem("Red on Black"); 253 colorMenu->insertItem("Red on Black");
253 colorMenu->insertItem("Green on Yellow"); 254 colorMenu->insertItem("Green on Yellow");
254 colorMenu->insertItem("Blue on Magenta"); 255 colorMenu->insertItem("Blue on Magenta");
255 colorMenu->insertItem("Magenta on Blue"); 256 colorMenu->insertItem("Magenta on Blue");
256 colorMenu->insertItem("Cyan on White"); 257 colorMenu->insertItem("Cyan on White");
257 colorMenu->insertItem("White on Cyan"); 258 colorMenu->insertItem("White on Cyan");
258 colorMenu->insertItem("Blue on Black"); 259 colorMenu->insertItem("Blue on Black");
259 configMenu->insertItem("Colors",colorMenu); 260 configMenu->insertItem("Colors",colorMenu);
260 261
261 connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); 262 connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
262 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); 263 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
263 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuSelected(int) )); 264 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuSelected(int) ));
264 265
265 menuBar->insertItem( tr("Font"), fontList ); 266 menuBar->insertItem( tr("Font"), fontList );
266 menuBar->insertItem( tr("Options"), configMenu ); 267 menuBar->insertItem( tr("Options"), configMenu );
267 268
268 QPEToolBar *toolbar = new QPEToolBar( this ); 269 QPEToolBar *toolbar = new QPEToolBar( this );
269 270
270 QAction *a; 271 QAction *a;
271 272
272 // Button Commands 273 // Button Commands
273 a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); 274 a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 );
274 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); 275 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar );
275 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); 276 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 );
276 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); 277 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar );
277 a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 ); 278 a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 );
278 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); 279 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar );
279 a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 ); 280 a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 );
280 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); 281 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar );
281 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); 282 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 );
282 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); 283 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
283 a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 ); 284 a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 );
284 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); 285 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
285 a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 286 a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
286 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar ); 287 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar );
287/* 288/*
288 a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); 289 a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
289 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); 290 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
290 a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); 291 a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
291 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); 292 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
292*/ 293*/
293 294
294 secondToolBar = new QPEToolBar( this ); 295 secondToolBar = new QPEToolBar( this );
295 secondToolBar->setHorizontalStretchable( TRUE ); 296 secondToolBar->setHorizontalStretchable( TRUE );
296 297
297 commonCombo = new QComboBox( secondToolBar ); 298 commonCombo = new QComboBox( secondToolBar );
298 commonCombo->setMaximumWidth(236); 299 commonCombo->setMaximumWidth(236);
299 configMenu->insertItem( "Edit Command List"); 300 configMenu->insertItem( "Edit Command List");
300 if( listHidden) { 301 if( listHidden) {
301 secondToolBar->hide(); 302 secondToolBar->hide();
302 configMenu->setItemEnabled(-20 ,FALSE); 303 configMenu->setItemEnabled(-20 ,FALSE);
303 } 304 }
304 305
305 cfg.setGroup("Commands"); 306 cfg.setGroup("Commands");
306 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 307 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
307 308
308 for (int i = 0; commonCmds[i] != NULL; i++) { 309 for (int i = 0; commonCmds[i] != NULL; i++) {
309 commonCombo->insertItem( commonCmds[i], i ); 310 commonCombo->insertItem( commonCmds[i], i );
310 tmp = cfg.readEntry( QString::number(i),""); 311 tmp = cfg.readEntry( QString::number(i),"");
311 if(tmp != "") 312 if(tmp != "")
312 commonCombo->changeItem( tmp,i ); 313 commonCombo->changeItem( tmp,i );
313 } 314 }
314 315
315 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); 316 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
316 317
317 // create applications ///////////////////////////////////////////////////// 318 // create applications /////////////////////////////////////////////////////
318 setCentralWidget(tab); 319 setCentralWidget(tab);
319 320
320 // load keymaps //////////////////////////////////////////////////////////// 321 // load keymaps ////////////////////////////////////////////////////////////
321 KeyTrans::loadAll(); 322 KeyTrans::loadAll();
322 for (int i = 0; i < KeyTrans::count(); i++) 323 for (int i = 0; i < KeyTrans::count(); i++)
323 { KeyTrans* s = KeyTrans::find(i); 324 { KeyTrans* s = KeyTrans::find(i);
324 assert( s ); 325 assert( s );
325 } 326 }
326 327
327 se_pgm = _pgm; 328 se_pgm = _pgm;
328 se_args = _args; 329 se_args = _args;
329 330
330 // read and apply default values /////////////////////////////////////////// 331 // read and apply default values ///////////////////////////////////////////
331 resize(321, 321); // Dummy. 332 resize(321, 321); // Dummy.
332 QSize currentSize = size(); 333 QSize currentSize = size();
333 if (currentSize != size()) 334 if (currentSize != size())
334 defaultSize = size(); 335 defaultSize = size();
335 336
336} 337}
337 338
338void Konsole::show() 339void Konsole::show()
339{ 340{
340 if ( !nsessions ) { 341 if ( !nsessions ) {
341 newSession(); 342 newSession();
342 } 343 }
343 QMainWindow::show(); 344 QMainWindow::show();
344} 345}
345 346
346void Konsole::initSession(const char*, QStrList &) 347void Konsole::initSession(const char*, QStrList &)
347{ 348{
348 QMainWindow::show(); 349 QMainWindow::show();
349} 350}
350 351
351Konsole::~Konsole() 352Konsole::~Konsole()
352{ 353{
353 while (nsessions > 0) { 354 while (nsessions > 0) {
354 doneSession(getTe()->currentSession, 0); 355 doneSession(getTe()->currentSession, 0);
355 } 356 }
356 357
357 Config cfg("Konsole"); 358 Config cfg("Konsole");
358 cfg.setGroup("Konsole"); 359 cfg.setGroup("Konsole");
359 cfg.writeEntry("FontID", cfont); 360 cfg.writeEntry("FontID", cfont);
360} 361}
361 362
362void Konsole::fontChanged(int f) 363void Konsole::fontChanged(int f)
363{ 364{
364 VTFont* font = fonts.at(f); 365 VTFont* font = fonts.at(f);
365 if (font != 0) { 366 if (font != 0) {
366 for(uint i = 0; i < fonts.count(); i++) { 367 for(uint i = 0; i < fonts.count(); i++) {
367 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); 368 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
368 } 369 }
369 370
370 cfont = f; 371 cfont = f;
371 372
372 TEWidget* te = getTe(); 373 TEWidget* te = getTe();
373 if (te != 0) { 374 if (te != 0) {
374 te->setVTFont(font->getFont()); 375 te->setVTFont(font->getFont());
375 } 376 }
376 } 377 }
377} 378}
378 379
379 380
380void Konsole::enterCommand(int c) 381void Konsole::enterCommand(int c)
381{ 382{
382 TEWidget* te = getTe(); 383 TEWidget* te = getTe();
383 if (te != 0) { 384 if (te != 0) {
384 if(!commonCombo->editable()) { 385 if(!commonCombo->editable()) {
385 QString text = commonCombo->text(c); //commonCmds[c]; 386 QString text = commonCombo->text(c); //commonCmds[c];
386 te->emitText(text); 387 te->emitText(text);
387 } else { 388 } else {
388 changeCommand( commonCombo->text(c), c); 389 changeCommand( commonCombo->text(c), c);
389 } 390 }
390 } 391 }
391} 392}
392 393
393void Konsole::hitEnter() 394void Konsole::hitEnter()
394{ 395{
395 TEWidget* te = getTe(); 396 TEWidget* te = getTe();
396 if (te != 0) { 397 if (te != 0) {
397 te->emitText(QString("\r")); 398 te->emitText(QString("\r"));
398 } 399 }
399} 400}
400 401
401void Konsole::hitSpace() 402void Konsole::hitSpace()
402{ 403{
403 TEWidget* te = getTe(); 404 TEWidget* te = getTe();
404 if (te != 0) { 405 if (te != 0) {
405 te->emitText(QString(" ")); 406 te->emitText(QString(" "));
406 } 407 }
407} 408}
408 409
409void Konsole::hitTab() 410void Konsole::hitTab()
410{ 411{
411 TEWidget* te = getTe(); 412 TEWidget* te = getTe();
412 if (te != 0) { 413 if (te != 0) {
413 te->emitText(QString("\t")); 414 te->emitText(QString("\t"));
414 } 415 }
415} 416}
416 417
417void Konsole::hitPaste() 418void Konsole::hitPaste()
418{ 419{
419 TEWidget* te = getTe(); 420 TEWidget* te = getTe();
420 if (te != 0) { 421 if (te != 0) {
421 te->pasteClipboard(); 422 te->pasteClipboard();
422 } 423 }
423} 424}
424 425
425void Konsole::hitUp() 426void Konsole::hitUp()
426{ 427{
427 TEWidget* te = getTe(); 428 TEWidget* te = getTe();
428 if (te != 0) { 429 if (te != 0) {
429 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); 430 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
430 QApplication::sendEvent( te, &ke ); 431 QApplication::sendEvent( te, &ke );
431 } 432 }
432} 433}
433 434
434void Konsole::hitDown() 435void Konsole::hitDown()
435{ 436{
436 TEWidget* te = getTe(); 437 TEWidget* te = getTe();
437 if (te != 0) { 438 if (te != 0) {
438 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); 439 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
439 QApplication::sendEvent( te, &ke ); 440 QApplication::sendEvent( te, &ke );
440 } 441 }
441} 442}
442 443
443/** 444/**
444 This function calculates the size of the external widget 445 This function calculates the size of the external widget
445 needed for the internal widget to be 446 needed for the internal widget to be
446 */ 447 */
447QSize Konsole::calcSize(int columns, int lines) { 448QSize Konsole::calcSize(int columns, int lines) {
448 TEWidget* te = getTe(); 449 TEWidget* te = getTe();
449 if (te != 0) { 450 if (te != 0) {
450 QSize size = te->calcSize(columns, lines); 451 QSize size = te->calcSize(columns, lines);
451 return size; 452 return size;
452 } else { 453 } else {
453 QSize size; 454 QSize size;
454 return size; 455 return size;
455 } 456 }
456} 457}
457 458
458/** 459/**
459 sets application window to a size based on columns X lines of the te 460 sets application window to a size based on columns X lines of the te
460 guest widget. Call with (0,0) for setting default size. 461 guest widget. Call with (0,0) for setting default size.
461*/ 462*/
462 463
463void Konsole::setColLin(int columns, int lines) 464void Konsole::setColLin(int columns, int lines)
464{ 465{
465 if ((columns==0) || (lines==0)) 466 if ((columns==0) || (lines==0))
466 { 467 {
467 if (defaultSize.isEmpty()) // not in config file : set default value 468 if (defaultSize.isEmpty()) // not in config file : set default value
468 { 469 {
469 defaultSize = calcSize(80,24); 470 defaultSize = calcSize(80,24);
470 // notifySize(24,80); // set menu items (strange arg order !) 471 // notifySize(24,80); // set menu items (strange arg order !)
471 } 472 }
472 resize(defaultSize); 473 resize(defaultSize);
473 } else { 474 } else {
474 resize(calcSize(columns, lines)); 475 resize(calcSize(columns, lines));
475 // notifySize(lines,columns); // set menu items (strange arg order !) 476 // notifySize(lines,columns); // set menu items (strange arg order !)
476 } 477 }
477} 478}
478 479
479/* 480/*
480void Konsole::setFont(int fontno) 481void Konsole::setFont(int fontno)
481{ 482{
482 QFont f; 483 QFont f;
483 if (fontno == 0) 484 if (fontno == 0)
484 f = defaultFont = QFont( "Helvetica", 12 ); 485 f = defaultFont = QFont( "Helvetica", 12 );
485 else 486 else
486 if (fonts[fontno][0] == '-') 487 if (fonts[fontno][0] == '-')
487 f.setRawName( fonts[fontno] ); 488 f.setRawName( fonts[fontno] );
488 else 489 else
489 { 490 {
490 f.setFamily(fonts[fontno]); 491 f.setFamily(fonts[fontno]);
491 f.setRawMode( TRUE ); 492 f.setRawMode( TRUE );
492 } 493 }
493 if ( !f.exactMatch() && fontno != 0) 494 if ( !f.exactMatch() && fontno != 0)
494 { 495 {
495 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); 496 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
496 QMessageBox(this, msg); 497 QMessageBox(this, msg);
497 return; 498 return;
498 } 499 }
499 if (se) se->setFontNo(fontno); 500 if (se) se->setFontNo(fontno);
500 te->setVTFont(f); 501 te->setVTFont(f);
501 n_font = fontno; 502 n_font = fontno;
502} 503}
503*/ 504*/
504 505
505// --| color selection |------------------------------------------------------- 506// --| color selection |-------------------------------------------------------
506 507
507void Konsole::changeColumns(int columns) 508void Konsole::changeColumns(int columns)
508{ 509{
509 TEWidget* te = getTe(); 510 TEWidget* te = getTe();
510 if (te != 0) { 511 if (te != 0) {
511 setColLin(columns,te->Lines()); 512 setColLin(columns,te->Lines());
512 te->update(); 513 te->update();
513 } 514 }
514} 515}
515 516
516//FIXME: If a child dies during session swap, 517//FIXME: If a child dies during session swap,
517// this routine might be called before 518// this routine might be called before
518// session swap is completed. 519// session swap is completed.
519 520
520void Konsole::doneSession(TESession*, int ) 521void Konsole::doneSession(TESession*, int )
521{ 522{
522 TEWidget *te = getTe(); 523 TEWidget *te = getTe();
523 if (te != 0) { 524 if (te != 0) {
524 te->currentSession->setConnect(FALSE); 525 te->currentSession->setConnect(FALSE);
525 tab->removeTab(te); 526 tab->removeTab(te);
526 delete te->currentSession; 527 delete te->currentSession;
527 delete te; 528 delete te;
528 nsessions--; 529 nsessions--;
529 } 530 }
530 531
531 if (nsessions == 0) { 532 if (nsessions == 0) {
532 close(); 533 close();
533 } 534 }
534} 535}
535 536
536void Konsole::newSession() { 537void Konsole::newSession() {
537 if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? 538 if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory?
538 TEWidget* te = new TEWidget(tab); 539 TEWidget* te = new TEWidget(tab);
539// te->setBackgroundMode(PaletteBase); //we want transparent!! 540// te->setBackgroundMode(PaletteBase); //we want transparent!!
540 te->setVTFont(fonts.at(cfont)->getFont()); 541 te->setVTFont(fonts.at(cfont)->getFont());
541 tab->addTab(te); 542 tab->addTab(te);
542 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); 543 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm");
543 te->currentSession = se; 544 te->currentSession = se;
544 connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); 545 connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) );
545 se->run(); 546 se->run();
546 se->setConnect(TRUE); 547 se->setConnect(TRUE);
547 se->setHistory(b_scroll); 548 se->setHistory(b_scroll);
548 tab->setCurrentPage(nsessions); 549 tab->setCurrentPage(nsessions);
549 nsessions++; 550 nsessions++;
550 setColor(); 551 setColor();
551 } 552 }
552} 553}
553 554
554TEWidget* Konsole::getTe() { 555TEWidget* Konsole::getTe() {
555 if (nsessions) { 556 if (nsessions) {
556 return (TEWidget *) tab->currentPage(); 557 return (TEWidget *) tab->currentPage();
557 } else { 558 } else {
558 return 0; 559 return 0;
559 } 560 }
560} 561}
561 562
562void Konsole::switchSession(QWidget* w) { 563void Konsole::switchSession(QWidget* w) {
563 TEWidget* te = (TEWidget *) w; 564 TEWidget* te = (TEWidget *) w;
564 565
565 QFont teFnt = te->getVTFont(); 566 QFont teFnt = te->getVTFont();
566 for(uint i = 0; i < fonts.count(); i++) { 567 for(uint i = 0; i < fonts.count(); i++) {
567 VTFont *fnt = fonts.at(i); 568 VTFont *fnt = fonts.at(i);
568 bool cf = fnt->getFont() == teFnt; 569 bool cf = fnt->getFont() == teFnt;
569 fontList->setItemChecked(i, cf); 570 fontList->setItemChecked(i, cf);
570 if (cf) { 571 if (cf) {
571 cfont = i; 572 cfont = i;
572 } 573 }
573 } 574 }
574} 575}
575 576
576/// ------------------------------- some new stuff by L.J. Potter 577/// ------------------------------- some new stuff by L.J. Potter
577void Konsole::colorMenuSelected(int iD) 578void Konsole::colorMenuSelected(int iD)
578{ // this is NOT pretty, elegant or anything else besides functional 579{ // this is NOT pretty, elegant or anything else besides functional
579// QString temp; 580// QString temp;
580// qDebug( temp.sprintf("%d", iD)); 581// qDebug( temp.sprintf("%d", iD));
581 TEWidget* te = getTe(); 582 TEWidget* te = getTe();
582 Config cfg("Konsole"); 583 Config cfg("Konsole");
583 cfg.setGroup("Colors"); 584 cfg.setGroup("Colors");
584 QColor foreground; 585 QColor foreground;
585 QColor background; 586 QColor background;
586 colorMenu->setItemChecked(lastSelectedMenu,FALSE); 587 colorMenu->setItemChecked(lastSelectedMenu,FALSE);
587 ColorEntry m_table[TABLE_COLORS]; 588 ColorEntry m_table[TABLE_COLORS];
588 const ColorEntry * defaultCt=te->getdefaultColorTable(); 589 const ColorEntry * defaultCt=te->getdefaultColorTable();
589 /////////// fore back 590 /////////// fore back
590 int i; 591 int i;
591 if(iD==-8) { // default default 592 if(iD==-8) { // default default
592 for (i = 0; i < TABLE_COLORS; i++) { 593 for (i = 0; i < TABLE_COLORS; i++) {
593 m_table[i].color = defaultCt[i].color; 594 m_table[i].color = defaultCt[i].color;
594 if(i==1 || i == 11) 595 if(i==1 || i == 11)
595 m_table[i].transparent=1; 596 m_table[i].transparent=1;
596 cfg.writeEntry("Schema","8"); 597 cfg.writeEntry("Schema","8");
597 colorMenu->setItemChecked(-8,TRUE); 598 colorMenu->setItemChecked(-8,TRUE);
598 } 599 }
599 } else { 600 } else {
600 if(iD==-5) { // green black 601 if(iD==-5) { // green black
601 foreground.setRgb(0x18,255,0x18); 602 foreground.setRgb(0x18,255,0x18);
602 background.setRgb(0x00,0x00,0x00); 603 background.setRgb(0x00,0x00,0x00);
603 cfg.writeEntry("Schema","5"); 604 cfg.writeEntry("Schema","5");
604 colorMenu->setItemChecked(-5,TRUE); 605 colorMenu->setItemChecked(-5,TRUE);
605 } 606 }
606 if(iD==-6) { // black white 607 if(iD==-6) { // black white
607 foreground.setRgb(0x00,0x00,0x00); 608 foreground.setRgb(0x00,0x00,0x00);
608 background.setRgb(0xFF,0xFF,0xFF); 609 background.setRgb(0xFF,0xFF,0xFF);
609 cfg.writeEntry("Schema","6"); 610 cfg.writeEntry("Schema","6");
610 colorMenu->setItemChecked(-6,TRUE); 611 colorMenu->setItemChecked(-6,TRUE);
611 } 612 }
612 if(iD==-7) { // white black 613 if(iD==-7) { // white black
613 foreground.setRgb(0xFF,0xFF,0xFF); 614 foreground.setRgb(0xFF,0xFF,0xFF);
614 background.setRgb(0x00,0x00,0x00); 615 background.setRgb(0x00,0x00,0x00);
615 cfg.writeEntry("Schema","7"); 616 cfg.writeEntry("Schema","7");
616 colorMenu->setItemChecked(-7,TRUE); 617 colorMenu->setItemChecked(-7,TRUE);
617 } 618 }
618 if(iD==-9) {// Black, Red 619 if(iD==-9) {// Black, Red
619 foreground.setRgb(0x00,0x00,0x00); 620 foreground.setRgb(0x00,0x00,0x00);
620 background.setRgb(0xB2,0x18,0x18); 621 background.setRgb(0xB2,0x18,0x18);