summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-02-06 02:25:25 (UTC)
committer llornkcor <llornkcor>2005-02-06 02:25:25 (UTC)
commitc3892e6c1a4ca15383a7da48f6d72b1d7d26f43d (patch) (unidiff)
treef4d401a3479c04923e11da27ef976bd21df4d12c
parent57d3426a26a2695be0d5358c99be3db9a90da806 (diff)
downloadopie-c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d.zip
opie-c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d.tar.gz
opie-c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d.tar.bz2
adding shell history into command combo off by default
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp43
1 files changed, 14 insertions, 29 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index 5cfd644..8b4202d 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -163,322 +163,307 @@ static const char *commonCmds[] =
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") == "TRUE") 291 if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") {
292 {
293 QString histfilename = QString(getenv("HOME")) + "/.bash_history"; 292 QString histfilename = QString(getenv("HOME")) + "/.bash_history";
294 histfilename = cfg.readEntry("ShellHistoryPath",histfilename); 293 histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
295 QFile histfile(histfilename); 294 QFile histfile(histfilename);
296 // note: compiler barfed on: 295 // note: compiler barfed on:
297 // QFile histfile(QString(getenv("HOME")) + "/.bash_history"); 296 // QFile histfile(QString(getenv("HOME")) + "/.bash_history");
298 if (histfile.open( IO_ReadOnly )) 297 if (histfile.open( IO_ReadOnly )) {
299 {
300 QString line; 298 QString line;
301 uint i; 299 uint i;
302 HistoryList items; 300 HistoryList items;
303 301
304 int lineno = 0; 302 int lineno = 0;
305 while(!histfile.atEnd()) 303 while(!histfile.atEnd()) {
306 { 304 if (histfile.readLine(line, 200) < 0) {
307 if (histfile.readLine(line, 200) < 0)
308 {
309 break; 305 break;
310 } 306 }
311 line = line.left(line.length()-1); 307 line = line.left(line.length()-1);
312 lineno++; 308 lineno++;
313 309
314 for(i=0; i<items.count(); i++) 310 for(i=0; i<items.count(); i++) {
315 { 311 if (line == items.at(i)->line) {
316 if (line == items.at(i)->line)
317 {
318 // weight recent commands & repeated commands more 312 // weight recent commands & repeated commands more
319 // by adding up the index of each command 313 // by adding up the index of each command
320 items.at(i)->count += lineno; 314 items.at(i)->count += lineno;
321 break; 315 break;
322 } 316 }
323 } 317 }
324 if (i >= items.count()) 318 if (i >= items.count()) {
325 {
326 items.append(new HistoryItem(lineno, line)); 319 items.append(new HistoryItem(lineno, line));
327 } 320 }
328 } 321 }
329 items.sort(); 322 items.sort();
330 int n = items.count(); 323 int n = items.count();
331 if (n > 40) 324 if (n > 40) {
332 {
333 n = 40; 325 n = 40;
334 } 326 }
335 for(int i=0; i<n; i++) 327 for(int i=0; i<n; i++) {
336 {
337 // should insert start of command, but keep whole thing 328 // should insert start of command, but keep whole thing
338 if (items.at(items.count()-i-1)->line.length() < 30) 329 if (items.at(items.count()-i-1)->line.length() < 30) {
339 {
340 commonCombo->insertItem(items.at(items.count()-i-1)->line); 330 commonCombo->insertItem(items.at(items.count()-i-1)->line);
341 } 331 }
342 } 332 }
343 histfile.close(); 333 histfile.close();
344 } 334 }
345 } 335 }
346 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") 336 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
347 { 337 for (int i = 0; commonCmds[i] != NULL; i++) {
348 for (int i = 0; commonCmds[i] != NULL; i++)
349 {
350 commonCombo->insertItem(commonCmds[i]); 338 commonCombo->insertItem(commonCmds[i]);
351 } 339 }
352 } 340 } else {
353 else 341 for (int i = 0; i < 100; i++) {
354 {
355 for (int i = 0; i < 100; i++)
356 {
357 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 342 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
358 commonCombo->insertItem(cfg.readEntry( QString::number(i),"")); 343 commonCombo->insertItem(cfg.readEntry( QString::number(i),""));
359 } 344 }
360 } 345 }
361 346
362 347
363} 348}
364 349
365static void sig_handler(int x) 350static void sig_handler(int x)
366{ 351{
367 printf("got signal %d\n",x); 352 printf("got signal %d\n",x);
368} 353}
369 354
370void Konsole::init(const char* _pgm, QStrList & _args) 355void Konsole::init(const char* _pgm, QStrList & _args)
371{ 356{
372 357
373#if 0 358#if 0
374 for(int i=1; i<=31; i++) 359 for(int i=1; i<=31; i++)
375 { 360 {
376 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV 361 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV
377 && i != SIGINT && i != SIGILL && i != SIGTERM 362 && i != SIGINT && i != SIGILL && i != SIGTERM
378 && i != SIGBUS) 363 && i != SIGBUS)
379 signal(i,sig_handler); 364 signal(i,sig_handler);
380 } 365 }
381#endif 366#endif
382 signal(SIGSTOP, sig_handler); 367 signal(SIGSTOP, sig_handler);
383 signal(SIGCONT, sig_handler); 368 signal(SIGCONT, sig_handler);
384 signal(SIGTSTP, sig_handler); 369 signal(SIGTSTP, sig_handler);
385 370
386 b_scroll = TRUE; // histon; 371 b_scroll = TRUE; // histon;
387 n_keytab = 0; 372 n_keytab = 0;
388 n_render = 0; 373 n_render = 0;
389 startUp=0; 374 startUp=0;
390 fromMenu = FALSE; 375 fromMenu = FALSE;
391 fullscreen = false; 376 fullscreen = false;
392 377
393 setCaption( tr( "Konsole" ) ); 378 setCaption( tr( "Konsole" ) );
394 setIcon( Resource::loadPixmap( "konsole/Terminal" ) ); 379 setIcon( Resource::loadPixmap( "konsole/Terminal" ) );
395 380
396 Config cfg( "Konsole" ); 381 Config cfg( "Konsole" );
397 cfg.setGroup("Font"); 382 cfg.setGroup("Font");
398 QString tmp; 383 QString tmp;
399 384
400 // initialize the list of allowed fonts /////////////////////////////////// 385 // initialize the list of allowed fonts ///////////////////////////////////
401 386
402 QString cfgFontName = cfg.readEntry("FontName","Lcfont"); 387 QString cfgFontName = cfg.readEntry("FontName","Lcfont");
403 int cfgFontSize = cfg.readNumEntry("FontSize",18); 388 int cfgFontSize = cfg.readNumEntry("FontSize",18);
404 389
405 cfont = -1; 390 cfont = -1;
406 391
407 // this code causes repeated access to all the font files 392 // this code causes repeated access to all the font files
408 // which does slow down startup 393 // which does slow down startup
409 QFontDatabase fontDB; 394 QFontDatabase fontDB;
410 QStringList familyNames; 395 QStringList familyNames;
411 familyNames = fontDB.families( FALSE ); 396 familyNames = fontDB.families( FALSE );
412 QString s; 397 QString s;
413 int fontIndex = 0; 398 int fontIndex = 0;
414 int familyNum = 0; 399 int familyNum = 0;
415 fontList = new QPopupMenu( this ); 400 fontList = new QPopupMenu( this );
416 401
417 for(uint j = 0; j < (uint)familyNames.count(); j++) 402 for(uint j = 0; j < (uint)familyNames.count(); j++)
418 { 403 {
419 s = familyNames[j]; 404 s = familyNames[j];
420 if ( s.contains('-') ) 405 if ( s.contains('-') )
421 { 406 {
422 int i = s.find('-'); 407 int i = s.find('-');
423 s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]"; 408 s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]";
424 } 409 }
425 s[0] = s[0].upper(); 410 s[0] = s[0].upper();
426 411
427 QValueList<int> sizes = fontDB.pointSizes( familyNames[j] ); 412 QValueList<int> sizes = fontDB.pointSizes( familyNames[j] );
428 413
429 printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(), 414 printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(),
430 sizes.count()); 415 sizes.count());
431 416
432 if (sizes.count() > 0) 417 if (sizes.count() > 0)
433 { 418 {
434 QPopupMenu *sizeMenu; 419 QPopupMenu *sizeMenu;
435 QFont f; 420 QFont f;
436 int last_width = -1; 421 int last_width = -1;
437 sizeMenu = NULL; 422 sizeMenu = NULL;
438 423
439 for(uint i = 0; i < (uint)sizes.count() + 4; i++) 424 for(uint i = 0; i < (uint)sizes.count() + 4; i++)
440 { 425 {
441 // printf("family %s size %d ", familyNames[j].latin1(), sizes[i]); 426 // printf("family %s size %d ", familyNames[j].latin1(), sizes[i]);
442 // need to divide by 10 on the Z, but not otherwise 427 // need to divide by 10 on the Z, but not otherwise
443 int size; 428 int size;
444 429
445 if (i >= (uint)sizes.count()) 430 if (i >= (uint)sizes.count())
446 { 431 {
447 // try for expandable fonts 432 // try for expandable fonts
448 size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1); 433 size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1);
449 } 434 }
450 else 435 else
451 { 436 {
452 printf("sizes[%d] = %d\n", i, sizes[i]); 437 printf("sizes[%d] = %d\n", i, sizes[i]);
453 size = sizes[i]; 438 size = sizes[i];
454 } 439 }
455 440
456 f = QFont(familyNames[j], size); 441 f = QFont(familyNames[j], size);
457 f.setFixedPitch(true); 442 f.setFixedPitch(true);
458 QFontMetrics fm(f); 443 QFontMetrics fm(f);
459 // don't trust f.fixedPitch() or f.exactMatch(), they lie!! 444 // don't trust f.fixedPitch() or f.exactMatch(), they lie!!
460 if (fm.width("l") == fm.width("m") 445 if (fm.width("l") == fm.width("m")
461 && (i < (uint)sizes.count() 446 && (i < (uint)sizes.count()
462 || fm.width("m") > last_width)) 447 || fm.width("m") > last_width))
463 { 448 {
464 if (i < (uint)sizes.count()) 449 if (i < (uint)sizes.count())
465 { 450 {
466 last_width = fm.width("m"); 451 last_width = fm.width("m");
467 } 452 }
468 if (sizeMenu == NULL) 453 if (sizeMenu == NULL)
469 { 454 {
470 sizeMenu = new QPopupMenu(); 455 sizeMenu = new QPopupMenu();
471 } 456 }
472 int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex); 457 int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex);
473 sizeMenu->setItemParameter(id, fontIndex); 458 sizeMenu->setItemParameter(id, fontIndex);
474 sizeMenu->connectItem(id, this, SLOT(setFont(int))); 459 sizeMenu->connectItem(id, this, SLOT(setFont(int)));
475 QString name = s + " " + QString::number(size); 460 QString name = s + " " + QString::number(size);
476 fonts.append(new VTFont(name, f, familyNames[j], familyNum, size)); 461 fonts.append(new VTFont(name, f, familyNames[j], familyNum, size));
477 if (familyNames[j] == cfgFontName && size == cfgFontSize) 462 if (familyNames[j] == cfgFontName && size == cfgFontSize)
478 { 463 {
479 cfont = fontIndex; 464 cfont = fontIndex;
480 } 465 }
481 printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size); 466 printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size);
482 fontIndex++; 467 fontIndex++;
483 } 468 }
484 } 469 }