summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/MyPty.cpp5
-rw-r--r--noncore/apps/opie-console/TEWidget.cpp4
-rw-r--r--noncore/apps/opie-console/TEmulation.cpp5
-rw-r--r--noncore/apps/opie-console/atconfigdialog.cpp6
-rw-r--r--noncore/apps/opie-console/btconfigwidget.cpp22
-rw-r--r--noncore/apps/opie-console/comboboxhelper.cpp55
-rw-r--r--noncore/apps/opie-console/comboboxhelper.h49
-rw-r--r--noncore/apps/opie-console/dialer.cpp14
-rw-r--r--noncore/apps/opie-console/emulation_handler.cpp9
-rw-r--r--noncore/apps/opie-console/emulation_widget.cpp6
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp18
-rw-r--r--noncore/apps/opie-console/io_bt.cpp21
-rw-r--r--noncore/apps/opie-console/io_bt.h3
-rw-r--r--noncore/apps/opie-console/io_irda.cpp20
-rw-r--r--noncore/apps/opie-console/io_irda.h3
-rw-r--r--noncore/apps/opie-console/io_modem.cpp22
-rw-r--r--noncore/apps/opie-console/io_modem.h7
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp7
-rw-r--r--noncore/apps/opie-console/modemconfigwidget.cpp19
-rw-r--r--noncore/apps/opie-console/opie-console.pro8
-rw-r--r--noncore/apps/opie-console/profileeditordialog.cpp22
-rw-r--r--noncore/apps/opie-console/serialconfigwidget.cpp23
-rw-r--r--noncore/apps/opie-console/settings.ui23
-rw-r--r--noncore/apps/opie-console/sz_transfer.cpp23
-rw-r--r--noncore/apps/opie-console/tabwidget.cpp4
-rw-r--r--noncore/apps/opie-console/terminalwidget.cpp6
-rw-r--r--noncore/apps/opie-console/vt102emulation.cpp1024
-rw-r--r--noncore/apps/opie-console/vt102emulation.h153
-rw-r--r--noncore/apps/opie-console/widget.cpp1278
-rw-r--r--noncore/apps/opie-console/widget.h213
-rw-r--r--noncore/apps/opie-console/widget_layer.cpp242
-rw-r--r--noncore/apps/opie-console/widget_layer.h265
32 files changed, 144 insertions, 3435 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp
index 315ea4a..27ba9ff 100644
--- a/noncore/apps/opie-console/MyPty.cpp
+++ b/noncore/apps/opie-console/MyPty.cpp
@@ -1,371 +1,366 @@
/* -------------------------------------------------------------------------- */
/* */
/* [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 "procctl.h"
#include "MyPty.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
/* QT */
#include <qsocketnotifier.h>
#include <qfile.h>
/* STD */
#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
#undef VERBOSE_DEBUG
/* -------------------------------------------------------------------------- */
/*!
Informs the client program about the
actual size of the window.
*/
void MyPty::setSize(int lines, int columns)
{
- owarn << "setting size" << oendl;
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");
#endif
::write(m_fd, ar.data(), ar.count());
}
/*! indicates that a block of data is received */
void MyPty::readPty()
{
QByteArray buf(4096);
int len = ::read( m_fd, buf.data(), 4096 );
if (len == -1 || len == 0) {
donePty();
return;
}
if (len < 0)
return;
buf.resize(len);
emit received(buf);
#ifdef VERBOSE_DEBUG
// verbose debug
printf("read bytes:\n");
for (uint i = 0; i < buf.count(); i++)
printf("%c", buf[i]);
printf("\n");
#endif
}
QBitArray MyPty::supports()const {
QBitArray ar(3);
//autoconnect
ar[0] = 1;
//
ar[1] = 0;
ar[2] = 0;
return ar;
}
diff --git a/noncore/apps/opie-console/TEWidget.cpp b/noncore/apps/opie-console/TEWidget.cpp
index d168a5e..98c1793 100644
--- a/noncore/apps/opie-console/TEWidget.cpp
+++ b/noncore/apps/opie-console/TEWidget.cpp
@@ -1,1356 +1,1352 @@
/* ------------------------------------------------------------------------ */
/* */
/* [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 <qpe/config.h>
#include <qapplication.h>
#include <qclipboard.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)));
hscrollbar = new QScrollBar( Qt::Horizontal, this );
hscrollbar->setCursor( arrowCursor );
connect(hscrollbar, SIGNAL(valueChanged(int)), this, SLOT(hscrollChanged(int)));
m_cornerButton = new QPushButton( this );
m_cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
m_cornerButton->setMaximumSize( 14, 14 );
m_cornerButton->hide();
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;
vcolumns = 0;
hposition = 0;
setMouseMarks(TRUE);
setVTFont( QFont("fixed") );
setColorTable(base_color_table); // init color table
qApp->installEventFilter( this ); //FIXME: see below
// KCursor::setAutoHideCursor( this, true );
// Init DnD ////////////////////////////////////////////////////////////////
currentSession = NULL;
// setAcceptDrops(true); // attempt
// m_drop = new QPopupMenu(this);
// m_drop->insertItem( QString("Paste"), 0);
// m_drop->insertItem( QString("cd"), 1);
// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
// we need focus so that the auto-hide cursor feature works
setFocus();
setFocusPolicy( WheelFocus );
}
//FIXME: make proper destructor
// Here's a start (David)
TEWidget::~TEWidget()
{
qApp->removeEventFilter( this );
if (image) free(image);
}
/* ------------------------------------------------------------------------- */
/* */
/* Display Operations */
/* */
/* ------------------------------------------------------------------------- */
/*!
attributed string draw primitive
*/
void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
QString& str, ca attr, BOOL pm, BOOL clear)
{
if (pm && color_table[attr.b].transparent)
{
paint.setBackgroundMode( TransparentMode );
if (clear) erase(rect);
}
else
{
if (blinking)
paint.fillRect(rect, color_table[attr.b].color);
else
{
paint.setBackgroundMode( OpaqueMode );
paint.setBackgroundColor( color_table[attr.b].color );
}
}
if (color_table[attr.f].bold)
paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
else
paint.setPen(color_table[attr.f].color);
paint.drawText(rect.x(),rect.y()+font_a, str);
if (attr.r & RE_UNDERLINE)
paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
}
/*!
The image can only be set completely.
The size of the new image may or may not match the size of the widget.
*/
void TEWidget::setImage(const ca* const newimg, int lines, int columns)
{ int y,x,len;
const QPixmap* pm = backgroundPixmap();
QPainter paint;
setUpdatesEnabled(FALSE);
paint.begin( this );
HCNT("setImage");
QPoint tL = contentsRect().topLeft();
int tLx = tL.x();
int tLy = tL.y();
hasBlinker = FALSE;
int cf = -1; // undefined
int cb = -1; // undefined
int cr = -1; // undefined
int lins = QMIN(this->lines, QMAX(0,lines ));
int cols = QMIN(this->columns,QMAX(0,columns));
QChar *disstrU = new QChar[cols];
//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
for (y = 0; y < lins; y++)
{
const ca* lcl = &image[y*this->columns];
const ca* const ext = &newimg[y*columns];
if (!resizing) // not while resizing, we're expecting a paintEvent
for (x = 0; x < cols; x++)
{
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] = fontMap(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] = fontMap(ext[x+len].c);
}
QString unistr(disstrU,len);
drawAttrStr(paint,
QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
unistr, ext[x], pm != NULL, true);
x += len - 1;
}
}
// finally, make `image' become `newimg'.
memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
}
drawFrame( &paint );
paint.end();
setUpdatesEnabled(TRUE);
if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
delete [] disstrU;
}
// paint Event ////////////////////////////////////////////////////
/*!
The difference of this routine vs. the `setImage' is,
that the drawing does not include a difference analysis
between the old and the new image. Instead, the internal
image is used and the painting bound by the PaintEvent box.
*/
void TEWidget::paintEvent( QPaintEvent* pe )
{
//{ static int cnt = 0; printf("paint %d\n",cnt++); }
const QPixmap* pm = backgroundPixmap();
QPainter paint;
setUpdatesEnabled(FALSE);
paint.begin( this );
paint.setBackgroundMode( TransparentMode );
HCNT("paintEvent");
// Note that the actual widget size can be slightly larger
// that the image (the size is truncated towards the smaller
// number of characters in `resizeEvent'. The paint rectangle
// can thus be larger than the image, but less then the size
// of one character.
QRect rect = pe->rect().intersect(contentsRect());
QPoint tL = contentsRect().topLeft();
int tLx = tL.x();
int tLy = tL.y();
int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
/*
printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
rect.left(), rect.right(), rect.top(), rect.bottom());
*/
// if (pm != NULL && color_table[image->b].transparent)
// erase(rect);
// BL: I have no idea why we need this, and it breaks the refresh.
QChar *disstrU = new QChar[columns];
for (int y = luy; y <= rly; y++)
for (int x = lux; x <= rlx; x++)
{
int len = 1;
disstrU[0] = fontMap(image[loc(x,y)].c);
int cf = image[loc(x,y)].f;
int cb = image[loc(x,y)].b;
int cr = image[loc(x,y)].r;
while (x+len <= rlx &&
image[loc(x+len,y)].f == cf &&
image[loc(x+len,y)].b == cb &&
image[loc(x+len,y)].r == cr )
{
disstrU[len] = fontMap(image[loc(x+len,y)].c);
len += 1;
}
QString unistr(disstrU,len);
drawAttrStr(paint,
QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
unistr, image[loc(x,y)], pm != NULL, false);
x += len - 1;
}
delete [] disstrU;
drawFrame( &paint );
paint.end();
setUpdatesEnabled(TRUE);
}
void TEWidget::blinkEvent()
{
blinking = !blinking;
repaint(FALSE);
}
/* ------------------------------------------------------------------------- */
/* */
/* Resizing */
/* */
/* ------------------------------------------------------------------------- */
void TEWidget::resizeEvent(QResizeEvent* ev)
{
// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
//printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
//printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
//printf("curren: %d,%d\n",width(),height());
HCNT("resizeEvent");
// see comment in `paintEvent' concerning the rounding.
//FIXME: could make a routine here; check width(),height()
assert(ev->size().width() == width());
assert(ev->size().height() == height());
propagateSize();
}
void TEWidget::propagateSize()
{
ca* oldimg = image;
int oldlin = lines;
int oldcol = columns;
makeImage();
// we copy the old image to reduce flicker
int lins = QMIN(oldlin,lines);
int cols = QMIN(oldcol,columns);
if (oldimg)
{
for (int lin = 0; lin < lins; lin++)
memcpy((void*)&image[columns*lin],
(void*)&oldimg[oldcol*lin],cols*sizeof(ca));
free(oldimg); //FIXME: try new,delete
}
else
clearImage();
//NOTE: control flows from the back through the chest right into the eye.
// `emu' will call back via `setImage'.
resizing = TRUE;
emit changedImageSizeSignal(lines, columns); // expose resizeEvent
resizing = FALSE;
}
/* ------------------------------------------------------------------------- */
/* */
/* Scrollbar */
/* */
/* ------------------------------------------------------------------------- */
void TEWidget::scrollChanged(int)
{
emit changedHistoryCursor(scrollbar->value()); //expose
}
void TEWidget::hscrollChanged(int loc)
{
hposition = loc;
propagateSize();
update();
}
void TEWidget::setScroll(int cursor, int slines)
{
disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
scrollbar->setRange(0,slines);
scrollbar->setSteps(1,lines);
scrollbar->setValue(cursor);
connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
}
void TEWidget::setScrollbarLocation(int loc)
{
if (scrollLoc == loc) return; // quickly
scrollLoc = loc;
propagateSize();
update();
}
/* ------------------------------------------------------------------------- */
/* */
/* Mouse */
/* */
/* ------------------------------------------------------------------------- */
/*!
Three different operations can be performed using the mouse, and the
routines in this section serve all of them:
1) The press/release events are exposed to the application
2) Marking (press and move left button) and Pasting (press middle button)
3) The right mouse button is used from the configuration menu
NOTE: During the marking process we attempt to keep the cursor within
the bounds of the text as being displayed by setting the mouse position
whenever the mouse has left the text area.
Two reasons to do so:
1) QT does not allow the `grabMouse' to confine-to the TEWidget.
Thus a `XGrapPointer' would have to be used instead.
2) Even if so, this would not help too much, since the text area
of the TEWidget is normally not identical with it's bounds.
The disadvantage of the current handling is, that the mouse can visibly
leave the bounds of the widget and is then moved back. Because of the
current construction, and the reasons mentioned above, we cannot do better
without changing the overall construction.
*/
/*!
*/
void TEWidget::mousePressEvent(QMouseEvent* ev)
{
//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
if ( !contentsRect().contains(ev->pos()) ) return;
QPoint tL = contentsRect().topLeft();
int tLx = tL.x();
int tLy = tL.y();
word_selection_mode = FALSE;
//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
if ( ev->button() == LeftButton)
{
QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
if (mouse_marks || (ev->state() & ShiftButton))
{
emit clearSelectionSignal();
iPntSel = pntSel = pos;
actSel = 1; // left mouse button pressed but nothing selected yet.
grabMouse( /*crossCursor*/ ); // handle with care!
}
else
{
emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
}
}
if ( ev->button() == MidButton )
{
emitSelection();
}
if ( ev->button() == RightButton ) // Configure
{
emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
}
}
void TEWidget::mouseMoveEvent(QMouseEvent* ev)
{
// for auto-hiding the cursor, we need mouseTracking
if (ev->state() == NoButton ) return;
if (actSel == 0) return;
// don't extend selection while pasting
if (ev->state() & MidButton) return;
//if ( !contentsRect().contains(ev->pos()) ) return;
QPoint tL = contentsRect().topLeft();
int tLx = tL.x();
int tLy = tL.y();
int scroll = scrollbar->value();
// we're in the process of moving the mouse with the left button pressed
// the mouse cursor will kept catched within the bounds of the text in
// this widget.
// Adjust position within text area bounds. See FIXME above.
QPoint pos = ev->pos();
if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
// check if we produce a mouse move event by this
if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
if ( pos.y() == tLy+bY+lines*font_h-1 )
{
scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
}
if ( pos.y() == tLy+bY )
{
scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
}
QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
QPoint ohere;
bool swapping = FALSE;
if ( word_selection_mode )
{
// Extend to word boundaries
int i;
int selClass;
bool left_not_right = ( here.y() < iPntSel.y() ||
here.y() == iPntSel.y() && here.x() < iPntSel.x() );
bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
swapping = left_not_right != old_left_not_right;
// Find left (left_not_right ? from here : from start)
QPoint left = left_not_right ? here : iPntSel;
i = loc(left.x(),left.y());
selClass = charClass(image[i].c);
while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
{ i--; left.rx()--; }
// Find left (left_not_right ? from start : from here)
QPoint right = left_not_right ? iPntSel : here;
i = loc(right.x(),right.y());
selClass = charClass(image[i].c);
while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
{ i++; right.rx()++; }
// Pick which is start (ohere) and which is extension (here)
if ( left_not_right )
{
here = left; ohere = right;
}
else
{
here = right; ohere = left;
}
}
if (here == pntSel && scroll == scrollbar->value()) return; // not moved
if ( word_selection_mode ) {
if ( actSel < 2 || swapping ) {
emit beginSelectionSignal( ohere.x(), ohere.y() );
}
} else if ( actSel < 2 ) {
emit beginSelectionSignal( pntSel.x(), pntSel.y() );
}
actSel = 2; // within selection
pntSel = here;
emit extendSelectionSignal( here.x(), here.y() );
}
void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
{
//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
if ( ev->button() == LeftButton)
{
if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
preserve_line_breaks = TRUE;
actSel = 0;
//FIXME: emits a release event even if the mouse is
// outside the range. The procedure used in `mouseMoveEvent'
// applies here, too.
QPoint tL = contentsRect().topLeft();
int tLx = tL.x();
int tLy = tL.y();
if (!mouse_marks && !(ev->state() & ShiftButton))
emit mouseSignal( 3, // release
(ev->x()-tLx-blX)/font_w + 1,
(ev->y()-tLy-bY)/font_h + 1 );
releaseMouse();
}
}
void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
{
if ( ev->button() != LeftButton) return;
QPoint tL = contentsRect().topLeft();
int tLx = tL.x();
int tLy = tL.y();
QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
// pass on double click as two clicks.
if (!mouse_marks && !(ev->state() & ShiftButton))
{
emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
return;
}
emit clearSelectionSignal();
QPoint bgnSel = pos;
QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
int i = loc(bgnSel.x(),bgnSel.y());
iPntSel = bgnSel;
word_selection_mode = TRUE;
// find word boundaries...
int selClass = charClass(image[i].c);
{
// set the start...
int x = bgnSel.x();
while ( x > 0 && charClass(image[i-1].c) == selClass )
{ i--; x--; }
bgnSel.setX(x);
emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
// set the end...
i = loc( endSel.x(), endSel.y() );
x = endSel.x();
while( x < columns-1 && charClass(image[i+1].c) == selClass )
{ i++; x++ ; }
endSel.setX(x);
actSel = 2; // within selection
emit extendSelectionSignal( endSel.x(), endSel.y() );
emit endSelectionSignal(preserve_line_breaks);
preserve_line_breaks = TRUE;
}
}
void TEWidget::focusInEvent( QFocusEvent * )
{
// do nothing, to prevent repainting
}
void TEWidget::focusOutEvent( QFocusEvent * )
{
// do nothing, to prevent repainting
}
bool TEWidget::focusNextPrevChild( bool next )
{
if (next)
return false; // This disables changing the active part in konqueror
// when pressing Tab
return QFrame::focusNextPrevChild( next );
}
int TEWidget::charClass(char ch) const
{
// This might seem like overkill, but imagine if ch was a Unicode
// character (Qt 2.0 QChar) - it might then be sensible to separate
// the different language ranges, etc.
if ( isspace(ch) ) return ' ';
static const char *word_characters = ":@-./_~";
if ( isalnum(ch) || strchr(word_characters, ch) )
return 'a';
// Everything else is weird
return 1;
}
void TEWidget::setMouseMarks(bool on)
{
mouse_marks = on;
setCursor( mouse_marks ? ibeamCursor : arrowCursor );
}
/* ------------------------------------------------------------------------- */
/* */
/* Clipboard */
/* */
/* ------------------------------------------------------------------------- */
#undef KeyPress
void TEWidget::emitSelection()
// Paste Clipboard by simulating keypress events
{
#ifndef QT_NO_CLIPBOARD
QString text = QApplication::clipboard()->text();
if ( ! text.isNull() )
{
text.replace(QRegExp("\n"), "\r");
QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
emit keyPressedSignal(&e); // expose as a big fat keypress event
emit clearSelectionSignal();
}
#endif
}
void TEWidget::emitText(QString text)
{
QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
emit keyPressedSignal(&e); // expose as a big fat keypress event
}
void TEWidget::pasteClipboard( )
{
emitSelection();
}
void TEWidget::setSelection(const QString& t)
{
#ifndef QT_NO_CLIPBOARD
// Disconnect signal while WE set the clipboard
QObject *cb = QApplication::clipboard();
QObject::disconnect( cb, SIGNAL(dataChanged()),
this, SLOT(onClearSelection()) );
QApplication::clipboard()->setText(t);
QObject::connect( cb, SIGNAL(dataChanged()),
this, SLOT(onClearSelection()) );
#endif
}
void TEWidget::onClearSelection()
{
emit clearSelectionSignal();
}
/* ------------------------------------------------------------------------- */
/* */
/* Keyboard */
/* */
/* ------------------------------------------------------------------------- */
//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
// due to a bug in `QT' or the ignorance of the author to prevent
// repaint events being emitted to the screen whenever one leaves
// or reenters the screen to/from another application.
//
// Troll says one needs to change focusInEvent() and focusOutEvent(),
// which would also let you have an in-focus cursor and an out-focus
// cursor like xterm does.
// for the auto-hide cursor feature, I added empty focusInEvent() and
// focusOutEvent() so that update() isn't called.
// For auto-hide, we need to get keypress-events, but we only get them when
// we have focus.
void TEWidget::doScroll(int lines)
{
scrollbar->setValue(scrollbar->value()+lines);
}
bool TEWidget::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
if ( e->type() == QEvent::Wheel) {
QApplication::sendEvent(scrollbar, e);
}
#ifdef FAKE_CTRL_AND_ALT
static bool control = FALSE;
static bool alt = FALSE;
-// odebug << " Has a keyboard with no CTRL and ALT keys, but we fake it:" << oendl;
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 TEWidget won't
// know where the current selection is.
-// odebug << "key pressed is 0x" << ke->key() << "" << oendl;
if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
-
-// odebug << "key pressed 2 is 0x" << ke->key() << "" << oendl;
emitText("\\"); // expose
} else
emit keyPressedSignal(ke); // expose
ke->accept();
#ifdef FAKE_CTRL_AND_ALT
if ( dele ) delete e;
#endif
return true; // stop the event
}
if ( e->type() == QEvent::Enter ) {
QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
this, SLOT(onClearSelection()) );
}
if ( e->type() == QEvent::Leave ) {
QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
this, SLOT(onClearSelection()) );
}
return QFrame::eventFilter( obj, e );
}
/* ------------------------------------------------------------------------- */
/* */
/* Frame */
/* */
/* ------------------------------------------------------------------------- */
void TEWidget::frameChanged()
{
propagateSize();
update();
}
/* ------------------------------------------------------------------------- */
/* */
/* Sound */
/* */
/* ------------------------------------------------------------------------- */
void TEWidget::Bell()
{
QApplication::beep();
}
/* ------------------------------------------------------------------------- */
/* */
/* Auxiluary */
/* */
/* ------------------------------------------------------------------------- */
void TEWidget::clearImage()
// initialize the image
// for internal use only
{
for (int y = 0; y < lines; y++)
for (int x = 0; x < columns; x++)
{
image[loc(x,y)].c = 0xff; //' ';
image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
}
}
// Create Image ///////////////////////////////////////////////////////
void TEWidget::calcGeometry()
{
//FIXME: set rimX == rimY == 0 when running in full screen mode.
int showhscrollbar = 1;
int hwidth = 0;
int dcolumns;
if(vcolumns == 0) showhscrollbar = 0;
if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
scrollbar->resize(QApplication::style().scrollBarExtent().width(),
contentsRect().height() - hwidth);
if(!showhscrollbar) cornerButton()->move(0, 0);
else cornerButton()->move(contentsRect().width() - hwidth, contentsRect().height() - hwidth);
switch(scrollLoc)
{
case SCRNONE :
columns = ( contentsRect().width() - 2 * rimX ) / font_w;
dcolumns = columns;
if(vcolumns) columns = vcolumns;
blX = (contentsRect().width() - (columns*font_w) ) / 2;
if(showhscrollbar)
blX = -hposition * font_w;
brX = blX;
scrollbar->hide();
break;
case SCRLEFT :
columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
dcolumns = columns;
if(vcolumns) columns = vcolumns;
brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
if(showhscrollbar)
brX = -hposition * font_w;
blX = brX + scrollbar->width();
scrollbar->move(contentsRect().topLeft());
scrollbar->show();
break;
case SCRRIGHT:
columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
dcolumns = columns;
if(vcolumns) columns = vcolumns;
blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
if(showhscrollbar)
blX = -hposition * font_w;
brX = blX;
scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
scrollbar->show();
break;
}
//FIXME: support 'rounding' styles
lines = ( contentsRect().height() - 2 * rimY ) / font_h;
bY = (contentsRect().height() - (lines *font_h)) / 2;
if(showhscrollbar == 1)
{
hscrollbar->resize(contentsRect().width() - hwidth, hwidth);
hscrollbar->setRange(0, vcolumns - dcolumns);
QPoint p = contentsRect().bottomLeft();
hscrollbar->move(QPoint(p.x(), p.y() - hwidth));
hscrollbar->show();
}
else hscrollbar->hide();
if(showhscrollbar == 1)
{
lines = lines - (hwidth / font_h) - 1;
if(lines < 1) lines = 1;
}
}
void TEWidget::makeImage()
//FIXME: rename 'calcGeometry?
{
calcGeometry();
image = (ca*) malloc(lines*columns*sizeof(ca));
clearImage();
}
// calculate the needed size
QSize TEWidget::calcSize(int cols, int lins) const
{
int frw = width() - contentsRect().width();
int frh = height() - contentsRect().height();
int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
}
QSize TEWidget::sizeHint() const
{
return size();
}
void TEWidget::styleChange(QStyle &)
{
propagateSize();
}
#ifdef QT_NO_DRAGANDDROP_FOO
/* --------------------------------------------------------------------- */
/* */
/* Drag & Drop */
/* */
/* --------------------------------------------------------------------- */
void TEWidget::dragEnterEvent(QDragEnterEvent* e)
{
e->accept(QTextDrag::canDecode(e) ||
QUriDrag::canDecode(e));
}
void TEWidget::dropEvent(QDropEvent* event)
{
// The current behaviour when url(s) are dropped is
// * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
// * in all other cases, just paste
// (for non-local ones, or for a list of URLs, 'cd' is nonsense)
QStrList strlist;
int file_count = 0;
dropText = "";
bool bPopup = true;
if(QUriDrag::decode(event, strlist)) {
if (strlist.count()) {
for(const char* p = strlist.first(); p; p = strlist.next()) {
if(file_count++ > 0) {
dropText += " ";
bPopup = false; // more than one file, don't popup
}
/*
KURL url(p);
if (url.isLocalFile()) {
dropText += url.path(); // local URL : remove protocol
}
else {
dropText += url.prettyURL();
bPopup = false; // a non-local file, don't popup
}
*/
}
if (bPopup)
// m_drop->popup(pos() + event->pos());
m_drop->popup(mapToGlobal(event->pos()));
else
{
if (currentSession) {
currentSession->getEmulation()->sendString(dropText.local8Bit());
}
// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
}
}
}
else if(QTextDrag::decode(event, dropText)) {
// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
if (currentSession) {
currentSession->getEmulation()->sendString(dropText.local8Bit());
}
// Paste it
}
}
#endif
void TEWidget::drop_menu_activated(int)
{
#ifdef QT_NO_DRAGANDDROP_FOO
switch (item)
{
case 0: // paste
currentSession->getEmulation()->sendString(dropText.local8Bit());
// KWM::activate((Window)this->winId());
break;
case 1: // cd ...
currentSession->getEmulation()->sendString("cd ");
struct stat statbuf;
if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
{
if ( !S_ISDIR(statbuf.st_mode) )
{
/*
KURL url;
url.setPath( dropText );
dropText = url.directory( true, false ); // remove filename
*/
}
}
dropText.replace(QRegExp(" "), "\\ "); // escape spaces
currentSession->getEmulation()->sendString(dropText.local8Bit());
currentSession->getEmulation()->sendString("\n");
// KWM::activate((Window)this->winId());
break;
}
#endif
}
QPushButton* TEWidget::cornerButton() {
return m_cornerButton;
}
void TEWidget::setWrapAt(int columns)
{
vcolumns = columns;
propagateSize();
update();
}
diff --git a/noncore/apps/opie-console/TEmulation.cpp b/noncore/apps/opie-console/TEmulation.cpp
index 6ff73af..72cce75 100644
--- a/noncore/apps/opie-console/TEmulation.cpp
+++ b/noncore/apps/opie-console/TEmulation.cpp
@@ -1,369 +1,364 @@
/* -------------------------------------------------------------------------- */
/* */
/* [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"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
/* STD */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.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 )
{
- owarn << "onKeyPress,...." << oendl;
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();
}
}
// ---------------------------------------------------------------------------
/*! triggered by image size change of the TEWidget `gui'.
This event is simply propagated to the attached screens
and to the related serial line.
*/
void TEmulation::onImageSizeChange(int lines, int columns)
{
if (!connected) return;
screen[0]->resizeImage(lines,columns);
screen[1]->resizeImage(lines,columns);
showBulk();
emit ImageSizeChanged(lines,columns); // propagate event to serial line
}
void TEmulation::onHistoryCursorChange(int cursor)
{
if (!connected) return;
scr->setHistCursor(cursor);
showBulk();
}
void TEmulation::setColumns(int columns)
{
//FIXME: this goes strange ways.
// Can we put this straight or explain it at least?
emit changeColumns(columns);
}
diff --git a/noncore/apps/opie-console/atconfigdialog.cpp b/noncore/apps/opie-console/atconfigdialog.cpp
index c998f96..f958b52 100644
--- a/noncore/apps/opie-console/atconfigdialog.cpp
+++ b/noncore/apps/opie-console/atconfigdialog.cpp
@@ -1,218 +1,212 @@
#include "atconfigdialog.h"
#include "io_modem.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
/* QT */
#include <qlineedit.h>
#include <qspinbox.h>
#include <qlayout.h>
#include <qcombobox.h>
#include <qtabwidget.h>
#include <qlabel.h>
#include <qscrollview.h>
ATConfigDialog::ATConfigDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl ) {
setCaption( tr( "Dialing parameter setup" ) );
QVBoxLayout *layout = new QVBoxLayout( this );
QTabWidget *tabWidget = new QTabWidget( this );
tabWidget->addTab( tab0( this ), tr("Settings1") );
tabWidget->addTab( tab1( this ), tr("Settings2") );
layout->addWidget( tabWidget );
}
QWidget* ATConfigDialog::tab0( QWidget* parent) {
QScrollView* sv = new QScrollView( parent );
QWidget *returnWidget = new QWidget( sv->viewport() );
sv->setResizePolicy( QScrollView::AutoOneFit );
// sv->setHScrollBarMode( QScrollView::AlwaysOff );
// sv->setFrameShape( QFrame::NoFrame );
QGridLayout *layout = new QGridLayout( returnWidget, 10, 2 );
QLabel *initStringLabel = new QLabel( tr("Init string "), returnWidget );
initStringLine = new QLineEdit( returnWidget );
layout->addWidget( initStringLabel, 0, 0 );
layout->addWidget( initStringLine, 0, 1 );
QLabel *resetStringLabel = new QLabel( tr("Reset string "), returnWidget );
resetStringLine = new QLineEdit( returnWidget );
layout->addWidget( resetStringLabel, 1, 0 );
layout->addWidget( resetStringLine, 1, 1 );
QLabel *dialPref1Label = new QLabel( tr("Dialing prefix #1 " ), returnWidget );
dialPref1Line = new QLineEdit( returnWidget );
layout->addWidget( dialPref1Label, 2, 0 );
layout->addWidget( dialPref1Line, 2, 1 );
QLabel *dialSuf1Label = new QLabel( tr("Dialing suffix #1 " ), returnWidget );
dialSuf1Line = new QLineEdit( returnWidget );
layout->addWidget( dialSuf1Label, 3, 0 );
layout->addWidget( dialSuf1Line, 3, 1 );
QLabel *dialPref2Label = new QLabel( tr("Dialing prefix #2 " ), returnWidget );
dialPref2Line = new QLineEdit( returnWidget );
layout->addWidget( dialPref2Label, 4, 0 );
layout->addWidget( dialPref2Line, 4, 1 );
QLabel *dialSuf2Label = new QLabel( tr("Dialing suffix #2 " ), returnWidget );
dialSuf2Line = new QLineEdit( returnWidget );
layout->addWidget( dialSuf2Label, 5, 0 );
layout->addWidget( dialSuf2Line, 5, 1 );
QLabel *dialPref3Label = new QLabel( tr("Dialing prefix #3 " ), returnWidget );
dialPref3Line = new QLineEdit( returnWidget );
layout->addWidget( dialPref3Label, 6, 0 );
layout->addWidget( dialPref3Line, 6, 1 );
QLabel *dialSuf3Label = new QLabel( tr("Dialing suffix #3 " ), returnWidget );
dialSuf3Line = new QLineEdit( returnWidget );
layout->addWidget( dialSuf3Label, 7, 0 );
layout->addWidget( dialSuf3Line, 7, 1 );
QLabel *connectLabel = new QLabel( tr("Connect string " ), returnWidget );
connectLine = new QLineEdit( returnWidget );
layout->addWidget( connectLabel, 8, 0 );
layout->addWidget( connectLine, 8, 1 );
QLabel *hangupLabel = new QLabel( tr("Hang-up string " ), returnWidget );
hangupLine = new QLineEdit( returnWidget );
layout->addWidget( hangupLabel, 9, 0 );
layout->addWidget( hangupLine, 9, 1 );
sv->addChild( returnWidget );
return sv;
}
QWidget* ATConfigDialog::tab1( QWidget* parent ) {
QWidget *returnWidget = new QWidget( parent );
QGridLayout *layout = new QGridLayout( returnWidget, 8, 2 );
QLabel *dialTimeLabel = new QLabel( tr("Dial time " ), returnWidget );
dialTimeSpin = new QSpinBox( returnWidget );
layout->addWidget( dialTimeLabel, 0, 0 );
layout->addWidget( dialTimeSpin, 0, 1 );
QLabel *delayRedialLabel = new QLabel( tr("Delay before redial " ), returnWidget );
delayRedialSpin = new QSpinBox( returnWidget );
layout->addWidget( delayRedialLabel, 1, 0 );
layout->addWidget( delayRedialSpin, 1, 1 );
QLabel *numberTriesLabel = new QLabel( tr("Number of tries " ), returnWidget );
numberTriesSpin = new QSpinBox( returnWidget );
layout->addWidget( numberTriesLabel, 2, 0 );
layout->addWidget( numberTriesSpin, 2, 1 );
QLabel *dtrDropTimeLabel = new QLabel( tr("DTR drop time (0=no) " ), returnWidget );
dtrDropTimeSpin = new QSpinBox( returnWidget );
layout->addWidget( dtrDropTimeLabel, 3, 0 );
layout->addWidget( dtrDropTimeSpin, 3, 1 );
QLabel *bpsDetectLabel = new QLabel( tr("Auto bps detect " ), returnWidget );
bpsDetectBox = new QComboBox( returnWidget );
layout->addWidget( bpsDetectLabel, 4, 0 );
layout->addWidget( bpsDetectBox, 4, 1 );
bpsDetectBox->insertItem( tr("No") );
bpsDetectBox->insertItem( tr("Yes") );
QLabel *dcdLinesLabel = new QLabel( tr("Modem has DCD line " ), returnWidget );
dcdLinesBox = new QComboBox( returnWidget );
layout->addWidget( dcdLinesLabel, 5, 0 );
layout->addWidget( dcdLinesBox, 5, 1 );
dcdLinesBox->insertItem( tr("No") );
dcdLinesBox->insertItem( tr("Yes") );
QLabel *multiLineUntagLabel = new QLabel( tr("Multi-line untag " ), returnWidget );
multiLineUntagBox = new QComboBox( returnWidget );
layout->addWidget( multiLineUntagLabel, 6, 0 );
layout->addWidget( multiLineUntagBox, 6, 1 );
multiLineUntagBox->insertItem( tr("No") );
multiLineUntagBox->insertItem( tr("Yes") );
return returnWidget;
}
void ATConfigDialog::readConfig( const Profile& config ) {
- owarn << "config in atconfigdialog" << oendl;
-
initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) );
resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) );
dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) );
dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) );
dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) );
dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
connectLine->setText( config.readEntry("DefaultConnect", MODEM_DEFAULT_CONNECT_STRING ) );
hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) );
dialTimeSpin->setValue( config.readNumEntry("DialTime", MODEM_DEFAULT_DIAL_TIME ) );
delayRedialSpin->setValue( config.readNumEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL ) );
numberTriesSpin->setValue( config.readNumEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES ) );
dtrDropTimeSpin->setValue( config.readNumEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME ) );
bpsDetectBox->setCurrentItem( config.readBoolEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT ) );
dcdLinesBox->setCurrentItem( config.readBoolEntry("DCDLines", MODEM_DEFAULT_DCD_LINES ) );
multiLineUntagBox->setCurrentItem( config.readBoolEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG ) );
// Not implemented yet
resetStringLine->setEnabled(false);
dialSuf1Line->setEnabled(false);
dialPref2Line->setEnabled(false);
dialSuf2Line->setEnabled(false);
dialPref3Line->setEnabled(false);
dialSuf3Line->setEnabled(false);
dialTimeSpin->setEnabled(false);
delayRedialSpin->setEnabled(false);
numberTriesSpin->setEnabled(false);
dtrDropTimeSpin->setEnabled(false);
bpsDetectBox->setEnabled(false);
dcdLinesBox->setEnabled(false);
multiLineUntagBox->setEnabled(false);
}
void ATConfigDialog::writeConfig( Profile& config ) {
config.writeEntry( "InitString", initStringLine->text() );
config.writeEntry( "ResetString", resetStringLine->text() );
config.writeEntry( "DialPrefix1", dialPref1Line->text() );
config.writeEntry( "DialSuffix1", dialSuf1Line->text() );
config.writeEntry( "DialPrefix2", dialPref2Line->text() );
config.writeEntry( "DialSuffix2", dialSuf2Line->text() );
config.writeEntry( "DialPrefix3", dialPref3Line->text() );
config.writeEntry( "DialSuffix3", dialSuf3Line->text() );
config.writeEntry( "DefaultConnect", connectLine->text() );
config.writeEntry( "HangupString", hangupLine->text() );
config.writeEntry( "DialTime", dialTimeSpin->value() );
config.writeEntry( "DelayRedial", delayRedialSpin->value() );
config.writeEntry( "NumberTries", numberTriesSpin->value() );
config.writeEntry( "DTRDRopTime", dtrDropTimeSpin->value() );
config.writeEntry( "BPSDetect", bpsDetectBox->currentItem() );
config.writeEntry( "DCDLines", dcdLinesBox->currentItem() );
config.writeEntry( "MultiLineUntag", multiLineUntagBox->currentItem() );
}
ATConfigDialog::~ATConfigDialog() {
}
diff --git a/noncore/apps/opie-console/btconfigwidget.cpp b/noncore/apps/opie-console/btconfigwidget.cpp
index 232e497..f2ed558 100644
--- a/noncore/apps/opie-console/btconfigwidget.cpp
+++ b/noncore/apps/opie-console/btconfigwidget.cpp
@@ -1,208 +1,198 @@
+#include "btconfigwidget.h"
+#include "iolayerbase.h"
+#include "comboboxhelper.h"
+
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qcombobox.h>
#include <qhbox.h>
#include <qradiobutton.h>
-#include "iolayerbase.h"
-#include "btconfigwidget.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 );
- }
-}
+
BTConfigWidget::BTConfigWidget( const QString& name,
QWidget* parent,
const char* na )
: ProfileDialogConnectionWidget( name, parent, na ) {
m_lay = new QVBoxLayout( this );
m_device = new QLabel( tr( "Device" ), this );
QHBox *deviceBox = new QHBox( this );
m_devRadio = new QRadioButton( deviceBox );
connect( m_devRadio, SIGNAL( toggled(bool) ), this, SLOT( slotDevRadio(bool) ) );
m_deviceCmb = new QComboBox( deviceBox );
m_deviceCmb->setEditable( TRUE );
QLabel *macLabel = new QLabel( this );
macLabel->setText( tr( "Or peer mac address" ) );
QHBox *macBox = new QHBox( this );
m_macRadio = new QRadioButton( macBox );
connect( m_macRadio, SIGNAL( toggled(bool) ), this, SLOT( slotMacRadio(bool) ) );
m_mac = new QLineEdit( macBox );
m_base = new IOLayerBase(this, "base");
m_lay->addWidget( m_device );
m_lay->addWidget( deviceBox );
m_lay->addWidget( macLabel );
m_lay->addWidget( macBox );
m_lay->addWidget( m_base );
m_deviceCmb->insertItem( "/dev/ttyU0" );
m_deviceCmb->insertItem( "/dev/ttyU1" );
}
BTConfigWidget::~BTConfigWidget() {
}
void BTConfigWidget::load( const Profile& prof ) {
int rad_flow = prof.readNumEntry("Flow");
int rad_parity = prof.readNumEntry("Parity");
int speed = prof.readNumEntry("Speed");
QString mac = prof.readEntry("Mac");
if (!mac.isEmpty() ) {
m_mac->setText( mac );
} else {
m_devRadio->setChecked( true );
}
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 4800:
m_base->setSpeed( IOLayerBase::Baud_4800 );
break;
case 2400:
m_base->setSpeed( IOLayerBase::Baud_2400 );
break;
case 1200:
m_base->setSpeed( IOLayerBase::Baud_1200 );
break;
case 9600:
default:
m_base->setSpeed(IOLayerBase::Baud_9600 );
break;
}
if ( prof.readEntry("Device").isEmpty() ) return;
- setCurrent( prof.readEntry("Device"), m_deviceCmb );
+ ComboboxHelper::setCurrent( prof.readEntry("Device"), m_deviceCmb );
}
/*
* save speed,
* flow,
* parity
*/
void BTConfigWidget::save( Profile& prof ) {
int flow, parity, speed;
flow = parity = speed = 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_4800:
speed = 4800;
break;
case IOLayerBase::Baud_2400:
speed = 2400;
break;
case IOLayerBase::Baud_1200:
speed = 1200;
break;
default:
case IOLayerBase::Baud_9600:
speed = 9600;
break;
}
prof.writeEntry("Flow", flow);
prof.writeEntry("Parity", parity);
prof.writeEntry("Speed", speed);
prof.writeEntry("Mac", m_mac->text() );
}
void BTConfigWidget::slotMacRadio( bool on ) {
if ( on ) {
m_devRadio->setChecked( false );
m_deviceCmb->setEnabled( false );
m_mac->setEnabled( true );
} else {
m_devRadio->setChecked( true );
}
}
void BTConfigWidget::slotDevRadio( bool on ) {
if ( on ) {
m_macRadio->setChecked( false );
m_deviceCmb->setEnabled( true );
m_mac->setEnabled( false );
} else {
m_macRadio->setChecked( true );
}
}
diff --git a/noncore/apps/opie-console/comboboxhelper.cpp b/noncore/apps/opie-console/comboboxhelper.cpp
new file mode 100644
index 0000000..1bfe0a7
--- a/dev/null
+++ b/noncore/apps/opie-console/comboboxhelper.cpp
@@ -0,0 +1,55 @@
+/*
+               =. This file is part of the OPIE Project
+             .=l. Copyright (c) 2002,2004 Holger Hans Peter Freyther <freyther@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This program is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = General Public License along with
+    --        :-=` this library; see the file COPYING.BIN.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "comboboxhelper.h"
+
+#include <qstring.h>
+#include <qcombobox.h>
+
+/**
+ * \brief Set string to be Current String inside the QCombox without duplicating it
+ *
+ * This method will make \par str the current QString. If
+ * the QString is already inside the QComboBox it will be
+ * set current. If it isn't it will be added.
+ *
+ * @param str The QString to be set current
+ * @param bo The QComboBox to operate on
+ */
+void ComboboxHelper::setCurrent( const QString& str, QComboBox* bo ) {
+ const uint b = bo->count();
+ for (uint i = 0; i < b; i++ ) {
+ if ( bo->text(i) == str ) {
+ bo->setCurrentItem( i );
+ return;
+ }
+ }
+
+ bo->insertItem( str );
+ bo->setCurrentItem( b );
+}
diff --git a/noncore/apps/opie-console/comboboxhelper.h b/noncore/apps/opie-console/comboboxhelper.h
new file mode 100644
index 0000000..40153bf
--- a/dev/null
+++ b/noncore/apps/opie-console/comboboxhelper.h
@@ -0,0 +1,49 @@
+/*
+               =. This file is part of the OPIE Project
+             .=l. Copyright (c) 2002,2004 Holger Hans Peter Freyther <freyther@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This program is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = General Public License along with
+    --        :-=` this library; see the file COPYING.BIN.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+#ifndef COMBO_BOX_HELPER_H
+#define COMBO_BOX_HELPER_H
+
+#include <qstring.h>
+
+
+class QComboBox;
+
+
+/**
+ * \brief ComboboxHelper with a small Helper for Configuring it
+ *
+ * ComboboxHelper contains methods for helping managing
+ * Comboboxes with 'dynamic' data.
+ * All Methods related to this class are static and operate
+ * on a QComboBox.
+ */
+struct ComboboxHelper {
+ static void setCurrent(const QString&, QComboBox *);
+};
+
+#endif
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp
index 7010594..8883b83 100644
--- a/noncore/apps/opie-console/dialer.cpp
+++ b/noncore/apps/opie-console/dialer.cpp
@@ -1,320 +1,308 @@
#include "dialer.h"
#include "io_modem.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
/* QT */
#include <qlayout.h>
#include <qprogressbar.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qapp.h>
#include <qtimer.h>
#include <qmessagebox.h>
/* STD */
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
// State machine: | When an error occurs, we don't have to
// | reset everything.
// (init) <------+ | But if the user wants to reset,
// | | | we stop dialing immediately.
// v | |
// (options) ----+ | Following the state machine is necessary
// | \ | to get determinable results.
// v ^ |
// (dial) ----+ |
// | ^ |
// v | |
// (online) --+ |
// | |
// v |
// from atconfigdialog
//initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) );
//resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) );
//dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) );
//dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
//dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) );
//dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
//dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) );
//dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
//connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) );
//hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) );
// from modemconfigwidget
//int rad_flow = prof.readNumEntry("Flow");
//int rad_parity = prof.readNumEntry("Parity");
//int speed = prof.readNumEntry("Speed");
//QString number = prof.readEntry("Number");
Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name)
: QDialog(parent, name, true), m_fd(fd), m_profile(profile)
{
QVBoxLayout *vbox;
QLabel *desc;
usercancel = 0;
cleanshutdown = 0;
desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this);
progress = new QProgressBar(this);
status = new QLabel("", this);
status->setFrameStyle(QFrame::Panel | QFrame::Sunken);
cancel = new QPushButton(QObject::tr("Cancel"), this);
vbox = new QVBoxLayout(this, 2);
vbox->add(desc);
vbox->add(progress);
vbox->add(status);
vbox->add(cancel);
connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
show();
QTimer::singleShot(500, this, SLOT(slotAutostart()));
}
Dialer::~Dialer()
{
}
void Dialer::setHangupOnly()
{
state = state_cancel;
usercancel = 1;
send( m_profile.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING )+"\r" );
}
void Dialer::slotCancel()
{
if(state != state_online)
{
usercancel = 1;
reset();
}
else {
accept();
}
}
void Dialer::reset()
{
- owarn << "reset" << oendl;
switchState(state_cancel);
}
void Dialer::slotAutostart()
{
//state = state_preinit;
dial(m_profile.readEntry("Number"));
}
void Dialer::dial(const QString& number)
{
while(state != state_online)
{
if(!usercancel)
{
state = state_preinit;
trydial(number);
}
else break;
}
if(usercancel)
{
// modem hangup
trydial(QString::null);
reject();
}
}
void Dialer::trydial(const QString& number)
{
- owarn << "TryDial:" << number.latin1() << "" << oendl;
if(state != state_cancel) switchState(state_preinit);
if(cleanshutdown)
{
- owarn << "HangupString " << m_profile.readEntry("HangupString") << oendl;
send(m_profile.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) + "\r");
}
if(state != state_cancel)
{
switchState(state_init);
-// owarn << "Init String " + m_profile.readEntry("InitString") << oendl;
send(m_profile.readEntry("InitString",MODEM_DEFAULT_INIT_STRING ) + "\r");
QString response2 = receive();
if(!response2.contains("\nOK\r"))
reset();
}
/* if(state != state_cancel)
{
switchState(state_options);
owarn << "ATM3l3" << oendl;
send("ATM3L3\r");
QString response3 = receive();
if(!response3.contains("\nOK\r"))
reset();
}
*/
if(state != state_cancel)
{
switchState(state_dialtone);
send("ATX1\r");
QString response4 = receive();
if(!response4.contains("\nOK\r"))
reset();
}
if(state != state_cancel)
{
- owarn << "progress" << oendl;
switchState(state_dialing);
// send(QString("ATDT %1\r").arg(number));
send(QString("%1 %2\r").arg(m_profile.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ))
.arg(number));
QString response5 = receive();
if(!response5.contains("CONNECT") )
{
if(response5.contains("BUSY"))
switchState(state_dialing);
else
{
QMessageBox::warning(this,
QObject::tr("Failure"),
- QObject::tr("Dialing the number failed."));
+ QObject::tr("<qt>Dialing the number failed.</qt>"));
slotCancel();
}
}
}
if(state != state_cancel)
{
state = state_online;
slotCancel();
}
}
void Dialer::send(const QString& msg)
{
QString m = msg;
int bytes;
QString termination;
- owarn << "Sending: " << m.latin1() << "" << oendl;
/* termination = "\r";
//termination = m_profile.readEntry("Termination");
if(termination == "\n") m = m + "\n";
else if(termination == "\r") m = m + "\r";
else m = m + "\r\n";
*/
m = m.replace(QRegExp("\n"), "\r");
bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit()));
if(bytes < 0)
{
reset();
}
}
QString Dialer::receive()
{
QString buf;
char buffer[1024];
int ret;
int counter = 0;
while(1)
{
ret = ::read(m_fd, buffer, sizeof(buffer));
if(ret > 0)
{
for(int i = 0; i < ret; i++)
buffer[i] = buffer[i] & 0x7F;
buffer[ret] = 0;
- owarn << "Got: " << buffer << "" << oendl;
buf.append(QString(buffer));
if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY")))
{
- //owarn << "Receiving: '" << buf.latin1() << "'" << oendl;
cleanshutdown = 1;
return buf;
}else if (buf.contains("NO CARRIER") || buf.contains("NO DIALTONE") ) {
cleanshutdown = 1;
return QString::null;
}
}
else if(ret < 0)
{
if(errno != EAGAIN) reset();
else if(!(counter++ % 100)) qApp->processEvents();
}
else if(!(counter++ % 100)) qApp->processEvents();
if(usercancel) return QString::null;
}
cleanshutdown = 1;
return QString::null;
}
void Dialer::switchState(int newstate)
{
int oldstate = state;
state = newstate;
switch(state)
{
case state_cancel:
status->setText(QObject::tr("Cancelling..."));
progress->setProgress(0);
break;
case state_preinit:
status->setText(QObject::tr("Searching modem"));
progress->setProgress(10);
break;
case state_init:
status->setText(QObject::tr("Initializing..."));
progress->setProgress(20);
break;
case state_options:
status->setText(QObject::tr("Reset speakers"));
progress->setProgress(30);
break;
case state_dialtone:
status->setText(QObject::tr("Turning off dialtone"));
progress->setProgress(40);
break;
case state_dialing:
if(oldstate != state_dialing) status->setText(QObject::tr("Dial number"));
else status->setText(QObject::tr("Line busy, redialing number"));
progress->setProgress(50);
break;
case state_online:
status->setText(QObject::tr("Connection established"));
progress->setProgress(100);
cancel->setText(QObject::tr("Dismiss"));
break;
}
}
diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp
index e045aef..986ae8d 100644
--- a/noncore/apps/opie-console/emulation_handler.cpp
+++ b/noncore/apps/opie-console/emulation_handler.cpp
@@ -1,247 +1,238 @@
#include "TEmuVt102.h"
#include "profile.h"
#include "emulation_handler.h"
#include "script.h"
#include "logger.h"
-/* OPIE */
-#include <opie2/odebug.h>
-
#include <qfile.h>
#include <qtextstream.h>
-using namespace Opie::Core;
-
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", 80) ? 0 : 80);
m_teWid->setMinimumSize(150, 70 );
m_script = 0;
m_log = 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;
delete m_log;
}
void EmulationHandler::load( const Profile& prof) {
// m_teWid->setVTFont( font( prof.readNumEntry("Font") ) );
QFont font( prof.readEntry("Font"), prof.readNumEntry( "FontSize" ), QFont::Normal );
font.setFixedPitch( TRUE );
m_teWid->setVTFont( 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() );
if ( isLogging() ) {
m_log->append( ar );
}
}
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:
- owarn << "Foreground green" << oendl;
co = Qt::green;
break;
case Profile::Orange:
- owarn << "Foreground orange" << oendl;
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:
- owarn << "Background black" << oendl;
co = Qt::black;
break;
case Profile::Orange:
- owarn << "Background black" << oendl;
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);
}
bool EmulationHandler::isLogging() {
return (m_log != 0);
}
void EmulationHandler::startRecording() {
if (!isRecording())
m_script = new Script();
}
void EmulationHandler::startLogging(const QString fileName) {
m_logFileName = fileName;
if (!isLogging())
m_log = new Logger(m_logFileName);
}
QString EmulationHandler::logFileName() {
return m_logFileName;
}
void EmulationHandler::clearScript() {
if (isRecording()) {
delete m_script;
m_script = 0;
}
}
void EmulationHandler::clearLog() {
if (isLogging()) {
delete m_log;
m_log = 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_widget.cpp b/noncore/apps/opie-console/emulation_widget.cpp
index 4688551..f0708d0 100644
--- a/noncore/apps/opie-console/emulation_widget.cpp
+++ b/noncore/apps/opie-console/emulation_widget.cpp
@@ -1,301 +1,295 @@
// opie-console includes
#include "emulation_widget.h"
// qt includes
#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() );
- odebug << QString(" TEST").arg( contentsRect().width() ) << oendl;
- odebug << QString(" TEST").arg( contentsRect().height() ) << oendl;
- odebug << "NEUER TESTT!!!!!!!!" << oendl;
-
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 )
{
- owarn << "Color1 " << color_table[attr.b].color.name().latin1() << "" << oendl;
if ( usePixmap && color_table[attr.b].transparent )
{
painter.setBackgroundMode( TransparentMode );
if ( clear )
erase( rect );
}
else
{
if ( blinking )
painter.fillRect( rect, color_table[attr.b].color );
else
{
painter.setBackgroundMode( OpaqueMode );
- owarn << "Color " << color_table[attr.b].color.name().latin1() << "" << oendl;
painter.setBackgroundColor( color_table[attr.b].color );
}
}
if ( color_table[attr.f].bold )
painter.setPen( QColor( 0x8F, 0x00, 0x00 ) );
else
painter.setPen( color_table[attr.f].color );
painter.drawText( rect.x(), rect.y() + f_ascent, string );
}
///////////////////////
// scrollbar
// ////////////////////
void EmulationWidget::scroll( int value )
{
}
void EmulationWidget::setScroll( int cursor, int slines )
{
}
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
index 6613183..0abe0d9 100644
--- a/noncore/apps/opie-console/function_keyboard.cpp
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -1,431 +1,423 @@
#include "function_keyboard.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
/* QT */
#include <qlayout.h>
#include <qlistbox.h>
#include <qlabel.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())
);
}
- //owarn << "loaded " << keys.count() << " keys" << oendl;
*/
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)
{
- owarn << "FunctionKeyboardConfig" << oendl;
-
-
kb = new FunctionKeyboard(this);
connect (kb, SIGNAL(keyPressed(FKey,ushort,ushort,bool)),
this, SLOT(slotKeyPressed(FKey,ushort,ushort,bool)));
QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimensions"), this);
- QLabel *l = new QLabel("Rows", dimentions);
+ QLabel *l = new QLabel(tr("Rows"), dimentions);
m_rowBox = new QSpinBox(1, 15, 1, dimentions);
connect (m_rowBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeRows(int)));
- l = new QLabel("Columns", dimentions);
+ l = new QLabel(tr("Columns"), dimentions);
m_colBox = new QSpinBox(1, 15, 1, dimentions);
connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int)));
QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this);
- l = new QLabel("Label", editKey);
+ l = new QLabel(tr("Label"), editKey);
m_labels = new QComboBox(true, editKey);
m_labels->setInsertionPolicy(QComboBox::AtCurrent);
m_labels->insertItem("");
QStringList files = QDir( QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList();
for (uint i = 0; i < files.count(); i++) {
m_labels->insertItem( Resource::loadPixmap("console/keys/" + files[i]), files[i]);
}
connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int)));
connect (m_labels, SIGNAL(textChanged(const QString&)), this, SLOT(slotChangeLabelText(const QString&)));
- l = new QLabel("Q Keycode", editKey);
+ l = new QLabel(tr("Q Keycode", "Qt Key Code for the OnScreen Keyboard"), editKey);
m_qvalues = new QComboBox(true, editKey);
m_qvalues->setInsertionPolicy(QComboBox::AtTop);
m_qvalues->setDuplicatesEnabled(false);
m_qvalues->insertItem("");
connect (m_qvalues, SIGNAL(textChanged(const QString&)), this, SLOT(slotChangeQCode(const QString&)));
- l = new QLabel("Unicode Value", editKey);
+ l = new QLabel(tr("Unicode Value", "The Unicode value of the key"), editKey);
m_uniValues = new QComboBox(true, editKey);
m_uniValues->setInsertionPolicy(QComboBox::AtTop);
m_uniValues->setDuplicatesEnabled(false);
m_uniValues->insertItem("");
connect (m_uniValues, SIGNAL(textChanged(const QString&)), this, SLOT(slotChangeUnicode(const QString&)));
QVBoxLayout *root = new QVBoxLayout(this, 2);
root->addWidget(kb);
root->addWidget(dimentions);
root->addWidget(editKey);
}
FunctionKeyboardConfig::~FunctionKeyboardConfig() {
}
void FunctionKeyboardConfig::load (const Profile& prof) {
kb->keys.clear();
kb->loadDefaults();
m_rowBox->setValue(prof.readNumEntry("keb_rows", 2));
m_colBox->setValue(prof.readNumEntry("keb_cols", 10));
/* load all the keys to the keyboard */
for (int i = 0; i <= m_rowBox->value() -1; i++)
for (int j = 0; j <= m_colBox->value() -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);
kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt());
// load pixmap if used
if (!l[1].isEmpty()) {
kb->keys[h].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + l[1] ) );
}
}
}
}
void FunctionKeyboardConfig::save (Profile& prof) {
prof.writeEntry("keb_rows", m_rowBox->value());
prof.writeEntry("keb_cols", m_colBox->value());
QMap<QString, FKey>::Iterator it;
for ( it = kb->keys.begin(); it != kb->keys.end(); it++) {
FKey k = it.data();
QString entry = k.label + "|"
+ k.pixFile + "|"
+ QString::number(k.qcode) + "|"
+ QString::number(k.unicode);
prof.writeEntry("keb_" + it.key(), entry);
}
}
void FunctionKeyboardConfig::slotChangeRows(int r) {
kb->changeRows(r);
}
void FunctionKeyboardConfig::slotChangeCols(int c) {
kb->changeCols(c);
}
void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) {
if (!pressed) return;
selectedHandle = "r" + QString::number(r) +
"c" + QString::number(c);
selectedRow = r;
selectedCol = c;
if (k.pixFile.isEmpty()) {
m_labels->setEditable(true);
m_labels->setCurrentItem(0);
m_labels->changeItem(k.label, 0);
} else {
// any better way to select the pixmap?
m_labels->setCurrentItem((m_labels->listBox())->index((m_labels->listBox())->findItem(kb->keys[selectedHandle].pixFile)));
m_labels->setEditable(false);
}
m_qvalues->changeItem(QString::number(k.qcode), 0);
m_uniValues->changeItem(QString::number(k.unicode), 0);
}
void FunctionKeyboardConfig::slotChangeIcon(int index) {
if (index == 0) {
// is text
m_labels->setEditable(true);
// why tf does the text get erased unless i do this?
m_labels->changeItem(m_labels->text(0), 0);
kb->keys[selectedHandle].pixFile = "";
delete kb->keys[selectedHandle].pix;
} else {
// is a pixmap
m_labels->setEditable(false);
kb->keys[selectedHandle].pixFile = m_labels->currentText();
kb->keys[selectedHandle].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + m_labels->currentText() ) );
}
kb->paintKey(selectedRow, selectedCol);
}
void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) {
kb->keys[selectedHandle].label = label;
kb->paintKey(selectedRow, selectedCol);
}
void FunctionKeyboardConfig::slotChangeQCode(const QString& qcode) {
kb->keys[selectedHandle].qcode = qcode.toUInt();
}
void FunctionKeyboardConfig::slotChangeUnicode(const QString& uni) {
kb->keys[selectedHandle].unicode = uni.toUInt();
}
diff --git a/noncore/apps/opie-console/io_bt.cpp b/noncore/apps/opie-console/io_bt.cpp
index c102427..a06b0c4 100644
--- a/noncore/apps/opie-console/io_bt.cpp
+++ b/noncore/apps/opie-console/io_bt.cpp
@@ -1,96 +1,79 @@
#include "io_bt.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
IOBt::IOBt( const Profile &config ) : IOSerial( config ) {
m_attach = 0;
}
IOBt::~IOBt() {
if ( m_attach ) {
delete m_attach;
}
}
void IOBt::close() {
IOSerial::close();
// still need error handling
if ( m_attach ) {
delete m_attach;
m_attach = 0;
}
}
bool IOBt::open() {
bool ret = false;
// only set up bt stuff if mac address was set, otherwise use the device set
if ( !m_mac.isEmpty() ) {
// now it should also be checked, if there is a connection to the device with that mac allready
// hciattach here
- m_attach = new OProcess();
+ m_attach = new Opie::Core::OProcess();
*m_attach << "hciattach /dev/ttyS2 any 57600";
// then start hcid, then rcfomm handling (m_mac)
connect( m_attach, SIGNAL( processExited(Opie::Core::OProcess*) ),
this, SLOT( slotExited(Opie::Core::OProcess*) ) );
if ( m_attach->start() ) {
ret = IOSerial::open();
} else {
- owarn << "could not attach to device" << oendl;
delete m_attach;
m_attach = 0;
}
} else {
// directly to the normal serial
// TODO: look first if the connection really exists. ( is set up )
ret =IOSerial::open();
}
return ret;
}
void IOBt::reload( const Profile &config ) {
m_device = config.readEntry("Device", BT_DEFAULT_DEVICE);
m_mac = config.readEntry("Mac", BT_DEFAULT_MAC);
m_baud = config.readNumEntry("Baud", BT_DEFAULT_BAUD);
m_parity = config.readNumEntry("Parity", BT_DEFAULT_PARITY);
m_dbits = config.readNumEntry("DataBits", BT_DEFAULT_DBITS);
m_sbits = config.readNumEntry("StopBits", BT_DEFAULT_SBITS);
m_flow = config.readNumEntry("Flow", BT_DEFAULT_FLOW);
}
QString IOBt::identifier() const {
return "bluetooth";
}
QString IOBt::name() const {
return "BLuetooth IO Layer";
}
-void IOBt::slotExited( OProcess* proc ){
+void IOBt::slotExited( Opie::Core::OProcess* proc ){
close();
delete proc;
}
-
-QBitArray IOBt::supports() const {
- return QBitArray( 3 );
-}
-
-bool IOBt::isConnected() {
- return false;
-}
-
-void IOBt::send(const QByteArray &data) {
- odebug << "Please overload me..." << oendl;
-}
diff --git a/noncore/apps/opie-console/io_bt.h b/noncore/apps/opie-console/io_bt.h
index 00ca7e5..156632b 100644
--- a/noncore/apps/opie-console/io_bt.h
+++ b/noncore/apps/opie-console/io_bt.h
@@ -1,51 +1,48 @@
#ifndef OPIE_IO_BT
#define OPIE_IO_BT
#include <opie2/oprocess.h>
#include "io_serial.h"
/* Default values to be used if the profile information is incomplete */
#define BT_DEFAULT_DEVICE "/dev/ttyU0"
#define BT_DEFAULT_BAUD 9600
#define BT_DEFAULT_PARITY 0
#define BT_DEFAULT_DBITS 8
#define BT_DEFAULT_SBITS 1
#define BT_DEFAULT_FLOW 0
#define BT_DEFAULT_MAC 0
/* IOSerial implements a RS232 IO Layer */
class IOBt : public IOSerial {
Q_OBJECT
public:
IOBt(const Profile &);
~IOBt();
virtual QString identifier() const;
virtual QString name() const;
- virtual QBitArray supports() const;
- virtual bool isConnected();
signals:
void received(const QByteArray &);
void error(int, const QString &);
public slots:
- virtual void send( const QByteArray& );
virtual bool open();
virtual void close();
virtual void reload(const Profile &);
private:
Opie::Core::OProcess *m_attach;
QString m_mac;
private slots:
void slotExited(Opie::Core::OProcess* proc);
};
#endif /* OPIE_IO_IRDA */
diff --git a/noncore/apps/opie-console/io_irda.cpp b/noncore/apps/opie-console/io_irda.cpp
index 38542f5..9d27c85 100644
--- a/noncore/apps/opie-console/io_irda.cpp
+++ b/noncore/apps/opie-console/io_irda.cpp
@@ -1,80 +1,64 @@
#include "io_irda.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
IOIrda::IOIrda( const Profile &config ) : IOSerial( config ) {
m_attach = 0;
}
IOIrda::~IOIrda() {
if ( m_attach ) {
delete m_attach;
}
}
void IOIrda::close() {
IOSerial::close();
// still need error handling
delete m_attach;
}
bool IOIrda::open() {
bool ret;
// irdaattach here
- m_attach = new OProcess();
+ m_attach = new Opie::Core::OProcess();
*m_attach << "irattach /dev/ttyS2 -s";
connect( m_attach, SIGNAL( processExited(Opie::Core::OProcess*) ),
this, SLOT( slotExited(Opie::Core::OProcess*) ) );
if ( m_attach->start() ) {
ret= IOSerial::open();
} else {
// emit error!!!
- owarn << "could not attach to device" << oendl;
delete m_attach;
m_attach = 0l;
}
return ret;
}
void IOIrda::reload( const Profile &config ) {
m_device = config.readEntry("Device", IRDA_DEFAULT_DEVICE);
m_baud = config.readNumEntry("Baud", IRDA_DEFAULT_BAUD);
m_parity = config.readNumEntry("Parity", IRDA_DEFAULT_PARITY);
m_dbits = config.readNumEntry("DataBits", IRDA_DEFAULT_DBITS);
m_sbits = config.readNumEntry("StopBits", IRDA_DEFAULT_SBITS);
m_flow = config.readNumEntry("Flow", IRDA_DEFAULT_FLOW);
}
QString IOIrda::identifier() const {
return "irda";
}
QString IOIrda::name() const {
return "Irda IO Layer";
}
-void IOIrda::slotExited(OProcess* proc ){
+void IOIrda::slotExited(Opie::Core::OProcess* proc ){
close();
delete proc;
}
-QBitArray IOIrda::supports()const {
- return QBitArray( 3 );
-}
-
-bool IOIrda::isConnected() {
- return false;
-}
-
-void IOIrda::send(const QByteArray &data) {
- odebug << "Please overload me..." << oendl;
-}
diff --git a/noncore/apps/opie-console/io_irda.h b/noncore/apps/opie-console/io_irda.h
index fb29686..1fdbd4b 100644
--- a/noncore/apps/opie-console/io_irda.h
+++ b/noncore/apps/opie-console/io_irda.h
@@ -1,49 +1,46 @@
#ifndef OPIE_IO_IRDA
#define OPIE_IO_IRDA
#include <opie2/oprocess.h>
#include "io_serial.h"
/* Default values to be used if the profile information is incomplete */
#define IRDA_DEFAULT_DEVICE "/dev/ircomm0"
#define IRDA_DEFAULT_BAUD 9600
#define IRDA_DEFAULT_PARITY 0
#define IRDA_DEFAULT_DBITS 8
#define IRDA_DEFAULT_SBITS 1
#define IRDA_DEFAULT_FLOW 0
/* IOSerial implements a RS232 IO Layer */
class IOIrda : public IOSerial {
Q_OBJECT
public:
IOIrda(const Profile &);
~IOIrda();
virtual QString identifier() const;
virtual QString name() const;
- virtual QBitArray supports() const;
- virtual bool isConnected();
signals:
void received(const QByteArray &);
void error(int, const QString &);
public slots:
- virtual void send( const QByteArray& );
virtual bool open();
virtual void close();
virtual void reload(const Profile &);
private:
Opie::Core::OProcess *m_attach;
private slots:
void slotExited(Opie::Core::OProcess* proc);
};
#endif /* OPIE_IO_IRDA */
diff --git a/noncore/apps/opie-console/io_modem.cpp b/noncore/apps/opie-console/io_modem.cpp
index c499dfe..915a1d2 100644
--- a/noncore/apps/opie-console/io_modem.cpp
+++ b/noncore/apps/opie-console/io_modem.cpp
@@ -1,108 +1,86 @@
#include "io_modem.h"
#include "dialer.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
-
IOModem::IOModem( const Profile &profile )
: IOSerial( profile ) {
m_profile = profile;
}
IOModem::~IOModem() {
}
void IOModem::close() {
// Hangup, discarding result
// int fd = rawIO();
internDetach();
Dialer d(m_profile, m_fd);
d.setHangupOnly();
//d.exec();
internAttach();
// closeRawIO(fd);
IOSerial::close();
}
bool IOModem::open() {
bool ret = IOSerial::open();
if(!ret) return false;
// int fd = rawIO();
internDetach();
Dialer d(m_profile, m_fd);
int result = d.exec();
internAttach();
// closeRawIO(fd);
if(result == QDialog::Accepted)
{
return true;
}
else
{
close();
return false;
}
}
void IOModem::reload( const Profile &config ) {
m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE);
m_baud = config.readNumEntry("Baud", MODEM_DEFAULT_BAUD);
m_parity = config.readNumEntry("Parity", MODEM_DEFAULT_PARITY);
m_dbits = config.readNumEntry("DataBits", MODEM_DEFAULT_DBITS);
m_sbits = config.readNumEntry("StopBits", MODEM_DEFAULT_SBITS);
m_flow = config.readNumEntry("Flow", MODEM_DEFAULT_FLOW);
m_initString = config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING );
m_resetString = config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING );
m_dialPref1 = config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 );
m_dialSuf1 = config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 );
m_dialPref2 = config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 );
m_dialSuf2 = config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 );
m_dialPref3 = config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 );
m_dialSuf3 = config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 );
m_connect = config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING );
m_hangup = config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING );
m_cancel = config.readEntry("CancelString", MODEM_DEFAULT_CANCEL_STRING );
m_dialTime = config.readNumEntry("DialTime", MODEM_DEFAULT_DIAL_TIME );
m_delayRedial = config.readNumEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL );
m_numberTries = config.readNumEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES );
m_dtrDropTime = config.readNumEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME );
m_bpsDetect = config.readBoolEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT );
m_dcdLines = config.readBoolEntry("DCDLines", MODEM_DEFAULT_DCD_LINES );
m_multiLineUntag = config.readBoolEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG );
}
QString IOModem::identifier() const {
return "modem";
}
QString IOModem::name() const {
return "Modem IO Layer";
}
-
-void IOModem::slotExited(OProcess* proc ){
- close();
- /* delete it afterwards */
- delete proc;
-}
-
-QBitArray IOModem::supports()const {
- return QBitArray( 3 );
-}
-
-bool IOModem::isConnected() {
- return false;
-}
-
-void IOModem::send(const QByteArray &data) {
- odebug << "Please overload me..." << oendl;
-}
diff --git a/noncore/apps/opie-console/io_modem.h b/noncore/apps/opie-console/io_modem.h
index 5b99e00..056e630 100644
--- a/noncore/apps/opie-console/io_modem.h
+++ b/noncore/apps/opie-console/io_modem.h
@@ -1,74 +1,67 @@
#ifndef OPIE_IO_MODEM
#define OPIE_IO_MODEM
#include <opie2/oprocess.h>
#include "io_serial.h"
#include "profile.h"
/* Default values to be used if the profile information is incomplete */
#define MODEM_DEFAULT_DEVICE "/dev/ttyS0"
#define MODEM_DEFAULT_BAUD 9600
#define MODEM_DEFAULT_PARITY 0
#define MODEM_DEFAULT_DBITS 8
#define MODEM_DEFAULT_SBITS 1
#define MODEM_DEFAULT_FLOW 0
#define MODEM_DEFAULT_INIT_STRING "AT"
#define MODEM_DEFAULT_RESET_STRING "ATZ~"
#define MODEM_DEFAULT_DIAL_PREFIX1 "ATDT"
#define MODEM_DEFAULT_DIAL_SUFFIX1 ""
#define MODEM_DEFAULT_DIAL_PREFIX2 ""
#define MODEM_DEFAULT_DIAL_SUFFIX2 ""
#define MODEM_DEFAULT_DIAL_PREFIX3 ""
#define MODEM_DEFAULT_DIAL_SUFFIX3 ""
#define MODEM_DEFAULT_CONNECT_STRING "CONNECT"
#define MODEM_DEFAULT_HANGUP_STRING "+++ATH"
#define MODEM_DEFAULT_CANCEL_STRING ""
#define MODEM_DEFAULT_DIAL_TIME 45
#define MODEM_DEFAULT_DELAY_REDIAL 2
#define MODEM_DEFAULT_NUMBER_TRIES 10
#define MODEM_DEFAULT_DTR_DROP_TIME 1
#define MODEM_DEFAULT_BPS_DETECT 0 // bool
#define MODEM_DEFAULT_DCD_LINES 1 //bool
#define MODEM_DEFAULT_MULTI_LINE_UNTAG 0 // bool
/* IOSerial implements a RS232 IO Layer */
class IOModem : public IOSerial {
Q_OBJECT
public:
IOModem(const Profile &);
~IOModem();
virtual QString identifier() const;
virtual QString name() const;
- virtual QBitArray supports() const;
- virtual bool isConnected();
signals:
void received(const QByteArray &);
void error(int, const QString &);
public slots:
- virtual void send( const QByteArray& );
virtual bool open();
virtual void close();
virtual void reload(const Profile &);
private:
QString m_initString, m_resetString, m_dialPref1, m_dialSuf1, m_dialPref2,
m_dialSuf2, m_dialPref3, m_dialSuf3, m_connect, m_hangup, m_cancel;
int m_dialTime, m_delayRedial, m_numberTries, m_dtrDropTime,
m_bpsDetect, m_dcdLines, m_multiLineUntag;
Profile m_profile;
-
-private slots:
- void slotExited(Opie::Core::OProcess* proc);
-
};
#endif
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 291912c..b3cb208 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -1,790 +1,783 @@
#include "TEmulation.h"
#include "profileeditordialog.h"
#include "configdialog.h"
#include "default.h"
#include "profilemanager.h"
#include "mainwindow.h"
#include "tabwidget.h"
#include "transferdialog.h"
#include "function_keyboard.h"
#include "emulation_handler.h"
#include "script.h"
#include "fixit.h"
/* OPIE */
-#include <opie2/odebug.h>
#include <opie2/ofiledialog.h>
#include <qpe/filemanager.h>
-using namespace Opie::Core;
using namespace Opie::Ui;
/* QT */
#include <qaction.h>
#include <qmenubar.h>
#include <qtoolbar.h>
#include <qmessagebox.h>
#include <qwhatsthis.h>
#include <qfileinfo.h>
/* STD */
#include <assert.h>
#ifdef EAST
#include <opie2/oconfig.h>
#endif
MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
#ifdef FSCKED_DISTRI
FixIt fix;
fix.fixIt();
#endif
setCaption(QObject::tr("Opie Console") );
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();
#ifndef EAST
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() ) );
#endif
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 = true;
m_wrap = new QAction( tr("Line wrap"), Resource::loadPixmap( "linewrap" ), QString::null, 0, this, 0, true );
m_wrap->addTo( m_console );
m_wrap->setOn( true );
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();
m_recordLog = new QAction();
m_recordLog->setText( tr("Start log") );
m_recordLog->addTo( m_console );
connect(m_recordLog, SIGNAL(activated() ),
this, SLOT( slotSaveLog() ) );
m_recordingLog = false;
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 */
#ifdef EAST
OConfig cfg("opie-console");
cfg.setGroup("10east");
if( !cfg.readEntry("scripthide",0) ) {
m_bar->insertItem( tr("Scripts"), m_scripts );
}
#endif
/* 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() );
}
}
void MainWindow::populateScripts() {
m_scriptsPop->clear();
m_scriptsData.clear();
DocLnkSet files(QPEApplication::documentDir(), "text/plain");
QListIterator<DocLnk> dit(files.children());
for (; dit.current(); ++dit) {
if (*dit && (*dit)->name().length()>0) {
QFileInfo info((*dit)->file());
if (info.extension(false) == "script") {
m_scriptsData.append(new DocLnk(**dit));
m_scriptsPop->insertItem((*dit)->name());
}
}
}
}
MainWindow::~MainWindow() {
delete m_factory;
manager()->save();
#ifdef FSCKED_DISTRI
FixIt fix;
fix.breakIt();
#endif
}
MetaFactory* MainWindow::factory() {
return m_factory;
}
Session* MainWindow::currentSession() {
return m_curSession;
}
QList<Session> MainWindow::sessions() {
return m_sessions;
}
void MainWindow::slotNew() {
ProfileEditorDialog dlg(factory() );
dlg.setCaption( tr("New Connection") );
int ret = QPEApplication::execDialog( &dlg );
if ( ret == QDialog::Accepted ) {
create( dlg.profile() );
}
}
void MainWindow::slotRecordScript() {
if (currentSession()) {
currentSession()->emulationHandler()->startRecording();
m_saveScript->setEnabled(true);
m_recordScript->setEnabled(false);
}
}
void MainWindow::slotSaveScript() {
if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("Script"), text );
QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
if (!filename.isEmpty()) {
QFileInfo info(filename);
if (info.extension(FALSE) != "script")
filename += ".script";
DocLnk nf;
nf.setType("text/plain");
nf.setFile(filename);
nf.setName(info.fileName());
FileManager fm;
fm.saveFile(nf, currentSession()->emulationHandler()->script()->script());
currentSession()->emulationHandler()->clearScript();
m_saveScript->setEnabled(false);
m_recordScript->setEnabled(true);
populateScripts();
}
}
}
void MainWindow::slotRunScript(int id) {
if (currentSession()) {
int index = m_scriptsPop->indexOf(id);
DocLnk *lnk = m_scriptsData.at(index);
QString filePath = lnk->file();
Script script(filePath);
currentSession()->emulationHandler()->runScript(&script);
}
}
void MainWindow::slotConnect() {
if ( currentSession() ) {
bool ret = currentSession()->layer()->open();
if(!ret) QMessageBox::warning(currentSession()->widgetStack(),
QObject::tr("Failed"),
QObject::tr("Connecting failed for this session."));
else {
m_connect->setEnabled( false );
m_disconnect->setEnabled( true );
// if it does not support file transfer, disable the menu entry
if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
m_transfer->setEnabled( false );
} else {
m_transfer->setEnabled( true );
}
m_recordScript->setEnabled( true );
m_scripts->setItemEnabled(m_runScript_id, true);
}
}
}
void MainWindow::slotDisconnect() {
if ( currentSession() ) {
currentSession()->layer()->close();
m_connect->setEnabled( true );
m_disconnect->setEnabled( false );
m_transfer->setEnabled( false );
m_recordScript->setEnabled( false);
m_saveScript->setEnabled( false );
m_scripts->setItemEnabled(m_runScript_id, false);
}
}
void MainWindow::slotTerminate() {
if ( currentSession() )
currentSession()->layer()->close();
slotClose();
/* FIXME move to the next session */
}
void MainWindow::slotQuickLaunch() {
Profile prof = manager()->profile( "default" );
if ( prof.name() == "default" ) {
create( prof );
} else {
#ifndef EAST
Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 );
newProf.setAutoConnect( true );
create( newProf );
slotSaveSession();
#endif
}
}
void MainWindow::slotConfigure() {
ConfigDialog conf( manager()->all(), factory() );
int ret = QPEApplication::execDialog( &conf );
if ( QDialog::Accepted == ret ) {
manager()->setProfiles( conf.list() );
manager()->save();
populateProfiles();
}
}
/*
* we will remove
* this window from the tabwidget
* remove it from the list
* delete it
* and set the currentSession()
*/
void MainWindow::slotClose() {
if (!currentSession() )
return;
Session* ses = currentSession();
- owarn << "removing! currentSession " << currentSession()->name().latin1() << "" << oendl;
/* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */
m_curSession = NULL;
tabWidget()->remove( /*currentSession()*/ses );
/*it's autodelete */
m_sessions.remove( ses );
- owarn << "after remove!!" << oendl;
if (!currentSession() ) {
m_connect->setEnabled( false );
m_disconnect->setEnabled( false );
m_terminate->setEnabled( false );
m_transfer->setEnabled( false );
m_recordScript->setEnabled( false );
m_saveScript->setEnabled( false );
m_scripts->setItemEnabled(m_runScript_id, false);
m_fullscreen->setEnabled( false );
m_wrap->setEnabled( false );
m_closewindow->setEnabled( false );
}
m_kb->loadDefaults();
}
/*
* We will get the name
* Then the profile
* and then we will make a profile
*/
void MainWindow::slotProfile( int id) {
Profile prof = manager()->profile( m_sessionsPop->text( id) );
create( prof );
}
void MainWindow::create( const Profile& prof ) {
if(m_curSession)
if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
Session *ses = manager()->fromProfile( prof, tabWidget() );
if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
{
QMessageBox::warning(this,
QObject::tr("Session failed"),
QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
//if(ses) delete ses;
return;
}
m_sessions.append( ses );
tabWidget()->add( ses );
tabWidget()->repaint();
m_curSession = ses;
// dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it
m_connect->setEnabled( true );
m_disconnect->setEnabled( false );
m_terminate->setEnabled( true );
m_fullscreen->setEnabled( true );
m_wrap->setEnabled( true );
m_closewindow->setEnabled( true );
m_transfer->setEnabled( false );
m_recordScript->setEnabled( false );
m_saveScript->setEnabled( false );
m_scripts->setItemEnabled(m_runScript_id, false);
// is io_layer wants direct connection, then autoconnect
//if ( ( m_curSession->layer() )->supports()[0] == 1 ) {
if (prof.autoConnect()) {
slotConnect();
}
QWidget *w = currentSession()->widget();
if(w) w->setFocus();
if(currentSession()->profile().readNumEntry("Wrap", 80)){
m_isWrapped = true;
} else {
m_isWrapped = false;
}
m_kb->load(currentSession()->profile());
}
void MainWindow::slotTransfer()
{
if ( currentSession() ) {
Session *mysession = currentSession();
TransferDialog dlg(/*mysession->widgetStack()*/this, this);
mysession->setTransferDialog(&dlg);
//dlg.reparent(mysession->widgetStack(), QPoint(0, 0));
//dlg.showMaximized();
currentSession()->widgetStack()->addWidget(&dlg, -1);
dlg.show();
//dlg.exec();
while(dlg.isRunning()) qApp->processEvents();
mysession->setTransferDialog(0l);
}
}
void MainWindow::slotOpenKeb(bool state) {
if (state) m_keyBar->show();
else m_keyBar->hide();
}
void MainWindow::slotOpenButtons( bool state ) {
if ( state ) {
m_buttonBar->show();
} else {
m_buttonBar->hide();
}
}
void MainWindow::slotSessionChanged( Session* ses ) {
- owarn << "changed!" << oendl;
-
if(m_curSession)
if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
if(ses)
if(ses->transferDialog()) ses->transferDialog()->show();
if ( ses ) {
m_curSession = ses;
- odebug << QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) << oendl;
if ( m_curSession->layer()->isConnected() ) {
m_connect->setEnabled( false );
m_disconnect->setEnabled( true );
m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording());
m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording());
m_scripts->setItemEnabled(m_runScript_id, true);
} else {
m_connect->setEnabled( true );
m_disconnect->setEnabled( false );
m_recordScript->setEnabled( false );
m_saveScript->setEnabled( false );
m_scripts->setItemEnabled(m_runScript_id, false);
}
if ( ( currentSession()->emulationHandler()->isLogging() ) ) {
m_recordLog->setText( tr("Stop log") );
} else {
m_recordLog->setText( tr("Start log") );
}
if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
m_transfer->setEnabled( false );
} else {
m_transfer->setEnabled( true );
}
QWidget *w = m_curSession->widget();
if(w) w->setFocus();
if(currentSession()->profile().readNumEntry("Wrap", 80)){
m_isWrapped = true;
} else {
m_isWrapped = false;
}
m_kb->load(currentSession()->profile());
}
}
void MainWindow::slotWrap()
{
if(m_curSession)
{
EmulationHandler *e = m_curSession->emulationHandler();
if(e)
{
e->setWrap( m_isWrapped ? 80:0 );
m_isWrapped = !m_isWrapped;
}
}
}
void MainWindow::slotFullscreen() {
if ( m_isFullscreen ) {
( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true );
( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() );
( m_curSession->emulationHandler() )->cornerButton()->hide();
disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
} else {
savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget();
( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame );
( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop
, QPoint(0,0), false );
( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() );
( m_curSession->widgetStack() )->setFocus();
( m_curSession->widgetStack() )->show();
( ( m_curSession->emulationHandler() )->cornerButton() )->show();
connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
}
m_isFullscreen = !m_isFullscreen;
}
void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) {
if ( m_curSession ) {
QEvent::Type state;
if (pressed) state = QEvent::KeyPress;
else state = QEvent::KeyRelease;
QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode)));
// is this the best way to do this? cant figure out any other way to work
QApplication::sendEvent((QObject *)m_curSession->widget(), &ke);
ke.ignore();
}
}
void MainWindow::slotCopy() {
if (!currentSession() ) return;
currentSession()->emulationHandler()->copy();
}
void MainWindow::slotPaste() {
if (!currentSession() ) return;
currentSession()->emulationHandler()->paste();
}
/*
* Save the session
*/
void MainWindow::slotSaveSession() {
if (!currentSession() ) {
QMessageBox::information(this, tr("Save Connection"),
tr("<qt>There is no Connection.</qt>"), 1 );
return;
}
manager()->add( currentSession()->profile() );
manager()->save();
populateProfiles();
}
void MainWindow::slotSaveLog() {
if( currentSession()->emulationHandler()->isLogging() ) {
DocLnk nf;
QString m_logName = currentSession()->emulationHandler()->logFileName();
QFileInfo info(m_logName);
nf.setType("text/plain");
nf.setFile(m_logName);
nf.setName(info.fileName());
nf.writeLink();
m_recordLog->setText( tr("Start log") );
m_recordingLog = false;
currentSession()->emulationHandler()->clearLog();
} else {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("Log"), text );
QString m_logName = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
if (m_logName.isEmpty() ) return;
m_recordLog->setText( tr("Stop log") );
m_recordingLog = true;
currentSession()->emulationHandler()->startLogging(m_logName);
}
}
void MainWindow::slotSaveHistory() {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("History"), text );
QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
if (filename.isEmpty() ) return;
QFileInfo info(filename);
DocLnk nf;
nf.setType("text/plain");
nf.setFile(filename);
nf.setName(info.fileName());
QFile file(filename);
file.open(IO_WriteOnly );
QTextStream str(&file );
if ( currentSession() )
currentSession()->emulationHandler()->emulation()->streamHistory(&str);
file.close();
nf.writeLink();
}
diff --git a/noncore/apps/opie-console/modemconfigwidget.cpp b/noncore/apps/opie-console/modemconfigwidget.cpp
index b2f5c68..eb4bd0d 100644
--- a/noncore/apps/opie-console/modemconfigwidget.cpp
+++ b/noncore/apps/opie-console/modemconfigwidget.cpp
@@ -1,276 +1,261 @@
#include "modemconfigwidget.h"
#include "dialdialog.h"
+#include "comboboxhelper.h"
/* OPIE */
-#include <opie2/odebug.h>
#include <qpe/qpeapplication.h>
-using namespace Opie::Core;
/* QT */
#include <qlabel.h>
#include <qlayout.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qhbox.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 4800:
m_base->setSpeed( IOLayerBase::Baud_4800 );
break;
case 2400:
m_base->setSpeed( IOLayerBase::Baud_2400 );
break;
case 1200:
m_base->setSpeed( IOLayerBase::Baud_1200 );
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() ) {
- owarn << "device empty!" << oendl;
return;
}
- setCurrent( prof.readEntry( "Device" ), m_deviceCmb );
+ ComboboxHelper::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;
case IOLayerBase::Baud_4800:
speed = 4800;
break;
case IOLayerBase::Baud_2400:
speed = 2400;
break;
case IOLayerBase::Baud_1200:
speed = 1200;
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
if ( QPEApplication::execDialog( atConf ) != 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("[\\-\\/\\ \\.\\,]"), ""));
}
if ( QPEApplication::execDialog( &dial ) == QDialog::Accepted ) {
m_telNumber->setText( dial.number() );
}
}
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index d947eec..a7b9d5f 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -1,74 +1,76 @@
TEMPLATE = app
CONFIG += qt warn_on
HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h io_modem.h \
file_layer.h filetransfer.h \
metafactory.h \
session.h \
mainwindow.h \
profile.h \
profileconfig.h \
profilemanager.h \
tabwidget.h \
configdialog.h \
keytrans.h \
transferdialog.h \
profiledialogwidget.h \
profileeditordialog.h \
default.h \
iolayerbase.h \
serialconfigwidget.h irdaconfigwidget.h \
btconfigwidget.h modemconfigwidget.h \
atconfigdialog.h dialdialog.h \
procctl.h \
function_keyboard.h \
receive_layer.h filereceive.h \
script.h \
dialer.h logger.h \
terminalwidget.h \
emulation_handler.h TECommon.h \
TEHistory.h TEScreen.h TEWidget.h \
TEmuVt102.h TEmulation.h MyPty.h \
- consoleconfigwidget.h fixit.h
+ consoleconfigwidget.h fixit.h \
+ comboboxhelper.h
SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \
file_layer.cpp filetransfer.cpp \
main.cpp \
metafactory.cpp \
session.cpp \
mainwindow.cpp \
profile.cpp \
profileconfig.cpp \
profilemanager.cpp \
tabwidget.cpp \
configdialog.cpp \
keytrans.cpp \
transferdialog.cpp \
profiledialogwidget.cpp \
profileeditordialog.cpp \
iolayerbase.cpp \
serialconfigwidget.cpp irdaconfigwidget.cpp \
btconfigwidget.cpp modemconfigwidget.cpp \
atconfigdialog.cpp dialdialog.cpp \
default.cpp procctl.cpp \
function_keyboard.cpp \
receive_layer.cpp filereceive.cpp \
script.cpp \
dialer.cpp logger.cpp \
terminalwidget.cpp \
emulation_handler.cpp TEHistory.cpp \
TEScreen.cpp TEWidget.cpp \
TEmuVt102.cpp TEmulation.cpp MyPty.cpp \
- consoleconfigwidget.cpp fixit.cpp
+ consoleconfigwidget.cpp fixit.cpp \
+ comboboxhelper.cpp
DESTDIR = $(OPIEDIR)/bin/
INTERFACES = configurebase.ui editbase.ui
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopiecore2 -lopieui2 -lutil
TARGET = opie-console
DEFINES += HAVE_OPENPTY
-#DEFINES += EAST FSCKED_DISTRI
+DEFINES += EAST FSCKED_DISTRI
include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/apps/opie-console/profileeditordialog.cpp b/noncore/apps/opie-console/profileeditordialog.cpp
index dc42d8b..8109070 100644
--- a/noncore/apps/opie-console/profileeditordialog.cpp
+++ b/noncore/apps/opie-console/profileeditordialog.cpp
@@ -1,242 +1,238 @@
+#include "profileeditordialog.h"
+#include "metafactory.h"
+#include "comboboxhelper.h"
+
+
#include <qlayout.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qmessagebox.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qscrollview.h>
-#include "metafactory.h"
-#include "profileeditordialog.h"
+
using namespace Opie::Ui;
-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 );
+ ComboboxHelper::setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb );
+ ComboboxHelper::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/serialconfigwidget.cpp b/noncore/apps/opie-console/serialconfigwidget.cpp
index c4c9c99..4efb286 100644
--- a/noncore/apps/opie-console/serialconfigwidget.cpp
+++ b/noncore/apps/opie-console/serialconfigwidget.cpp
@@ -1,216 +1,203 @@
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qcombobox.h>
-
#include "iolayerbase.h"
#include "serialconfigwidget.h"
+#include "comboboxhelper.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 );
- }
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qcombobox.h>
-}
SerialConfigWidget::SerialConfigWidget( const QString& name,
QWidget* parent,
const char* na )
: ProfileDialogConnectionWidget( name, parent, na ) {
m_lay = new QVBoxLayout(this );
m_device = new QLabel(tr("Device"), this );
m_deviceCmb = new QComboBox(this );
m_deviceCmb->setEditable( TRUE );
m_base = new IOLayerBase(this, "base");
m_lay->addWidget( m_device );
m_lay->addWidget( m_deviceCmb );
m_lay->addWidget( m_base );
m_deviceCmb->insertItem( "/dev/ttyS0" );
m_deviceCmb->insertItem( "/dev/ttyS1" );
m_deviceCmb->insertItem( "/dev/ttySA0");
m_deviceCmb->insertItem( "/dev/ttySA1");
}
SerialConfigWidget::~SerialConfigWidget() {
}
void SerialConfigWidget::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");
if (rad_flow == 1) {
m_base->setFlow( IOLayerBase::Hardware );
} else if (rad_flow == 2) {
m_base->setFlow( IOLayerBase::Software );
} else {
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 4800:
m_base->setSpeed( IOLayerBase::Baud_4800 );
break;
case 2400:
m_base->setSpeed( IOLayerBase::Baud_2400 );
break;
case 1200:
m_base->setSpeed( IOLayerBase::Baud_1200 );
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 );
}
if ( prof.readEntry("Device").isEmpty() ) return;
- setCurrent( prof.readEntry("Device"), m_deviceCmb );
+ ComboboxHelper::setCurrent( prof.readEntry("Device"), m_deviceCmb );
}
/*
* save speed,
* flow,
* parity
*/
void SerialConfigWidget::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_4800:
speed = 4800;
break;
case IOLayerBase::Baud_2400:
speed = 2400;
break;
case IOLayerBase::Baud_1200:
speed = 1200;
break;
default:
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);
}
diff --git a/noncore/apps/opie-console/settings.ui b/noncore/apps/opie-console/settings.ui
deleted file mode 100644
index 6944dd0..0000000
--- a/noncore/apps/opie-console/settings.ui
+++ b/dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE UI><UI>
-<class>Settings</class>
-<widget>
- <class>QDialog</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Settings</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>0</y>
- <width>596</width>
- <height>480</height>
- </rect>
- </property>
- <property stdset="1">
- <name>caption</name>
- <string>Settings</string>
- </property>
-</widget>
-</UI>
diff --git a/noncore/apps/opie-console/sz_transfer.cpp b/noncore/apps/opie-console/sz_transfer.cpp
index f505998..3299e33 100644
--- a/noncore/apps/opie-console/sz_transfer.cpp
+++ b/noncore/apps/opie-console/sz_transfer.cpp
@@ -1,86 +1,69 @@
#include "sz_transfer.h"
#include <qfile.h>
#include <stdio.h>
#include <sys/termios.h>
using namespace Opie::Core;
using namespace Opie::Core;
SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t)
{
}
SzTransfer::~SzTransfer() {
}
void SzTransfer::sendFile(const QFile& file) {
sendFile(file.name());
}
void SzTransfer::sendFile(const QString& file) {
//setcbreak(2); /* raw no echo */
proc = new OProcess;
*proc << "sz";
*proc << "-v" << "-v" << "-b" << file;
connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)),
this, SLOT(sent()));
connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
this, SLOT(SzReceivedStdout(Opie::Core::OProcess*,char*,int)));
connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),
this, SLOT(SzReceivedStderr(Opie::Core::OProcess*,char*,int)));
connect(layer(), SIGNAL(received(const QByteArray&)),
this, SLOT(receivedStdin(const QByteArray&)));
proc->start(OProcess::NotifyOnExit, OProcess::All);
}
void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) {
-
- owarn << "recieved from sz on stdout " << buflen << " bytes" << oendl;
-
QByteArray data(buflen);
data.fill(*buffer, buflen);
+
+#ifdef DEBUG_RECEIVE
for (uint i = 0; i < data.count(); i++ ) {
printf("%c", buffer[i] );
}
printf("\n");
+#endif
// send out through the io layer
layer()->send(data);
}
void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) {
-
- // parse and show data in a progress dialog/widget
- printf("stderr:\n");
- //for (int i = 0; i < length; i++)
- // printf("%c", buffer[i]);
- //printf("\n");
}
void SzTransfer::receivedStdin(const QByteArray &data) {
-
- owarn << "recieved from io_serial " << data.size() << " bytes" << oendl;
-
// recieved data from the io layer goes to sz
proc->writeStdin(data.data(), data.size());
-
}
void SzTransfer::sent() {
-
- owarn << "sent file" << oendl;
-
- //setcbreak(0); /* default */
-
-
delete proc;
disconnect(layer(), SIGNAL(received(const QByteArray&)),
this, SLOT(receivedStdin(const QByteArray&)));
-
}
diff --git a/noncore/apps/opie-console/tabwidget.cpp b/noncore/apps/opie-console/tabwidget.cpp
index 152c26b..79ccac5 100644
--- a/noncore/apps/opie-console/tabwidget.cpp
+++ b/noncore/apps/opie-console/tabwidget.cpp
@@ -1,50 +1,46 @@
#include "tabwidget.h"
-/* OPIE */
-#include <opie2/odebug.h>
-using namespace Opie::Core;
using Opie::Ui::OTabWidget;
TabWidget::TabWidget( QWidget* parent, const char* name )
: OTabWidget( parent, name ) {
connect(this, SIGNAL( currentChanged(QWidget*) ),
this, SLOT( slotCurChanged(QWidget*) ) );
}
TabWidget::~TabWidget() {
}
void TabWidget::add( Session* ses ) {
- owarn << "session ses " + ses->name() << oendl;
if ( !ses->widgetStack() ) return;
//reparent( ses->widgetStack(), QPoint() );
addTab( ses->widgetStack(), "console/konsole", ses->name() );
//addTab( ses->widgetStack(), ses->name() );
m_map.insert( ses->widgetStack(), ses );
}
void TabWidget::remove( Session* ses ) {
m_map.remove( ses->widgetStack() );
removePage( ses->widgetStack() );
}
void TabWidget::slotCurChanged( QWidget* wid ) {
QMap<QWidget*, Session*>::Iterator it;
it = m_map.find( wid );
if ( it == m_map.end() ) {
return;
}
emit activated( it.data() );
}
void TabWidget::setCurrent( Session* ses ) {
if (!ses )
return;
//showPage( ses->widgetStack() );
setCurrentTab( ses->widgetStack() );
}
diff --git a/noncore/apps/opie-console/terminalwidget.cpp b/noncore/apps/opie-console/terminalwidget.cpp
index 3e3b8a6..907de1b 100644
--- a/noncore/apps/opie-console/terminalwidget.cpp
+++ b/noncore/apps/opie-console/terminalwidget.cpp
@@ -1,242 +1,236 @@
#include "terminalwidget.h"
-/* OPIE */
-#include <opie2/odebug.h>
-
-using namespace Opie::Core;
-
/* QT */
#include <qlabel.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qradiobutton.h>
#include <qhgroupbox.h>
#include <qhbuttongroup.h>
#include <qlayout.h>
#include <qhbox.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_groupSize = new QHBox( this );
m_fontSelector = new Opie::Ui::OFontSelector( false, m_groupSize );
// 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
- owarn << "Options for terminal box" << oendl;
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;
};
m_fontSelector->setSelectedFont( prof.readEntry( "Font"), prof.readEntry( "FontStyle"), prof.readNumEntry( "FontSize" ), prof.readEntry( "FontCharset") );
// 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;
};
profile.writeEntry( "FontSize", m_fontSelector->fontSize() );
profile.writeEntry( "FontStyle", m_fontSelector->fontStyle() );
profile.writeEntry( "FontCharset", m_fontSelector->fontCharSet() );
profile.writeEntry( "Font", m_fontSelector->fontFamily() );
// 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/vt102emulation.cpp b/noncore/apps/opie-console/vt102emulation.cpp
deleted file mode 100644
index 35b789c..0000000
--- a/noncore/apps/opie-console/vt102emulation.cpp
+++ b/dev/null
@@ -1,1024 +0,0 @@
-/* ------------------------------------------------------------------------- */
-/* */
-/* [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 <stdio.h>
-#include <unistd.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
- {
- if (lec(1,0,ESC)) return;
- if (les(1,0,CHR)) { tau( TY_CHR___( ), s[0], 0); resetToken(); return; }
- if (lec(2,1,'Y')) return;
- if (lec(3,1,'Y')) return;
- if (p < 4) { tau( TY_VT52__(s[1] ), 0, 0); resetToken(); return; }
- tau( TY_VT52__(s[1] ), s[2],s[3]); resetToken(); return;
- }
-}
-
-void Vt102Emulation::XtermHack()
-{ int i,arg = 0;
- for (i = 2; i < ppos && '0'<=pbuf[i] && pbuf[i]<'9' ; i++)
- arg = 10*arg + (pbuf[i]-'0');
- if (pbuf[i] != ';') { ReportErrorToken(); return; }
- QChar *str = new QChar[ppos-i-2];
- for (int j = 0; j < ppos-i-2; j++) str[j] = pbuf[i+1+j];
- QString unistr(str,ppos-i-2);
- // arg == 1 doesn't change the title. In XTerm it only changes the icon name
- // (btw: arg=0 changes title and icon, arg=1 only icon, arg=2 only title
- if (arg == 0 || arg == 2) emit changeTitle(arg,unistr);
- delete [] str;
-}
-
-// Interpreting Codes ---------------------------------------------------------
-
-/*
- Now that the incoming character stream is properly tokenized,
- meaning is assigned to them. These are either operations of
- the current screen, or of the emulation class itself.
-
- The token to be interpreteted comes in as a machine word
- possibly accompanied by two parameters.
-
- Likewise, the operations assigned to, come with up to two
- arguments. One could consider to make up a proper table
- from the function below.
-
- The technical reference manual provides more informations
- about this mapping.
-*/
-
-void Vt102Emulation::tau( int token, int p, int q )
-{
-//scan_buffer_report();
-//if (token == TY_CHR___()) printf("%c",p); else
-//printf("tau(%d,%d,%d, %d,%d)\n",(token>>0)&0xff,(token>>8)&0xff,(token>>16)&0xffff,p,q);
- switch (token)
- {
-
- case TY_CHR___( ) : scr->ShowCharacter (p ); break; //UTF16
-
- // 127 DEL : ignored on input
-
- case TY_CTL___('@' ) : /* NUL: ignored */ break;
- case TY_CTL___('A' ) : /* SOH: ignored */ break;
- case TY_CTL___('B' ) : /* STX: ignored */ break;
- case TY_CTL___('C' ) : /* ETX: ignored */ break;
- case TY_CTL___('D' ) : /* EOT: ignored */ break;
- case TY_CTL___('E' ) : reportAnswerBack ( ); break; //VT100
- case TY_CTL___('F' ) : /* ACK: ignored */ break;
- case TY_CTL___('G' ) : gui->bell ( ); break; //VT100
- case TY_CTL___('H' ) : scr->BackSpace ( ); break; //VT100
- case TY_CTL___('I' ) : scr->Tabulate ( ); break; //VT100
- case TY_CTL___('J' ) : scr->NewLine ( ); break; //VT100
- case TY_CTL___('K' ) : scr->NewLine ( ); break; //VT100
- case TY_CTL___('L' ) : scr->NewLine ( ); break; //VT100
- case TY_CTL___('M' ) : scr->Return ( ); break; //VT100
-
- case TY_CTL___('N' ) : useCharset ( 1); break; //VT100
- case TY_CTL___('O' ) : useCharset ( 0); break; //VT100
-
- case TY_CTL___('P' ) : /* DLE: ignored */ break;
- case TY_CTL___('Q' ) : /* DC1: XON continue */ break; //VT100
- case TY_CTL___('R' ) : /* DC2: ignored */ break;
- case TY_CTL___('S' ) : /* DC3: XOFF halt */ break; //VT100
- case TY_CTL___('T' ) : /* DC4: ignored */ break;
- case TY_CTL___('U' ) : /* NAK: ignored */ break;
- case TY_CTL___('V' ) : /* SYN: ignored */ break;
- case TY_CTL___('W' ) : /* ETB: ignored */ break;
- case TY_CTL___('X' ) : scr->ShowCharacter ( 0x2592); break; //VT100
- case TY_CTL___('Y' ) : /* EM : ignored */ break;
- case TY_CTL___('Z' ) : scr->ShowCharacter ( 0x2592); break; //VT100
- case TY_CTL___('[' ) : /* ESC: cannot be seen here. */ break;
- case TY_CTL___('\\' ) : /* FS : ignored */ break;
- case TY_CTL___(']' ) : /* GS : ignored */ break;
- case TY_CTL___('^' ) : /* RS : ignored */ break;
- case TY_CTL___('_' ) : /* US : ignored */ break;
-
- case TY_ESC___('D' ) : scr->index ( ); break; //VT100
- case TY_ESC___('E' ) : scr->NextLine ( ); break; //VT100
- case TY_ESC___('H' ) : scr->changeTabStop (TRUE ); break; //VT100
- case TY_ESC___('M' ) : scr->reverseIndex ( ); break; //VT100
- case TY_ESC___('Z' ) : reportTerminalType ( ); break;
- case TY_ESC___('c' ) : reset ( ); break;
-
- case TY_ESC___('n' ) : useCharset ( 2); break;
- case TY_ESC___('o' ) : useCharset ( 3); break;
- case TY_ESC___('7' ) : saveCursor ( ); break;
- case TY_ESC___('8' ) : restoreCursor ( ); break;
-
- case TY_ESC___('=' ) : setMode (MODE_AppKeyPad); break;
- case TY_ESC___('>' ) : resetMode (MODE_AppKeyPad); break;
- case TY_ESC___('<' ) : setMode (MODE_Ansi ); break; //VT100
-
- case TY_ESC_CS('(', '0') : setCharset (0, '0'); break; //VT100
- case TY_ESC_CS('(', 'A') : setCharset (0, 'A'); break; //VT100
- case TY_ESC_CS('(', 'B') : setCharset (0, 'B'); break; //VT100
-
- case TY_ESC_CS(')', '0') : setCharset (1, '0'); break; //VT100
- case TY_ESC_CS(')', 'A') : setCharset (1, 'A'); break; //VT100
- case TY_ESC_CS(')', 'B') : setCharset (1, 'B'); break; //VT100
-
- case TY_ESC_CS('*', '0') : setCharset (2, '0'); break; //VT100
- case TY_ESC_CS('*', 'A') : setCharset (2, 'A'); break; //VT100
- case TY_ESC_CS('*', 'B') : setCharset (2, 'B'); break; //VT100
-
- case TY_ESC_CS('+', '0') : setCharset (3, '0'); break; //VT100
- case TY_ESC_CS('+', 'A') : setCharset (3, 'A'); break; //VT100
- case TY_ESC_CS('+', 'B') : setCharset (3, 'B'); break; //VT100
-
- case TY_ESC_CS('%', 'G') : setCodec (1 ); break; //LINUX
- case TY_ESC_CS('%', '@') : setCodec (0 ); break; //LINUX
-
- case TY_ESC_DE('3' ) : /* IGNORED: double high, top half */ break;
- case TY_ESC_DE('4' ) : /* IGNORED: double high, bottom half */ break;
- case TY_ESC_DE('5' ) : /* IGNORED: single width, single high*/ break;
- case TY_ESC_DE('6' ) : /* IGNORED: double width, single high*/ break;
- case TY_ESC_DE('8' ) : scr->helpAlign ( ); break;
-
- case TY_CSI_PS('K', 0) : scr->clearToEndOfLine ( ); break;
- case TY_CSI_PS('K', 1) : scr->clearToBeginOfLine ( ); break;
- case TY_CSI_PS('K', 2) : scr->clearEntireLine ( ); break;
- case TY_CSI_PS('J', 0) : scr->clearToEndOfScreen ( ); break;
- case TY_CSI_PS('J', 1) : scr->clearToBeginOfScreen ( ); break;
- case TY_CSI_PS('J', 2) : scr->clearEntireScreen ( ); break;
- case TY_CSI_PS('g', 0) : scr->changeTabStop (FALSE ); break; //VT100
- case TY_CSI_PS('g', 3) : scr->clearTabStops ( ); break; //VT100
- case TY_CSI_PS('h', 4) : scr-> setMode (MODE_Insert ); break;
- case TY_CSI_PS('h', 20) : setMode (MODE_NewLine ); break;
- case TY_CSI_PS('i', 0) : /* IGNORE: attached printer */ break; //VT100
- case TY_CSI_PS('l', 4) : scr-> resetMode (MODE_Insert ); break;
- case TY_CSI_PS('l', 20) : resetMode (MODE_NewLine ); break;
-
- case TY_CSI_PS('m', 0) : scr->setDefaultRendition ( ); break;
- case TY_CSI_PS('m', 1) : scr-> setRendition (RE_BOLD ); break; //VT100
- case TY_CSI_PS('m', 4) : scr-> setRendition (RE_UNDERLINE); break; //VT100
- case TY_CSI_PS('m', 5) : scr-> setRendition (RE_BLINK ); break; //VT100
- case TY_CSI_PS('m', 7) : scr-> setRendition (RE_REVERSE ); break;
- case TY_CSI_PS('m', 10) : /* IGNORED: mapping related */ break; //LINUX
- case TY_CSI_PS('m', 11) : /* IGNORED: mapping related */ break; //LINUX
- case TY_CSI_PS('m', 12) : /* IGNORED: mapping related */ break; //LINUX
- case TY_CSI_PS('m', 22) : scr->resetRendition (RE_BOLD ); break;
- case TY_CSI_PS('m', 24) : scr->resetRendition (RE_UNDERLINE); break;
- case TY_CSI_PS('m', 25) : scr->resetRendition (RE_BLINK ); break;
- case TY_CSI_PS('m', 27) : scr->resetRendition (RE_REVERSE ); break;
-
- case TY_CSI_PS('m', 30) : scr->setForeColor ( 0); break;
- case TY_CSI_PS('m', 31) : scr->setForeColor ( 1); break;
- case TY_CSI_PS('m', 32) : scr->setForeColor ( 2); break;
- case TY_CSI_PS('m', 33) : scr->setForeColor ( 3); break;
- case TY_CSI_PS('m', 34) : scr->setForeColor ( 4); break;
- case TY_CSI_PS('m', 35) : scr->setForeColor ( 5); break;
- case TY_CSI_PS('m', 36) : scr->setForeColor ( 6); break;
- case TY_CSI_PS('m', 37) : scr->setForeColor ( 7); break;
- case TY_CSI_PS('m', 39) : scr->setForeColorToDefault( ); break;
-
- case TY_CSI_PS('m', 40) : scr->setBackColor ( 0); break;
- case TY_CSI_PS('m', 41) : scr->setBackColor ( 1); break;
- case TY_CSI_PS('m', 42) : scr->setBackColor ( 2); break;
- case TY_CSI_PS('m', 43) : scr->setBackColor ( 3); break;
- case TY_CSI_PS('m', 44) : scr->setBackColor ( 4); break;
- case TY_CSI_PS('m', 45) : scr->setBackColor ( 5); break;
- case TY_CSI_PS('m', 46) : scr->setBackColor ( 6); break;
- case TY_CSI_PS('m', 47) : scr->setBackColor ( 7); break;
- case TY_CSI_PS('m', 49) : scr->setBackColorToDefault( ); break;
-
- case TY_CSI_PS('m', 90) : scr->setForeColor ( 8); break;
- case TY_CSI_PS('m', 91) : scr->setForeColor ( 9); break;
- case TY_CSI_PS('m', 92) : scr->setForeColor ( 10); break;
- case TY_CSI_PS('m', 93) : scr->setForeColor ( 11); break;
- case TY_CSI_PS('m', 94) : scr->setForeColor ( 12); break;
- case TY_CSI_PS('m', 95) : scr->setForeColor ( 13); break;
- case TY_CSI_PS('m', 96) : scr->setForeColor ( 14); break;
- case TY_CSI_PS('m', 97) : scr->setForeColor ( 15); break;
-
- case TY_CSI_PS('m', 100) : scr->setBackColor ( 8); break;
- case TY_CSI_PS('m', 101) : scr->setBackColor ( 9); break;
- case TY_CSI_PS('m', 102) : scr->setBackColor ( 10); break;
- case TY_CSI_PS('m', 103) : scr->setBackColor ( 11); break;
- case TY_CSI_PS('m', 104) : scr->setBackColor ( 12); break;
- case TY_CSI_PS('m', 105) : scr->setBackColor ( 13); break;
- case TY_CSI_PS('m', 106) : scr->setBackColor ( 14); break;
- case TY_CSI_PS('m', 107) : scr->setBackColor ( 15); break;
-
- case TY_CSI_PS('n', 5) : reportStatus ( ); break;
- case TY_CSI_PS('n', 6) : reportCursorPosition ( ); break;
- case TY_CSI_PS('q', 0) : /* IGNORED: LEDs off */ break; //VT100
- case TY_CSI_PS('q', 1) : /* IGNORED: LED1 on */ break; //VT100
- case TY_CSI_PS('q', 2) : /* IGNORED: LED2 on */ break; //VT100
- case TY_CSI_PS('q', 3) : /* IGNORED: LED3 on */ break; //VT100
- case TY_CSI_PS('q', 4) : /* IGNORED: LED4 on */ break; //VT100
- case TY_CSI_PS('x', 0) : reportTerminalParms ( 2); break; //VT100
- case TY_CSI_PS('x', 1) : reportTerminalParms ( 3); break; //VT100
-
- case TY_CSI_PN('@' ) : scr->insertChars (p ); break;
- case TY_CSI_PN('A' ) : scr->cursorUp (p ); break; //VT100
- case TY_CSI_PN('B' ) : scr->cursorDown (p ); break; //VT100
- case TY_CSI_PN('C' ) : scr->cursorRight (p ); break; //VT100
- case TY_CSI_PN('D' ) : scr->cursorLeft (p ); break; //VT100
- case TY_CSI_PN('G' ) : scr->setCursorX (p ); break; //LINUX
- case TY_CSI_PN('H' ) : scr->setCursorYX (p, q); break; //VT100
- case TY_CSI_PN('L' ) : scr->insertLines (p ); break;
- case TY_CSI_PN('M' ) : scr->deleteLines (p ); break;
- case TY_CSI_PN('P' ) : scr->deleteChars (p ); break;
- case TY_CSI_PN('X' ) : scr->eraseChars (p ); break;
- case TY_CSI_PN('c' ) : reportTerminalType ( ); break; //VT100
- case TY_CSI_PN('d' ) : scr->setCursorY (p ); break; //LINUX
- case TY_CSI_PN('f' ) : scr->setCursorYX (p, q); break; //VT100
- case TY_CSI_PN('r' ) : scr->setMargins (p, q); break; //VT100
- case TY_CSI_PN('y' ) : /* IGNORED: Confidence test */ break; //VT100
-
- case TY_CSI_PR('h', 1) : setMode (MODE_AppCuKeys); break; //VT100
- case TY_CSI_PR('l', 1) : resetMode (MODE_AppCuKeys); break; //VT100
- case TY_CSI_PR('s', 1) : saveMode (MODE_AppCuKeys); break; //FIXME
- case TY_CSI_PR('r', 1) : restoreMode (MODE_AppCuKeys); break; //FIXME
-
- case TY_CSI_PR('l', 2) : resetMode (MODE_Ansi ); break; //VT100
-
- case TY_CSI_PR('h', 3) : setColumns ( 132); break; //VT100
- case TY_CSI_PR('l', 3) : setColumns ( 80); break; //VT100
-
- case TY_CSI_PR('h', 4) : /* IGNORED: soft scrolling */ break; //VT100
- case TY_CSI_PR('l', 4) : /* IGNORED: soft scrolling */ break; //VT100
-
- case TY_CSI_PR('h', 5) : scr-> setMode (MODE_Screen ); break; //VT100
- case TY_CSI_PR('l', 5) : scr-> resetMode (MODE_Screen ); break; //VT100
-
- case TY_CSI_PR('h', 6) : scr-> setMode (MODE_Origin ); break; //VT100
- case TY_CSI_PR('l', 6) : scr-> resetMode (MODE_Origin ); break; //VT100
- case TY_CSI_PR('s', 6) : scr-> saveMode (MODE_Origin ); break; //FIXME
- case TY_CSI_PR('r', 6) : scr->restoreMode (MODE_Origin ); break; //FIXME
-
- case TY_CSI_PR('h', 7) : scr-> setMode (MODE_Wrap ); break; //VT100
- case TY_CSI_PR('l', 7) : scr-> resetMode (MODE_Wrap ); break; //VT100
- case TY_CSI_PR('s', 7) : scr-> saveMode (MODE_Wrap ); break; //FIXME
- case TY_CSI_PR('r', 7) : scr->restoreMode (MODE_Wrap ); break; //FIXME
-
- case TY_CSI_PR('h', 8) : /* IGNORED: autorepeat on */ break; //VT100
- case TY_CSI_PR('l', 8) : /* IGNORED: autorepeat off */ break; //VT100
-
- case TY_CSI_PR('h', 9) : /* IGNORED: interlace */ break; //VT100
- case TY_CSI_PR('l', 9) : /* IGNORED: interlace */ break; //VT100
-
- case TY_CSI_PR('h', 25) : setMode (MODE_Cursor ); break; //VT100
- case TY_CSI_PR('l', 25) : resetMode (MODE_Cursor ); break; //VT100
-
- case TY_CSI_PR('h', 41) : /* IGNORED: obsolete more(1) fix */ break; //XTERM
- case TY_CSI_PR('l', 41) : /* IGNORED: obsolete more(1) fix */ break; //XTERM
- case TY_CSI_PR('s', 41) : /* IGNORED: obsolete more(1) fix */ break; //XTERM
- case TY_CSI_PR('r', 41) : /* IGNORED: obsolete more(1) fix */ break; //XTERM
-
- case TY_CSI_PR('h', 47) : setMode (MODE_AppScreen); break; //VT100
- case TY_CSI_PR('l', 47) : resetMode (MODE_AppScreen); break; //VT100
-
- case TY_CSI_PR('h', 1000) : setMode (MODE_Mouse1000); break; //XTERM
- case TY_CSI_PR('l', 1000) : resetMode (MODE_Mouse1000); break; //XTERM
- case TY_CSI_PR('s', 1000) : saveMode (MODE_Mouse1000); break; //XTERM
- case TY_CSI_PR('r', 1000) : restoreMode (MODE_Mouse1000); break; //XTERM
-
- case TY_CSI_PR('h', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
- case TY_CSI_PR('l', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
- case TY_CSI_PR('s', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
- case TY_CSI_PR('r', 1001) : /* IGNORED: hilite mouse tracking */ break; //XTERM
-
- case TY_CSI_PR('h', 1047) : setMode (MODE_AppScreen); break; //XTERM
- case TY_CSI_PR('l', 1047) : resetMode (MODE_AppScreen); break; //XTERM
-
- //FIXME: Unitoken: save translations
- case TY_CSI_PR('h', 1048) : saveCursor ( ); break; //XTERM
- case TY_CSI_PR('l', 1048) : restoreCursor ( ); break; //XTERM
-
- //FIXME: every once new sequences like this pop up in xterm.
- // Here's a guess of what they could mean.
- case TY_CSI_PR('h', 1049) : setMode (MODE_AppScreen); break; //XTERM
- case TY_CSI_PR('l', 1049) : resetMode (MODE_AppScreen); break; //XTERM
-
- //FIXME: when changing between vt52 and ansi mode evtl do some resetting.
- case TY_VT52__('A' ) : scr->cursorUp ( 1); break; //VT52
- case TY_VT52__('B' ) : scr->cursorDown ( 1); break; //VT52
- case TY_VT52__('C' ) : scr->cursorRight ( 1); break; //VT52
- case TY_VT52__('D' ) : scr->cursorLeft ( 1); break; //VT52
-
- case TY_VT52__('F' ) : setAndUseCharset (0, '0'); break; //VT52
- case TY_VT52__('G' ) : setAndUseCharset (0, 'B'); break; //VT52
-
- case TY_VT52__('H' ) : scr->setCursorYX (1,1 ); break; //VT52
- case TY_VT52__('I' ) : scr->reverseIndex ( ); break; //VT52
- case TY_VT52__('J' ) : scr->clearToEndOfScreen ( ); break; //VT52
- case TY_VT52__('K' ) : scr->clearToEndOfLine ( ); break; //VT52
- case TY_VT52__('Y' ) : scr->setCursorYX (p-31,q-31 ); break; //VT52
- case TY_VT52__('Z' ) : reportTerminalType ( ); break; //VT52
- case TY_VT52__('<' ) : setMode (MODE_Ansi ); break; //VT52
- case TY_VT52__('=' ) : setMode (MODE_AppKeyPad); break; //VT52
- case TY_VT52__('>' ) : resetMode (MODE_AppKeyPad); break; //VT52
-
- default : ReportErrorToken(); break;
- };
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Terminal to Host protocol */
-/* */
-/* ------------------------------------------------------------------------- */
-
-/*
- Outgoing bytes originate from several sources:
-
- - Replies to Enquieries.
- - Mouse Events
- - Keyboard Events
-*/
-
-/*!
-*/
-
-void Vt102Emulation::sendString(const char* s)
-{
- QByteArray tmp;
- tmp.setRawData( s, strlen( s ));
- emit sndBlock( tmp);
-}
-
-void Vt102Emulation::sendString(const QByteArray& s)
-{
- emit sndBlock( s );
-}
-
-// Replies ----------------------------------------------------------------- --
-
-// This section copes with replies send as response to an enquiery control code.
-
-/*!
-*/
-
-void Vt102Emulation::reportCursorPosition()
-{ char tmp[20];
- sprintf(tmp,"\033[%d;%dR",scr->getCursorY()+1,scr->getCursorX()+1);
- sendString(tmp);
-}
-
-/*
- What follows here is rather obsolete and faked stuff.
- The correspondent enquieries are neverthenless issued.
-*/
-
-/*!
-*/
-
-void Vt102Emulation::reportTerminalType()
-{
-//FIXME: should change?
- if (getMode(MODE_Ansi))
-// sendString("\033[?1;2c"); // I'm a VT100 with AP0 //FIXME: send only in response to ^[[0c
- sendString("\033[>0;115;0c"); // I'm a VT220 //FIXME: send only in response to ^[[>c
- else
- sendString("\033/Z"); // I'm a VT52
-}
-
-void Vt102Emulation::reportTerminalParms(int p)
-// DECREPTPARM
-{ char tmp[100];
- sprintf(tmp,"\033[%d;1;1;112;112;1;0x",p); // not really true.
- sendString(tmp);
-}
-
-/*!
-*/
-
-void Vt102Emulation::reportStatus()
-{
- sendString("\033[0n"); //VT100. Device status report. 0 = Ready.
-}
-
-/*!
-*/
-
-#define ANSWER_BACK "" // This is really obsolete VT100 stuff.
-
-void Vt102Emulation::reportAnswerBack()
-{
- sendString(ANSWER_BACK);
-}
-
-// Mouse Handling ---------------------------------------------------------- --
-
-/*!
- Mouse clicks are possibly reported to the client
- application if it has issued interest in them.
- They are normally consumed by the widget for copy
- and paste, but may be propagated from the widget
- when gui->setMouseMarks is set via setMode(MODE_Mouse1000).
-
- `x',`y' are 1-based.
- `ev' (event) indicates the button pressed (0-2)
- or a general mouse release (3).
-*/
-
-void Vt102Emulation::onMouse( int cb, int cx, int cy )
-{ char tmp[20];
- if (!connected) return;
- sprintf(tmp,"\033[M%c%c%c",cb+040,cx+040,cy+040);
- sendString(tmp);
-}
-
-// Keyboard Handling ------------------------------------------------------- --
-
-#define encodeMode(M,B) BITS(B,getMode(M))
-#define encodeStat(M,B) BITS(B,((ev->state() & (M)) == (M)))
-
-/*
- Keyboard event handling has been simplified somewhat by pushing
- the complications towards a configuration file [see KeyTrans class].
-*/
-
-void Vt102Emulation::onKeyPress( QKeyEvent* ev )
-{
- if (!connected) return; // someone else gets the keys
-
-//printf("State/Key: 0x%04x 0x%04x (%d,%d)\n",ev->state(),ev->key(),ev->text().length(),ev->text().length()?ev->text().ascii()[0]:0);
-
- // revert to non-history when typing
- if (scr->getHistCursor() != scr->getHistLines());
- scr->setHistCursor(scr->getHistLines());
-
- // lookup in keyboard translation table ...
- int cmd; const char* txt; int len;
- if (keytrans->findEntry(ev->key(), encodeMode(MODE_NewLine , BITS_NewLine ) + // OLD,
- encodeMode(MODE_Ansi , BITS_Ansi ) + // OBSOLETE,
- encodeMode(MODE_AppCuKeys, BITS_AppCuKeys ) + // VT100 stuff
- encodeStat(ControlButton , BITS_Control ) +
- encodeStat(ShiftButton , BITS_Shift ) +
- encodeStat(AltButton , BITS_Alt ),
- &cmd, &txt, &len ))
-//printf("cmd: %d, %s, %d\n",cmd,txt,len);
- {
- switch(cmd) // ... and execute if found.
- {
- case CMD_emitSelection : gui->insertSelection(); return;
- case CMD_scrollPageUp : gui->scroll(-gui->lines()/2); return;
- case CMD_scrollPageDown : gui->scroll(+gui->lines()/2); return;
- case CMD_scrollLineUp : gui->scroll(-1 ); return;
- case CMD_scrollLineDown : gui->scroll(+1 ); return;
- case CMD_send : sendString( txt ); return;
- case CMD_prevSession : emit prevSession(); return;
- case CMD_nextSession : emit nextSession(); return;
- }
- }
- // fall back handling
- if (!ev->text().isEmpty())
- {
- if (ev->state() & AltButton) sendString("\033"); // ESC, this is the ALT prefix
- /// very hacky
- if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='A')) sendString("\01");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='B')) sendString("\02");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='C')) sendString("\03");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='D')) sendString("\04");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='E')) sendString("\05");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='F')) sendString("\06");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='G')) sendString("\07");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='H')) sendString("\010");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='I')) sendString("\011");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='J')) sendString("\012");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='K')) sendString("\013");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='L')) sendString("\014");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='M')) sendString("\015");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='N')) sendString("\016");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='O')) sendString("\017");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='P')) sendString("\020");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Q')) sendString("\021");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='R')) sendString("\022");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='S')) sendString("\023");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='T')) sendString("\024");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='U')) sendString("\025");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='V')) sendString("\026");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='W')) sendString("\027");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='X')) sendString("\030");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Y')) sendString("\031");
- else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Z')) sendString("\032");
- else
- {
- QCString s = codec->fromUnicode(ev->text()); // encode for application
- sendString( s ); // we may well have s.length() > 1
- }
- return;
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* VT100 Charsets */
-/* */
-/* ------------------------------------------------------------------------- */
-
-// Character Set Conversion ------------------------------------------------ --
-
-/*
- The processing contains a VT100 specific code translation layer.
- It's still in use and mainly responsible for the line drawing graphics.
-
- These and some other glyphs are assigned to codes (0x5f-0xfe)
- normally occupied by the latin letters. Since this codes also
- appear within control sequences, the extra code conversion
- does not permute with the tokenizer and is placed behind it
- in the pipeline. It only applies to tokens, which represent
- plain characters.
-
- This conversion it eventually continued in TEWidget.C, since
- it might involve VT100 enhanced fonts, which have these
- particular glyphs allocated in (0x00-0x1f) in their code page.
-*/
-
-#define CHARSET charset[scr==screen[1]]
-
-// Apply current character map.
-
-unsigned short Vt102Emulation::applyCharset(unsigned short c)
-{
- if (CHARSET.graphic && 0x5f <= c && c <= 0x7e) return vt100_graphics[c-0x5f];
- if (CHARSET.pound && c == '#' ) return 0xa3; //This mode is obsolete
- return c;
-}
-
-/*
- "Charset" related part of the emulation state.
- This configures the VT100 charset filter.
-
- While most operation work on the current screen,
- the following two are different.
-*/
-
-void Vt102Emulation::resetCharset(int scrno)
-{
- charset[scrno].cu_cs = 0;
- strncpy(charset[scrno].charset,"BBBB",4);
- charset[scrno].sa_graphic = FALSE;
- charset[scrno].sa_pound = FALSE;
- charset[scrno].graphic = FALSE;
- charset[scrno].pound = FALSE;
-}
-
-/*!
-*/
-
-void Vt102Emulation::setCharset(int n, int cs) // on both screens.
-{
- charset[0].charset[n&3] = cs; useCharset(charset[0].cu_cs);
- charset[1].charset[n&3] = cs; useCharset(charset[1].cu_cs);
-}
-
-/*!
-*/
-
-void Vt102Emulation::setAndUseCharset(int n, int cs)
-{
- CHARSET.charset[n&3] = cs;
- useCharset(n&3);
-}
-
-/*!
-*/
-
-void Vt102Emulation::useCharset(int n)
-{
- CHARSET.cu_cs = n&3;
- CHARSET.graphic = (CHARSET.charset[n&3] == '0');
- CHARSET.pound = (CHARSET.charset[n&3] == 'A'); //This mode is obsolete
-}
-
-/*! Save the cursor position and the rendition attribute settings. */
-
-void Vt102Emulation::saveCursor()
-{
- CHARSET.sa_graphic = CHARSET.graphic;
- CHARSET.sa_pound = CHARSET.pound; //This mode is obsolete
- // we are not clear about these
- //sa_charset = charsets[cScreen->charset];
- //sa_charset_num = cScreen->charset;
- scr->saveCursor();
-}
-
-/*! Restore the cursor position and the rendition attribute settings. */
-
-void Vt102Emulation::restoreCursor()
-{
- CHARSET.graphic = CHARSET.sa_graphic;
- CHARSET.pound = CHARSET.sa_pound; //This mode is obsolete
- scr->restoreCursor();
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Mode Operations */
-/* */
-/* ------------------------------------------------------------------------- */
-
-/*
- Some of the emulations state is either added to the state of the screens.
-
- This causes some scoping problems, since different emulations choose to
- located the mode either to the current screen or to both.
-
- For strange reasons, the extend of the rendition attributes ranges over
- all screens and not over the actual screen.
-
- We decided on the precise precise extend, somehow.
-*/
-
-// "Mode" related part of the state. These are all booleans.
-
-void Vt102Emulation::resetModes()
-{
- resetMode(MODE_Mouse1000); saveMode(MODE_Mouse1000);
- resetMode(MODE_AppScreen); saveMode(MODE_AppScreen);
- // here come obsolete modes
- resetMode(MODE_AppCuKeys); saveMode(MODE_AppCuKeys);
- resetMode(MODE_NewLine );
- setMode(MODE_Ansi );
-}
-
-void Vt102Emulation::setMode(int m)
-{
- currParm.mode[m] = TRUE;
- switch (m)
- {
- case MODE_Mouse1000 : //gui->setMouseMarks(FALSE);
- break;
- case MODE_AppScreen : screen[1]->clearSelection();
- screen[1]->clearEntireScreen();
- setScreen(1);
- break;
- }
- if (m < MODES_SCREEN || m == MODE_NewLine)
- {
- screen[0]->setMode(m);
- screen[1]->setMode(m);
- }
-}
-
-void Vt102Emulation::resetMode(int m)
-{
- currParm.mode[m] = FALSE;
- switch (m)
- {
- case MODE_Mouse1000 : //gui->setMouseMarks(TRUE);
- break;
- case MODE_AppScreen : screen[0]->clearSelection();
- setScreen(0);
- break;
- }
- if (m < MODES_SCREEN || m == MODE_NewLine)
- {
- screen[0]->resetMode(m);
- screen[1]->resetMode(m);
- }
-}
-
-void Vt102Emulation::saveMode(int m)
-{
- saveParm.mode[m] = currParm.mode[m];
-}
-
-void Vt102Emulation::restoreMode(int m)
-{
- if(saveParm.mode[m]) setMode(m); else resetMode(m);
-}
-
-BOOL Vt102Emulation::getMode(int m)
-{
- return currParm.mode[m];
-}
-
-void Vt102Emulation::setConnect(bool c)
-{
- EmulationLayer::setConnect(c);
- if (c)
- { // refresh mouse mode
- if (getMode(MODE_Mouse1000))
- setMode(MODE_Mouse1000);
- else
- resetMode(MODE_Mouse1000);
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Diagnostic */
-/* */
-/* ------------------------------------------------------------------------- */
-
-/*! shows the contents of the scan buffer.
-
- This functions is used for diagnostics. It is called by \e ReportErrorToken
- to inform about strings that cannot be decoded or handled by the emulation.
-
- \sa ReportErrorToken
-*/
-
-/*!
-*/
-
-static void hexdump(int* s, int len)
-{ int i;
- for (i = 0; i < len; i++)
- {
- if (s[i] == '\\')
- printf("\\\\");
- else
- if ((s[i]) > 32 && s[i] < 127)
- printf("%c",s[i]);
- else
- printf("\\%04x(hex)",s[i]);
- }
-}
-
-void Vt102Emulation::scan_buffer_report()
-{
- if (ppos == 0 || ppos == 1 && (pbuf[0] & 0xff) >= 32) return;
- printf("token: "); hexdump(pbuf,ppos); printf("\n");
-}
-
-/*!
-*/
-
-void Vt102Emulation::ReportErrorToken()
-{
- printf("undecodable "); scan_buffer_report();
-}
diff --git a/noncore/apps/opie-console/vt102emulation.h b/noncore/apps/opie-console/vt102emulation.h
deleted file mode 100644
index 17ab449..0000000
--- a/noncore/apps/opie-console/vt102emulation.h
+++ b/dev/null
@@ -1,153 +0,0 @@
-/* -------------------------------------------------------------------------- */
-/* */
-/* [TEmuVt102.h] X 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> */
-/* */
-/* -------------------------------------------------------------------------- */
-/* Ported embedded-konsole to opie-terminal */
-/* */
-/* Copyright (C) 2002 by opie developers <opie@handhelds.org> */
-/* */
-/* -------------------------------------------------------------------------- */
-
-#ifndef VT102EMU_H
-#define VT102EMU_H
-
-#include "widget_layer.h"
-#include "screen.h"
-#include "emulation_layer.h"
-#include <qtimer.h>
-#include <stdio.h>
-
-//
-
-#define MODE_AppScreen (MODES_SCREEN+0)
-#define MODE_AppCuKeys (MODES_SCREEN+1)
-#define MODE_AppKeyPad (MODES_SCREEN+2)
-#define MODE_Mouse1000 (MODES_SCREEN+3)
-#define MODE_Ansi (MODES_SCREEN+4)
-#define MODE_total (MODES_SCREEN+5)
-
-struct DECpar
-{
- BOOL mode[MODE_total];
-};
-
-struct CharCodes
-{
- // coding info
- char charset[4]; //
- int cu_cs; // actual charset.
- bool graphic; // Some VT100 tricks
- bool pound ; // Some VT100 tricks
- bool sa_graphic; // saved graphic
- bool sa_pound; // saved pound
-};
-
-class Vt102Emulation: public EmulationLayer
-{ Q_OBJECT
-
-public:
-
- Vt102Emulation(WidgetLayer* gui);
- ~Vt102Emulation();
-
-public slots: // signals incoming from Widget
-
- void onKeyPress(QKeyEvent*);
- void onMouse(int cb, int cx, int cy);
-
-signals:
-
- void changeTitle(int,const QString&);
- void prevSession();
- void nextSession();
-
-public:
-
- void reset();
-
- /**
- * receive a char from IOLayer
- */
- void onRcvChar(int cc);
-
- /**
- * sends a list of bytes to the IOLayer
- */
- void sendString(const QByteArray&);
-
- /**
- * @deprecated use QByteArray instead
- * see sendString() above
- */
- void sendString(const char *);
-
-public:
-
- BOOL getMode (int m);
-
- void setMode (int m);
- void resetMode (int m);
- void saveMode (int m);
- void restoreMode(int m);
- void resetModes();
-
- void setConnect(bool r);
-
-private:
-
- void resetToken();
-#define MAXPBUF 80
- void pushToToken(int cc);
- int pbuf[MAXPBUF]; //FIXME: overflow?
- int ppos;
-#define MAXARGS 15
- void addDigit(int dig);
- void addArgument();
- int argv[MAXARGS];
- int argc;
- void initTokenizer();
- int tbl[256];
-
- void scan_buffer_report(); //FIXME: rename
- void ReportErrorToken(); //FIXME: rename
-
- void tau(int code, int p, int q);
- void XtermHack();
-
- //
-
- void reportTerminalType();
- void reportStatus();
- void reportAnswerBack();
- void reportCursorPosition();
- void reportTerminalParms(int p);
-
-protected:
-
- unsigned short applyCharset(unsigned short c);
- void setCharset(int n, int cs);
- void useCharset(int n);
- void setAndUseCharset(int n, int cs);
- void saveCursor();
- void restoreCursor();
- void resetCharset(int scrno);
- CharCodes charset[2];
-
- DECpar currParm;
- DECpar saveParm;
-};
-
-#endif // ifndef ANSIEMU_H
diff --git a/noncore/apps/opie-console/widget.cpp b/noncore/apps/opie-console/widget.cpp
deleted file mode 100644
index 4a578be..0000000
--- a/noncore/apps/opie-console/widget.cpp
+++ b/dev/null
@@ -1,1278 +0,0 @@
-/* ------------------------------------------------------------------------ */
-/* */
-/* [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 <qpe/config.h>
-
-#include <qclipboard.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);
- setVTFont( QFont("fixed") );
- setColorTable(base_color_table); // init color table
-
- qApp->installEventFilter( this ); //FIXME: see below
-// KCursor::setAutoHideCursor( this, true );
-
- // Init DnD ////////////////////////////////////////////////////////////////
- currentSession = NULL;
-// setAcceptDrops(true); // attempt
-// m_drop = new QPopupMenu(this);
-// m_drop->insertItem( QString("Paste"), 0);
-// m_drop->insertItem( QString("cd"), 1);
-// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
-
- // we need focus so that the auto-hide cursor feature works
- setFocus();
- setFocusPolicy( WheelFocus );
-}
-
-//FIXME: make proper destructor
-// Here's a start (David)
-Widget::~Widget()
-{
- qApp->removeEventFilter( this );
- if (image) free(image);
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Display Operations */
-/* */
-/* ------------------------------------------------------------------------- */
-
-/*!
- attributed string draw primitive
-*/
-
-void Widget::drawAttrStr(QPainter &paint, QRect rect,
- QString& str, Character attr, BOOL pm, BOOL clear)
-{
- if (pm && color_table[attr.b].transparent)
- {
- paint.setBackgroundMode( TransparentMode );
- if (clear) erase(rect);
- }
- else
- {
- if (blinking)
- paint.fillRect(rect, color_table[attr.b].color);
- else
- {
- paint.setBackgroundMode( OpaqueMode );
- paint.setBackgroundColor( color_table[attr.b].color );
- }
- }
-
- if (color_table[attr.f].bold)
- paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
- else
- paint.setPen(color_table[attr.f].color);
-
- paint.drawText(rect.x(),rect.y()+font_a, str);
-
- if (attr.r & RE_UNDERLINE)
- paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
-}
-
-/*!
- The image can only be set completely.
-
- The size of the new image may or may not match the size of the widget.
-*/
-
-void Widget::setImage(const Character* const newimg, int lines, int columns)
-{ int y,x,len;
- const QPixmap* pm = backgroundPixmap();
- QPainter paint;
- setUpdatesEnabled(FALSE);
- paint.begin( this );
-HCNT("setImage");
-
- QPoint tL = contentsRect().topLeft();
- int tLx = tL.x();
- int tLy = tL.y();
- hasBlinker = FALSE;
-
- int cf = -1; // undefined
- int cb = -1; // undefined
- int cr = -1; // undefined
-
- int lins = QMIN(this->lines, QMAX(0,lines ));
- int cols = QMIN(this->columns,QMAX(0,columns));
- QChar *disstrU = new QChar[cols];
-
-//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
- for (y = 0; y < lins; y++)
- {
- const Character* lcl = &image[y*this->columns];
- const Character* const ext = &newimg[y*columns];
- if (!resizing) // not while resizing, we're expecting a paintEvent
- for (x = 0; x < cols; x++)
- {
- 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] = fontMap(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] = fontMap(ext[x+len].c);
- }
- QString unistr(disstrU,len);
- drawAttrStr(paint,
- QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
- unistr, ext[x], pm != NULL, true);
- x += len - 1;
- }
- }
- // finally, 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); // 1000 ms
- if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
- delete [] disstrU;
-}
-
-// paint Event ////////////////////////////////////////////////////
-
-/*!
- The difference of this routine vs. the `setImage' is,
- that the drawing does not include a difference analysis
- between the old and the new image. Instead, the internal
- image is used and the painting bound by the PaintEvent box.
-*/
-
-void Widget::paintEvent( QPaintEvent* pe )
-{
-
-//{ static int cnt = 0; printf("paint %d\n",cnt++); }
- const QPixmap* pm = backgroundPixmap();
- QPainter paint;
- setUpdatesEnabled(FALSE);
- paint.begin( this );
- paint.setBackgroundMode( TransparentMode );
-HCNT("paintEvent");
-
- // Note that the actual widget size can be slightly larger
- // that the image (the size is truncated towards the smaller
- // number of characters in `resizeEvent'. The paint rectangle
- // can thus be larger than the image, but less then the size
- // of one character.
-
- QRect rect = pe->rect().intersect(contentsRect());
-
- QPoint tL = contentsRect().topLeft();
- int tLx = tL.x();
- int tLy = tL.y();
-
- int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
- int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
- int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
- int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
-
- /*
- printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
- rect.left(), rect.right(), rect.top(), rect.bottom());
- */
-
- // if (pm != NULL && color_table[image->b].transparent)
- // erase(rect);
- // BL: I have no idea why we need this, and it breaks the refresh.
-
- QChar *disstrU = new QChar[columns];
- for (int y = luy; y <= rly; y++)
- for (int x = lux; x <= rlx; x++)
- {
- int len = 1;
- disstrU[0] = fontMap(image[loc(x,y)].c);
- int cf = image[loc(x,y)].f;
- int cb = image[loc(x,y)].b;
- int cr = image[loc(x,y)].r;
- while (x+len <= rlx &&
- image[loc(x+len,y)].f == cf &&
- image[loc(x+len,y)].b == cb &&
- image[loc(x+len,y)].r == cr )
- {
- disstrU[len] = fontMap(image[loc(x+len,y)].c);
- len += 1;
- }
- QString unistr(disstrU,len);
- drawAttrStr(paint,
- QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
- unistr, image[loc(x,y)], pm != NULL, false);
- x += len - 1;
- }
- delete [] disstrU;
- drawFrame( &paint );
- paint.end();
- setUpdatesEnabled(TRUE);
-}
-
-void Widget::blinkEvent()
-{
- blinking = !blinking;
- repaint(FALSE);
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Resizing */
-/* */
-/* ------------------------------------------------------------------------- */
-
-void Widget::resizeEvent(QResizeEvent* ev)
-{
-// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
- //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
- //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
- //printf("curren: %d,%d\n",width(),height());
-HCNT("resizeEvent");
-
- // see comment in `paintEvent' concerning the rounding.
- //FIXME: could make a routine here; check width(),height()
- assert(ev->size().width() == width());
- assert(ev->size().height() == height());
-
- propagateSize();
-}
-
-void Widget::propagateSize()
-{
- Character* oldimg = image;
- int oldlin = lines;
- int oldcol = columns;
- makeImage();
- // we copy the old image to reduce flicker
- int lins = QMIN(oldlin,lines);
- int cols = QMIN(oldcol,columns);
- if (oldimg)
- {
- for (int lin = 0; lin < lins; lin++)
- memcpy((void*)&image[columns*lin],
- (void*)&oldimg[oldcol*lin],cols*sizeof(Character));
- free(oldimg); //FIXME: try new,delete
- }
- else
- clearImage();
-
- //NOTE: control flows from the back through the chest right into the eye.
- // `emu' will call back via `setImage'.
-
- resizing = TRUE;
- emit changedImageSizeSignal(lines, columns); // expose resizeEvent
- resizing = FALSE;
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Scrollbar */
-/* */
-/* ------------------------------------------------------------------------- */
-
-void Widget::scrollChanged(int)
-{
- emit changedHistoryCursor(scrollbar->value()); //expose
-}
-
-void Widget::setScroll(int cursor, int slines)
-{
- disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
- scrollbar->setRange(0,slines);
- scrollbar->setSteps(1,lines);
- scrollbar->setValue(cursor);
- connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
-}
-
-void Widget::setScrollbarLocation(int loc)
-{
- if (scrollLoc == loc) return; // quickly
- scrollLoc = loc;
- propagateSize();
- update();
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Mouse */
-/* */
-/* ------------------------------------------------------------------------- */
-
-/*!
- Three different operations can be performed using the mouse, and the
- routines in this section serve all of them:
-
- 1) The press/release events are exposed to the application
- 2) Marking (press and move left button) and Pasting (press middle button)
- 3) The right mouse button is used from the configuration menu
-
- NOTE: During the marking process we attempt to keep the cursor within
- the bounds of the text as being displayed by setting the mouse position
- whenever the mouse has left the text area.
-
- Two reasons to do so:
- 1) QT does not allow the `grabMouse' to confine-to the Widget.
- Thus a `XGrapPointer' would have to be used instead.
- 2) Even if so, this would not help too much, since the text area
- of the Widget is normally not identical with it's bounds.
-
- The disadvantage of the current handling is, that the mouse can visibly
- leave the bounds of the widget and is then moved back. Because of the
- current construction, and the reasons mentioned above, we cannot do better
- without changing the overall construction.
-*/
-
-/*!
-*/
-
-void Widget::mousePressEvent(QMouseEvent* ev)
-{
-//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
- if ( !contentsRect().contains(ev->pos()) ) return;
- QPoint tL = contentsRect().topLeft();
- int tLx = tL.x();
- int tLy = tL.y();
-
- word_selection_mode = FALSE;
-
-//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
- if ( ev->button() == LeftButton)
- {
- QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
-
- if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
-
- if (mouse_marks || (ev->state() & ShiftButton))
- {
- emit clearSelectionSignal();
- iPntSel = pntSel = pos;
- actSel = 1; // left mouse button pressed but nothing selected yet.
- grabMouse( /*crossCursor*/ ); // handle with care!
- }
- else
- {
- emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
- }
- }
- if ( ev->button() == MidButton )
- {
- emitSelection();
- }
- if ( ev->button() == RightButton ) // Configure
- {
- emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
- }
-}
-
-void Widget::mouseMoveEvent(QMouseEvent* ev)
-{
- // for auto-hiding the cursor, we need mouseTracking
- if (ev->state() == NoButton ) return;
-
- if (actSel == 0) return;
-
- // don't extend selection while pasting
- if (ev->state() & MidButton) return;
-
- //if ( !contentsRect().contains(ev->pos()) ) return;
- QPoint tL = contentsRect().topLeft();
- int tLx = tL.x();
- int tLy = tL.y();
- int scroll = scrollbar->value();
-
- // we're in the process of moving the mouse with the left button pressed
- // the mouse cursor will kept catched within the bounds of the text in
- // this widget.
-
- // Adjust position within text area bounds. See FIXME above.
- QPoint pos = ev->pos();
- if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
- if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
- if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
- if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
- // check if we produce a mouse move event by this
- if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
-
- if ( pos.y() == tLy+bY+lines*font_h-1 )
- {
- scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
- }
- if ( pos.y() == tLy+bY )
- {
- scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
- }
-
- QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
- QPoint ohere;
- bool swapping = FALSE;
-
- if ( word_selection_mode )
- {
- // Extend to word boundaries
- int i;
- int selClass;
-
- bool left_not_right = ( here.y() < iPntSel.y() ||
- here.y() == iPntSel.y() && here.x() < iPntSel.x() );
- bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
- pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
- swapping = left_not_right != old_left_not_right;
-
- // Find left (left_not_right ? from here : from start)
- QPoint left = left_not_right ? here : iPntSel;
- i = loc(left.x(),left.y());
- selClass = charClass(image[i].c);
- while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
- { i--; left.rx()--; }
-
- // Find left (left_not_right ? from start : from here)
- QPoint right = left_not_right ? iPntSel : here;
- i = loc(right.x(),right.y());
- selClass = charClass(image[i].c);
- while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
- { i++; right.rx()++; }
-
- // Pick which is start (ohere) and which is extension (here)
- if ( left_not_right )
- {
- here = left; ohere = right;
- }
- else
- {
- here = right; ohere = left;
- }
- }
-
- if (here == pntSel && scroll == scrollbar->value()) return; // not moved
-
- if ( word_selection_mode ) {
- if ( actSel < 2 || swapping ) {
- emit beginSelectionSignal( ohere.x(), ohere.y() );
- }
- } else if ( actSel < 2 ) {
- emit beginSelectionSignal( pntSel.x(), pntSel.y() );
- }
-
- actSel = 2; // within selection
- pntSel = here;
- emit extendSelectionSignal( here.x(), here.y() );
-}
-
-void Widget::mouseReleaseEvent(QMouseEvent* ev)
-{
-//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
- if ( ev->button() == LeftButton)
- {
- if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
- preserve_line_breaks = TRUE;
- actSel = 0;
-
- //FIXME: emits a release event even if the mouse is
- // outside the range. The procedure used in `mouseMoveEvent'
- // applies here, too.
-
- QPoint tL = contentsRect().topLeft();
- int tLx = tL.x();
- int tLy = tL.y();
-
- if (!mouse_marks && !(ev->state() & ShiftButton))
- emit mouseSignal( 3, // release
- (ev->x()-tLx-blX)/font_w + 1,
- (ev->y()-tLy-bY)/font_h + 1 );
- releaseMouse();
- }
-}
-
-void Widget::mouseDoubleClickEvent(QMouseEvent* ev)
-{
- if ( ev->button() != LeftButton) return;
-
- QPoint tL = contentsRect().topLeft();
- int tLx = tL.x();
- int tLy = tL.y();
- QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
-
- // pass on double click as two clicks.
- if (!mouse_marks && !(ev->state() & ShiftButton))
- {
- emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
- emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
- emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
- return;
- }
-
-
- emit clearSelectionSignal();
- QPoint bgnSel = pos;
- QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
- int i = loc(bgnSel.x(),bgnSel.y());
- iPntSel = bgnSel;
-
- word_selection_mode = TRUE;
-
- // find word boundaries...
- int selClass = charClass(image[i].c);
- {
- // set the start...
- int x = bgnSel.x();
- while ( x > 0 && charClass(image[i-1].c) == selClass )
- { i--; x--; }
- bgnSel.setX(x);
- emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
-
- // set the end...
- i = loc( endSel.x(), endSel.y() );
- x = endSel.x();
- while( x < columns-1 && charClass(image[i+1].c) == selClass )
- { i++; x++ ; }
- endSel.setX(x);
- actSel = 2; // within selection
- emit extendSelectionSignal( endSel.x(), endSel.y() );
- emit endSelectionSignal(preserve_line_breaks);
- preserve_line_breaks = TRUE;
- }
-}
-
-void Widget::focusInEvent( QFocusEvent * )
-{
-
- // do nothing, to prevent repainting
-}
-
-
-void Widget::focusOutEvent( QFocusEvent * )
-{
- // do nothing, to prevent repainting
-}
-
-bool Widget::focusNextPrevChild( bool next )
-{
- if (next)
- return false; // This disables changing the active part in konqueror
- // when pressing Tab
- return QFrame::focusNextPrevChild( next );
-}
-
-
-int Widget::charClass(char ch) const
-{
- // This might seem like overkill, but imagine if ch was a Unicode
- // character (Qt 2.0 QChar) - it might then be sensible to separate
- // the different language ranges, etc.
-
- if ( isspace(ch) ) return ' ';
-
- static const char *word_characters = ":@-./_~";
- if ( isalnum(ch) || strchr(word_characters, ch) )
- return 'a';
-
- // Everything else is weird
- return 1;
-}
-
-void Widget::setMouseMarks(bool on)
-{
- mouse_marks = on;
- setCursor( mouse_marks ? ibeamCursor : arrowCursor );
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Clipboard */
-/* */
-/* ------------------------------------------------------------------------- */
-
-#undef KeyPress
-
-void Widget::emitSelection()
-// Paste Clipboard by simulating keypress events
-{
-#ifndef QT_NO_CLIPBOARD
- QString text = QApplication::clipboard()->text();
- if ( ! text.isNull() )
- {
- text.replace(QRegExp("\n"), "\r");
- QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
- emit keyPressedSignal(&e); // expose as a big fat keypress event
- emit clearSelectionSignal();
- }
-#endif
-}
-
-void Widget::emitText(QString text)
-{
- QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
- emit keyPressedSignal(&e); // expose as a big fat keypress event
-}
-
-void Widget::pasteClipboard( )
-{
- emitSelection();
-}
-
-void Widget::setSelection(const QString& t)
-{
-#ifndef QT_NO_CLIPBOARD
- // Disconnect signal while WE set the clipboard
- QObject *cb = QApplication::clipboard();
- QObject::disconnect( cb, SIGNAL(dataChanged()),
- this, SLOT(onClearSelection()) );
-
- QApplication::clipboard()->setText(t);
-
- QObject::connect( cb, SIGNAL(dataChanged()),
- this, SLOT(onClearSelection()) );
-#endif
-}
-
-void Widget::onClearSelection()
-{
- emit clearSelectionSignal();
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Keyboard */
-/* */
-/* ------------------------------------------------------------------------- */
-
-//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
-// due to a bug in `QT' or the ignorance of the author to prevent
-// repaint events being emitted to the screen whenever one leaves
-// or reenters the screen to/from another application.
-//
-// Troll says one needs to change focusInEvent() and focusOutEvent(),
-// which would also let you have an in-focus cursor and an out-focus
-// cursor like xterm does.
-
-// for the auto-hide cursor feature, I added empty focusInEvent() and
-// focusOutEvent() so that update() isn't called.
-// For auto-hide, we need to get keypress-events, but we only get them when
-// we have focus.
-
-void Widget::doScroll(int lines)
-{
- scrollbar->setValue(scrollbar->value()+lines);
-}
-
-bool Widget::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
- if ( e->type() == QEvent::Wheel) {
- QApplication::sendEvent(scrollbar, e);
- }
-
-#ifdef FAKE_CTRL_AND_ALT
- static bool control = FALSE;
- static bool alt = FALSE;
- 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.
-
- if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
- emitText("\\"); // expose
- } else
- emit keyPressedSignal(ke); // expose
- ke->accept();
-#ifdef FAKE_CTRL_AND_ALT
- if ( dele ) delete e;
-#endif
- return true; // stop the event
- }
- if ( e->type() == QEvent::Enter ) {
- QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
- this, SLOT(onClearSelection()) );
- }
- if ( e->type() == QEvent::Leave ) {
- QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
- this, SLOT(onClearSelection()) );
- }
- return QFrame::eventFilter( obj, e );
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Frame */
-/* */
-/* ------------------------------------------------------------------------- */
-
-void Widget::frameChanged()
-{
- propagateSize();
- update();
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Sound */
-/* */
-/* ------------------------------------------------------------------------- */
-
-void Widget::Bell()
-{
- QApplication::beep();
-}
-
-/* ------------------------------------------------------------------------- */
-/* */
-/* Auxiluary */
-/* */
-/* ------------------------------------------------------------------------- */
-
-void Widget::clearImage()
-// initialize the image
-// for internal use only
-{
- for (int y = 0; y < lines; y++)
- for (int x = 0; x < columns; x++)
- {
- image[loc(x,y)].c = 0xff; //' ';
- image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
- image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
- image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
- }
-}
-
-// Create Image ///////////////////////////////////////////////////////
-
-void Widget::calcGeometry()
-{
- //FIXME: set rimX == rimY == 0 when running in full screen mode.
-
- scrollbar->resize(QApplication::style().scrollBarExtent().width(),
- contentsRect().height());
- switch(scrollLoc)
- {
- case SCRNONE :
- columns = ( contentsRect().width() - 2 * rimX ) / font_w;
- blX = (contentsRect().width() - (columns*font_w) ) / 2;
- brX = blX;
- scrollbar->hide();
- break;
- case SCRLEFT :
- columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
- brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
- blX = brX + scrollbar->width();
- scrollbar->move(contentsRect().topLeft());
- scrollbar->show();
- break;
- case SCRRIGHT:
- columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
- blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
- brX = blX;
- scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
- scrollbar->show();
- break;
- }
- //FIXME: support 'rounding' styles
- lines = ( contentsRect().height() - 2 * rimY ) / font_h;
- bY = (contentsRect().height() - (lines *font_h)) / 2;
-}
-
-void Widget::makeImage()
-//FIXME: rename 'calcGeometry?
-{
- calcGeometry();
- image = (Character*) malloc(lines*columns*sizeof(Character));
- clearImage();
-}
-
-// calculate the needed size
-QSize Widget::calcSize(int cols, int lins) const
-{
- int frw = width() - contentsRect().width();
- int frh = height() - contentsRect().height();
- int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
- return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
-}
-
-QSize Widget::sizeHint() const
-{
- return size();
-}
-
-void Widget::styleChange(QStyle &)
-{
- propagateSize();
-}
-
-#ifndef QT_NO_DRAGANDDROP
-
-/* --------------------------------------------------------------------- */
-/* */
-/* Drag & Drop */
-/* */
-/* --------------------------------------------------------------------- */
-
-
-void Widget::dragEnterEvent(QDragEnterEvent* e)
-{
- e->accept(QTextDrag::canDecode(e) ||
- QUriDrag::canDecode(e));
-}
-
-void Widget::dropEvent(QDropEvent* event)
-{
- // The current behaviour when url(s) are dropped is
- // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
- // * in all other cases, just paste
- // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
- QStrList strlist;
- int file_count = 0;
- dropText = "";
- bool bPopup = true;
-
- if(QUriDrag::decode(event, strlist)) {
- if (strlist.count()) {
- for(const char* p = strlist.first(); p; p = strlist.next()) {
- if(file_count++ > 0) {
- dropText += " ";
- bPopup = false; // more than one file, don't popup
- }
-
-/*
- KURL url(p);
- if (url.isLocalFile()) {
- dropText += url.path(); // local URL : remove protocol
- }
- else {
- dropText += url.prettyURL();
- bPopup = false; // a non-local file, don't popup
- }
-*/
-
- }
-
- if (bPopup)
- // m_drop->popup(pos() + event->pos());
- m_drop->popup(mapToGlobal(event->pos()));
- else
- {
- if (currentSession) {
- //currentSession->getEmulation()->sendString(dropText.local8Bit());
- QByteArray tmp;
- // ibot: this should be pretty wrong...
- // now it sends to the right layer
- currentSession-> emulationLayer()->send( tmp.setRawData( dropText.local8Bit()));
- }
- // kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
- }
- }
- }
- else if(QTextDrag::decode(event, dropText)) {
-// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
- if (currentSession) {
- //currentSession->getEmulation()->sendString(dropText.local8Bit());
- QByteArray tmp;
- currentSession->emulationLayer()->send( tmp.setRawData( dropText.local8Bit()));
- }
- // Paste it
- }
-}
-#endif
-
-
-void Widget::drop_menu_activated(int item)
-{
-#ifndef QT_NO_DRAGANDDROP
- QByteArray tmp;
- switch (item)
- {
- case 0: // paste
- //currentSession->getEmulation()->sendString(dropText.local8Bit());
- currentSession->emulationLayer()->send( tmp.setRawData( dropText.local8Bit()));
-
-// KWM::activate((Window)this->winId());
- break;
- case 1: // cd ...
- //currentSession->getEmulation()->sendString("cd ");
- tmp.setRawData( "cd " );
- currentSession->emulationLayer()->send( tmp );
- struct stat statbuf;
- if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
- {
- if ( !S_ISDIR(statbuf.st_mode) )
- {
-/*
- KURL url;
- url.setPath( dropText );
- dropText = url.directory( true, false ); // remove filename
-*/
- }
- }
- dropText.replace(QRegExp(" "), "\\ "); // escape spaces
- QByteArray tmp2;
- tmp.setRawDate( dropText.local8Bit() + "\n" );
- //currentSession->getEmulation()->sendString(dropText.local8Bit());
- //currentSession->getEmulation()->sendString("\n");
- currentSession->emulationLayer()->send( tmp );
-// KWM::activate((Window)this->winId());
- break;
- }
-#endif
-}
-
diff --git a/noncore/apps/opie-console/widget.h b/noncore/apps/opie-console/widget.h
deleted file mode 100644
index cfd709c..0000000
--- a/noncore/apps/opie-console/widget.h
+++ b/dev/null
@@ -1,213 +0,0 @@
-/* ----------------------------------------------------------------------- */
-/* */
-/* [widget.h] Terminal Emulation Widget */
-/* */
-/* ----------------------------------------------------------------------- */
-/* */
-/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
-/* */
-/* This file was 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> */
-/* */
-/* ------------------------------------------------------------------------ */
-
-// ibot: TODO *
-
-#ifndef WIDGET_H
-#define WIDGET_H
-
-#include <qapplication.h>
-#include <qwidget.h>
-#include <qlabel.h>
-#include <qtimer.h>
-#include <qcolor.h>
-#include <qkeycode.h>
-#include <qscrollbar.h>
-
-#include <qpopupmenu.h>
-
-#include "common.h"
-
-extern unsigned short vt100_graphics[32];
-
-class Session;
-
-// class Konsole;
-
-class Widget : public QFrame
-// a widget representing attributed text
-{ Q_OBJECT
-
-// friend class Konsole;
-
-public:
-
- Widget(QWidget *parent=0, const char *name=0);
- virtual ~Widget();
-
-public:
-
- QColor getDefaultBackColor();
-
- const ColorEntry* getColorTable() const;
- const ColorEntry* getdefaultColorTable() const;
- void setColorTable(const ColorEntry table[]);
-
- void setScrollbarLocation(int loc);
- enum { SCRNONE=0, SCRLEFT=1, SCRRIGHT=2 };
-
- void setScroll(int cursor, int lines);
- void doScroll(int lines);
-
- void emitSelection();
-
-public:
-
- void setImage(const Character* const newimg, int lines, int columns);
-
- int Lines() { return lines; }
- int Columns() { return columns; }
-
- void calcGeometry();
- void propagateSize();
- QSize calcSize(int cols, int lins) const;
-
- QSize sizeHint() const;
-
-public:
-
- void Bell();
- void emitText(QString text);
- void pasteClipboard();
-
-signals:
-
- void keyPressedSignal(QKeyEvent *e);
- void mouseSignal(int cb, int cx, int cy);
- void changedImageSizeSignal(int lines, int columns);
- void changedHistoryCursor(int value);
- void configureRequest( Widget*, int state, int x, int y );
-
- void clearSelectionSignal();
- void beginSelectionSignal( const int x, const int y );
- void extendSelectionSignal( const int x, const int y );
- void endSelectionSignal(const BOOL preserve_line_breaks);
-
-
-protected:
-
- virtual void styleChange( QStyle& );
-
- bool eventFilter( QObject *, QEvent * );
-
- void drawAttrStr(QPainter &paint, QRect rect,
- QString& str, Character attr, BOOL pm, BOOL clear);
- void paintEvent( QPaintEvent * );
-
- void resizeEvent(QResizeEvent*);
-
- void fontChange(const QFont &font);
- void frameChanged();
-
- void mouseDoubleClickEvent(QMouseEvent* ev);
- void mousePressEvent( QMouseEvent* );
- void mouseReleaseEvent( QMouseEvent* );
- void mouseMoveEvent( QMouseEvent* );
-
- void focusInEvent( QFocusEvent * );
- void focusOutEvent( QFocusEvent * );
- bool focusNextPrevChild( bool next );
-
-#ifndef QT_NO_DRAGANDDROP
- // Dnd
- void dragEnterEvent(QDragEnterEvent* event);
- void dropEvent(QDropEvent* event);
-#endif
-
- virtual int charClass(char) const;
-
- void clearImage();
-
-public:
- const QPixmap *backgroundPixmap();
-
- void setSelection(const QString &t);
-
- virtual void setFont(const QFont &);
- void setVTFont(const QFont &);
- QFont getVTFont();
-
- void setMouseMarks(bool on);
-
-public slots:
-
- void onClearSelection();
-
-protected slots:
-
- void scrollChanged(int value);
- void blinkEvent();
-
-private:
-
- QChar (*fontMap)(QChar); // possible vt100 font extention
-
- bool fixed_font; // has fixed pitch
- int font_h; // height
- int font_w; // width
- int font_a; // ascend
-
- int blX; // actual offset (left)
- int brX; // actual offset (right)
- int bY; // actual offset
-
- int lines;
- int columns;
- Character *image; // [lines][columns]
-
- ColorEntry color_table[TABLE_COLORS];
-
- BOOL resizing;
- bool mouse_marks;
-
- void makeImage();
-
- QPoint iPntSel; // initial selection point
- QPoint pntSel; // current selection point
- int actSel; // selection state
- BOOL word_selection_mode;
- BOOL preserve_line_breaks;
-
- QClipboard* cb;
- QScrollBar* scrollbar;
- int scrollLoc;
-
-//#define SCRNONE 0
-//#define SCRLEFT 1
-//#define SCRRIGHT 2
-
- BOOL blinking; // hide text in paintEvent
- BOOL hasBlinker; // has characters to blink
- QTimer* blinkT; // active when hasBlinker
- QPopupMenu* m_drop;
- QString dropText;
- public:
- // current session in this widget
- // ibot: switch from TESession to Session!
- Session *currentSession;
-private slots:
- void drop_menu_activated(int item);
-};
-
-#endif // TE_WIDGET_H
diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp
deleted file mode 100644
index afded92..0000000
--- a/noncore/apps/opie-console/widget_layer.cpp
+++ b/dev/null
@@ -1,242 +0,0 @@
-/* ------------------------------------------------------------------------- */
-/* */
-/* widget_layer.cpp Widget Layer */
-/* */
-/* opie developers <opie@handhelds.org> */
-/* */
-/* ------------------------------------------------------------------------- */
-
-
-
-#include "widget_layer.h"
-
-
-#include <string.h>
-//#include <
-
-
-
-
-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;
- 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.
-
- 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
-};
-
diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h
deleted file mode 100644
index 6812711..0000000
--- a/noncore/apps/opie-console/widget_layer.h
+++ b/dev/null
@@ -1,265 +0,0 @@
-/* -------------------------------------------------------------------------- */
-/* */
-/* [widget_layer.h] Widget Layer */
-/* */
-/* -------------------------------------------------------------------------- */
-
-// proposal of a widget Layer in opie-console
-//
-// fellow devels:
-// just mail me (ibotty@web.de), what you additionally need from the main widget
-// (or say in chat)
-
-#ifndef WIDGET_LAYER_H
-#define WIDGET_LAYER_H
-
-// qt includes
-#include <qapplication.h>
-#include <qframe.h>
-#include <qarray.h>
-#include <qtimer.h>
-#include <qkeycode.h>
-#include <qclipboard.h>
-
-
-// opie-console includes
-#include "session.h"
-#include "common.h"
-#include "profile.h"
-
-
-/*
- * given a pseudo location ( column, line ),
- * returns the actual index, in the QArray<Character>
- */
-#define loc(X,Y) ((Y)*m_columns+(X))
-
-
-
-extern unsigned short vt100_graphics[32];
-
-class WidgetLayer : public QFrame
-{ Q_OBJECT
-
-public:
-
- /**
- * constructor
- * @param const Profile &config, the configuration for this widget
- * @param QWidget *parent, the parent widget
- * @param const char *name, the name of the widget, defaults to ""
- */
- WidgetLayer( const Profile& config, QWidget *parent=0, const char *name=0 );
-
- /**
- * destructor
- */
- virtual ~WidgetLayer();
-
-public:
- /**
- * sets the image
- * @param QArray<Character> const newimg, the new image
- * @param int lines, lines count of newimg
- * @param int columns, columns count of newimg
- */
- virtual void setImage( QArray<Character> const newimg, int lines, int colums ) = 0;
-
- /**
- * annoy the user
- */
- void bell();
-
- /**
- * @return int m_lines, the lines count
- */
- int lines() { return m_lines; }
-
- /**
- * @return int m_columns, the columns count
- */
- int columns() { return m_columns; }
-
- /**
- * insert current selection (currently this is only the clipboard)
- */
- void insertSelection();
-
- /**
- * insert text
- * @param QString text, the text to be inserted
- */
- void insertText( QString text );
-
- /**
- * set selection (clipboard) to text
- * @param const QString &text, the text to be selected
- */
- void setSelection( const QString &text );
-
- /**
- * paste content of clipboard
- */
- void pasteClipboard();
-
-
- /**
- * reload configuration
- * @param const Profile& config, the config to be used (may be the same as in constructor)
- */
- virtual void reloadConfig( const Profile& config ) = 0;
-
-
- /**
- * sets the scrollbar (if implemented by successor of this class)
- */
- virtual void setScroll( int cursor, int slines ) = 0;
-
- /**
- * scrolls (if implemented, by successor of this class)
- * @param int value, how much the widget should scroll up (positive value) or down (negative value)
- */
- virtual void scroll( int value ) = 0;
-
-
- virtual bool eventFilter( QObject *obj, QEvent *event );
-
-
- QSize sizeHint();
-
- virtual QSize calcSize( int cols, int lins ) const = 0;
-signals:
-
- /**
- * key was pressed
- */
- void keyPressed( QKeyEvent *e );
-
- /**
- * whenever Mouse selects something
- * @param int button, the button that us pressed :
- * 0 left Button
- * 3 Button released
- * @param int x, x position
- * @param int y, y position
- *
- * // numbering due to layout in old TEWidget
- */
- void mousePressed( int button, int x, int y );
-
- /**
- * size of image changed
- * @param int lines, line count of new size
- * @param int columns, column count of new size
- */
- void imageSizeChanged( int lines, int columns );
-
- /**
- * cursor in history changed
- * @param int value, value of history cursor
- */
- void historyCursorChanged( int value );
-
- /**
- * selection should be cleared
- */
- void selectionCleared();
-
- /**
- * selection begin
- * @param const int x, x position
- * @param const int y, y position
- */
- void selectionBegin( const int x, const int y );
-
- /**
- * selection extended
- * (from begin (s.a.) to x, y)
- * @param const int x, x position
- * @param const int y, y position
- */
- void selectionExtended( const int x, const int y );
-
- /**
- * selection end
- * @param const bool lineBreakPreserve, preserve line breaks in selection
- */
- void selectionEnd( const bool lineBreakPreserve );
-
-
-
-// protected methods
-protected:
-
- // image operations
-
- /**
- * changes image, to suit new size
- * TODO: find meaningful name!
- */
- void propagateSize();
-
- /**
- *determines count of lines and columns
- */
- virtual void calcGeometry() = 0;
-
- /**
- * makes an empty image
- */
- void makeImage();
-
- /**
- * clears the image
- */
- void clearImage();
-
-protected slots:
-
- /**
- * clear selection
- */
- void onClearSelection();
-
-
-// protected vars
-protected:
-
- /**
- * current Session
- */
- Session *m_session;
-
- /**
- * current character image
- *
- * a Character at loc( column, line )
- * has the actual index:
- * ix = line * m_columns + column;
- *
- * use loc( x, y ) macro to access.
- */
- QArray<Character> m_image;
-
- /**
- * lines count
- */
- int m_lines;
-
- /**
- * columns count
- */
- int m_columns;
-
- /**
- * clipboard
- */
- QClipboard* m_clipboard;
-
- /**
- * whether widget is resizing
- */
- bool m_resizing;
-};
-
-#endif // WIDGET_LAYER_H