summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-02-06 02:49:25 (UTC)
committer llornkcor <llornkcor>2005-02-06 02:49:25 (UTC)
commit6764eece4d63724d55252b2cbfa04e8f2fb5787d (patch) (unidiff)
tree914f5d32d4c353f27e659d246ae0588a18c5d7a4
parentc3892e6c1a4ca15383a7da48f6d72b1d7d26f43d (diff)
downloadopie-6764eece4d63724d55252b2cbfa04e8f2fb5787d.zip
opie-6764eece4d63724d55252b2cbfa04e8f2fb5787d.tar.gz
opie-6764eece4d63724d55252b2cbfa04e8f2fb5787d.tar.bz2
too long
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index 8b4202d..de00494 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,363 +1,363 @@
1 1
2/* ---------------------------------------------------------------------- */ 2/* ---------------------------------------------------------------------- */
3/* */ 3/* */
4/* [main.C] Konsole */ 4/* [main.C] Konsole */
5/* */ 5/* */
6/* ---------------------------------------------------------------------- */ 6/* ---------------------------------------------------------------------- */
7/* */ 7/* */
8/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 8/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
9/* */ 9/* */
10/* This file is part of Konsole, an X terminal. */ 10/* This file is part of Konsole, an X terminal. */
11/* */ 11/* */
12/* The material contained in here more or less directly orginates from */ 12/* The material contained in here more or less directly orginates from */
13/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ 13/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
14/* */ 14/* */
15/* ---------------------------------------------------------------------- */ 15/* ---------------------------------------------------------------------- */
16/* */ 16/* */
17/* Ported Konsole to Qt/Embedded */ 17/* Ported Konsole to Qt/Embedded */
18/* */ 18/* */
19/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 19/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
20/* */ 20/* */
21/* -------------------------------------------------------------------------- */ 21/* -------------------------------------------------------------------------- */
22// enhancements added by L.J. Potter <ljp@llornkcor.com> 22// enhancements added by L.J. Potter <ljp@llornkcor.com>
23// enhancements added by Phillip Kuhn 23// enhancements added by Phillip Kuhn
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26#include <sys/types.h> 26#include <sys/types.h>
27#include <pwd.h> 27#include <pwd.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#ifdef QT_QWS_OPIE 30#ifdef QT_QWS_OPIE
31#include <opie2/ocolorpopupmenu.h> 31#include <opie2/ocolorpopupmenu.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33using namespace Opie; 33using namespace Opie;
34#endif 34#endif
35 35
36#include <qpe/resource.h> 36#include <qpe/resource.h>
37 37
38#include <qmenubar.h> 38#include <qmenubar.h>
39#include <qtabbar.h> 39#include <qtabbar.h>
40#include <qpe/config.h> 40#include <qpe/config.h>
41#include <qfontdatabase.h> 41#include <qfontdatabase.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qspinbox.h> 43#include <qspinbox.h>
44#include <qlayout.h> 44#include <qlayout.h>
45 45
46#include <sys/wait.h> 46#include <sys/wait.h>
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
49#include <assert.h> 49#include <assert.h>
50 50
51#include "konsole.h" 51#include "konsole.h"
52#include "commandeditdialog.h" 52#include "commandeditdialog.h"
53 53
54class EKNumTabBar : public QTabBar 54class EKNumTabBar : public QTabBar
55{ 55{
56public: 56public:
57 EKNumTabBar(QWidget *parent = 0, const char *name = 0) : 57 EKNumTabBar(QWidget *parent = 0, const char *name = 0) :
58 QTabBar(parent, name) 58 QTabBar(parent, name)
59 {} 59 {}
60 60
61 // QList<QTab> *getTabList() { return(tabList()); } 61 // QList<QTab> *getTabList() { return(tabList()); }
62 62
63 void numberTabs() 63 void numberTabs()
64 { 64 {
65 // Yes, it really is this messy. QTabWidget needs functions 65 // Yes, it really is this messy. QTabWidget needs functions
66 // that provide acces to tabs in a sequential way. 66 // that provide acces to tabs in a sequential way.
67 int m=INT_MIN; 67 int m=INT_MIN;
68 for (int i=0; i<count(); i++) 68 for (int i=0; i<count(); i++)
69 { 69 {
70 QTab* left=0; 70 QTab* left=0;
71 QListIterator<QTab> it(*tabList()); 71 QListIterator<QTab> it(*tabList());
72 int x=INT_MAX; 72 int x=INT_MAX;
73 for( QTab* t; (t=it.current()); ++it ) 73 for( QTab* t; (t=it.current()); ++it )
74 { 74 {
75 int tx = t->rect().x(); 75 int tx = t->rect().x();
76 if ( tx<x && tx>m ) 76 if ( tx<x && tx>m )
77 { 77 {
78 x = tx; 78 x = tx;
79 left = t; 79 left = t;
80 } 80 }
81 } 81 }
82 if ( left ) 82 if ( left )
83 { 83 {
84 left->setText(QString::number(i+1)); 84 left->setText(QString::number(i+1));
85 m = left->rect().x(); 85 m = left->rect().x();
86 } 86 }
87 } 87 }
88 } 88 }
89 89
90 virtual QSize sizeHint() const 90 virtual QSize sizeHint() const
91 { 91 {
92 if (isHidden()) 92 if (isHidden())
93 { 93 {
94 return(QSize(0,0)); 94 return(QSize(0,0));
95 } 95 }
96 else 96 else
97 { 97 {
98 QSize size = QTabBar::sizeHint(); 98 QSize size = QTabBar::sizeHint();
99 int shrink = 5; 99 int shrink = 5;
100 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600) 100 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600)
101 { 101 {
102 shrink = 10; 102 shrink = 10;
103 } 103 }
104 size.setHeight(size.height() - shrink); 104 size.setHeight(size.height() - shrink);
105 return(size); 105 return(size);
106 } 106 }
107 } 107 }
108 108
109}; 109};
110 110
111class EKNumTabWidget : public QTabWidget 111class EKNumTabWidget : public QTabWidget
112{ 112{
113public: 113public:
114 EKNumTabWidget(QWidget* parent) : QTabWidget(parent) 114 EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
115 { 115 {
116 setTabBar(new EKNumTabBar(parent,"EKTabBar")); 116 setTabBar(new EKNumTabBar(parent,"EKTabBar"));
117 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); 117 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
118 } 118 }
119 119
120 EKNumTabBar *getTabBar() const 120 EKNumTabBar *getTabBar() const
121 { 121 {
122 return ((EKNumTabBar*)tabBar()); 122 return ((EKNumTabBar*)tabBar());
123 } 123 }
124 124
125 125
126 void addTab(QWidget* w) 126 void addTab(QWidget* w)
127 { 127 {
128 QTab* t = new QTab(QString::number(tabBar()->count()+1)); 128 QTab* t = new QTab(QString::number(tabBar()->count()+1));
129 QTabWidget::addTab(w,t); 129 QTabWidget::addTab(w,t);
130 } 130 }
131 131
132 void removeTab(QWidget* w) 132 void removeTab(QWidget* w)
133 { 133 {
134 removePage(w); 134 removePage(w);
135 ((EKNumTabBar*)tabBar())->numberTabs(); 135 ((EKNumTabBar*)tabBar())->numberTabs();
136 } 136 }
137}; 137};
138 138
139// This could be configurable or dynamicly generated from the bash history 139// This could be configurable or dynamicly generated from the bash history
140// file of the user 140// file of the user
141static const char *commonCmds[] = 141static const char *commonCmds[] =
142 { 142 {
143 "ls ", // I left this here, cause it looks better than the first alpha 143 "ls ", // I left this here, cause it looks better than the first alpha
144 "cardctl eject", 144 "cardctl eject",
145 "cat ", 145 "cat ",
146 "cd ", 146 "cd ",
147 "chmod ", 147 "chmod ",
148 "clear", 148 "clear",
149 "cp ", 149 "cp ",
150 "dc ", 150 "dc ",
151 "df ", 151 "df ",
152 "dmesg", 152 "dmesg",
153 "echo ", 153 "echo ",
154 "env", 154 "env",
155 "find ", 155 "find ",
156 "free", 156 "free",
157 "grep ", 157 "grep ",
158 "ifconfig ", 158 "ifconfig ",
159 "ipkg ", 159 "ipkg ",
160 "mkdir ", 160 "mkdir ",
161 "mv ", 161 "mv ",
162 "nc localhost 7776", 162 "nc localhost 7776",
163 "nc localhost 7777", 163 "nc localhost 7777",
164 "netstat ", 164 "netstat ",
165 "nslookup ", 165 "nslookup ",
166 "ping ", 166 "ping ",
167 "ps aux", 167 "ps aux",
168 "pwd ", 168 "pwd ",
169 "qcop QPE/System 'linkChanged(QString)' ''", 169// "qcop QPE/System 'linkChanged(QString)' ''",
170 "qcop QPE/System 'restart()'", 170// "qcop QPE/System 'restart()'",
171 "qcop QPE/System 'quit()'", 171// "qcop QPE/System 'quit()'",
172 "rm ", 172 "rm ",
173 "rmdir ", 173 "rmdir ",
174 "route ", 174 "route ",
175 "set ", 175 "set ",
176 "traceroute", 176 "traceroute",
177 177
178 /* 178 /*
179 "gzip", 179 "gzip",
180 "gunzip", 180 "gunzip",
181 "chgrp", 181 "chgrp",
182 "chown", 182 "chown",
183 "date", 183 "date",
184 "dd", 184 "dd",
185 "df", 185 "df",
186 "dmesg", 186 "dmesg",
187 "fuser", 187 "fuser",
188 "hostname", 188 "hostname",
189 "kill", 189 "kill",
190 "killall", 190 "killall",
191 "ln", 191 "ln",
192 "ping", 192 "ping",
193 "mount", 193 "mount",
194 "more", 194 "more",
195 "sort", 195 "sort",
196 "touch", 196 "touch",
197 "umount", 197 "umount",
198 "mknod", 198 "mknod",
199 "netstat", 199 "netstat",
200 */ 200 */
201 201
202 "exit", 202 "exit",
203 NULL 203 NULL
204 }; 204 };
205 205
206 206
207static void konsoleInit(const char** shell) { 207static void konsoleInit(const char** shell) {
208 if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl; 208 if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl;
209 if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl; // drop privileges 209 if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl; // drop privileges
210 210
211 211
212// QPEApplication::grabKeyboard(); // for CTRL and ALT 212// QPEApplication::grabKeyboard(); // for CTRL and ALT
213 213
214 odebug << "keyboard grabbed" << oendl; 214 odebug << "keyboard grabbed" << oendl;
215#ifdef FAKE_CTRL_AND_ALT 215#ifdef FAKE_CTRL_AND_ALT
216 odebug << "Fake Ctrl and Alt defined" << oendl; 216 odebug << "Fake Ctrl and Alt defined" << oendl;
217 QPEApplication::grabKeyboard(); // for CTRL and ALT 217 QPEApplication::grabKeyboard(); // for CTRL and ALT
218#endif 218#endif
219 219
220 *shell = getenv("SHELL"); 220 *shell = getenv("SHELL");
221 owarn << "SHell initially is " << *shell << "" << oendl; 221 owarn << "SHell initially is " << *shell << "" << oendl;
222 222
223 if (shell == NULL || *shell == '\0') { 223 if (shell == NULL || *shell == '\0') {
224 struct passwd *ent = 0; 224 struct passwd *ent = 0;
225 uid_t me = getuid(); 225 uid_t me = getuid();
226 *shell = "/bin/sh"; 226 *shell = "/bin/sh";
227 227
228 while ( (ent = getpwent()) != 0 ) { 228 while ( (ent = getpwent()) != 0 ) {
229 if (ent->pw_uid == me) { 229 if (ent->pw_uid == me) {
230 if (ent->pw_shell != "") 230 if (ent->pw_shell != "")
231 *shell = ent->pw_shell; 231 *shell = ent->pw_shell;
232 break; 232 break;
233 } 233 }
234 } 234 }
235 endpwent(); 235 endpwent();
236 } 236 }
237 237
238 if( putenv((char*)"COLORTERM=") !=0) 238 if( putenv((char*)"COLORTERM=") !=0)
239 odebug << "putenv failed" << oendl; // to trigger mc's color detection 239 odebug << "putenv failed" << oendl; // to trigger mc's color detection
240} 240}
241 241
242 242
243Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 243Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
244 QMainWindow(parent, name, fl) 244 QMainWindow(parent, name, fl)
245{ 245{
246 QStrList tmp; const char* shell; 246 QStrList tmp; const char* shell;
247 247
248 konsoleInit( &shell); 248 konsoleInit( &shell);
249 init(shell,tmp); 249 init(shell,tmp);
250} 250}
251 251
252Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) 252Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
253 : QMainWindow(0, name) 253 : QMainWindow(0, name)
254{ 254{
255 init(_pgm,_args); 255 init(_pgm,_args);
256} 256}
257 257
258struct HistoryItem 258struct HistoryItem
259{ 259{
260 HistoryItem(int c, const QString &l) 260 HistoryItem(int c, const QString &l)
261 { 261 {
262 count = c; 262 count = c;
263 line = l; 263 line = l;
264 } 264 }
265 int count; 265 int count;
266 QString line; 266 QString line;
267}; 267};
268 268
269class HistoryList : public QList<HistoryItem> 269class HistoryList : public QList<HistoryItem>
270{ 270{
271 virtual int compareItems( QCollection::Item item1, QCollection::Item item2) 271 virtual int compareItems( QCollection::Item item1, QCollection::Item item2)
272 { 272 {
273 int c1 = ((HistoryItem*)item1)->count; 273 int c1 = ((HistoryItem*)item1)->count;
274 int c2 = ((HistoryItem*)item2)->count; 274 int c2 = ((HistoryItem*)item2)->count;
275 if (c1 > c2) 275 if (c1 > c2)
276 return(1); 276 return(1);
277 if (c1 < c2) 277 if (c1 < c2)
278 return(-1); 278 return(-1);
279 return(0); 279 return(0);
280 } 280 }
281}; 281};
282 282
283void Konsole::initCommandList() 283void Konsole::initCommandList()
284{ 284{
285 // odebug << "Konsole::initCommandList" << oendl; 285 // odebug << "Konsole::initCommandList" << oendl;
286 Config cfg( "Konsole" ); 286 Config cfg( "Konsole" );
287 cfg.setGroup("Commands"); 287 cfg.setGroup("Commands");
288 // commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 288 // commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
289 commonCombo->clear(); 289 commonCombo->clear();
290 290
291 if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") { 291 if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") {
292 QString histfilename = QString(getenv("HOME")) + "/.bash_history"; 292 QString histfilename = QString(getenv("HOME")) + "/.bash_history";
293 histfilename = cfg.readEntry("ShellHistoryPath",histfilename); 293 histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
294 QFile histfile(histfilename); 294 QFile histfile(histfilename);
295 // note: compiler barfed on: 295 // note: compiler barfed on:
296 // QFile histfile(QString(getenv("HOME")) + "/.bash_history"); 296 // QFile histfile(QString(getenv("HOME")) + "/.bash_history");
297 if (histfile.open( IO_ReadOnly )) { 297 if (histfile.open( IO_ReadOnly )) {
298 QString line; 298 QString line;
299 uint i; 299 uint i;
300 HistoryList items; 300 HistoryList items;
301 301
302 int lineno = 0; 302 int lineno = 0;
303 while(!histfile.atEnd()) { 303 while(!histfile.atEnd()) {
304 if (histfile.readLine(line, 200) < 0) { 304 if (histfile.readLine(line, 200) < 0) {
305 break; 305 break;
306 } 306 }
307 line = line.left(line.length()-1); 307 line = line.left(line.length()-1);
308 lineno++; 308 lineno++;
309 309
310 for(i=0; i<items.count(); i++) { 310 for(i=0; i<items.count(); i++) {
311 if (line == items.at(i)->line) { 311 if (line == items.at(i)->line) {
312 // weight recent commands & repeated commands more 312 // weight recent commands & repeated commands more
313 // by adding up the index of each command 313 // by adding up the index of each command
314 items.at(i)->count += lineno; 314 items.at(i)->count += lineno;
315 break; 315 break;
316 } 316 }
317 } 317 }
318 if (i >= items.count()) { 318 if (i >= items.count()) {
319 items.append(new HistoryItem(lineno, line)); 319 items.append(new HistoryItem(lineno, line));
320 } 320 }
321 } 321 }
322 items.sort(); 322 items.sort();
323 int n = items.count(); 323 int n = items.count();
324 if (n > 40) { 324 if (n > 40) {
325 n = 40; 325 n = 40;
326 } 326 }
327 for(int i=0; i<n; i++) { 327 for(int i=0; i<n; i++) {
328 // should insert start of command, but keep whole thing 328 // should insert start of command, but keep whole thing
329 if (items.at(items.count()-i-1)->line.length() < 30) { 329 if (items.at(items.count()-i-1)->line.length() < 30) {
330 commonCombo->insertItem(items.at(items.count()-i-1)->line); 330 commonCombo->insertItem(items.at(items.count()-i-1)->line);
331 } 331 }
332 } 332 }
333 histfile.close(); 333 histfile.close();
334 } 334 }
335 } 335 }
336 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 336 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
337 for (int i = 0; commonCmds[i] != NULL; i++) { 337 for (int i = 0; commonCmds[i] != NULL; i++) {
338 commonCombo->insertItem(commonCmds[i]); 338 commonCombo->insertItem(commonCmds[i]);
339 } 339 }
340 } else { 340 } else {
341 for (int i = 0; i < 100; i++) { 341 for (int i = 0; i < 100; i++) {
342 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 342 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
343 commonCombo->insertItem(cfg.readEntry( QString::number(i),"")); 343 commonCombo->insertItem(cfg.readEntry( QString::number(i),""));
344 } 344 }
345 } 345 }
346 346
347 347
348} 348}
349 349
350static void sig_handler(int x) 350static void sig_handler(int x)
351{ 351{
352 printf("got signal %d\n",x); 352 printf("got signal %d\n",x);
353} 353}
354 354
355void Konsole::init(const char* _pgm, QStrList & _args) 355void Konsole::init(const char* _pgm, QStrList & _args)
356{ 356{
357 357
358#if 0 358#if 0
359 for(int i=1; i<=31; i++) 359 for(int i=1; i<=31; i++)
360 { 360 {
361 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV 361 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV
362 && i != SIGINT && i != SIGILL && i != SIGTERM 362 && i != SIGINT && i != SIGILL && i != SIGTERM
363 && i != SIGBUS) 363 && i != SIGBUS)