summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/konsole.cpp
Unidiff
Diffstat (limited to 'core/apps/embeddedkonsole/konsole.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp87
1 files changed, 80 insertions, 7 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index fff2f68..a5adc03 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,88 +1,94 @@
1/* ---------------------------------------------------------------------- */ 1/* ---------------------------------------------------------------------- */
2/* */ 2/* */
3/* [main.C] Konsole */ 3/* [main.C] Konsole */
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. */ 9/* This file is part of Konsole, an X terminal. */
10/* */ 10/* */
11/* The material contained in here more or less directly orginates from */ 11/* The material contained in here more or less directly orginates from */
12/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ 12/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
13/* */ 13/* */
14/* ---------------------------------------------------------------------- */ 14/* ---------------------------------------------------------------------- */
15/* */ 15/* */
16/* Ported Konsole to Qt/Embedded */ 16/* Ported Konsole to Qt/Embedded */
17/* */ 17/* */
18/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 18/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
19/* */ 19/* */
20/* -------------------------------------------------------------------------- */ 20/* -------------------------------------------------------------------------- */
21// enhancements added by L.J. Potter <ljp@llornkcor.com> 21// enhancements added by L.J. Potter <ljp@llornkcor.com>
22#define QT_QWS_OPIE 22//#define QT_QWS_OPIE
23
24#include "signal.h"
23 25
24#include <qpe/resource.h> 26#include <qpe/resource.h>
25 27
26#include <qdir.h> 28#include <qdir.h>
27#include <qevent.h> 29#include <qevent.h>
28#include <qdragobject.h> 30#include <qdragobject.h>
29#include <qobjectlist.h> 31#include <qobjectlist.h>
30#include <qtoolbutton.h> 32#include <qtoolbutton.h>
31#include <qtoolbar.h> 33#include <qtoolbar.h>
32#include <qpushbutton.h> 34#include <qpushbutton.h>
33#include <qfontdialog.h> 35#include <qfontdialog.h>
34#include <qglobal.h> 36#include <qglobal.h>
35#include <qpainter.h> 37#include <qpainter.h>
36#include <qmenubar.h> 38#include <qmenubar.h>
37#include <qmessagebox.h> 39#include <qmessagebox.h>
38#include <qaction.h> 40#include <qaction.h>
39#include <qapplication.h> 41#include <qapplication.h>
40#include <qfontmetrics.h> 42#include <qfontmetrics.h>
41#include <qcombobox.h> 43#include <qcombobox.h>
42#include <qevent.h> 44#include <qevent.h>
43#include <qtabwidget.h> 45#include <qtabwidget.h>
44#include <qtabbar.h> 46#include <qtabbar.h>
45#include <qpe/config.h> 47#include <qpe/config.h>
46#include <qstringlist.h> 48#include <qstringlist.h>
47#include <qpalette.h> 49#include <qpalette.h>
48 50
49#include <unistd.h> 51#include <unistd.h>
50#include <pwd.h> 52#include <pwd.h>
51#include <sys/types.h> 53#include <sys/types.h>
52#include <sys/wait.h> 54//#include <sys/wait.h>
53#include <stdio.h> 55#include <stdio.h>
54#include <stdlib.h> 56#include <stdlib.h>
55#include <assert.h> 57#include <assert.h>
56 58
57#include "konsole.h" 59#include "konsole.h"
58#include "keytrans.h" 60#include "keytrans.h"
59#include "commandeditdialog.h" 61#include "commandeditdialog.h"
60 62
61#ifdef QT_QWS_OPIE 63#ifdef QT_QWS_OPIE
62#include <opie/colorpopupmenu.h> 64#include <opie/colorpopupmenu.h>
63#endif 65#endif
64 66
67 #include <qfontdatabase.h>// U.B.
68 #include <qstringlist.h>// U.B.
69 #include <qvaluelist.h> // U.B.
70
65class EKNumTabBar : public QTabBar { 71class EKNumTabBar : public QTabBar {
66public: 72public:
67 void numberTabs() 73 void numberTabs()
68 { 74 {
69 // Yes, it really is this messy. QTabWidget needs functions 75 // Yes, it really is this messy. QTabWidget needs functions
70 // that provide acces to tabs in a sequential way. 76 // that provide acces to tabs in a sequential way.
71 int m=INT_MIN; 77 int m=INT_MIN;
72 for (int i=0; i<count(); i++) { 78 for (int i=0; i<count(); i++) {
73 QTab* left=0; 79 QTab* left=0;
74 QListIterator<QTab> it(*tabList()); 80 QListIterator<QTab> it(*tabList());
75 int x=INT_MAX; 81 int x=INT_MAX;
76 for( QTab* t; (t=it.current()); ++it ) { 82 for( QTab* t; (t=it.current()); ++it ) {
77 int tx = t->rect().x(); 83 int tx = t->rect().x();
78 if ( tx<x && tx>m ) { 84 if ( tx<x && tx>m ) {
79 x = tx; 85 x = tx;
80 left = t; 86 left = t;
81 } 87 }
82 } 88 }
83 if ( left ) { 89 if ( left ) {
84 left->setText(QString::number(i+1)); 90 left->setText(QString::number(i+1));
85 m = left->rect().x(); 91 m = left->rect().x();
86 } 92 }
87 } 93 }
88 } 94 }
@@ -157,162 +163,228 @@ static const char *commonCmds[] =
157 "dmesg", 163 "dmesg",
158 "fuser", 164 "fuser",
159 "hostname", 165 "hostname",
160 "kill", 166 "kill",
161 "killall", 167 "killall",
162 "ln", 168 "ln",
163 "ping", 169 "ping",
164 "mount", 170 "mount",
165 "more", 171 "more",
166 "sort", 172 "sort",
167 "touch", 173 "touch",
168 "umount", 174 "umount",
169 "mknod", 175 "mknod",
170 "netstat", 176 "netstat",
171*/ 177*/
172 178
173 "exit", 179 "exit",
174 NULL 180 NULL
175}; 181};
176 182
177static void konsoleInit(const char** shell) { 183static void konsoleInit(const char** shell) {
178 if(setuid(getuid()) !=0) qDebug("setuid failed"); 184 if(setuid(getuid()) !=0) qDebug("setuid failed");
179 if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges 185 if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges
180 186
187 // signal (SIGSTOP, SIG_IGN);
181 188
182// QPEApplication::grabKeyboard(); // for CTRL and ALT 189// QPEApplication::grabKeyboard(); // for CTRL and ALT
183 190
184 qDebug("keyboard grabbed"); 191// qDebug("keyboard grabbed");
185#ifdef FAKE_CTRL_AND_ALT 192#ifdef FAKE_CTRL_AND_ALT
186 qDebug("Fake Ctrl and Alt defined"); 193 qDebug("Fake Ctrl and Alt defined");
187 QPEApplication::grabKeyboard(); // for CTRL and ALT 194 QPEApplication::grabKeyboard(); // for CTRL and ALT
188#endif 195#endif
189 196
190 *shell = getenv("SHELL"); 197 *shell = getenv("SHELL");
191 qWarning("SHell initially is %s", *shell ); 198// qWarning("SHell initially is %s", *shell );
192 199
193 if (shell == NULL || *shell == '\0') { 200 if (shell == NULL || *shell == '\0') {
194 struct passwd *ent = 0; 201 struct passwd *ent = 0;
195 uid_t me = getuid(); 202 uid_t me = getuid();
196 *shell = "/bin/sh"; 203 *shell = "/bin/sh";
197 204
198 while ( (ent = getpwent()) != 0 ) { 205 while ( (ent = getpwent()) != 0 ) {
199 if (ent->pw_uid == me) { 206 if (ent->pw_uid == me) {
200 if (ent->pw_shell != "") 207 if (ent->pw_shell != "")
201 *shell = ent->pw_shell; 208 *shell = ent->pw_shell;
202 break; 209 break;
203 } 210 }
204 } 211 }
205 endpwent(); 212 endpwent();
206 } 213 }
207 214
208 qWarning("SHELL now is %s", *shell ); 215// qWarning("SHELL now is %s", *shell );
209 216
210 if( putenv((char*)"COLORTERM=") !=0) 217 if( putenv((char*)"COLORTERM=") !=0)
211 qDebug("putenv failed"); // to trigger mc's color detection 218 qDebug("putenv failed"); // to trigger mc's color detection
212} 219}
213 220
214Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 221Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
215 QMainWindow(parent, name, fl) 222 QMainWindow(parent, name, fl)
216{ 223{
217 QStrList tmp; const char* shell; 224 QStrList tmp; const char* shell;
218 225
219 setCaption( tr("Terminal") ); 226 setCaption( tr("Terminal") );
220 227
221 konsoleInit( &shell); 228 konsoleInit( &shell);
222 qWarning("Using shell %s", shell); 229// qWarning("Using shell %s", shell);
223 init(shell,tmp); 230 init(shell,tmp);
224} 231}
225 232
226 233
227 234
228void Konsole::initCommandList() 235void Konsole::initCommandList()
229{ 236{
230// qDebug("Konsole::initCommandList"); 237// qDebug("Konsole::initCommandList");
231 Config cfg("Konsole"); 238 Config cfg("Konsole");
232 cfg.setGroup("Commands"); 239 cfg.setGroup("Commands");
233 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 240 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
234 commonCombo->clear(); 241 commonCombo->clear();
235 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 242 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
236 for (int i = 0; commonCmds[i] != NULL; i++) { 243 for (int i = 0; commonCmds[i] != NULL; i++) {
237 commonCombo->insertItem(commonCmds[i],i); 244 commonCombo->insertItem(commonCmds[i],i);
238 } 245 }
239 } else { 246 } else {
240 for (int i = 0; i < 100; i++) { 247 for (int i = 0; i < 100; i++) {
241 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 248 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
242 commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); 249 commonCombo->insertItem((cfg.readEntry( QString::number(i),"")));
243 } 250 }
244 } 251 }
245 252
246} 253}
247 254
248void Konsole::init(const char* _pgm, QStrList & _args) 255void Konsole::init(const char* _pgm, QStrList & _args)
249{ 256{
250 b_scroll = TRUE; // histon; 257 b_scroll = TRUE; // histon;
251 n_keytab = 0; 258 n_keytab = 0;
252 n_render = 0; 259 n_render = 0;
253 startUp=0; 260 startUp=0;
254 fromMenu = FALSE; 261 fromMenu = FALSE;
255 262
256 setCaption( tr("Terminal") ); 263 setCaption( tr("Terminal") );
257 setIcon( Resource::loadPixmap( "konsole" ) ); 264 setIcon( Resource::loadPixmap( "konsole" ) );
258 265
259 Config cfg("Konsole"); 266 Config cfg("Konsole");
260 cfg.setGroup("Konsole"); 267 cfg.setGroup("Konsole");
261 QString tmp; 268 QString tmp;
262 // initialize the list of allowed fonts /////////////////////////////////// 269 // initialize the list of allowed fonts ///////////////////////////////////
263 cfont = cfg.readNumEntry("FontID", 1); 270 cfont = cfg.readNumEntry("FontID", 1);
271
264 QFont f = QFont("Micro", 4, QFont::Normal); 272 QFont f = QFont("Micro", 4, QFont::Normal);
265 f.setFixedPitch(TRUE); 273 f.setFixedPitch(TRUE);
266 fonts.append(new VTFont(tr("Micro"), f)); 274 fonts.append(new VTFont(tr("Micro"), f));
267 275
268 f = QFont("Fixed", 7, QFont::Normal); 276 f = QFont("Fixed", 7, QFont::Normal);
269 f.setFixedPitch(TRUE); 277 f.setFixedPitch(TRUE);
270 fonts.append(new VTFont(tr("Small Fixed"), f)); 278 fonts.append(new VTFont(tr("Small Fixed"), f));
271 279
272 f = QFont("Fixed", 12, QFont::Normal); 280 f = QFont("Fixed", 12, QFont::Normal);
273 f.setFixedPitch(TRUE); 281 f.setFixedPitch(TRUE);
274 fonts.append(new VTFont(tr("Medium Fixed"), f)); 282 fonts.append(new VTFont(tr("Medium Fixed"), f));
275 283
284// NEW STUFF
285
286 QStringList ignfont = cfg.readListEntry("IgnFont", ',');
287 /* If there is no "IgnFont = ..." entry in "myonsole.conf",
288 * put some Japanese fonts of the SL-C7x0 to "ignfont". */
289
290 if (ignfont.isEmpty()) {
291 ignfont = QStringList::split (',',"jisupasp,mmkjg1,mmkjg4,mmkjg5");
292 }
293
294 //QFont
295 f = QFont("Fixed", 16, QFont::Normal);
296 f.setFixedPitch(true);
297 fonts.append(new VTFont(tr("Default"), f));
298
299 int fcount = 1;
300
301 f.setCharSet(QFont::AnyCharSet);
302 f.setStyleHint(QFont::TypeWriter, QFont::PreferMatch);
303// f.setWeight(QFont::Normal);
304
305 /*
306 * Look for installed font families. If the family is not in
307 * the "ignfont" list, look for available sizes.
308 * If it is fixed pitch font, put the font and the size
309 * to the fontlist.
310 */
311 QFontDatabase fdb;
312 QStringList ff = fdb.families(false);
313
314 for (QStringList::Iterator it = ff.begin(); it != ff.end(); ++it ) {
315 QString fit = *it;
316
317 if( fit != "fixed" && fit != "micro" ) {
318 if ( ignfont.contains(*it) == 0) {
319 QValueList<int> pt = fdb.pointSizes(*it);
320
321 for (QValueList<int>::Iterator itv = pt.begin();
322 itv != pt.end(); ++itv ) {
323 int size = (*itv)/10;
324 if(size > 0) {
325 f.setFamily(*it);
326 f.setPointSize(size);
327 }
328
329 QFontMetrics fm(f);
330
331//qDebug("%s %d:\twidth('i')=%d, width('w')=%d", (*it).latin1(), (*itv)/10, fm.width('i'), fm.width('w'));
332
333 if (fm.width('i') == fm.width('w') ) {
334 qDebug((*it));
335 f.setFixedPitch(true);
336 fonts.append(new VTFont(*it + ' ' + QString::number(size), f));
337 fcount++;
338 }
339 }
340 }
341 }
342 }
343
344// END NEW STUFF
345
346
276 // create terminal emulation framework //////////////////////////////////// 347 // create terminal emulation framework ////////////////////////////////////
277 nsessions = 0; 348 nsessions = 0;
278 349
279 tab = new EKNumTabWidget(this); 350 tab = new EKNumTabWidget(this);
280 351
281 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); 352 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
282 353
283 // create terminal toolbar //////////////////////////////////////////////// 354 // create terminal toolbar ////////////////////////////////////////////////
284 setToolBarsMovable( FALSE ); 355 setToolBarsMovable( FALSE );
285 QToolBar *menuToolBar = new QToolBar( this ); 356 QToolBar *menuToolBar = new QToolBar( this );
286 menuToolBar->setHorizontalStretchable( TRUE ); 357 menuToolBar->setHorizontalStretchable( TRUE );
287 358
288 QMenuBar *menuBar = new QMenuBar( menuToolBar ); 359 QMenuBar *menuBar = new QMenuBar( menuToolBar );
289 360
290 fontList = new QPopupMenu( this ); 361 fontList = new QPopupMenu( this );
291 for(uint i = 0; i < fonts.count(); i++) { 362 for(uint i = 0; i < fonts.count(); i++) {
292 VTFont *fnt = fonts.at(i); 363 VTFont *fnt = fonts.at(i);
293 fontList->insertItem(fnt->getName(), i); 364 fontList->insertItem(fnt->getName(), i);
294 } 365 }
366
295 fontChanged(cfont); 367 fontChanged(cfont);
296 368
297 configMenu = new QPopupMenu( this); 369 configMenu = new QPopupMenu( this);
298 colorMenu = new QPopupMenu( this); 370 colorMenu = new QPopupMenu( this);
299 scrollMenu = new QPopupMenu( this); 371 scrollMenu = new QPopupMenu( this);
300 editCommandListMenu = new QPopupMenu( this); 372 editCommandListMenu = new QPopupMenu( this);
301 373
302 configMenu->insertItem(tr("Command List"), editCommandListMenu); 374 configMenu->insertItem(tr("Command List"), editCommandListMenu);
303 375
304 bool listHidden; 376 bool listHidden;
305 cfg.setGroup("Menubar"); 377 cfg.setGroup("Menubar");
306 if( cfg.readEntry("Hidden","FALSE") == "TRUE") { 378 if( cfg.readEntry("Hidden","FALSE") == "TRUE") {
307 editCommandListMenu->insertItem( tr( "Show command list" )); 379 editCommandListMenu->insertItem( tr( "Show command list" ));
308 listHidden=TRUE; 380 listHidden=TRUE;
309 } else { 381 } else {
310 editCommandListMenu->insertItem( tr( "Hide command list" )); 382 editCommandListMenu->insertItem( tr( "Hide command list" ));
311 listHidden=FALSE; 383 listHidden=FALSE;
312 } 384 }
313 385
314 cfg.setGroup("Tabs"); 386 cfg.setGroup("Tabs");
315 tmp=cfg.readEntry("Position","Bottom"); 387 tmp=cfg.readEntry("Position","Bottom");
316 if(tmp=="Top") { 388 if(tmp=="Top") {
317 tab->setTabPosition(QTabWidget::Top); 389 tab->setTabPosition(QTabWidget::Top);
318 configMenu->insertItem( tr( "Tabs on Bottom" ) ); 390 configMenu->insertItem( tr( "Tabs on Bottom" ) );
@@ -604,49 +676,50 @@ void Konsole::setFont(int fontno)
604 f = defaultFont = QFont( "Helvetica", 12 ); 676 f = defaultFont = QFont( "Helvetica", 12 );
605 else 677 else
606 if (fonts[fontno][0] == '-') 678 if (fonts[fontno][0] == '-')
607 f.setRawName( fonts[fontno] ); 679 f.setRawName( fonts[fontno] );
608 else 680 else
609 { 681 {
610 f.setFamily(fonts[fontno]); 682 f.setFamily(fonts[fontno]);
611 f.setRawMode( TRUE ); 683 f.setRawMode( TRUE );
612 } 684 }
613 if ( !f.exactMatch() && fontno != 0) 685 if ( !f.exactMatch() && fontno != 0)
614 { 686 {
615 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); 687 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
616 QMessageBox(this, msg); 688 QMessageBox(this, msg);
617 return; 689 return;
618 } 690 }
619 if (se) se->setFontNo(fontno); 691 if (se) se->setFontNo(fontno);
620 te->setVTFont(f); 692 te->setVTFont(f);
621 n_font = fontno; 693 n_font = fontno;
622} 694}
623*/ 695*/
624 696
625// --| color selection |------------------------------------------------------- 697// --| color selection |-------------------------------------------------------
626 698
627void Konsole::changeColumns(int columns) 699void Konsole::changeColumns(int columns)
628{ //FIXME this seems to cause silliness when reset command is executed 700{
701 //FIXME this seems to cause silliness when reset command is executed
629// qDebug("change columns"); 702// qDebug("change columns");
630// TEWidget* te = getTe(); 703// TEWidget* te = getTe();
631// if (te != 0) { 704// if (te != 0) {
632// setColLin(columns,te->Lines()); 705// setColLin(columns,te->Lines());
633// te->update(); 706// te->update();
634// } 707// }
635} 708}
636 709
637//FIXME: If a child dies during session swap, 710//FIXME: If a child dies during session swap,
638// this routine might be called before 711// this routine might be called before
639// session swap is completed. 712// session swap is completed.
640 713
641void Konsole::doneSession(TESession*, int ) 714void Konsole::doneSession(TESession*, int )
642{ 715{
643 TEWidget *te = getTe(); 716 TEWidget *te = getTe();
644 if (te != 0) { 717 if (te != 0) {
645 te->currentSession->setConnect(FALSE); 718 te->currentSession->setConnect(FALSE);
646 tab->removeTab(te); 719 tab->removeTab(te);
647 delete te->currentSession; 720 delete te->currentSession;
648 delete te; 721 delete te;
649 nsessions--; 722 nsessions--;
650 } 723 }
651 724
652 if (nsessions == 0) { 725 if (nsessions == 0) {