summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-14 22:58:11 (UTC)
committer zecke <zecke>2002-10-14 22:58:11 (UTC)
commitd7290c6b24266303abd95e7f38c0fecae395f355 (patch) (unidiff)
treef8202b056d9ae8de1cfa818de60ff2929c520f90
parentf5d1ce4b3887e0f09704abad5b9414c9cd90be4b (diff)
downloadopie-d7290c6b24266303abd95e7f38c0fecae395f355.zip
opie-d7290c6b24266303abd95e7f38c0fecae395f355.tar.gz
opie-d7290c6b24266303abd95e7f38c0fecae395f355.tar.bz2
A small console emulation layer...
And some configuration stuff fonts are working colors are not fully working BackGround and ForeGround both are black :(
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/MyPty.cpp299
-rw-r--r--noncore/apps/opie-console/MyPty.h95
-rw-r--r--noncore/apps/opie-console/default.cpp16
-rw-r--r--noncore/apps/opie-console/default.h4
-rw-r--r--noncore/apps/opie-console/emulation_handler.cpp89
-rw-r--r--noncore/apps/opie-console/emulation_handler.h8
-rw-r--r--noncore/apps/opie-console/io_layer.h4
-rw-r--r--noncore/apps/opie-console/opie-console.pro6
8 files changed, 507 insertions, 14 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp
new file mode 100644
index 0000000..10828b0
--- a/dev/null
+++ b/noncore/apps/opie-console/MyPty.cpp
@@ -0,0 +1,299 @@
1/* -------------------------------------------------------------------------- */
2/* */
3/* [MyPty.C] Pseudo Terminal Device */
4/* */
5/* -------------------------------------------------------------------------- */
6/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */
9/* This file is part of Konsole - an X terminal for KDE */
10/* -------------------------------------------------------------------------- */
11 /* */
12/* Ported Konsole to Qt/Embedded */
13 /* */
14/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
15 /* */
16/* -------------------------------------------------------------------------- */
17
18/* If you're compiling konsole on non-Linux platforms and find
19 problems that you can track down to this file, please have
20 a look into ../README.ports, too.
21*/
22
23/*! \file
24*/
25
26/*! \class TEPty
27
28 \brief Ptys provide a pseudo terminal connection to a program.
29
30 Although closely related to pipes, these pseudo terminal connections have
31 some ability, that makes it nessesary to uses them. Most importent, they
32 know about changing screen sizes and UNIX job control.
33
34 Within the terminal emulation framework, this class represents the
35 host side of the terminal together with the connecting serial line.
36
37 One can create many instances of this class within a program.
38 As a side effect of using this class, a signal(2) handler is
39 installed on SIGCHLD.
40
41 \par FIXME
42
43 [NOTE: much of the technical stuff below will be replaced by forkpty.]
44
45 publish the SIGCHLD signal if not related to an instance.
46
47 clearify TEPty::done vs. TEPty::~TEPty semantics.
48 check if pty is restartable via run after done.
49
50 \par Pseudo terminals
51
52 Pseudo terminals are a unique feature of UNIX, and always come in form of
53 pairs of devices (/dev/ptyXX and /dev/ttyXX), which are connected to each
54 other by the operating system. One may think of them as two serial devices
55 linked by a null-modem cable. Being based on devices the number of
56 simultanous instances of this class is (globally) limited by the number of
57 those device pairs, which is 256.
58
59 Another technic are UNIX 98 PTY's. These are supported also, and prefered
60 over the (obsolete) predecessor.
61
62 There's a sinister ioctl(2), signal(2) and job control stuff
63 nessesary to make everything work as it should.
64*/
65
66
67#include <qapplication.h>
68#include <qsocketnotifier.h>
69#include <qstring.h>
70
71#include <stdlib.h>
72#include <stdio.h>
73#include <signal.h>
74#include <fcntl.h>
75#include <unistd.h>
76#include <termios.h>
77#include <sys/types.h>
78#include <sys/ioctl.h>
79#include <sys/wait.h>
80
81#ifdef HAVE_OPENPTY
82#include <pty.h>
83#endif
84
85#include "MyPty.h"
86
87
88#undef VERBOSE_DEBUG
89
90
91/* -------------------------------------------------------------------------- */
92
93/*!
94 Informs the client program about the
95 actual size of the window.
96*/
97
98void MyPty::setSize(int lines, int columns)
99{
100 struct winsize wsize;
101 wsize.ws_row = (unsigned short)lines;
102 wsize.ws_col = (unsigned short)columns;
103 if(m_fd < 0) return;
104 ioctl(m_fd,TIOCSWINSZ,(char *)&wsize);
105}
106
107
108void MyPty::donePty()
109{
110 // This is code from the Qt DumbTerminal example
111 int status = 0;
112
113 ::close(m_fd);
114
115 if (m_cpid) {
116 kill(m_cpid, SIGHUP);
117 waitpid(m_cpid, &status, 0);
118 }
119
120 emit done(status);
121}
122
123
124const char* MyPty::deviceName()
125{
126 return m_ttynam;
127}
128
129
130void MyPty::error()
131{
132 // This is code from the Qt DumbTerminal example
133 donePty();
134}
135
136void MyPty::start() {
137 char* cmd = "/bin/sh";
138 QStrList lis;
139 int r =run(cmd, lis, 0, 0);
140 r = r;
141}
142/*!
143 start the client program.
144*/
145int MyPty::run(const char* cmd, QStrList &, const char*, int)
146{
147 // This is code from the Qt DumbTerminal example
148 m_cpid = fork();
149
150 if ( !m_cpid ) {
151 // child - exec shell on tty
152 for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL);
153 int ttyfd = ::open(m_ttynam, O_RDWR);
154 dup2(ttyfd, STDIN_FILENO);
155 dup2(ttyfd, STDOUT_FILENO);
156 dup2(ttyfd, STDERR_FILENO);
157 // should be done with tty, so close it
158 ::close(ttyfd);
159 static struct termios ttmode;
160 if ( setsid() < 0 )
161 perror( "failed to set process group" );
162#if defined (TIOCSCTTY)
163 // grabbed from APUE by Stevens
164 ioctl(STDIN_FILENO, TIOCSCTTY, 0);
165#endif
166 tcgetattr( STDIN_FILENO, &ttmode );
167 ttmode.c_cc[VINTR] = 3;
168 ttmode.c_cc[VERASE] = 8;
169 tcsetattr( STDIN_FILENO, TCSANOW, &ttmode );
170 setenv("TERM","vt100",1);
171 setenv("COLORTERM","0",1);
172
173 if (getuid() == 0) {
174 char msg[] = "WARNING: You are running this shell as root!\n";
175 write(ttyfd, msg, sizeof(msg));
176 }
177 execl(cmd, cmd, 0);
178
179 donePty();
180 exit(-1);
181 }
182
183 // parent - continue as a widget
184 QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
185 QSocketNotifier* sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this);
186 connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
187 connect(sn_e,SIGNAL(activated(int)),this,SLOT(error()));
188
189 return 0;
190}
191
192int MyPty::openPty()
193{
194 // This is code from the Qt DumbTerminal example
195 int ptyfd = -1;
196
197#ifdef HAVE_OPENPTY
198 int ttyfd;
199 if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) )
200 ptyfd = -1;
201 else
202 close(ttyfd); // we open the ttynam ourselves.
203#else
204 for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) {
205 for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) {
206 sprintf(m_ptynam,"/dev/pty%c%c",*c0,*c1);
207 sprintf(m_ttynam,"/dev/tty%c%c",*c0,*c1);
208 if ((ptyfd = ::open(m_ptynam,O_RDWR)) >= 0) {
209 if (geteuid() != 0 && !access(m_ttynam,R_OK|W_OK) == 0) {
210 ::close(ptyfd);
211 ptyfd = -1;
212 }
213 }
214 }
215 }
216#endif
217
218 if ( ptyfd < 0 ) {
219 qApp->exit(1);
220 return -1;
221 }
222
223 return ptyfd;
224}
225
226/*!
227 Create an instance.
228*/
229MyPty::MyPty(const Profile&) : m_cpid(0)
230{
231 m_fd = openPty();
232}
233
234/*!
235 Destructor.
236 Note that the related client program is not killed
237 (yet) when a instance is deleted.
238*/
239MyPty::~MyPty()
240{
241 donePty();
242}
243QString MyPty::identifier()const {
244 return QString::fromLatin1("term");
245}
246QString MyPty::name()const{
247 return identifier();
248}
249bool MyPty::open() {
250 start();
251 return true;
252}
253void MyPty::close() {
254 donePty();
255}
256void MyPty::reload( const Profile& ) {
257
258}
259/*! sends len bytes through the line */
260void MyPty::send(const QByteArray& ar)
261{
262
263#ifdef VERBOSE_DEBUG
264 // verbose debug
265 printf("sending bytes:\n");
266 for (uint i = 0; i < ar.count(); i++)
267 printf("%c", ar[i]);
268 printf("\n");
269#endif
270
271 ::write(m_fd, ar.data(), ar.count());
272}
273
274/*! indicates that a block of data is received */
275void MyPty::readPty()
276{
277 QByteArray buf(4096);
278
279 int len = ::read( m_fd, buf.data(), 4096 );
280
281 if (len == -1)
282 donePty();
283
284 if (len < 0)
285 return;
286
287 buf.resize(len);
288 emit received(buf);
289
290#ifdef VERBOSE_DEBUG
291 // verbose debug
292 printf("read bytes:\n");
293 for (uint i = 0; i < buf.count(); i++)
294 printf("%c", buf[i]);
295 printf("\n");
296#endif
297
298}
299
diff --git a/noncore/apps/opie-console/MyPty.h b/noncore/apps/opie-console/MyPty.h
new file mode 100644
index 0000000..9231a8a
--- a/dev/null
+++ b/noncore/apps/opie-console/MyPty.h
@@ -0,0 +1,95 @@
1/* -------------------------------------------------------------------------- */
2/* */
3/* [MyPty.h] Pseudo Terminal Device */
4/* */
5/* -------------------------------------------------------------------------- */
6/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */
9/* This file is part of Konsole - an X terminal for KDE */
10/* */
11/* -------------------------------------------------------------------------- */
12 /* */
13/* Ported Konsole to Qt/Embedded */
14 /* */
15/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
16 /* */
17/* -------------------------------------------------------------------------- */
18
19/*! \file
20*/
21
22#ifndef MY_PTY_H
23#define MY_PTY_H
24
25#include <qobject.h>
26#include <qstrlist.h>
27
28#include "io_layer.h"
29
30class Profile;
31class MyPty : public IOLayer
32{
33 Q_OBJECT
34public:
35
36 MyPty(const Profile&);
37 ~MyPty();
38
39
40
41 QString identifier()const;
42 QString name()const;
43
44 public slots:
45 /*!
46 having a `run' separate from the constructor allows to make
47 the necessary connections to the signals and slots of the
48 instance before starting the execution of the client.
49 */
50 void start();
51 int run(const char* pgm, QStrList & args , const char* term, int addutmp);
52 bool open();
53 void close();
54 void reload( const Profile& );
55 void setSize(int lines, int columns);
56 void error();
57
58 signals:
59
60 /*!
61 emitted when the client program terminates.
62 \param status the wait(2) status code of the terminated client program.
63 */
64 void done(int status);
65
66 /*!
67 emitted when a new block of data comes in.
68 \param s - the data
69 \param len - the length of the block
70 */
71 void received(const QByteArray&);
72
73 public slots:
74
75 void send(const QByteArray& );
76
77private:
78 const char* deviceName();
79
80protected slots:
81 void readPty();
82 void donePty();
83
84private:
85 int openPty();
86
87private:
88
89 char m_ptynam[16]; // "/dev/ptyxx" | "/dev/ptmx"
90 char m_ttynam[16]; // "/dev/ttyxx" | "/dev/pts/########..."
91 int m_fd;
92 int m_cpid;
93};
94
95#endif
diff --git a/noncore/apps/opie-console/default.cpp b/noncore/apps/opie-console/default.cpp
index 5c1c05a..64c9542 100644
--- a/noncore/apps/opie-console/default.cpp
+++ b/noncore/apps/opie-console/default.cpp
@@ -4,17 +4,17 @@
4#include "io_modem.h" 4#include "io_modem.h"
5#include "filetransfer.h" 5#include "filetransfer.h"
6#include "filereceive.h" 6#include "filereceive.h"
7#include "serialconfigwidget.h" 7#include "serialconfigwidget.h"
8#include "irdaconfigwidget.h" 8#include "irdaconfigwidget.h"
9#include "btconfigwidget.h" 9#include "btconfigwidget.h"
10#include "modemconfigwidget.h" 10#include "modemconfigwidget.h"
11#include "terminalwidget.h" 11#include "terminalwidget.h"
12#include "vt102emulation.h" 12#include "MyPty.h"
13 13
14#include "default.h" 14#include "default.h"
15 15
16extern "C" { 16extern "C" {
17 // FILE Transfer Stuff 17 // FILE Transfer Stuff
18 FileTransferLayer* newSZTransfer(IOLayer* lay) { 18 FileTransferLayer* newSZTransfer(IOLayer* lay) {
19 return new FileTransfer( FileTransfer::SZ, lay ); 19 return new FileTransfer( FileTransfer::SZ, lay );
20 } 20 }
@@ -44,37 +44,43 @@ extern "C" {
44 return new IOBt( prof ); 44 return new IOBt( prof );
45 } 45 }
46 IOLayer* newIrDaLayer( const Profile& prof ) { 46 IOLayer* newIrDaLayer( const Profile& prof ) {
47 return new IOIrda( prof ); 47 return new IOIrda( prof );
48 } 48 }
49 IOLayer* newModemLayer( const Profile& prof ) { 49 IOLayer* newModemLayer( const Profile& prof ) {
50 return new IOModem( prof ); 50 return new IOModem( prof );
51 } 51 }
52 IOLayer* newConsole( const Profile& prof ) {
53 return new MyPty(prof );
54 }
52 55
53 // Connection Widgets 56 // Connection Widgets
54 ProfileDialogWidget* newSerialWidget( const QString& str, QWidget* wid ) { 57 ProfileDialogWidget* newSerialWidget( const QString& str, QWidget* wid ) {
55 return new SerialConfigWidget( str, wid ); 58 return new SerialConfigWidget( str, wid );
56 } 59 }
57 ProfileDialogWidget* newIrDaWidget( const QString& str, QWidget* wid ) { 60 ProfileDialogWidget* newIrDaWidget( const QString& str, QWidget* wid ) {
58 return new IrdaConfigWidget( str, wid ); 61 return new IrdaConfigWidget( str, wid );
59 } 62 }
60 ProfileDialogWidget* newModemWidget( const QString& str, QWidget* wid ) { 63 ProfileDialogWidget* newModemWidget( const QString& str, QWidget* wid ) {
61 return new ModemConfigWidget(str, wid ); 64 return new ModemConfigWidget(str, wid );
62 } 65 }
63 ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) { 66 ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) {
64 return new BTConfigWidget(str, wid ); 67 return new BTConfigWidget(str, wid );
65 } 68 }
69 ProfileDialogWidget* newConsoleWid( const QString& str, QWidget* wid ) {
70 return 0l;
71 }
66 72
67 73
68 // Terminal Widget(s) 74 // Terminal Widget(s)
69/* ProfileDialogWidget* newTerminalWidget(const QString& na, QWidget* wid) { 75 ProfileDialogWidget* newTerminalWidget(const QString& na, QWidget* wid) {
70 return new TerminalWidget(na, wid,0 ); 76 return new TerminalWidget(na, wid,0 );
71 } 77 }
72*/ 78
73/* // VT Emulations 79/* // VT Emulations
74 EmulationLayer* newVT102( WidgetLayer* wid ) { 80 EmulationLayer* newVT102( WidgetLayer* wid ) {
75 return new Vt102Emulation( wid ); 81 return new Vt102Emulation( wid );
76 } 82 }
77*/ 83*/
78}; 84};
79 85
80Default::Default( MetaFactory* fact ) { 86Default::Default( MetaFactory* fact ) {
@@ -85,21 +91,23 @@ Default::Default( MetaFactory* fact ) {
85 fact->addReceiveLayer( "SZ", QObject::tr("Z-Modem"), newSZReceive ); 91 fact->addReceiveLayer( "SZ", QObject::tr("Z-Modem"), newSZReceive );
86 fact->addReceiveLayer( "SY", QObject::tr("Y-Modem"), newSYReceive ); 92 fact->addReceiveLayer( "SY", QObject::tr("Y-Modem"), newSYReceive );
87 fact->addReceiveLayer( "SX", QObject::tr("X-Modem"), newSXReceive ); 93 fact->addReceiveLayer( "SX", QObject::tr("X-Modem"), newSXReceive );
88 94
89 fact->addIOLayerFactory( "serial", QObject::tr("Serial"), newSerialLayer ); 95 fact->addIOLayerFactory( "serial", QObject::tr("Serial"), newSerialLayer );
90 fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer ); 96 fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer );
91 fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer ); 97 fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer );
92 fact->addIOLayerFactory( "modem", QObject::tr("Modem"), newModemLayer ); 98 fact->addIOLayerFactory( "modem", QObject::tr("Modem"), newModemLayer );
99 fact->addIOLayerFactory( "console", QObject::tr("Console"), newConsole );
93 100
94 fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget ); 101 fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget );
95 fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget ); 102 fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget );
96 fact->addConnectionWidgetFactory( "modem", QObject::tr("Modem"), newModemWidget ); 103 fact->addConnectionWidgetFactory( "modem", QObject::tr("Modem"), newModemWidget );
97 fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget ); 104 fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget );
105 fact->addConnectionWidgetFactory( "console", QObject::tr("Console"), newConsoleWid );
98 106
99// fact->addTerminalWidgetFactory( "default", QObject::tr("Default Terminal"), newTerminalWidget ); 107 fact->addTerminalWidgetFactory( "default", QObject::tr("Default Terminal"), newTerminalWidget );
100 108
101// fact->addEmulationLayer( "default", QObject::tr("Default Terminal"), newVT102 ); 109// fact->addEmulationLayer( "default", QObject::tr("Default Terminal"), newVT102 );
102} 110}
103Default::~Default() { 111Default::~Default() {
104 112
105} 113}
diff --git a/noncore/apps/opie-console/default.h b/noncore/apps/opie-console/default.h
index 288f370..b8cda03 100644
--- a/noncore/apps/opie-console/default.h
+++ b/noncore/apps/opie-console/default.h
@@ -12,22 +12,24 @@ extern "C" {
12 12
13 ReceiveLayer* newSZReceive(IOLayer*); 13 ReceiveLayer* newSZReceive(IOLayer*);
14 ReceiveLayer* newSYReceive(IOLayer*); 14 ReceiveLayer* newSYReceive(IOLayer*);
15 ReceiveLayer* newSXReceive(IOLayer*); 15 ReceiveLayer* newSXReceive(IOLayer*);
16 16
17 IOLayer* newSerialLayer(const Profile&); 17 IOLayer* newSerialLayer(const Profile&);
18 IOLayer* newBTLayer(const Profile& ); 18 IOLayer* newBTLayer(const Profile& );
19 IOLayer* newIrDaLayer(const Profile& ); 19 IOLayer* newIrDaLayer(const Profile& );
20 IOLayer* newConsole(const Profile& );
20 21
21 ProfileDialogWidget* newSerialWidget(const QString&, QWidget* ); 22 ProfileDialogWidget* newSerialWidget(const QString&, QWidget* );
22 ProfileDialogWidget* newIrDaWidget (const QString&, QWidget* ); 23 ProfileDialogWidget* newIrDaWidget (const QString&, QWidget* );
23 ProfileDialogWidget* newBTWidget (const QString&, QWidget* ); 24 ProfileDialogWidget* newBTWidget (const QString&, QWidget* );
25 ProfileDialogWidget* newConsoleWid (const QString&, QWidget* );
24 26
25// ProfileDialogWidget* newTerminalWidget(const QString&, QWidget* ); 27 ProfileDialogWidget* newTerminalWidget(const QString&, QWidget* );
26 28
27// EmulationLayer* newVT102( WidgetLayer* ); 29// EmulationLayer* newVT102( WidgetLayer* );
28}; 30};
29 31
30class MetaFactory; 32class MetaFactory;
31struct Default { 33struct Default {
32public: 34public:
33 Default(MetaFactory* ); 35 Default(MetaFactory* );
diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp
index 9e7f56c..48218e6 100644
--- a/noncore/apps/opie-console/emulation_handler.cpp
+++ b/noncore/apps/opie-console/emulation_handler.cpp
@@ -1,13 +1,14 @@
1#include <qwidget.h> 1#include <qwidget.h>
2 2
3#include "TEWidget.h" 3#include "TEWidget.h"
4#include "TEmuVt102.h" 4#include "TEmuVt102.h"
5 5
6#include "profile.h"
6#include "emulation_handler.h" 7#include "emulation_handler.h"
7 8
8 9
9EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) 10EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name )
10 : QObject(0, name ) 11 : QObject(0, name )
11{ 12{
12 m_teWid = new TEWidget( parent, "TerminalMain"); 13 m_teWid = new TEWidget( parent, "TerminalMain");
13 m_teWid->setMinimumSize(150, 70 ); 14 m_teWid->setMinimumSize(150, 70 );
@@ -24,29 +25,107 @@ EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const c
24 25
25 26
26 27
27} 28}
28EmulationHandler::~EmulationHandler() { 29EmulationHandler::~EmulationHandler() {
29 delete m_teEmu; 30 delete m_teEmu;
30 delete m_teWid; 31 delete m_teWid;
31} 32}
32void EmulationHandler::load( const Profile& ) { 33void EmulationHandler::load( const Profile& prof) {
33 QFont font = QFont("Fixed", 12, QFont::Normal ); 34 m_teWid->setVTFont( font( prof.readNumEntry("Font") ) );
34 font.setFixedPitch(TRUE); 35 int num = prof.readNumEntry("Color");
35 m_teWid->setVTFont( font ); 36 setColor( foreColor(num), backColor(num) );
36 m_teWid->setBackgroundColor(Qt::gray ); 37 m_teWid->setBackgroundColor(backColor(num) );
37} 38}
38void EmulationHandler::recv( const QByteArray& ar) { 39void EmulationHandler::recv( const QByteArray& ar) {
39 qWarning("received in EmulationHandler!"); 40 qWarning("received in EmulationHandler!");
40 m_teEmu->onRcvBlock(ar.data(), ar.count() ); 41 m_teEmu->onRcvBlock(ar.data(), ar.count() );
41} 42}
42void EmulationHandler::recvEmulation(const char* src, int len ) { 43void EmulationHandler::recvEmulation(const char* src, int len ) {
43 qWarning("received from te "); 44 qWarning("received from te ");
44 QByteArray ar(len); 45 QByteArray ar(len);
45 46
46 memcpy(ar.data(), src, sizeof(char) * len ); 47 memcpy(ar.data(), src, sizeof(char) * len );
47 48
48 emit send(ar); 49 emit send(ar);
49} 50}
50QWidget* EmulationHandler::widget() { 51QWidget* EmulationHandler::widget() {
51 return m_teWid; 52 return m_teWid;
52} 53}
54/*
55 * allocate a new table of colors
56 */
57void EmulationHandler::setColor( const QColor& fore, const QColor& back ) {
58 ColorEntry table[TABLE_COLORS];
59 const ColorEntry *defaultCt = m_teWid->getdefaultColorTable();
60
61 for (int i = 0; i < TABLE_COLORS; i++ ) {
62 if ( i == 0 || i == 10 ) {
63 table[i].color = fore;
64 }else if ( i == 1 || i == 11 ) {
65 table[i].color = back;
66 table[i].transparent = 0;
67 }else {
68 table[i].color = defaultCt[i].color;
69 }
70 }
71// m_teWid->setColorTable(table );
72 m_teWid->update();
73}
74QFont EmulationHandler::font( int id ) {
75 QString name;
76 int size = 0;
77 switch(id ) {
78 default: // fall through
79 case 0:
80 name = QString::fromLatin1("Micro");
81 size = 4;
82 break;
83 case 1:
84 name = QString::fromLatin1("Fixed");
85 size = 7;
86 break;
87 case 2:
88 name = QString::fromLatin1("Fixed");
89 size = 12;
90 break;
91 }
92 QFont font(name, size, QFont::Normal );
93 font.setFixedPitch(TRUE );
94 return font;
95}
96QColor EmulationHandler::foreColor(int col) {
97 QColor co;
98 /* we need to switch it */
99 switch( col ) {
100 default:
101 case Profile::White:
102 qWarning("Foreground black");
103 /* color is black */
104 co = Qt::black;
105 break;
106 case Profile::Black:
107 qWarning("Foreground white");
108 co = Qt::white;
109 break;
110 }
111
112 return co;
113}
114QColor EmulationHandler::backColor(int col ) {
115 QColor co;
116 /* we need to switch it */
117 switch( col ) {
118 default:
119 case Profile::White:
120 qWarning("Background white");
121 /* color is white */
122 co = Qt::white;
123 break;
124 case Profile::Black:
125 qWarning("Background black");
126 co = Qt::black;
127 break;
128 }
129
130 return co;
131}
diff --git a/noncore/apps/opie-console/emulation_handler.h b/noncore/apps/opie-console/emulation_handler.h
index 58b94bc..9af7680 100644
--- a/noncore/apps/opie-console/emulation_handler.h
+++ b/noncore/apps/opie-console/emulation_handler.h
@@ -1,12 +1,13 @@
1#ifndef OPIE_EMULATION_HANDLER_H 1#ifndef OPIE_EMULATION_HANDLER_H
2#define OPIE_EMULATION_HANDLER_H 2#define OPIE_EMULATION_HANDLER_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qcolor.h>
5#include <qcstring.h> 6#include <qcstring.h>
6 7
7/* 8/*
8 * Badly ibotty lacks the time to finish 9 * Badly ibotty lacks the time to finish
9 * his widget in time.. 10 * his widget in time..
10 * Never the less we've to have an EmulationWidget 11 * Never the less we've to have an EmulationWidget
11 * This is why I'm taking the inferior not cleaned 12 * This is why I'm taking the inferior not cleaned
12 * up TE* KDE STUFF 13 * up TE* KDE STUFF
@@ -21,16 +22,17 @@
21 * it'll set up the widget internally 22 * it'll set up the widget internally
22 * and manage the communication between 23 * and manage the communication between
23 * the pre QByteArray world! 24 * the pre QByteArray world!
24 */ 25 */
25class Profile; 26class Profile;
26class QWidget; 27class QWidget;
27class TEWidget; 28class TEWidget;
28class TEmulation; 29class TEmulation;
30class QFont;
29class EmulationHandler : public QObject { 31class EmulationHandler : public QObject {
30 Q_OBJECT 32 Q_OBJECT
31public: 33public:
32 /** 34 /**
33 * simple c'tor the parent of the TEWdiget 35 * simple c'tor the parent of the TEWdiget
34 * and a name 36 * and a name
35 * and a Profile 37 * and a Profile
36 */ 38 */
@@ -38,25 +40,31 @@ public:
38 40
39 /** 41 /**
40 * delete all components 42 * delete all components
41 */ 43 */
42 ~EmulationHandler(); 44 ~EmulationHandler();
43 45
44 void load( const Profile& ); 46 void load( const Profile& );
45 QWidget* widget(); 47 QWidget* widget();
48 void setColor( const QColor& fore, const QColor& back );
46signals: 49signals:
47 void send( const QByteArray& ); 50 void send( const QByteArray& );
48 void changeSize(int rows, int cols ); 51 void changeSize(int rows, int cols );
49 52
53
50public slots: 54public slots:
51 void recv( const QByteArray& ); 55 void recv( const QByteArray& );
52 56
53private slots: 57private slots:
54 void recvEmulation( const char*, int len ); 58 void recvEmulation( const char*, int len );
59private:
60 QFont font( int );
61 QColor foreColor(int );
62 QColor backColor(int );
55 63
56private: 64private:
57 TEWidget* m_teWid; 65 TEWidget* m_teWid;
58 TEmulation* m_teEmu; 66 TEmulation* m_teEmu;
59 67
60}; 68};
61 69
62#endif 70#endif
diff --git a/noncore/apps/opie-console/io_layer.h b/noncore/apps/opie-console/io_layer.h
index 9c99222..5f2fa3c 100644
--- a/noncore/apps/opie-console/io_layer.h
+++ b/noncore/apps/opie-console/io_layer.h
@@ -65,24 +65,24 @@ public:
65 */ 65 */
66 virtual void closeRawIO(int); 66 virtual void closeRawIO(int);
67 67
68 68
69signals: 69signals:
70 /** 70 /**
71 * received input as QCString 71 * received input as QCString
72 */ 72 */
73 virtual void received( const QByteArray& ) = 0; 73 virtual void received( const QByteArray& );
74 74
75 /** 75 /**
76 * an error occured 76 * an error occured
77 * int for the error number 77 * int for the error number
78 * and QString for a text 78 * and QString for a text
79 */ 79 */
80 virtual void error( int, const QString& ) = 0; 80 virtual void error( int, const QString& );
81 81
82public slots: 82public slots:
83 /** 83 /**
84 * send a QCString to the device 84 * send a QCString to the device
85 */ 85 */
86 virtual void send( const QByteArray& ) = 0; 86 virtual void send( const QByteArray& ) = 0;
87 87
88 /** 88 /**
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index 7990a64..c2fb558 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -22,19 +22,20 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h io_modem.h \
22 serialconfigwidget.h irdaconfigwidget.h \ 22 serialconfigwidget.h irdaconfigwidget.h \
23 btconfigwidget.h modemconfigwidget.h \ 23 btconfigwidget.h modemconfigwidget.h \
24 atconfigdialog.h dialdialog.h \ 24 atconfigdialog.h dialdialog.h \
25 procctl.h \ 25 procctl.h \
26 function_keyboard.h \ 26 function_keyboard.h \
27 receive_layer.h filereceive.h \ 27 receive_layer.h filereceive.h \
28 script.h \ 28 script.h \
29 dialer.h \ 29 dialer.h \
30 terminalwidget.h \
30 emulation_handler.h TECommon.h \ 31 emulation_handler.h TECommon.h \
31 TEHistroy.h TEScreen.h TEWidget.h \ 32 TEHistroy.h TEScreen.h TEWidget.h \
32 TEmuVt102.h TEmulation.h 33 TEmuVt102.h TEmulation.h MyPty.h
33 34
34SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \ 35SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \
35 file_layer.cpp filetransfer.cpp \ 36 file_layer.cpp filetransfer.cpp \
36 main.cpp \ 37 main.cpp \
37 metafactory.cpp \ 38 metafactory.cpp \
38 session.cpp \ 39 session.cpp \
39 mainwindow.cpp \ 40 mainwindow.cpp \
40 profile.cpp \ 41 profile.cpp \
@@ -50,19 +51,20 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \
50 serialconfigwidget.cpp irdaconfigwidget.cpp \ 51 serialconfigwidget.cpp irdaconfigwidget.cpp \
51 btconfigwidget.cpp modemconfigwidget.cpp \ 52 btconfigwidget.cpp modemconfigwidget.cpp \
52 atconfigdialog.cpp dialdialog.cpp \ 53 atconfigdialog.cpp dialdialog.cpp \
53 default.cpp procctl.cpp \ 54 default.cpp procctl.cpp \
54 function_keyboard.cpp \ 55 function_keyboard.cpp \
55 receive_layer.cpp filereceive.cpp \ 56 receive_layer.cpp filereceive.cpp \
56 script.cpp \ 57 script.cpp \
57 dialer.cpp \ 58 dialer.cpp \
59 terminalwidget.cpp \
58 emulation_handler.cpp TEHistory.cpp \ 60 emulation_handler.cpp TEHistory.cpp \
59 TEScreen.cpp TEWidget.cpp \ 61 TEScreen.cpp TEWidget.cpp \
60 TEmuVt102.cpp TEmulation.cpp 62 TEmuVt102.cpp TEmulation.cpp MyPty.cpp
61 63
62 64
63INTERFACES = configurebase.ui editbase.ui 65INTERFACES = configurebase.ui editbase.ui
64INCLUDEPATH += $(OPIEDIR)/include 66INCLUDEPATH += $(OPIEDIR)/include
65DEPENDPATH += $(OPIEDIR)/include 67DEPENDPATH += $(OPIEDIR)/include
66LIBS += -lqpe -lopie 68LIBS += -lqpe -lopie
67TARGET = opie-console 69TARGET = opie-console
68 70