Diffstat (limited to 'core/apps/embeddedkonsole/konsole.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 322 |
1 files changed, 286 insertions, 36 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index 7253baf..1102ef3 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp | |||
@@ -41,6 +41,8 @@ | |||
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> | ||
45 | #include <qpalette.h> | ||
44 | 46 | ||
45 | #include <sys/wait.h> | 47 | #include <sys/wait.h> |
46 | #include <stdio.h> | 48 | #include <stdio.h> |
@@ -99,39 +101,34 @@ public: | |||
99 | // file of the user | 101 | // file of the user |
100 | static const char *commonCmds[] = | 102 | static const char *commonCmds[] = |
101 | { | 103 | { |
102 | "ls ", | 104 | "ls ", // I left this here, cause it looks better than the first alpha |
103 | //"ls -la ", | 105 | "cardctl eject", |
106 | "cat ", | ||
104 | "cd ", | 107 | "cd ", |
105 | "pwd", | 108 | "chmod ", |
106 | //"cat", | 109 | "cp ", |
107 | //"less ", | 110 | "dc ", |
108 | //"vi ", | 111 | "df ", |
109 | //"man ", | 112 | "dmesg", |
110 | "echo ", | 113 | "echo ", |
111 | "set ", | 114 | "find ", |
112 | //"ps", | 115 | "free", |
113 | "ps aux", | ||
114 | //"tar", | ||
115 | //"tar -zxf", | ||
116 | "grep ", | 116 | "grep ", |
117 | //"grep -i", | 117 | "ifconfig ", |
118 | //"mkdir", | 118 | "ipkg ", |
119 | "cp ", | 119 | "mkdir ", |
120 | "mv ", | 120 | "mv ", |
121 | "nc localhost 7776", | ||
122 | "nc localhost 7777", | ||
123 | "nslookup ", | ||
124 | "ping ", | ||
125 | "ps aux", | ||
126 | "pwd ", | ||
121 | "rm ", | 127 | "rm ", |
122 | "rmdir ", | 128 | "rmdir ", |
123 | //"chmod", | 129 | "route ", |
124 | //"su", | 130 | "set ", |
125 | // "top", | 131 | "traceroute", |
126 | //"find", | ||
127 | //"make", | ||
128 | //"tail", | ||
129 | "cardctl eject", | ||
130 | "ifconfig ", | ||
131 | // "iwconfig eth0 ", | ||
132 | "nc localhost 7777", | ||
133 | "nc localhost 7776", | ||
134 | //"mount /dev/hda1", | ||
135 | 132 | ||
136 | /* | 133 | /* |
137 | "gzip", | 134 | "gzip", |
@@ -186,7 +183,7 @@ void Konsole::init(const char* _pgm, QStrList & _args) | |||
186 | 183 | ||
187 | Config cfg("Konsole"); | 184 | Config cfg("Konsole"); |
188 | cfg.setGroup("Konsole"); | 185 | cfg.setGroup("Konsole"); |
189 | 186 | QString tmp; | |
190 | // initialize the list of allowed fonts /////////////////////////////////// | 187 | // initialize the list of allowed fonts /////////////////////////////////// |
191 | cfont = cfg.readNumEntry("FontID", 1); | 188 | cfont = cfg.readNumEntry("FontID", 1); |
192 | QFont f = QFont("Micro", 4, QFont::Normal); | 189 | QFont f = QFont("Micro", 4, QFont::Normal); |
@@ -203,8 +200,9 @@ void Konsole::init(const char* _pgm, QStrList & _args) | |||
203 | 200 | ||
204 | // create terminal emulation framework //////////////////////////////////// | 201 | // create terminal emulation framework //////////////////////////////////// |
205 | nsessions = 0; | 202 | nsessions = 0; |
203 | |||
206 | tab = new EKNumTabWidget(this); | 204 | tab = new EKNumTabWidget(this); |
207 | tab->setTabPosition(QTabWidget::Bottom); | 205 | |
208 | connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); | 206 | connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); |
209 | 207 | ||
210 | // create terminal toolbar //////////////////////////////////////////////// | 208 | // create terminal toolbar //////////////////////////////////////////////// |
@@ -221,9 +219,50 @@ void Konsole::init(const char* _pgm, QStrList & _args) | |||
221 | } | 219 | } |
222 | fontChanged(cfont); | 220 | fontChanged(cfont); |
223 | 221 | ||
222 | configMenu = new QPopupMenu( this); | ||
223 | colorMenu = new QPopupMenu( this); | ||
224 | |||
225 | bool listHidden; | ||
226 | cfg.setGroup("Menubar"); | ||
227 | if( cfg.readEntry("Hidden","FALSE") == "TRUE") { | ||
228 | configMenu->insertItem("Show command list"); | ||
229 | listHidden=TRUE; | ||
230 | } else { | ||
231 | configMenu->insertItem("Hide command list"); | ||
232 | listHidden=FALSE; | ||
233 | } | ||
234 | |||
235 | cfg.setGroup("Tabs"); | ||
236 | tmp=cfg.readEntry("Position","Bottom"); | ||
237 | if(tmp=="Top") { | ||
238 | tab->setTabPosition(QTabWidget::Top); | ||
239 | configMenu->insertItem("Tabs on Bottom"); | ||
240 | } else { | ||
241 | tab->setTabPosition(QTabWidget::Bottom); | ||
242 | configMenu->insertItem("Tabs on Top"); | ||
243 | } | ||
244 | configMenu->insertSeparator(2); | ||
245 | |||
246 | colorMenu->insertItem("Green on Black"); | ||
247 | colorMenu->insertItem("Black on White"); | ||
248 | colorMenu->insertItem("White on Black"); | ||
249 | colorMenu->insertItem("Black on Transparent"); | ||
250 | colorMenu->insertItem("Black on Red"); | ||
251 | colorMenu->insertItem("Red on Black"); | ||
252 | colorMenu->insertItem("Green on Yellow"); | ||
253 | colorMenu->insertItem("Blue on Magenta"); | ||
254 | colorMenu->insertItem("Magenta on Blue"); | ||
255 | colorMenu->insertItem("Cyan on White"); | ||
256 | colorMenu->insertItem("White on Cyan"); | ||
257 | colorMenu->insertItem("Blue on Black"); | ||
258 | configMenu->insertItem("Colors",colorMenu); | ||
259 | |||
224 | connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); | 260 | connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); |
261 | connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); | ||
262 | connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuSelected(int) )); | ||
225 | 263 | ||
226 | menuBar->insertItem( tr("Font"), fontList ); | 264 | menuBar->insertItem( tr("Font"), fontList ); |
265 | menuBar->insertItem( tr("Options"), configMenu ); | ||
227 | 266 | ||
228 | QPEToolBar *toolbar = new QPEToolBar( this ); | 267 | QPEToolBar *toolbar = new QPEToolBar( this ); |
229 | 268 | ||
@@ -251,13 +290,25 @@ void Konsole::init(const char* _pgm, QStrList & _args) | |||
251 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); | 290 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); |
252 | */ | 291 | */ |
253 | 292 | ||
254 | QPEToolBar *secondToolBar = new QPEToolBar( this ); | 293 | secondToolBar = new QPEToolBar( this ); |
255 | secondToolBar->setHorizontalStretchable( TRUE ); | 294 | secondToolBar->setHorizontalStretchable( TRUE ); |
256 | 295 | ||
257 | QComboBox *commonCombo = new QComboBox( secondToolBar ); | 296 | commonCombo = new QComboBox( secondToolBar ); |
258 | // commonCombo->setEditable( TRUE ); | 297 | |
259 | for (int i = 0; commonCmds[i] != NULL; i++) | 298 | if( listHidden) |
299 | secondToolBar->hide(); | ||
300 | configMenu->insertItem( "Edit Command List"); | ||
301 | |||
302 | cfg.setGroup("Commands"); | ||
303 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); | ||
304 | |||
305 | for (int i = 0; commonCmds[i] != NULL; i++) { | ||
260 | commonCombo->insertItem( commonCmds[i], i ); | 306 | commonCombo->insertItem( commonCmds[i], i ); |
307 | tmp = cfg.readEntry( QString::number(i),""); | ||
308 | if(tmp != "") | ||
309 | commonCombo->changeItem( tmp,i ); | ||
310 | } | ||
311 | |||
261 | connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); | 312 | connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); |
262 | 313 | ||
263 | // create applications ///////////////////////////////////////////////////// | 314 | // create applications ///////////////////////////////////////////////////// |
@@ -278,6 +329,7 @@ void Konsole::init(const char* _pgm, QStrList & _args) | |||
278 | QSize currentSize = size(); | 329 | QSize currentSize = size(); |
279 | if (currentSize != size()) | 330 | if (currentSize != size()) |
280 | defaultSize = size(); | 331 | defaultSize = size(); |
332 | |||
281 | } | 333 | } |
282 | 334 | ||
283 | void Konsole::show() | 335 | void Konsole::show() |
@@ -321,12 +373,17 @@ void Konsole::fontChanged(int f) | |||
321 | } | 373 | } |
322 | } | 374 | } |
323 | 375 | ||
376 | |||
324 | void Konsole::enterCommand(int c) | 377 | void Konsole::enterCommand(int c) |
325 | { | 378 | { |
326 | TEWidget* te = getTe(); | 379 | TEWidget* te = getTe(); |
327 | if (te != 0) { | 380 | if (te != 0) { |
328 | QString text = commonCmds[c]; | 381 | if(!commonCombo->editable()) { |
382 | QString text = commonCombo->text(c); //commonCmds[c]; | ||
329 | te->emitText(text); | 383 | te->emitText(text); |
384 | } else { | ||
385 | changeCommand( commonCombo->text(c), c); | ||
386 | } | ||
330 | } | 387 | } |
331 | } | 388 | } |
332 | 389 | ||
@@ -473,10 +530,10 @@ void Konsole::doneSession(TESession*, int ) | |||
473 | } | 530 | } |
474 | } | 531 | } |
475 | 532 | ||
476 | |||
477 | void Konsole::newSession() { | 533 | void Konsole::newSession() { |
534 | if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? | ||
478 | TEWidget* te = new TEWidget(tab); | 535 | TEWidget* te = new TEWidget(tab); |
479 | te->setBackgroundMode(PaletteBase); | 536 | // te->setBackgroundMode(PaletteBase); //we want transparent!! |
480 | te->setVTFont(fonts.at(cfont)->getFont()); | 537 | te->setVTFont(fonts.at(cfont)->getFont()); |
481 | tab->addTab(te); | 538 | tab->addTab(te); |
482 | TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); | 539 | TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); |
@@ -487,6 +544,8 @@ void Konsole::newSession() { | |||
487 | se->setHistory(b_scroll); | 544 | se->setHistory(b_scroll); |
488 | tab->setCurrentPage(nsessions); | 545 | tab->setCurrentPage(nsessions); |
489 | nsessions++; | 546 | nsessions++; |
547 | setColor(); | ||
548 | } | ||
490 | } | 549 | } |
491 | 550 | ||
492 | TEWidget* Konsole::getTe() { | 551 | TEWidget* Konsole::getTe() { |
@@ -510,3 +569,194 @@ void Konsole::switchSession(QWidget* w) { | |||
510 | } | 569 | } |
511 | } | 570 | } |
512 | } | 571 | } |
572 | |||
573 | /// ------------------------------- some new stuff by L.J. Potter | ||
574 | void Konsole::colorMenuSelected(int iD) | ||
575 | { // this is NOT pretty, elegant or anything else besides functional | ||
576 | // QString temp; | ||
577 | // temp.sprintf("%d", iD); | ||
578 | // qDebug(temp); | ||
579 | TEWidget* te = getTe(); | ||
580 | Config cfg("Konsole"); | ||
581 | cfg.setGroup("Colors"); | ||
582 | QColor foreground; | ||
583 | QColor background; | ||
584 | colorMenu->setItemChecked(lastSelectedMenu,FALSE); | ||
585 | ColorEntry m_table[TABLE_COLORS]; | ||
586 | const ColorEntry * defaultCt=te->getdefaultColorTable(); | ||
587 | /////////// fore back | ||
588 | int i; | ||
589 | if(iD==-8) { // default default | ||
590 | for (i = 0; i < TABLE_COLORS; i++) { | ||
591 | m_table[i].color = defaultCt[i].color; | ||
592 | if(i==1 || i == 11) | ||
593 | m_table[i].transparent=1; | ||
594 | cfg.writeEntry("Schema","8"); | ||
595 | colorMenu->setItemChecked(-8,TRUE); | ||
596 | } | ||
597 | } else { | ||
598 | if(iD==-5) { // green black | ||
599 | foreground.setRgb(0x18,255,0x18); | ||
600 | background.setRgb(0x00,0x00,0x00); | ||
601 | cfg.writeEntry("Schema","5"); | ||
602 | colorMenu->setItemChecked(-5,TRUE); | ||
603 | } | ||
604 | if(iD==-6) { // black white | ||
605 | foreground.setRgb(0x00,0x00,0x00); | ||
606 | background.setRgb(0xFF,0xFF,0xFF); | ||
607 | cfg.writeEntry("Schema","6"); | ||
608 | colorMenu->setItemChecked(-6,TRUE); | ||
609 | } | ||
610 | if(iD==-7) { // white black | ||
611 | foreground.setRgb(0xFF,0xFF,0xFF); | ||
612 | background.setRgb(0x00,0x00,0x00); | ||
613 | cfg.writeEntry("Schema","7"); | ||
614 | colorMenu->setItemChecked(-7,TRUE); | ||
615 | } | ||
616 | if(iD==-9) {// Black, Red | ||
617 | foreground.setRgb(0x00,0x00,0x00); | ||
618 | background.setRgb(0xB2,0x18,0x18); | ||
619 | cfg.writeEntry("Schema","9"); | ||
620 | colorMenu->setItemChecked(-9,TRUE); | ||
621 | } | ||
622 | if(iD==-10) {// Red, Black | ||
623 | foreground.setRgb(230,31,31); //0xB2,0x18,0x18 | ||
624 | background.setRgb(0x00,0x00,0x00); | ||
625 | cfg.writeEntry("Schema","10"); | ||
626 | colorMenu->setItemChecked(-10,TRUE); | ||
627 | } | ||
628 | if(iD==-11) {// Green, Yellow - is ugly | ||
629 | // foreground.setRgb(0x18,0xB2,0x18); | ||
630 | foreground.setRgb(36,139,10); | ||
631 | // background.setRgb(0xB2,0x68,0x18); | ||
632 | background.setRgb(255,255,0); | ||
633 | cfg.writeEntry("Schema","11"); | ||
634 | colorMenu->setItemChecked(-11,TRUE); | ||
635 | } | ||
636 | if(iD==-12) {// Blue, Magenta | ||
637 | foreground.setRgb(0x18,0xB2,0xB2); | ||
638 | background.setRgb(0x18,0x18,0xB2); | ||
639 | cfg.writeEntry("Schema","12"); | ||
640 | colorMenu->setItemChecked(-12,TRUE); | ||
641 | } | ||
642 | if(iD==-13) {// Magenta, Blue | ||
643 | foreground.setRgb(0x18,0x18,0xB2); | ||
644 | background.setRgb(0x18,0xB2,0xB2); | ||
645 | cfg.writeEntry("Schema","13"); | ||
646 | colorMenu->setItemChecked(-13,TRUE); | ||
647 | } | ||
648 | if(iD==-14) {// Cyan, White | ||
649 | foreground.setRgb(0x18,0xB2,0xB2); | ||
650 | background.setRgb(0xFF,0xFF,0xFF); | ||
651 | cfg.writeEntry("Schema","14"); | ||
652 | colorMenu->setItemChecked(-14,TRUE); | ||
653 | } | ||
654 | if(iD==-15) {// White, Cyan | ||
655 | background.setRgb(0x18,0xB2,0xB2); | ||
656 | foreground.setRgb(0xFF,0xFF,0xFF); | ||
657 | cfg.writeEntry("Schema","15"); | ||
658 | colorMenu->setItemChecked(-15,TRUE); | ||
659 | } | ||
660 | if(iD==-16) {// Black, Blue | ||
661 | background.setRgb(0x00,0x00,0x00); | ||
662 | foreground.setRgb(0x18,0xB2,0xB2); | ||
663 | cfg.writeEntry("Schema","16"); | ||
664 | colorMenu->setItemChecked(-16,TRUE); | ||
665 | } | ||
666 | |||
667 | for (i = 0; i < TABLE_COLORS; i++) { | ||
668 | if(i==0 || i == 10) { | ||
669 | m_table[i].color = foreground; | ||
670 | } | ||
671 | else if(i==1 || i == 11) { | ||
672 | m_table[i].color = background; m_table[i].transparent=0; | ||
673 | } | ||
674 | else | ||
675 | m_table[i].color = defaultCt[i].color; | ||
676 | } | ||
677 | } | ||
678 | lastSelectedMenu = iD; | ||
679 | te->setColorTable(m_table); | ||
680 | // update(); | ||
681 | } | ||
682 | |||
683 | void Konsole::configMenuSelected(int iD) | ||
684 | { | ||
685 | // QString temp; | ||
686 | // temp.sprintf("%d",iD); | ||
687 | // qDebug(temp); | ||
688 | TEWidget* te = getTe(); | ||
689 | Config cfg("Konsole"); | ||
690 | cfg.setGroup("Menubar"); | ||
691 | if( iD == -2) { | ||
692 | if(!secondToolBar->isHidden()) { | ||
693 | secondToolBar->hide(); | ||
694 | configMenu->changeItem( iD,"Show Command List"); | ||
695 | cfg.writeEntry("Hidden","TRUE"); | ||
696 | configMenu->setItemEnabled(-20 ,FALSE); | ||
697 | } else { | ||
698 | secondToolBar->show(); | ||
699 | configMenu->changeItem( iD,"Hide Command List"); | ||
700 | cfg.writeEntry("Hidden","FALSE"); | ||
701 | configMenu->setItemEnabled(-20 ,TRUE); | ||
702 | |||
703 | if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { | ||
704 | configMenu->setItemChecked(-16,TRUE); | ||
705 | commonCombo->setEditable( TRUE ); | ||
706 | } else { | ||
707 | configMenu->setItemChecked(-20,FALSE); | ||
708 | commonCombo->setEditable( FALSE ); | ||
709 | } | ||
710 | } | ||
711 | } | ||
712 | if( iD == -3) { | ||
713 | cfg.setGroup("Tabs"); | ||
714 | QString tmp=cfg.readEntry("Position","Top"); | ||
715 | |||
716 | if(tmp=="Top") { | ||
717 | tab->setTabPosition(QTabWidget::Bottom); | ||
718 | configMenu->changeItem( iD,"Tabs on Top"); | ||
719 | cfg.writeEntry("Position","Bottom"); | ||
720 | } else { | ||
721 | tab->setTabPosition(QTabWidget::Top); | ||
722 | configMenu->changeItem( iD,"Tabs on Bottom"); | ||
723 | cfg.writeEntry("Position","Top"); | ||
724 | } | ||
725 | } | ||
726 | if( iD == -20) { | ||
727 | cfg.setGroup("Commands"); | ||
728 | // qDebug("enableCommandEdit"); | ||
729 | if( !configMenu->isItemChecked(iD) ) { | ||
730 | commonCombo->setEditable( TRUE ); | ||
731 | configMenu->setItemChecked(iD,TRUE); | ||
732 | commonCombo->setCurrentItem(0); | ||
733 | cfg.writeEntry("EditEnabled","TRUE"); | ||
734 | } else { | ||
735 | commonCombo->setEditable( FALSE ); | ||
736 | configMenu->setItemChecked(iD,FALSE); | ||
737 | cfg.writeEntry("EditEnabled","FALSE"); | ||
738 | commonCombo->setFocusPolicy(QWidget::NoFocus); | ||
739 | te->setFocus(); | ||
740 | } | ||
741 | } | ||
742 | } | ||
743 | |||
744 | void Konsole::changeCommand(const QString &text, int c) | ||
745 | { | ||
746 | Config cfg("Konsole"); | ||
747 | cfg.setGroup("Commands"); | ||
748 | if(commonCmds[c] != text) { | ||
749 | cfg.writeEntry(QString::number(c),text); | ||
750 | commonCombo->clearEdit(); | ||
751 | commonCombo->setCurrentItem(c); | ||
752 | } | ||
753 | } | ||
754 | |||
755 | void Konsole::setColor() | ||
756 | { | ||
757 | Config cfg("Konsole"); | ||
758 | cfg.setGroup("Colors"); | ||
759 | int scheme = cfg.readNumEntry("Schema",1); | ||
760 | if(scheme != 1) colorMenuSelected( -scheme); | ||
761 | |||
762 | } | ||