-rw-r--r-- | noncore/apps/opie-console/MyPty.cpp | 299 | ||||
-rw-r--r-- | noncore/apps/opie-console/MyPty.h | 95 | ||||
-rw-r--r-- | noncore/apps/opie-console/default.cpp | 16 | ||||
-rw-r--r-- | noncore/apps/opie-console/default.h | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_handler.cpp | 89 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_handler.h | 8 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_layer.h | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/opie-console.pro | 6 |
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 | |||
98 | void 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 | |||
108 | void 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 | |||
124 | const char* MyPty::deviceName() | ||
125 | { | ||
126 | return m_ttynam; | ||
127 | } | ||
128 | |||
129 | |||
130 | void MyPty::error() | ||
131 | { | ||
132 | // This is code from the Qt DumbTerminal example | ||
133 | donePty(); | ||
134 | } | ||
135 | |||
136 | void 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 | */ | ||
145 | int 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 | |||
192 | int 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 | */ | ||
229 | MyPty::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 | */ | ||
239 | MyPty::~MyPty() | ||
240 | { | ||
241 | donePty(); | ||
242 | } | ||
243 | QString MyPty::identifier()const { | ||
244 | return QString::fromLatin1("term"); | ||
245 | } | ||
246 | QString MyPty::name()const{ | ||
247 | return identifier(); | ||
248 | } | ||
249 | bool MyPty::open() { | ||
250 | start(); | ||
251 | return true; | ||
252 | } | ||
253 | void MyPty::close() { | ||
254 | donePty(); | ||
255 | } | ||
256 | void MyPty::reload( const Profile& ) { | ||
257 | |||
258 | } | ||
259 | /*! sends len bytes through the line */ | ||
260 | void 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 */ | ||
275 | void 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 | |||
30 | class Profile; | ||
31 | class MyPty : public IOLayer | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | public: | ||
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 | |||
77 | private: | ||
78 | const char* deviceName(); | ||
79 | |||
80 | protected slots: | ||
81 | void readPty(); | ||
82 | void donePty(); | ||
83 | |||
84 | private: | ||
85 | int openPty(); | ||
86 | |||
87 | private: | ||
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 | |||
@@ -9,7 +9,7 @@ | |||
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 | ||
@@ -49,6 +49,9 @@ extern "C" { | |||
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 ) { |
@@ -63,13 +66,16 @@ extern "C" { | |||
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 ); |
@@ -90,13 +96,15 @@ Default::Default( MetaFactory* fact ) { | |||
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 | } |
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 | |||
@@ -17,12 +17,14 @@ extern "C" { | |||
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 | }; |
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 | |||
@@ -3,6 +3,7 @@ | |||
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 | ||
@@ -29,11 +30,11 @@ EmulationHandler::~EmulationHandler() { | |||
29 | delete m_teEmu; | 30 | delete m_teEmu; |
30 | delete m_teWid; | 31 | delete m_teWid; |
31 | } | 32 | } |
32 | void EmulationHandler::load( const Profile& ) { | 33 | void 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 | } |
38 | void EmulationHandler::recv( const QByteArray& ar) { | 39 | void EmulationHandler::recv( const QByteArray& ar) { |
39 | qWarning("received in EmulationHandler!"); | 40 | qWarning("received in EmulationHandler!"); |
@@ -50,3 +51,81 @@ void EmulationHandler::recvEmulation(const char* src, int len ) { | |||
50 | QWidget* EmulationHandler::widget() { | 51 | QWidget* EmulationHandler::widget() { |
51 | return m_teWid; | 52 | return m_teWid; |
52 | } | 53 | } |
54 | /* | ||
55 | * allocate a new table of colors | ||
56 | */ | ||
57 | void 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 | } | ||
74 | QFont 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 | } | ||
96 | QColor 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 | } | ||
114 | QColor 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 | |||
@@ -2,6 +2,7 @@ | |||
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 | /* |
@@ -26,6 +27,7 @@ class Profile; | |||
26 | class QWidget; | 27 | class QWidget; |
27 | class TEWidget; | 28 | class TEWidget; |
28 | class TEmulation; | 29 | class TEmulation; |
30 | class QFont; | ||
29 | class EmulationHandler : public QObject { | 31 | class EmulationHandler : public QObject { |
30 | Q_OBJECT | 32 | Q_OBJECT |
31 | public: | 33 | public: |
@@ -43,15 +45,21 @@ public: | |||
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 ); | ||
46 | signals: | 49 | signals: |
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 | |||
50 | public slots: | 54 | public slots: |
51 | void recv( const QByteArray& ); | 55 | void recv( const QByteArray& ); |
52 | 56 | ||
53 | private slots: | 57 | private slots: |
54 | void recvEmulation( const char*, int len ); | 58 | void recvEmulation( const char*, int len ); |
59 | private: | ||
60 | QFont font( int ); | ||
61 | QColor foreColor(int ); | ||
62 | QColor backColor(int ); | ||
55 | 63 | ||
56 | private: | 64 | private: |
57 | TEWidget* m_teWid; | 65 | TEWidget* m_teWid; |
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 | |||
@@ -70,14 +70,14 @@ signals: | |||
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 | ||
82 | public slots: | 82 | public slots: |
83 | /** | 83 | /** |
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 | |||
@@ -27,9 +27,10 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h io_modem.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 | ||
34 | SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \ | 35 | SOURCES = 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 \ |
@@ -55,9 +56,10 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.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 | ||
63 | INTERFACES = configurebase.ui editbase.ui | 65 | INTERFACES = configurebase.ui editbase.ui |