author | harlekin <harlekin> | 2004-02-01 12:52:08 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-02-01 12:52:08 (UTC) |
commit | 29220ef88ff2f93cef17695e3733da62c16d89ca (patch) (side-by-side diff) | |
tree | c98007f673dfcf3480ac7e1a61746ce7d68c5b45 | |
parent | da02269f0d59e4cc932b9dbc7294374e3398ecad (diff) | |
download | opie-29220ef88ff2f93cef17695e3733da62c16d89ca.zip opie-29220ef88ff2f93cef17695e3733da62c16d89ca.tar.gz opie-29220ef88ff2f93cef17695e3733da62c16d89ca.tar.bz2 |
less includes
29 files changed, 0 insertions, 102 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp index b2f6a74..a37f980 100644 --- a/noncore/apps/opie-console/MyPty.cpp +++ b/noncore/apps/opie-console/MyPty.cpp @@ -1,325 +1,323 @@ /* -------------------------------------------------------------------------- */ /* */ /* [MyPty.C] Pseudo Terminal Device */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /* If you're compiling konsole on non-Linux platforms and find problems that you can track down to this file, please have a look into ../README.ports, too. */ /*! \file */ /*! \class TEPty \brief Ptys provide a pseudo terminal connection to a program. Although closely related to pipes, these pseudo terminal connections have some ability, that makes it nessesary to uses them. Most importent, they know about changing screen sizes and UNIX job control. Within the terminal emulation framework, this class represents the host side of the terminal together with the connecting serial line. One can create many instances of this class within a program. As a side effect of using this class, a signal(2) handler is installed on SIGCHLD. \par FIXME [NOTE: much of the technical stuff below will be replaced by forkpty.] publish the SIGCHLD signal if not related to an instance. clearify TEPty::done vs. TEPty::~TEPty semantics. check if pty is restartable via run after done. \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 <qapplication.h> #include <qsocketnotifier.h> -#include <qstring.h> #include <qfile.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> #ifdef HAVE_OPENPTY #include <pty.h> #endif #include "procctl.h" #include "MyPty.h" #undef VERBOSE_DEBUG /* -------------------------------------------------------------------------- */ /*! Informs the client program about the actual size of the window. */ void MyPty::setSize(int lines, int columns) { qWarning("setting size"); struct winsize wsize; wsize.ws_row = (unsigned short)lines; wsize.ws_col = (unsigned short)columns; if(m_fd < 0) return; ioctl(m_fd,TIOCSWINSZ,(char *)&wsize); } void MyPty::donePty() { // This is code from the Qt DumbTerminal example ::close(m_fd); if (m_cpid) { kill(m_cpid, SIGHUP); //waitpid(m_cpid, &status, 0); delete m_sn_e; delete m_sn_r; m_sn_e = 0l; m_sn_r = 0l; } m_cpid = 0; m_fd = -1; // emit done(status); } const char* MyPty::deviceName() { return m_ttynam; } void MyPty::error() { // This is code from the Qt DumbTerminal example donePty(); } void MyPty::start() { QStrList lis; int r =run(m_cmd.latin1(), lis, 0, 0); r = r; } /*! start the client program. */ int MyPty::run(const char* cmd, QStrList &, const char*, int) { // This is code from the Qt DumbTerminal example m_cpid = fork(); if ( !m_cpid ) { // child - exec shell on tty for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); int ttyfd = ::open(m_ttynam, O_RDWR); dup2(ttyfd, STDIN_FILENO); dup2(ttyfd, STDOUT_FILENO); dup2(ttyfd, STDERR_FILENO); // should be done with tty, so close it ::close(ttyfd); static struct termios ttmode; if ( setsid() < 0 ) perror( "failed to set process group" ); #if defined (TIOCSCTTY) // grabbed from APUE by Stevens ioctl(STDIN_FILENO, TIOCSCTTY, 0); #endif tcgetattr( STDIN_FILENO, &ttmode ); ttmode.c_cc[VINTR] = 3; ttmode.c_cc[VERASE] = 8; tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); setenv("TERM",m_term,1); setenv("COLORTERM","0",1); EnvironmentMap::Iterator it; for (it = m_env.begin(); it != m_env.end(); it++) { setenv(it.key().latin1(), it.data().latin1(), 1); } if (getuid() == 0) { char msg[] = "WARNING: You are running this shell as root!\n"; write(ttyfd, msg, sizeof(msg)); } execl(cmd, cmd, 0); donePty(); exit(-1); } // parent - continue as a widget delete m_sn_r; m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); delete m_sn_e; m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error())); return 0; } int MyPty::openPty() { // This is code from the Qt DumbTerminal example int ptyfd = -1; #ifdef HAVE_OPENPTY int ttyfd; if ( openpty(&ptyfd,&ttyfd,m_ttynam,0,0) ) ptyfd = -1; else ::close(ttyfd); // we open the ttynam ourselves. #else for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) { for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) { sprintf(m_ptynam,"/dev/pty%c%c",*c0,*c1); sprintf(m_ttynam,"/dev/tty%c%c",*c0,*c1); if ((ptyfd = ::open(m_ptynam,O_RDWR)) >= 0) { if (geteuid() != 0 && !access(m_ttynam,R_OK|W_OK) == 0) { ::close(ptyfd); ptyfd = -1; } } } } #endif if ( ptyfd < 0 ) { // qApp->exit(1); return -1; } return ptyfd; } /*! Create an instance. */ MyPty::MyPty(const Profile& prof) : m_cpid(0) { int term = prof.readNumEntry("Terminal", Profile::VT100 ); switch( term ) { default: case Profile::VT100: case Profile::VT102: m_term = "vt100"; break; case Profile::Linux: m_term = "linux"; break; case Profile::XTerm: m_term = "xterm"; break; } m_sn_e = 0l; m_sn_r = 0l; m_fd = openPty(); ProcCtl* ctl = ProcCtl::self(); Q_UNUSED(ctl); reload(prof); } /*! Destructor. Note that the related client program is not killed (yet) when a instance is deleted. */ MyPty::~MyPty() { donePty(); } QString MyPty::identifier()const { return QString::fromLatin1("term"); } QString MyPty::name()const{ return identifier(); } bool MyPty::open() { if (m_fd < 0) m_fd = openPty(); start(); return true; } void MyPty::close() { donePty(); m_fd = openPty(); } void MyPty::reload( const Profile& prof) { m_env.clear(); m_cmd = prof.readEntry("Command", "/bin/sh"); /* * Lets check if m_cmd actually * exists.... * we try to use bin/bash and if * this fails we * will fallback to /bin/sh * which should be there 100% */ if ( m_cmd.stripWhiteSpace() == "/bin/bash" && !QFile::exists(QFile::encodeName(m_cmd) ) ) m_cmd = "/bin/sh"; int envcount = prof.readNumEntry("EnvVars", 0); for (int i=0; i<envcount; i++) { QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); if (!(name.isEmpty() || value.isEmpty())) { m_env.insert(name, value); } } } /*! sends len bytes through the line */ void MyPty::send(const QByteArray& ar) { #ifdef VERBOSE_DEBUG // verbose debug printf("sending bytes:\n"); for (uint i = 0; i < ar.count(); i++) printf("%c", ar[i]); printf("\n"); diff --git a/noncore/apps/opie-console/TEWidget.cpp b/noncore/apps/opie-console/TEWidget.cpp index 444924b..e535296 100644 --- a/noncore/apps/opie-console/TEWidget.cpp +++ b/noncore/apps/opie-console/TEWidget.cpp @@ -1,319 +1,311 @@ /* ------------------------------------------------------------------------ */ /* */ /* [TEWidget.C] Terminal Emulation Widget */ /* */ /* ------------------------------------------------------------------------ */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* ------------------------------------------------------------------------ */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /*! \class TEWidget \brief Visible screen contents This class is responsible to map the `image' of a terminal emulation to the display. All the dependency of the emulation to a specific GUI or toolkit is localized here. Further, this widget has no knowledge about being part of an emulation, it simply work within the terminal emulation framework by exposing size and key events and by being ordered to show a new image. <ul> <li> The internal image has the size of the widget (evtl. rounded up) <li> The external image used in setImage can have any size. <li> (internally) the external image is simply copied to the internal when a setImage happens. During a resizeEvent no painting is done a paintEvent is expected to follow anyway. </ul> \sa TEScreen \sa Emulation */ /* FIXME: - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent - 'font_a' not used in mouse events - add destructor */ /* TODO - evtl. be sensitive to `paletteChange' while using default colors. - set different 'rounding' styles? I.e. have a mode to show clipped chars? */ // #include "config.h" #include "TEWidget.h" -#include "session.h" #include <qpe/config.h> #include <qapplication.h> -#include <qcursor.h> -#include <qregexp.h> -#include <qpainter.h> #include <qclipboard.h> -#include <qstyle.h> -#include <qfile.h> -#include <qdragobject.h> -#include <qvbox.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <ctype.h> #include <sys/stat.h> #include <sys/types.h> #include <signal.h> #include <assert.h> // #include "TEWidget.moc" //#include <kapp.h> //#include <kcursor.h> //#include <kurl.h> //#include <kdebug.h> //#include <klocale.h> #define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } #define loc(X,Y) ((Y)*columns+(X)) //FIXME: the rim should normally be 1, 0 only when running in full screen mode. #define rimX 0 // left/right rim width #define rimY 0 // top/bottom rim high #define yMouseScroll 1 // scroll increment used when dragging selection at top/bottom of window. /* Button XPM */ namespace { static char * menu_xpm[] = { "12 12 5 1", " c None", ". c #000000", "+ c #FFFDAD", "@ c #FFFF00", "# c #E5E100", " ", " ", " ......... ", " .+++++++. ", " .+@@@@#. ", " .+@@@#. ", " .+@@#. ", " .+@#. ", " .+#. ", " .+. ", " .. ", " "}; } /* ------------------------------------------------------------------------- */ /* */ /* Colors */ /* */ /* ------------------------------------------------------------------------- */ //FIXME: the default color table is in session.C now. // We need a way to get rid of this one, here. static const ColorEntry base_color_table[TABLE_COLORS] = // The following are almost IBM standard color codes, with some slight // gamma correction for the dim colors to compensate for bright X screens. // It contains the 8 ansiterm/xterm colors in 2 intensities. { // Fixme: could add faint colors here, also. // normal ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White // intensiv ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) }; /* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) Code 0 1 2 3 4 5 6 7 ----------- ------- ------- ------- ------- ------- ------- ------- ------- ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White */ QColor TEWidget::getDefaultBackColor() { return color_table[DEFAULT_BACK_COLOR].color; } const ColorEntry* TEWidget::getColorTable() const { return color_table; } const ColorEntry* TEWidget::getdefaultColorTable() const { return base_color_table; } const QPixmap *TEWidget::backgroundPixmap() { static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); const QPixmap *pm = bg; return pm; } void TEWidget::setColorTable(const ColorEntry table[]) { for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; const QPixmap* pm = backgroundPixmap(); if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); update(); } //FIXME: add backgroundPixmapChanged. /* ------------------------------------------------------------------------- */ /* */ /* Font */ /* */ /* ------------------------------------------------------------------------- */ /* The VT100 has 32 special graphical characters. The usual vt100 extended xterm fonts have these at 0x00..0x1f. QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals come in here as proper unicode characters. We treat non-iso10646 fonts as VT100 extended and do the requiered mapping from unicode to 0x00..0x1f. The remaining translation is then left to the QCodec. */ // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. unsigned short vt100_graphics[32] = { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 }; static QChar vt100extended(QChar c) { switch (c.unicode()) { case 0x25c6 : return 1; case 0x2592 : return 2; case 0x2409 : return 3; case 0x240c : return 4; case 0x240d : return 5; case 0x240a : return 6; case 0x00b0 : return 7; case 0x00b1 : return 8; case 0x2424 : return 9; case 0x240b : return 10; case 0x2518 : return 11; case 0x2510 : return 12; case 0x250c : return 13; case 0x2514 : return 14; case 0x253c : return 15; case 0xf800 : return 16; case 0xf801 : return 17; case 0x2500 : return 18; case 0xf803 : return 19; case 0xf804 : return 20; case 0x251c : return 21; case 0x2524 : return 22; case 0x2534 : return 23; case 0x252c : return 24; case 0x2502 : return 25; case 0x2264 : return 26; case 0x2265 : return 27; case 0x03c0 : return 28; case 0x2260 : return 29; case 0x00a3 : return 30; case 0x00b7 : return 31; } return c; } static QChar identicalMap(QChar c) { return c; } void TEWidget::fontChange(const QFont &) { QFontMetrics fm(font()); font_h = fm.height(); font_w = fm.maxWidth(); font_a = fm.ascent(); //printf("font_h: %d\n",font_h); //printf("font_w: %d\n",font_w); //printf("font_a: %d\n",font_a); //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); //printf("rawname: %s\n",font().rawName().ascii()); fontMap = #if QT_VERSION < 300 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") ? vt100extended : #endif identicalMap; propagateSize(); update(); } void TEWidget::setVTFont(const QFont& f) { QFrame::setFont(f); } QFont TEWidget::getVTFont() { return font(); } void TEWidget::setFont(const QFont &) { // ignore font change request if not coming from konsole itself } /* ------------------------------------------------------------------------- */ /* */ /* Constructor / Destructor */ /* */ /* ----------------------------------------------------------------------- */ TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) { #ifndef QT_NO_CLIPBOARD cb = QApplication::clipboard(); QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); #endif scrollbar = new QScrollBar( this ); scrollbar->setCursor( arrowCursor ); connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); diff --git a/noncore/apps/opie-console/TEmuVt102.cpp b/noncore/apps/opie-console/TEmuVt102.cpp index 275c18d..0d6aef5 100644 --- a/noncore/apps/opie-console/TEmuVt102.cpp +++ b/noncore/apps/opie-console/TEmuVt102.cpp @@ -1,290 +1,285 @@ /* ------------------------------------------------------------------------- */ /* */ /* [TEmuVt102.C] VT102 Terminal Emulation */ /* */ /* ------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* ------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /*! \class TEmuVt102 \brief Actual Emulation for Konsole \sa TEWidget \sa TEScreen */ #include "TEmuVt102.h" -#include "TEWidget.h" -#include "TEScreen.h" -#include "keytrans.h" #include <stdio.h> #include <unistd.h> -#include <qkeycode.h> -#include <qtextcodec.h> /* VT102 Terminal Emulation This class puts together the screens, the pty and the widget to a complete terminal emulation. Beside combining it's componentes, it handles the emulations's protocol. This module consists of the following sections: - Constructor/Destructor - Incoming Bytes Event pipeline - Outgoing Bytes - Mouse Events - Keyboard Events - Modes and Charset State - Diagnostics */ /* ------------------------------------------------------------------------- */ /* */ /* Constructor / Destructor */ /* */ /* ------------------------------------------------------------------------- */ /* Nothing really intesting happens here. */ /*! */ TEmuVt102::TEmuVt102(TEWidget* gui) : TEmulation(gui) { QObject::connect(gui,SIGNAL(mouseSignal(int,int,int)), this,SLOT(onMouse(int,int,int))); initTokenizer(); reset(); } /*! */ TEmuVt102::~TEmuVt102() { } /*! */ void TEmuVt102::reset() { resetToken(); resetModes(); resetCharset(0); screen[0]->reset(); resetCharset(1); screen[0]->reset(); setCodec(0); setKeytrans("linux.keytab"); } /* ------------------------------------------------------------------------- */ /* */ /* Processing the incoming byte stream */ /* */ /* ------------------------------------------------------------------------- */ /* Incoming Bytes Event pipeline This section deals with decoding the incoming character stream. Decoding means here, that the stream is first seperated into `tokens' which are then mapped to a `meaning' provided as operations by the `TEScreen' class or by the emulation class itself. The pipeline proceeds as follows: - Tokenizing the ESC codes (onRcvChar) - VT100 code page translation of plain characters (applyCharset) - Interpretation of ESC codes (tau) The escape codes and their meaning are described in the technical reference of this program. */ // Tokens ------------------------------------------------------------------ -- /* Since the tokens are the central notion if this section, we've put them in front. They provide the syntactical elements used to represent the terminals operations as byte sequences. They are encodes here into a single machine word, so that we can later switch over them easily. Depending on the token itself, additional argument variables are filled with parameter values. The tokens are defined below: - CHR - Printable characters (32..255 but DEL (=127)) - CTL - Control characters (0..31 but ESC (= 27), DEL) - ESC - Escape codes of the form <ESC><CHR but `[]()+*#'> - ESC_DE - Escape codes of the form <ESC><any of `()+*#%'> C - CSI_PN - Escape codes of the form <ESC>'[' {Pn} ';' {Pn} C - CSI_PS - Escape codes of the form <ESC>'[' {Pn} ';' ... C - CSI_PR - Escape codes of the form <ESC>'[' '?' {Pn} ';' ... C - VT52 - VT52 escape codes - <ESC><Chr> - <ESC>'Y'{Pc}{Pc} - XTE_HA - Xterm hacks <ESC>`]' {Pn} `;' {Text} <BEL> note that this is handled differently The last two forms allow list of arguments. Since the elements of the lists are treated individually the same way, they are passed as individual tokens to the interpretation. Further, because the meaning of the parameters are names (althought represented as numbers), they are includes within the token ('N'). */ #define TY_CONSTR(T,A,N) ( ((((int)N) & 0xffff) << 16) | ((((int)A) & 0xff) << 8) | (((int)T) & 0xff) ) #define TY_CHR___( ) TY_CONSTR(0,0,0) #define TY_CTL___(A ) TY_CONSTR(1,A,0) #define TY_ESC___(A ) TY_CONSTR(2,A,0) #define TY_ESC_CS(A,B) TY_CONSTR(3,A,B) #define TY_ESC_DE(A ) TY_CONSTR(4,A,0) #define TY_CSI_PS(A,N) TY_CONSTR(5,A,N) #define TY_CSI_PN(A ) TY_CONSTR(6,A,0) #define TY_CSI_PR(A,N) TY_CONSTR(7,A,N) #define TY_VT52__(A ) TY_CONSTR(8,A,0) // Tokenizer --------------------------------------------------------------- -- /* The tokenizers state The state is represented by the buffer (pbuf, ppos), and accompanied by decoded arguments kept in (argv,argc). Note that they are kept internal in the tokenizer. */ void TEmuVt102::resetToken() { ppos = 0; argc = 0; argv[0] = 0; argv[1] = 0; } void TEmuVt102::addDigit(int dig) { argv[argc] = 10*argv[argc] + dig; } void TEmuVt102::addArgument() { argc = QMIN(argc+1,MAXARGS-1); argv[argc] = 0; } void TEmuVt102::pushToToken(int cc) { pbuf[ppos] = cc; ppos = QMIN(ppos+1,MAXPBUF-1); } // Character Classes used while decoding #define CTL 1 #define CHR 2 #define CPN 4 #define DIG 8 #define SCS 16 #define GRP 32 void TEmuVt102::initTokenizer() { int i; UINT8* s; for(i = 0; i < 256; i++) tbl[ i] = 0; for(i = 0; i < 32; i++) tbl[ i] |= CTL; for(i = 32; i < 256; i++) tbl[ i] |= CHR; for(s = (UINT8*)"@ABCDGHLMPXcdfry"; *s; s++) tbl[*s] |= CPN; for(s = (UINT8*)"0123456789" ; *s; s++) tbl[*s] |= DIG; for(s = (UINT8*)"()+*%" ; *s; s++) tbl[*s] |= SCS; for(s = (UINT8*)"()+*#[]%" ; *s; s++) tbl[*s] |= GRP; resetToken(); } /* Ok, here comes the nasty part of the decoder. Instead of keeping an explicit state, we deduce it from the token scanned so far. It is then immediately combined with the current character to form a scanning decision. This is done by the following defines. - P is the length of the token scanned so far. - L (often P-1) is the position on which contents we base a decision. - C is a character or a group of characters (taken from 'tbl'). Note that they need to applied in proper order. */ #define lec(P,L,C) (p == (P) && s[(L)] == (C)) #define lun( ) (p == 1 && cc >= 32 ) #define les(P,L,C) (p == (P) && s[L] < 256 && (tbl[s[(L)]] & (C)) == (C)) #define eec(C) (p >= 3 && cc == (C)) #define ees(C) (p >= 3 && cc < 256 && (tbl[ cc ] & (C)) == (C)) #define eps(C) (p >= 3 && s[2] != '?' && cc < 256 && (tbl[ cc ] & (C)) == (C)) #define epp( ) (p >= 3 && s[2] == '?' ) #define egt( ) (p == 3 && s[2] == '>' ) #define Xpe (ppos>=2 && pbuf[1] == ']' ) #define Xte (Xpe && cc == 7 ) #define ces(C) ( cc < 256 && (tbl[ cc ] & (C)) == (C) && !Xte) #define ESC 27 #define CNTL(c) ((c)-'@') // process an incoming unicode character void TEmuVt102::onRcvChar(int cc) { int i; if (cc == 127) return; //VT100: ignore. if (ces( CTL)) { // DEC HACK ALERT! Control Characters are allowed *within* esc sequences in VT100 // This means, they do neither a resetToken nor a pushToToken. Some of them, do // of course. Guess this originates from a weakly layered handling of the X-on // X-off protocol, which comes really below this level. if (cc == CNTL('X') || cc == CNTL('Z') || cc == ESC) resetToken(); //VT100: CAN or SUB if (cc != ESC) { tau( TY_CTL___(cc+'@' ), 0, 0); return; } } pushToToken(cc); // advance the state int* s = pbuf; int p = ppos; if (getMode(MODE_Ansi)) // decide on proper action { if (lec(1,0,ESC)) { return; } if (les(2,1,GRP)) { return; } if (Xte ) { XtermHack(); resetToken(); return; } if (Xpe ) { return; } if (lec(3,2,'?')) { return; } if (lec(3,2,'>')) { return; } if (lun( )) { tau( TY_CHR___(), applyCharset(cc), 0); resetToken(); return; } if (lec(2,0,ESC)) { tau( TY_ESC___(s[1]), 0, 0); resetToken(); return; } if (les(3,1,SCS)) { tau( TY_ESC_CS(s[1],s[2]), 0, 0); resetToken(); return; } if (lec(3,1,'#')) { tau( TY_ESC_DE(s[2]), 0, 0); resetToken(); return; } // if (egt( )) { tau( TY_CSI_PG(cc ), '>', 0); resetToken(); return; } if (eps( CPN)) { tau( TY_CSI_PN(cc), argv[0],argv[1]); resetToken(); return; } if (ees( DIG)) { addDigit(cc-'0'); return; } if (eec( ';')) { addArgument(); return; } for (i=0;i<=argc;i++) if (epp( )) tau( TY_CSI_PR(cc,argv[i]), 0, 0); else tau( TY_CSI_PS(cc,argv[i]), 0, 0); resetToken(); } else // mode VT52 diff --git a/noncore/apps/opie-console/TEmulation.cpp b/noncore/apps/opie-console/TEmulation.cpp index 3b1b9e1..d0169d7 100644 --- a/noncore/apps/opie-console/TEmulation.cpp +++ b/noncore/apps/opie-console/TEmulation.cpp @@ -1,334 +1,331 @@ /* -------------------------------------------------------------------------- */ /* */ /* [TEmulation.cpp] Terminal Emulation Decoder */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /*! \class TEmulation \brief Mediator between TEWidget and TEScreen. This class is responsible to scan the escapes sequences of the terminal emulation and to map it to their corresponding semantic complements. Thus this module knows mainly about decoding escapes sequences and is a stateless device w.r.t. the semantics. It is also responsible to refresh the TEWidget by certain rules. \sa TEWidget \sa TEScreen \par A note on refreshing Although the modifications to the current screen image could immediately be propagated via `TEWidget' to the graphical surface, we have chosen another way here. The reason for doing so is twofold. First, experiments show that directly displaying the operation results in slowing down the overall performance of emulations. Displaying individual characters using X11 creates a lot of overhead. Second, by using the following refreshing method, the screen operations can be completely separated from the displaying. This greatly simplifies the programmer's task of coding and maintaining the screen operations, since one need not worry about differential modifications on the display affecting the operation of concern. We use a refreshing algorithm here that has been adoped from rxvt/kvt. By this, refreshing is driven by a timer, which is (re)started whenever a new bunch of data to be interpreted by the emulation arives at `onRcvBlock'. As soon as no more data arrive for `BULK_TIMEOUT' milliseconds, we trigger refresh. This rule suits both bulk display operation as done by curses as well as individual characters typed. (BULK_TIMEOUT < 1000 / max characters received from keyboard per second). Additionally, we trigger refreshing by newlines comming in to make visual snapshots of lists as produced by `cat', `ls' and likely programs, thereby producing the illusion of a permanent and immediate display operation. As a sort of catch-all needed for cases where none of the above conditions catch, the screen refresh is also triggered by a count of incoming bulks (`bulk_incnt'). */ /* FIXME - evtl. the bulk operations could be made more transparent. */ #include "TEmulation.h" -#include "TEWidget.h" -#include "TEScreen.h" #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <qkeycode.h> /* ------------------------------------------------------------------------- */ /* */ /* TEmulation */ /* */ /* ------------------------------------------------------------------------- */ #define CNTL(c) ((c)-'@') /*! */ TEmulation::TEmulation(TEWidget* gui) : decoder((QTextDecoder*)NULL) { this->gui = gui; screen[0] = new TEScreen(gui->Lines(),gui->Columns()); screen[1] = new TEScreen(gui->Lines(),gui->Columns()); scr = screen[0]; bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter connected = FALSE; QObject::connect(&bulk_timer, SIGNAL(timeout()), this, SLOT(showBulk()) ); QObject::connect(gui,SIGNAL(changedImageSizeSignal(int,int)), this,SLOT(onImageSizeChange(int,int))); QObject::connect(gui,SIGNAL(changedHistoryCursor(int)), this,SLOT(onHistoryCursorChange(int))); QObject::connect(gui,SIGNAL(keyPressedSignal(QKeyEvent*)), this,SLOT(onKeyPress(QKeyEvent*))); QObject::connect(gui,SIGNAL(beginSelectionSignal(const int,const int)), this,SLOT(onSelectionBegin(const int,const int)) ); QObject::connect(gui,SIGNAL(extendSelectionSignal(const int,const int)), this,SLOT(onSelectionExtend(const int,const int)) ); QObject::connect(gui,SIGNAL(endSelectionSignal(const BOOL)), this,SLOT(setSelection(const BOOL)) ); QObject::connect(gui,SIGNAL(clearSelectionSignal()), this,SLOT(clearSelection()) ); } /*! */ TEmulation::~TEmulation() { delete screen[0]; delete screen[1]; bulk_timer.stop(); } /*! change between primary and alternate screen */ void TEmulation::setScreen(int n) { scr = screen[n&1]; } void TEmulation::setHistory(bool on) { screen[0]->setScroll(on); if (!connected) return; showBulk(); } bool TEmulation::history() { return screen[0]->hasScroll(); } void TEmulation::setCodec(int c) { //FIXME: check whether we have to free codec codec = c ? QTextCodec::codecForName("utf8") : QTextCodec::codecForLocale(); if (decoder) delete decoder; decoder = codec->makeDecoder(); } void TEmulation::setKeytrans(int no) { keytrans = KeyTrans::find(no); } void TEmulation::setKeytrans(const char * no) { keytrans = KeyTrans::find(no); } // Interpreting Codes --------------------------------------------------------- /* This section deals with decoding the incoming character stream. Decoding means here, that the stream is first seperated into `tokens' which are then mapped to a `meaning' provided as operations by the `Screen' class. */ /*! */ void TEmulation::onRcvChar(int c) // process application unicode input to terminal // this is a trivial scanner { c &= 0xff; switch (c) { case '\b' : scr->BackSpace(); break; case '\t' : scr->Tabulate(); break; case '\n' : scr->NewLine(); break; case '\r' : scr->Return(); break; case 0x07 : gui->Bell(); break; default : scr->ShowCharacter(c); break; }; } /* ------------------------------------------------------------------------- */ /* */ /* Keyboard Handling */ /* */ /* ------------------------------------------------------------------------- */ /*! */ void TEmulation::onKeyPress( QKeyEvent* ev ) { qWarning("onKeyPress,...."); if (!connected) return; // someone else gets the keys if (scr->getHistCursor() != scr->getHistLines()); scr->setHistCursor(scr->getHistLines()); if (!ev->text().isEmpty()) { // A block of text // Note that the text is proper unicode. // We should do a conversion here, but since this // routine will never be used, we simply emit plain ascii. emit sndBlock(ev->text().ascii(),ev->text().length()); } else if (ev->ascii()>0) { unsigned char c[1]; c[0] = ev->ascii(); emit sndBlock((char*)c,1); } } // Unblocking, Byte to Unicode translation --------------------------------- -- /* We are doing code conversion from locale to unicode first. */ void TEmulation::onRcvBlock(const char *s, int len) { bulkStart(); bulk_incnt += 1; for (int i = 0; i < len; i++) { QString result = decoder->toUnicode(&s[i],1); int reslen = result.length(); for (int j = 0; j < reslen; j++) onRcvChar(result[j].unicode()); if (s[i] == '\n') bulkNewline(); } bulkEnd(); } // Selection --------------------------------------------------------------- -- void TEmulation::onSelectionBegin(const int x, const int y) { if (!connected) return; scr->setSelBeginXY(x,y); showBulk(); } void TEmulation::onSelectionExtend(const int x, const int y) { if (!connected) return; scr->setSelExtentXY(x,y); showBulk(); } void TEmulation::setSelection(const BOOL preserve_line_breaks) { if (!connected) return; QString t = scr->getSelText(preserve_line_breaks); if (!t.isNull()) gui->setSelection(t); } void TEmulation::clearSelection() { if (!connected) return; scr->clearSelection(); showBulk(); } void TEmulation::streamHistory(QTextStream* stream) { *stream << scr->getHistory(); } // Refreshing -------------------------------------------------------------- -- #define BULK_TIMEOUT 20 /*! called when \n comes in. Evtl. triggers showBulk at endBulk */ void TEmulation::bulkNewline() { bulk_nlcnt += 1; bulk_incnt = 0; // reset bulk counter since `nl' rule applies } /*! */ void TEmulation::showBulk() { bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter if (connected) { ca* image = scr->getCookedImage(); // get the image gui->setImage(image, scr->getLines(), scr->getColumns()); // actual refresh free(image); //FIXME: check that we do not trigger other draw event here. gui->setScroll(scr->getHistCursor(),scr->getHistLines()); } } void TEmulation::bulkStart() { if (bulk_timer.isActive()) bulk_timer.stop(); } void TEmulation::bulkEnd() { if ( bulk_nlcnt > gui->Lines() || bulk_incnt > 20 ) showBulk(); // resets bulk_??cnt to 0, too. else bulk_timer.start(BULK_TIMEOUT,TRUE); } void TEmulation::setConnect(bool c) { connected = c; if ( connected) { onImageSizeChange(gui->Lines(), gui->Columns()); showBulk(); } else { scr->clearSelection(); } diff --git a/noncore/apps/opie-console/configdialog.cpp b/noncore/apps/opie-console/configdialog.cpp index 53b3853..b23f4d0 100644 --- a/noncore/apps/opie-console/configdialog.cpp +++ b/noncore/apps/opie-console/configdialog.cpp @@ -1,114 +1,111 @@ -#include <qdialog.h> #include <qlistview.h> -#include "profile.h" #include "configdialog.h" -#include "metafactory.h" #include "profileeditordialog.h" class ConfigListItem : public QListViewItem { public: ConfigListItem( QListView* item, const Profile& ); ~ConfigListItem(); Profile profile()const; private: Profile m_prof; }; ConfigListItem::ConfigListItem( QListView* item, const Profile& prof ) : QListViewItem( item ), m_prof( prof ) { setText(0, prof.name() ); } ConfigListItem::~ConfigListItem() { } Profile ConfigListItem::profile()const { return m_prof; } /* Dialog */ ConfigDialog::ConfigDialog( const Profile::ValueList& lis, MetaFactory* fa, QWidget* parent ) : ConfigureBase( parent, 0, TRUE ), m_fact( fa ) { //init(); { Profile::ValueList::ConstIterator it; for (it = lis.begin(); it != lis.end(); ++it ) { new ConfigListItem( lstView, (*it) ); } } } ConfigDialog::~ConfigDialog() { } Profile::ValueList ConfigDialog::list()const { /* iterate over the list */ Profile::ValueList lst; QListViewItemIterator it(lstView); for ( ; it.current(); ++it ) { ConfigListItem* item = (ConfigListItem*)it.current(); lst.append( item->profile() ); } return lst; } /* our slots */ void ConfigDialog::slotRemove() { ConfigListItem* item = (ConfigListItem*)lstView->currentItem(); if (!item ) return; lstView->takeItem( item ); delete item; } void ConfigDialog::slotEdit() { Profile p; if(!lstView->currentItem()) return; // Load profile p = ((ConfigListItem*)lstView->currentItem())->profile(); ProfileEditorDialog dlg(m_fact, p); dlg.setCaption(tr("Edit Connection Profile")); dlg.showMaximized(); int ret = dlg.exec(); if(ret == QDialog::Accepted) { if(lstView->currentItem()) delete lstView->currentItem(); // use dlg.terminal()! Profile p = dlg.profile(); new ConfigListItem(lstView, p); } } void ConfigDialog::slotAdd() { ProfileEditorDialog dlg(m_fact); dlg.setCaption(tr("New Connection")); dlg.showMaximized(); int ret = dlg.exec(); if(ret == QDialog::Accepted) { // TODO: Move into general profile save part // assignments //QString type = dlg.term_type(); //if(type == "VT102") profile = Profile::VT102; // get profile from editor Profile p = dlg.profile(); new ConfigListItem(lstView, p); } } diff --git a/noncore/apps/opie-console/consoleconfigwidget.cpp b/noncore/apps/opie-console/consoleconfigwidget.cpp index faedc58..a6ad8d2 100644 --- a/noncore/apps/opie-console/consoleconfigwidget.cpp +++ b/noncore/apps/opie-console/consoleconfigwidget.cpp @@ -1,111 +1,109 @@ #include <qlabel.h> #include <qlayout.h> -#include <qcombobox.h> #include <qlineedit.h> #include <qpushbutton.h> #include <qlistview.h> #include <qhbox.h> -#include <qregexp.h> #include <stdio.h> #include <pwd.h> #include <sys/types.h> #include "consoleconfigwidget.h" ConsoleConfigWidget::ConsoleConfigWidget( const QString& name, QWidget* parent, const char* na ) : ProfileDialogConnectionWidget( name, parent, na ) { m_lay = new QVBoxLayout( this ); QLabel *label = new QLabel(tr("Command to execute"), this); m_lay->addWidget(label); m_cmd = new QLineEdit(this); m_lay->addWidget(m_cmd); label = new QLabel(tr("Environment Variables"), this); m_lay->addWidget(label); m_env = new QListView(this); m_env->addColumn(tr("Name")); m_env->addColumn(tr("Value")); m_lay->addWidget(m_env); QHBox *hbox = new QHBox(this); label = new QLabel(tr("Name :"), hbox); m_name = new QLineEdit(hbox); m_lay->addWidget(hbox); hbox = new QHBox(this); label = new QLabel(tr("Value :"), hbox); m_value = new QLineEdit(hbox); m_lay->addWidget(hbox); hbox = new QHBox(this); hbox->setSpacing(10); m_remove = new QPushButton(tr("Remove"), hbox); connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove())); m_add = new QPushButton(tr("Add"), hbox); connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd())); m_lay->addWidget(hbox); } void ConsoleConfigWidget::slotAdd() { if (!(m_name->text().isEmpty() || m_value->text().isEmpty())) { QListViewItem *item = new QListViewItem(m_env); item->setText(0, m_name->text()); item->setText(1, m_value->text()); m_env->insertItem(item); } } void ConsoleConfigWidget::slotRemove() { QListViewItem *item = m_env->currentItem(); if (item) { m_env->takeItem(item); } } ConsoleConfigWidget::~ConsoleConfigWidget() { } void ConsoleConfigWidget::load( const Profile& prof ) { /* * default to the users default shell */ struct passwd *ent = 0; char *shell = "/bin/sh"; while ( (ent = getpwent()) != 0 ) { if (ent->pw_shell != "") { shell = ent->pw_shell; } } m_cmd->setText(prof.readEntry("Command", shell )); int envcount = prof.readNumEntry("EnvVars", 0); for (int i=0; i<envcount; i++) { QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); if (!(name.isEmpty() || value.isEmpty())) { QListViewItem *item = new QListViewItem(m_env); item->setText(0, name); item->setText(1, value); m_env->insertItem(item); } } } void ConsoleConfigWidget::save( Profile& prof ) { prof.writeEntry( "Command", m_cmd->text()); QListViewItem *item = m_env->firstChild(); int counter = 0; while (item) { QString name = item->text(0); QString value = item->text(1); prof.writeEntry("Env_Name_" + QString::number(counter), name); prof.writeEntry("Env_Value_" + QString::number(counter), value); item = item->nextSibling(); counter++; } prof.writeEntry("EnvVars", QString::number(counter)); } diff --git a/noncore/apps/opie-console/default.cpp b/noncore/apps/opie-console/default.cpp index b060139..c237575 100644 --- a/noncore/apps/opie-console/default.cpp +++ b/noncore/apps/opie-console/default.cpp @@ -1,122 +1,121 @@ -#include "io_serial.h" #include "io_irda.h" #include "io_bt.h" #include "io_modem.h" #include "filetransfer.h" #include "filereceive.h" #include "serialconfigwidget.h" #include "irdaconfigwidget.h" #include "btconfigwidget.h" #include "modemconfigwidget.h" #include "terminalwidget.h" #include "function_keyboard.h" #include "consoleconfigwidget.h" #include "MyPty.h" #include "default.h" extern "C" { // FILE Transfer Stuff FileTransferLayer* newSZTransfer(IOLayer* lay) { return new FileTransfer( FileTransfer::SZ, lay ); } FileTransferLayer* newSYTransfer(IOLayer* lay) { return new FileTransfer( FileTransfer::SY, lay ); } FileTransferLayer* newSXTransfer(IOLayer* lay) { return new FileTransfer(FileTransfer ::SX, lay ); } // FILE Transfer Receive Stuff ReceiveLayer* newSZReceive(IOLayer* lay) { return new FileReceive( FileReceive::SZ, lay ); } ReceiveLayer* newSYReceive(IOLayer* lay) { return new FileReceive( FileReceive::SY, lay ); } ReceiveLayer* newSXReceive(IOLayer* lay) { return new FileReceive(FileReceive::SX, lay ); } // Layer stuff IOLayer* newSerialLayer( const Profile& prof) { return new IOSerial( prof ); } IOLayer* newBTLayer( const Profile& prof ) { return new IOBt( prof ); } IOLayer* newIrDaLayer( const Profile& prof ) { return new IOIrda( prof ); } IOLayer* newModemLayer( const Profile& prof ) { return new IOModem( prof ); } IOLayer* newConsole( const Profile& prof ) { return new MyPty( prof ); } // Connection Widgets ProfileDialogWidget* newSerialWidget( const QString& str, QWidget* wid ) { return new SerialConfigWidget( str, wid ); } ProfileDialogWidget* newIrDaWidget( const QString& str, QWidget* wid ) { return new IrdaConfigWidget( str, wid ); } ProfileDialogWidget* newModemWidget( const QString& str, QWidget* wid ) { return new ModemConfigWidget(str, wid ); } ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) { return new BTConfigWidget(str, wid ); } ProfileDialogWidget* newConsoleWid( const QString& str, QWidget* wid ) { return new ConsoleConfigWidget(str, wid ); } // Terminal Widget(s) ProfileDialogWidget* newTerminalWidget(const QString& na, QWidget* wid) { return new TerminalWidget(na, wid,0 ); } // Function Keyboard Widget ProfileDialogWidget* newKeyboardWidget(const QString& na, QWidget *wid) { return new FunctionKeyboardConfig(na, wid); } /* // VT Emulations EmulationLayer* newVT102( WidgetLayer* wid ) { return new Vt102Emulation( wid ); } */ }; Default::Default( MetaFactory* fact ) { fact->addFileTransferLayer( "SZ", QObject::tr("Z-Modem"), newSZTransfer ); fact->addFileTransferLayer( "SY", QObject::tr("Y-Modem"), newSYTransfer ); fact->addFileTransferLayer( "SX", QObject::tr("X-Modem"), newSXTransfer ); fact->addReceiveLayer( "SZ", QObject::tr("Z-Modem"), newSZReceive ); fact->addReceiveLayer( "SY", QObject::tr("Y-Modem"), newSYReceive ); fact->addReceiveLayer( "SX", QObject::tr("X-Modem"), newSXReceive ); fact->addIOLayerFactory( "serial", QObject::tr("Serial"), newSerialLayer ); // fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer ); // fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer ); fact->addIOLayerFactory( "modem", QObject::tr("Modem"), newModemLayer ); fact->addIOLayerFactory( "console", QObject::tr("Local Console"), newConsole ); fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget ); // fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget ); fact->addConnectionWidgetFactory( "modem", QObject::tr("Modem"), newModemWidget ); // fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget ); fact->addConnectionWidgetFactory( "console", QObject::tr("Local Console"), newConsoleWid ); fact->addTerminalWidgetFactory( "default", QObject::tr("Default Terminal"), newTerminalWidget ); fact->addKeyboardWidgetFactory( "defaultKeys", QObject::tr("Default Keyboard"), newKeyboardWidget ); // fact->addEmulationLayer( "default", QObject::tr("Default Terminal"), newVT102 ); } Default::~Default() { } diff --git a/noncore/apps/opie-console/dialdialog.cpp b/noncore/apps/opie-console/dialdialog.cpp index b91727b..6bc1240 100644 --- a/noncore/apps/opie-console/dialdialog.cpp +++ b/noncore/apps/opie-console/dialdialog.cpp @@ -1,101 +1,98 @@ #include <qlayout.h> #include <qlabel.h> -#include <qcombobox.h> -#include <qscrollview.h> #include <qpushbutton.h> -#include <qfont.h> #include <qbuttongroup.h> #include "dialdialog.h" DialDialog::DialDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { setCaption( tr( "Enter number" ) ); QVBoxLayout *mainLayout = new QVBoxLayout( this ); QLabel *textLabel = new QLabel( this ); textLabel->setTextFormat( QLabel::RichText ); textLabel->setText( tr("Enter the number you want to dial. When finished, press ok") ); m_dialLine = new QLineEdit( this ); m_dialLine->setReadOnly( true ); m_dialLine->setFrame( false ); m_dialLine->setAlignment( Qt::AlignLeft ); QFont dialLine_font( m_dialLine->font() ); dialLine_font.setBold( TRUE ); dialLine_font.setPointSize( 18 ); m_dialLine->setFont( dialLine_font ); QWidget* dialWidget = new QWidget( this ); QGridLayout *layout = new QGridLayout( dialWidget , 4, 3 ); QButtonGroup *dialButtons = new QButtonGroup( ); QPushButton *number0 = new QPushButton( dialWidget ); number0->setText( QString( "0" ) ); QFont number0_font( number0->font() ); number0_font.setBold( TRUE ); number0->setFont( number0_font ); layout->addWidget( number0, 4, 1 ); dialButtons->insert( number0 ); int x = 0, y = 0; for ( int i = 0 ; i < 9; i++ ) { QPushButton *number = new QPushButton( dialWidget ); number->setText( QString( "%1" ).arg( i + 1 ) ); QFont number_font( number->font() ); number_font.setBold( TRUE ); number->setFont( number_font ); dialButtons->insert( number ); layout->addWidget( number, x, y ); if ( y < 2 ) { y++; } else { x++; y = 0; } } connect( dialButtons, SIGNAL( clicked( int ) ), this, SLOT( slotEnterNumber( int ) ) ); mainLayout->addStretch( 2 ); mainLayout->addWidget( textLabel ); mainLayout->addStretch( 1 ); mainLayout->addWidget( m_dialLine ); mainLayout->addStretch( 2 ); mainLayout->addWidget( dialWidget ); mainLayout->addStretch( 4 ); } void DialDialog::slotEnterNumber( int number ) { // pretty stupid, just for testing .-) m_number.append(QString("%1").arg(number)); setNumber(m_number); } DialDialog::~DialDialog() { } QString DialDialog::number() { return m_number; } void DialDialog::setNumber( QString number ) { m_dialLine->setText( QString("%1").arg( number ) ); } diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp index 235facb..2c1d888 100644 --- a/noncore/apps/opie-console/emulation_handler.cpp +++ b/noncore/apps/opie-console/emulation_handler.cpp @@ -1,209 +1,206 @@ -#include <qwidget.h> -#include <qpushbutton.h> -#include "TEWidget.h" #include "TEmuVt102.h" #include "profile.h" #include "emulation_handler.h" #include "script.h" EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) : QObject(0, name ) { m_teWid = new TEWidget( parent, "TerminalMain"); // use setWrapAt(0) for classic behaviour (wrap at screen width, no scrollbar) // use setWrapAt(80) for normal console with scrollbar setWrap(prof.readNumEntry("Wrap", 0) ? 0 : 80); m_teWid->setMinimumSize(150, 70 ); m_script = 0; parent->resize( m_teWid->calcSize(80, 24 ) ); m_teEmu = new TEmuVt102(m_teWid ); connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), this, SIGNAL(changeSize(int, int) ) ); connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), this, SLOT(recvEmulation(const char*, int) ) ); m_teEmu->setConnect( true ); m_teEmu->setHistory( TRUE ); load( prof ); } TEmulation* EmulationHandler::emulation() { return m_teEmu; } EmulationHandler::~EmulationHandler() { if (isRecording()) clearScript(); delete m_teEmu; delete m_teWid; } void EmulationHandler::load( const Profile& prof) { m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); int num = prof.readNumEntry("Color"); setColor( foreColor(num), backColor(num) ); m_teWid->setBackgroundColor(backColor(num) ); int term = prof.readNumEntry("Terminal", 0) ; switch(term) { default: case Profile::VT102: case Profile::VT100: m_teEmu->setKeytrans("vt100.keytab"); break; case Profile::Linux: m_teEmu->setKeytrans("linux.keytab"); break; case Profile::XTerm: m_teEmu->setKeytrans("default.Keytab"); break; } } void EmulationHandler::recv( const QByteArray& ar) { m_teEmu->onRcvBlock(ar.data(), ar.count() ); } void EmulationHandler::recvEmulation(const char* src, int len ) { QByteArray ar(len); memcpy(ar.data(), src, sizeof(char) * len ); if (isRecording()) m_script->append(ar); emit send(ar); } QWidget* EmulationHandler::widget() { return m_teWid; } /* * allocate a new table of colors */ void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { ColorEntry table[TABLE_COLORS]; const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); for (int i = 0; i < TABLE_COLORS; i++ ) { if ( i == 0 || i == 10 ) { table[i].color = fore; }else if ( i == 1 || i == 11 ) { table[i].color = back; table[i].transparent = 0; }else { table[i].color = defaultCt[i].color; } } m_teWid->setColorTable(table ); m_teWid->update(); } QFont EmulationHandler::font( int id ) { QString name; int size = 0; switch(id ) { default: // fall through case 0: name = QString::fromLatin1("Micro"); size = 4; break; case 1: name = QString::fromLatin1("Fixed"); size = 7; break; case 2: name = QString::fromLatin1("Fixed"); size = 12; break; } QFont font(name, size, QFont::Normal ); font.setFixedPitch(TRUE ); return font; } QColor EmulationHandler::foreColor(int col) { QColor co; /* we need to switch it */ switch( col ) { default: case Profile::White: /* color is black */ co = Qt::white; break; case Profile::Black: co = Qt::black; break; case Profile::Green: qWarning("Foreground green"); co = Qt::green; break; case Profile::Orange: qWarning("Foreground orange"); co.setRgb( 231, 184, 98 ); break; } return co; } QColor EmulationHandler::backColor(int col ) { QColor co; /* we need to switch it */ switch( col ) { default: case Profile::White: /* color is white */ co = Qt::black; break; case Profile::Black: co = Qt::white; break; case Profile::Green: qWarning("Background black"); co = Qt::black; break; case Profile::Orange: qWarning("Background black"); co = Qt::black; break; } return co; } QPushButton* EmulationHandler::cornerButton() { return m_teWid->cornerButton(); } Script *EmulationHandler::script() { return m_script; } bool EmulationHandler::isRecording() { return (m_script != 0); } void EmulationHandler::startRecording() { if (!isRecording()) m_script = new Script(); } void EmulationHandler::clearScript() { if (isRecording()) { delete m_script; m_script = 0; } } void EmulationHandler::runScript(const Script *script) { emit send(script->script()); } void EmulationHandler::copy() { m_teWid->emitSelection(); } void EmulationHandler::paste() { m_teWid->pasteClipboard(); } void EmulationHandler::setWrap(int columns) { m_teWid->setWrapAt(columns); } diff --git a/noncore/apps/opie-console/emulation_layer.cpp b/noncore/apps/opie-console/emulation_layer.cpp index 6a2679e..2bef801 100644 --- a/noncore/apps/opie-console/emulation_layer.cpp +++ b/noncore/apps/opie-console/emulation_layer.cpp @@ -1,340 +1,337 @@ /* -------------------------------------------------------------------------- */ /* */ /* [emulation_layer.cpp] Terminal Emulation Decoder */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Modified to suit opie-console */ /* */ /* Copyright (C) 2002 by opie developers <opie@handhelds.org> */ /* */ /* -------------------------------------------------------------------------- */ /*! \class EmulationLayer \brief Mediator between Widget and Screen. This class is responsible to scan the escapes sequences of the terminal emulation and to map it to their corresponding semantic complements. Thus this module knows mainly about decoding escapes sequences and is a stateless device w.r.t. the semantics. It is also responsible to refresh the Widget by certain rules. \sa Widget \sa Screen \par A note on refreshing Although the modifications to the current screen image could immediately be propagated via `Widget' to the graphical surface, we have chosen another way here. The reason for doing so is twofold. First, experiments show that directly displaying the operation results in slowing down the overall performance of emulations. Displaying individual characters using X11 creates a lot of overhead. Second, by using the following refreshing method, the screen operations can be completely separated from the displaying. This greatly simplifies the programmer's task of coding and maintaining the screen operations, since one need not worry about differential modifications on the display affecting the operation of concern. We use a refreshing algorithm here that has been adoped from rxvt/kvt. By this, refreshing is driven by a timer, which is (re)started whenever a new bunch of data to be interpreted by the emulation arives at `onRcvBlock'. As soon as no more data arrive for `BULK_TIMEOUT' milliseconds, we trigger refresh. This rule suits both bulk display operation as done by curses as well as individual characters typed. (BULK_TIMEOUT < 1000 / max characters received from keyboard per second). Additionally, we trigger refreshing by newlines comming in to make visual snapshots of lists as produced by `cat', `ls' and likely programs, thereby producing the illusion of a permanent and immediate display operation. As a sort of catch-all needed for cases where none of the above conditions catch, the screen refresh is also triggered by a count of incoming bulks (`bulk_incnt'). */ /* FIXME - evtl. the bulk operations could be made more transparent. */ #include "emulation_layer.h" -#include "widget_layer.h" -#include "screen.h" #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <qkeycode.h> /* ------------------------------------------------------------------------- */ /* */ /* EmulationLayer */ /* */ /* ------------------------------------------------------------------------- */ #define CNTL(c) ((c)-'@') /*! */ EmulationLayer::EmulationLayer( WidgetLayer* gui ) : decoder((QTextDecoder*)NULL) { this->gui = gui; screen[0] = new Screen(gui->lines(),gui->columns()); screen[1] = new Screen(gui->lines(),gui->columns()); scr = screen[0]; bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter connected = FALSE; QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), this,SLOT( onImageSizeChange( int, int ) ) ); QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), this,SLOT( historyCursorChange( int ) ) ); QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), this,SLOT( onKeyPress( QKeyEvent* ) ) ); QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), this,SLOT( onSelectionBegin( const int, const int ) ) ); QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), this,SLOT( onSelectionExtend( const int,const int ) ) ); QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ), this,SLOT( setSelection( const bool ) ) ); QObject::connect(gui,SIGNAL( selectionCleared() ), this,SLOT( clearSelection() ) ); } /*! */ EmulationLayer::~EmulationLayer() { delete screen[0]; delete screen[1]; bulk_timer.stop(); } /*! change between primary and alternate screen */ void EmulationLayer::setScreen(int n) { scr = screen[n&1]; } void EmulationLayer::setHistory(bool on) { screen[0]->setScroll(on); if (!connected) return; showBulk(); } bool EmulationLayer::history() { return screen[0]->hasScroll(); } void EmulationLayer::setCodec(int c) { //FIXME: check whether we have to free codec codec = c ? QTextCodec::codecForName("utf8") : QTextCodec::codecForLocale(); if (decoder) delete decoder; decoder = codec->makeDecoder(); } void EmulationLayer::setKeytrans(int no) { keytrans = KeyTrans::find(no); } void EmulationLayer::setKeytrans(const char * no) { keytrans = KeyTrans::find(no); } // Interpreting Codes --------------------------------------------------------- /* This section deals with decoding the incoming character stream. Decoding means here, that the stream is first seperated into `tokens' which are then mapped to a `meaning' provided as operations by the `Screen' class. */ /*! */ void EmulationLayer::onRcvChar(int c) // process application unicode input to terminal // this is a trivial scanner { c &= 0xff; switch (c) { case '\b' : scr->BackSpace(); break; case '\t' : scr->Tabulate(); break; case '\n' : scr->NewLine(); break; case '\r' : scr->Return(); break; case 0x07 : gui->bell(); break; default : scr->ShowCharacter(c); break; }; } /* ------------------------------------------------------------------------- */ /* */ /* Keyboard Handling */ /* */ /* ------------------------------------------------------------------------- */ /*! */ void EmulationLayer::onKeyPress( QKeyEvent* ev ) { if (!connected) return; // someone else gets the keys if (scr->getHistCursor() != scr->getHistLines()); scr->setHistCursor(scr->getHistLines()); if (!ev->text().isEmpty()) { // A block of text // Note that the text is proper unicode. // We should do a conversion here, but since this // routine will never be used, we simply emit plain ascii. sendString( ev->text().ascii() ); //,ev->text().length()); } else if (ev->ascii()>0) { QByteArray c = QByteArray( 1 ); c.at( 0 ) = ev->ascii(); // ibot: qbytearray is emited not char* emit sndBlock( (QByteArray) c ); } } // Unblocking, Byte to Unicode translation --------------------------------- -- /* We are doing code conversion from locale to unicode first. */ void EmulationLayer::onRcvBlock(const QByteArray &s ) { bulkStart(); bulk_incnt += 1; for (int i = 0; i < s.size(); i++) { //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? QString result = decoder->toUnicode(&s[i],1); int reslen = result.length(); for (int j = 0; j < reslen; j++) onRcvChar(result[j].unicode()); if (s[i] == '\n') bulkNewline(); } bulkEnd(); } // Selection --------------------------------------------------------------- -- void EmulationLayer::onSelectionBegin(const int x, const int y) { if (!connected) return; scr->setSelBeginXY(x,y); showBulk(); } void EmulationLayer::onSelectionExtend(const int x, const int y) { if (!connected) return; scr->setSelExtentXY(x,y); showBulk(); } void EmulationLayer::setSelection(const BOOL preserve_line_breaks) { if (!connected) return; QString t = scr->getSelText(preserve_line_breaks); if (!t.isNull()) gui->setSelection(t); } void EmulationLayer::clearSelection() { if (!connected) return; scr->clearSelection(); showBulk(); } // Refreshing -------------------------------------------------------------- -- #define BULK_TIMEOUT 20 /*! called when \n comes in. Evtl. triggers showBulk at endBulk */ void EmulationLayer::bulkNewline() { bulk_nlcnt += 1; bulk_incnt = 0; // reset bulk counter since `nl' rule applies } /*! */ void EmulationLayer::showBulk() { bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter if (connected) { QArray<Character> image = scr->getCookedImage(); // get the image gui->setImage(image, scr->getLines(), scr->getColumns()); // actual refresh delete image; //FIXME: check that we do not trigger other draw event here. gui->setScroll(scr->getHistCursor(),scr->getHistLines()); } } void EmulationLayer::bulkStart() { if (bulk_timer.isActive()) bulk_timer.stop(); } void EmulationLayer::bulkEnd() { if ( bulk_nlcnt > gui->lines() || bulk_incnt > 20 ) showBulk(); // resets bulk_??cnt to 0, too. else bulk_timer.start(BULK_TIMEOUT,TRUE); } void EmulationLayer::setConnect(bool c) { connected = c; if ( connected) { onImageSizeChange(gui->lines(), gui->columns()); showBulk(); } else { scr->clearSelection(); diff --git a/noncore/apps/opie-console/emulation_widget.cpp b/noncore/apps/opie-console/emulation_widget.cpp index 9f95c72..ad8ecba 100644 --- a/noncore/apps/opie-console/emulation_widget.cpp +++ b/noncore/apps/opie-console/emulation_widget.cpp @@ -1,268 +1,260 @@ // opie-console includes #include "emulation_widget.h" -#include "common.h" -#include "widget_layer.h" -#include "profile.h" // qt includes -#include <qwidget.h> -#include <qarray.h> -#include <qstring.h> -#include <qpainter.h> -#include <qrect.h> #include <qscrollbar.h> #define rimX 0 // left/right rim width #define rimY 0 // top/bottom rim high static const ColorEntry color_table[TABLE_COLORS] = { ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White // intensiv ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) }; EmulationWidget::EmulationWidget( const Profile& config, QWidget *parent, const char* name ) : WidgetLayer( config, parent, name ) { // initialize font attributes QFontMetrics fm( font() ); f_height = fm.height(); f_width = fm.maxWidth(); f_ascent = fm.ascent(); // initialize scrollbar related vars m_scrollbar = new QScrollBar( this ); m_scrollbar->setCursor( arrowCursor ); // give reasonable defaults to m_columns, m_lines calcGeometry(); // load config reloadConfig( config ); m_resizing = false; } void EmulationWidget::reloadConfig( const Profile& config ) { // nothing yet } EmulationWidget::~EmulationWidget() { //clean up } static QChar vt100extended(QChar c) { switch (c.unicode()) { case 0x25c6 : return 1; case 0x2592 : return 2; case 0x2409 : return 3; case 0x240c : return 4; case 0x240d : return 5; case 0x240a : return 6; case 0x00b0 : return 7; case 0x00b1 : return 8; case 0x2424 : return 9; case 0x240b : return 10; case 0x2518 : return 11; case 0x2510 : return 12; case 0x250c : return 13; case 0x2514 : return 14; case 0x253c : return 15; case 0xf800 : return 16; case 0xf801 : return 17; case 0x2500 : return 18; case 0xf803 : return 19; case 0xf804 : return 20; case 0x251c : return 21; case 0x2524 : return 22; case 0x2534 : return 23; case 0x252c : return 24; case 0x2502 : return 25; case 0x2264 : return 26; case 0x2265 : return 27; case 0x03c0 : return 28; case 0x2260 : return 29; case 0x00a3 : return 30; case 0x00b7 : return 31; } return c; } QSize EmulationWidget::calcSize( int cols, int lins ) const { int frw = width() - contentsRect().width(); int frh = height() - contentsRect().height(); int scw = (scrollLoc == SCRNONE? 0 : m_scrollbar->width() ); return QSize( f_width * cols + 2 * rimX + frw + scw, f_height * lins + 2 * rimY + frh ); } void EmulationWidget::setImage( QArray<Character> const newimg, int lines, int columns ) { const QPixmap* pm = backgroundPixmap(); QPainter paint; // dont allow updates, while drawing setUpdatesEnabled( false ); paint.begin( this ); QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); // hasBlinker = false; int cf = -1; int cb = -1; int cr = -1; int lins = QMIN( m_lines, QMAX( 0, lines ) ); int cols = QMIN( m_columns, QMAX( 0, columns ) ); QArray<QChar> disstrU = QArray<QChar>( cols ); for ( int y = 0; y < lins; ++y ) { int len; const Character* lcl = &m_image[y * m_columns]; const Character* ext = &newimg[y * m_columns]; if ( ! m_resizing ) for ( int x = 0; x < cols; ++x ) { // disable, till widget works, WITHOUT blinking //hasBlinker |= ( ext[x].r & RE_BLINK ); if ( ext[x] != lcl[x] ) { cr = ext[x].r; cb = ext[x].b; if ( ext[x].f != cf ) cf = ext[x].f; int lln = cols - x; disstrU[0] = vt100extended( ext[x+0].c ); for ( len = 1; len < lln; ++len ) { if ( ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || ext[x+len] == lcl[x+len] ) break; disstrU[len] = vt100extended( ext[x+len].c ); } QString unistr( disstrU, len ); drawAttrString( unistr, paint, QRect( m_blX+tLx+f_width*x, m_bY+tLy+f_height*y, f_width*len, f_height ), ext[x], pm != NULL, true ); x += len -1; } } // make image become newimg memcpy( (void*) lcl, (const void*) ext, cols*sizeof( Character ) ); } drawFrame( &paint ); paint.end(); setUpdatesEnabled( true ); /*if ( hasBlinker && !blinkT->isActive() ) blinkT->start(1000); //ms if ( ! hasBlinker && blinkT->isActive() ) { blinkT->stop(); blinking = false; }*/ delete [] disstrU; } void EmulationWidget::paintEvent( QPaintEvent* pe ) { QPainter painter; const QPixmap* pm = backgroundPixmap(); painter.begin( this ); painter.setBackgroundMode( TransparentMode ); QRect rect = pe->rect().intersect( contentsRect() ); QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); int lux = QMIN(m_columns-1, QMAX(0,(rect.left() - tLx - m_blX ) / f_width)); int luy = QMIN(m_lines-1, QMAX(0,(rect.top() - tLy - m_bY ) / f_height)); int rlx = QMIN(m_columns-1, QMAX(0,(rect.right() - tLx - m_blX ) / f_width)); int rly = QMIN(m_lines-1, QMAX(0,(rect.bottom() - tLy - m_bY ) / f_height)); QChar *disstrU = new QChar[m_columns]; for (int y = luy; y <= rly; y++) for (int x = lux; x <= rlx; x++) { int len = 1; disstrU[0] = vt100extended(m_image[loc(x,y)].c); int cf = m_image[loc(x,y)].f; int cb = m_image[loc(x,y)].b; int cr = m_image[loc(x,y)].r; while (x+len <= rlx && m_image[loc(x+len,y)].f == cf && m_image[loc(x+len,y)].b == cb && m_image[loc(x+len,y)].r == cr ) { disstrU[len] = vt100extended(m_image[loc(x+len,y)].c); len += 1; } QString unistr(disstrU,len); drawAttrString( unistr, painter, QRect( m_blX+tLx+f_width*x,m_bY+tLy+f_height*y,f_width*len,f_height ), m_image[loc(x ,y )], pm != 0l, false ); x +=len -1; } delete [] disstrU; drawFrame( &painter ); painter.end(); } void EmulationWidget::calcGeometry() { m_scrollbar->resize(QApplication::style().scrollBarExtent().width(), contentsRect().height() ); qDebug( QString(" TEST").arg( contentsRect().width() ) ); qDebug( QString(" TEST").arg( contentsRect().height() ) ); qDebug("NEUER TESTT!!!!!!!!"); switch( scrollLoc ) { case SCRNONE : m_columns = ( contentsRect().width() -2 * rimX ) / f_width; m_blX = ( contentsRect().width() - ( m_columns*f_width ) ) / 2; m_brX = m_blX; m_scrollbar->hide(); break; case SCRLEFT : m_columns = ( contentsRect().width() - 2 * rimX - m_scrollbar->width() ) / f_width; m_brX = ( contentsRect().width() - ( m_columns*f_width ) - m_scrollbar->width() ) / 2; m_blX = m_brX + m_scrollbar->width(); m_scrollbar->move( contentsRect().topLeft() ); m_scrollbar->show(); break; case SCRIGHT: m_columns = ( contentsRect().width() - 2 * rimX - m_scrollbar->width() ) / f_width; m_blX = ( contentsRect().width() - ( m_columns*f_width ) - m_scrollbar->width() ) / 2; m_brX = m_blX; m_scrollbar->move( contentsRect().topRight() - QPoint (m_scrollbar->width()-1,0 ) ); m_scrollbar->show(); break; } m_lines = ( contentsRect().height() - 2 * rimY ) / f_height; m_bY = ( contentsRect().height() - (m_lines * f_height ) ) / 2; } void EmulationWidget::drawAttrString( QString& string, QPainter &painter, QRect rect, Character attr, bool usePixmap, bool clear ) { diff --git a/noncore/apps/opie-console/file_layer.cpp b/noncore/apps/opie-console/file_layer.cpp index 0c83700..9ddef80 100644 --- a/noncore/apps/opie-console/file_layer.cpp +++ b/noncore/apps/opie-console/file_layer.cpp @@ -1,23 +1,22 @@ -#include <qfile.h> #include <opie/oprocess.h> #include "file_layer.h" FileTransferLayer::FileTransferLayer(IOLayer *layer) : QObject(), m_layer( layer ) { } FileTransferLayer::~FileTransferLayer() { } void FileTransferLayer::sendFile(const QFile&) { } void FileTransferLayer::sendFile(const QString&) { } IOLayer* FileTransferLayer::layer() { return m_layer; } diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp index 5144941..347d6e0 100644 --- a/noncore/apps/opie-console/filetransfer.cpp +++ b/noncore/apps/opie-console/filetransfer.cpp @@ -1,251 +1,250 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> -#include <qcstring.h> #include <qsocketnotifier.h> #include <opie/oprocess.h> #include "procctl.h" #include "filetransfer.h" FileTransfer::FileTransfer( Type t, IOLayer* lay ) : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) { signal(SIGPIPE, SIG_IGN ); m_pid = 0; m_not = 0l; m_proc = 0l; } FileTransfer::~FileTransfer() { } /** * now we will send the file. * * we request an fd. The IOLayer should be closed * then we will setup a pipe for progress communication * then we will dup2 the m_fd in the forked process * to do direct IO from and to the fd */ void FileTransfer::sendFile( const QString& file ) { m_prog =-1; m_fd = layer()->rawIO(); // // m_fd = ::open("/dev/ttyS0", O_RDWR); m_file = file; if ( pipe( m_comm ) < 0 ) m_comm[0] = m_comm[1] = 0; if ( pipe( m_info ) < 0 ) m_info[0] = m_info[1] = 0; m_pid = fork(); switch( m_pid ) { case -1: emit error( StartError, tr("Was not able to fork") ); slotExec(); break; case 0:{ setupChild(); /* exec */ char* verbose = "-vv"; char* binray = "-b"; char* typus; switch(m_type ) { default: case SZ: typus = ""; break; case SX: typus = "-X"; break; case SY: typus = "--ymodem"; break; } /* we should never return from here */ execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); /* communication for error!*/ char resultByte =1; if (m_info[1] ) write(m_info[1], &resultByte, 1 ); _exit( -1 ); break; } default:{ if ( m_info[1] ) close( m_info[1] ); if ( m_info[0] ) for (;;) { char resultByte; int len; len = read(m_info[0], &resultByte, 1 ); /* len == 1 start up failed */ if ( len == 1 ) { emit error( StartError, tr("Could not start") ); return; } if ( len == -1 ) if ( (errno == ECHILD ) || (errno == EINTR ) ) continue; // len == 0 or something like this break; } if ( m_info[0] ) close( m_info[0] ); /* replace by QSocketNotifier!!! */ m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); connect(m_not, SIGNAL(activated(int) ), this, SLOT(slotRead() ) ); if ( pipe(m_term) < 0 ) m_term[0] = m_term[1] = 0; ProcCtl::self()->add(m_pid, m_term[1] ); m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); connect(m_proc, SIGNAL(activated(int) ), this, SLOT(slotExec() ) ); } break; } } /* * let's call the one with the filename */ void FileTransfer::sendFile( const QFile& file ) { sendFile( file.name() ); } /* * setting up communication * between parent child and ioLayer */ void FileTransfer::setupChild() { /* * we do not want to read from our * information channel */ if (m_info[0] ) close(m_info[0] ); /* * FD_CLOEXEC will close the * fd on successful exec */ if (m_info[1] ) fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); if (m_comm[0] ) close( m_comm[0] ); /* * now set the communication * m_fd STDIN_FILENO * STDOUT_FILENO * STDERR_FILENO */ dup2( m_fd, STDIN_FILENO ); dup2( m_fd, STDOUT_FILENO ); dup2( m_comm[1], STDERR_FILENO ); } /* * read from the stderr of the child * process */ void FileTransfer::slotRead() { QByteArray ar(4096); int len = read(m_comm[0], ar.data(), 4096 ); for (int i = 0; i < len; i++ ) { // printf("%c", ar[i] ); } ar.resize( len ); QString str( ar ); QStringList lis = QStringList::split(' ', str ); /* * Transfer finished.. either complete or incomplete */ if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { return; } /* * do progress reading */ slotProgress( lis ); } /* * find the progress */ void FileTransfer::slotProgress( const QStringList& list ) { if ( m_type != SZ ) return; bool complete = true; int min, sec; int bps; unsigned long sent, total; min = sec = bps = -1; sent = total = 0; // Data looks like this // 0 1 2 3 4 5 // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); sent = progi[0].toULong(&complete ); if (!complete ) return; total = progi[1].toULong(&complete ); if (!complete || total == 0) { return; } double pro = (double)sent/total; int prog = pro * 100; // speed progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); bps = progi[1].toInt(); // time progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); min = progi[0].toInt(); sec = progi[1].toInt(); if ( prog > m_prog ) { m_prog = prog; emit progress(m_file, m_prog, bps, -1, min , sec ); } } void FileTransfer::cancel() { if(m_pid > 0) ::kill(m_pid,9 ); } void FileTransfer::slotExec() { char buf[2]; ::read(m_term[0], buf, 1 ); delete m_proc; delete m_not; m_proc = m_not = 0l; close( m_term[0] ); close( m_term[1] ); close( m_comm[0] ); close( m_comm[1] ); layer()->closeRawIO( m_fd ); emit sent(); m_pid = 0; } diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp index 0191915..c232d89 100644 --- a/noncore/apps/opie-console/function_keyboard.cpp +++ b/noncore/apps/opie-console/function_keyboard.cpp @@ -1,269 +1,261 @@ #include "function_keyboard.h" -#include <qpe/resource.h> -#include <qpe/qpeapplication.h> -#include <qsizepolicy.h> -#include <qevent.h> -#include <qwindowsystem_qws.h> -#include <qapplication.h> #include <qlayout.h> -#include <qspinbox.h> #include <qlistbox.h> #include <qlabel.h> -#include <qcombobox.h> #include <qdir.h> #define DEFAULT_ROWS 2 #define DEFAULT_COLS 12 /* FunctionKeyboard {{{1 */ FunctionKeyboard::FunctionKeyboard(QWidget *parent) : QFrame(parent), numRows(DEFAULT_ROWS), numCols(DEFAULT_COLS), pressedRow(0), pressedCol(0) { setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); /* * all the saving/loading is now done in a profile. downside is that you cant modify * the keyboard for all profiles, but must do it on a profile-basis * Config conf("opie-console-keys"); conf.setGroup("keys"); for (uint r = 0; r < numRows; r++) for (uint c = 0; c < numCols; c++) { QString handle = "r" + QString::number(r) + "c" + QString::number(c); QStringList value_list = conf.readListEntry( handle, '|'); if (value_list.isEmpty()) continue; keys.insert( handle, FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort()) ); } //qWarning("loaded %d keys", keys.count()); */ if (keys.isEmpty()) loadDefaults(); } FunctionKeyboard::~FunctionKeyboard() {} void FunctionKeyboard::changeRows(int r) { numRows = r; // have to do this so the whole thing gets redrawn hide(); show(); } void FunctionKeyboard::changeCols(int c) { numCols = c; keyWidth = (double)width()/numCols; // have to reset this thing too repaint(false); } void FunctionKeyboard::load (const Profile& prof) { keys.clear(); numRows = prof.readNumEntry("keb_rows", 2); numCols = prof.readNumEntry("keb_cols", 10); keyWidth = (double)width()/numCols; // have to reset this thing too /* load all the keys to the keyboard */ for (ushort i = 0; i <= numRows - 1; i++) for (ushort j = 0; j <= numCols - 1; j++) { QString h = "r" + QString::number(i) + "c" + QString::number(j); QString values = prof.readEntry("keb_" + h); if (!values.isEmpty()) { QStringList l = QStringList::split(QChar('|'), values, TRUE); keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt()); // load pixmap if used if (!l[1].isEmpty()) { keys[h].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + l[1] ) ); } } } if (keys.isEmpty()) loadDefaults(); hide(); show(); } void FunctionKeyboard::paintEvent(QPaintEvent *e) { QPainter p(this); p.setClipRect(e->rect()); p.fillRect(0, 0, width(), height(), QColor(255,255,255)); p.setPen(QColor(0,0,0)); /* those decimals do count! becomes short if use plain int */ for (double i = 0; i <= width(); i += keyWidth) { p.drawLine((int)i, 0, (int)i, height()); } // sometimes the last line doesnt get drawn p.drawLine(width() -1, 0, width() -1, height()); for (int i = 0; i <= height(); i += keyHeight) { p.drawLine(0, i, width(), i); } for (uint r = 0; r < numRows; r++) { for (uint c = 0; c < numCols; c++) { QString handle = "r" + QString::number(r) + "c" + QString::number(c); if (keys.contains(handle)) { if (keys[handle].pixFile.isEmpty()) p.drawText( c * keyWidth + 1, r * keyHeight + 1, keyWidth, keyHeight, Qt::AlignHCenter | Qt::AlignVCenter, keys[handle].label ); else { ushort centerX = (ushort)(c *keyWidth) + (ushort)(keyWidth - keys[handle].pix->width()) / 2; ushort centerY = r * keyHeight + (keyHeight - keys[handle].pix->height()) / 2; p.drawPixmap(centerX, centerY, *keys[handle].pix); } } } } } void FunctionKeyboard::paintKey(uint row, uint col) { QPainter p(this); p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); QString handle ("r" + QString::number(row) + "c" + QString::number(col)); if (keys[handle].pixFile.isEmpty()) p.drawText( col * keyWidth + 1, row * keyHeight + 1, keyWidth, keyHeight, Qt::AlignHCenter | Qt::AlignVCenter, keys[handle].label ); else { ushort centerX = (ushort)(col *keyWidth) + (ushort)(keyWidth - keys[handle].pix->width()) / 2; ushort centerY = row * keyHeight + (keyHeight - keys[handle].pix->height()) / 2; p.drawPixmap(centerX, centerY, *keys[handle].pix); } if (col == numCols - 1) { // sometimes it doesnt draw the last line p.drawLine((col+1) * keyWidth -1, row * keyHeight, (col+1) * keyWidth -1, (row + 1) * keyHeight ); } } void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { pressedRow = e->y() / keyHeight; pressedCol = (int) (e->x() / keyWidth); paintKey(pressedRow, pressedCol); // emit that sucker! FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; emit keyPressed(k, pressedRow, pressedCol, 1); } void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { if (pressedRow != -1 && pressedRow != -1) { int row = pressedRow; pressedRow = -1; int col = pressedCol; pressedCol = -1; paintKey(row, col); FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; emit keyPressed(k, row, col, 0); } } void FunctionKeyboard::resizeEvent(QResizeEvent*) { /* set he default font height/width */ QFontMetrics fm=fontMetrics(); keyHeight = fm.lineSpacing() + 2; keyWidth = (double)width()/numCols; } QSize FunctionKeyboard::sizeHint() const { return QSize(width(), keyHeight * numRows + 1); } void FunctionKeyboard::loadDefaults() { numRows = DEFAULT_ROWS; numCols = DEFAULT_COLS; keyWidth = (double)width()/numCols; // have to reset this thing too keys.insert( "r0c0", FKey ("Enter", "enter", Qt::Key_Enter, 0)); keys.insert( "r0c1", FKey ("Space", "space", Qt::Key_Space, Qt::Key_Space)); keys.insert( "r0c2", FKey ("Tab", "tab", Qt::Key_Tab, 0)); keys.insert( "r0c3", FKey ("Up", "up", Qt::Key_Up, 0)); keys.insert( "r0c4", FKey ("Down", "down", Qt::Key_Down, 0)); keys.insert( "r0c7", FKey ("Ho", 0, 4112, 0)); keys.insert( "r0c8", FKey ("End", 0, 4113, 0)); keys.insert( "r0c9", FKey ("Pu", 0, 4118, 0)); keys.insert( "r0c10", FKey ("Pd", 0, 4119, 0)); keys.insert( "r0c11", FKey ("Esc", 0, Qt::Key_Escape, 0xfff)); keys.insert( "r1c0", FKey ("F1", 0, 4144, 0)); keys.insert( "r1c1", FKey ("F2", 0, 4145, 0)); keys.insert( "r1c2", FKey ("F3", 0, 4146, 0)); keys.insert( "r1c3", FKey ("F4", 0, 4147, 0)); keys.insert( "r1c4", FKey ("F5", 0, 4148, 0)); keys.insert( "r1c5", FKey ("F6", 0, 4149, 0)); keys.insert( "r1c6", FKey ("F7", 0, 4150, 0)); keys.insert( "r1c7", FKey ("F8", 0, 4151, 0)); keys.insert( "r1c8", FKey ("F9", 0, 4152, 0)); keys.insert( "r1c9", FKey ("F10", 0, 4153, 0)); keys.insert( "r1c10", FKey ("F11", 0, 4154, 0)); keys.insert( "r1c11", FKey ("F12", 0, 4155, 0)); } /* FunctionKeyboardConfig {{{1 */ FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na ) : ProfileDialogKeyWidget(name, parent, na), selectedRow(0), selectedCol(0) { qWarning("FunctionKeyboardConfig"); diff --git a/noncore/apps/opie-console/iolayerbase.cpp b/noncore/apps/opie-console/iolayerbase.cpp index ba7c86e..b434e66 100644 --- a/noncore/apps/opie-console/iolayerbase.cpp +++ b/noncore/apps/opie-console/iolayerbase.cpp @@ -1,239 +1,237 @@ #include <qlabel.h> #include <qlayout.h> #include <qcombobox.h> -#include <qbuttongroup.h> #include <qhbuttongroup.h> #include <qradiobutton.h> -#include <qhbox.h> #include "iolayerbase.h" namespace { enum ParityIds { id_parity_none, id_parity_odd, id_parity_even }; enum FlowIds { id_flow_hw, id_flow_sw, id_flow_none, }; enum SpeedIds { id_baud_115200, id_baud_57600, id_baud_38400, id_baud_19200, id_baud_9600 }; enum DataIds { id_data_5, id_data_6, id_data_7, id_data_8 }; enum StopIds { id_stop_1, id_stop_1_5, id_stop_2 }; } IOLayerBase::IOLayerBase( QWidget* par, const char* name ) : QWidget( par, name ) { m_speedLabel = new QLabel(tr("Speed"), this ); m_speedBox = new QComboBox(this ); m_groupFlow = new QHButtonGroup(tr("Flow control"),this ); m_flowHw = new QRadioButton(tr("Hardware"), m_groupFlow ); m_flowSw = new QRadioButton(tr("Software"), m_groupFlow ); m_flowNone = new QRadioButton( tr("None"), m_groupFlow ); m_groupParity = new QHButtonGroup(tr("Parity"), this ); m_parityNone = new QRadioButton(tr("None"), m_groupParity ); m_parityOdd = new QRadioButton(tr("Odd"), m_groupParity ); m_parityEven = new QRadioButton(tr("Even"), m_groupParity ); m_groupData = new QHButtonGroup(tr("Data Bits"), this); m_data5 = new QRadioButton(tr("5"), m_groupData ); m_data6 = new QRadioButton(tr("6"), m_groupData ); m_data7 = new QRadioButton(tr("7"), m_groupData ); m_data8 = new QRadioButton(tr("8"), m_groupData ); m_groupStop = new QHButtonGroup(tr("Stop Bits"), this ); m_stop1 = new QRadioButton(tr("1"), m_groupStop ); m_stop15 = new QRadioButton(tr("1.5"), m_groupStop ); m_stop2 = new QRadioButton(tr("2"), m_groupStop ); m_lroot = new QVBoxLayout( this ); m_lroot->add(m_speedLabel ); m_lroot->add(m_speedBox ); m_lroot->add(m_groupFlow ); m_lroot->add(m_groupParity ); m_lroot->add( m_groupData ); m_lroot->add( m_groupStop ); m_lroot->addStretch(2); // profiles m_speedBox->insertItem(tr("115200 baud"), id_baud_115200 ); m_speedBox->insertItem(tr("57600 baud"), id_baud_57600 ); m_speedBox->insertItem(tr("38400 baud"), id_baud_38400 ); m_speedBox->insertItem(tr("19200 baud"), id_baud_19200 ); m_speedBox->insertItem(tr("9600 baud"), id_baud_9600 ); }; IOLayerBase::~IOLayerBase() { } void IOLayerBase::setFlow( Flow flo ) { switch ( flo ) { case Software: m_flowSw->setChecked( true ); break; case Hardware: m_flowHw->setChecked( true ); break; case None: m_flowNone->setChecked( true ); break; } } void IOLayerBase::setParity( Parity par ) { switch( par ) { case NonePar: m_parityNone->setChecked( true ); break; case Odd: m_parityOdd->setChecked( true ); break; case Even: m_parityEven->setChecked( true ); break; } } void IOLayerBase::setSpeed( Speed sp ) { int index = -1; switch( sp ) { case Baud_115200: index = id_baud_115200; break; case Baud_57600: index = id_baud_57600; break; case Baud_38400: index = id_baud_38400; break; case Baud_19200: index = id_baud_19200; break; default: case Baud_9600: index = id_baud_9600; break; } m_speedBox->setCurrentItem(index ); } void IOLayerBase::setData( Data data ) { switch( data ) { case Data_Five: m_data5->setChecked( true ); break; case Data_Six: m_data6->setChecked( true ); break; case Data_Seven: m_data7->setChecked( true ); break; default: m_data8->setChecked( true ); break; } } void IOLayerBase::setStop( Stop stop ) { switch( stop ) { case Stop_Two: m_stop2->setChecked( true ); break; case Stop_OnePointFive: m_stop15->setChecked( true ); break; default: m_stop1->setChecked( true ); break; } } IOLayerBase::Flow IOLayerBase::flow()const { if (m_flowHw->isChecked() ) { return Hardware; }else if( m_flowSw->isChecked() ) { return Software; } else { return None; } } IOLayerBase::Parity IOLayerBase::parity()const { if ( m_parityOdd->isChecked() ) { return Odd; } else if ( m_parityEven->isChecked() ) { return Even; } else { return NonePar; } } IOLayerBase::Speed IOLayerBase::speed()const{ switch( m_speedBox->currentItem() ) { case id_baud_115200: return Baud_115200; break; case id_baud_57600: return Baud_57600; break; case id_baud_38400: return Baud_38400; break; case id_baud_19200: return Baud_19200; break; default: case id_baud_9600: return Baud_9600; break; } } IOLayerBase::Data IOLayerBase::data()const { if ( m_data5->isChecked() ) { return Data_Five; } else if ( m_data6->isChecked() ) { return Data_Six; } else if ( m_data7->isChecked() ) { return Data_Seven; } else { return Data_Eight; } } IOLayerBase::Stop IOLayerBase::stop()const { if ( m_stop2->isChecked() ) { return Stop_Two; } else if ( m_stop15->isChecked() ) { return Stop_OnePointFive; } else { return Stop_One; } } diff --git a/noncore/apps/opie-console/main.cpp b/noncore/apps/opie-console/main.cpp index 228db57..dfb2f83 100644 --- a/noncore/apps/opie-console/main.cpp +++ b/noncore/apps/opie-console/main.cpp @@ -1,111 +1,110 @@ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> -#include <qfile.h> #include <qpe/qpeapplication.h> #include "mainwindow.h" //#define FSCKED_DISTRIBUTION 1 #ifdef FSCKED_DISTRIBUTION /* * The Zaurus rom */ class FixIt { public: FixIt(); ~FixIt(); void fixIt(); /* no real interested in implementing it */ void breakIt() { }; char* m_file; }; FixIt::FixIt() { /* the new inittab */ m_file = "#\n# /etc/inittab" "#" "" "# 0 - halt (Do NOT set initdefault to this)" "# 1 - Single user mode" "# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)" "# 3 - Full multiuser mode" "# 4 - JavaVM(Intent) developer mode" "# 5 - JavaVM(Intent)" "# 6 - reboot (Do NOT set initdefault to this)" "#" "id:5:initdefault:" "" "# Specify things to do when starting" "si::sysinit:/etc/rc.d/rc.sysinit" "" "l0:0:wait:/root/etc/rc.d/rc 0" "l1:1:wait:/etc/rc.d/rc 1" "l2:2:wait:/etc/rc.d/rc 2" "l3:3:wait:/etc/rc.d/rc 3" "l4:4:wait:/etc/rc.d/rc 4" "l5:5:wait:/etc/rc.d/rc 5" "l6:6:wait:/root/etc/rc.d/rc 6" "" "# Specify things to do before rebooting" "um::ctrlaltdel:/bin/umount -a -r > /dev/null 2>&1" "sw::ctrlaltdel:/sbin/swapoff -a > /dev/null 2>&1" "" "# Specify program to run on ttyS0" "s0:24:respawn:/sbin/getty 9600 ttyS0" "#pd:5:respawn:/etc/sync/serialctl" "" "# Specify program to run on tty1" "1:2:respawn:/sbin/getty 9600 tty1" "ln:345:respawn:survive -l 6 /sbin/launch" "#qt:5:respawn:/sbin/qt" "" "# collie sp." "sy::respawn:/sbin/shsync\n"; } FixIt::~FixIt() { } /* * the retail Zaurus is broken in many ways * one is that pppd is listening on our port... * we've to stop it from that and then do kill(SIGHUP,1); */ void FixIt::fixIt() { ::rename("/etc/inittab", QPEApplication::qpeDir() + "/etc/inittab" ); QFile file( "/etc/inittab" ); if ( file.open(IO_WriteOnly | IO_Raw ) ) { file.writeBlock(m_file,strlen(m_file) ); } file.close(); ::kill( SIGHUP, 1 ); } #endif int main(int argc, char **argv) { // too bad this gives us trouble the taskbar... argv[0]="embeddedkonsole"; QPEApplication app( argc, argv ); #ifdef FSCKED_DISTRIBUTION qWarning("fscked"); FixIt it; it.fixIt(); #endif MainWindow mw; mw.setCaption(QObject::tr("Opie Console") ); app.showMainWidget( &mw ); int ap = app.exec(); #ifdef FSCKED_DISTRIBUTION /* should add a signal handler too */ it.breakIt(); #endif return ap; } diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index 3c9603c..2673335 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp @@ -1,283 +1,273 @@ #include <assert.h> #include <qaction.h> #include <qmenubar.h> -#include <qlabel.h> -#include <qpopupmenu.h> #include <qtoolbar.h> #include <qmessagebox.h> -#include <qpushbutton.h> #include <qwhatsthis.h> #include <qfileinfo.h> -#include <qtextstream.h> -#include <qpe/resource.h> -#include <qpe/qpeapplication.h> #include <qpe/filemanager.h> -#include <qpe/mimetype.h> #include <opie/ofiledialog.h> #include "TEmulation.h" -#include "keytrans.h" #include "profileeditordialog.h" #include "configdialog.h" #include "default.h" -#include "metafactory.h" -#include "profile.h" #include "profilemanager.h" #include "mainwindow.h" #include "tabwidget.h" #include "transferdialog.h" #include "function_keyboard.h" #include "emulation_handler.h" #include "script.h" MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { KeyTrans::loadAll(); for (int i = 0; i < KeyTrans::count(); i++ ) { KeyTrans* s = KeyTrans::find(i ); assert( s ); } m_factory = new MetaFactory(); Default def(m_factory); m_sessions.setAutoDelete( TRUE ); m_curSession = 0; m_manager = new ProfileManager( m_factory ); m_manager->load(); m_scriptsData.setAutoDelete(TRUE); initUI(); populateProfiles(); populateScripts(); } void MainWindow::initUI() { setToolBarsMovable( FALSE ); /* tool bar for the menu */ m_tool = new QToolBar( this ); m_tool->setHorizontalStretchable( TRUE ); m_bar = new QMenuBar( m_tool ); m_console = new QPopupMenu( this ); m_scripts = new QPopupMenu( this ); m_sessionsPop= new QPopupMenu( this ); m_scriptsPop = new QPopupMenu( this ); /* add a toolbar for icons */ m_icons = new QToolBar(this); /* * the settings action */ m_setProfiles = new QAction(tr("Configure Profiles"), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0); m_setProfiles->addTo( m_console ); connect( m_setProfiles, SIGNAL(activated() ), this, SLOT(slotConfigure() ) ); m_console->insertSeparator(); /* * new Action for new sessions */ QAction* newCon = new QAction(tr("New Profile"), Resource::loadPixmap( "new" ), QString::null, 0, this, 0); newCon->addTo( m_console ); connect( newCon, SIGNAL(activated() ), this, SLOT(slotNew() ) ); m_console->insertSeparator(); QAction *saveCon = new QAction( tr("Save Profile" ), Resource::loadPixmap( "save" ), QString::null, 0, this, 0 ); saveCon->addTo( m_console ); connect( saveCon, SIGNAL(activated() ), this, SLOT(slotSaveSession() ) ); m_console->insertSeparator(); /* * connect action */ m_connect = new QAction( tr("Connect"), Resource::loadPixmap("console/connected"), QString::null, 0, this, 0 ); m_connect->addTo( m_console ); connect(m_connect, SIGNAL(activated() ), this, SLOT(slotConnect() ) ); /* * disconnect action */ m_disconnect = new QAction( tr("Disconnect"), Resource::loadPixmap("console/notconnected"), QString::null, 0, this, 0 ); m_disconnect->addTo( m_console ); connect(m_disconnect, SIGNAL(activated() ), this, SLOT(slotDisconnect() ) ); m_console->insertSeparator(); m_quickLaunch = new QAction( tr("QuickLaunch"), Resource::loadPixmap("console/konsole_mini"), QString::null, 0, this, 0 ); m_quickLaunch->addTo( m_icons ); connect( m_quickLaunch, SIGNAL( activated() ), this, SLOT( slotQuickLaunch() ) ); QWhatsThis::add( m_icons, tr( "The shell button launches the \"default\" profile. If there is none default values are taken" ) ); m_transfer = new QAction( tr("Transfer file..."), Resource::loadPixmap("pass") , QString::null, 0, this, 0 ); m_transfer->addTo( m_console ); connect(m_transfer, SIGNAL(activated() ), this, SLOT(slotTransfer() ) ); /* * immediate change of line wrap policy */ m_isWrapped = false; m_wrap = new QAction( tr("Line wrap"), Resource::loadPixmap( "linewrap" ), QString::null, 0, this, 0 ); m_wrap->addTo( m_console ); connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) ); /* * fullscreen */ m_isFullscreen = false; m_fullscreen = new QAction( tr("Full screen"), Resource::loadPixmap( "fullscreen" ) , QString::null, 0, this, 0); m_fullscreen->addTo( m_console ); connect( m_fullscreen, SIGNAL( activated() ), this, SLOT( slotFullscreen() ) ); m_console->insertSeparator(); QAction *a = new QAction(); a->setText( tr("Save history") ); a->addTo( m_console ); connect(a, SIGNAL(activated() ), this, SLOT(slotSaveHistory() ) ); /* * terminate action */ m_terminate = new QAction(); m_terminate->setText( tr("Terminate") ); m_terminate->addTo( m_console ); connect(m_terminate, SIGNAL(activated() ), this, SLOT(slotTerminate() ) ); m_closewindow = new QAction(); m_closewindow->setText( tr("Close Window") ); m_closewindow->addTo( m_console ); connect( m_closewindow, SIGNAL(activated() ), this, SLOT(slotClose() ) ); /* * script actions */ m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0); connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int))); m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); m_recordScript->addTo(m_scripts); connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); m_saveScript->addTo(m_scripts); connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); /* * action that open/closes the keyboard */ m_openKeys = new QAction (tr("Open Keyboard..."), Resource::loadPixmap( "console/keys/keyboard_icon" ), QString::null, 0, this, 0); m_openKeys->setToggleAction(true); connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool))); /* insert the submenu */ m_console->insertItem(tr("New from Profile"), m_sessionsPop, -1, 0); /* insert the connection menu */ m_bar->insertItem( tr("Connection"), m_console ); /* the scripts menu */ m_bar->insertItem( tr("Scripts"), m_scripts ); /* and the keyboard */ m_keyBar = new QToolBar(this); addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); m_keyBar->setHorizontalStretchable( TRUE ); m_keyBar->hide(); m_kb = new FunctionKeyboard(m_keyBar); connect(m_kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), this, SLOT(slotKeyReceived(FKey, ushort, ushort, bool))); a = new QAction(tr("Copy"), Resource::loadPixmap("copy"), QString::null, 0, this, 0 ); //a->addTo( m_icons ); connect( a, SIGNAL(activated() ), this, SLOT(slotCopy() ) ); QAction *paste = new QAction(tr("Paste"), Resource::loadPixmap("paste"), QString::null, 0, this, 0 ); connect( paste, SIGNAL(activated() ), this, SLOT(slotPaste() ) ); newCon->addTo( m_icons ); //m_setProfiles->addTo( m_icons ); paste->addTo( m_icons ); m_openKeys->addTo(m_icons); m_fullscreen->addTo( m_icons ); m_connect->setEnabled( false ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( false ); m_transfer->setEnabled( false ); m_scripts->setItemEnabled(m_runScript_id, false); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); m_fullscreen->setEnabled( false ); m_closewindow->setEnabled( false ); m_wrap->setEnabled( false ); /* * connect to the menu activation */ connect( m_sessionsPop, SIGNAL(activated( int ) ), this, SLOT(slotProfile( int ) ) ); m_consoleWindow = new TabWidget( this, "blah"); connect(m_consoleWindow, SIGNAL(activated(Session*) ), this, SLOT(slotSessionChanged(Session*) ) ); setCentralWidget( m_consoleWindow ); slotQuickLaunch(); } ProfileManager* MainWindow::manager() { return m_manager; } TabWidget* MainWindow::tabWidget() { return m_consoleWindow; } void MainWindow::populateProfiles() { m_sessionsPop->clear(); Profile::ValueList list = manager()->all(); for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { m_sessionsPop->insertItem( (*it).name() ); } diff --git a/noncore/apps/opie-console/metafactory.cpp b/noncore/apps/opie-console/metafactory.cpp index 24928e7..32e93ce 100644 --- a/noncore/apps/opie-console/metafactory.cpp +++ b/noncore/apps/opie-console/metafactory.cpp @@ -1,165 +1,164 @@ -#include <qpe/config.h> #include "metafactory.h" MetaFactory::MetaFactory() { } MetaFactory::~MetaFactory() { } void MetaFactory::addConnectionWidgetFactory( const QCString& name, const QString& str, configWidget wid) { m_strings.insert( str, name ); m_conFact.insert( str, wid ); } void MetaFactory::addTerminalWidgetFactory( const QCString& name, const QString& str, configWidget wid ) { m_strings.insert( str, name ); m_termFact.insert( str, wid ); } void MetaFactory::addKeyboardWidgetFactory( const QCString& name, const QString & str, configWidget wid) { m_strings.insert( str, name ); m_keyFact.insert( str, wid ); } void MetaFactory::addIOLayerFactory( const QCString& name, const QString& str, iolayer lay) { m_strings.insert( str, name ); m_layerFact.insert( str, lay ); } void MetaFactory::addFileTransferLayer( const QCString& name, const QString& str, filelayer lay) { m_strings.insert(str, name ); m_fileFact.insert( str, lay ); } void MetaFactory::addReceiveLayer( const QCString& name, const QString& str, receivelayer lay) { m_strings.insert(str, name ); m_receiveFact.insert( str, lay ); } QStringList MetaFactory::ioLayers()const { QStringList list; QMap<QString, iolayer>::ConstIterator it; for (it = m_layerFact.begin(); it != m_layerFact.end(); ++it ) { list << it.key(); } return list; } QStringList MetaFactory::connectionWidgets()const { QStringList list; QMap<QString, configWidget>::ConstIterator it; for ( it = m_conFact.begin(); it != m_conFact.end(); ++it ) { list << it.key(); } return list; } QStringList MetaFactory::terminalWidgets()const { QStringList list; QMap<QString, configWidget>::ConstIterator it; for ( it = m_termFact.begin(); it != m_termFact.end(); ++it ) { list << it.key(); } return list; } QStringList MetaFactory::fileTransferLayers()const { QStringList list; QMap<QString, filelayer>::ConstIterator it; for ( it = m_fileFact.begin(); it != m_fileFact.end(); ++it ) { list << it.key(); } return list; } QStringList MetaFactory::receiveLayers()const { QStringList list; QMap<QString, receivelayer>::ConstIterator it; for ( it = m_receiveFact.begin(); it != m_receiveFact.end(); ++it ) { list << it.key(); } return list; } IOLayer* MetaFactory::newIOLayer( const QString& str,const Profile& prof ) { IOLayer* lay = 0l; QMap<QString, iolayer>::Iterator it; it = m_layerFact.find( str ); if ( it != m_layerFact.end() ) { lay = (*(it.data()))(prof); /* iolayer laye = it.data(); lay = (*laye )(conf);*/ } return lay; } ProfileDialogWidget *MetaFactory::newConnectionPlugin ( const QString& str, QWidget *parent) { ProfileDialogWidget* wid = 0l; QMap<QString, configWidget>::Iterator it; it = m_conFact.find( str ); if ( it != m_conFact.end() ) { wid = (*(it.data() ) )(str,parent); } return wid; } ProfileDialogWidget *MetaFactory::newTerminalPlugin( const QString& str, QWidget *parent) { if (str.isEmpty() ) return 0l; ProfileDialogWidget* wid = 0l; QMap<QString, configWidget>::Iterator it; it = m_termFact.find( str ); if ( it != m_termFact.end() ) { wid = (*(it.data() ) )(str,parent); } return wid; } ProfileDialogWidget *MetaFactory::newKeyboardPlugin( const QString& str, QWidget *parent) { if (str.isEmpty() ) return 0l; ProfileDialogWidget* wid = 0l; QMap<QString, configWidget>::Iterator it; it = m_keyFact.find( str ); if ( it != m_keyFact.end() ) { wid = (*(it.data() ) )(str,parent); } return wid; } FileTransferLayer* MetaFactory::newFileTransfer(const QString& str, IOLayer* lay ) { FileTransferLayer* file = 0l; QMap<QString, filelayer>::Iterator it; it = m_fileFact.find( str ); if ( it != m_fileFact.end() ) { file = (*(it.data() ) )(lay); } return file; } ReceiveLayer* MetaFactory::newReceive(const QString& str, IOLayer* lay ) { ReceiveLayer* file = 0l; QMap<QString, receivelayer>::Iterator it; it = m_receiveFact.find( str ); if ( it != m_receiveFact.end() ) { file = (*(it.data() ) )(lay); } return file; } QCString MetaFactory::internal( const QString& str )const { return m_strings[str]; } QString MetaFactory::external( const QCString& str )const { QMap<QString, QCString>::ConstIterator it; for ( it = m_strings.begin(); it != m_strings.end(); ++it ) { if ( it.data() == str ) return it.key(); } return QString::null; } diff --git a/noncore/apps/opie-console/modemconfigwidget.cpp b/noncore/apps/opie-console/modemconfigwidget.cpp index f7fb6f3..e552990 100644 --- a/noncore/apps/opie-console/modemconfigwidget.cpp +++ b/noncore/apps/opie-console/modemconfigwidget.cpp @@ -1,257 +1,255 @@ #include <qlabel.h> #include <qlayout.h> #include <qcombobox.h> -#include <qlineedit.h> #include <qpushbutton.h> #include <qhbox.h> -#include <qregexp.h> #include "modemconfigwidget.h" #include "dialdialog.h" namespace { void setCurrent( const QString& str, QComboBox* bo ) { uint b = bo->count(); for (int i = 0; i < bo->count(); i++ ) { if ( bo->text(i) == str ) { bo->setCurrentItem( i ); return; } } bo->insertItem( str ); bo->setCurrentItem( b ); } } ModemConfigWidget::ModemConfigWidget( const QString& name, QWidget* parent, const char* na ) : ProfileDialogConnectionWidget( name, parent, na ) { m_lay = new QVBoxLayout( this ); m_device = new QLabel(tr( "Modem is attached to:" ), this ); m_deviceCmb = new QComboBox(this ); m_deviceCmb->setEditable( TRUE ); QLabel* telLabel = new QLabel( this ); telLabel->setText( tr( "Enter telefon number here:" ) ); QHBox *buttonBox = new QHBox( this ); m_telNumber = new QLineEdit( buttonBox ); QPushButton *atButton = new QPushButton( buttonBox ); atButton->setText( tr( "AT commands" ) ); connect( atButton, SIGNAL( clicked() ), this, SLOT( slotAT() ) ); QPushButton *dialButton = new QPushButton( buttonBox ); dialButton->setText( tr( "Enter number" ) ); connect( dialButton, SIGNAL( clicked() ), this, SLOT( slotDial() ) ); m_base = new IOLayerBase( this, "base" ); m_lay->addWidget( m_device ); m_lay->addWidget( m_deviceCmb ); m_lay->addWidget( telLabel ); m_lay->addWidget( buttonBox ); m_lay->addWidget( m_base ); m_lay->addStretch( 0 ); m_deviceCmb->insertItem( "/dev/ttyS0" ); m_deviceCmb->insertItem( "/dev/ttyS1" ); m_deviceCmb->insertItem( "/dev/ttyS2" ); atConf = new ATConfigDialog( this, "ATConfig", true ); } ModemConfigWidget::~ModemConfigWidget() { } void ModemConfigWidget::load( const Profile& prof ) { int rad_flow = prof.readNumEntry( "Flow" ); int rad_parity = prof.readNumEntry( "Parity" ); int speed = prof.readNumEntry( "Speed" ); int dbits = prof.readNumEntry("DataBits"); int sbits = prof.readNumEntry("StopBits"); QString number = prof.readEntry( "Number" ); if ( !number.isEmpty() ) { m_telNumber->setText( number ); } if ( rad_flow == 1 ) { m_base->setFlow( IOLayerBase::Hardware ); } else if (rad_flow == 2) { m_base->setFlow( IOLayerBase::Software ); } else if (rad_flow == 0) { m_base->setFlow( IOLayerBase::None ); } if ( rad_parity == 1 ) { m_base->setParity( IOLayerBase::Even ); } else if ( rad_parity == 2 ){ m_base->setParity( IOLayerBase::Odd ); } else { m_base->setParity( IOLayerBase::NonePar ); } switch( speed ) { case 115200: m_base->setSpeed( IOLayerBase::Baud_115200 ); break; case 57600: m_base->setSpeed( IOLayerBase::Baud_57600 ); break; case 38400: m_base->setSpeed( IOLayerBase::Baud_38400 ); break; case 19200: m_base->setSpeed( IOLayerBase::Baud_19200 ); break; case 9600: default: m_base->setSpeed( IOLayerBase::Baud_9600 ); break; } if ( dbits == 5) { m_base->setData( IOLayerBase::Data_Five ); } else if (rad_flow == 6) { m_base->setData( IOLayerBase::Data_Six ); } else if (rad_flow == 7) { m_base->setData( IOLayerBase::Data_Seven ); } else { m_base->setData( IOLayerBase::Data_Eight ); } if ( sbits == 2) { m_base->setStop( IOLayerBase::Stop_Two ); } else if ( sbits == 15 ) { m_base->setStop( IOLayerBase::Stop_OnePointFive ); } else { m_base->setStop( IOLayerBase::Stop_One ); } atConf->readConfig( prof ); if ( prof.readEntry( "Device" ).isEmpty() ) { qWarning("device empty!"); return; } setCurrent( prof.readEntry( "Device" ), m_deviceCmb ); } /* * save speed, * flow, * parity */ void ModemConfigWidget::save( Profile& prof ) { int flow, parity, speed, data, stop; flow = parity = speed = data = stop = 0; prof.writeEntry( "Device", m_deviceCmb->currentText() ); switch( m_base->flow() ) { case IOLayerBase::None: flow = 0; break; case IOLayerBase::Software: flow = 2; break; case IOLayerBase::Hardware: flow = 1; break; } switch( m_base->parity() ) { case IOLayerBase::Odd: parity = 2; break; case IOLayerBase::Even: parity = 1; break; case IOLayerBase::NonePar: parity = 0; break; } switch( m_base->speed() ) { case IOLayerBase::Baud_115200: speed = 115200; break; case IOLayerBase::Baud_57600: speed = 57600; break; case IOLayerBase::Baud_38400: speed = 38400; break; case IOLayerBase::Baud_19200: speed = 19200; break; case IOLayerBase::Baud_9600: speed = 9600; break; } switch( m_base->data() ) { case IOLayerBase::Data_Five: data = 5; break; case IOLayerBase::Data_Six: data = 6; break; case IOLayerBase::Data_Seven: data = 7; break; case IOLayerBase::Data_Eight: data = 8; break; } switch( m_base->stop() ) { case IOLayerBase::Stop_One: stop = 1; break; case IOLayerBase::Stop_OnePointFive: stop = 15; break; case IOLayerBase::Stop_Two: stop = 2; break; } prof.writeEntry( "Flow", flow ); prof.writeEntry( "Parity", parity ); prof.writeEntry( "Speed", speed ); prof.writeEntry("DataBits", data); prof.writeEntry("StopBits", stop); prof.writeEntry( "Number", m_telNumber->text() ); atConf->writeConfig(prof); } void ModemConfigWidget::slotAT() { // ATConfigDialog conf( this, "ATConfig", true ); // josef/Max I know why don't you create the stuff on the stack // but making it a TopLevel Dialog and ignoring // cancel is not fun either... // what to do? FIXME!!! -zecke atConf->showMaximized(); if ( atConf->exec() != QDialog::Accepted ) { // reload old settings } } void ModemConfigWidget::slotDial() { DialDialog dial( this, "DialConfig", true ); if(!m_telNumber->text().isEmpty()) { dial.setNumber(m_telNumber->text().replace(QRegExp("[\\-\\/\\ \\.\\,]"), "")); } dial.showMaximized(); if ( dial.exec() == QDialog::Accepted ) { m_telNumber->setText( dial.number() ); } } diff --git a/noncore/apps/opie-console/profileeditordialog.cpp b/noncore/apps/opie-console/profileeditordialog.cpp index e2501a6..979e89d 100644 --- a/noncore/apps/opie-console/profileeditordialog.cpp +++ b/noncore/apps/opie-console/profileeditordialog.cpp @@ -1,242 +1,241 @@ #include <qlayout.h> #include <qlineedit.h> #include <qlabel.h> #include <qmessagebox.h> -#include <qstringlist.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qscrollview.h> #include "metafactory.h" #include "profileeditordialog.h" namespace { void setCurrent( const QString& str, QComboBox* bo ) { for (int i = 0; i < bo->count(); i++ ) { if ( bo->text(i) == str ) { bo->setCurrentItem( i ); } } }; } ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact, const Profile& prof ) : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof ) { initUI(); // Apply current profile // plugin_plugin->load(profile); // ... (reset profile name line edit etc.) } ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact ) : QDialog(0, 0, TRUE), m_fact( fact ) { // Default profile m_prof = Profile(tr("New Profile"), "serial", "default", Profile::Black, Profile::White, Profile::VT102); initUI(); // Apply current profile // plugin_plugin->load(profile); } Profile ProfileEditorDialog::profile() const { return m_prof; } void ProfileEditorDialog::initUI() { m_con = m_term = m_key = 0l; QVBoxLayout *mainLayout = new QVBoxLayout( this ); tabWidget = new OTabWidget( this ); tabWidget->setTabStyle(OTabWidget::TextTab); mainLayout->add(tabWidget); /* base tabs */ tabprof = new QWidget(this); m_tabTerm = new QWidget(this); m_tabCon = new QWidget(this); m_tabKey = new QWidget(this); m_svCon = new QScrollView( m_tabCon ); m_svCon->setResizePolicy( QScrollView::AutoOneFit ); //m_svCon->setHScrollBarMode( QScrollView::AlwaysOff ); m_svCon->setFrameShape( QFrame::NoFrame ); m_svTerm = new QScrollView( m_tabTerm ); m_svTerm->setResizePolicy( QScrollView::AutoOneFit ); //m_svTerm->setHScrollBarMode( QScrollView::AlwaysOff ); m_svTerm->setFrameShape( QFrame::NoFrame ); /* base layout for tabs */ m_layCon = new QHBoxLayout( m_tabCon , 2 ); m_layTerm = new QHBoxLayout( m_tabTerm, 2 ); m_layKey = new QHBoxLayout( m_tabKey, 2 ); m_layCon->addWidget( m_svCon ); m_layTerm->addWidget( m_svTerm ); // profile tab QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof); m_name = new QLineEdit(tabprof); QLabel *con = new QLabel(tr("Connection"), tabprof ); QLabel *term = new QLabel(tr("Terminal"), tabprof ); m_conCmb = new QComboBox( tabprof ); m_termCmb = new QComboBox( tabprof ); m_autoConnect = new QCheckBox(tr("Auto connect after load"), tabprof); // layouting QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2); vbox3->add(name); vbox3->add(m_name); vbox3->add(con ); vbox3->add(m_conCmb ); vbox3->add(term ); vbox3->add(m_termCmb ); vbox3->add(m_autoConnect); vbox3->addStretch(1); m_showconntab = 0; tabWidget->addTab(tabprof, "", QObject::tr("Profile")); tabWidget->addTab(m_tabCon, "", QObject::tr("Connection")); tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal")); tabWidget->addTab(m_tabKey, "", QObject::tr("Special Keys")); tabWidget->setCurrentTab( tabprof ); // fill the comboboxes QStringList list = m_fact->connectionWidgets(); QStringList::Iterator it; for (it =list.begin(); it != list.end(); ++it ) { m_conCmb->insertItem( (*it) ); } list = m_fact->terminalWidgets(); for (it =list.begin(); it != list.end(); ++it ) { m_termCmb->insertItem( (*it) ); } // load profile values m_name->setText(m_prof.name()); slotKeyActivated( "Default Keyboard" ); setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb ); setCurrent( m_fact->external(m_prof.terminalName() ), m_termCmb ); slotConActivated( m_fact->external(m_prof.ioLayerName() ) ); slotTermActivated( m_fact->external(m_prof.terminalName() ) ); m_autoConnect->setChecked(m_prof.autoConnect()); // signal and slots connect(m_conCmb, SIGNAL(activated(const QString& ) ), this, SLOT(slotConActivated(const QString&) ) ); connect(m_termCmb, SIGNAL(activated(const QString& ) ), this, SLOT(slotTermActivated(const QString& ) ) ); } ProfileEditorDialog::~ProfileEditorDialog() { } void ProfileEditorDialog::accept() { if(profName().isEmpty()) { QMessageBox::information(this, QObject::tr("Invalid profile"), QObject::tr("Please enter a profile name.")); return; } // Save profile and plugin profile //if(plugin_plugin) plugin_plugin->save(); // Save general values m_prof.setName( profName() ); m_prof.setIOLayer( m_fact->internal(m_conCmb ->currentText() ) ); m_prof.setTerminalName( m_fact->internal(m_termCmb->currentText() ) ); m_prof.setAutoConnect( m_autoConnect->isChecked() ); if (m_con ) m_con->save( m_prof ); if (m_term ) m_term->save( m_prof ); if (m_key) m_key->save( m_prof ); QDialog::accept(); } QString ProfileEditorDialog::profName()const { return m_name->text(); } QCString ProfileEditorDialog::profType()const { /*QStringList w = m_fact->configWidgets(); for(QStringList::Iterator it = w.begin(); it != w.end(); it++) if(device_box->currentText() == m_fact->name((*it))) return (*it); */ return QCString(); } /* * we need to switch the widget */ void ProfileEditorDialog::slotConActivated( const QString& str ) { delete m_con; m_con = m_fact->newConnectionPlugin( str, m_svCon->viewport() ); if ( !m_con ) { m_con = new NoOptions( str, m_svCon->viewport(), "name"); } // FIXME ugly hack right. Right solution would be to look into the layer and see if it // supports auto connect and then set it as prefered if ( m_conCmb ->currentText() == tr("Local Console") ) { m_autoConnect->setChecked( true ); m_prof.writeEntry("Terminal", Profile::Linux ); slotTermActivated( m_fact->external (m_prof.terminalName() ) ); } else { m_prof.writeEntry("Terminal", Profile::VT102 ); slotTermActivated( m_fact->external (m_prof.terminalName() ) ); m_autoConnect->setChecked( false ); } m_con->load( m_prof ); m_svCon->addChild( m_con ); } /* * we need to switch the widget */ void ProfileEditorDialog::slotTermActivated( const QString& str ) { delete m_term; m_term = m_fact->newTerminalPlugin( str, m_svTerm->viewport() ); if ( m_term ) { m_term->load( m_prof ); m_svTerm->addChild( m_term ); } } void ProfileEditorDialog::slotKeyActivated(const QString &str) { delete m_key; m_key = m_fact->newKeyboardPlugin( str, m_tabKey ); if (m_key) { m_key->load(m_prof); m_layKey->addWidget(m_key); } } diff --git a/noncore/apps/opie-console/profilemanager.cpp b/noncore/apps/opie-console/profilemanager.cpp index cad2567..71188d1 100644 --- a/noncore/apps/opie-console/profilemanager.cpp +++ b/noncore/apps/opie-console/profilemanager.cpp @@ -1,141 +1,136 @@ #include <stdio.h> #include <stdlib.h> #include <qfile.h> #include <qhbox.h> -#include <qlayout.h> -#include <qwidgetstack.h> -#include <qpe/config.h> #include "emulation_handler.h" -#include "widget_layer.h" -#include "emulation_widget.h" #include "metafactory.h" #include "profileconfig.h" #include "profilemanager.h" ProfileManager::ProfileManager( MetaFactory* fact ) : m_fact( fact ) { } ProfileManager::~ProfileManager() { } void ProfileManager::load() { m_list.clear(); ProfileConfig conf("opie-console-profiles"); QStringList groups = conf.groups(); QStringList::Iterator it; /* * for each profile */ for ( it = groups.begin(); it != groups.end(); ++it ) { conf.setGroup( (*it) ); Profile prof; prof.setName( conf.readEntry("name") ); prof.setIOLayer( conf.readEntry("iolayer").utf8() ); prof.setTerminalName( conf.readEntry("term").utf8() ); prof.setAutoConnect( conf.readBoolEntry("autoConnect") ); prof.setBackground( conf.readNumEntry("back") ); prof.setForeground( conf.readNumEntry("fore") ); prof.setTerminal( conf.readNumEntry("terminal") ); // THIS is evil because all data get's reset prof.setConf( conf.items( (*it) ) ); /* now add it */ m_list.append( prof ); } } void ProfileManager::clear() { m_list.clear(); } Profile::ValueList ProfileManager::all()const { return m_list; } /* * Our goal is to create a Session * We will load the the IOLayer and EmulationLayer * from the factory * we will generate a QWidgetStack * add a dummy widget with layout * add "Widget" to the layout * add the dummy to the stack * raise the dummy * call session->connect(= * this way we only need to reparent * in TabWidget */ Session* ProfileManager::fromProfile( const Profile& prof, QWidget* parent) { /* TEST PROFILE!!! Profile prof; QString str = "/dev/ttyS0"; prof.writeEntry("Device",str ); prof.writeEntry("Baud", 115200 ); prof.setIOLayer("serial"); prof.setName( "test"); */ Session* session = new Session(); session->setName( prof.name() ); /* translate the internal name to the external */ session->setIOLayer(m_fact->newIOLayer( m_fact->external(prof.ioLayerName()) , prof) ); QWidgetStack *stack = new QWidgetStack( parent ); session->setWidgetStack( stack ); QWidget* dummy = new QHBox( stack ); stack->raiseWidget( dummy ); EmulationHandler* handler = new EmulationHandler(prof,dummy ); session->setEmulationHandler( handler ); session->connect(); session->setProfile( prof ); return session; } void ProfileManager::save( ) { QFile::remove( (QString(getenv("HOME") )+ "/Settings/opie-console-profiles.conf" ) ); ProfileConfig conf("opie-console-profiles"); Profile::ValueList::Iterator it2; for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { conf.setGroup( (*it2).name() ); /* now the config stuff */ QMap<QString, QString> map = (*it2).conf(); QMap<QString, QString>::Iterator confIt; for ( confIt = map.begin(); confIt != map.end(); ++confIt ) { conf.writeEntry( confIt.key(), confIt.data() ); } conf.writeEntry( "name", (*it2).name() ); QString str = QString::fromUtf8( (*it2).ioLayerName() ); conf.writeEntry( "iolayer", str ); conf.writeEntry( "term", QString::fromUtf8( (*it2).terminalName() ) ); conf.writeEntry( "autoConnect", (*it2).autoConnect()); conf.writeEntry( "back", (*it2).background() ); conf.writeEntry( "fore", (*it2).foreground() ); conf.writeEntry( "terminal", (*it2).terminal() ); } } void ProfileManager::add( const Profile& prof) { m_list.append( prof ); } void ProfileManager::setProfiles( const Profile::ValueList& list ) { m_list = list; }; Profile ProfileManager::profile( const QString& name )const { Profile prof; Profile::ValueList::ConstIterator it; for ( it = m_list.begin(); it != m_list.end(); ++it ) { if ( name == (*it).name() ) { prof = (*it); break; } } return prof; } diff --git a/noncore/apps/opie-console/receive_layer.cpp b/noncore/apps/opie-console/receive_layer.cpp index bbde339..b255452 100644 --- a/noncore/apps/opie-console/receive_layer.cpp +++ b/noncore/apps/opie-console/receive_layer.cpp @@ -1,34 +1,31 @@ #include <unistd.h> #include <qdir.h> -#include <qstring.h> -#include <qfile.h> -#include "io_layer.h" #include "receive_layer.h" ReceiveLayer::ReceiveLayer( IOLayer* lay, const QString& startDir ) : QObject(), m_curDir( startDir ), m_layer(lay ) { } ReceiveLayer::~ReceiveLayer() { } IOLayer* ReceiveLayer::layer() { return m_layer; } QString ReceiveLayer::currentDir()const{ if (m_curDir.isEmpty() ) return QDir::currentDirPath(); return m_curDir; } void ReceiveLayer::changeDir( const QString& str) { ::chdir( str.latin1() ); } void ReceiveLayer::receive( const QString& dir, Mode, Features ) { receive( dir ); } void ReceiveLayer::cancel() { } diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp index e6e9d6d..faea412 100644 --- a/noncore/apps/opie-console/script.cpp +++ b/noncore/apps/opie-console/script.cpp @@ -1,30 +1,29 @@ #include <qfile.h> -#include <qtextstream.h> #include "script.h" Script::Script() { } Script::Script(const QString fileName) { QFile file(fileName); file.open(IO_ReadOnly ); m_script = file.readAll(); } void Script::saveTo(const QString fileName) const { QFile file(fileName); file.open(IO_WriteOnly); file.writeBlock(m_script); file.close(); } void Script::append(const QByteArray &data) { int size = m_script.size(); m_script.resize(size + data.size()); memcpy(m_script.data() + size, data.data(), data.size()); } QByteArray Script::script() const { return m_script; } diff --git a/noncore/apps/opie-console/session.cpp b/noncore/apps/opie-console/session.cpp index 4f52584..1034ede 100644 --- a/noncore/apps/opie-console/session.cpp +++ b/noncore/apps/opie-console/session.cpp @@ -1,117 +1,115 @@ -#include "profile.h" -#include "io_layer.h" #include "file_layer.h" #include "emulation_handler.h" #include "session.h" Session::Session() { m_widget = 0l; m_layer = 0l; m_emu = 0l; m_transfer = 0l; } Session::Session( const QString& na, QWidgetStack* widget, IOLayer* lay) : m_name( na ), m_widget( widget ), m_layer( lay ) { // m_widLay = 0l; // m_emLay = 0l; m_emu = 0l; } Session::~Session() { delete m_layer; delete m_emu; delete m_widget; /* the widget layer should be deleted by the m_widget */ } QString Session::name()const { return m_name; } QWidgetStack* Session::widgetStack() { return m_widget; } IOLayer* Session::layer() { return m_layer; } EmulationHandler* Session::emulationHandler() { return m_emu; } QWidget* Session::widget() { if (!m_emu ) return 0l; return m_emu->widget(); } Profile Session::profile()const { return m_prof; } /* WidgetLayer* Session::emulationWidget() { return m_widLay; } */ void Session::connect() { if ( !m_layer || !m_emu ) return; QObject::connect(m_layer, SIGNAL(received(const QByteArray&) ), m_emu, SLOT(recv(const QByteArray&) ) ); QObject::connect(m_emu, SIGNAL(send(const QByteArray&) ), m_layer, SLOT(send(const QByteArray&) ) ); QObject::connect(m_emu, SIGNAL(changeSize(int, int) ), m_layer, SLOT(setSize(int, int) ) ); } void Session::disconnect() { if ( !m_layer || !m_emu ) return; QObject::disconnect(m_layer, SIGNAL(received(const QByteArray&) ), m_emu, SLOT(recv(const QByteArray&) ) ); QObject::disconnect(m_emu, SIGNAL(send(const QByteArray&) ), m_layer, SLOT(send(const QByteArray&) ) ); } void Session::setName( const QString& na){ m_name = na; } void Session::setWidgetStack( QWidgetStack* wid ) { delete m_emu; m_emu = 0l; delete m_widget; /* the EmulationLayer was destroyed... */ m_widget = wid; } void Session::setIOLayer( IOLayer* lay ) { delete m_layer; m_layer = lay; } void Session::setEmulationHandler( EmulationHandler* lay ) { delete m_emu; m_emu = lay; } void Session::setProfile( const Profile& prof ) { m_prof = prof; } /* void Session::setEmulationWidget( WidgetLayer* lay ) { delete m_widLay; m_widLay = lay; } */ void Session::setTransferDialog(QWidget *d) { m_transfer = d; } QWidget *Session::transferDialog() { return m_transfer; } diff --git a/noncore/apps/opie-console/terminalwidget.cpp b/noncore/apps/opie-console/terminalwidget.cpp index 70f7c9b..6870487 100644 --- a/noncore/apps/opie-console/terminalwidget.cpp +++ b/noncore/apps/opie-console/terminalwidget.cpp @@ -1,225 +1,221 @@ -#include <qbuttongroup.h> #include <qlabel.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qradiobutton.h> -#include <qgroupbox.h> -#include <qvbox.h> #include <qhgroupbox.h> #include <qhbuttongroup.h> #include <qlayout.h> -#include <qhbox.h> #include "terminalwidget.h" namespace { enum TermIds { id_term_vt100 = 0, id_term_vt102, id_term_linux, id_term_xterm }; enum ColourIds { id_term_black, id_term_white, id_term_green, id_term_orange }; enum FontIds { id_size_small, id_size_medium, id_size_large }; }; TerminalWidget::TerminalWidget( const QString& name, QWidget* parent, const char* na ) : ProfileDialogTerminalWidget( name, parent, na ) { m_terminal = new QLabel(tr("Terminal Type"), this ); m_terminalBox = new QComboBox(this); m_colorLabel = new QLabel(tr("Color scheme"), this); m_colorCmb = new QComboBox(this ); m_groupSize = new QHButtonGroup(tr("Font size"), this ); m_sizeSmall = new QRadioButton(tr("small"), m_groupSize ); m_sizeMedium = new QRadioButton(tr("medium"), m_groupSize ); m_sizeLarge = new QRadioButton(tr("large"), m_groupSize ); m_groupConv = new QHGroupBox( tr("Line-break conversions"), this ); m_convInbound = new QCheckBox( tr("Inbound"), m_groupConv ); m_convOutbound = new QCheckBox( tr("Outbound"), m_groupConv ); m_groupOptions = new QHGroupBox( tr("Options"), this ); m_optionEcho = new QCheckBox( tr("Local echo"), m_groupOptions ); m_optionWrap = new QCheckBox( tr("Line wrap"), m_groupOptions ); m_lroot = new QVBoxLayout( this ); m_typeBox = new QVBoxLayout( m_lroot ); m_colorBox = new QVBoxLayout( m_lroot ); // Layout m_typeBox->add( m_terminal ); m_typeBox->add( m_terminalBox ); m_lroot->add( m_groupSize ); m_colorBox->add( m_colorLabel ); m_colorBox->add( m_colorCmb ); m_lroot->add( m_groupConv ); m_lroot->add( m_groupOptions ); m_lroot->addStretch( 0 ); // Fill in some options qWarning("Options for terminal box"); m_terminalBox->insertItem( tr("VT 100"), 0 ); // /*, id_term_vt100*/ ); m_terminalBox->insertItem( tr("VT 102"), 1 ); // /* , id_term_vt102 */); m_terminalBox->insertItem( tr("Linux Console"), 2 ); //, id_term_linux ); m_terminalBox->insertItem( tr("X-Terminal"), 3 ); //, id_term_xterm ); //m_terminalBox->insertItem( tr("ANSI"), id_term_ansi ); m_colorCmb->insertItem( tr("black on white"), id_term_black ); m_colorCmb->insertItem( tr("white on black"), id_term_white ); m_colorCmb->insertItem( tr("green on black"), id_term_green ); m_colorCmb->insertItem( tr("orange on black"), id_term_orange ); // signals + slots /* connect(m_terminalBox, SIGNAL(activated(int) ), this, SLOT(slotTermTerm(int) ) ); connect(m_colorBox, SIGNAL(activated(int) ), tis, SLOT(slotTermColor(int) ) ); connect(m_groupSize, SIGNAL(activated(int) ), this, SLOT(slotTermFont(int) ) ); connect(m_optionEcho, SIGNAL(toggled(bool) ), this, SLOT(slotTermEcho(bool) ) ); connect(m_optionWrap, SIGNAL(toggled(bool) ), this, SLOT(slotTermWrap(bool) ) ); connect(m_convInbound, SIGNAL(toggled(bool) ), this, SLOT(slotTermInbound(bool) ) ); connect(m_convOutbound, SIGNAL(toggled(bool) ), this, SLOT(slotTermOutbound(bool) ) ); */ } TerminalWidget::~TerminalWidget() { } void TerminalWidget::load( const Profile& prof ) { int term = prof.readNumEntry("Terminal"); int color = prof.readNumEntry("Color"); int fontsize = prof.readNumEntry("Font"); int opt_echo = prof.readNumEntry("Echo"); int opt_wrap = prof.readNumEntry("Wrap"); int opt_inbound = prof.readNumEntry("Inbound"); int opt_outbound = prof.readNumEntry("Outbound"); switch( term ) { case Profile::VT100: m_terminalBox->setCurrentItem(id_term_vt100 ); break; case Profile::VT102: m_terminalBox->setCurrentItem(id_term_vt102 ); break; case Profile::Linux: m_terminalBox->setCurrentItem(id_term_linux ); break; case Profile::XTerm: m_terminalBox->setCurrentItem(id_term_xterm ); break; default: m_terminalBox->setCurrentItem(id_term_vt102 ); break; }; switch( color ) { case Profile::Black: m_colorCmb->setCurrentItem(id_term_black ); break; case Profile::White: m_colorCmb->setCurrentItem(id_term_white ); break; case Profile::Green: m_colorCmb->setCurrentItem(id_term_green ); break; case Profile::Orange: m_colorCmb->setCurrentItem(id_term_orange ); break; default: break; }; switch( fontsize ) { case Profile::Micro: m_sizeSmall->setChecked(true ); break; case Profile::Small: m_sizeMedium->setChecked(true ); break; case Profile::Medium: m_sizeLarge->setChecked( true ); break; default: m_sizeMedium->setChecked(true ); break; }; if (opt_echo) m_optionEcho->setChecked( true ); if (opt_wrap) m_optionWrap->setChecked( true ); if (opt_inbound) m_convInbound->setChecked( true ); if (opt_outbound) m_convOutbound->setChecked( true ); } void TerminalWidget::save( Profile& profile ) { switch(m_terminalBox->currentItem() ) { case id_term_vt100: profile.writeEntry("Terminal", Profile::VT100 ); break; case id_term_vt102: profile.writeEntry("Terminal", Profile::VT102 ); break; case id_term_linux: profile.writeEntry("Terminal", Profile::Linux ); break; case id_term_xterm: profile.writeEntry("Terminal", Profile::XTerm ); break; //case id_term_ansi: // profile.writeEntry("Terminal", Profile::VT102 ); // break; default: break; }; // color switch(m_colorCmb->currentItem() ) { case id_term_black: profile.writeEntry("Color", Profile::Black ); break; case id_term_white: profile.writeEntry("Color", Profile::White ); break; case id_term_green: profile.writeEntry("Color", Profile::Green ); break; case id_term_orange: profile.writeEntry("Color", Profile::Orange ); break; default: break; }; if (m_sizeSmall->isChecked() ) { profile.writeEntry("Font", Profile::Micro ); }else if (m_sizeMedium->isChecked() ) { profile.writeEntry("Font", Profile::Small ); }else { profile.writeEntry("Font", Profile::Medium ); } profile.writeEntry("Echo", m_optionEcho->isChecked() ); profile.writeEntry("Wrap", m_optionWrap->isChecked() ); profile.writeEntry("Inbound", m_convInbound->isChecked() ); profile.writeEntry("Outbound",m_convOutbound->isChecked() ); } diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp index 0af1911..55dd748 100644 --- a/noncore/apps/opie-console/transferdialog.cpp +++ b/noncore/apps/opie-console/transferdialog.cpp @@ -1,270 +1,268 @@ #include <qlayout.h> #include <qcombobox.h> #include <qlabel.h> #include <qlineedit.h> #include <qpushbutton.h> #include <qmessagebox.h> #include <qprogressbar.h> #include <qradiobutton.h> #include <qbuttongroup.h> #include <opie/ofiledialog.h> -#include "file_layer.h" -#include "receive_layer.h" #include "metafactory.h" #include "mainwindow.h" #include "transferdialog.h" TransferDialog::TransferDialog(QWidget *parent, MainWindow *mainwindow, const char *) : QDialog(parent, 0l, false), m_win(mainwindow) { m_lay = 0l; m_recvlay = 0l; QVBoxLayout *vbox, *vbox2; QHBoxLayout *hbox, *hbox2, *hbox3; QLabel *file, *mode, *progress, *status; QButtonGroup *group; QRadioButton *mode_send, *mode_receive; m_autocleanup = 0; m_running = true; group = new QButtonGroup(QObject::tr("Transfer mode"), this); mode_send = new QRadioButton(QObject::tr("Send"), group); mode_receive = new QRadioButton(QObject::tr("Receive"), group); group->insert(mode_send, id_send); group->insert(mode_receive, id_receive); vbox2 = new QVBoxLayout(group, 2); vbox2->addSpacing(10); hbox3 = new QHBoxLayout(vbox2, 2); hbox3->add(mode_send); hbox3->add(mode_receive); mode_send->setChecked(true); m_transfermode = id_send; file = new QLabel(QObject::tr("Send file"), this); mode = new QLabel(QObject::tr("Transfer protocol"), this); progress = new QLabel(QObject::tr("Progress"), this); status = new QLabel(QObject::tr("Status"), this); statusbar = new QLabel(QObject::tr("Ready"), this); statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken); protocol = new QComboBox(this); QStringList list = m_win->factory()->fileTransferLayers(); for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) protocol->insertItem((*it)); filename = new QLineEdit(this); progressbar = new QProgressBar(this); progressbar->setProgress(0); selector = new QPushButton("...", this); ok = new QPushButton(QObject::tr("Start transfer"), this); cancel = new QPushButton(QObject::tr("Cancel"), this); vbox = new QVBoxLayout(this, 2); vbox->add(group); vbox->add(file); hbox = new QHBoxLayout(vbox, 0); hbox->add(filename); hbox->add(selector); vbox->add(mode); vbox->add(protocol); vbox->add(progress); vbox->add(progressbar); vbox->add(status); vbox->add(statusbar); vbox->addStretch(1); hbox2 = new QHBoxLayout(vbox, 2); hbox2->add(ok); hbox2->add(cancel); setCaption(QObject::tr("File transfer")); show(); connect(selector, SIGNAL(clicked()), SLOT(slotFilename())); connect(ok, SIGNAL(clicked()), SLOT(slotTransfer())); connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); connect(group, SIGNAL(clicked(int)), SLOT(slotMode(int))); } TransferDialog::~TransferDialog() { } void TransferDialog::slotFilename() { QString f; f = OFileDialog::getOpenFileName(0); if(!f.isNull()) filename->setText(f); } void TransferDialog::slotTransfer() { if((m_transfermode == id_send) && (filename->text().isEmpty())) { QMessageBox::information(this, QObject::tr("Attention"), QObject::tr("No file has been specified.")); return; } ok->setEnabled(false); cleanup(); m_autocleanup = 0; if(m_transfermode == id_send) statusbar->setText(QObject::tr("Sending...")); else statusbar->setText(QObject::tr("Receiving...")); if(m_transfermode == id_send) { m_lay = m_win->factory()->newFileTransfer(protocol->currentText(), m_win->currentSession()->layer()); m_lay->sendFile(filename->text()); connect(m_lay, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int))); connect(m_lay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&))); connect(m_lay, SIGNAL(sent()), SLOT(slotSent())); } else { m_recvlay = m_win->factory()->newReceive(protocol->currentText(), m_win->currentSession()->layer()); m_recvlay->receive(); connect(m_recvlay, SIGNAL(progress(const QString&, int, int, int, int, int)), SLOT(slotProgress(const QString&, int, int, int, int, int))); connect(m_recvlay, SIGNAL(error(int, const QString&)), SLOT(slotError(int, const QString&))); connect(m_recvlay, SIGNAL(received(const QString&)), SLOT(slotReceived(const QString&))); } } void TransferDialog::cleanup() { if(m_lay) { m_lay->cancel(); delete m_lay; m_lay = 0l; } if(m_recvlay) { m_recvlay->cancel(); delete m_recvlay; m_recvlay = 0l; } } void TransferDialog::slotCancel() { ok->setEnabled(true); statusbar->setText(QObject::tr("Ready")); if((m_lay) || (m_recvlay)) { cleanup(); if(m_autocleanup) { m_running = false; close(); } else { QMessageBox::information(this, QObject::tr("Cancelled"), QObject::tr("The file transfer has been cancelled.")); } } else { m_running = false; close(); } } void TransferDialog::slotProgress(const QString& , int progress, int , int , int, int ) { progressbar->setProgress(progress); } void TransferDialog::slotError(int error, const QString& ) { statusbar->setText(QObject::tr("Ready")); switch(error) { case FileTransferLayer::NotSupported: QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("Operation not supported.")); break; case FileTransferLayer::StartError: QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("Transfer could not be started.")); break; case FileTransferLayer::NoError: QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("No error.")); break; case FileTransferLayer::Undefined: QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("Undefined error occured.")); break; case FileTransferLayer::Incomplete: QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("Incomplete transfer.")); break; case FileTransferLayer::Unknown: default: QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("Unknown error occured.")); break; } m_autocleanup = 1; } void TransferDialog::slotSent() { progressbar->setProgress(100); QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been sent.")); ok->setEnabled(true); progressbar->setProgress(0); statusbar->setText(QObject::tr("Ready")); m_autocleanup = 1; } void TransferDialog::slotReceived(const QString& ) { progressbar->setProgress(100); QMessageBox::information(this, QObject::tr("Received"), QObject::tr("File has been received.")); //QMessageBox::information(this, QObject::tr("Sent"), QObject::tr("File has been received as %1.").arg(file)); ok->setEnabled(true); progressbar->setProgress(0); statusbar->setText(QObject::tr("Ready")); m_autocleanup = 1; } void TransferDialog::slotMode(int id) { if(id == id_send) { selector->setEnabled(true); filename->setEnabled(true); } else { selector->setEnabled(false); filename->setEnabled(false); } m_transfermode = id; diff --git a/noncore/apps/opie-console/vt102emulation.cpp b/noncore/apps/opie-console/vt102emulation.cpp index 0ebefa0..35b789c 100644 --- a/noncore/apps/opie-console/vt102emulation.cpp +++ b/noncore/apps/opie-console/vt102emulation.cpp @@ -1,290 +1,285 @@ /* ------------------------------------------------------------------------- */ /* */ /* [vt102emulation.cpp] VT102 Terminal Emulation */ /* */ /* ------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* ------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /*! \class Vt102Emulation \brief Actual Emulation for Konsole \sa Widget \sa Screen \sa EmulationLayer */ #include "vt102emulation.h" -#include "widget_layer.h" -#include "screen.h" -#include "keytrans.h" #include <stdio.h> #include <unistd.h> -#include <qkeycode.h> -#include <qtextcodec.h> /* VT102 Terminal Emulation This class puts together the screens, the pty and the widget to a complete terminal emulation. Beside combining it's componentes, it handles the emulations's protocol. This module consists of the following sections: - Constructor/Destructor - Incoming Bytes Event pipeline - Outgoing Bytes - Mouse Events - Keyboard Events - Modes and Charset State - Diagnostics */ /* ------------------------------------------------------------------------- */ /* */ /* Constructor / Destructor */ /* */ /* ------------------------------------------------------------------------- */ /* Nothing really intesting happens here. */ /*! */ Vt102Emulation::Vt102Emulation(WidgetLayer* gui) : EmulationLayer(gui) { QObject::connect(gui,SIGNAL(mouseSignal(int,int,int)), this,SLOT(onMouse(int,int,int))); initTokenizer(); reset(); } /*! */ Vt102Emulation::~Vt102Emulation() { } /*! */ void Vt102Emulation::reset() { resetToken(); resetModes(); resetCharset(0); screen[0]->reset(); resetCharset(1); screen[0]->reset(); setCodec(0); setKeytrans("linux.keytab"); } /* ------------------------------------------------------------------------- */ /* */ /* Processing the incoming byte stream */ /* */ /* ------------------------------------------------------------------------- */ /* Incoming Bytes Event pipeline This section deals with decoding the incoming character stream. Decoding means here, that the stream is first seperated into `tokens' which are then mapped to a `meaning' provided as operations by the `TEScreen' class or by the emulation class itself. The pipeline proceeds as follows: - Tokenizing the ESC codes (onRcvChar) - VT100 code page translation of plain characters (applyCharset) - Interpretation of ESC codes (tau) The escape codes and their meaning are described in the technical reference of this program. */ // Tokens ------------------------------------------------------------------ -- /* Since the tokens are the central notion if this section, we've put them in front. They provide the syntactical elements used to represent the terminals operations as byte sequences. They are encodes here into a single machine word, so that we can later switch over them easily. Depending on the token itself, additional argument variables are filled with parameter values. The tokens are defined below: - CHR - Printable characters (32..255 but DEL (=127)) - CTL - Control characters (0..31 but ESC (= 27), DEL) - ESC - Escape codes of the form <ESC><CHR but `[]()+*#'> - ESC_DE - Escape codes of the form <ESC><any of `()+*#%'> C - CSI_PN - Escape codes of the form <ESC>'[' {Pn} ';' {Pn} C - CSI_PS - Escape codes of the form <ESC>'[' {Pn} ';' ... C - CSI_PR - Escape codes of the form <ESC>'[' '?' {Pn} ';' ... C - VT52 - VT52 escape codes - <ESC><Chr> - <ESC>'Y'{Pc}{Pc} - XTE_HA - Xterm hacks <ESC>`]' {Pn} `;' {Text} <BEL> note that this is handled differently The last two forms allow list of arguments. Since the elements of the lists are treated individually the same way, they are passed as individual tokens to the interpretation. Further, because the meaning of the parameters are names (althought represented as numbers), they are includes within the token ('N'). */ #define TY_CONSTR(T,A,N) ( ((((int)N) & 0xffff) << 16) | ((((int)A) & 0xff) << 8) | (((int)T) & 0xff) ) #define TY_CHR___( ) TY_CONSTR(0,0,0) #define TY_CTL___(A ) TY_CONSTR(1,A,0) #define TY_ESC___(A ) TY_CONSTR(2,A,0) #define TY_ESC_CS(A,B) TY_CONSTR(3,A,B) #define TY_ESC_DE(A ) TY_CONSTR(4,A,0) #define TY_CSI_PS(A,N) TY_CONSTR(5,A,N) #define TY_CSI_PN(A ) TY_CONSTR(6,A,0) #define TY_CSI_PR(A,N) TY_CONSTR(7,A,N) #define TY_VT52__(A ) TY_CONSTR(8,A,0) // Tokenizer --------------------------------------------------------------- -- /* The tokenizers state The state is represented by the buffer (pbuf, ppos), and accompanied by decoded arguments kept in (argv,argc). Note that they are kept internal in the tokenizer. */ void Vt102Emulation::resetToken() { ppos = 0; argc = 0; argv[0] = 0; argv[1] = 0; } void Vt102Emulation::addDigit(int dig) { argv[argc] = 10*argv[argc] + dig; } void Vt102Emulation::addArgument() { argc = QMIN(argc+1,MAXARGS-1); argv[argc] = 0; } void Vt102Emulation::pushToToken(int cc) { pbuf[ppos] = cc; ppos = QMIN(ppos+1,MAXPBUF-1); } // Character Classes used while decoding #define CTL 1 #define CHR 2 #define CPN 4 #define DIG 8 #define SCS 16 #define GRP 32 void Vt102Emulation::initTokenizer() { int i; UINT8* s; for(i = 0; i < 256; i++) tbl[ i] = 0; for(i = 0; i < 32; i++) tbl[ i] |= CTL; for(i = 32; i < 256; i++) tbl[ i] |= CHR; for(s = (UINT8*)"@ABCDGHLMPXcdfry"; *s; s++) tbl[*s] |= CPN; for(s = (UINT8*)"0123456789" ; *s; s++) tbl[*s] |= DIG; for(s = (UINT8*)"()+*%" ; *s; s++) tbl[*s] |= SCS; for(s = (UINT8*)"()+*#[]%" ; *s; s++) tbl[*s] |= GRP; resetToken(); } /* Ok, here comes the nasty part of the decoder. Instead of keeping an explicit state, we deduce it from the token scanned so far. It is then immediately combined with the current character to form a scanning decision. This is done by the following defines. - P is the length of the token scanned so far. - L (often P-1) is the position on which contents we base a decision. - C is a character or a group of characters (taken from 'tbl'). Note that they need to applied in proper order. */ #define lec(P,L,C) (p == (P) && s[(L)] == (C)) #define lun( ) (p == 1 && cc >= 32 ) #define les(P,L,C) (p == (P) && s[L] < 256 && (tbl[s[(L)]] & (C)) == (C)) #define eec(C) (p >= 3 && cc == (C)) #define ees(C) (p >= 3 && cc < 256 && (tbl[ cc ] & (C)) == (C)) #define eps(C) (p >= 3 && s[2] != '?' && cc < 256 && (tbl[ cc ] & (C)) == (C)) #define epp( ) (p >= 3 && s[2] == '?' ) #define egt( ) (p == 3 && s[2] == '>' ) #define Xpe (ppos>=2 && pbuf[1] == ']' ) #define Xte (Xpe && cc == 7 ) #define ces(C) ( cc < 256 && (tbl[ cc ] & (C)) == (C) && !Xte) #define ESC 27 #define CNTL(c) ((c)-'@') // process an incoming unicode character void Vt102Emulation::onRcvChar(int cc) { int i; if (cc == 127) return; //VT100: ignore. if (ces( CTL)) { // DEC HACK ALERT! Control Characters are allowed *within* esc sequences in VT100 // This means, they do neither a resetToken nor a pushToToken. Some of them, do // of course. Guess this originates from a weakly layered handling of the X-on // X-off protocol, which comes really below this level. if (cc == CNTL('X') || cc == CNTL('Z') || cc == ESC) resetToken(); //VT100: CAN or SUB if (cc != ESC) { tau( TY_CTL___(cc+'@' ), 0, 0); return; } } pushToToken(cc); // advance the state int* s = pbuf; int p = ppos; if (getMode(MODE_Ansi)) // decide on proper action { if (lec(1,0,ESC)) { return; } if (les(2,1,GRP)) { return; } if (Xte ) { XtermHack(); resetToken(); return; } if (Xpe ) { return; } if (lec(3,2,'?')) { return; } if (lec(3,2,'>')) { return; } if (lun( )) { tau( TY_CHR___(), applyCharset(cc), 0); resetToken(); return; } if (lec(2,0,ESC)) { tau( TY_ESC___(s[1]), 0, 0); resetToken(); return; } if (les(3,1,SCS)) { tau( TY_ESC_CS(s[1],s[2]), 0, 0); resetToken(); return; } if (lec(3,1,'#')) { tau( TY_ESC_DE(s[2]), 0, 0); resetToken(); return; } // if (egt( )) { tau( TY_CSI_PG(cc ), '>', 0); resetToken(); return; } if (eps( CPN)) { tau( TY_CSI_PN(cc), argv[0],argv[1]); resetToken(); return; } if (ees( DIG)) { addDigit(cc-'0'); return; } if (eec( ';')) { addArgument(); return; } for (i=0;i<=argc;i++) if (epp( )) tau( TY_CSI_PR(cc,argv[i]), 0, 0); else tau( TY_CSI_PS(cc,argv[i]), 0, 0); resetToken(); } else // mode VT52 diff --git a/noncore/apps/opie-console/widget.cpp b/noncore/apps/opie-console/widget.cpp index 10045c6..e17dfd4 100644 --- a/noncore/apps/opie-console/widget.cpp +++ b/noncore/apps/opie-console/widget.cpp @@ -1,333 +1,325 @@ /* ------------------------------------------------------------------------ */ /* */ /* [TEWidget.C] Terminal Emulation Widget */ /* */ /* ------------------------------------------------------------------------ */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* ------------------------------------------------------------------------ */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /* ibot: i changed "currentSession->getEmulation()->sendString()" to "currentSession->layer()->send()" # this is not right! EmulationLayer should send it... i changed all those to use emulationLayer()->send() instead i had to create a QByteArray before... TODO: alter Widget to use only QByteArray, where applicable. */ /*! \class Widget \brief Visible screen contents This class is responsible to map the `image' of a terminal emulation to the display. All the dependency of the emulation to a specific GUI or toolkit is localized here. Further, this widget has no knowledge about being part of an emulation, it simply work within the terminal emulation framework by exposing size and key events and by being ordered to show a new image. <ul> <li> The internal image has the size of the widget (evtl. rounded up) <li> The external image used in setImage can have any size. <li> (internally) the external image is simply copied to the internal when a setImage happens. During a resizeEvent no painting is done a paintEvent is expected to follow anyway. </ul> \sa TEScreen \sa Emulation */ /* FIXME: - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent - 'font_a' not used in mouse events - add destructor */ /* TODO - evtl. be sensitive to `paletteChange' while using default colors. - set different 'rounding' styles? I.e. have a mode to show clipped chars? */ // #include "config.h" #include "widget.h" -#include "session.h" #include <qpe/config.h> -#include <qapplication.h> -#include <qcursor.h> -#include <qregexp.h> -#include <qpainter.h> #include <qclipboard.h> -#include <qstyle.h> -#include <qfile.h> -#include <qdragobject.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <ctype.h> #include <sys/stat.h> #include <sys/types.h> #include <signal.h> #include <assert.h> // #include "widget.moc" //#include <kapp.h> //#include <kcursor.h> //#include <kurl.h> //#include <kdebug.h> //#include <klocale.h> #define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } #define loc(X,Y) ((Y)*columns+(X)) //FIXME: the rim should normally be 1, 0 only when running in full screen mode. #define rimX 0 // left/right rim width #define rimY 0 // top/bottom rim high #define yMouseScroll 1 // scroll increment used when dragging selection at top/bottom of window. /* ------------------------------------------------------------------------- */ /* */ /* Colors */ /* */ /* ------------------------------------------------------------------------- */ //FIXME: the default color table is in session.C now. // We need a way to get rid of this one, here. static const ColorEntry base_color_table[TABLE_COLORS] = // The following are almost IBM standard color codes, with some slight // gamma correction for the dim colors to compensate for bright X screens. // It contains the 8 ansiterm/xterm colors in 2 intensities. { // Fixme: could add faint colors here, also. // normal ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White // intensiv ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) }; /* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) Code 0 1 2 3 4 5 6 7 ----------- ------- ------- ------- ------- ------- ------- ------- ------- ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White */ QColor Widget::getDefaultBackColor() { return color_table[DEFAULT_BACK_COLOR].color; } const ColorEntry* Widget::getColorTable() const { return color_table; } const ColorEntry* Widget::getdefaultColorTable() const { return base_color_table; } const QPixmap *Widget::backgroundPixmap() { static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); const QPixmap *pm = bg; return pm; } void Widget::setColorTable(const ColorEntry table[]) { for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; const QPixmap* pm = backgroundPixmap(); if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); update(); } //FIXME: add backgroundPixmapChanged. /* ------------------------------------------------------------------------- */ /* */ /* Font */ /* */ /* ------------------------------------------------------------------------- */ /* The VT100 has 32 special graphical characters. The usual vt100 extended xterm fonts have these at 0x00..0x1f. QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals come in here as proper unicode characters. We treat non-iso10646 fonts as VT100 extended and do the requiered mapping from unicode to 0x00..0x1f. The remaining translation is then left to the QCodec. */ // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. unsigned short vt100_graphics[32] = { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 }; static QChar vt100extended(QChar c) { switch (c.unicode()) { case 0x25c6 : return 1; case 0x2592 : return 2; case 0x2409 : return 3; case 0x240c : return 4; case 0x240d : return 5; case 0x240a : return 6; case 0x00b0 : return 7; case 0x00b1 : return 8; case 0x2424 : return 9; case 0x240b : return 10; case 0x2518 : return 11; case 0x2510 : return 12; case 0x250c : return 13; case 0x2514 : return 14; case 0x253c : return 15; case 0xf800 : return 16; case 0xf801 : return 17; case 0x2500 : return 18; case 0xf803 : return 19; case 0xf804 : return 20; case 0x251c : return 21; case 0x2524 : return 22; case 0x2534 : return 23; case 0x252c : return 24; case 0x2502 : return 25; case 0x2264 : return 26; case 0x2265 : return 27; case 0x03c0 : return 28; case 0x2260 : return 29; case 0x00a3 : return 30; case 0x00b7 : return 31; } return c; } static QChar identicalMap(QChar c) { return c; } void Widget::fontChange(const QFont &) { QFontMetrics fm(font()); font_h = fm.height(); font_w = fm.maxWidth(); font_a = fm.ascent(); //printf("font_h: %d\n",font_h); //printf("font_w: %d\n",font_w); //printf("font_a: %d\n",font_a); //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); //printf("rawname: %s\n",font().rawName().ascii()); fontMap = #if QT_VERSION < 300 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") ? vt100extended : #endif identicalMap; propagateSize(); update(); } void Widget::setVTFont(const QFont& f) { QFrame::setFont(f); } QFont Widget::getVTFont() { return font(); } void Widget::setFont(const QFont &) { // ignore font change request if not coming from konsole itself } /* ------------------------------------------------------------------------- */ /* */ /* Constructor / Destructor */ /* */ /* ------------------------------------------------------------------------- */ Widget::Widget(QWidget *parent, const char *name) : QFrame(parent,name) { #ifndef QT_NO_CLIPBOARD cb = QApplication::clipboard(); QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); #endif scrollbar = new QScrollBar(this); scrollbar->setCursor( arrowCursor ); connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); Config cfg("Konsole"); cfg.setGroup("ScrollBar"); switch( cfg.readNumEntry("Position",2)){ case 0: scrollLoc = SCRNONE; break; case 1: scrollLoc = SCRLEFT; break; case 2: scrollLoc = SCRRIGHT; break; }; blinkT = new QTimer(this); connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); // blinking = FALSE; blinking = TRUE; resizing = FALSE; actSel = 0; image = 0; lines = 1; columns = 1; font_w = 1; font_h = 1; font_a = 1; word_selection_mode = FALSE; setMouseMarks(TRUE); diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp index ac84f8b..96dda1c 100644 --- a/noncore/apps/opie-console/widget_layer.cpp +++ b/noncore/apps/opie-console/widget_layer.cpp @@ -1,249 +1,245 @@ /* ------------------------------------------------------------------------- */ /* */ /* widget_layer.cpp Widget Layer */ /* */ /* opie developers <opie@handhelds.org> */ /* */ /* ------------------------------------------------------------------------- */ #include "widget_layer.h" -#include <qclipboard.h> -#include <qregexp.h> -#include <qglobal.h> #include <string.h> //#include < -#include "common.h" WidgetLayer::WidgetLayer( const Profile &config, QWidget *parent, const char *name ) : QFrame( parent, name ) { // get the clipboard m_clipboard = QApplication::clipboard(); // when data on clipboard changes, clear selection QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), (QObject*)this, SLOT( onClearSelection() ) ); // initialize vars: m_lines = 1; m_columns = 1; m_resizing = false; // just for demonstrating //m_image = QArray<Character>( m_lines * m_columns ); m_image = QArray<Character>( 1 ); // we need to install an event filter, // to emit keypresses. qApp->installEventFilter( this ); } WidgetLayer::~WidgetLayer() { // clean up delete m_image; } QSize WidgetLayer::sizeHint() { return size(); } /* --------------------------------- audio ---------------------------------- */ void WidgetLayer::bell() { QApplication::beep(); } bool WidgetLayer::eventFilter( QObject *obj, QEvent *e ) { if ( (e->type() == QEvent::Accel || e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { static_cast<QKeyEvent *>( e )->ignore(); return true; } if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) return false; // not us #ifdef FAKE_CTRL_AND_ALT static bool control = false; static bool alt = false; // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); bool dele = false; if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent* ke = (QKeyEvent*)e; bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); switch (ke->key()) { case Key_F9: // let this be "Control" control = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); dele=TRUE; break; case Key_F13: // let this be "Alt" alt = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); dele=TRUE; break; default: if ( control ) { int a = toupper(ke->ascii())-64; if ( a >= 0 && a < ' ' ) { e = new QKeyEvent(e->type(), ke->key(), a, ke->state()|ControlButton, QChar(a,0)); dele=TRUE; } } if ( alt ) { e = new QKeyEvent(e->type(), ke->key(), ke->ascii(), ke->state()|AltButton, ke->text()); dele=TRUE; } } } #endif if ( e->type() == QEvent::KeyPress ) { QKeyEvent* ke = (QKeyEvent*)e; //actSel=0; // Key stroke implies a screen update, so Widget won't // know where the current selection is. // qDebug("key pressed is 0x%x",ke->key()); if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker insertText("\\"); // expose } else emit keyPressed( ke ); // expose ke->accept(); #ifdef FAKE_CTRL_AND_ALT if ( dele ) delete e; #endif return true; // stop the event } return QFrame::eventFilter( obj, e ); } /* --------------------------------- screen --------------------------------- */ void WidgetLayer::propagateSize() { QArray<Character> oldimage = m_image.copy(); int oldlines = m_lines; int oldcolumns = m_columns; makeImage(); // copy old image, to reduce flicker if ( ! oldimage.isEmpty() ) { int lins = QMIN( oldlines, m_lines ); int cols = QMIN( oldcolumns, m_columns ); for ( int lin = 0; lin < lins; ++lin ) { memcpy( (void*) &m_image[m_columns*lin], (void*) &oldimage[oldcolumns*lin], cols*sizeof( Character ) ); } } else clearImage(); delete oldimage; m_resizing = true; emit imageSizeChanged( m_lines, m_columns ); m_resizing = false; } void WidgetLayer::makeImage() { calcGeometry(); m_image = QArray<Character>( m_columns * m_lines ); clearImage(); } void WidgetLayer::clearImage() { //should this belong here?? for ( int y = 0; y < m_lines; y++ ) for ( int x = 0; x < m_columns; x++ ) { m_image[loc(x,y)].c = 0xff; m_image[loc(x,y)].f = 0xff; m_image[loc(x,y)].b = 0xff; m_image[loc(x,y)].r = 0xff; } } /* --------------------------------- selection ------------------------------ */ void WidgetLayer::pasteClipboard() { insertSelection(); } void WidgetLayer::insertSelection() { QString text = QApplication::clipboard()->text(); if ( ! text.isNull() ) { text.replace( QRegExp( "\n" ), "\r" ); insertText( text ); // selection should be unselected emit selectionCleared(); } } void WidgetLayer::insertText( QString text ) { // text is inserted as key event QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text); emit keyPressed( &e ); } void WidgetLayer::onClearSelection() { emit selectionCleared(); } void WidgetLayer::setSelection( const QString& text ) { // why get the clipboard, we have it as instance var... QObject *m_clipboard = QApplication::clipboard(); // we know, that cliboard changes, when we change clipboard QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), (QObject*) this, SLOT( selectionCleared() ) ); QApplication::clipboard()->setText( text ); QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), (QObject*) this, SLOT( selectionCleared() ) ); } ///////// // special font characters ///////// unsigned short vt100_graphics[32] = { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 }; |