-rw-r--r-- | core/apps/textedit/textedit.cpp | 33 | ||||
-rw-r--r-- | core/launcher/qprocess_unix.cpp | 6 | ||||
-rw-r--r-- | core/launcher/server.cpp | 19 | ||||
-rw-r--r-- | core/settings/launcher/menusettings.cpp | 5 | ||||
-rw-r--r-- | core/settings/launcher/taskbarsettings.cpp | 13 | ||||
-rw-r--r-- | libopie2/opiecore/oglobal.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiecore/oprocess.cpp | 2 | ||||
-rw-r--r-- | library/global.cpp | 63 | ||||
-rw-r--r-- | noncore/apps/advancedfm/output.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katebuffer.cpp | 5 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 9 |
11 files changed, 94 insertions, 68 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 759e440..61beac5 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -281,784 +281,785 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
281 | nAdvanced = new QAction( tr("Prompt on Exit"), | 281 | nAdvanced = new QAction( tr("Prompt on Exit"), |
282 | QString::null, 0, this, 0 ); | 282 | QString::null, 0, this, 0 ); |
283 | connect( nAdvanced, SIGNAL( toggled(bool) ), | 283 | connect( nAdvanced, SIGNAL( toggled(bool) ), |
284 | this, SLOT( doPrompt(bool) ) ); | 284 | this, SLOT( doPrompt(bool) ) ); |
285 | nAdvanced->setToggleAction(true); | 285 | nAdvanced->setToggleAction(true); |
286 | nAdvanced->addTo( advancedMenu ); | 286 | nAdvanced->addTo( advancedMenu ); |
287 | 287 | ||
288 | desktopAction = new QAction( tr("Always open linked file"), | 288 | desktopAction = new QAction( tr("Always open linked file"), |
289 | QString::null, 0, this, 0 ); | 289 | QString::null, 0, this, 0 ); |
290 | connect( desktopAction, SIGNAL( toggled(bool) ), | 290 | connect( desktopAction, SIGNAL( toggled(bool) ), |
291 | this, SLOT( doDesktop(bool) ) ); | 291 | this, SLOT( doDesktop(bool) ) ); |
292 | desktopAction->setToggleAction(true); | 292 | desktopAction->setToggleAction(true); |
293 | desktopAction->addTo( advancedMenu); | 293 | desktopAction->addTo( advancedMenu); |
294 | 294 | ||
295 | filePermAction = new QAction( tr("File Permissions"), | 295 | filePermAction = new QAction( tr("File Permissions"), |
296 | QString::null, 0, this, 0 ); | 296 | QString::null, 0, this, 0 ); |
297 | connect( filePermAction, SIGNAL( toggled(bool) ), | 297 | connect( filePermAction, SIGNAL( toggled(bool) ), |
298 | this, SLOT( doFilePerms(bool) ) ); | 298 | this, SLOT( doFilePerms(bool) ) ); |
299 | filePermAction->setToggleAction(true); | 299 | filePermAction->setToggleAction(true); |
300 | filePermAction->addTo( advancedMenu); | 300 | filePermAction->addTo( advancedMenu); |
301 | 301 | ||
302 | searchBarAction = new QAction( tr("Search Bar Open"), | 302 | searchBarAction = new QAction( tr("Search Bar Open"), |
303 | QString::null, 0, this, 0 ); | 303 | QString::null, 0, this, 0 ); |
304 | connect( searchBarAction, SIGNAL( toggled(bool) ), | 304 | connect( searchBarAction, SIGNAL( toggled(bool) ), |
305 | this, SLOT( setSearchBar(bool) ) ); | 305 | this, SLOT( setSearchBar(bool) ) ); |
306 | searchBarAction->setToggleAction(true); | 306 | searchBarAction->setToggleAction(true); |
307 | searchBarAction->addTo( advancedMenu); | 307 | searchBarAction->addTo( advancedMenu); |
308 | 308 | ||
309 | nAutoSave = new QAction( tr("Auto Save 5 min."), | 309 | nAutoSave = new QAction( tr("Auto Save 5 min."), |
310 | QString::null, 0, this, 0 ); | 310 | QString::null, 0, this, 0 ); |
311 | connect( nAutoSave, SIGNAL( toggled(bool) ), | 311 | connect( nAutoSave, SIGNAL( toggled(bool) ), |
312 | this, SLOT( doTimer(bool) ) ); | 312 | this, SLOT( doTimer(bool) ) ); |
313 | nAutoSave->setToggleAction(true); | 313 | nAutoSave->setToggleAction(true); |
314 | nAutoSave->addTo( advancedMenu); | 314 | nAutoSave->addTo( advancedMenu); |
315 | 315 | ||
316 | 316 | ||
317 | //font->insertSeparator(); | 317 | //font->insertSeparator(); |
318 | 318 | ||
319 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 319 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
320 | 320 | ||
321 | mb->insertItem( tr( "File" ), file ); | 321 | mb->insertItem( tr( "File" ), file ); |
322 | mb->insertItem( tr( "Edit" ), edit ); | 322 | mb->insertItem( tr( "Edit" ), edit ); |
323 | mb->insertItem( tr( "View" ), font ); | 323 | mb->insertItem( tr( "View" ), font ); |
324 | 324 | ||
325 | searchBar = new QToolBar(this); | 325 | searchBar = new QToolBar(this); |
326 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 326 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
327 | 327 | ||
328 | searchBar->setHorizontalStretchable( true ); | 328 | searchBar->setHorizontalStretchable( true ); |
329 | 329 | ||
330 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 330 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
331 | searchBar->setStretchableWidget( searchEdit ); | 331 | searchBar->setStretchableWidget( searchEdit ); |
332 | connect( searchEdit, SIGNAL( textChanged(const QString&) ), | 332 | connect( searchEdit, SIGNAL( textChanged(const QString&) ), |
333 | this, SLOT( search() ) ); | 333 | this, SLOT( search() ) ); |
334 | 334 | ||
335 | a = new QAction( tr( "Find Next" ), Opie::Core::OResource::loadPixmap( "next", Opie::Core::OResource::SmallIcon ), | 335 | a = new QAction( tr( "Find Next" ), Opie::Core::OResource::loadPixmap( "next", Opie::Core::OResource::SmallIcon ), |
336 | QString::null, 0, this, 0 ); | 336 | QString::null, 0, this, 0 ); |
337 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 337 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
338 | a->addTo( searchBar ); | 338 | a->addTo( searchBar ); |
339 | a->addTo( edit ); | 339 | a->addTo( edit ); |
340 | 340 | ||
341 | a = new QAction( tr( "Close Find" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ), | 341 | a = new QAction( tr( "Close Find" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ), |
342 | QString::null, 0, this, 0 ); | 342 | QString::null, 0, this, 0 ); |
343 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 343 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
344 | a->addTo( searchBar ); | 344 | a->addTo( searchBar ); |
345 | 345 | ||
346 | edit->insertSeparator(); | 346 | edit->insertSeparator(); |
347 | a = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ), | 347 | a = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ), |
348 | QString::null, 0, this, 0 ); | 348 | QString::null, 0, this, 0 ); |
349 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 349 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
350 | a->addTo( edit ); | 350 | a->addTo( edit ); |
351 | 351 | ||
352 | searchBar->hide(); | 352 | searchBar->hide(); |
353 | 353 | ||
354 | editor = new QpeEditor( this ); | 354 | editor = new QpeEditor( this ); |
355 | setCentralWidget( editor ); | 355 | setCentralWidget( editor ); |
356 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 356 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
357 | connect( editor, SIGNAL( textChanged() ), | 357 | connect( editor, SIGNAL( textChanged() ), |
358 | this, SLOT( editorChanged() ) ); | 358 | this, SLOT( editorChanged() ) ); |
359 | 359 | ||
360 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 360 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
361 | 361 | ||
362 | Config cfg("TextEdit"); | 362 | Config cfg("TextEdit"); |
363 | cfg. setGroup ( "Font" ); | 363 | cfg. setGroup ( "Font" ); |
364 | 364 | ||
365 | QFont defaultFont = editor-> font ( ); | 365 | QFont defaultFont = editor-> font ( ); |
366 | 366 | ||
367 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 367 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
368 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 368 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
369 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 369 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
370 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 370 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
371 | 371 | ||
372 | defaultFont = QFont ( family, size, weight, italic ); | 372 | defaultFont = QFont ( family, size, weight, italic ); |
373 | editor-> setFont ( defaultFont ); | 373 | editor-> setFont ( defaultFont ); |
374 | // updateCaption(); | 374 | // updateCaption(); |
375 | 375 | ||
376 | cfg.setGroup ( "View" ); | 376 | cfg.setGroup ( "View" ); |
377 | 377 | ||
378 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 378 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
379 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 379 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
380 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 380 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
381 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 381 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
382 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 382 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
383 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | 383 | featureAutoSave = cfg.readBoolEntry( "autosave", false); |
384 | 384 | ||
385 | if(useSearchBar) searchBarAction->setOn(true); | 385 | if(useSearchBar) searchBarAction->setOn(true); |
386 | if(promptExit) nAdvanced->setOn( true ); | 386 | if(promptExit) nAdvanced->setOn( true ); |
387 | if(openDesktop) desktopAction->setOn( true ); | 387 | if(openDesktop) desktopAction->setOn( true ); |
388 | if(filePerms) filePermAction->setOn( true ); | 388 | if(filePerms) filePermAction->setOn( true ); |
389 | if(startWithNew) nStart->setOn( true ); | 389 | if(startWithNew) nStart->setOn( true ); |
390 | if(featureAutoSave) nAutoSave->setOn(true); | 390 | if(featureAutoSave) nAutoSave->setOn(true); |
391 | 391 | ||
392 | // { | 392 | // { |
393 | // doTimer(true); | 393 | // doTimer(true); |
394 | // } | 394 | // } |
395 | 395 | ||
396 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 396 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
397 | wa-> setOn ( wrap ); | 397 | wa-> setOn ( wrap ); |
398 | setWordWrap ( wrap ); | 398 | setWordWrap ( wrap ); |
399 | 399 | ||
400 | ///////////////// | 400 | ///////////////// |
401 | if( qApp->argc() > 1) { | 401 | if( qApp->argc() > 1) { |
402 | currentFileName=qApp->argv()[1]; | 402 | currentFileName=qApp->argv()[1]; |
403 | 403 | ||
404 | QFileInfo fi(currentFileName); | 404 | QFileInfo fi(currentFileName); |
405 | 405 | ||
406 | if(fi.baseName().left(1) == "") { | 406 | if(fi.baseName().left(1) == "") { |
407 | openDotFile(currentFileName); | 407 | openDotFile(currentFileName); |
408 | } else { | 408 | } else { |
409 | openFile(currentFileName); | 409 | openFile(currentFileName); |
410 | } | 410 | } |
411 | } else { | 411 | } else { |
412 | edited1=false; | 412 | edited1=false; |
413 | openDotFile(""); | 413 | openDotFile(""); |
414 | } | 414 | } |
415 | 415 | ||
416 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 416 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
417 | } | 417 | } |
418 | 418 | ||
419 | TextEdit::~TextEdit() { | 419 | TextEdit::~TextEdit() { |
420 | if( edited1 && !promptExit) { | 420 | if( edited1 && !promptExit) { |
421 | switch( savePrompt() ) { | 421 | switch( savePrompt() ) { |
422 | case 1: { | 422 | case 1: { |
423 | saveAs(); | 423 | saveAs(); |
424 | } | 424 | } |
425 | break; | 425 | break; |
426 | }; | 426 | }; |
427 | } | 427 | } |
428 | 428 | ||
429 | delete editor; | 429 | delete editor; |
430 | } | 430 | } |
431 | 431 | ||
432 | void TextEdit::closeEvent(QCloseEvent *) { | 432 | void TextEdit::closeEvent(QCloseEvent *) { |
433 | if( promptExit) { | 433 | if( promptExit) { |
434 | switch( savePrompt() ) { | 434 | switch( savePrompt() ) { |
435 | case 1: { | 435 | case 1: { |
436 | saveAs(); | 436 | saveAs(); |
437 | qApp->quit(); | 437 | qApp->quit(); |
438 | } | 438 | } |
439 | break; | 439 | break; |
440 | 440 | ||
441 | case 2: { | 441 | case 2: { |
442 | qApp->quit(); | 442 | qApp->quit(); |
443 | } | 443 | } |
444 | break; | 444 | break; |
445 | 445 | ||
446 | case -1: | 446 | case -1: |
447 | break; | 447 | break; |
448 | }; | 448 | }; |
449 | } | 449 | } |
450 | else | 450 | else |
451 | qApp->quit(); | 451 | qApp->quit(); |
452 | } | 452 | } |
453 | 453 | ||
454 | void TextEdit::cleanUp() { | 454 | void TextEdit::cleanUp() { |
455 | 455 | ||
456 | Config cfg ( "TextEdit" ); | 456 | Config cfg ( "TextEdit" ); |
457 | cfg. setGroup ( "Font" ); | 457 | cfg. setGroup ( "Font" ); |
458 | QFont f = editor->font(); | 458 | QFont f = editor->font(); |
459 | cfg.writeEntry ( "Family", f. family ( )); | 459 | cfg.writeEntry ( "Family", f. family ( )); |
460 | cfg.writeEntry ( "Size", f. pointSize ( )); | 460 | cfg.writeEntry ( "Size", f. pointSize ( )); |
461 | cfg.writeEntry ( "Weight", f. weight ( )); | 461 | cfg.writeEntry ( "Weight", f. weight ( )); |
462 | cfg.writeEntry ( "Italic", f. italic ( )); | 462 | cfg.writeEntry ( "Italic", f. italic ( )); |
463 | 463 | ||
464 | cfg.setGroup ( "View" ); | 464 | cfg.setGroup ( "View" ); |
465 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 465 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
466 | cfg.writeEntry ( "FileView", viewSelection ); | 466 | cfg.writeEntry ( "FileView", viewSelection ); |
467 | 467 | ||
468 | cfg.writeEntry ( "PromptExit", promptExit ); | 468 | cfg.writeEntry ( "PromptExit", promptExit ); |
469 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 469 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
470 | cfg.writeEntry ( "FilePermissions", filePerms ); | 470 | cfg.writeEntry ( "FilePermissions", filePerms ); |
471 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 471 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
472 | cfg.writeEntry ( "startNew", startWithNew ); | 472 | cfg.writeEntry ( "startNew", startWithNew ); |
473 | 473 | ||
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | void TextEdit::accept() { | 477 | void TextEdit::accept() { |
478 | if( edited1) | 478 | if( edited1) |
479 | saveAs(); | 479 | saveAs(); |
480 | qApp->quit(); | 480 | qApp->quit(); |
481 | } | 481 | } |
482 | 482 | ||
483 | void TextEdit::zoomIn() { | 483 | void TextEdit::zoomIn() { |
484 | setFontSize(editor->font().pointSize()+1,false); | 484 | setFontSize(editor->font().pointSize()+1,false); |
485 | } | 485 | } |
486 | 486 | ||
487 | void TextEdit::zoomOut() { | 487 | void TextEdit::zoomOut() { |
488 | setFontSize(editor->font().pointSize()-1,true); | 488 | setFontSize(editor->font().pointSize()-1,true); |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 492 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
493 | int s=10; | 493 | int s=10; |
494 | for (int i=0; i<nfontsizes; i++) { | 494 | for (int i=0; i<nfontsizes; i++) { |
495 | if ( fontsize[i] == sz ) { | 495 | if ( fontsize[i] == sz ) { |
496 | s = sz; | 496 | s = sz; |
497 | break; | 497 | break; |
498 | } else if ( round_down_not_up ) { | 498 | } else if ( round_down_not_up ) { |
499 | if ( fontsize[i] < sz ) | 499 | if ( fontsize[i] < sz ) |
500 | s = fontsize[i]; | 500 | s = fontsize[i]; |
501 | } else { | 501 | } else { |
502 | if ( fontsize[i] > sz ) { | 502 | if ( fontsize[i] > sz ) { |
503 | s = fontsize[i]; | 503 | s = fontsize[i]; |
504 | break; | 504 | break; |
505 | } | 505 | } |
506 | } | 506 | } |
507 | } | 507 | } |
508 | 508 | ||
509 | QFont f = editor->font(); | 509 | QFont f = editor->font(); |
510 | f.setPointSize(s); | 510 | f.setPointSize(s); |
511 | editor->setFont(f); | 511 | editor->setFont(f); |
512 | 512 | ||
513 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 513 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
514 | zout->setEnabled(s != fontsize[0]); | 514 | zout->setEnabled(s != fontsize[0]); |
515 | } | 515 | } |
516 | 516 | ||
517 | void TextEdit::setBold(bool y) { | 517 | void TextEdit::setBold(bool y) { |
518 | QFont f = editor->font(); | 518 | QFont f = editor->font(); |
519 | f.setBold(y); | 519 | f.setBold(y); |
520 | editor->setFont(f); | 520 | editor->setFont(f); |
521 | } | 521 | } |
522 | 522 | ||
523 | void TextEdit::setItalic(bool y) { | 523 | void TextEdit::setItalic(bool y) { |
524 | QFont f = editor->font(); | 524 | QFont f = editor->font(); |
525 | f.setItalic(y); | 525 | f.setItalic(y); |
526 | editor->setFont(f); | 526 | editor->setFont(f); |
527 | } | 527 | } |
528 | 528 | ||
529 | void TextEdit::setWordWrap(bool y) { | 529 | void TextEdit::setWordWrap(bool y) { |
530 | bool state = editor->edited(); | 530 | bool state = editor->edited(); |
531 | QString captionStr = caption(); | 531 | QString captionStr = caption(); |
532 | bool b1 = edited1; | 532 | bool b1 = edited1; |
533 | bool b2 = edited; | 533 | bool b2 = edited; |
534 | 534 | ||
535 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 535 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
536 | editor->setEdited( state ); | 536 | editor->setEdited( state ); |
537 | edited1=b1; | 537 | edited1=b1; |
538 | edited=b2; | 538 | edited=b2; |
539 | setCaption(captionStr); | 539 | setCaption(captionStr); |
540 | } | 540 | } |
541 | 541 | ||
542 | void TextEdit::setSearchBar(bool b) { | 542 | void TextEdit::setSearchBar(bool b) { |
543 | useSearchBar=b; | 543 | useSearchBar=b; |
544 | Config cfg("TextEdit"); | 544 | Config cfg("TextEdit"); |
545 | cfg.setGroup("View"); | 545 | cfg.setGroup("View"); |
546 | cfg.writeEntry ( "SearchBar", b ); | 546 | cfg.writeEntry ( "SearchBar", b ); |
547 | searchBarAction->setOn(b); | 547 | searchBarAction->setOn(b); |
548 | if(b) | 548 | if(b) |
549 | searchBar->show(); | 549 | searchBar->show(); |
550 | else | 550 | else |
551 | searchBar->hide(); | 551 | searchBar->hide(); |
552 | editor->setFocus(); | 552 | editor->setFocus(); |
553 | } | 553 | } |
554 | 554 | ||
555 | void TextEdit::fileNew() { | 555 | void TextEdit::fileNew() { |
556 | // if( !bFromDocView ) { | 556 | // if( !bFromDocView ) { |
557 | // saveAs(); | 557 | // saveAs(); |
558 | // } | 558 | // } |
559 | newFile(DocLnk()); | 559 | newFile(DocLnk()); |
560 | } | 560 | } |
561 | 561 | ||
562 | void TextEdit::fileOpen() { | 562 | void TextEdit::fileOpen() { |
563 | Config cfg("TextEdit"); | 563 | Config cfg("TextEdit"); |
564 | cfg. setGroup ( "View" ); | 564 | cfg. setGroup ( "View" ); |
565 | QMap<QString, QStringList> map; | 565 | QMap<QString, QStringList> map; |
566 | map.insert(tr("All"), QStringList() ); | 566 | map.insert(tr("All"), QStringList() ); |
567 | QStringList text; | 567 | QStringList text; |
568 | text << "text/*"; | 568 | text << "text/*"; |
569 | map.insert(tr("Text"), text ); | 569 | map.insert(tr("Text"), text ); |
570 | text << "*"; | 570 | text << "*"; |
571 | map.insert(tr("All"), text ); | 571 | map.insert(tr("All"), text ); |
572 | QString str = OFileDialog::getOpenFileName( 2, | 572 | QString str = OFileDialog::getOpenFileName( 2, |
573 | QString::null , | 573 | QString::null , |
574 | QString::null, map); | 574 | QString::null, map); |
575 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) | 575 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) |
576 | { | 576 | { |
577 | openFile( str ); | 577 | openFile( str ); |
578 | } | 578 | } |
579 | else | 579 | else |
580 | updateCaption(); | 580 | updateCaption(); |
581 | } | 581 | } |
582 | 582 | ||
583 | void TextEdit::doSearchBar() { | 583 | void TextEdit::doSearchBar() { |
584 | if(!useSearchBar) | 584 | if(!useSearchBar) |
585 | searchBar->hide(); | 585 | searchBar->hide(); |
586 | else | 586 | else |
587 | searchBar->show(); | 587 | searchBar->show(); |
588 | } | 588 | } |
589 | 589 | ||
590 | #if 0 | 590 | #if 0 |
591 | void TextEdit::slotFind() { | 591 | void TextEdit::slotFind() { |
592 | FindDialog frmFind( tr("Text Editor"), this ); | 592 | FindDialog frmFind( tr("Text Editor"), this ); |
593 | connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), | 593 | connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), |
594 | editor, SLOT(slotDoFind(const QString&,bool,bool))); | 594 | editor, SLOT(slotDoFind(const QString&,bool,bool))); |
595 | 595 | ||
596 | //case sensitive, backwards, [category] | 596 | //case sensitive, backwards, [category] |
597 | 597 | ||
598 | connect( editor, SIGNAL(notFound()), | 598 | connect( editor, SIGNAL(notFound()), |
599 | &frmFind, SLOT(slotNotFound()) ); | 599 | &frmFind, SLOT(slotNotFound()) ); |
600 | connect( editor, SIGNAL(searchWrapped()), | 600 | connect( editor, SIGNAL(searchWrapped()), |
601 | &frmFind, SLOT(slotWrapAround()) ); | 601 | &frmFind, SLOT(slotWrapAround()) ); |
602 | 602 | ||
603 | frmFind.exec(); | 603 | frmFind.exec(); |
604 | 604 | ||
605 | 605 | ||
606 | } | 606 | } |
607 | #endif | 607 | #endif |
608 | 608 | ||
609 | void TextEdit::fileRevert() { | 609 | void TextEdit::fileRevert() { |
610 | clear(); | 610 | clear(); |
611 | fileOpen(); | 611 | fileOpen(); |
612 | } | 612 | } |
613 | 613 | ||
614 | void TextEdit::editCut() { | 614 | void TextEdit::editCut() { |
615 | #ifndef QT_NO_CLIPBOARD | 615 | #ifndef QT_NO_CLIPBOARD |
616 | editor->cut(); | 616 | editor->cut(); |
617 | #endif | 617 | #endif |
618 | } | 618 | } |
619 | 619 | ||
620 | void TextEdit::editCopy() { | 620 | void TextEdit::editCopy() { |
621 | #ifndef QT_NO_CLIPBOARD | 621 | #ifndef QT_NO_CLIPBOARD |
622 | editor->copy(); | 622 | editor->copy(); |
623 | #endif | 623 | #endif |
624 | } | 624 | } |
625 | 625 | ||
626 | void TextEdit::editPaste() { | 626 | void TextEdit::editPaste() { |
627 | #ifndef QT_NO_CLIPBOARD | 627 | #ifndef QT_NO_CLIPBOARD |
628 | editor->paste(); | 628 | editor->paste(); |
629 | #endif | 629 | #endif |
630 | } | 630 | } |
631 | 631 | ||
632 | void TextEdit::editFind() { | 632 | void TextEdit::editFind() { |
633 | searchBar->show(); | 633 | searchBar->show(); |
634 | searchEdit->setFocus(); | 634 | searchEdit->setFocus(); |
635 | } | 635 | } |
636 | 636 | ||
637 | void TextEdit::findNext() { | 637 | void TextEdit::findNext() { |
638 | editor->find( searchEdit->text(), false, false ); | 638 | editor->find( searchEdit->text(), false, false ); |
639 | 639 | ||
640 | } | 640 | } |
641 | 641 | ||
642 | void TextEdit::findClose() { | 642 | void TextEdit::findClose() { |
643 | searchBar->hide(); | 643 | searchBar->hide(); |
644 | } | 644 | } |
645 | 645 | ||
646 | void TextEdit::search() { | 646 | void TextEdit::search() { |
647 | editor->find( searchEdit->text(), false, false ); | 647 | editor->find( searchEdit->text(), false, false ); |
648 | } | 648 | } |
649 | 649 | ||
650 | void TextEdit::newFile( const DocLnk &f ) { | 650 | void TextEdit::newFile( const DocLnk &f ) { |
651 | DocLnk nf = f; | 651 | DocLnk nf = f; |
652 | nf.setType("text/plain"); | 652 | nf.setType("text/plain"); |
653 | clear(); | 653 | clear(); |
654 | setWState (WState_Reserved1 ); | 654 | setWState (WState_Reserved1 ); |
655 | editor->setFocus(); | 655 | editor->setFocus(); |
656 | doc = new DocLnk(nf); | 656 | doc = new DocLnk(nf); |
657 | currentFileName = "Unnamed"; | 657 | currentFileName = "Unnamed"; |
658 | odebug << "newFile "+currentFileName << oendl; | 658 | odebug << "newFile "+currentFileName << oendl; |
659 | updateCaption( currentFileName); | 659 | updateCaption( currentFileName); |
660 | // editor->setEdited( false); | 660 | // editor->setEdited( false); |
661 | } | 661 | } |
662 | 662 | ||
663 | void TextEdit::openDotFile( const QString &f ) { | 663 | void TextEdit::openDotFile( const QString &f ) { |
664 | if(!currentFileName.isEmpty()) { | 664 | if(!currentFileName.isEmpty()) { |
665 | currentFileName=f; | 665 | currentFileName=f; |
666 | 666 | ||
667 | odebug << "openFile dotfile " + currentFileName << oendl; | 667 | odebug << "openFile dotfile " + currentFileName << oendl; |
668 | QString txt; | 668 | QString txt; |
669 | QFile file(f); | 669 | QFile file(f); |
670 | file.open(IO_ReadWrite); | 670 | if (!file.open(IO_ReadWrite)) |
671 | QTextStream t(&file); | 671 | owarn << "Failed to open file " << file.name() << oendl; |
672 | while ( !t.atEnd()) { | 672 | else { |
673 | txt+=t.readLine()+"\n"; | 673 | QTextStream t(&file); |
674 | } | 674 | while ( !t.atEnd()) { |
675 | editor->setText(txt); | 675 | txt+=t.readLine()+"\n"; |
676 | editor->setEdited( false); | 676 | } |
677 | edited1=false; | 677 | editor->setText(txt); |
678 | edited=false; | 678 | editor->setEdited( false); |
679 | 679 | edited1=false; | |
680 | 680 | edited=false; | |
681 | } | ||
681 | } | 682 | } |
682 | updateCaption( currentFileName); | 683 | updateCaption( currentFileName); |
683 | } | 684 | } |
684 | 685 | ||
685 | void TextEdit::openFile( const QString &f ) { | 686 | void TextEdit::openFile( const QString &f ) { |
686 | odebug << "filename is "+ f << oendl; | 687 | odebug << "filename is "+ f << oendl; |
687 | QString filer; | 688 | QString filer; |
688 | QFileInfo fi( f); | 689 | QFileInfo fi( f); |
689 | // bFromDocView = true; | 690 | // bFromDocView = true; |
690 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 691 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
691 | { | 692 | { |
692 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) | 693 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) |
693 | { | 694 | { |
694 | case 0: //desktop | 695 | case 0: //desktop |
695 | filer = f; | 696 | filer = f; |
696 | break; | 697 | break; |
697 | case 1: //linked | 698 | case 1: //linked |
698 | DocLnk sf(f); | 699 | DocLnk sf(f); |
699 | filer = sf.file(); | 700 | filer = sf.file(); |
700 | break; | 701 | break; |
701 | }; | 702 | }; |
702 | } | 703 | } |
703 | else if(fi.baseName().left(1) == "") | 704 | else if(fi.baseName().left(1) == "") |
704 | { | 705 | { |
705 | odebug << "opening dotfile" << oendl; | 706 | odebug << "opening dotfile" << oendl; |
706 | currentFileName=f; | 707 | currentFileName=f; |
707 | openDotFile(currentFileName); | 708 | openDotFile(currentFileName); |
708 | return; | 709 | return; |
709 | } | 710 | } |
710 | /* | 711 | /* |
711 | * The problem is a file where Config(f).isValid() and it does not | 712 | * The problem is a file where Config(f).isValid() and it does not |
712 | * end with .desktop will be treated as desktop file | 713 | * end with .desktop will be treated as desktop file |
713 | */ | 714 | */ |
714 | else if (f.find(".desktop",0,true) != -1 ) | 715 | else if (f.find(".desktop",0,true) != -1 ) |
715 | { | 716 | { |
716 | DocLnk sf(f); | 717 | DocLnk sf(f); |
717 | filer = sf.file(); | 718 | filer = sf.file(); |
718 | if(filer.right(1) == "/") | 719 | if(filer.right(1) == "/") |
719 | filer = f; | 720 | filer = f; |
720 | 721 | ||
721 | } | 722 | } |
722 | else | 723 | else |
723 | filer = f; | 724 | filer = f; |
724 | 725 | ||
725 | DocLnk nf; | 726 | DocLnk nf; |
726 | nf.setType("text/plain"); | 727 | nf.setType("text/plain"); |
727 | nf.setFile(filer); | 728 | nf.setFile(filer); |
728 | currentFileName=filer; | 729 | currentFileName=filer; |
729 | 730 | ||
730 | nf.setName(fi.baseName()); | 731 | nf.setName(fi.baseName()); |
731 | openFile(nf); | 732 | openFile(nf); |
732 | 733 | ||
733 | odebug << "openFile string "+currentFileName << oendl; | 734 | odebug << "openFile string "+currentFileName << oendl; |
734 | 735 | ||
735 | showEditTools(); | 736 | showEditTools(); |
736 | // Show filename in caption | 737 | // Show filename in caption |
737 | QString name = filer; | 738 | QString name = filer; |
738 | int sep = name.findRev( '/' ); | 739 | int sep = name.findRev( '/' ); |
739 | if ( sep > 0 ) | 740 | if ( sep > 0 ) |
740 | name = name.mid( sep+1 ); | 741 | name = name.mid( sep+1 ); |
741 | updateCaption( name ); | 742 | updateCaption( name ); |
742 | } | 743 | } |
743 | 744 | ||
744 | void TextEdit::openFile( const DocLnk &f ) { | 745 | void TextEdit::openFile( const DocLnk &f ) { |
745 | // clear(); | 746 | // clear(); |
746 | // bFromDocView = true; | 747 | // bFromDocView = true; |
747 | FileManager fm; | 748 | FileManager fm; |
748 | QString txt; | 749 | QString txt; |
749 | currentFileName=f.file(); | 750 | currentFileName=f.file(); |
750 | odebug << "openFile doclnk " + currentFileName << oendl; | 751 | odebug << "openFile doclnk " + currentFileName << oendl; |
751 | if ( !fm.loadFile( f, txt ) ) { | 752 | if ( !fm.loadFile( f, txt ) ) { |
752 | // ####### could be a new file | 753 | // ####### could be a new file |
753 | odebug << "Cannot open file" << oendl; | 754 | odebug << "Cannot open file" << oendl; |
754 | } | 755 | } |
755 | // fileNew(); | 756 | // fileNew(); |
756 | if ( doc ) | 757 | if ( doc ) |
757 | delete doc; | 758 | delete doc; |
758 | doc = new DocLnk(f); | 759 | doc = new DocLnk(f); |
759 | editor->setText(txt); | 760 | editor->setText(txt); |
760 | editor->setEdited( false); | 761 | editor->setEdited( false); |
761 | edited1=false; | 762 | edited1=false; |
762 | edited=false; | 763 | edited=false; |
763 | 764 | ||
764 | doc->setName(currentFileName); | 765 | doc->setName(currentFileName); |
765 | updateCaption(); | 766 | updateCaption(); |
766 | setTimer(); | 767 | setTimer(); |
767 | } | 768 | } |
768 | 769 | ||
769 | void TextEdit::showEditTools() { | 770 | void TextEdit::showEditTools() { |
770 | menu->show(); | 771 | menu->show(); |
771 | editBar->show(); | 772 | editBar->show(); |
772 | if(!useSearchBar) | 773 | if(!useSearchBar) |
773 | searchBar->hide(); | 774 | searchBar->hide(); |
774 | else | 775 | else |
775 | searchBar->show(); | 776 | searchBar->show(); |
776 | setWState (WState_Reserved1 ); | 777 | setWState (WState_Reserved1 ); |
777 | } | 778 | } |
778 | 779 | ||
779 | /*! | 780 | /*! |
780 | unprompted save */ | 781 | unprompted save */ |
781 | bool TextEdit::save() { | 782 | bool TextEdit::save() { |
782 | QString name, file; | 783 | QString name, file; |
783 | odebug << "saveAsFile " + currentFileName << oendl; | 784 | odebug << "saveAsFile " + currentFileName << oendl; |
784 | if(currentFileName.isEmpty()) { | 785 | if(currentFileName.isEmpty()) { |
785 | saveAs(); | 786 | saveAs(); |
786 | return false; | 787 | return false; |
787 | } | 788 | } |
788 | name = currentFileName; | 789 | name = currentFileName; |
789 | if(doc) { | 790 | if(doc) { |
790 | file = doc->file(); | 791 | file = doc->file(); |
791 | odebug << "saver file "+file << oendl; | 792 | odebug << "saver file "+file << oendl; |
792 | name = doc->name(); | 793 | name = doc->name(); |
793 | odebug << "File named "+name << oendl; | 794 | odebug << "File named "+name << oendl; |
794 | } else { | 795 | } else { |
795 | file = currentFileName; | 796 | file = currentFileName; |
796 | name = QFileInfo(currentFileName).baseName(); | 797 | name = QFileInfo(currentFileName).baseName(); |
797 | } | 798 | } |
798 | 799 | ||
799 | QString rt = editor->text(); | 800 | QString rt = editor->text(); |
800 | if( !rt.isEmpty() ) { | 801 | if( !rt.isEmpty() ) { |
801 | if(name.isEmpty()) { | 802 | if(name.isEmpty()) { |
802 | saveAs(); | 803 | saveAs(); |
803 | } else { | 804 | } else { |
804 | currentFileName = name; | 805 | currentFileName = name; |
805 | odebug << "saveFile "+currentFileName << oendl; | 806 | odebug << "saveFile "+currentFileName << oendl; |
806 | 807 | ||
807 | struct stat buf; | 808 | struct stat buf; |
808 | mode_t mode; | 809 | mode_t mode; |
809 | stat(file.latin1(), &buf); | 810 | stat(file.latin1(), &buf); |
810 | mode = buf.st_mode; | 811 | mode = buf.st_mode; |
811 | 812 | ||
812 | if(!fileIs) { | 813 | if(!fileIs) { |
813 | doc->setName( name); | 814 | doc->setName( name); |
814 | FileManager fm; | 815 | FileManager fm; |
815 | if ( !fm.saveFile( *doc, rt ) ) { | 816 | if ( !fm.saveFile( *doc, rt ) ) { |
816 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 817 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
817 | return false; | 818 | return false; |
818 | } | 819 | } |
819 | } else { | 820 | } else { |
820 | odebug << "regular save file" << oendl; | 821 | odebug << "regular save file" << oendl; |
821 | QFile f(file); | 822 | QFile f(file); |
822 | if( f.open(IO_WriteOnly)) { | 823 | if( f.open(IO_WriteOnly)) { |
823 | QCString crt = rt.utf8(); | 824 | QCString crt = rt.utf8(); |
824 | f.writeBlock(crt,crt.length()); | 825 | f.writeBlock(crt,crt.length()); |
825 | } else { | 826 | } else { |
826 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 827 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
827 | return false; | 828 | return false; |
828 | } | 829 | } |
829 | 830 | ||
830 | } | 831 | } |
831 | editor->setEdited( false); | 832 | editor->setEdited( false); |
832 | edited1=false; | 833 | edited1=false; |
833 | edited=false; | 834 | edited=false; |
834 | if(caption().left(1)=="*") | 835 | if(caption().left(1)=="*") |
835 | setCaption(caption().right(caption().length()-1)); | 836 | setCaption(caption().right(caption().length()-1)); |
836 | 837 | ||
837 | 838 | ||
838 | chmod( file.latin1(), mode); | 839 | chmod( file.latin1(), mode); |
839 | } | 840 | } |
840 | return true; | 841 | return true; |
841 | } | 842 | } |
842 | return false; | 843 | return false; |
843 | } | 844 | } |
844 | 845 | ||
845 | /*! | 846 | /*! |
846 | prompted save */ | 847 | prompted save */ |
847 | bool TextEdit::saveAs() { | 848 | bool TextEdit::saveAs() { |
848 | 849 | ||
849 | if(caption() == tr("Text Editor")) | 850 | if(caption() == tr("Text Editor")) |
850 | return false; | 851 | return false; |
851 | odebug << "saveAsFile " + currentFileName << oendl; | 852 | odebug << "saveAsFile " + currentFileName << oendl; |
852 | // case of nothing to save... | 853 | // case of nothing to save... |
853 | // if ( !doc && !currentFileName.isEmpty()) { | 854 | // if ( !doc && !currentFileName.isEmpty()) { |
854 | // //|| !bFromDocView) | 855 | // //|| !bFromDocView) |
855 | // odebug << "no doc" << oendl; | 856 | // odebug << "no doc" << oendl; |
856 | // return true; | 857 | // return true; |
857 | // } | 858 | // } |
858 | // if ( !editor->edited() ) { | 859 | // if ( !editor->edited() ) { |
859 | // delete doc; | 860 | // delete doc; |
860 | // doc = 0; | 861 | // doc = 0; |
861 | // return true; | 862 | // return true; |
862 | // } | 863 | // } |
863 | 864 | ||
864 | QString rt = editor->text(); | 865 | QString rt = editor->text(); |
865 | odebug << currentFileName << oendl; | 866 | odebug << currentFileName << oendl; |
866 | 867 | ||
867 | if( currentFileName.isEmpty() | 868 | if( currentFileName.isEmpty() |
868 | || currentFileName == tr("Unnamed") | 869 | || currentFileName == tr("Unnamed") |
869 | || currentFileName == tr("Text Editor")) { | 870 | || currentFileName == tr("Text Editor")) { |
870 | odebug << "do silly TT filename thing" << oendl; | 871 | odebug << "do silly TT filename thing" << oendl; |
871 | // if ( doc && doc->name().isEmpty() ) { | 872 | // if ( doc && doc->name().isEmpty() ) { |
872 | QString pt = rt.simplifyWhiteSpace(); | 873 | QString pt = rt.simplifyWhiteSpace(); |
873 | int i = pt.find( ' ' ); | 874 | int i = pt.find( ' ' ); |
874 | QString docname = pt; | 875 | QString docname = pt; |
875 | if ( i > 0 ) | 876 | if ( i > 0 ) |
876 | docname = pt.left( i ); | 877 | docname = pt.left( i ); |
877 | // remove "." at the beginning | 878 | // remove "." at the beginning |
878 | while( docname.startsWith( "." ) ) | 879 | while( docname.startsWith( "." ) ) |
879 | docname = docname.mid( 1 ); | 880 | docname = docname.mid( 1 ); |
880 | docname.replace( QRegExp("/"), "_" ); | 881 | docname.replace( QRegExp("/"), "_" ); |
881 | // cut the length. filenames longer than that | 882 | // cut the length. filenames longer than that |
882 | //don't make sense and something goes wrong when they get too long. | 883 | //don't make sense and something goes wrong when they get too long. |
883 | if ( docname.length() > 40 ) | 884 | if ( docname.length() > 40 ) |
884 | docname = docname.left(40); | 885 | docname = docname.left(40); |
885 | if ( docname.isEmpty() ) | 886 | if ( docname.isEmpty() ) |
886 | docname = tr("Unnamed"); | 887 | docname = tr("Unnamed"); |
887 | if(doc) doc->setName(docname); | 888 | if(doc) doc->setName(docname); |
888 | currentFileName=docname; | 889 | currentFileName=docname; |
889 | // } | 890 | // } |
890 | // else | 891 | // else |
891 | // odebug << "hmmmmmm" << oendl; | 892 | // odebug << "hmmmmmm" << oendl; |
892 | } | 893 | } |
893 | 894 | ||
894 | 895 | ||
895 | QMap<QString, QStringList> map; | 896 | QMap<QString, QStringList> map; |
896 | map.insert(tr("All"), QStringList() ); | 897 | map.insert(tr("All"), QStringList() ); |
897 | QStringList text; | 898 | QStringList text; |
898 | text << "text/*"; | 899 | text << "text/*"; |
899 | map.insert(tr("Text"), text ); | 900 | map.insert(tr("Text"), text ); |
900 | text << "*"; | 901 | text << "*"; |
901 | map.insert(tr("All"), text ); | 902 | map.insert(tr("All"), text ); |
902 | 903 | ||
903 | QFileInfo cuFi( currentFileName); | 904 | QFileInfo cuFi( currentFileName); |
904 | QString filee = cuFi.fileName(); | 905 | QString filee = cuFi.fileName(); |
905 | QString dire = cuFi.dirPath(); | 906 | QString dire = cuFi.dirPath(); |
906 | if(dire==".") | 907 | if(dire==".") |
907 | dire = QPEApplication::documentDir(); | 908 | dire = QPEApplication::documentDir(); |
908 | QString str; | 909 | QString str; |
909 | if( !featureAutoSave) { | 910 | if( !featureAutoSave) { |
910 | str = OFileDialog::getSaveFileName( 2, | 911 | str = OFileDialog::getSaveFileName( 2, |
911 | dire, | 912 | dire, |
912 | filee, map); | 913 | filee, map); |
913 | } else | 914 | } else |
914 | str = currentFileName; | 915 | str = currentFileName; |
915 | 916 | ||
916 | if(!str.isEmpty()) { | 917 | if(!str.isEmpty()) { |
917 | QString fileNm=str; | 918 | QString fileNm=str; |
918 | 919 | ||
919 | odebug << "saving filename "+fileNm << oendl; | 920 | odebug << "saving filename "+fileNm << oendl; |
920 | QFileInfo fi(fileNm); | 921 | QFileInfo fi(fileNm); |
921 | currentFileName=fi.fileName(); | 922 | currentFileName=fi.fileName(); |
922 | if(doc) | 923 | if(doc) |
923 | // QString file = doc->file(); | 924 | // QString file = doc->file(); |
924 | // doc->removeFiles(); | 925 | // doc->removeFiles(); |
925 | delete doc; | 926 | delete doc; |
926 | DocLnk nf; | 927 | DocLnk nf; |
927 | nf.setType("text/plain"); | 928 | nf.setType("text/plain"); |
928 | nf.setFile( fileNm); | 929 | nf.setFile( fileNm); |
929 | doc = new DocLnk(nf); | 930 | doc = new DocLnk(nf); |
930 | // editor->setText(rt); | 931 | // editor->setText(rt); |
931 | odebug << "Saving file as "+currentFileName << oendl; | 932 | odebug << "Saving file as "+currentFileName << oendl; |
932 | doc->setName( fi.baseName() /*currentFileName*/); | 933 | doc->setName( fi.baseName() /*currentFileName*/); |
933 | updateCaption( currentFileName); | 934 | updateCaption( currentFileName); |
934 | 935 | ||
935 | FileManager fm; | 936 | FileManager fm; |
936 | if ( !fm.saveFile( *doc, rt ) ) { | 937 | if ( !fm.saveFile( *doc, rt ) ) { |
937 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 938 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
938 | return false; | 939 | return false; |
939 | } | 940 | } |
940 | 941 | ||
941 | if( filePerms ) { | 942 | if( filePerms ) { |
942 | filePermissions *filePerm; | 943 | filePermissions *filePerm; |
943 | filePerm = new filePermissions(this, | 944 | filePerm = new filePermissions(this, |
944 | tr("Permissions"),true, | 945 | tr("Permissions"),true, |
945 | 0,(const QString &)fileNm); | 946 | 0,(const QString &)fileNm); |
946 | QPEApplication::execDialog( filePerm ); | 947 | QPEApplication::execDialog( filePerm ); |
947 | 948 | ||
948 | if( filePerm) | 949 | if( filePerm) |
949 | delete filePerm; | 950 | delete filePerm; |
950 | } | 951 | } |
951 | // } | 952 | // } |
952 | editor->setEdited( false); | 953 | editor->setEdited( false); |
953 | edited1 = false; | 954 | edited1 = false; |
954 | edited = false; | 955 | edited = false; |
955 | if(caption().left(1)=="*") | 956 | if(caption().left(1)=="*") |
956 | setCaption(caption().right(caption().length()-1)); | 957 | setCaption(caption().right(caption().length()-1)); |
957 | 958 | ||
958 | return true; | 959 | return true; |
959 | } | 960 | } |
960 | odebug << "returning false" << oendl; | 961 | odebug << "returning false" << oendl; |
961 | currentFileName = ""; | 962 | currentFileName = ""; |
962 | return false; | 963 | return false; |
963 | } //end saveAs | 964 | } //end saveAs |
964 | 965 | ||
965 | void TextEdit::clear() { | 966 | void TextEdit::clear() { |
966 | delete doc; | 967 | delete doc; |
967 | doc = 0; | 968 | doc = 0; |
968 | editor->clear(); | 969 | editor->clear(); |
969 | } | 970 | } |
970 | 971 | ||
971 | void TextEdit::updateCaption( const QString &name ) { | 972 | void TextEdit::updateCaption( const QString &name ) { |
972 | 973 | ||
973 | if ( name.isEmpty() ) | 974 | if ( name.isEmpty() ) |
974 | setCaption( tr("Text Editor") ); | 975 | setCaption( tr("Text Editor") ); |
975 | else { | 976 | else { |
976 | QString s = name; | 977 | QString s = name; |
977 | if ( s.isNull() ) | 978 | if ( s.isNull() ) |
978 | s = doc->name(); | 979 | s = doc->name(); |
979 | if ( s.isEmpty() ) { | 980 | if ( s.isEmpty() ) { |
980 | s = tr( "Unnamed" ); | 981 | s = tr( "Unnamed" ); |
981 | currentFileName=s; | 982 | currentFileName=s; |
982 | } | 983 | } |
983 | // if(s.left(1) == "/") | 984 | // if(s.left(1) == "/") |
984 | // s = s.right(s.length()-1); | 985 | // s = s.right(s.length()-1); |
985 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 986 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
986 | } | 987 | } |
987 | } | 988 | } |
988 | 989 | ||
989 | void TextEdit::setDocument(const QString& fileref) { | 990 | void TextEdit::setDocument(const QString& fileref) { |
990 | if(fileref != "Unnamed") { | 991 | if(fileref != "Unnamed") { |
991 | currentFileName=fileref; | 992 | currentFileName=fileref; |
992 | odebug << "setDocument" << oendl; | 993 | odebug << "setDocument" << oendl; |
993 | QFileInfo fi(currentFileName); | 994 | QFileInfo fi(currentFileName); |
994 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; | 995 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; |
995 | if( (fi.baseName().left(1)).isEmpty() ) { | 996 | if( (fi.baseName().left(1)).isEmpty() ) { |
996 | openDotFile(currentFileName); | 997 | openDotFile(currentFileName); |
997 | 998 | ||
998 | } else { | 999 | } else { |
999 | odebug << "setDoc open" << oendl; | 1000 | odebug << "setDoc open" << oendl; |
1000 | bFromDocView = true; | 1001 | bFromDocView = true; |
1001 | openFile(fileref); | 1002 | openFile(fileref); |
1002 | editor->setEdited(true); | 1003 | editor->setEdited(true); |
1003 | edited1=false; | 1004 | edited1=false; |
1004 | edited=true; | 1005 | edited=true; |
1005 | // fromSetDocument=false; | 1006 | // fromSetDocument=false; |
1006 | // doSearchBar(); | 1007 | // doSearchBar(); |
1007 | } | 1008 | } |
1008 | } | 1009 | } |
1009 | updateCaption( currentFileName); | 1010 | updateCaption( currentFileName); |
1010 | } | 1011 | } |
1011 | 1012 | ||
1012 | void TextEdit::changeFont() { | 1013 | void TextEdit::changeFont() { |
1013 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1014 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1014 | d-> setCaption ( tr( "Choose font" )); | 1015 | d-> setCaption ( tr( "Choose font" )); |
1015 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1016 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1016 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1017 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1017 | lay-> addWidget ( ofs ); | 1018 | lay-> addWidget ( ofs ); |
1018 | ofs-> setSelectedFont ( editor-> font ( )); | 1019 | ofs-> setSelectedFont ( editor-> font ( )); |
1019 | 1020 | ||
1020 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) | 1021 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) |
1021 | editor-> setFont ( ofs-> selectedFont ( )); | 1022 | editor-> setFont ( ofs-> selectedFont ( )); |
1022 | delete d; | 1023 | delete d; |
1023 | 1024 | ||
1024 | } | 1025 | } |
1025 | 1026 | ||
1026 | void TextEdit::editDelete() { | 1027 | void TextEdit::editDelete() { |
1027 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1028 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1028 | tr("Do you really want<BR>to <B>delete</B> " | 1029 | tr("Do you really want<BR>to <B>delete</B> " |
1029 | "the current file\nfrom the disk?<BR>This is " | 1030 | "the current file\nfrom the disk?<BR>This is " |
1030 | "<B>irreversable!</B>"), | 1031 | "<B>irreversable!</B>"), |
1031 | tr("Yes"),tr("No"),0,0,1) ) { | 1032 | tr("Yes"),tr("No"),0,0,1) ) { |
1032 | case 0: | 1033 | case 0: |
1033 | if(doc) { | 1034 | if(doc) { |
1034 | doc->removeFiles(); | 1035 | doc->removeFiles(); |
1035 | clear(); | 1036 | clear(); |
1036 | setCaption( tr("Text Editor") ); | 1037 | setCaption( tr("Text Editor") ); |
1037 | } | 1038 | } |
1038 | break; | 1039 | break; |
1039 | case 1: | 1040 | case 1: |
1040 | // exit | 1041 | // exit |
1041 | break; | 1042 | break; |
1042 | }; | 1043 | }; |
1043 | } | 1044 | } |
1044 | 1045 | ||
1045 | void TextEdit::changeStartConfig( bool b ) { | 1046 | void TextEdit::changeStartConfig( bool b ) { |
1046 | startWithNew=b; | 1047 | startWithNew=b; |
1047 | Config cfg("TextEdit"); | 1048 | Config cfg("TextEdit"); |
1048 | cfg.setGroup("View"); | 1049 | cfg.setGroup("View"); |
1049 | cfg.writeEntry("startNew",b); | 1050 | cfg.writeEntry("startNew",b); |
1050 | update(); | 1051 | update(); |
1051 | } | 1052 | } |
1052 | 1053 | ||
1053 | void TextEdit::editorChanged() { | 1054 | void TextEdit::editorChanged() { |
1054 | // odebug << "editor changed" << oendl; | 1055 | // odebug << "editor changed" << oendl; |
1055 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1056 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1056 | setCaption( "*"+caption()); | 1057 | setCaption( "*"+caption()); |
1057 | edited1=true; | 1058 | edited1=true; |
1058 | } | 1059 | } |
1059 | edited=true; | 1060 | edited=true; |
1060 | } | 1061 | } |
1061 | 1062 | ||
1062 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1063 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1063 | odebug << "QCop "+msg << oendl; | 1064 | odebug << "QCop "+msg << oendl; |
1064 | if ( msg == "setDocument(QString)" ) { | 1065 | if ( msg == "setDocument(QString)" ) { |
diff --git a/core/launcher/qprocess_unix.cpp b/core/launcher/qprocess_unix.cpp index 97c0460..3125bcc 100644 --- a/core/launcher/qprocess_unix.cpp +++ b/core/launcher/qprocess_unix.cpp | |||
@@ -1,700 +1,704 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | // Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. | 21 | // Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. |
22 | #if defined(connect) | 22 | #if defined(connect) |
23 | #undef connect | 23 | #undef connect |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #include "qprocess.h" | 26 | #include "qprocess.h" |
27 | 27 | ||
28 | /* OPIE */ | 28 | /* OPIE */ |
29 | #include <opie2/odebug.h> | 29 | #include <opie2/odebug.h> |
30 | using namespace Opie::Core; | 30 | using namespace Opie::Core; |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #ifndef QT_NO_PROCESS | 33 | #ifndef QT_NO_PROCESS |
34 | #include <qapplication.h> | 34 | #include <qapplication.h> |
35 | #include <qqueue.h> | 35 | #include <qqueue.h> |
36 | #include <qlist.h> | 36 | #include <qlist.h> |
37 | #include <qsocketnotifier.h> | 37 | #include <qsocketnotifier.h> |
38 | #include <qtimer.h> | 38 | #include <qtimer.h> |
39 | #include <qregexp.h> | 39 | #include <qregexp.h> |
40 | 40 | ||
41 | #include "qcleanuphandler_p.h" | 41 | #include "qcleanuphandler_p.h" |
42 | 42 | ||
43 | /* STD */ | 43 | /* STD */ |
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | #include <signal.h> | 46 | #include <signal.h> |
47 | #include <sys/socket.h> | 47 | #include <sys/socket.h> |
48 | #include <sys/ioctl.h> | 48 | #include <sys/ioctl.h> |
49 | #include <sys/wait.h> | 49 | #include <sys/wait.h> |
50 | #include <sys/fcntl.h> | 50 | #include <sys/fcntl.h> |
51 | #include <errno.h> | 51 | #include <errno.h> |
52 | #ifdef Q_OS_MACX | 52 | #ifdef Q_OS_MACX |
53 | #include <sys/time.h> | 53 | #include <sys/time.h> |
54 | #endif | 54 | #endif |
55 | #include <sys/resource.h> | 55 | #include <sys/resource.h> |
56 | 56 | ||
57 | #ifdef __MIPSEL__ | 57 | #ifdef __MIPSEL__ |
58 | # ifndef SOCK_DGRAM | 58 | # ifndef SOCK_DGRAM |
59 | # define SOCK_DGRAM 1 | 59 | # define SOCK_DGRAM 1 |
60 | # endif | 60 | # endif |
61 | # ifndef SOCK_STREAM | 61 | # ifndef SOCK_STREAM |
62 | # define SOCK_STREAM 2 | 62 | # define SOCK_STREAM 2 |
63 | # endif | 63 | # endif |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | //#define QT_QPROCESS_DEBUG | 66 | //#define QT_QPROCESS_DEBUG |
67 | 67 | ||
68 | 68 | ||
69 | #ifdef Q_C_CALLBACKS | 69 | #ifdef Q_C_CALLBACKS |
70 | extern "C" { | 70 | extern "C" { |
71 | #endif // Q_C_CALLBACKS | 71 | #endif // Q_C_CALLBACKS |
72 | 72 | ||
73 | #define QT_SIGNAL_RETTYPE void | 73 | #define QT_SIGNAL_RETTYPE void |
74 | #define QT_SIGNAL_ARGS int | 74 | #define QT_SIGNAL_ARGS int |
75 | #define QT_SIGNAL_IGNORE SIG_IGN | 75 | #define QT_SIGNAL_IGNORE SIG_IGN |
76 | 76 | ||
77 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd(QT_SIGNAL_ARGS); | 77 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd(QT_SIGNAL_ARGS); |
78 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd(QT_SIGNAL_ARGS); | 78 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd(QT_SIGNAL_ARGS); |
79 | 79 | ||
80 | #ifdef Q_C_CALLBACKS | 80 | #ifdef Q_C_CALLBACKS |
81 | } | 81 | } |
82 | #endif // Q_C_CALLBACKS | 82 | #endif // Q_C_CALLBACKS |
83 | 83 | ||
84 | 84 | ||
85 | class QProc; | 85 | class QProc; |
86 | class QProcessManager; | 86 | class QProcessManager; |
87 | class QProcessPrivate | 87 | class QProcessPrivate |
88 | { | 88 | { |
89 | public: | 89 | public: |
90 | QProcessPrivate(); | 90 | QProcessPrivate(); |
91 | ~QProcessPrivate(); | 91 | ~QProcessPrivate(); |
92 | 92 | ||
93 | void closeOpenSocketsForChild(); | 93 | void closeOpenSocketsForChild(); |
94 | void newProc( pid_t pid, QProcess *process ); | 94 | void newProc( pid_t pid, QProcess *process ); |
95 | 95 | ||
96 | QByteArray bufStdout; | 96 | QByteArray bufStdout; |
97 | QByteArray bufStderr; | 97 | QByteArray bufStderr; |
98 | 98 | ||
99 | QQueue<QByteArray> stdinBuf; | 99 | QQueue<QByteArray> stdinBuf; |
100 | 100 | ||
101 | QSocketNotifier *notifierStdin; | 101 | QSocketNotifier *notifierStdin; |
102 | QSocketNotifier *notifierStdout; | 102 | QSocketNotifier *notifierStdout; |
103 | QSocketNotifier *notifierStderr; | 103 | QSocketNotifier *notifierStderr; |
104 | 104 | ||
105 | ssize_t stdinBufRead; | 105 | ssize_t stdinBufRead; |
106 | QProc *proc; | 106 | QProc *proc; |
107 | 107 | ||
108 | bool exitValuesCalculated; | 108 | bool exitValuesCalculated; |
109 | bool socketReadCalled; | 109 | bool socketReadCalled; |
110 | 110 | ||
111 | static QProcessManager *procManager; | 111 | static QProcessManager *procManager; |
112 | }; | 112 | }; |
113 | 113 | ||
114 | 114 | ||
115 | /*********************************************************************** | 115 | /*********************************************************************** |
116 | * | 116 | * |
117 | * QProc | 117 | * QProc |
118 | * | 118 | * |
119 | **********************************************************************/ | 119 | **********************************************************************/ |
120 | /* | 120 | /* |
121 | The class QProcess does not necessarily map exactly to the running | 121 | The class QProcess does not necessarily map exactly to the running |
122 | child processes: if the process is finished, the QProcess class may still be | 122 | child processes: if the process is finished, the QProcess class may still be |
123 | there; furthermore a user can use QProcess to start more than one process. | 123 | there; furthermore a user can use QProcess to start more than one process. |
124 | 124 | ||
125 | The helper-class QProc has the semantics that one instance of this class maps | 125 | The helper-class QProc has the semantics that one instance of this class maps |
126 | directly to a running child process. | 126 | directly to a running child process. |
127 | */ | 127 | */ |
128 | class QProc | 128 | class QProc |
129 | { | 129 | { |
130 | public: | 130 | public: |
131 | QProc( pid_t p, QProcess *proc=0 ) : pid(p), process(proc) | 131 | QProc( pid_t p, QProcess *proc=0 ) : pid(p), process(proc) |
132 | { | 132 | { |
133 | #if defined(QT_QPROCESS_DEBUG) | 133 | #if defined(QT_QPROCESS_DEBUG) |
134 | odebug << "QProc: Constructor for pid " << pid << " and QProcess " << process << "" << oendl; | 134 | odebug << "QProc: Constructor for pid " << pid << " and QProcess " << process << "" << oendl; |
135 | #endif | 135 | #endif |
136 | socketStdin = 0; | 136 | socketStdin = 0; |
137 | socketStdout = 0; | 137 | socketStdout = 0; |
138 | socketStderr = 0; | 138 | socketStderr = 0; |
139 | } | 139 | } |
140 | ~QProc() | 140 | ~QProc() |
141 | { | 141 | { |
142 | #if defined(QT_QPROCESS_DEBUG) | 142 | #if defined(QT_QPROCESS_DEBUG) |
143 | odebug << "QProc: Destructor for pid " << pid << " and QProcess " << process << "" << oendl; | 143 | odebug << "QProc: Destructor for pid " << pid << " and QProcess " << process << "" << oendl; |
144 | #endif | 144 | #endif |
145 | if ( process != 0 ) { | 145 | if ( process != 0 ) { |
146 | if ( process->d->notifierStdin ) | 146 | if ( process->d->notifierStdin ) |
147 | process->d->notifierStdin->setEnabled( FALSE ); | 147 | process->d->notifierStdin->setEnabled( FALSE ); |
148 | if ( process->d->notifierStdout ) | 148 | if ( process->d->notifierStdout ) |
149 | process->d->notifierStdout->setEnabled( FALSE ); | 149 | process->d->notifierStdout->setEnabled( FALSE ); |
150 | if ( process->d->notifierStderr ) | 150 | if ( process->d->notifierStderr ) |
151 | process->d->notifierStderr->setEnabled( FALSE ); | 151 | process->d->notifierStderr->setEnabled( FALSE ); |
152 | process->d->proc = 0; | 152 | process->d->proc = 0; |
153 | } | 153 | } |
154 | if( socketStdin != 0 ) | 154 | if( socketStdin != 0 ) |
155 | ::close( socketStdin ); | 155 | ::close( socketStdin ); |
156 | // ### close these sockets even on parent exit or is it better only on | 156 | // ### close these sockets even on parent exit or is it better only on |
157 | // sigchld (but what do I have to do with them on exit then)? | 157 | // sigchld (but what do I have to do with them on exit then)? |
158 | if( socketStdout != 0 ) | 158 | if( socketStdout != 0 ) |
159 | ::close( socketStdout ); | 159 | ::close( socketStdout ); |
160 | if( socketStderr != 0 ) | 160 | if( socketStderr != 0 ) |
161 | ::close( socketStderr ); | 161 | ::close( socketStderr ); |
162 | } | 162 | } |
163 | 163 | ||
164 | pid_t pid; | 164 | pid_t pid; |
165 | int socketStdin; | 165 | int socketStdin; |
166 | int socketStdout; | 166 | int socketStdout; |
167 | int socketStderr; | 167 | int socketStderr; |
168 | QProcess *process; | 168 | QProcess *process; |
169 | }; | 169 | }; |
170 | 170 | ||
171 | /*********************************************************************** | 171 | /*********************************************************************** |
172 | * | 172 | * |
173 | * QProcessManager | 173 | * QProcessManager |
174 | * | 174 | * |
175 | **********************************************************************/ | 175 | **********************************************************************/ |
176 | class QProcessManager : public QObject | 176 | class QProcessManager : public QObject |
177 | { | 177 | { |
178 | Q_OBJECT | 178 | Q_OBJECT |
179 | 179 | ||
180 | public: | 180 | public: |
181 | QProcessManager(); | 181 | QProcessManager(); |
182 | ~QProcessManager(); | 182 | ~QProcessManager(); |
183 | 183 | ||
184 | void append( QProc *p ); | 184 | void append( QProc *p ); |
185 | void remove( QProc *p ); | 185 | void remove( QProc *p ); |
186 | 186 | ||
187 | void cleanup(); | 187 | void cleanup(); |
188 | 188 | ||
189 | public slots: | 189 | public slots: |
190 | void removeMe(); | 190 | void removeMe(); |
191 | void sigchldHnd( int ); | 191 | void sigchldHnd( int ); |
192 | 192 | ||
193 | public: | 193 | public: |
194 | struct sigaction oldactChld; | 194 | struct sigaction oldactChld; |
195 | struct sigaction oldactPipe; | 195 | struct sigaction oldactPipe; |
196 | QList<QProc> *procList; | 196 | QList<QProc> *procList; |
197 | int sigchldFd[2]; | 197 | int sigchldFd[2]; |
198 | }; | 198 | }; |
199 | 199 | ||
200 | QCleanupHandler<QProcessManager> qprocess_cleanup_procmanager; | 200 | QCleanupHandler<QProcessManager> qprocess_cleanup_procmanager; |
201 | 201 | ||
202 | QProcessManager::QProcessManager() | 202 | QProcessManager::QProcessManager() |
203 | { | 203 | { |
204 | procList = new QList<QProc>; | 204 | procList = new QList<QProc>; |
205 | procList->setAutoDelete( TRUE ); | 205 | procList->setAutoDelete( TRUE ); |
206 | 206 | ||
207 | // The SIGCHLD handler writes to a socket to tell the manager that | 207 | // The SIGCHLD handler writes to a socket to tell the manager that |
208 | // something happened. This is done to get the processing in sync with the | 208 | // something happened. This is done to get the processing in sync with the |
209 | // event reporting. | 209 | // event reporting. |
210 | if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { | 210 | if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { |
211 | sigchldFd[0] = 0; | 211 | sigchldFd[0] = 0; |
212 | sigchldFd[1] = 0; | 212 | sigchldFd[1] = 0; |
213 | } else { | 213 | } else { |
214 | #if defined(QT_QPROCESS_DEBUG) | 214 | #if defined(QT_QPROCESS_DEBUG) |
215 | odebug << "QProcessManager: install socket notifier (" << sigchldFd[1] << ")" << oendl; | 215 | odebug << "QProcessManager: install socket notifier (" << sigchldFd[1] << ")" << oendl; |
216 | #endif | 216 | #endif |
217 | QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], | 217 | QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], |
218 | QSocketNotifier::Read, this ); | 218 | QSocketNotifier::Read, this ); |
219 | connect( sn, SIGNAL(activated(int)), | 219 | connect( sn, SIGNAL(activated(int)), |
220 | this, SLOT(sigchldHnd(int)) ); | 220 | this, SLOT(sigchldHnd(int)) ); |
221 | sn->setEnabled( TRUE ); | 221 | sn->setEnabled( TRUE ); |
222 | } | 222 | } |
223 | 223 | ||
224 | // install a SIGCHLD handler and ignore SIGPIPE | 224 | // install a SIGCHLD handler and ignore SIGPIPE |
225 | struct sigaction act; | 225 | struct sigaction act; |
226 | 226 | ||
227 | #if defined(QT_QPROCESS_DEBUG) | 227 | #if defined(QT_QPROCESS_DEBUG) |
228 | odebug << "QProcessManager: install a SIGCHLD handler" << oendl; | 228 | odebug << "QProcessManager: install a SIGCHLD handler" << oendl; |
229 | #endif | 229 | #endif |
230 | act.sa_handler = qt_C_sigchldHnd; | 230 | act.sa_handler = qt_C_sigchldHnd; |
231 | sigemptyset( &(act.sa_mask) ); | 231 | sigemptyset( &(act.sa_mask) ); |
232 | sigaddset( &(act.sa_mask), SIGCHLD ); | 232 | sigaddset( &(act.sa_mask), SIGCHLD ); |
233 | act.sa_flags = SA_NOCLDSTOP; | 233 | act.sa_flags = SA_NOCLDSTOP; |
234 | #if defined(SA_RESTART) | 234 | #if defined(SA_RESTART) |
235 | act.sa_flags |= SA_RESTART; | 235 | act.sa_flags |= SA_RESTART; |
236 | #endif | 236 | #endif |
237 | if ( sigaction( SIGCHLD, &act, &oldactChld ) != 0 ) | 237 | if ( sigaction( SIGCHLD, &act, &oldactChld ) != 0 ) |
238 | owarn << "Error installing SIGCHLD handler" << oendl; | 238 | owarn << "Error installing SIGCHLD handler" << oendl; |
239 | 239 | ||
240 | #if defined(QT_QPROCESS_DEBUG) | 240 | #if defined(QT_QPROCESS_DEBUG) |
241 | odebug << "QProcessManager: install a SIGPIPE handler (SIG_IGN)" << oendl; | 241 | odebug << "QProcessManager: install a SIGPIPE handler (SIG_IGN)" << oendl; |
242 | #endif | 242 | #endif |
243 | /* | 243 | /* |
244 | Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround | 244 | Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround |
245 | for a strange problem where GNU tar (called by backuprestore) | 245 | for a strange problem where GNU tar (called by backuprestore) |
246 | would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd | 246 | would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd |
247 | is never even called, yet this avoids the hang. | 247 | is never even called, yet this avoids the hang. |
248 | */ | 248 | */ |
249 | act.sa_handler = qt_C_sigpipeHnd; | 249 | act.sa_handler = qt_C_sigpipeHnd; |
250 | sigemptyset( &(act.sa_mask) ); | 250 | sigemptyset( &(act.sa_mask) ); |
251 | sigaddset( &(act.sa_mask), SIGPIPE ); | 251 | sigaddset( &(act.sa_mask), SIGPIPE ); |
252 | act.sa_flags = 0; | 252 | act.sa_flags = 0; |
253 | if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 ) | 253 | if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 ) |
254 | owarn << "Error installing SIGPIPE handler" << oendl; | 254 | owarn << "Error installing SIGPIPE handler" << oendl; |
255 | } | 255 | } |
256 | 256 | ||
257 | QProcessManager::~QProcessManager() | 257 | QProcessManager::~QProcessManager() |
258 | { | 258 | { |
259 | delete procList; | 259 | delete procList; |
260 | 260 | ||
261 | if ( sigchldFd[0] != 0 ) | 261 | if ( sigchldFd[0] != 0 ) |
262 | ::close( sigchldFd[0] ); | 262 | ::close( sigchldFd[0] ); |
263 | if ( sigchldFd[1] != 0 ) | 263 | if ( sigchldFd[1] != 0 ) |
264 | ::close( sigchldFd[1] ); | 264 | ::close( sigchldFd[1] ); |
265 | 265 | ||
266 | // restore SIGCHLD handler | 266 | // restore SIGCHLD handler |
267 | #if defined(QT_QPROCESS_DEBUG) | 267 | #if defined(QT_QPROCESS_DEBUG) |
268 | odebug << "QProcessManager: restore old sigchild handler" << oendl; | 268 | odebug << "QProcessManager: restore old sigchild handler" << oendl; |
269 | #endif | 269 | #endif |
270 | if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 ) | 270 | if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 ) |
271 | owarn << "Error restoring SIGCHLD handler" << oendl; | 271 | owarn << "Error restoring SIGCHLD handler" << oendl; |
272 | 272 | ||
273 | #if defined(QT_QPROCESS_DEBUG) | 273 | #if defined(QT_QPROCESS_DEBUG) |
274 | odebug << "QProcessManager: restore old sigpipe handler" << oendl; | 274 | odebug << "QProcessManager: restore old sigpipe handler" << oendl; |
275 | #endif | 275 | #endif |
276 | if ( sigaction( SIGPIPE, &oldactPipe, 0 ) != 0 ) | 276 | if ( sigaction( SIGPIPE, &oldactPipe, 0 ) != 0 ) |
277 | owarn << "Error restoring SIGPIPE handler" << oendl; | 277 | owarn << "Error restoring SIGPIPE handler" << oendl; |
278 | } | 278 | } |
279 | 279 | ||
280 | void QProcessManager::append( QProc *p ) | 280 | void QProcessManager::append( QProc *p ) |
281 | { | 281 | { |
282 | procList->append( p ); | 282 | procList->append( p ); |
283 | #if defined(QT_QPROCESS_DEBUG) | 283 | #if defined(QT_QPROCESS_DEBUG) |
284 | odebug << "QProcessManager: append process (procList.count(): " << procList->count() << ")" << oendl; | 284 | odebug << "QProcessManager: append process (procList.count(): " << procList->count() << ")" << oendl; |
285 | #endif | 285 | #endif |
286 | } | 286 | } |
287 | 287 | ||
288 | void QProcessManager::remove( QProc *p ) | 288 | void QProcessManager::remove( QProc *p ) |
289 | { | 289 | { |
290 | procList->remove( p ); | 290 | procList->remove( p ); |
291 | #if defined(QT_QPROCESS_DEBUG) | 291 | #if defined(QT_QPROCESS_DEBUG) |
292 | odebug << "QProcessManager: remove process (procList.count(): " << procList->count() << ")" << oendl; | 292 | odebug << "QProcessManager: remove process (procList.count(): " << procList->count() << ")" << oendl; |
293 | #endif | 293 | #endif |
294 | cleanup(); | 294 | cleanup(); |
295 | } | 295 | } |
296 | 296 | ||
297 | void QProcessManager::cleanup() | 297 | void QProcessManager::cleanup() |
298 | { | 298 | { |
299 | if ( procList->count() == 0 ) { | 299 | if ( procList->count() == 0 ) { |
300 | QTimer::singleShot( 0, this, SLOT(removeMe()) ); | 300 | QTimer::singleShot( 0, this, SLOT(removeMe()) ); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | void QProcessManager::removeMe() | 304 | void QProcessManager::removeMe() |
305 | { | 305 | { |
306 | if ( procList->count() == 0 ) { | 306 | if ( procList->count() == 0 ) { |
307 | qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); | 307 | qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); |
308 | QProcessPrivate::procManager = 0; | 308 | QProcessPrivate::procManager = 0; |
309 | delete this; | 309 | delete this; |
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | void QProcessManager::sigchldHnd( int fd ) | 313 | void QProcessManager::sigchldHnd( int fd ) |
314 | { | 314 | { |
315 | char tmp; | 315 | char tmp; |
316 | ::read( fd, &tmp, sizeof(tmp) ); | 316 | if (::read( fd, &tmp, sizeof(tmp) ) < 0) |
317 | #if defined(QT_QPROCESS_DEBUG) | ||
318 | odebug << "QProcessManager::sigchldHnd() failed dummy read of file descriptor" << oendl; | ||
319 | #endif | ||
320 | ; | ||
317 | #if defined(QT_QPROCESS_DEBUG) | 321 | #if defined(QT_QPROCESS_DEBUG) |
318 | odebug << "QProcessManager::sigchldHnd()" << oendl; | 322 | odebug << "QProcessManager::sigchldHnd()" << oendl; |
319 | #endif | 323 | #endif |
320 | QProc *proc; | 324 | QProc *proc; |
321 | QProcess *process; | 325 | QProcess *process; |
322 | bool removeProc; | 326 | bool removeProc; |
323 | proc = procList->first(); | 327 | proc = procList->first(); |
324 | while ( proc != 0 ) { | 328 | while ( proc != 0 ) { |
325 | removeProc = FALSE; | 329 | removeProc = FALSE; |
326 | process = proc->process; | 330 | process = proc->process; |
327 | QProcess *process_exit_notify=0; | 331 | QProcess *process_exit_notify=0; |
328 | if ( process != 0 ) { | 332 | if ( process != 0 ) { |
329 | if ( !process->isRunning() ) { | 333 | if ( !process->isRunning() ) { |
330 | #if defined(QT_QPROCESS_DEBUG) | 334 | #if defined(QT_QPROCESS_DEBUG) |
331 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess available)" << oendl; | 335 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess available)" << oendl; |
332 | #endif | 336 | #endif |
333 | // read pending data | 337 | // read pending data |
334 | int nbytes = 0; | 338 | int nbytes = 0; |
335 | if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { | 339 | if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { |
336 | #if defined(QT_QPROCESS_DEBUG) | 340 | #if defined(QT_QPROCESS_DEBUG) |
337 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stdout" << oendl; | 341 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stdout" << oendl; |
338 | #endif | 342 | #endif |
339 | process->socketRead( proc->socketStdout ); | 343 | process->socketRead( proc->socketStdout ); |
340 | } | 344 | } |
341 | nbytes = 0; | 345 | nbytes = 0; |
342 | if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { | 346 | if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { |
343 | #if defined(QT_QPROCESS_DEBUG) | 347 | #if defined(QT_QPROCESS_DEBUG) |
344 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stderr" << oendl; | 348 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stderr" << oendl; |
345 | #endif | 349 | #endif |
346 | process->socketRead( proc->socketStderr ); | 350 | process->socketRead( proc->socketStderr ); |
347 | } | 351 | } |
348 | 352 | ||
349 | if ( process->notifyOnExit ) | 353 | if ( process->notifyOnExit ) |
350 | process_exit_notify = process; | 354 | process_exit_notify = process; |
351 | 355 | ||
352 | removeProc = TRUE; | 356 | removeProc = TRUE; |
353 | } | 357 | } |
354 | } else { | 358 | } else { |
355 | int status; | 359 | int status; |
356 | if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { | 360 | if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { |
357 | #if defined(QT_QPROCESS_DEBUG) | 361 | #if defined(QT_QPROCESS_DEBUG) |
358 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess not available)" << oendl; | 362 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess not available)" << oendl; |
359 | #endif | 363 | #endif |
360 | removeProc = TRUE; | 364 | removeProc = TRUE; |
361 | } | 365 | } |
362 | } | 366 | } |
363 | if ( removeProc ) { | 367 | if ( removeProc ) { |
364 | QProc *oldproc = proc; | 368 | QProc *oldproc = proc; |
365 | proc = procList->next(); | 369 | proc = procList->next(); |
366 | remove( oldproc ); | 370 | remove( oldproc ); |
367 | } else { | 371 | } else { |
368 | proc = procList->next(); | 372 | proc = procList->next(); |
369 | } | 373 | } |
370 | if ( process_exit_notify ) | 374 | if ( process_exit_notify ) |
371 | emit process_exit_notify->processExited(); | 375 | emit process_exit_notify->processExited(); |
372 | } | 376 | } |
373 | } | 377 | } |
374 | 378 | ||
375 | #include "qprocess_unix.moc" | 379 | #include "qprocess_unix.moc" |
376 | 380 | ||
377 | 381 | ||
378 | /*********************************************************************** | 382 | /*********************************************************************** |
379 | * | 383 | * |
380 | * QProcessPrivate | 384 | * QProcessPrivate |
381 | * | 385 | * |
382 | **********************************************************************/ | 386 | **********************************************************************/ |
383 | QProcessManager *QProcessPrivate::procManager = 0; | 387 | QProcessManager *QProcessPrivate::procManager = 0; |
384 | 388 | ||
385 | QProcessPrivate::QProcessPrivate() | 389 | QProcessPrivate::QProcessPrivate() |
386 | { | 390 | { |
387 | #if defined(QT_QPROCESS_DEBUG) | 391 | #if defined(QT_QPROCESS_DEBUG) |
388 | odebug << "QProcessPrivate: Constructor" << oendl; | 392 | odebug << "QProcessPrivate: Constructor" << oendl; |
389 | #endif | 393 | #endif |
390 | stdinBufRead = 0; | 394 | stdinBufRead = 0; |
391 | 395 | ||
392 | notifierStdin = 0; | 396 | notifierStdin = 0; |
393 | notifierStdout = 0; | 397 | notifierStdout = 0; |
394 | notifierStderr = 0; | 398 | notifierStderr = 0; |
395 | 399 | ||
396 | exitValuesCalculated = FALSE; | 400 | exitValuesCalculated = FALSE; |
397 | socketReadCalled = FALSE; | 401 | socketReadCalled = FALSE; |
398 | 402 | ||
399 | proc = 0; | 403 | proc = 0; |
400 | } | 404 | } |
401 | 405 | ||
402 | QProcessPrivate::~QProcessPrivate() | 406 | QProcessPrivate::~QProcessPrivate() |
403 | { | 407 | { |
404 | #if defined(QT_QPROCESS_DEBUG) | 408 | #if defined(QT_QPROCESS_DEBUG) |
405 | odebug << "QProcessPrivate: Destructor" << oendl; | 409 | odebug << "QProcessPrivate: Destructor" << oendl; |
406 | #endif | 410 | #endif |
407 | 411 | ||
408 | if ( proc != 0 ) { | 412 | if ( proc != 0 ) { |
409 | if ( proc->socketStdin != 0 ) { | 413 | if ( proc->socketStdin != 0 ) { |
410 | ::close( proc->socketStdin ); | 414 | ::close( proc->socketStdin ); |
411 | proc->socketStdin = 0; | 415 | proc->socketStdin = 0; |
412 | } | 416 | } |
413 | proc->process = 0; | 417 | proc->process = 0; |
414 | } | 418 | } |
415 | 419 | ||
416 | while ( !stdinBuf.isEmpty() ) { | 420 | while ( !stdinBuf.isEmpty() ) { |
417 | delete stdinBuf.dequeue(); | 421 | delete stdinBuf.dequeue(); |
418 | } | 422 | } |
419 | delete notifierStdin; | 423 | delete notifierStdin; |
420 | delete notifierStdout; | 424 | delete notifierStdout; |
421 | delete notifierStderr; | 425 | delete notifierStderr; |
422 | } | 426 | } |
423 | 427 | ||
424 | /* | 428 | /* |
425 | Closes all open sockets in the child process that are not needed by the child | 429 | Closes all open sockets in the child process that are not needed by the child |
426 | process. Otherwise one child may have an open socket on standard input, etc. | 430 | process. Otherwise one child may have an open socket on standard input, etc. |
427 | of another child. | 431 | of another child. |
428 | */ | 432 | */ |
429 | void QProcessPrivate::closeOpenSocketsForChild() | 433 | void QProcessPrivate::closeOpenSocketsForChild() |
430 | { | 434 | { |
431 | if ( procManager != 0 ) { | 435 | if ( procManager != 0 ) { |
432 | if ( procManager->sigchldFd[0] != 0 ) | 436 | if ( procManager->sigchldFd[0] != 0 ) |
433 | ::close( procManager->sigchldFd[0] ); | 437 | ::close( procManager->sigchldFd[0] ); |
434 | if ( procManager->sigchldFd[1] != 0 ) | 438 | if ( procManager->sigchldFd[1] != 0 ) |
435 | ::close( procManager->sigchldFd[1] ); | 439 | ::close( procManager->sigchldFd[1] ); |
436 | 440 | ||
437 | // close also the sockets from other QProcess instances | 441 | // close also the sockets from other QProcess instances |
438 | QProc *proc; | 442 | QProc *proc; |
439 | for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { | 443 | for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { |
440 | ::close( proc->socketStdin ); | 444 | ::close( proc->socketStdin ); |
441 | ::close( proc->socketStdout ); | 445 | ::close( proc->socketStdout ); |
442 | ::close( proc->socketStderr ); | 446 | ::close( proc->socketStderr ); |
443 | } | 447 | } |
444 | } | 448 | } |
445 | } | 449 | } |
446 | 450 | ||
447 | void QProcessPrivate::newProc( pid_t pid, QProcess *process ) | 451 | void QProcessPrivate::newProc( pid_t pid, QProcess *process ) |
448 | { | 452 | { |
449 | proc = new QProc( pid, process ); | 453 | proc = new QProc( pid, process ); |
450 | if ( procManager == 0 ) { | 454 | if ( procManager == 0 ) { |
451 | procManager = new QProcessManager; | 455 | procManager = new QProcessManager; |
452 | qprocess_cleanup_procmanager.add( &procManager ); | 456 | qprocess_cleanup_procmanager.add( &procManager ); |
453 | } | 457 | } |
454 | // the QProcessManager takes care of deleting the QProc instances | 458 | // the QProcessManager takes care of deleting the QProc instances |
455 | procManager->append( proc ); | 459 | procManager->append( proc ); |
456 | } | 460 | } |
457 | 461 | ||
458 | /*********************************************************************** | 462 | /*********************************************************************** |
459 | * | 463 | * |
460 | * sigchld handler callback | 464 | * sigchld handler callback |
461 | * | 465 | * |
462 | **********************************************************************/ | 466 | **********************************************************************/ |
463 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) | 467 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) |
464 | { | 468 | { |
465 | if ( QProcessPrivate::procManager == 0 ) | 469 | if ( QProcessPrivate::procManager == 0 ) |
466 | return; | 470 | return; |
467 | if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) | 471 | if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) |
468 | return; | 472 | return; |
469 | 473 | ||
470 | char a = 1; | 474 | char a = 1; |
471 | ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) ); | 475 | ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) ); |
472 | } | 476 | } |
473 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd( QT_SIGNAL_ARGS ) | 477 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd( QT_SIGNAL_ARGS ) |
474 | { | 478 | { |
475 | // Ignore (but in a way somehow different to SIG_IGN). | 479 | // Ignore (but in a way somehow different to SIG_IGN). |
476 | } | 480 | } |
477 | 481 | ||
478 | 482 | ||
479 | /*********************************************************************** | 483 | /*********************************************************************** |
480 | * | 484 | * |
481 | * QProcess | 485 | * QProcess |
482 | * | 486 | * |
483 | **********************************************************************/ | 487 | **********************************************************************/ |
484 | /*! | 488 | /*! |
485 | This private class does basic initialization. | 489 | This private class does basic initialization. |
486 | */ | 490 | */ |
487 | void QProcess::init() | 491 | void QProcess::init() |
488 | { | 492 | { |
489 | d = new QProcessPrivate(); | 493 | d = new QProcessPrivate(); |
490 | exitStat = 0; | 494 | exitStat = 0; |
491 | exitNormal = FALSE; | 495 | exitNormal = FALSE; |
492 | } | 496 | } |
493 | 497 | ||
494 | /*! | 498 | /*! |
495 | This private class resets the process variables, etc. so that it can be used | 499 | This private class resets the process variables, etc. so that it can be used |
496 | for another process to start. | 500 | for another process to start. |
497 | */ | 501 | */ |
498 | void QProcess::reset() | 502 | void QProcess::reset() |
499 | { | 503 | { |
500 | delete d; | 504 | delete d; |
501 | d = new QProcessPrivate(); | 505 | d = new QProcessPrivate(); |
502 | exitStat = 0; | 506 | exitStat = 0; |
503 | exitNormal = FALSE; | 507 | exitNormal = FALSE; |
504 | d->bufStdout.resize( 0 ); | 508 | d->bufStdout.resize( 0 ); |
505 | d->bufStderr.resize( 0 ); | 509 | d->bufStderr.resize( 0 ); |
506 | } | 510 | } |
507 | 511 | ||
508 | QByteArray* QProcess::bufStdout() | 512 | QByteArray* QProcess::bufStdout() |
509 | { | 513 | { |
510 | if ( d->proc && d->proc->socketStdout ) { | 514 | if ( d->proc && d->proc->socketStdout ) { |
511 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see | 515 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see |
512 | // if data is available)? | 516 | // if data is available)? |
513 | socketRead( d->proc->socketStdout ); | 517 | socketRead( d->proc->socketStdout ); |
514 | } | 518 | } |
515 | return &d->bufStdout; | 519 | return &d->bufStdout; |
516 | } | 520 | } |
517 | 521 | ||
518 | QByteArray* QProcess::bufStderr() | 522 | QByteArray* QProcess::bufStderr() |
519 | { | 523 | { |
520 | if ( d->proc && d->proc->socketStderr ) { | 524 | if ( d->proc && d->proc->socketStderr ) { |
521 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see | 525 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see |
522 | // if data is available)? | 526 | // if data is available)? |
523 | socketRead( d->proc->socketStderr ); | 527 | socketRead( d->proc->socketStderr ); |
524 | } | 528 | } |
525 | return &d->bufStderr; | 529 | return &d->bufStderr; |
526 | } | 530 | } |
527 | 531 | ||
528 | void QProcess::consumeBufStdout( int consume ) | 532 | void QProcess::consumeBufStdout( int consume ) |
529 | { | 533 | { |
530 | uint n = d->bufStdout.size(); | 534 | uint n = d->bufStdout.size(); |
531 | if ( consume==-1 || (uint)consume >= n ) { | 535 | if ( consume==-1 || (uint)consume >= n ) { |
532 | d->bufStdout.resize( 0 ); | 536 | d->bufStdout.resize( 0 ); |
533 | } else { | 537 | } else { |
534 | QByteArray tmp( n - consume ); | 538 | QByteArray tmp( n - consume ); |
535 | memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); | 539 | memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); |
536 | d->bufStdout = tmp; | 540 | d->bufStdout = tmp; |
537 | } | 541 | } |
538 | } | 542 | } |
539 | 543 | ||
540 | void QProcess::consumeBufStderr( int consume ) | 544 | void QProcess::consumeBufStderr( int consume ) |
541 | { | 545 | { |
542 | uint n = d->bufStderr.size(); | 546 | uint n = d->bufStderr.size(); |
543 | if ( consume==-1 || (uint)consume >= n ) { | 547 | if ( consume==-1 || (uint)consume >= n ) { |
544 | d->bufStderr.resize( 0 ); | 548 | d->bufStderr.resize( 0 ); |
545 | } else { | 549 | } else { |
546 | QByteArray tmp( n - consume ); | 550 | QByteArray tmp( n - consume ); |
547 | memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); | 551 | memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); |
548 | d->bufStderr = tmp; | 552 | d->bufStderr = tmp; |
549 | } | 553 | } |
550 | } | 554 | } |
551 | 555 | ||
552 | /*! | 556 | /*! |
553 | Destroys the class. | 557 | Destroys the class. |
554 | 558 | ||
555 | If the process is running, it is NOT terminated! Standard input, standard | 559 | If the process is running, it is NOT terminated! Standard input, standard |
556 | output and standard error of the process are closed. | 560 | output and standard error of the process are closed. |
557 | 561 | ||
558 | You can connect the destroyed() signal to the kill() slot, if you want the | 562 | You can connect the destroyed() signal to the kill() slot, if you want the |
559 | process to be terminated automatically when the class is destroyed. | 563 | process to be terminated automatically when the class is destroyed. |
560 | 564 | ||
561 | \sa tryTerminate() kill() | 565 | \sa tryTerminate() kill() |
562 | */ | 566 | */ |
563 | QProcess::~QProcess() | 567 | QProcess::~QProcess() |
564 | { | 568 | { |
565 | delete d; | 569 | delete d; |
566 | } | 570 | } |
567 | 571 | ||
568 | /*! | 572 | /*! |
569 | Tries to run a process for the command and arguments that were specified with | 573 | Tries to run a process for the command and arguments that were specified with |
570 | setArguments(), addArgument() or that were specified in the constructor. The | 574 | setArguments(), addArgument() or that were specified in the constructor. The |
571 | command is searched in the path for executable programs; you can also use an | 575 | command is searched in the path for executable programs; you can also use an |
572 | absolute path to the command. | 576 | absolute path to the command. |
573 | 577 | ||
574 | If \a env is null, then the process is started with the same environment as | 578 | If \a env is null, then the process is started with the same environment as |
575 | the starting process. If \a env is non-null, then the values in the | 579 | the starting process. If \a env is non-null, then the values in the |
576 | stringlist are interpreted as environment setttings of the form \c | 580 | stringlist are interpreted as environment setttings of the form \c |
577 | {key=value} and the process is started in these environment settings. For | 581 | {key=value} and the process is started in these environment settings. For |
578 | convenience, there is a small exception to this rule: under Unix, if \a env | 582 | convenience, there is a small exception to this rule: under Unix, if \a env |
579 | does not contain any settings for the environment variable \c | 583 | does not contain any settings for the environment variable \c |
580 | LD_LIBRARY_PATH, then this variable is inherited from the starting process; | 584 | LD_LIBRARY_PATH, then this variable is inherited from the starting process; |
581 | under Windows the same applies for the enverionment varialbe \c PATH. | 585 | under Windows the same applies for the enverionment varialbe \c PATH. |
582 | 586 | ||
583 | Returns TRUE if the process could be started, otherwise FALSE. | 587 | Returns TRUE if the process could be started, otherwise FALSE. |
584 | 588 | ||
585 | You can write data to standard input of the process with | 589 | You can write data to standard input of the process with |
586 | writeToStdin(), you can close standard input with closeStdin() and you can | 590 | writeToStdin(), you can close standard input with closeStdin() and you can |
587 | terminate the process tryTerminate() resp. kill(). | 591 | terminate the process tryTerminate() resp. kill(). |
588 | 592 | ||
589 | You can call this function even when there already is a running | 593 | You can call this function even when there already is a running |
590 | process in this object. In this case, QProcess closes standard input | 594 | process in this object. In this case, QProcess closes standard input |
591 | of the old process and deletes pending data, i.e., you loose all | 595 | of the old process and deletes pending data, i.e., you loose all |
592 | control over that process, but the process is not terminated. This applies | 596 | control over that process, but the process is not terminated. This applies |
593 | also if the process could not be started. (On operating systems that have | 597 | also if the process could not be started. (On operating systems that have |
594 | zombie processes, Qt will also wait() on the old process.) | 598 | zombie processes, Qt will also wait() on the old process.) |
595 | 599 | ||
596 | \sa launch() closeStdin() | 600 | \sa launch() closeStdin() |
597 | */ | 601 | */ |
598 | bool QProcess::start( QStringList *env ) | 602 | bool QProcess::start( QStringList *env ) |
599 | { | 603 | { |
600 | #if defined(QT_QPROCESS_DEBUG) | 604 | #if defined(QT_QPROCESS_DEBUG) |
601 | odebug << "QProcess::start()" << oendl; | 605 | odebug << "QProcess::start()" << oendl; |
602 | #endif | 606 | #endif |
603 | reset(); | 607 | reset(); |
604 | 608 | ||
605 | int sStdin[2]; | 609 | int sStdin[2]; |
606 | int sStdout[2]; | 610 | int sStdout[2]; |
607 | int sStderr[2]; | 611 | int sStderr[2]; |
608 | 612 | ||
609 | // open sockets for piping | 613 | // open sockets for piping |
610 | if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) { | 614 | if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) { |
611 | return FALSE; | 615 | return FALSE; |
612 | } | 616 | } |
613 | if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) { | 617 | if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) { |
614 | return FALSE; | 618 | return FALSE; |
615 | } | 619 | } |
616 | if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) { | 620 | if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) { |
617 | return FALSE; | 621 | return FALSE; |
618 | } | 622 | } |
619 | 623 | ||
620 | // the following pipe is only used to determine if the process could be | 624 | // the following pipe is only used to determine if the process could be |
621 | // started | 625 | // started |
622 | int fd[2]; | 626 | int fd[2]; |
623 | if ( pipe( fd ) < 0 ) { | 627 | if ( pipe( fd ) < 0 ) { |
624 | // non critical error, go on | 628 | // non critical error, go on |
625 | fd[0] = 0; | 629 | fd[0] = 0; |
626 | fd[1] = 0; | 630 | fd[1] = 0; |
627 | } | 631 | } |
628 | 632 | ||
629 | // construct the arguments for exec | 633 | // construct the arguments for exec |
630 | QCString *arglistQ = new QCString[ _arguments.count() + 1 ]; | 634 | QCString *arglistQ = new QCString[ _arguments.count() + 1 ]; |
631 | const char** arglist = new const char*[ _arguments.count() + 1 ]; | 635 | const char** arglist = new const char*[ _arguments.count() + 1 ]; |
632 | int i = 0; | 636 | int i = 0; |
633 | for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) { | 637 | for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) { |
634 | arglistQ[i] = (*it).local8Bit(); | 638 | arglistQ[i] = (*it).local8Bit(); |
635 | arglist[i] = arglistQ[i]; | 639 | arglist[i] = arglistQ[i]; |
636 | #if defined(QT_QPROCESS_DEBUG) | 640 | #if defined(QT_QPROCESS_DEBUG) |
637 | odebug << "QProcess::start(): arg " << i << " = " << arglist[i] << "" << oendl; | 641 | odebug << "QProcess::start(): arg " << i << " = " << arglist[i] << "" << oendl; |
638 | #endif | 642 | #endif |
639 | i++; | 643 | i++; |
640 | } | 644 | } |
641 | arglist[i] = 0; | 645 | arglist[i] = 0; |
642 | 646 | ||
643 | // Must make sure signal handlers are installed before exec'ing | 647 | // Must make sure signal handlers are installed before exec'ing |
644 | // in case the process exits quickly. | 648 | // in case the process exits quickly. |
645 | if ( d->procManager == 0 ) { | 649 | if ( d->procManager == 0 ) { |
646 | d->procManager = new QProcessManager; | 650 | d->procManager = new QProcessManager; |
647 | qprocess_cleanup_procmanager.add( &d->procManager ); | 651 | qprocess_cleanup_procmanager.add( &d->procManager ); |
648 | } | 652 | } |
649 | 653 | ||
650 | // fork and exec | 654 | // fork and exec |
651 | QApplication::flushX(); | 655 | QApplication::flushX(); |
652 | pid_t pid = fork(); | 656 | pid_t pid = fork(); |
653 | if ( pid == 0 ) { | 657 | if ( pid == 0 ) { |
654 | // child | 658 | // child |
655 | d->closeOpenSocketsForChild(); | 659 | d->closeOpenSocketsForChild(); |
656 | if ( comms & Stdin ) { | 660 | if ( comms & Stdin ) { |
657 | ::close( sStdin[1] ); | 661 | ::close( sStdin[1] ); |
658 | ::dup2( sStdin[0], STDIN_FILENO ); | 662 | ::dup2( sStdin[0], STDIN_FILENO ); |
659 | } | 663 | } |
660 | if ( comms & Stdout ) { | 664 | if ( comms & Stdout ) { |
661 | ::close( sStdout[0] ); | 665 | ::close( sStdout[0] ); |
662 | ::dup2( sStdout[1], STDOUT_FILENO ); | 666 | ::dup2( sStdout[1], STDOUT_FILENO ); |
663 | } | 667 | } |
664 | if ( comms & Stderr ) { | 668 | if ( comms & Stderr ) { |
665 | ::close( sStderr[0] ); | 669 | ::close( sStderr[0] ); |
666 | ::dup2( sStderr[1], STDERR_FILENO ); | 670 | ::dup2( sStderr[1], STDERR_FILENO ); |
667 | } | 671 | } |
668 | if ( comms & DupStderr ) { | 672 | if ( comms & DupStderr ) { |
669 | ::dup2( STDOUT_FILENO, STDERR_FILENO ); | 673 | ::dup2( STDOUT_FILENO, STDERR_FILENO ); |
670 | } | 674 | } |
671 | #ifndef QT_NO_DIR | 675 | #ifndef QT_NO_DIR |
672 | ::chdir( workingDir.absPath().latin1() ); | 676 | ::chdir( workingDir.absPath().latin1() ); |
673 | #endif | 677 | #endif |
674 | if ( fd[0] ) | 678 | if ( fd[0] ) |
675 | ::close( fd[0] ); | 679 | ::close( fd[0] ); |
676 | if ( fd[1] ) | 680 | if ( fd[1] ) |
677 | ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess | 681 | ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess |
678 | 682 | ||
679 | if ( env == 0 ) { // inherit environment and start process | 683 | if ( env == 0 ) { // inherit environment and start process |
680 | ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice | 684 | ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice |
681 | } else { // start process with environment settins as specified in env | 685 | } else { // start process with environment settins as specified in env |
682 | // construct the environment for exec | 686 | // construct the environment for exec |
683 | int numEntries = env->count(); | 687 | int numEntries = env->count(); |
684 | bool setLibraryPath = | 688 | bool setLibraryPath = |
685 | env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && | 689 | env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && |
686 | getenv( "LD_LIBRARY_PATH" ) != 0; | 690 | getenv( "LD_LIBRARY_PATH" ) != 0; |
687 | if ( setLibraryPath ) | 691 | if ( setLibraryPath ) |
688 | numEntries++; | 692 | numEntries++; |
689 | QCString *envlistQ = new QCString[ numEntries + 1 ]; | 693 | QCString *envlistQ = new QCString[ numEntries + 1 ]; |
690 | const char** envlist = new const char*[ numEntries + 1 ]; | 694 | const char** envlist = new const char*[ numEntries + 1 ]; |
691 | int i = 0; | 695 | int i = 0; |
692 | if ( setLibraryPath ) { | 696 | if ( setLibraryPath ) { |
693 | envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); | 697 | envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); |
694 | envlist[i] = envlistQ[i]; | 698 | envlist[i] = envlistQ[i]; |
695 | i++; | 699 | i++; |
696 | } | 700 | } |
697 | for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { | 701 | for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { |
698 | envlistQ[i] = (*it).local8Bit(); | 702 | envlistQ[i] = (*it).local8Bit(); |
699 | envlist[i] = envlistQ[i]; | 703 | envlist[i] = envlistQ[i]; |
700 | i++; | 704 | i++; |
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp index 921b790..c45265a 100644 --- a/core/launcher/server.cpp +++ b/core/launcher/server.cpp | |||
@@ -1,1006 +1,1015 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "server.h" | 21 | #include "server.h" |
22 | #include "serverapp.h" | 22 | #include "serverapp.h" |
23 | #include "startmenu.h" | 23 | #include "startmenu.h" |
24 | #include "launcher.h" | 24 | #include "launcher.h" |
25 | #include "transferserver.h" | 25 | #include "transferserver.h" |
26 | #include "qcopbridge.h" | 26 | #include "qcopbridge.h" |
27 | #include "irserver.h" | 27 | #include "irserver.h" |
28 | #include "packageslave.h" | 28 | #include "packageslave.h" |
29 | #include "calibrate.h" | 29 | #include "calibrate.h" |
30 | #include "qrsync.h" | 30 | #include "qrsync.h" |
31 | #include "syncdialog.h" | 31 | #include "syncdialog.h" |
32 | #include "shutdownimpl.h" | 32 | #include "shutdownimpl.h" |
33 | #include "applauncher.h" | 33 | #include "applauncher.h" |
34 | #if 0 | 34 | #if 0 |
35 | #include "suspendmonitor.h" | 35 | #include "suspendmonitor.h" |
36 | #endif | 36 | #endif |
37 | #include "documentlist.h" | 37 | #include "documentlist.h" |
38 | #include "qrr.h" | 38 | #include "qrr.h" |
39 | 39 | ||
40 | /* OPIE */ | 40 | /* OPIE */ |
41 | #include <opie2/odebug.h> | 41 | #include <opie2/odebug.h> |
42 | #include <opie2/odevicebutton.h> | 42 | #include <opie2/odevicebutton.h> |
43 | #include <opie2/odevice.h> | 43 | #include <opie2/odevice.h> |
44 | #include <opie2/oprocess.h> | 44 | #include <opie2/oprocess.h> |
45 | 45 | ||
46 | #include <qtopia/applnk.h> | 46 | #include <qtopia/applnk.h> |
47 | #include <qtopia/private/categories.h> | 47 | #include <qtopia/private/categories.h> |
48 | #include <qtopia/mimetype.h> | 48 | #include <qtopia/mimetype.h> |
49 | #include <qtopia/config.h> | 49 | #include <qtopia/config.h> |
50 | #include <qtopia/resource.h> | 50 | #include <qtopia/resource.h> |
51 | #include <qtopia/version.h> | 51 | #include <qtopia/version.h> |
52 | #include <qtopia/storage.h> | 52 | #include <qtopia/storage.h> |
53 | #include <qtopia/qcopenvelope_qws.h> | 53 | #include <qtopia/qcopenvelope_qws.h> |
54 | #include <qtopia/global.h> | 54 | #include <qtopia/global.h> |
55 | using namespace Opie::Core; | 55 | using namespace Opie::Core; |
56 | 56 | ||
57 | /* QT */ | 57 | /* QT */ |
58 | #include <qmainwindow.h> | 58 | #include <qmainwindow.h> |
59 | #include <qmessagebox.h> | 59 | #include <qmessagebox.h> |
60 | #include <qtimer.h> | 60 | #include <qtimer.h> |
61 | #include <qtextstream.h> | 61 | #include <qtextstream.h> |
62 | #include <qwindowsystem_qws.h> | 62 | #include <qwindowsystem_qws.h> |
63 | #include <qgfx_qws.h> | 63 | #include <qgfx_qws.h> |
64 | 64 | ||
65 | /* STD */ | 65 | /* STD */ |
66 | #include <unistd.h> | 66 | #include <unistd.h> |
67 | #include <stdlib.h> | 67 | #include <stdlib.h> |
68 | 68 | ||
69 | extern QRect qt_maxWindowRect; | 69 | extern QRect qt_maxWindowRect; |
70 | 70 | ||
71 | static QWidget *calibrate(bool) | 71 | static QWidget *calibrate(bool) |
72 | { | 72 | { |
73 | #ifdef Q_WS_QWS | 73 | #ifdef Q_WS_QWS |
74 | Calibrate *c = new Calibrate; | 74 | Calibrate *c = new Calibrate; |
75 | c->show(); | 75 | c->show(); |
76 | return c; | 76 | return c; |
77 | #else | 77 | #else |
78 | return 0; | 78 | return 0; |
79 | #endif | 79 | #endif |
80 | } | 80 | } |
81 | 81 | ||
82 | #define FACTORY(T) \ | 82 | #define FACTORY(T) \ |
83 | static QWidget *new##T( bool maximized ) { \ | 83 | static QWidget *new##T( bool maximized ) { \ |
84 | QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ | 84 | QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ |
85 | if ( maximized ) { \ | 85 | if ( maximized ) { \ |
86 | if ( qApp->desktop()->width() <= 350 ) { \ | 86 | if ( qApp->desktop()->width() <= 350 ) { \ |
87 | w->showMaximized(); \ | 87 | w->showMaximized(); \ |
88 | } else { \ | 88 | } else { \ |
89 | w->resize( QSize( 300, 300 ) ); \ | 89 | w->resize( QSize( 300, 300 ) ); \ |
90 | } \ | 90 | } \ |
91 | } \ | 91 | } \ |
92 | w->show(); \ | 92 | w->show(); \ |
93 | return w; \ | 93 | return w; \ |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | #ifdef SINGLE_APP | 97 | #ifdef SINGLE_APP |
98 | #define APP(a,b,c,d) FACTORY(b) | 98 | #define APP(a,b,c,d) FACTORY(b) |
99 | #include "apps.h" | 99 | #include "apps.h" |
100 | #undef APP | 100 | #undef APP |
101 | #endif // SINGLE_APP | 101 | #endif // SINGLE_APP |
102 | 102 | ||
103 | static Global::Command builtins[] = { | 103 | static Global::Command builtins[] = { |
104 | 104 | ||
105 | #ifdef SINGLE_APP | 105 | #ifdef SINGLE_APP |
106 | #define APP(a,b,c,d) { a, new##b, c, d }, | 106 | #define APP(a,b,c,d) { a, new##b, c, d }, |
107 | #include "apps.h" | 107 | #include "apps.h" |
108 | #undef APP | 108 | #undef APP |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | /* FIXME defines need to be defined*/ | 111 | /* FIXME defines need to be defined*/ |
112 | #if !defined(OPIE_NO_BUILTIN_CALIBRATE) | 112 | #if !defined(OPIE_NO_BUILTIN_CALIBRATE) |
113 | { "calibrate", calibrate, 1, 0 }, // No tr | 113 | { "calibrate", calibrate, 1, 0 }, // No tr |
114 | #endif | 114 | #endif |
115 | #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) | 115 | #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) |
116 | { "shutdown", Global::shutdown, 1, 0 }, // No tr | 116 | { "shutdown", Global::shutdown, 1, 0 }, // No tr |
117 | // { "run", run, 1, 0 }, // No tr | 117 | // { "run", run, 1, 0 }, // No tr |
118 | #endif | 118 | #endif |
119 | 119 | ||
120 | { 0, calibrate, 0, 0 }, | 120 | { 0, calibrate, 0, 0 }, |
121 | }; | 121 | }; |
122 | 122 | ||
123 | #ifdef QPE_HAVE_DIRECT_ACCESS | 123 | #ifdef QPE_HAVE_DIRECT_ACCESS |
124 | extern void readyDirectAccess(QString cardInfo, QString installLocations); | 124 | extern void readyDirectAccess(QString cardInfo, QString installLocations); |
125 | extern const char *directAccessQueueFile(); | 125 | extern const char *directAccessQueueFile(); |
126 | #endif | 126 | #endif |
127 | 127 | ||
128 | //--------------------------------------------------------------------------- | 128 | //--------------------------------------------------------------------------- |
129 | 129 | ||
130 | 130 | ||
131 | //=========================================================================== | 131 | //=========================================================================== |
132 | 132 | ||
133 | Server::Server() : | 133 | Server::Server() : |
134 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | 134 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), |
135 | qcopBridge( 0 ), | 135 | qcopBridge( 0 ), |
136 | transferServer( 0 ), | 136 | transferServer( 0 ), |
137 | packageHandler( 0 ), | 137 | packageHandler( 0 ), |
138 | syncDialog( 0 ), | 138 | syncDialog( 0 ), |
139 | process( 0 ) | 139 | process( 0 ) |
140 | { | 140 | { |
141 | Global::setBuiltinCommands(builtins); | 141 | Global::setBuiltinCommands(builtins); |
142 | 142 | ||
143 | tid_xfer = 0; | 143 | tid_xfer = 0; |
144 | /* ### FIXME ### */ | 144 | /* ### FIXME ### */ |
145 | /* tid_today = startTimer(3600*2*1000);*/ | 145 | /* tid_today = startTimer(3600*2*1000);*/ |
146 | last_today_show = QDate::currentDate(); | 146 | last_today_show = QDate::currentDate(); |
147 | 147 | ||
148 | #warning FIXME support TempScreenSaverMode | 148 | #warning FIXME support TempScreenSaverMode |
149 | #if 0 | 149 | #if 0 |
150 | tsmMonitor = new TempScreenSaverMode(); | 150 | tsmMonitor = new TempScreenSaverMode(); |
151 | connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); | 151 | connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); |
152 | #endif | 152 | #endif |
153 | 153 | ||
154 | serverGui = new Launcher; | 154 | serverGui = new Launcher; |
155 | serverGui->createGUI(); | 155 | serverGui->createGUI(); |
156 | 156 | ||
157 | docList = new DocumentList( serverGui ); | 157 | docList = new DocumentList( serverGui ); |
158 | appLauncher = new AppLauncher(this); | 158 | appLauncher = new AppLauncher(this); |
159 | connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) ); | 159 | connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) ); |
160 | connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) ); | 160 | connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) ); |
161 | connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) ); | 161 | connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) ); |
162 | 162 | ||
163 | storage = new StorageInfo( this ); | 163 | storage = new StorageInfo( this ); |
164 | connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); | 164 | connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); |
165 | 165 | ||
166 | 166 | ||
167 | #ifdef QPE_HAVE_DIRECT_ACCESS | 167 | #ifdef QPE_HAVE_DIRECT_ACCESS |
168 | QCopChannel *desktopChannel = new QCopChannel( "QPE/Desktop", this ); | 168 | QCopChannel *desktopChannel = new QCopChannel( "QPE/Desktop", this ); |
169 | connect( desktopChannel, SIGNAL(received( const QCString &, const QByteArray & )), | 169 | connect( desktopChannel, SIGNAL(received( const QCString &, const QByteArray & )), |
170 | this, SLOT(desktopMessage( const QCString &, const QByteArray & )) ); | 170 | this, SLOT(desktopMessage( const QCString &, const QByteArray & )) ); |
171 | #endif | 171 | #endif |
172 | 172 | ||
173 | soundServerExited(); | 173 | soundServerExited(); |
174 | 174 | ||
175 | // start services | 175 | // start services |
176 | startTransferServer(); | 176 | startTransferServer(); |
177 | (void) new IrServer( this ); | 177 | (void) new IrServer( this ); |
178 | 178 | ||
179 | packageHandler = new PackageHandler( this ); | 179 | packageHandler = new PackageHandler( this ); |
180 | connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), | 180 | connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), |
181 | this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); | 181 | this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); |
182 | 182 | ||
183 | setGeometry( -10, -10, 9, 9 ); | 183 | setGeometry( -10, -10, 9, 9 ); |
184 | 184 | ||
185 | QCopChannel *channel = new QCopChannel("QPE/System", this); | 185 | QCopChannel *channel = new QCopChannel("QPE/System", this); |
186 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | 186 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), |
187 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); | 187 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); |
188 | 188 | ||
189 | QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); | 189 | QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); |
190 | connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 190 | connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
191 | this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); | 191 | this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); |
192 | 192 | ||
193 | connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); | 193 | connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); |
194 | connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); | 194 | connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); |
195 | 195 | ||
196 | preloadApps(); | 196 | preloadApps(); |
197 | } | 197 | } |
198 | 198 | ||
199 | void Server::show() | 199 | void Server::show() |
200 | { | 200 | { |
201 | ServerApplication::login(TRUE); | 201 | ServerApplication::login(TRUE); |
202 | QWidget::show(); | 202 | QWidget::show(); |
203 | } | 203 | } |
204 | 204 | ||
205 | Server::~Server() | 205 | Server::~Server() |
206 | { | 206 | { |
207 | serverGui->destroyGUI(); | 207 | serverGui->destroyGUI(); |
208 | delete docList; | 208 | delete docList; |
209 | delete qcopBridge; | 209 | delete qcopBridge; |
210 | delete transferServer; | 210 | delete transferServer; |
211 | delete serverGui; | 211 | delete serverGui; |
212 | #if 0 | 212 | #if 0 |
213 | delete tsmMonitor; | 213 | delete tsmMonitor; |
214 | #endif | 214 | #endif |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | static bool hasVisibleWindow(const QString& clientname, bool partial) | 218 | static bool hasVisibleWindow(const QString& clientname, bool partial) |
219 | { | 219 | { |
220 | #ifdef QWS | 220 | #ifdef QWS |
221 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 221 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
222 | QWSWindow* w; | 222 | QWSWindow* w; |
223 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { | 223 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { |
224 | if ( w->client()->identity() == clientname ) { | 224 | if ( w->client()->identity() == clientname ) { |
225 | if ( partial && !w->isFullyObscured() ) | 225 | if ( partial && !w->isFullyObscured() ) |
226 | return TRUE; | 226 | return TRUE; |
227 | if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { | 227 | if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { |
228 | # if QT_VERSION < 0x030000 | 228 | # if QT_VERSION < 0x030000 |
229 | QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, | 229 | QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, |
230 | QSize(qt_screen->width(),qt_screen->height()) ); | 230 | QSize(qt_screen->width(),qt_screen->height()) ); |
231 | # else | 231 | # else |
232 | QRect mwr = qt_maxWindowRect; | 232 | QRect mwr = qt_maxWindowRect; |
233 | # endif | 233 | # endif |
234 | if ( mwr.contains(w->requested().boundingRect()) ) | 234 | if ( mwr.contains(w->requested().boundingRect()) ) |
235 | return TRUE; | 235 | return TRUE; |
236 | } | 236 | } |
237 | } | 237 | } |
238 | } | 238 | } |
239 | #endif | 239 | #endif |
240 | return FALSE; | 240 | return FALSE; |
241 | } | 241 | } |
242 | 242 | ||
243 | void Server::activate(const ODeviceButton* button, bool held) | 243 | void Server::activate(const ODeviceButton* button, bool held) |
244 | { | 244 | { |
245 | Global::terminateBuiltin("calibrate"); // No tr | 245 | Global::terminateBuiltin("calibrate"); // No tr |
246 | OQCopMessage om; | 246 | OQCopMessage om; |
247 | if ( held ) { | 247 | if ( held ) { |
248 | om = button->heldAction(); | 248 | om = button->heldAction(); |
249 | } else { | 249 | } else { |
250 | om = button->pressedAction(); | 250 | om = button->pressedAction(); |
251 | } | 251 | } |
252 | 252 | ||
253 | if ( om.channel() != "ignore" ) | 253 | if ( om.channel() != "ignore" ) |
254 | om.send(); | 254 | om.send(); |
255 | 255 | ||
256 | // A button with no action defined, will return a null ServiceRequest. Don't attempt | 256 | // A button with no action defined, will return a null ServiceRequest. Don't attempt |
257 | // to send/do anything with this as it will crash | 257 | // to send/do anything with this as it will crash |
258 | /* ### FIXME */ | 258 | /* ### FIXME */ |
259 | #if 0 | 259 | #if 0 |
260 | if ( !sr.isNull() ) { | 260 | if ( !sr.isNull() ) { |
261 | QString app = sr.app(); | 261 | QString app = sr.app(); |
262 | bool vis = hasVisibleWindow(app, app != "qpe"); | 262 | bool vis = hasVisibleWindow(app, app != "qpe"); |
263 | if ( sr.message() == "raise()" && vis ) { | 263 | if ( sr.message() == "raise()" && vis ) { |
264 | sr.setMessage("nextView()"); | 264 | sr.setMessage("nextView()"); |
265 | } else { | 265 | } else { |
266 | // "back door" | 266 | // "back door" |
267 | sr << (int)vis; | 267 | sr << (int)vis; |
268 | } | 268 | } |
269 | 269 | ||
270 | sr.send(); | 270 | sr.send(); |
271 | } | 271 | } |
272 | #endif | 272 | #endif |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | #ifdef Q_WS_QWS | 276 | #ifdef Q_WS_QWS |
277 | 277 | ||
278 | typedef struct KeyOverride { | 278 | typedef struct KeyOverride { |
279 | ushort scan_code; | 279 | ushort scan_code; |
280 | QWSServer::KeyMap map; | 280 | QWSServer::KeyMap map; |
281 | }; | 281 | }; |
282 | 282 | ||
283 | 283 | ||
284 | static const KeyOverride jp109keys[] = { | 284 | static const KeyOverride jp109keys[] = { |
285 | { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, | 285 | { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, |
286 | { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, | 286 | { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, |
287 | { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, | 287 | { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, |
288 | { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, | 288 | { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, |
289 | { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, | 289 | { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, |
290 | { 0x0b, { Qt::Key_0, '0' , 0xffff, 0xffff } }, | 290 | { 0x0b, { Qt::Key_0, '0' , 0xffff, 0xffff } }, |
291 | { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, | 291 | { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, |
292 | { 0x0d, { Qt::Key_AsciiCircum, '^' , '~' , '^'-64 } }, | 292 | { 0x0d, { Qt::Key_AsciiCircum, '^' , '~' , '^'-64 } }, |
293 | { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, | 293 | { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, |
294 | { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '['-64 } }, | 294 | { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '['-64 } }, |
295 | { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, | 295 | { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, |
296 | { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, | 296 | { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, |
297 | { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff, 0xffff, 0xffff } }, | 297 | { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff, 0xffff, 0xffff } }, |
298 | { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, | 298 | { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, |
299 | { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff, 0xffff, 0xffff } }, | 299 | { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff, 0xffff, 0xffff } }, |
300 | { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, | 300 | { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, |
301 | { 0x79, { Qt::Key_Henkan, 0xffff, 0xffff, 0xffff } }, | 301 | { 0x79, { Qt::Key_Henkan, 0xffff, 0xffff, 0xffff } }, |
302 | { 0x7b, { Qt::Key_Muhenkan, 0xffff, 0xffff, 0xffff } }, | 302 | { 0x7b, { Qt::Key_Muhenkan, 0xffff, 0xffff, 0xffff } }, |
303 | { 0x7d, { Qt::Key_yen, 0x00a5, '|' , 0xffff } }, | 303 | { 0x7d, { Qt::Key_yen, 0x00a5, '|' , 0xffff } }, |
304 | { 0x00, { 0, 0xffff, 0xffff, 0xffff } } | 304 | { 0x00, { 0, 0xffff, 0xffff, 0xffff } } |
305 | }; | 305 | }; |
306 | 306 | ||
307 | bool Server::setKeyboardLayout( const QString &kb ) | 307 | bool Server::setKeyboardLayout( const QString &kb ) |
308 | { | 308 | { |
309 | //quick demo version that can be extended | 309 | //quick demo version that can be extended |
310 | 310 | ||
311 | QIntDict<QWSServer::KeyMap> *om = 0; | 311 | QIntDict<QWSServer::KeyMap> *om = 0; |
312 | if ( kb == "us101" ) { // No tr | 312 | if ( kb == "us101" ) { // No tr |
313 | om = 0; | 313 | om = 0; |
314 | } else if ( kb == "jp109" ) { | 314 | } else if ( kb == "jp109" ) { |
315 | om = new QIntDict<QWSServer::KeyMap>(37); | 315 | om = new QIntDict<QWSServer::KeyMap>(37); |
316 | const KeyOverride *k = jp109keys; | 316 | const KeyOverride *k = jp109keys; |
317 | while ( k->scan_code ) { | 317 | while ( k->scan_code ) { |
318 | om->insert( k->scan_code, &k->map ); | 318 | om->insert( k->scan_code, &k->map ); |
319 | k++; | 319 | k++; |
320 | } | 320 | } |
321 | } | 321 | } |
322 | QWSServer::setOverrideKeys( om ); | 322 | QWSServer::setOverrideKeys( om ); |
323 | 323 | ||
324 | return TRUE; | 324 | return TRUE; |
325 | } | 325 | } |
326 | #endif | 326 | #endif |
327 | 327 | ||
328 | void Server::systemMsg(const QCString &msg, const QByteArray &data) | 328 | void Server::systemMsg(const QCString &msg, const QByteArray &data) |
329 | { | 329 | { |
330 | QDataStream stream( data, IO_ReadOnly ); | 330 | QDataStream stream( data, IO_ReadOnly ); |
331 | 331 | ||
332 | if ( msg == "securityChanged()" ) { | 332 | if ( msg == "securityChanged()" ) { |
333 | if ( transferServer ) | 333 | if ( transferServer ) |
334 | transferServer->authorizeConnections(); | 334 | transferServer->authorizeConnections(); |
335 | 335 | ||
336 | if ( qcopBridge ) | 336 | if ( qcopBridge ) |
337 | qcopBridge->authorizeConnections(); | 337 | qcopBridge->authorizeConnections(); |
338 | #warning FIXME support TempScreenSaverMode | 338 | #warning FIXME support TempScreenSaverMode |
339 | #if 0 | 339 | #if 0 |
340 | } else if ( msg == "setTempScreenSaverMode(int,int)" ) { | 340 | } else if ( msg == "setTempScreenSaverMode(int,int)" ) { |
341 | int mode, pid; | 341 | int mode, pid; |
342 | stream >> mode >> pid; | 342 | stream >> mode >> pid; |
343 | tsmMonitor->setTempMode(mode, pid); | 343 | tsmMonitor->setTempMode(mode, pid); |
344 | #endif | 344 | #endif |
345 | } else if ( msg == "linkChanged(QString)" ) { | 345 | } else if ( msg == "linkChanged(QString)" ) { |
346 | QString link; | 346 | QString link; |
347 | stream >> link; | 347 | stream >> link; |
348 | odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; | 348 | odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; |
349 | docList->linkChanged(link); | 349 | docList->linkChanged(link); |
350 | } else if (msg =="reforceDocuments()") { | 350 | } else if (msg =="reforceDocuments()") { |
351 | docList->reforceDocuments(); | 351 | docList->reforceDocuments(); |
352 | } else if ( msg == "serviceChanged(QString)" ) { | 352 | } else if ( msg == "serviceChanged(QString)" ) { |
353 | MimeType::updateApplications(); | 353 | MimeType::updateApplications(); |
354 | } else if ( msg == "mkdir(QString)" ) { | 354 | } else if ( msg == "mkdir(QString)" ) { |
355 | QString dir; | 355 | QString dir; |
356 | stream >> dir; | 356 | stream >> dir; |
357 | if ( !dir.isEmpty() ) | 357 | if ( !dir.isEmpty() ) |
358 | mkdir( dir ); | 358 | mkdir( dir ); |
359 | } else if ( msg == "rdiffGenSig(QString,QString)" ) { | 359 | } else if ( msg == "rdiffGenSig(QString,QString)" ) { |
360 | QString baseFile, sigFile; | 360 | QString baseFile, sigFile; |
361 | stream >> baseFile >> sigFile; | 361 | stream >> baseFile >> sigFile; |
362 | QRsync::generateSignature( baseFile, sigFile ); | 362 | QRsync::generateSignature( baseFile, sigFile ); |
363 | } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { | 363 | } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { |
364 | QString baseFile, sigFile, deltaFile; | 364 | QString baseFile, sigFile, deltaFile; |
365 | stream >> baseFile >> sigFile >> deltaFile; | 365 | stream >> baseFile >> sigFile >> deltaFile; |
366 | QRsync::generateDiff( baseFile, sigFile, deltaFile ); | 366 | QRsync::generateDiff( baseFile, sigFile, deltaFile ); |
367 | } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { | 367 | } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { |
368 | QString baseFile, deltaFile; | 368 | QString baseFile, deltaFile; |
369 | stream >> baseFile >> deltaFile; | 369 | stream >> baseFile >> deltaFile; |
370 | bool fileWasCreated = false; | ||
370 | if ( !QFile::exists( baseFile ) ) { | 371 | if ( !QFile::exists( baseFile ) ) { |
371 | QFile f( baseFile ); | 372 | QFile f( baseFile ); |
372 | f.open( IO_WriteOnly ); | 373 | fileWasCreated = f.open( IO_WriteOnly ); |
373 | f.close(); | 374 | f.close(); |
374 | } | 375 | } |
375 | QRsync::applyDiff( baseFile, deltaFile ); | 376 | if ( fileWasCreated ) { |
377 | QRsync::applyDiff( baseFile, deltaFile ); | ||
376 | #ifndef QT_NO_COP | 378 | #ifndef QT_NO_COP |
377 | QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); | 379 | QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); |
378 | e << baseFile; | 380 | e << baseFile; |
379 | #endif | 381 | #endif |
382 | } else { | ||
383 | #ifndef QT_NO_COP | ||
384 | QCopEnvelope e( "QPE/Desktop", "patchUnapplied(QString)" ); | ||
385 | e << baseFile; | ||
386 | #endif | ||
387 | } | ||
380 | } else if ( msg == "rdiffCleanup()" ) { | 388 | } else if ( msg == "rdiffCleanup()" ) { |
381 | mkdir( "/tmp/rdiff" ); | 389 | mkdir( "/tmp/rdiff" ); |
382 | QDir dir; | 390 | QDir dir; |
383 | dir.setPath( "/tmp/rdiff" ); | 391 | dir.setPath( "/tmp/rdiff" ); |
384 | QStringList entries = dir.entryList(); | 392 | QStringList entries = dir.entryList(); |
385 | for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) | 393 | for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) |
386 | dir.remove( *it ); | 394 | dir.remove( *it ); |
387 | } else if ( msg == "sendHandshakeInfo()" ) { | 395 | } else if ( msg == "sendHandshakeInfo()" ) { |
388 | QString home = getenv( "HOME" ); | 396 | QString home = getenv( "HOME" ); |
389 | #ifndef QT_NO_COP | 397 | #ifndef QT_NO_COP |
390 | QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); | 398 | QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); |
391 | e << home; | 399 | e << home; |
392 | int locked = (int) ServerApplication::screenLocked(); | 400 | int locked = (int) ServerApplication::screenLocked(); |
393 | e << locked; | 401 | e << locked; |
394 | #endif | 402 | #endif |
395 | } else if ( msg == "sendVersionInfo()" ) { | 403 | } else if ( msg == "sendVersionInfo()" ) { |
396 | /* | 404 | /* |
397 | * @&$*! Qtopiadesktop relies on the major number | 405 | * @&$*! Qtopiadesktop relies on the major number |
398 | * to start with 1. (or 2 as the case of version 2.1 will be) | 406 | * to start with 1. (or 2 as the case of version 2.1 will be) |
399 | * we need to fake 1.7 to be able | 407 | * we need to fake 1.7 to be able |
400 | * to sync with Qtopiadesktop 1.7. | 408 | * to sync with Qtopiadesktop 1.7. |
401 | * We'll send it Opie's version in the platform string for now, | 409 | * We'll send it Opie's version in the platform string for now, |
402 | * until such time when QD gets rewritten correctly. | 410 | * until such time when QD gets rewritten correctly. |
403 | */ | 411 | */ |
404 | QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); | 412 | QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); |
405 | 413 | ||
406 | QString opiename = "Opie "+QString(QPE_VERSION); | 414 | QString opiename = "Opie "+QString(QPE_VERSION); |
407 | QString QDVersion="1.7"; | 415 | QString QDVersion="1.7"; |
408 | e << QDVersion << opiename; | 416 | e << QDVersion << opiename; |
409 | 417 | ||
410 | } else if ( msg == "sendCardInfo()" ) { | 418 | } else if ( msg == "sendCardInfo()" ) { |
411 | #ifndef QT_NO_COP | 419 | #ifndef QT_NO_COP |
412 | QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); | 420 | QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); |
413 | #endif | 421 | #endif |
414 | storage->update(); | 422 | storage->update(); |
415 | const QList<FileSystem> &fs = storage->fileSystems(); | 423 | const QList<FileSystem> &fs = storage->fileSystems(); |
416 | QListIterator<FileSystem> it ( fs ); | 424 | QListIterator<FileSystem> it ( fs ); |
417 | QString s; | 425 | QString s; |
418 | QString homeDir = getenv("HOME"); | 426 | QString homeDir = getenv("HOME"); |
419 | QString homeFs, homeFsPath; | 427 | QString homeFs, homeFsPath; |
420 | for ( ; it.current(); ++it ) { | 428 | for ( ; it.current(); ++it ) { |
421 | int k4 = (*it)->blockSize()/256; | 429 | int k4 = (*it)->blockSize()/256; |
422 | if ( (*it)->isRemovable() ) { | 430 | if ( (*it)->isRemovable() ) { |
423 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr | 431 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr |
424 | + QString::number( (*it)->availBlocks() * k4/4 ) | 432 | + QString::number( (*it)->availBlocks() * k4/4 ) |
425 | + "K " + (*it)->options() + ";"; | 433 | + "K " + (*it)->options() + ";"; |
426 | } else if ( homeDir.contains( (*it)->path() ) && | 434 | } else if ( homeDir.contains( (*it)->path() ) && |
427 | (*it)->path().length() > homeFsPath.length() ) { | 435 | (*it)->path().length() > homeFsPath.length() ) { |
428 | homeFsPath = (*it)->path(); | 436 | homeFsPath = (*it)->path(); |
429 | homeFs = | 437 | homeFs = |
430 | (*it)->name() + "=" + homeDir + "/Documents " // No tr | 438 | (*it)->name() + "=" + homeDir + "/Documents " // No tr |
431 | + QString::number( (*it)->availBlocks() * k4/4 ) | 439 | + QString::number( (*it)->availBlocks() * k4/4 ) |
432 | + "K " + (*it)->options() + ";"; | 440 | + "K " + (*it)->options() + ";"; |
433 | } | 441 | } |
434 | } | 442 | } |
435 | if ( !homeFs.isEmpty() ) | 443 | if ( !homeFs.isEmpty() ) |
436 | s += homeFs; | 444 | s += homeFs; |
437 | #ifndef QT_NO_COP | 445 | #ifndef QT_NO_COP |
438 | e << s; | 446 | e << s; |
439 | #endif | 447 | #endif |
440 | } else if ( msg == "sendInstallLocations()" ) { | 448 | } else if ( msg == "sendInstallLocations()" ) { |
441 | #ifndef QT_NO_COP | 449 | #ifndef QT_NO_COP |
442 | QCopEnvelope e( "QPE/Desktop", "installLocations(QString)" ); | 450 | QCopEnvelope e( "QPE/Desktop", "installLocations(QString)" ); |
443 | e << installLocationsString(); | 451 | e << installLocationsString(); |
444 | #endif | 452 | #endif |
445 | } else if ( msg == "sendSyncDate(QString)" ) { | 453 | } else if ( msg == "sendSyncDate(QString)" ) { |
446 | QString app; | 454 | QString app; |
447 | stream >> app; | 455 | stream >> app; |
448 | Config cfg( "qpe" ); | 456 | Config cfg( "qpe" ); |
449 | cfg.setGroup("SyncDate"); | 457 | cfg.setGroup("SyncDate"); |
450 | #ifndef QT_NO_COP | 458 | #ifndef QT_NO_COP |
451 | QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); | 459 | QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); |
452 | e << app << cfg.readEntry( app ); | 460 | e << app << cfg.readEntry( app ); |
453 | #endif | 461 | #endif |
454 | //odebug << "QPE/System sendSyncDate for " << app.latin1() << ": response " | 462 | //odebug << "QPE/System sendSyncDate for " << app.latin1() << ": response " |
455 | // << cfg.readEntry( app ).latin1() << oendl; | 463 | // << cfg.readEntry( app ).latin1() << oendl; |
456 | } else if ( msg == "setSyncDate(QString,QString)" ) { | 464 | } else if ( msg == "setSyncDate(QString,QString)" ) { |
457 | QString app, date; | 465 | QString app, date; |
458 | stream >> app >> date; | 466 | stream >> app >> date; |
459 | Config cfg( "qpe" ); | 467 | Config cfg( "qpe" ); |
460 | cfg.setGroup("SyncDate"); | 468 | cfg.setGroup("SyncDate"); |
461 | cfg.writeEntry( app, date ); | 469 | cfg.writeEntry( app, date ); |
462 | //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; | 470 | //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; |
463 | } else if ( msg == "startSync(QString)" ) { | 471 | } else if ( msg == "startSync(QString)" ) { |
464 | QString what; | 472 | QString what; |
465 | stream >> what; | 473 | stream >> what; |
466 | delete syncDialog; | 474 | delete syncDialog; |
467 | syncDialog = new SyncDialog( this, what ); | 475 | syncDialog = new SyncDialog( this, what ); |
468 | syncDialog->show(); | 476 | syncDialog->show(); |
469 | connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); | 477 | connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); |
470 | } else if ( msg == "stopSync()") { | 478 | } else if ( msg == "stopSync()") { |
471 | delete syncDialog; | 479 | delete syncDialog; |
472 | syncDialog = 0; | 480 | syncDialog = 0; |
473 | } else if (msg == "restoreDone(QString)") { | 481 | } else if (msg == "restoreDone(QString)") { |
474 | docList->restoreDone(); | 482 | docList->restoreDone(); |
475 | } else if ( msg == "getAllDocLinks()" ) { | 483 | } else if ( msg == "getAllDocLinks()" ) { |
476 | docList->sendAllDocLinks(); | 484 | docList->sendAllDocLinks(); |
477 | } | 485 | } |
478 | #ifdef QPE_HAVE_DIRECT_ACCESS | 486 | #ifdef QPE_HAVE_DIRECT_ACCESS |
479 | else if ( msg == "prepareDirectAccess()" ) { | 487 | else if ( msg == "prepareDirectAccess()" ) { |
480 | prepareDirectAccess(); | 488 | prepareDirectAccess(); |
481 | } else if ( msg == "postDirectAccess()" ) { | 489 | } else if ( msg == "postDirectAccess()" ) { |
482 | postDirectAccess(); | 490 | postDirectAccess(); |
483 | } | 491 | } |
484 | #endif | 492 | #endif |
485 | #ifdef Q_WS_QWS | 493 | #ifdef Q_WS_QWS |
486 | 494 | ||
487 | else if ( msg == "setMouseProto(QString)" ) { | 495 | else if ( msg == "setMouseProto(QString)" ) { |
488 | QString mice; | 496 | QString mice; |
489 | stream >> mice; | 497 | stream >> mice; |
490 | setenv("QWS_MOUSE_PROTO",mice.latin1(),1); | 498 | setenv("QWS_MOUSE_PROTO",mice.latin1(),1); |
491 | qwsServer->openMouse(); | 499 | qwsServer->openMouse(); |
492 | } else if ( msg == "setKeyboard(QString)" ) { | 500 | } else if ( msg == "setKeyboard(QString)" ) { |
493 | QString kb; | 501 | QString kb; |
494 | stream >> kb; | 502 | stream >> kb; |
495 | setenv("QWS_KEYBOARD",kb.latin1(),1); | 503 | setenv("QWS_KEYBOARD",kb.latin1(),1); |
496 | qwsServer->openKeyboard(); | 504 | qwsServer->openKeyboard(); |
497 | } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { | 505 | } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { |
498 | int delay, period; | 506 | int delay, period; |
499 | stream >> delay >> period; | 507 | stream >> delay >> period; |
500 | qwsSetKeyboardAutoRepeat( delay, period ); | 508 | qwsSetKeyboardAutoRepeat( delay, period ); |
501 | Config cfg( "qpe" ); | 509 | Config cfg( "qpe" ); |
502 | cfg.setGroup("Keyboard"); | 510 | cfg.setGroup("Keyboard"); |
503 | cfg.writeEntry( "RepeatDelay", delay ); | 511 | cfg.writeEntry( "RepeatDelay", delay ); |
504 | cfg.writeEntry( "RepeatPeriod", period ); | 512 | cfg.writeEntry( "RepeatPeriod", period ); |
505 | } else if ( msg == "setKeyboardLayout(QString)" ) { | 513 | } else if ( msg == "setKeyboardLayout(QString)" ) { |
506 | QString kb; | 514 | QString kb; |
507 | stream >> kb; | 515 | stream >> kb; |
508 | setKeyboardLayout( kb ); | 516 | setKeyboardLayout( kb ); |
509 | Config cfg( "qpe" ); | 517 | Config cfg( "qpe" ); |
510 | cfg.setGroup("Keyboard"); | 518 | cfg.setGroup("Keyboard"); |
511 | cfg.writeEntry( "Layout", kb ); | 519 | cfg.writeEntry( "Layout", kb ); |
512 | } else if ( msg == "autoStart(QString)" ) { | 520 | } else if ( msg == "autoStart(QString)" ) { |
513 | QString appName; | 521 | QString appName; |
514 | stream >> appName; | 522 | stream >> appName; |
515 | Config cfg( "autostart" ); | 523 | Config cfg( "autostart" ); |
516 | cfg.setGroup( "AutoStart" ); | 524 | cfg.setGroup( "AutoStart" ); |
517 | if ( appName.compare("clear") == 0){ | 525 | if ( appName.compare("clear") == 0){ |
518 | cfg.writeEntry("Apps", ""); | 526 | cfg.writeEntry("Apps", ""); |
519 | } | 527 | } |
520 | } else if ( msg == "autoStart(QString,QString)" ) { | 528 | } else if ( msg == "autoStart(QString,QString)" ) { |
521 | QString modifier, appName; | 529 | QString modifier, appName; |
522 | stream >> modifier >> appName; | 530 | stream >> modifier >> appName; |
523 | Config cfg( "autostart" ); | 531 | Config cfg( "autostart" ); |
524 | cfg.setGroup( "AutoStart" ); | 532 | cfg.setGroup( "AutoStart" ); |
525 | if ( modifier.compare("add") == 0 ){ | 533 | if ( modifier.compare("add") == 0 ){ |
526 | // only add if appname is entered | 534 | // only add if appname is entered |
527 | if (!appName.isEmpty()) { | 535 | if (!appName.isEmpty()) { |
528 | cfg.writeEntry("Apps", appName); | 536 | cfg.writeEntry("Apps", appName); |
529 | } | 537 | } |
530 | } else if (modifier.compare("remove") == 0 ) { | 538 | } else if (modifier.compare("remove") == 0 ) { |
531 | // need to change for multiple entries | 539 | // need to change for multiple entries |
532 | // actually remove is right now simular to clear, but in future there | 540 | // actually remove is right now simular to clear, but in future there |
533 | // should be multiple apps in autostart possible. | 541 | // should be multiple apps in autostart possible. |
534 | QString checkName; | 542 | QString checkName; |
535 | checkName = cfg.readEntry("Apps", ""); | 543 | checkName = cfg.readEntry("Apps", ""); |
536 | if (checkName == appName) { | 544 | if (checkName == appName) { |
537 | cfg.writeEntry("Apps", ""); | 545 | cfg.writeEntry("Apps", ""); |
538 | } | 546 | } |
539 | } | 547 | } |
540 | // case the autostart feature should be delayed | 548 | // case the autostart feature should be delayed |
541 | } else if ( msg == "autoStart(QString,QString,QString)") { | 549 | } else if ( msg == "autoStart(QString,QString,QString)") { |
542 | QString modifier, appName, delay; | 550 | QString modifier, appName, delay; |
543 | stream >> modifier >> appName >> delay; | 551 | stream >> modifier >> appName >> delay; |
544 | Config cfg( "autostart" ); | 552 | Config cfg( "autostart" ); |
545 | 553 | ||
546 | cfg.setGroup( "AutoStart" ); | 554 | cfg.setGroup( "AutoStart" ); |
547 | if ( modifier.compare("add") == 0 ){ | 555 | if ( modifier.compare("add") == 0 ){ |
548 | // only add it appname is entered | 556 | // only add it appname is entered |
549 | if (!appName.isEmpty()) { | 557 | if (!appName.isEmpty()) { |
550 | cfg.writeEntry("Apps", appName); | 558 | cfg.writeEntry("Apps", appName); |
551 | cfg.writeEntry("Delay", delay); | 559 | cfg.writeEntry("Delay", delay); |
552 | } | 560 | } |
553 | } | 561 | } |
554 | } | 562 | } |
555 | #endif | 563 | #endif |
556 | } | 564 | } |
557 | 565 | ||
558 | QString Server::cardInfoString() | 566 | QString Server::cardInfoString() |
559 | { | 567 | { |
560 | storage->update(); | 568 | storage->update(); |
561 | const QList<FileSystem> &fs = storage->fileSystems(); | 569 | const QList<FileSystem> &fs = storage->fileSystems(); |
562 | QListIterator<FileSystem> it ( fs ); | 570 | QListIterator<FileSystem> it ( fs ); |
563 | QString s; | 571 | QString s; |
564 | QString homeDir = getenv("HOME"); | 572 | QString homeDir = getenv("HOME"); |
565 | QString homeFs, homeFsPath; | 573 | QString homeFs, homeFsPath; |
566 | for ( ; it.current(); ++it ) { | 574 | for ( ; it.current(); ++it ) { |
567 | int k4 = (*it)->blockSize()/256; | 575 | int k4 = (*it)->blockSize()/256; |
568 | if ( (*it)->isRemovable() ) { | 576 | if ( (*it)->isRemovable() ) { |
569 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr | 577 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr |
570 | + QString::number( (*it)->availBlocks() * k4/4 ) | 578 | + QString::number( (*it)->availBlocks() * k4/4 ) |
571 | + "K " + (*it)->options() + ";"; | 579 | + "K " + (*it)->options() + ";"; |
572 | } else if ( homeDir.contains( (*it)->path() ) && | 580 | } else if ( homeDir.contains( (*it)->path() ) && |
573 | (*it)->path().length() > homeFsPath.length() ) { | 581 | (*it)->path().length() > homeFsPath.length() ) { |
574 | homeFsPath = (*it)->path(); | 582 | homeFsPath = (*it)->path(); |
575 | homeFs = | 583 | homeFs = |
576 | (*it)->name() + "=" + homeDir + "/Documents " // No tr | 584 | (*it)->name() + "=" + homeDir + "/Documents " // No tr |
577 | + QString::number( (*it)->availBlocks() * k4/4 ) | 585 | + QString::number( (*it)->availBlocks() * k4/4 ) |
578 | + "K " + (*it)->options() + ";"; | 586 | + "K " + (*it)->options() + ";"; |
579 | } | 587 | } |
580 | } | 588 | } |
581 | if ( !homeFs.isEmpty() ) | 589 | if ( !homeFs.isEmpty() ) |
582 | s += homeFs; | 590 | s += homeFs; |
583 | return s; | 591 | return s; |
584 | } | 592 | } |
585 | 593 | ||
586 | QString Server::installLocationsString() | 594 | QString Server::installLocationsString() |
587 | { | 595 | { |
588 | storage->update(); | 596 | storage->update(); |
589 | const QList<FileSystem> &fs = storage->fileSystems(); | 597 | const QList<FileSystem> &fs = storage->fileSystems(); |
590 | QListIterator<FileSystem> it ( fs ); | 598 | QListIterator<FileSystem> it ( fs ); |
591 | QString s; | 599 | QString s; |
592 | QString homeDir = getenv("HOME"); | 600 | QString homeDir = getenv("HOME"); |
593 | QString homeFs, homeFsPath; | 601 | QString homeFs, homeFsPath; |
594 | for ( ; it.current(); ++it ) { | 602 | for ( ; it.current(); ++it ) { |
595 | int k4 = (*it)->blockSize()/256; | 603 | int k4 = (*it)->blockSize()/256; |
596 | if ( (*it)->isRemovable() ) { | 604 | if ( (*it)->isRemovable() ) { |
597 | s += (*it)->name() + "=" + (*it)->path() + " " // No tr | 605 | s += (*it)->name() + "=" + (*it)->path() + " " // No tr |
598 | + QString::number( (*it)->availBlocks() * k4/4 ) | 606 | + QString::number( (*it)->availBlocks() * k4/4 ) |
599 | + "K " + (*it)->options() + ";"; | 607 | + "K " + (*it)->options() + ";"; |
600 | } else if ( homeDir.contains( (*it)->path() ) && | 608 | } else if ( homeDir.contains( (*it)->path() ) && |
601 | (*it)->path().length() > homeFsPath.length() ) { | 609 | (*it)->path().length() > homeFsPath.length() ) { |
602 | homeFsPath = (*it)->path(); | 610 | homeFsPath = (*it)->path(); |
603 | homeFs = | 611 | homeFs = |
604 | (*it)->name() + "=" + homeDir + " " // No tr | 612 | (*it)->name() + "=" + homeDir + " " // No tr |
605 | + QString::number( (*it)->availBlocks() * k4/4 ) | 613 | + QString::number( (*it)->availBlocks() * k4/4 ) |
606 | + "K " + (*it)->options() + ";"; | 614 | + "K " + (*it)->options() + ";"; |
607 | } | 615 | } |
608 | } | 616 | } |
609 | if ( !homeFs.isEmpty() ) | 617 | if ( !homeFs.isEmpty() ) |
610 | s = homeFs + s; | 618 | s = homeFs + s; |
611 | return s; | 619 | return s; |
612 | } | 620 | } |
613 | 621 | ||
614 | void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) | 622 | void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) |
615 | { | 623 | { |
616 | QDataStream stream( data, IO_ReadOnly ); | 624 | QDataStream stream( data, IO_ReadOnly ); |
617 | 625 | ||
618 | if ( msg == "reloadApps()" ) { | 626 | if ( msg == "reloadApps()" ) { |
619 | docList->reloadAppLnks(); | 627 | docList->reloadAppLnks(); |
620 | } else if ( msg == "soundAlarm()" ) { | 628 | } else if ( msg == "soundAlarm()" ) { |
621 | ServerApplication::soundAlarm(); | 629 | ServerApplication::soundAlarm(); |
622 | } else if ( msg == "setLed(int,bool)" ) { | 630 | } else if ( msg == "setLed(int,bool)" ) { |
623 | int led, status; | 631 | int led, status; |
624 | stream >> led >> status; | 632 | stream >> led >> status; |
625 | 633 | ||
626 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); | 634 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); |
627 | if ( ll. count ( )) { | 635 | if ( ll. count ( )) { |
628 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; | 636 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; |
629 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); | 637 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); |
630 | 638 | ||
631 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); | 639 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); |
632 | } | 640 | } |
633 | } | 641 | } |
634 | } | 642 | } |
635 | 643 | ||
636 | void Server::cancelSync() | 644 | void Server::cancelSync() |
637 | { | 645 | { |
638 | #ifndef QT_NO_COP | 646 | #ifndef QT_NO_COP |
639 | QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); | 647 | QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); |
640 | #endif | 648 | #endif |
641 | delete syncDialog; | 649 | delete syncDialog; |
642 | syncDialog = 0; | 650 | syncDialog = 0; |
643 | } | 651 | } |
644 | 652 | ||
645 | bool Server::mkdir(const QString &localPath) | 653 | bool Server::mkdir(const QString &localPath) |
646 | { | 654 | { |
647 | QDir fullDir(localPath); | 655 | QDir fullDir(localPath); |
648 | if (fullDir.exists()) | 656 | if (fullDir.exists()) |
649 | return true; | 657 | return true; |
650 | 658 | ||
651 | // at this point the directory doesn't exist | 659 | // at this point the directory doesn't exist |
652 | // go through the directory tree and start creating the direcotories | 660 | // go through the directory tree and start creating the direcotories |
653 | // that don't exist; if we can't create the directories, return false | 661 | // that don't exist; if we can't create the directories, return false |
654 | 662 | ||
655 | QString dirSeps = "/"; | 663 | QString dirSeps = "/"; |
656 | int dirIndex = localPath.find(dirSeps); | 664 | int dirIndex = localPath.find(dirSeps); |
657 | QString checkedPath; | 665 | QString checkedPath; |
658 | 666 | ||
659 | // didn't find any seps; weird, use the cur dir instead | 667 | // didn't find any seps; weird, use the cur dir instead |
660 | if (dirIndex == -1) { | 668 | if (dirIndex == -1) { |
661 | //odebug << "No seperators found in path " << localPath << "" << oendl; | 669 | //odebug << "No seperators found in path " << localPath << "" << oendl; |
662 | checkedPath = QDir::currentDirPath(); | 670 | checkedPath = QDir::currentDirPath(); |
663 | } | 671 | } |
664 | 672 | ||
665 | while (checkedPath != localPath) { | 673 | while (checkedPath != localPath) { |
666 | // no more seperators found, use the local path | 674 | // no more seperators found, use the local path |
667 | if (dirIndex == -1) { | 675 | if (dirIndex == -1) { |
668 | checkedPath = localPath; | 676 | checkedPath = localPath; |
669 | } else { | 677 | } else { |
670 | // the next directory to check | 678 | // the next directory to check |
671 | checkedPath = localPath.left(dirIndex) + "/"; | 679 | checkedPath = localPath.left(dirIndex) + "/"; |
672 | // advance the iterator; the next dir seperator | 680 | // advance the iterator; the next dir seperator |
673 | dirIndex = localPath.find(dirSeps, dirIndex+1); | 681 | dirIndex = localPath.find(dirSeps, dirIndex+1); |
674 | } | 682 | } |
675 | 683 | ||
676 | QDir checkDir(checkedPath); | 684 | QDir checkDir(checkedPath); |
677 | if (!checkDir.exists()) { | 685 | if (!checkDir.exists()) { |
678 | //odebug << "mkdir making dir " << checkedPath << "" << oendl; | 686 | //odebug << "mkdir making dir " << checkedPath << "" << oendl; |
679 | 687 | ||
680 | if (!checkDir.mkdir(checkedPath)) { | 688 | if (!checkDir.mkdir(checkedPath)) { |
681 | odebug << "Unable to make directory " << checkedPath << "" << oendl; | 689 | odebug << "Unable to make directory " << checkedPath << "" << oendl; |
682 | return FALSE; | 690 | return FALSE; |
683 | } | 691 | } |
684 | } | 692 | } |
685 | 693 | ||
686 | } | 694 | } |
687 | return TRUE; | 695 | return TRUE; |
688 | } | 696 | } |
689 | 697 | ||
690 | void Server::styleChange( QStyle &s ) | 698 | void Server::styleChange( QStyle &s ) |
691 | { | 699 | { |
692 | QWidget::styleChange( s ); | 700 | QWidget::styleChange( s ); |
693 | } | 701 | } |
694 | 702 | ||
695 | void Server::startTransferServer() | 703 | void Server::startTransferServer() |
696 | { | 704 | { |
697 | if ( !qcopBridge ) { | 705 | if ( !qcopBridge ) { |
698 | // start qcop bridge server | 706 | // start qcop bridge server |
699 | qcopBridge = new QCopBridge( 4243 ); | 707 | qcopBridge = new QCopBridge( 4243 ); |
700 | if ( qcopBridge->ok() ) { | 708 | if ( qcopBridge->ok() ) { |
701 | // ... OK | 709 | // ... OK |
702 | connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), | 710 | connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), |
703 | this, SLOT(syncConnectionClosed(const QHostAddress&)) ); | 711 | this, SLOT(syncConnectionClosed(const QHostAddress&)) ); |
704 | } else { | 712 | } else { |
705 | delete qcopBridge; | 713 | delete qcopBridge; |
706 | qcopBridge = 0; | 714 | qcopBridge = 0; |
707 | } | 715 | } |
708 | } | 716 | } |
709 | 717 | ||
710 | if ( !transferServer ) { | 718 | if ( !transferServer ) { |
711 | // start transfer server | 719 | // start transfer server |
712 | transferServer = new TransferServer( 4242 ); | 720 | transferServer = new TransferServer( 4242 ); |
713 | if ( transferServer->ok() ) { | 721 | if ( transferServer->ok() ) { |
714 | // ... OK | 722 | // ... OK |
715 | } else { | 723 | } else { |
716 | delete transferServer; | 724 | delete transferServer; |
717 | transferServer = 0; | 725 | transferServer = 0; |
718 | } | 726 | } |
719 | 727 | ||
720 | if ( !qcopBridge ) | 728 | if ( !qcopBridge ) |
721 | tid_xfer = startTimer( 2000 ); | 729 | tid_xfer = startTimer( 2000 ); |
722 | } | 730 | } |
723 | } | 731 | } |
724 | 732 | ||
725 | void Server::timerEvent( QTimerEvent *e ) | 733 | void Server::timerEvent( QTimerEvent *e ) |
726 | { | 734 | { |
727 | if ( e->timerId() == tid_xfer ) { | 735 | if ( e->timerId() == tid_xfer ) { |
728 | killTimer( tid_xfer ); | 736 | killTimer( tid_xfer ); |
729 | tid_xfer = 0; | 737 | tid_xfer = 0; |
730 | startTransferServer(); | 738 | startTransferServer(); |
731 | } | 739 | } |
732 | #if 0 | 740 | #if 0 |
733 | /* ### FIXME today startin */ | 741 | /* ### FIXME today startin */ |
734 | else if ( e->timerId() == tid_today ) { | 742 | else if ( e->timerId() == tid_today ) { |
735 | QDate today = QDate::currentDate(); | 743 | QDate today = QDate::currentDate(); |
736 | if ( today != last_today_show ) { | 744 | if ( today != last_today_show ) { |
737 | last_today_show = today; | 745 | last_today_show = today; |
738 | Config cfg("today"); | 746 | Config cfg("today"); |
739 | cfg.setGroup("Start"); | 747 | cfg.setGroup("Start"); |
740 | #ifndef QPE_DEFAULT_TODAY_MODE | 748 | #ifndef QPE_DEFAULT_TODAY_MODE |
741 | #define QPE_DEFAULT_TODAY_MODE "Never" | 749 | #define QPE_DEFAULT_TODAY_MODE "Never" |
742 | #endif | 750 | #endif |
743 | if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { | 751 | if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { |
744 | QCopEnvelope env(Service::channel("today"),"raise()"); | 752 | QCopEnvelope env(Service::channel("today"),"raise()"); |
745 | } | 753 | } |
746 | } | 754 | } |
747 | } | 755 | } |
748 | #endif | 756 | #endif |
749 | } | 757 | } |
750 | 758 | ||
751 | void Server::terminateServers() | 759 | void Server::terminateServers() |
752 | { | 760 | { |
753 | delete transferServer; | 761 | delete transferServer; |
754 | delete qcopBridge; | 762 | delete qcopBridge; |
755 | transferServer = 0; | 763 | transferServer = 0; |
756 | qcopBridge = 0; | 764 | qcopBridge = 0; |
757 | } | 765 | } |
758 | 766 | ||
759 | void Server::syncConnectionClosed( const QHostAddress & ) | 767 | void Server::syncConnectionClosed( const QHostAddress & ) |
760 | { | 768 | { |
761 | odebug << "Lost sync connection" << oendl; | 769 | odebug << "Lost sync connection" << oendl; |
762 | delete syncDialog; | 770 | delete syncDialog; |
763 | syncDialog = 0; | 771 | syncDialog = 0; |
764 | } | 772 | } |
765 | 773 | ||
766 | void Server::pokeTimeMonitors() | 774 | void Server::pokeTimeMonitors() |
767 | { | 775 | { |
768 | #if 0 | 776 | #if 0 |
769 | // inform all TimeMonitors | 777 | // inform all TimeMonitors |
770 | QStrList tms = Service::channels("TimeMonitor"); | 778 | QStrList tms = Service::channels("TimeMonitor"); |
771 | for (const char* ch = tms.first(); ch; ch=tms.next()) { | 779 | for (const char* ch = tms.first(); ch; ch=tms.next()) { |
772 | QString t = getenv("TZ"); | 780 | QString t = getenv("TZ"); |
773 | QCopEnvelope e(ch, "timeChange(QString)"); | 781 | QCopEnvelope e(ch, "timeChange(QString)"); |
774 | e << t; | 782 | e << t; |
775 | } | 783 | } |
776 | #endif | 784 | #endif |
777 | } | 785 | } |
778 | 786 | ||
779 | void Server::applicationLaunched(int, const QString &app) | 787 | void Server::applicationLaunched(int, const QString &app) |
780 | { | 788 | { |
781 | serverGui->applicationStateChanged( app, ServerInterface::Launching ); | 789 | serverGui->applicationStateChanged( app, ServerInterface::Launching ); |
782 | } | 790 | } |
783 | 791 | ||
784 | void Server::applicationTerminated(int pid, const QString &app) | 792 | void Server::applicationTerminated(int pid, const QString &app) |
785 | { | 793 | { |
786 | serverGui->applicationStateChanged( app, ServerInterface::Terminated ); | 794 | serverGui->applicationStateChanged( app, ServerInterface::Terminated ); |
787 | #if 0 | 795 | #if 0 |
788 | tsmMonitor->applicationTerminated( pid ); | 796 | tsmMonitor->applicationTerminated( pid ); |
789 | #else | 797 | #else |
790 | Q_UNUSED( pid ) | 798 | Q_UNUSED( pid ) |
791 | #endif | 799 | #endif |
792 | } | 800 | } |
793 | 801 | ||
794 | void Server::applicationConnected(const QString &app) | 802 | void Server::applicationConnected(const QString &app) |
795 | { | 803 | { |
796 | serverGui->applicationStateChanged( app, ServerInterface::Running ); | 804 | serverGui->applicationStateChanged( app, ServerInterface::Running ); |
797 | } | 805 | } |
798 | 806 | ||
799 | void Server::storageChanged() | 807 | void Server::storageChanged() |
800 | { | 808 | { |
801 | system( "opie-update-symlinks" ); | 809 | system( "opie-update-symlinks" ); |
802 | serverGui->storageChanged( storage->fileSystems() ); | 810 | serverGui->storageChanged( storage->fileSystems() ); |
803 | docList->storageChanged(); | 811 | docList->storageChanged(); |
804 | } | 812 | } |
805 | 813 | ||
806 | 814 | ||
807 | 815 | ||
808 | void Server::preloadApps() | 816 | void Server::preloadApps() |
809 | { | 817 | { |
810 | Config cfg("Launcher"); | 818 | Config cfg("Launcher"); |
811 | cfg.setGroup("Preload"); | 819 | cfg.setGroup("Preload"); |
812 | QStringList apps = cfg.readListEntry("Apps",','); | 820 | QStringList apps = cfg.readListEntry("Apps",','); |
813 | for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { | 821 | for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { |
814 | #ifndef QT_NO_COP | 822 | #ifndef QT_NO_COP |
815 | QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); | 823 | QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); |
816 | #endif | 824 | #endif |
817 | } | 825 | } |
818 | } | 826 | } |
819 | 827 | ||
820 | // This is only called if QPE_HAVE_DIRECT_ACCESS is defined | 828 | // This is only called if QPE_HAVE_DIRECT_ACCESS is defined |
821 | void Server::prepareDirectAccess() | 829 | void Server::prepareDirectAccess() |
822 | { | 830 | { |
823 | qDebug( "Server::prepareDirectAccess()" ); | 831 | qDebug( "Server::prepareDirectAccess()" ); |
824 | // Put up a pretty dialog | 832 | // Put up a pretty dialog |
825 | syncDialog = new SyncDialog( this, tr("USB Lock") ); | 833 | syncDialog = new SyncDialog( this, tr("USB Lock") ); |
826 | syncDialog->show(); | 834 | syncDialog->show(); |
827 | 835 | ||
828 | // Prevent the PDA from acting as a PDA | 836 | // Prevent the PDA from acting as a PDA |
829 | terminateServers(); | 837 | terminateServers(); |
830 | 838 | ||
831 | // suspend the mtab monitor | 839 | // suspend the mtab monitor |
832 | #ifndef QT_NO_COP | 840 | #ifndef QT_NO_COP |
833 | { | 841 | { |
834 | QCopEnvelope e( "QPE/Stabmon", "suspendMonitor()" ); | 842 | QCopEnvelope e( "QPE/Stabmon", "suspendMonitor()" ); |
835 | } | 843 | } |
836 | #endif | 844 | #endif |
837 | 845 | ||
838 | // send out a flush message | 846 | // send out a flush message |
839 | // once flushes are done call runDirectAccess() | 847 | // once flushes are done call runDirectAccess() |
840 | // We just count the number of apps and set a timer. | 848 | // We just count the number of apps and set a timer. |
841 | // Either the timer expires or the correct number of apps responds. | 849 | // Either the timer expires or the correct number of apps responds. |
842 | // Note: quicklauncher isn't in the runningApps list but it responds | 850 | // Note: quicklauncher isn't in the runningApps list but it responds |
843 | // to the flush so we start the counter at 1 | 851 | // to the flush so we start the counter at 1 |
844 | pendingFlushes = 1; | 852 | pendingFlushes = 1; |
845 | directAccessRun = FALSE; | 853 | directAccessRun = FALSE; |
846 | for ( QMap<int,QString>::ConstIterator it = | 854 | for ( QMap<int,QString>::ConstIterator it = |
847 | appLauncher->runningApplications().begin(); | 855 | appLauncher->runningApplications().begin(); |
848 | it != appLauncher->runningApplications().end(); | 856 | it != appLauncher->runningApplications().end(); |
849 | ++it ) { | 857 | ++it ) { |
850 | pendingFlushes++; | 858 | pendingFlushes++; |
851 | } | 859 | } |
852 | #ifndef QT_NO_COP | 860 | #ifndef QT_NO_COP |
853 | QCopEnvelope e1( "QPE/System", "flush()" ); | 861 | QCopEnvelope e1( "QPE/System", "flush()" ); |
854 | #endif | 862 | #endif |
855 | QTimer::singleShot( 10000, this, SLOT(runDirectAccess()) ); | 863 | QTimer::singleShot( 10000, this, SLOT(runDirectAccess()) ); |
856 | #warning FIXME support TempScreenSaverMode | 864 | #warning FIXME support TempScreenSaverMode |
857 | #if 0 | 865 | #if 0 |
858 | QPEApplication::setTempScreenSaverMode(QPEApplication::DisableSuspend); | 866 | QPEApplication::setTempScreenSaverMode(QPEApplication::DisableSuspend); |
859 | #endif | 867 | #endif |
860 | } | 868 | } |
861 | 869 | ||
862 | // This is only connected if QPE_HAVE_DIRECT_ACCESS is defined | 870 | // This is only connected if QPE_HAVE_DIRECT_ACCESS is defined |
863 | // It fakes the presence of Qtopia Desktop | 871 | // It fakes the presence of Qtopia Desktop |
864 | void Server::desktopMessage( const QCString &message, const QByteArray &data ) | 872 | void Server::desktopMessage( const QCString &message, const QByteArray &data ) |
865 | { | 873 | { |
866 | QDataStream stream( data, IO_ReadOnly ); | 874 | QDataStream stream( data, IO_ReadOnly ); |
867 | if ( message == "flushDone(QString)" ) { | 875 | if ( message == "flushDone(QString)" ) { |
868 | QString app; | 876 | QString app; |
869 | stream >> app; | 877 | stream >> app; |
870 | qDebug( "flushDone from %s", app.latin1() ); | 878 | qDebug( "flushDone from %s", app.latin1() ); |
871 | if ( --pendingFlushes == 0 ) { | 879 | if ( --pendingFlushes == 0 ) { |
872 | qDebug( "pendingFlushes == 0, all the apps responded" ); | 880 | qDebug( "pendingFlushes == 0, all the apps responded" ); |
873 | runDirectAccess(); | 881 | runDirectAccess(); |
874 | } | 882 | } |
875 | } else if ( message == "installStarted(QString)" ) { | 883 | } else if ( message == "installStarted(QString)" ) { |
876 | QString package; | 884 | QString package; |
877 | stream >> package; | 885 | stream >> package; |
878 | qDebug( "\tInstall Started for package %s", package.latin1() ); | 886 | qDebug( "\tInstall Started for package %s", package.latin1() ); |
879 | } else if ( message == "installStep(QString)" ) { | 887 | } else if ( message == "installStep(QString)" ) { |
880 | QString step; | 888 | QString step; |
881 | stream >> step; | 889 | stream >> step; |
882 | qDebug( "\tInstall Step %s", step.latin1() ); | 890 | qDebug( "\tInstall Step %s", step.latin1() ); |
883 | } else if ( message == "installDone(QString)" ) { | 891 | } else if ( message == "installDone(QString)" ) { |
884 | QString package; | 892 | QString package; |
885 | stream >> package; | 893 | stream >> package; |
886 | qDebug( "\tInstall Finished for package %s", package.latin1() ); | 894 | qDebug( "\tInstall Finished for package %s", package.latin1() ); |
887 | } else if ( message == "installFailed(QString,int,QString)" ) { | 895 | } else if ( message == "installFailed(QString,int,QString)" ) { |
888 | QString package, error; | 896 | QString package, error; |
889 | int status; | 897 | int status; |
890 | stream >> package >> status >> error; | 898 | stream >> package >> status >> error; |
891 | qDebug( "\tInstall Failed for package %s with error code %d and error message %s", | 899 | qDebug( "\tInstall Failed for package %s with error code %d and error message %s", |
892 | package.latin1(), status, error.latin1() ); | 900 | package.latin1(), status, error.latin1() ); |
893 | } else if ( message == "removeStarted(QString)" ) { | 901 | } else if ( message == "removeStarted(QString)" ) { |
894 | QString package; | 902 | QString package; |
895 | stream >> package; | 903 | stream >> package; |
896 | qDebug( "\tRemove Started for package %s", package.latin1() ); | 904 | qDebug( "\tRemove Started for package %s", package.latin1() ); |
897 | } else if ( message == "removeDone(QString)" ) { | 905 | } else if ( message == "removeDone(QString)" ) { |
898 | QString package; | 906 | QString package; |
899 | stream >> package; | 907 | stream >> package; |
900 | qDebug( "\tRemove Finished for package %s", package.latin1() ); | 908 | qDebug( "\tRemove Finished for package %s", package.latin1() ); |
901 | } else if ( message == "removeFailed(QString)" ) { | 909 | } else if ( message == "removeFailed(QString)" ) { |
902 | QString package; | 910 | QString package; |
903 | stream >> package; | 911 | stream >> package; |
904 | qDebug( "\tRemove Failed for package %s", package.latin1() ); | 912 | qDebug( "\tRemove Failed for package %s", package.latin1() ); |
905 | } | 913 | } |
906 | 914 | ||
907 | if ( qrr && qrr->waitingForMessages ) | 915 | if ( qrr && qrr->waitingForMessages ) |
908 | qrr->desktopMessage( message, data ); | 916 | qrr->desktopMessage( message, data ); |
909 | } | 917 | } |
910 | 918 | ||
911 | 919 | ||
912 | // This is only connected if QPE_HAVE_DIRECT_ACCESS is defined | 920 | // This is only connected if QPE_HAVE_DIRECT_ACCESS is defined |
913 | void Server::runDirectAccess() | 921 | void Server::runDirectAccess() |
914 | { | 922 | { |
915 | #ifdef QPE_HAVE_DIRECT_ACCESS | 923 | #ifdef QPE_HAVE_DIRECT_ACCESS |
916 | // The timer must have fired after all the apps responded | 924 | // The timer must have fired after all the apps responded |
917 | // with flushDone(). Just ignore it. | 925 | // with flushDone(). Just ignore it. |
918 | if ( directAccessRun ) | 926 | if ( directAccessRun ) |
919 | return; | 927 | return; |
920 | 928 | ||
921 | directAccessRun = TRUE; | 929 | directAccessRun = TRUE; |
922 | ::readyDirectAccess(cardInfoString(), installLocationsString()); | 930 | ::readyDirectAccess(cardInfoString(), installLocationsString()); |
923 | #endif | 931 | #endif |
924 | } | 932 | } |
925 | 933 | ||
926 | // This is only called if QPE_HAVE_DIRECT_ACCESS is defined | 934 | // This is only called if QPE_HAVE_DIRECT_ACCESS is defined |
927 | void Server::postDirectAccess() | 935 | void Server::postDirectAccess() |
928 | { | 936 | { |
929 | #ifdef QPE_HAVE_DIRECT_ACCESS | 937 | #ifdef QPE_HAVE_DIRECT_ACCESS |
930 | qDebug( "Server::postDirectAccess()" ); | 938 | qDebug( "Server::postDirectAccess()" ); |
931 | 939 | ||
932 | // Categories may have changed | 940 | // Categories may have changed |
933 | QCopEnvelope e1( "QPE/System", "categoriesChanged()" ); | 941 | QCopEnvelope e1( "QPE/System", "categoriesChanged()" ); |
934 | // Apps need to reload their data | 942 | // Apps need to reload their data |
935 | QCopEnvelope e2( "QPE/System", "reload()" ); | 943 | QCopEnvelope e2( "QPE/System", "reload()" ); |
936 | // Reload DocLinks | 944 | // Reload DocLinks |
937 | docList->storageChanged(); | 945 | docList->storageChanged(); |
938 | // Restart the PDA server stuff | 946 | // Restart the PDA server stuff |
939 | startTransferServer(); | 947 | startTransferServer(); |
940 | 948 | ||
941 | // restart the mtab monitor | 949 | // restart the mtab monitor |
942 | #ifndef QT_NO_COP | 950 | #ifndef QT_NO_COP |
943 | { | 951 | { |
944 | QCopEnvelope e( "QPE/Stabmon", "restartMonitor()" ); | 952 | QCopEnvelope e( "QPE/Stabmon", "restartMonitor()" ); |
945 | } | 953 | } |
946 | #endif | 954 | #endif |
947 | 955 | ||
948 | // Process queued requests | 956 | // Process queued requests |
949 | const char *queueFile = ::directAccessQueueFile(); | 957 | const char *queueFile = ::directAccessQueueFile(); |
950 | QFile *file = new QFile( queueFile ); | 958 | QFile *file = new QFile( queueFile ); |
951 | if ( !file->exists() ) { | 959 | if ( !file->exists() ) { |
952 | delete file; | 960 | delete file; |
953 | // Get rid of the dialog | 961 | // Get rid of the dialog |
954 | if ( syncDialog ) { | 962 | if ( syncDialog ) { |
955 | delete syncDialog; | 963 | delete syncDialog; |
956 | syncDialog = 0; | 964 | syncDialog = 0; |
957 | } | 965 | } |
958 | #warning FIXME support TempScreenSaverMode | 966 | #warning FIXME support TempScreenSaverMode |
959 | #if 0 | 967 | #if 0 |
960 | QPEApplication::setTempScreenSaverMode(QPEApplication::Enable); | 968 | QPEApplication::setTempScreenSaverMode(QPEApplication::Enable); |
961 | #endif | 969 | #endif |
962 | } else { | 970 | } else { |
963 | qrr = new QueuedRequestRunner( file, syncDialog ); | 971 | qrr = new QueuedRequestRunner( file, syncDialog ); |
964 | connect( qrr, SIGNAL(finished()), | 972 | connect( qrr, SIGNAL(finished()), |
965 | this, SLOT(finishedQueuedRequests()) ); | 973 | this, SLOT(finishedQueuedRequests()) ); |
966 | QTimer::singleShot( 100, qrr, SLOT(process()) ); | 974 | QTimer::singleShot( 100, qrr, SLOT(process()) ); |
967 | // qrr will remove the sync dialog later | 975 | // qrr will remove the sync dialog later |
968 | } | 976 | } |
969 | #endif | 977 | #endif |
970 | } | 978 | } |
971 | 979 | ||
972 | void Server::finishedQueuedRequests() | 980 | void Server::finishedQueuedRequests() |
973 | { | 981 | { |
974 | if ( qrr->readyToDelete ) { | 982 | if ( qrr->readyToDelete ) { |
975 | delete qrr; | 983 | delete qrr; |
976 | qrr = 0; | 984 | qrr = 0; |
977 | // Get rid of the dialog | 985 | // Get rid of the dialog |
978 | if ( syncDialog ) { | 986 | if ( syncDialog ) { |
979 | delete syncDialog; | 987 | delete syncDialog; |
980 | syncDialog = 0; | 988 | syncDialog = 0; |
981 | } | 989 | } |
982 | #warning FIXME support TempScreenSaverMode | 990 | #warning FIXME support TempScreenSaverMode |
983 | #if 0 | 991 | #if 0 |
984 | QPEApplication::setTempScreenSaverMode(QPEApplication::Enable); | 992 | QPEApplication::setTempScreenSaverMode(QPEApplication::Enable); |
985 | #endif | 993 | #endif |
986 | } else { | 994 | } else { |
987 | qrr->readyToDelete = TRUE; | 995 | qrr->readyToDelete = TRUE; |
988 | QTimer::singleShot( 0, this, SLOT(finishedQueuedRequests()) ); | 996 | QTimer::singleShot( 0, this, SLOT(finishedQueuedRequests()) ); |
989 | } | 997 | } |
990 | } | 998 | } |
991 | 999 | ||
992 | void Server::startSoundServer() { | 1000 | void Server::startSoundServer() { |
993 | if ( !process ) { | 1001 | if ( !process ) { |
994 | process = new Opie::Core::OProcess( this ); | 1002 | process = new Opie::Core::OProcess( this ); |
995 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), | 1003 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), |
996 | SLOT(soundServerExited())); | 1004 | SLOT(soundServerExited())); |
997 | } | 1005 | } |
998 | 1006 | ||
999 | process->clearArguments(); | 1007 | process->clearArguments(); |
1000 | *process << QPEApplication::qpeDir() + "bin/qss"; | 1008 | *process << QPEApplication::qpeDir() + "bin/qss"; |
1001 | process->start(); | 1009 | if (!process->start()) |
1010 | owarn << "Sound server process did not start" << oendl; | ||
1002 | } | 1011 | } |
1003 | 1012 | ||
1004 | void Server::soundServerExited() { | 1013 | void Server::soundServerExited() { |
1005 | QTimer::singleShot(5000, this, SLOT(startSoundServer())); | 1014 | QTimer::singleShot(5000, this, SLOT(startSoundServer())); |
1006 | } | 1015 | } |
diff --git a/core/settings/launcher/menusettings.cpp b/core/settings/launcher/menusettings.cpp index 29ce841..d63b203 100644 --- a/core/settings/launcher/menusettings.cpp +++ b/core/settings/launcher/menusettings.cpp | |||
@@ -1,178 +1,181 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> | 3 | =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> |
4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "menusettings.h" | 29 | #include "menusettings.h" |
30 | 30 | ||
31 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
32 | #include <qpe/qlibrary.h> | 32 | #include <qpe/qlibrary.h> |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #include <qpe/menuappletinterface.h> | 34 | #include <qpe/menuappletinterface.h> |
35 | #include <qpe/qcopenvelope_qws.h> | 35 | #include <qpe/qcopenvelope_qws.h> |
36 | #include <opie2/odebug.h> | ||
36 | 37 | ||
37 | #include <qdir.h> | 38 | #include <qdir.h> |
38 | #include <qlistview.h> | 39 | #include <qlistview.h> |
39 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
40 | #include <qheader.h> | 41 | #include <qheader.h> |
41 | #include <qlayout.h> | 42 | #include <qlayout.h> |
42 | #include <qlabel.h> | 43 | #include <qlabel.h> |
43 | #include <qwhatsthis.h> | 44 | #include <qwhatsthis.h> |
44 | 45 | ||
45 | #include <stdlib.h> | 46 | #include <stdlib.h> |
46 | 47 | ||
47 | 48 | ||
48 | MenuSettings::MenuSettings ( QWidget *parent, const char *name ) | 49 | MenuSettings::MenuSettings ( QWidget *parent, const char *name ) |
49 | : QWidget ( parent, name ) | 50 | : QWidget ( parent, name ) |
50 | { | 51 | { |
51 | m_applets_changed = false; | 52 | m_applets_changed = false; |
52 | 53 | ||
53 | QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); | 54 | QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); |
54 | 55 | ||
55 | QLabel *l = new QLabel ( tr( "Load applets in O-Menu:" ), this ); | 56 | QLabel *l = new QLabel ( tr( "Load applets in O-Menu:" ), this ); |
56 | lay-> addWidget ( l ); | 57 | lay-> addWidget ( l ); |
57 | 58 | ||
58 | m_list = new QListView ( this ); | 59 | m_list = new QListView ( this ); |
59 | m_list-> addColumn ( "foobar" ); | 60 | m_list-> addColumn ( "foobar" ); |
60 | m_list-> header ( )-> hide ( ); | 61 | m_list-> header ( )-> hide ( ); |
61 | 62 | ||
62 | lay-> addWidget ( m_list ); | 63 | lay-> addWidget ( m_list ); |
63 | 64 | ||
64 | m_menutabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this ); | 65 | m_menutabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this ); |
65 | lay-> addWidget ( m_menutabs ); | 66 | lay-> addWidget ( m_menutabs ); |
66 | 67 | ||
67 | m_menusubpopup = new QCheckBox ( tr( "Show Applications in Subpopups" ), this ); | 68 | m_menusubpopup = new QCheckBox ( tr( "Show Applications in Subpopups" ), this ); |
68 | lay-> addWidget ( m_menusubpopup ); | 69 | lay-> addWidget ( m_menusubpopup ); |
69 | 70 | ||
70 | QWhatsThis::add ( m_list, tr( "Check the applets that you want to have included in the O-Menu." )); | 71 | QWhatsThis::add ( m_list, tr( "Check the applets that you want to have included in the O-Menu." )); |
71 | QWhatsThis::add ( m_menutabs, tr( "Adds the contents of the Launcher Tabs as menus in the O-Menu." )); | 72 | QWhatsThis::add ( m_menutabs, tr( "Adds the contents of the Launcher Tabs as menus in the O-Menu." )); |
72 | 73 | ||
73 | connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); | 74 | connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); |
74 | 75 | ||
75 | init ( ); | 76 | init ( ); |
76 | } | 77 | } |
77 | 78 | ||
78 | void MenuSettings::init ( ) | 79 | void MenuSettings::init ( ) |
79 | { | 80 | { |
80 | Config cfg ( "StartMenu" ); | 81 | Config cfg ( "StartMenu" ); |
81 | cfg. setGroup ( "Applets" ); | 82 | cfg. setGroup ( "Applets" ); |
82 | QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); | 83 | QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); |
83 | 84 | ||
84 | QString path = QPEApplication::qpeDir ( ) + "plugins/applets"; | 85 | QString path = QPEApplication::qpeDir ( ) + "plugins/applets"; |
85 | #ifdef Q_OS_MACX | 86 | #ifdef Q_OS_MACX |
86 | QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); | 87 | QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); |
87 | #else | 88 | #else |
88 | QStringList list = QDir ( path, "lib*.so" ). entryList ( ); | 89 | QStringList list = QDir ( path, "lib*.so" ). entryList ( ); |
89 | #endif /* Q_OS_MACX */ | 90 | #endif /* Q_OS_MACX */ |
90 | 91 | ||
91 | for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { | 92 | for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { |
92 | QString name; | 93 | QString name; |
93 | QPixmap icon; | 94 | QPixmap icon; |
94 | MenuAppletInterface *iface = 0; | 95 | MenuAppletInterface *iface = 0; |
95 | 96 | ||
96 | QLibrary *lib = new QLibrary ( path + "/" + *it ); | 97 | QLibrary *lib = new QLibrary ( path + "/" + *it ); |
97 | lib-> queryInterface ( IID_MenuApplet, (QUnknownInterface**) &iface ); | 98 | QRESULT retVal = QS_OK; |
99 | if ((retVal = lib-> queryInterface ( IID_MenuApplet, (QUnknownInterface**)(&iface) )) != QS_OK ) | ||
100 | owarn << "queryInterface failed with " << retVal << oendl; | ||
98 | if ( iface ) { | 101 | if ( iface ) { |
99 | QString lang = getenv( "LANG" ); | 102 | QString lang = getenv( "LANG" ); |
100 | QTranslator *trans = new QTranslator ( qApp ); | 103 | QTranslator *trans = new QTranslator ( qApp ); |
101 | QString type = (*it). left ((*it). find (".")); | 104 | QString type = (*it). left ((*it). find (".")); |
102 | QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm"; | 105 | QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm"; |
103 | if ( trans-> load ( tfn )) | 106 | if ( trans-> load ( tfn )) |
104 | qApp-> installTranslator ( trans ); | 107 | qApp-> installTranslator ( trans ); |
105 | else | 108 | else |
106 | delete trans; | 109 | delete trans; |
107 | name = iface-> name ( ); | 110 | name = iface-> name ( ); |
108 | icon = iface-> icon ( ). pixmap (); | 111 | icon = iface-> icon ( ). pixmap (); |
109 | iface-> release ( ); | 112 | iface-> release ( ); |
110 | lib-> unload ( ); | 113 | lib-> unload ( ); |
111 | 114 | ||
112 | QCheckListItem *item; | 115 | QCheckListItem *item; |
113 | item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); | 116 | item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); |
114 | if ( !icon. isNull ( )) | 117 | if ( !icon. isNull ( )) |
115 | item-> setPixmap ( 0, icon ); | 118 | item-> setPixmap ( 0, icon ); |
116 | item-> setOn ( exclude. find ( *it ) == exclude. end ( )); | 119 | item-> setOn ( exclude. find ( *it ) == exclude. end ( )); |
117 | m_applets [*it] = item; | 120 | m_applets [*it] = item; |
118 | } else { | 121 | } else { |
119 | delete lib; | 122 | delete lib; |
120 | } | 123 | } |
121 | } | 124 | } |
122 | 125 | ||
123 | cfg. setGroup ( "Menu" ); | 126 | cfg. setGroup ( "Menu" ); |
124 | m_menutabs->setChecked( cfg.readBoolEntry( "LauncherTabs", true ) ); | 127 | m_menutabs->setChecked( cfg.readBoolEntry( "LauncherTabs", true ) ); |
125 | m_menusubpopup->setChecked( cfg.readBoolEntry( "LauncherSubPopup", true ) ); | 128 | m_menusubpopup->setChecked( cfg.readBoolEntry( "LauncherSubPopup", true ) ); |
126 | m_menusubpopup->setEnabled( m_menutabs->isChecked() ); | 129 | m_menusubpopup->setEnabled( m_menutabs->isChecked() ); |
127 | connect( m_menutabs, SIGNAL( stateChanged(int) ), m_menusubpopup, SLOT( setEnabled(bool) ) ); | 130 | connect( m_menutabs, SIGNAL( stateChanged(int) ), m_menusubpopup, SLOT( setEnabled(bool) ) ); |
128 | 131 | ||
129 | } | 132 | } |
130 | 133 | ||
131 | void MenuSettings::appletChanged() | 134 | void MenuSettings::appletChanged() |
132 | { | 135 | { |
133 | m_applets_changed = true; | 136 | m_applets_changed = true; |
134 | } | 137 | } |
135 | 138 | ||
136 | void MenuSettings::accept ( ) | 139 | void MenuSettings::accept ( ) |
137 | { | 140 | { |
138 | bool apps_changed = false; | 141 | bool apps_changed = false; |
139 | 142 | ||
140 | Config cfg ( "StartMenu" ); | 143 | Config cfg ( "StartMenu" ); |
141 | cfg. setGroup ( "Applets" ); | 144 | cfg. setGroup ( "Applets" ); |
142 | if ( m_applets_changed ) { | 145 | if ( m_applets_changed ) { |
143 | QStringList exclude; | 146 | QStringList exclude; |
144 | QMap <QString, QCheckListItem *>::Iterator it; | 147 | QMap <QString, QCheckListItem *>::Iterator it; |
145 | for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { | 148 | for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { |
146 | if ( !(*it)-> isOn ( )) | 149 | if ( !(*it)-> isOn ( )) |
147 | exclude << it. key ( ); | 150 | exclude << it. key ( ); |
148 | } | 151 | } |
149 | cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); | 152 | cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); |
150 | } | 153 | } |
151 | cfg. writeEntry ( "SafeMode", false ); | 154 | cfg. writeEntry ( "SafeMode", false ); |
152 | 155 | ||
153 | cfg. setGroup ( "Menu" ); | 156 | cfg. setGroup ( "Menu" ); |
154 | 157 | ||
155 | if ( m_menutabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) { | 158 | if ( m_menutabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) { |
156 | apps_changed = true; | 159 | apps_changed = true; |
157 | cfg. writeEntry ( "LauncherTabs", m_menutabs-> isChecked ( )); | 160 | cfg. writeEntry ( "LauncherTabs", m_menutabs-> isChecked ( )); |
158 | } | 161 | } |
159 | 162 | ||
160 | if ( m_menusubpopup-> isChecked ( ) != cfg. readBoolEntry ( "LauncherSubPopup", true )) { | 163 | if ( m_menusubpopup-> isChecked ( ) != cfg. readBoolEntry ( "LauncherSubPopup", true )) { |
161 | apps_changed = true; | 164 | apps_changed = true; |
162 | cfg. writeEntry ( "LauncherSubPopup", m_menusubpopup-> isChecked ( )); | 165 | cfg. writeEntry ( "LauncherSubPopup", m_menusubpopup-> isChecked ( )); |
163 | } | 166 | } |
164 | 167 | ||
165 | cfg. write ( ); | 168 | cfg. write ( ); |
166 | 169 | ||
167 | if ( m_applets_changed ) { | 170 | if ( m_applets_changed ) { |
168 | QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" ); | 171 | QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" ); |
169 | m_applets_changed = false; | 172 | m_applets_changed = false; |
170 | } | 173 | } |
171 | if ( apps_changed ) { | 174 | if ( apps_changed ) { |
172 | // currently use reloadApplets() since reloadApps is now used exclusive for server | 175 | // currently use reloadApplets() since reloadApps is now used exclusive for server |
173 | // to refresh the tabs. But what we want here is also a refresh of the startmenu entries | 176 | // to refresh the tabs. But what we want here is also a refresh of the startmenu entries |
174 | QCopEnvelope ( "QPE/TaskBar", "reloadApps()" ); | 177 | QCopEnvelope ( "QPE/TaskBar", "reloadApps()" ); |
175 | QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" ); | 178 | QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" ); |
176 | } | 179 | } |
177 | } | 180 | } |
178 | 181 | ||
diff --git a/core/settings/launcher/taskbarsettings.cpp b/core/settings/launcher/taskbarsettings.cpp index 861ff3a..c2b82b9 100644 --- a/core/settings/launcher/taskbarsettings.cpp +++ b/core/settings/launcher/taskbarsettings.cpp | |||
@@ -1,176 +1,179 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> | 3 | =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> |
4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "taskbarsettings.h" | 29 | #include "taskbarsettings.h" |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <qpe/qlibrary.h> | 33 | #include <qpe/qlibrary.h> |
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/taskbarappletinterface.h> | 35 | #include <qpe/taskbarappletinterface.h> |
36 | #include <qpe/qcopenvelope_qws.h> | 36 | #include <qpe/qcopenvelope_qws.h> |
37 | #include <opie2/odebug.h> | 37 | #include <opie2/odebug.h> |
38 | 38 | ||
39 | /* QT */ | 39 | /* QT */ |
40 | #include <qdir.h> | 40 | #include <qdir.h> |
41 | #include <qlistview.h> | 41 | #include <qlistview.h> |
42 | #include <qheader.h> | 42 | #include <qheader.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | #include <qlabel.h> | 44 | #include <qlabel.h> |
45 | #include <qwhatsthis.h> | 45 | #include <qwhatsthis.h> |
46 | 46 | ||
47 | /* STD */ | 47 | /* STD */ |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | 49 | ||
50 | 50 | ||
51 | TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name ) | 51 | TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name ) |
52 | : QWidget ( parent, name ) | 52 | : QWidget ( parent, name ) |
53 | { | 53 | { |
54 | m_applets_changed = false; | 54 | m_applets_changed = false; |
55 | 55 | ||
56 | QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); | 56 | QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); |
57 | 57 | ||
58 | QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this ); | 58 | QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this ); |
59 | lay-> addWidget ( l ); | 59 | lay-> addWidget ( l ); |
60 | 60 | ||
61 | m_list = new QListView ( this ); | 61 | m_list = new QListView ( this ); |
62 | m_list-> addColumn ( "foobar" ); | 62 | m_list-> addColumn ( "foobar" ); |
63 | m_list-> header ( )-> hide ( ); | 63 | m_list-> header ( )-> hide ( ); |
64 | 64 | ||
65 | lay-> addWidget ( m_list ); | 65 | lay-> addWidget ( m_list ); |
66 | 66 | ||
67 | QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." )); | 67 | QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." )); |
68 | 68 | ||
69 | connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); | 69 | connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); |
70 | 70 | ||
71 | init ( ); | 71 | init ( ); |
72 | } | 72 | } |
73 | 73 | ||
74 | void TaskbarSettings::init ( ) | 74 | void TaskbarSettings::init ( ) |
75 | { | 75 | { |
76 | Config cfg ( "Taskbar" ); | 76 | Config cfg ( "Taskbar" ); |
77 | cfg. setGroup ( "Applets" ); | 77 | cfg. setGroup ( "Applets" ); |
78 | QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); | 78 | QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); |
79 | 79 | ||
80 | QString path = QPEApplication::qpeDir ( ) + "plugins/applets"; | 80 | QString path = QPEApplication::qpeDir ( ) + "plugins/applets"; |
81 | #ifdef Q_OS_MACX | 81 | #ifdef Q_OS_MACX |
82 | QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); | 82 | QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); |
83 | #else | 83 | #else |
84 | QStringList list = QDir ( path, "lib*.so" ). entryList ( ); | 84 | QStringList list = QDir ( path, "lib*.so" ). entryList ( ); |
85 | #endif /* Q_OS_MACX */ | 85 | #endif /* Q_OS_MACX */ |
86 | 86 | ||
87 | for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { | 87 | for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { |
88 | QString name; | 88 | QString name; |
89 | QPixmap icon; | 89 | QPixmap icon; |
90 | TaskbarNamedAppletInterface *iface = 0; | 90 | TaskbarNamedAppletInterface *iface = 0; |
91 | 91 | ||
92 | owarn << "Load applet: " << (*it) << "" << oendl; | 92 | owarn << "Load applet: " << (*it) << "" << oendl; |
93 | QLibrary *lib = new QLibrary ( path + "/" + *it ); | 93 | QLibrary *lib = new QLibrary ( path + "/" + *it ); |
94 | lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface ); | 94 | QRESULT retVal = QS_OK; |
95 | if ((retVal = lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**)(&iface) )) != QS_OK) | ||
96 | owarn << "<0>" << oendl; | ||
95 | owarn << "<1>" << oendl; | 97 | owarn << "<1>" << oendl; |
96 | if ( iface ) { | 98 | if ( iface ) { |
97 | owarn << "<2>" << oendl; | 99 | owarn << "<2>" << oendl; |
98 | QString lang = getenv( "LANG" ); | 100 | QString lang = getenv( "LANG" ); |
99 | QTranslator *trans = new QTranslator ( qApp ); | 101 | QTranslator *trans = new QTranslator ( qApp ); |
100 | QString type = (*it). left ((*it). find (".")); | 102 | QString type = (*it). left ((*it). find (".")); |
101 | QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm"; | 103 | QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm"; |
102 | if ( trans-> load ( tfn )) | 104 | if ( trans-> load ( tfn )) |
103 | qApp-> installTranslator ( trans ); | 105 | qApp-> installTranslator ( trans ); |
104 | else | 106 | else |
105 | delete trans; | 107 | delete trans; |
106 | name = iface-> name ( ); | 108 | name = iface-> name ( ); |
107 | icon = iface-> icon ( ); | 109 | icon = iface-> icon ( ); |
108 | iface-> release ( ); | 110 | iface-> release ( ); |
109 | } | 111 | } |
110 | owarn << "<3>" << oendl; | 112 | owarn << "<3>" << oendl; |
111 | if ( !iface ) { | 113 | if ( !iface ) { |
112 | owarn << "<4>" << oendl; | 114 | owarn << "<4>" << oendl; |
113 | lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**) &iface ); | 115 | if ((retVal = lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**)(&iface))) != QS_OK) |
116 | owarn << "<5>" << oendl; | ||
114 | 117 | ||
115 | if ( iface ) { | 118 | if ( iface ) { |
116 | owarn << "<5>" << oendl; | 119 | owarn << "<6>" << oendl; |
117 | name = (*it). mid ( 3 ); | 120 | name = (*it). mid ( 3 ); |
118 | owarn << "Found applet: " << name << "" << oendl; | 121 | owarn << "Found applet: " << name << "" << oendl; |
119 | #ifdef Q_OS_MACX | 122 | #ifdef Q_OS_MACX |
120 | int sep = name. find( ".dylib" ); | 123 | int sep = name. find( ".dylib" ); |
121 | #else | 124 | #else |
122 | int sep = name. find( ".so" ); | 125 | int sep = name. find( ".so" ); |
123 | #endif /* Q_OS_MACX */ | 126 | #endif /* Q_OS_MACX */ |
124 | if ( sep > 0 ) | 127 | if ( sep > 0 ) |
125 | name. truncate ( sep ); | 128 | name. truncate ( sep ); |
126 | sep = name. find ( "applet" ); | 129 | sep = name. find ( "applet" ); |
127 | if ( sep == (int) name.length ( ) - 6 ) | 130 | if ( sep == (int) name.length ( ) - 6 ) |
128 | name. truncate ( sep ); | 131 | name. truncate ( sep ); |
129 | name[0] = name[0]. upper ( ); | 132 | name[0] = name[0]. upper ( ); |
130 | iface-> release ( ); | 133 | iface-> release ( ); |
131 | } | 134 | } |
132 | } | 135 | } |
133 | owarn << "<6>" << oendl; | 136 | owarn << "<7>" << oendl; |
134 | 137 | ||
135 | if ( iface ) { | 138 | if ( iface ) { |
136 | owarn << "<7>" << oendl; | 139 | owarn << "<8>" << oendl; |
137 | QCheckListItem *item; | 140 | QCheckListItem *item; |
138 | item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); | 141 | item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); |
139 | if ( !icon. isNull ( )) | 142 | if ( !icon. isNull ( )) |
140 | item-> setPixmap ( 0, icon ); | 143 | item-> setPixmap ( 0, icon ); |
141 | item-> setOn ( exclude. find ( *it ) == exclude. end ( )); | 144 | item-> setOn ( exclude. find ( *it ) == exclude. end ( )); |
142 | m_applets [*it] = item; | 145 | m_applets [*it] = item; |
143 | } | 146 | } |
144 | lib-> unload ( ); | 147 | lib-> unload ( ); |
145 | delete lib; | 148 | delete lib; |
146 | } | 149 | } |
147 | } | 150 | } |
148 | 151 | ||
149 | void TaskbarSettings::appletChanged() | 152 | void TaskbarSettings::appletChanged() |
150 | { | 153 | { |
151 | m_applets_changed = true; | 154 | m_applets_changed = true; |
152 | } | 155 | } |
153 | 156 | ||
154 | void TaskbarSettings::accept ( ) | 157 | void TaskbarSettings::accept ( ) |
155 | { | 158 | { |
156 | Config cfg ( "Taskbar" ); | 159 | Config cfg ( "Taskbar" ); |
157 | cfg. setGroup ( "Applets" ); | 160 | cfg. setGroup ( "Applets" ); |
158 | 161 | ||
159 | if ( m_applets_changed ) { | 162 | if ( m_applets_changed ) { |
160 | QStringList exclude; | 163 | QStringList exclude; |
161 | QMap <QString, QCheckListItem *>::Iterator it; | 164 | QMap <QString, QCheckListItem *>::Iterator it; |
162 | for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { | 165 | for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { |
163 | if ( !(*it)-> isOn ( )) | 166 | if ( !(*it)-> isOn ( )) |
164 | exclude << it. key ( ); | 167 | exclude << it. key ( ); |
165 | } | 168 | } |
166 | cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); | 169 | cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); |
167 | } | 170 | } |
168 | cfg. writeEntry ( "SafeMode", false ); | 171 | cfg. writeEntry ( "SafeMode", false ); |
169 | cfg. write ( ); | 172 | cfg. write ( ); |
170 | 173 | ||
171 | if ( m_applets_changed ) { | 174 | if ( m_applets_changed ) { |
172 | QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" ); | 175 | QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" ); |
173 | m_applets_changed = false; | 176 | m_applets_changed = false; |
174 | } | 177 | } |
175 | } | 178 | } |
176 | 179 | ||
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp index 706ac6c..b7d59fc 100644 --- a/libopie2/opiecore/oglobal.cpp +++ b/libopie2/opiecore/oglobal.cpp | |||
@@ -1,422 +1,422 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> | 4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/oglobal.h> | 30 | #include <opie2/oglobal.h> |
31 | 31 | ||
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qdir.h> | 33 | #include <qdir.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/storage.h> | 36 | #include <qpe/storage.h> |
37 | 37 | ||
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <sys/types.h> | 39 | #include <sys/types.h> |
40 | 40 | ||
41 | using namespace Opie::Core; | 41 | using namespace Opie::Core; |
42 | 42 | ||
43 | static const char Base64EncMap[64] = | 43 | static const char Base64EncMap[64] = |
44 | { | 44 | { |
45 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | 45 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
46 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, | 46 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, |
47 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | 47 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
48 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, | 48 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, |
49 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, | 49 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, |
50 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, | 50 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, |
51 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, | 51 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, |
52 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F | 52 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F |
53 | }; | 53 | }; |
54 | 54 | ||
55 | static char Base64DecMap[128] = | 55 | static char Base64DecMap[128] = |
56 | { | 56 | { |
57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
62 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, | 62 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, |
63 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, | 63 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, |
64 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 64 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
65 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, | 65 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
66 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, | 66 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, |
67 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, | 67 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, |
68 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, | 68 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, |
69 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, | 69 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, |
70 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, | 70 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
71 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, | 71 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, |
72 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 | 72 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | OConfig* OGlobal::_config = 0; | 76 | OConfig* OGlobal::_config = 0; |
77 | OConfig* OGlobal::_qpe_config = 0; | 77 | OConfig* OGlobal::_qpe_config = 0; |
78 | 78 | ||
79 | void OGlobal::clean_up() | 79 | void OGlobal::clean_up() |
80 | { | 80 | { |
81 | qDebug( "Oglobal clean up" ); | 81 | qDebug( "Oglobal clean up" ); |
82 | delete OGlobal::_config; | 82 | delete OGlobal::_config; |
83 | delete OGlobal::_qpe_config; | 83 | delete OGlobal::_qpe_config; |
84 | OGlobal::_config = 0; | 84 | OGlobal::_config = 0; |
85 | OGlobal::_qpe_config = 0; | 85 | OGlobal::_qpe_config = 0; |
86 | } | 86 | } |
87 | 87 | ||
88 | OConfig* OGlobal::config() | 88 | OConfig* OGlobal::config() |
89 | { | 89 | { |
90 | if ( !OGlobal::_config ) | 90 | if ( !OGlobal::_config ) |
91 | { | 91 | { |
92 | // odebug classes are reading config, so can't use them here! | 92 | // odebug classes are reading config, so can't use them here! |
93 | qAddPostRoutine( OGlobal::clean_up ); | 93 | qAddPostRoutine( OGlobal::clean_up ); |
94 | qDebug( "OGlobal::creating global configuration instance." ); | 94 | qDebug( "OGlobal::creating global configuration instance." ); |
95 | OGlobal::_config = new OConfig( "global" ); | 95 | OGlobal::_config = new OConfig( "global" ); |
96 | } | 96 | } |
97 | return OGlobal::_config; | 97 | return OGlobal::_config; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | /** | 101 | /** |
102 | * Return the internal builtin Global::Command object | 102 | * Return the internal builtin Global::Command object |
103 | * | 103 | * |
104 | */ | 104 | */ |
105 | Global::Command* OGlobal::builtinCommands() { | 105 | Global::Command* OGlobal::builtinCommands() { |
106 | return builtin; | 106 | return builtin; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Return the internal builtin QGuardedPtr<QWidget> object | 111 | * Return the internal builtin QGuardedPtr<QWidget> object |
112 | */ | 112 | */ |
113 | QGuardedPtr<QWidget>* OGlobal::builtinRunning() { | 113 | QGuardedPtr<QWidget>* OGlobal::builtinRunning() { |
114 | return running; | 114 | return running; |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | /** | 118 | /** |
119 | * \brief generate a new UUID as QString | 119 | * \brief generate a new UUID as QString |
120 | * Return a new UUID as QString. UUID are global unique | 120 | * Return a new UUID as QString. UUID are global unique |
121 | * | 121 | * |
122 | * | 122 | * |
123 | * @return the UUID or QString::null | 123 | * @return the UUID or QString::null |
124 | */ | 124 | */ |
125 | QString OGlobal::generateUuid() { | 125 | QString OGlobal::generateUuid() { |
126 | QFile file( "/proc/sys/kernel/random/uuid" ); | 126 | QFile file( "/proc/sys/kernel/random/uuid" ); |
127 | if (!file.open(IO_ReadOnly ) ) | 127 | if (!file.open(IO_ReadOnly ) ) |
128 | return QString::null; | 128 | return QString::null; |
129 | 129 | ||
130 | QTextStream stream(&file); | 130 | QTextStream stream(&file); |
131 | 131 | ||
132 | return "{" + stream.read().stripWhiteSpace() + "}"; | 132 | return "{" + stream.read().stripWhiteSpace() + "}"; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | /** | 136 | /** |
137 | * \brief Encode a QByteArray in base64 | 137 | * \brief Encode a QByteArray in base64 |
138 | * | 138 | * |
139 | * An Implementation of the RF1521 base64 encoding. | 139 | * An Implementation of the RF1521 base64 encoding. |
140 | * | 140 | * |
141 | * The boolean argument determines if the encoded data is | 141 | * The boolean argument determines if the encoded data is |
142 | * going to be restricted to 76 characters or less per line | 142 | * going to be restricted to 76 characters or less per line |
143 | * as specified by RFC 2045. If @p insertLFs is true, then | 143 | * as specified by RFC 2045. If @p insertLFs is true, then |
144 | * there will be 76 characters or less per line. | 144 | * there will be 76 characters or less per line. |
145 | * | 145 | * |
146 | * If you use this to create a QCString remember that it is null terminated! | 146 | * If you use this to create a QCString remember that it is null terminated! |
147 | * \code | 147 | * \code |
148 | * QByteArray ar = OGlobal::encodeBase64(&array); | 148 | * QByteArray ar = OGlobal::encodeBase64(&array); |
149 | * QCString str(ar.data(),ar.size()+1); // the NUL at the end | 149 | * QCString str(ar.data(),ar.size()+1); // the NUL at the end |
150 | * | 150 | * |
151 | * \endcode | 151 | * \endcode |
152 | * | 152 | * |
153 | * @param in The QByteArray to encode | 153 | * @param in The QByteArray to encode |
154 | * @param insertLFs Limit number of characters per line | 154 | * @param insertLFs Limit number of characters per line |
155 | * @return The argument as base64 encoded or QByteArray() if in.isEmpty() | 155 | * @return The argument as base64 encoded or QByteArray() if in.isEmpty() |
156 | * @see QByteArray | 156 | * @see QByteArray |
157 | * @see QArray | 157 | * @see QArray |
158 | * @see QMemArray | 158 | * @see QMemArray |
159 | * @see QCString | 159 | * @see QCString |
160 | */ | 160 | */ |
161 | /* | 161 | /* |
162 | * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp | 162 | * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp |
163 | */ | 163 | */ |
164 | QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { | 164 | QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { |
165 | if ( in.isEmpty() ) | 165 | if ( in.isEmpty() ) |
166 | return QByteArray(); | 166 | return QByteArray(); |
167 | 167 | ||
168 | unsigned int sidx = 0; | 168 | unsigned int sidx = 0; |
169 | unsigned int didx = 0; | 169 | unsigned int didx = 0; |
170 | const char* data = in.data(); | 170 | const char* data = in.data(); |
171 | const unsigned int len = in.size(); | 171 | const unsigned int len = in.size(); |
172 | 172 | ||
173 | unsigned int out_len = ((len+2)/3)*4; | 173 | unsigned int out_len = ((len+2)/3)*4; |
174 | 174 | ||
175 | // Deal with the 76 characters or less per | 175 | // Deal with the 76 characters or less per |
176 | // line limit specified in RFC 2045 on a | 176 | // line limit specified in RFC 2045 on a |
177 | // pre request basis. | 177 | // pre request basis. |
178 | insertLFs = (insertLFs && out_len > 76); | 178 | insertLFs = (insertLFs && out_len > 76); |
179 | if ( insertLFs ) | 179 | if ( insertLFs ) |
180 | out_len += ((out_len-1)/76); | 180 | out_len += ((out_len-1)/76); |
181 | 181 | ||
182 | int count = 0; | 182 | int count = 0; |
183 | QByteArray out( out_len ); | 183 | QByteArray out( out_len ); |
184 | 184 | ||
185 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 185 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
186 | if ( len > 1 ) | 186 | if ( len > 1 ) |
187 | { | 187 | { |
188 | while (sidx < len-2) | 188 | while (sidx < len-2) |
189 | { | 189 | { |
190 | if ( insertLFs ) | 190 | if ( insertLFs ) |
191 | { | 191 | { |
192 | if ( count && (count%76) == 0 ) | 192 | if ( count && (count%76) == 0 ) |
193 | out[didx++] = '\n'; | 193 | out[didx++] = '\n'; |
194 | count += 4; | 194 | count += 4; |
195 | } | 195 | } |
196 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; | 196 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
197 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 197 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
198 | (data[sidx] << 4) & 077]; | 198 | (data[sidx] << 4) & 077]; |
199 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | | 199 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | |
200 | (data[sidx+1] << 2) & 077]; | 200 | (data[sidx+1] << 2) & 077]; |
201 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; | 201 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; |
202 | sidx += 3; | 202 | sidx += 3; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | if (sidx < len) | 206 | if (sidx < len) |
207 | { | 207 | { |
208 | if ( insertLFs && (count > 0) && (count%76) == 0 ) | 208 | if ( insertLFs && (count > 0) && (count%76) == 0 ) |
209 | out[didx++] = '\n'; | 209 | out[didx++] = '\n'; |
210 | 210 | ||
211 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; | 211 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
212 | if (sidx < len-1) | 212 | if (sidx < len-1) |
213 | { | 213 | { |
214 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 214 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
215 | (data[sidx] << 4) & 077]; | 215 | (data[sidx] << 4) & 077]; |
216 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; | 216 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; |
217 | } | 217 | } |
218 | else | 218 | else |
219 | { | 219 | { |
220 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; | 220 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; |
221 | } | 221 | } |
222 | } | 222 | } |
223 | 223 | ||
224 | // Add padding | 224 | // Add padding |
225 | while (didx < out.size()) | 225 | while (didx < out.size()) |
226 | { | 226 | { |
227 | out[didx] = '='; | 227 | out[didx] = '='; |
228 | didx++; | 228 | didx++; |
229 | } | 229 | } |
230 | 230 | ||
231 | return out; | 231 | return out; |
232 | } | 232 | } |
233 | 233 | ||
234 | /** | 234 | /** |
235 | * Decodes the given data that was encoded with the base64 | 235 | * Decodes the given data that was encoded with the base64 |
236 | * algorithm. | 236 | * algorithm. |
237 | * | 237 | * |
238 | * | 238 | * |
239 | * @param in the encoded data to be decoded. | 239 | * @param in the encoded data to be decoded. |
240 | * @return the decoded QByteArray or QByteArray() in case of failure | 240 | * @return the decoded QByteArray or QByteArray() in case of failure |
241 | * @see OGlobal::encodeBase64 | 241 | * @see OGlobal::encodeBase64 |
242 | */ | 242 | */ |
243 | QByteArray OGlobal::decodeBase64( const QByteArray& in) { | 243 | QByteArray OGlobal::decodeBase64( const QByteArray& in) { |
244 | if ( in.isEmpty() ) | 244 | if ( in.isEmpty() ) |
245 | return QByteArray(); | 245 | return QByteArray(); |
246 | 246 | ||
247 | QByteArray out; | 247 | QByteArray out; |
248 | unsigned int count = 0; | 248 | unsigned int count = 0; |
249 | unsigned int len = in.size(), tail = len; | 249 | unsigned int len = in.size(), tail = len; |
250 | const char* data = in.data(); | 250 | const char* data = in.data(); |
251 | 251 | ||
252 | // Deal with possible *nix "BEGIN" marker!! | 252 | // Deal with possible *nix "BEGIN" marker!! |
253 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || | 253 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || |
254 | data[count] == '\t' || data[count] == ' ') ) | 254 | data[count] == '\t' || data[count] == ' ') ) |
255 | count++; | 255 | count++; |
256 | 256 | ||
257 | if ( strncasecmp(data+count, "begin", 5) == 0 ) | 257 | if ( strncasecmp(data+count, "begin", 5) == 0 ) |
258 | { | 258 | { |
259 | count += 5; | 259 | count += 5; |
260 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) | 260 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) |
261 | count++; | 261 | count++; |
262 | 262 | ||
263 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) | 263 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) |
264 | count ++; | 264 | count ++; |
265 | 265 | ||
266 | data += count; | 266 | data += count; |
267 | tail = (len -= count); | 267 | tail = (len -= count); |
268 | } | 268 | } |
269 | 269 | ||
270 | // Find the tail end of the actual encoded data even if | 270 | // Find the tail end of the actual encoded data even if |
271 | // there is/are trailing CR and/or LF. | 271 | // there is/are trailing CR and/or LF. |
272 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || | 272 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || |
273 | data[tail-1] == '\r' ) | 273 | data[tail-1] == '\r' ) |
274 | if ( data[--tail] != '=' ) len = tail; | 274 | if ( data[--tail] != '=' ) len = tail; |
275 | 275 | ||
276 | unsigned int outIdx = 0; | 276 | unsigned int outIdx = 0; |
277 | out.resize( (count=len) ); | 277 | out.resize( (count=len) ); |
278 | for (unsigned int idx = 0; idx < count; idx++) | 278 | for (unsigned int idx = 0; idx < count; idx++) |
279 | { | 279 | { |
280 | // Adhere to RFC 2045 and ignore characters | 280 | // Adhere to RFC 2045 and ignore characters |
281 | // that are not part of the encoding table. | 281 | // that are not part of the encoding table. |
282 | unsigned char ch = data[idx]; | 282 | unsigned char ch = data[idx]; |
283 | if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || | 283 | if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || |
284 | (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') | 284 | (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') |
285 | { | 285 | { |
286 | out[outIdx++] = Base64DecMap[ch]; | 286 | out[outIdx++] = Base64DecMap[ch]; |
287 | } | 287 | } |
288 | else | 288 | else |
289 | { | 289 | { |
290 | len--; | 290 | len--; |
291 | tail--; | 291 | tail--; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; | 295 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; |
296 | 296 | ||
297 | // 4-byte to 3-byte conversion | 297 | // 4-byte to 3-byte conversion |
298 | len = (tail>(len/4)) ? tail-(len/4) : 0; | 298 | len = (tail>(len/4)) ? tail-(len/4) : 0; |
299 | unsigned int sidx = 0, didx = 0; | 299 | unsigned int sidx = 0, didx = 0; |
300 | if ( len > 1 ) | 300 | if ( len > 1 ) |
301 | { | 301 | { |
302 | while (didx < len-2) | 302 | while (didx < len-2) |
303 | { | 303 | { |
304 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); | 304 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
305 | out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); | 305 | out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
306 | out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); | 306 | out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); |
307 | sidx += 4; | 307 | sidx += 4; |
308 | didx += 3; | 308 | didx += 3; |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | if (didx < len) | 312 | if (didx < len) |
313 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); | 313 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
314 | 314 | ||
315 | if (++didx < len ) | 315 | if (++didx < len ) |
316 | out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); | 316 | out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
317 | 317 | ||
318 | // Resize the output buffer | 318 | // Resize the output buffer |
319 | if ( len == 0 || len < out.size() ) | 319 | if ( len == 0 || len < out.size() ) |
320 | out.resize(len); | 320 | out.resize(len); |
321 | 321 | ||
322 | return out; | 322 | return out; |
323 | } | 323 | } |
324 | 324 | ||
325 | bool OGlobal::isAppLnkFileName( const QString& str ) | 325 | bool OGlobal::isAppLnkFileName( const QString& str ) |
326 | { | 326 | { |
327 | if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false; | 327 | if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false; |
328 | return str.startsWith(MimeType::appsFolderName()+QDir::separator()); | 328 | return str.startsWith(MimeType::appsFolderName()+QDir::separator()); |
329 | } | 329 | } |
330 | 330 | ||
331 | /* ToDo: | 331 | /* ToDo: |
332 | * This fun should check the document-path value for the mounted media | 332 | * This fun should check the document-path value for the mounted media |
333 | * which has to be implemented later. this moment we just check for a | 333 | * which has to be implemented later. this moment we just check for a |
334 | * mounted media name. | 334 | * mounted media name. |
335 | */ | 335 | */ |
336 | bool OGlobal::isDocumentFileName( const QString& file ) | 336 | bool OGlobal::isDocumentFileName( const QString& file ) |
337 | { | 337 | { |
338 | if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false; | 338 | if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false; |
339 | if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; | 339 | if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; |
340 | StorageInfo si; | 340 | StorageInfo si; |
341 | QList< FileSystem > fl = si.fileSystems(); | 341 | QList< FileSystem > fl = si.fileSystems(); |
342 | FileSystem*fs; | 342 | FileSystem*fs; |
343 | for (fs = fl.first();fs!=0;fs=fl.next()) { | 343 | for (fs = fl.first();fs!=0;fs=fl.next()) { |
344 | if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) | 344 | if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) |
345 | return true; | 345 | return true; |
346 | } | 346 | } |
347 | if (file.startsWith(homeDirPath())+"/Documents/") return true; | 347 | if (file.startsWith(homeDirPath()+"/Documents/")) return true; |
348 | return false; | 348 | return false; |
349 | } | 349 | } |
350 | 350 | ||
351 | QString OGlobal::tempDirPath() | 351 | QString OGlobal::tempDirPath() |
352 | { | 352 | { |
353 | static QString defstring="/tmp"; | 353 | static QString defstring="/tmp"; |
354 | char * tmpp = 0; | 354 | char * tmpp = 0; |
355 | if ( (tmpp=getenv("TEMP"))) { | 355 | if ( (tmpp=getenv("TEMP"))) { |
356 | return tmpp; | 356 | return tmpp; |
357 | } | 357 | } |
358 | return defstring; | 358 | return defstring; |
359 | } | 359 | } |
360 | 360 | ||
361 | QString OGlobal::homeDirPath() | 361 | QString OGlobal::homeDirPath() |
362 | { | 362 | { |
363 | char * tmpp = getenv("HOME"); | 363 | char * tmpp = getenv("HOME"); |
364 | return (tmpp?tmpp:"/"); | 364 | return (tmpp?tmpp:"/"); |
365 | } | 365 | } |
366 | 366 | ||
367 | bool OGlobal::weekStartsOnMonday() | 367 | bool OGlobal::weekStartsOnMonday() |
368 | { | 368 | { |
369 | OConfig*conf=OGlobal::qpe_config(); | 369 | OConfig*conf=OGlobal::qpe_config(); |
370 | if (!conf)return false; | 370 | if (!conf)return false; |
371 | conf->setGroup("Time"); | 371 | conf->setGroup("Time"); |
372 | return conf->readBoolEntry("MONDAY",true); | 372 | return conf->readBoolEntry("MONDAY",true); |
373 | } | 373 | } |
374 | 374 | ||
375 | void OGlobal::setWeekStartsOnMonday( bool what) | 375 | void OGlobal::setWeekStartsOnMonday( bool what) |
376 | { | 376 | { |
377 | OConfig*conf=OGlobal::qpe_config(); | 377 | OConfig*conf=OGlobal::qpe_config(); |
378 | if (!conf)return; | 378 | if (!conf)return; |
379 | conf->setGroup("Time"); | 379 | conf->setGroup("Time"); |
380 | return conf->writeEntry("MONDAY",what); | 380 | return conf->writeEntry("MONDAY",what); |
381 | } | 381 | } |
382 | 382 | ||
383 | bool OGlobal::useAMPM() | 383 | bool OGlobal::useAMPM() |
384 | { | 384 | { |
385 | OConfig*conf=OGlobal::qpe_config(); | 385 | OConfig*conf=OGlobal::qpe_config(); |
386 | if (!conf)return false; | 386 | if (!conf)return false; |
387 | conf->setGroup("Time"); | 387 | conf->setGroup("Time"); |
388 | return conf->readBoolEntry("AMPM",false); | 388 | return conf->readBoolEntry("AMPM",false); |
389 | } | 389 | } |
390 | 390 | ||
391 | void OGlobal::setUseAMPM( bool what) | 391 | void OGlobal::setUseAMPM( bool what) |
392 | { | 392 | { |
393 | OConfig*conf=OGlobal::qpe_config(); | 393 | OConfig*conf=OGlobal::qpe_config(); |
394 | if (!conf)return; | 394 | if (!conf)return; |
395 | conf->setGroup("Time"); | 395 | conf->setGroup("Time"); |
396 | return conf->writeEntry("AMPM",what); | 396 | return conf->writeEntry("AMPM",what); |
397 | } | 397 | } |
398 | 398 | ||
399 | OConfig* OGlobal::qpe_config() | 399 | OConfig* OGlobal::qpe_config() |
400 | { | 400 | { |
401 | if ( !OGlobal::_qpe_config ) { | 401 | if ( !OGlobal::_qpe_config ) { |
402 | OGlobal::_qpe_config = new OConfig( "qpe" ); | 402 | OGlobal::_qpe_config = new OConfig( "qpe" ); |
403 | } | 403 | } |
404 | return OGlobal::_qpe_config; | 404 | return OGlobal::_qpe_config; |
405 | } | 405 | } |
406 | 406 | ||
407 | bool OGlobal::truncateFile( QFile &f, off_t size ) | 407 | bool OGlobal::truncateFile( QFile &f, off_t size ) |
408 | { | 408 | { |
409 | /* or should we let enlarge Files? then remove this | 409 | /* or should we let enlarge Files? then remove this |
410 | f.size()< part! - Alwin | 410 | f.size()< part! - Alwin |
411 | */ | 411 | */ |
412 | if (!f.exists()||f.size()<(unsigned)size) return false; | 412 | if (!f.exists()||f.size()<(unsigned)size) return false; |
413 | bool closeit=false; | 413 | bool closeit=false; |
414 | if (!f.isOpen()) { | 414 | if (!f.isOpen()) { |
415 | closeit=true; | 415 | closeit=true; |
416 | f.open(IO_Raw | IO_ReadWrite | IO_Append); | 416 | f.open(IO_Raw | IO_ReadWrite | IO_Append); |
417 | } | 417 | } |
418 | if (!f.isOpen()) { return false; } | 418 | if (!f.isOpen()) { return false; } |
419 | int r = ftruncate(f.handle(),size); | 419 | int r = ftruncate(f.handle(),size); |
420 | if (closeit) f.close(); | 420 | if (closeit) f.close(); |
421 | return r==0; | 421 | return r==0; |
422 | } | 422 | } |
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp index b3f9724..56f9883 100644 --- a/libopie2/opiecore/oprocess.cpp +++ b/libopie2/opiecore/oprocess.cpp | |||
@@ -547,405 +547,405 @@ bool OProcess::closeStderr() | |||
547 | if ( communication & Stderr ) | 547 | if ( communication & Stderr ) |
548 | { | 548 | { |
549 | communication = static_cast<Communication>( communication & ~Stderr ); | 549 | communication = static_cast<Communication>( communication & ~Stderr ); |
550 | delete errnot; | 550 | delete errnot; |
551 | errnot = 0; | 551 | errnot = 0; |
552 | close( err[ 0 ] ); | 552 | close( err[ 0 ] ); |
553 | rv = true; | 553 | rv = true; |
554 | } | 554 | } |
555 | else | 555 | else |
556 | rv = false; | 556 | rv = false; |
557 | return rv; | 557 | return rv; |
558 | } | 558 | } |
559 | 559 | ||
560 | void OProcess::slotChildOutput( int fdno ) | 560 | void OProcess::slotChildOutput( int fdno ) |
561 | { | 561 | { |
562 | if ( !childOutput( fdno ) ) | 562 | if ( !childOutput( fdno ) ) |
563 | closeStdout(); | 563 | closeStdout(); |
564 | } | 564 | } |
565 | 565 | ||
566 | void OProcess::slotChildError( int fdno ) | 566 | void OProcess::slotChildError( int fdno ) |
567 | { | 567 | { |
568 | if ( !childError( fdno ) ) | 568 | if ( !childError( fdno ) ) |
569 | closeStderr(); | 569 | closeStderr(); |
570 | } | 570 | } |
571 | 571 | ||
572 | void OProcess::slotSendData( int ) | 572 | void OProcess::slotSendData( int ) |
573 | { | 573 | { |
574 | if ( input_sent == input_total ) | 574 | if ( input_sent == input_total ) |
575 | { | 575 | { |
576 | innot->setEnabled( false ); | 576 | innot->setEnabled( false ); |
577 | input_data = 0; | 577 | input_data = 0; |
578 | emit wroteStdin( this ); | 578 | emit wroteStdin( this ); |
579 | } | 579 | } |
580 | else | 580 | else |
581 | input_sent += ::write( in[ 1 ], input_data + input_sent, input_total - input_sent ); | 581 | input_sent += ::write( in[ 1 ], input_data + input_sent, input_total - input_sent ); |
582 | } | 582 | } |
583 | 583 | ||
584 | void OProcess::processHasExited( int state ) | 584 | void OProcess::processHasExited( int state ) |
585 | { | 585 | { |
586 | if ( runs ) | 586 | if ( runs ) |
587 | { | 587 | { |
588 | runs = false; | 588 | runs = false; |
589 | status = state; | 589 | status = state; |
590 | 590 | ||
591 | commClose(); // cleanup communication sockets | 591 | commClose(); // cleanup communication sockets |
592 | 592 | ||
593 | // also emit a signal if the process was run Blocking | 593 | // also emit a signal if the process was run Blocking |
594 | if ( DontCare != run_mode ) | 594 | if ( DontCare != run_mode ) |
595 | { | 595 | { |
596 | emit processExited( this ); | 596 | emit processExited( this ); |
597 | } | 597 | } |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | int OProcess::childOutput( int fdno ) | 601 | int OProcess::childOutput( int fdno ) |
602 | { | 602 | { |
603 | if ( communication & NoRead ) | 603 | if ( communication & NoRead ) |
604 | { | 604 | { |
605 | int len = -1; | 605 | int len = -1; |
606 | emit receivedStdout( fdno, len ); | 606 | emit receivedStdout( fdno, len ); |
607 | errno = 0; // Make sure errno doesn't read "EAGAIN" | 607 | errno = 0; // Make sure errno doesn't read "EAGAIN" |
608 | return len; | 608 | return len; |
609 | } | 609 | } |
610 | else | 610 | else |
611 | { | 611 | { |
612 | char buffer[ 1024 ]; | 612 | char buffer[ 1024 ]; |
613 | int len; | 613 | int len; |
614 | 614 | ||
615 | len = ::read( fdno, buffer, 1024 ); | 615 | len = ::read( fdno, buffer, 1024 ); |
616 | 616 | ||
617 | if ( 0 < len ) | 617 | if ( 0 < len ) |
618 | { | 618 | { |
619 | emit receivedStdout( this, buffer, len ); | 619 | emit receivedStdout( this, buffer, len ); |
620 | } | 620 | } |
621 | return len; | 621 | return len; |
622 | } | 622 | } |
623 | } | 623 | } |
624 | 624 | ||
625 | int OProcess::childError( int fdno ) | 625 | int OProcess::childError( int fdno ) |
626 | { | 626 | { |
627 | char buffer[ 1024 ]; | 627 | char buffer[ 1024 ]; |
628 | int len; | 628 | int len; |
629 | 629 | ||
630 | len = ::read( fdno, buffer, 1024 ); | 630 | len = ::read( fdno, buffer, 1024 ); |
631 | 631 | ||
632 | if ( 0 < len ) | 632 | if ( 0 < len ) |
633 | emit receivedStderr( this, buffer, len ); | 633 | emit receivedStderr( this, buffer, len ); |
634 | return len; | 634 | return len; |
635 | } | 635 | } |
636 | 636 | ||
637 | int OProcess::setupCommunication( Communication comm ) | 637 | int OProcess::setupCommunication( Communication comm ) |
638 | { | 638 | { |
639 | int ok; | 639 | int ok; |
640 | 640 | ||
641 | communication = comm; | 641 | communication = comm; |
642 | 642 | ||
643 | ok = 1; | 643 | ok = 1; |
644 | if ( comm & Stdin ) | 644 | if ( comm & Stdin ) |
645 | ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, in ) >= 0; | 645 | ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, in ) >= 0; |
646 | 646 | ||
647 | if ( comm & Stdout ) | 647 | if ( comm & Stdout ) |
648 | ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, out ) >= 0; | 648 | ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, out ) >= 0; |
649 | 649 | ||
650 | if ( comm & Stderr ) | 650 | if ( comm & Stderr ) |
651 | ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, err ) >= 0; | 651 | ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, err ) >= 0; |
652 | 652 | ||
653 | return ok; | 653 | return ok; |
654 | } | 654 | } |
655 | 655 | ||
656 | int OProcess::commSetupDoneP() | 656 | int OProcess::commSetupDoneP() |
657 | { | 657 | { |
658 | int ok = 1; | 658 | int ok = 1; |
659 | 659 | ||
660 | if ( communication != NoCommunication ) | 660 | if ( communication != NoCommunication ) |
661 | { | 661 | { |
662 | if ( communication & Stdin ) | 662 | if ( communication & Stdin ) |
663 | close( in[ 0 ] ); | 663 | close( in[ 0 ] ); |
664 | if ( communication & Stdout ) | 664 | if ( communication & Stdout ) |
665 | close( out[ 1 ] ); | 665 | close( out[ 1 ] ); |
666 | if ( communication & Stderr ) | 666 | if ( communication & Stderr ) |
667 | close( err[ 1 ] ); | 667 | close( err[ 1 ] ); |
668 | 668 | ||
669 | // Don't create socket notifiers and set the sockets non-blocking if | 669 | // Don't create socket notifiers and set the sockets non-blocking if |
670 | // blocking is requested. | 670 | // blocking is requested. |
671 | if ( run_mode == Block ) | 671 | if ( run_mode == Block ) |
672 | return ok; | 672 | return ok; |
673 | 673 | ||
674 | if ( communication & Stdin ) | 674 | if ( communication & Stdin ) |
675 | { | 675 | { |
676 | // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); | 676 | // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); |
677 | innot = new QSocketNotifier( in[ 1 ], QSocketNotifier::Write, this ); | 677 | innot = new QSocketNotifier( in[ 1 ], QSocketNotifier::Write, this ); |
678 | CHECK_PTR( innot ); | 678 | CHECK_PTR( innot ); |
679 | innot->setEnabled( false ); // will be enabled when data has to be sent | 679 | innot->setEnabled( false ); // will be enabled when data has to be sent |
680 | QObject::connect( innot, SIGNAL( activated(int) ), | 680 | QObject::connect( innot, SIGNAL( activated(int) ), |
681 | this, SLOT( slotSendData(int) ) ); | 681 | this, SLOT( slotSendData(int) ) ); |
682 | } | 682 | } |
683 | 683 | ||
684 | if ( communication & Stdout ) | 684 | if ( communication & Stdout ) |
685 | { | 685 | { |
686 | // ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK)); | 686 | // ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK)); |
687 | outnot = new QSocketNotifier( out[ 0 ], QSocketNotifier::Read, this ); | 687 | outnot = new QSocketNotifier( out[ 0 ], QSocketNotifier::Read, this ); |
688 | CHECK_PTR( outnot ); | 688 | CHECK_PTR( outnot ); |
689 | QObject::connect( outnot, SIGNAL( activated(int) ), | 689 | QObject::connect( outnot, SIGNAL( activated(int) ), |
690 | this, SLOT( slotChildOutput(int) ) ); | 690 | this, SLOT( slotChildOutput(int) ) ); |
691 | if ( communication & NoRead ) | 691 | if ( communication & NoRead ) |
692 | suspend(); | 692 | suspend(); |
693 | } | 693 | } |
694 | 694 | ||
695 | if ( communication & Stderr ) | 695 | if ( communication & Stderr ) |
696 | { | 696 | { |
697 | // ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK)); | 697 | // ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK)); |
698 | errnot = new QSocketNotifier( err[ 0 ], QSocketNotifier::Read, this ); | 698 | errnot = new QSocketNotifier( err[ 0 ], QSocketNotifier::Read, this ); |
699 | CHECK_PTR( errnot ); | 699 | CHECK_PTR( errnot ); |
700 | QObject::connect( errnot, SIGNAL( activated(int) ), | 700 | QObject::connect( errnot, SIGNAL( activated(int) ), |
701 | this, SLOT( slotChildError(int) ) ); | 701 | this, SLOT( slotChildError(int) ) ); |
702 | } | 702 | } |
703 | } | 703 | } |
704 | return ok; | 704 | return ok; |
705 | } | 705 | } |
706 | 706 | ||
707 | int OProcess::commSetupDoneC() | 707 | int OProcess::commSetupDoneC() |
708 | { | 708 | { |
709 | int ok = 1; | 709 | int ok = 1; |
710 | struct linger so; | 710 | struct linger so; |
711 | memset( &so, 0, sizeof( so ) ); | 711 | memset( &so, 0, sizeof( so ) ); |
712 | 712 | ||
713 | if ( communication & Stdin ) | 713 | if ( communication & Stdin ) |
714 | close( in[ 1 ] ); | 714 | close( in[ 1 ] ); |
715 | if ( communication & Stdout ) | 715 | if ( communication & Stdout ) |
716 | close( out[ 0 ] ); | 716 | close( out[ 0 ] ); |
717 | if ( communication & Stderr ) | 717 | if ( communication & Stderr ) |
718 | close( err[ 0 ] ); | 718 | close( err[ 0 ] ); |
719 | 719 | ||
720 | if ( communication & Stdin ) | 720 | if ( communication & Stdin ) |
721 | ok &= dup2( in[ 0 ], STDIN_FILENO ) != -1; | 721 | ok &= dup2( in[ 0 ], STDIN_FILENO ) != -1; |
722 | else | 722 | else |
723 | { | 723 | { |
724 | int null_fd = open( "/dev/null", O_RDONLY ); | 724 | int null_fd = open( "/dev/null", O_RDONLY ); |
725 | ok &= dup2( null_fd, STDIN_FILENO ) != -1; | 725 | ok &= dup2( null_fd, STDIN_FILENO ) != -1; |
726 | close( null_fd ); | 726 | close( null_fd ); |
727 | } | 727 | } |
728 | if ( communication & Stdout ) | 728 | if ( communication & Stdout ) |
729 | { | 729 | { |
730 | ok &= dup2( out[ 1 ], STDOUT_FILENO ) != -1; | 730 | ok &= dup2( out[ 1 ], STDOUT_FILENO ) != -1; |
731 | ok &= !setsockopt( out[ 1 ], SOL_SOCKET, SO_LINGER, ( char* ) & so, sizeof( so ) ); | 731 | ok &= !setsockopt( out[ 1 ], SOL_SOCKET, SO_LINGER, ( char* ) & so, sizeof( so ) ); |
732 | } | 732 | } |
733 | else | 733 | else |
734 | { | 734 | { |
735 | int null_fd = open( "/dev/null", O_WRONLY ); | 735 | int null_fd = open( "/dev/null", O_WRONLY ); |
736 | ok &= dup2( null_fd, STDOUT_FILENO ) != -1; | 736 | ok &= dup2( null_fd, STDOUT_FILENO ) != -1; |
737 | close( null_fd ); | 737 | close( null_fd ); |
738 | } | 738 | } |
739 | if ( communication & Stderr ) | 739 | if ( communication & Stderr ) |
740 | { | 740 | { |
741 | ok &= dup2( err[ 1 ], STDERR_FILENO ) != -1; | 741 | ok &= dup2( err[ 1 ], STDERR_FILENO ) != -1; |
742 | ok &= !setsockopt( err[ 1 ], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>( &so ), sizeof( so ) ); | 742 | ok &= !setsockopt( err[ 1 ], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>( &so ), sizeof( so ) ); |
743 | } | 743 | } |
744 | else | 744 | else |
745 | { | 745 | { |
746 | int null_fd = open( "/dev/null", O_WRONLY ); | 746 | int null_fd = open( "/dev/null", O_WRONLY ); |
747 | ok &= dup2( null_fd, STDERR_FILENO ) != -1; | 747 | ok &= dup2( null_fd, STDERR_FILENO ) != -1; |
748 | close( null_fd ); | 748 | close( null_fd ); |
749 | } | 749 | } |
750 | return ok; | 750 | return ok; |
751 | } | 751 | } |
752 | 752 | ||
753 | void OProcess::commClose() | 753 | void OProcess::commClose() |
754 | { | 754 | { |
755 | if ( NoCommunication != communication ) | 755 | if ( NoCommunication != communication ) |
756 | { | 756 | { |
757 | bool b_in = ( communication & Stdin ); | 757 | bool b_in = ( communication & Stdin ); |
758 | bool b_out = ( communication & Stdout ); | 758 | bool b_out = ( communication & Stdout ); |
759 | bool b_err = ( communication & Stderr ); | 759 | bool b_err = ( communication & Stderr ); |
760 | if ( b_in ) | 760 | if ( b_in ) |
761 | delete innot; | 761 | delete innot; |
762 | 762 | ||
763 | if ( b_out || b_err ) | 763 | if ( b_out || b_err ) |
764 | { | 764 | { |
765 | // If both channels are being read we need to make sure that one socket buffer | 765 | // If both channels are being read we need to make sure that one socket buffer |
766 | // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). | 766 | // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). |
767 | // Hence we need to use select. | 767 | // Hence we need to use select. |
768 | 768 | ||
769 | // Once one or other of the channels has reached EOF (or given an error) go back | 769 | // Once one or other of the channels has reached EOF (or given an error) go back |
770 | // to the usual mechanism. | 770 | // to the usual mechanism. |
771 | 771 | ||
772 | int fds_ready = 1; | 772 | int fds_ready = 1; |
773 | fd_set rfds; | 773 | fd_set rfds; |
774 | 774 | ||
775 | int max_fd = 0; | 775 | int max_fd = 0; |
776 | if ( b_out ) | 776 | if ( b_out ) |
777 | { | 777 | { |
778 | fcntl( out[ 0 ], F_SETFL, O_NONBLOCK ); | 778 | fcntl( out[ 0 ], F_SETFL, O_NONBLOCK ); |
779 | if ( out[ 0 ] > max_fd ) | 779 | if ( out[ 0 ] > max_fd ) |
780 | max_fd = out[ 0 ]; | 780 | max_fd = out[ 0 ]; |
781 | delete outnot; | 781 | delete outnot; |
782 | outnot = 0; | 782 | outnot = 0; |
783 | } | 783 | } |
784 | if ( b_err ) | 784 | if ( b_err ) |
785 | { | 785 | { |
786 | fcntl( err[ 0 ], F_SETFL, O_NONBLOCK ); | 786 | fcntl( err[ 0 ], F_SETFL, O_NONBLOCK ); |
787 | if ( err[ 0 ] > max_fd ) | 787 | if ( err[ 0 ] > max_fd ) |
788 | max_fd = err[ 0 ]; | 788 | max_fd = err[ 0 ]; |
789 | delete errnot; | 789 | delete errnot; |
790 | errnot = 0; | 790 | errnot = 0; |
791 | } | 791 | } |
792 | 792 | ||
793 | 793 | ||
794 | while ( b_out || b_err ) | 794 | while ( b_out || b_err ) |
795 | { | 795 | { |
796 | // * If the process is still running we block until we | 796 | // * If the process is still running we block until we |
797 | // receive data. (p_timeout = 0, no timeout) | 797 | // receive data. (p_timeout = 0, no timeout) |
798 | // * If the process has already exited, we only check | 798 | // * If the process has already exited, we only check |
799 | // the available data, we don't wait for more. | 799 | // the available data, we don't wait for more. |
800 | // (p_timeout = &timeout, timeout immediately) | 800 | // (p_timeout = &timeout, timeout immediately) |
801 | struct timeval timeout; | 801 | struct timeval timeout; |
802 | timeout.tv_sec = 0; | 802 | timeout.tv_sec = 0; |
803 | timeout.tv_usec = 0; | 803 | timeout.tv_usec = 0; |
804 | struct timeval *p_timeout = runs ? 0 : &timeout; | 804 | struct timeval *p_timeout = runs ? 0 : &timeout; |
805 | 805 | ||
806 | FD_ZERO( &rfds ); | 806 | FD_ZERO( &rfds ); |
807 | if ( b_out ) | 807 | if ( b_out ) |
808 | FD_SET( out[ 0 ], &rfds ); | 808 | FD_SET( out[ 0 ], &rfds ); |
809 | 809 | ||
810 | if ( b_err ) | 810 | if ( b_err ) |
811 | FD_SET( err[ 0 ], &rfds ); | 811 | FD_SET( err[ 0 ], &rfds ); |
812 | 812 | ||
813 | fds_ready = select( max_fd + 1, &rfds, 0, 0, p_timeout ); | 813 | fds_ready = select( max_fd + 1, &rfds, 0, 0, p_timeout ); |
814 | if ( fds_ready <= 0 ) | 814 | if ( fds_ready <= 0 ) |
815 | break; | 815 | break; |
816 | 816 | ||
817 | if ( b_out && FD_ISSET( out[ 0 ], &rfds ) ) | 817 | if ( b_out && FD_ISSET( out[ 0 ], &rfds ) ) |
818 | { | 818 | { |
819 | int ret = 1; | 819 | int ret = 1; |
820 | while ( ret > 0 ) | 820 | while ( ret > 0 ) |
821 | ret = childOutput( out[ 0 ] ); | 821 | ret = childOutput( out[ 0 ] ); |
822 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) | 822 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) |
823 | b_out = false; | 823 | b_out = false; |
824 | } | 824 | } |
825 | 825 | ||
826 | if ( b_err && FD_ISSET( err[ 0 ], &rfds ) ) | 826 | if ( b_err && FD_ISSET( err[ 0 ], &rfds ) ) |
827 | { | 827 | { |
828 | int ret = 1; | 828 | int ret = 1; |
829 | while ( ret > 0 ) | 829 | while ( ret > 0 ) |
830 | ret = childError( err[ 0 ] ); | 830 | ret = childError( err[ 0 ] ); |
831 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) | 831 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) |
832 | b_err = false; | 832 | b_err = false; |
833 | } | 833 | } |
834 | } | 834 | } |
835 | } | 835 | } |
836 | 836 | ||
837 | if ( b_in ) | 837 | if ( b_in ) |
838 | { | 838 | { |
839 | communication = ( Communication ) ( communication & ~Stdin ); | 839 | communication = ( Communication ) ( communication & ~Stdin ); |
840 | close( in[ 1 ] ); | 840 | close( in[ 1 ] ); |
841 | } | 841 | } |
842 | if ( b_out ) | 842 | if ( b_out ) |
843 | { | 843 | { |
844 | communication = ( Communication ) ( communication & ~Stdout ); | 844 | communication = ( Communication ) ( communication & ~Stdout ); |
845 | close( out[ 0 ] ); | 845 | close( out[ 0 ] ); |
846 | } | 846 | } |
847 | if ( b_err ) | 847 | if ( b_err ) |
848 | { | 848 | { |
849 | communication = ( Communication ) ( communication & ~Stderr ); | 849 | communication = ( Communication ) ( communication & ~Stderr ); |
850 | close( err[ 0 ] ); | 850 | close( err[ 0 ] ); |
851 | } | 851 | } |
852 | } | 852 | } |
853 | } | 853 | } |
854 | 854 | ||
855 | void OProcess::setUseShell( bool useShell, const char *shell ) | 855 | void OProcess::setUseShell( bool useShell, const char *shell ) |
856 | { | 856 | { |
857 | if ( !d ) | 857 | if ( !d ) |
858 | d = new OProcessPrivate; | 858 | d = new OProcessPrivate; |
859 | d->useShell = useShell; | 859 | d->useShell = useShell; |
860 | d->shell = shell; | 860 | d->shell = shell; |
861 | if ( d->shell.isEmpty() ) | 861 | if ( d->shell.isEmpty() ) |
862 | d->shell = searchShell(); | 862 | d->shell = searchShell(); |
863 | } | 863 | } |
864 | 864 | ||
865 | QString OProcess::quote( const QString &arg ) | 865 | QString OProcess::quote( const QString &arg ) |
866 | { | 866 | { |
867 | QString res = arg; | 867 | QString res = arg; |
868 | res.replace( QRegExp( QString::fromLatin1( "\'" ) ), | 868 | res.replace( QRegExp( QString::fromLatin1( "\'" ) ), |
869 | QString::fromLatin1( "'\"'\"'" ) ); | 869 | QString::fromLatin1( "'\"'\"'" ) ); |
870 | res.prepend( '\'' ); | 870 | res.prepend( '\'' ); |
871 | res.append( '\'' ); | 871 | res.append( '\'' ); |
872 | return res; | 872 | return res; |
873 | } | 873 | } |
874 | 874 | ||
875 | QCString OProcess::searchShell() | 875 | QCString OProcess::searchShell() |
876 | { | 876 | { |
877 | QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace(); | 877 | QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace(); |
878 | if ( !isExecutable( tmpShell ) ) | 878 | if ( !isExecutable( tmpShell ) ) |
879 | { | 879 | { |
880 | tmpShell = "/bin/sh"; | 880 | tmpShell = "/bin/sh"; |
881 | } | 881 | } |
882 | 882 | ||
883 | return tmpShell; | 883 | return tmpShell; |
884 | } | 884 | } |
885 | 885 | ||
886 | bool OProcess::isExecutable( const QCString &filename ) | 886 | bool OProcess::isExecutable( const QCString &filename ) |
887 | { | 887 | { |
888 | struct stat fileinfo; | 888 | struct stat fileinfo; |
889 | 889 | ||
890 | if ( filename.isEmpty() ) | 890 | if ( filename.isEmpty() ) |
891 | return false; | 891 | return false; |
892 | 892 | ||
893 | // CC: we've got a valid filename, now let's see whether we can execute that file | 893 | // CC: we've got a valid filename, now let's see whether we can execute that file |
894 | 894 | ||
895 | if ( -1 == stat( filename.data(), &fileinfo ) ) | 895 | if ( -1 == stat( filename.data(), &fileinfo ) ) |
896 | return false; | 896 | return false; |
897 | // CC: return false if the file does not exist | 897 | // CC: return false if the file does not exist |
898 | 898 | ||
899 | // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets | 899 | // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets |
900 | if ( ( S_ISDIR( fileinfo.st_mode ) ) || | 900 | if ( ( S_ISDIR( fileinfo.st_mode ) ) || |
901 | ( S_ISCHR( fileinfo.st_mode ) ) || | 901 | ( S_ISCHR( fileinfo.st_mode ) ) || |
902 | ( S_ISBLK( fileinfo.st_mode ) ) || | 902 | ( S_ISBLK( fileinfo.st_mode ) ) || |
903 | #ifdef S_ISSOCK | 903 | #ifdef S_ISSOCK |
904 | // CC: SYSVR4 systems don't have that macro | 904 | // CC: SYSVR4 systems don't have that macro |
905 | ( S_ISSOCK( fileinfo.st_mode ) ) || | 905 | ( S_ISSOCK( fileinfo.st_mode ) ) || |
906 | #endif | 906 | #endif |
907 | ( S_ISFIFO( fileinfo.st_mode ) ) || | 907 | ( S_ISFIFO( fileinfo.st_mode ) ) || |
908 | ( S_ISDIR( fileinfo.st_mode ) ) ) | 908 | ( S_ISDIR( fileinfo.st_mode ) ) ) |
909 | { | 909 | { |
910 | return false; | 910 | return false; |
911 | } | 911 | } |
912 | 912 | ||
913 | // CC: now check for permission to execute the file | 913 | // CC: now check for permission to execute the file |
914 | if ( access( filename.data(), X_OK ) != 0 ) | 914 | if ( access( filename.data(), X_OK ) != 0 ) |
915 | return false; | 915 | return false; |
916 | 916 | ||
917 | // CC: we've passed all the tests... | 917 | // CC: we've passed all the tests... |
918 | return true; | 918 | return true; |
919 | } | 919 | } |
920 | 920 | ||
921 | int OProcess::processPID( const QString& process ) | 921 | int OProcess::processPID( const QString& process ) |
922 | { | 922 | { |
923 | QString line; | 923 | QString line; |
924 | QDir d = QDir( "/proc" ); | 924 | QDir d = QDir( "/proc" ); |
925 | QStringList dirs = d.entryList( QDir::Dirs ); | 925 | QStringList dirs = d.entryList( QDir::Dirs ); |
926 | QStringList::Iterator it; | 926 | QStringList::Iterator it; |
927 | for ( it = dirs.begin(); it != dirs.end(); ++it ) | 927 | for ( it = dirs.begin(); it != dirs.end(); ++it ) |
928 | { | 928 | { |
929 | //qDebug( "next entry: %s", (const char*) *it ); | 929 | //qDebug( "next entry: %s", (const char*) *it ); |
930 | QFile file( "/proc/"+*it+"/cmdline" ); | 930 | QFile file( "/proc/"+*it+"/cmdline" ); |
931 | file.open( IO_ReadOnly ); | 931 | if ( !file.open( IO_ReadOnly ) ) continue; |
932 | if ( !file.isOpen() ) continue; | 932 | if ( !file.isOpen() ) continue; |
933 | QTextStream t( &file ); | 933 | QTextStream t( &file ); |
934 | line = t.readLine(); | 934 | line = t.readLine(); |
935 | //qDebug( "cmdline = %s", (const char*) line ); | 935 | //qDebug( "cmdline = %s", (const char*) line ); |
936 | if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) | 936 | if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) |
937 | } | 937 | } |
938 | if ( line.contains( process ) ) | 938 | if ( line.contains( process ) ) |
939 | { | 939 | { |
940 | //qDebug( "found process id #%d", (*it).toInt() ); | 940 | //qDebug( "found process id #%d", (*it).toInt() ); |
941 | return (*it).toInt(); | 941 | return (*it).toInt(); |
942 | } | 942 | } |
943 | else | 943 | else |
944 | { | 944 | { |
945 | //qDebug( "process '%s' not found", (const char*) process ); | 945 | //qDebug( "process '%s' not found", (const char*) process ); |
946 | return 0; | 946 | return 0; |
947 | } | 947 | } |
948 | } | 948 | } |
949 | 949 | ||
950 | } | 950 | } |
951 | } | 951 | } |
diff --git a/library/global.cpp b/library/global.cpp index f7a0767..7bdd0b1 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -1,635 +1,634 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define QTOPIA_INTERNAL_LANGLIST | 20 | #define QTOPIA_INTERNAL_LANGLIST |
21 | #include <qpe/qpedebug.h> | 21 | #include <qpe/qpedebug.h> |
22 | #include <qpe/global.h> | 22 | #include <qpe/global.h> |
23 | #include <qpe/qdawg.h> | 23 | #include <qpe/qdawg.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/storage.h> | 26 | #include <qpe/storage.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | #include <qpe/qcopenvelope_qws.h> | 28 | #include <qpe/qcopenvelope_qws.h> |
29 | #include <qpe/config.h> | 29 | #include <qpe/config.h> |
30 | 30 | ||
31 | #include <qlabel.h> | 31 | #include <qlabel.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | #include <qmap.h> | 33 | #include <qmap.h> |
34 | #include <qdict.h> | 34 | #include <qdict.h> |
35 | #include <qdir.h> | 35 | #include <qdir.h> |
36 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
37 | #include <qregexp.h> | 37 | #include <qregexp.h> |
38 | 38 | ||
39 | #include <stdlib.h> | 39 | #include <stdlib.h> |
40 | #include <sys/stat.h> | 40 | #include <sys/stat.h> |
41 | #include <sys/wait.h> | 41 | #include <sys/wait.h> |
42 | #include <sys/types.h> | 42 | #include <sys/types.h> |
43 | #include <fcntl.h> | 43 | #include <fcntl.h> |
44 | #include <unistd.h> | 44 | #include <unistd.h> |
45 | #include <errno.h> | 45 | #include <errno.h> |
46 | 46 | ||
47 | #include <qwindowsystem_qws.h> // for qwsServer | 47 | #include <qwindowsystem_qws.h> // for qwsServer |
48 | #include <qdatetime.h> | 48 | #include <qdatetime.h> |
49 | 49 | ||
50 | 50 | ||
51 | //#include "quickexec_p.h" | 51 | //#include "quickexec_p.h" |
52 | 52 | ||
53 | class Emitter : public QObject { | 53 | class Emitter : public QObject { |
54 | Q_OBJECT | 54 | Q_OBJECT |
55 | public: | 55 | public: |
56 | Emitter( QWidget* receiver, const QString& document ) | 56 | Emitter( QWidget* receiver, const QString& document ) |
57 | { | 57 | { |
58 | connect(this, SIGNAL(setDocument(const QString&)), | 58 | connect(this, SIGNAL(setDocument(const QString&)), |
59 | receiver, SLOT(setDocument(const QString&))); | 59 | receiver, SLOT(setDocument(const QString&))); |
60 | emit setDocument(document); | 60 | emit setDocument(document); |
61 | disconnect(this, SIGNAL(setDocument(const QString&)), | 61 | disconnect(this, SIGNAL(setDocument(const QString&)), |
62 | receiver, SLOT(setDocument(const QString&))); | 62 | receiver, SLOT(setDocument(const QString&))); |
63 | } | 63 | } |
64 | 64 | ||
65 | signals: | 65 | signals: |
66 | void setDocument(const QString&); | 66 | void setDocument(const QString&); |
67 | }; | 67 | }; |
68 | 68 | ||
69 | 69 | ||
70 | class StartingAppList : public QObject { | 70 | class StartingAppList : public QObject { |
71 | Q_OBJECT | 71 | Q_OBJECT |
72 | public: | 72 | public: |
73 | static void add( const QString& name ); | 73 | static void add( const QString& name ); |
74 | static bool isStarting( const QString name ); | 74 | static bool isStarting( const QString name ); |
75 | private slots: | 75 | private slots: |
76 | void handleNewChannel( const QString &); | 76 | void handleNewChannel( const QString &); |
77 | private: | 77 | private: |
78 | StartingAppList( QObject *parent=0, const char* name=0 ) ; | 78 | StartingAppList( QObject *parent=0, const char* name=0 ) ; |
79 | 79 | ||
80 | QDict<QTime> dict; | 80 | QDict<QTime> dict; |
81 | static StartingAppList *appl; | 81 | static StartingAppList *appl; |
82 | }; | 82 | }; |
83 | 83 | ||
84 | StartingAppList* StartingAppList::appl = 0; | 84 | StartingAppList* StartingAppList::appl = 0; |
85 | 85 | ||
86 | StartingAppList::StartingAppList( QObject *parent, const char* name ) | 86 | StartingAppList::StartingAppList( QObject *parent, const char* name ) |
87 | :QObject( parent, name ) | 87 | :QObject( parent, name ) |
88 | { | 88 | { |
89 | #if QT_VERSION >= 232 && defined(QWS) | 89 | #if QT_VERSION >= 232 && defined(QWS) |
90 | connect( qwsServer, SIGNAL( newChannel(const QString&)), | 90 | connect( qwsServer, SIGNAL( newChannel(const QString&)), |
91 | this, SLOT( handleNewChannel(const QString&)) ); | 91 | this, SLOT( handleNewChannel(const QString&)) ); |
92 | #endif | 92 | #endif |
93 | dict.setAutoDelete( TRUE ); | 93 | dict.setAutoDelete( TRUE ); |
94 | } | 94 | } |
95 | 95 | ||
96 | void StartingAppList::add( const QString& name ) | 96 | void StartingAppList::add( const QString& name ) |
97 | { | 97 | { |
98 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 98 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
99 | if ( !appl ) | 99 | if ( !appl ) |
100 | appl = new StartingAppList; | 100 | appl = new StartingAppList; |
101 | QTime *t = new QTime; | 101 | QTime *t = new QTime; |
102 | t->start(); | 102 | t->start(); |
103 | appl->dict.insert( "QPE/Application/" + name, t ); | 103 | appl->dict.insert( "QPE/Application/" + name, t ); |
104 | #endif | 104 | #endif |
105 | } | 105 | } |
106 | 106 | ||
107 | bool StartingAppList::isStarting( const QString name ) | 107 | bool StartingAppList::isStarting( const QString name ) |
108 | { | 108 | { |
109 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 109 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
110 | if ( appl ) { | 110 | if ( appl ) { |
111 | QTime *t = appl->dict.find( "QPE/Application/" + name ); | 111 | QTime *t = appl->dict.find( "QPE/Application/" + name ); |
112 | if ( !t ) | 112 | if ( !t ) |
113 | return FALSE; | 113 | return FALSE; |
114 | if ( t->elapsed() > 10000 ) { | 114 | if ( t->elapsed() > 10000 ) { |
115 | // timeout in case of crash or something | 115 | // timeout in case of crash or something |
116 | appl->dict.remove( "QPE/Application/" + name ); | 116 | appl->dict.remove( "QPE/Application/" + name ); |
117 | return FALSE; | 117 | return FALSE; |
118 | } | 118 | } |
119 | return TRUE; | 119 | return TRUE; |
120 | } | 120 | } |
121 | #endif | 121 | #endif |
122 | return FALSE; | 122 | return FALSE; |
123 | } | 123 | } |
124 | 124 | ||
125 | void StartingAppList::handleNewChannel( const QString & name ) | 125 | void StartingAppList::handleNewChannel( const QString & name ) |
126 | { | 126 | { |
127 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 127 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
128 | dict.remove( name ); | 128 | dict.remove( name ); |
129 | #endif | 129 | #endif |
130 | } | 130 | } |
131 | 131 | ||
132 | static bool docDirCreated = FALSE; | 132 | static bool docDirCreated = FALSE; |
133 | static QDawg* fixed_dawg = 0; | 133 | static QDawg* fixed_dawg = 0; |
134 | static QDict<QDawg> *named_dawg = 0; | 134 | static QDict<QDawg> *named_dawg = 0; |
135 | 135 | ||
136 | static QString qpeDir() | 136 | static QString qpeDir() |
137 | { | 137 | { |
138 | QString dir = getenv("OPIEDIR"); | 138 | QString dir = getenv("OPIEDIR"); |
139 | if ( dir.isEmpty() ) dir = ".."; | 139 | if ( dir.isEmpty() ) dir = ".."; |
140 | return dir; | 140 | return dir; |
141 | } | 141 | } |
142 | 142 | ||
143 | static QString dictDir() | 143 | static QString dictDir() |
144 | { | 144 | { |
145 | return qpeDir() + "/etc/dict"; | 145 | return qpeDir() + "/etc/dict"; |
146 | } | 146 | } |
147 | 147 | ||
148 | /*! | 148 | /*! |
149 | \class Global global.h | 149 | \class Global global.h |
150 | \brief The Global class provides application-wide global functions. | 150 | \brief The Global class provides application-wide global functions. |
151 | 151 | ||
152 | The Global functions are grouped as follows: | 152 | The Global functions are grouped as follows: |
153 | \tableofcontents | 153 | \tableofcontents |
154 | 154 | ||
155 | \section1 User Interface | 155 | \section1 User Interface |
156 | 156 | ||
157 | The statusMessage() function provides short-duration messages to the | 157 | The statusMessage() function provides short-duration messages to the |
158 | user. The showInputMethod() function shows the current input method, | 158 | user. The showInputMethod() function shows the current input method, |
159 | and hideInputMethod() hides the input method. | 159 | and hideInputMethod() hides the input method. |
160 | 160 | ||
161 | \section1 Document related | 161 | \section1 Document related |
162 | 162 | ||
163 | The findDocuments() function creates a set of \link doclnk.html | 163 | The findDocuments() function creates a set of \link doclnk.html |
164 | DocLnk\endlink objects in a particular folder. | 164 | DocLnk\endlink objects in a particular folder. |
165 | 165 | ||
166 | \section1 Filesystem related | 166 | \section1 Filesystem related |
167 | 167 | ||
168 | Global provides an applicationFileName() function that returns the | 168 | Global provides an applicationFileName() function that returns the |
169 | full path of an application-specific file. | 169 | full path of an application-specific file. |
170 | 170 | ||
171 | The execute() function runs an application. | 171 | The execute() function runs an application. |
172 | 172 | ||
173 | \section1 Word list related | 173 | \section1 Word list related |
174 | 174 | ||
175 | A list of words relevant to the current locale is maintained by the | 175 | A list of words relevant to the current locale is maintained by the |
176 | system. The list is held in a \link qdawg.html DAWG\endlink | 176 | system. The list is held in a \link qdawg.html DAWG\endlink |
177 | (implemented by the QDawg class). This list is used, for example, by | 177 | (implemented by the QDawg class). This list is used, for example, by |
178 | the pickboard input method. | 178 | the pickboard input method. |
179 | 179 | ||
180 | The global QDawg is returned by fixedDawg(); this cannot be updated. | 180 | The global QDawg is returned by fixedDawg(); this cannot be updated. |
181 | An updatable copy of the global QDawg is returned by addedDawg(). | 181 | An updatable copy of the global QDawg is returned by addedDawg(). |
182 | Applications may have their own word lists stored in \l{QDawg}s | 182 | Applications may have their own word lists stored in \l{QDawg}s |
183 | which are returned by dawg(). Use addWords() to add words to the | 183 | which are returned by dawg(). Use addWords() to add words to the |
184 | updateable copy of the global QDawg or to named application | 184 | updateable copy of the global QDawg or to named application |
185 | \l{QDawg}s. | 185 | \l{QDawg}s. |
186 | 186 | ||
187 | \section1 Quoting | 187 | \section1 Quoting |
188 | 188 | ||
189 | The shellQuote() function quotes a string suitable for passing to a | 189 | The shellQuote() function quotes a string suitable for passing to a |
190 | shell. The stringQuote() function backslash escapes '\' and '"' | 190 | shell. The stringQuote() function backslash escapes '\' and '"' |
191 | characters. | 191 | characters. |
192 | 192 | ||
193 | \section1 Hardware | 193 | \section1 Hardware |
194 | 194 | ||
195 | The implementation of the writeHWClock() function depends on the AlarmServer | 195 | The implementation of the writeHWClock() function depends on the AlarmServer |
196 | implementation. If the AlarmServer is using atd the clock will be synced to | 196 | implementation. If the AlarmServer is using atd the clock will be synced to |
197 | hardware. If opie-alarm is used the hardware clock will be synced before | 197 | hardware. If opie-alarm is used the hardware clock will be synced before |
198 | suspending the device. opie-alarm is used by iPAQ and Zaurii implementation | 198 | suspending the device. opie-alarm is used by iPAQ and Zaurii implementation |
199 | 199 | ||
200 | \ingroup qtopiaemb | 200 | \ingroup qtopiaemb |
201 | */ | 201 | */ |
202 | 202 | ||
203 | /*! | 203 | /*! |
204 | \internal | 204 | \internal |
205 | */ | 205 | */ |
206 | Global::Global() | 206 | Global::Global() |
207 | { | 207 | { |
208 | } | 208 | } |
209 | 209 | ||
210 | /*! | 210 | /*! |
211 | Returns the unchangeable QDawg that contains general | 211 | Returns the unchangeable QDawg that contains general |
212 | words for the current locale. | 212 | words for the current locale. |
213 | 213 | ||
214 | \sa addedDawg() | 214 | \sa addedDawg() |
215 | */ | 215 | */ |
216 | const QDawg& Global::fixedDawg() | 216 | const QDawg& Global::fixedDawg() |
217 | { | 217 | { |
218 | if ( !fixed_dawg ) { | 218 | if ( !fixed_dawg ) { |
219 | if ( !docDirCreated ) | 219 | if ( !docDirCreated ) |
220 | createDocDir(); | 220 | createDocDir(); |
221 | 221 | ||
222 | fixed_dawg = new QDawg; | 222 | fixed_dawg = new QDawg; |
223 | QString dawgfilename = dictDir() + "/dawg"; | 223 | QString dawgfilename = dictDir() + "/dawg"; |
224 | QString words_lang; | 224 | QString words_lang; |
225 | QStringList langs = Global::languageList(); | 225 | QStringList langs = Global::languageList(); |
226 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { | 226 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
227 | QString lang = *it; | 227 | QString lang = *it; |
228 | words_lang = dictDir() + "/words." + lang; | 228 | words_lang = dictDir() + "/words." + lang; |
229 | QString dawgfilename_lang = dawgfilename + "." + lang; | 229 | QString dawgfilename_lang = dawgfilename + "." + lang; |
230 | if ( QFile::exists(dawgfilename_lang) || | 230 | if ( QFile::exists(dawgfilename_lang) || |
231 | QFile::exists(words_lang) ) { | 231 | QFile::exists(words_lang) ) { |
232 | dawgfilename = dawgfilename_lang; | 232 | dawgfilename = dawgfilename_lang; |
233 | break; | 233 | break; |
234 | } | 234 | } |
235 | } | ||
236 | QFile dawgfile(dawgfilename); | ||
237 | |||
238 | if ( !dawgfile.exists() ) { | ||
239 | QString fn = dictDir() + "/words"; | ||
240 | if ( QFile::exists(words_lang) ) | ||
241 | fn = words_lang; | ||
242 | QFile in(fn); | ||
243 | if ( in.open(IO_ReadOnly) ) { | ||
244 | fixed_dawg->createFromWords(&in); | ||
245 | dawgfile.open(IO_WriteOnly); | ||
246 | fixed_dawg->write(&dawgfile); | ||
247 | dawgfile.close(); | ||
248 | } | 235 | } |
249 | } else { | 236 | QFile dawgfile(dawgfilename); |
250 | fixed_dawg->readFile(dawgfilename); | 237 | |
251 | } | 238 | if ( !dawgfile.exists() ) { |
239 | QString fn = dictDir() + "/words"; | ||
240 | if ( QFile::exists(words_lang) ) | ||
241 | fn = words_lang; | ||
242 | QFile in(fn); | ||
243 | if ( in.open(IO_ReadOnly) ) { | ||
244 | fixed_dawg->createFromWords(&in); | ||
245 | if (dawgfile.open(IO_WriteOnly)) | ||
246 | fixed_dawg->write(&dawgfile); | ||
247 | dawgfile.close(); | ||
248 | } | ||
249 | } else | ||
250 | fixed_dawg->readFile(dawgfilename); | ||
252 | } | 251 | } |
253 | 252 | ||
254 | return *fixed_dawg; | 253 | return *fixed_dawg; |
255 | } | 254 | } |
256 | 255 | ||
257 | /*! | 256 | /*! |
258 | Returns the changeable QDawg that contains general | 257 | Returns the changeable QDawg that contains general |
259 | words for the current locale. | 258 | words for the current locale. |
260 | 259 | ||
261 | \sa fixedDawg() | 260 | \sa fixedDawg() |
262 | */ | 261 | */ |
263 | const QDawg& Global::addedDawg() | 262 | const QDawg& Global::addedDawg() |
264 | { | 263 | { |
265 | return dawg("local"); | 264 | return dawg("local"); |
266 | } | 265 | } |
267 | 266 | ||
268 | /*! | 267 | /*! |
269 | Returns the QDawg with the given \a name. | 268 | Returns the QDawg with the given \a name. |
270 | This is an application-specific word list. | 269 | This is an application-specific word list. |
271 | 270 | ||
272 | \a name should not contain "/". | 271 | \a name should not contain "/". |
273 | */ | 272 | */ |
274 | const QDawg& Global::dawg(const QString& name) | 273 | const QDawg& Global::dawg(const QString& name) |
275 | { | 274 | { |
276 | createDocDir(); | 275 | createDocDir(); |
277 | if ( !named_dawg ) | 276 | if ( !named_dawg ) |
278 | named_dawg = new QDict<QDawg>; | 277 | named_dawg = new QDict<QDawg>; |
279 | QDawg* r = named_dawg->find(name); | 278 | QDawg* r = named_dawg->find(name); |
280 | if ( !r ) { | 279 | if ( !r ) { |
281 | r = new QDawg; | 280 | r = new QDawg; |
282 | named_dawg->insert(name,r); | 281 | named_dawg->insert(name,r); |
283 | QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; | 282 | QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; |
284 | QFile dawgfile(dawgfilename); | 283 | QFile dawgfile(dawgfilename); |
285 | if ( dawgfile.open(IO_ReadOnly) ) | 284 | if ( dawgfile.open(IO_ReadOnly) ) |
286 | r->readFile(dawgfilename); | 285 | r->readFile(dawgfilename); |
287 | } | 286 | } |
288 | return *r; | 287 | return *r; |
289 | } | 288 | } |
290 | 289 | ||
291 | /*! | 290 | /*! |
292 | \overload | 291 | \overload |
293 | Adds \a wordlist to the addedDawg(). | 292 | Adds \a wordlist to the addedDawg(). |
294 | 293 | ||
295 | Note that the addition of words persists between program executions | 294 | Note that the addition of words persists between program executions |
296 | (they are saved in the dictionary files), so you should confirm the | 295 | (they are saved in the dictionary files), so you should confirm the |
297 | words with the user before adding them. | 296 | words with the user before adding them. |
298 | */ | 297 | */ |
299 | void Global::addWords(const QStringList& wordlist) | 298 | void Global::addWords(const QStringList& wordlist) |
300 | { | 299 | { |
301 | addWords("local",wordlist); | 300 | addWords("local",wordlist); |
302 | } | 301 | } |
303 | 302 | ||
304 | /*! | 303 | /*! |
305 | \overload | 304 | \overload |
306 | Adds \a wordlist to the addedDawg(). | 305 | Adds \a wordlist to the addedDawg(). |
307 | 306 | ||
308 | Note that the addition of words persists between program executions | 307 | Note that the addition of words persists between program executions |
309 | (they are saved in the dictionary files), so you should confirm the | 308 | (they are saved in the dictionary files), so you should confirm the |
310 | words with the user before adding them. | 309 | words with the user before adding them. |
311 | */ | 310 | */ |
312 | void Global::addWords(const QString& dictname, const QStringList& wordlist) | 311 | void Global::addWords(const QString& dictname, const QStringList& wordlist) |
313 | { | 312 | { |
314 | QDawg& d = (QDawg&)dawg(dictname); | 313 | QDawg& d = (QDawg&)dawg(dictname); |
315 | QStringList all = d.allWords() + wordlist; | 314 | QStringList all = d.allWords() + wordlist; |
316 | d.createFromWords(all); | 315 | d.createFromWords(all); |
317 | 316 | ||
318 | QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; | 317 | QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; |
319 | QFile dawgfile(dawgfilename); | 318 | QFile dawgfile(dawgfilename); |
320 | if ( dawgfile.open(IO_WriteOnly) ) { | 319 | if ( dawgfile.open(IO_WriteOnly) ) { |
321 | d.write(&dawgfile); | 320 | d.write(&dawgfile); |
322 | dawgfile.close(); | 321 | dawgfile.close(); |
323 | } | 322 | } |
324 | 323 | ||
325 | // #### Re-read the dawg here if we use mmap(). | 324 | // #### Re-read the dawg here if we use mmap(). |
326 | 325 | ||
327 | // #### Signal other processes to re-read. | 326 | // #### Signal other processes to re-read. |
328 | } | 327 | } |
329 | 328 | ||
330 | 329 | ||
331 | /*! | 330 | /*! |
332 | Returns the full path for the application called \a appname, with the | 331 | Returns the full path for the application called \a appname, with the |
333 | given \a filename. Returns QString::null if there was a problem creating | 332 | given \a filename. Returns QString::null if there was a problem creating |
334 | the directory tree for \a appname. | 333 | the directory tree for \a appname. |
335 | If \a filename contains "/", it is the caller's responsibility to | 334 | If \a filename contains "/", it is the caller's responsibility to |
336 | ensure that those directories exist. | 335 | ensure that those directories exist. |
337 | */ | 336 | */ |
338 | QString Global::applicationFileName(const QString& appname, const QString& filename) | 337 | QString Global::applicationFileName(const QString& appname, const QString& filename) |
339 | { | 338 | { |
340 | QDir d; | 339 | QDir d; |
341 | QString r = getenv("HOME"); | 340 | QString r = getenv("HOME"); |
342 | r += "/Applications/"; | 341 | r += "/Applications/"; |
343 | if ( !QFile::exists( r ) ) | 342 | if ( !QFile::exists( r ) ) |
344 | if ( d.mkdir(r) == false ) | 343 | if ( d.mkdir(r) == false ) |
345 | return QString::null; | 344 | return QString::null; |
346 | r += appname; | 345 | r += appname; |
347 | if ( !QFile::exists( r ) ) | 346 | if ( !QFile::exists( r ) ) |
348 | if ( d.mkdir(r) == false ) | 347 | if ( d.mkdir(r) == false ) |
349 | return QString::null; | 348 | return QString::null; |
350 | r += "/"; r += filename; | 349 | r += "/"; r += filename; |
351 | return r; | 350 | return r; |
352 | } | 351 | } |
353 | 352 | ||
354 | /*! | 353 | /*! |
355 | \internal | 354 | \internal |
356 | */ | 355 | */ |
357 | void Global::createDocDir() | 356 | void Global::createDocDir() |
358 | { | 357 | { |
359 | if ( !docDirCreated ) { | 358 | if ( !docDirCreated ) { |
360 | docDirCreated = TRUE; | 359 | docDirCreated = TRUE; |
361 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); | 360 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); |
362 | } | 361 | } |
363 | } | 362 | } |
364 | 363 | ||
365 | 364 | ||
366 | /*! | 365 | /*! |
367 | Displays a status \a message to the user. This usually appears | 366 | Displays a status \a message to the user. This usually appears |
368 | in the taskbar for a short amount of time, then disappears. | 367 | in the taskbar for a short amount of time, then disappears. |
369 | */ | 368 | */ |
370 | void Global::statusMessage(const QString& message) | 369 | void Global::statusMessage(const QString& message) |
371 | { | 370 | { |
372 | #if !defined(QT_NO_COP) | 371 | #if !defined(QT_NO_COP) |
373 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); | 372 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); |
374 | e << message; | 373 | e << message; |
375 | #endif | 374 | #endif |
376 | } | 375 | } |
377 | 376 | ||
378 | /*! | 377 | /*! |
379 | \internal | 378 | \internal |
380 | */ | 379 | */ |
381 | void Global::applyStyle() | 380 | void Global::applyStyle() |
382 | { | 381 | { |
383 | #if !defined(QT_NO_COP) | 382 | #if !defined(QT_NO_COP) |
384 | QCopChannel::send( "QPE/System", "applyStyle()" ); | 383 | QCopChannel::send( "QPE/System", "applyStyle()" ); |
385 | #else | 384 | #else |
386 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version | 385 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version |
387 | #endif | 386 | #endif |
388 | } | 387 | } |
389 | 388 | ||
390 | /*! | 389 | /*! |
391 | \internal | 390 | \internal |
392 | */ | 391 | */ |
393 | QWidget *Global::shutdown( bool ) | 392 | QWidget *Global::shutdown( bool ) |
394 | { | 393 | { |
395 | #if !defined(QT_NO_COP) | 394 | #if !defined(QT_NO_COP) |
396 | QCopChannel::send( "QPE/System", "shutdown()" ); | 395 | QCopChannel::send( "QPE/System", "shutdown()" ); |
397 | #endif | 396 | #endif |
398 | return 0; | 397 | return 0; |
399 | } | 398 | } |
400 | 399 | ||
401 | /*! | 400 | /*! |
402 | \internal | 401 | \internal |
403 | */ | 402 | */ |
404 | QWidget *Global::restart( bool ) | 403 | QWidget *Global::restart( bool ) |
405 | { | 404 | { |
406 | #if !defined(QT_NO_COP) | 405 | #if !defined(QT_NO_COP) |
407 | QCopChannel::send( "QPE/System", "restart()" ); | 406 | QCopChannel::send( "QPE/System", "restart()" ); |
408 | #endif | 407 | #endif |
409 | return 0; | 408 | return 0; |
410 | } | 409 | } |
411 | 410 | ||
412 | /*! | 411 | /*! |
413 | Explicitly show the current input method. | 412 | Explicitly show the current input method. |
414 | 413 | ||
415 | Input methods are indicated in the taskbar by a small icon. If the | 414 | Input methods are indicated in the taskbar by a small icon. If the |
416 | input method is activated (shown) then it takes up some proportion | 415 | input method is activated (shown) then it takes up some proportion |
417 | of the bottom of the screen, to allow the user to interact (input | 416 | of the bottom of the screen, to allow the user to interact (input |
418 | characters) with it. | 417 | characters) with it. |
419 | 418 | ||
420 | \sa hideInputMethod() | 419 | \sa hideInputMethod() |
421 | */ | 420 | */ |
422 | void Global::showInputMethod() | 421 | void Global::showInputMethod() |
423 | { | 422 | { |
424 | #if !defined(QT_NO_COP) | 423 | #if !defined(QT_NO_COP) |
425 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); | 424 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); |
426 | #endif | 425 | #endif |
427 | } | 426 | } |
428 | 427 | ||
429 | /*! | 428 | /*! |
430 | Explicitly hide the current input method. | 429 | Explicitly hide the current input method. |
431 | 430 | ||
432 | The current input method is still indicated in the taskbar, but no | 431 | The current input method is still indicated in the taskbar, but no |
433 | longer takes up screen space, and can no longer be interacted with. | 432 | longer takes up screen space, and can no longer be interacted with. |
434 | 433 | ||
435 | \sa showInputMethod() | 434 | \sa showInputMethod() |
436 | */ | 435 | */ |
437 | void Global::hideInputMethod() | 436 | void Global::hideInputMethod() |
438 | { | 437 | { |
439 | #if !defined(QT_NO_COP) | 438 | #if !defined(QT_NO_COP) |
440 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); | 439 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); |
441 | #endif | 440 | #endif |
442 | } | 441 | } |
443 | 442 | ||
444 | 443 | ||
445 | /*! | 444 | /*! |
446 | \internal | 445 | \internal |
447 | */ | 446 | */ |
448 | bool Global::isBuiltinCommand( const QString &name ) | 447 | bool Global::isBuiltinCommand( const QString &name ) |
449 | { | 448 | { |
450 | if(!builtin) | 449 | if(!builtin) |
451 | return FALSE; // yes, it can happen | 450 | return FALSE; // yes, it can happen |
452 | for (int i = 0; builtin[i].file; i++) { | 451 | for (int i = 0; builtin[i].file; i++) { |
453 | if ( builtin[i].file == name ) { | 452 | if ( builtin[i].file == name ) { |
454 | return TRUE; | 453 | return TRUE; |
455 | } | 454 | } |
456 | } | 455 | } |
457 | return FALSE; | 456 | return FALSE; |
458 | } | 457 | } |
459 | 458 | ||
460 | Global::Command* Global::builtin=0; | 459 | Global::Command* Global::builtin=0; |
461 | QGuardedPtr<QWidget> *Global::running=0; | 460 | QGuardedPtr<QWidget> *Global::running=0; |
462 | 461 | ||
463 | /*! | 462 | /*! |
464 | \class Global::Command | 463 | \class Global::Command |
465 | \brief The Global::Command class is internal. | 464 | \brief The Global::Command class is internal. |
466 | \internal | 465 | \internal |
467 | */ | 466 | */ |
468 | 467 | ||
469 | /*! | 468 | /*! |
470 | \internal | 469 | \internal |
471 | */ | 470 | */ |
472 | void Global::setBuiltinCommands( Command* list ) | 471 | void Global::setBuiltinCommands( Command* list ) |
473 | { | 472 | { |
474 | if ( running ) | 473 | if ( running ) |
475 | delete [] running; | 474 | delete [] running; |
476 | 475 | ||
477 | builtin = list; | 476 | builtin = list; |
478 | int count = 0; | 477 | int count = 0; |
479 | if (!builtin) | 478 | if (!builtin) |
480 | return; | 479 | return; |
481 | while ( builtin[count].file ) | 480 | while ( builtin[count].file ) |
482 | count++; | 481 | count++; |
483 | 482 | ||
484 | running = new QGuardedPtr<QWidget> [ count ]; | 483 | running = new QGuardedPtr<QWidget> [ count ]; |
485 | } | 484 | } |
486 | 485 | ||
487 | /*! | 486 | /*! |
488 | \internal | 487 | \internal |
489 | */ | 488 | */ |
490 | void Global::setDocument( QWidget* receiver, const QString& document ) | 489 | void Global::setDocument( QWidget* receiver, const QString& document ) |
491 | { | 490 | { |
492 | Emitter emitter(receiver,document); | 491 | Emitter emitter(receiver,document); |
493 | } | 492 | } |
494 | 493 | ||
495 | /*! | 494 | /*! |
496 | \internal | 495 | \internal |
497 | */ | 496 | */ |
498 | bool Global::terminateBuiltin( const QString& n ) | 497 | bool Global::terminateBuiltin( const QString& n ) |
499 | { | 498 | { |
500 | if (!builtin) | 499 | if (!builtin) |
501 | return FALSE; | 500 | return FALSE; |
502 | for (int i = 0; builtin[i].file; i++) { | 501 | for (int i = 0; builtin[i].file; i++) { |
503 | if ( builtin[i].file == n ) { | 502 | if ( builtin[i].file == n ) { |
504 | delete running[i]; | 503 | delete running[i]; |
505 | return TRUE; | 504 | return TRUE; |
506 | } | 505 | } |
507 | } | 506 | } |
508 | return FALSE; | 507 | return FALSE; |
509 | } | 508 | } |
510 | 509 | ||
511 | /*! | 510 | /*! |
512 | \internal | 511 | \internal |
513 | */ | 512 | */ |
514 | void Global::terminate( const AppLnk* app ) | 513 | void Global::terminate( const AppLnk* app ) |
515 | { | 514 | { |
516 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 515 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
517 | 516 | ||
518 | #ifndef QT_NO_COP | 517 | #ifndef QT_NO_COP |
519 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 518 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
520 | if ( QCopChannel::isRegistered(channel) ) { | 519 | if ( QCopChannel::isRegistered(channel) ) { |
521 | QCopEnvelope e(channel, "quit()"); | 520 | QCopEnvelope e(channel, "quit()"); |
522 | } | 521 | } |
523 | #endif | 522 | #endif |
524 | } | 523 | } |
525 | 524 | ||
526 | /*! | 525 | /*! |
527 | Low-level function to run command \a c. | 526 | Low-level function to run command \a c. |
528 | 527 | ||
529 | \warning Do not use this function. Use execute instead. | 528 | \warning Do not use this function. Use execute instead. |
530 | 529 | ||
531 | \sa execute() | 530 | \sa execute() |
532 | */ | 531 | */ |
533 | void Global::invoke(const QString &c) | 532 | void Global::invoke(const QString &c) |
534 | { | 533 | { |
535 | // Convert the command line in to a list of arguments | 534 | // Convert the command line in to a list of arguments |
536 | QStringList list = QStringList::split(QRegExp(" *"),c); | 535 | QStringList list = QStringList::split(QRegExp(" *"),c); |
537 | 536 | ||
538 | #if !defined(QT_NO_COP) | 537 | #if !defined(QT_NO_COP) |
539 | QString ap=list[0]; | 538 | QString ap=list[0]; |
540 | // see if the application is already running | 539 | // see if the application is already running |
541 | // XXX should lock file /tmp/qcop-msg-ap | 540 | // XXX should lock file /tmp/qcop-msg-ap |
542 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 541 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
543 | // If the channel is already register, the app is already running, so show it. | 542 | // If the channel is already register, the app is already running, so show it. |
544 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 543 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
545 | 544 | ||
546 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 545 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
547 | //e << ap; | 546 | //e << ap; |
548 | return; | 547 | return; |
549 | } | 548 | } |
550 | // XXX should unlock file /tmp/qcop-msg-ap | 549 | // XXX should unlock file /tmp/qcop-msg-ap |
551 | //see if it is being started | 550 | //see if it is being started |
552 | if ( StartingAppList::isStarting( ap ) ) { | 551 | if ( StartingAppList::isStarting( ap ) ) { |
553 | // FIXME take it out for now, since it leads to a much to short showing of wait if | 552 | // FIXME take it out for now, since it leads to a much to short showing of wait if |
554 | // some entry is clicked. | 553 | // some entry is clicked. |
555 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes | 554 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes |
556 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there | 555 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there |
557 | // had the idea that an apploader belongs to the launcher ... | 556 | // had the idea that an apploader belongs to the launcher ... |
558 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 557 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
559 | //e << ap; | 558 | //e << ap; |
560 | return; | 559 | return; |
561 | } | 560 | } |
562 | 561 | ||
563 | #endif | 562 | #endif |
564 | 563 | ||
565 | #ifdef QT_NO_QWS_MULTIPROCESS | 564 | #ifdef QT_NO_QWS_MULTIPROCESS |
566 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 565 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
567 | #else | 566 | #else |
568 | 567 | ||
569 | QStrList slist; | 568 | QStrList slist; |
570 | unsigned int j; | 569 | unsigned int j; |
571 | for ( j = 0; j < list.count(); j++ ) | 570 | for ( j = 0; j < list.count(); j++ ) |
572 | slist.append( list[j].utf8() ); | 571 | slist.append( list[j].utf8() ); |
573 | 572 | ||
574 | const char **args = new const char *[slist.count() + 1]; | 573 | const char **args = new const char *[slist.count() + 1]; |
575 | for ( j = 0; j < slist.count(); j++ ) | 574 | for ( j = 0; j < slist.count(); j++ ) |
576 | args[j] = slist.at(j); | 575 | args[j] = slist.at(j); |
577 | args[j] = NULL; | 576 | args[j] = NULL; |
578 | 577 | ||
579 | #if !defined(QT_NO_COP) | 578 | #if !defined(QT_NO_COP) |
580 | // an attempt to show a wait... | 579 | // an attempt to show a wait... |
581 | // more logic should be used, but this will be fine for the moment... | 580 | // more logic should be used, but this will be fine for the moment... |
582 | QCopEnvelope ( "QPE/System", "busy()" ); | 581 | QCopEnvelope ( "QPE/System", "busy()" ); |
583 | #endif | 582 | #endif |
584 | 583 | ||
585 | #ifdef HAVE_QUICKEXEC | 584 | #ifdef HAVE_QUICKEXEC |
586 | #ifdef Q_OS_MACX | 585 | #ifdef Q_OS_MACX |
587 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; | 586 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; |
588 | #else | 587 | #else |
589 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 588 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
590 | #endif | 589 | #endif |
591 | qDebug("libfile = %s", libexe.latin1() ); | 590 | qDebug("libfile = %s", libexe.latin1() ); |
592 | if ( QFile::exists( libexe ) ) { | 591 | if ( QFile::exists( libexe ) ) { |
593 | qDebug("calling quickexec %s", libexe.latin1() ); | 592 | qDebug("calling quickexec %s", libexe.latin1() ); |
594 | quickexecv( libexe.utf8().data(), (const char **)args ); | 593 | quickexecv( libexe.utf8().data(), (const char **)args ); |
595 | } else | 594 | } else |
596 | #endif | 595 | #endif |
597 | { | 596 | { |
598 | bool success = false; | 597 | bool success = false; |
599 | int pfd [2]; | 598 | int pfd [2]; |
600 | if ( ::pipe ( pfd ) < 0 ) | 599 | if ( ::pipe ( pfd ) < 0 ) |
601 | pfd [0] = pfd [1] = -1; | 600 | pfd [0] = pfd [1] = -1; |
602 | 601 | ||
603 | pid_t pid = ::fork ( ); | 602 | pid_t pid = ::fork ( ); |
604 | 603 | ||
605 | if ( pid == 0 ) { // child | 604 | if ( pid == 0 ) { // child |
606 | for ( int fd = 3; fd < 100; fd++ ) { | 605 | for ( int fd = 3; fd < 100; fd++ ) { |
607 | if ( fd != pfd [1] ) | 606 | if ( fd != pfd [1] ) |
608 | ::close ( fd ); | 607 | ::close ( fd ); |
609 | } | 608 | } |
610 | ::setpgid ( ::getpid ( ), ::getppid ( )); | 609 | ::setpgid ( ::getpid ( ), ::getppid ( )); |
611 | 610 | ||
612 | // Closing of fd[1] indicates that the execvp succeeded! | 611 | // Closing of fd[1] indicates that the execvp succeeded! |
613 | if ( pfd [1] >= 0 ) | 612 | if ( pfd [1] >= 0 ) |
614 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); | 613 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); |
615 | 614 | ||
616 | // Try bindir first, so that foo/bar works too | 615 | // Try bindir first, so that foo/bar works too |
617 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); | 616 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); |
618 | ::execvp ( args [0], (char * const *) args ); | 617 | ::execvp ( args [0], (char * const *) args ); |
619 | 618 | ||
620 | char resultByte = 1; | 619 | char resultByte = 1; |
621 | if ( pfd [1] >= 0 ) | 620 | if ( pfd [1] >= 0 ) |
622 | ::write ( pfd [1], &resultByte, 1 ); | 621 | ::write ( pfd [1], &resultByte, 1 ); |
623 | ::_exit ( -1 ); | 622 | ::_exit ( -1 ); |
624 | } | 623 | } |
625 | else if ( pid > 0 ) { | 624 | else if ( pid > 0 ) { |
626 | success = true; | 625 | success = true; |
627 | 626 | ||
628 | if ( pfd [1] >= 0 ) | 627 | if ( pfd [1] >= 0 ) |
629 | ::close ( pfd [1] ); | 628 | ::close ( pfd [1] ); |
630 | if ( pfd [0] >= 0 ) { | 629 | if ( pfd [0] >= 0 ) { |
631 | while ( true ) { | 630 | while ( true ) { |
632 | char resultByte; | 631 | char resultByte; |
633 | int n = ::read ( pfd [0], &resultByte, 1 ); | 632 | int n = ::read ( pfd [0], &resultByte, 1 ); |
634 | if ( n == 1 ) { | 633 | if ( n == 1 ) { |
635 | success = false; | 634 | success = false; |
diff --git a/noncore/apps/advancedfm/output.cpp b/noncore/apps/advancedfm/output.cpp index 8c585f4..8f654d5 100644 --- a/noncore/apps/advancedfm/output.cpp +++ b/noncore/apps/advancedfm/output.cpp | |||
@@ -1,281 +1,282 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** outputEdit.cpp | 2 | ** outputEdit.cpp |
3 | ** | 3 | ** |
4 | ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com> | 4 | ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com> |
5 | ****************************************************************************/ | 5 | ****************************************************************************/ |
6 | #include "output.h" | 6 | #include "output.h" |
7 | 7 | ||
8 | /* OPIE */ | 8 | /* OPIE */ |
9 | #include <opie2/odebug.h> | 9 | #include <opie2/odebug.h> |
10 | #include <qpe/qpeapplication.h> | 10 | #include <qpe/qpeapplication.h> |
11 | #include <qpe/applnk.h> | 11 | #include <qpe/applnk.h> |
12 | using namespace Opie::Core; | 12 | using namespace Opie::Core; |
13 | 13 | ||
14 | /* QT */ | 14 | /* QT */ |
15 | #include <qfile.h> | 15 | #include <qfile.h> |
16 | #include <qmultilineedit.h> | 16 | #include <qmultilineedit.h> |
17 | #include <qpushbutton.h> | 17 | #include <qpushbutton.h> |
18 | #include <qlayout.h> | 18 | #include <qlayout.h> |
19 | 19 | ||
20 | /* STD */ | 20 | /* STD */ |
21 | #include <errno.h> | 21 | #include <errno.h> |
22 | 22 | ||
23 | /* XPM */ | 23 | /* XPM */ |
24 | static char * filesave_xpm[] = { | 24 | static char * filesave_xpm[] = { |
25 | "16 16 78 1", | 25 | "16 16 78 1", |
26 | " c None", | 26 | " c None", |
27 | ". c #343434", | 27 | ". c #343434", |
28 | "+ c #A0A0A0", | 28 | "+ c #A0A0A0", |
29 | "@ c #565656", | 29 | "@ c #565656", |
30 | "# c #9E9E9E", | 30 | "# c #9E9E9E", |
31 | "$ c #525252", | 31 | "$ c #525252", |
32 | "% c #929292", | 32 | "% c #929292", |
33 | "& c #676767", | 33 | "& c #676767", |
34 | "* c #848484", | 34 | "* c #848484", |
35 | "= c #666666", | 35 | "= c #666666", |
36 | "- c #D8D8D8", | 36 | "- c #D8D8D8", |
37 | "; c #FFFFFF", | 37 | "; c #FFFFFF", |
38 | "> c #DBDBDB", | 38 | "> c #DBDBDB", |
39 | ", c #636363", | 39 | ", c #636363", |
40 | "' c #989898", | 40 | "' c #989898", |
41 | ") c #2D2D2D", | 41 | ") c #2D2D2D", |
42 | "! c #909090", | 42 | "! c #909090", |
43 | "~ c #AEAEAE", | 43 | "~ c #AEAEAE", |
44 | "{ c #EAEAEA", | 44 | "{ c #EAEAEA", |
45 | "] c #575757", | 45 | "] c #575757", |
46 | "^ c #585858", | 46 | "^ c #585858", |
47 | "/ c #8A8A8A", | 47 | "/ c #8A8A8A", |
48 | "( c #828282", | 48 | "( c #828282", |
49 | "_ c #6F6F6F", | 49 | "_ c #6F6F6F", |
50 | ": c #C9C9C9", | 50 | ": c #C9C9C9", |
51 | "< c #050505", | 51 | "< c #050505", |
52 | "[ c #292929", | 52 | "[ c #292929", |
53 | "} c #777777", | 53 | "} c #777777", |
54 | "| c #616161", | 54 | "| c #616161", |
55 | "1 c #3A3A3A", | 55 | "1 c #3A3A3A", |
56 | "2 c #BEBEBE", | 56 | "2 c #BEBEBE", |
57 | "3 c #2C2C2C", | 57 | "3 c #2C2C2C", |
58 | "4 c #7C7C7C", | 58 | "4 c #7C7C7C", |
59 | "5 c #F6F6F6", | 59 | "5 c #F6F6F6", |
60 | "6 c #FCFCFC", | 60 | "6 c #FCFCFC", |
61 | "7 c #6B6B6B", | 61 | "7 c #6B6B6B", |
62 | "8 c #959595", | 62 | "8 c #959595", |
63 | "9 c #4F4F4F", | 63 | "9 c #4F4F4F", |
64 | "0 c #808080", | 64 | "0 c #808080", |
65 | "a c #767676", | 65 | "a c #767676", |
66 | "b c #818181", | 66 | "b c #818181", |
67 | "c c #B8B8B8", | 67 | "c c #B8B8B8", |
68 | "d c #FBFBFB", | 68 | "d c #FBFBFB", |
69 | "e c #F9F9F9", | 69 | "e c #F9F9F9", |
70 | "f c #CCCCCC", | 70 | "f c #CCCCCC", |
71 | "g c #030303", | 71 | "g c #030303", |
72 | "h c #737373", | 72 | "h c #737373", |
73 | "i c #7A7A7A", | 73 | "i c #7A7A7A", |
74 | "j c #7E7E7E", | 74 | "j c #7E7E7E", |
75 | "k c #6A6A6A", | 75 | "k c #6A6A6A", |
76 | "l c #FAFAFA", | 76 | "l c #FAFAFA", |
77 | "m c #505050", | 77 | "m c #505050", |
78 | "n c #9D9D9D", | 78 | "n c #9D9D9D", |
79 | "o c #333333", | 79 | "o c #333333", |
80 | "p c #7B7B7B", | 80 | "p c #7B7B7B", |
81 | "q c #787878", | 81 | "q c #787878", |
82 | "r c #696969", | 82 | "r c #696969", |
83 | "s c #494949", | 83 | "s c #494949", |
84 | "t c #555555", | 84 | "t c #555555", |
85 | "u c #949494", | 85 | "u c #949494", |
86 | "v c #E6E6E6", | 86 | "v c #E6E6E6", |
87 | "w c #424242", | 87 | "w c #424242", |
88 | "x c #515151", | 88 | "x c #515151", |
89 | "y c #535353", | 89 | "y c #535353", |
90 | "z c #3E3E3E", | 90 | "z c #3E3E3E", |
91 | "A c #D4D4D4", | 91 | "A c #D4D4D4", |
92 | "B c #0C0C0C", | 92 | "B c #0C0C0C", |
93 | "C c #353535", | 93 | "C c #353535", |
94 | "D c #474747", | 94 | "D c #474747", |
95 | "E c #ECECEC", | 95 | "E c #ECECEC", |
96 | "F c #919191", | 96 | "F c #919191", |
97 | "G c #7D7D7D", | 97 | "G c #7D7D7D", |
98 | "H c #000000", | 98 | "H c #000000", |
99 | "I c #404040", | 99 | "I c #404040", |
100 | "J c #858585", | 100 | "J c #858585", |
101 | "K c #323232", | 101 | "K c #323232", |
102 | "L c #D0D0D0", | 102 | "L c #D0D0D0", |
103 | "M c #1C1C1C", | 103 | "M c #1C1C1C", |
104 | " ...+ ", | 104 | " ...+ ", |
105 | " @#$%&..+ ", | 105 | " @#$%&..+ ", |
106 | " .*=-;;>,..+ ", | 106 | " .*=-;;>,..+ ", |
107 | " ')!~;;;;;;{]..", | 107 | " ')!~;;;;;;{]..", |
108 | " ^/(-;;;;;;;_:<", | 108 | " ^/(-;;;;;;;_:<", |
109 | " [}|;;;;;;;{12$", | 109 | " [}|;;;;;;;{12$", |
110 | " #34-55;;;;678$+", | 110 | " #34-55;;;;678$+", |
111 | " 90ab=c;dd;e1fg ", | 111 | " 90ab=c;dd;e1fg ", |
112 | " [ahij((kbl0mn$ ", | 112 | " [ahij((kbl0mn$ ", |
113 | " op^q^^7r&]s/$+ ", | 113 | " op^q^^7r&]s/$+ ", |
114 | "@btu;vbwxy]zAB ", | 114 | "@btu;vbwxy]zAB ", |
115 | "CzDEvEv;;DssF$ ", | 115 | "CzDEvEv;;DssF$ ", |
116 | "G.H{E{E{IxsJ$+ ", | 116 | "G.H{E{E{IxsJ$+ ", |
117 | " +...vEKxzLM ", | 117 | " +...vEKxzLM ", |
118 | " +...z]n$ ", | 118 | " +...z]n$ ", |
119 | " +... "}; | 119 | " +... "}; |
120 | 120 | ||
121 | Output::Output( const QStringList commands, QWidget* parent, const char* name, bool modal, WFlags fl) | 121 | Output::Output( const QStringList commands, QWidget* parent, const char* name, bool modal, WFlags fl) |
122 | : QDialog( parent, name, modal, fl ) | 122 | : QDialog( parent, name, modal, fl ) |
123 | { | 123 | { |
124 | QStringList cmmds; | 124 | QStringList cmmds; |
125 | // cmmds=QStringList::split( " ", commands, false); | 125 | // cmmds=QStringList::split( " ", commands, false); |
126 | cmmds=commands; | 126 | cmmds=commands; |
127 | // odebug << "count " << cmmds.count() << "" << oendl; | 127 | // odebug << "count " << cmmds.count() << "" << oendl; |
128 | if ( !name ) | 128 | if ( !name ) |
129 | setName( tr("Output")); | 129 | setName( tr("Output")); |
130 | resize( 196, 269 ); | 130 | resize( 196, 269 ); |
131 | setCaption( name ); | 131 | setCaption( name ); |
132 | 132 | ||
133 | OutputLayout = new QGridLayout( this ); | 133 | OutputLayout = new QGridLayout( this ); |
134 | OutputLayout->setSpacing( 2); | 134 | OutputLayout->setSpacing( 2); |
135 | OutputLayout->setMargin( 2); | 135 | OutputLayout->setMargin( 2); |
136 | 136 | ||
137 | QPushButton *docButton; | 137 | QPushButton *docButton; |
138 | docButton = new QPushButton( QPixmap(( const char** ) filesave_xpm ) ,"",this,"saveButton"); | 138 | docButton = new QPushButton( QPixmap(( const char** ) filesave_xpm ) ,"",this,"saveButton"); |
139 | docButton->setFixedSize( QSize( 20, 20 ) ); | 139 | docButton->setFixedSize( QSize( 20, 20 ) ); |
140 | connect( docButton,SIGNAL(released()),this,SLOT( saveOutput() )); | 140 | connect( docButton,SIGNAL(released()),this,SLOT( saveOutput() )); |
141 | // docButton->setFlat(TRUE); | 141 | // docButton->setFlat(TRUE); |
142 | OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 ); | 142 | OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 ); |
143 | 143 | ||
144 | OutputEdit = new QMultiLineEdit( this, "OutputEdit" ); | 144 | OutputEdit = new QMultiLineEdit( this, "OutputEdit" ); |
145 | OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 ); | 145 | OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 ); |
146 | 146 | ||
147 | proc = new OProcess(); | 147 | proc = new OProcess(); |
148 | 148 | ||
149 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)), | 149 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)), |
150 | this, SLOT( processFinished())); | 150 | this, SLOT( processFinished())); |
151 | 151 | ||
152 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), | 152 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), |
153 | this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int))); | 153 | this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int))); |
154 | 154 | ||
155 | connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), | 155 | connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), |
156 | this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int))); | 156 | this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int))); |
157 | 157 | ||
158 | // connect( , SIGNAL(received(const QByteArray&)), | 158 | // connect( , SIGNAL(received(const QByteArray&)), |
159 | // this, SLOT(commandStdin(const QByteArray&))); | 159 | // this, SLOT(commandStdin(const QByteArray&))); |
160 | 160 | ||
161 | // * proc << commands.latin1(); | 161 | // * proc << commands.latin1(); |
162 | for ( QStringList::Iterator it = cmmds.begin(); it != cmmds.end(); ++it ) { | 162 | for ( QStringList::Iterator it = cmmds.begin(); it != cmmds.end(); ++it ) { |
163 | odebug << "" << (*it).latin1() << "" << oendl; | 163 | odebug << "" << (*it).latin1() << "" << oendl; |
164 | * proc << (*it).latin1(); | 164 | * proc << (*it).latin1(); |
165 | } | 165 | } |
166 | 166 | ||
167 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) { | 167 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) { |
168 | 168 | ||
169 | OutputEdit->append(tr("Process could not start") ); | 169 | OutputEdit->append(tr("Process could not start") ); |
170 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | 170 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); |
171 | perror("Error: "); | 171 | perror("Error: "); |
172 | QString errorMsg=tr("Error\n")+(QString)strerror(errno); | 172 | QString errorMsg=tr("Error\n")+(QString)strerror(errno); |
173 | OutputEdit->append( errorMsg); | 173 | OutputEdit->append( errorMsg); |
174 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | 174 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | Output::~Output() { | 178 | Output::~Output() { |
179 | } | 179 | } |
180 | 180 | ||
181 | void Output::saveOutput() { | 181 | void Output::saveOutput() { |
182 | 182 | ||
183 | InputDialog *fileDlg; | 183 | InputDialog *fileDlg; |
184 | fileDlg = new InputDialog(this,tr("Save output to file (name only)"),TRUE, 0); | 184 | fileDlg = new InputDialog(this,tr("Save output to file (name only)"),TRUE, 0); |
185 | fileDlg->exec(); | 185 | fileDlg->exec(); |
186 | if( fileDlg->result() == 1 ) { | 186 | if( fileDlg->result() == 1 ) { |
187 | QString filename = QPEApplication::documentDir(); | 187 | QString filename = QPEApplication::documentDir(); |
188 | if(filename.right(1).find('/') == -1) | 188 | if(filename.right(1).find('/') == -1) |
189 | filename+="/"; | 189 | filename+="/"; |
190 | QString name = fileDlg->LineEdit1->text(); | 190 | QString name = fileDlg->LineEdit1->text(); |
191 | filename+="text/plain/"+name; | 191 | filename+="text/plain/"+name; |
192 | odebug << filename << oendl; | 192 | odebug << filename << oendl; |
193 | 193 | ||
194 | QFile f(filename); | 194 | QFile f(filename); |
195 | f.open( IO_WriteOnly); | 195 | if ( !f.open( IO_WriteOnly ) ) |
196 | if( f.writeBlock( OutputEdit->text(), qstrlen( OutputEdit->text()) ) != -1) { | 196 | owarn << "Could no open file" << oendl; |
197 | else if( f.writeBlock( OutputEdit->text(), qstrlen( OutputEdit->text()) ) != -1) { | ||
197 | DocLnk lnk; | 198 | DocLnk lnk; |
198 | lnk.setName(name); //sets file name | 199 | lnk.setName(name); //sets file name |
199 | lnk.setFile(filename); //sets File property | 200 | lnk.setFile(filename); //sets File property |
200 | lnk.setType("text/plain"); | 201 | lnk.setType("text/plain"); |
201 | if(!lnk.writeLink()) { | 202 | if(!lnk.writeLink()) { |
202 | odebug << "Writing doclink did not work" << oendl; | 203 | odebug << "Writing doclink did not work" << oendl; |
203 | } | 204 | } |
204 | } else | 205 | } else |
205 | owarn << "Could not write file" << oendl; | 206 | owarn << "Could not write file" << oendl; |
206 | f.close(); | 207 | f.close(); |
207 | } | 208 | } |
208 | } | 209 | } |
209 | 210 | ||
210 | void Output::commandStdout(OProcess*, char *buffer, int buflen) { | 211 | void Output::commandStdout(OProcess*, char *buffer, int buflen) { |
211 | owarn << "received stdout " << buflen << " bytes" << oendl; | 212 | owarn << "received stdout " << buflen << " bytes" << oendl; |
212 | 213 | ||
213 | // QByteArray data(buflen); | 214 | // QByteArray data(buflen); |
214 | // data.fill(*buffer, buflen); | 215 | // data.fill(*buffer, buflen); |
215 | // for (uint i = 0; i < data.count(); i++ ) { | 216 | // for (uint i = 0; i < data.count(); i++ ) { |
216 | // printf("%c", buffer[i] ); | 217 | // printf("%c", buffer[i] ); |
217 | // } | 218 | // } |
218 | // printf("\n"); | 219 | // printf("\n"); |
219 | 220 | ||
220 | QString lineStr = buffer; | 221 | QString lineStr = buffer; |
221 | lineStr=lineStr.left(lineStr.length()-1); | 222 | lineStr=lineStr.left(lineStr.length()-1); |
222 | OutputEdit->append(lineStr); | 223 | OutputEdit->append(lineStr); |
223 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | 224 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); |
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
227 | void Output::commandStdin( const QByteArray &data) { | 228 | void Output::commandStdin( const QByteArray &data) { |
228 | owarn << "received stdin " << data.size() << " bytes" << oendl; | 229 | owarn << "received stdin " << data.size() << " bytes" << oendl; |
229 | // recieved data from the io layer goes to sz | 230 | // recieved data from the io layer goes to sz |
230 | proc->writeStdin(data.data(), data.size()); | 231 | proc->writeStdin(data.data(), data.size()); |
231 | } | 232 | } |
232 | 233 | ||
233 | void Output::commandStderr(OProcess*, char *buffer, int buflen) { | 234 | void Output::commandStderr(OProcess*, char *buffer, int buflen) { |
234 | owarn << "received stderrt " << buflen << " bytes" << oendl; | 235 | owarn << "received stderrt " << buflen << " bytes" << oendl; |
235 | 236 | ||
236 | QString lineStr = buffer; | 237 | QString lineStr = buffer; |
237 | // lineStr=lineStr.left(lineStr.length()-1); | 238 | // lineStr=lineStr.left(lineStr.length()-1); |
238 | OutputEdit->append(lineStr); | 239 | OutputEdit->append(lineStr); |
239 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | 240 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); |
240 | } | 241 | } |
241 | 242 | ||
242 | void Output::processFinished() { | 243 | void Output::processFinished() { |
243 | 244 | ||
244 | delete proc; | 245 | delete proc; |
245 | OutputEdit->append( tr("\nFinished\n") ); | 246 | OutputEdit->append( tr("\nFinished\n") ); |
246 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | 247 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); |
247 | // close(); | 248 | // close(); |
248 | // disconnect( layer(), SIGNAL(received(const QByteArray&)), | 249 | // disconnect( layer(), SIGNAL(received(const QByteArray&)), |
249 | // this, SLOT(commandStdin(const QByteArray&))); | 250 | // this, SLOT(commandStdin(const QByteArray&))); |
250 | } | 251 | } |
251 | 252 | ||
252 | //============================== | 253 | //============================== |
253 | 254 | ||
254 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | 255 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) |
255 | : QDialog( parent, name, modal, fl ) | 256 | : QDialog( parent, name, modal, fl ) |
256 | { | 257 | { |
257 | if ( !name ) | 258 | if ( !name ) |
258 | setName( "InputDialog" ); | 259 | setName( "InputDialog" ); |
259 | resize( 234, 50 ); | 260 | resize( 234, 50 ); |
260 | setMaximumSize( QSize( 240, 50 ) ); | 261 | setMaximumSize( QSize( 240, 50 ) ); |
261 | setCaption( tr(name ) ); | 262 | setCaption( tr(name ) ); |
262 | 263 | ||
263 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | 264 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); |
264 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); | 265 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); |
265 | LineEdit1->setFocus(); | 266 | LineEdit1->setFocus(); |
266 | LineEdit1->setFocus(); | 267 | LineEdit1->setFocus(); |
267 | connect(LineEdit1,SIGNAL(returnPressed()),this,SLOT(returned() )); | 268 | connect(LineEdit1,SIGNAL(returnPressed()),this,SLOT(returned() )); |
268 | } | 269 | } |
269 | 270 | ||
270 | InputDialog::~InputDialog() { | 271 | InputDialog::~InputDialog() { |
271 | inputText = LineEdit1->text(); | 272 | inputText = LineEdit1->text(); |
272 | } | 273 | } |
273 | 274 | ||
274 | void InputDialog::setInputText(const QString &string) { | 275 | void InputDialog::setInputText(const QString &string) { |
275 | LineEdit1->setText( string); | 276 | LineEdit1->setText( string); |
276 | } | 277 | } |
277 | 278 | ||
278 | void InputDialog::returned() { | 279 | void InputDialog::returned() { |
279 | inputText = LineEdit1->text(); | 280 | inputText = LineEdit1->text(); |
280 | this->accept(); | 281 | this->accept(); |
281 | } | 282 | } |
diff --git a/noncore/apps/tinykate/libkate/document/katebuffer.cpp b/noncore/apps/tinykate/libkate/document/katebuffer.cpp index 4c15fd0..d89edbd 100644 --- a/noncore/apps/tinykate/libkate/document/katebuffer.cpp +++ b/noncore/apps/tinykate/libkate/document/katebuffer.cpp | |||
@@ -1,180 +1,183 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KWrite | 2 | This file is part of KWrite |
3 | Copyright (c) 2000 Waldo Bastian <bastian@kde.org> | 3 | Copyright (c) 2000 Waldo Bastian <bastian@kde.org> |
4 | Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org> | 4 | Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org> |
5 | 5 | ||
6 | $Id$ | 6 | $Id$ |
7 | 7 | ||
8 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
10 | License version 2 as published by the Free Software Foundation. | 10 | License version 2 as published by the Free Software Foundation. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | 23 | ||
24 | #include "katebuffer.h" | 24 | #include "katebuffer.h" |
25 | #include "kdebug.h" | 25 | #include "kdebug.h" |
26 | 26 | ||
27 | /* OPIE */ | 27 | /* OPIE */ |
28 | #include <opie2/odebug.h> | 28 | #include <opie2/odebug.h> |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | #include <qtextcodec.h> | 34 | #include <qtextcodec.h> |
35 | 35 | ||
36 | /* STD */ | 36 | /* STD */ |
37 | // Includes for reading file | 37 | // Includes for reading file |
38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
39 | #include <sys/stat.h> | 39 | #include <sys/stat.h> |
40 | #include <fcntl.h> | 40 | #include <fcntl.h> |
41 | #include <errno.h> | 41 | #include <errno.h> |
42 | #include <unistd.h> | 42 | #include <unistd.h> |
43 | #include <assert.h> | 43 | #include <assert.h> |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Create an empty buffer. | 46 | * Create an empty buffer. |
47 | */ | 47 | */ |
48 | KWBuffer::KWBuffer() | 48 | KWBuffer::KWBuffer() |
49 | { | 49 | { |
50 | clear(); | 50 | clear(); |
51 | } | 51 | } |
52 | 52 | ||
53 | void | 53 | void |
54 | KWBuffer::clear() | 54 | KWBuffer::clear() |
55 | { | 55 | { |
56 | m_stringListIt=0; | 56 | m_stringListIt=0; |
57 | m_stringListCurrent=0; | 57 | m_stringListCurrent=0; |
58 | m_stringList.clear(); | 58 | m_stringList.clear(); |
59 | m_lineCount=1; | 59 | m_lineCount=1; |
60 | m_stringListIt = m_stringList.append(new TextLine()); | 60 | m_stringListIt = m_stringList.append(new TextLine()); |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Insert a file at line @p line in the buffer. | 64 | * Insert a file at line @p line in the buffer. |
65 | */ | 65 | */ |
66 | void | 66 | void |
67 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) | 67 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) |
68 | { | 68 | { |
69 | if (line) { | 69 | if (line) { |
70 | odebug << "insert File only supports insertion at line 0 == file opening" << oendl; | 70 | odebug << "insert File only supports insertion at line 0 == file opening" << oendl; |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | clear(); | 73 | clear(); |
74 | QFile iofile(file); | 74 | QFile iofile(file); |
75 | iofile.open(IO_ReadOnly); | 75 | if (!iofile.open(IO_ReadOnly)) { |
76 | owarn << "failed to open file " << iofile.name() << oendl; | ||
77 | return; | ||
78 | } | ||
76 | QTextStream stream(&iofile); | 79 | QTextStream stream(&iofile); |
77 | stream.setCodec(codec); | 80 | stream.setCodec(codec); |
78 | QString qsl; | 81 | QString qsl; |
79 | int count=0; | 82 | int count=0; |
80 | for (count=0;((qsl=stream.readLine())!=QString::null); count++) | 83 | for (count=0;((qsl=stream.readLine())!=QString::null); count++) |
81 | { | 84 | { |
82 | if (count==0) | 85 | if (count==0) |
83 | { | 86 | { |
84 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); | 87 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); |
85 | } | 88 | } |
86 | else | 89 | else |
87 | { | 90 | { |
88 | TextLine::Ptr tl=new TextLine(); | 91 | TextLine::Ptr tl=new TextLine(); |
89 | tl ->append(qsl.unicode(),qsl.length()); | 92 | tl ->append(qsl.unicode(),qsl.length()); |
90 | m_stringListIt=m_stringList.append(tl); | 93 | m_stringListIt=m_stringList.append(tl); |
91 | } | 94 | } |
92 | } | 95 | } |
93 | if (count!=0) | 96 | if (count!=0) |
94 | { | 97 | { |
95 | m_stringListCurrent=count-1; | 98 | m_stringListCurrent=count-1; |
96 | m_lineCount=count; | 99 | m_lineCount=count; |
97 | } | 100 | } |
98 | } | 101 | } |
99 | 102 | ||
100 | void | 103 | void |
101 | KWBuffer::loadFilePart() | 104 | KWBuffer::loadFilePart() |
102 | { | 105 | { |
103 | } | 106 | } |
104 | 107 | ||
105 | 108 | ||
106 | void | 109 | void |
107 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) | 110 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) |
108 | { | 111 | { |
109 | } | 112 | } |
110 | 113 | ||
111 | void | 114 | void |
112 | KWBuffer::slotLoadFile() | 115 | KWBuffer::slotLoadFile() |
113 | { | 116 | { |
114 | loadFilePart(); | 117 | loadFilePart(); |
115 | // emit linesChanged(m_totalLines); | 118 | // emit linesChanged(m_totalLines); |
116 | emit linesChanged(20); | 119 | emit linesChanged(20); |
117 | } | 120 | } |
118 | 121 | ||
119 | /** | 122 | /** |
120 | * Return the total number of lines in the buffer. | 123 | * Return the total number of lines in the buffer. |
121 | */ | 124 | */ |
122 | int | 125 | int |
123 | KWBuffer::count() | 126 | KWBuffer::count() |
124 | { | 127 | { |
125 | odebug << "m_stringList.count " << m_stringList.count() << "" << oendl; | 128 | odebug << "m_stringList.count " << m_stringList.count() << "" << oendl; |
126 | return m_lineCount; | 129 | return m_lineCount; |
127 | // return m_stringList.count(); | 130 | // return m_stringList.count(); |
128 | // return m_totalLines; | 131 | // return m_totalLines; |
129 | } | 132 | } |
130 | 133 | ||
131 | 134 | ||
132 | void KWBuffer::seek(int i) | 135 | void KWBuffer::seek(int i) |
133 | { | 136 | { |
134 | if (m_stringListCurrent == i) | 137 | if (m_stringListCurrent == i) |
135 | return; | 138 | return; |
136 | while(m_stringListCurrent < i) | 139 | while(m_stringListCurrent < i) |
137 | { | 140 | { |
138 | ++m_stringListCurrent; | 141 | ++m_stringListCurrent; |
139 | ++m_stringListIt; | 142 | ++m_stringListIt; |
140 | } | 143 | } |
141 | while(m_stringListCurrent > i) | 144 | while(m_stringListCurrent > i) |
142 | { | 145 | { |
143 | --m_stringListCurrent; | 146 | --m_stringListCurrent; |
144 | --m_stringListIt; | 147 | --m_stringListIt; |
145 | } | 148 | } |
146 | } | 149 | } |
147 | 150 | ||
148 | 151 | ||
149 | TextLine::Ptr | 152 | TextLine::Ptr |
150 | KWBuffer::line(int i) | 153 | KWBuffer::line(int i) |
151 | { | 154 | { |
152 | if (i>=m_stringList.count()) return 0; | 155 | if (i>=m_stringList.count()) return 0; |
153 | seek(i); | 156 | seek(i); |
154 | return *m_stringListIt; | 157 | return *m_stringListIt; |
155 | } | 158 | } |
156 | 159 | ||
157 | void | 160 | void |
158 | KWBuffer::insertLine(int i, TextLine::Ptr line) | 161 | KWBuffer::insertLine(int i, TextLine::Ptr line) |
159 | { | 162 | { |
160 | seek(i); | 163 | seek(i); |
161 | m_stringListIt = m_stringList.insert(m_stringListIt, line); | 164 | m_stringListIt = m_stringList.insert(m_stringListIt, line); |
162 | m_stringListCurrent = i; | 165 | m_stringListCurrent = i; |
163 | m_lineCount++; | 166 | m_lineCount++; |
164 | } | 167 | } |
165 | 168 | ||
166 | 169 | ||
167 | void | 170 | void |
168 | KWBuffer::removeLine(int i) | 171 | KWBuffer::removeLine(int i) |
169 | { | 172 | { |
170 | seek(i); | 173 | seek(i); |
171 | m_stringListIt = m_stringList.remove(m_stringListIt); | 174 | m_stringListIt = m_stringList.remove(m_stringListIt); |
172 | m_stringListCurrent = i; | 175 | m_stringListCurrent = i; |
173 | m_lineCount--; | 176 | m_lineCount--; |
174 | } | 177 | } |
175 | 178 | ||
176 | void | 179 | void |
177 | KWBuffer::changeLine(int i) | 180 | KWBuffer::changeLine(int i) |
178 | { | 181 | { |
179 | } | 182 | } |
180 | 183 | ||
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 3654639..75a96a6 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -1,489 +1,492 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "userdialog.h" | 10 | #include "userdialog.h" |
11 | #include "passwd.h" | 11 | #include "passwd.h" |
12 | 12 | ||
13 | /* OPIE */ | 13 | /* OPIE */ |
14 | #include <opie2/odebug.h> | 14 | #include <opie2/odebug.h> |
15 | #include <opie2/odevice.h> | 15 | #include <opie2/odevice.h> |
16 | #include <opie2/oresource.h> | 16 | #include <opie2/oresource.h> |
17 | #include <qpe/qpeapplication.h> | 17 | #include <qpe/qpeapplication.h> |
18 | using namespace Opie::Core; | 18 | using namespace Opie::Core; |
19 | using namespace Opie::Ui; | 19 | using namespace Opie::Ui; |
20 | 20 | ||
21 | /* QT */ | 21 | /* QT */ |
22 | #include <qlayout.h> | 22 | #include <qlayout.h> |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qmessagebox.h> | 24 | #include <qmessagebox.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | 26 | ||
27 | /* STD */ | 27 | /* STD */ |
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/wait.h> | 29 | #include <sys/wait.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | #include <signal.h> | 31 | #include <signal.h> |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. | 34 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. |
35 | * | 35 | * |
36 | */ | 36 | */ |
37 | UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) | 37 | UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) |
38 | { | 38 | { |
39 | vm=viewmode; | 39 | vm=viewmode; |
40 | QVBoxLayout *layout = new QVBoxLayout(this); | 40 | QVBoxLayout *layout = new QVBoxLayout(this); |
41 | myTabWidget=new QTabWidget(this,"User Tab Widget"); | 41 | myTabWidget=new QTabWidget(this,"User Tab Widget"); |
42 | layout->addWidget(myTabWidget); | 42 | layout->addWidget(myTabWidget); |
43 | setupTab1(); | 43 | setupTab1(); |
44 | setupTab2(); | 44 | setupTab2(); |
45 | 45 | ||
46 | accounts->groupStringList.sort(); | 46 | accounts->groupStringList.sort(); |
47 | // And also fill the listview & the combobox with all available groups. | 47 | // And also fill the listview & the combobox with all available groups. |
48 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) | 48 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) |
49 | { | 49 | { |
50 | accounts->splitGroupEntry(*it); | 50 | accounts->splitGroupEntry(*it); |
51 | if(accounts->gr_name.find(QRegExp("^#"),0)) | 51 | if(accounts->gr_name.find(QRegExp("^#"),0)) |
52 | { // Skip commented lines. | 52 | { // Skip commented lines. |
53 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); | 53 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); |
54 | groupComboBox->insertItem(accounts->gr_name); | 54 | groupComboBox->insertItem(accounts->gr_name); |
55 | } | 55 | } |
56 | } | 56 | } |
57 | QPEApplication::showDialog( this ); | 57 | QPEApplication::showDialog( this ); |
58 | } | 58 | } |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Empty destructor. | 61 | * Empty destructor. |
62 | * | 62 | * |
63 | */ | 63 | */ |
64 | UserDialog::~UserDialog() | 64 | UserDialog::~UserDialog() |
65 | {} | 65 | {} |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Creates the first tab, all userinfo is here. | 68 | * Creates the first tab, all userinfo is here. |
69 | * | 69 | * |
70 | */ | 70 | */ |
71 | void UserDialog::setupTab1() | 71 | void UserDialog::setupTab1() |
72 | { | 72 | { |
73 | QPixmap mypixmap; | 73 | QPixmap mypixmap; |
74 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); | 74 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); |
75 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 75 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
76 | layout->setMargin(5); | 76 | layout->setMargin(5); |
77 | 77 | ||
78 | // Picture | 78 | // Picture |
79 | picturePushButton = new QPushButton(tabpage,"Label"); | 79 | picturePushButton = new QPushButton(tabpage,"Label"); |
80 | picturePushButton->setMinimumSize(48,48); | 80 | picturePushButton->setMinimumSize(48,48); |
81 | picturePushButton->setMaximumSize(48,48); | 81 | picturePushButton->setMaximumSize(48,48); |
82 | picturePushButton->setPixmap(Opie::Core::OResource::loadPixmap("usermanager/usericon")); // Load default usericon. | 82 | picturePushButton->setPixmap(Opie::Core::OResource::loadPixmap("usermanager/usericon")); // Load default usericon. |
83 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture())); // Clicking the picture should invoke pictureselector. | 83 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture())); // Clicking the picture should invoke pictureselector. |
84 | 84 | ||
85 | // Login | 85 | // Login |
86 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 86 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
87 | loginLabel->setText("Login: "); | 87 | loginLabel->setText("Login: "); |
88 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 88 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
89 | 89 | ||
90 | // UID | 90 | // UID |
91 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); | 91 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); |
92 | uidLabel->setText("UserID: "); | 92 | uidLabel->setText("UserID: "); |
93 | uidLineEdit=new QLineEdit(tabpage,"uid: "); | 93 | uidLineEdit=new QLineEdit(tabpage,"uid: "); |
94 | uidLineEdit->setEnabled(false); | 94 | uidLineEdit->setEnabled(false); |
95 | 95 | ||
96 | // Username (gecos) | 96 | // Username (gecos) |
97 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); | 97 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); |
98 | gecosLabel->setText("Username: "); | 98 | gecosLabel->setText("Username: "); |
99 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); | 99 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); |
100 | 100 | ||
101 | // Password | 101 | // Password |
102 | QLabel *passwordLabel=new QLabel(tabpage,"password"); | 102 | QLabel *passwordLabel=new QLabel(tabpage,"password"); |
103 | passwordLabel->setText("Password: "); | 103 | passwordLabel->setText("Password: "); |
104 | passwordLineEdit=new QLineEdit(tabpage,"password"); | 104 | passwordLineEdit=new QLineEdit(tabpage,"password"); |
105 | passwordLineEdit->setEchoMode(QLineEdit::Password); | 105 | passwordLineEdit->setEchoMode(QLineEdit::Password); |
106 | 106 | ||
107 | // Shell | 107 | // Shell |
108 | QLabel *shellLabel=new QLabel(tabpage,"shell"); | 108 | QLabel *shellLabel=new QLabel(tabpage,"shell"); |
109 | shellLabel->setText("Shell: "); | 109 | shellLabel->setText("Shell: "); |
110 | shellComboBox=new QComboBox(tabpage,"shell"); | 110 | shellComboBox=new QComboBox(tabpage,"shell"); |
111 | shellComboBox->setEditable(true); | 111 | shellComboBox->setEditable(true); |
112 | shellComboBox->insertItem("/bin/sh"); | 112 | shellComboBox->insertItem("/bin/sh"); |
113 | shellComboBox->insertItem("/bin/ash"); | 113 | shellComboBox->insertItem("/bin/ash"); |
114 | shellComboBox->insertItem("/bin/false"); | 114 | shellComboBox->insertItem("/bin/false"); |
115 | 115 | ||
116 | // Primary Group | 116 | // Primary Group |
117 | QLabel *groupLabel=new QLabel(tabpage,"group"); | 117 | QLabel *groupLabel=new QLabel(tabpage,"group"); |
118 | groupLabel->setText("Primary group: "); | 118 | groupLabel->setText("Primary group: "); |
119 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); | 119 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); |
120 | 120 | ||
121 | if(vm==VIEWMODE_NEW) | 121 | if(vm==VIEWMODE_NEW) |
122 | { | 122 | { |
123 | // Copy /etc/skel | 123 | // Copy /etc/skel |
124 | skelLabel=new QLabel(tabpage,"skel"); | 124 | skelLabel=new QLabel(tabpage,"skel"); |
125 | skelLabel->setText("Copy /etc/skel: "); | 125 | skelLabel->setText("Copy /etc/skel: "); |
126 | skelCheckBox=new QCheckBox(tabpage); | 126 | skelCheckBox=new QCheckBox(tabpage); |
127 | skelCheckBox->setChecked(true); | 127 | skelCheckBox->setChecked(true); |
128 | } | 128 | } |
129 | 129 | ||
130 | // Widget layout | 130 | // Widget layout |
131 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 131 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
132 | layout->addWidget(picturePushButton); | 132 | layout->addWidget(picturePushButton); |
133 | layout->addSpacing(5); | 133 | layout->addSpacing(5); |
134 | layout->addLayout(hlayout); | 134 | layout->addLayout(hlayout); |
135 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); | 135 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); |
136 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); | 136 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); |
137 | // First column, labels | 137 | // First column, labels |
138 | vlayout1->addWidget(loginLabel); | 138 | vlayout1->addWidget(loginLabel); |
139 | vlayout1->addSpacing(5); | 139 | vlayout1->addSpacing(5); |
140 | vlayout1->addWidget(uidLabel); | 140 | vlayout1->addWidget(uidLabel); |
141 | vlayout1->addSpacing(5); | 141 | vlayout1->addSpacing(5); |
142 | vlayout1->addWidget(gecosLabel); | 142 | vlayout1->addWidget(gecosLabel); |
143 | vlayout1->addSpacing(5); | 143 | vlayout1->addSpacing(5); |
144 | vlayout1->addWidget(passwordLabel); | 144 | vlayout1->addWidget(passwordLabel); |
145 | vlayout1->addSpacing(5); | 145 | vlayout1->addSpacing(5); |
146 | vlayout1->addWidget(shellLabel); | 146 | vlayout1->addWidget(shellLabel); |
147 | vlayout1->addSpacing(5); | 147 | vlayout1->addSpacing(5); |
148 | vlayout1->addWidget(groupLabel); | 148 | vlayout1->addWidget(groupLabel); |
149 | if(vm==VIEWMODE_NEW) | 149 | if(vm==VIEWMODE_NEW) |
150 | { | 150 | { |
151 | vlayout1->addSpacing(5); | 151 | vlayout1->addSpacing(5); |
152 | vlayout1->addWidget(skelLabel); | 152 | vlayout1->addWidget(skelLabel); |
153 | } | 153 | } |
154 | // Second column, data | 154 | // Second column, data |
155 | vlayout2->addWidget(loginLineEdit); | 155 | vlayout2->addWidget(loginLineEdit); |
156 | vlayout2->addSpacing(5); | 156 | vlayout2->addSpacing(5); |
157 | vlayout2->addWidget(uidLineEdit); | 157 | vlayout2->addWidget(uidLineEdit); |
158 | vlayout2->addSpacing(5); | 158 | vlayout2->addSpacing(5); |
159 | vlayout2->addWidget(gecosLineEdit); | 159 | vlayout2->addWidget(gecosLineEdit); |
160 | vlayout2->addSpacing(5); | 160 | vlayout2->addSpacing(5); |
161 | vlayout2->addWidget(passwordLineEdit); | 161 | vlayout2->addWidget(passwordLineEdit); |
162 | vlayout2->addSpacing(5); | 162 | vlayout2->addSpacing(5); |
163 | vlayout2->addWidget(shellComboBox); | 163 | vlayout2->addWidget(shellComboBox); |
164 | vlayout2->addSpacing(5); | 164 | vlayout2->addSpacing(5); |
165 | vlayout2->addWidget(groupComboBox); | 165 | vlayout2->addWidget(groupComboBox); |
166 | if(vm==VIEWMODE_NEW) | 166 | if(vm==VIEWMODE_NEW) |
167 | { | 167 | { |
168 | vlayout2->addSpacing(5); | 168 | vlayout2->addSpacing(5); |
169 | vlayout2->addWidget(skelCheckBox); | 169 | vlayout2->addWidget(skelCheckBox); |
170 | } | 170 | } |
171 | hlayout->addLayout(vlayout1); | 171 | hlayout->addLayout(vlayout1); |
172 | hlayout->addLayout(vlayout2); | 172 | hlayout->addLayout(vlayout2); |
173 | 173 | ||
174 | myTabWidget->addTab(tabpage,"User Info"); | 174 | myTabWidget->addTab(tabpage,"User Info"); |
175 | } | 175 | } |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Creates the second tab containing additional groups for the user. | 178 | * Creates the second tab containing additional groups for the user. |
179 | * | 179 | * |
180 | */ | 180 | */ |
181 | void UserDialog::setupTab2() | 181 | void UserDialog::setupTab2() |
182 | { | 182 | { |
183 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 183 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
184 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 184 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
185 | layout->setMargin(5); | 185 | layout->setMargin(5); |
186 | 186 | ||
187 | // Additional groups | 187 | // Additional groups |
188 | groupsListView=new QListView(tabpage,"groups"); | 188 | groupsListView=new QListView(tabpage,"groups"); |
189 | groupsListView->addColumn("Additional groups"); | 189 | groupsListView->addColumn("Additional groups"); |
190 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 190 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
191 | groupsListView->setMultiSelection(false); | 191 | groupsListView->setMultiSelection(false); |
192 | groupsListView->setAllColumnsShowFocus(false); | 192 | groupsListView->setAllColumnsShowFocus(false); |
193 | 193 | ||
194 | layout->addSpacing(5); | 194 | layout->addSpacing(5); |
195 | // Grouplist | 195 | // Grouplist |
196 | layout->addWidget(groupsListView); | 196 | layout->addWidget(groupsListView); |
197 | 197 | ||
198 | myTabWidget->addTab(tabpage,"User Groups"); | 198 | myTabWidget->addTab(tabpage,"User Groups"); |
199 | } | 199 | } |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Static function that creates the userinfo dialog. | 202 | * Static function that creates the userinfo dialog. |
203 | * The user will be prompted to add a user. | 203 | * The user will be prompted to add a user. |
204 | * | 204 | * |
205 | * @param uid This is a suggested available UID. | 205 | * @param uid This is a suggested available UID. |
206 | * @param gid This is a suggested available GID. | 206 | * @param gid This is a suggested available GID. |
207 | * | 207 | * |
208 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. | 208 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. |
209 | * | 209 | * |
210 | */ | 210 | */ |
211 | bool UserDialog::addUser(int uid, int gid) | 211 | bool UserDialog::addUser(int uid, int gid) |
212 | { | 212 | { |
213 | QCheckListItem *temp; | 213 | QCheckListItem *temp; |
214 | QFile ozTest; | 214 | QFile ozTest; |
215 | int oz=false; | 215 | int oz=false; |
216 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; | 216 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; |
217 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. | 217 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. |
218 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); | 218 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); |
219 | adduserDialog->setCaption(tr("Add User")); | 219 | adduserDialog->setCaption(tr("Add User")); |
220 | adduserDialog->userID=uid; // Set next available UID as default uid. | 220 | adduserDialog->userID=uid; // Set next available UID as default uid. |
221 | adduserDialog->groupID=gid; // Set next available GID as default gid. | 221 | adduserDialog->groupID=gid; // Set next available GID as default gid. |
222 | // Insert default group into groupComboBox | 222 | // Insert default group into groupComboBox |
223 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 223 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
224 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 224 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
225 | // If we're running on OZ, add new users to some default groups. | 225 | // If we're running on OZ, add new users to some default groups. |
226 | if(oz) | 226 | if(oz) |
227 | { | 227 | { |
228 | QListViewItemIterator iter( adduserDialog->groupsListView ); | 228 | QListViewItemIterator iter( adduserDialog->groupsListView ); |
229 | for ( ; iter.current(); ++iter ) | 229 | for ( ; iter.current(); ++iter ) |
230 | { | 230 | { |
231 | temp=(QCheckListItem*)iter.current(); | 231 | temp=(QCheckListItem*)iter.current(); |
232 | if (temp->text()=="video") temp->setOn(true); | 232 | if (temp->text()=="video") temp->setOn(true); |
233 | if (temp->text()=="audio") temp->setOn(true); | 233 | if (temp->text()=="audio") temp->setOn(true); |
234 | if (temp->text()=="time") temp->setOn(true); | 234 | if (temp->text()=="time") temp->setOn(true); |
235 | if (temp->text()=="power") temp->setOn(true); | 235 | if (temp->text()=="power") temp->setOn(true); |
236 | if (temp->text()=="input") temp->setOn(true); | 236 | if (temp->text()=="input") temp->setOn(true); |
237 | if (temp->text()=="sharp") temp->setOn(true); | 237 | if (temp->text()=="sharp") temp->setOn(true); |
238 | if (temp->text()=="tty") temp->setOn(true); | 238 | if (temp->text()=="tty") temp->setOn(true); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | // Show the dialog! | 241 | // Show the dialog! |
242 | if(!(adduserDialog->exec())) return false; | 242 | if(!(adduserDialog->exec())) return false; |
243 | if((adduserDialog->groupComboBox->currentItem()!=0)) | 243 | if((adduserDialog->groupComboBox->currentItem()!=0)) |
244 | { | 244 | { |
245 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 245 | // making the call findGroup() puts the group info in the accounts gr_gid |
246 | adduserDialog->groupID=accounts->gr_gid; | 246 | if (accounts->findGroup(adduserDialog->groupComboBox->currentText())) |
247 | owarn << QString::number(accounts->gr_gid) << oendl; | 247 | { |
248 | adduserDialog->groupID=accounts->gr_gid; | ||
249 | owarn << QString::number(accounts->gr_gid) << oendl; | ||
250 | } | ||
248 | } | 251 | } |
249 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 252 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
250 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 253 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
251 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) | 254 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) |
252 | { | 255 | { |
253 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 256 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
254 | return false; | 257 | return false; |
255 | } | 258 | } |
256 | 259 | ||
257 | // Add User to additional groups. | 260 | // Add User to additional groups. |
258 | QListViewItemIterator it( adduserDialog->groupsListView ); | 261 | QListViewItemIterator it( adduserDialog->groupsListView ); |
259 | for ( ; it.current(); ++it ) | 262 | for ( ; it.current(); ++it ) |
260 | { | 263 | { |
261 | temp=(QCheckListItem*)it.current(); | 264 | temp=(QCheckListItem*)it.current(); |
262 | if (temp->isOn() ) | 265 | if (temp->isOn() ) |
263 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 266 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
264 | } | 267 | } |
265 | // Copy image to pics/users/ | 268 | // Copy image to pics/users/ |
266 | if(!(adduserDialog->userImage.isNull())) | 269 | if(!(adduserDialog->userImage.isNull())) |
267 | { | 270 | { |
268 | QDir d; | 271 | QDir d; |
269 | if(!(d.exists(QPEApplication::qpeDir() + "pics/users"))) | 272 | if(!(d.exists(QPEApplication::qpeDir() + "pics/users"))) |
270 | { | 273 | { |
271 | d.mkdir(QPEApplication::qpeDir() + "pics/users"); | 274 | d.mkdir(QPEApplication::qpeDir() + "pics/users"); |
272 | } | 275 | } |
273 | QString filename= QPEApplication::qpeDir()+"pics/users/"+accounts->pw_name+".png"; | 276 | QString filename= QPEApplication::qpeDir()+"pics/users/"+accounts->pw_name+".png"; |
274 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 277 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
275 | adduserDialog->userImage.save(filename,"PNG"); | 278 | adduserDialog->userImage.save(filename,"PNG"); |
276 | } | 279 | } |
277 | 280 | ||
278 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? | 281 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? |
279 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 282 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
280 | if(adduserDialog->skelCheckBox->isChecked()) | 283 | if(adduserDialog->skelCheckBox->isChecked()) |
281 | { | 284 | { |
282 | QString command_cp; | 285 | QString command_cp; |
283 | QString command_chown; | 286 | QString command_chown; |
284 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); | 287 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); |
285 | system(command_cp); | 288 | system(command_cp); |
286 | 289 | ||
287 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1()); // Bug in busybox, ".*" includes parent directory, does this work as a workaround? | 290 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1()); // Bug in busybox, ".*" includes parent directory, does this work as a workaround? |
288 | system(command_cp); | 291 | system(command_cp); |
289 | 292 | ||
290 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); | 293 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); |
291 | system(command_chown); | 294 | system(command_chown); |
292 | } | 295 | } |
293 | 296 | ||
294 | return true; | 297 | return true; |
295 | } | 298 | } |
296 | 299 | ||
297 | /** | 300 | /** |
298 | * Deletes the user account. | 301 | * Deletes the user account. |
299 | * | 302 | * |
300 | * @param username User to be deleted. | 303 | * @param username User to be deleted. |
301 | * | 304 | * |
302 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 305 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
303 | * | 306 | * |
304 | */ | 307 | */ |
305 | bool UserDialog::delUser(const char *username) | 308 | bool UserDialog::delUser(const char *username) |
306 | { | 309 | { |
307 | if((accounts->findUser(username))) | 310 | if((accounts->findUser(username))) |
308 | { // Does that user exist? | 311 | { // Does that user exist? |
309 | if(!(accounts->delUser(username))) | 312 | if(!(accounts->delUser(username))) |
310 | { // Delete the user. | 313 | { // Delete the user. |
311 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 314 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
312 | } | 315 | } |
313 | } | 316 | } |
314 | else | 317 | else |
315 | { | 318 | { |
316 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 319 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
317 | return false; | 320 | return false; |
318 | } | 321 | } |
319 | return true; | 322 | return true; |
320 | } | 323 | } |
321 | 324 | ||
322 | /** | 325 | /** |
323 | * This displays a confirmation dialog wether a user should be deleted or not. | 326 | * This displays a confirmation dialog wether a user should be deleted or not. |
324 | * (And also deletes the account) | 327 | * (And also deletes the account) |
325 | * | 328 | * |
326 | * @param username User to be deleted. | 329 | * @param username User to be deleted. |
327 | * | 330 | * |
328 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 331 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
329 | * | 332 | * |
330 | */ | 333 | */ |
331 | bool UserDialog::editUser(const char *username) | 334 | bool UserDialog::editUser(const char *username) |
332 | { | 335 | { |
333 | int invalid_group=0; | 336 | int invalid_group=0; |
334 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. | 337 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. |
335 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog | 338 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog |
336 | edituserDialog->setCaption(tr("Edit User")); | 339 | edituserDialog->setCaption(tr("Edit User")); |
337 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. | 340 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. |
338 | if(!(accounts->findGroup(accounts->pw_gid))) | 341 | if(!(accounts->findGroup(accounts->pw_gid))) |
339 | { // Locate the user's primary group, and fill group variables in 'accounts' object. | 342 | { // Locate the user's primary group, and fill group variables in 'accounts' object. |
340 | invalid_group=1; | 343 | invalid_group=1; |
341 | } | 344 | } |
342 | // Fill widgets with userinfo. | 345 | // Fill widgets with userinfo. |
343 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 346 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
344 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 347 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
345 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 348 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
346 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. | 349 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. |
347 | edituserDialog->passwordLineEdit->setText("........"); | 350 | edituserDialog->passwordLineEdit->setText("........"); |
348 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 351 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
349 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") | 352 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") |
350 | { | 353 | { |
351 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 354 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
352 | edituserDialog->shellComboBox->setCurrentItem(0); | 355 | edituserDialog->shellComboBox->setCurrentItem(0); |
353 | } | 356 | } |
354 | // Select the primary group for this user. | 357 | // Select the primary group for this user. |
355 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) | 358 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) |
356 | { | 359 | { |
357 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) | 360 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) |
358 | { | 361 | { |
359 | edituserDialog->groupComboBox->setCurrentItem(i); | 362 | edituserDialog->groupComboBox->setCurrentItem(i); |
360 | break; | 363 | break; |
361 | } | 364 | } |
362 | } | 365 | } |
363 | if(invalid_group) | 366 | if(invalid_group) |
364 | { | 367 | { |
365 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); | 368 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); |
366 | edituserDialog->groupComboBox->setCurrentItem(0); | 369 | edituserDialog->groupComboBox->setCurrentItem(0); |
367 | } | 370 | } |
368 | 371 | ||
369 | // Select the groups in the listview, to which the user belongs. | 372 | // Select the groups in the listview, to which the user belongs. |
370 | QCheckListItem *temp; | 373 | QCheckListItem *temp; |
371 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. | 374 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. |
372 | QRegExp userRegExp(QString("[:,]%1$").arg(username)); // The end of line variant. | 375 | QRegExp userRegExp(QString("[:,]%1$").arg(username)); // The end of line variant. |
373 | QStringList tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. | 376 | QStringList tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. |
374 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 377 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
375 | { // Iterate over all of them. | 378 | { // Iterate over all of them. |
376 | owarn << *it << oendl; | 379 | owarn << *it << oendl; |
377 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. | 380 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. |
378 | for ( ; lvit.current(); ++lvit ) | 381 | for ( ; lvit.current(); ++lvit ) |
379 | { | 382 | { |
380 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | 383 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) |
381 | { | 384 | { |
382 | temp=(QCheckListItem*)lvit.current(); | 385 | temp=(QCheckListItem*)lvit.current(); |
383 | temp->setOn(true); // If we find a line with that groupname, select it.; | 386 | temp->setOn(true); // If we find a line with that groupname, select it.; |
384 | } | 387 | } |
385 | } | 388 | } |
386 | } | 389 | } |
387 | userRegExp=QRegExp(QString("[:,]%1,").arg(username)); // And the other one. (not end of line.) | 390 | userRegExp=QRegExp(QString("[:,]%1,").arg(username)); // And the other one. (not end of line.) |
388 | tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. | 391 | tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. |
389 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 392 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
390 | { // Iterate over all of them. | 393 | { // Iterate over all of them. |
391 | owarn << *it << oendl; | 394 | owarn << *it << oendl; |
392 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. | 395 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. |
393 | for ( ; lvit.current(); ++lvit ) | 396 | for ( ; lvit.current(); ++lvit ) |
394 | { | 397 | { |
395 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | 398 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) |
396 | { | 399 | { |
397 | temp=(QCheckListItem*)lvit.current(); | 400 | temp=(QCheckListItem*)lvit.current(); |
398 | temp->setOn(true); // If we find a line with that groupname, select it.; | 401 | temp->setOn(true); // If we find a line with that groupname, select it.; |
399 | } | 402 | } |
400 | } | 403 | } |
401 | } | 404 | } |
402 | 405 | ||
403 | if(!(edituserDialog->exec())) return false; // SHOW THE DIALOG! | 406 | if(!(edituserDialog->exec())) return false; // SHOW THE DIALOG! |
404 | 407 | ||
405 | accounts->findUser(username); // Fill user variables in 'acccounts' object. | 408 | accounts->findUser(username); // Fill user variables in 'acccounts' object. |
406 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 409 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
407 | // Has the password been changed ? Make a new "crypt":ed password. | 410 | // Has the password been changed ? Make a new "crypt":ed password. |
408 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 411 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
409 | 412 | ||
410 | // Set all variables in accounts object, that will be used when calling 'updateUser()' | 413 | // Set all variables in accounts object, that will be used when calling 'updateUser()' |
411 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); | 414 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); |
412 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) | 415 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) |
413 | { // Fill all group variables in 'accounts' object. | 416 | { // Fill all group variables in 'accounts' object. |
414 | accounts->pw_gid=accounts->gr_gid; // Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. | 417 | accounts->pw_gid=accounts->gr_gid; // Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. |
415 | } | 418 | } |
416 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); | 419 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); |
417 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); | 420 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); |
418 | // Update userinfo, using the information stored in the user variables stored in the accounts object. | 421 | // Update userinfo, using the information stored in the user variables stored in the accounts object. |
419 | accounts->updateUser(username); | 422 | accounts->updateUser(username); |
420 | 423 | ||
421 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 424 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) |
422 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 425 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
423 | { | 426 | { |
424 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 427 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
425 | } | 428 | } |
426 | 429 | ||
427 | // Add User to additional groups that he/she is a member of. | 430 | // Add User to additional groups that he/she is a member of. |
428 | QListViewItemIterator it( edituserDialog->groupsListView ); | 431 | QListViewItemIterator it( edituserDialog->groupsListView ); |
429 | for ( ; it.current(); ++it ) | 432 | for ( ; it.current(); ++it ) |
430 | { | 433 | { |
431 | temp=(QCheckListItem*)it.current(); | 434 | temp=(QCheckListItem*)it.current(); |
432 | if ( temp->isOn() ) | 435 | if ( temp->isOn() ) |
433 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); | 436 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); |
434 | } | 437 | } |
435 | 438 | ||
436 | // Copy image to pics/users/ | 439 | // Copy image to pics/users/ |
437 | if(!(edituserDialog->userImage.isNull())) | 440 | if(!(edituserDialog->userImage.isNull())) |
438 | { | 441 | { |
439 | QDir d; | 442 | QDir d; |
440 | if(!(d.exists(QPEApplication::qpeDir()+"pics/users"))) | 443 | if(!(d.exists(QPEApplication::qpeDir()+"pics/users"))) |
441 | { | 444 | { |
442 | d.mkdir(QPEApplication::qpeDir()+"pics/users"); | 445 | d.mkdir(QPEApplication::qpeDir()+"pics/users"); |
443 | } | 446 | } |
444 | QString filename=QPEApplication::qpeDir()+"pics/users/"+accounts->pw_name+".png"; | 447 | QString filename=QPEApplication::qpeDir()+"pics/users/"+accounts->pw_name+".png"; |
445 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | 448 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); |
446 | edituserDialog->userImage.save(filename,"PNG"); | 449 | edituserDialog->userImage.save(filename,"PNG"); |
447 | } | 450 | } |
448 | return true; | 451 | return true; |
449 | } | 452 | } |
450 | 453 | ||
451 | /** | 454 | /** |
452 | * "OK" has been clicked. Verify some information before closing the dialog. | 455 | * "OK" has been clicked. Verify some information before closing the dialog. |
453 | * | 456 | * |
454 | */ | 457 | */ |
455 | void UserDialog::accept() | 458 | void UserDialog::accept() |
456 | { | 459 | { |
457 | // Add checking... valid username? username taken? | 460 | // Add checking... valid username? username taken? |
458 | if(loginLineEdit->text().isEmpty()) | 461 | if(loginLineEdit->text().isEmpty()) |
459 | { | 462 | { |
460 | QMessageBox::information(0,"Empty Login","Please enter a login."); | 463 | QMessageBox::information(0,"Empty Login","Please enter a login."); |
461 | return; | 464 | return; |
462 | } | 465 | } |
463 | QDialog::accept(); | 466 | QDialog::accept(); |
464 | } | 467 | } |
465 | 468 | ||
466 | /** | 469 | /** |
467 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. | 470 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. |
468 | * | 471 | * |
469 | */ | 472 | */ |
470 | void UserDialog::clickedPicture() | 473 | void UserDialog::clickedPicture() |
471 | { | 474 | { |
472 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); | 475 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); |
473 | if(!(filename.isEmpty())) | 476 | if(!(filename.isEmpty())) |
474 | { | 477 | { |
475 | userImage.reset(); | 478 | userImage.reset(); |
476 | if(!(userImage.load(filename))) | 479 | if(!(userImage.load(filename))) |
477 | { | 480 | { |
478 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); | 481 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); |
479 | } | 482 | } |
480 | else | 483 | else |
481 | { | 484 | { |
482 | // userImage=userImage.smoothScale(48,48); | 485 | // userImage=userImage.smoothScale(48,48); |
483 | QPixmap *picture; | 486 | QPixmap *picture; |
484 | picture=(QPixmap *)picturePushButton->pixmap(); | 487 | picture=(QPixmap *)picturePushButton->pixmap(); |
485 | picture->convertFromImage(userImage,0); | 488 | picture->convertFromImage(userImage,0); |
486 | picturePushButton->update(); | 489 | picturePushButton->update(); |
487 | } | 490 | } |
488 | } | 491 | } |
489 | } | 492 | } |