summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/konsole.cpp
Side-by-side diff
Diffstat (limited to 'core/apps/embeddedkonsole/konsole.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp74
1 files changed, 57 insertions, 17 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
@@ -43,12 +43,15 @@
#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"
@@ -168,26 +171,63 @@ static const char *commonCmds[] =
*/
"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);
@@ -296,13 +336,13 @@ void Konsole::init(const char* _pgm, QStrList & _args)
colorMenu->insertItem(tr( "Blue on Black"));
colorMenu->insertItem(tr( "Amber on Black"));
#ifdef QT_QWS_OPIE
colorMenu->insertItem(tr( "Custom"));
#endif
-
+
configMenu->insertItem( tr("Font"), fontList );
configMenu->insertItem(tr( "Colors") ,colorMenu);
connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) ));
@@ -365,25 +405,25 @@ void Konsole::init(const char* _pgm, QStrList & _args)
scrollMenu->insertItem(tr( "None" ));
scrollMenu->insertItem(tr( "Left" ));
scrollMenu->insertItem(tr( "Right" ));
// scrollMenu->insertSeparator(4);
// scrollMenu->insertItem(tr( "Horizontal" ));
-
+
configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
int jut = configMenu->insertItem(tr( "Wrap" ));
cfg.setGroup("ScrollBar");
configMenu->setItemChecked(jut, cfg.readBoolEntry("HorzScroll",0));
jut = configMenu->insertItem(tr( "Use Beep" ));
cfg.setGroup("Menubar");
configMenu->setItemChecked(jut, cfg.readBoolEntry("useBeep",0));
-
+
//scrollMenuSelected(-29);
// cfg.setGroup("ScrollBar");
// if(cfg.readBoolEntry("HorzScroll",0)) {
// if(cfg.readNumEntry("Position",2) == 0)
// te->setScrollbarLocation(1);
// else
@@ -415,13 +455,13 @@ parseCommandLine();
void Konsole::show()
{
if ( !nsessions ) {
newSession();
}
QMainWindow::show();
-
+
}
void Konsole::initSession(const char*, QStrList &)
{
QMainWindow::show();
}
@@ -538,13 +578,13 @@ QSize Konsole::calcSize(int columns, int lines) {
guest widget. Call with (0,0) for setting default size.
*/
void Konsole::setColLin(int columns, int lines)
{
qDebug("konsole::setColLin:: Columns %d", columns);
-
+
if ((columns==0) || (lines==0))
{
if (defaultSize.isEmpty()) // not in config file : set default value
{
defaultSize = calcSize(80,24);
// notifySize(24,80); // set menu items (strange arg order !)
@@ -760,13 +800,13 @@ void Konsole::colorMenuSelected(int iD)
if(iD==-18) {// Black, Gold
background.setRgb(0x00,0x00,0x00);
foreground.setRgb(255,215,0);
cfg.writeEntry("Schema","18");
colorMenu->setItemChecked(-18,TRUE);
}
-#ifdef QT_QWS_OPIE
+#ifdef QT_QWS_OPIE
if(iD==-19) {
// Custom
qDebug("do custom");
if(fromMenu) {
OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, this, "foreground color");
connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this,
@@ -887,21 +927,21 @@ i=-24;j=-25;k=-26;
#endif
if(index == i) {
te->setScrollbarLocation(0);
cfg.writeEntry("Position",0);
} else if(index == j) {
-
+
te->setScrollbarLocation(1);
cfg.writeEntry("Position",1);
} else if(index == k) {
te->setScrollbarLocation(2);
cfg.writeEntry("Position",2);
}
-
+
// case -29: {
// bool b=cfg.readBoolEntry("HorzScroll",0);
// cfg.writeEntry("HorzScroll", !b );
// cfg.write();
// if(cfg.readNumEntry("Position",2) == 0) {
// te->setScrollbarLocation(1);
@@ -1044,19 +1084,19 @@ void Konsole::doWrap() {
int i;
#ifdef QT_QWS_OPIE
i=-29;
#else
i=-28;
#endif
-
+
Config cfg("Konsole");
cfg.setGroup("ScrollBar");
TEWidget* te = getTe();
if( !cfg.readBoolEntry("HorzScroll",0)) {
te->setWrapAt(0);
configMenu->setItemChecked( i,TRUE);
} else {
// te->setWrapAt(90);
te->setWrapAt(120);
configMenu->setItemChecked( i,FALSE);
- }
+ }
}