summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp361
1 files changed, 3 insertions, 358 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 8448352..8aae786 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -27,104 +27,77 @@
27#ifndef QT_NO_COP 27#ifndef QT_NO_COP
28#if QT_VERSION <= 231 28#if QT_VERSION <= 231
29#define private public 29#define private public
30#define sendLocally processEvent 30#define sendLocally processEvent
31#include "qcopenvelope_qws.h" 31#include "qcopenvelope_qws.h"
32#undef private 32#undef private
33#else 33#else
34#include "qcopenvelope_qws.h" 34#include "qcopenvelope_qws.h"
35#endif 35#endif
36#endif 36#endif
37#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
38#endif 38#endif
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qpalette.h> 40#include <qpalette.h>
41#include <qbuffer.h> 41#include <qbuffer.h>
42#include <qptrdict.h> 42#include <qptrdict.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qdir.h> 44#include <qdir.h>
45#include <qlabel.h> 45#include <qlabel.h>
46#include <qdialog.h> 46#include <qdialog.h>
47#include <qdragobject.h> 47#include <qdragobject.h>
48#include <qevent.h> 48#include <qevent.h>
49#include <qtooltip.h> 49#include <qtooltip.h>
50#include <qsignal.h> 50#include <qsignal.h>
51
52
53//#include <linux/fb.h> better not rely on kernel headers in userspace ...
54
55/* VESA Blanking Levels */
56#define VESA_NO_BLANKING 0
57#define VESA_VSYNC_SUSPEND 1
58#define VESA_HSYNC_SUSPEND 2
59#define VESA_POWERDOWN 3
60
61#define FBIOBLANK 0x4611
62
63
64#include <qsignal.h>
65#include "qpeapplication.h" 51#include "qpeapplication.h"
66#include "qpestyle.h" 52#include "qpestyle.h"
67#include "styleinterface.h" 53#include "styleinterface.h"
68#if QT_VERSION >= 300 54#if QT_VERSION >= 300
69#include <qstylefactory.h> 55#include <qstylefactory.h>
70#else 56#else
71#include <qplatinumstyle.h> 57#include <qplatinumstyle.h>
72#include <qwindowsstyle.h> 58#include <qwindowsstyle.h>
73#include <qmotifstyle.h> 59#include <qmotifstyle.h>
74#include <qmotifplusstyle.h> 60#include <qmotifplusstyle.h>
75#include "lightstyle.h" 61#include "lightstyle.h"
76 62
77#include <qpe/qlibrary.h> 63#include <qpe/qlibrary.h>
78#endif 64#endif
79#include "global.h" 65#include "global.h"
80#include "resource.h" 66#include "resource.h"
81#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
82#include "qutfcodec.h"
83#endif
84#include "config.h" 67#include "config.h"
85#include "network.h"
86#include "fontmanager.h" 68#include "fontmanager.h"
87#include "fontdatabase.h" 69#include "fontdatabase.h"
88 70
89#include "power.h"
90#include "alarmserver.h" 71#include "alarmserver.h"
91#include "applnk.h" 72#include "applnk.h"
92#include "qpemenubar.h" 73#include "qpemenubar.h"
93 74
94#include <unistd.h> 75#include <unistd.h>
95#include <sys/file.h> 76#include <sys/file.h>
96#include <sys/ioctl.h> 77#include <sys/ioctl.h>
97#include <sys/soundcard.h> 78#include <sys/soundcard.h>
98 79
99// for setBacklight()
100#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
101#include <linux/fb.h>
102#include <sys/types.h>
103#include <sys/stat.h>
104#endif
105#include <stdlib.h>
106
107 80
108class QPEApplicationData 81class QPEApplicationData
109{ 82{
110public: 83public:
111 QPEApplicationData() : presstimer( 0 ), presswidget( 0 ), rightpressed( FALSE ), 84 QPEApplicationData() : presstimer( 0 ), presswidget( 0 ), rightpressed( FALSE ),
112 kbgrabber( 0 ), kbregrab( FALSE ), notbusysent( FALSE ), preloaded( FALSE ), 85 kbgrabber( 0 ), kbregrab( FALSE ), notbusysent( FALSE ), preloaded( FALSE ),
113 forceshow( FALSE ), nomaximize( FALSE ), qpe_main_widget( 0 ), 86 forceshow( FALSE ), nomaximize( FALSE ), qpe_main_widget( 0 ),
114 keep_running( TRUE ) 87 keep_running( TRUE )
115 { 88 {
116 qcopq.setAutoDelete( TRUE ); 89 qcopq.setAutoDelete( TRUE );
117 } 90 }
118 91
119 int presstimer; 92 int presstimer;
120 QWidget* presswidget; 93 QWidget* presswidget;
121 QPoint presspos; 94 QPoint presspos;
122 bool rightpressed; 95 bool rightpressed;
123 int kbgrabber; 96 int kbgrabber;
124 bool kbregrab; 97 bool kbregrab;
125 bool notbusysent; 98 bool notbusysent;
126 QString appName; 99 QString appName;
127 struct QCopRec 100 struct QCopRec
128 { 101 {
129 QCopRec( const QCString &ch, const QCString &msg, 102 QCopRec( const QCString &ch, const QCString &msg,
130 const QByteArray &d ) : 103 const QByteArray &d ) :
@@ -209,300 +182,48 @@ static void setVolume( int t = 0, int percent = -1 )
209 break; 182 break;
210 } 183 }
211} 184}
212 185
213static void setMic( int t = 0, int percent = -1 ) 186static void setMic( int t = 0, int percent = -1 )
214{ 187{
215 switch ( t ) { 188 switch ( t ) {
216 case 0: { 189 case 0: {
217 Config cfg( "qpe" ); 190 Config cfg( "qpe" );
218 cfg.setGroup( "Volume" ); 191 cfg.setGroup( "Volume" );
219 if ( percent < 0 ) 192 if ( percent < 0 )
220 percent = cfg.readNumEntry( "Mic", 50 ); 193 percent = cfg.readNumEntry( "Mic", 50 );
221 194
222 int fd = 0; 195 int fd = 0;
223 int mic = micMuted ? 0 : percent; 196 int mic = micMuted ? 0 : percent;
224 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 197 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
225 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 198 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
226 ::close( fd ); 199 ::close( fd );
227 } 200 }
228 } 201 }
229 break; 202 break;
230 } 203 }
231} 204}
232 205
233int qpe_sysBrightnessSteps()
234{
235#if defined(QT_QWS_IPAQ)
236 return 255;
237#elif defined(QT_QWS_EBX)
238
239 return 4;
240#else
241
242 return 255; // ?
243#endif
244}
245
246
247static int& hack( int& i )
248{
249#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
250 // These should be created, but aren't in Qt 2.3.0
251 ( void ) new QUtf8Codec;
252 ( void ) new QUtf16Codec;
253#endif
254
255 return i;
256}
257
258static bool forced_off = FALSE;
259static int curbl = -1;
260
261static int backlight()
262{
263 if ( curbl == -1 ) {
264 // Read from config
265 Config config( "qpe" );
266 config.setGroup( "Screensaver" );
267 curbl = config.readNumEntry( "Brightness", 255 );
268 }
269 return curbl;
270}
271
272static void setBacklight( int bright )
273{
274 if ( bright == -3 ) {
275 // Forced on
276 forced_off = FALSE;
277 bright = -1;
278 }
279 if ( forced_off && bright != -2 )
280 return ;
281 if ( bright == -2 ) {
282 // Toggle between off and on
283 bright = curbl ? 0 : -1;
284 forced_off = !bright;
285 }
286 if ( bright == -1 ) {
287 // Read from config
288 Config config( "qpe" );
289 config.setGroup( "Screensaver" );
290 bright = config.readNumEntry( "Brightness", 255 );
291 }
292#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
293 if ( QFile::exists( "/usr/bin/bl" ) ) {
294 QString cmd = "/usr/bin/bl 1 ";
295 cmd += bright <= 0 ? "0 " : "1 ";
296 cmd += QString::number( bright );
297 system( cmd.latin1() );
298#if defined(QT_QWS_EBX)
299
300 }
301 else if ( QFile::exists( "/dev/fl" ) ) {
302#define FL_IOCTL_STEP_CONTRAST 100
303 int fd = open( "/dev/fl", O_WRONLY );
304 if ( fd >= 0 ) {
305 int steps = qpe_sysBrightnessSteps();
306 int bl = ( bright * steps + 127 ) / 255;
307 if ( bright && !bl )
308 bl = 1;
309 bl = ioctl( fd, FL_IOCTL_STEP_CONTRAST, bl );
310 close( fd );
311 }
312 }
313#elif defined(QT_QWS_IPAQ)
314
315 }
316 else if ( QFile::exists( "/dev/ts" ) || QFile::exists( "/dev/h3600_ts" ) )
317 {
318 typedef struct {
319 unsigned char mode;
320 unsigned char pwr;
321 unsigned char brightness;
322 }
323 FLITE_IN;
324# ifndef FLITE_ON
325# ifndef _LINUX_IOCTL_H
326# include <linux/ioctl.h>
327# endif
328# define FLITE_ON _IOW('f', 7, FLITE_IN)
329# endif
330
331 int fd;
332 if ( QFile::exists( "/dev/ts" ) )
333 fd = open( "/dev/ts", O_WRONLY );
334 else
335 fd = open( "/dev/h3600_ts", O_WRONLY );
336 if ( fd >= 0 ) {
337 FLITE_IN bl;
338 bl.mode = 1;
339 bl.pwr = bright ? 1 : 0;
340 bl.brightness = bright;
341 ioctl( fd, FLITE_ON, &bl );
342 close( fd );
343 }
344 }
345#endif
346#endif
347 curbl = bright;
348}
349
350void qpe_setBacklight( int bright ) {
351 setBacklight( bright );
352}
353
354static bool dim_on = FALSE;
355static bool lightoff_on = FALSE;
356static int disable_suspend = 100;
357
358static bool powerOnline()
359{
360 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;
361}
362
363static bool networkOnline()
364{
365 return Network::networkOnline();
366}
367
368class QPEScreenSaver : public QWSScreenSaver
369{
370private:
371 int LcdOn;
372
373public:
374 QPEScreenSaver()
375 {
376 int fd;
377
378 LcdOn = TRUE;
379 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
380 fd = open( "/dev/fb0", O_RDWR );
381 if ( fd != -1 ) {
382 ioctl( fd, FBIOBLANK, VESA_NO_BLANKING );
383 close( fd );
384 }
385 }
386 void restore()
387 {
388 if ( !LcdOn ) // We must have turned it off
389 {
390 int fd;
391 fd = open( "/dev/fb0", O_RDWR );
392 if ( fd != -1 )
393 {
394 ioctl( fd, FBIOBLANK, VESA_NO_BLANKING );
395 close( fd );
396 }
397 }
398 setBacklight( -1 );
399 }
400 bool save( int level )
401 {
402 int fd;
403
404 switch ( level ) {
405 case 0:
406 if ( disable_suspend > 0 && dim_on ) {
407 if ( backlight() > 1 )
408 setBacklight( 1 ); // lowest non-off
409 }
410 return TRUE;
411 break;
412 case 1:
413 if ( disable_suspend > 1 && lightoff_on ) {
414 setBacklight( 0 ); // off
415 }
416 return TRUE;
417 break;
418 case 2:
419 Config config( "qpe" );
420 config.setGroup( "Screensaver" );
421 if ( config.readNumEntry( "LcdOffOnly", 0 ) != 0 ) // We're only turning off the LCD
422 {
423 fd = open( "/dev/fb0", O_RDWR );
424 if ( fd != -1 )
425 {
426 ioctl( fd, FBIOBLANK, VESA_POWERDOWN );
427 close( fd );
428 }
429 LcdOn = FALSE;
430 }
431 else // We're going to suspend the whole machine
432 {
433 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) {
434 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
435 return TRUE;
436 }
437 }
438 break;
439 }
440 return FALSE;
441 }
442};
443
444static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def )
445{
446 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 )
447 return 0;
448
449 if ( interval < 0 ) {
450 // Restore screen blanking and power saving state
451 interval = config.readNumEntry( value, def );
452 }
453 return interval;
454}
455
456static void setScreenSaverIntervals( int i1, int i2, int i3 )
457{
458 Config config( "qpe" );
459 config.setGroup( "Screensaver" );
460
461 int v[ 4 ];
462 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 );
463 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 );
464 i3 = ssi( i3, config, "", "Interval", 60 );
465
466 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
467
468 v[ 0 ] = QMAX( 1000 * i1, 100 );
469 v[ 1 ] = QMAX( 1000 * i2, 100 );
470 v[ 2 ] = QMAX( 1000 * i3, 100 );
471 v[ 3 ] = 0;
472 dim_on = ( ( i1 != 0 ) ? config.readNumEntry( "Dim", 1 ) : FALSE );
473 lightoff_on = ( ( i2 != 0 ) ? config.readNumEntry( "LightOff", 1 ) : FALSE );
474 if ( !i1 && !i2 && !i3 )
475 QWSServer::setScreenSaverInterval( 0 );
476 else
477 QWSServer::setScreenSaverIntervals( v );
478}
479
480static void setScreenSaverInterval( int interval )
481{
482 setScreenSaverIntervals( -1, -1, interval );
483}
484
485 206
486/*! 207/*!
487 \class QPEApplication qpeapplication.h 208 \class QPEApplication qpeapplication.h
488 \brief The QPEApplication class implements various system services 209 \brief The QPEApplication class implements various system services
489 that are available to all Qtopia applications. 210 that are available to all Qtopia applications.
490 211
491 Simply by using QPEApplication instead of QApplication, a plain Qt 212 Simply by using QPEApplication instead of QApplication, a plain Qt
492 application becomes a Qtopia application. It automatically follows 213 application becomes a Qtopia application. It automatically follows
493 style changes, quits and raises, and in the 214 style changes, quits and raises, and in the
494 case of \link docwidget.html document-oriented\endlink applications, 215 case of \link docwidget.html document-oriented\endlink applications,
495 changes the current displayed document in response to the environment. 216 changes the current displayed document in response to the environment.
496*/ 217*/
497 218
498/*! 219/*!
499 \fn void QPEApplication::clientMoused() 220 \fn void QPEApplication::clientMoused()
500 221
501 \internal 222 \internal
502*/ 223*/
503 224
504/*! 225/*!
505 \fn void QPEApplication::timeChanged(); 226 \fn void QPEApplication::timeChanged();
506 227
507 This signal is emitted when the time jumps forward or backwards 228 This signal is emitted when the time jumps forward or backwards
508 by more than the normal passage of time. 229 by more than the normal passage of time.
@@ -526,49 +247,49 @@ static void setScreenSaverInterval( int interval )
526 in the following way: 247 in the following way:
527 248
528\code 249\code
529 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 250 void MyWidget::receive( const QCString& msg, const QByteArray& data )
530 { 251 {
531 QDataStream stream( data, IO_ReadOnly ); 252 QDataStream stream( data, IO_ReadOnly );
532 if ( msg == "someMessage(int,int,int)" ) { 253 if ( msg == "someMessage(int,int,int)" ) {
533 int a,b,c; 254 int a,b,c;
534 stream >> a >> b >> c; 255 stream >> a >> b >> c;
535 ... 256 ...
536 } else if ( msg == "otherMessage(QString)" ) { 257 } else if ( msg == "otherMessage(QString)" ) {
537 ... 258 ...
538 } 259 }
539 } 260 }
540\endcode 261\endcode
541 262
542 \sa qcop.html 263 \sa qcop.html
543*/ 264*/
544 265
545/*! 266/*!
546 Constructs a QPEApplication just as you would construct 267 Constructs a QPEApplication just as you would construct
547 a QApplication, passing \a argc, \a argv, and \a t. 268 a QApplication, passing \a argc, \a argv, and \a t.
548*/ 269*/
549QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 270QPEApplication::QPEApplication( int & argc, char **argv, Type t )
550 : QApplication( hack( argc ), argv, t ) 271 : QApplication( argc, argv, t )
551{ 272{
552 int dw = desktop() ->width(); 273 int dw = desktop() ->width();
553 if ( dw < 200 ) { 274 if ( dw < 200 ) {
554 // setFont( QFont( "helvetica", 8 ) ); 275 // setFont( QFont( "helvetica", 8 ) );
555 AppLnk::setSmallIconSize( 10 ); 276 AppLnk::setSmallIconSize( 10 );
556 AppLnk::setBigIconSize( 28 ); 277 AppLnk::setBigIconSize( 28 );
557 } 278 }
558 279
559 d = new QPEApplicationData; 280 d = new QPEApplicationData;
560 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 281 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
561 282
562 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 283 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
563#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 284#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
564 285
565 QString qcopfn( "/tmp/qcop-msg-" ); 286 QString qcopfn( "/tmp/qcop-msg-" );
566 qcopfn += QString( argv[ 0 ] ); // append command name 287 qcopfn += QString( argv[ 0 ] ); // append command name
567 288
568 QFile f( qcopfn ); 289 QFile f( qcopfn );
569 if ( f.open( IO_ReadOnly ) ) { 290 if ( f.open( IO_ReadOnly ) ) {
570 flock( f.handle(), LOCK_EX ); 291 flock( f.handle(), LOCK_EX );
571 } 292 }
572 293
573 sysChannel = new QCopChannel( "QPE/System", this ); 294 sysChannel = new QCopChannel( "QPE/System", this );
574 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 295 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
@@ -653,51 +374,49 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
653 setFont( fn ); 374 setFont( fn );
654 } 375 }
655 376
656 else { 377 else {
657 */ 378 */
658 Config config( "qpe" ); 379 Config config( "qpe" );
659 config.setGroup( "Appearance" ); 380 config.setGroup( "Appearance" );
660 QString familyStr = config.readEntry( "FontFamily", "helvetica" ); 381 QString familyStr = config.readEntry( "FontFamily", "helvetica" );
661 QString styleStr = config.readEntry( "FontStyle", "Regular" ); 382 QString styleStr = config.readEntry( "FontStyle", "Regular" );
662 QString sizeStr = config.readEntry( "FontSize", "10" ); 383 QString sizeStr = config.readEntry( "FontSize", "10" );
663 QString charSetStr = config.readEntry( "FontCharSet", QString::null ); 384 QString charSetStr = config.readEntry( "FontCharSet", QString::null );
664 bool ok; 385 bool ok;
665 int i_size = sizeStr.toInt( &ok, 10 ); 386 int i_size = sizeStr.toInt( &ok, 10 );
666 FontDatabase fdb; 387 FontDatabase fdb;
667 QFont selectedFont = fdb.font( familyStr, styleStr, i_size, charSetStr ); 388 QFont selectedFont = fdb.font( familyStr, styleStr, i_size, charSetStr );
668 setFont( selectedFont ); 389 setFont( selectedFont );
669 //} 390 //}
670 } 391 }
671 392
672#endif 393#endif
673 394
674 applyStyle(); 395 applyStyle();
675 396
676 if ( type() == GuiServer ) { 397 if ( type() == GuiServer ) {
677 setScreenSaverInterval( -1 );
678 setVolume(); 398 setVolume();
679 QWSServer::setScreenSaver( new QPEScreenSaver );
680 } 399 }
681 400
682 installEventFilter( this ); 401 installEventFilter( this );
683 402
684 QPEMenuToolFocusManager::initialize(); 403 QPEMenuToolFocusManager::initialize();
685 404
686#ifdef QT_NO_QWS_CURSOR 405#ifdef QT_NO_QWS_CURSOR
687 // if we have no cursor, probably don't want tooltips 406 // if we have no cursor, probably don't want tooltips
688 QToolTip::setEnabled( FALSE ); 407 QToolTip::setEnabled( FALSE );
689#endif 408#endif
690} 409}
691 410
692static QPtrDict<void>* inputMethodDict = 0; 411static QPtrDict<void>* inputMethodDict = 0;
693static void createInputMethodDict() 412static void createInputMethodDict()
694{ 413{
695 if ( !inputMethodDict ) 414 if ( !inputMethodDict )
696 inputMethodDict = new QPtrDict<void>; 415 inputMethodDict = new QPtrDict<void>;
697} 416}
698 417
699/*! 418/*!
700 Returns the currently set hint to the system as to whether 419 Returns the currently set hint to the system as to whether
701 \a w has any use for text input methods. 420 \a w has any use for text input methods.
702 421
703 \sa setInputMethodHint() 422 \sa setInputMethodHint()
@@ -991,101 +710,82 @@ void QPEApplication::applyStyle()
991 QString color = config.readEntry( "Highlight", "#800000" ); 710 QString color = config.readEntry( "Highlight", "#800000" );
992 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 711 pal.setColor( QColorGroup::Highlight, QColor( color ) );
993 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 712 color = config.readEntry( "HighlightedText", "#FFFFFF" );
994 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 713 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
995 color = config.readEntry( "Text", "#000000" ); 714 color = config.readEntry( "Text", "#000000" );
996 pal.setColor( QColorGroup::Text, QColor( color ) ); 715 pal.setColor( QColorGroup::Text, QColor( color ) );
997 color = config.readEntry( "ButtonText", "#000000" ); 716 color = config.readEntry( "ButtonText", "#000000" );
998 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 717 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
999 color = config.readEntry( "Base", "#FFFFFF" ); 718 color = config.readEntry( "Base", "#FFFFFF" );
1000 pal.setColor( QColorGroup::Base, QColor( color ) ); 719 pal.setColor( QColorGroup::Base, QColor( color ) );
1001 720
1002 pal.setColor( QPalette::Disabled, QColorGroup::Text, 721 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1003 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 722 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1004 723
1005 setPalette( pal, TRUE ); 724 setPalette( pal, TRUE );
1006} 725}
1007 726
1008void QPEApplication::systemMessage( const QCString & msg, const QByteArray & data ) 727void QPEApplication::systemMessage( const QCString & msg, const QByteArray & data )
1009{ 728{
1010#ifdef Q_WS_QWS 729#ifdef Q_WS_QWS
1011 QDataStream stream( data, IO_ReadOnly ); 730 QDataStream stream( data, IO_ReadOnly );
1012 if ( msg == "applyStyle()" ) { 731 if ( msg == "applyStyle()" ) {
1013 applyStyle(); 732 applyStyle();
1014 } 733 }
1015 else if ( msg == "setScreenSaverInterval(int)" ) {
1016 if ( type() == GuiServer ) {
1017 int time;
1018 stream >> time;
1019 setScreenSaverInterval( time );
1020 }
1021 }
1022 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
1023 if ( type() == GuiServer ) {
1024 int t1, t2, t3;
1025 stream >> t1 >> t2 >> t3;
1026 setScreenSaverIntervals( t1, t2, t3 );
1027 }
1028 }
1029 else if ( msg == "setBacklight(int)" ) {
1030 if ( type() == GuiServer ) {
1031 int bright;
1032 stream >> bright;
1033 setBacklight( bright );
1034 }
1035 }
1036 else if ( msg == "setDefaultRotation(int)" ) { 734 else if ( msg == "setDefaultRotation(int)" ) {
1037 if ( type() == GuiServer ) { 735 if ( type() == GuiServer ) {
1038 int r; 736 int r;
1039 stream >> r; 737 stream >> r;
1040 setDefaultRotation( r ); 738 setDefaultRotation( r );
1041 } 739 }
1042 } 740 }
1043 else if ( msg == "shutdown()" ) { 741 else if ( msg == "shutdown()" ) {
1044 if ( type() == GuiServer ) 742 if ( type() == GuiServer )
1045 shutdown(); 743 shutdown();
1046 } 744 }
1047 else if ( msg == "quit()" ) { 745 else if ( msg == "quit()" ) {
1048 if ( type() != GuiServer ) 746 if ( type() != GuiServer )
1049 tryQuit(); 747 tryQuit();
1050 } 748 }
1051 else if ( msg == "forceQuit()" ) { 749 else if ( msg == "forceQuit()" ) {
1052 if ( type() != GuiServer ) 750 if ( type() != GuiServer )
1053 quit(); 751 quit();
1054 } 752 }
1055 else if ( msg == "restart()" ) { 753 else if ( msg == "restart()" ) {
1056 if ( type() == GuiServer ) 754 if ( type() == GuiServer )
1057 restart(); 755 restart();
1058 } 756 }
1059 else if ( msg == "grabKeyboard(QString)" ) { 757 else if ( msg == "grabKeyboard(QString)" ) {
1060 QString who; 758 QString who;
1061 stream >> who; 759 stream >> who;
1062 if ( who.isEmpty() ) 760 if ( who.isEmpty() )
1063 d->kbgrabber = 0; 761 d->kbgrabber = 0;
1064 else if ( who != d->appName ) 762 else if ( who != d->appName )
1065 d->kbgrabber = 1; 763 d->kbgrabber = 1;
1066 else 764 else
1067 d->kbgrabber = 2; 765 d->kbgrabber = 2;
766
767 printf( "'%s' received grabKeyboard ( '%s' ) -> kbgrabber = %d\n", d-> appName.latin1(), who.latin1(), d-> kbgrabber );
1068 } 768 }
1069 else if ( msg == "language(QString)" ) { 769 else if ( msg == "language(QString)" ) {
1070 if ( type() == GuiServer ) { 770 if ( type() == GuiServer ) {
1071 QString l; 771 QString l;
1072 stream >> l; 772 stream >> l;
1073 QString cl = getenv( "LANG" ); 773 QString cl = getenv( "LANG" );
1074 if ( cl != l ) { 774 if ( cl != l ) {
1075 if ( l.isNull() ) 775 if ( l.isNull() )
1076 unsetenv( "LANG" ); 776 unsetenv( "LANG" );
1077 else 777 else
1078 setenv( "LANG", l.latin1(), 1 ); 778 setenv( "LANG", l.latin1(), 1 );
1079 restart(); 779 restart();
1080 } 780 }
1081 } 781 }
1082 } 782 }
1083 else if ( msg == "timeChange(QString)" ) { 783 else if ( msg == "timeChange(QString)" ) {
1084 QString t; 784 QString t;
1085 stream >> t; 785 stream >> t;
1086 if ( t.isNull() ) 786 if ( t.isNull() )
1087 unsetenv( "TZ" ); 787 unsetenv( "TZ" );
1088 else 788 else
1089 setenv( "TZ", t.latin1(), 1 ); 789 setenv( "TZ", t.latin1(), 1 );
1090 // emit the signal so everyone else knows... 790 // emit the signal so everyone else knows...
1091 emit timeChanged(); 791 emit timeChanged();
@@ -1138,57 +838,48 @@ void QPEApplication::systemMessage( const QCString & msg, const QByteArray & dat
1138 emit dateFormatChanged( tmp ); 838 emit dateFormatChanged( tmp );
1139 } 839 }
1140 else if ( msg == "setVolume(int,int)" ) { 840 else if ( msg == "setVolume(int,int)" ) {
1141 int t, v; 841 int t, v;
1142 stream >> t >> v; 842 stream >> t >> v;
1143 setVolume( t, v ); 843 setVolume( t, v );
1144 emit volumeChanged( muted ); 844 emit volumeChanged( muted );
1145 } 845 }
1146 else if ( msg == "volumeChange(bool)" ) { 846 else if ( msg == "volumeChange(bool)" ) {
1147 stream >> muted; 847 stream >> muted;
1148 setVolume(); 848 setVolume();
1149 emit volumeChanged( muted ); 849 emit volumeChanged( muted );
1150 } 850 }
1151 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 851 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1152 int t, v; 852 int t, v;
1153 stream >> t >> v; 853 stream >> t >> v;
1154 setMic( t, v ); 854 setMic( t, v );
1155 emit micChanged( micMuted ); 855 emit micChanged( micMuted );
1156 } 856 }
1157 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 857 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1158 stream >> micMuted; 858 stream >> micMuted;
1159 setMic(); 859 setMic();
1160 emit micChanged( micMuted ); 860 emit micChanged( micMuted );
1161 } 861 }
1162 else if ( msg == "setScreenSaverMode(int)" ) {
1163 if ( type() == GuiServer ) {
1164 int old = disable_suspend;
1165 stream >> disable_suspend;
1166 //qDebug("setScreenSaverMode(%d)", disable_suspend );
1167 if ( disable_suspend > old )
1168 setScreenSaverInterval( -1 );
1169 }
1170 }
1171#endif 862#endif
1172} 863}
1173 864
1174/*! 865/*!
1175 \internal 866 \internal
1176*/ 867*/
1177bool QPEApplication::raiseAppropriateWindow() 868bool QPEApplication::raiseAppropriateWindow()
1178{ 869{
1179 bool r = FALSE; 870 bool r = FALSE;
1180 // ########## raise()ing main window should raise and set active 871 // ########## raise()ing main window should raise and set active
1181 // ########## it and then all childen. This belongs in Qt/Embedded 872 // ########## it and then all childen. This belongs in Qt/Embedded
1182 QWidget *top = d->qpe_main_widget; 873 QWidget *top = d->qpe_main_widget;
1183 if ( !top ) 874 if ( !top )
1184 top = mainWidget(); 875 top = mainWidget();
1185 if ( top && d->keep_running ) { 876 if ( top && d->keep_running ) {
1186 if ( top->isVisible() ) 877 if ( top->isVisible() )
1187 r = TRUE; 878 r = TRUE;
1188#ifdef Q_WS_QWS 879#ifdef Q_WS_QWS
1189 880
1190 if ( !d->nomaximize ) 881 if ( !d->nomaximize )
1191 top->showMaximized(); 882 top->showMaximized();
1192 else 883 else
1193#endif 884#endif
1194 885
@@ -1415,127 +1106,81 @@ void QPEApplication::internalSetStyle( const QString &style )
1415 setStyle( new QWindowsStyle ); 1106 setStyle( new QWindowsStyle );
1416 } 1107 }
1417 else if ( style == "QPE" ) { 1108 else if ( style == "QPE" ) {
1418 setStyle( new QPEStyle ); 1109 setStyle( new QPEStyle );
1419 } 1110 }
1420 else if ( style == "Light" ) { 1111 else if ( style == "Light" ) {
1421 setStyle( new LightStyle ); 1112 setStyle( new LightStyle );
1422 } 1113 }
1423#ifndef QT_NO_STYLE_PLATINUM 1114#ifndef QT_NO_STYLE_PLATINUM
1424 else if ( style == "Platinum" ) { 1115 else if ( style == "Platinum" ) {
1425 setStyle( new QPlatinumStyle ); 1116 setStyle( new QPlatinumStyle );
1426 } 1117 }
1427#endif 1118#endif
1428#ifndef QT_NO_STYLE_MOTIF 1119#ifndef QT_NO_STYLE_MOTIF
1429 else if ( style == "Motif" ) { 1120 else if ( style == "Motif" ) {
1430 setStyle( new QMotifStyle ); 1121 setStyle( new QMotifStyle );
1431 } 1122 }
1432#endif 1123#endif
1433#ifndef QT_NO_STYLE_MOTIFPLUS 1124#ifndef QT_NO_STYLE_MOTIFPLUS
1434 else if ( style == "MotifPlus" ) { 1125 else if ( style == "MotifPlus" ) {
1435 setStyle( new QMotifPlusStyle ); 1126 setStyle( new QMotifPlusStyle );
1436 } 1127 }
1437#endif 1128#endif
1438 1129
1439 // HACK for Qt2 only
1440 else { 1130 else {
1441 QStyle *sty = 0; 1131 QStyle *sty = 0;
1442 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/lib" + style. lower ( ) + ".so"; 1132 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/lib" + style. lower ( ) + ".so";
1443 1133
1444 static QLibrary *lastlib = 0; 1134 static QLibrary *lastlib = 0;
1445 static StyleInterface *lastiface = 0; 1135 static StyleInterface *lastiface = 0;
1446 1136
1447 QLibrary *lib = new QLibrary ( path ); 1137 QLibrary *lib = new QLibrary ( path );
1448 StyleInterface *iface = 0; 1138 StyleInterface *iface = 0;
1449 1139
1450 if ( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) 1140 if ( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK )
1451 sty = iface-> create ( ); 1141 sty = iface-> create ( );
1452 1142
1453 if ( sty ) { 1143 if ( sty ) {
1454 setStyle ( sty ); 1144 setStyle ( sty );
1455 1145
1456 qDebug ( "Got Style: %p -- iface: %p, lib: %p\n", sty, iface, lib );
1457
1458 if ( lastiface ) 1146 if ( lastiface )
1459 lastiface-> release ( ); 1147 lastiface-> release ( );
1460 lastiface = iface; 1148 lastiface = iface;
1461 1149
1462
1463 if ( lastlib ) { 1150 if ( lastlib ) {
1464 lastlib-> unload ( ); 1151 lastlib-> unload ( );
1465 delete lastlib; 1152 delete lastlib;
1466 } 1153 }
1467 lastlib = lib; 1154 lastlib = lib;
1468 } 1155 }
1469 else { 1156 else {
1470 if ( iface ) 1157 if ( iface )
1471 iface-> release ( ); 1158 iface-> release ( );
1472 delete lib; 1159 delete lib;
1473 1160
1474 setStyle ( new QPEStyle ( )); 1161 setStyle ( new QPEStyle ( ));
1475 } 1162 }
1476
1477#if 0
1478 // style == "Liquid Style (libliquid.so)" (or "Windows XP (libxp.so)"
1479
1480 int p2 = style. findRev ( ']' );
1481 int p1 = style. findRev ( '[' );
1482 QString style2;
1483
1484 if ( ( p1 > 0 ) && ( p2 > 0 ) && ( ( p1 + 1 ) < p2 ) )
1485 style2 = "lib" + style. mid ( p1 + 1, p2 - p1 - 1 ). lower ( ) + ".so";
1486 else
1487 style2 = "lib" + style. lower ( ) + ".so";
1488
1489 static QLibrary *currentlib = 0;
1490
1491 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/" + style2;
1492
1493 do { // try/catch simulation
1494 QLibrary *lib = new QLibrary ( path, QLibrary::Immediately );
1495
1496 if ( lib ) {
1497 QStyle * ( *fpa ) ( ) = ( QStyle * ( * ) ( ) ) lib-> resolve ( "allocate" );
1498
1499 if ( fpa ) {
1500 QStyle * sty = ( *fpa ) ( );
1501
1502 if ( sty ) {
1503 setStyle ( sty );
1504
1505 if ( currentlib )
1506 delete currentlib;
1507 currentlib = lib;
1508
1509 break;
1510 }
1511 }
1512 delete lib;
1513 }
1514 }
1515 while ( false );
1516 // HACK for Qt2 only
1517#endif
1518 } 1163 }
1519#endif 1164#endif
1520} 1165}
1521 1166
1522/*! 1167/*!
1523 \internal 1168 \internal
1524*/ 1169*/
1525void QPEApplication::prepareForTermination( bool willrestart ) 1170void QPEApplication::prepareForTermination( bool willrestart )
1526{ 1171{
1527 if ( willrestart ) { 1172 if ( willrestart ) {
1528 // Draw a big wait icon, the image can be altered in later revisions 1173 // Draw a big wait icon, the image can be altered in later revisions
1529 // QWidget *d = QApplication::desktop(); 1174 // QWidget *d = QApplication::desktop();
1530 QImage img = Resource::loadImage( "launcher/new_wait" ); 1175 QImage img = Resource::loadImage( "launcher/new_wait" );
1531 QPixmap pix; 1176 QPixmap pix;
1532 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1177 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1533 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1178 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1534 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1179 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1535 lblWait->setPixmap( pix ); 1180 lblWait->setPixmap( pix );
1536 lblWait->setAlignment( QWidget::AlignCenter ); 1181 lblWait->setAlignment( QWidget::AlignCenter );
1537 lblWait->show(); 1182 lblWait->show();
1538 lblWait->showMaximized(); 1183 lblWait->showMaximized();
1539 } 1184 }
1540#ifndef SINGLE_APP 1185#ifndef SINGLE_APP
1541 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1186 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );