summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/konsole.cpp
Unidiff
Diffstat (limited to 'core/apps/embeddedkonsole/konsole.cpp') (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
@@ -243,162 +243,147 @@ static void konsoleInit(const char** shell) {
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