summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-10-21 09:16:20 (UTC)
committer llornkcor <llornkcor>2004-10-21 09:16:20 (UTC)
commit84b7a20c67226aa4305ad0cb7c05e2507ca0cc0e (patch) (unidiff)
treef826a49b2875e416b02dec228280c4958f25ac8b
parent8232b072180742d87a8e543b6968e9c4109c0612 (diff)
downloadopie-84b7a20c67226aa4305ad0cb7c05e2507ca0cc0e.zip
opie-84b7a20c67226aa4305ad0cb7c05e2507ca0cc0e.tar.gz
opie-84b7a20c67226aa4305ad0cb7c05e2507ca0cc0e.tar.bz2
turn off qDebug and qWarning in release mode. This should also quiet any 3rd party applications outside opie control
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 1117240..4adfc8f 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -271,1035 +271,1058 @@ public:
271 maximized = l[4].toInt(); 271 maximized = l[4].toInt();
272 272
273 return TRUE; 273 return TRUE;
274 } 274 }
275 275
276 return FALSE; 276 return FALSE;
277 } 277 }
278 278
279 279
280 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 280 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
281 { 281 {
282#ifndef Q_WS_QWS 282#ifndef Q_WS_QWS
283 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 283 QRect qt_maxWindowRect = qApp->desktop()->geometry();
284#endif 284#endif
285 int maxX = qt_maxWindowRect.width(); 285 int maxX = qt_maxWindowRect.width();
286 int maxY = qt_maxWindowRect.height(); 286 int maxY = qt_maxWindowRect.height();
287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
289 289
290 // total window size is not allowed to be larger than desktop window size 290 // total window size is not allowed to be larger than desktop window size
291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
292 return FALSE; 292 return FALSE;
293 293
294 if ( wWidth > maxX ) { 294 if ( wWidth > maxX ) {
295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
296 wWidth = maxX; 296 wWidth = maxX;
297 } 297 }
298 298
299 if ( wHeight > maxY ) { 299 if ( wHeight > maxY ) {
300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
301 wHeight = maxY; 301 wHeight = maxY;
302 } 302 }
303 303
304 // any smaller than this and the maximize/close/help buttons will be overlapping 304 // any smaller than this and the maximize/close/help buttons will be overlapping
305 if ( wWidth < 80 || wHeight < 60 ) 305 if ( wWidth < 80 || wHeight < 60 )
306 return FALSE; 306 return FALSE;
307 307
308 if ( p.x() < 0 ) 308 if ( p.x() < 0 )
309 p.setX(0); 309 p.setX(0);
310 if ( p.y() < 0 ) 310 if ( p.y() < 0 )
311 p.setY(0); 311 p.setY(0);
312 312
313 if ( p.x() + wWidth > maxX ) 313 if ( p.x() + wWidth > maxX )
314 p.setX( maxX - wWidth ); 314 p.setX( maxX - wWidth );
315 if ( p.y() + wHeight > maxY ) 315 if ( p.y() + wHeight > maxY )
316 p.setY( maxY - wHeight ); 316 p.setY( maxY - wHeight );
317 317
318 return TRUE; 318 return TRUE;
319 } 319 }
320 320
321 static void store_widget_rect(QWidget *w, QString &app) 321 static void store_widget_rect(QWidget *w, QString &app)
322 { 322 {
323 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 323 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
324 if ( qApp->desktop()->width() <= 350 ) 324 if ( qApp->desktop()->width() <= 350 )
325 return; 325 return;
326 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 326 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
327 // get the non-maximized version, so we have to do it the hard way ) 327 // get the non-maximized version, so we have to do it the hard way )
328 int offsetX = w->x() - w->geometry().left(); 328 int offsetX = w->x() - w->geometry().left();
329 int offsetY = w->y() - w->geometry().top(); 329 int offsetY = w->y() - w->geometry().top();
330 330
331 QRect r; 331 QRect r;
332 if ( w->isMaximized() ) 332 if ( w->isMaximized() )
333 r = ( (HackWidget *) w)->normalGeometry(); 333 r = ( (HackWidget *) w)->normalGeometry();
334 else 334 else
335 r = w->geometry(); 335 r = w->geometry();
336 336
337 // Stores the window placement as pos(), size() (due to the offset mapping) 337 // Stores the window placement as pos(), size() (due to the offset mapping)
338 Config cfg( "qpe" ); 338 Config cfg( "qpe" );
339 cfg.setGroup("ApplicationPositions"); 339 cfg.setGroup("ApplicationPositions");
340 QString s; 340 QString s;
341 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 341 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
342 cfg.writeEntry( app, s ); 342 cfg.writeEntry( app, s );
343 } 343 }
344 344
345 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 345 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
346 { 346 {
347 /* 347 /*
348 // This works but disable it for now until it is safe to apply 348 // This works but disable it for now until it is safe to apply
349 // What is does is scan the .desktop files of all the apps for 349 // What is does is scan the .desktop files of all the apps for
350 // the applnk that has the corresponding argv[0] as this program 350 // the applnk that has the corresponding argv[0] as this program
351 // then it uses the name stored in the .desktop file as the caption 351 // then it uses the name stored in the .desktop file as the caption
352 // for the main widget. This saves duplicating translations for 352 // for the main widget. This saves duplicating translations for
353 // the app name in the program and in the .desktop files. 353 // the app name in the program and in the .desktop files.
354 354
355 AppLnkSet apps( appsPath ); 355 AppLnkSet apps( appsPath );
356 356
357 QList<AppLnk> appsList = apps.children(); 357 QList<AppLnk> appsList = apps.children();
358 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 358 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
359 if ( (*it)->exec() == appName ) { 359 if ( (*it)->exec() == appName ) {
360 mw->setCaption( (*it)->name() ); 360 mw->setCaption( (*it)->name() );
361 return TRUE; 361 return TRUE;
362 } 362 }
363 } 363 }
364 */ 364 */
365 return FALSE; 365 return FALSE;
366 } 366 }
367 367
368 368
369 void show(QWidget* mw, bool nomax) 369 void show(QWidget* mw, bool nomax)
370 { 370 {
371 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 371 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
372 nomaximize = nomax; 372 nomaximize = nomax;
373 qpe_main_widget = mw; 373 qpe_main_widget = mw;
374 qcopQok = TRUE; 374 qcopQok = TRUE;
375#ifndef QT_NO_COP 375#ifndef QT_NO_COP
376 376
377 sendQCopQ(); 377 sendQCopQ();
378#endif 378#endif
379 379
380 if ( preloaded ) { 380 if ( preloaded ) {
381 if (forceshow) 381 if (forceshow)
382 show_mx(mw, nomax, appName); 382 show_mx(mw, nomax, appName);
383 } 383 }
384 else if ( keep_running ) { 384 else if ( keep_running ) {
385 show_mx(mw, nomax, appName); 385 show_mx(mw, nomax, appName);
386 } 386 }
387 } 387 }
388 388
389 void loadTextCodecs() 389 void loadTextCodecs()
390 { 390 {
391 QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; 391 QString path = QPEApplication::qpeDir() + "plugins/textcodecs";
392#ifdef Q_OS_MACX 392#ifdef Q_OS_MACX
393 QDir dir( path, "lib*.dylib" ); 393 QDir dir( path, "lib*.dylib" );
394#else 394#else
395 QDir dir( path, "lib*.so" ); 395 QDir dir( path, "lib*.so" );
396#endif 396#endif
397 QStringList list; 397 QStringList list;
398 if ( dir. exists ( )) 398 if ( dir. exists ( ))
399 list = dir.entryList(); 399 list = dir.entryList();
400 QStringList::Iterator it; 400 QStringList::Iterator it;
401 for ( it = list.begin(); it != list.end(); ++it ) { 401 for ( it = list.begin(); it != list.end(); ++it ) {
402 TextCodecInterface *iface = 0; 402 TextCodecInterface *iface = 0;
403 QLibrary *lib = new QLibrary( path + "/" + *it ); 403 QLibrary *lib = new QLibrary( path + "/" + *it );
404 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 404 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
405 QValueList<int> mibs = iface->mibEnums(); 405 QValueList<int> mibs = iface->mibEnums();
406 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 406 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
407 (void)iface->createForMib(*i); 407 (void)iface->createForMib(*i);
408 // ### it exists now; need to remember if we can delete it 408 // ### it exists now; need to remember if we can delete it
409 } 409 }
410 } 410 }
411 else { 411 else {
412 lib->unload(); 412 lib->unload();
413 delete lib; 413 delete lib;
414 } 414 }
415 } 415 }
416 } 416 }
417 417
418 void loadImageCodecs() 418 void loadImageCodecs()
419 { 419 {
420 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; 420 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs";
421#ifdef Q_OS_MACX 421#ifdef Q_OS_MACX
422 QDir dir( path, "lib*.dylib" ); 422 QDir dir( path, "lib*.dylib" );
423#else 423#else
424 QDir dir( path, "lib*.so" ); 424 QDir dir( path, "lib*.so" );
425#endif 425#endif
426 QStringList list; 426 QStringList list;
427 if ( dir. exists ( )) 427 if ( dir. exists ( ))
428 list = dir.entryList(); 428 list = dir.entryList();
429 QStringList::Iterator it; 429 QStringList::Iterator it;
430 for ( it = list.begin(); it != list.end(); ++it ) { 430 for ( it = list.begin(); it != list.end(); ++it ) {
431 ImageCodecInterface *iface = 0; 431 ImageCodecInterface *iface = 0;
432 QLibrary *lib = new QLibrary( path + "/" + *it ); 432 QLibrary *lib = new QLibrary( path + "/" + *it );
433 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 433 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
434 QStringList formats = iface->keys(); 434 QStringList formats = iface->keys();
435 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 435 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
436 (void)iface->installIOHandler(*i); 436 (void)iface->installIOHandler(*i);
437 // ### it exists now; need to remember if we can delete it 437 // ### it exists now; need to remember if we can delete it
438 } 438 }
439 } 439 }
440 else { 440 else {
441 lib->unload(); 441 lib->unload();
442 delete lib; 442 delete lib;
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447}; 447};
448 448
449class ResourceMimeFactory : public QMimeSourceFactory 449class ResourceMimeFactory : public QMimeSourceFactory
450{ 450{
451public: 451public:
452 ResourceMimeFactory() : resImage( 0 ) 452 ResourceMimeFactory() : resImage( 0 )
453 { 453 {
454 setFilePath( Global::helpPath() ); 454 setFilePath( Global::helpPath() );
455 setExtensionType( "html", "text/html;charset=UTF-8" ); 455 setExtensionType( "html", "text/html;charset=UTF-8" );
456 } 456 }
457 ~ResourceMimeFactory() { 457 ~ResourceMimeFactory() {
458 delete resImage; 458 delete resImage;
459 } 459 }
460 460
461 const QMimeSource* data( const QString& abs_name ) const 461 const QMimeSource* data( const QString& abs_name ) const
462 { 462 {
463 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 463 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
464 if ( !r ) { 464 if ( !r ) {
465 int sl = abs_name.length(); 465 int sl = abs_name.length();
466 do { 466 do {
467 sl = abs_name.findRev( '/', sl - 1 ); 467 sl = abs_name.findRev( '/', sl - 1 );
468 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 468 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
469 int dot = name.findRev( '.' ); 469 int dot = name.findRev( '.' );
470 if ( dot >= 0 ) 470 if ( dot >= 0 )
471 name = name.left( dot ); 471 name = name.left( dot );
472 QImage img = Resource::loadImage( name ); 472 QImage img = Resource::loadImage( name );
473 if ( !img.isNull() ) { 473 if ( !img.isNull() ) {
474 delete resImage; 474 delete resImage;
475 resImage = new QImageDrag( img ); 475 resImage = new QImageDrag( img );
476 r = resImage; 476 r = resImage;
477 } 477 }
478 } 478 }
479 while ( !r && sl > 0 ); 479 while ( !r && sl > 0 );
480 } 480 }
481 return r; 481 return r;
482 } 482 }
483private: 483private:
484 mutable QImageDrag *resImage; 484 mutable QImageDrag *resImage;
485}; 485};
486 486
487static int& hack(int& i) 487static int& hack(int& i)
488{ 488{
489#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 489#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
490 // These should be created, but aren't in Qt 2.3.0 490 // These should be created, but aren't in Qt 2.3.0
491 (void)new QUtf8Codec; 491 (void)new QUtf8Codec;
492 (void)new QUtf16Codec; 492 (void)new QUtf16Codec;
493#endif 493#endif
494 return i; 494 return i;
495} 495}
496 496
497static int muted = 0; 497static int muted = 0;
498static int micMuted = 0; 498static int micMuted = 0;
499 499
500static void setVolume( int t = 0, int percent = -1 ) 500static void setVolume( int t = 0, int percent = -1 )
501{ 501{
502 switch ( t ) { 502 switch ( t ) {
503 case 0: { 503 case 0: {
504 Config cfg( "qpe" ); 504 Config cfg( "qpe" );
505 cfg.setGroup( "Volume" ); 505 cfg.setGroup( "Volume" );
506 if ( percent < 0 ) 506 if ( percent < 0 )
507 percent = cfg.readNumEntry( "VolumePercent", 50 ); 507 percent = cfg.readNumEntry( "VolumePercent", 50 );
508#ifndef QT_NO_SOUND 508#ifndef QT_NO_SOUND
509 int fd = 0; 509 int fd = 0;
510#ifdef QT_QWS_DEVFS 510#ifdef QT_QWS_DEVFS
511 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 511 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
512#else 512#else
513 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 513 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
514#endif 514#endif
515 int vol = muted ? 0 : percent; 515 int vol = muted ? 0 : percent;
516 // set both channels to same volume 516 // set both channels to same volume
517 vol |= vol << 8; 517 vol |= vol << 8;
518 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 518 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
519 ::close( fd ); 519 ::close( fd );
520 } 520 }
521#endif 521#endif
522 } 522 }
523 break; 523 break;
524 } 524 }
525} 525}
526 526
527static void setMic( int t = 0, int percent = -1 ) 527static void setMic( int t = 0, int percent = -1 )
528{ 528{
529 switch ( t ) { 529 switch ( t ) {
530 case 0: { 530 case 0: {
531 Config cfg( "qpe" ); 531 Config cfg( "qpe" );
532 cfg.setGroup( "Volume" ); 532 cfg.setGroup( "Volume" );
533 if ( percent < 0 ) 533 if ( percent < 0 )
534 percent = cfg.readNumEntry( "Mic", 50 ); 534 percent = cfg.readNumEntry( "Mic", 50 );
535 535
536#ifndef QT_NO_SOUND 536#ifndef QT_NO_SOUND
537 int fd = 0; 537 int fd = 0;
538 int mic = micMuted ? 0 : percent; 538 int mic = micMuted ? 0 : percent;
539#ifdef QT_QWS_DEVFS 539#ifdef QT_QWS_DEVFS
540 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 540 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
541#else 541#else
542 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 542 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
543#endif 543#endif
544 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 544 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
545 ::close( fd ); 545 ::close( fd );
546 } 546 }
547#endif 547#endif
548 } 548 }
549 break; 549 break;
550 } 550 }
551} 551}
552 552
553 553
554static void setBass( int t = 0, int percent = -1 ) 554static void setBass( int t = 0, int percent = -1 )
555{ 555{
556 switch ( t ) { 556 switch ( t ) {
557 case 0: { 557 case 0: {
558 Config cfg( "qpe" ); 558 Config cfg( "qpe" );
559 cfg.setGroup( "Volume" ); 559 cfg.setGroup( "Volume" );
560 if ( percent < 0 ) 560 if ( percent < 0 )
561 percent = cfg.readNumEntry( "BassPercent", 50 ); 561 percent = cfg.readNumEntry( "BassPercent", 50 );
562 562
563#ifndef QT_NO_SOUND 563#ifndef QT_NO_SOUND
564 int fd = 0; 564 int fd = 0;
565 int bass = percent; 565 int bass = percent;
566#ifdef QT_QWS_DEVFS 566#ifdef QT_QWS_DEVFS
567 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 567 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
568#else 568#else
569 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 569 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
570#endif 570#endif
571 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 571 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
572 ::close( fd ); 572 ::close( fd );
573 } 573 }
574#endif 574#endif
575 } 575 }
576 break; 576 break;
577 } 577 }
578} 578}
579 579
580 580
581static void setTreble( int t = 0, int percent = -1 ) 581static void setTreble( int t = 0, int percent = -1 )
582{ 582{
583 switch ( t ) { 583 switch ( t ) {
584 case 0: { 584 case 0: {
585 Config cfg( "qpe" ); 585 Config cfg( "qpe" );
586 cfg.setGroup( "Volume" ); 586 cfg.setGroup( "Volume" );
587 if ( percent < 0 ) 587 if ( percent < 0 )
588 percent = cfg.readNumEntry( "TreblePercent", 50 ); 588 percent = cfg.readNumEntry( "TreblePercent", 50 );
589 589
590#ifndef QT_NO_SOUND 590#ifndef QT_NO_SOUND
591 int fd = 0; 591 int fd = 0;
592 int treble = percent; 592 int treble = percent;
593#ifdef QT_QWS_DEVFS 593#ifdef QT_QWS_DEVFS
594 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 594 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
595#else 595#else
596 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 596 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
597#endif 597#endif
598 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 598 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
599 ::close( fd ); 599 ::close( fd );
600 } 600 }
601#endif 601#endif
602 } 602 }
603 break; 603 break;
604 } 604 }
605} 605}
606 606
607 607
608/** 608/**
609 \class QPEApplication 609 \class QPEApplication
610 \brief The QPEApplication class implements various system services 610 \brief The QPEApplication class implements various system services
611 that are available to all Qtopia applications. 611 that are available to all Qtopia applications.
612 612
613 Simply by using QPEApplication instead of QApplication, a standard Qt 613 Simply by using QPEApplication instead of QApplication, a standard Qt
614 application becomes a Qtopia application. It automatically follows 614 application becomes a Qtopia application. It automatically follows
615 style changes, quits and raises, and in the 615 style changes, quits and raises, and in the
616 case of \link docwidget.html document-oriented\endlink applications, 616 case of \link docwidget.html document-oriented\endlink applications,
617 changes the currently displayed document in response to the environment. 617 changes the currently displayed document in response to the environment.
618 618
619 To create a \link docwidget.html document-oriented\endlink 619 To create a \link docwidget.html document-oriented\endlink
620 application use showMainDocumentWidget(); to create a 620 application use showMainDocumentWidget(); to create a
621 non-document-oriented application use showMainWidget(). The 621 non-document-oriented application use showMainWidget(). The
622 keepRunning() function indicates whether the application will 622 keepRunning() function indicates whether the application will
623 continue running after it's processed the last \link qcop.html 623 continue running after it's processed the last \link qcop.html
624 QCop\endlink message. This can be changed using setKeepRunning(). 624 QCop\endlink message. This can be changed using setKeepRunning().
625 625
626 A variety of signals are emitted when certain events occur, for 626 A variety of signals are emitted when certain events occur, for
627 example, timeChanged(), clockChanged(), weekChanged(), 627 example, timeChanged(), clockChanged(), weekChanged(),
628 dateFormatChanged() and volumeChanged(). If the application receives 628 dateFormatChanged() and volumeChanged(). If the application receives
629 a \link qcop.html QCop\endlink message on the application's 629 a \link qcop.html QCop\endlink message on the application's
630 QPE/Application/\e{appname} channel, the appMessage() signal is 630 QPE/Application/\e{appname} channel, the appMessage() signal is
631 emitted. There are also flush() and reload() signals, which 631 emitted. There are also flush() and reload() signals, which
632 are emitted when synching begins and ends respectively - upon these 632 are emitted when synching begins and ends respectively - upon these
633 signals, the application should save and reload any data 633 signals, the application should save and reload any data
634 files that are involved in synching. Most of these signals will initially 634 files that are involved in synching. Most of these signals will initially
635 be received and unfiltered through the appMessage() signal. 635 be received and unfiltered through the appMessage() signal.
636 636
637 This class also provides a set of useful static functions. The 637 This class also provides a set of useful static functions. The
638 qpeDir() and documentDir() functions return the respective paths. 638 qpeDir() and documentDir() functions return the respective paths.
639 The grabKeyboard() and ungrabKeyboard() functions are used to 639 The grabKeyboard() and ungrabKeyboard() functions are used to
640 control whether the application takes control of the device's 640 control whether the application takes control of the device's
641 physical buttons (e.g. application launch keys). The stylus' mode of 641 physical buttons (e.g. application launch keys). The stylus' mode of
642 operation is set with setStylusOperation() and retrieved with 642 operation is set with setStylusOperation() and retrieved with
643 stylusOperation(). There are also setInputMethodHint() and 643 stylusOperation(). There are also setInputMethodHint() and
644 inputMethodHint() functions. 644 inputMethodHint() functions.
645 645
646 \ingroup qtopiaemb 646 \ingroup qtopiaemb
647*/ 647*/
648 648
649/*! 649/*!
650 \fn void QPEApplication::clientMoused() 650 \fn void QPEApplication::clientMoused()
651 651
652 \internal 652 \internal
653*/ 653*/
654 654
655/*! 655/*!
656 \fn void QPEApplication::timeChanged(); 656 \fn void QPEApplication::timeChanged();
657 This signal is emitted when the time changes outside the normal 657 This signal is emitted when the time changes outside the normal
658 passage of time, i.e. if the time is set backwards or forwards. 658 passage of time, i.e. if the time is set backwards or forwards.
659*/ 659*/
660 660
661/*! 661/*!
662 \fn void QPEApplication::clockChanged( bool ampm ); 662 \fn void QPEApplication::clockChanged( bool ampm );
663 663
664 This signal is emitted when the user changes the clock's style. If 664 This signal is emitted when the user changes the clock's style. If
665 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 665 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
666 they want a 24-hour clock. 666 they want a 24-hour clock.
667*/ 667*/
668 668
669/*! 669/*!
670 \fn void QPEApplication::volumeChanged( bool muted ) 670 \fn void QPEApplication::volumeChanged( bool muted )
671 671
672 This signal is emitted whenever the mute state is changed. If \a 672 This signal is emitted whenever the mute state is changed. If \a
673 muted is TRUE, then sound output has been muted. 673 muted is TRUE, then sound output has been muted.
674*/ 674*/
675 675
676/*! 676/*!
677 \fn void QPEApplication::weekChanged( bool startOnMonday ) 677 \fn void QPEApplication::weekChanged( bool startOnMonday )
678 678
679 This signal is emitted if the week start day is changed. If \a 679 This signal is emitted if the week start day is changed. If \a
680 startOnMonday is TRUE then the first day of the week is Monday; if 680 startOnMonday is TRUE then the first day of the week is Monday; if
681 \a startOnMonday is FALSE then the first day of the week is 681 \a startOnMonday is FALSE then the first day of the week is
682 Sunday. 682 Sunday.
683*/ 683*/
684 684
685/*! 685/*!
686 \fn void QPEApplication::dateFormatChanged(DateFormat) 686 \fn void QPEApplication::dateFormatChanged(DateFormat)
687 687
688 This signal is emitted whenever the date format is changed. 688 This signal is emitted whenever the date format is changed.
689*/ 689*/
690 690
691/*! 691/*!
692 \fn void QPEApplication::flush() 692 \fn void QPEApplication::flush()
693 693
694 ### 694 ###
695*/ 695*/
696 696
697/*! 697/*!
698 \fn void QPEApplication::reload() 698 \fn void QPEApplication::reload()
699 699
700*/ 700*/
701 701
702 702
703 703
704void QPEApplication::processQCopFile() 704void QPEApplication::processQCopFile()
705{ 705{
706 QString qcopfn("/tmp/qcop-msg-"); 706 QString qcopfn("/tmp/qcop-msg-");
707 qcopfn += d->appName; // append command name 707 qcopfn += d->appName; // append command name
708 708
709 QFile f(qcopfn); 709 QFile f(qcopfn);
710 if ( f.open(IO_ReadWrite) ) { 710 if ( f.open(IO_ReadWrite) ) {
711#ifndef Q_OS_WIN32 711#ifndef Q_OS_WIN32
712 flock(f.handle(), LOCK_EX); 712 flock(f.handle(), LOCK_EX);
713#endif 713#endif
714 QDataStream ds(&f); 714 QDataStream ds(&f);
715 QCString channel, message; 715 QCString channel, message;
716 QByteArray data; 716 QByteArray data;
717 while(!ds.atEnd()) { 717 while(!ds.atEnd()) {
718 ds >> channel >> message >> data; 718 ds >> channel >> message >> data;
719 d->enqueueQCop(channel,message,data); 719 d->enqueueQCop(channel,message,data);
720 } 720 }
721 ::ftruncate(f.handle(), 0); 721 ::ftruncate(f.handle(), 0);
722#ifndef Q_OS_WIN32 722#ifndef Q_OS_WIN32
723 f.flush(); 723 f.flush();
724 flock(f.handle(), LOCK_UN); 724 flock(f.handle(), LOCK_UN);
725#endif 725#endif
726 } 726 }
727#endif 727#endif
728} 728}
729 729
730 730
731/*! 731/*!
732 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 732 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
733 733
734 This signal is emitted when a message is received on this 734 This signal is emitted when a message is received on this
735 application's QPE/Application/<i>appname</i> \link qcop.html 735 application's QPE/Application/<i>appname</i> \link qcop.html
736 QCop\endlink channel. 736 QCop\endlink channel.
737 737
738 The slot to which you connect this signal uses \a msg and \a data 738 The slot to which you connect this signal uses \a msg and \a data
739 in the following way: 739 in the following way:
740 740
741\code 741\code
742 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 742 void MyWidget::receive( const QCString& msg, const QByteArray& data )
743 { 743 {
744 QDataStream stream( data, IO_ReadOnly ); 744 QDataStream stream( data, IO_ReadOnly );
745 if ( msg == "someMessage(int,int,int)" ) { 745 if ( msg == "someMessage(int,int,int)" ) {
746 int a,b,c; 746 int a,b,c;
747 stream >> a >> b >> c; 747 stream >> a >> b >> c;
748 ... 748 ...
749 } else if ( msg == "otherMessage(QString)" ) { 749 } else if ( msg == "otherMessage(QString)" ) {
750 ... 750 ...
751 } 751 }
752 } 752 }
753\endcode 753\endcode
754 754
755 \sa qcop.html 755 \sa qcop.html
756 Note that messages received here may be processed by qpe application 756 Note that messages received here may be processed by qpe application
757 and emitted as signals, such as flush() and reload(). 757 and emitted as signals, such as flush() and reload().
758*/ 758*/
759 759
760#ifndef QT_NO_TRANSLATION 760#ifndef QT_NO_TRANSLATION
761static void qtopia_loadTranslations( const QStringList& qms ) 761static void qtopia_loadTranslations( const QStringList& qms )
762{ 762{
763 QStringList langs = Global::languageList(); 763 QStringList langs = Global::languageList();
764 764
765 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 765 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
766 QString lang = *it; 766 QString lang = *it;
767 767
768 QTranslator * trans; 768 QTranslator * trans;
769 QString tfn; 769 QString tfn;
770 770
771 for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { 771 for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) {
772 trans = new QTranslator(qApp); 772 trans = new QTranslator(qApp);
773 tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; 773 tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm";
774 if ( trans->load( tfn )) 774 if ( trans->load( tfn ))
775 qApp->installTranslator( trans ); 775 qApp->installTranslator( trans );
776 else 776 else
777 delete trans; 777 delete trans;
778 } 778 }
779 } 779 }
780} 780}
781#endif 781#endif
782 782
783/*
784 Turn off qDebug in release mode
785 */
786static void qtopiaMsgHandler(QtMsgType type, const char* msg)
787{
788 switch ( type ) {
789 case QtDebugMsg:
790#ifdef QT_DEBUG
791 fprintf( stderr, "Debug: %s\n", msg );
792#endif
793 break;
794 case QtWarningMsg:
795#ifdef QT_DEBUG
796 fprintf( stderr, "Warning: %s\n", msg );
797#endif
798 break;
799 case QtFatalMsg:
800 fprintf( stderr, "Fatal: %s\n", msg );
801 abort();
802 }
803}
804
783/*! 805/*!
784 Constructs a QPEApplication just as you would construct 806 Constructs a QPEApplication just as you would construct
785 a QApplication, passing \a argc, \a argv, and \a t. 807 a QApplication, passing \a argc, \a argv, and \a t.
786 808
787 For applications, \a t should be the default, GuiClient. Only 809 For applications, \a t should be the default, GuiClient. Only
788 the Qtopia server passes GuiServer. 810 the Qtopia server passes GuiServer.
789*/ 811*/
790QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 812QPEApplication::QPEApplication( int & argc, char **argv, Type t )
791 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 813 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
792{ 814{
793 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 815 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
816 qInstallMsgHandler(qtopiaMsgHandler);
794 817
795 d = new QPEApplicationData; 818 d = new QPEApplicationData;
796 d->loadTextCodecs(); 819 d->loadTextCodecs();
797 d->loadImageCodecs(); 820 d->loadImageCodecs();
798 821
799 setFont( QFont( d->fontFamily, d->fontSize ) ); 822 setFont( QFont( d->fontFamily, d->fontSize ) );
800 AppLnk::setSmallIconSize( d->smallIconSize ); 823 AppLnk::setSmallIconSize( d->smallIconSize );
801 AppLnk::setBigIconSize( d->bigIconSize ); 824 AppLnk::setBigIconSize( d->bigIconSize );
802 825
803 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 826 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
804 827
805 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 828 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
806 829
807 830
808 sysChannel = new QCopChannel( "QPE/System", this ); 831 sysChannel = new QCopChannel( "QPE/System", this );
809 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 832 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
810 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); 833 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
811 834
812/* COde now in initapp */ 835/* COde now in initapp */
813#if 0 836#if 0
814#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 837#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
815 838
816 QString qcopfn( "/tmp/qcop-msg-" ); 839 QString qcopfn( "/tmp/qcop-msg-" );
817 qcopfn += QString( argv[ 0 ] ); // append command name 840 qcopfn += QString( argv[ 0 ] ); // append command name
818 841
819 QFile f( qcopfn ); 842 QFile f( qcopfn );
820 if ( f.open( IO_ReadOnly ) ) { 843 if ( f.open( IO_ReadOnly ) ) {
821 flock( f.handle(), LOCK_EX ); 844 flock( f.handle(), LOCK_EX );
822 } 845 }
823 846
824 847
825 848
826 QCString channel = QCString( argv[ 0 ] ); 849 QCString channel = QCString( argv[ 0 ] );
827 channel.replace( QRegExp( ".*/" ), "" ); 850 channel.replace( QRegExp( ".*/" ), "" );
828 d->appName = channel; 851 d->appName = channel;
829 channel = "QPE/Application/" + channel; 852 channel = "QPE/Application/" + channel;
830 pidChannel = new QCopChannel( channel, this ); 853 pidChannel = new QCopChannel( channel, this );
831 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 854 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
832 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 855 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
833 856
834 if ( f.isOpen() ) { 857 if ( f.isOpen() ) {
835 d->keep_running = FALSE; 858 d->keep_running = FALSE;
836 QDataStream ds( &f ); 859 QDataStream ds( &f );
837 QCString channel, message; 860 QCString channel, message;
838 QByteArray data; 861 QByteArray data;
839 while ( !ds.atEnd() ) { 862 while ( !ds.atEnd() ) {
840 ds >> channel >> message >> data; 863 ds >> channel >> message >> data;
841 d->enqueueQCop( channel, message, data ); 864 d->enqueueQCop( channel, message, data );
842 } 865 }
843 866
844 flock( f.handle(), LOCK_UN ); 867 flock( f.handle(), LOCK_UN );
845 f.close(); 868 f.close();
846 f.remove(); 869 f.remove();
847 } 870 }
848 871
849 for ( int a = 0; a < argc; a++ ) { 872 for ( int a = 0; a < argc; a++ ) {
850 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 873 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
851 argv[ a ] = argv[ a + 1 ]; 874 argv[ a ] = argv[ a + 1 ];
852 a++; 875 a++;
853 d->preloaded = TRUE; 876 d->preloaded = TRUE;
854 argc -= 1; 877 argc -= 1;
855 } 878 }
856 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 879 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
857 argv[ a ] = argv[ a + 1 ]; 880 argv[ a ] = argv[ a + 1 ];
858 a++; 881 a++;
859 d->preloaded = TRUE; 882 d->preloaded = TRUE;
860 d->forceshow = TRUE; 883 d->forceshow = TRUE;
861 argc -= 1; 884 argc -= 1;
862 } 885 }
863 } 886 }
864 887
865 /* overide stored arguments */ 888 /* overide stored arguments */
866 setArgs( argc, argv ); 889 setArgs( argc, argv );
867 890
868#endif 891#endif
869#else 892#else
870 initApp( argc, argv ); 893 initApp( argc, argv );
871#endif 894#endif
872#ifdef Q_WS_QWS 895#ifdef Q_WS_QWS
873 /* load the font renderer factories */ 896 /* load the font renderer factories */
874 FontDatabase::loadRenderers(); 897 FontDatabase::loadRenderers();
875#endif 898#endif
876#ifndef QT_NO_TRANSLATION 899#ifndef QT_NO_TRANSLATION
877 QStringList qms; 900 QStringList qms;
878 qms << "libqpe"; 901 qms << "libqpe";
879 qms << "libopie"; 902 qms << "libopie";
880 qms << d->appName; 903 qms << d->appName;
881 904
882 qtopia_loadTranslations(qms); 905 qtopia_loadTranslations(qms);
883#endif 906#endif
884 907
885 applyStyle(); 908 applyStyle();
886 909
887 if ( type() == GuiServer ) { 910 if ( type() == GuiServer ) {
888 setVolume(); 911 setVolume();
889 } 912 }
890 913
891 installEventFilter( this ); 914 installEventFilter( this );
892 915
893 QPEMenuToolFocusManager::initialize(); 916 QPEMenuToolFocusManager::initialize();
894 917
895#ifdef QT_NO_QWS_CURSOR 918#ifdef QT_NO_QWS_CURSOR
896 // if we have no cursor, probably don't want tooltips 919 // if we have no cursor, probably don't want tooltips
897 QToolTip::setEnabled( FALSE ); 920 QToolTip::setEnabled( FALSE );
898#endif 921#endif
899} 922}
900 923
901 924
902#ifdef QTOPIA_INTERNAL_INITAPP 925#ifdef QTOPIA_INTERNAL_INITAPP
903void QPEApplication::initApp( int argc, char **argv ) 926void QPEApplication::initApp( int argc, char **argv )
904{ 927{
905 delete pidChannel; 928 delete pidChannel;
906 d->keep_running = TRUE; 929 d->keep_running = TRUE;
907 d->preloaded = FALSE; 930 d->preloaded = FALSE;
908 d->forceshow = FALSE; 931 d->forceshow = FALSE;
909 932
910 QCString channel = QCString(argv[0]); 933 QCString channel = QCString(argv[0]);
911 934
912 channel.replace(QRegExp(".*/"),""); 935 channel.replace(QRegExp(".*/"),"");
913 d->appName = channel; 936 d->appName = channel;
914 937
915#ifndef QT_NO_TRANSLATION 938#ifndef QT_NO_TRANSLATION
916 qtopia_loadTranslations( QStringList()<<channel ); 939 qtopia_loadTranslations( QStringList()<<channel );
917#endif 940#endif
918 941
919 #if QT_VERSION > 235 942 #if QT_VERSION > 235
920 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 943 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
921 #endif 944 #endif
922 945
923 channel = "QPE/Application/" + channel; 946 channel = "QPE/Application/" + channel;
924 pidChannel = new QCopChannel( channel, this); 947 pidChannel = new QCopChannel( channel, this);
925 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 948 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
926 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 949 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
927 950
928 951
929 952
930 processQCopFile(); 953 processQCopFile();
931 d->keep_running = d->qcopq.isEmpty(); 954 d->keep_running = d->qcopq.isEmpty();
932 955
933 for (int a=0; a<argc; a++) { 956 for (int a=0; a<argc; a++) {
934 if ( qstrcmp(argv[a],"-preload")==0 ) { 957 if ( qstrcmp(argv[a],"-preload")==0 ) {
935 argv[a] = argv[a+1]; 958 argv[a] = argv[a+1];
936 a++; 959 a++;
937 d->preloaded = TRUE; 960 d->preloaded = TRUE;
938 argc-=1; 961 argc-=1;
939 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 962 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
940 argv[a] = argv[a+1]; 963 argv[a] = argv[a+1];
941 a++; 964 a++;
942 d->preloaded = TRUE; 965 d->preloaded = TRUE;
943 d->forceshow = TRUE; 966 d->forceshow = TRUE;
944 argc-=1; 967 argc-=1;
945 } 968 }
946 } 969 }
947 970
948 /* overide stored arguments */ 971 /* overide stored arguments */
949 setArgs(argc, argv); 972 setArgs(argc, argv);
950} 973}
951#endif 974#endif
952 975
953 976
954static QPtrDict<void>* inputMethodDict = 0; 977static QPtrDict<void>* inputMethodDict = 0;
955static void createInputMethodDict() 978static void createInputMethodDict()
956{ 979{
957 if ( !inputMethodDict ) 980 if ( !inputMethodDict )
958 inputMethodDict = new QPtrDict<void>; 981 inputMethodDict = new QPtrDict<void>;
959} 982}
960 983
961/*! 984/*!
962 Returns the currently set hint to the system as to whether 985 Returns the currently set hint to the system as to whether
963 widget \a w has any use for text input methods. 986 widget \a w has any use for text input methods.
964 987
965 988
966 \sa setInputMethodHint() InputMethodHint 989 \sa setInputMethodHint() InputMethodHint
967*/ 990*/
968QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 991QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
969{ 992{
970 if ( inputMethodDict && w ) 993 if ( inputMethodDict && w )
971 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 994 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
972 return Normal; 995 return Normal;
973} 996}
974 997
975/*! 998/*!
976 \enum QPEApplication::InputMethodHint 999 \enum QPEApplication::InputMethodHint
977 1000
978 \value Normal the application sometimes needs text input (the default). 1001 \value Normal the application sometimes needs text input (the default).
979 \value AlwaysOff the application never needs text input. 1002 \value AlwaysOff the application never needs text input.
980 \value AlwaysOn the application always needs text input. 1003 \value AlwaysOn the application always needs text input.
981*/ 1004*/
982 1005
983/*! 1006/*!
984 Hints to the system that widget \a w has use for text input methods 1007 Hints to the system that widget \a w has use for text input methods
985 as specified by \a mode. 1008 as specified by \a mode.
986 1009
987 \sa inputMethodHint() InputMethodHint 1010 \sa inputMethodHint() InputMethodHint
988*/ 1011*/
989void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1012void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
990{ 1013{
991 createInputMethodDict(); 1014 createInputMethodDict();
992 if ( mode == Normal ) { 1015 if ( mode == Normal ) {
993 inputMethodDict->remove 1016 inputMethodDict->remove
994 ( w ); 1017 ( w );
995 } 1018 }
996 else { 1019 else {
997 inputMethodDict->insert( w, ( void* ) mode ); 1020 inputMethodDict->insert( w, ( void* ) mode );
998 } 1021 }
999} 1022}
1000 1023
1001class HackDialog : public QDialog 1024class HackDialog : public QDialog
1002{ 1025{
1003public: 1026public:
1004 void acceptIt() 1027 void acceptIt()
1005 { 1028 {
1006 accept(); 1029 accept();
1007 } 1030 }
1008 void rejectIt() 1031 void rejectIt()
1009 { 1032 {
1010 reject(); 1033 reject();
1011 } 1034 }
1012}; 1035};
1013 1036
1014 1037
1015void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1038void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
1016{ 1039{
1017 // specialised actions for certain widgets. May want to 1040 // specialised actions for certain widgets. May want to
1018 // add more stuff here. 1041 // add more stuff here.
1019 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1042 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
1020 && activePopupWidget() ->parentWidget() 1043 && activePopupWidget() ->parentWidget()
1021 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1044 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
1022 key = Qt::Key_Return; 1045 key = Qt::Key_Return;
1023 1046
1024 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1047 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
1025 key = Qt::Key_Return; 1048 key = Qt::Key_Return;
1026 1049
1027#ifdef QWS 1050#ifdef QWS
1028 1051
1029 ke->simpleData.keycode = key; 1052 ke->simpleData.keycode = key;
1030#endif 1053#endif
1031} 1054}
1032 1055
1033 1056
1034/*! 1057/*!
1035 \internal 1058 \internal
1036*/ 1059*/
1037 1060
1038#ifdef QWS 1061#ifdef QWS
1039bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1062bool QPEApplication::qwsEventFilter( QWSEvent * e )
1040{ 1063{
1041 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1064 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
1042 if ( qApp->type() != QApplication::GuiServer ) { 1065 if ( qApp->type() != QApplication::GuiServer ) {
1043 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1066 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
1044 e << d->appName; 1067 e << d->appName;
1045 } 1068 }
1046 d->notbusysent = TRUE; 1069 d->notbusysent = TRUE;
1047 } 1070 }
1048 if ( type() == GuiServer ) { 1071 if ( type() == GuiServer ) {
1049 switch ( e->type ) { 1072 switch ( e->type ) {
1050 case QWSEvent::Mouse: 1073 case QWSEvent::Mouse:
1051 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1074 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
1052 emit clientMoused(); 1075 emit clientMoused();
1053 break; 1076 break;
1054 default: 1077 default:
1055 break; 1078 break;
1056 } 1079 }
1057 } 1080 }
1058 if ( e->type == QWSEvent::Key ) { 1081 if ( e->type == QWSEvent::Key ) {
1059 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1082 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
1060 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1083 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
1061 // Use special "OK" key to press "OK" on top level widgets 1084 // Use special "OK" key to press "OK" on top level widgets
1062 QWidget * active = activeWindow(); 1085 QWidget * active = activeWindow();
1063 QWidget *popup = 0; 1086 QWidget *popup = 0;
1064 if ( active && active->isPopup() ) { 1087 if ( active && active->isPopup() ) {
1065 popup = active; 1088 popup = active;
1066 active = active->parentWidget(); 1089 active = active->parentWidget();
1067 } 1090 }
1068 if ( active && ( int ) active->winId() == ke->simpleData.window && 1091 if ( active && ( int ) active->winId() == ke->simpleData.window &&
1069 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1092 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1070 if ( ke->simpleData.is_press ) { 1093 if ( ke->simpleData.is_press ) {
1071 if ( popup ) 1094 if ( popup )
1072 popup->close(); 1095 popup->close();
1073 if ( active->inherits( "QDialog" ) ) { 1096 if ( active->inherits( "QDialog" ) ) {
1074 HackDialog * d = ( HackDialog * ) active; 1097 HackDialog * d = ( HackDialog * ) active;
1075 d->acceptIt(); 1098 d->acceptIt();
1076 return TRUE; 1099 return TRUE;
1077 } 1100 }
1078 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1101 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
1079 QSignal s; 1102 QSignal s;
1080 s.connect( active, SLOT( accept() ) ); 1103 s.connect( active, SLOT( accept() ) );
1081 s.activate(); 1104 s.activate();
1082 } 1105 }
1083 else { 1106 else {
1084 // do the same as with the select key: Map to the default action of the widget: 1107 // do the same as with the select key: Map to the default action of the widget:
1085 mapToDefaultAction( ke, Qt::Key_Return ); 1108 mapToDefaultAction( ke, Qt::Key_Return );
1086 } 1109 }
1087 } 1110 }
1088 } 1111 }
1089 } 1112 }
1090 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1113 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
1091 // Use special "select" key to do whatever default action a widget has 1114 // Use special "select" key to do whatever default action a widget has
1092 mapToDefaultAction( ke, Qt::Key_Space ); 1115 mapToDefaultAction( ke, Qt::Key_Space );
1093 } 1116 }
1094 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1117 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
1095 ke->simpleData.is_press ) { 1118 ke->simpleData.is_press ) {
1096 // Escape key closes app if focus on toplevel 1119 // Escape key closes app if focus on toplevel
1097 QWidget * active = activeWindow(); 1120 QWidget * active = activeWindow();
1098 if ( active && active->testWFlags( WType_TopLevel ) && 1121 if ( active && active->testWFlags( WType_TopLevel ) &&
1099 ( int ) active->winId() == ke->simpleData.window && 1122 ( int ) active->winId() == ke->simpleData.window &&
1100 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1123 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1101 if ( active->inherits( "QDialog" ) ) { 1124 if ( active->inherits( "QDialog" ) ) {
1102 HackDialog * d = ( HackDialog * ) active; 1125 HackDialog * d = ( HackDialog * ) active;
1103 d->rejectIt(); 1126 d->rejectIt();
1104 return TRUE; 1127 return TRUE;
1105 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { 1128 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ {
1106 active->close(); 1129 active->close();
1107 } 1130 }
1108 } 1131 }
1109 1132
1110 } 1133 }
1111 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1134 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
1112 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1135 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
1113 // but we cannot access libopie function within libqpe :( 1136 // but we cannot access libopie function within libqpe :(
1114 1137
1115 QWidget * active = activeWindow ( ); 1138 QWidget * active = activeWindow ( );
1116 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1139 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
1117 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1140 if ( d-> kbgrabbed ) { // we grabbed the keyboard
1118 QChar ch ( ke-> simpleData.unicode ); 1141 QChar ch ( ke-> simpleData.unicode );
1119 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1142 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
1120 ke-> simpleData.keycode, 1143 ke-> simpleData.keycode,
1121 ch. latin1 ( ), 1144 ch. latin1 ( ),
1122 ke-> simpleData.modifiers, 1145 ke-> simpleData.modifiers,
1123 QString ( ch ), 1146 QString ( ch ),
1124 ke-> simpleData.is_auto_repeat, 1 ); 1147 ke-> simpleData.is_auto_repeat, 1 );
1125 1148
1126 QObject *which = QWidget::keyboardGrabber ( ); 1149 QObject *which = QWidget::keyboardGrabber ( );
1127 if ( !which ) 1150 if ( !which )
1128 which = QApplication::focusWidget ( ); 1151 which = QApplication::focusWidget ( );
1129 if ( !which ) 1152 if ( !which )
1130 which = QApplication::activeWindow ( ); 1153 which = QApplication::activeWindow ( );
1131 if ( !which ) 1154 if ( !which )
1132 which = qApp; 1155 which = qApp;
1133 1156
1134 QApplication::sendEvent ( which, &qke ); 1157 QApplication::sendEvent ( which, &qke );
1135 } 1158 }
1136 else { // we didn't grab the keyboard, so send the event to the launcher 1159 else { // we didn't grab the keyboard, so send the event to the launcher
1137 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1160 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
1138 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1161 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
1139 } 1162 }
1140 } 1163 }
1141 return true; 1164 return true;
1142 } 1165 }
1143 } 1166 }
1144 if ( e->type == QWSEvent::Focus ) { 1167 if ( e->type == QWSEvent::Focus ) {
1145 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1168 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
1146 if ( !fe->simpleData.get_focus ) { 1169 if ( !fe->simpleData.get_focus ) {
1147 QWidget * active = activeWindow(); 1170 QWidget * active = activeWindow();
1148 while ( active && active->isPopup() ) { 1171 while ( active && active->isPopup() ) {
1149 active->close(); 1172 active->close();
1150 active = activeWindow(); 1173 active = activeWindow();
1151 } 1174 }
1152 } 1175 }
1153 else { 1176 else {
1154 // make sure our modal widget is ALWAYS on top 1177 // make sure our modal widget is ALWAYS on top
1155 QWidget *topm = activeModalWidget(); 1178 QWidget *topm = activeModalWidget();
1156 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1179 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
1157 topm->raise(); 1180 topm->raise();
1158 } 1181 }
1159 } 1182 }
1160 if ( fe->simpleData.get_focus && inputMethodDict ) { 1183 if ( fe->simpleData.get_focus && inputMethodDict ) {
1161 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1184 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1162 if ( m == AlwaysOff ) 1185 if ( m == AlwaysOff )
1163 Global::hideInputMethod(); 1186 Global::hideInputMethod();
1164 if ( m == AlwaysOn ) 1187 if ( m == AlwaysOn )
1165 Global::showInputMethod(); 1188 Global::showInputMethod();
1166 } 1189 }
1167 } 1190 }
1168 1191
1169 1192
1170 return QApplication::qwsEventFilter( e ); 1193 return QApplication::qwsEventFilter( e );
1171} 1194}
1172#endif 1195#endif
1173 1196
1174/*! 1197/*!
1175 Destroys the QPEApplication. 1198 Destroys the QPEApplication.
1176*/ 1199*/
1177QPEApplication::~QPEApplication() 1200QPEApplication::~QPEApplication()
1178{ 1201{
1179 ungrabKeyboard(); 1202 ungrabKeyboard();
1180#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1203#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1181 // Need to delete QCopChannels early, since the display will 1204 // Need to delete QCopChannels early, since the display will
1182 // be gone by the time we get to ~QObject(). 1205 // be gone by the time we get to ~QObject().
1183 delete sysChannel; 1206 delete sysChannel;
1184 delete pidChannel; 1207 delete pidChannel;
1185#endif 1208#endif
1186 1209
1187#ifdef OPIE_WITHROHFEEDBACK 1210#ifdef OPIE_WITHROHFEEDBACK
1188 if( d->RoH ) 1211 if( d->RoH )
1189 delete d->RoH; 1212 delete d->RoH;
1190#endif 1213#endif
1191 delete d; 1214 delete d;
1192} 1215}
1193 1216
1194/*! 1217/*!
1195 Returns <tt>$OPIEDIR/</tt>. 1218 Returns <tt>$OPIEDIR/</tt>.
1196*/ 1219*/
1197QString QPEApplication::qpeDir() 1220QString QPEApplication::qpeDir()
1198{ 1221{
1199 QString base, dir; 1222 QString base, dir;
1200 1223
1201 if (getenv( "OPIEDIR" )) 1224 if (getenv( "OPIEDIR" ))
1202 base = QString(getenv("OPIEDIR")).stripWhiteSpace(); 1225 base = QString(getenv("OPIEDIR")).stripWhiteSpace();
1203 if ( !base.isNull() && (base.length() > 0 )){ 1226 if ( !base.isNull() && (base.length() > 0 )){
1204#ifdef Q_OS_WIN32 1227#ifdef Q_OS_WIN32
1205 QString temp(base); 1228 QString temp(base);
1206 if (temp[(int)temp.length()-1] != QDir::separator()) 1229 if (temp[(int)temp.length()-1] != QDir::separator())
1207 temp.append(QDir::separator()); 1230 temp.append(QDir::separator());
1208 dir = temp; 1231 dir = temp;
1209#else 1232#else
1210 dir = QString( base ) + "/"; 1233 dir = QString( base ) + "/";
1211#endif 1234#endif
1212 }else{ 1235 }else{
1213 dir = QString( ".." ) + QDir::separator(); 1236 dir = QString( ".." ) + QDir::separator();
1214 } 1237 }
1215 1238
1216 return dir; 1239 return dir;
1217} 1240}
1218 1241
1219/*! 1242/*!
1220 Returns the user's current Document directory. There is a trailing "/". 1243 Returns the user's current Document directory. There is a trailing "/".
1221 .. well, it does now,, and there's no trailing '/' 1244 .. well, it does now,, and there's no trailing '/'
1222*/ 1245*/
1223QString QPEApplication::documentDir() 1246QString QPEApplication::documentDir()
1224{ 1247{
1225 const char* base = getenv( "HOME"); 1248 const char* base = getenv( "HOME");
1226 if ( base ) 1249 if ( base )
1227 return QString( base ) + "/Documents"; 1250 return QString( base ) + "/Documents";
1228 1251
1229 return QString( "../Documents" ); 1252 return QString( "../Documents" );
1230} 1253}
1231 1254
1232static int deforient = -1; 1255static int deforient = -1;
1233 1256
1234/*! 1257/*!
1235 \internal 1258 \internal
1236*/ 1259*/
1237int QPEApplication::defaultRotation() 1260int QPEApplication::defaultRotation()
1238{ 1261{
1239 if ( deforient < 0 ) { 1262 if ( deforient < 0 ) {
1240 QString d = getenv( "QWS_DISPLAY" ); 1263 QString d = getenv( "QWS_DISPLAY" );
1241 if ( d.contains( "Rot90" ) ) { 1264 if ( d.contains( "Rot90" ) ) {
1242 deforient = 90; 1265 deforient = 90;
1243 } 1266 }
1244 else if ( d.contains( "Rot180" ) ) { 1267 else if ( d.contains( "Rot180" ) ) {
1245 deforient = 180; 1268 deforient = 180;
1246 } 1269 }
1247 else if ( d.contains( "Rot270" ) ) { 1270 else if ( d.contains( "Rot270" ) ) {
1248 deforient = 270; 1271 deforient = 270;
1249 } 1272 }
1250 else { 1273 else {
1251 deforient = 0; 1274 deforient = 0;
1252 } 1275 }
1253 } 1276 }
1254 return deforient; 1277 return deforient;
1255} 1278}
1256 1279
1257/*! 1280/*!
1258 \internal 1281 \internal
1259*/ 1282*/
1260void QPEApplication::setDefaultRotation( int r ) 1283void QPEApplication::setDefaultRotation( int r )
1261{ 1284{
1262 if ( qApp->type() == GuiServer ) { 1285 if ( qApp->type() == GuiServer ) {
1263 deforient = r; 1286 deforient = r;
1264 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1287 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1265 Config config("qpe"); 1288 Config config("qpe");
1266 config.setGroup( "Rotation" ); 1289 config.setGroup( "Rotation" );
1267 config.writeEntry( "Rot", r ); 1290 config.writeEntry( "Rot", r );
1268 } 1291 }
1269 else { 1292 else {
1270#ifndef QT_NO_COP 1293#ifndef QT_NO_COP
1271 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1294 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1272 e << r; 1295 e << r;
1273 } 1296 }
1274#endif 1297#endif
1275 1298
1276 } 1299 }
1277} 1300}
1278 1301
1279#include <qgfx_qws.h> 1302#include <qgfx_qws.h>
1280#include <qwindowsystem_qws.h> 1303#include <qwindowsystem_qws.h>
1281 1304
1282#if QT_VERSION > 236 1305#if QT_VERSION > 236
1283extern void qws_clearLoadedFonts(); 1306extern void qws_clearLoadedFonts();
1284#endif 1307#endif
1285 1308
1286void QPEApplication::setCurrentMode( int x, int y, int depth ) 1309void QPEApplication::setCurrentMode( int x, int y, int depth )
1287{ 1310{
1288 // Reset the caches 1311 // Reset the caches
1289#if QT_VERSION > 236 1312#if QT_VERSION > 236
1290 qws_clearLoadedFonts(); 1313 qws_clearLoadedFonts();
1291#endif 1314#endif
1292 QPixmapCache::clear(); 1315 QPixmapCache::clear();
1293 1316
1294 // Change the screen mode 1317 // Change the screen mode
1295 qt_screen->setMode(x, y, depth); 1318 qt_screen->setMode(x, y, depth);
1296 1319
1297 if ( qApp->type() == GuiServer ) { 1320 if ( qApp->type() == GuiServer ) {
1298#if QT_VERSION > 236 1321#if QT_VERSION > 236
1299 // Reconfigure the GuiServer 1322 // Reconfigure the GuiServer
1300 qwsServer->beginDisplayReconfigure(); 1323 qwsServer->beginDisplayReconfigure();
1301 qwsServer->endDisplayReconfigure(); 1324 qwsServer->endDisplayReconfigure();
1302#endif 1325#endif
1303 // Get all the running apps to reset 1326 // Get all the running apps to reset
1304 QCopEnvelope env( "QPE/System", "reset()" ); 1327 QCopEnvelope env( "QPE/System", "reset()" );
1305 } 1328 }