summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/MyPty.cpp17
-rw-r--r--noncore/apps/opie-console/consoleconfigwidget.cpp11
-rw-r--r--noncore/apps/opie-console/profileeditordialog.cpp2
3 files changed, 25 insertions, 5 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp
index b0f0275..c3c58be 100644
--- a/noncore/apps/opie-console/MyPty.cpp
+++ b/noncore/apps/opie-console/MyPty.cpp
@@ -1,355 +1,370 @@
1/* -------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------- */
2/* */ 2/* */
3/* [MyPty.C] Pseudo Terminal Device */ 3/* [MyPty.C] Pseudo Terminal Device */
4/* */ 4/* */
5/* -------------------------------------------------------------------------- */ 5/* -------------------------------------------------------------------------- */
6/* */ 6/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */ 8/* */
9/* This file is part of Konsole - an X terminal for KDE */ 9/* This file is part of Konsole - an X terminal for KDE */
10/* -------------------------------------------------------------------------- */ 10/* -------------------------------------------------------------------------- */
11 /* */ 11 /* */
12/* Ported Konsole to Qt/Embedded */ 12/* Ported Konsole to Qt/Embedded */
13 /* */ 13 /* */
14/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 14/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
15 /* */ 15 /* */
16/* -------------------------------------------------------------------------- */ 16/* -------------------------------------------------------------------------- */
17 17
18/* If you're compiling konsole on non-Linux platforms and find 18/* If you're compiling konsole on non-Linux platforms and find
19 problems that you can track down to this file, please have 19 problems that you can track down to this file, please have
20 a look into ../README.ports, too. 20 a look into ../README.ports, too.
21*/ 21*/
22 22
23/*! \file 23/*! \file
24*/ 24*/
25 25
26/*! \class TEPty 26/*! \class TEPty
27 27
28 \brief Ptys provide a pseudo terminal connection to a program. 28 \brief Ptys provide a pseudo terminal connection to a program.
29 29
30 Although closely related to pipes, these pseudo terminal connections have 30 Although closely related to pipes, these pseudo terminal connections have
31 some ability, that makes it nessesary to uses them. Most importent, they 31 some ability, that makes it nessesary to uses them. Most importent, they
32 know about changing screen sizes and UNIX job control. 32 know about changing screen sizes and UNIX job control.
33 33
34 Within the terminal emulation framework, this class represents the 34 Within the terminal emulation framework, this class represents the
35 host side of the terminal together with the connecting serial line. 35 host side of the terminal together with the connecting serial line.
36 36
37 One can create many instances of this class within a program. 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 38 As a side effect of using this class, a signal(2) handler is
39 installed on SIGCHLD. 39 installed on SIGCHLD.
40 40
41 \par FIXME 41 \par FIXME
42 42
43 [NOTE: much of the technical stuff below will be replaced by forkpty.] 43 [NOTE: much of the technical stuff below will be replaced by forkpty.]
44 44
45 publish the SIGCHLD signal if not related to an instance. 45 publish the SIGCHLD signal if not related to an instance.
46 46
47 clearify TEPty::done vs. TEPty::~TEPty semantics. 47 clearify TEPty::done vs. TEPty::~TEPty semantics.
48 check if pty is restartable via run after done. 48 check if pty is restartable via run after done.
49 49
50 \par Pseudo terminals 50 \par Pseudo terminals
51 51
52 Pseudo terminals are a unique feature of UNIX, and always come in form of 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 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 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 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 56 simultanous instances of this class is (globally) limited by the number of
57 those device pairs, which is 256. 57 those device pairs, which is 256.
58 58
59 Another technic are UNIX 98 PTY's. These are supported also, and prefered 59 Another technic are UNIX 98 PTY's. These are supported also, and prefered
60 over the (obsolete) predecessor. 60 over the (obsolete) predecessor.
61 61
62 There's a sinister ioctl(2), signal(2) and job control stuff 62 There's a sinister ioctl(2), signal(2) and job control stuff
63 nessesary to make everything work as it should. 63 nessesary to make everything work as it should.
64*/ 64*/
65 65
66 66
67#include <qapplication.h> 67#include <qapplication.h>
68#include <qsocketnotifier.h> 68#include <qsocketnotifier.h>
69#include <qstring.h> 69#include <qstring.h>
70#include <qfile.h> 70#include <qfile.h>
71 71
72#include <stdlib.h> 72#include <stdlib.h>
73#include <stdio.h> 73#include <stdio.h>
74#include <signal.h> 74#include <signal.h>
75#include <fcntl.h> 75#include <fcntl.h>
76#include <unistd.h> 76#include <unistd.h>
77#include <termios.h> 77#include <termios.h>
78#include <sys/types.h> 78#include <sys/types.h>
79#include <sys/ioctl.h> 79#include <sys/ioctl.h>
80#include <sys/wait.h> 80#include <sys/wait.h>
81 81
82#ifdef HAVE_OPENPTY 82#ifdef HAVE_OPENPTY
83#include <pty.h> 83#include <pty.h>
84#endif 84#endif
85 85
86#include "procctl.h" 86#include "procctl.h"
87#include "MyPty.h" 87#include "MyPty.h"
88 88
89 89
90#undef VERBOSE_DEBUG 90#undef VERBOSE_DEBUG
91 91
92 92
93/* -------------------------------------------------------------------------- */ 93/* -------------------------------------------------------------------------- */
94 94
95/*! 95/*!
96 Informs the client program about the 96 Informs the client program about the
97 actual size of the window. 97 actual size of the window.
98*/ 98*/
99 99
100void MyPty::setSize(int lines, int columns) 100void MyPty::setSize(int lines, int columns)
101{ 101{
102 qWarning("setting size"); 102 qWarning("setting size");
103 struct winsize wsize; 103 struct winsize wsize;
104 wsize.ws_row = (unsigned short)lines; 104 wsize.ws_row = (unsigned short)lines;
105 wsize.ws_col = (unsigned short)columns; 105 wsize.ws_col = (unsigned short)columns;
106 if(m_fd < 0) return; 106 if(m_fd < 0) return;
107 ioctl(m_fd,TIOCSWINSZ,(char *)&wsize); 107 ioctl(m_fd,TIOCSWINSZ,(char *)&wsize);
108} 108}
109 109
110 110
111void MyPty::donePty() 111void MyPty::donePty()
112{ 112{
113 // This is code from the Qt DumbTerminal example 113 // This is code from the Qt DumbTerminal example
114 114
115 ::close(m_fd); 115 ::close(m_fd);
116 116
117 if (m_cpid) { 117 if (m_cpid) {
118 kill(m_cpid, SIGHUP); 118 kill(m_cpid, SIGHUP);
119 //waitpid(m_cpid, &status, 0); 119 //waitpid(m_cpid, &status, 0);
120 delete m_sn_e; 120 delete m_sn_e;
121 delete m_sn_r; 121 delete m_sn_r;
122 m_sn_e = 0l; 122 m_sn_e = 0l;
123 m_sn_r = 0l; 123 m_sn_r = 0l;
124 } 124 }
125 125
126 m_cpid = 0; 126 m_cpid = 0;
127 m_fd = -1; 127 m_fd = -1;
128// emit done(status); 128// emit done(status);
129} 129}
130 130
131 131
132const char* MyPty::deviceName() 132const char* MyPty::deviceName()
133{ 133{
134 return m_ttynam; 134 return m_ttynam;
135} 135}
136 136
137 137
138void MyPty::error() 138void MyPty::error()
139{ 139{
140 // This is code from the Qt DumbTerminal example 140 // This is code from the Qt DumbTerminal example
141 donePty(); 141 donePty();
142} 142}
143 143
144void MyPty::start() { 144void MyPty::start() {
145 QStrList lis; 145 QStrList lis;
146 int r =run(m_cmd.latin1(), lis, 0, 0); 146 int r =run(m_cmd.latin1(), lis, 0, 0);
147 r = r; 147 r = r;
148} 148}
149/*! 149/*!
150 start the client program. 150 start the client program.
151*/ 151*/
152int MyPty::run(const char* cmd, QStrList &, const char*, int) 152int MyPty::run(const char* cmd, QStrList &, const char*, int)
153{ 153{
154 // This is code from the Qt DumbTerminal example 154 // This is code from the Qt DumbTerminal example
155 m_cpid = fork(); 155 m_cpid = fork();
156 156
157 if ( !m_cpid ) { 157 if ( !m_cpid ) {
158 // child - exec shell on tty 158 // child - exec shell on tty
159 for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); 159 for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL);
160 int ttyfd = ::open(m_ttynam, O_RDWR); 160 int ttyfd = ::open(m_ttynam, O_RDWR);
161 dup2(ttyfd, STDIN_FILENO); 161 dup2(ttyfd, STDIN_FILENO);
162 dup2(ttyfd, STDOUT_FILENO); 162 dup2(ttyfd, STDOUT_FILENO);
163 dup2(ttyfd, STDERR_FILENO); 163 dup2(ttyfd, STDERR_FILENO);
164 // should be done with tty, so close it 164 // should be done with tty, so close it
165 ::close(ttyfd); 165 ::close(ttyfd);
166 static struct termios ttmode; 166 static struct termios ttmode;
167 if ( setsid() < 0 ) 167 if ( setsid() < 0 )
168 perror( "failed to set process group" ); 168 perror( "failed to set process group" );
169#if defined (TIOCSCTTY) 169#if defined (TIOCSCTTY)
170 // grabbed from APUE by Stevens 170 // grabbed from APUE by Stevens
171 ioctl(STDIN_FILENO, TIOCSCTTY, 0); 171 ioctl(STDIN_FILENO, TIOCSCTTY, 0);
172#endif 172#endif
173 tcgetattr( STDIN_FILENO, &ttmode ); 173 tcgetattr( STDIN_FILENO, &ttmode );
174 ttmode.c_cc[VINTR] = 3; 174 ttmode.c_cc[VINTR] = 3;
175 ttmode.c_cc[VERASE] = 8; 175 ttmode.c_cc[VERASE] = 8;
176 tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); 176 tcsetattr( STDIN_FILENO, TCSANOW, &ttmode );
177 setenv("TERM",m_term,1); 177 setenv("TERM",m_term,1);
178 setenv("COLORTERM","0",1); 178 setenv("COLORTERM","0",1);
179 EnvironmentMap::Iterator it; 179 EnvironmentMap::Iterator it;
180 for (it = m_env.begin(); it != m_env.end(); it++) { 180 for (it = m_env.begin(); it != m_env.end(); it++) {
181 setenv(it.key().latin1(), it.data().latin1(), 1); 181 setenv(it.key().latin1(), it.data().latin1(), 1);
182 } 182 }
183 if (getuid() == 0) { 183 if (getuid() == 0) {
184 char msg[] = "WARNING: You are running this shell as root!\n"; 184 char msg[] = "WARNING: You are running this shell as root!\n";
185 write(ttyfd, msg, sizeof(msg)); 185 write(ttyfd, msg, sizeof(msg));
186 } 186 }
187 execl(cmd, cmd, 0); 187 execl(cmd, cmd, 0);
188 188
189 donePty(); 189 donePty();
190 exit(-1); 190 exit(-1);
191 } 191 }
192 192
193 // parent - continue as a widget 193 // parent - continue as a widget
194 delete m_sn_r; 194 delete m_sn_r;
195 m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); 195 m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
196 delete m_sn_e; 196 delete m_sn_e;
197 m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); 197 m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this);
198 connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); 198 connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
199 connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error())); 199 connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error()));
200 200
201 return 0; 201 return 0;
202} 202}
203 203
204int MyPty::openPty() 204int MyPty::openPty()
205{ 205{
206 // This is code from the Qt DumbTerminal example 206 // This is code from the Qt DumbTerminal example
207 int ptyfd = -1; 207 int ptyfd = -1;
208 208
209#ifdef HAVE_OPENPTY 209#ifdef HAVE_OPENPTY
210 int ttyfd; 210 int ttyfd;
211 if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) 211 if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) )
212 ptyfd = -1; 212 ptyfd = -1;
213 else 213 else
214 close(ttyfd); // we open the ttynam ourselves. 214 close(ttyfd); // we open the ttynam ourselves.
215#else 215#else
216 for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) { 216 for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) {
217 for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) { 217 for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) {
218 sprintf(m_ptynam,"/dev/pty%c%c",*c0,*c1); 218 sprintf(m_ptynam,"/dev/pty%c%c",*c0,*c1);
219 sprintf(m_ttynam,"/dev/tty%c%c",*c0,*c1); 219 sprintf(m_ttynam,"/dev/tty%c%c",*c0,*c1);
220 if ((ptyfd = ::open(m_ptynam,O_RDWR)) >= 0) { 220 if ((ptyfd = ::open(m_ptynam,O_RDWR)) >= 0) {
221 if (geteuid() != 0 && !access(m_ttynam,R_OK|W_OK) == 0) { 221 if (geteuid() != 0 && !access(m_ttynam,R_OK|W_OK) == 0) {
222 ::close(ptyfd); 222 ::close(ptyfd);
223 ptyfd = -1; 223 ptyfd = -1;
224 } 224 }
225 } 225 }
226 } 226 }
227 } 227 }
228#endif 228#endif
229 229
230 if ( ptyfd < 0 ) { 230 if ( ptyfd < 0 ) {
231 //qApp->exit(1); 231 //qApp->exit(1);
232 return -1; 232 return -1;
233 } 233 }
234 234
235 return ptyfd; 235 return ptyfd;
236} 236}
237 237
238/*! 238/*!
239 Create an instance. 239 Create an instance.
240*/ 240*/
241MyPty::MyPty(const Profile& prof) : m_cpid(0) 241MyPty::MyPty(const Profile& prof) : m_cpid(0)
242{ 242{
243 243
244 int term = prof.readNumEntry("Terminal", Profile::VT100 ); 244 int term = prof.readNumEntry("Terminal", Profile::VT100 );
245 switch( term ) { 245 switch( term ) {
246 default: 246 default:
247 case Profile::VT100: 247 case Profile::VT100:
248 case Profile::VT102: 248 case Profile::VT102:
249 m_term = "vt100"; 249 m_term = "vt100";
250 break; 250 break;
251 case Profile::Linux: 251 case Profile::Linux:
252 m_term = "linux"; 252 m_term = "linux";
253 break; 253 break;
254 case Profile::XTerm: 254 case Profile::XTerm:
255 m_term = "xterm"; 255 m_term = "xterm";
256 break; 256 break;
257 } 257 }
258 m_sn_e = 0l; 258 m_sn_e = 0l;
259 m_sn_r = 0l; 259 m_sn_r = 0l;
260 m_fd = openPty(); 260 m_fd = openPty();
261 ProcCtl* ctl = ProcCtl::self(); 261 ProcCtl* ctl = ProcCtl::self();
262 Q_UNUSED(ctl); 262 Q_UNUSED(ctl);
263 reload(prof); 263 reload(prof);
264} 264}
265 265
266/*! 266/*!
267 Destructor. 267 Destructor.
268 Note that the related client program is not killed 268 Note that the related client program is not killed
269 (yet) when a instance is deleted. 269 (yet) when a instance is deleted.
270*/ 270*/
271MyPty::~MyPty() 271MyPty::~MyPty()
272{ 272{
273 donePty(); 273 donePty();
274} 274}
275QString MyPty::identifier()const { 275QString MyPty::identifier()const {
276 return QString::fromLatin1("term"); 276 return QString::fromLatin1("term");
277} 277}
278QString MyPty::name()const{ 278QString MyPty::name()const{
279 return identifier(); 279 return identifier();
280} 280}
281bool MyPty::open() { 281bool MyPty::open() {
282 if (m_fd < 0) 282 if (m_fd < 0)
283 m_fd = openPty(); 283 m_fd = openPty();
284 284
285 start(); 285 start();
286 return true; 286 return true;
287} 287}
288void MyPty::close() { 288void MyPty::close() {
289 donePty(); 289 donePty();
290 m_fd = openPty(); 290 m_fd = openPty();
291} 291}
292void MyPty::reload( const Profile& prof) { 292void MyPty::reload( const Profile& prof) {
293 m_env.clear(); 293 m_env.clear();
294 m_cmd = prof.readEntry("Command", "/bin/bash"); 294 m_cmd = prof.readEntry("Command", "/bin/sh");
295
296 /*
297 * Lets check if m_cmd actually
298 * exists....
299 * we try to use bin/bash and if
300 * this fails we
301 * will fallback to /bin/sh
302 * which should be there 100%
303 */
304 if ( !QFile::exists(QFile::encodeName(m_cmd) ) )
305 if (QFile::exists("/bin/bash") )
306 m_cmd = "/bin/bash";
307 else
308 m_cmd = "/bin/sh";
309
295 int envcount = prof.readNumEntry("EnvVars", 0); 310 int envcount = prof.readNumEntry("EnvVars", 0);
296 for (int i=0; i<envcount; i++) { 311 for (int i=0; i<envcount; i++) {
297 QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); 312 QString name = prof.readEntry("Env_Name_" + QString::number(i), "");
298 QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); 313 QString value = prof.readEntry("Env_Value_" + QString::number(i), "");
299 if (!(name.isEmpty() || value.isEmpty())) { 314 if (!(name.isEmpty() || value.isEmpty())) {
300 m_env.insert(name, value); 315 m_env.insert(name, value);
301 } 316 }
302 } 317 }
303} 318}
304/*! sends len bytes through the line */ 319/*! sends len bytes through the line */
305void MyPty::send(const QByteArray& ar) 320void MyPty::send(const QByteArray& ar)
306{ 321{
307#ifdef VERBOSE_DEBUG 322#ifdef VERBOSE_DEBUG
308 // verbose debug 323 // verbose debug
309 printf("sending bytes:\n"); 324 printf("sending bytes:\n");
310 for (uint i = 0; i < ar.count(); i++) 325 for (uint i = 0; i < ar.count(); i++)
311 printf("%c", ar[i]); 326 printf("%c", ar[i]);
312 printf("\n"); 327 printf("\n");
313#endif 328#endif
314 329
315 ::write(m_fd, ar.data(), ar.count()); 330 ::write(m_fd, ar.data(), ar.count());
316} 331}
317 332
318/*! indicates that a block of data is received */ 333/*! indicates that a block of data is received */
319void MyPty::readPty() 334void MyPty::readPty()
320{ 335{
321 QByteArray buf(4096); 336 QByteArray buf(4096);
322 337
323 int len = ::read( m_fd, buf.data(), 4096 ); 338 int len = ::read( m_fd, buf.data(), 4096 );
324 339
325 if (len == -1 || len == 0) { 340 if (len == -1 || len == 0) {
326 donePty(); 341 donePty();
327 return; 342 return;
328 } 343 }
329 344
330 if (len < 0) 345 if (len < 0)
331 return; 346 return;
332 347
333 348
334 buf.resize(len); 349 buf.resize(len);
335 emit received(buf); 350 emit received(buf);
336 351
337#ifdef VERBOSE_DEBUG 352#ifdef VERBOSE_DEBUG
338 // verbose debug 353 // verbose debug
339 printf("read bytes:\n"); 354 printf("read bytes:\n");
340 for (uint i = 0; i < buf.count(); i++) 355 for (uint i = 0; i < buf.count(); i++)
341 printf("%c", buf[i]); 356 printf("%c", buf[i]);
342 printf("\n"); 357 printf("\n");
343#endif 358#endif
344 359
345} 360}
346QBitArray MyPty::supports()const { 361QBitArray MyPty::supports()const {
347 QBitArray ar(3); 362 QBitArray ar(3);
348 //autoconnect 363 //autoconnect
349 ar[0] = 1; 364 ar[0] = 1;
350 // 365 //
351 ar[1] = 0; 366 ar[1] = 0;
352 ar[2] = 0; 367 ar[2] = 0;
353 368
354 return ar; 369 return ar;
355} 370}
diff --git a/noncore/apps/opie-console/consoleconfigwidget.cpp b/noncore/apps/opie-console/consoleconfigwidget.cpp
index 70e2e78..3f2d154 100644
--- a/noncore/apps/opie-console/consoleconfigwidget.cpp
+++ b/noncore/apps/opie-console/consoleconfigwidget.cpp
@@ -1,95 +1,100 @@
1#include <qlabel.h> 1#include <qlabel.h>
2#include <qlayout.h> 2#include <qlayout.h>
3#include <qcombobox.h> 3#include <qcombobox.h>
4#include <qlineedit.h> 4#include <qlineedit.h>
5#include <qpushbutton.h> 5#include <qpushbutton.h>
6#include <qlistview.h> 6#include <qlistview.h>
7#include <qhbox.h> 7#include <qhbox.h>
8#include <qregexp.h> 8#include <qregexp.h>
9#include <stdio.h> 9#include <stdio.h>
10 10
11#include "consoleconfigwidget.h" 11#include "consoleconfigwidget.h"
12 12
13ConsoleConfigWidget::ConsoleConfigWidget( const QString& name, QWidget* parent, 13ConsoleConfigWidget::ConsoleConfigWidget( const QString& name, QWidget* parent,
14 const char* na ) 14 const char* na )
15 : ProfileDialogConnectionWidget( name, parent, na ) { 15 : ProfileDialogConnectionWidget( name, parent, na ) {
16 m_lay = new QVBoxLayout( this ); 16 m_lay = new QVBoxLayout( this );
17 QLabel *label = new QLabel(tr("Command to execute"), this); 17 QLabel *label = new QLabel(tr("Command to execute"), this);
18 m_lay->addWidget(label); 18 m_lay->addWidget(label);
19 m_cmd = new QLineEdit(this); 19 m_cmd = new QLineEdit(this);
20 m_lay->addWidget(m_cmd); 20 m_lay->addWidget(m_cmd);
21 label = new QLabel(tr("Environment Variables"), this); 21 label = new QLabel(tr("Environment Variables"), this);
22 m_lay->addWidget(label); 22 m_lay->addWidget(label);
23 m_env = new QListView(this); 23 m_env = new QListView(this);
24 m_env->addColumn(tr("Name")); 24 m_env->addColumn(tr("Name"));
25 m_env->addColumn(tr("Value")); 25 m_env->addColumn(tr("Value"));
26 m_lay->addWidget(m_env); 26 m_lay->addWidget(m_env);
27 27
28 QHBox *hbox = new QHBox(this); 28 QHBox *hbox = new QHBox(this);
29 label = new QLabel(tr("Name :"), hbox); 29 label = new QLabel(tr("Name :"), hbox);
30 m_name = new QLineEdit(hbox); 30 m_name = new QLineEdit(hbox);
31 m_lay->addWidget(hbox); 31 m_lay->addWidget(hbox);
32 32
33 hbox = new QHBox(this); 33 hbox = new QHBox(this);
34 label = new QLabel(tr("Value :"), hbox); 34 label = new QLabel(tr("Value :"), hbox);
35 m_value = new QLineEdit(hbox); 35 m_value = new QLineEdit(hbox);
36 m_lay->addWidget(hbox); 36 m_lay->addWidget(hbox);
37 37
38 hbox = new QHBox(this); 38 hbox = new QHBox(this);
39 hbox->setSpacing(10); 39 hbox->setSpacing(10);
40 m_remove = new QPushButton(tr("Remove"), hbox); 40 m_remove = new QPushButton(tr("Remove"), hbox);
41 connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove())); 41 connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove()));
42 m_add = new QPushButton(tr("Add"), hbox); 42 m_add = new QPushButton(tr("Add"), hbox);
43 connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd())); 43 connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd()));
44 m_lay->addWidget(hbox); 44 m_lay->addWidget(hbox);
45} 45}
46 46
47void ConsoleConfigWidget::slotAdd() { 47void ConsoleConfigWidget::slotAdd() {
48 if (!(m_name->text().isEmpty() || m_value->text().isEmpty())) { 48 if (!(m_name->text().isEmpty() || m_value->text().isEmpty())) {
49 QListViewItem *item = new QListViewItem(m_env); 49 QListViewItem *item = new QListViewItem(m_env);
50 item->setText(0, m_name->text()); 50 item->setText(0, m_name->text());
51 item->setText(1, m_value->text()); 51 item->setText(1, m_value->text());
52 m_env->insertItem(item); 52 m_env->insertItem(item);
53 } 53 }
54} 54}
55 55
56void ConsoleConfigWidget::slotRemove() { 56void ConsoleConfigWidget::slotRemove() {
57 QListViewItem *item = m_env->currentItem(); 57 QListViewItem *item = m_env->currentItem();
58 if (item) { 58 if (item) {
59 m_env->takeItem(item); 59 m_env->takeItem(item);
60 } 60 }
61} 61}
62 62
63ConsoleConfigWidget::~ConsoleConfigWidget() { 63ConsoleConfigWidget::~ConsoleConfigWidget() {
64} 64}
65 65
66void ConsoleConfigWidget::load( const Profile& prof ) { 66void ConsoleConfigWidget::load( const Profile& prof ) {
67 /*
68 * we will use /bin/bash as default
69 * but will fallback in MyPty to /bin/sh
70 * if necessary
71 */
67 m_cmd->setText(prof.readEntry("Command", "/bin/bash")); 72 m_cmd->setText(prof.readEntry("Command", "/bin/bash"));
68 int envcount = prof.readNumEntry("EnvVars", 0); 73 int envcount = prof.readNumEntry("EnvVars", 0);
69 for (int i=0; i<envcount; i++) { 74 for (int i=0; i<envcount; i++) {
70 QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); 75 QString name = prof.readEntry("Env_Name_" + QString::number(i), "");
71 QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); 76 QString value = prof.readEntry("Env_Value_" + QString::number(i), "");
72 if (!(name.isEmpty() || value.isEmpty())) { 77 if (!(name.isEmpty() || value.isEmpty())) {
73 QListViewItem *item = new QListViewItem(m_env); 78 QListViewItem *item = new QListViewItem(m_env);
74 item->setText(0, name); 79 item->setText(0, name);
75 item->setText(1, value); 80 item->setText(1, value);
76 m_env->insertItem(item); 81 m_env->insertItem(item);
77 } 82 }
78 } 83 }
79} 84}
80 85
81void ConsoleConfigWidget::save( Profile& prof ) { 86void ConsoleConfigWidget::save( Profile& prof ) {
82 prof.writeEntry( "Command", m_cmd->text()); 87 prof.writeEntry( "Command", m_cmd->text());
83 QListViewItem *item = m_env->firstChild(); 88 QListViewItem *item = m_env->firstChild();
84 int counter = 0; 89 int counter = 0;
85 while (item) { 90 while (item) {
86 QString name = item->text(0); 91 QString name = item->text(0);
87 QString value = item->text(1); 92 QString value = item->text(1);
88 prof.writeEntry("Env_Name_" + QString::number(counter), name); 93 prof.writeEntry("Env_Name_" + QString::number(counter), name);
89 prof.writeEntry("Env_Value_" + QString::number(counter), value); 94 prof.writeEntry("Env_Value_" + QString::number(counter), value);
90 item = item->nextSibling(); 95 item = item->nextSibling();
91 counter++; 96 counter++;
92 } 97 }
93 prof.writeEntry("EnvVars", QString::number(counter)); 98 prof.writeEntry("EnvVars", QString::number(counter));
94} 99}
95 100
diff --git a/noncore/apps/opie-console/profileeditordialog.cpp b/noncore/apps/opie-console/profileeditordialog.cpp
index fd04b6b..6b607df 100644
--- a/noncore/apps/opie-console/profileeditordialog.cpp
+++ b/noncore/apps/opie-console/profileeditordialog.cpp
@@ -1,239 +1,239 @@
1#include <qlayout.h> 1#include <qlayout.h>
2#include <qlineedit.h> 2#include <qlineedit.h>
3#include <qlabel.h> 3#include <qlabel.h>
4#include <qmessagebox.h> 4#include <qmessagebox.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6#include <qcombobox.h> 6#include <qcombobox.h>
7#include <qcheckbox.h> 7#include <qcheckbox.h>
8#include <qscrollview.h> 8#include <qscrollview.h>
9 9
10#include "metafactory.h" 10#include "metafactory.h"
11#include "profileeditordialog.h" 11#include "profileeditordialog.h"
12 12
13namespace { 13namespace {
14 void setCurrent( const QString& str, QComboBox* bo ) { 14 void setCurrent( const QString& str, QComboBox* bo ) {
15 for (int i = 0; i < bo->count(); i++ ) { 15 for (int i = 0; i < bo->count(); i++ ) {
16 if ( bo->text(i) == str ) { 16 if ( bo->text(i) == str ) {
17 bo->setCurrentItem( i ); 17 bo->setCurrentItem( i );
18 } 18 }
19 } 19 }
20 }; 20 };
21} 21}
22 22
23ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact, 23ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact,
24 const Profile& prof ) 24 const Profile& prof )
25 : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof ) 25 : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof )
26{ 26{
27 initUI(); 27 initUI();
28 28
29 // Apply current profile 29 // Apply current profile
30 // plugin_plugin->load(profile); 30 // plugin_plugin->load(profile);
31 // ... (reset profile name line edit etc.) 31 // ... (reset profile name line edit etc.)
32} 32}
33 33
34ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact ) 34ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact )
35 : QDialog(0, 0, TRUE), m_fact( fact ) 35 : QDialog(0, 0, TRUE), m_fact( fact )
36{ 36{
37 // Default profile 37 // Default profile
38 m_prof = Profile("New Profile", "serial", "default", Profile::Black, Profile::White, Profile::VT102); 38 m_prof = Profile("New Profile", "serial", "default", Profile::Black, Profile::White, Profile::VT102);
39 39
40 initUI(); 40 initUI();
41 41
42 // Apply current profile 42 // Apply current profile
43 // plugin_plugin->load(profile); 43 // plugin_plugin->load(profile);
44} 44}
45 45
46Profile ProfileEditorDialog::profile() const 46Profile ProfileEditorDialog::profile() const
47{ 47{
48 return m_prof; 48 return m_prof;
49} 49}
50 50
51void ProfileEditorDialog::initUI() 51void ProfileEditorDialog::initUI()
52{ 52{
53 m_con = m_term = m_key = 0l; 53 m_con = m_term = m_key = 0l;
54 54
55 55
56 QVBoxLayout *mainLayout = new QVBoxLayout( this ); 56 QVBoxLayout *mainLayout = new QVBoxLayout( this );
57 tabWidget = new OTabWidget( this ); 57 tabWidget = new OTabWidget( this );
58 tabWidget->setTabStyle(OTabWidget::TextTab); 58 tabWidget->setTabStyle(OTabWidget::TextTab);
59 mainLayout->add(tabWidget); 59 mainLayout->add(tabWidget);
60 60
61 /* base tabs */ 61 /* base tabs */
62 tabprof = new QWidget(this); 62 tabprof = new QWidget(this);
63 m_tabTerm = new QWidget(this); 63 m_tabTerm = new QWidget(this);
64 m_tabCon = new QWidget(this); 64 m_tabCon = new QWidget(this);
65 m_tabKey = new QWidget(this); 65 m_tabKey = new QWidget(this);
66 66
67 m_svCon = new QScrollView( m_tabCon ); 67 m_svCon = new QScrollView( m_tabCon );
68 m_svCon->setResizePolicy( QScrollView::AutoOneFit ); 68 m_svCon->setResizePolicy( QScrollView::AutoOneFit );
69 //m_svCon->setHScrollBarMode( QScrollView::AlwaysOff ); 69 //m_svCon->setHScrollBarMode( QScrollView::AlwaysOff );
70 m_svCon->setFrameShape( QFrame::NoFrame ); 70 m_svCon->setFrameShape( QFrame::NoFrame );
71 m_svTerm = new QScrollView( m_tabTerm ); 71 m_svTerm = new QScrollView( m_tabTerm );
72 m_svTerm->setResizePolicy( QScrollView::AutoOneFit ); 72 m_svTerm->setResizePolicy( QScrollView::AutoOneFit );
73 //m_svTerm->setHScrollBarMode( QScrollView::AlwaysOff ); 73 //m_svTerm->setHScrollBarMode( QScrollView::AlwaysOff );
74 m_svTerm->setFrameShape( QFrame::NoFrame ); 74 m_svTerm->setFrameShape( QFrame::NoFrame );
75 75
76 /* base layout for tabs */ 76 /* base layout for tabs */
77 m_layCon = new QHBoxLayout( m_tabCon , 2 ); 77 m_layCon = new QHBoxLayout( m_tabCon , 2 );
78 m_layTerm = new QHBoxLayout( m_tabTerm, 2 ); 78 m_layTerm = new QHBoxLayout( m_tabTerm, 2 );
79 m_layKey = new QHBoxLayout( m_tabKey, 2 ); 79 m_layKey = new QHBoxLayout( m_tabKey, 2 );
80 80
81 m_layCon->addWidget( m_svCon ); 81 m_layCon->addWidget( m_svCon );
82 m_layTerm->addWidget( m_svTerm ); 82 m_layTerm->addWidget( m_svTerm );
83 83
84 // profile tab 84 // profile tab
85 85
86 QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof); 86 QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof);
87 m_name = new QLineEdit(tabprof); 87 m_name = new QLineEdit(tabprof);
88 QLabel *con = new QLabel(tr("Connection"), tabprof ); 88 QLabel *con = new QLabel(tr("Connection"), tabprof );
89 QLabel *term = new QLabel(tr("Terminal"), tabprof ); 89 QLabel *term = new QLabel(tr("Terminal"), tabprof );
90 m_conCmb = new QComboBox( tabprof ); 90 m_conCmb = new QComboBox( tabprof );
91 m_termCmb = new QComboBox( tabprof ); 91 m_termCmb = new QComboBox( tabprof );
92 m_autoConnect = new QCheckBox(tr("Auto connect after load"), tabprof); 92 m_autoConnect = new QCheckBox(tr("Auto connect after load"), tabprof);
93 93
94 // layouting 94 // layouting
95 QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2); 95 QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2);
96 vbox3->add(name); 96 vbox3->add(name);
97 vbox3->add(m_name); 97 vbox3->add(m_name);
98 vbox3->add(con ); 98 vbox3->add(con );
99 vbox3->add(m_conCmb ); 99 vbox3->add(m_conCmb );
100 vbox3->add(term ); 100 vbox3->add(term );
101 vbox3->add(m_termCmb ); 101 vbox3->add(m_termCmb );
102 vbox3->add(m_autoConnect); 102 vbox3->add(m_autoConnect);
103 vbox3->addStretch(1); 103 vbox3->addStretch(1);
104 104
105 m_showconntab = 0; 105 m_showconntab = 0;
106 tabWidget->addTab(tabprof, "", QObject::tr("Profile")); 106 tabWidget->addTab(tabprof, "", QObject::tr("Profile"));
107 tabWidget->addTab(m_tabCon, "", QObject::tr("Connection")); 107 tabWidget->addTab(m_tabCon, "", QObject::tr("Connection"));
108 tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal")); 108 tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal"));
109 tabWidget->addTab(m_tabKey, "", QObject::tr("Special Keys")); 109 tabWidget->addTab(m_tabKey, "", QObject::tr("Special Keys"));
110 tabWidget->setCurrentTab( tabprof ); 110 tabWidget->setCurrentTab( tabprof );
111 111
112 112
113 // fill the comboboxes 113 // fill the comboboxes
114 QStringList list = m_fact->connectionWidgets(); 114 QStringList list = m_fact->connectionWidgets();
115 QStringList::Iterator it; 115 QStringList::Iterator it;
116 for (it =list.begin(); it != list.end(); ++it ) { 116 for (it =list.begin(); it != list.end(); ++it ) {
117 m_conCmb->insertItem( (*it) ); 117 m_conCmb->insertItem( (*it) );
118 } 118 }
119 list = m_fact->terminalWidgets(); 119 list = m_fact->terminalWidgets();
120 for (it =list.begin(); it != list.end(); ++it ) { 120 for (it =list.begin(); it != list.end(); ++it ) {
121 m_termCmb->insertItem( (*it) ); 121 m_termCmb->insertItem( (*it) );
122 } 122 }
123 123
124 // load profile values 124 // load profile values
125 m_name->setText(m_prof.name()); 125 m_name->setText(m_prof.name());
126 slotConActivated( m_fact->external(m_prof.ioLayerName() ) ); 126 slotConActivated( m_fact->external(m_prof.ioLayerName() ) );
127 slotTermActivated( m_fact->external(m_prof.terminalName() ) ); 127 slotTermActivated( m_fact->external(m_prof.terminalName() ) );
128 slotKeyActivated( "Default Keyboard" ); 128 slotKeyActivated( "Default Keyboard" );
129 setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb ); 129 setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb );
130 setCurrent( m_fact->external(m_prof.terminalName() ), m_termCmb ); 130 setCurrent( m_fact->external(m_prof.terminalName() ), m_termCmb );
131 m_autoConnect->setChecked(m_prof.autoConnect()); 131 m_autoConnect->setChecked(m_prof.autoConnect());
132 132
133 133
134 // signal and slots 134 // signal and slots
135 connect(m_conCmb, SIGNAL(activated(const QString& ) ), 135 connect(m_conCmb, SIGNAL(activated(const QString& ) ),
136 this, SLOT(slotConActivated(const QString&) ) ); 136 this, SLOT(slotConActivated(const QString&) ) );
137 connect(m_termCmb, SIGNAL(activated(const QString& ) ), 137 connect(m_termCmb, SIGNAL(activated(const QString& ) ),
138 this, SLOT(slotTermActivated(const QString& ) ) ); 138 this, SLOT(slotTermActivated(const QString& ) ) );
139 139
140} 140}
141 141
142ProfileEditorDialog::~ProfileEditorDialog() { 142ProfileEditorDialog::~ProfileEditorDialog() {
143 143
144} 144}
145void ProfileEditorDialog::accept() 145void ProfileEditorDialog::accept()
146{ 146{
147 if(profName().isEmpty()) 147 if(profName().isEmpty())
148 { 148 {
149 QMessageBox::information(this, 149 QMessageBox::information(this,
150 QObject::tr("Invalid profile"), 150 QObject::tr("Invalid profile"),
151 QObject::tr("Please enter a profile name.")); 151 QObject::tr("Please enter a profile name."));
152 return; 152 return;
153 } 153 }
154 // Save profile and plugin profile 154 // Save profile and plugin profile
155 //if(plugin_plugin) plugin_plugin->save(); 155 //if(plugin_plugin) plugin_plugin->save();
156 156
157 // Save general values 157 // Save general values
158 m_prof.setName( profName() ); 158 m_prof.setName( profName() );
159 m_prof.setIOLayer( m_fact->internal(m_conCmb ->currentText() ) ); 159 m_prof.setIOLayer( m_fact->internal(m_conCmb ->currentText() ) );
160 m_prof.setTerminalName( m_fact->internal(m_termCmb->currentText() ) ); 160 m_prof.setTerminalName( m_fact->internal(m_termCmb->currentText() ) );
161 m_prof.setAutoConnect( m_autoConnect->isChecked() ); 161 m_prof.setAutoConnect( m_autoConnect->isChecked() );
162 162
163 if (m_con ) 163 if (m_con )
164 m_con->save( m_prof ); 164 m_con->save( m_prof );
165 if (m_term ) 165 if (m_term )
166 m_term->save( m_prof ); 166 m_term->save( m_prof );
167 if (m_key) 167 if (m_key)
168 m_key->save( m_prof ); 168 m_key->save( m_prof );
169 169
170 QDialog::accept(); 170 QDialog::accept();
171} 171}
172 172
173 173
174QString ProfileEditorDialog::profName()const 174QString ProfileEditorDialog::profName()const
175{ 175{
176 return m_name->text(); 176 return m_name->text();
177} 177}
178 178
179QCString ProfileEditorDialog::profType()const 179QCString ProfileEditorDialog::profType()const
180{ 180{
181 /*QStringList w = m_fact->configWidgets(); 181 /*QStringList w = m_fact->configWidgets();
182 for(QStringList::Iterator it = w.begin(); it != w.end(); it++) 182 for(QStringList::Iterator it = w.begin(); it != w.end(); it++)
183 if(device_box->currentText() == m_fact->name((*it))) return (*it); 183 if(device_box->currentText() == m_fact->name((*it))) return (*it);
184 */ 184 */
185 return QCString(); 185 return QCString();
186} 186}
187/* 187/*
188 * we need to switch the widget 188 * we need to switch the widget
189 */ 189 */
190void ProfileEditorDialog::slotConActivated( const QString& str ) { 190void ProfileEditorDialog::slotConActivated( const QString& str ) {
191 191
192 delete m_con; 192 delete m_con;
193 193
194 m_con = m_fact->newConnectionPlugin( str, m_svCon->viewport() ); 194 m_con = m_fact->newConnectionPlugin( str, m_svCon->viewport() );
195 195
196 if ( !m_con ) { 196 if ( !m_con ) {
197 m_con = new NoOptions( str, m_svCon->viewport(), "name"); 197 m_con = new NoOptions( str, m_svCon->viewport(), "name");
198 } 198 }
199 199
200 // FIXME ugly hack right. Right solution would be to look into the layer and see if it 200 // FIXME ugly hack right. Right solution would be to look into the layer and see if it
201 // supports auto connect and then set it as prefered 201 // supports auto connect and then set it as prefered
202 //if ( ( )->layer()->supports()[0] == 1 ) { 202 //if ( ( )->layer()->supports()[0] == 1 ) {
203 if ( m_conCmb ->currentText() == tr("local Console") ) { 203 if ( m_conCmb ->currentText() == tr("Local Console") ) {
204 m_autoConnect->setChecked( true ); 204 m_autoConnect->setChecked( true );
205 } else { 205 } else {
206 m_autoConnect->setChecked( false ); 206 m_autoConnect->setChecked( false );
207 } 207 }
208 208
209 m_con->load( m_prof ); 209 m_con->load( m_prof );
210 m_svCon->addChild( m_con ); 210 m_svCon->addChild( m_con );
211} 211}
212 212
213 213
214/* 214/*
215 * we need to switch the widget 215 * we need to switch the widget
216 */ 216 */
217void ProfileEditorDialog::slotTermActivated( const QString& str ) { 217void ProfileEditorDialog::slotTermActivated( const QString& str ) {
218 218
219 delete m_term; 219 delete m_term;
220 220
221 m_term = m_fact->newTerminalPlugin( str, m_svTerm->viewport() ); 221 m_term = m_fact->newTerminalPlugin( str, m_svTerm->viewport() );
222 222
223 if (m_term) { 223 if (m_term) {
224 m_term->load( m_prof ); 224 m_term->load( m_prof );
225 m_svTerm->addChild( m_term ); 225 m_svTerm->addChild( m_term );
226 } 226 }
227} 227}
228 228
229void ProfileEditorDialog::slotKeyActivated(const QString &str) { 229void ProfileEditorDialog::slotKeyActivated(const QString &str) {
230 delete m_key; 230 delete m_key;
231 m_key = m_fact->newKeyboardPlugin( str, m_tabKey ); 231 m_key = m_fact->newKeyboardPlugin( str, m_tabKey );
232 232
233 if (m_key) { 233 if (m_key) {
234 234
235 m_key->load(m_prof); 235 m_key->load(m_prof);
236 m_layKey->addWidget(m_key); 236 m_layKey->addWidget(m_key);
237 } 237 }
238 238
239} 239}