-rw-r--r-- | core/apps/embeddedkonsole/MyPty.cpp | 7 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 21 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/konsole.h | 6 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/session.h | 2 |
4 files changed, 17 insertions, 19 deletions
diff --git a/core/apps/embeddedkonsole/MyPty.cpp b/core/apps/embeddedkonsole/MyPty.cpp index e7d8274..5a8519a 100644 --- a/core/apps/embeddedkonsole/MyPty.cpp +++ b/core/apps/embeddedkonsole/MyPty.cpp @@ -50,65 +50,64 @@ \par Pseudo terminals Pseudo terminals are a unique feature of UNIX, and always come in form of pairs of devices (/dev/ptyXX and /dev/ttyXX), which are connected to each other by the operating system. One may think of them as two serial devices linked by a null-modem cable. Being based on devices the number of simultanous instances of this class is (globally) limited by the number of those device pairs, which is 256. Another technic are UNIX 98 PTY's. These are supported also, and prefered over the (obsolete) predecessor. There's a sinister ioctl(2), signal(2) and job control stuff nessesary to make everything work as it should. */ #include <qfileinfo.h> #include <qapplication.h> #include <qsocketnotifier.h> #include <qstring.h> #include <stdlib.h> #include <stdio.h> #include <signal.h> #include <fcntl.h> #include <unistd.h> #include <termios.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/wait.h> -#undef HAVE_OPENPTY #ifdef HAVE_OPENPTY #include <pty.h> #endif #include "MyPty.h" #undef VERBOSE_DEBUG /* -------------------------------------------------------------------------- */ /*! Informs the client program about the actual size of the window. */ void MyPty::setSize(int lines, int columns) { struct winsize wsize; wsize.ws_row = (unsigned short)lines; wsize.ws_col = (unsigned short)columns; if(fd < 0) return; ioctl(fd,TIOCSWINSZ,(char *)&wsize); } void MyPty::donePty() { // This is code from the Qt DumbTerminal example int status = 0; @@ -231,60 +230,60 @@ int MyPty::openPty() /*! Create an instance. */ MyPty::MyPty() : cpid(0) { fd = openPty(); } /*! Destructor. Note that the related client program is not killed (yet) when a instance is deleted. */ MyPty::~MyPty() { donePty(); } /*! sends len bytes through the line */ void MyPty::send_bytes(const char* s, int len) { #ifdef VERBOSE_DEBUG // verbose debug printf("sending bytes:\n"); for (int i = 0; i < len; i++) printf("%c", s[i]); printf("\n"); #endif - ::write(fd, s, len); + ::write(fd, s, len); } /*! indicates that a block of data is received */ void MyPty::readPty() -{ +{ char buf[4096]; int len = ::read( fd, buf, 4096 ); if (len == -1) donePty(); if (len < 0) return; emit block_in(buf,len); - + #ifdef VERBOSE_DEBUG // verbose debug printf("read bytes:\n"); for (int i = 0; i < len; i++) printf("%c", buf[i]); printf("\n"); #endif } diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index b8f009d..1c613a9 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp @@ -1,56 +1,55 @@ /* ---------------------------------------------------------------------- */ /* */ /* [main.C] 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> */ /* */ /* -------------------------------------------------------------------------- */ // enhancements added by L.J. Potter <ljp@llornkcor.com> // enhancements added by Phillip Kuhn -//#define QT_QWS_OPIE #include <stdlib.h> #ifdef QT_QWS_OPIE #include <opie2/ocolorpopupmenu.h> #endif #include <qpe/resource.h> #include <qdir.h> #include <qevent.h> #include <qdragobject.h> #include <qobjectlist.h> #include <qtoolbutton.h> #include <qtoolbar.h> #include <qpushbutton.h> #include <qfontdialog.h> #include <qglobal.h> #include <qpainter.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qaction.h> #include <qapplication.h> #include <qfontmetrics.h> #include <qcombobox.h> #include <qevent.h> #include <qtabwidget.h> #include <qtabbar.h> #include <qpe/config.h> #include <qstringlist.h> #include <qpalette.h> #include <qfontdatabase.h> @@ -340,66 +339,66 @@ void Konsole::initCommandList() } static void sig_handler(int x) { printf("got signal %d\n",x); } void Konsole::init(const char* _pgm, QStrList & _args) { #if 0 for(int i=1; i<=31; i++) { if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV && i != SIGINT && i != SIGILL && i != SIGTERM && i != SIGBUS) signal(i,sig_handler); } #endif signal(SIGSTOP, sig_handler); signal(SIGCONT, sig_handler); signal(SIGTSTP, sig_handler); b_scroll = TRUE; // histon; n_keytab = 0; n_render = 0; startUp=0; fromMenu = FALSE; fullscreen = false; - setCaption( "Konsole" ); - setIcon( Resource::loadPixmap( "qkonsole/qkonsole" ) ); + setCaption( tr( "Konsole" ) ); + setIcon( Resource::loadPixmap( "konsole/Terminal" ) ); Config cfg( "Konsole" ); cfg.setGroup("Font"); QString tmp; // initialize the list of allowed fonts /////////////////////////////////// QString cfgFontName = cfg.readEntry("FontName","Lcfont"); int cfgFontSize = cfg.readNumEntry("FontSize",18); cfont = -1; // this code causes repeated access to all the font files // which does slow down startup QFontDatabase fontDB; QStringList familyNames; familyNames = fontDB.families( FALSE ); QString s; int fontIndex = 0; int familyNum = 0; fontList = new QPopupMenu( this ); for(uint j = 0; j < (uint)familyNames.count(); j++) { s = familyNames[j]; if ( s.contains('-') ) { int i = s.find('-'); s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]"; } s[0] = s[0].upper(); @@ -548,65 +547,65 @@ void Konsole::init(const char* _pgm, QStrList & _args) 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 ( Resource::loadPixmap ( "qkonsole/qkonsole" ), tr( "new session" ), this, + sessionList-> insertItem ( Resource::loadPixmap ( "konsole/Terminal" ), 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"), Resource::loadPixmap( "konsole/Terminal" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolBar ); a = new QAction( tr("Full Screen"), Resource::loadPixmap( "fullscreen" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( toggleFullScreen() ) ); a->addTo( toolBar ); a = new QAction( tr("Zoom"), Resource::loadPixmap( "zoom" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) ); a->addTo( toolBar ); @@ -850,65 +849,65 @@ void Konsole::changeFontSize(int delta) setFont(i+1); printf("font %d\n", i+1); return; } } else if (delta < 0) { if (i > 0 && fonts.at(i-1)->getFamilyNum() == fonts.at(i)->getFamilyNum()) { setFont(i-1); printf("font %d\n", i-1); return; } } } int fsize = fonts.at(i)->getSize(); printf("%d size=%d fsize=%d closest=%d\n", i, size, fsize, closest); if ((delta > 0 && fsize > size && fsize < closest) || (delta < 0 && fsize < size && fsize > closest)) { closest = fsize; closest_font = i; } } if (closest_font >= 0) { printf("font closest %d (%d)\n", closest_font, closest); setFont(closest_font); } } -int Konsole::findFont(QString name, int size, bool exactMatch) +int Konsole::findFont(const QString& name, int size, bool exactMatch) { for(uint i = 0; i < fonts.count(); i++) { if (fonts.at(i)->getName() == name && fonts.at(i)->getSize() == size) { return(i); } } if (exactMatch) { return(-1); } for(uint i = 0; i < fonts.count(); i++) { if (fonts.at(i)->getSize() == size) { return(i); } } return(-1); } void Konsole::setFont(int f) { VTFont* font = fonts.at(f); if (font) { TEWidget* te = getTe(); if (te != 0) { te->setVTFont(font->getFont()); @@ -1130,107 +1129,107 @@ void Konsole::doneSession(TEWidget* te, int ) // printf("done current session\n"); // te = getTe(); // } else { // int currentPage = tab->currentPageIndex(); // printf("done not current session\n"); // for(int i = 0; i < nsessions; i++) { // tab->setCurrentPage(i); // printf("find session %d tab page %x session %x\n", // i, tab->currentPage(), sess->currentSession); // if (tab->currentPage() == sess->currentSession) { // printf("found session %d\n", i); // te = tab->currentPage(); // break; // } // } // tab->setCurrentPage(currentPage); // } if (te != 0) { te->currentSession->setConnect(FALSE); tab->removeTab(te); delete te->currentSession; delete te; sessionList->removeItem(nsessions); nsessions--; } if (nsessions == 0) { close(); } } -void Konsole::changeTitle(TEWidget* te, QString newTitle ) +void Konsole::changeTitle(TEWidget* te, const QString& newTitle ) { if (te == getTe()) { - setCaption(newTitle + " - QKonsole"); + setCaption( newTitle + " - " + tr( "Konsole " ) ); } } void Konsole::newSession() { if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? TEWidget* te = new TEWidget(tab); Config cfg( "Konsole" ); cfg.setGroup("Menubar"); // FIXME use more defaults from config file te->useBeep=cfg.readBoolEntry("useBeep",0); // te->setBackgroundMode(PaletteBase); //we want transparent!! cfg.setGroup("Font"); QString sn = "Session" + QString::number(nsessions+1); printf("read font session %s\n", sn.latin1()); QString fontName = cfg.readEntry("FontName"+sn, cfg.readEntry("FontName", fonts.at(cfont)->getFamily())); int fontSize = cfg.readNumEntry("FontSize"+sn, cfg.readNumEntry("FontSize", fonts.at(cfont)->getSize())); cfont = findFont(fontName, fontSize, false); printf("lookup font %s size %d got %d\n", fontName.latin1(), fontSize, cfont); if (cfont < 0) cfont = 0; te->setVTFont(fonts.at(cfont)->getFont()); tab->addTab(te); TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); te->currentSession = se; connect( se, SIGNAL(done(TEWidget*,int)), this, SLOT(doneSession(TEWidget*,int)) ); - connect( se, SIGNAL(changeTitle(TEWidget*,QString)), this, - SLOT(changeTitle(TEWidget*,QString)) ); + connect( se, SIGNAL(changeTitle(TEWidget*,const QString&)), this, + SLOT(changeTitle(TEWidget*,const QString&)) ); connect(te, SIGNAL(changeFontSize(int)), this, SLOT(changeFontSize(int))); connect(te, SIGNAL(changeSession(int)), this, SLOT(changeSession(int))); connect(te, SIGNAL(newSession()), this, SLOT(newSession())); connect(te, SIGNAL(toggleFullScreen()), this, SLOT(toggleFullScreen())); connect(te, SIGNAL(setFullScreen(bool)), this, SLOT(setFullScreen(bool))); se->run(); se->setConnect(TRUE); se->setHistory(b_scroll); nsessions++; sessionList->insertItem(QString::number(nsessions), nsessions); sessionListSelected(nsessions); doWrap(); setColor(nsessions-1); } } TEWidget* Konsole::getTe() { if (nsessions) { return (TEWidget *) tab->currentPage(); } else { return 0; } } void Konsole::sessionListSelected(int id) { if (id < 0) { @@ -1280,69 +1279,69 @@ void Konsole::changeSession(int delta) { tab->setCurrentPage(i); break; } n++; } } } void Konsole::switchSession(QWidget* w) { TEWidget* te = (TEWidget *) w; QFont teFnt = te->getVTFont(); int familyNum = -1; for(uint i = 0; i < fonts.count(); i++) { VTFont *fnt = fonts.at(i); bool cf = fnt->getFont() == teFnt; fontList->setItemChecked(i, cf); if (cf) { cfont = i; familyNum = fnt->getFamilyNum(); } } for(int i = 0; i < (int)fontList->count(); i++) { fontList->setItemChecked(i + 1000, i == familyNum); } if (! te->currentSession->Title().isEmpty() ) { - setCaption(te->currentSession->Title() + " - QKonsole"); + setCaption( te->currentSession->Title() + " - " + tr( "Konsole" ) ); } else { - setCaption( "Konsole" ); + setCaption( tr( "Konsole" ) ); } // colorMenuSelected(te->color_menu_item); } void Konsole::toggleFullScreen() { setFullScreen(! fullscreen); } void Konsole::setFullScreen ( bool b ) { static QSize normalsize; static bool listHidden; if (b == fullscreen) { return; } fullscreen = b; if ( b ) { if ( !normalsize. isValid ( )) { normalsize = size ( ); } setFixedSize ( qApp-> desktop ( )-> size ( )); showNormal ( ); reparent ( 0, WStyle_Customize | WStyle_NoBorder, diff --git a/core/apps/embeddedkonsole/konsole.h b/core/apps/embeddedkonsole/konsole.h index 37babbb..e163cb8 100644 --- a/core/apps/embeddedkonsole/konsole.h +++ b/core/apps/embeddedkonsole/konsole.h @@ -44,116 +44,116 @@ 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*,QString); + 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(); 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(QString name, int size, bool exact = false); + 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(QString name, QFont& font, QString family, int familyNum, int size) + 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; diff --git a/core/apps/embeddedkonsole/session.h b/core/apps/embeddedkonsole/session.h index f399e96..a4b33e2 100644 --- a/core/apps/embeddedkonsole/session.h +++ b/core/apps/embeddedkonsole/session.h @@ -39,56 +39,56 @@ public: public: void setConnect(bool r); TEmulation* getEmulation(); // to control emulation bool isSecure(); public: int schemaNo(); int fontNo(); const char* emuName(); const QString& Title(); bool history(); int keymap(); void setHistory(bool on); void setSchemaNo(int sn); void setKeymapNo(int kn); void setFontNo(int fn); void kill(int signal); public slots: void run(); void done(int status); void terminate(); void changeTitle(int, const QString& title); signals: void done(TEWidget*, int); - void changeTitle(TEWidget*, QString); + void changeTitle(TEWidget*, const QString&); private: // TEPty* sh; MyPty* sh; TEWidget* te; TEmulation* em; //FIXME: using the indices here // is propably very bad. We should // use a persistent reference instead. int schema_no; int font_no; int keymap_no; QString title; const char* pgm; QStrList args; QCString term; }; #endif |