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
@@ -45,26 +45,12 @@
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
@@ -75,38 +61,25 @@
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 ),
@@ -227,264 +200,12 @@ static void setMic( int t = 0, int percent = -1 )
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
@@ -544,13 +265,13 @@ static void setScreenSaverInterval( int interval )
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 );
@@ -671,15 +392,13 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
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
@@ -1009,33 +728,12 @@ void QPEApplication::systemMessage( const QCString & msg, const QByteArray & dat
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 }
@@ -1062,12 +760,14 @@ void QPEApplication::systemMessage( const QCString & msg, const QByteArray & dat
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" );
@@ -1156,21 +856,12 @@ void QPEApplication::systemMessage( const QCString & msg, const QByteArray & dat
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*/
@@ -1433,13 +1124,12 @@ void QPEApplication::internalSetStyle( const QString &style )
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;
@@ -1450,19 +1140,16 @@ void QPEApplication::internalSetStyle( const QString &style )
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 }
@@ -1470,54 +1157,12 @@ void QPEApplication::internalSetStyle( const QString &style )
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