summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 3b6a987..59ca61b 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -263,2038 +263,2042 @@ static void qpe_show_dialog( QDialog* d, bool nomax )
263 } else { 263 } else {
264 // try centering the dialog around its parent 264 // try centering the dialog around its parent
265 QPoint p(0,0); 265 QPoint p(0,0);
266 if ( d->parentWidget() ) { 266 if ( d->parentWidget() ) {
267 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); 267 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
268 p = QPoint( pp.x() + d->parentWidget()->width()/2, 268 p = QPoint( pp.x() + d->parentWidget()->width()/2,
269 pp.y() + d->parentWidget()->height()/ 2 ); 269 pp.y() + d->parentWidget()->height()/ 2 );
270 } else { 270 } else {
271 p = QPoint( maxX/2, maxY/2 ); 271 p = QPoint( maxX/2, maxY/2 );
272 } 272 }
273 273
274 p = QPoint( p.x() - w/2, p.y() - h/2 ); 274 p = QPoint( p.x() - w/2, p.y() - h/2 );
275// qDebug("p(x,y) is %d %d", p.x(), p.y() ); 275// qDebug("p(x,y) is %d %d", p.x(), p.y() );
276 276
277 if ( w >= maxX ) { 277 if ( w >= maxX ) {
278 if ( p.y() < 0 ) 278 if ( p.y() < 0 )
279 p.setY(0); 279 p.setY(0);
280 if ( p.y() + h > maxY ) 280 if ( p.y() + h > maxY )
281 p.setY( maxY - h); 281 p.setY( maxY - h);
282 282
283 d->resize(maxX, h); 283 d->resize(maxX, h);
284 d->move(0, p.y() ); 284 d->move(0, p.y() );
285 } else if ( h >= maxY ) { 285 } else if ( h >= maxY ) {
286 if ( p.x() < 0 ) 286 if ( p.x() < 0 )
287 p.setX(0); 287 p.setX(0);
288 if ( p.x() + w > maxX ) 288 if ( p.x() + w > maxX )
289 p.setX( maxX - w); 289 p.setX( maxX - w);
290 290
291 d->resize(w, maxY); 291 d->resize(w, maxY);
292 d->move(p.x(),0); 292 d->move(p.x(),0);
293 } else { 293 } else {
294 d->resize(w, h); 294 d->resize(w, h);
295 } 295 }
296 296
297 d->show(); 297 d->show();
298 } 298 }
299} 299}
300 300
301 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) 301 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
302 { 302 {
303 maximized = TRUE; 303 maximized = TRUE;
304 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 304 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
305 if ( qApp->desktop()->width() <= 350 ) 305 if ( qApp->desktop()->width() <= 350 )
306 return FALSE; 306 return FALSE;
307 307
308 Config cfg( "qpe" ); 308 Config cfg( "qpe" );
309 cfg.setGroup("ApplicationPositions"); 309 cfg.setGroup("ApplicationPositions");
310 QString str = cfg.readEntry( app, QString::null ); 310 QString str = cfg.readEntry( app, QString::null );
311 QStringList l = QStringList::split(",", str); 311 QStringList l = QStringList::split(",", str);
312 312
313 if ( l.count() == 5) { 313 if ( l.count() == 5) {
314 p.setX( l[0].toInt() ); 314 p.setX( l[0].toInt() );
315 p.setY( l[1].toInt() ); 315 p.setY( l[1].toInt() );
316 316
317 s.setWidth( l[2].toInt() ); 317 s.setWidth( l[2].toInt() );
318 s.setHeight( l[3].toInt() ); 318 s.setHeight( l[3].toInt() );
319 319
320 maximized = l[4].toInt(); 320 maximized = l[4].toInt();
321 321
322 return TRUE; 322 return TRUE;
323 } 323 }
324 324
325 return FALSE; 325 return FALSE;
326 } 326 }
327 327
328 328
329 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 329 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
330 { 330 {
331#ifndef Q_WS_QWS 331#ifndef Q_WS_QWS
332 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 332 QRect qt_maxWindowRect = qApp->desktop()->geometry();
333#endif 333#endif
334 int maxX = qt_maxWindowRect.width(); 334 int maxX = qt_maxWindowRect.width();
335 int maxY = qt_maxWindowRect.height(); 335 int maxY = qt_maxWindowRect.height();
336 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 336 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
337 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 337 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
338 338
339 // total window size is not allowed to be larger than desktop window size 339 // total window size is not allowed to be larger than desktop window size
340 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 340 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
341 return FALSE; 341 return FALSE;
342 342
343 if ( wWidth > maxX ) { 343 if ( wWidth > maxX ) {
344 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 344 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
345 wWidth = maxX; 345 wWidth = maxX;
346 } 346 }
347 347
348 if ( wHeight > maxY ) { 348 if ( wHeight > maxY ) {
349 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 349 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
350 wHeight = maxY; 350 wHeight = maxY;
351 } 351 }
352 352
353 // any smaller than this and the maximize/close/help buttons will be overlapping 353 // any smaller than this and the maximize/close/help buttons will be overlapping
354 if ( wWidth < 80 || wHeight < 60 ) 354 if ( wWidth < 80 || wHeight < 60 )
355 return FALSE; 355 return FALSE;
356 356
357 if ( p.x() < 0 ) 357 if ( p.x() < 0 )
358 p.setX(0); 358 p.setX(0);
359 if ( p.y() < 0 ) 359 if ( p.y() < 0 )
360 p.setY(0); 360 p.setY(0);
361 361
362 if ( p.x() + wWidth > maxX ) 362 if ( p.x() + wWidth > maxX )
363 p.setX( maxX - wWidth ); 363 p.setX( maxX - wWidth );
364 if ( p.y() + wHeight > maxY ) 364 if ( p.y() + wHeight > maxY )
365 p.setY( maxY - wHeight ); 365 p.setY( maxY - wHeight );
366 366
367 return TRUE; 367 return TRUE;
368 } 368 }
369 369
370 static void store_widget_rect(QWidget *w, QString &app) 370 static void store_widget_rect(QWidget *w, QString &app)
371 { 371 {
372 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 372 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
373 if ( qApp->desktop()->width() <= 350 ) 373 if ( qApp->desktop()->width() <= 350 )
374 return; 374 return;
375 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 375 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
376 // get the non-maximized version, so we have to do it the hard way ) 376 // get the non-maximized version, so we have to do it the hard way )
377 int offsetX = w->x() - w->geometry().left(); 377 int offsetX = w->x() - w->geometry().left();
378 int offsetY = w->y() - w->geometry().top(); 378 int offsetY = w->y() - w->geometry().top();
379 379
380 QRect r; 380 QRect r;
381 if ( w->isMaximized() ) 381 if ( w->isMaximized() )
382 r = ( (HackWidget *) w)->normalGeometry(); 382 r = ( (HackWidget *) w)->normalGeometry();
383 else 383 else
384 r = w->geometry(); 384 r = w->geometry();
385 385
386 // Stores the window placement as pos(), size() (due to the offset mapping) 386 // Stores the window placement as pos(), size() (due to the offset mapping)
387 Config cfg( "qpe" ); 387 Config cfg( "qpe" );
388 cfg.setGroup("ApplicationPositions"); 388 cfg.setGroup("ApplicationPositions");
389 QString s; 389 QString s;
390 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 390 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
391 cfg.writeEntry( app, s ); 391 cfg.writeEntry( app, s );
392 } 392 }
393 393
394 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 394 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
395 { 395 {
396 /* 396 /*
397 // This works but disable it for now until it is safe to apply 397 // This works but disable it for now until it is safe to apply
398 // What is does is scan the .desktop files of all the apps for 398 // What is does is scan the .desktop files of all the apps for
399 // the applnk that has the corresponding argv[0] as this program 399 // the applnk that has the corresponding argv[0] as this program
400 // then it uses the name stored in the .desktop file as the caption 400 // then it uses the name stored in the .desktop file as the caption
401 // for the main widget. This saves duplicating translations for 401 // for the main widget. This saves duplicating translations for
402 // the app name in the program and in the .desktop files. 402 // the app name in the program and in the .desktop files.
403 403
404 AppLnkSet apps( appsPath ); 404 AppLnkSet apps( appsPath );
405 405
406 QList<AppLnk> appsList = apps.children(); 406 QList<AppLnk> appsList = apps.children();
407 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 407 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
408 if ( (*it)->exec() == appName ) { 408 if ( (*it)->exec() == appName ) {
409 mw->setCaption( (*it)->name() ); 409 mw->setCaption( (*it)->name() );
410 return TRUE; 410 return TRUE;
411 } 411 }
412 } 412 }
413 */ 413 */
414 return FALSE; 414 return FALSE;
415 } 415 }
416 416
417 417
418 void show(QWidget* mw, bool nomax) 418 void show(QWidget* mw, bool nomax)
419 { 419 {
420 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 420 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
421 nomaximize = nomax; 421 nomaximize = nomax;
422 qpe_main_widget = mw; 422 qpe_main_widget = mw;
423 qcopQok = TRUE; 423 qcopQok = TRUE;
424#ifndef QT_NO_COP 424#ifndef QT_NO_COP
425 425
426 sendQCopQ(); 426 sendQCopQ();
427#endif 427#endif
428 428
429 if ( preloaded ) { 429 if ( preloaded ) {
430 if (forceshow) 430 if (forceshow)
431 show_mx(mw, nomax, appName); 431 show_mx(mw, nomax, appName);
432 } 432 }
433 else if ( keep_running ) { 433 else if ( keep_running ) {
434 show_mx(mw, nomax, appName); 434 show_mx(mw, nomax, appName);
435 } 435 }
436 } 436 }
437 437
438 void loadTextCodecs() 438 void loadTextCodecs()
439 { 439 {
440 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 440 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
441#ifdef Q_OS_MACX 441#ifdef Q_OS_MACX
442 QDir dir( path, "lib*.dylib" ); 442 QDir dir( path, "lib*.dylib" );
443#else 443#else
444 QDir dir( path, "lib*.so" ); 444 QDir dir( path, "lib*.so" );
445#endif 445#endif
446 QStringList list; 446 QStringList list;
447 if ( dir. exists ( )) 447 if ( dir. exists ( ))
448 list = dir.entryList(); 448 list = dir.entryList();
449 QStringList::Iterator it; 449 QStringList::Iterator it;
450 for ( it = list.begin(); it != list.end(); ++it ) { 450 for ( it = list.begin(); it != list.end(); ++it ) {
451 TextCodecInterface *iface = 0; 451 TextCodecInterface *iface = 0;
452 QLibrary *lib = new QLibrary( path + "/" + *it ); 452 QLibrary *lib = new QLibrary( path + "/" + *it );
453 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 453 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
454 QValueList<int> mibs = iface->mibEnums(); 454 QValueList<int> mibs = iface->mibEnums();
455 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 455 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
456 (void)iface->createForMib(*i); 456 (void)iface->createForMib(*i);
457 // ### it exists now; need to remember if we can delete it 457 // ### it exists now; need to remember if we can delete it
458 } 458 }
459 } 459 }
460 else { 460 else {
461 lib->unload(); 461 lib->unload();
462 delete lib; 462 delete lib;
463 } 463 }
464 } 464 }
465 } 465 }
466 466
467 void loadImageCodecs() 467 void loadImageCodecs()
468 { 468 {
469 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 469 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
470#ifdef Q_OS_MACX 470#ifdef Q_OS_MACX
471 QDir dir( path, "lib*.dylib" ); 471 QDir dir( path, "lib*.dylib" );
472#else 472#else
473 QDir dir( path, "lib*.so" ); 473 QDir dir( path, "lib*.so" );
474#endif 474#endif
475 QStringList list; 475 QStringList list;
476 if ( dir. exists ( )) 476 if ( dir. exists ( ))
477 list = dir.entryList(); 477 list = dir.entryList();
478 QStringList::Iterator it; 478 QStringList::Iterator it;
479 for ( it = list.begin(); it != list.end(); ++it ) { 479 for ( it = list.begin(); it != list.end(); ++it ) {
480 ImageCodecInterface *iface = 0; 480 ImageCodecInterface *iface = 0;
481 QLibrary *lib = new QLibrary( path + "/" + *it ); 481 QLibrary *lib = new QLibrary( path + "/" + *it );
482 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 482 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
483 QStringList formats = iface->keys(); 483 QStringList formats = iface->keys();
484 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 484 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
485 (void)iface->installIOHandler(*i); 485 (void)iface->installIOHandler(*i);
486 // ### it exists now; need to remember if we can delete it 486 // ### it exists now; need to remember if we can delete it
487 } 487 }
488 } 488 }
489 else { 489 else {
490 lib->unload(); 490 lib->unload();
491 delete lib; 491 delete lib;
492 } 492 }
493 } 493 }
494 } 494 }
495}; 495};
496 496
497class ResourceMimeFactory : public QMimeSourceFactory 497class ResourceMimeFactory : public QMimeSourceFactory
498{ 498{
499public: 499public:
500 ResourceMimeFactory() : resImage( 0 ) 500 ResourceMimeFactory() : resImage( 0 )
501 { 501 {
502 setFilePath( Global::helpPath() ); 502 setFilePath( Global::helpPath() );
503 setExtensionType( "html", "text/html;charset=UTF-8" ); 503 setExtensionType( "html", "text/html;charset=UTF-8" );
504 } 504 }
505 ~ResourceMimeFactory() { 505 ~ResourceMimeFactory() {
506 delete resImage; 506 delete resImage;
507 } 507 }
508 508
509 const QMimeSource* data( const QString& abs_name ) const 509 const QMimeSource* data( const QString& abs_name ) const
510 { 510 {
511 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 511 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
512 if ( !r ) { 512 if ( !r ) {
513 int sl = abs_name.length(); 513 int sl = abs_name.length();
514 do { 514 do {
515 sl = abs_name.findRev( '/', sl - 1 ); 515 sl = abs_name.findRev( '/', sl - 1 );
516 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 516 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
517 int dot = name.findRev( '.' ); 517 int dot = name.findRev( '.' );
518 if ( dot >= 0 ) 518 if ( dot >= 0 )
519 name = name.left( dot ); 519 name = name.left( dot );
520 QImage img = Resource::loadImage( name ); 520 QImage img = Resource::loadImage( name );
521 if ( !img.isNull() ) { 521 if ( !img.isNull() ) {
522 delete resImage; 522 delete resImage;
523 resImage = new QImageDrag( img ); 523 resImage = new QImageDrag( img );
524 r = resImage; 524 r = resImage;
525 } 525 }
526 } 526 }
527 while ( !r && sl > 0 ); 527 while ( !r && sl > 0 );
528 } 528 }
529 return r; 529 return r;
530 } 530 }
531private: 531private:
532 mutable QImageDrag *resImage; 532 mutable QImageDrag *resImage;
533}; 533};
534 534
535static int& hack(int& i) 535static int& hack(int& i)
536{ 536{
537#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 537#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
538 // These should be created, but aren't in Qt 2.3.0 538 // These should be created, but aren't in Qt 2.3.0
539 (void)new QUtf8Codec; 539 (void)new QUtf8Codec;
540 (void)new QUtf16Codec; 540 (void)new QUtf16Codec;
541#endif 541#endif
542 return i; 542 return i;
543} 543}
544 544
545static int muted = 0; 545static int muted = 0;
546static int micMuted = 0; 546static int micMuted = 0;
547 547
548static void setVolume( int t = 0, int percent = -1 ) 548static void setVolume( int t = 0, int percent = -1 )
549{ 549{
550 switch ( t ) { 550 switch ( t ) {
551 case 0: { 551 case 0: {
552 Config cfg( "qpe" ); 552 Config cfg( "qpe" );
553 cfg.setGroup( "Volume" ); 553 cfg.setGroup( "Volume" );
554 if ( percent < 0 ) 554 if ( percent < 0 )
555 percent = cfg.readNumEntry( "VolumePercent", 50 ); 555 percent = cfg.readNumEntry( "VolumePercent", 50 );
556#ifndef QT_NO_SOUND 556#ifndef QT_NO_SOUND
557 int fd = 0; 557 int fd = 0;
558 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 558 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
559 int vol = muted ? 0 : percent; 559 int vol = muted ? 0 : percent;
560 // set both channels to same volume 560 // set both channels to same volume
561 vol |= vol << 8; 561 vol |= vol << 8;
562 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 562 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
563 ::close( fd ); 563 ::close( fd );
564 } 564 }
565#endif 565#endif
566 } 566 }
567 break; 567 break;
568 } 568 }
569} 569}
570 570
571static void setMic( int t = 0, int percent = -1 ) 571static void setMic( int t = 0, int percent = -1 )
572{ 572{
573 switch ( t ) { 573 switch ( t ) {
574 case 0: { 574 case 0: {
575 Config cfg( "qpe" ); 575 Config cfg( "qpe" );
576 cfg.setGroup( "Volume" ); 576 cfg.setGroup( "Volume" );
577 if ( percent < 0 ) 577 if ( percent < 0 )
578 percent = cfg.readNumEntry( "Mic", 50 ); 578 percent = cfg.readNumEntry( "Mic", 50 );
579 579
580#ifndef QT_NO_SOUND 580#ifndef QT_NO_SOUND
581 int fd = 0; 581 int fd = 0;
582 int mic = micMuted ? 0 : percent; 582 int mic = micMuted ? 0 : percent;
583 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 583 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
584 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 584 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
585 ::close( fd ); 585 ::close( fd );
586 } 586 }
587#endif 587#endif
588 } 588 }
589 break; 589 break;
590 } 590 }
591} 591}
592 592
593 593
594static void setBass( int t = 0, int percent = -1 ) 594static void setBass( int t = 0, int percent = -1 )
595{ 595{
596 switch ( t ) { 596 switch ( t ) {
597 case 0: { 597 case 0: {
598 Config cfg( "qpe" ); 598 Config cfg( "qpe" );
599 cfg.setGroup( "Volume" ); 599 cfg.setGroup( "Volume" );
600 if ( percent < 0 ) 600 if ( percent < 0 )
601 percent = cfg.readNumEntry( "BassPercent", 50 ); 601 percent = cfg.readNumEntry( "BassPercent", 50 );
602 602
603#ifndef QT_NO_SOUND 603#ifndef QT_NO_SOUND
604 int fd = 0; 604 int fd = 0;
605 int bass = percent; 605 int bass = percent;
606 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 606 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
607 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 607 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
608 ::close( fd ); 608 ::close( fd );
609 } 609 }
610#endif 610#endif
611 } 611 }
612 break; 612 break;
613 } 613 }
614} 614}
615 615
616 616
617static void setTreble( int t = 0, int percent = -1 ) 617static void setTreble( int t = 0, int percent = -1 )
618{ 618{
619 switch ( t ) { 619 switch ( t ) {
620 case 0: { 620 case 0: {
621 Config cfg( "qpe" ); 621 Config cfg( "qpe" );
622 cfg.setGroup( "Volume" ); 622 cfg.setGroup( "Volume" );
623 if ( percent < 0 ) 623 if ( percent < 0 )
624 percent = cfg.readNumEntry( "TreblePercent", 50 ); 624 percent = cfg.readNumEntry( "TreblePercent", 50 );
625 625
626#ifndef QT_NO_SOUND 626#ifndef QT_NO_SOUND
627 int fd = 0; 627 int fd = 0;
628 int treble = percent; 628 int treble = percent;
629 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 629 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
630 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 630 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
631 ::close( fd ); 631 ::close( fd );
632 } 632 }
633#endif 633#endif
634 } 634 }
635 break; 635 break;
636 } 636 }
637} 637}
638 638
639 639
640/** 640/**
641 \class QPEApplication 641 \class QPEApplication
642 \brief The QPEApplication class implements various system services 642 \brief The QPEApplication class implements various system services
643 that are available to all Qtopia applications. 643 that are available to all Qtopia applications.
644 644
645 Simply by using QPEApplication instead of QApplication, a standard Qt 645 Simply by using QPEApplication instead of QApplication, a standard Qt
646 application becomes a Qtopia application. It automatically follows 646 application becomes a Qtopia application. It automatically follows
647 style changes, quits and raises, and in the 647 style changes, quits and raises, and in the
648 case of \link docwidget.html document-oriented\endlink applications, 648 case of \link docwidget.html document-oriented\endlink applications,
649 changes the currently displayed document in response to the environment. 649 changes the currently displayed document in response to the environment.
650 650
651 To create a \link docwidget.html document-oriented\endlink 651 To create a \link docwidget.html document-oriented\endlink
652 application use showMainDocumentWidget(); to create a 652 application use showMainDocumentWidget(); to create a
653 non-document-oriented application use showMainWidget(). The 653 non-document-oriented application use showMainWidget(). The
654 keepRunning() function indicates whether the application will 654 keepRunning() function indicates whether the application will
655 continue running after it's processed the last \link qcop.html 655 continue running after it's processed the last \link qcop.html
656 QCop\endlink message. This can be changed using setKeepRunning(). 656 QCop\endlink message. This can be changed using setKeepRunning().
657 657
658 A variety of signals are emitted when certain events occur, for 658 A variety of signals are emitted when certain events occur, for
659 example, timeChanged(), clockChanged(), weekChanged(), 659 example, timeChanged(), clockChanged(), weekChanged(),
660 dateFormatChanged() and volumeChanged(). If the application receives 660 dateFormatChanged() and volumeChanged(). If the application receives
661 a \link qcop.html QCop\endlink message on the application's 661 a \link qcop.html QCop\endlink message on the application's
662 QPE/Application/\e{appname} channel, the appMessage() signal is 662 QPE/Application/\e{appname} channel, the appMessage() signal is
663 emitted. There are also flush() and reload() signals, which 663 emitted. There are also flush() and reload() signals, which
664 are emitted when synching begins and ends respectively - upon these 664 are emitted when synching begins and ends respectively - upon these
665 signals, the application should save and reload any data 665 signals, the application should save and reload any data
666 files that are involved in synching. Most of these signals will initially 666 files that are involved in synching. Most of these signals will initially
667 be received and unfiltered through the appMessage() signal. 667 be received and unfiltered through the appMessage() signal.
668 668
669 This class also provides a set of useful static functions. The 669 This class also provides a set of useful static functions. The
670 qpeDir() and documentDir() functions return the respective paths. 670 qpeDir() and documentDir() functions return the respective paths.
671 The grabKeyboard() and ungrabKeyboard() functions are used to 671 The grabKeyboard() and ungrabKeyboard() functions are used to
672 control whether the application takes control of the device's 672 control whether the application takes control of the device's
673 physical buttons (e.g. application launch keys). The stylus' mode of 673 physical buttons (e.g. application launch keys). The stylus' mode of
674 operation is set with setStylusOperation() and retrieved with 674 operation is set with setStylusOperation() and retrieved with
675 stylusOperation(). There are also setInputMethodHint() and 675 stylusOperation(). There are also setInputMethodHint() and
676 inputMethodHint() functions. 676 inputMethodHint() functions.
677 677
678 \ingroup qtopiaemb 678 \ingroup qtopiaemb
679*/ 679*/
680 680
681/*! 681/*!
682 \fn void QPEApplication::clientMoused() 682 \fn void QPEApplication::clientMoused()
683 683
684 \internal 684 \internal
685*/ 685*/
686 686
687/*! 687/*!
688 \fn void QPEApplication::timeChanged(); 688 \fn void QPEApplication::timeChanged();
689 This signal is emitted when the time changes outside the normal 689 This signal is emitted when the time changes outside the normal
690 passage of time, i.e. if the time is set backwards or forwards. 690 passage of time, i.e. if the time is set backwards or forwards.
691*/ 691*/
692 692
693/*! 693/*!
694 \fn void QPEApplication::clockChanged( bool ampm ); 694 \fn void QPEApplication::clockChanged( bool ampm );
695 695
696 This signal is emitted when the user changes the clock's style. If 696 This signal is emitted when the user changes the clock's style. If
697 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 697 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
698 they want a 24-hour clock. 698 they want a 24-hour clock.
699*/ 699*/
700 700
701/*! 701/*!
702 \fn void QPEApplication::volumeChanged( bool muted ) 702 \fn void QPEApplication::volumeChanged( bool muted )
703 703
704 This signal is emitted whenever the mute state is changed. If \a 704 This signal is emitted whenever the mute state is changed. If \a
705 muted is TRUE, then sound output has been muted. 705 muted is TRUE, then sound output has been muted.
706*/ 706*/
707 707
708/*! 708/*!
709 \fn void QPEApplication::weekChanged( bool startOnMonday ) 709 \fn void QPEApplication::weekChanged( bool startOnMonday )
710 710
711 This signal is emitted if the week start day is changed. If \a 711 This signal is emitted if the week start day is changed. If \a
712 startOnMonday is TRUE then the first day of the week is Monday; if 712 startOnMonday is TRUE then the first day of the week is Monday; if
713 \a startOnMonday is FALSE then the first day of the week is 713 \a startOnMonday is FALSE then the first day of the week is
714 Sunday. 714 Sunday.
715*/ 715*/
716 716
717/*! 717/*!
718 \fn void QPEApplication::dateFormatChanged(DateFormat) 718 \fn void QPEApplication::dateFormatChanged(DateFormat)
719 719
720 This signal is emitted whenever the date format is changed. 720 This signal is emitted whenever the date format is changed.
721*/ 721*/
722 722
723/*! 723/*!
724 \fn void QPEApplication::flush() 724 \fn void QPEApplication::flush()
725 725
726 ### 726 ###
727*/ 727*/
728 728
729/*! 729/*!
730 \fn void QPEApplication::reload() 730 \fn void QPEApplication::reload()
731 731
732*/ 732*/
733 733
734 734
735 735
736void QPEApplication::processQCopFile() 736void QPEApplication::processQCopFile()
737{ 737{
738 QString qcopfn("/tmp/qcop-msg-"); 738 QString qcopfn("/tmp/qcop-msg-");
739 qcopfn += d->appName; // append command name 739 qcopfn += d->appName; // append command name
740 740
741 QFile f(qcopfn); 741 QFile f(qcopfn);
742 if ( f.open(IO_ReadWrite) ) { 742 if ( f.open(IO_ReadWrite) ) {
743#ifndef Q_OS_WIN32 743#ifndef Q_OS_WIN32
744 flock(f.handle(), LOCK_EX); 744 flock(f.handle(), LOCK_EX);
745#endif 745#endif
746 QDataStream ds(&f); 746 QDataStream ds(&f);
747 QCString channel, message; 747 QCString channel, message;
748 QByteArray data; 748 QByteArray data;
749 while(!ds.atEnd()) { 749 while(!ds.atEnd()) {
750 ds >> channel >> message >> data; 750 ds >> channel >> message >> data;
751 d->enqueueQCop(channel,message,data); 751 d->enqueueQCop(channel,message,data);
752 } 752 }
753 ::ftruncate(f.handle(), 0); 753 ::ftruncate(f.handle(), 0);
754#ifndef Q_OS_WIN32 754#ifndef Q_OS_WIN32
755 f.flush(); 755 f.flush();
756 flock(f.handle(), LOCK_UN); 756 flock(f.handle(), LOCK_UN);
757#endif 757#endif
758 } 758 }
759#endif 759#endif
760} 760}
761 761
762 762
763/*! 763/*!
764 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 764 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
765 765
766 This signal is emitted when a message is received on this 766 This signal is emitted when a message is received on this
767 application's QPE/Application/<i>appname</i> \link qcop.html 767 application's QPE/Application/<i>appname</i> \link qcop.html
768 QCop\endlink channel. 768 QCop\endlink channel.
769 769
770 The slot to which you connect this signal uses \a msg and \a data 770 The slot to which you connect this signal uses \a msg and \a data
771 in the following way: 771 in the following way:
772 772
773\code 773\code
774 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 774 void MyWidget::receive( const QCString& msg, const QByteArray& data )
775 { 775 {
776 QDataStream stream( data, IO_ReadOnly ); 776 QDataStream stream( data, IO_ReadOnly );
777 if ( msg == "someMessage(int,int,int)" ) { 777 if ( msg == "someMessage(int,int,int)" ) {
778 int a,b,c; 778 int a,b,c;
779 stream >> a >> b >> c; 779 stream >> a >> b >> c;
780 ... 780 ...
781 } else if ( msg == "otherMessage(QString)" ) { 781 } else if ( msg == "otherMessage(QString)" ) {
782 ... 782 ...
783 } 783 }
784 } 784 }
785\endcode 785\endcode
786 786
787 \sa qcop.html 787 \sa qcop.html
788 Note that messages received here may be processed by qpe application 788 Note that messages received here may be processed by qpe application
789 and emitted as signals, such as flush() and reload(). 789 and emitted as signals, such as flush() and reload().
790*/ 790*/
791 791
792/*! 792/*!
793 Constructs a QPEApplication just as you would construct 793 Constructs a QPEApplication just as you would construct
794 a QApplication, passing \a argc, \a argv, and \a t. 794 a QApplication, passing \a argc, \a argv, and \a t.
795 795
796 For applications, \a t should be the default, GuiClient. Only 796 For applications, \a t should be the default, GuiClient. Only
797 the Qtopia server passes GuiServer. 797 the Qtopia server passes GuiServer.
798*/ 798*/
799QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 799QPEApplication::QPEApplication( int & argc, char **argv, Type t )
800 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 800 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
801{ 801{
802 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 802 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
803 803
804 d = new QPEApplicationData; 804 d = new QPEApplicationData;
805 d->loadTextCodecs(); 805 d->loadTextCodecs();
806 d->loadImageCodecs(); 806 d->loadImageCodecs();
807 807
808 setFont( QFont( d->fontFamily, d->fontSize ) ); 808 setFont( QFont( d->fontFamily, d->fontSize ) );
809 AppLnk::setSmallIconSize( d->smallIconSize ); 809 AppLnk::setSmallIconSize( d->smallIconSize );
810 AppLnk::setBigIconSize( d->bigIconSize ); 810 AppLnk::setBigIconSize( d->bigIconSize );
811 811
812 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 812 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
813 813
814 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 814 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
815 815
816 816
817 sysChannel = new QCopChannel( "QPE/System", this ); 817 sysChannel = new QCopChannel( "QPE/System", this );
818 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 818 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
819 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); 819 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
820 820
821/* COde now in initapp */ 821/* COde now in initapp */
822#if 0 822#if 0
823#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 823#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
824 824
825 QString qcopfn( "/tmp/qcop-msg-" ); 825 QString qcopfn( "/tmp/qcop-msg-" );
826 qcopfn += QString( argv[ 0 ] ); // append command name 826 qcopfn += QString( argv[ 0 ] ); // append command name
827 827
828 QFile f( qcopfn ); 828 QFile f( qcopfn );
829 if ( f.open( IO_ReadOnly ) ) { 829 if ( f.open( IO_ReadOnly ) ) {
830 flock( f.handle(), LOCK_EX ); 830 flock( f.handle(), LOCK_EX );
831 } 831 }
832 832
833 833
834 834
835 QCString channel = QCString( argv[ 0 ] ); 835 QCString channel = QCString( argv[ 0 ] );
836 channel.replace( QRegExp( ".*/" ), "" ); 836 channel.replace( QRegExp( ".*/" ), "" );
837 d->appName = channel; 837 d->appName = channel;
838 channel = "QPE/Application/" + channel; 838 channel = "QPE/Application/" + channel;
839 pidChannel = new QCopChannel( channel, this ); 839 pidChannel = new QCopChannel( channel, this );
840 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 840 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
841 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 841 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
842 842
843 if ( f.isOpen() ) { 843 if ( f.isOpen() ) {
844 d->keep_running = FALSE; 844 d->keep_running = FALSE;
845 QDataStream ds( &f ); 845 QDataStream ds( &f );
846 QCString channel, message; 846 QCString channel, message;
847 QByteArray data; 847 QByteArray data;
848 while ( !ds.atEnd() ) { 848 while ( !ds.atEnd() ) {
849 ds >> channel >> message >> data; 849 ds >> channel >> message >> data;
850 d->enqueueQCop( channel, message, data ); 850 d->enqueueQCop( channel, message, data );
851 } 851 }
852 852
853 flock( f.handle(), LOCK_UN ); 853 flock( f.handle(), LOCK_UN );
854 f.close(); 854 f.close();
855 f.remove(); 855 f.remove();
856 } 856 }
857 857
858 for ( int a = 0; a < argc; a++ ) { 858 for ( int a = 0; a < argc; a++ ) {
859 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 859 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
860 argv[ a ] = argv[ a + 1 ]; 860 argv[ a ] = argv[ a + 1 ];
861 a++; 861 a++;
862 d->preloaded = TRUE; 862 d->preloaded = TRUE;
863 argc -= 1; 863 argc -= 1;
864 } 864 }
865 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 865 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
866 argv[ a ] = argv[ a + 1 ]; 866 argv[ a ] = argv[ a + 1 ];
867 a++; 867 a++;
868 d->preloaded = TRUE; 868 d->preloaded = TRUE;
869 d->forceshow = TRUE; 869 d->forceshow = TRUE;
870 argc -= 1; 870 argc -= 1;
871 } 871 }
872 } 872 }
873 873
874 /* overide stored arguments */ 874 /* overide stored arguments */
875 setArgs( argc, argv ); 875 setArgs( argc, argv );
876 876
877#endif 877#endif
878#else 878#else
879 initApp( argc, argv ); 879 initApp( argc, argv );
880#endif 880#endif
881#ifdef Q_WS_QWS 881#ifdef Q_WS_QWS
882 /* load the font renderer factories */ 882 /* load the font renderer factories */
883 FontDatabase::loadRenderers(); 883 FontDatabase::loadRenderers();
884#endif 884#endif
885#ifndef QT_NO_TRANSLATION 885#ifndef QT_NO_TRANSLATION
886 886
887 d->langs = Global::languageList(); 887 d->langs = Global::languageList();
888 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 888 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
889 QString lang = *it; 889 QString lang = *it;
890 890
891 installTranslation( lang + "/libopie.qm"); 891 installTranslation( lang + "/libopie.qm");
892 installTranslation( lang + "/libqpe.qm" ); 892 installTranslation( lang + "/libqpe.qm" );
893 installTranslation( lang + "/" + d->appName + ".qm" ); 893 installTranslation( lang + "/" + d->appName + ".qm" );
894 894
895 895
896 //###language/font hack; should look it up somewhere 896 //###language/font hack; should look it up somewhere
897#ifdef QWS 897#ifdef QWS
898 898
899 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 899 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
900 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 900 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
901 setFont( fn ); 901 setFont( fn );
902 } 902 }
903#endif 903#endif
904 } 904 }
905#endif 905#endif
906 906
907 applyStyle(); 907 applyStyle();
908 908
909 if ( type() == GuiServer ) { 909 if ( type() == GuiServer ) {
910 setVolume(); 910 setVolume();
911 } 911 }
912 912
913 installEventFilter( this ); 913 installEventFilter( this );
914 914
915 QPEMenuToolFocusManager::initialize(); 915 QPEMenuToolFocusManager::initialize();
916 916
917#ifdef QT_NO_QWS_CURSOR 917#ifdef QT_NO_QWS_CURSOR
918 // if we have no cursor, probably don't want tooltips 918 // if we have no cursor, probably don't want tooltips
919 QToolTip::setEnabled( FALSE ); 919 QToolTip::setEnabled( FALSE );
920#endif 920#endif
921} 921}
922 922
923 923
924#ifdef QTOPIA_INTERNAL_INITAPP 924#ifdef QTOPIA_INTERNAL_INITAPP
925void QPEApplication::initApp( int argc, char **argv ) 925void QPEApplication::initApp( int argc, char **argv )
926{ 926{
927 delete pidChannel; 927 delete pidChannel;
928 d->keep_running = TRUE; 928 d->keep_running = TRUE;
929 d->preloaded = FALSE; 929 d->preloaded = FALSE;
930 d->forceshow = FALSE; 930 d->forceshow = FALSE;
931 931
932 QCString channel = QCString(argv[0]); 932 QCString channel = QCString(argv[0]);
933 933
934 channel.replace(QRegExp(".*/"),""); 934 channel.replace(QRegExp(".*/"),"");
935 d->appName = channel; 935 d->appName = channel;
936 936
937 #if QT_VERSION > 235 937 #if QT_VERSION > 235
938 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 938 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
939 #endif 939 #endif
940 940
941 channel = "QPE/Application/" + channel; 941 channel = "QPE/Application/" + channel;
942 pidChannel = new QCopChannel( channel, this); 942 pidChannel = new QCopChannel( channel, this);
943 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 943 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
944 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 944 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
945 945
946 946
947 947
948 processQCopFile(); 948 processQCopFile();
949 d->keep_running = d->qcopq.isEmpty(); 949 d->keep_running = d->qcopq.isEmpty();
950 950
951 for (int a=0; a<argc; a++) { 951 for (int a=0; a<argc; a++) {
952 if ( qstrcmp(argv[a],"-preload")==0 ) { 952 if ( qstrcmp(argv[a],"-preload")==0 ) {
953 argv[a] = argv[a+1]; 953 argv[a] = argv[a+1];
954 a++; 954 a++;
955 d->preloaded = TRUE; 955 d->preloaded = TRUE;
956 argc-=1; 956 argc-=1;
957 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 957 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
958 argv[a] = argv[a+1]; 958 argv[a] = argv[a+1];
959 a++; 959 a++;
960 d->preloaded = TRUE; 960 d->preloaded = TRUE;
961 d->forceshow = TRUE; 961 d->forceshow = TRUE;
962 argc-=1; 962 argc-=1;
963 } 963 }
964 } 964 }
965 965
966 /* overide stored arguments */ 966 /* overide stored arguments */
967 setArgs(argc, argv); 967 setArgs(argc, argv);
968 968
969 /* install translation here */ 969 /* install translation here */
970 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 970 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
971 installTranslation( (*it) + "/" + d->appName + ".qm" ); 971 installTranslation( (*it) + "/" + d->appName + ".qm" );
972} 972}
973#endif 973#endif
974 974
975 975
976static QPtrDict<void>* inputMethodDict = 0; 976static QPtrDict<void>* inputMethodDict = 0;
977static void createInputMethodDict() 977static void createInputMethodDict()
978{ 978{
979 if ( !inputMethodDict ) 979 if ( !inputMethodDict )
980 inputMethodDict = new QPtrDict<void>; 980 inputMethodDict = new QPtrDict<void>;
981} 981}
982 982
983/*! 983/*!
984 Returns the currently set hint to the system as to whether 984 Returns the currently set hint to the system as to whether
985 widget \a w has any use for text input methods. 985 widget \a w has any use for text input methods.
986 986
987 987
988 \sa setInputMethodHint() InputMethodHint 988 \sa setInputMethodHint() InputMethodHint
989*/ 989*/
990QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 990QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
991{ 991{
992 if ( inputMethodDict && w ) 992 if ( inputMethodDict && w )
993 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 993 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
994 return Normal; 994 return Normal;
995} 995}
996 996
997/*! 997/*!
998 \enum QPEApplication::InputMethodHint 998 \enum QPEApplication::InputMethodHint
999 999
1000 \value Normal the application sometimes needs text input (the default). 1000 \value Normal the application sometimes needs text input (the default).
1001 \value AlwaysOff the application never needs text input. 1001 \value AlwaysOff the application never needs text input.
1002 \value AlwaysOn the application always needs text input. 1002 \value AlwaysOn the application always needs text input.
1003*/ 1003*/
1004 1004
1005/*! 1005/*!
1006 Hints to the system that widget \a w has use for text input methods 1006 Hints to the system that widget \a w has use for text input methods
1007 as specified by \a mode. 1007 as specified by \a mode.
1008 1008
1009 \sa inputMethodHint() InputMethodHint 1009 \sa inputMethodHint() InputMethodHint
1010*/ 1010*/
1011void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1011void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
1012{ 1012{
1013 createInputMethodDict(); 1013 createInputMethodDict();
1014 if ( mode == Normal ) { 1014 if ( mode == Normal ) {
1015 inputMethodDict->remove 1015 inputMethodDict->remove
1016 ( w ); 1016 ( w );
1017 } 1017 }
1018 else { 1018 else {
1019 inputMethodDict->insert( w, ( void* ) mode ); 1019 inputMethodDict->insert( w, ( void* ) mode );
1020 } 1020 }
1021} 1021}
1022 1022
1023class HackDialog : public QDialog 1023class HackDialog : public QDialog
1024{ 1024{
1025public: 1025public:
1026 void acceptIt() 1026 void acceptIt()
1027 { 1027 {
1028 accept(); 1028 accept();
1029 } 1029 }
1030 void rejectIt() 1030 void rejectIt()
1031 { 1031 {
1032 reject(); 1032 reject();
1033 } 1033 }
1034}; 1034};
1035 1035
1036 1036
1037void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1037void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
1038{ 1038{
1039 // specialised actions for certain widgets. May want to 1039 // specialised actions for certain widgets. May want to
1040 // add more stuff here. 1040 // add more stuff here.
1041 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1041 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
1042 && activePopupWidget() ->parentWidget() 1042 && activePopupWidget() ->parentWidget()
1043 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1043 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
1044 key = Qt::Key_Return; 1044 key = Qt::Key_Return;
1045 1045
1046 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1046 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
1047 key = Qt::Key_Return; 1047 key = Qt::Key_Return;
1048 1048
1049#ifdef QWS 1049#ifdef QWS
1050 1050
1051 ke->simpleData.keycode = key; 1051 ke->simpleData.keycode = key;
1052#endif 1052#endif
1053} 1053}
1054 1054
1055 1055
1056/*! 1056/*!
1057 \internal 1057 \internal
1058*/ 1058*/
1059 1059
1060#ifdef QWS 1060#ifdef QWS
1061bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1061bool QPEApplication::qwsEventFilter( QWSEvent * e )
1062{ 1062{
1063 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1063 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
1064 if ( qApp->type() != QApplication::GuiServer ) { 1064 if ( qApp->type() != QApplication::GuiServer ) {
1065 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1065 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
1066 e << d->appName; 1066 e << d->appName;
1067 } 1067 }
1068 d->notbusysent = TRUE; 1068 d->notbusysent = TRUE;
1069 } 1069 }
1070 if ( type() == GuiServer ) { 1070 if ( type() == GuiServer ) {
1071 switch ( e->type ) { 1071 switch ( e->type ) {
1072 case QWSEvent::Mouse: 1072 case QWSEvent::Mouse:
1073 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1073 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
1074 emit clientMoused(); 1074 emit clientMoused();
1075 break; 1075 break;
1076 default: 1076 default:
1077 break; 1077 break;
1078 } 1078 }
1079 } 1079 }
1080 if ( e->type == QWSEvent::Key ) { 1080 if ( e->type == QWSEvent::Key ) {
1081 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1081 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
1082 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1082 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
1083 // Use special "OK" key to press "OK" on top level widgets 1083 // Use special "OK" key to press "OK" on top level widgets
1084 QWidget * active = activeWindow(); 1084 QWidget * active = activeWindow();
1085 QWidget *popup = 0; 1085 QWidget *popup = 0;
1086 if ( active && active->isPopup() ) { 1086 if ( active && active->isPopup() ) {
1087 popup = active; 1087 popup = active;
1088 active = active->parentWidget(); 1088 active = active->parentWidget();
1089 } 1089 }
1090 if ( active && ( int ) active->winId() == ke->simpleData.window && 1090 if ( active && ( int ) active->winId() == ke->simpleData.window &&
1091 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1091 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1092 if ( ke->simpleData.is_press ) { 1092 if ( ke->simpleData.is_press ) {
1093 if ( popup ) 1093 if ( popup )
1094 popup->close(); 1094 popup->close();
1095 if ( active->inherits( "QDialog" ) ) { 1095 if ( active->inherits( "QDialog" ) ) {
1096 HackDialog * d = ( HackDialog * ) active; 1096 HackDialog * d = ( HackDialog * ) active;
1097 d->acceptIt(); 1097 d->acceptIt();
1098 return TRUE; 1098 return TRUE;
1099 } 1099 }
1100 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1100 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
1101 QSignal s; 1101 QSignal s;
1102 s.connect( active, SLOT( accept() ) ); 1102 s.connect( active, SLOT( accept() ) );
1103 s.activate(); 1103 s.activate();
1104 } 1104 }
1105 else { 1105 else {
1106 // do the same as with the select key: Map to the default action of the widget: 1106 // do the same as with the select key: Map to the default action of the widget:
1107 mapToDefaultAction( ke, Qt::Key_Return ); 1107 mapToDefaultAction( ke, Qt::Key_Return );
1108 } 1108 }
1109 } 1109 }
1110 } 1110 }
1111 } 1111 }
1112 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1112 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
1113 // Use special "select" key to do whatever default action a widget has 1113 // Use special "select" key to do whatever default action a widget has
1114 mapToDefaultAction( ke, Qt::Key_Space ); 1114 mapToDefaultAction( ke, Qt::Key_Space );
1115 } 1115 }
1116 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1116 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
1117 ke->simpleData.is_press ) { 1117 ke->simpleData.is_press ) {
1118 // Escape key closes app if focus on toplevel 1118 // Escape key closes app if focus on toplevel
1119 QWidget * active = activeWindow(); 1119 QWidget * active = activeWindow();
1120 if ( active && active->testWFlags( WType_TopLevel ) && 1120 if ( active && active->testWFlags( WType_TopLevel ) &&
1121 ( int ) active->winId() == ke->simpleData.window && 1121 ( int ) active->winId() == ke->simpleData.window &&
1122 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1122 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1123 if ( active->inherits( "QDialog" ) ) { 1123 if ( active->inherits( "QDialog" ) ) {
1124 HackDialog * d = ( HackDialog * ) active; 1124 HackDialog * d = ( HackDialog * ) active;
1125 d->rejectIt(); 1125 d->rejectIt();
1126 return TRUE; 1126 return TRUE;
1127 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { 1127 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ {
1128 active->close(); 1128 active->close();
1129 } 1129 }
1130 } 1130 }
1131 1131
1132 } 1132 }
1133 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1133 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
1134 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1134 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
1135 // but we cannot access libopie function within libqpe :( 1135 // but we cannot access libopie function within libqpe :(
1136 1136
1137 QWidget * active = activeWindow ( ); 1137 QWidget * active = activeWindow ( );
1138 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1138 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
1139 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1139 if ( d-> kbgrabbed ) { // we grabbed the keyboard
1140 QChar ch ( ke-> simpleData.unicode ); 1140 QChar ch ( ke-> simpleData.unicode );
1141 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1141 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
1142 ke-> simpleData.keycode, 1142 ke-> simpleData.keycode,
1143 ch. latin1 ( ), 1143 ch. latin1 ( ),
1144 ke-> simpleData.modifiers, 1144 ke-> simpleData.modifiers,
1145 QString ( ch ), 1145 QString ( ch ),
1146 ke-> simpleData.is_auto_repeat, 1 ); 1146 ke-> simpleData.is_auto_repeat, 1 );
1147 1147
1148 QObject *which = QWidget::keyboardGrabber ( ); 1148 QObject *which = QWidget::keyboardGrabber ( );
1149 if ( !which ) 1149 if ( !which )
1150 which = QApplication::focusWidget ( ); 1150 which = QApplication::focusWidget ( );
1151 if ( !which ) 1151 if ( !which )
1152 which = QApplication::activeWindow ( ); 1152 which = QApplication::activeWindow ( );
1153 if ( !which ) 1153 if ( !which )
1154 which = qApp; 1154 which = qApp;
1155 1155
1156 QApplication::sendEvent ( which, &qke ); 1156 QApplication::sendEvent ( which, &qke );
1157 } 1157 }
1158 else { // we didn't grab the keyboard, so send the event to the launcher 1158 else { // we didn't grab the keyboard, so send the event to the launcher
1159 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1159 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
1160 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1160 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
1161 } 1161 }
1162 } 1162 }
1163 return true; 1163 return true;
1164 } 1164 }
1165 } 1165 }
1166 if ( e->type == QWSEvent::Focus ) { 1166 if ( e->type == QWSEvent::Focus ) {
1167 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1167 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
1168 if ( !fe->simpleData.get_focus ) { 1168 if ( !fe->simpleData.get_focus ) {
1169 QWidget * active = activeWindow(); 1169 QWidget * active = activeWindow();
1170 while ( active && active->isPopup() ) { 1170 while ( active && active->isPopup() ) {
1171 active->close(); 1171 active->close();
1172 active = activeWindow(); 1172 active = activeWindow();
1173 } 1173 }
1174 } 1174 }
1175 else { 1175 else {
1176 // make sure our modal widget is ALWAYS on top 1176 // make sure our modal widget is ALWAYS on top
1177 QWidget *topm = activeModalWidget(); 1177 QWidget *topm = activeModalWidget();
1178 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1178 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
1179 topm->raise(); 1179 topm->raise();
1180 } 1180 }
1181 } 1181 }
1182 if ( fe->simpleData.get_focus && inputMethodDict ) { 1182 if ( fe->simpleData.get_focus && inputMethodDict ) {
1183 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1183 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1184 if ( m == AlwaysOff ) 1184 if ( m == AlwaysOff )
1185 Global::hideInputMethod(); 1185 Global::hideInputMethod();
1186 if ( m == AlwaysOn ) 1186 if ( m == AlwaysOn )
1187 Global::showInputMethod(); 1187 Global::showInputMethod();
1188 } 1188 }
1189 } 1189 }
1190 1190
1191 1191
1192 return QApplication::qwsEventFilter( e ); 1192 return QApplication::qwsEventFilter( e );
1193} 1193}
1194#endif 1194#endif
1195 1195
1196/*! 1196/*!
1197 Destroys the QPEApplication. 1197 Destroys the QPEApplication.
1198*/ 1198*/
1199QPEApplication::~QPEApplication() 1199QPEApplication::~QPEApplication()
1200{ 1200{
1201 ungrabKeyboard(); 1201 ungrabKeyboard();
1202#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1202#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1203 // Need to delete QCopChannels early, since the display will 1203 // Need to delete QCopChannels early, since the display will
1204 // be gone by the time we get to ~QObject(). 1204 // be gone by the time we get to ~QObject().
1205 delete sysChannel; 1205 delete sysChannel;
1206 delete pidChannel; 1206 delete pidChannel;
1207#endif 1207#endif
1208 1208
1209 delete d; 1209 delete d;
1210} 1210}
1211 1211
1212/*! 1212/*!
1213 Returns <tt>$OPIEDIR/</tt>. 1213 Returns <tt>$OPIEDIR/</tt>.
1214*/ 1214*/
1215QString QPEApplication::qpeDir() 1215QString QPEApplication::qpeDir()
1216{ 1216{
1217 const char * base = getenv( "OPIEDIR" ); 1217 const char * base = getenv( "OPIEDIR" );
1218 if ( base ) 1218 if ( base )
1219 return QString( base ) + "/"; 1219 return QString( base ) + "/";
1220 1220
1221 return QString( "../" ); 1221 return QString( "../" );
1222} 1222}
1223 1223
1224/*! 1224/*!
1225 Returns the user's current Document directory. There is a trailing "/". 1225 Returns the user's current Document directory. There is a trailing "/".
1226 .. well, it does now,, and there's no trailing '/' 1226 .. well, it does now,, and there's no trailing '/'
1227*/ 1227*/
1228QString QPEApplication::documentDir() 1228QString QPEApplication::documentDir()
1229{ 1229{
1230 const char* base = getenv( "HOME"); 1230 const char* base = getenv( "HOME");
1231 if ( base ) 1231 if ( base )
1232 return QString( base ) + "/Documents"; 1232 return QString( base ) + "/Documents";
1233 1233
1234 return QString( "../Documents" ); 1234 return QString( "../Documents" );
1235} 1235}
1236 1236
1237static int deforient = -1; 1237static int deforient = -1;
1238 1238
1239/*! 1239/*!
1240 \internal 1240 \internal
1241*/ 1241*/
1242int QPEApplication::defaultRotation() 1242int QPEApplication::defaultRotation()
1243{ 1243{
1244 if ( deforient < 0 ) { 1244 if ( deforient < 0 ) {
1245 QString d = getenv( "QWS_DISPLAY" ); 1245 QString d = getenv( "QWS_DISPLAY" );
1246 if ( d.contains( "Rot90" ) ) { 1246 if ( d.contains( "Rot90" ) ) {
1247 deforient = 90; 1247 deforient = 90;
1248 } 1248 }
1249 else if ( d.contains( "Rot180" ) ) { 1249 else if ( d.contains( "Rot180" ) ) {
1250 deforient = 180; 1250 deforient = 180;
1251 } 1251 }
1252 else if ( d.contains( "Rot270" ) ) { 1252 else if ( d.contains( "Rot270" ) ) {
1253 deforient = 270; 1253 deforient = 270;
1254 } 1254 }
1255 else { 1255 else {
1256 deforient = 0; 1256 deforient = 0;
1257 } 1257 }
1258 } 1258 }
1259 return deforient; 1259 return deforient;
1260} 1260}
1261 1261
1262/*! 1262/*!
1263 \internal 1263 \internal
1264*/ 1264*/
1265void QPEApplication::setDefaultRotation( int r ) 1265void QPEApplication::setDefaultRotation( int r )
1266{ 1266{
1267 if ( qApp->type() == GuiServer ) { 1267 if ( qApp->type() == GuiServer ) {
1268 deforient = r; 1268 deforient = r;
1269 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1269 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1270 Config config("qpe"); 1270 Config config("qpe");
1271 config.setGroup( "Rotation" ); 1271 config.setGroup( "Rotation" );
1272 config.writeEntry( "Rot", r ); 1272 config.writeEntry( "Rot", r );
1273 } 1273 }
1274 else { 1274 else {
1275#ifndef QT_NO_COP 1275#ifndef QT_NO_COP
1276 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1276 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1277 e << r; 1277 e << r;
1278 } 1278 }
1279#endif 1279#endif
1280 1280
1281 } 1281 }
1282} 1282}
1283 1283
1284#include <qgfx_qws.h> 1284#include <qgfx_qws.h>
1285#include <qwindowsystem_qws.h> 1285#include <qwindowsystem_qws.h>
1286 1286
1287#if QT_VERSION > 236
1287extern void qws_clearLoadedFonts(); 1288extern void qws_clearLoadedFonts();
1289#endif
1288 1290
1289void QPEApplication::setCurrentMode( int x, int y, int depth ) 1291void QPEApplication::setCurrentMode( int x, int y, int depth )
1290{ 1292{
1291 // Reset the caches 1293 // Reset the caches
1294#if QT_VERSION > 236
1292 qws_clearLoadedFonts(); 1295 qws_clearLoadedFonts();
1296#endif
1293 QPixmapCache::clear(); 1297 QPixmapCache::clear();
1294 1298
1295 // Change the screen mode 1299 // Change the screen mode
1296 qt_screen->setMode(x, y, depth); 1300 qt_screen->setMode(x, y, depth);
1297 1301
1298 if ( qApp->type() == GuiServer ) { 1302 if ( qApp->type() == GuiServer ) {
1299#if QT_VERSION > 236 1303#if QT_VERSION > 236
1300 // Reconfigure the GuiServer 1304 // Reconfigure the GuiServer
1301 qwsServer->beginDisplayReconfigure(); 1305 qwsServer->beginDisplayReconfigure();
1302 qwsServer->endDisplayReconfigure(); 1306 qwsServer->endDisplayReconfigure();
1303#endif 1307#endif
1304 // Get all the running apps to reset 1308 // Get all the running apps to reset
1305 QCopEnvelope env( "QPE/System", "reset()" ); 1309 QCopEnvelope env( "QPE/System", "reset()" );
1306 } 1310 }
1307} 1311}
1308 1312
1309void QPEApplication::reset() { 1313void QPEApplication::reset() {
1310 // Reconnect to the screen 1314 // Reconnect to the screen
1311 qt_screen->disconnect(); 1315 qt_screen->disconnect();
1312 qt_screen->connect( QString::null ); 1316 qt_screen->connect( QString::null );
1313 1317
1314 // Redraw everything 1318 // Redraw everything
1315 applyStyle(); 1319 applyStyle();
1316} 1320}
1317 1321
1318#if (QT_VERSION < 238) && defined Q_OS_MACX 1322#if (QT_VERSION < 238) && defined Q_OS_MACX
1319bool qt_left_hand_scrollbars = false; 1323bool qt_left_hand_scrollbars = false;
1320#else 1324#else
1321#ifdef Q_OS_MACX 1325#ifdef Q_OS_MACX
1322#define WEAK_SYMBOL __attribute__((weak_import)) 1326#define WEAK_SYMBOL __attribute__((weak_import))
1323#else 1327#else
1324#define WEAK_SYMBOL __attribute__((weak)) 1328#define WEAK_SYMBOL __attribute__((weak))
1325#endif 1329#endif
1326extern bool qt_left_hand_scrollbars WEAK_SYMBOL; 1330extern bool qt_left_hand_scrollbars WEAK_SYMBOL;
1327#endif 1331#endif
1328 1332
1329/*! 1333/*!
1330 \internal 1334 \internal
1331*/ 1335*/
1332void QPEApplication::applyStyle() 1336void QPEApplication::applyStyle()
1333{ 1337{
1334 Config config( "qpe" ); 1338 Config config( "qpe" );
1335 config.setGroup( "Appearance" ); 1339 config.setGroup( "Appearance" );
1336 1340
1337#if QT_VERSION > 233 1341#if QT_VERSION > 233
1338#if !defined(OPIE_NO_OVERRIDE_QT) 1342#if !defined(OPIE_NO_OVERRIDE_QT)
1339 // don't block ourselves ... 1343 // don't block ourselves ...
1340 Opie::force_appearance = 0; 1344 Opie::force_appearance = 0;
1341 1345
1342 static QString appname = Opie::binaryName ( ); 1346 static QString appname = Opie::binaryName ( );
1343 1347
1344 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1348 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1345 int nostyle = 0; 1349 int nostyle = 0;
1346 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1350 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1347 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1351 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1348 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1352 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1349 break; 1353 break;
1350 } 1354 }
1351 } 1355 }
1352#else 1356#else
1353 int nostyle = 0; 1357 int nostyle = 0;
1354#endif 1358#endif
1355 1359
1356 // Widget style 1360 // Widget style
1357 QString style = config.readEntry( "Style", "FlatStyle" ); 1361 QString style = config.readEntry( "Style", "FlatStyle" );
1358 1362
1359 // don't set a custom style 1363 // don't set a custom style
1360 if ( nostyle & Opie::Force_Style ) 1364 if ( nostyle & Opie::Force_Style )
1361 style = "FlatStyle"; 1365 style = "FlatStyle";
1362 1366
1363 internalSetStyle ( style ); 1367 internalSetStyle ( style );
1364 1368
1365 // Colors - from /etc/colors/Liquid.scheme 1369 // Colors - from /etc/colors/Liquid.scheme
1366 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1370 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1367 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1371 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1368 QPalette pal( btncolor, bgcolor ); 1372 QPalette pal( btncolor, bgcolor );
1369 QString color = config.readEntry( "Highlight", "#73adef" ); 1373 QString color = config.readEntry( "Highlight", "#73adef" );
1370 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1374 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1371 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1375 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1372 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1376 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1373 color = config.readEntry( "Text", "#000000" ); 1377 color = config.readEntry( "Text", "#000000" );
1374 pal.setColor( QColorGroup::Text, QColor( color ) ); 1378 pal.setColor( QColorGroup::Text, QColor( color ) );
1375 color = config.readEntry( "ButtonText", "#000000" ); 1379 color = config.readEntry( "ButtonText", "#000000" );
1376 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1380 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1377 color = config.readEntry( "Base", "#FFFFFF" ); 1381 color = config.readEntry( "Base", "#FFFFFF" );
1378 pal.setColor( QColorGroup::Base, QColor( color ) ); 1382 pal.setColor( QColorGroup::Base, QColor( color ) );
1379 1383
1380 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1384 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1381 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1385 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1382 1386
1383 setPalette( pal, TRUE ); 1387 setPalette( pal, TRUE );
1384 1388
1385 1389
1386 // Set the ScrollBar on the 'right' side but only if the weak symbol is present 1390 // Set the ScrollBar on the 'right' side but only if the weak symbol is present
1387 if (&qt_left_hand_scrollbars ) 1391 if (&qt_left_hand_scrollbars )
1388 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); 1392 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false );
1389 1393
1390 // Window Decoration 1394 // Window Decoration
1391 QString dec = config.readEntry( "Decoration", "Flat" ); 1395 QString dec = config.readEntry( "Decoration", "Flat" );
1392 1396
1393 // don't set a custom deco 1397 // don't set a custom deco
1394 if ( nostyle & Opie::Force_Decoration ) 1398 if ( nostyle & Opie::Force_Decoration )
1395 dec = ""; 1399 dec = "";
1396 1400
1397 1401
1398 if ( dec != d->decorationName ) { 1402 if ( dec != d->decorationName ) {
1399 qwsSetDecoration( new QPEDecoration( dec ) ); 1403 qwsSetDecoration( new QPEDecoration( dec ) );
1400 d->decorationName = dec; 1404 d->decorationName = dec;
1401 } 1405 }
1402 1406
1403 // Font 1407 // Font
1404 QString ff = config.readEntry( "FontFamily", font().family() ); 1408 QString ff = config.readEntry( "FontFamily", font().family() );
1405 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1409 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1406 1410
1407 // don't set a custom font 1411 // don't set a custom font
1408 if ( nostyle & Opie::Force_Font ) { 1412 if ( nostyle & Opie::Force_Font ) {
1409 ff = "Vera"; 1413 ff = "Vera";
1410 fs = 10; 1414 fs = 10;
1411 } 1415 }
1412 1416
1413 setFont ( QFont ( ff, fs ), true ); 1417 setFont ( QFont ( ff, fs ), true );
1414 1418
1415#if !defined(OPIE_NO_OVERRIDE_QT) 1419#if !defined(OPIE_NO_OVERRIDE_QT)
1416 // revert to global blocking policy ... 1420 // revert to global blocking policy ...
1417 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1421 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1418 Opie::force_appearance &= ~nostyle; 1422 Opie::force_appearance &= ~nostyle;
1419#endif 1423#endif
1420#endif 1424#endif
1421} 1425}
1422 1426
1423void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1427void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1424{ 1428{
1425#ifdef Q_WS_QWS 1429#ifdef Q_WS_QWS
1426 QDataStream stream( data, IO_ReadOnly ); 1430 QDataStream stream( data, IO_ReadOnly );
1427 if ( msg == "applyStyle()" ) { 1431 if ( msg == "applyStyle()" ) {
1428 applyStyle(); 1432 applyStyle();
1429 } 1433 }
1430 else if ( msg == "toggleApplicationMenu()" ) { 1434 else if ( msg == "toggleApplicationMenu()" ) {
1431 QWidget *active = activeWindow ( ); 1435 QWidget *active = activeWindow ( );
1432 1436
1433 if ( active ) { 1437 if ( active ) {
1434 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1438 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1435 bool oldactive = man-> isActive ( ); 1439 bool oldactive = man-> isActive ( );
1436 1440
1437 man-> setActive( !man-> isActive() ); 1441 man-> setActive( !man-> isActive() );
1438 1442
1439 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1443 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1440 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1444 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1441 } 1445 }
1442 } 1446 }
1443 } 1447 }
1444 else if ( msg == "setDefaultRotation(int)" ) { 1448 else if ( msg == "setDefaultRotation(int)" ) {
1445 if ( type() == GuiServer ) { 1449 if ( type() == GuiServer ) {
1446 int r; 1450 int r;
1447 stream >> r; 1451 stream >> r;
1448 setDefaultRotation( r ); 1452 setDefaultRotation( r );
1449 } 1453 }
1450 } 1454 }
1451 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1455 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1452 if ( type() == GuiServer ) { 1456 if ( type() == GuiServer ) {
1453 int x, y, depth; 1457 int x, y, depth;
1454 stream >> x; 1458 stream >> x;
1455 stream >> y; 1459 stream >> y;
1456 stream >> depth; 1460 stream >> depth;
1457 setCurrentMode( x, y, depth ); 1461 setCurrentMode( x, y, depth );
1458 } 1462 }
1459 } 1463 }
1460 else if ( msg == "reset()" ) { 1464 else if ( msg == "reset()" ) {
1461 if ( type() != GuiServer ) 1465 if ( type() != GuiServer )
1462 reset(); 1466 reset();
1463 } 1467 }
1464 else if ( msg == "setCurrentRotation(int)" ) { 1468 else if ( msg == "setCurrentRotation(int)" ) {
1465 int r; 1469 int r;
1466 stream >> r; 1470 stream >> r;
1467 setCurrentRotation( r ); 1471 setCurrentRotation( r );
1468 } 1472 }
1469 else if ( msg == "shutdown()" ) { 1473 else if ( msg == "shutdown()" ) {
1470 if ( type() == GuiServer ) 1474 if ( type() == GuiServer )
1471 shutdown(); 1475 shutdown();
1472 } 1476 }
1473 else if ( msg == "quit()" ) { 1477 else if ( msg == "quit()" ) {
1474 if ( type() != GuiServer ) 1478 if ( type() != GuiServer )
1475 tryQuit(); 1479 tryQuit();
1476 } 1480 }
1477 else if ( msg == "forceQuit()" ) { 1481 else if ( msg == "forceQuit()" ) {
1478 if ( type() != GuiServer ) 1482 if ( type() != GuiServer )
1479 quit(); 1483 quit();
1480 } 1484 }
1481 else if ( msg == "restart()" ) { 1485 else if ( msg == "restart()" ) {
1482 if ( type() == GuiServer ) 1486 if ( type() == GuiServer )
1483 restart(); 1487 restart();
1484 } 1488 }
1485 else if ( msg == "language(QString)" ) { 1489 else if ( msg == "language(QString)" ) {
1486 if ( type() == GuiServer ) { 1490 if ( type() == GuiServer ) {
1487 QString l; 1491 QString l;
1488 stream >> l; 1492 stream >> l;
1489 QString cl = getenv( "LANG" ); 1493 QString cl = getenv( "LANG" );
1490 if ( cl != l ) { 1494 if ( cl != l ) {
1491 if ( l.isNull() ) 1495 if ( l.isNull() )
1492 unsetenv( "LANG" ); 1496 unsetenv( "LANG" );
1493 else 1497 else
1494 setenv( "LANG", l.latin1(), 1 ); 1498 setenv( "LANG", l.latin1(), 1 );
1495 restart(); 1499 restart();
1496 } 1500 }
1497 } 1501 }
1498 } 1502 }
1499 else if ( msg == "timeChange(QString)" ) { 1503 else if ( msg == "timeChange(QString)" ) {
1500 QString t; 1504 QString t;
1501 stream >> t; 1505 stream >> t;
1502 if ( t.isNull() ) 1506 if ( t.isNull() )
1503 unsetenv( "TZ" ); 1507 unsetenv( "TZ" );
1504 else 1508 else
1505 setenv( "TZ", t.latin1(), 1 ); 1509 setenv( "TZ", t.latin1(), 1 );
1506 // emit the signal so everyone else knows... 1510 // emit the signal so everyone else knows...
1507 emit timeChanged(); 1511 emit timeChanged();
1508 } 1512 }
1509 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1513 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1510 if ( type() == GuiServer ) { 1514 if ( type() == GuiServer ) {
1511 QDateTime when; 1515 QDateTime when;
1512 QCString channel, message; 1516 QCString channel, message;
1513 int data; 1517 int data;
1514 stream >> when >> channel >> message >> data; 1518 stream >> when >> channel >> message >> data;
1515 AlarmServer::addAlarm( when, channel, message, data ); 1519 AlarmServer::addAlarm( when, channel, message, data );
1516 } 1520 }
1517 } 1521 }
1518 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1522 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1519 if ( type() == GuiServer ) { 1523 if ( type() == GuiServer ) {
1520 QDateTime when; 1524 QDateTime when;
1521 QCString channel, message; 1525 QCString channel, message;
1522 int data; 1526 int data;
1523 stream >> when >> channel >> message >> data; 1527 stream >> when >> channel >> message >> data;
1524 AlarmServer::deleteAlarm( when, channel, message, data ); 1528 AlarmServer::deleteAlarm( when, channel, message, data );
1525 } 1529 }
1526 } 1530 }
1527 else if ( msg == "clockChange(bool)" ) { 1531 else if ( msg == "clockChange(bool)" ) {
1528 int tmp; 1532 int tmp;
1529 stream >> tmp; 1533 stream >> tmp;
1530 emit clockChanged( tmp ); 1534 emit clockChanged( tmp );
1531 } 1535 }
1532 else if ( msg == "weekChange(bool)" ) { 1536 else if ( msg == "weekChange(bool)" ) {
1533 int tmp; 1537 int tmp;
1534 stream >> tmp; 1538 stream >> tmp;
1535 emit weekChanged( tmp ); 1539 emit weekChanged( tmp );
1536 } 1540 }
1537 else if ( msg == "setDateFormat(DateFormat)" ) { 1541 else if ( msg == "setDateFormat(DateFormat)" ) {
1538 DateFormat tmp; 1542 DateFormat tmp;
1539 stream >> tmp; 1543 stream >> tmp;
1540 emit dateFormatChanged( tmp ); 1544 emit dateFormatChanged( tmp );
1541 } 1545 }
1542 else if ( msg == "setVolume(int,int)" ) { 1546 else if ( msg == "setVolume(int,int)" ) {
1543 int t, v; 1547 int t, v;
1544 stream >> t >> v; 1548 stream >> t >> v;
1545 setVolume( t, v ); 1549 setVolume( t, v );
1546 emit volumeChanged( muted ); 1550 emit volumeChanged( muted );
1547 } 1551 }
1548 else if ( msg == "volumeChange(bool)" ) { 1552 else if ( msg == "volumeChange(bool)" ) {
1549 stream >> muted; 1553 stream >> muted;
1550 setVolume(); 1554 setVolume();
1551 emit volumeChanged( muted ); 1555 emit volumeChanged( muted );
1552 } 1556 }
1553 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1557 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1554 int t, v; 1558 int t, v;
1555 stream >> t >> v; 1559 stream >> t >> v;
1556 setMic( t, v ); 1560 setMic( t, v );
1557 emit micChanged( micMuted ); 1561 emit micChanged( micMuted );
1558 } 1562 }
1559 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1563 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1560 stream >> micMuted; 1564 stream >> micMuted;
1561 setMic(); 1565 setMic();
1562 emit micChanged( micMuted ); 1566 emit micChanged( micMuted );
1563 } 1567 }
1564 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1568 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1565 int t, v; 1569 int t, v;
1566 stream >> t >> v; 1570 stream >> t >> v;
1567 setBass( t, v ); 1571 setBass( t, v );
1568 } 1572 }
1569 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1573 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1570 setBass(); 1574 setBass();
1571 } 1575 }
1572 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1576 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1573 int t, v; 1577 int t, v;
1574 stream >> t >> v; 1578 stream >> t >> v;
1575 setTreble( t, v ); 1579 setTreble( t, v );
1576 } 1580 }
1577 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1581 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1578 setTreble(); 1582 setTreble();
1579 } else if ( msg == "getMarkedText()" ) { 1583 } else if ( msg == "getMarkedText()" ) {
1580 if ( type() == GuiServer ) { 1584 if ( type() == GuiServer ) {
1581 const ushort unicode = 'C'-'@'; 1585 const ushort unicode = 'C'-'@';
1582 const int scan = Key_C; 1586 const int scan = Key_C;
1583 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1587 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1584 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1588 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1585 } 1589 }
1586 } else if ( msg == "newChannel(QString)") { 1590 } else if ( msg == "newChannel(QString)") {
1587 QString myChannel = "QPE/Application/" + d->appName; 1591 QString myChannel = "QPE/Application/" + d->appName;
1588 QString channel; 1592 QString channel;
1589 stream >> channel; 1593 stream >> channel;
1590 if (channel == myChannel) { 1594 if (channel == myChannel) {
1591 processQCopFile(); 1595 processQCopFile();
1592 d->sendQCopQ(); 1596 d->sendQCopQ();
1593 } 1597 }
1594 } 1598 }
1595 1599
1596 1600
1597#endif 1601#endif
1598} 1602}
1599 1603
1600 1604
1601 1605
1602 1606
1603 1607
1604/*! 1608/*!
1605 \internal 1609 \internal
1606*/ 1610*/
1607bool QPEApplication::raiseAppropriateWindow() 1611bool QPEApplication::raiseAppropriateWindow()
1608{ 1612{
1609 bool r=FALSE; 1613 bool r=FALSE;
1610 1614
1611 // 1. Raise the main widget 1615 // 1. Raise the main widget
1612 QWidget *top = d->qpe_main_widget; 1616 QWidget *top = d->qpe_main_widget;
1613 if ( !top ) top = mainWidget(); 1617 if ( !top ) top = mainWidget();
1614 1618
1615 if ( top && d->keep_running ) { 1619 if ( top && d->keep_running ) {
1616 if ( top->isVisible() ) 1620 if ( top->isVisible() )
1617 r = TRUE; 1621 r = TRUE;
1618 else if (d->preloaded) { 1622 else if (d->preloaded) {
1619 // We are preloaded and not visible.. pretend we just started.. 1623 // We are preloaded and not visible.. pretend we just started..
1620#ifndef QT_NO_COP 1624#ifndef QT_NO_COP
1621 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1625 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1622 e << d->appName; 1626 e << d->appName;
1623#endif 1627#endif
1624 } 1628 }
1625 1629
1626 d->show_mx(top,d->nomaximize, d->appName); 1630 d->show_mx(top,d->nomaximize, d->appName);
1627 top->raise(); 1631 top->raise();
1628 } 1632 }
1629 1633
1630 QWidget *topm = activeModalWidget(); 1634 QWidget *topm = activeModalWidget();
1631 1635
1632 // 2. Raise any parentless widgets (except top and topm, as they 1636 // 2. Raise any parentless widgets (except top and topm, as they
1633 // are raised before and after this loop). Order from most 1637 // are raised before and after this loop). Order from most
1634 // recently raised as deepest to least recently as top, so 1638 // recently raised as deepest to least recently as top, so
1635 // that repeated calls cycle through widgets. 1639 // that repeated calls cycle through widgets.
1636 QWidgetList *list = topLevelWidgets(); 1640 QWidgetList *list = topLevelWidgets();
1637 if ( list ) { 1641 if ( list ) {
1638 bool foundlast = FALSE; 1642 bool foundlast = FALSE;
1639 QWidget* topsub = 0; 1643 QWidget* topsub = 0;
1640 if ( d->lastraised ) { 1644 if ( d->lastraised ) {
1641 for (QWidget* w = list->first(); w; w = list->next()) { 1645 for (QWidget* w = list->first(); w; w = list->next()) {
1642 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1646 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1643 if ( w == d->lastraised ) 1647 if ( w == d->lastraised )
1644 foundlast = TRUE; 1648 foundlast = TRUE;
1645 if ( foundlast ) { 1649 if ( foundlast ) {
1646 w->raise(); 1650 w->raise();
1647 topsub = w; 1651 topsub = w;
1648 } 1652 }
1649 } 1653 }
1650 } 1654 }
1651 } 1655 }
1652 for (QWidget* w = list->first(); w; w = list->next()) { 1656 for (QWidget* w = list->first(); w; w = list->next()) {
1653 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1657 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1654 if ( w == d->lastraised ) 1658 if ( w == d->lastraised )
1655 break; 1659 break;
1656 w->raise(); 1660 w->raise();
1657 topsub = w; 1661 topsub = w;
1658 } 1662 }
1659 } 1663 }
1660 d->lastraised = topsub; 1664 d->lastraised = topsub;
1661 delete list; 1665 delete list;
1662 } 1666 }
1663 1667
1664 // 3. Raise the active modal widget. 1668 // 3. Raise the active modal widget.
1665 if ( topm ) { 1669 if ( topm ) {
1666 topm->show(); 1670 topm->show();
1667 topm->raise(); 1671 topm->raise();
1668 // If we haven't already handled the fastAppShowing message 1672 // If we haven't already handled the fastAppShowing message
1669 if (!top && d->preloaded) { 1673 if (!top && d->preloaded) {
1670#ifndef QT_NO_COP 1674#ifndef QT_NO_COP
1671 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1675 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1672 e << d->appName; 1676 e << d->appName;
1673#endif 1677#endif
1674 } 1678 }
1675 r = FALSE; 1679 r = FALSE;
1676 } 1680 }
1677 1681
1678 return r; 1682 return r;
1679} 1683}
1680 1684
1681 1685
1682void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1686void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1683{ 1687{
1684#ifdef Q_WS_QWS 1688#ifdef Q_WS_QWS
1685 1689
1686 if ( msg == "quit()" ) { 1690 if ( msg == "quit()" ) {
1687 tryQuit(); 1691 tryQuit();
1688 } 1692 }
1689 else if ( msg == "quitIfInvisible()" ) { 1693 else if ( msg == "quitIfInvisible()" ) {
1690 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1694 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1691 quit(); 1695 quit();
1692 } 1696 }
1693 else if ( msg == "close()" ) { 1697 else if ( msg == "close()" ) {
1694 hideOrQuit(); 1698 hideOrQuit();
1695 } 1699 }
1696 else if ( msg == "disablePreload()" ) { 1700 else if ( msg == "disablePreload()" ) {
1697 d->preloaded = FALSE; 1701 d->preloaded = FALSE;
1698 d->keep_running = TRUE; 1702 d->keep_running = TRUE;
1699 /* so that quit will quit */ 1703 /* so that quit will quit */
1700 } 1704 }
1701 else if ( msg == "enablePreload()" ) { 1705 else if ( msg == "enablePreload()" ) {
1702 if (d->qpe_main_widget) 1706 if (d->qpe_main_widget)
1703 d->preloaded = TRUE; 1707 d->preloaded = TRUE;
1704 d->keep_running = TRUE; 1708 d->keep_running = TRUE;
1705 /* so next quit won't quit */ 1709 /* so next quit won't quit */
1706 } 1710 }
1707 else if ( msg == "raise()" ) { 1711 else if ( msg == "raise()" ) {
1708 d->keep_running = TRUE; 1712 d->keep_running = TRUE;
1709 d->notbusysent = FALSE; 1713 d->notbusysent = FALSE;
1710 raiseAppropriateWindow(); 1714 raiseAppropriateWindow();
1711 // Tell the system we're still chugging along... 1715 // Tell the system we're still chugging along...
1712 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1716 QCopEnvelope e("QPE/System", "appRaised(QString)");
1713 e << d->appName; 1717 e << d->appName;
1714 } 1718 }
1715 else if ( msg == "flush()" ) { 1719 else if ( msg == "flush()" ) {
1716 emit flush(); 1720 emit flush();
1717 // we need to tell the desktop 1721 // we need to tell the desktop
1718 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1722 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1719 e << d->appName; 1723 e << d->appName;
1720 } 1724 }
1721 else if ( msg == "reload()" ) { 1725 else if ( msg == "reload()" ) {
1722 emit reload(); 1726 emit reload();
1723 } 1727 }
1724 else if ( msg == "setDocument(QString)" ) { 1728 else if ( msg == "setDocument(QString)" ) {
1725 d->keep_running = TRUE; 1729 d->keep_running = TRUE;
1726 QDataStream stream( data, IO_ReadOnly ); 1730 QDataStream stream( data, IO_ReadOnly );
1727 QString doc; 1731 QString doc;
1728 stream >> doc; 1732 stream >> doc;
1729 QWidget *mw = mainWidget(); 1733 QWidget *mw = mainWidget();
1730 if ( !mw ) 1734 if ( !mw )
1731 mw = d->qpe_main_widget; 1735 mw = d->qpe_main_widget;
1732 if ( mw ) 1736 if ( mw )
1733 Global::setDocument( mw, doc ); 1737 Global::setDocument( mw, doc );
1734 1738
1735 } else if ( msg == "QPEProcessQCop()" ) { 1739 } else if ( msg == "QPEProcessQCop()" ) {
1736 processQCopFile(); 1740 processQCopFile();
1737 d->sendQCopQ(); 1741 d->sendQCopQ();
1738 }else 1742 }else
1739 { 1743 {
1740 bool p = d->keep_running; 1744 bool p = d->keep_running;
1741 d->keep_running = FALSE; 1745 d->keep_running = FALSE;
1742 emit appMessage( msg, data); 1746 emit appMessage( msg, data);
1743 if ( d->keep_running ) { 1747 if ( d->keep_running ) {
1744 d->notbusysent = FALSE; 1748 d->notbusysent = FALSE;
1745 raiseAppropriateWindow(); 1749 raiseAppropriateWindow();
1746 if ( !p ) { 1750 if ( !p ) {
1747 // Tell the system we're still chugging along... 1751 // Tell the system we're still chugging along...
1748#ifndef QT_NO_COP 1752#ifndef QT_NO_COP
1749 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1753 QCopEnvelope e("QPE/System", "appRaised(QString)");
1750 e << d->appName; 1754 e << d->appName;
1751#endif 1755#endif
1752 } 1756 }
1753 } 1757 }
1754 if ( p ) 1758 if ( p )
1755 d->keep_running = p; 1759 d->keep_running = p;
1756 } 1760 }
1757#endif 1761#endif
1758} 1762}
1759 1763
1760 1764
1761/*! 1765/*!
1762 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1766 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1763 consider passing TRUE for \a nomaximize rather than the default FALSE. 1767 consider passing TRUE for \a nomaximize rather than the default FALSE.
1764 1768
1765 \sa showMainDocumentWidget() 1769 \sa showMainDocumentWidget()
1766*/ 1770*/
1767void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1771void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1768{ 1772{
1769// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit 1773// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit
1770 d->show(mw, nomaximize ); 1774 d->show(mw, nomaximize );
1771} 1775}
1772 1776
1773/*! 1777/*!
1774 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1778 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1775 consider passing TRUE for \a nomaximize rather than the default FALSE. 1779 consider passing TRUE for \a nomaximize rather than the default FALSE.
1776 1780
1777 This calls designates the application as 1781 This calls designates the application as
1778 a \link docwidget.html document-oriented\endlink application. 1782 a \link docwidget.html document-oriented\endlink application.
1779 1783
1780 The \a mw widget \e must have this slot: setDocument(const QString&). 1784 The \a mw widget \e must have this slot: setDocument(const QString&).
1781 1785
1782 \sa showMainWidget() 1786 \sa showMainWidget()
1783*/ 1787*/
1784void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1788void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1785{ 1789{
1786 if ( mw && argc() == 2 ) 1790 if ( mw && argc() == 2 )
1787 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1791 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1788 1792
1789 1793
1790// setMainWidget(mw); see above 1794// setMainWidget(mw); see above
1791 d->show(mw, nomaximize ); 1795 d->show(mw, nomaximize );
1792} 1796}
1793 1797
1794 1798
1795/*! 1799/*!
1796 If an application is started via a \link qcop.html QCop\endlink 1800 If an application is started via a \link qcop.html QCop\endlink
1797 message, the application will process the \link qcop.html 1801 message, the application will process the \link qcop.html
1798 QCop\endlink message and then quit. If the application calls this 1802 QCop\endlink message and then quit. If the application calls this
1799 function while processing a \link qcop.html QCop\endlink message, 1803 function while processing a \link qcop.html QCop\endlink message,
1800 after processing its outstanding \link qcop.html QCop\endlink 1804 after processing its outstanding \link qcop.html QCop\endlink
1801 messages the application will start 'properly' and show itself. 1805 messages the application will start 'properly' and show itself.
1802 1806
1803 \sa keepRunning() 1807 \sa keepRunning()
1804*/ 1808*/
1805void QPEApplication::setKeepRunning() 1809void QPEApplication::setKeepRunning()
1806{ 1810{
1807 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1811 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1808 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1812 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1809 qpeApp->d->keep_running = TRUE; 1813 qpeApp->d->keep_running = TRUE;
1810 } 1814 }
1811} 1815}
1812 1816
1813/*! 1817/*!
1814 Returns TRUE if the application will quit after processing the 1818 Returns TRUE if the application will quit after processing the
1815 current list of qcop messages; otherwise returns FALSE. 1819 current list of qcop messages; otherwise returns FALSE.
1816 1820
1817 \sa setKeepRunning() 1821 \sa setKeepRunning()
1818*/ 1822*/
1819bool QPEApplication::keepRunning() const 1823bool QPEApplication::keepRunning() const
1820{ 1824{
1821 return d->keep_running; 1825 return d->keep_running;
1822} 1826}
1823 1827
1824/*! 1828/*!
1825 \internal 1829 \internal
1826*/ 1830*/
1827void QPEApplication::internalSetStyle( const QString &style ) 1831void QPEApplication::internalSetStyle( const QString &style )
1828{ 1832{
1829#if QT_VERSION >= 300 1833#if QT_VERSION >= 300
1830 if ( style == "QPE" ) { 1834 if ( style == "QPE" ) {
1831 setStyle( new QPEStyle ); 1835 setStyle( new QPEStyle );
1832 } 1836 }
1833 else { 1837 else {
1834 QStyle *s = QStyleFactory::create( style ); 1838 QStyle *s = QStyleFactory::create( style );
1835 if ( s ) 1839 if ( s )
1836 setStyle( s ); 1840 setStyle( s );
1837 } 1841 }
1838#else 1842#else
1839 if ( style == "Windows" ) { 1843 if ( style == "Windows" ) {
1840 setStyle( new QWindowsStyle ); 1844 setStyle( new QWindowsStyle );
1841 } 1845 }
1842 else if ( style == "QPE" ) { 1846 else if ( style == "QPE" ) {
1843 setStyle( new QPEStyle ); 1847 setStyle( new QPEStyle );
1844 } 1848 }
1845 else if ( style == "Light" ) { 1849 else if ( style == "Light" ) {
1846 setStyle( new LightStyle ); 1850 setStyle( new LightStyle );
1847 } 1851 }
1848#ifndef QT_NO_STYLE_PLATINUM 1852#ifndef QT_NO_STYLE_PLATINUM
1849 else if ( style == "Platinum" ) { 1853 else if ( style == "Platinum" ) {
1850 setStyle( new QPlatinumStyle ); 1854 setStyle( new QPlatinumStyle );
1851 } 1855 }
1852#endif 1856#endif
1853#ifndef QT_NO_STYLE_MOTIF 1857#ifndef QT_NO_STYLE_MOTIF
1854 else if ( style == "Motif" ) { 1858 else if ( style == "Motif" ) {
1855 setStyle( new QMotifStyle ); 1859 setStyle( new QMotifStyle );
1856 } 1860 }
1857#endif 1861#endif
1858#ifndef QT_NO_STYLE_MOTIFPLUS 1862#ifndef QT_NO_STYLE_MOTIFPLUS
1859 else if ( style == "MotifPlus" ) { 1863 else if ( style == "MotifPlus" ) {
1860 setStyle( new QMotifPlusStyle ); 1864 setStyle( new QMotifPlusStyle );
1861 } 1865 }
1862#endif 1866#endif
1863 1867
1864 else { 1868 else {
1865 QStyle *sty = 0; 1869 QStyle *sty = 0;
1866 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 1870 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
1867 1871
1868#ifdef Q_OS_MACX 1872#ifdef Q_OS_MACX
1869 if ( style. find ( ".dylib" ) > 0 ) 1873 if ( style. find ( ".dylib" ) > 0 )
1870 path += style; 1874 path += style;
1871 else 1875 else
1872 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility 1876 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
1873#else 1877#else
1874 if ( style. find ( ".so" ) > 0 ) 1878 if ( style. find ( ".so" ) > 0 )
1875 path += style; 1879 path += style;
1876 else 1880 else
1877 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1881 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1878#endif 1882#endif
1879 static QLibrary *lastlib = 0; 1883 static QLibrary *lastlib = 0;
1880 static StyleInterface *lastiface = 0; 1884 static StyleInterface *lastiface = 0;
1881 1885
1882 QLibrary *lib = new QLibrary ( path ); 1886 QLibrary *lib = new QLibrary ( path );
1883 StyleInterface *iface = 0; 1887 StyleInterface *iface = 0;
1884 1888
1885 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1889 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1886 sty = iface-> style ( ); 1890 sty = iface-> style ( );
1887 1891
1888 if ( sty ) { 1892 if ( sty ) {
1889 setStyle ( sty ); 1893 setStyle ( sty );
1890 1894
1891 if ( lastiface ) 1895 if ( lastiface )
1892 lastiface-> release ( ); 1896 lastiface-> release ( );
1893 lastiface = iface; 1897 lastiface = iface;
1894 1898
1895 if ( lastlib ) { 1899 if ( lastlib ) {
1896 lastlib-> unload ( ); 1900 lastlib-> unload ( );
1897 delete lastlib; 1901 delete lastlib;
1898 } 1902 }
1899 lastlib = lib; 1903 lastlib = lib;
1900 } 1904 }
1901 else { 1905 else {
1902 if ( iface ) 1906 if ( iface )
1903 iface-> release ( ); 1907 iface-> release ( );
1904 delete lib; 1908 delete lib;
1905 1909
1906 setStyle ( new LightStyle ( )); 1910 setStyle ( new LightStyle ( ));
1907 } 1911 }
1908 } 1912 }
1909#endif 1913#endif
1910} 1914}
1911 1915
1912/*! 1916/*!
1913 \internal 1917 \internal
1914*/ 1918*/
1915void QPEApplication::prepareForTermination( bool willrestart ) 1919void QPEApplication::prepareForTermination( bool willrestart )
1916{ 1920{
1917 if ( willrestart ) { 1921 if ( willrestart ) {
1918 // Draw a big wait icon, the image can be altered in later revisions 1922 // Draw a big wait icon, the image can be altered in later revisions
1919 // QWidget *d = QApplication::desktop(); 1923 // QWidget *d = QApplication::desktop();
1920 QImage img = Resource::loadImage( "launcher/new_wait" ); 1924 QImage img = Resource::loadImage( "launcher/new_wait" );
1921 QPixmap pix; 1925 QPixmap pix;
1922 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1926 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1923 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1927 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1924 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1928 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1925 lblWait->setPixmap( pix ); 1929 lblWait->setPixmap( pix );
1926 lblWait->setAlignment( QWidget::AlignCenter ); 1930 lblWait->setAlignment( QWidget::AlignCenter );
1927 lblWait->show(); 1931 lblWait->show();
1928 lblWait->showMaximized(); 1932 lblWait->showMaximized();
1929 } 1933 }
1930#ifndef SINGLE_APP 1934#ifndef SINGLE_APP
1931 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1935 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1932 } 1936 }
1933 processEvents(); // ensure the message goes out. 1937 processEvents(); // ensure the message goes out.
1934 sleep( 1 ); // You have 1 second to comply. 1938 sleep( 1 ); // You have 1 second to comply.
1935#endif 1939#endif
1936} 1940}
1937 1941
1938/*! 1942/*!
1939 \internal 1943 \internal
1940*/ 1944*/
1941void QPEApplication::shutdown() 1945void QPEApplication::shutdown()
1942{ 1946{
1943 // Implement in server's QPEApplication subclass 1947 // Implement in server's QPEApplication subclass
1944} 1948}
1945 1949
1946/*! 1950/*!
1947 \internal 1951 \internal
1948*/ 1952*/
1949void QPEApplication::restart() 1953void QPEApplication::restart()
1950{ 1954{
1951 // Implement in server's QPEApplication subclass 1955 // Implement in server's QPEApplication subclass
1952} 1956}
1953 1957
1954static QPtrDict<void>* stylusDict = 0; 1958static QPtrDict<void>* stylusDict = 0;
1955static void createDict() 1959static void createDict()
1956{ 1960{
1957 if ( !stylusDict ) 1961 if ( !stylusDict )
1958 stylusDict = new QPtrDict<void>; 1962 stylusDict = new QPtrDict<void>;
1959} 1963}
1960 1964
1961/*! 1965/*!
1962 Returns the current StylusMode for widget \a w. 1966 Returns the current StylusMode for widget \a w.
1963 1967
1964 \sa setStylusOperation() StylusMode 1968 \sa setStylusOperation() StylusMode
1965*/ 1969*/
1966QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1970QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1967{ 1971{
1968 if ( stylusDict ) 1972 if ( stylusDict )
1969 return ( StylusMode ) ( int ) stylusDict->find( w ); 1973 return ( StylusMode ) ( int ) stylusDict->find( w );
1970 return LeftOnly; 1974 return LeftOnly;
1971} 1975}
1972 1976
1973/*! 1977/*!
1974 \enum QPEApplication::StylusMode 1978 \enum QPEApplication::StylusMode
1975 1979
1976 \value LeftOnly the stylus only generates LeftButton 1980 \value LeftOnly the stylus only generates LeftButton
1977 events (the default). 1981 events (the default).
1978 \value RightOnHold the stylus generates RightButton events 1982 \value RightOnHold the stylus generates RightButton events
1979 if the user uses the press-and-hold gesture. 1983 if the user uses the press-and-hold gesture.
1980 1984
1981 \sa setStylusOperation() stylusOperation() 1985 \sa setStylusOperation() stylusOperation()
1982*/ 1986*/
1983 1987
1984/*! 1988/*!
1985 Causes widget \a w to receive mouse events according to the stylus 1989 Causes widget \a w to receive mouse events according to the stylus
1986 \a mode. 1990 \a mode.
1987 1991
1988 \sa stylusOperation() StylusMode 1992 \sa stylusOperation() StylusMode
1989*/ 1993*/
1990void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1994void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1991{ 1995{
1992 createDict(); 1996 createDict();
1993 if ( mode == LeftOnly ) { 1997 if ( mode == LeftOnly ) {
1994 stylusDict->remove 1998 stylusDict->remove
1995 ( w ); 1999 ( w );
1996 w->removeEventFilter( qApp ); 2000 w->removeEventFilter( qApp );
1997 } 2001 }
1998 else { 2002 else {
1999 stylusDict->insert( w, ( void* ) mode ); 2003 stylusDict->insert( w, ( void* ) mode );
2000 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 2004 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
2001 w->installEventFilter( qApp ); 2005 w->installEventFilter( qApp );
2002 } 2006 }
2003} 2007}
2004 2008
2005 2009
2006/*! 2010/*!
2007 \reimp 2011 \reimp
2008*/ 2012*/
2009bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 2013bool QPEApplication::eventFilter( QObject *o, QEvent *e )
2010{ 2014{
2011 if ( !o->isWidgetType() ) 2015 if ( !o->isWidgetType() )
2012 return FALSE; 2016 return FALSE;
2013 2017
2014 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 2018 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
2015 QMouseEvent * me = ( QMouseEvent* ) e; 2019 QMouseEvent * me = ( QMouseEvent* ) e;
2016 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 2020 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
2017 switch (mode) { 2021 switch (mode) {
2018 case RightOnHold: 2022 case RightOnHold:
2019 switch ( me->type() ) { 2023 switch ( me->type() ) {
2020 case QEvent::MouseButtonPress: 2024 case QEvent::MouseButtonPress:
2021 if ( me->button() == LeftButton ) { 2025 if ( me->button() == LeftButton ) {
2022 if (!d->presstimer ) 2026 if (!d->presstimer )
2023 d->presstimer = startTimer(500); // #### pref. 2027 d->presstimer = startTimer(500); // #### pref.
2024 d->presswidget = (QWidget*)o; 2028 d->presswidget = (QWidget*)o;
2025 d->presspos = me->pos(); 2029 d->presspos = me->pos();
2026 d->rightpressed = FALSE; 2030 d->rightpressed = FALSE;
2027 } 2031 }
2028 break; 2032 break;
2029 case QEvent::MouseMove: 2033 case QEvent::MouseMove:
2030 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 2034 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
2031 killTimer(d->presstimer); 2035 killTimer(d->presstimer);
2032 d->presstimer = 0; 2036 d->presstimer = 0;
2033 } 2037 }
2034 break; 2038 break;
2035 case QEvent::MouseButtonRelease: 2039 case QEvent::MouseButtonRelease:
2036 if ( me->button() == LeftButton ) { 2040 if ( me->button() == LeftButton ) {
2037 if ( d->presstimer ) { 2041 if ( d->presstimer ) {
2038 killTimer(d->presstimer); 2042 killTimer(d->presstimer);
2039 d->presstimer = 0; 2043 d->presstimer = 0;
2040 } 2044 }
2041 if ( d->rightpressed && d->presswidget ) { 2045 if ( d->rightpressed && d->presswidget ) {
2042 // Right released 2046 // Right released
2043 postEvent( d->presswidget, 2047 postEvent( d->presswidget,
2044 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 2048 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
2045 RightButton, LeftButton + RightButton ) ); 2049 RightButton, LeftButton + RightButton ) );
2046 // Left released, off-widget 2050 // Left released, off-widget
2047 postEvent( d->presswidget, 2051 postEvent( d->presswidget,
2048 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 2052 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
2049 LeftButton, LeftButton ) ); 2053 LeftButton, LeftButton ) );
2050 postEvent( d->presswidget, 2054 postEvent( d->presswidget,
2051 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 2055 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
2052 LeftButton, LeftButton ) ); 2056 LeftButton, LeftButton ) );
2053 d->rightpressed = FALSE; 2057 d->rightpressed = FALSE;
2054 return TRUE; // don't send the real Left release 2058 return TRUE; // don't send the real Left release
2055 } 2059 }
2056 } 2060 }
2057 break; 2061 break;
2058 default: 2062 default:
2059 break; 2063 break;
2060 } 2064 }
2061 break; 2065 break;
2062 default: 2066 default:
2063 ; 2067 ;
2064 } 2068 }
2065 } 2069 }
2066 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 2070 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
2067 QKeyEvent *ke = (QKeyEvent *)e; 2071 QKeyEvent *ke = (QKeyEvent *)e;
2068 if ( ke->key() == Key_Enter ) { 2072 if ( ke->key() == Key_Enter ) {
2069 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 2073 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
2070 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 2074 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
2071 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 2075 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
2072 return TRUE; 2076 return TRUE;
2073 } 2077 }
2074 } 2078 }
2075 } 2079 }
2076 return FALSE; 2080 return FALSE;
2077} 2081}
2078 2082
2079/*! 2083/*!
2080 \reimp 2084 \reimp
2081*/ 2085*/
2082void QPEApplication::timerEvent( QTimerEvent *e ) 2086void QPEApplication::timerEvent( QTimerEvent *e )
2083{ 2087{
2084 if ( e->timerId() == d->presstimer && d->presswidget ) { 2088 if ( e->timerId() == d->presstimer && d->presswidget ) {
2085 // Right pressed 2089 // Right pressed
2086 postEvent( d->presswidget, 2090 postEvent( d->presswidget,
2087 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 2091 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
2088 RightButton, LeftButton ) ); 2092 RightButton, LeftButton ) );
2089 killTimer( d->presstimer ); 2093 killTimer( d->presstimer );
2090 d->presstimer = 0; 2094 d->presstimer = 0;
2091 d->rightpressed = TRUE; 2095 d->rightpressed = TRUE;
2092 } 2096 }
2093} 2097}
2094 2098
2095void QPEApplication::removeSenderFromStylusDict() 2099void QPEApplication::removeSenderFromStylusDict()
2096{ 2100{
2097 stylusDict->remove 2101 stylusDict->remove
2098 ( ( void* ) sender() ); 2102 ( ( void* ) sender() );
2099 if ( d->presswidget == sender() ) 2103 if ( d->presswidget == sender() )
2100 d->presswidget = 0; 2104 d->presswidget = 0;
2101} 2105}
2102 2106
2103/*! 2107/*!
2104 \internal 2108 \internal
2105*/ 2109*/
2106bool QPEApplication::keyboardGrabbed() const 2110bool QPEApplication::keyboardGrabbed() const
2107{ 2111{
2108 return d->kbgrabbed; 2112 return d->kbgrabbed;
2109} 2113}
2110 2114
2111 2115
2112/*! 2116/*!
2113 Reverses the effect of grabKeyboard(). This is called automatically 2117 Reverses the effect of grabKeyboard(). This is called automatically
2114 on program exit. 2118 on program exit.
2115*/ 2119*/
2116void QPEApplication::ungrabKeyboard() 2120void QPEApplication::ungrabKeyboard()
2117{ 2121{
2118 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 2122 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
2119} 2123}
2120 2124
2121/*! 2125/*!
2122 Grabs the physical keyboard keys, e.g. the application's launching 2126 Grabs the physical keyboard keys, e.g. the application's launching
2123 keys. Instead of launching applications when these keys are pressed 2127 keys. Instead of launching applications when these keys are pressed
2124 the signals emitted are sent to this application instead. Some games 2128 the signals emitted are sent to this application instead. Some games
2125 programs take over the launch keys in this way to make interaction 2129 programs take over the launch keys in this way to make interaction
2126 easier. 2130 easier.
2127 2131
2128 \sa ungrabKeyboard() 2132 \sa ungrabKeyboard()
2129*/ 2133*/
2130void QPEApplication::grabKeyboard() 2134void QPEApplication::grabKeyboard()
2131{ 2135{
2132 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 2136 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
2133} 2137}
2134 2138
2135/*! 2139/*!
2136 \reimp 2140 \reimp
2137*/ 2141*/
2138int QPEApplication::exec() 2142int QPEApplication::exec()
2139{ 2143{
2140 d->qcopQok = true; 2144 d->qcopQok = true;
2141#ifndef QT_NO_COP 2145#ifndef QT_NO_COP
2142 d->sendQCopQ(); 2146 d->sendQCopQ();
2143 if ( !d->keep_running ) 2147 if ( !d->keep_running )
2144 processEvents(); // we may have received QCop messages in the meantime. 2148 processEvents(); // we may have received QCop messages in the meantime.
2145#endif 2149#endif
2146 2150
2147 if ( d->keep_running ) 2151 if ( d->keep_running )
2148 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 2152 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
2149 return QApplication::exec(); 2153 return QApplication::exec();
2150 2154
2151#ifndef QT_NO_COP 2155#ifndef QT_NO_COP
2152 2156
2153 { 2157 {
2154 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2158 QCopEnvelope e( "QPE/System", "closing(QString)" );
2155 e << d->appName; 2159 e << d->appName;
2156 } 2160 }
2157#endif 2161#endif
2158 processEvents(); 2162 processEvents();
2159 return 0; 2163 return 0;
2160} 2164}
2161 2165
2162/*! 2166/*!
2163 \internal 2167 \internal
2164 External request for application to quit. Quits if possible without 2168 External request for application to quit. Quits if possible without
2165 loosing state. 2169 loosing state.
2166*/ 2170*/
2167void QPEApplication::tryQuit() 2171void QPEApplication::tryQuit()
2168{ 2172{
2169 if ( activeModalWidget() ) 2173 if ( activeModalWidget() )
2170 return ; // Inside modal loop or konsole. Too hard to save state. 2174 return ; // Inside modal loop or konsole. Too hard to save state.
2171#ifndef QT_NO_COP 2175#ifndef QT_NO_COP
2172 2176
2173 { 2177 {
2174 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2178 QCopEnvelope e( "QPE/System", "closing(QString)" );
2175 e << d->appName; 2179 e << d->appName;
2176 } 2180 }
2177#endif 2181#endif
2178 if ( d->keep_running ) 2182 if ( d->keep_running )
2179 d->store_widget_rect(d->qpe_main_widget, d->appName); 2183 d->store_widget_rect(d->qpe_main_widget, d->appName);
2180 processEvents(); 2184 processEvents();
2181 2185
2182 quit(); 2186 quit();
2183} 2187}
2184 2188
2185/*! 2189/*!
2186 \internal 2190 \internal
2187*/ 2191*/
2188void QPEApplication::installTranslation( const QString& baseName ) { 2192void QPEApplication::installTranslation( const QString& baseName ) {
2189 QTranslator* trans = new QTranslator(this); 2193 QTranslator* trans = new QTranslator(this);
2190 QString tfn = qpeDir() + "/i18n/"+baseName; 2194 QString tfn = qpeDir() + "/i18n/"+baseName;
2191 if ( trans->load( tfn ) ) 2195 if ( trans->load( tfn ) )
2192 installTranslator( trans ); 2196 installTranslator( trans );
2193 else 2197 else
2194 delete trans; 2198 delete trans;
2195} 2199}
2196 2200
2197/*! 2201/*!
2198 \internal 2202 \internal
2199 User initiated quit. Makes the window 'Go Away'. If preloaded this means 2203 User initiated quit. Makes the window 'Go Away'. If preloaded this means
2200 hiding the window. If not it means quitting the application. 2204 hiding the window. If not it means quitting the application.
2201 As this is user initiated we don't need to check state. 2205 As this is user initiated we don't need to check state.
2202*/ 2206*/
2203void QPEApplication::hideOrQuit() 2207void QPEApplication::hideOrQuit()
2204{ 2208{
2205 if ( d->keep_running ) 2209 if ( d->keep_running )
2206 d->store_widget_rect(d->qpe_main_widget, d->appName); 2210 d->store_widget_rect(d->qpe_main_widget, d->appName);
2207 processEvents(); 2211 processEvents();
2208 2212
2209 // If we are a preloaded application we don't actually quit, so emit 2213 // If we are a preloaded application we don't actually quit, so emit
2210 // a System message indicating we're quasi-closing. 2214 // a System message indicating we're quasi-closing.
2211 if ( d->preloaded && d->qpe_main_widget ) 2215 if ( d->preloaded && d->qpe_main_widget )
2212#ifndef QT_NO_COP 2216#ifndef QT_NO_COP
2213 2217
2214 { 2218 {
2215 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 2219 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
2216 e << d->appName; 2220 e << d->appName;
2217 d->qpe_main_widget->hide(); 2221 d->qpe_main_widget->hide();
2218 } 2222 }
2219#endif 2223#endif
2220 else 2224 else
2221 quit(); 2225 quit();
2222} 2226}
2223 2227
2224#if (__GNUC__ > 2 ) 2228#if (__GNUC__ > 2 )
2225extern "C" void __cxa_pure_virtual(); 2229extern "C" void __cxa_pure_virtual();
2226 2230
2227void __cxa_pure_virtual() 2231void __cxa_pure_virtual()
2228{ 2232{
2229 fprintf( stderr, "Pure virtual called\n"); 2233 fprintf( stderr, "Pure virtual called\n");
2230 abort(); 2234 abort();
2231 2235
2232} 2236}
2233 2237
2234#endif 2238#endif
2235 2239
2236 2240
2237#if defined(OPIE_NEW_MALLOC) 2241#if defined(OPIE_NEW_MALLOC)
2238 2242
2239// The libraries with the skiff package (and possibly others) have 2243// The libraries with the skiff package (and possibly others) have
2240// completely useless implementations of builtin new and delete that 2244// completely useless implementations of builtin new and delete that
2241// use about 50% of your CPU. Here we revert to the simple libc 2245// use about 50% of your CPU. Here we revert to the simple libc
2242// functions. 2246// functions.
2243 2247
2244void* operator new[]( size_t size ) 2248void* operator new[]( size_t size )
2245{ 2249{
2246 return malloc( size ); 2250 return malloc( size );
2247} 2251}
2248 2252
2249void* operator new( size_t size ) 2253void* operator new( size_t size )
2250{ 2254{
2251 return malloc( size ); 2255 return malloc( size );
2252} 2256}
2253 2257
2254void operator delete[]( void* p ) 2258void operator delete[]( void* p )
2255{ 2259{
2256 free( p ); 2260 free( p );
2257} 2261}
2258 2262
2259void operator delete[]( void* p, size_t /*size*/ ) 2263void operator delete[]( void* p, size_t /*size*/ )
2260{ 2264{
2261 free( p ); 2265 free( p );
2262} 2266}
2263 2267
2264 2268
2265void operator delete( void* p ) 2269void operator delete( void* p )
2266{ 2270{
2267 free( p ); 2271 free( p );
2268} 2272}
2269 2273
2270void operator delete( void* p, size_t /*size*/ ) 2274void operator delete( void* p, size_t /*size*/ )
2271{ 2275{
2272 free( p ); 2276 free( p );
2273} 2277}
2274 2278
2275#endif 2279#endif
2276 2280
2277#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 2281#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
2278#include <qwidgetlist.h> 2282#include <qwidgetlist.h>
2279#ifdef QWS 2283#ifdef QWS
2280#include <qgfx_qws.h> 2284#include <qgfx_qws.h>
2281extern QRect qt_maxWindowRect; 2285extern QRect qt_maxWindowRect;
2282void qt_setMaxWindowRect(const QRect& r ) 2286void qt_setMaxWindowRect(const QRect& r )
2283{ 2287{
2284 qt_maxWindowRect = qt_screen->mapFromDevice( r, 2288 qt_maxWindowRect = qt_screen->mapFromDevice( r,
2285 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2289 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
2286 // Re-resize any maximized windows 2290 // Re-resize any maximized windows
2287 QWidgetList* l = QApplication::topLevelWidgets(); 2291 QWidgetList* l = QApplication::topLevelWidgets();
2288 if ( l ) { 2292 if ( l ) {
2289 QWidget * w = l->first(); 2293 QWidget * w = l->first();
2290 while ( w ) { 2294 while ( w ) {
2291 if ( w->isVisible() && w->isMaximized() ) { 2295 if ( w->isVisible() && w->isMaximized() ) {
2292 w->showMaximized(); 2296 w->showMaximized();
2293 } 2297 }
2294 w = l->next(); 2298 w = l->next();
2295 } 2299 }
2296 delete l; 2300 delete l;
2297 } 2301 }
2298} 2302}
2299#endif 2303#endif
2300#endif 2304#endif