author | zecke <zecke> | 2003-08-25 14:46:43 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-25 14:46:43 (UTC) |
commit | 292b097e7db25dd231381c5b09307a1fbe81a492 (patch) (unidiff) | |
tree | b103c6c5e15e784dc07af55539672a72559da821 /library/global.cpp | |
parent | 5f292b6e4fc0f4ee8e4bced9a916f6bdce864b6b (diff) | |
download | opie-292b097e7db25dd231381c5b09307a1fbe81a492.zip opie-292b097e7db25dd231381c5b09307a1fbe81a492.tar.gz opie-292b097e7db25dd231381c5b09307a1fbe81a492.tar.bz2 |
-instead of defining for an board we define now what this
boards need
QPE_NEED_CALIBRATE
-launcher is the only one executin application
-allow processing of QCOPfiles after start ( qpeapplication )
-qcopenvelope no longer calls Global::execute
-rw-r--r-- | library/global.cpp | 59 |
1 files changed, 7 insertions, 52 deletions
diff --git a/library/global.cpp b/library/global.cpp index 189b830..5c89430 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -295,563 +295,518 @@ const QDawg& Global::dawg(const QString& name) | |||
295 | createDocDir(); | 295 | createDocDir(); |
296 | if ( !named_dawg ) | 296 | if ( !named_dawg ) |
297 | named_dawg = new QDict<QDawg>; | 297 | named_dawg = new QDict<QDawg>; |
298 | QDawg* r = named_dawg->find(name); | 298 | QDawg* r = named_dawg->find(name); |
299 | if ( !r ) { | 299 | if ( !r ) { |
300 | r = new QDawg; | 300 | r = new QDawg; |
301 | named_dawg->insert(name,r); | 301 | named_dawg->insert(name,r); |
302 | QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; | 302 | QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; |
303 | QFile dawgfile(dawgfilename); | 303 | QFile dawgfile(dawgfilename); |
304 | if ( dawgfile.open(IO_ReadOnly) ) | 304 | if ( dawgfile.open(IO_ReadOnly) ) |
305 | r->readFile(dawgfilename); | 305 | r->readFile(dawgfilename); |
306 | } | 306 | } |
307 | return *r; | 307 | return *r; |
308 | } | 308 | } |
309 | 309 | ||
310 | /*! | 310 | /*! |
311 | \overload | 311 | \overload |
312 | Adds \a wordlist to the addedDawg(). | 312 | Adds \a wordlist to the addedDawg(). |
313 | 313 | ||
314 | Note that the addition of words persists between program executions | 314 | Note that the addition of words persists between program executions |
315 | (they are saved in the dictionary files), so you should confirm the | 315 | (they are saved in the dictionary files), so you should confirm the |
316 | words with the user before adding them. | 316 | words with the user before adding them. |
317 | */ | 317 | */ |
318 | void Global::addWords(const QStringList& wordlist) | 318 | void Global::addWords(const QStringList& wordlist) |
319 | { | 319 | { |
320 | addWords("local",wordlist); | 320 | addWords("local",wordlist); |
321 | } | 321 | } |
322 | 322 | ||
323 | /*! | 323 | /*! |
324 | \overload | 324 | \overload |
325 | Adds \a wordlist to the addedDawg(). | 325 | Adds \a wordlist to the addedDawg(). |
326 | 326 | ||
327 | Note that the addition of words persists between program executions | 327 | Note that the addition of words persists between program executions |
328 | (they are saved in the dictionary files), so you should confirm the | 328 | (they are saved in the dictionary files), so you should confirm the |
329 | words with the user before adding them. | 329 | words with the user before adding them. |
330 | */ | 330 | */ |
331 | void Global::addWords(const QString& dictname, const QStringList& wordlist) | 331 | void Global::addWords(const QString& dictname, const QStringList& wordlist) |
332 | { | 332 | { |
333 | QDawg& d = (QDawg&)dawg(dictname); | 333 | QDawg& d = (QDawg&)dawg(dictname); |
334 | QStringList all = d.allWords() + wordlist; | 334 | QStringList all = d.allWords() + wordlist; |
335 | d.createFromWords(all); | 335 | d.createFromWords(all); |
336 | 336 | ||
337 | QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; | 337 | QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; |
338 | QFile dawgfile(dawgfilename); | 338 | QFile dawgfile(dawgfilename); |
339 | if ( dawgfile.open(IO_WriteOnly) ) { | 339 | if ( dawgfile.open(IO_WriteOnly) ) { |
340 | d.write(&dawgfile); | 340 | d.write(&dawgfile); |
341 | dawgfile.close(); | 341 | dawgfile.close(); |
342 | } | 342 | } |
343 | 343 | ||
344 | // #### Re-read the dawg here if we use mmap(). | 344 | // #### Re-read the dawg here if we use mmap(). |
345 | 345 | ||
346 | // #### Signal other processes to re-read. | 346 | // #### Signal other processes to re-read. |
347 | } | 347 | } |
348 | 348 | ||
349 | 349 | ||
350 | /*! | 350 | /*! |
351 | Returns the full path for the application called \a appname, with the | 351 | Returns the full path for the application called \a appname, with the |
352 | given \a filename. Returns QString::null if there was a problem creating | 352 | given \a filename. Returns QString::null if there was a problem creating |
353 | the directory tree for \a appname. | 353 | the directory tree for \a appname. |
354 | If \a filename contains "/", it is the caller's responsibility to | 354 | If \a filename contains "/", it is the caller's responsibility to |
355 | ensure that those directories exist. | 355 | ensure that those directories exist. |
356 | */ | 356 | */ |
357 | QString Global::applicationFileName(const QString& appname, const QString& filename) | 357 | QString Global::applicationFileName(const QString& appname, const QString& filename) |
358 | { | 358 | { |
359 | QDir d; | 359 | QDir d; |
360 | QString r = getenv("HOME"); | 360 | QString r = getenv("HOME"); |
361 | r += "/Applications/"; | 361 | r += "/Applications/"; |
362 | if ( !QFile::exists( r ) ) | 362 | if ( !QFile::exists( r ) ) |
363 | if ( d.mkdir(r) == false ) | 363 | if ( d.mkdir(r) == false ) |
364 | return QString::null; | 364 | return QString::null; |
365 | r += appname; | 365 | r += appname; |
366 | if ( !QFile::exists( r ) ) | 366 | if ( !QFile::exists( r ) ) |
367 | if ( d.mkdir(r) == false ) | 367 | if ( d.mkdir(r) == false ) |
368 | return QString::null; | 368 | return QString::null; |
369 | r += "/"; r += filename; | 369 | r += "/"; r += filename; |
370 | return r; | 370 | return r; |
371 | } | 371 | } |
372 | 372 | ||
373 | /*! | 373 | /*! |
374 | \internal | 374 | \internal |
375 | */ | 375 | */ |
376 | void Global::createDocDir() | 376 | void Global::createDocDir() |
377 | { | 377 | { |
378 | if ( !docDirCreated ) { | 378 | if ( !docDirCreated ) { |
379 | docDirCreated = TRUE; | 379 | docDirCreated = TRUE; |
380 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); | 380 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); |
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | /*! | 385 | /*! |
386 | Displays a status \a message to the user. This usually appears | 386 | Displays a status \a message to the user. This usually appears |
387 | in the taskbar for a short amount of time, then disappears. | 387 | in the taskbar for a short amount of time, then disappears. |
388 | */ | 388 | */ |
389 | void Global::statusMessage(const QString& message) | 389 | void Global::statusMessage(const QString& message) |
390 | { | 390 | { |
391 | #if !defined(QT_NO_COP) | 391 | #if !defined(QT_NO_COP) |
392 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); | 392 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); |
393 | e << message; | 393 | e << message; |
394 | #endif | 394 | #endif |
395 | } | 395 | } |
396 | 396 | ||
397 | /*! | 397 | /*! |
398 | \internal | 398 | \internal |
399 | */ | 399 | */ |
400 | void Global::applyStyle() | 400 | void Global::applyStyle() |
401 | { | 401 | { |
402 | #if !defined(QT_NO_COP) | 402 | #if !defined(QT_NO_COP) |
403 | QCopChannel::send( "QPE/System", "applyStyle()" ); | 403 | QCopChannel::send( "QPE/System", "applyStyle()" ); |
404 | #else | 404 | #else |
405 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version | 405 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version |
406 | #endif | 406 | #endif |
407 | } | 407 | } |
408 | 408 | ||
409 | /*! | 409 | /*! |
410 | \internal | 410 | \internal |
411 | */ | 411 | */ |
412 | QWidget *Global::shutdown( bool ) | 412 | QWidget *Global::shutdown( bool ) |
413 | { | 413 | { |
414 | #if !defined(QT_NO_COP) | 414 | #if !defined(QT_NO_COP) |
415 | QCopChannel::send( "QPE/System", "shutdown()" ); | 415 | QCopChannel::send( "QPE/System", "shutdown()" ); |
416 | #endif | 416 | #endif |
417 | return 0; | 417 | return 0; |
418 | } | 418 | } |
419 | 419 | ||
420 | /*! | 420 | /*! |
421 | \internal | 421 | \internal |
422 | */ | 422 | */ |
423 | QWidget *Global::restart( bool ) | 423 | QWidget *Global::restart( bool ) |
424 | { | 424 | { |
425 | #if !defined(QT_NO_COP) | 425 | #if !defined(QT_NO_COP) |
426 | QCopChannel::send( "QPE/System", "restart()" ); | 426 | QCopChannel::send( "QPE/System", "restart()" ); |
427 | #endif | 427 | #endif |
428 | return 0; | 428 | return 0; |
429 | } | 429 | } |
430 | 430 | ||
431 | /*! | 431 | /*! |
432 | Explicitly show the current input method. | 432 | Explicitly show the current input method. |
433 | 433 | ||
434 | Input methods are indicated in the taskbar by a small icon. If the | 434 | Input methods are indicated in the taskbar by a small icon. If the |
435 | input method is activated (shown) then it takes up some proportion | 435 | input method is activated (shown) then it takes up some proportion |
436 | of the bottom of the screen, to allow the user to interact (input | 436 | of the bottom of the screen, to allow the user to interact (input |
437 | characters) with it. | 437 | characters) with it. |
438 | 438 | ||
439 | \sa hideInputMethod() | 439 | \sa hideInputMethod() |
440 | */ | 440 | */ |
441 | void Global::showInputMethod() | 441 | void Global::showInputMethod() |
442 | { | 442 | { |
443 | #if !defined(QT_NO_COP) | 443 | #if !defined(QT_NO_COP) |
444 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); | 444 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); |
445 | #endif | 445 | #endif |
446 | } | 446 | } |
447 | 447 | ||
448 | /*! | 448 | /*! |
449 | Explicitly hide the current input method. | 449 | Explicitly hide the current input method. |
450 | 450 | ||
451 | The current input method is still indicated in the taskbar, but no | 451 | The current input method is still indicated in the taskbar, but no |
452 | longer takes up screen space, and can no longer be interacted with. | 452 | longer takes up screen space, and can no longer be interacted with. |
453 | 453 | ||
454 | \sa showInputMethod() | 454 | \sa showInputMethod() |
455 | */ | 455 | */ |
456 | void Global::hideInputMethod() | 456 | void Global::hideInputMethod() |
457 | { | 457 | { |
458 | #if !defined(QT_NO_COP) | 458 | #if !defined(QT_NO_COP) |
459 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); | 459 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); |
460 | #endif | 460 | #endif |
461 | } | 461 | } |
462 | 462 | ||
463 | 463 | ||
464 | /*! | 464 | /*! |
465 | \internal | 465 | \internal |
466 | */ | 466 | */ |
467 | bool Global::isBuiltinCommand( const QString &name ) | 467 | bool Global::isBuiltinCommand( const QString &name ) |
468 | { | 468 | { |
469 | if(!builtin) | 469 | if(!builtin) |
470 | return FALSE; // yes, it can happen | 470 | return FALSE; // yes, it can happen |
471 | for (int i = 0; builtin[i].file; i++) { | 471 | for (int i = 0; builtin[i].file; i++) { |
472 | if ( builtin[i].file == name ) { | 472 | if ( builtin[i].file == name ) { |
473 | return TRUE; | 473 | return TRUE; |
474 | } | 474 | } |
475 | } | 475 | } |
476 | return FALSE; | 476 | return FALSE; |
477 | } | 477 | } |
478 | 478 | ||
479 | Global::Command* Global::builtin=0; | 479 | Global::Command* Global::builtin=0; |
480 | QGuardedPtr<QWidget> *Global::running=0; | 480 | QGuardedPtr<QWidget> *Global::running=0; |
481 | 481 | ||
482 | /*! | 482 | /*! |
483 | \class Global::Command | 483 | \class Global::Command |
484 | \brief The Global::Command class is internal. | 484 | \brief The Global::Command class is internal. |
485 | \internal | 485 | \internal |
486 | */ | 486 | */ |
487 | 487 | ||
488 | /*! | 488 | /*! |
489 | \internal | 489 | \internal |
490 | */ | 490 | */ |
491 | void Global::setBuiltinCommands( Command* list ) | 491 | void Global::setBuiltinCommands( Command* list ) |
492 | { | 492 | { |
493 | if ( running ) | 493 | if ( running ) |
494 | delete [] running; | 494 | delete [] running; |
495 | 495 | ||
496 | builtin = list; | 496 | builtin = list; |
497 | int count = 0; | 497 | int count = 0; |
498 | if (!builtin) | 498 | if (!builtin) |
499 | return; | 499 | return; |
500 | while ( builtin[count].file ) | 500 | while ( builtin[count].file ) |
501 | count++; | 501 | count++; |
502 | 502 | ||
503 | running = new QGuardedPtr<QWidget> [ count ]; | 503 | running = new QGuardedPtr<QWidget> [ count ]; |
504 | } | 504 | } |
505 | 505 | ||
506 | /*! | 506 | /*! |
507 | \internal | 507 | \internal |
508 | */ | 508 | */ |
509 | void Global::setDocument( QWidget* receiver, const QString& document ) | 509 | void Global::setDocument( QWidget* receiver, const QString& document ) |
510 | { | 510 | { |
511 | Emitter emitter(receiver,document); | 511 | Emitter emitter(receiver,document); |
512 | } | 512 | } |
513 | 513 | ||
514 | /*! | 514 | /*! |
515 | \internal | 515 | \internal |
516 | */ | 516 | */ |
517 | bool Global::terminateBuiltin( const QString& n ) | 517 | bool Global::terminateBuiltin( const QString& n ) |
518 | { | 518 | { |
519 | if (!builtin) | 519 | if (!builtin) |
520 | return FALSE; | 520 | return FALSE; |
521 | for (int i = 0; builtin[i].file; i++) { | 521 | for (int i = 0; builtin[i].file; i++) { |
522 | if ( builtin[i].file == n ) { | 522 | if ( builtin[i].file == n ) { |
523 | delete running[i]; | 523 | delete running[i]; |
524 | return TRUE; | 524 | return TRUE; |
525 | } | 525 | } |
526 | } | 526 | } |
527 | return FALSE; | 527 | return FALSE; |
528 | } | 528 | } |
529 | 529 | ||
530 | /*! | 530 | /*! |
531 | \internal | 531 | \internal |
532 | */ | 532 | */ |
533 | void Global::terminate( const AppLnk* app ) | 533 | void Global::terminate( const AppLnk* app ) |
534 | { | 534 | { |
535 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 535 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
536 | 536 | ||
537 | #ifndef QT_NO_COP | 537 | #ifndef QT_NO_COP |
538 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 538 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
539 | if ( QCopChannel::isRegistered(channel) ) { | 539 | if ( QCopChannel::isRegistered(channel) ) { |
540 | QCopEnvelope e(channel, "quit()"); | 540 | QCopEnvelope e(channel, "quit()"); |
541 | } | 541 | } |
542 | #endif | 542 | #endif |
543 | } | 543 | } |
544 | 544 | ||
545 | /*! | 545 | /*! |
546 | Low-level function to run command \a c. | 546 | Low-level function to run command \a c. |
547 | 547 | ||
548 | \warning Do not use this function. Use execute instead. | 548 | \warning Do not use this function. Use execute instead. |
549 | 549 | ||
550 | \sa execute() | 550 | \sa execute() |
551 | */ | 551 | */ |
552 | void Global::invoke(const QString &c) | 552 | void Global::invoke(const QString &c) |
553 | { | 553 | { |
554 | // Convert the command line in to a list of arguments | 554 | // Convert the command line in to a list of arguments |
555 | QStringList list = QStringList::split(QRegExp(" *"),c); | 555 | QStringList list = QStringList::split(QRegExp(" *"),c); |
556 | 556 | ||
557 | #if !defined(QT_NO_COP) | 557 | #if !defined(QT_NO_COP) |
558 | QString ap=list[0]; | 558 | QString ap=list[0]; |
559 | // see if the application is already running | 559 | // see if the application is already running |
560 | // XXX should lock file /tmp/qcop-msg-ap | 560 | // XXX should lock file /tmp/qcop-msg-ap |
561 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 561 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
562 | // If the channel is already register, the app is already running, so show it. | 562 | // If the channel is already register, the app is already running, so show it. |
563 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 563 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
564 | 564 | ||
565 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 565 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
566 | //e << ap; | 566 | //e << ap; |
567 | return; | 567 | return; |
568 | } | 568 | } |
569 | // XXX should unlock file /tmp/qcop-msg-ap | 569 | // XXX should unlock file /tmp/qcop-msg-ap |
570 | //see if it is being started | 570 | //see if it is being started |
571 | if ( StartingAppList::isStarting( ap ) ) { | 571 | if ( StartingAppList::isStarting( ap ) ) { |
572 | // FIXME take it out for now, since it leads to a much to short showing of wait if | 572 | // FIXME take it out for now, since it leads to a much to short showing of wait if |
573 | // some entry is clicked. | 573 | // some entry is clicked. |
574 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes | 574 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes |
575 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there | 575 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there |
576 | // had the idea that an apploader belongs to the launcher ... | 576 | // had the idea that an apploader belongs to the launcher ... |
577 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 577 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
578 | //e << ap; | 578 | //e << ap; |
579 | return; | 579 | return; |
580 | } | 580 | } |
581 | 581 | ||
582 | #endif | 582 | #endif |
583 | 583 | ||
584 | #ifdef QT_NO_QWS_MULTIPROCESS | 584 | #ifdef QT_NO_QWS_MULTIPROCESS |
585 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 585 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
586 | #else | 586 | #else |
587 | 587 | ||
588 | QStrList slist; | 588 | QStrList slist; |
589 | unsigned int j; | 589 | unsigned int j; |
590 | for ( j = 0; j < list.count(); j++ ) | 590 | for ( j = 0; j < list.count(); j++ ) |
591 | slist.append( list[j].utf8() ); | 591 | slist.append( list[j].utf8() ); |
592 | 592 | ||
593 | const char **args = new (const char *)[slist.count() + 1]; | 593 | const char **args = new (const char *)[slist.count() + 1]; |
594 | for ( j = 0; j < slist.count(); j++ ) | 594 | for ( j = 0; j < slist.count(); j++ ) |
595 | args[j] = slist.at(j); | 595 | args[j] = slist.at(j); |
596 | args[j] = NULL; | 596 | args[j] = NULL; |
597 | 597 | ||
598 | #if !defined(QT_NO_COP) | 598 | #if !defined(QT_NO_COP) |
599 | // an attempt to show a wait... | 599 | // an attempt to show a wait... |
600 | // more logic should be used, but this will be fine for the moment... | 600 | // more logic should be used, but this will be fine for the moment... |
601 | QCopEnvelope ( "QPE/System", "busy()" ); | 601 | QCopEnvelope ( "QPE/System", "busy()" ); |
602 | #endif | 602 | #endif |
603 | 603 | ||
604 | #ifdef HAVE_QUICKEXEC | 604 | #ifdef HAVE_QUICKEXEC |
605 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 605 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
606 | qDebug("libfile = %s", libexe.latin1() ); | 606 | qDebug("libfile = %s", libexe.latin1() ); |
607 | if ( QFile::exists( libexe ) ) { | 607 | if ( QFile::exists( libexe ) ) { |
608 | qDebug("calling quickexec %s", libexe.latin1() ); | 608 | qDebug("calling quickexec %s", libexe.latin1() ); |
609 | quickexecv( libexe.utf8().data(), (const char **)args ); | 609 | quickexecv( libexe.utf8().data(), (const char **)args ); |
610 | } else | 610 | } else |
611 | #endif | 611 | #endif |
612 | { | 612 | { |
613 | bool success = false; | 613 | bool success = false; |
614 | int pfd [2]; | 614 | int pfd [2]; |
615 | if ( ::pipe ( pfd ) < 0 ) | 615 | if ( ::pipe ( pfd ) < 0 ) |
616 | pfd [0] = pfd [1] = -1; | 616 | pfd [0] = pfd [1] = -1; |
617 | 617 | ||
618 | pid_t pid = ::fork ( ); | 618 | pid_t pid = ::fork ( ); |
619 | 619 | ||
620 | if ( pid == 0 ) { // child | 620 | if ( pid == 0 ) { // child |
621 | for ( int fd = 3; fd < 100; fd++ ) { | 621 | for ( int fd = 3; fd < 100; fd++ ) { |
622 | if ( fd != pfd [1] ) | 622 | if ( fd != pfd [1] ) |
623 | ::close ( fd ); | 623 | ::close ( fd ); |
624 | } | 624 | } |
625 | ::setpgid ( ::getpid ( ), ::getppid ( )); | 625 | ::setpgid ( ::getpid ( ), ::getppid ( )); |
626 | 626 | ||
627 | // Closing of fd[1] indicates that the execvp succeeded! | 627 | // Closing of fd[1] indicates that the execvp succeeded! |
628 | if ( pfd [1] >= 0 ) | 628 | if ( pfd [1] >= 0 ) |
629 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); | 629 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); |
630 | 630 | ||
631 | // Try bindir first, so that foo/bar works too | 631 | // Try bindir first, so that foo/bar works too |
632 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); | 632 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); |
633 | ::execvp ( args [0], (char * const *) args ); | 633 | ::execvp ( args [0], (char * const *) args ); |
634 | 634 | ||
635 | char resultByte = 1; | 635 | char resultByte = 1; |
636 | if ( pfd [1] >= 0 ) | 636 | if ( pfd [1] >= 0 ) |
637 | ::write ( pfd [1], &resultByte, 1 ); | 637 | ::write ( pfd [1], &resultByte, 1 ); |
638 | ::_exit ( -1 ); | 638 | ::_exit ( -1 ); |
639 | } | 639 | } |
640 | else if ( pid > 0 ) { | 640 | else if ( pid > 0 ) { |
641 | success = true; | 641 | success = true; |
642 | 642 | ||
643 | if ( pfd [1] >= 0 ) | 643 | if ( pfd [1] >= 0 ) |
644 | ::close ( pfd [1] ); | 644 | ::close ( pfd [1] ); |
645 | if ( pfd [0] >= 0 ) { | 645 | if ( pfd [0] >= 0 ) { |
646 | while ( true ) { | 646 | while ( true ) { |
647 | char resultByte; | 647 | char resultByte; |
648 | int n = ::read ( pfd [0], &resultByte, 1 ); | 648 | int n = ::read ( pfd [0], &resultByte, 1 ); |
649 | if ( n == 1 ) { | 649 | if ( n == 1 ) { |
650 | success = false; | 650 | success = false; |
651 | break; | 651 | break; |
652 | } | 652 | } |
653 | if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) | 653 | if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) |
654 | continue; | 654 | continue; |
655 | 655 | ||
656 | break; // success | 656 | break; // success |
657 | } | 657 | } |
658 | ::close ( pfd [0] ); | 658 | ::close ( pfd [0] ); |
659 | } | 659 | } |
660 | } | 660 | } |
661 | if ( success ) | 661 | if ( success ) |
662 | StartingAppList::add( list[0] ); | 662 | StartingAppList::add( list[0] ); |
663 | else | 663 | else |
664 | QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); | 664 | QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); |
665 | } | 665 | } |
666 | #endif //QT_NO_QWS_MULTIPROCESS | 666 | #endif //QT_NO_QWS_MULTIPROCESS |
667 | } | 667 | } |
668 | 668 | ||
669 | 669 | ||
670 | /*! | 670 | /*! |
671 | Executes the application identfied by \a c, passing \a | 671 | Executes the application identfied by \a c, passing \a |
672 | document if it isn't null. | 672 | document if it isn't null. |
673 | 673 | ||
674 | Note that a better approach might be to send a QCop message to the | 674 | Note that a better approach might be to send a QCop message to the |
675 | application's QPE/Application/\e{appname} channel. | 675 | application's QPE/Application/\e{appname} channel. |
676 | */ | 676 | */ |
677 | void Global::execute( const QString &c, const QString& document ) | 677 | void Global::execute( const QString &c, const QString& document ) |
678 | { | 678 | { |
679 | if ( qApp->type() != QApplication::GuiServer ) { | ||
680 | // ask the server to do the work | 679 | // ask the server to do the work |
681 | #if !defined(QT_NO_COP) | 680 | #if !defined(QT_NO_COP) |
682 | if ( document.isNull() ) { | 681 | if ( document.isNull() ) { |
683 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 682 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
684 | e << c; | 683 | e << c; |
685 | } else { | 684 | } else { |
686 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); | 685 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); |
687 | e << c << document; | 686 | e << c << document; |
688 | } | ||
689 | #endif | ||
690 | return; | ||
691 | } | ||
692 | |||
693 | // Attempt to execute the app using a builtin class for the app first | ||
694 | // else try and find it in the bin directory | ||
695 | if (builtin) { | ||
696 | for (int i = 0; builtin[i].file; i++) { | ||
697 | if ( builtin[i].file == c ) { | ||
698 | if ( running[i] ) { | ||
699 | if ( !document.isNull() && builtin[i].documentary ) | ||
700 | setDocument(running[i], document); | ||
701 | running[i]->raise(); | ||
702 | running[i]->show(); | ||
703 | running[i]->setActiveWindow(); | ||
704 | } else { | ||
705 | running[i] = builtin[i].func( builtin[i].maximized ); | ||
706 | } | ||
707 | #ifndef QT_NO_COP | ||
708 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | ||
709 | e << c; // that was quick ;-) | ||
710 | #endif | ||
711 | return; | ||
712 | } | ||
713 | } | ||
714 | } | ||
715 | |||
716 | //Global::invoke(c, document); | ||
717 | |||
718 | // Convert the command line in to a list of arguments | ||
719 | QStringList list = QStringList::split(QRegExp(" *"),c); | ||
720 | |||
721 | #if !defined(QT_NO_COP) | ||
722 | QString ap=list[0]; | ||
723 | |||
724 | qDebug("executing %s", ap.latin1() ); | ||
725 | |||
726 | /* if need be, sending a qcop message will result in an invoke, see | ||
727 | preceeding function */ | ||
728 | invoke( ap ); | ||
729 | //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | ||
730 | if ( !document.isEmpty() ) { | ||
731 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); | ||
732 | env << document; | ||
733 | } | 687 | } |
734 | #endif | 688 | #endif |
689 | return; | ||
735 | } | 690 | } |
736 | 691 | ||
737 | /*! | 692 | /*! |
738 | Returns the string \a s with the characters '\', '"', and '$' quoted | 693 | Returns the string \a s with the characters '\', '"', and '$' quoted |
739 | by a preceeding '\'. | 694 | by a preceeding '\'. |
740 | 695 | ||
741 | \sa stringQuote() | 696 | \sa stringQuote() |
742 | */ | 697 | */ |
743 | QString Global::shellQuote(const QString& s) | 698 | QString Global::shellQuote(const QString& s) |
744 | { | 699 | { |
745 | QString r="\""; | 700 | QString r="\""; |
746 | for (int i=0; i<(int)s.length(); i++) { | 701 | for (int i=0; i<(int)s.length(); i++) { |
747 | char c = s[i].latin1(); | 702 | char c = s[i].latin1(); |
748 | switch (c) { | 703 | switch (c) { |
749 | case '\\': case '"': case '$': | 704 | case '\\': case '"': case '$': |
750 | r+="\\"; | 705 | r+="\\"; |
751 | } | 706 | } |
752 | r += s[i]; | 707 | r += s[i]; |
753 | } | 708 | } |
754 | r += "\""; | 709 | r += "\""; |
755 | return r; | 710 | return r; |
756 | } | 711 | } |
757 | 712 | ||
758 | /*! | 713 | /*! |
759 | Returns the string \a s with the characters '\' and '"' quoted by a | 714 | Returns the string \a s with the characters '\' and '"' quoted by a |
760 | preceeding '\'. | 715 | preceeding '\'. |
761 | 716 | ||
762 | \sa shellQuote() | 717 | \sa shellQuote() |
763 | */ | 718 | */ |
764 | QString Global::stringQuote(const QString& s) | 719 | QString Global::stringQuote(const QString& s) |
765 | { | 720 | { |
766 | QString r="\""; | 721 | QString r="\""; |
767 | for (int i=0; i<(int)s.length(); i++) { | 722 | for (int i=0; i<(int)s.length(); i++) { |
768 | char c = s[i].latin1(); | 723 | char c = s[i].latin1(); |
769 | switch (c) { | 724 | switch (c) { |
770 | case '\\': case '"': | 725 | case '\\': case '"': |
771 | r+="\\"; | 726 | r+="\\"; |
772 | } | 727 | } |
773 | r += s[i]; | 728 | r += s[i]; |
774 | } | 729 | } |
775 | r += "\""; | 730 | r += "\""; |
776 | return r; | 731 | return r; |
777 | } | 732 | } |
778 | 733 | ||
779 | /*! | 734 | /*! |
780 | Finds all documents on the system's document directories which | 735 | Finds all documents on the system's document directories which |
781 | match the filter \a mimefilter, and appends the resulting DocLnk | 736 | match the filter \a mimefilter, and appends the resulting DocLnk |
782 | objects to \a folder. | 737 | objects to \a folder. |
783 | */ | 738 | */ |
784 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) | 739 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) |
785 | { | 740 | { |
786 | QString homedocs = QString(getenv("HOME")) + "/Documents"; | 741 | QString homedocs = QString(getenv("HOME")) + "/Documents"; |
787 | DocLnkSet d(homedocs,mimefilter); | 742 | DocLnkSet d(homedocs,mimefilter); |
788 | folder->appendFrom(d); | 743 | folder->appendFrom(d); |
789 | /** let's do intellegint way of searching these files | 744 | /** let's do intellegint way of searching these files |
790 | * a) the user don't want to check mediums global | 745 | * a) the user don't want to check mediums global |
791 | * b) the user wants to check but use the global options for it | 746 | * b) the user wants to check but use the global options for it |
792 | * c) the user wants to check it but not this medium | 747 | * c) the user wants to check it but not this medium |
793 | * d) the user wants to check and this medium as well | 748 | * d) the user wants to check and this medium as well |
794 | * | 749 | * |
795 | * In all cases we need to apply a different mimefilter to | 750 | * In all cases we need to apply a different mimefilter to |
796 | * the medium. | 751 | * the medium. |
797 | * a) mimefilter.isEmpty() we need to apply the responding filter | 752 | * a) mimefilter.isEmpty() we need to apply the responding filter |
798 | * either the global or the one on the medium | 753 | * either the global or the one on the medium |
799 | * | 754 | * |
800 | * b) mimefilter is set to an application we need to find out if the | 755 | * b) mimefilter is set to an application we need to find out if the |
801 | * mimetypes are included in the mime mask of the medium | 756 | * mimetypes are included in the mime mask of the medium |
802 | */ | 757 | */ |
803 | StorageInfo storage; | 758 | StorageInfo storage; |
804 | const QList<FileSystem> &fs = storage.fileSystems(); | 759 | const QList<FileSystem> &fs = storage.fileSystems(); |
805 | QListIterator<FileSystem> it ( fs ); | 760 | QListIterator<FileSystem> it ( fs ); |
806 | for ( ; it.current(); ++it ) { | 761 | for ( ; it.current(); ++it ) { |
807 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it | 762 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it |
808 | // this is a candidate look at the cf and see if we should search on it | 763 | // this is a candidate look at the cf and see if we should search on it |
809 | QString path = (*it)->path(); | 764 | QString path = (*it)->path(); |
810 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) | 765 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) |
811 | continue; | 766 | continue; |
812 | DocLnkSet ide( path, mimefilter ); | 767 | DocLnkSet ide( path, mimefilter ); |
813 | folder->appendFrom(ide); | 768 | folder->appendFrom(ide); |
814 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { | 769 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { |
815 | QString path = (*it)->path() + "/Documents"; | 770 | QString path = (*it)->path() + "/Documents"; |
816 | DocLnkSet ide( path, mimefilter ); | 771 | DocLnkSet ide( path, mimefilter ); |
817 | folder->appendFrom(ide); | 772 | folder->appendFrom(ide); |
818 | } | 773 | } |
819 | } | 774 | } |
820 | } | 775 | } |
821 | 776 | ||
822 | QStringList Global::languageList() | 777 | QStringList Global::languageList() |
823 | { | 778 | { |
824 | QString lang = getenv("LANG"); | 779 | QString lang = getenv("LANG"); |
825 | QStringList langs; | 780 | QStringList langs; |
826 | langs.append(lang); | 781 | langs.append(lang); |
827 | int i = lang.find("."); | 782 | int i = lang.find("."); |
828 | if ( i > 0 ) | 783 | if ( i > 0 ) |
829 | lang = lang.left( i ); | 784 | lang = lang.left( i ); |
830 | i = lang.find( "_" ); | 785 | i = lang.find( "_" ); |
831 | if ( i > 0 ) | 786 | if ( i > 0 ) |
832 | langs.append(lang.left(i)); | 787 | langs.append(lang.left(i)); |
833 | return langs; | 788 | return langs; |
834 | } | 789 | } |
835 | 790 | ||
836 | QStringList Global::helpPath() | 791 | QStringList Global::helpPath() |
837 | { | 792 | { |
838 | QString qpeDir = QPEApplication::qpeDir(); | 793 | QString qpeDir = QPEApplication::qpeDir(); |
839 | QStringList path; | 794 | QStringList path; |
840 | QStringList langs = Global::languageList(); | 795 | QStringList langs = Global::languageList(); |
841 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { | 796 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { |
842 | QString lang = *it; | 797 | QString lang = *it; |
843 | if ( !lang.isEmpty() ) | 798 | if ( !lang.isEmpty() ) |
844 | path += qpeDir + "/help/" + lang + "/html"; | 799 | path += qpeDir + "/help/" + lang + "/html"; |
845 | } | 800 | } |
846 | path += qpeDir + "/pics"; | 801 | path += qpeDir + "/pics"; |
847 | path += qpeDir + "/help/html"; | 802 | path += qpeDir + "/help/html"; |
848 | /* we even put english into the en dir so try it as fallback as well for opie */ | 803 | /* we even put english into the en dir so try it as fallback as well for opie */ |
849 | path += qpeDir + "/help/en/html"; | 804 | path += qpeDir + "/help/en/html"; |
850 | path += qpeDir + "/docs"; | 805 | path += qpeDir + "/docs"; |
851 | 806 | ||
852 | 807 | ||
853 | return path; | 808 | return path; |
854 | } | 809 | } |
855 | 810 | ||
856 | 811 | ||
857 | #include "global.moc" | 812 | #include "global.moc" |