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.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
@@ -25,48 +25,51 @@
25 25
26#include <qdir.h> 26#include <qdir.h>
27#include <qevent.h> 27#include <qevent.h>
28#include <qdragobject.h> 28#include <qdragobject.h>
29#include <qobjectlist.h> 29#include <qobjectlist.h>
30#include <qtoolbutton.h> 30#include <qtoolbutton.h>
31#include <qpe/qpetoolbar.h> 31#include <qpe/qpetoolbar.h>
32#include <qpushbutton.h> 32#include <qpushbutton.h>
33#include <qfontdialog.h> 33#include <qfontdialog.h>
34#include <qglobal.h> 34#include <qglobal.h>
35#include <qpainter.h> 35#include <qpainter.h>
36#include <qpe/qpemenubar.h> 36#include <qpe/qpemenubar.h>
37#include <qmessagebox.h> 37#include <qmessagebox.h>
38#include <qaction.h> 38#include <qaction.h>
39#include <qapplication.h> 39#include <qapplication.h>
40#include <qfontmetrics.h> 40#include <qfontmetrics.h>
41#include <qcombobox.h> 41#include <qcombobox.h>
42#include <qevent.h> 42#include <qevent.h>
43#include <qtabwidget.h> 43#include <qtabwidget.h>
44#include <qtabbar.h> 44#include <qtabbar.h>
45#include <qpe/config.h> 45#include <qpe/config.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47#include <qpalette.h> 47#include <qpalette.h>
48 48
49#include <unistd.h>
50#include <pwd.h>
51#include <sys/types.h>
49#include <sys/wait.h> 52#include <sys/wait.h>
50#include <stdio.h> 53#include <stdio.h>
51#include <stdlib.h> 54#include <stdlib.h>
52#include <assert.h> 55#include <assert.h>
53 56
54#include "konsole.h" 57#include "konsole.h"
55#include "keytrans.h" 58#include "keytrans.h"
56#include "commandeditdialog.h" 59#include "commandeditdialog.h"
57 60
58#ifdef QT_QWS_OPIE 61#ifdef QT_QWS_OPIE
59#include <opie/colorpopupmenu.h> 62#include <opie/colorpopupmenu.h>
60#endif 63#endif
61 64
62class EKNumTabBar : public QTabBar { 65class EKNumTabBar : public QTabBar {
63public: 66public:
64 void numberTabs() 67 void numberTabs()
65 { 68 {
66 // Yes, it really is this messy. QTabWidget needs functions 69 // Yes, it really is this messy. QTabWidget needs functions
67 // that provide acces to tabs in a sequential way. 70 // that provide acces to tabs in a sequential way.
68 int m=INT_MIN; 71 int m=INT_MIN;
69 for (int i=0; i<count(); i++) { 72 for (int i=0; i<count(); i++) {
70 QTab* left=0; 73 QTab* left=0;
71 QListIterator<QTab> it(*tabList()); 74 QListIterator<QTab> it(*tabList());
72 int x=INT_MAX; 75 int x=INT_MAX;
@@ -150,62 +153,99 @@ static const char *commonCmds[] =
150 "chown", 153 "chown",
151 "date", 154 "date",
152 "dd", 155 "dd",
153 "df", 156 "df",
154 "dmesg", 157 "dmesg",
155 "fuser", 158 "fuser",
156 "hostname", 159 "hostname",
157 "kill", 160 "kill",
158 "killall", 161 "killall",
159 "ln", 162 "ln",
160 "ping", 163 "ping",
161 "mount", 164 "mount",
162 "more", 165 "more",
163 "sort", 166 "sort",
164 "touch", 167 "touch",
165 "umount", 168 "umount",
166 "mknod", 169 "mknod",
167 "netstat", 170 "netstat",
168*/ 171*/
169 172
170 "exit", 173 "exit",
171 NULL 174 NULL
172}; 175};
173 176
177static void konsoleInit(const char** shell) {
178 if(setuid(getuid()) !=0) qDebug("setuid failed");
179 if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges
180
181
182// QPEApplication::grabKeyboard(); // for CTRL and ALT
183
184 qDebug("keyboard grabbed");
185#ifdef FAKE_CTRL_AND_ALT
186 qDebug("Fake Ctrl and Alt defined");
187 QPEApplication::grabKeyboard(); // for CTRL and ALT
188#endif
189
190 *shell = getenv("SHELL");
191 qWarning("SHell initially is %s", *shell );
192
193 if (shell == NULL || *shell == '\0') {
194 struct passwd *ent = 0;
195 uid_t me = getuid();
196 *shell = "/bin/sh";
197
198 while ( (ent = getpwent()) != 0 ) {
199 if (ent->pw_uid == me) {
200 if (ent->pw_shell != "")
201 *shell = ent->pw_shell;
202 break;
203 }
204 }
205 endpwent();
206 }
207
208 qWarning("SHELL now is %s", *shell );
209
210 if( putenv((char*)"COLORTERM=") !=0)
211 qDebug("putenv failed"); // to trigger mc's color detection
212}
174 213
175Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 214Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
176 QMainWindow(parent, name, fl) 215 QMainWindow(parent, name, fl)
177{ 216{
178 QStrList args; 217 QStrList tmp; const char* shell;
179 init("/bin/sh",args);
180}
181 218
182Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) 219 setCaption( tr("Terminal") );
183 : QMainWindow(0, name) 220
184{ 221 konsoleInit( &shell);
185 init(_pgm,_args); 222 qWarning("Using shell %s", shell);
223 init(shell,tmp);
186} 224}
187 225
226
227
188void Konsole::initCommandList() 228void Konsole::initCommandList()
189{ 229{
190// qDebug("Konsole::initCommandList"); 230// qDebug("Konsole::initCommandList");
191 Config cfg("Konsole"); 231 Config cfg("Konsole");
192 cfg.setGroup("Commands"); 232 cfg.setGroup("Commands");
193 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 233 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
194 commonCombo->clear(); 234 commonCombo->clear();
195 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 235 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
196 for (int i = 0; commonCmds[i] != NULL; i++) { 236 for (int i = 0; commonCmds[i] != NULL; i++) {
197 commonCombo->insertItem(commonCmds[i],i); 237 commonCombo->insertItem(commonCmds[i],i);
198 } 238 }
199 } else { 239 } else {
200 for (int i = 0; i < 100; i++) { 240 for (int i = 0; i < 100; i++) {
201 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 241 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
202 commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); 242 commonCombo->insertItem((cfg.readEntry( QString::number(i),"")));
203 } 243 }
204 } 244 }
205 245
206} 246}
207 247
208void Konsole::init(const char* _pgm, QStrList & _args) 248void Konsole::init(const char* _pgm, QStrList & _args)
209{ 249{
210 b_scroll = TRUE; // histon; 250 b_scroll = TRUE; // histon;
211 n_keytab = 0; 251 n_keytab = 0;