summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/konsole.cpp
Side-by-side diff
Diffstat (limited to 'core/apps/embeddedkonsole/konsole.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp54
1 files changed, 47 insertions, 7 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index c324c35..ec438c3 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,96 +1,99 @@
/* ---------------------------------------------------------------------- */
/* */
/* [main.C] Konsole */
/* */
/* ---------------------------------------------------------------------- */
/* */
/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
/* */
/* This file is part of Konsole, an X terminal. */
/* */
/* The material contained in here more or less directly orginates from */
/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
/* */
/* ---------------------------------------------------------------------- */
/* */
/* Ported Konsole to Qt/Embedded */
/* */
/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
/* */
/* -------------------------------------------------------------------------- */
// enhancements added by L.J. Potter <ljp@llornkcor.com>
#define QT_QWS_OPIE
#include <qpe/resource.h>
#include <qdir.h>
#include <qevent.h>
#include <qdragobject.h>
#include <qobjectlist.h>
#include <qtoolbutton.h>
#include <qpe/qpetoolbar.h>
#include <qpushbutton.h>
#include <qfontdialog.h>
#include <qglobal.h>
#include <qpainter.h>
#include <qpe/qpemenubar.h>
#include <qmessagebox.h>
#include <qaction.h>
#include <qapplication.h>
#include <qfontmetrics.h>
#include <qcombobox.h>
#include <qevent.h>
#include <qtabwidget.h>
#include <qtabbar.h>
#include <qpe/config.h>
#include <qstringlist.h>
#include <qpalette.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "konsole.h"
#include "keytrans.h"
#include "commandeditdialog.h"
#ifdef QT_QWS_OPIE
#include <opie/colorpopupmenu.h>
#endif
class EKNumTabBar : public QTabBar {
public:
void numberTabs()
{
// Yes, it really is this messy. QTabWidget needs functions
// that provide acces to tabs in a sequential way.
int m=INT_MIN;
for (int i=0; i<count(); i++) {
QTab* left=0;
QListIterator<QTab> it(*tabList());
int x=INT_MAX;
for( QTab* t; (t=it.current()); ++it ) {
int tx = t->rect().x();
if ( tx<x && tx>m ) {
x = tx;
left = t;
}
}
if ( left ) {
left->setText(QString::number(i+1));
m = left->rect().x();
}
}
}
};
class EKNumTabWidget : public QTabWidget {
public:
EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
{
}
void addTab(QWidget* w)
{
QTab* t = new QTab(QString::number(tabBar()->count()+1));
@@ -126,110 +129,147 @@ static const char *commonCmds[] =
"ifconfig ",
"ipkg ",
"mkdir ",
"mv ",
"nc localhost 7776",
"nc localhost 7777",
"netstat ",
"nslookup ",
"ping ",
"ps aux",
"pwd ",
"qcop QPE/System 'linkChanged(QString)' ''",
"qcop QPE/System 'restart()'",
"qcop QPE/System 'quit()'",
"rm ",
"rmdir ",
"route ",
"set ",
"traceroute",
/*
"gzip",
"gunzip",
"chgrp",
"chown",
"date",
"dd",
"df",
"dmesg",
"fuser",
"hostname",
"kill",
"killall",
"ln",
"ping",
"mount",
"more",
"sort",
"touch",
"umount",
"mknod",
"netstat",
*/
"exit",
NULL
};
+static void konsoleInit(const char** shell) {
+ if(setuid(getuid()) !=0) qDebug("setuid failed");
+ if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges
+
+
+// QPEApplication::grabKeyboard(); // for CTRL and ALT
+
+ qDebug("keyboard grabbed");
+#ifdef FAKE_CTRL_AND_ALT
+ qDebug("Fake Ctrl and Alt defined");
+ QPEApplication::grabKeyboard(); // for CTRL and ALT
+#endif
+
+ *shell = getenv("SHELL");
+ qWarning("SHell initially is %s", *shell );
+
+ if (shell == NULL || *shell == '\0') {
+ struct passwd *ent = 0;
+ uid_t me = getuid();
+ *shell = "/bin/sh";
+
+ while ( (ent = getpwent()) != 0 ) {
+ if (ent->pw_uid == me) {
+ if (ent->pw_shell != "")
+ *shell = ent->pw_shell;
+ break;
+ }
+ }
+ endpwent();
+ }
+
+ qWarning("SHELL now is %s", *shell );
+
+ if( putenv((char*)"COLORTERM=") !=0)
+ qDebug("putenv failed"); // to trigger mc's color detection
+}
Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
QMainWindow(parent, name, fl)
{
- QStrList args;
- init("/bin/sh",args);
-}
+ QStrList tmp; const char* shell;
-Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
- : QMainWindow(0, name)
-{
- init(_pgm,_args);
+ setCaption( tr("Terminal") );
+
+ konsoleInit( &shell);
+ qWarning("Using shell %s", shell);
+ init(shell,tmp);
}
+
+
void Konsole::initCommandList()
{
// qDebug("Konsole::initCommandList");
Config cfg("Konsole");
cfg.setGroup("Commands");
commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
commonCombo->clear();
if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
for (int i = 0; commonCmds[i] != NULL; i++) {
commonCombo->insertItem(commonCmds[i],i);
}
} else {
for (int i = 0; i < 100; i++) {
if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
commonCombo->insertItem((cfg.readEntry( QString::number(i),"")));
}
}
}
void Konsole::init(const char* _pgm, QStrList & _args)
{
b_scroll = TRUE; // histon;
n_keytab = 0;
n_render = 0;
startUp=0;
fromMenu = FALSE;
setCaption( tr("Terminal") );
setIcon( Resource::loadPixmap( "konsole" ) );
Config cfg("Konsole");
cfg.setGroup("Konsole");
QString tmp;
// initialize the list of allowed fonts ///////////////////////////////////
cfont = cfg.readNumEntry("FontID", 1);
QFont f = QFont("Micro", 4, QFont::Normal);
f.setFixedPitch(TRUE);
fonts.append(new VTFont(tr("Micro"), f));
f = QFont("Fixed", 7, QFont::Normal);
f.setFixedPitch(TRUE);
fonts.append(new VTFont(tr("Small Fixed"), f));
f = QFont("Fixed", 12, QFont::Normal);
f.setFixedPitch(TRUE);
fonts.append(new VTFont(tr("Medium Fixed"), f));