Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

konsole.cpp

Go to the documentation of this file.
00001 
00002 /* ---------------------------------------------------------------------- */
00003 /*                                                                        */
00004 /* [main.C]                        Konsole                                */
00005 /*                                                                        */
00006 /* ---------------------------------------------------------------------- */
00007 /*                                                                        */
00008 /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>        */
00009 /*                                                                        */
00010 /* This file is part of Konsole, an X terminal.                           */
00011 /*                                                                        */
00012 /* The material contained in here more or less directly orginates from    */
00013 /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
00014 /*                                                                        */
00015 /* ---------------------------------------------------------------------- */
00016 /*                        */
00017 /* Ported Konsole to Qt/Embedded                                              */
00018 /*                        */
00019 /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com>                  */
00020 /*                        */
00021 /* -------------------------------------------------------------------------- */
00022 // enhancements added by L.J. Potter <ljp@llornkcor.com>
00023 // enhancements added by Phillip Kuhn
00024 
00025 #include <stdlib.h>
00026 #include <sys/types.h>
00027 #include <pwd.h>
00028 #include <unistd.h>
00029 
00030 #ifdef  QT_QWS_OPIE
00031 #include <opie2/ocolorpopupmenu.h>
00032 #include <opie2/odebug.h>
00033 #include <opie2/oresource.h>
00034 
00035 using namespace Opie;
00036 #endif
00037 
00038 #include <qmenubar.h>
00039 #include <qtabbar.h>
00040 #include <qpe/config.h>
00041 #include <qfontdatabase.h>
00042 #include <qfile.h>
00043 #include <qspinbox.h>
00044 #include <qlayout.h>
00045 
00046 #include <sys/wait.h>
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <assert.h>
00050 
00051 #include "konsole.h"
00052 #include "commandeditdialog.h"
00053 
00054 class EKNumTabBar : public QTabBar
00055 {
00056 public:
00057     EKNumTabBar(QWidget *parent = 0, const char *name = 0) :
00058             QTabBar(parent, name)
00059     {}
00060 
00061     //  QList<QTab> *getTabList() { return(tabList()); }
00062 
00063     void numberTabs()
00064     {
00065         // Yes, it really is this messy. QTabWidget needs functions
00066         // that provide acces to tabs in a sequential way.
00067         int m=INT_MIN;
00068         for (int i=0; i<count(); i++)
00069         {
00070             QTab* left=0;
00071             QListIterator<QTab> it(*tabList());
00072             int x=INT_MAX;
00073             for( QTab* t; (t=it.current()); ++it )
00074             {
00075                 int tx = t->rect().x();
00076                 if ( tx<x && tx>m )
00077                 {
00078                     x = tx;
00079                     left = t;
00080                 }
00081             }
00082             if ( left )
00083             {
00084                 left->setText(QString::number(i+1));
00085                 m = left->rect().x();
00086             }
00087         }
00088     }
00089 
00090     virtual QSize sizeHint() const
00091     {
00092         if (isHidden())
00093         {
00094             return(QSize(0,0));
00095         }
00096         else
00097         {
00098             QSize size = QTabBar::sizeHint();
00099             int shrink = 5;
00100             if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600)
00101             {
00102                 shrink = 10;
00103             }
00104             size.setHeight(size.height() - shrink);
00105             return(size);
00106         }
00107     }
00108 
00109 };
00110 
00111 class EKNumTabWidget : public QTabWidget
00112 {
00113 public:
00114     EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
00115     {
00116         setTabBar(new EKNumTabBar(parent,"EKTabBar"));
00117         setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
00118     }
00119 
00120     EKNumTabBar *getTabBar() const
00121     {
00122         return ((EKNumTabBar*)tabBar());
00123     }
00124 
00125 
00126     void addTab(QWidget* w)
00127     {
00128         QTab* t = new QTab(QString::number(tabBar()->count()+1));
00129         QTabWidget::addTab(w,t);
00130     }
00131 
00132     void removeTab(QWidget* w)
00133     {
00134         removePage(w);
00135         ((EKNumTabBar*)tabBar())->numberTabs();
00136     }
00137 };
00138 
00139 // This could be configurable or dynamicly generated from the bash history
00140 // file of the user
00141 static const char *commonCmds[] =
00142     {
00143         "ls ", // I left this here, cause it looks better than the first alpha
00144         "cardctl eject",
00145         "cat ",
00146         "cd ",
00147         "chmod ",
00148         "clear",
00149         "cp ",
00150         "dc ",
00151         "df ",
00152         "dmesg",
00153         "echo ",
00154         "env",
00155         "find ",
00156         "free",
00157         "grep ",
00158         "ifconfig ",
00159         "ipkg ",
00160         "mkdir ",
00161         "mv ",
00162         "nc localhost 7776",
00163         "nc localhost 7777",
00164         "netstat ",
00165         "nslookup ",
00166         "ping ",
00167         "ps aux",
00168         "pwd ",
00169 //        "qcop QPE/System 'linkChanged(QString)' ''",
00170 //        "qcop QPE/System 'restart()'",
00171 //        "qcop QPE/System 'quit()'",
00172         "rm ",
00173         "rmdir ",
00174         "route ",
00175         "set ",
00176         "traceroute",
00177 
00178         /*
00179             "gzip",
00180             "gunzip",
00181             "chgrp",
00182             "chown",
00183             "date",
00184             "dd",
00185             "df",
00186             "dmesg",
00187             "fuser",
00188             "hostname",
00189             "kill",
00190             "killall",
00191             "ln",
00192             "ping",
00193             "mount",
00194             "more",
00195             "sort",
00196             "touch",
00197             "umount",
00198             "mknod",
00199             "netstat",
00200         */
00201 
00202         "exit",
00203         NULL
00204     };
00205 
00206 
00207 static void konsoleInit(const char** shell) {
00208     if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl;
00209     if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl;  // drop privileges
00210 
00211 
00212 //  QPEApplication::grabKeyboard(); // for CTRL and ALT
00213 
00214     odebug << "keyboard grabbed" << oendl;
00215 #ifdef FAKE_CTRL_AND_ALT
00216     odebug << "Fake Ctrl and Alt defined" << oendl;
00217     QPEApplication::grabKeyboard(); // for CTRL and ALT
00218 #endif
00219 
00220     *shell = getenv("SHELL");
00221     owarn << "SHell initially is " << *shell << "" << oendl;
00222 
00223     if (shell == NULL || *shell == '\0') {
00224         struct passwd *ent = 0;
00225         uid_t me = getuid();
00226         *shell = "/bin/sh";
00227 
00228         while ( (ent = getpwent()) != 0 ) {
00229             if (ent->pw_uid == me) {
00230                 if (ent->pw_shell != "")
00231                     *shell = ent->pw_shell;
00232                 break;
00233             }
00234         }
00235         endpwent();
00236     }
00237 
00238     if( putenv((char*)"COLORTERM=") !=0)
00239         odebug << "putenv failed" << oendl;  // to trigger mc's color detection
00240 }
00241 
00242 
00243 Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
00244         QMainWindow(parent, name, fl)
00245 {
00246     QStrList tmp; const char* shell;
00247 
00248     konsoleInit( &shell);
00249     init(shell,tmp);
00250 }
00251 
00252 Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
00253         : QMainWindow(0, name)
00254 {
00255     init(_pgm,_args);
00256 }
00257 
00258 struct HistoryItem
00259 {
00260     HistoryItem(int c, const QString &l)
00261     {
00262         count = c;
00263         line = l;
00264     }
00265     int count;
00266     QString line;
00267 };
00268 
00269 class HistoryList : public QList<HistoryItem>
00270 {
00271     virtual int compareItems( QCollection::Item item1, QCollection::Item item2)
00272     {
00273         int c1 = ((HistoryItem*)item1)->count;
00274         int c2 = ((HistoryItem*)item2)->count;
00275         if (c1 > c2)
00276             return(1);
00277         if (c1 < c2)
00278             return(-1);
00279         return(0);
00280     }
00281 };
00282 
00283 void Konsole::initCommandList()
00284 {
00285     //    odebug << "Konsole::initCommandList" << oendl;
00286     Config cfg( "Konsole" );
00287     cfg.setGroup("Commands");
00288     //    commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
00289     commonCombo->clear();
00290 
00291     if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") {
00292         QString histfilename = QString(getenv("HOME")) + "/.bash_history";
00293         histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
00294         QFile histfile(histfilename);
00295         // note: compiler barfed on:
00296         // QFile histfile(QString(getenv("HOME")) + "/.bash_history");
00297         if (histfile.open( IO_ReadOnly ))  {
00298             QString line;
00299             uint i;
00300             HistoryList items;
00301 
00302             int lineno = 0;
00303             while(!histfile.atEnd()) {
00304                 if (histfile.readLine(line, 200) < 0) {
00305                     break;
00306                 }
00307                 line = line.left(line.length()-1);
00308                 lineno++;
00309 
00310                 for(i=0; i<items.count(); i++) {
00311                     if (line == items.at(i)->line) {
00312                         // weight recent commands & repeated commands more
00313                         // by adding up the index of each command
00314                         items.at(i)->count += lineno;
00315                         break;
00316                     }
00317                 }
00318                 if (i >= items.count()) {
00319                     items.append(new HistoryItem(lineno, line));
00320                 }
00321             }
00322             items.sort();
00323             int n = items.count();
00324             if (n > 40) {
00325                 n = 40;
00326             }
00327             for(int i=0; i<n; i++) {
00328                 // should insert start of command, but keep whole thing
00329                 if (items.at(items.count()-i-1)->line.length() < 30) {
00330                     commonCombo->insertItem(items.at(items.count()-i-1)->line);
00331                 }
00332             }
00333             histfile.close();
00334         }
00335     }
00336     if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
00337         for (int i = 0; commonCmds[i] != NULL; i++) {
00338             commonCombo->insertItem(commonCmds[i]);
00339         }
00340     } else {
00341         for (int i = 0; i < 100; i++) {
00342             if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
00343                 commonCombo->insertItem(cfg.readEntry( QString::number(i),""));
00344         }
00345     }
00346 
00347 
00348 }
00349 
00350 static void sig_handler(int x)
00351 {
00352     printf("got signal %d\n",x);
00353 }
00354 
00355 void Konsole::init(const char* _pgm, QStrList & _args)
00356 {
00357 
00358 #if 0
00359     for(int i=1; i<=31; i++)
00360     {
00361         if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV
00362                 && i != SIGINT && i != SIGILL && i != SIGTERM
00363                 && i != SIGBUS)
00364             signal(i,sig_handler);
00365     }
00366 #endif
00367     signal(SIGSTOP, sig_handler);
00368     signal(SIGCONT, sig_handler);
00369     signal(SIGTSTP, sig_handler);
00370 
00371     b_scroll = TRUE; // histon;
00372     n_keytab = 0;
00373     n_render = 0;
00374     startUp=0;
00375     fromMenu = FALSE;
00376     fullscreen = false;
00377 
00378     setCaption( tr( "Konsole" ) );
00379     setIcon( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ) );
00380 
00381     Config cfg( "Konsole" );
00382     cfg.setGroup("Font");
00383     QString tmp;
00384 
00385     // initialize the list of allowed fonts ///////////////////////////////////
00386 
00387     QString cfgFontName = cfg.readEntry("FontName","Lcfont");
00388     int cfgFontSize = cfg.readNumEntry("FontSize",18);
00389 
00390     cfont = -1;
00391 
00392     // this code causes repeated access to all the font files
00393     // which does slow down startup
00394     QFontDatabase fontDB;
00395     QStringList familyNames;
00396     familyNames = fontDB.families( FALSE );
00397     QString s;
00398     int fontIndex = 0;
00399     int familyNum = 0;
00400     fontList = new QPopupMenu( this );
00401 
00402     for(uint j = 0; j < (uint)familyNames.count(); j++)
00403     {
00404         s = familyNames[j];
00405         if ( s.contains('-') )
00406         {
00407             int i = s.find('-');
00408             s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]";
00409         }
00410         s[0] = s[0].upper();
00411 
00412         QValueList<int> sizes = fontDB.pointSizes( familyNames[j] );
00413 
00414         printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(),
00415                sizes.count());
00416 
00417         if (sizes.count() > 0)
00418         {
00419             QPopupMenu *sizeMenu;
00420             QFont f;
00421             int last_width = -1;
00422             sizeMenu = NULL;
00423 
00424             for(uint i = 0; i < (uint)sizes.count() + 4; i++)
00425             {
00426                 //    printf("family %s size %d  ", familyNames[j].latin1(), sizes[i]);
00427                 // need to divide by 10 on the Z, but not otherwise
00428                 int size;
00429 
00430                 if (i >= (uint)sizes.count())
00431                 {
00432                     // try for expandable fonts
00433                     size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1);
00434                 }
00435                 else
00436                 {
00437                     printf("sizes[%d] = %d\n", i, sizes[i]);
00438                     size = sizes[i];
00439                 }
00440 
00441                 f = QFont(familyNames[j], size);
00442                 f.setFixedPitch(true);
00443                 QFontMetrics fm(f);
00444                 // don't trust f.fixedPitch() or f.exactMatch(), they lie!!
00445                 if (fm.width("l") == fm.width("m")
00446                         && (i < (uint)sizes.count()
00447                             || fm.width("m") > last_width))
00448                 {
00449                     if (i < (uint)sizes.count())
00450                     {
00451                         last_width = fm.width("m");
00452                     }
00453                     if (sizeMenu == NULL)
00454                     {
00455                         sizeMenu = new QPopupMenu();
00456                     }
00457                     int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex);
00458                     sizeMenu->setItemParameter(id, fontIndex);
00459                     sizeMenu->connectItem(id, this, SLOT(setFont(int)));
00460                     QString name = s + " " + QString::number(size);
00461                     fonts.append(new VTFont(name, f, familyNames[j], familyNum, size));
00462                     if (familyNames[j] == cfgFontName && size == cfgFontSize)
00463                     {
00464                         cfont = fontIndex;
00465                     }
00466                     printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size);
00467                     fontIndex++;
00468                 }
00469             }
00470             if (sizeMenu)
00471             {
00472                 fontList->insertItem(s, sizeMenu, familyNum + 1000);
00473 
00474                 familyNum++;
00475             }
00476         }
00477 
00478     }
00479 
00480     if (cfont < 0 || cfont >= (int)fonts.count())
00481     {
00482         cfont = 0;
00483     }
00484 
00485     // create terminal emulation framework ////////////////////////////////////
00486     nsessions = 0;
00487 
00488     tab = new EKNumTabWidget(this);
00489     //  tab->setMargin(tab->margin()-5);
00490     connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
00491 
00492     // create terminal toolbar ////////////////////////////////////////////////
00493     setToolBarsMovable( FALSE );
00494     menuToolBar = new QToolBar( this );
00495     menuToolBar->setHorizontalStretchable( TRUE );
00496 
00497     QMenuBar *menuBar = new QMenuBar( menuToolBar );
00498 
00499     setFont(cfont);
00500 
00501     configMenu = new QPopupMenu( this);
00502     colorMenu = new QPopupMenu( this);
00503    scrollMenu = new QPopupMenu( this);
00504     editCommandListMenu = new QPopupMenu( this);
00505 
00506     configMenu->insertItem(tr("Command List"), editCommandListMenu);
00507 
00508     bool listHidden;
00509     cfg.setGroup("Menubar");
00510     if( cfg.readEntry("Hidden","FALSE") == "TRUE")
00511     {
00512         ec_cmdlist = editCommandListMenu->insertItem( tr( "Show command list" ));
00513         listHidden=TRUE;
00514     }
00515     else
00516     {
00517         ec_cmdlist = editCommandListMenu->insertItem( tr( "Hide command list" ));
00518         listHidden=FALSE;
00519     }
00520 
00521     cfg.setGroup("Tabs");
00522 
00523     tabMenu = new QPopupMenu(this);
00524     tm_bottom = tabMenu->insertItem(tr("Bottom" ));
00525     tm_top = tabMenu->insertItem(tr("Top"));
00526     tm_hidden = tabMenu->insertItem(tr("Hidden"));
00527 
00528     configMenu->insertItem(tr("Tabs"), tabMenu);
00529 
00530     tmp=cfg.readEntry("Position","Top");
00531     if(tmp=="Top")
00532     {
00533         tab->setTabPosition(QTabWidget::Top);
00534         tab->getTabBar()->show();
00535         tabPos = tm_top;
00536     }
00537     else if (tmp=="Bottom")
00538     {
00539         tab->setTabPosition(QTabWidget::Bottom);
00540         tab->getTabBar()->show();
00541         tabPos = tm_bottom;
00542     }
00543     else
00544     {
00545         tab->getTabBar()->hide();
00546         tab->setMargin(tab->margin());
00547         tabPos = tm_hidden;
00548     }
00549 
00550     cm_bw = colorMenu->insertItem(tr( "Black on White"));
00551     cm_wb = colorMenu->insertItem(tr( "White on Black"));
00552     cm_gb = colorMenu->insertItem(tr( "Green on Black"));
00553     //  cm_bt = colorMenu->insertItem(tr( "Black on Transparent"));
00554     cm_br = colorMenu->insertItem(tr( "Black on Pink"));
00555     cm_rb = colorMenu->insertItem(tr( "Pink on Black"));
00556     cm_gy = colorMenu->insertItem(tr( "Green on Yellow"));
00557     cm_bm = colorMenu->insertItem(tr( "Blue on Magenta"));
00558     cm_mb = colorMenu->insertItem(tr( "Magenta on Blue"));
00559     cm_cw = colorMenu->insertItem(tr( "Cyan on White"));
00560     cm_wc = colorMenu->insertItem(tr( "White on Cyan"));
00561     cm_bb = colorMenu->insertItem(tr( "Blue on Black"));
00562     cm_ab = colorMenu->insertItem(tr( "Amber on Black"));
00563     cm_default = colorMenu->insertItem(tr("default"));
00564 
00565 #ifdef QT_QWS_OPIE
00566 
00567     colorMenu->insertItem(tr( "Custom"));
00568 #endif
00569 
00570     configMenu->insertItem(tr( "Colors") ,colorMenu);
00571 
00572     sessionList = new QPopupMenu(this);
00573     sessionList-> insertItem ( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ),
00574                                tr( "new session" ), this, SLOT(newSession()) );
00575 
00576     //  connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
00577     connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
00578     connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) ));
00579     connect( tabMenu, SIGNAL( activated(int) ), this, SLOT( tabMenuSelected(int) ));
00580     connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int)));
00581     connect( editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int)));
00582     connect( sessionList, SIGNAL(activated(int)), this, SLOT( sessionListSelected(int) ) );
00583 
00584     menuBar->insertItem( tr("View"), configMenu );
00585     menuBar->insertItem( tr("Fonts"), fontList );
00586     menuBar->insertItem( tr("Sessions"), sessionList );
00587 
00588     toolBar = new QToolBar( this );
00589 
00590     QAction *a;
00591 
00592     // Button Commands
00593     a = new QAction( tr("New"), Opie::Core::OResource::loadPixmap( "konsole/konsole", Opie::Core::OResource::SmallIcon ),
00594                      QString::null, 0, this, 0 );
00595     connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) );
00596     a->addTo( toolBar );
00597 
00598     a = new QAction( tr("Full Screen"), Opie::Core::OResource::loadPixmap( "fullscreen", Opie::Core::OResource::SmallIcon ),
00599                      QString::null, 0, this, 0 );
00600     connect( a, SIGNAL( activated() ), this, SLOT( toggleFullScreen() ) );
00601     a->addTo( toolBar );
00602 
00603     a = new QAction( tr("Zoom"), Opie::Core::OResource::loadPixmap( "zoom", Opie::Core::OResource::SmallIcon ),
00604                      QString::null, 0, this, 0 );
00605     connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) );
00606     a->addTo( toolBar );
00607 
00608 
00609     a = new QAction( tr("Enter"), Opie::Core::OResource::loadPixmap( "konsole/enter", Opie::Core::OResource::SmallIcon ),
00610                      QString::null, 0, this, 0 );
00611     connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolBar );
00612     a = new QAction( tr("Space"), Opie::Core::OResource::loadPixmap( "konsole/space", Opie::Core::OResource::SmallIcon ),
00613                      QString::null, 0, this, 0 );
00614     connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolBar );
00615     a = new QAction( tr("Tab"), Opie::Core::OResource::loadPixmap( "konsole/tab", Opie::Core::OResource::SmallIcon ),
00616                      QString::null, 0, this, 0 );
00617     connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolBar );
00618     a = new QAction( tr("Up"), Opie::Core::OResource::loadPixmap( "konsole/up", Opie::Core::OResource::SmallIcon ),
00619                      QString::null, 0, this, 0 );
00620     connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolBar );
00621     a = new QAction( tr("Down"), Opie::Core::OResource::loadPixmap( "konsole/down", Opie::Core::OResource::SmallIcon ),
00622                      QString::null, 0, this, 0 );
00623     connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolBar );
00624 
00625     a = new QAction( tr("Paste"), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00626     connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) );
00627 
00628     a = new QAction( tr("Close"), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),QString::null, 0, this, 0 );
00629     connect( a, SIGNAL( activated() ), this, SLOT( closeSession() ) );
00630 
00631     a->addTo( toolBar );
00632 
00633     secondToolBar = new QToolBar( this );
00634     secondToolBar->setHorizontalStretchable( TRUE );
00635 
00636     commonCombo = new QComboBox( secondToolBar );
00637     //  commonCombo->setMaximumWidth(236);
00638 
00639     ec_quick = editCommandListMenu->insertItem( tr( "Quick Edit" ) );
00640     if( listHidden)
00641     {
00642         secondToolBar->hide();
00643         editCommandListMenu->setItemEnabled(ec_quick ,FALSE);
00644     }
00645     ec_edit = editCommandListMenu->insertItem(tr(  "Edit..." ) );
00646 
00647     cfg.setGroup("Commands");
00648     commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
00649 
00650     initCommandList();
00651     //   for (int i = 0; commonCmds[i] != NULL; i++) {
00652     //        commonCombo->insertItem( commonCmds[i], i );
00653     //        tmp = cfg.readEntry( QString::number(i),"");
00654     //        if(tmp != "")
00655     //            commonCombo->changeItem( tmp,i );
00656     //    }
00657 
00658     connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
00659 
00660     sm_none = scrollMenu->insertItem(tr( "None" ));
00661     sm_left = scrollMenu->insertItem(tr( "Left" ));
00662     sm_right = scrollMenu->insertItem(tr( "Right" ));
00663     //   scrollMenu->insertSeparator(4);
00664     //   scrollMenu->insertItem(tr( "Horizontal" ));
00665 
00666     configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
00667 
00668     configMenu->insertItem(tr( "History..." ), this, SLOT(historyDialog()));
00669 
00670     cm_wrap = configMenu->insertItem(tr( "Wrap" ));
00671     cfg.setGroup("ScrollBar");
00672     configMenu->setItemChecked(cm_wrap, cfg.readBoolEntry("HorzScroll",0));
00673 
00674     cm_beep = configMenu->insertItem(tr( "Use Beep" ));
00675     cfg.setGroup("Menubar");
00676     configMenu->setItemChecked(cm_beep, cfg.readBoolEntry("useBeep",0));
00677 
00678     fullscreen_msg = new QLabel(this);
00679     fullscreen_msg-> setAlignment ( AlignCenter | SingleLine );
00680     fullscreen_msg-> hide();
00681     fullscreen_msg-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ));
00682     fullscreen_msg-> setAutoResize(true);
00683     fullscreen_msg-> setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
00684     fullscreen_msg-> setText(tr("To exit fullscreen, tap here."));
00685 
00686     fullscreen_timer = new QTimer(this);
00687     connect(fullscreen_timer, SIGNAL(timeout()),
00688             this, SLOT(fullscreenTimeout()));
00689     show_fullscreen_msg = true;
00690 
00691     //scrollMenuSelected(-29);
00692     //   cfg.setGroup("ScrollBar");
00693     //   if(cfg.readBoolEntry("HorzScroll",0)) {
00694     //       if(cfg.readNumEntry("Position",2) == 0)
00695     //           te->setScrollbarLocation(1);
00696     //       else
00697     //           te->setScrollbarLocation(0);
00698     //       te->setScrollbarLocation( cfg.readNumEntry("Position",2));
00699     //       te->setWrapAt(120);
00700     //   }
00701     // create applications /////////////////////////////////////////////////////
00702     setCentralWidget(tab);
00703 
00704     // load keymaps ////////////////////////////////////////////////////////////
00705     KeyTrans::loadAll();
00706     for (int i = 0; i < KeyTrans::count(); i++)
00707     {
00708         KeyTrans* s = KeyTrans::find(i);
00709         assert( s );
00710     }
00711 
00712     se_pgm = _pgm;
00713     se_args = _args;
00714 
00715     cfg.setGroup("CommandLine");
00716 
00717     if (cfg.hasKey("shell_args"))
00718     {
00719         QStringList se_args_list = cfg.readListEntry("shell_args",'|');
00720         for(uint i = 0; i < se_args_list.count(); i++)
00721         {
00722             se_args.prepend(se_args_list[se_args_list.count() - i - 1].latin1());
00723         }
00724     }
00725     else
00726     {
00727         se_args.prepend("--login");
00728     }
00729 
00730     se_pgm = cfg.readEntry("shell_bin", QString(se_pgm));
00731 
00732     // this is the "documentation" for those who know to look
00733     if (! cfg.hasKey("shell_args"))
00734     {
00735         cfg.writeEntry("shell_args",QStringList::fromStrList(se_args),'|');
00736     }
00737     if (! cfg.hasKey("shell_bin"))
00738     {
00739         cfg.writeEntry("shell_bin",QString(se_pgm));
00740     }
00741 
00742     parseCommandLine();
00743 
00744     // read and apply default values ///////////////////////////////////////////
00745     resize(321, 321); // Dummy.
00746     QSize currentSize = size();
00747     if (currentSize != size())
00748         defaultSize = size();
00749 
00750 
00751     /* allows us to catch cancel/escape */
00752     reparent ( 0, WStyle_Customize | WStyle_NoBorder,
00753                QPoint ( 0, 0 ));
00754 }
00755 
00756 void Konsole::show()
00757 {
00758     if ( !nsessions )
00759     {
00760         newSession();
00761     }
00762     QMainWindow::show();
00763 
00764 }
00765 
00766 void Konsole::initSession(const char*, QStrList &)
00767 {
00768     QMainWindow::show();
00769 }
00770 
00771 Konsole::~Konsole()
00772 {
00773     while (nsessions > 0)
00774     {
00775         doneSession(getTe(), 0);
00776     }
00777 }
00778 
00779 void
00780 Konsole::historyDialog()
00781 {
00782     QDialog *d = new QDialog ( this, "histdlg", true );
00783     //    d-> setCaption ( tr( "History" ));
00784 
00785     QBoxLayout *lay = new QVBoxLayout ( d, 4, 4  );
00786 
00787     QLabel *l = new QLabel ( tr( "History Lines:" ), d );
00788     lay-> addWidget ( l );
00789 
00790     Config cfg( "Konsole" );
00791     cfg.setGroup("History");
00792     int hist = cfg.readNumEntry("history_lines",300);
00793     int avg_line = cfg.readNumEntry("avg_line_length",60);
00794 
00795     QSpinBox *spin = new QSpinBox ( 1, 100000, 20, d );
00796     spin-> setValue ( hist );
00797     spin-> setWrapping ( true );
00798     spin-> setButtonSymbols ( QSpinBox::PlusMinus );
00799     lay-> addWidget ( spin );
00800 
00801     if ( d-> exec ( ) == QDialog::Accepted )
00802     {
00803         cfg.writeEntry("history_lines", spin->value());
00804         cfg.writeEntry("avg_line_length", avg_line);
00805         if (getTe() != NULL)
00806         {
00807             getTe()->currentSession->setHistory(true);
00808         }
00809     }
00810 
00811     delete d;
00812 }
00813 
00814 
00815 void Konsole::cycleZoom()
00816 {
00817     TEWidget* te = getTe();
00818     QFont font = te->getVTFont();
00819     int size = font.pointSize();
00820     changeFontSize(1);
00821     font = te->getVTFont();
00822     if (font.pointSize() <= size)
00823     {
00824         do
00825         {
00826             font = te->getVTFont();
00827             size = font.pointSize();
00828             changeFontSize(-1);
00829             font = te->getVTFont();
00830         }
00831         while (font.pointSize() < size);
00832     }
00833 }
00834 
00835 void Konsole::changeFontSize(int delta)
00836 {
00837     //  printf("delta font size %d\n", delta);
00838     TEWidget* te = getTe();
00839     QFont font = te->getVTFont();
00840     int size = font.pointSize();
00841     int closest = delta > 0? 10000 : -10000;
00842     int closest_font = -1;
00843     for(uint i = 0; i < fonts.count(); i++)
00844     {
00845         if (fonts.at(i)->getFont() == font)
00846         {
00847             if (delta > 0)
00848             {
00849                 if (i+1 < fonts.count()
00850                         && fonts.at(i+1)->getFamilyNum() == fonts.at(i)->getFamilyNum())
00851                 {
00852                     setFont(i+1);
00853                     printf("font %d\n", i+1);
00854                     return;
00855                 }
00856             }
00857             else if (delta < 0)
00858             {
00859                 if (i > 0
00860                         && fonts.at(i-1)->getFamilyNum() == fonts.at(i)->getFamilyNum())
00861                 {
00862                     setFont(i-1);
00863                     printf("font %d\n", i-1);
00864                     return;
00865                 }
00866             }
00867         }
00868         int fsize = fonts.at(i)->getSize();
00869         printf("%d size=%d fsize=%d closest=%d\n", i, size, fsize, closest);
00870         if ((delta > 0 && fsize > size && fsize < closest)
00871                 || (delta < 0 && fsize < size && fsize > closest))
00872         {
00873             closest = fsize;
00874             closest_font = i;
00875         }
00876     }
00877     if (closest_font >= 0)
00878     {
00879         printf("font closest %d (%d)\n", closest_font, closest);
00880         setFont(closest_font);
00881     }
00882 }
00883 
00884 int Konsole::findFont(const QString& name, int size, bool exactMatch)
00885 {
00886     for(uint i = 0; i < fonts.count(); i++)
00887     {
00888         if (fonts.at(i)->getName() == name
00889                 && fonts.at(i)->getSize() == size)
00890         {
00891             return(i);
00892         }
00893     }
00894     if (exactMatch)
00895     {
00896         return(-1);
00897     }
00898     for(uint i = 0; i < fonts.count(); i++)
00899     {
00900         if (fonts.at(i)->getSize() == size)
00901         {
00902             return(i);
00903         }
00904     }
00905     return(-1);
00906 }
00907 
00908 void Konsole::setFont(int f)
00909 {
00910     VTFont* font = fonts.at(f);
00911     if (font)
00912     {
00913         TEWidget* te = getTe();
00914         if (te != 0)
00915         {
00916             te->setVTFont(font->getFont());
00917         }
00918         cfont = f;
00919 
00920         int familyNum = font->getFamilyNum();
00921         int size = font->getSize();
00922         printf("familyNum = %d  size = %d  count=%d\n", familyNum, size,
00923                fontList->count());
00924         for(int i = 0; i < (int)fontList->count(); i++)
00925         {
00926             fontList->setItemChecked(i + 1000, i == familyNum);
00927         }
00928         for(int i = 0; i < (int)fonts.count(); i++)
00929         {
00930             fontList->setItemChecked(i, fonts.at(i)->getFamilyNum() == familyNum
00931                                      && fonts.at(i)->getSize() == size);
00932         }
00933         Config cfg( "Konsole" );
00934         cfg.setGroup("Font");
00935         QString ss = "Session"+ QString::number(tab->currentPageIndex()+1);
00936         if (tab->currentPageIndex() == 0)
00937         {
00938             cfg.writeEntry("FontName", fonts.at(cfont)->getFamily());
00939             cfg.writeEntry("FontSize", fonts.at(cfont)->getSize());
00940         }
00941         cfg.writeEntry("FontName"+ss, fonts.at(cfont)->getFamily());
00942         cfg.writeEntry("FontSize"+ss, fonts.at(cfont)->getSize());
00943     }
00944 }
00945 
00946 #if 0
00947 void Konsole::fontChanged(int f)
00948 {
00949     VTFont* font = fonts.at(f);
00950     if (font != 0)
00951     {
00952         for(uint i = 0; i < fonts.count(); i++)
00953         {
00954             fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
00955         }
00956 
00957         cfont = f;
00958 
00959         TEWidget* te = getTe();
00960         if (te != 0)
00961         {
00962             te->setVTFont(font->getFont());
00963         }
00964     }
00965 }
00966 #endif
00967 
00968 
00969 void Konsole::enterCommand(int c)
00970 {
00971     TEWidget* te = getTe();
00972     if (te != 0)
00973     {
00974         if(!commonCombo->editable())
00975         {
00976             QString text = commonCombo->text(c); //commonCmds[c];
00977             te->emitText(text);
00978         }
00979         else
00980         {
00981             changeCommand( commonCombo->text(c), c);
00982         }
00983     }
00984 }
00985 
00986 void Konsole::hitEnter()
00987 {
00988     TEWidget* te = getTe();
00989     if (te != 0)
00990     {
00991         te->emitText(QString("\r"));
00992     }
00993 }
00994 
00995 void Konsole::hitSpace()
00996 {
00997     TEWidget* te = getTe();
00998     if (te != 0)
00999     {
01000         te->emitText(QString(" "));
01001     }
01002 }
01003 
01004 void Konsole::hitTab()
01005 {
01006     TEWidget* te = getTe();
01007     if (te != 0)
01008     {
01009         te->emitText(QString("\t"));
01010     }
01011 }
01012 
01013 void Konsole::hitPaste()
01014 {
01015     TEWidget* te = getTe();
01016     if (te != 0)
01017     {
01018         te->pasteClipboard();
01019     }
01020 }
01021 
01022 void Konsole::hitUp()
01023 {
01024     TEWidget* te = getTe();
01025     if (te != 0)
01026     {
01027         QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
01028         QApplication::sendEvent( te, &ke );
01029     }
01030 }
01031 
01032 void Konsole::hitDown()
01033 {
01034     TEWidget* te = getTe();
01035     if (te != 0)
01036     {
01037         QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
01038         QApplication::sendEvent( te, &ke );
01039     }
01040 }
01041 
01046 QSize Konsole::calcSize(int columns, int lines)
01047 {
01048     TEWidget* te = getTe();
01049     if (te != 0)
01050     {
01051         QSize size = te->calcSize(columns, lines);
01052         return size;
01053     }
01054     else
01055     {
01056         QSize size;
01057         return size;
01058     }
01059 }
01060 
01066 void Konsole::setColLin(int columns, int lines)
01067 {
01068     odebug << "konsole::setColLin:: Columns " << columns << "" << oendl;
01069 
01070     if ((columns==0) || (lines==0))
01071     {
01072         if (defaultSize.isEmpty()) // not in config file : set default value
01073         {
01074             defaultSize = calcSize(80,24);
01075             // notifySize(24,80); // set menu items (strange arg order !)
01076         }
01077         resize(defaultSize);
01078     }
01079     else
01080     {
01081         resize(calcSize(columns, lines));
01082         // notifySize(lines,columns); // set menu items (strange arg order !)
01083     }
01084 }
01085 
01086 /*
01087 void Konsole::setFont(int fontno)
01088 {
01089   QFont f;
01090   if (fontno == 0)
01091     f = defaultFont = QFont( "Helvetica", 12  );
01092   else
01093   if (fonts[fontno][0] == '-')
01094     f.setRawName( fonts[fontno] );
01095   else
01096   {
01097     f.setFamily(fonts[fontno]);
01098     f.setRawMode( TRUE );
01099   }
01100   if ( !f.exactMatch() && fontno != 0)
01101   {
01102     QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
01103     QMessageBox(this,  msg);
01104     return;
01105   }
01106   if (se) se->setFontNo(fontno);
01107   te->setVTFont(f);
01108   n_font = fontno;
01109 }
01110 */
01111 
01112 // --| color selection |-------------------------------------------------------
01113 
01114 void Konsole::changeColumns(int /*columns*/)
01115 { //FIXME this seems to cause silliness when reset command is executed
01116     //     odebug << "change columns" << oendl;
01117     //   TEWidget* te = getTe();
01118     //   if (te != 0) {
01119     //   setColLin(columns,te->Lines());
01120     //   te->update();
01121     //   }
01122 }
01123 
01124 //FIXME: If a child dies during session swap,
01125 //       this routine might be called before
01126 //       session swap is completed.
01127 
01128 void Konsole::doneSession(TEWidget* te, int )
01129 {
01130     //  TEWidget *te = NULL;
01131     //  if (sess->currentSession == tab->currentPage()) {
01132     //    printf("done current session\n");
01133     //    te = getTe();
01134     //  } else {
01135     //    int currentPage = tab->currentPageIndex();
01136     //    printf("done not current session\n");
01137     //    for(int i = 0; i < nsessions; i++) {
01138     //      tab->setCurrentPage(i);
01139     //      printf("find session %d tab page %x session %x\n",
01140     //         i, tab->currentPage(), sess->currentSession);
01141     //      if (tab->currentPage() == sess->currentSession) {
01142     //    printf("found session %d\n", i);
01143     //    te = tab->currentPage();
01144     //    break;
01145     //      }
01146     //    }
01147     //    tab->setCurrentPage(currentPage);
01148     //  }
01149     if (te != 0)
01150     {
01151         te->currentSession->setConnect(FALSE);
01152         tab->removeTab(te);
01153         delete te->currentSession;
01154         delete te;
01155         sessionList->removeItem(nsessions);
01156         nsessions--;
01157     }
01158     if (nsessions == 0)
01159     {
01160         close();
01161     }
01162 }
01163 
01164 void Konsole::changeTitle(TEWidget* te, const QString& newTitle )
01165 {
01166     if (te == getTe())
01167     {
01168         setCaption( newTitle + " - " + tr( "Konsole " ) );
01169     }
01170 }
01171 
01172 
01173 void Konsole::newSession()
01174 {
01175     if(nsessions < 15)
01176     {    // seems to be something weird about 16 tabs on the Zaurus.... memory?
01177         TEWidget* te = new TEWidget(tab);
01178         Config cfg( "Konsole" );
01179         cfg.setGroup("Menubar");
01180 
01181         // FIXME use more defaults from config file
01182         te->useBeep=cfg.readBoolEntry("useBeep",0);
01183 
01184         //  te->setBackgroundMode(PaletteBase); //we want transparent!!
01185 
01186         cfg.setGroup("Font");
01187         QString sn = "Session" + QString::number(nsessions+1);
01188         printf("read font session %s\n", sn.latin1());
01189         QString fontName = cfg.readEntry("FontName"+sn,
01190                                          cfg.readEntry("FontName",
01191                                                        fonts.at(cfont)->getFamily()));
01192         int fontSize = cfg.readNumEntry("FontSize"+sn,
01193                                         cfg.readNumEntry("FontSize",
01194                                                          fonts.at(cfont)->getSize()));
01195         cfont = findFont(fontName, fontSize, false);
01196         printf("lookup font %s size %d got %d\n", fontName.latin1(), fontSize, cfont);
01197         if (cfont < 0)
01198             cfont = 0;
01199         te->setVTFont(fonts.at(cfont)->getFont());
01200 
01201         tab->addTab(te);
01202         TESession* se = new TESession(this, te, se_pgm, se_args, "xterm");
01203         te->currentSession = se;
01204         connect( se, SIGNAL(done(TEWidget*,int)), this, SLOT(doneSession(TEWidget*,int)) );
01205         connect( se, SIGNAL(changeTitle(TEWidget*,const QString&)), this,
01206                  SLOT(changeTitle(TEWidget*,const QString&)) );
01207         connect(te, SIGNAL(changeFontSize(int)), this, SLOT(changeFontSize(int)));
01208         connect(te, SIGNAL(changeSession(int)), this, SLOT(changeSession(int)));
01209         connect(te, SIGNAL(newSession()), this, SLOT(newSession()));
01210         connect(te, SIGNAL(toggleFullScreen()), this, SLOT(toggleFullScreen()));
01211         connect(te, SIGNAL(setFullScreen(bool)), this, SLOT(setFullScreen(bool)));
01212         se->run();
01213         se->setConnect(TRUE);
01214         se->setHistory(b_scroll);
01215         nsessions++;
01216         sessionList->insertItem(QString::number(nsessions), nsessions);
01217         sessionListSelected(nsessions);
01218         doWrap();
01219         setColor(nsessions-1);
01220     }
01221 }
01222 
01223 TEWidget* Konsole::getTe()
01224 {
01225     if (nsessions)
01226     {
01227         return (TEWidget *) tab->currentPage();
01228     }
01229     else
01230     {
01231         return 0;
01232     }
01233 }
01234 
01235 void Konsole::sessionListSelected(int id)
01236 {
01237     if (id < 0)
01238     {
01239         return;
01240     }
01241     QString selected = sessionList->text(id);
01242     EKNumTabBar *tabBar = tab->getTabBar();
01243 
01244     int n = 0;
01245     for(int i = 0; n < tabBar->count(); i++)
01246     {
01247         if (tabBar->tab(i))
01248         {
01249             //      printf("selected = %s  tab %d = %s\n", selected.latin1(),
01250             //         i, tabBar->tab(i)->text().latin1());
01251             if (tabBar->tab(i)->text() == selected)
01252             {
01253                 tab->setCurrentPage(i);
01254                 break;
01255             }
01256             n++;
01257         }
01258     }
01259 }
01260 
01261 
01262 void Konsole::changeSession(int delta)
01263 {
01264     printf("delta session %d\n", delta);
01265     QTabBar *tabBar = tab->getTabBar();
01266     int i = tabBar->tab(tabBar->currentTab())->text().toInt() - 1;
01267     i += delta;
01268     if (i < 0)
01269         i += tabBar->count();
01270     if (i >= tabBar->count())
01271         i -= tabBar->count();
01272 
01273     QString selected = QString::number(i+1);
01274     int n = 0;
01275     for(int i = 0; n < tabBar->count(); i++)
01276     {
01277         if (tabBar->tab(i))
01278         {
01279             printf("selected = %s  tab %d = %s\n", selected.latin1(),
01280                    i, tabBar->tab(i)->text().latin1());
01281             if (tabBar->tab(i)->text() == selected)
01282             {
01283                 tab->setCurrentPage(i);
01284                 break;
01285             }
01286             n++;
01287         }
01288     }
01289 }
01290 
01291 void Konsole::switchSession(QWidget* w)
01292 {
01293     TEWidget* te = (TEWidget *) w;
01294     QFont teFnt = te->getVTFont();
01295     int familyNum = -1;
01296 
01297     for(uint i = 0; i < fonts.count(); i++)
01298     {
01299         VTFont *fnt = fonts.at(i);
01300         bool cf = fnt->getFont() == teFnt;
01301         fontList->setItemChecked(i, cf);
01302         if (cf)
01303         {
01304             cfont = i;
01305             familyNum = fnt->getFamilyNum();
01306         }
01307     }
01308     for(int i = 0; i < (int)fontList->count(); i++)
01309     {
01310         fontList->setItemChecked(i + 1000, i == familyNum);
01311     }
01312     if (! te->currentSession->Title().isEmpty() )
01313     {
01314         setCaption( te->currentSession->Title() + " - " + tr( "Konsole" ) );
01315     }
01316     else
01317     {
01318         setCaption( tr( "Konsole" ) );
01319     }
01320     //  colorMenuSelected(te->color_menu_item);
01321 }
01322 
01323 
01324 void Konsole::toggleFullScreen()
01325 {
01326     setFullScreen(! fullscreen);
01327 }
01328 
01329 void Konsole::setFullScreen ( bool b )
01330 {
01331     static QSize normalsize;
01332     static bool listHidden;
01333 
01334     if (b == fullscreen)
01335     {
01336         return;
01337     }
01338 
01339     fullscreen = b;
01340 
01341     if ( b )
01342     {
01343         if ( !normalsize. isValid ( ))
01344         {
01345             normalsize = size ( );
01346         }
01347 
01348         setFixedSize ( qApp-> desktop ( )-> size ( ));
01349         showNormal ( );
01350         reparent ( 0, WStyle_Customize | WStyle_NoBorder,
01351                    QPoint ( 0, 0 ));
01352         showFullScreen ( );
01353 
01354         menuToolBar->hide();
01355         toolBar->hide();
01356         listHidden = secondToolBar->isHidden();
01357         secondToolBar->hide();
01358         //    commonCombo->hide();
01359         tab->getTabBar()->hide();
01360         tab->setMargin(tab->margin());
01361 
01362         if (show_fullscreen_msg)
01363         {
01364             fullscreen_msg-> move(tab->x() + tab->width()/2 - fullscreen_msg->width()/2,
01365                                   qApp->desktop()->height()/16 - fullscreen_msg->height()/2);
01366             fullscreen_msg->show();
01367             fullscreen_timer->start(3000, true);
01368             show_fullscreen_msg = false;
01369         }
01370     }
01371     else
01372     {
01373         showNormal ( );
01374         reparent ( 0, WStyle_Customize, QPoint ( 0, 0 ));
01375         resize ( normalsize );
01376         showMaximized ( );
01377         normalsize = QSize ( );
01378 
01379         menuToolBar->show();
01380         toolBar->show();
01381         if(! listHidden)
01382         {
01383             secondToolBar->show();
01384         }
01385         //    commonCombo->show();
01386         menuToolBar->show();
01387         if (tabPos != tm_hidden)
01388         {
01389             tab->getTabBar()->show();
01390         }
01391     }
01392     tab->setMargin(tab->margin());  // cause setup to run
01393 }
01394 
01395 
01396 void Konsole::fullscreenTimeout()
01397 {
01398     fullscreen_msg->hide();
01399 }
01400 
01401 void Konsole::colorMenuIsSelected(int iD)
01402 {
01403     fromMenu = TRUE;
01404     colorMenuSelected(iD);
01405 }
01406 
01408 
01409 
01410 void Konsole::colorMenuSelected(int iD)
01411 {
01412     // this is NOT pretty, elegant or anything else besides functional
01413     //       QString temp;
01414     //      odebug << temp.sprintf("colormenu " << iD) << "" << oendl;
01415 
01416     TEWidget* te = getTe();
01417     Config cfg( "Konsole" );
01418     cfg.setGroup("Colors");
01419 
01420     ColorEntry m_table[TABLE_COLORS];
01421     const ColorEntry * defaultCt=te->getdefaultColorTable();
01422 
01423     int i;
01424 
01425     //    te->color_menu_item = iD;
01426 
01427     colorMenu->setItemChecked(cm_ab,FALSE);
01428     colorMenu->setItemChecked(cm_bb,FALSE);
01429     colorMenu->setItemChecked(cm_wc,FALSE);
01430     colorMenu->setItemChecked(cm_cw,FALSE);
01431     colorMenu->setItemChecked(cm_mb,FALSE);
01432     colorMenu->setItemChecked(cm_bm,FALSE);
01433     colorMenu->setItemChecked(cm_gy,FALSE);
01434     colorMenu->setItemChecked(cm_rb,FALSE);
01435     colorMenu->setItemChecked(cm_br,FALSE);
01436     colorMenu->setItemChecked(cm_wb,FALSE);
01437     colorMenu->setItemChecked(cm_bw,FALSE);
01438     colorMenu->setItemChecked(cm_gb,FALSE);
01439 
01440     if(iD==cm_default)
01441     { // default default
01442         printf("default colors\n");
01443         for (i = 0; i < TABLE_COLORS; i++)
01444         {
01445             m_table[i].color = defaultCt[i].color;
01446             if(i==1 || i == 11)
01447                 m_table[i].transparent=1;
01448             colorMenu->setItemChecked(cm_default,TRUE);
01449         }
01450         te->setColorTable(m_table);
01451     }
01452     if(iD==cm_gb)
01453     { // green black
01454         foreground.setRgb(100,255,100); // (0x18,255,0x18);
01455         background.setRgb(0x00,0x00,0x00);
01456         colorMenu->setItemChecked(cm_gb,TRUE);
01457     }
01458     if(iD==cm_bw)
01459     { // black white
01460         foreground.setRgb(0x00,0x00,0x00);
01461         background.setRgb(0xFF,0xFF,0xFF);
01462         colorMenu->setItemChecked(cm_bw,TRUE);
01463     }
01464     if(iD==cm_wb)
01465     { // white black
01466         foreground.setRgb(0xFF,0xFF,0xFF);
01467         background.setRgb(0x00,0x00,0x00);
01468         colorMenu->setItemChecked(cm_wb,TRUE);
01469     }
01470     if(iD==cm_br)
01471     {// Black, Red
01472         foreground.setRgb(0x00,0x00,0x00);
01473         background.setRgb(255,85,85); //(0xB2,0x18,0x18);
01474         colorMenu->setItemChecked(cm_br,TRUE);
01475     }
01476     if(iD==cm_rb)
01477     {// Red, Black
01478         foreground.setRgb(255,85,85);
01479         background.setRgb(0x00,0x00,0x00);
01480         colorMenu->setItemChecked(cm_rb,TRUE);
01481     }
01482     if(iD==cm_gy)
01483     {// Green, Yellow - is ugly
01484         //            foreground.setRgb(0x18,0xB2,0x18);
01485         foreground.setRgb(15,115,0);
01486         //            background.setRgb(0xB2,0x68,0x18);
01487         background.setRgb(255,255,0);
01488         colorMenu->setItemChecked(cm_gy,TRUE);
01489     }
01490     if(iD==cm_bm)
01491     {// Blue,  Magenta
01492         foreground.setRgb(3,24,132);
01493         background.setRgb(225,2,255);
01494         colorMenu->setItemChecked(cm_bm,TRUE);
01495     }
01496     if(iD==cm_mb)
01497     {// Magenta, Blue
01498         foreground.setRgb(225,2,255);
01499         background.setRgb(3,24,132);
01500         colorMenu->setItemChecked(cm_mb,TRUE);
01501     }
01502     if(iD==cm_cw)
01503     {// Cyan,  White
01504         foreground.setRgb(8,91,129);
01505         background.setRgb(0xFF,0xFF,0xFF);
01506         colorMenu->setItemChecked(cm_cw,TRUE);
01507     }
01508     if(iD==cm_wc)
01509     {// White, Cyan
01510         background.setRgb(8,91,129);
01511         foreground.setRgb(0xFF,0xFF,0xFF);
01512         colorMenu->setItemChecked(cm_wc,TRUE);
01513     }
01514     if(iD==cm_bb)
01515     {// Black, Blue
01516         background.setRgb(0x00,0x00,0x00);
01517         foreground.setRgb(127,147,225);
01518         colorMenu->setItemChecked(cm_bb,TRUE);
01519     }
01520     if(iD==cm_ab)
01521     {// Black, Gold
01522         background.setRgb(0x00,0x00,0x00);
01523         foreground.setRgb(255,215,105);
01524         colorMenu->setItemChecked(cm_ab,TRUE);
01525     }
01526 #ifdef QT_QWS_OPIE
01527     if(iD==-19)
01528     {
01529         // Custom
01530         odebug << "do custom" << oendl;
01531         if(fromMenu)
01532         {
01533             Opie::OColorPopupMenu* penColorPopupMenu = new Opie::OColorPopupMenu(Qt::black, this, "foreground color");
01534             connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this,
01535                     SLOT(changeForegroundColor(const QColor&)));
01536             penColorPopupMenu->exec();
01537         }
01538         if(!fromMenu)
01539         {
01540             foreground.setNamedColor(cfg.readEntry("foreground",""));
01541             background.setNamedColor(cfg.readEntry("background",""));
01542         }
01543         fromMenu=FALSE;
01544         colorMenu->setItemChecked(-19,TRUE);
01545     }
01546 #endif
01547 
01548     lastSelectedMenu = iD;
01549 
01550     setColors(foreground, background);
01551 
01552     QTabBar *tabBar = tab->getTabBar();
01553     QString ss = QString("Session%1").arg(tabBar->currentTab());
01554     //    printf("current tab = %d\n", tabBar->currentTab());
01555 
01556     if (tabBar->currentTab() == 0)
01557     {
01558         cfg.writeEntry("foregroundRed",QString::number(foreground.red()));
01559         cfg.writeEntry("foregroundGreen",QString::number(foreground.green()));
01560         cfg.writeEntry("foregroundBlue",QString::number(foreground.blue()));
01561         cfg.writeEntry("backgroundRed",QString::number(background.red()));
01562         cfg.writeEntry("backgroundGreen",QString::number(background.green()));
01563         cfg.writeEntry("backgroundBlue",QString::number(background.blue()));
01564     }
01565     cfg.writeEntry("foregroundRed"+ss,QString::number(foreground.red()));
01566     cfg.writeEntry("foregroundGreen"+ss,QString::number(foreground.green()));
01567     cfg.writeEntry("foregroundBlue"+ss,QString::number(foreground.blue()));
01568     cfg.writeEntry("backgroundRed"+ss,QString::number(background.red()));
01569     cfg.writeEntry("backgroundGreen"+ss,QString::number(background.green()));
01570     cfg.writeEntry("backgroundBlue"+ss,QString::number(background.blue()));
01571 
01572     update();
01573 }
01574 
01575 void Konsole::setColors(QColor foreground, QColor background)
01576 {
01577     int i;
01578     ColorEntry m_table[TABLE_COLORS];
01579     TEWidget* te = getTe();
01580     const ColorEntry * defaultCt=te->getdefaultColorTable();
01581 
01582     for (i = 0; i < TABLE_COLORS; i++)
01583     {
01584         if(i==0 || i == 10)
01585         {
01586             m_table[i].color = foreground;
01587         }
01588         else if(i==1 || i == 11)
01589         {
01590             m_table[i].color = background;
01591             m_table[i].transparent=0;
01592         }
01593         else
01594             m_table[i].color = defaultCt[i].color;
01595     }
01596     te->setColorTable(m_table);
01597 }
01598 
01599 void Konsole::tabMenuSelected(int id)
01600 {
01601     Config cfg( "Konsole" );
01602     cfg.setGroup("Tabs");
01603     tabMenu->setItemChecked(tabPos, false);
01604     if (id == tm_bottom)
01605     {
01606         printf("set bottom tab\n");
01607         tab->getTabBar()->show();
01608         tab->setTabPosition(QTabWidget::Bottom);
01609         tab->getTabBar()->show();
01610         cfg.writeEntry("Position","Bottom");
01611     }
01612     else if (id == tm_top)
01613     {
01614         printf("set top tab\n");
01615         tab->getTabBar()->show();
01616         tab->setTabPosition(QTabWidget::Bottom);
01617         tab->setTabPosition(QTabWidget::Top);
01618         tab->getTabBar()->show();
01619         cfg.writeEntry("Position","Top");
01620     }
01621     else if (id == tm_hidden)
01622     {
01623         tab->getTabBar()->hide();
01624         tab->setMargin(tab->margin());
01625         cfg.writeEntry("Position","Hidden");
01626     }
01627     tabMenu->setItemChecked(id, true);
01628     tabPos = id;
01629 }
01630 
01631 
01632 void Konsole::configMenuSelected(int iD)
01633 {
01634     //      QString temp;
01635     //      odebug << temp.sprintf("configmenu " << iD) << "" << oendl;
01636 
01637     TEWidget* te = getTe();
01638     Config cfg( "Konsole" );
01639     cfg.setGroup("Menubar");
01640     if(iD == cm_wrap)
01641     {
01642         cfg.setGroup("ScrollBar");
01643         bool b=cfg.readBoolEntry("HorzScroll",0);
01644         b=!b;
01645         cfg.writeEntry("HorzScroll", b );
01646         cfg.write();
01647         doWrap();
01648         if(cfg.readNumEntry("Position",2) == 0)
01649         {
01650             te->setScrollbarLocation(1);
01651         }
01652         else
01653         {
01654             te->setScrollbarLocation(0);
01655         }
01656         te->setScrollbarLocation( cfg.readNumEntry("Position",2));
01657     }
01658     if(iD ==  cm_beep)
01659     {
01660         cfg.setGroup("Menubar");
01661         bool b=cfg.readBoolEntry("useBeep",0);
01662         b=!b;
01663         cfg.writeEntry("useBeep", b );
01664         cfg.write();
01665         configMenu->setItemChecked(cm_beep,b);
01666         te->useBeep=b;
01667     }
01668 }
01669 
01670 void Konsole::changeCommand(const QString &text, int c)
01671 {
01672     Config cfg( "Konsole" );
01673     cfg.setGroup("Commands");
01674     if(commonCmds[c] != text)
01675     {
01676         cfg.writeEntry(QString::number(c),text);
01677         commonCombo->clearEdit();
01678         commonCombo->setCurrentItem(c);
01679     }
01680 }
01681 
01682 void Konsole::setColor(int sess)
01683 {
01684     Config cfg( "Konsole" );
01685     cfg.setGroup("Colors");
01686     QColor foreground, background;
01687     QString ss = QString("Session") + QString::number(sess);
01688     foreground.setRgb(cfg.readNumEntry("foregroundRed"+ss,
01689                                        cfg.readNumEntry("foregroundRed",0xff)),
01690                       cfg.readNumEntry("foregroundGreen"+ss,
01691                                        cfg.readNumEntry("foregroundGreen",0xff)),
01692                       cfg.readNumEntry("foregroundBlue"+ss,
01693                                        cfg.readNumEntry("foregroundBlue",0xff)));
01694     background.setRgb(cfg.readNumEntry("backgroundRed"+ss,
01695                                        cfg.readNumEntry("backgroundRed",0)),
01696                       cfg.readNumEntry("backgroundGreen"+ss,
01697                                        cfg.readNumEntry("backgroundGreen",0)),
01698                       cfg.readNumEntry("backgroundBlue"+ss,
01699                                        cfg.readNumEntry("backgroundBlue",0)));
01700     setColors(foreground, background);
01701 }
01702 
01703 void Konsole::scrollMenuSelected(int index)
01704 {
01705     //    odebug << "scrollbar menu " << index << "" << oendl;
01706 
01707     TEWidget* te = getTe();
01708     Config cfg( "Konsole" );
01709     cfg.setGroup("ScrollBar");
01710 
01711     if(index == sm_none)
01712     {
01713         te->setScrollbarLocation(0);
01714         cfg.writeEntry("Position",0);
01715     }
01716     else if(index == sm_left)
01717     {
01718         te->setScrollbarLocation(1);
01719         cfg.writeEntry("Position",1);
01720     }
01721     else if(index == sm_right)
01722     {
01723         te->setScrollbarLocation(2);
01724         cfg.writeEntry("Position",2);
01725     }
01726     scrollMenu->setItemChecked(sm_none, index == sm_none);
01727     scrollMenu->setItemChecked(sm_left, index == sm_left);
01728     scrollMenu->setItemChecked(sm_right, index == sm_right);
01729 }
01730 
01731 //       case -29: {
01732 //           bool b=cfg.readBoolEntry("HorzScroll",0);
01733 //           cfg.writeEntry("HorzScroll", !b );
01734 //           cfg.write();
01735 //           if(cfg.readNumEntry("Position",2) == 0) {
01736 //               te->setScrollbarLocation(1);
01737 //           te->setWrapAt(0);
01738 //           } else {
01739 //               te->setScrollbarLocation(0);
01740 //           te->setWrapAt(120);
01741 //           }
01742 //           te->setScrollbarLocation( cfg.readNumEntry("Position",2));
01743 //       }
01744 //         break;
01745 
01746 void Konsole::editCommandListMenuSelected(int iD)
01747 {
01748     //      QString temp;
01749     //      odebug << temp.sprintf("edit command list " << iD) << "" << oendl;
01750 
01751     // FIXME: more cleanup needed here
01752 
01753 
01754     TEWidget* te = getTe();
01755     Config cfg( "Konsole" );
01756     cfg.setGroup("Menubar");
01757     if( iD  == ec_cmdlist)
01758     {
01759         if(!secondToolBar->isHidden())
01760         {
01761             secondToolBar->hide();
01762             configMenu->changeItem( iD,tr( "Show Command List" ));
01763             cfg.writeEntry("Hidden","TRUE");
01764             configMenu->setItemEnabled(ec_edit ,FALSE);
01765             configMenu->setItemEnabled(ec_quick ,FALSE);
01766         }
01767         else
01768         {
01769             secondToolBar->show();
01770             configMenu->changeItem( iD,tr( "Hide Command List" ));
01771             cfg.writeEntry("Hidden","FALSE");
01772             configMenu->setItemEnabled(ec_edit ,TRUE);
01773             configMenu->setItemEnabled(ec_quick ,TRUE);
01774 
01775             if(cfg.readEntry("EditEnabled","FALSE")=="TRUE")
01776             {
01777                 configMenu->setItemChecked(ec_edit,TRUE);
01778                 commonCombo->setEditable( TRUE );
01779             }
01780             else
01781             {
01782                 configMenu->setItemChecked(ec_edit,FALSE);
01783                 commonCombo->setEditable( FALSE );
01784             }
01785         }
01786     }
01787     if( iD  == ec_quick)
01788     {
01789         cfg.setGroup("Commands");
01790         //        odebug << "enableCommandEdit" << oendl;
01791         if( !configMenu->isItemChecked(iD) )
01792         {
01793             commonCombo->setEditable( TRUE );
01794             configMenu->setItemChecked(iD,TRUE);
01795             commonCombo->setCurrentItem(0);
01796             cfg.writeEntry("EditEnabled","TRUE");
01797         }
01798         else
01799         {
01800             commonCombo->setEditable( FALSE );
01801             configMenu->setItemChecked(iD,FALSE);
01802             cfg.writeEntry("EditEnabled","FALSE");
01803             commonCombo->setFocusPolicy(QWidget::NoFocus);
01804             te->setFocus();
01805         }
01806     }
01807     if(iD == ec_edit)
01808     {
01809         // "edit commands"
01810         CommandEditDialog *m = new CommandEditDialog(this);
01811         connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList()));
01812         m->showMaximized();
01813     }
01814 
01815 }
01816 
01817 // $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V'
01818 void Konsole::setDocument( const QString &cmd)
01819 {
01820     newSession();
01821     TEWidget* te = getTe();
01822     if(cmd.find("-e", 0, TRUE) != -1)
01823     {
01824         QString cmd2;
01825         cmd2=cmd.right(cmd.length()-3)+" &";
01826         system(cmd2.latin1());
01827         if(startUp <= 1 && nsessions < 2)
01828         {
01829             doneSession(getTe(), 0);
01830             exit(0);
01831         }
01832         else
01833             doneSession(getTe(), 0);
01834     }
01835     else
01836     {
01837         if (te != 0)
01838         {
01839             te->emitText(cmd+"\r");
01840         }
01841     }
01842     startUp++;
01843 }
01844 
01845 
01846 // what is the point of this when you can just
01847 // run commands by using the shell directly??
01848 void Konsole::parseCommandLine()
01849 {
01850     QString cmd;
01851     //    newSession();
01852     for (int i=1;i< qApp->argc();i++)
01853     {
01854         if( QString(qApp->argv()[i]) == "-e")
01855         {
01856             i++;
01857             for ( int j=i;j< qApp->argc();j++)
01858             {
01859                 cmd+=QString(qApp->argv()[j])+" ";
01860             }
01861             cmd.stripWhiteSpace();
01862             system(cmd.latin1());
01863             exit(0);//close();
01864         } // end -e switch
01865     }
01866     startUp++;
01867 }
01868 
01869 void Konsole::changeForegroundColor(const QColor &color)
01870 {
01871     Config cfg( "Konsole" );
01872     cfg.setGroup("Colors");
01873     int r, g, b;
01874     color.rgb(&r,&g,&b);
01875     foreground.setRgb(r,g,b);
01876 
01877     cfg.writeEntry("foreground",color.name());
01878     odebug << "foreground "+color.name() << oendl;
01879     cfg.write();
01880 
01881     odebug << "do other dialog" << oendl;
01882 #ifdef QT_QWS_OPIE
01883 
01884     Opie::OColorPopupMenu* penColorPopupMenu2 = new Opie::OColorPopupMenu(Qt::black, this,"background color");
01885     connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this,
01886             SLOT(changeBackgroundColor(const QColor&)));
01887     penColorPopupMenu2->exec();
01888 #endif
01889 }
01890 
01891 void Konsole::changeBackgroundColor(const QColor &color)
01892 {
01893 
01894     odebug << "Change background" << oendl;
01895     Config cfg( "Konsole" );
01896     cfg.setGroup("Colors");
01897     int r, g, b;
01898     color.rgb(&r,&g,&b);
01899     background.setRgb(r,g,b);
01900     cfg.writeEntry("background",color.name());
01901     odebug << "background "+color.name() << oendl;
01902     cfg.write();
01903 }
01904 
01905 void Konsole::doWrap()
01906 {
01907     Config cfg( "Konsole" );
01908     cfg.setGroup("ScrollBar");
01909     TEWidget* te = getTe();
01910     if( !cfg.readBoolEntry("HorzScroll",0))
01911     {
01912         te->setWrapAt(0);
01913         configMenu->setItemChecked( cm_wrap,TRUE);
01914     }
01915     else
01916     {
01917         //        te->setWrapAt(90);
01918         te->setWrapAt(120);
01919         configMenu->setItemChecked( cm_wrap,FALSE);
01920     }
01921 }
01922 void Konsole::closeSession() {
01923    doneSession(getTe(), 0);
01924 }

Generated on Sat Nov 5 16:15:26 2005 for OPIE by  doxygen 1.4.2