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