author | llornkcor <llornkcor> | 2005-02-06 02:25:25 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-02-06 02:25:25 (UTC) |
commit | c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d (patch) (side-by-side diff) | |
tree | f4d401a3479c04923e11da27ef976bd21df4d12c | |
parent | 57d3426a26a2695be0d5358c99be3db9a90da806 (diff) | |
download | opie-c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d.zip opie-c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d.tar.gz opie-c3892e6c1a4ca15383a7da48f6d72b1d7d26f43d.tar.bz2 |
adding shell history into command combo off by default
-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 43 |
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 @@ -195,258 +195,243 @@ static const char *commonCmds[] = "sort", "touch", "umount", "mknod", "netstat", */ "exit", NULL }; static void konsoleInit(const char** shell) { if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl; if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl; // drop privileges // QPEApplication::grabKeyboard(); // for CTRL and ALT odebug << "keyboard grabbed" << oendl; #ifdef FAKE_CTRL_AND_ALT odebug << "Fake Ctrl and Alt defined" << oendl; QPEApplication::grabKeyboard(); // for CTRL and ALT #endif *shell = getenv("SHELL"); owarn << "SHell initially is " << *shell << "" << oendl; 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(); } if( putenv((char*)"COLORTERM=") !=0) odebug << "putenv failed" << oendl; // to trigger mc's color detection } Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { QStrList tmp; const char* shell; konsoleInit( &shell); init(shell,tmp); } Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) : QMainWindow(0, name) { init(_pgm,_args); } struct HistoryItem { HistoryItem(int c, const QString &l) { count = c; line = l; } int count; QString line; }; class HistoryList : public QList<HistoryItem> { virtual int compareItems( QCollection::Item item1, QCollection::Item item2) { int c1 = ((HistoryItem*)item1)->count; int c2 = ((HistoryItem*)item2)->count; if (c1 > c2) return(1); if (c1 < c2) return(-1); return(0); } }; void Konsole::initCommandList() { // odebug << "Konsole::initCommandList" << oendl; Config cfg( "Konsole" ); cfg.setGroup("Commands"); // commonCombo->setInsertionPolicy(QComboBox::AtCurrent); commonCombo->clear(); - if (cfg.readEntry("ShellHistory","TRUE") == "TRUE") - { + if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") { QString histfilename = QString(getenv("HOME")) + "/.bash_history"; histfilename = cfg.readEntry("ShellHistoryPath",histfilename); QFile histfile(histfilename); // note: compiler barfed on: // QFile histfile(QString(getenv("HOME")) + "/.bash_history"); - if (histfile.open( IO_ReadOnly )) - { + if (histfile.open( IO_ReadOnly )) { QString line; uint i; HistoryList items; int lineno = 0; - while(!histfile.atEnd()) - { - if (histfile.readLine(line, 200) < 0) - { + while(!histfile.atEnd()) { + if (histfile.readLine(line, 200) < 0) { break; } line = line.left(line.length()-1); lineno++; - for(i=0; i<items.count(); i++) - { - if (line == items.at(i)->line) - { + for(i=0; i<items.count(); i++) { + if (line == items.at(i)->line) { // weight recent commands & repeated commands more // by adding up the index of each command items.at(i)->count += lineno; break; } } - if (i >= items.count()) - { + if (i >= items.count()) { items.append(new HistoryItem(lineno, line)); } } items.sort(); int n = items.count(); - if (n > 40) - { + if (n > 40) { n = 40; } - for(int i=0; i<n; i++) - { + for(int i=0; i<n; i++) { // should insert start of command, but keep whole thing - if (items.at(items.count()-i-1)->line.length() < 30) - { + if (items.at(items.count()-i-1)->line.length() < 30) { commonCombo->insertItem(items.at(items.count()-i-1)->line); } } histfile.close(); } } - if (cfg.readEntry("Commands Set","FALSE") == "FALSE") - { - for (int i = 0; commonCmds[i] != NULL; i++) - { + if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { + for (int i = 0; commonCmds[i] != NULL; i++) { commonCombo->insertItem(commonCmds[i]); } - } - else - { - for (int i = 0; i < 100; i++) - { + } else { + for (int i = 0; i < 100; i++) { if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) commonCombo->insertItem(cfg.readEntry( QString::number(i),"")); } } } static void sig_handler(int x) { printf("got signal %d\n",x); } void Konsole::init(const char* _pgm, QStrList & _args) { #if 0 for(int i=1; i<=31; i++) { if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV && i != SIGINT && i != SIGILL && i != SIGTERM && i != SIGBUS) signal(i,sig_handler); } #endif signal(SIGSTOP, sig_handler); signal(SIGCONT, sig_handler); signal(SIGTSTP, sig_handler); b_scroll = TRUE; // histon; n_keytab = 0; n_render = 0; startUp=0; fromMenu = FALSE; fullscreen = false; setCaption( tr( "Konsole" ) ); setIcon( Resource::loadPixmap( "konsole/Terminal" ) ); Config cfg( "Konsole" ); cfg.setGroup("Font"); QString tmp; // initialize the list of allowed fonts /////////////////////////////////// QString cfgFontName = cfg.readEntry("FontName","Lcfont"); int cfgFontSize = cfg.readNumEntry("FontSize",18); cfont = -1; // this code causes repeated access to all the font files // which does slow down startup QFontDatabase fontDB; QStringList familyNames; familyNames = fontDB.families( FALSE ); QString s; int fontIndex = 0; int familyNum = 0; fontList = new QPopupMenu( this ); for(uint j = 0; j < (uint)familyNames.count(); j++) { s = familyNames[j]; if ( s.contains('-') ) { int i = s.find('-'); s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]"; } s[0] = s[0].upper(); QValueList<int> sizes = fontDB.pointSizes( familyNames[j] ); printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(), sizes.count()); if (sizes.count() > 0) { QPopupMenu *sizeMenu; QFont f; int last_width = -1; sizeMenu = NULL; for(uint i = 0; i < (uint)sizes.count() + 4; i++) { // printf("family %s size %d ", familyNames[j].latin1(), sizes[i]); // need to divide by 10 on the Z, but not otherwise int size; if (i >= (uint)sizes.count()) { // try for expandable fonts size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1); } else { printf("sizes[%d] = %d\n", i, sizes[i]); |