-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 10 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/konsole.h | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index 7f3ea65..f4ca0bf 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp @@ -433,387 +433,390 @@ void Konsole::init(const char* _pgm, QStrList & _args) size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1); } else { printf("sizes[%d] = %d\n", i, sizes[i]); size = sizes[i]; } f = QFont(familyNames[j], size); f.setFixedPitch(true); QFontMetrics fm(f); // don't trust f.fixedPitch() or f.exactMatch(), they lie!! if (fm.width("l") == fm.width("m") && (i < (uint)sizes.count() || fm.width("m") > last_width)) { if (i < (uint)sizes.count()) { last_width = fm.width("m"); } if (sizeMenu == NULL) { sizeMenu = new QPopupMenu(); } int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex); sizeMenu->setItemParameter(id, fontIndex); sizeMenu->connectItem(id, this, SLOT(setFont(int))); QString name = s + " " + QString::number(size); fonts.append(new VTFont(name, f, familyNames[j], familyNum, size)); if (familyNames[j] == cfgFontName && size == cfgFontSize) { cfont = fontIndex; } printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size); fontIndex++; } } if (sizeMenu) { fontList->insertItem(s, sizeMenu, familyNum + 1000); familyNum++; } } } if (cfont < 0 || cfont >= (int)fonts.count()) { cfont = 0; } // create terminal emulation framework //////////////////////////////////// nsessions = 0; tab = new EKNumTabWidget(this); // tab->setMargin(tab->margin()-5); connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); // create terminal toolbar //////////////////////////////////////////////// setToolBarsMovable( FALSE ); menuToolBar = new QToolBar( this ); menuToolBar->setHorizontalStretchable( TRUE ); QMenuBar *menuBar = new QMenuBar( menuToolBar ); setFont(cfont); configMenu = new QPopupMenu( this); colorMenu = new QPopupMenu( this); scrollMenu = new QPopupMenu( this); editCommandListMenu = new QPopupMenu( this); configMenu->insertItem(tr("Command List"), editCommandListMenu); bool listHidden; cfg.setGroup("Menubar"); if( cfg.readEntry("Hidden","FALSE") == "TRUE") { ec_cmdlist = editCommandListMenu->insertItem( tr( "Show command list" )); listHidden=TRUE; } else { ec_cmdlist = editCommandListMenu->insertItem( tr( "Hide command list" )); listHidden=FALSE; } cfg.setGroup("Tabs"); tabMenu = new QPopupMenu(this); tm_bottom = tabMenu->insertItem(tr("Bottom" )); tm_top = tabMenu->insertItem(tr("Top")); tm_hidden = tabMenu->insertItem(tr("Hidden")); configMenu->insertItem(tr("Tabs"), tabMenu); tmp=cfg.readEntry("Position","Top"); if(tmp=="Top") { tab->setTabPosition(QTabWidget::Top); tab->getTabBar()->show(); tabPos = tm_top; } else if (tmp=="Bottom") { tab->setTabPosition(QTabWidget::Bottom); tab->getTabBar()->show(); tabPos = tm_bottom; } else { tab->getTabBar()->hide(); tab->setMargin(tab->margin()); tabPos = tm_hidden; } cm_bw = colorMenu->insertItem(tr( "Black on White")); cm_wb = colorMenu->insertItem(tr( "White on Black")); cm_gb = colorMenu->insertItem(tr( "Green on Black")); // cm_bt = colorMenu->insertItem(tr( "Black on Transparent")); cm_br = colorMenu->insertItem(tr( "Black on Pink")); cm_rb = colorMenu->insertItem(tr( "Pink on Black")); cm_gy = colorMenu->insertItem(tr( "Green on Yellow")); cm_bm = colorMenu->insertItem(tr( "Blue on Magenta")); cm_mb = colorMenu->insertItem(tr( "Magenta on Blue")); cm_cw = colorMenu->insertItem(tr( "Cyan on White")); cm_wc = colorMenu->insertItem(tr( "White on Cyan")); cm_bb = colorMenu->insertItem(tr( "Blue on Black")); cm_ab = colorMenu->insertItem(tr( "Amber on Black")); cm_default = colorMenu->insertItem(tr("default")); #ifdef QT_QWS_OPIE colorMenu->insertItem(tr( "Custom")); #endif configMenu->insertItem(tr( "Colors") ,colorMenu); sessionList = new QPopupMenu(this); sessionList-> insertItem ( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ), tr( "new session" ), this, SLOT(newSession()) ); // connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); connect( tabMenu, SIGNAL( activated(int) ), this, SLOT( tabMenuSelected(int) )); connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); connect( editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); connect( sessionList, SIGNAL(activated(int)), this, SLOT( sessionListSelected(int) ) ); menuBar->insertItem( tr("View"), configMenu ); menuBar->insertItem( tr("Fonts"), fontList ); menuBar->insertItem( tr("Sessions"), sessionList ); toolBar = new QToolBar( this ); QAction *a; // Button Commands a = new QAction( tr("New"), Opie::Core::OResource::loadPixmap( "konsole/konsole", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolBar ); a = new QAction( tr("Full Screen"), Opie::Core::OResource::loadPixmap( "fullscreen", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( toggleFullScreen() ) ); a->addTo( toolBar ); a = new QAction( tr("Zoom"), Opie::Core::OResource::loadPixmap( "zoom", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) ); a->addTo( toolBar ); a = new QAction( tr("Enter"), Opie::Core::OResource::loadPixmap( "konsole/enter", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolBar ); a = new QAction( tr("Space"), Opie::Core::OResource::loadPixmap( "konsole/space", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolBar ); a = new QAction( tr("Tab"), Opie::Core::OResource::loadPixmap( "konsole/tab", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolBar ); a = new QAction( tr("Up"), Opie::Core::OResource::loadPixmap( "konsole/up", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolBar ); a = new QAction( tr("Down"), Opie::Core::OResource::loadPixmap( "konsole/down", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolBar ); - a = new QAction( tr("Paste"), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), - QString::null, 0, this, 0 ); + a = new QAction( tr("Paste"), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); + + a = new QAction( tr("Close"), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( closeSession() ) ); + a->addTo( toolBar ); secondToolBar = new QToolBar( this ); secondToolBar->setHorizontalStretchable( TRUE ); commonCombo = new QComboBox( secondToolBar ); // commonCombo->setMaximumWidth(236); ec_quick = editCommandListMenu->insertItem( tr( "Quick Edit" ) ); if( listHidden) { secondToolBar->hide(); editCommandListMenu->setItemEnabled(ec_quick ,FALSE); } ec_edit = editCommandListMenu->insertItem(tr( "Edit..." ) ); cfg.setGroup("Commands"); commonCombo->setInsertionPolicy(QComboBox::AtCurrent); initCommandList(); // for (int i = 0; commonCmds[i] != NULL; i++) { // commonCombo->insertItem( commonCmds[i], i ); // tmp = cfg.readEntry( QString::number(i),""); // if(tmp != "") // commonCombo->changeItem( tmp,i ); // } connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); sm_none = scrollMenu->insertItem(tr( "None" )); sm_left = scrollMenu->insertItem(tr( "Left" )); sm_right = scrollMenu->insertItem(tr( "Right" )); // scrollMenu->insertSeparator(4); // scrollMenu->insertItem(tr( "Horizontal" )); configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); configMenu->insertItem(tr( "History..." ), this, SLOT(historyDialog())); cm_wrap = configMenu->insertItem(tr( "Wrap" )); cfg.setGroup("ScrollBar"); configMenu->setItemChecked(cm_wrap, cfg.readBoolEntry("HorzScroll",0)); cm_beep = configMenu->insertItem(tr( "Use Beep" )); cfg.setGroup("Menubar"); configMenu->setItemChecked(cm_beep, cfg.readBoolEntry("useBeep",0)); fullscreen_msg = new QLabel(this); fullscreen_msg-> setAlignment ( AlignCenter | SingleLine ); fullscreen_msg-> hide(); fullscreen_msg-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding )); fullscreen_msg-> setAutoResize(true); fullscreen_msg-> setFrameStyle(QFrame::PopupPanel | QFrame::Raised); fullscreen_msg-> setText(tr("To exit fullscreen, tap here.")); fullscreen_timer = new QTimer(this); connect(fullscreen_timer, SIGNAL(timeout()), this, SLOT(fullscreenTimeout())); show_fullscreen_msg = true; //scrollMenuSelected(-29); // cfg.setGroup("ScrollBar"); // if(cfg.readBoolEntry("HorzScroll",0)) { // if(cfg.readNumEntry("Position",2) == 0) // te->setScrollbarLocation(1); // else // te->setScrollbarLocation(0); // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); // te->setWrapAt(120); // } // create applications ///////////////////////////////////////////////////// setCentralWidget(tab); // load keymaps //////////////////////////////////////////////////////////// KeyTrans::loadAll(); for (int i = 0; i < KeyTrans::count(); i++) { KeyTrans* s = KeyTrans::find(i); assert( s ); } se_pgm = _pgm; se_args = _args; cfg.setGroup("CommandLine"); if (cfg.hasKey("shell_args")) { QStringList se_args_list = cfg.readListEntry("shell_args",'|'); for(uint i = 0; i < se_args_list.count(); i++) { se_args.prepend(se_args_list[se_args_list.count() - i - 1].latin1()); } } else { se_args.prepend("--login"); } se_pgm = cfg.readEntry("shell_bin", QString(se_pgm)); // this is the "documentation" for those who know to look if (! cfg.hasKey("shell_args")) { cfg.writeEntry("shell_args",QStringList::fromStrList(se_args),'|'); } if (! cfg.hasKey("shell_bin")) { cfg.writeEntry("shell_bin",QString(se_pgm)); } parseCommandLine(); // read and apply default values /////////////////////////////////////////// resize(321, 321); // Dummy. QSize currentSize = size(); if (currentSize != size()) defaultSize = size(); /* allows us to catch cancel/escape */ reparent ( 0, WStyle_Customize | WStyle_NoBorder, QPoint ( 0, 0 )); } void Konsole::show() { if ( !nsessions ) { newSession(); } QMainWindow::show(); } void Konsole::initSession(const char*, QStrList &) { QMainWindow::show(); } Konsole::~Konsole() { while (nsessions > 0) { doneSession(getTe(), 0); } } void Konsole::historyDialog() { QDialog *d = new QDialog ( this, "histdlg", true ); // d-> setCaption ( tr( "History" )); QBoxLayout *lay = new QVBoxLayout ( d, 4, 4 ); QLabel *l = new QLabel ( tr( "History Lines:" ), d ); lay-> addWidget ( l ); Config cfg( "Konsole" ); cfg.setGroup("History"); int hist = cfg.readNumEntry("history_lines",300); int avg_line = cfg.readNumEntry("avg_line_length",60); QSpinBox *spin = new QSpinBox ( 1, 100000, 20, d ); spin-> setValue ( hist ); spin-> setWrapping ( true ); spin-> setButtonSymbols ( QSpinBox::PlusMinus ); lay-> addWidget ( spin ); if ( d-> exec ( ) == QDialog::Accepted ) { cfg.writeEntry("history_lines", spin->value()); cfg.writeEntry("avg_line_length", avg_line); if (getTe() != NULL) { getTe()->currentSession->setHistory(true); } } delete d; } void Konsole::cycleZoom() { TEWidget* te = getTe(); QFont font = te->getVTFont(); int size = font.pointSize(); changeFontSize(1); font = te->getVTFont(); if (font.pointSize() <= size) @@ -1727,192 +1730,195 @@ void Konsole::scrollMenuSelected(int index) // case -29: { // bool b=cfg.readBoolEntry("HorzScroll",0); // cfg.writeEntry("HorzScroll", !b ); // cfg.write(); // if(cfg.readNumEntry("Position",2) == 0) { // te->setScrollbarLocation(1); // te->setWrapAt(0); // } else { // te->setScrollbarLocation(0); // te->setWrapAt(120); // } // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); // } // break; void Konsole::editCommandListMenuSelected(int iD) { // QString temp; // odebug << temp.sprintf("edit command list " << iD) << "" << oendl; // FIXME: more cleanup needed here TEWidget* te = getTe(); Config cfg( "Konsole" ); cfg.setGroup("Menubar"); if( iD == ec_cmdlist) { if(!secondToolBar->isHidden()) { secondToolBar->hide(); configMenu->changeItem( iD,tr( "Show Command List" )); cfg.writeEntry("Hidden","TRUE"); configMenu->setItemEnabled(ec_edit ,FALSE); configMenu->setItemEnabled(ec_quick ,FALSE); } else { secondToolBar->show(); configMenu->changeItem( iD,tr( "Hide Command List" )); cfg.writeEntry("Hidden","FALSE"); configMenu->setItemEnabled(ec_edit ,TRUE); configMenu->setItemEnabled(ec_quick ,TRUE); if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { configMenu->setItemChecked(ec_edit,TRUE); commonCombo->setEditable( TRUE ); } else { configMenu->setItemChecked(ec_edit,FALSE); commonCombo->setEditable( FALSE ); } } } if( iD == ec_quick) { cfg.setGroup("Commands"); // odebug << "enableCommandEdit" << oendl; if( !configMenu->isItemChecked(iD) ) { commonCombo->setEditable( TRUE ); configMenu->setItemChecked(iD,TRUE); commonCombo->setCurrentItem(0); cfg.writeEntry("EditEnabled","TRUE"); } else { commonCombo->setEditable( FALSE ); configMenu->setItemChecked(iD,FALSE); cfg.writeEntry("EditEnabled","FALSE"); commonCombo->setFocusPolicy(QWidget::NoFocus); te->setFocus(); } } if(iD == ec_edit) { // "edit commands" CommandEditDialog *m = new CommandEditDialog(this); connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); m->showMaximized(); } } // $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' void Konsole::setDocument( const QString &cmd) { newSession(); TEWidget* te = getTe(); if(cmd.find("-e", 0, TRUE) != -1) { QString cmd2; cmd2=cmd.right(cmd.length()-3)+" &"; system(cmd2.latin1()); if(startUp <= 1 && nsessions < 2) { doneSession(getTe(), 0); exit(0); } else doneSession(getTe(), 0); } else { if (te != 0) { te->emitText(cmd+"\r"); } } startUp++; } // what is the point of this when you can just // run commands by using the shell directly?? void Konsole::parseCommandLine() { QString cmd; // newSession(); for (int i=1;i< qApp->argc();i++) { if( QString(qApp->argv()[i]) == "-e") { i++; for ( int j=i;j< qApp->argc();j++) { cmd+=QString(qApp->argv()[j])+" "; } cmd.stripWhiteSpace(); system(cmd.latin1()); exit(0);//close(); } // end -e switch } startUp++; } void Konsole::changeForegroundColor(const QColor &color) { Config cfg( "Konsole" ); cfg.setGroup("Colors"); int r, g, b; color.rgb(&r,&g,&b); foreground.setRgb(r,g,b); cfg.writeEntry("foreground",color.name()); odebug << "foreground "+color.name() << oendl; cfg.write(); odebug << "do other dialog" << oendl; #ifdef QT_QWS_OPIE Opie::OColorPopupMenu* penColorPopupMenu2 = new Opie::OColorPopupMenu(Qt::black, this,"background color"); connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBackgroundColor(const QColor&))); penColorPopupMenu2->exec(); #endif } void Konsole::changeBackgroundColor(const QColor &color) { odebug << "Change background" << oendl; Config cfg( "Konsole" ); cfg.setGroup("Colors"); int r, g, b; color.rgb(&r,&g,&b); background.setRgb(r,g,b); cfg.writeEntry("background",color.name()); odebug << "background "+color.name() << oendl; cfg.write(); } void Konsole::doWrap() { Config cfg( "Konsole" ); cfg.setGroup("ScrollBar"); TEWidget* te = getTe(); if( !cfg.readBoolEntry("HorzScroll",0)) { te->setWrapAt(0); configMenu->setItemChecked( cm_wrap,TRUE); } else { // te->setWrapAt(90); te->setWrapAt(120); configMenu->setItemChecked( cm_wrap,FALSE); } } +void Konsole::closeSession() { + doneSession(getTe(), 0); +} diff --git a/core/apps/embeddedkonsole/konsole.h b/core/apps/embeddedkonsole/konsole.h index e163cb8..40f5284 100644 --- a/core/apps/embeddedkonsole/konsole.h +++ b/core/apps/embeddedkonsole/konsole.h @@ -1,206 +1,207 @@ /* ----------------------------------------------------------------------- */ /* */ /* [konsole.h] Konsole */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole, an X terminal. */ /* */ /* The material contained in here more or less directly orginates from */ /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ #ifndef KONSOLE_H #define KONSOLE_H #include <qmainwindow.h> #include <qaction.h> #include <qpopupmenu.h> #include <qstrlist.h> #include <qintdict.h> #include <qptrdict.h> #include <qtabwidget.h> #include <qtoolbar.h> #include <qcombobox.h> #include <qcolor.h> #include "MyPty.h" #include "TEWidget.h" #include "TEmuVt102.h" #include "session.h" class EKNumTabWidget; class Konsole : public QMainWindow { Q_OBJECT public: static QString appName() { return QString::fromLatin1("embeddedkonsole"); } Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); Konsole(const char * name, const char* pgm, QStrList & _args, int histon); ~Konsole(); void setColLin(int columns, int lines); QToolBar *secondToolBar; void show(); void setColor(int); int lastSelectedMenu; int startUp; public slots: void changeFontSize(int); void toggleFullScreen(); void setFullScreen(bool); void changeSession(int); void cycleZoom(); void newSession(); private slots: void setDocument(const QString &); void doneSession(TEWidget*,int); void changeTitle(TEWidget*, const QString&); void changeColumns(int); void setFont(int); // void fontChanged(int); void configMenuSelected(int ); void colorMenuSelected(int); void colorMenuIsSelected(int); void tabMenuSelected(int); void sessionListSelected(int); void enterCommand(int); void hitEnter(); void hitSpace(); void hitTab(); void hitPaste(); void hitUp(); void hitDown(); void switchSession(QWidget *); void changeCommand(const QString &, int); void initCommandList(); void scrollMenuSelected(int); void editCommandListMenuSelected(int); void parseCommandLine(); void changeForegroundColor(const QColor &); void changeBackgroundColor(const QColor &); void historyDialog(); void fullscreenTimeout(); + void closeSession(); private: void doWrap(); void init(const char* _pgm, QStrList & _args); void initSession(const char* _pgm, QStrList & _args); void runSession(TESession* s); void setColorPixmaps(); void setHistory(bool); void setColors(QColor foreground, QColor background); int findFont(const QString& name, int size, bool exact = false); QSize calcSize(int columns, int lines); TEWidget* getTe(); QStringList commands; QLabel * msgLabel; QColor foreground, background; bool fromMenu; bool fullscreen; private: class VTFont { public: VTFont(const QString& name, QFont& font, const QString& family, int familyNum, int size) { this->name = name; this->font = font; this->family = family; this->size = size; this->familyNum = familyNum; } QFont& getFont() { return font; } QString getName() { return name; } int getSize() { return(size); } QString getFamily() { return(family); } int getFamilyNum() { return(familyNum); } private: QFont font; QString name; QString family; int familyNum; int size; }; EKNumTabWidget* tab; int tabPos; int nsessions; QList<VTFont> fonts; int cfont; QCString se_pgm; QStrList se_args; QToolBar *menuToolBar; QToolBar *toolBar; QComboBox *commonCombo; QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu; QPopupMenu *sessionList, *tabMenu; int sm_none, sm_left, sm_right; int cm_beep, cm_wrap; int cm_default; int cm_bw, cm_wb, cm_gb, cm_bt, cm_br, cm_rb, cm_gy, cm_bm, cm_mb, cm_cw, cm_wc, cm_bb, cm_ab; int tm_top, tm_bottom, tm_hidden; int ec_edit, ec_cmdlist, ec_quick; bool show_fullscreen_msg; QTimer *fullscreen_timer; QLabel *fullscreen_msg; // history scrolling I think bool b_scroll; int n_keytab; int n_scroll; int n_render; QString pmPath; // pixmap path QString dropText; QFont defaultFont; QSize defaultSize; }; #endif |