summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/konsole.cpp
Unidiff
Diffstat (limited to 'core/apps/embeddedkonsole/konsole.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp1542
1 files changed, 1142 insertions, 400 deletions
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,2 +1,3 @@
1
1/* ---------------------------------------------------------------------- */ 2/* ---------------------------------------------------------------------- */
2/* */ 3/* */
@@ -22,5 +23,5 @@
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>
@@ -45,13 +46,14 @@
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>
@@ -66,10 +68,13 @@
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 {
@@ -77,16 +82,20 @@ public:
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++)
85 {
80 QTab* left=0; 86 QTab* left=0;
81 QListIterator<QTab> it(*tabList()); 87 QListIterator<QTab> it(*tabList());
82 int x=INT_MAX; 88 int x=INT_MAX;
83 for( QTab* t; (t=it.current()); ++it ) { 89 for( QTab* t; (t=it.current()); ++it )
90 {
84 int tx = t->rect().x(); 91 int tx = t->rect().x();
85 if ( tx<x && tx>m ) { 92 if ( tx<x && tx>m )
93 {
86 x = tx; 94 x = tx;
87 left = t; 95 left = t;
88 } 96 }
89 } 97 }
90 if ( left ) { 98 if ( left )
99 {
91 left->setText(QString::number(i+1)); 100 left->setText(QString::number(i+1));
92 m = left->rect().x(); 101 m = left->rect().x();
@@ -94,12 +103,41 @@ public:
94 } 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 {
@@ -182,78 +220,146 @@ static const char *commonCmds[] =
182}; 220};
183 221
184static void konsoleInit(const char** shell) {
185 if(setuid(getuid()) !=0) qDebug("setuid failed");
186 if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges
187
188 // signal (SIGSTOP, SIG_IGN);
189
190// QPEApplication::grabKeyboard(); // for CTRL and ALT
191
192// qDebug("keyboard grabbed");
193#ifdef FAKE_CTRL_AND_ALT
194 qDebug("Fake Ctrl and Alt defined");
195 QPEApplication::grabKeyboard(); // for CTRL and ALT
196#endif
197
198 *shell = getenv("SHELL");
199// qWarning("SHell initially is %s", *shell );
200
201 if (shell == NULL || *shell == '\0') {
202 struct passwd *ent = 0;
203 uid_t me = getuid();
204 *shell = "/bin/sh";
205
206 while ( (ent = getpwent()) != 0 ) {
207 if (ent->pw_uid == me) {
208 if (ent->pw_shell != "")
209 *shell = ent->pw_shell;
210 break;
211 }
212 }
213 endpwent();
214 }
215
216// qWarning("SHELL now is %s", *shell );
217
218 if( putenv((char*)"COLORTERM=") !=0)
219 qDebug("putenv failed"); // to trigger mc's color detection
220}
221 222
222Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 223Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
223 QMainWindow(parent, name, fl) 224 QMainWindow(parent, name, fl)
224{ 225{
225 QStrList tmp; const char* shell; 226 QStrList args;
226 227 init("/bin/bash",args);
227 setCaption( tr("Terminal") ); 228}
228 229
229 konsoleInit( &shell); 230Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
230// qWarning("Using shell %s", shell); 231 : QMainWindow(0, name)
231 init(shell,tmp); 232{
233 init(_pgm,_args);
232} 234}
233 235
236struct HistoryItem
237{
238 HistoryItem(int c, const QString &l)
239 {
240 count = c;
241 line = l;
242 }
243 int count;
244 QString line;
245};
234 246
247class HistoryList : public QList<HistoryItem>
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};
235 260
236void Konsole::initCommandList() 261void Konsole::initCommandList()
237{ 262{
238// qDebug("Konsole::initCommandList"); 263// qDebug("Konsole::initCommandList");
239 Config cfg("Konsole"); 264 Config cfg("Qkonsole");
240 cfg.setGroup("Commands"); 265 cfg.setGroup("Commands");
241 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 266 // commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
242 commonCombo->clear(); 267 commonCombo->clear();
243 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 268
244 for (int i = 0; commonCmds[i] != NULL; i++) { 269 if (cfg.readEntry("ShellHistory","TRUE") == "TRUE")
245 commonCombo->insertItem(commonCmds[i],i); 270 {
271 QString histfilename = QString(getenv("HOME")) + "/.bash_history";
272 histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
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;
246 } 288 }
247 } else { 289 line = line.left(line.length()-1);
248 for (int i = 0; i < 100; i++) { 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;
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 {
249 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 335 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
250 commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); 336 commonCombo->insertItem(cfg.readEntry( QString::number(i),""));
251 } 337 }
252 } 338 }
253 339
340
341}
342
343static void sig_handler(int x)
344{
345 printf("got signal %d\n",x);
254} 346}
255 347
256void Konsole::init(const char* _pgm, QStrList & _args) 348void Konsole::init(const char* _pgm, QStrList & _args)
257{ 349{
350
351#if 0
352 for(int i=1; i<=31; i++)
353 {
354 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV
355 && i != SIGINT && i != SIGILL && i != SIGTERM
356 && i != SIGBUS)
357 signal(i,sig_handler);
358 }
359#endif
360 signal(SIGSTOP, sig_handler);
361 signal(SIGCONT, sig_handler);
362 signal(SIGTSTP, sig_handler);
363
258 b_scroll = TRUE; // histon; 364 b_scroll = TRUE; // histon;
259 n_keytab = 0; 365 n_keytab = 0;
@@ -261,88 +367,116 @@ void Konsole::init(const char* _pgm, QStrList & _args)
261 startUp=0; 367 startUp=0;
262 fromMenu = FALSE; 368 fromMenu = FALSE;
369 fullscreen = false;
263 370
264 setCaption( tr("Terminal") ); 371 setCaption( "Qkonsole" );
265 setIcon( Resource::loadPixmap( "konsole" ) ); 372 setIcon( Resource::loadPixmap( "qkonsole/qkonsole" ) );
266 373
267 Config cfg("Konsole"); 374 Config cfg("Qkonsole");
268 cfg.setGroup("Konsole"); 375 cfg.setGroup("Font");
269 QString tmp; 376 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 377
277 f = QFont("Fixed", 7, QFont::Normal); 378 // initialize the list of allowed fonts ///////////////////////////////////
278 f.setFixedPitch(TRUE);
279 fonts.append(new VTFont(tr("Small Fixed"), f));
280 379
281 f = QFont("Fixed", 12, QFont::Normal); 380 QString cfgFontName = cfg.readEntry("FontName","Lcfont");
282 f.setFixedPitch(TRUE); 381 int cfgFontSize = cfg.readNumEntry("FontSize",18);
283 fonts.append(new VTFont(tr("Medium Fixed"), f));
284 382
285// NEW STUFF 383 cfont = -1;
286 384
287 QStringList ignfont = cfg.readListEntry("IgnFont", ','); 385 // this code causes repeated access to all the font files
288 /* If there is no "IgnFont = ..." entry in "myonsole.conf", 386 // which does slow down startup
289 * put some Japanese fonts of the SL-C7x0 to "ignfont". */ 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 );
290 394
291 if (ignfont.isEmpty()) { 395 for(uint j = 0; j < (uint)familyNames.count(); j++)
292 ignfont = QStringList::split (',',"jisupasp,mmkjg1,mmkjg4,mmkjg5"); 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 ) + "]";
293 } 402 }
403 s[0] = s[0].upper();
294 404
295 //QFont 405 QValueList<int> sizes = fontDB.pointSizes( familyNames[j] );
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 406
302 f.setCharSet(QFont::AnyCharSet); 407 printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(),
303 f.setStyleHint(QFont::TypeWriter, QFont::PreferMatch); 408 sizes.count());
304// f.setWeight(QFont::Normal);
305 409
306 /* 410 if (sizes.count() > 0)
307 * Look for installed font families. If the family is not in 411 {
308 * the "ignfont" list, look for available sizes. 412 QPopupMenu *sizeMenu;
309 * If it is fixed pitch font, put the font and the size 413 QFont f;
310 * to the fontlist. 414 int last_width = -1;
311 */ 415 sizeMenu = NULL;
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 416
318 if( fit != "fixed" && fit != "micro" ) { 417 for(uint i = 0; i < (uint)sizes.count() + 4; i++)
319 if ( ignfont.contains(*it) == 0) { 418 {
320 QValueList<int> pt = fdb.pointSizes(*it); 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;
321 422
322 for (QValueList<int>::Iterator itv = pt.begin(); 423 if (i >= (uint)sizes.count())
323 itv != pt.end(); ++itv ) { 424 {
324 int size = (*itv)/10; 425 // try for expandable fonts
325 if(size > 0) { 426 size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1);
326 f.setFamily(*it);
327 f.setPointSize(size);
328 } 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
329 437
330 QFontMetrics fm(f); 438 f = QFont(familyNames[j], size);
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); 439 f.setFixedPitch(true);
337 fonts.append(new VTFont(*it + ' ' + QString::number(size), f)); 440 QFontMetrics fm(f);
338 fcount++; 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");
339 } 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;
340 } 462 }
463 printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size);
464 fontIndex++;
341 } 465 }
342 } 466 }
467 if (sizeMenu)
468 {
469 fontList->insertItem(s, sizeMenu, familyNum + 1000);
470
471 familyNum++;
472 }
343 } 473 }
344 474
345// END NEW STUFF 475 }
346 476
477 if (cfont < 0 || cfont >= (int)fonts.count())
478 {
479 cfont = 0;
480 }
347 481
348// create terminal emulation framework //////////////////////////////////// 482// create terminal emulation framework ////////////////////////////////////
@@ -350,21 +484,24 @@ void Konsole::init(const char* _pgm, QStrList & _args)
350 484
351 tab = new EKNumTabWidget(this); 485 tab = new EKNumTabWidget(this);
352 486 // tab->setMargin(tab->margin()-5);
353 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); 487 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
354 488
355 // create terminal toolbar //////////////////////////////////////////////// 489 // create terminal toolbar ////////////////////////////////////////////////
356 setToolBarsMovable( FALSE ); 490 setToolBarsMovable( FALSE );
357 QToolBar *menuToolBar = new QToolBar( this ); 491 menuToolBar = new QToolBar( this );
358 menuToolBar->setHorizontalStretchable( TRUE ); 492 menuToolBar->setHorizontalStretchable( TRUE );
359 493
360 QMenuBar *menuBar = new QMenuBar( menuToolBar ); 494 QMenuBar *menuBar = new QMenuBar( menuToolBar );
361 495
362 fontList = new QPopupMenu( this ); 496 bool c7xx = false;
363 for(uint i = 0; i < fonts.count(); i++) { 497 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600)
364 VTFont *fnt = fonts.at(i); 498 {
365 fontList->insertItem(fnt->getName(), i); 499 c7xx = true;
366 } 500 }
501 QFont menuFont;
502 menuFont.setPointSize(c7xx? 18 : 10);
503 qApp->setFont(menuFont, true);
367 504
368 fontChanged(cfont); 505 setFont(cfont);
369 506
370 configMenu = new QPopupMenu( this); 507 configMenu = new QPopupMenu( this);
@@ -377,77 +514,117 @@ void Konsole::init(const char* _pgm, QStrList & _args)
377 bool listHidden; 514 bool listHidden;
378 cfg.setGroup("Menubar"); 515 cfg.setGroup("Menubar");
379 if( cfg.readEntry("Hidden","FALSE") == "TRUE") { 516 if( cfg.readEntry("Hidden","FALSE") == "TRUE")
380 editCommandListMenu->insertItem( tr( "Show command list" )); 517 {
518 ec_cmdlist = editCommandListMenu->insertItem( tr( "Show command list" ));
381 listHidden=TRUE; 519 listHidden=TRUE;
382 } else { 520 }
383 editCommandListMenu->insertItem( tr( "Hide command list" )); 521 else
522 {
523 ec_cmdlist = editCommandListMenu->insertItem( tr( "Hide command list" ));
384 listHidden=FALSE; 524 listHidden=FALSE;
385 } 525 }
386 526
387 cfg.setGroup("Tabs"); 527 cfg.setGroup("Tabs");
388 tmp=cfg.readEntry("Position","Bottom"); 528
389 if(tmp=="Top") { 529 tabMenu = new QPopupMenu(this);
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 {
390 tab->setTabPosition(QTabWidget::Top); 539 tab->setTabPosition(QTabWidget::Top);
391 configMenu->insertItem( tr( "Tabs on Bottom" ) ); 540 tab->getTabBar()->show();
392 } else { 541 tabPos = tm_top;
542 }
543 else if (tmp=="Bottom")
544 {
393 tab->setTabPosition(QTabWidget::Bottom); 545 tab->setTabPosition(QTabWidget::Bottom);
394 configMenu->insertItem(tr("Tabs on Top")); 546 tab->getTabBar()->show();
395 } 547 tabPos = tm_bottom;
396 configMenu->insertSeparator(2); 548 }
397 549 else
398 colorMenu->insertItem(tr( "Green on Black")); 550 {
399 colorMenu->insertItem(tr( "Black on White")); 551 tab->getTabBar()->hide();
400 colorMenu->insertItem(tr( "White on Black")); 552 tab->setMargin(tab->margin());
401 colorMenu->insertItem(tr( "Black on Transparent")); 553 tabPos = tm_hidden;
402 colorMenu->insertItem(tr( "Black on Red")); 554 }
403 colorMenu->insertItem(tr( "Red on Black")); 555
404 colorMenu->insertItem(tr( "Green on Yellow")); 556 cm_bw = colorMenu->insertItem(tr( "Black on White"));
405 colorMenu->insertItem(tr( "Blue on Magenta")); 557 cm_wb = colorMenu->insertItem(tr( "White on Black"));
406 colorMenu->insertItem(tr( "Magenta on Blue")); 558 cm_gb = colorMenu->insertItem(tr( "Green on Black"));
407 colorMenu->insertItem(tr( "Cyan on White")); 559 // cm_bt = colorMenu->insertItem(tr( "Black on Transparent"));
408 colorMenu->insertItem(tr( "White on Cyan")); 560 cm_br = colorMenu->insertItem(tr( "Black on Pink"));
409 colorMenu->insertItem(tr( "Blue on Black")); 561 cm_rb = colorMenu->insertItem(tr( "Pink on Black"));
410 colorMenu->insertItem(tr( "Amber 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
572
413 colorMenu->insertItem(tr( "Custom")); 573 colorMenu->insertItem(tr( "Custom"));
414#endif 574#endif
415 575
416 configMenu->insertItem( tr("Font"), fontList );
417 configMenu->insertItem(tr( "Colors") ,colorMenu); 576 configMenu->insertItem(tr( "Colors") ,colorMenu);
418 577
419 connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); 578 sessionList = new QPopupMenu(this);
579 sessionList-> insertItem ( Resource::loadPixmap ( "qkonsole/qkonsole" ), tr( "new session" ), this,
580 SLOT(newSession()) );
581
582 // connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
420 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); 583 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
421 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); 584 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) ));
585 connect( tabMenu, SIGNAL( activated(int) ), this, SLOT( tabMenuSelected(int) ));
422 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); 586 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int)));
423 connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); 587 connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int)));
588 connect( sessionList, SIGNAL(activated(int)), this, SLOT( sessionListSelected(int) ) );
424 589
425 menuBar->insertItem( tr("Options"), configMenu ); 590 menuBar->insertItem( tr("View"), configMenu );
591 menuBar->insertItem( tr("Fonts"), fontList );
592 menuBar->insertItem( tr("Sessions"), sessionList );
426 593
427 QToolBar *toolbar = new QToolBar( this ); 594 toolBar = new QToolBar( this );
428 595
429 QAction *a; 596 QAction *a;
430 597
431 // Button Commands 598 // Button Commands
432 a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); 599 a = new QAction( tr("New"), Resource::loadPixmap( "konsole/Terminal" ), QString::null, 0, this, 0 );
433 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); 600 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) );
601 a->addTo( toolBar );
602
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 );
606
607 a = new QAction( tr("Zoom"), Resource::loadPixmap( "zoom" ), QString::null, 0, this, 0 );
608 connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) );
609 a->addTo( toolBar );
610
611
612 /*
434 a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); 613 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 ); 614 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 ); 615 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 ); 616 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 ); 617 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 ); 618 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolBar );
619 */
620 /*
440 a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); 621 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 ); 622 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 ); 623 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 ); 624 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*/ 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 );
452 629
453 secondToolBar = new QToolBar( this ); 630 secondToolBar = new QToolBar( this );
@@ -455,12 +632,13 @@ void Konsole::init(const char* _pgm, QStrList & _args)
455 632
456 commonCombo = new QComboBox( secondToolBar ); 633 commonCombo = new QComboBox( secondToolBar );
457 commonCombo->setMaximumWidth(236); 634 // commonCombo->setMaximumWidth(236);
458 635
459 editCommandListMenu->insertItem( tr( "Quick Edit" ) ); 636 ec_quick = editCommandListMenu->insertItem( tr( "Quick Edit" ) );
460 if( listHidden) { 637 if( listHidden)
638 {
461 secondToolBar->hide(); 639 secondToolBar->hide();
462 editCommandListMenu->setItemEnabled(-23 ,FALSE); 640 editCommandListMenu->setItemEnabled(ec_quick ,FALSE);
463 } 641 }
464 editCommandListMenu->insertItem(tr( "Edit" ) ); 642 ec_edit = editCommandListMenu->insertItem(tr( "Edit" ) );
465 643
466 cfg.setGroup("Commands"); 644 cfg.setGroup("Commands");
@@ -477,7 +655,7 @@ void Konsole::init(const char* _pgm, QStrList & _args)
477 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); 655 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
478 656
479 scrollMenu->insertItem(tr( "None" )); 657 sm_none = scrollMenu->insertItem(tr( "None" ));
480 scrollMenu->insertItem(tr( "Left" )); 658 sm_left = scrollMenu->insertItem(tr( "Left" ));
481 scrollMenu->insertItem(tr( "Right" )); 659 sm_right = scrollMenu->insertItem(tr( "Right" ));
482// scrollMenu->insertSeparator(4); 660// scrollMenu->insertSeparator(4);
483// scrollMenu->insertItem(tr( "Horizontal" )); 661// scrollMenu->insertItem(tr( "Horizontal" ));
@@ -485,13 +663,26 @@ void Konsole::init(const char* _pgm, QStrList & _args)
485 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); 663 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
486 664
487 int jut = configMenu->insertItem(tr( "Wrap" )); 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");
673 configMenu->setItemChecked(cm_beep, cfg.readBoolEntry("useBeep",0));
493 674
494 configMenu->setItemChecked(jut, cfg.readBoolEntry("useBeep",0)); 675 fullscreen_msg = new QLabel(this);
676 fullscreen_msg-> setAlignment ( AlignCenter | SingleLine );
677 fullscreen_msg-> hide();
678 fullscreen_msg-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ));
679 fullscreen_msg-> setAutoResize(true);
680 fullscreen_msg-> setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
681 fullscreen_msg-> setText(tr("To exit fullscreen, tap here."));
495 682
683 fullscreen_timer = new QTimer(this);
684 connect(fullscreen_timer, SIGNAL(timeout()),
685 this, SLOT(fullscreenTimeout()));
686 show_fullscreen_msg = true;
496 687
497//scrollMenuSelected(-29); 688//scrollMenuSelected(-29);
@@ -511,5 +702,6 @@ void Konsole::init(const char* _pgm, QStrList & _args)
511 KeyTrans::loadAll(); 702 KeyTrans::loadAll();
512 for (int i = 0; i < KeyTrans::count(); i++) 703 for (int i = 0; i < KeyTrans::count(); i++)
513 { KeyTrans* s = KeyTrans::find(i); 704 {
705 KeyTrans* s = KeyTrans::find(i);
514 assert( s ); 706 assert( s );
515 } 707 }
@@ -517,6 +709,34 @@ void Konsole::init(const char* _pgm, QStrList & _args)
517 se_pgm = _pgm; 709 se_pgm = _pgm;
518 se_args = _args; 710 se_args = _args;
711
712 cfg.setGroup("CommandLine");
713
714 if (cfg.hasKey("shell_args"))
715 {
716 QStringList se_args_list = cfg.readListEntry("shell_args",'|');
717 for(uint i = 0; i < se_args_list.count(); i++)
718 {
719 se_args.prepend(se_args_list[se_args_list.count() - i - 1].latin1());
720 }
721 }
722 else
723 {
519 se_args.prepend("--login"); 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
520parseCommandLine(); 739parseCommandLine();
740
521 // read and apply default values /////////////////////////////////////////// 741 // read and apply default values ///////////////////////////////////////////
522 resize(321, 321); // Dummy. 742 resize(321, 321); // Dummy.
@@ -524,9 +744,15 @@ parseCommandLine();
524 if (currentSize != size()) 744 if (currentSize != size())
525 defaultSize = 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 )
756 {
531 newSession(); 757 newSession();
532 } 758 }
@@ -542,18 +768,185 @@ void Konsole::initSession(const char*, QStrList &)
542Konsole::~Konsole() 768Konsole::~Konsole()
543{ 769{
544 while (nsessions > 0) { 770 while (nsessions > 0)
545 doneSession(getTe()->currentSession, 0); 771 {
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 }
546 } 879 }
547 880
548 Config cfg("Konsole"); 881int Konsole::findFont(QString name, int size, bool exactMatch)
549 cfg.setGroup("Konsole"); 882{
550 cfg.writeEntry("FontID", cfont); 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);
551} 903}
552 904
905void Konsole::setFont(int f)
906{
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 }
941}
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 }
@@ -562,9 +955,11 @@ void Konsole::fontChanged(int 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
@@ -572,9 +967,13 @@ void 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 }
@@ -585,5 +984,6 @@ void Konsole::hitEnter()
585{ 984{
586 TEWidget* te = getTe(); 985 TEWidget* te = getTe();
587 if (te != 0) { 986 if (te != 0)
987 {
588 te->emitText(QString("\r")); 988 te->emitText(QString("\r"));
589 } 989 }
@@ -593,5 +993,6 @@ void Konsole::hitSpace()
593{ 993{
594 TEWidget* te = getTe(); 994 TEWidget* te = getTe();
595 if (te != 0) { 995 if (te != 0)
996 {
596 te->emitText(QString(" ")); 997 te->emitText(QString(" "));
597 } 998 }
@@ -601,5 +1002,6 @@ void Konsole::hitTab()
601{ 1002{
602 TEWidget* te = getTe(); 1003 TEWidget* te = getTe();
603 if (te != 0) { 1004 if (te != 0)
1005 {
604 te->emitText(QString("\t")); 1006 te->emitText(QString("\t"));
605 } 1007 }
@@ -609,5 +1011,6 @@ void Konsole::hitPaste()
609{ 1011{
610 TEWidget* te = getTe(); 1012 TEWidget* te = getTe();
611 if (te != 0) { 1013 if (te != 0)
1014 {
612 te->pasteClipboard(); 1015 te->pasteClipboard();
613 } 1016 }
@@ -617,5 +1020,6 @@ void Konsole::hitUp()
617{ 1020{
618 TEWidget* te = getTe(); 1021 TEWidget* te = getTe();
619 if (te != 0) { 1022 if (te != 0)
1023 {
620 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); 1024 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
621 QApplication::sendEvent( te, &ke ); 1025 QApplication::sendEvent( te, &ke );
@@ -626,5 +1030,6 @@ void Konsole::hitDown()
626{ 1030{
627 TEWidget* te = getTe(); 1031 TEWidget* te = getTe();
628 if (te != 0) { 1032 if (te != 0)
1033 {
629 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); 1034 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
630 QApplication::sendEvent( te, &ke ); 1035 QApplication::sendEvent( te, &ke );
@@ -636,10 +1041,14 @@ void Konsole::hitDown()
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)
1047 {
641 QSize size = te->calcSize(columns, lines); 1048 QSize size = te->calcSize(columns, lines);
642 return size; 1049 return size;
643 } else { 1050 }
1051 else
1052 {
644 QSize size; 1053 QSize size;
645 return size; 1054 return size;
@@ -664,5 +1073,7 @@ void Konsole::setColLin(int columns, int lines)
664 } 1073 }
665 resize(defaultSize); 1074 resize(defaultSize);
666 } else { 1075 }
1076 else
1077 {
667 resize(calcSize(columns, lines)); 1078 resize(calcSize(columns, lines));
668 // notifySize(lines,columns); // set menu items (strange arg order !) 1079 // notifySize(lines,columns); // set menu items (strange arg order !)
@@ -698,7 +1109,6 @@ void Konsole::setFont(int fontno)
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
703 // qDebug("change columns"); 1113 // qDebug("change columns");
704 // TEWidget* te = getTe(); 1114 // TEWidget* te = getTe();
@@ -713,66 +1123,279 @@ void Konsole::changeColumns(int columns)
713// session swap is completed. 1123// session swap is completed.
714 1124
715void Konsole::doneSession(TESession*, int ) 1125void Konsole::doneSession(TEWidget* te, int )
1126{
1127 // TEWidget *te = NULL;
1128 // if (sess->currentSession == tab->currentPage()) {
1129 // printf("done current session\n");
1130 // te = getTe();
1131 // } else {
1132 // int currentPage = tab->currentPageIndex();
1133 // printf("done not current session\n");
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)
716{ 1147{
717 TEWidget *te = getTe();
718 if (te != 0) {
719 te->currentSession->setConnect(FALSE); 1148 te->currentSession->setConnect(FALSE);
720 tab->removeTab(te); 1149 tab->removeTab(te);
721 delete te->currentSession; 1150 delete te->currentSession;
722 delete te; 1151 delete te;
1152 sessionList->removeItem(nsessions);
723 nsessions--; 1153 nsessions--;
724 } 1154 }
725 1155 if (nsessions == 0)
726 if (nsessions == 0) { 1156 {
727 close(); 1157 close();
728 } 1158 }
729} 1159}
730 1160
731void Konsole::newSession() { 1161void Konsole::changeTitle(TEWidget* te, QString newTitle )
732 if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? 1162{
1163 if (te == getTe())
1164 {
1165 setCaption(newTitle + " - QKonsole");
1166 }
1167}
1168
1169
1170void Konsole::newSession()
1171{
1172 if(nsessions < 15)
1173 { // seems to be something weird about 16 tabs on the Zaurus.... memory?
733 TEWidget* te = new TEWidget(tab); 1174 TEWidget* te = new TEWidget(tab);
734 Config c("Konsole"); 1175 Config cfg("Qkonsole");
735 c.setGroup("Menubar"); 1176 cfg.setGroup("Menubar");
736 te->useBeep=c.readBoolEntry("useBeep",0); 1177
1178 // FIXME use more defaults from config file
1179 te->useBeep=cfg.readBoolEntry("useBeep",0);
737 1180
738// te->setBackgroundMode(PaletteBase); //we want transparent!! 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{
1222 if (nsessions)
1223 {
756 return (TEWidget *) tab->currentPage(); 1224 return (TEWidget *) tab->currentPage();
757 } else { 1225 }
1226 else
1227 {
758 return 0; 1228 return 0;
759 } 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();
1240
1241 int n = 0;
1242 for(int i = 0; n < tabBar->count(); i++)
1243 {
1244 if (tabBar->tab(i))
1245 {
1246 // printf("selected = %s tab %d = %s\n", selected.latin1(),
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 }
1255 }
1256}
764 1257
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;
765 QFont teFnt = te->getVTFont(); 1291 QFont teFnt = te->getVTFont();
766 for(uint i = 0; i < fonts.count(); i++) { 1292 int familyNum = -1;
1293
1294 for(uint i = 0; i < fonts.count(); i++)
1295 {
767 VTFont *fnt = fonts.at(i); 1296 VTFont *fnt = fonts.at(i);
768 bool cf = fnt->getFont() == teFnt; 1297 bool cf = fnt->getFont() == teFnt;
769 fontList->setItemChecked(i, cf); 1298 fontList->setItemChecked(i, cf);
770 if (cf) { 1299 if (cf)
1300 {
771 cfont = i; 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);
772 } 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 ( );
773 } 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();
774} 1396}
775 1397
776void Konsole::colorMenuIsSelected(int iD) { 1398void Konsole::colorMenuIsSelected(int iD)
1399{
777 fromMenu = TRUE; 1400 fromMenu = TRUE;
778 colorMenuSelected(iD); 1401 colorMenuSelected(iD);
@@ -780,107 +1403,129 @@ void Konsole::colorMenuIsSelected(int iD) {
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{
1409 // this is NOT pretty, elegant or anything else besides functional
784// QString temp; 1410// QString temp;
785// qDebug( temp.sprintf("colormenu %d", iD)); 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); 1446 }
1447 te->setColorTable(m_table);
804 } 1448 }
805 } else { 1449 if(iD==cm_gb)
806 if(iD==-6) { // green black 1450 { // green black
807 foreground.setRgb(0x18,255,0x18); 1451 foreground.setRgb(100,255,100); // (0x18,255,0x18);
808 background.setRgb(0x00,0x00,0x00); 1452 background.setRgb(0x00,0x00,0x00);
809 cfg.writeEntry("Schema","6"); 1453 colorMenu->setItemChecked(cm_gb,TRUE);
810 colorMenu->setItemChecked(-6,TRUE);
811 } 1454 }
812 if(iD==-7) { // black white 1455 if(iD==cm_bw)
1456 { // black white
813 foreground.setRgb(0x00,0x00,0x00); 1457 foreground.setRgb(0x00,0x00,0x00);
814 background.setRgb(0xFF,0xFF,0xFF); 1458 background.setRgb(0xFF,0xFF,0xFF);
815 cfg.writeEntry("Schema","7"); 1459 colorMenu->setItemChecked(cm_bw,TRUE);
816 colorMenu->setItemChecked(-7,TRUE);
817 } 1460 }
818 if(iD==-8) { // white black 1461 if(iD==cm_wb)
1462 { // white black
819 foreground.setRgb(0xFF,0xFF,0xFF); 1463 foreground.setRgb(0xFF,0xFF,0xFF);
820 background.setRgb(0x00,0x00,0x00); 1464 background.setRgb(0x00,0x00,0x00);
821 cfg.writeEntry("Schema","8"); 1465 colorMenu->setItemChecked(cm_wb,TRUE);
822 colorMenu->setItemChecked(-8,TRUE);
823 } 1466 }
824 if(iD==-10) {// Black, Red 1467 if(iD==cm_br)
1468 {// Black, Red
825 foreground.setRgb(0x00,0x00,0x00); 1469 foreground.setRgb(0x00,0x00,0x00);
826 background.setRgb(0xB2,0x18,0x18); 1470 background.setRgb(255,85,85); //(0xB2,0x18,0x18);
827 cfg.writeEntry("Schema","10"); 1471 colorMenu->setItemChecked(cm_br,TRUE);
828 colorMenu->setItemChecked(-10,TRUE);
829 } 1472 }
830 if(iD==-11) {// Red, Black 1473 if(iD==cm_rb)
831 foreground.setRgb(230,31,31); //0xB2,0x18,0x18 1474 {// Red, Black
1475 foreground.setRgb(255,85,85);
832 background.setRgb(0x00,0x00,0x00); 1476 background.setRgb(0x00,0x00,0x00);
833 cfg.writeEntry("Schema","11"); 1477 colorMenu->setItemChecked(cm_rb,TRUE);
834 colorMenu->setItemChecked(-11,TRUE);
835 } 1478 }
836 if(iD==-12) {// Green, Yellow - is ugly 1479 if(iD==cm_gy)
1480 {// Green, Yellow - is ugly
837// foreground.setRgb(0x18,0xB2,0x18); 1481// foreground.setRgb(0x18,0xB2,0x18);
838 foreground.setRgb(36,139,10); 1482 foreground.setRgb(15,115,0);
839// background.setRgb(0xB2,0x68,0x18); 1483// background.setRgb(0xB2,0x68,0x18);
840 background.setRgb(255,255,0); 1484 background.setRgb(255,255,0);
841 cfg.writeEntry("Schema","12"); 1485 colorMenu->setItemChecked(cm_gy,TRUE);
842 colorMenu->setItemChecked(-12,TRUE); 1486 }
843 } 1487 if(iD==cm_bm)
844 if(iD==-13) {// Blue, Magenta 1488 {// Blue, Magenta
845 foreground.setRgb(0x18,0xB2,0xB2); 1489 foreground.setRgb(3,24,132);
846 background.setRgb(0x18,0x18,0xB2); 1490 background.setRgb(225,2,255);
847 cfg.writeEntry("Schema","13"); 1491 colorMenu->setItemChecked(cm_bm,TRUE);
848 colorMenu->setItemChecked(-13,TRUE); 1492 }
849 } 1493 if(iD==cm_mb)
850 if(iD==-14) {// Magenta, Blue 1494 {// Magenta, Blue
851 foreground.setRgb(0x18,0x18,0xB2); 1495 foreground.setRgb(225,2,255);
852 background.setRgb(0x18,0xB2,0xB2); 1496 background.setRgb(3,24,132);
853 cfg.writeEntry("Schema","14"); 1497 colorMenu->setItemChecked(cm_mb,TRUE);
854 colorMenu->setItemChecked(-14,TRUE); 1498 }
855 } 1499 if(iD==cm_cw)
856 if(iD==-15) {// Cyan, White 1500 {// Cyan, White
857 foreground.setRgb(0x18,0xB2,0xB2); 1501 foreground.setRgb(8,91,129);
858 background.setRgb(0xFF,0xFF,0xFF); 1502 background.setRgb(0xFF,0xFF,0xFF);
859 cfg.writeEntry("Schema","15"); 1503 colorMenu->setItemChecked(cm_cw,TRUE);
860 colorMenu->setItemChecked(-15,TRUE);
861 } 1504 }
862 if(iD==-16) {// White, Cyan 1505 if(iD==cm_wc)
863 background.setRgb(0x18,0xB2,0xB2); 1506 {// White, Cyan
1507 background.setRgb(8,91,129);
864 foreground.setRgb(0xFF,0xFF,0xFF); 1508 foreground.setRgb(0xFF,0xFF,0xFF);
865 cfg.writeEntry("Schema","16"); 1509 colorMenu->setItemChecked(cm_wc,TRUE);
866 colorMenu->setItemChecked(-16,TRUE);
867 } 1510 }
868 if(iD==-17) {// Black, Blue 1511 if(iD==cm_bb)
1512 {// Black, Blue
869 background.setRgb(0x00,0x00,0x00); 1513 background.setRgb(0x00,0x00,0x00);
870 foreground.setRgb(0x18,0xB2,0xB2); 1514 foreground.setRgb(127,147,225);
871 cfg.writeEntry("Schema","17"); 1515 colorMenu->setItemChecked(cm_bb,TRUE);
872 colorMenu->setItemChecked(-17,TRUE);
873 } 1516 }
874 if(iD==-18) {// Black, Gold 1517 if(iD==cm_ab)
1518 {// Black, Gold
875 background.setRgb(0x00,0x00,0x00); 1519 background.setRgb(0x00,0x00,0x00);
876 foreground.setRgb(255,215,0); 1520 foreground.setRgb(255,215,105);
877 cfg.writeEntry("Schema","18"); 1521 colorMenu->setItemChecked(cm_ab,TRUE);
878 colorMenu->setItemChecked(-18,TRUE);
879 } 1522 }
880#ifdef QT_QWS_OPIE 1523#ifdef QT_QWS_OPIE
881 if(iD==-19) { 1524 if(iD==-19)
1525 {
882// Custom 1526// Custom
883 qDebug("do custom"); 1527 qDebug("do custom");
884 if(fromMenu) { 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,
@@ -888,6 +1533,6 @@ void Konsole::colorMenuSelected(int iD)
888 penColorPopupMenu->exec(); 1533 penColorPopupMenu->exec();
889 } 1534 }
890 cfg.writeEntry("Schema","19"); 1535 if(!fromMenu)
891 if(!fromMenu) { 1536 {
892 foreground.setNamedColor(cfg.readEntry("foreground","")); 1537 foreground.setNamedColor(cfg.readEntry("foreground",""));
893 background.setNamedColor(cfg.readEntry("background","")); 1538 background.setNamedColor(cfg.readEntry("background",""));
@@ -897,51 +1542,99 @@ void Konsole::colorMenuSelected(int iD)
897 } 1542 }
898#endif 1543#endif
899 for (i = 0; i < TABLE_COLORS; i++) { 1544
900 if(i==0 || i == 10) { 1545 lastSelectedMenu = iD;
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
1569 update();
1570}
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 {
901 m_table[i].color = foreground; 1583 m_table[i].color = foreground;
902 } 1584 }
903 else if(i==1 || i == 11) { 1585 else if(i==1 || i == 11)
904 m_table[i].color = background; m_table[i].transparent=0; 1586 {
1587 m_table[i].color = background;
1588 m_table[i].transparent=0;
905 } 1589 }
906 else 1590 else
907 m_table[i].color = defaultCt[i].color; 1591 m_table[i].color = defaultCt[i].color;
908 } 1592 }
909 }
910 lastSelectedMenu = iD;
911 te->setColorTable(m_table); 1593 te->setColorTable(m_table);
912 update();
913
914} 1594}
915 1595
916void Konsole::configMenuSelected(int iD) 1596void Konsole::tabMenuSelected(int id)
917{ 1597{
918// QString temp; 1598 Config cfg("Qkonsole");
919// qDebug( temp.sprintf("configmenu %d",iD));
920
921 TEWidget* te = getTe();
922 Config cfg("Konsole");
923 cfg.setGroup("Menubar");
924 int i,j;
925#ifdef QT_QWS_OPIE
926 i=-29;j=-30;
927#else
928 i=-28;j=-29;
929#endif
930
931 if(iD == -4) {
932 cfg.setGroup("Tabs"); 1599 cfg.setGroup("Tabs");
933 QString tmp=cfg.readEntry("Position","Bottom"); 1600 tabMenu->setItemChecked(tabPos, false);
934 1601 if (id == tm_bottom)
935 if(tmp=="Top") { 1602 {
1603 printf("set bottom tab\n");
1604 tab->getTabBar()->show();
936 tab->setTabPosition(QTabWidget::Bottom); 1605 tab->setTabPosition(QTabWidget::Bottom);
937 configMenu->changeItem( iD, tr("Tabs on Top")); 1606 tab->getTabBar()->show();
938 cfg.writeEntry("Position","Bottom"); 1607 cfg.writeEntry("Position","Bottom");
939 } else { 1608 }
1609 else if (id == tm_top)
1610 {
1611 printf("set top tab\n");
1612 tab->getTabBar()->show();
1613 tab->setTabPosition(QTabWidget::Bottom);
940 tab->setTabPosition(QTabWidget::Top); 1614 tab->setTabPosition(QTabWidget::Top);
941 configMenu->changeItem( iD, tr("Tabs on Bottom")); 1615 tab->getTabBar()->show();
942 cfg.writeEntry("Position","Top"); 1616 cfg.writeEntry("Position","Top");
943 } 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;
944 } 1626 }
945 if(iD == i) { 1627
1628
1629void Konsole::configMenuSelected(int iD)
1630{
1631 // QString temp;
1632 // qDebug( temp.sprintf("configmenu %d",iD));
1633
1634 TEWidget* te = getTe();
1635 Config cfg("Qkonsole");
1636 cfg.setGroup("Menubar");
1637 if(iD == cm_wrap)
1638 {
946 cfg.setGroup("ScrollBar"); 1639 cfg.setGroup("ScrollBar");
947 bool b=cfg.readBoolEntry("HorzScroll",0); 1640 bool b=cfg.readBoolEntry("HorzScroll",0);
@@ -950,12 +1643,16 @@ void Konsole::configMenuSelected(int iD)
950 cfg.write(); 1643 cfg.write();
951 doWrap(); 1644 doWrap();
952 if(cfg.readNumEntry("Position",2) == 0) { 1645 if(cfg.readNumEntry("Position",2) == 0)
1646 {
953 te->setScrollbarLocation(1); 1647 te->setScrollbarLocation(1);
954 } else { 1648 }
1649 else
1650 {
955 te->setScrollbarLocation(0); 1651 te->setScrollbarLocation(0);
956 } 1652 }
957 te->setScrollbarLocation( cfg.readNumEntry("Position",2)); 1653 te->setScrollbarLocation( cfg.readNumEntry("Position",2));
958 } 1654 }
959 if(iD == j) { 1655 if(iD == cm_beep)
1656 {
960 cfg.setGroup("Menubar"); 1657 cfg.setGroup("Menubar");
961 bool b=cfg.readBoolEntry("useBeep",0); 1658 bool b=cfg.readBoolEntry("useBeep",0);
@@ -963,5 +1660,5 @@ void Konsole::configMenuSelected(int iD)
963 cfg.writeEntry("useBeep", b ); 1660 cfg.writeEntry("useBeep", b );
964 cfg.write(); 1661 cfg.write();
965 configMenu->setItemChecked(j,b); 1662 configMenu->setItemChecked(cm_beep,b);
966 te->useBeep=b; 1663 te->useBeep=b;
967 } 1664 }
@@ -970,7 +1667,8 @@ void Konsole::configMenuSelected(int iD)
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();
@@ -979,10 +1677,23 @@ void Konsole::changeCommand(const QString &text, int c)
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
@@ -992,25 +1703,26 @@ void Konsole::scrollMenuSelected(int 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 1707
1708 if(index == sm_none)
1709 {
1004 te->setScrollbarLocation(0); 1710 te->setScrollbarLocation(0);
1005 cfg.writeEntry("Position",0); 1711 cfg.writeEntry("Position",0);
1006 } else if(index == j) { 1712 }
1007 1713 else if(index == sm_left)
1714 {
1008 te->setScrollbarLocation(1); 1715 te->setScrollbarLocation(1);
1009 cfg.writeEntry("Position",1); 1716 cfg.writeEntry("Position",1);
1010 } else if(index == k) { 1717 }
1011 1718 else if(index == sm_right)
1719 {
1012 te->setScrollbarLocation(2); 1720 te->setScrollbarLocation(2);
1013 cfg.writeEntry("Position",2); 1721 cfg.writeEntry("Position",2);
1014 } 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: {
@@ -1028,5 +1740,4 @@ i=-24;j=-25;k=-26;
1028// } 1740// }
1029// break; 1741// break;
1030}
1031 1742
1032void Konsole::editCommandListMenuSelected(int iD) 1743void Konsole::editCommandListMenuSelected(int iD)
@@ -1034,37 +1745,54 @@ void Konsole::editCommandListMenuSelected(int iD)
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);
@@ -1074,9 +1802,10 @@ void Konsole::editCommandListMenuSelected(int iD)
1074 } 1802 }
1075 } 1803 }
1076 if(iD == -24) { 1804 if(iD == ec_edit)
1805 {
1077 // "edit commands" 1806 // "edit commands"
1078 CommandEditDialog *m = new CommandEditDialog(this); 1807 CommandEditDialog *m = new CommandEditDialog(this);
1079 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); 1808 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList()));
1080 QPEApplication::showDialog( m ); 1809 m->showMaximized();
1081 } 1810 }
1082 1811
@@ -1084,18 +1813,25 @@ void Konsole::editCommandListMenuSelected(int iD)
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 }
@@ -1104,11 +1840,18 @@ void Konsole::setDocument( const QString &cmd) {
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 }
@@ -1121,6 +1864,7 @@ void Konsole::parseCommandLine() {
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;
@@ -1142,8 +1886,9 @@ qDebug("do other dialog");
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;
@@ -1155,22 +1900,19 @@ void Konsole::changeBackgroundColor(const QColor &color) {
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 }
1912 else
1913 {
1172// te->setWrapAt(90); 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}