summaryrefslogtreecommitdiff
path: root/library/global.cpp
authorsandman <sandman>2002-12-07 19:58:03 (UTC)
committer sandman <sandman>2002-12-07 19:58:03 (UTC)
commitd856a53635479f5ace72159aa513480ecd90bf1e (patch) (unidiff)
treeaba6aaa2cc9168ebd364308f37cdc9c4286c6703 /library/global.cpp
parent09aa2b9a766e02e52ad64c0294e8b72e6fda8c85 (diff)
downloadopie-d856a53635479f5ace72159aa513480ecd90bf1e.zip
opie-d856a53635479f5ace72159aa513480ecd90bf1e.tar.gz
opie-d856a53635479f5ace72159aa513480ecd90bf1e.tar.bz2
- removed the libpreload stuff from global.cpp
- added qt_override.* which provides the same functionality as libpreload (the new -override patch for Qt/E is needed for this to work/compile) - changed qpeapplication a bit to accomodate the new interface
Diffstat (limited to 'library/global.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp16
1 files changed, 1 insertions, 15 deletions
diff --git a/library/global.cpp b/library/global.cpp
index 2162e02..d6ba84f 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -222,599 +222,585 @@ static QString dictDir()
222 \internal 222 \internal
223*/ 223*/
224Global::Global() 224Global::Global()
225{ 225{
226} 226}
227 227
228/*! 228/*!
229 Returns the unchangeable QDawg that contains general 229 Returns the unchangeable QDawg that contains general
230 words for the current locale. 230 words for the current locale.
231 231
232 \sa addedDawg() 232 \sa addedDawg()
233*/ 233*/
234const QDawg& Global::fixedDawg() 234const QDawg& Global::fixedDawg()
235{ 235{
236 if ( !fixed_dawg ) { 236 if ( !fixed_dawg ) {
237 if ( !docDirCreated ) 237 if ( !docDirCreated )
238 createDocDir(); 238 createDocDir();
239 239
240 fixed_dawg = new QDawg; 240 fixed_dawg = new QDawg;
241 QString dawgfilename = dictDir() + "/dawg"; 241 QString dawgfilename = dictDir() + "/dawg";
242 QString words_lang; 242 QString words_lang;
243 QStringList langs = Global::languageList(); 243 QStringList langs = Global::languageList();
244 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 244 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
245 QString lang = *it; 245 QString lang = *it;
246 words_lang = dictDir() + "/words." + lang; 246 words_lang = dictDir() + "/words." + lang;
247 QString dawgfilename_lang = dawgfilename + "." + lang; 247 QString dawgfilename_lang = dawgfilename + "." + lang;
248 if ( QFile::exists(dawgfilename_lang) || 248 if ( QFile::exists(dawgfilename_lang) ||
249 QFile::exists(words_lang) ) { 249 QFile::exists(words_lang) ) {
250 dawgfilename = dawgfilename_lang; 250 dawgfilename = dawgfilename_lang;
251 break; 251 break;
252 } 252 }
253 } 253 }
254 QFile dawgfile(dawgfilename); 254 QFile dawgfile(dawgfilename);
255 255
256 if ( !dawgfile.exists() ) { 256 if ( !dawgfile.exists() ) {
257 QString fn = dictDir() + "/words"; 257 QString fn = dictDir() + "/words";
258 if ( QFile::exists(words_lang) ) 258 if ( QFile::exists(words_lang) )
259 fn = words_lang; 259 fn = words_lang;
260 QFile in(fn); 260 QFile in(fn);
261 if ( in.open(IO_ReadOnly) ) { 261 if ( in.open(IO_ReadOnly) ) {
262 fixed_dawg->createFromWords(&in); 262 fixed_dawg->createFromWords(&in);
263 dawgfile.open(IO_WriteOnly); 263 dawgfile.open(IO_WriteOnly);
264 fixed_dawg->write(&dawgfile); 264 fixed_dawg->write(&dawgfile);
265 dawgfile.close(); 265 dawgfile.close();
266 } 266 }
267 } else { 267 } else {
268 fixed_dawg->readFile(dawgfilename); 268 fixed_dawg->readFile(dawgfilename);
269 } 269 }
270 } 270 }
271 271
272 return *fixed_dawg; 272 return *fixed_dawg;
273} 273}
274 274
275/*! 275/*!
276 Returns the changeable QDawg that contains general 276 Returns the changeable QDawg that contains general
277 words for the current locale. 277 words for the current locale.
278 278
279 \sa fixedDawg() 279 \sa fixedDawg()
280*/ 280*/
281const QDawg& Global::addedDawg() 281const QDawg& Global::addedDawg()
282{ 282{
283 return dawg("local"); 283 return dawg("local");
284} 284}
285 285
286/*! 286/*!
287 Returns the QDawg with the given \a name. 287 Returns the QDawg with the given \a name.
288 This is an application-specific word list. 288 This is an application-specific word list.
289 289
290 \a name should not contain "/". 290 \a name should not contain "/".
291*/ 291*/
292const QDawg& Global::dawg(const QString& name) 292const QDawg& Global::dawg(const QString& name)
293{ 293{
294 createDocDir(); 294 createDocDir();
295 if ( !named_dawg ) 295 if ( !named_dawg )
296 named_dawg = new QDict<QDawg>; 296 named_dawg = new QDict<QDawg>;
297 QDawg* r = named_dawg->find(name); 297 QDawg* r = named_dawg->find(name);
298 if ( !r ) { 298 if ( !r ) {
299 r = new QDawg; 299 r = new QDawg;
300 named_dawg->insert(name,r); 300 named_dawg->insert(name,r);
301 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 301 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
302 QFile dawgfile(dawgfilename); 302 QFile dawgfile(dawgfilename);
303 if ( dawgfile.open(IO_ReadOnly) ) 303 if ( dawgfile.open(IO_ReadOnly) )
304 r->readFile(dawgfilename); 304 r->readFile(dawgfilename);
305 } 305 }
306 return *r; 306 return *r;
307} 307}
308 308
309/*! 309/*!
310 \overload 310 \overload
311 Adds \a wordlist to the addedDawg(). 311 Adds \a wordlist to the addedDawg().
312 312
313 Note that the addition of words persists between program executions 313 Note that the addition of words persists between program executions
314 (they are saved in the dictionary files), so you should confirm the 314 (they are saved in the dictionary files), so you should confirm the
315 words with the user before adding them. 315 words with the user before adding them.
316*/ 316*/
317void Global::addWords(const QStringList& wordlist) 317void Global::addWords(const QStringList& wordlist)
318{ 318{
319 addWords("local",wordlist); 319 addWords("local",wordlist);
320} 320}
321 321
322/*! 322/*!
323 \overload 323 \overload
324 Adds \a wordlist to the addedDawg(). 324 Adds \a wordlist to the addedDawg().
325 325
326 Note that the addition of words persists between program executions 326 Note that the addition of words persists between program executions
327 (they are saved in the dictionary files), so you should confirm the 327 (they are saved in the dictionary files), so you should confirm the
328 words with the user before adding them. 328 words with the user before adding them.
329*/ 329*/
330void Global::addWords(const QString& dictname, const QStringList& wordlist) 330void Global::addWords(const QString& dictname, const QStringList& wordlist)
331{ 331{
332 QDawg& d = (QDawg&)dawg(dictname); 332 QDawg& d = (QDawg&)dawg(dictname);
333 QStringList all = d.allWords() + wordlist; 333 QStringList all = d.allWords() + wordlist;
334 d.createFromWords(all); 334 d.createFromWords(all);
335 335
336 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 336 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
337 QFile dawgfile(dawgfilename); 337 QFile dawgfile(dawgfilename);
338 if ( dawgfile.open(IO_WriteOnly) ) { 338 if ( dawgfile.open(IO_WriteOnly) ) {
339 d.write(&dawgfile); 339 d.write(&dawgfile);
340 dawgfile.close(); 340 dawgfile.close();
341 } 341 }
342 342
343 // #### Re-read the dawg here if we use mmap(). 343 // #### Re-read the dawg here if we use mmap().
344 344
345 // #### Signal other processes to re-read. 345 // #### Signal other processes to re-read.
346} 346}
347 347
348 348
349/*! 349/*!
350 Returns the full path for the application called \a appname, with the 350 Returns the full path for the application called \a appname, with the
351 given \a filename. Returns QString::null if there was a problem creating 351 given \a filename. Returns QString::null if there was a problem creating
352 the directory tree for \a appname. 352 the directory tree for \a appname.
353 If \a filename contains "/", it is the caller's responsibility to 353 If \a filename contains "/", it is the caller's responsibility to
354 ensure that those directories exist. 354 ensure that those directories exist.
355*/ 355*/
356QString Global::applicationFileName(const QString& appname, const QString& filename) 356QString Global::applicationFileName(const QString& appname, const QString& filename)
357{ 357{
358 QDir d; 358 QDir d;
359 QString r = getenv("HOME"); 359 QString r = getenv("HOME");
360 r += "/Applications/"; 360 r += "/Applications/";
361 if ( !QFile::exists( r ) ) 361 if ( !QFile::exists( r ) )
362 if ( d.mkdir(r) == false ) 362 if ( d.mkdir(r) == false )
363 return QString::null; 363 return QString::null;
364 r += appname; 364 r += appname;
365 if ( !QFile::exists( r ) ) 365 if ( !QFile::exists( r ) )
366 if ( d.mkdir(r) == false ) 366 if ( d.mkdir(r) == false )
367 return QString::null; 367 return QString::null;
368 r += "/"; r += filename; 368 r += "/"; r += filename;
369 return r; 369 return r;
370} 370}
371 371
372/*! 372/*!
373 \internal 373 \internal
374*/ 374*/
375void Global::createDocDir() 375void Global::createDocDir()
376{ 376{
377 if ( !docDirCreated ) { 377 if ( !docDirCreated ) {
378 docDirCreated = TRUE; 378 docDirCreated = TRUE;
379 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 379 mkdir( QPEApplication::documentDir().latin1(), 0755 );
380 } 380 }
381} 381}
382 382
383 383
384/*! 384/*!
385 Displays a status \a message to the user. This usually appears 385 Displays a status \a message to the user. This usually appears
386 in the taskbar for a short amount of time, then disappears. 386 in the taskbar for a short amount of time, then disappears.
387*/ 387*/
388void Global::statusMessage(const QString& message) 388void Global::statusMessage(const QString& message)
389{ 389{
390#if!defined(QT_NO_COP) 390#if!defined(QT_NO_COP)
391 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 391 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
392 e << message; 392 e << message;
393#endif 393#endif
394} 394}
395 395
396/*! 396/*!
397 \internal 397 \internal
398*/ 398*/
399void Global::applyStyle() 399void Global::applyStyle()
400{ 400{
401#if !defined(QT_NO_COP) 401#if !defined(QT_NO_COP)
402 QCopChannel::send( "QPE/System", "applyStyle()" ); 402 QCopChannel::send( "QPE/System", "applyStyle()" );
403#else 403#else
404 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 404 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
405#endif 405#endif
406} 406}
407 407
408/*! 408/*!
409 \internal 409 \internal
410*/ 410*/
411QWidget *Global::shutdown( bool ) 411QWidget *Global::shutdown( bool )
412{ 412{
413#if !defined(QT_NO_COP) 413#if !defined(QT_NO_COP)
414 QCopChannel::send( "QPE/System", "shutdown()" ); 414 QCopChannel::send( "QPE/System", "shutdown()" );
415#endif 415#endif
416 return 0; 416 return 0;
417} 417}
418 418
419/*! 419/*!
420 \internal 420 \internal
421*/ 421*/
422QWidget *Global::restart( bool ) 422QWidget *Global::restart( bool )
423{ 423{
424#if !defined(QT_NO_COP) 424#if !defined(QT_NO_COP)
425 QCopChannel::send( "QPE/System", "restart()" ); 425 QCopChannel::send( "QPE/System", "restart()" );
426#endif 426#endif
427 return 0; 427 return 0;
428} 428}
429 429
430/*! 430/*!
431 Explicitly show the current input method. 431 Explicitly show the current input method.
432 432
433 Input methods are indicated in the taskbar by a small icon. If the 433 Input methods are indicated in the taskbar by a small icon. If the
434 input method is activated (shown) then it takes up some proportion 434 input method is activated (shown) then it takes up some proportion
435 of the bottom of the screen, to allow the user to interact (input 435 of the bottom of the screen, to allow the user to interact (input
436 characters) with it. 436 characters) with it.
437 437
438 \sa hideInputMethod() 438 \sa hideInputMethod()
439*/ 439*/
440void Global::showInputMethod() 440void Global::showInputMethod()
441{ 441{
442#if !defined(QT_NO_COP) 442#if !defined(QT_NO_COP)
443 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 443 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
444#endif 444#endif
445} 445}
446 446
447/*! 447/*!
448 Explicitly hide the current input method. 448 Explicitly hide the current input method.
449 449
450 The current input method is still indicated in the taskbar, but no 450 The current input method is still indicated in the taskbar, but no
451 longer takes up screen space, and can no longer be interacted with. 451 longer takes up screen space, and can no longer be interacted with.
452 452
453 \sa showInputMethod() 453 \sa showInputMethod()
454*/ 454*/
455void Global::hideInputMethod() 455void Global::hideInputMethod()
456{ 456{
457#if !defined(QT_NO_COP) 457#if !defined(QT_NO_COP)
458 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 458 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
459#endif 459#endif
460} 460}
461 461
462 462
463/*! 463/*!
464 \internal 464 \internal
465*/ 465*/
466bool Global::isBuiltinCommand( const QString &name ) 466bool Global::isBuiltinCommand( const QString &name )
467{ 467{
468 if(!builtin) 468 if(!builtin)
469 return FALSE; // yes, it can happen 469 return FALSE; // yes, it can happen
470 for (int i = 0; builtin[i].file; i++) { 470 for (int i = 0; builtin[i].file; i++) {
471 if ( builtin[i].file == name ) { 471 if ( builtin[i].file == name ) {
472 return TRUE; 472 return TRUE;
473 } 473 }
474 } 474 }
475 return FALSE; 475 return FALSE;
476} 476}
477 477
478Global::Command* Global::builtin=0; 478Global::Command* Global::builtin=0;
479QGuardedPtr<QWidget> *Global::running=0; 479QGuardedPtr<QWidget> *Global::running=0;
480 480
481/*! 481/*!
482 \class Global::Command 482 \class Global::Command
483 \brief The Global::Command class is internal. 483 \brief The Global::Command class is internal.
484 \internal 484 \internal
485*/ 485*/
486 486
487/*! 487/*!
488 \internal 488 \internal
489*/ 489*/
490void Global::setBuiltinCommands( Command* list ) 490void Global::setBuiltinCommands( Command* list )
491{ 491{
492 if ( running ) 492 if ( running )
493 delete [] running; 493 delete [] running;
494 494
495 builtin = list; 495 builtin = list;
496 int count = 0; 496 int count = 0;
497 if (!builtin) 497 if (!builtin)
498 return; 498 return;
499 while ( builtin[count].file ) 499 while ( builtin[count].file )
500 count++; 500 count++;
501 501
502 running = new QGuardedPtr<QWidget> [ count ]; 502 running = new QGuardedPtr<QWidget> [ count ];
503} 503}
504 504
505/*! 505/*!
506 \internal 506 \internal
507*/ 507*/
508void Global::setDocument( QWidget* receiver, const QString& document ) 508void Global::setDocument( QWidget* receiver, const QString& document )
509{ 509{
510 Emitter emitter(receiver,document); 510 Emitter emitter(receiver,document);
511} 511}
512 512
513/*! 513/*!
514 \internal 514 \internal
515*/ 515*/
516bool Global::terminateBuiltin( const QString& n ) 516bool Global::terminateBuiltin( const QString& n )
517{ 517{
518 if (!builtin) 518 if (!builtin)
519 return FALSE; 519 return FALSE;
520 for (int i = 0; builtin[i].file; i++) { 520 for (int i = 0; builtin[i].file; i++) {
521 if ( builtin[i].file == n ) { 521 if ( builtin[i].file == n ) {
522 delete running[i]; 522 delete running[i];
523 return TRUE; 523 return TRUE;
524 } 524 }
525 } 525 }
526 return FALSE; 526 return FALSE;
527} 527}
528 528
529/*! 529/*!
530 \internal 530 \internal
531*/ 531*/
532void Global::terminate( const AppLnk* app ) 532void Global::terminate( const AppLnk* app )
533{ 533{
534 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 534 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
535 535
536#ifndef QT_NO_COP 536#ifndef QT_NO_COP
537 QCString channel = "QPE/Application/" + app->exec().utf8(); 537 QCString channel = "QPE/Application/" + app->exec().utf8();
538 if ( QCopChannel::isRegistered(channel) ) { 538 if ( QCopChannel::isRegistered(channel) ) {
539 QCopEnvelope e(channel, "quit()"); 539 QCopEnvelope e(channel, "quit()");
540 } 540 }
541#endif 541#endif
542} 542}
543 543
544/*! 544/*!
545 Low-level function to run command \a c. 545 Low-level function to run command \a c.
546 546
547 \warning Do not use this function. Use execute instead. 547 \warning Do not use this function. Use execute instead.
548 548
549 \sa execute() 549 \sa execute()
550*/ 550*/
551void Global::invoke(const QString &c) 551void Global::invoke(const QString &c)
552{ 552{
553 // Convert the command line in to a list of arguments 553 // Convert the command line in to a list of arguments
554 QStringList list = QStringList::split(QRegExp(" *"),c); 554 QStringList list = QStringList::split(QRegExp(" *"),c);
555 555
556#if !defined(QT_NO_COP) 556#if !defined(QT_NO_COP)
557 QString ap=list[0]; 557 QString ap=list[0];
558 // see if the application is already running 558 // see if the application is already running
559 // XXX should lock file /tmp/qcop-msg-ap 559 // XXX should lock file /tmp/qcop-msg-ap
560 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 560 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
561 // If the channel is already register, the app is already running, so show it. 561 // If the channel is already register, the app is already running, so show it.
562 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 562 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
563 563
564 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 564 QCopEnvelope e("QPE/System", "notBusy(QString)" );
565 e << ap; 565 e << ap;
566 return; 566 return;
567 } 567 }
568 // XXX should unlock file /tmp/qcop-msg-ap 568 // XXX should unlock file /tmp/qcop-msg-ap
569 //see if it is being started 569 //see if it is being started
570 if ( StartingAppList::isStarting( ap ) ) { 570 if ( StartingAppList::isStarting( ap ) ) {
571 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 571 QCopEnvelope e("QPE/System", "notBusy(QString)" );
572 e << ap; 572 e << ap;
573 return; 573 return;
574 } 574 }
575 575
576#endif 576#endif
577 577
578#ifdef QT_NO_QWS_MULTIPROCESS 578#ifdef QT_NO_QWS_MULTIPROCESS
579 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 579 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
580#else 580#else
581 581
582 QStrList slist; 582 QStrList slist;
583 unsigned int j; 583 unsigned int j;
584 for ( j = 0; j < list.count(); j++ ) 584 for ( j = 0; j < list.count(); j++ )
585 slist.append( list[j].utf8() ); 585 slist.append( list[j].utf8() );
586 586
587 const char **args = new (const char *)[slist.count() + 1]; 587 const char **args = new (const char *)[slist.count() + 1];
588 for ( j = 0; j < slist.count(); j++ ) 588 for ( j = 0; j < slist.count(); j++ )
589 args[j] = slist.at(j); 589 args[j] = slist.at(j);
590 args[j] = NULL; 590 args[j] = NULL;
591 591
592#if !defined(QT_NO_COP) 592#if !defined(QT_NO_COP)
593 // an attempt to show a wait... 593 // an attempt to show a wait...
594 // more logic should be used, but this will be fine for the moment... 594 // more logic should be used, but this will be fine for the moment...
595 QCopEnvelope ( "QPE/System", "busy()" ); 595 QCopEnvelope ( "QPE/System", "busy()" );
596#endif 596#endif
597 597
598#ifdef HAVE_QUICKEXEC 598#ifdef HAVE_QUICKEXEC
599 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 599 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
600 qDebug("libfile = %s", libexe.latin1() ); 600 qDebug("libfile = %s", libexe.latin1() );
601 if ( QFile::exists( libexe ) ) { 601 if ( QFile::exists( libexe ) ) {
602 qDebug("calling quickexec %s", libexe.latin1() ); 602 qDebug("calling quickexec %s", libexe.latin1() );
603 quickexecv( libexe.utf8().data(), (const char **)args ); 603 quickexecv( libexe.utf8().data(), (const char **)args );
604 } else 604 } else
605#endif 605#endif
606 { 606 {
607 char *oldpre = ::getenv ( "LD_PRELOAD" );
608
609 QString newpre = QPEApplication::qpeDir ( ) + "/lib/libpreload.so";
610 if ( QFile::exists ( newpre )) {
611 if ( oldpre && oldpre [0] )
612 newpre = newpre + ":" + oldpre;
613 ::setenv ( "LD_PRELOAD", newpre. latin1( ), 1 );
614 qDebug ( "\nPRELOADING\n" );
615 }
616
617 if ( !::vfork() ) { 607 if ( !::vfork() ) {
618 for ( int fd = 3; fd < 100; fd++ ) 608 for ( int fd = 3; fd < 100; fd++ )
619 ::close( fd ); 609 ::close( fd );
620 ::setpgid( ::getpid(), ::getppid() ); 610 ::setpgid( ::getpid(), ::getppid() );
621 // Try bindir first, so that foo/bar works too 611 // Try bindir first, so that foo/bar works too
622 ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); 612 ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args );
623 ::execvp( args[0], (char * const *)args ); 613 ::execvp( args[0], (char * const *)args );
624 _exit( -1 ); 614 _exit( -1 );
625 } 615 }
626 if ( oldpre )
627 ::setenv ( "LD_PRELOAD", oldpre, 1 );
628 else
629 ::unsetenv ( "LD_PRELOAD" );
630 } 616 }
631 StartingAppList::add( list[0] ); 617 StartingAppList::add( list[0] );
632#endif //QT_NO_QWS_MULTIPROCESS 618#endif //QT_NO_QWS_MULTIPROCESS
633} 619}
634 620
635 621
636/*! 622/*!
637 Executes the application identfied by \a c, passing \a 623 Executes the application identfied by \a c, passing \a
638 document if it isn't null. 624 document if it isn't null.
639 625
640 Note that a better approach might be to send a QCop message to the 626 Note that a better approach might be to send a QCop message to the
641 application's QPE/Application/\e{appname} channel. 627 application's QPE/Application/\e{appname} channel.
642*/ 628*/
643void Global::execute( const QString &c, const QString& document ) 629void Global::execute( const QString &c, const QString& document )
644{ 630{
645 if ( qApp->type() != QApplication::GuiServer ) { 631 if ( qApp->type() != QApplication::GuiServer ) {
646 // ask the server to do the work 632 // ask the server to do the work
647#if !defined(QT_NO_COP) 633#if !defined(QT_NO_COP)
648 if ( document.isNull() ) { 634 if ( document.isNull() ) {
649 QCopEnvelope e( "QPE/System", "execute(QString)" ); 635 QCopEnvelope e( "QPE/System", "execute(QString)" );
650 e << c; 636 e << c;
651 } else { 637 } else {
652 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 638 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
653 e << c << document; 639 e << c << document;
654 } 640 }
655#endif 641#endif
656 return; 642 return;
657 } 643 }
658 644
659 // Attempt to execute the app using a builtin class for the app first 645 // Attempt to execute the app using a builtin class for the app first
660 // else try and find it in the bin directory 646 // else try and find it in the bin directory
661 if (builtin) { 647 if (builtin) {
662 for (int i = 0; builtin[i].file; i++) { 648 for (int i = 0; builtin[i].file; i++) {
663 if ( builtin[i].file == c ) { 649 if ( builtin[i].file == c ) {
664 if ( running[i] ) { 650 if ( running[i] ) {
665 if ( !document.isNull() && builtin[i].documentary ) 651 if ( !document.isNull() && builtin[i].documentary )
666 setDocument(running[i], document); 652 setDocument(running[i], document);
667 running[i]->raise(); 653 running[i]->raise();
668 running[i]->show(); 654 running[i]->show();
669 running[i]->setActiveWindow(); 655 running[i]->setActiveWindow();
670 } else { 656 } else {
671 running[i] = builtin[i].func( builtin[i].maximized ); 657 running[i] = builtin[i].func( builtin[i].maximized );
672 } 658 }
673#ifndef QT_NO_COP 659#ifndef QT_NO_COP
674 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 660 QCopEnvelope e("QPE/System", "notBusy(QString)" );
675 e << c; // that was quick ;-) 661 e << c; // that was quick ;-)
676#endif 662#endif
677 return; 663 return;
678 } 664 }
679 } 665 }
680 } 666 }
681 667
682 //Global::invoke(c, document); 668 //Global::invoke(c, document);
683 669
684 // Convert the command line in to a list of arguments 670 // Convert the command line in to a list of arguments
685 QStringList list = QStringList::split(QRegExp(" *"),c); 671 QStringList list = QStringList::split(QRegExp(" *"),c);
686 672
687#if !defined(QT_NO_COP) 673#if !defined(QT_NO_COP)
688 QString ap=list[0]; 674 QString ap=list[0];
689 675
690 qDebug("executing %s", ap.latin1() ); 676 qDebug("executing %s", ap.latin1() );
691 677
692 /* if need be, sending a qcop message will result in an invoke, see 678 /* if need be, sending a qcop message will result in an invoke, see
693 preceeding function */ 679 preceeding function */
694 invoke( ap ); 680 invoke( ap );
695 //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 681 //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
696 if ( !document.isEmpty() ) { 682 if ( !document.isEmpty() ) {
697 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); 683 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" );
698 env << document; 684 env << document;
699 } 685 }
700#endif 686#endif
701} 687}
702 688
703/*! 689/*!
704 Returns the string \a s with the characters '\', '"', and '$' quoted 690 Returns the string \a s with the characters '\', '"', and '$' quoted
705 by a preceeding '\'. 691 by a preceeding '\'.
706 692
707 \sa stringQuote() 693 \sa stringQuote()
708*/ 694*/
709QString Global::shellQuote(const QString& s) 695QString Global::shellQuote(const QString& s)
710{ 696{
711 QString r="\""; 697 QString r="\"";
712 for (int i=0; i<(int)s.length(); i++) { 698 for (int i=0; i<(int)s.length(); i++) {
713 char c = s[i].latin1(); 699 char c = s[i].latin1();
714 switch (c) { 700 switch (c) {
715 case '\\': case '"': case '$': 701 case '\\': case '"': case '$':
716 r+="\\"; 702 r+="\\";
717 } 703 }
718 r += s[i]; 704 r += s[i];
719 } 705 }
720 r += "\""; 706 r += "\"";
721 return r; 707 return r;
722} 708}
723 709
724/*! 710/*!
725 Returns the string \a s with the characters '\' and '"' quoted by a 711 Returns the string \a s with the characters '\' and '"' quoted by a
726 preceeding '\'. 712 preceeding '\'.
727 713
728 \sa shellQuote() 714 \sa shellQuote()
729*/ 715*/
730QString Global::stringQuote(const QString& s) 716QString Global::stringQuote(const QString& s)
731{ 717{
732 QString r="\""; 718 QString r="\"";
733 for (int i=0; i<(int)s.length(); i++) { 719 for (int i=0; i<(int)s.length(); i++) {
734 char c = s[i].latin1(); 720 char c = s[i].latin1();
735 switch (c) { 721 switch (c) {
736 case '\\': case '"': 722 case '\\': case '"':
737 r+="\\"; 723 r+="\\";
738 } 724 }
739 r += s[i]; 725 r += s[i];
740 } 726 }
741 r += "\""; 727 r += "\"";
742 return r; 728 return r;
743} 729}
744 730
745/*! 731/*!
746 Finds all documents on the system's document directories which 732 Finds all documents on the system's document directories which
747 match the filter \a mimefilter, and appends the resulting DocLnk 733 match the filter \a mimefilter, and appends the resulting DocLnk
748 objects to \a folder. 734 objects to \a folder.
749*/ 735*/
750void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 736void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
751{ 737{
752 QString homedocs = QString(getenv("HOME")) + "/Documents"; 738 QString homedocs = QString(getenv("HOME")) + "/Documents";
753 DocLnkSet d(homedocs,mimefilter); 739 DocLnkSet d(homedocs,mimefilter);
754 folder->appendFrom(d); 740 folder->appendFrom(d);
755 /** let's do intellegint way of searching these files 741 /** let's do intellegint way of searching these files
756 * a) the user don't want to check mediums global 742 * a) the user don't want to check mediums global
757 * b) the user wants to check but use the global options for it 743 * b) the user wants to check but use the global options for it
758 * c) the user wants to check it but not this medium 744 * c) the user wants to check it but not this medium
759 * d) the user wants to check and this medium as well 745 * d) the user wants to check and this medium as well
760 * 746 *
761 * In all cases we need to apply a different mimefilter to 747 * In all cases we need to apply a different mimefilter to
762 * the medium. 748 * the medium.
763 * a) mimefilter.isEmpty() we need to apply the responding filter 749 * a) mimefilter.isEmpty() we need to apply the responding filter
764 * either the global or the one on the medium 750 * either the global or the one on the medium
765 * 751 *
766 * b) mimefilter is set to an application we need to find out if the 752 * b) mimefilter is set to an application we need to find out if the
767 * mimetypes are included in the mime mask of the medium 753 * mimetypes are included in the mime mask of the medium
768 */ 754 */
769 StorageInfo storage; 755 StorageInfo storage;
770 const QList<FileSystem> &fs = storage.fileSystems(); 756 const QList<FileSystem> &fs = storage.fileSystems();
771 QListIterator<FileSystem> it ( fs ); 757 QListIterator<FileSystem> it ( fs );
772 for ( ; it.current(); ++it ) { 758 for ( ; it.current(); ++it ) {
773 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 759 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
774 // this is a candidate look at the cf and see if we should search on it 760 // this is a candidate look at the cf and see if we should search on it
775 QString path = (*it)->path(); 761 QString path = (*it)->path();
776 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) 762 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) )
777 continue; 763 continue;
778 DocLnkSet ide( path, mimefilter ); 764 DocLnkSet ide( path, mimefilter );
779 folder->appendFrom(ide); 765 folder->appendFrom(ide);
780 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 766 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
781 QString path = (*it)->path() + "/Documents"; 767 QString path = (*it)->path() + "/Documents";
782 DocLnkSet ide( path, mimefilter ); 768 DocLnkSet ide( path, mimefilter );
783 folder->appendFrom(ide); 769 folder->appendFrom(ide);
784 } 770 }
785 } 771 }
786} 772}
787 773
788QStringList Global::languageList() 774QStringList Global::languageList()
789{ 775{
790 QString lang = getenv("LANG"); 776 QString lang = getenv("LANG");
791 QStringList langs; 777 QStringList langs;
792 langs.append(lang); 778 langs.append(lang);
793 int i = lang.find("."); 779 int i = lang.find(".");
794 if ( i > 0 ) 780 if ( i > 0 )
795 lang = lang.left( i ); 781 lang = lang.left( i );
796 i = lang.find( "_" ); 782 i = lang.find( "_" );
797 if ( i > 0 ) 783 if ( i > 0 )
798 langs.append(lang.left(i)); 784 langs.append(lang.left(i));
799 return langs; 785 return langs;
800} 786}
801 787
802QStringList Global::helpPath() 788QStringList Global::helpPath()
803{ 789{
804 QStringList path; 790 QStringList path;
805 QStringList langs = Global::languageList(); 791 QStringList langs = Global::languageList();
806 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 792 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
807 QString lang = *it; 793 QString lang = *it;
808 if ( !lang.isEmpty() ) 794 if ( !lang.isEmpty() )
809 path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; 795 path += QPEApplication::qpeDir() + "/help/" + lang + "/html";
810 } 796 }
811 path += QPEApplication::qpeDir() + "/pics"; 797 path += QPEApplication::qpeDir() + "/pics";
812 path += QPEApplication::qpeDir() + "/help/html"; 798 path += QPEApplication::qpeDir() + "/help/html";
813 path += QPEApplication::qpeDir() + "/docs"; 799 path += QPEApplication::qpeDir() + "/docs";
814 800
815 801
816 return path; 802 return path;
817} 803}
818 804
819 805
820#include "global.moc" 806#include "global.moc"