summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-13 16:12:08 (UTC)
committer sandman <sandman>2002-10-13 16:12:08 (UTC)
commit467451d6d19a2cf5245afa2d219b7d2b1cd008f5 (patch) (unidiff)
tree8c59b58615a817377c0ae1db10a4093387fdaa77
parent92aabc976e4a8e58d7db0bba42cb8d0f3ebe8982 (diff)
downloadopie-467451d6d19a2cf5245afa2d219b7d2b1cd008f5.zip
opie-467451d6d19a2cf5245afa2d219b7d2b1cd008f5.tar.gz
opie-467451d6d19a2cf5245afa2d219b7d2b1cd008f5.tar.bz2
- added qcop "QPE/System" "setDisplayState(int)" to toggle the LCD on/off
- removed qcop "QPE/Desktop" "home()" -- this is now handled via qcop "QPE/Application/qpe" "raise()" - renamed qcop "QPE/Desktop" "suspend()" to qcop "QPE/System" "suspend()"
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 6ee7132..0e60839 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -1,1025 +1,1039 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#include "desktop.h"
22#include "info.h" 22#include "info.h"
23#include "launcher.h" 23#include "launcher.h"
24//#include "mrulist.h" 24//#include "mrulist.h"
25#include "qcopbridge.h" 25#include "qcopbridge.h"
26#include "shutdownimpl.h" 26#include "shutdownimpl.h"
27#include "startmenu.h" 27#include "startmenu.h"
28#include "taskbar.h" 28#include "taskbar.h"
29#include "transferserver.h" 29#include "transferserver.h"
30#include "irserver.h" 30#include "irserver.h"
31#include "packageslave.h" 31#include "packageslave.h"
32 32
33#include <qpe/applnk.h> 33#include <qpe/applnk.h>
34#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
35#include <qpe/password.h> 35#include <qpe/password.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/power.h> 37#include <qpe/power.h>
38#include <qpe/timeconversion.h> 38#include <qpe/timeconversion.h>
39#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
40#include <qpe/network.h> 40#include <qpe/network.h>
41#include <qpe/global.h> 41#include <qpe/global.h>
42 42
43#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 43#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
44#include <qpe/custom.h> 44#include <qpe/custom.h>
45#endif 45#endif
46 46
47#include <opie/odevice.h> 47#include <opie/odevice.h>
48 48
49#include <qgfx_qws.h> 49#include <qgfx_qws.h>
50#include <qmainwindow.h> 50#include <qmainwindow.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qtimer.h> 52#include <qtimer.h>
53#include <qwindowsystem_qws.h> 53#include <qwindowsystem_qws.h>
54 54
55#include <qvaluelist.h> 55#include <qvaluelist.h>
56 56
57#include <stdlib.h> 57#include <stdlib.h>
58#include <unistd.h> 58#include <unistd.h>
59#include <fcntl.h> 59#include <fcntl.h>
60 60
61using namespace Opie; 61using namespace Opie;
62 62
63class QCopKeyRegister 63class QCopKeyRegister
64{ 64{
65public: 65public:
66 QCopKeyRegister() : keyCode( 0 ) 66 QCopKeyRegister() : keyCode( 0 )
67 { } 67 { }
68 QCopKeyRegister( int k, const QString &c, const QString &m ) 68 QCopKeyRegister( int k, const QString &c, const QString &m )
69 : keyCode( k ), channel( c ), message( m ) 69 : keyCode( k ), channel( c ), message( m )
70 { } 70 { }
71 71
72 int getKeyCode() const 72 int getKeyCode() const
73 { 73 {
74 return keyCode; 74 return keyCode;
75 } 75 }
76 QString getChannel() const 76 QString getChannel() const
77 { 77 {
78 return channel; 78 return channel;
79 } 79 }
80 QString getMessage() const 80 QString getMessage() const
81 { 81 {
82 return message; 82 return message;
83 } 83 }
84 84
85private: 85private:
86 int keyCode; 86 int keyCode;
87 QString channel, message; 87 QString channel, message;
88}; 88};
89 89
90typedef QValueList<QCopKeyRegister> KeyRegisterList; 90typedef QValueList<QCopKeyRegister> KeyRegisterList;
91KeyRegisterList keyRegisterList; 91KeyRegisterList keyRegisterList;
92 92
93static Desktop* qpedesktop = 0; 93static Desktop* qpedesktop = 0;
94static int loggedin = 0; 94static int loggedin = 0;
95static void login( bool at_poweron ) 95static void login( bool at_poweron )
96{ 96{
97 if ( !loggedin ) { 97 if ( !loggedin ) {
98 Global::terminateBuiltin( "calibrate" ); 98 Global::terminateBuiltin( "calibrate" );
99 Password::authenticate( at_poweron ); 99 Password::authenticate( at_poweron );
100 loggedin = 1; 100 loggedin = 1;
101 QCopEnvelope e( "QPE/Desktop", "unlocked()" ); 101 QCopEnvelope e( "QPE/Desktop", "unlocked()" );
102 } 102 }
103} 103}
104 104
105bool Desktop::screenLocked() 105bool Desktop::screenLocked()
106{ 106{
107 return loggedin == 0; 107 return loggedin == 0;
108} 108}
109 109
110/* 110/*
111 Priority is number of alerts that are needed to pop up 111 Priority is number of alerts that are needed to pop up
112 alert. 112 alert.
113 */ 113 */
114class DesktopPowerAlerter : public QMessageBox 114class DesktopPowerAlerter : public QMessageBox
115{ 115{
116public: 116public:
117 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 117 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
118 : QMessageBox( tr( "Battery Status" ), "Low Battery", 118 : QMessageBox( tr( "Battery Status" ), "Low Battery",
119 QMessageBox::Critical, 119 QMessageBox::Critical,
120 QMessageBox::Ok | QMessageBox::Default, 120 QMessageBox::Ok | QMessageBox::Default,
121 QMessageBox::NoButton, QMessageBox::NoButton, 121 QMessageBox::NoButton, QMessageBox::NoButton,
122 parent, name, FALSE ) 122 parent, name, FALSE )
123 { 123 {
124 currentPriority = INT_MAX; 124 currentPriority = INT_MAX;
125 alertCount = 0; 125 alertCount = 0;
126 } 126 }
127 127
128 void alert( const QString &text, int priority ); 128 void alert( const QString &text, int priority );
129 void hideEvent( QHideEvent * ); 129 void hideEvent( QHideEvent * );
130private: 130private:
131 int currentPriority; 131 int currentPriority;
132 int alertCount; 132 int alertCount;
133}; 133};
134 134
135void DesktopPowerAlerter::alert( const QString &text, int priority ) 135void DesktopPowerAlerter::alert( const QString &text, int priority )
136{ 136{
137 alertCount++; 137 alertCount++;
138 if ( alertCount < priority ) 138 if ( alertCount < priority )
139 return ; 139 return ;
140 if ( priority > currentPriority ) 140 if ( priority > currentPriority )
141 return ; 141 return ;
142 currentPriority = priority; 142 currentPriority = priority;
143 setText( text ); 143 setText( text );
144 show(); 144 show();
145} 145}
146 146
147 147
148void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 148void DesktopPowerAlerter::hideEvent( QHideEvent *e )
149{ 149{
150 QMessageBox::hideEvent( e ); 150 QMessageBox::hideEvent( e );
151 alertCount = 0; 151 alertCount = 0;
152 currentPriority = INT_MAX; 152 currentPriority = INT_MAX;
153} 153}
154 154
155 155
156class QPEScreenSaver : public QWSScreenSaver 156class QPEScreenSaver : public QWSScreenSaver
157{ 157{
158private: 158private:
159 int LcdOn; 159 int LcdOn;
160 160
161public: 161public:
162 QPEScreenSaver() 162 QPEScreenSaver()
163 { 163 {
164 m_disable_suspend = 100; 164 m_disable_suspend = 100;
165 m_enable_dim = false; 165 m_enable_dim = false;
166 m_enable_lightoff = false; 166 m_enable_lightoff = false;
167 m_enable_onlylcdoff = false; 167 m_enable_onlylcdoff = false;
168 168
169 m_lcd_status = true; 169 m_lcd_status = true;
170 170
171 m_backlight_bright = -1; 171 m_backlight_bright = -1;
172 m_backlight_forcedoff = false; 172 m_backlight_forcedoff = false;
173 173
174 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 174 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
175 ODevice::inst ( ) -> setDisplayStatus ( true ); 175 ODevice::inst ( ) -> setDisplayStatus ( true );
176 } 176 }
177 void restore() 177 void restore()
178 { 178 {
179 if ( !m_lcd_status ) // We must have turned it off 179 if ( !m_lcd_status ) { // We must have turned it off
180 ODevice::inst ( ) -> setDisplayStatus ( true ); 180 ODevice::inst ( ) -> setDisplayStatus ( true );
181 m_lcd_status = true;
182 }
181 183
182 setBacklight ( -3 ); 184 setBacklight ( -3 );
183 } 185 }
184 bool save( int level ) 186 bool save( int level )
185 { 187 {
186 switch ( level ) { 188 switch ( level ) {
187 case 0: 189 case 0:
188 if ( m_disable_suspend > 0 && m_enable_dim ) { 190 if ( m_disable_suspend > 0 && m_enable_dim ) {
189 if ( backlight() > 1 ) 191 if ( backlight() > 1 )
190 setBacklight( 1 ); // lowest non-off 192 setBacklight( 1 ); // lowest non-off
191 } 193 }
192 return true; 194 return true;
193 break; 195 break;
194 case 1: 196 case 1:
195 if ( m_disable_suspend > 1 && m_enable_lightoff ) { 197 if ( m_disable_suspend > 1 && m_enable_lightoff ) {
196 setBacklight( 0 ); // off 198 setBacklight( 0 ); // off
197 } 199 }
198 return true; 200 return true;
199 break; 201 break;
200 case 2: 202 case 2:
201 if ( m_enable_onlylcdoff ) { 203 if ( m_enable_onlylcdoff ) {
202 ODevice::inst ( ) -> setDisplayStatus ( false ); 204 ODevice::inst ( ) -> setDisplayStatus ( false );
203 m_lcd_status = false; 205 m_lcd_status = false;
204 return true; 206 return true;
205 } 207 }
206 else // We're going to suspend the whole machine 208 else // We're going to suspend the whole machine
207 { 209 {
208 if ( ( m_disable_suspend > 2 ) && 210 if ( ( m_disable_suspend > 2 ) &&
209 ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && 211 ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) &&
210 ( !Network::networkOnline ( ) ) ) { 212 ( !Network::networkOnline ( ) ) ) {
211 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 213 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
212 return true; 214 return true;
213 } 215 }
214 } 216 }
215 break; 217 break;
216 } 218 }
217 return false; 219 return false;
218 } 220 }
219 221
220private: 222private:
221 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) 223 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def )
222 { 224 {
223 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) 225 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 )
224 return 0; 226 return 0;
225 227
226 if ( interval < 0 ) { 228 if ( interval < 0 ) {
227 // Restore screen blanking and power saving state 229 // Restore screen blanking and power saving state
228 interval = config.readNumEntry( value, def ); 230 interval = config.readNumEntry( value, def );
229 } 231 }
230 return interval; 232 return interval;
231 } 233 }
232 234
233public: 235public:
234 void setIntervals( int i1, int i2, int i3 ) 236 void setIntervals( int i1, int i2, int i3 )
235 { 237 {
236 Config config( "qpe" ); 238 Config config( "qpe" );
237 config.setGroup( "Screensaver" ); 239 config.setGroup( "Screensaver" );
238 240
239 int v[ 4 ]; 241 int v[ 4 ];
240 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); 242 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 );
241 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); 243 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 );
242 i3 = ssi( i3, config, "", "Interval", 60 ); 244 i3 = ssi( i3, config, "", "Interval", 60 );
243 245
244 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 246 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
245 247
246 v [ 0 ] = QMAX( 1000 * i1, 100 ); 248 v [ 0 ] = QMAX( 1000 * i1, 100 );
247 v [ 1 ] = QMAX( 1000 * i2, 100 ); 249 v [ 1 ] = QMAX( 1000 * i2, 100 );
248 v [ 2 ] = QMAX( 1000 * i3, 100 ); 250 v [ 2 ] = QMAX( 1000 * i3, 100 );
249 v [ 3 ] = 0; 251 v [ 3 ] = 0;
250 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); 252 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false );
251 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); 253 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false );
252 m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); 254 m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 );
253 255
254 if ( !i1 && !i2 && !i3 ) 256 if ( !i1 && !i2 && !i3 )
255 QWSServer::setScreenSaverInterval( 0 ); 257 QWSServer::setScreenSaverInterval( 0 );
256 else 258 else
257 QWSServer::setScreenSaverIntervals( v ); 259 QWSServer::setScreenSaverIntervals( v );
258 } 260 }
259 261
260 void setInterval ( int interval ) 262 void setInterval ( int interval )
261 { 263 {
262 setIntervals ( -1, -1, interval ); 264 setIntervals ( -1, -1, interval );
263 } 265 }
264 266
265 void setMode ( int mode ) 267 void setMode ( int mode )
266 { 268 {
267 if ( mode > m_disable_suspend ) 269 if ( mode > m_disable_suspend )
268 setInterval( -1 ); 270 setInterval( -1 );
269 m_disable_suspend = mode; 271 m_disable_suspend = mode;
270 } 272 }
271 273
272 int backlight ( ) 274 int backlight ( )
273 { 275 {
274 if ( m_backlight_bright == -1 ) { 276 if ( m_backlight_bright == -1 ) {
275 // Read from config 277 // Read from config
276 Config config ( "qpe" ); 278 Config config ( "qpe" );
277 config. setGroup ( "Screensaver" ); 279 config. setGroup ( "Screensaver" );
278 m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); 280 m_backlight_bright = config. readNumEntry ( "Brightness", 255 );
279 } 281 }
280 return m_backlight_bright; 282 return m_backlight_bright;
281 } 283 }
282 284
283 void setBacklight ( int bright ) 285 void setBacklight ( int bright )
284 { 286 {
285 if ( bright == -3 ) { 287 if ( bright == -3 ) {
286 // Forced on 288 // Forced on
287 m_backlight_forcedoff = false; 289 m_backlight_forcedoff = false;
288 bright = -1; 290 bright = -1;
289 } 291 }
290 if ( m_backlight_forcedoff && bright != -2 ) 292 if ( m_backlight_forcedoff && bright != -2 )
291 return ; 293 return ;
292 if ( bright == -2 ) { 294 if ( bright == -2 ) {
293 // Toggle between off and on 295 // Toggle between off and on
294 bright = m_backlight_bright ? 0 : -1; 296 bright = m_backlight_bright ? 0 : -1;
295 m_backlight_forcedoff = !bright; 297 m_backlight_forcedoff = !bright;
296 } 298 }
297 299
298 m_backlight_bright = bright; 300 m_backlight_bright = bright;
299 301
300 bright = backlight ( ); 302 bright = backlight ( );
301 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 303 ODevice::inst ( ) -> setDisplayBrightness ( bright );
302 304
303 m_backlight_bright = bright; 305 m_backlight_bright = bright;
304 } 306 }
305 307
308 void setDisplayState ( bool on )
309 {
310 if ( m_lcd_status != on ) {
311 ODevice::inst ( ) -> setDisplayStatus ( on );
312 m_lcd_status = on;
313 }
314 }
315
306private: 316private:
307 int m_disable_suspend; 317 int m_disable_suspend;
308 bool m_enable_dim; 318 bool m_enable_dim;
309 bool m_enable_lightoff; 319 bool m_enable_lightoff;
310 bool m_enable_onlylcdoff; 320 bool m_enable_onlylcdoff;
311 321
312 bool m_lcd_status; 322 bool m_lcd_status;
313 323
314 int m_backlight_bright; 324 int m_backlight_bright;
315 bool m_backlight_forcedoff; 325 bool m_backlight_forcedoff;
316}; 326};
317 327
318 328
319void DesktopApplication::switchLCD ( bool on ) 329void DesktopApplication::switchLCD ( bool on )
320{ 330{
321 if ( qApp ) { 331 if ( qApp ) {
322 DesktopApplication *dapp = (DesktopApplication *) qApp; 332 DesktopApplication *dapp = (DesktopApplication *) qApp;
323 333
324 if ( dapp-> m_screensaver ) { 334 if ( dapp-> m_screensaver ) {
325 if ( on ) 335 if ( on )
326 dapp-> m_screensaver-> restore ( ); //setBacklight ( on ? -3 : -1 ); 336 dapp-> m_screensaver-> restore ( ); //setBacklight ( on ? -3 : -1 );
327 else 337 else
328 dapp-> m_screensaver-> save ( 1 ); 338 dapp-> m_screensaver-> save ( 1 );
329 339
330 } 340 }
331 } 341 }
332} 342}
333 343
334 344
335DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) 345DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
336 : QPEApplication( argc, argv, appType ) 346 : QPEApplication( argc, argv, appType )
337{ 347{
338 348
339 QTimer * t = new QTimer( this ); 349 QTimer * t = new QTimer( this );
340 connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); 350 connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) );
341 t->start( 10000 ); 351 t->start( 10000 );
342 ps = new PowerStatus; 352 ps = new PowerStatus;
343 pa = new DesktopPowerAlerter( 0 ); 353 pa = new DesktopPowerAlerter( 0 );
344 354
345 channel = new QCopChannel( "QPE/Desktop", this ); 355 channel = new QCopChannel( "QPE/Desktop", this );
346 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 356 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
347 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); 357 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) );
348 358
349 channel = new QCopChannel( "QPE/System", this ); 359 channel = new QCopChannel( "QPE/System", this );
350 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 360 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
351 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); 361 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
352 362
353 m_screensaver = new QPEScreenSaver; 363 m_screensaver = new QPEScreenSaver;
354 364
355 m_screensaver-> setInterval ( -1 ); 365 m_screensaver-> setInterval ( -1 );
356 QWSServer::setScreenSaver( m_screensaver ); 366 QWSServer::setScreenSaver( m_screensaver );
357} 367}
358 368
359 369
360DesktopApplication::~DesktopApplication() 370DesktopApplication::~DesktopApplication()
361{ 371{
362 delete ps; 372 delete ps;
363 delete pa; 373 delete pa;
364} 374}
365 375
366void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) 376void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data )
367{ 377{
368#ifdef Q_WS_QWS 378#ifdef Q_WS_QWS
369 QDataStream stream( data, IO_ReadOnly ); 379 QDataStream stream( data, IO_ReadOnly );
370 if ( msg == "keyRegister(int key, QString channel, QString message)" ) { 380 if ( msg == "keyRegister(int key, QString channel, QString message)" ) {
371 int k; 381 int k;
372 QString c, m; 382 QString c, m;
373 stream >> k; 383 stream >> k;
374 stream >> c; 384 stream >> c;
375 stream >> m; 385 stream >> m;
376 386
377 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); 387 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m );
378 keyRegisterList.append( QCopKeyRegister( k, c, m ) ); 388 keyRegisterList.append( QCopKeyRegister( k, c, m ) );
379 } 389 }
380 else if ( msg == "suspend()" ) {
381 emit power();
382 }
383 else if ( msg == "home()" ) {
384 qpedesktop-> home ( );
385 }
386#endif 390#endif
387} 391}
388 392
389 393
390void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) 394void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data )
391{ 395{
392#ifdef Q_WS_QWS 396#ifdef Q_WS_QWS
393 QDataStream stream ( data, IO_ReadOnly ); 397 QDataStream stream ( data, IO_ReadOnly );
394 398
395 if ( msg == "setScreenSaverInterval(int)" ) { 399 if ( msg == "setScreenSaverInterval(int)" ) {
396 int time; 400 int time;
397 stream >> time; 401 stream >> time;
398 m_screensaver-> setInterval( time ); 402 m_screensaver-> setInterval( time );
399 } 403 }
400 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 404 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
401 int t1, t2, t3; 405 int t1, t2, t3;
402 stream >> t1 >> t2 >> t3; 406 stream >> t1 >> t2 >> t3;
403 m_screensaver-> setIntervals( t1, t2, t3 ); 407 m_screensaver-> setIntervals( t1, t2, t3 );
404 } 408 }
405 else if ( msg == "setBacklight(int)" ) { 409 else if ( msg == "setBacklight(int)" ) {
406 int bright; 410 int bright;
407 stream >> bright; 411 stream >> bright;
408 m_screensaver-> setBacklight( bright ); 412 m_screensaver-> setBacklight( bright );
409 } 413 }
410 else if ( msg == "setScreenSaverMode(int)" ) { 414 else if ( msg == "setScreenSaverMode(int)" ) {
411 int mode; 415 int mode;
412 stream >> mode; 416 stream >> mode;
413 m_screensaver-> setMode ( mode ); 417 m_screensaver-> setMode ( mode );
414 } 418 }
419 else if ( msg == "setDisplayState(int)" ) {
420 int state;
421 stream >> state;
422 m_screensaver-> setDisplayState ( state != 0 );
423 }
424 else if ( msg == "suspend()" ) {
425 emit power();
426 }
415#endif 427#endif
416} 428}
417 429
418enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; 430enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown;
419 431
420#ifdef Q_WS_QWS 432#ifdef Q_WS_QWS
421bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 433bool DesktopApplication::qwsEventFilter( QWSEvent *e )
422{ 434{
423 qpedesktop->checkMemory(); 435 qpedesktop->checkMemory();
424 436
425 if ( e->type == QWSEvent::Key ) { 437 if ( e->type == QWSEvent::Key ) {
426 QWSKeyEvent * ke = ( QWSKeyEvent * ) e; 438 QWSKeyEvent * ke = ( QWSKeyEvent * ) e;
427 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 439 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
428 return TRUE; 440 return TRUE;
429 bool press = ke->simpleData.is_press; 441 bool press = ke->simpleData.is_press;
430 bool autoRepeat = ke->simpleData.is_auto_repeat; 442 bool autoRepeat = ke->simpleData.is_auto_repeat;
431 443
432 /* 444 /*
433 app that registers key/message to be sent back to the app, when it doesn't have focus, 445 app that registers key/message to be sent back to the app, when it doesn't have focus,
434 when user presses key, unless keyboard has been requested from app. 446 when user presses key, unless keyboard has been requested from app.
435 will not send multiple repeats if user holds key 447 will not send multiple repeats if user holds key
436 i.e. one shot 448 i.e. one shot
437 */ 449 */
438 if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { 450 if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) {
439// qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); 451// qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode);
440 KeyRegisterList::Iterator it; 452 KeyRegisterList::Iterator it;
441 for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { 453 for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
442 if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { 454 if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) {
443 if ( press ) 455 if ( press )
444 qDebug( "press" ); 456 qDebug( "press" );
445 else 457 else
446 qDebug( "release" ); 458 qDebug( "release" );
447 QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); 459 QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() );
448 } 460 }
449 } 461 }
450 } 462 }
451 463
452 if ( !keyboardGrabbed() ) { 464 if ( !keyboardGrabbed() ) {
453 if ( ke->simpleData.keycode == Key_F9 ) { 465 if ( ke->simpleData.keycode == Key_F9 ) {
454 if ( press ) 466 if ( press )
455 emit datebook(); 467 emit datebook();
456 return TRUE; 468 return TRUE;
457 } 469 }
458 if ( ke->simpleData.keycode == Key_F10 ) { 470 if ( ke->simpleData.keycode == Key_F10 ) {
459 if ( !press && cardSendTimer ) { 471 if ( !press && cardSendTimer ) {
460 emit contacts(); 472 emit contacts();
461 delete cardSendTimer; 473 delete cardSendTimer;
462 } 474 }
463 else if ( press ) { 475 else if ( press ) {
464 cardSendTimer = new QTimer(); 476 cardSendTimer = new QTimer();
465 cardSendTimer->start( 2000, TRUE ); 477 cardSendTimer->start( 2000, TRUE );
466 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 478 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
467 } 479 }
468 return TRUE; 480 return TRUE;
469 } 481 }
470 /* menu key now opens application menu/toolbar 482 /* menu key now opens application menu/toolbar
471 if ( ke->simpleData.keycode == Key_F11 ) { 483 if ( ke->simpleData.keycode == Key_F11 ) {
472 if ( press ) emit menu(); 484 if ( press ) emit menu();
473 return TRUE; 485 return TRUE;
474 } 486 }
475 */ 487 */
476 if ( ke->simpleData.keycode == Key_F12 ) { 488 if ( ke->simpleData.keycode == Key_F12 ) {
477 while ( activePopupWidget() ) 489 while ( activePopupWidget() )
478 activePopupWidget() ->close(); 490 activePopupWidget() ->close();
479 if ( press ) 491 if ( press )
480 emit launch(); 492 emit launch();
481 return TRUE; 493 return TRUE;
482 } 494 }
483 if ( ke->simpleData.keycode == Key_F13 ) { 495 if ( ke->simpleData.keycode == Key_F13 ) {
484 if ( press ) 496 if ( press )
485 emit email(); 497 emit email();
486 return TRUE; 498 return TRUE;
487 } 499 }
488 } 500 }
489 501
490 if ( ke->simpleData.keycode == Key_F34 ) { 502 if ( ke->simpleData.keycode == Key_F34 ) {
491 if ( press ) 503 if ( press )
492 emit power(); 504 emit power();
493 return TRUE; 505 return TRUE;
494 } 506 }
495 // This was used for the iPAQ PowerButton 507 // This was used for the iPAQ PowerButton
496 // See main.cpp for new KeyboardFilter 508 // See main.cpp for new KeyboardFilter
497 // 509 //
498 // if ( ke->simpleData.keycode == Key_SysReq ) { 510 // if ( ke->simpleData.keycode == Key_SysReq ) {
499 // if ( press ) emit power(); 511 // if ( press ) emit power();
500 // return TRUE; 512 // return TRUE;
501 // } 513 // }
502 if ( ke->simpleData.keycode == Key_F35 ) { 514 if ( ke->simpleData.keycode == Key_F35 ) {
503 if ( press ) 515 if ( press )
504 emit backlight(); 516 emit backlight();
505 return TRUE; 517 return TRUE;
506 } 518 }
507 if ( ke->simpleData.keycode == Key_F32 ) { 519 if ( ke->simpleData.keycode == Key_F32 ) {
508 if ( press ) 520 if ( press )
509 QCopEnvelope e( "QPE/Desktop", "startSync()" ); 521 QCopEnvelope e( "QPE/Desktop", "startSync()" );
510 return TRUE; 522 return TRUE;
511 } 523 }
512 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 524 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
513 if ( press ) 525 if ( press )
514 emit symbol(); 526 emit symbol();
515 return TRUE; 527 return TRUE;
516 } 528 }
517 if ( ke->simpleData.keycode == Key_NumLock ) { 529 if ( ke->simpleData.keycode == Key_NumLock ) {
518 if ( press ) 530 if ( press )
519 emit numLockStateToggle(); 531 emit numLockStateToggle();
520 } 532 }
521 if ( ke->simpleData.keycode == Key_CapsLock ) { 533 if ( ke->simpleData.keycode == Key_CapsLock ) {
522 if ( press ) 534 if ( press )
523 emit capsLockStateToggle(); 535 emit capsLockStateToggle();
524 } 536 }
525 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) 537 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) )
526 qpedesktop->keyClick(); 538 qpedesktop->keyClick();
527 } 539 }
528 else { 540 else {
529 if ( e->type == QWSEvent::Mouse ) { 541 if ( e->type == QWSEvent::Mouse ) {
530 QWSMouseEvent * me = ( QWSMouseEvent * ) e; 542 QWSMouseEvent * me = ( QWSMouseEvent * ) e;
531 static bool up = TRUE; 543 static bool up = TRUE;
532 if ( me->simpleData.state & LeftButton ) { 544 if ( me->simpleData.state & LeftButton ) {
533 if ( up ) { 545 if ( up ) {
534 up = FALSE; 546 up = FALSE;
535 qpedesktop->screenClick(); 547 qpedesktop->screenClick();
536 } 548 }
537 } 549 }
538 else { 550 else {
539 up = TRUE; 551 up = TRUE;
540 } 552 }
541 } 553 }
542 } 554 }
543 555
544 return QPEApplication::qwsEventFilter( e ); 556 return QPEApplication::qwsEventFilter( e );
545} 557}
546#endif 558#endif
547 559
548void DesktopApplication::psTimeout() 560void DesktopApplication::psTimeout()
549{ 561{
550 qpedesktop->checkMemory(); // in case no events are being generated 562 qpedesktop->checkMemory(); // in case no events are being generated
551 563
552 *ps = PowerStatusManager::readStatus(); 564 *ps = PowerStatusManager::readStatus();
553 565
554 if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { 566 if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) {
555 pa->alert( tr( "Battery is running very low." ), 6 ); 567 pa->alert( tr( "Battery is running very low." ), 6 );
556 } 568 }
557 569
558 if ( ps->batteryStatus() == PowerStatus::Critical ) { 570 if ( ps->batteryStatus() == PowerStatus::Critical ) {
559 pa->alert( tr( "Battery level is critical!\n" 571 pa->alert( tr( "Battery level is critical!\n"
560 "Keep power off until power restored!" ), 1 ); 572 "Keep power off until power restored!" ), 1 );
561 } 573 }
562 574
563 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 575 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
564 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 576 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
565 } 577 }
566} 578}
567 579
568 580
569void DesktopApplication::sendCard() 581void DesktopApplication::sendCard()
570{ 582{
571 delete cardSendTimer; 583 delete cardSendTimer;
572 cardSendTimer = 0; 584 cardSendTimer = 0;
573 QString card = getenv( "HOME" ); 585 QString card = getenv( "HOME" );
574 card += "/Applications/addressbook/businesscard.vcf"; 586 card += "/Applications/addressbook/businesscard.vcf";
575 587
576 if ( QFile::exists( card ) ) { 588 if ( QFile::exists( card ) ) {
577 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); 589 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" );
578 QString mimetype = "text/x-vCard"; 590 QString mimetype = "text/x-vCard";
579 e << tr( "business card" ) << card << mimetype; 591 e << tr( "business card" ) << card << mimetype;
580 } 592 }
581} 593}
582 594
583#if defined(QPE_HAVE_MEMALERTER) 595#if defined(QPE_HAVE_MEMALERTER)
584QPE_MEMALERTER_IMPL 596QPE_MEMALERTER_IMPL
585#endif 597#endif
586 598
587//=========================================================================== 599//===========================================================================
588 600
589Desktop::Desktop() : 601Desktop::Desktop() :
590 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 602 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
591 qcopBridge( 0 ), 603 qcopBridge( 0 ),
592 transferServer( 0 ), 604 transferServer( 0 ),
593 packageSlave( 0 ) 605 packageSlave( 0 )
594{ 606{
595 qpedesktop = this; 607 qpedesktop = this;
596 608
597 // bg = new Info( this ); 609 // bg = new Info( this );
598 tb = new TaskBar; 610 tb = new TaskBar;
599 611
600 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 612 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
601 613
602 connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); 614 connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) );
603 connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); 615 connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) );
604 616
605 int displayw = qApp->desktop() ->width(); 617 int displayw = qApp->desktop() ->width();
606 int displayh = qApp->desktop() ->height(); 618 int displayh = qApp->desktop() ->height();
607 619
608 620
609 QSize sz = tb->sizeHint(); 621 QSize sz = tb->sizeHint();
610 622
611 setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 623 setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
612 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 624 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
613 625
614 tb->show(); 626 tb->show();
615 launcher->showMaximized(); 627 launcher->showMaximized();
616 launcher->show(); 628 launcher->show();
617 launcher->raise(); 629 launcher->raise();
618#if defined(QPE_HAVE_MEMALERTER) 630#if defined(QPE_HAVE_MEMALERTER)
619 631
620 initMemalerter(); 632 initMemalerter();
621#endif 633#endif
622 // start services 634 // start services
623 startTransferServer(); 635 startTransferServer();
624 ( void ) new IrServer( this ); 636 ( void ) new IrServer( this );
625 rereadVolumes(); 637 rereadVolumes();
626 638
627 packageSlave = new PackageSlave( this ); 639 packageSlave = new PackageSlave( this );
628 connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); 640 connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) );
629 641
630 qApp->installEventFilter( this ); 642 qApp->installEventFilter( this );
643
644 qApp-> setMainWidget ( launcher );
631} 645}
632 646
633void Desktop::show() 647void Desktop::show()
634{ 648{
635 login( TRUE ); 649 login( TRUE );
636 QWidget::show(); 650 QWidget::show();
637} 651}
638 652
639Desktop::~Desktop() 653Desktop::~Desktop()
640{ 654{
641 delete launcher; 655 delete launcher;
642 delete tb; 656 delete tb;
643 delete qcopBridge; 657 delete qcopBridge;
644 delete transferServer; 658 delete transferServer;
645} 659}
646 660
647bool Desktop::recoverMemory() 661bool Desktop::recoverMemory()
648{ 662{
649 return tb->recoverMemory(); 663 return tb->recoverMemory();
650} 664}
651 665
652void Desktop::checkMemory() 666void Desktop::checkMemory()
653{ 667{
654#if defined(QPE_HAVE_MEMALERTER) 668#if defined(QPE_HAVE_MEMALERTER)
655 static bool ignoreNormal = FALSE; 669 static bool ignoreNormal = FALSE;
656 static bool existingMessage = FALSE; 670 static bool existingMessage = FALSE;
657 671
658 if ( existingMessage ) 672 if ( existingMessage )
659 return ; // don't show a second message while still on first 673 return ; // don't show a second message while still on first
660 674
661 existingMessage = TRUE; 675 existingMessage = TRUE;
662 switch ( memstate ) { 676 switch ( memstate ) {
663 case Unknown: 677 case Unknown:
664 break; 678 break;
665 case Low: 679 case Low:
666 memstate = Unknown; 680 memstate = Unknown;
667 if ( recoverMemory() ) 681 if ( recoverMemory() )
668 ignoreNormal = TRUE; 682 ignoreNormal = TRUE;
669 else 683 else
670 QMessageBox::warning( 0 , "Memory Status", 684 QMessageBox::warning( 0 , "Memory Status",
671 "The memory smacks of shortage. \n" 685 "The memory smacks of shortage. \n"
672 "Please save data. " ); 686 "Please save data. " );
673 break; 687 break;
674 case Normal: 688 case Normal:
675 memstate = Unknown; 689 memstate = Unknown;
676 if ( ignoreNormal ) 690 if ( ignoreNormal )
677 ignoreNormal = FALSE; 691 ignoreNormal = FALSE;
678// else 692// else
679// QMessageBox::information ( 0 , "Memory Status", 693// QMessageBox::information ( 0 , "Memory Status",
680// "There is enough memory again." ); 694// "There is enough memory again." );
681 break; 695 break;
682 case VeryLow: 696 case VeryLow:
683 memstate = Unknown; 697 memstate = Unknown;
684 QMessageBox::critical( 0 , "Memory Status", 698 QMessageBox::critical( 0 , "Memory Status",
685 "The memory is very low. \n" 699 "The memory is very low. \n"
686 "Please end this application \n" 700 "Please end this application \n"
687 "immediately." ); 701 "immediately." );
688 recoverMemory(); 702 recoverMemory();
689 } 703 }
690 existingMessage = FALSE; 704 existingMessage = FALSE;
691#endif 705#endif
692} 706}
693 707
694static bool isVisibleWindow( int wid ) 708static bool isVisibleWindow( int wid )
695{ 709{
696 const QList<QWSWindow> &list = qwsServer->clientWindows(); 710 const QList<QWSWindow> &list = qwsServer->clientWindows();
697 QWSWindow* w; 711 QWSWindow* w;
698 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { 712 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) {
699 if ( w->winId() == wid ) 713 if ( w->winId() == wid )
700 return !w->isFullyObscured(); 714 return !w->isFullyObscured();
701 } 715 }
702 return FALSE; 716 return FALSE;
703} 717}
704 718
705static bool hasVisibleWindow( const QString& clientname ) 719static bool hasVisibleWindow( const QString& clientname )
706{ 720{
707 const QList<QWSWindow> &list = qwsServer->clientWindows(); 721 const QList<QWSWindow> &list = qwsServer->clientWindows();
708 QWSWindow* w; 722 QWSWindow* w;
709 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { 723 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) {
710 if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) 724 if ( w->client() ->identity() == clientname && !w->isFullyObscured() )
711 return TRUE; 725 return TRUE;
712 } 726 }
713 return FALSE; 727 return FALSE;
714} 728}
715 729
716void Desktop::raiseLauncher() 730void Desktop::raiseLauncher()
717{ 731{
718 Config cfg( "qpe" ); //F12 'Home' 732 Config cfg( "qpe" ); //F12 'Home'
719 cfg.setGroup( "AppsKey" ); 733 cfg.setGroup( "AppsKey" );
720 QString tempItem; 734 QString tempItem;
721 tempItem = cfg.readEntry( "Middle", "Home" ); 735 tempItem = cfg.readEntry( "Middle", "Home" );
722 if ( tempItem == "Home" || tempItem.isEmpty() ) { 736 if ( tempItem == "Home" || tempItem.isEmpty() ) {
723 home ( ); 737 home ( );
724 } 738 }
725 else { 739 else {
726 QCopEnvelope e( "QPE/System", "execute(QString)" ); 740 QCopEnvelope e( "QPE/System", "execute(QString)" );
727 e << tempItem; 741 e << tempItem;
728 } 742 }
729} 743}
730 744
731void Desktop::home ( ) 745void Desktop::home ( )
732{ 746{
733 if ( isVisibleWindow( launcher->winId() ) ) 747 if ( isVisibleWindow( launcher->winId() ) )
734 launcher->nextView(); 748 launcher->nextView();
735 else 749 else
736 launcher->raise(); 750 launcher->raise();
737} 751}
738 752
739void Desktop::executeOrModify( const QString& appLnkFile ) 753void Desktop::executeOrModify( const QString& appLnkFile )
740{ 754{
741 AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); 755 AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile );
742 if ( lnk.isValid() ) { 756 if ( lnk.isValid() ) {
743 QCString app = lnk.exec().utf8(); 757 QCString app = lnk.exec().utf8();
744 Global::terminateBuiltin( "calibrate" ); 758 Global::terminateBuiltin( "calibrate" );
745 if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { 759 if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) {
746 // MRUList::addTask( &lnk ); 760 // MRUList::addTask( &lnk );
747 if ( hasVisibleWindow( app ) ) 761 if ( hasVisibleWindow( app ) )
748 QCopChannel::send( "QPE/Application/" + app, "nextView()" ); 762 QCopChannel::send( "QPE/Application/" + app, "nextView()" );
749 else 763 else
750 QCopChannel::send( "QPE/Application/" + app, "raise()" ); 764 QCopChannel::send( "QPE/Application/" + app, "raise()" );
751 } 765 }
752 else { 766 else {
753 lnk.execute(); 767 lnk.execute();
754 } 768 }
755 } 769 }
756} 770}
757 771
758void Desktop::raiseDatebook() 772void Desktop::raiseDatebook()
759{ 773{
760 Config cfg( "qpe" ); //F9 'Activity' 774 Config cfg( "qpe" ); //F9 'Activity'
761 cfg.setGroup( "AppsKey" ); 775 cfg.setGroup( "AppsKey" );
762 QString tempItem; 776 QString tempItem;
763 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); 777 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" );
764 if ( tempItem == "Calendar" || tempItem.isEmpty() ) { 778 if ( tempItem == "Calendar" || tempItem.isEmpty() ) {
765 tempItem = "datebook"; 779 tempItem = "datebook";
766 } 780 }
767 QCopEnvelope e( "QPE/System", "execute(QString)" ); 781 QCopEnvelope e( "QPE/System", "execute(QString)" );
768 e << tempItem; 782 e << tempItem;
769} 783}
770 784
771void Desktop::raiseContacts() 785void Desktop::raiseContacts()
772{ 786{
773 Config cfg( "qpe" ); //F10, 'Contacts' 787 Config cfg( "qpe" ); //F10, 'Contacts'
774 cfg.setGroup( "AppsKey" ); 788 cfg.setGroup( "AppsKey" );
775 QString tempItem; 789 QString tempItem;
776 tempItem = cfg.readEntry( "Left2nd", "Address Book" ); 790 tempItem = cfg.readEntry( "Left2nd", "Address Book" );
777 if ( tempItem == "Address Book" || tempItem.isEmpty() ) { 791 if ( tempItem == "Address Book" || tempItem.isEmpty() ) {
778 tempItem = "addressbook"; 792 tempItem = "addressbook";
779 } 793 }
780 QCopEnvelope e( "QPE/System", "execute(QString)" ); 794 QCopEnvelope e( "QPE/System", "execute(QString)" );
781 e << tempItem; 795 e << tempItem;
782} 796}
783 797
784void Desktop::raiseMenu() 798void Desktop::raiseMenu()
785{ 799{
786 Config cfg( "qpe" ); //F11, 'Menu 800 Config cfg( "qpe" ); //F11, 'Menu
787 cfg.setGroup( "AppsKey" ); 801 cfg.setGroup( "AppsKey" );
788 QString tempItem; 802 QString tempItem;
789 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); 803 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" );
790 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { 804 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) {
791 Global::terminateBuiltin( "calibrate" ); 805 Global::terminateBuiltin( "calibrate" );
792 tb->startMenu() ->launch(); 806 tb->startMenu() ->launch();
793 } 807 }
794 else { 808 else {
795 QCopEnvelope e( "QPE/System", "execute(QString)" ); 809 QCopEnvelope e( "QPE/System", "execute(QString)" );
796 e << tempItem; 810 e << tempItem;
797 } 811 }
798} 812}
799 813
800void Desktop::raiseEmail() 814void Desktop::raiseEmail()
801{ 815{
802 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 816 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11
803 cfg.setGroup( "AppsKey" ); 817 cfg.setGroup( "AppsKey" );
804 QString tempItem; 818 QString tempItem;
805 tempItem = cfg.readEntry( "RightEnd", "Mail" ); 819 tempItem = cfg.readEntry( "RightEnd", "Mail" );
806 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { 820 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) {
807 tempItem = "mail"; 821 tempItem = "mail";
808 } 822 }
809 QCopEnvelope e( "QPE/System", "execute(QString)" ); 823 QCopEnvelope e( "QPE/System", "execute(QString)" );
810 e << tempItem; 824 e << tempItem;
811} 825}
812 826
813// autoStarts apps on resume and start 827// autoStarts apps on resume and start
814void Desktop::execAutoStart() 828void Desktop::execAutoStart()
815{ 829{
816 QString appName; 830 QString appName;
817 int delay; 831 int delay;
818 QDateTime now = QDateTime::currentDateTime(); 832 QDateTime now = QDateTime::currentDateTime();
819 Config cfg( "autostart" ); 833 Config cfg( "autostart" );
820 cfg.setGroup( "AutoStart" ); 834 cfg.setGroup( "AutoStart" );
821 appName = cfg.readEntry( "Apps", "" ); 835 appName = cfg.readEntry( "Apps", "" );
822 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); 836 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt();
823 // If the time between suspend and resume was longer then the 837 // If the time between suspend and resume was longer then the
824 // value saved as delay, start the app 838 // value saved as delay, start the app
825 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { 839 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
826 QCopEnvelope e( "QPE/System", "execute(QString)" ); 840 QCopEnvelope e( "QPE/System", "execute(QString)" );
827 e << QString( appName ); 841 e << QString( appName );
828 } 842 }
829} 843}
830 844
831#if defined(QPE_HAVE_TOGGLELIGHT) 845#if defined(QPE_HAVE_TOGGLELIGHT)
832#include <qpe/config.h> 846#include <qpe/config.h>
833 847
834#include <sys/ioctl.h> 848#include <sys/ioctl.h>
835#include <sys/types.h> 849#include <sys/types.h>
836#include <fcntl.h> 850#include <fcntl.h>
837#include <unistd.h> 851#include <unistd.h>
838#include <errno.h> 852#include <errno.h>
839#include <linux/ioctl.h> 853#include <linux/ioctl.h>
840#include <time.h> 854#include <time.h>
841#endif 855#endif
842 856
843 857
844void Desktop::togglePower() 858void Desktop::togglePower()
845{ 859{
846 static bool excllock = false; 860 static bool excllock = false;
847 861
848 qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); 862 qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 );
849 863
850 if ( excllock ) 864 if ( excllock )
851 return ; 865 return ;
852 866
853 excllock = true; 867 excllock = true;
854 868
855 bool wasloggedin = loggedin; 869 bool wasloggedin = loggedin;
856 loggedin = 0; 870 loggedin = 0;
857 suspendTime = QDateTime::currentDateTime(); 871 suspendTime = QDateTime::currentDateTime();
858 872
859 ODevice::inst ( ) -> suspend ( ); 873 ODevice::inst ( ) -> suspend ( );
860 874
861 QWSServer::screenSaverActivate ( false ); 875 QWSServer::screenSaverActivate ( false );
862 DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call 876 DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call
863 877
864 { 878 {
865 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep 879 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep
866 } 880 }
867 881
868 if ( wasloggedin ) 882 if ( wasloggedin )
869 login( TRUE ); 883 login( TRUE );
870 884
871 execAutoStart(); 885 execAutoStart();
872 //qcopBridge->closeOpenConnections(); 886 //qcopBridge->closeOpenConnections();
873 887
874 excllock = false; 888 excllock = false;
875} 889}
876 890
877void Desktop::toggleLight() 891void Desktop::toggleLight()
878{ 892{
879 QCopEnvelope e( "QPE/System", "setBacklight(int)" ); 893 QCopEnvelope e( "QPE/System", "setBacklight(int)" );
880 e << -2; // toggle 894 e << -2; // toggle
881} 895}
882 896
883void Desktop::toggleSymbolInput() 897void Desktop::toggleSymbolInput()
884{ 898{
885 tb->toggleSymbolInput(); 899 tb->toggleSymbolInput();
886} 900}
887 901
888void Desktop::toggleNumLockState() 902void Desktop::toggleNumLockState()
889{ 903{
890 tb->toggleNumLockState(); 904 tb->toggleNumLockState();
891} 905}
892 906
893void Desktop::toggleCapsLockState() 907void Desktop::toggleCapsLockState()
894{ 908{
895 tb->toggleCapsLockState(); 909 tb->toggleCapsLockState();
896} 910}
897 911
898void Desktop::styleChange( QStyle &s ) 912void Desktop::styleChange( QStyle &s )
899{ 913{
900 QWidget::styleChange( s ); 914 QWidget::styleChange( s );
901 int displayw = qApp->desktop() ->width(); 915 int displayw = qApp->desktop() ->width();
902 int displayh = qApp->desktop() ->height(); 916 int displayh = qApp->desktop() ->height();
903 917
904 QSize sz = tb->sizeHint(); 918 QSize sz = tb->sizeHint();
905 919
906 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 920 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
907} 921}
908 922
909void DesktopApplication::shutdown() 923void DesktopApplication::shutdown()
910{ 924{
911 if ( type() != GuiServer ) 925 if ( type() != GuiServer )
912 return ; 926 return ;
913 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 927 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
914 connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), 928 connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ),
915 this, SLOT( shutdown( ShutdownImpl::Type ) ) ); 929 this, SLOT( shutdown( ShutdownImpl::Type ) ) );
916 sd->showMaximized(); 930 sd->showMaximized();
917} 931}
918 932
919void DesktopApplication::shutdown( ShutdownImpl::Type t ) 933void DesktopApplication::shutdown( ShutdownImpl::Type t )
920{ 934{
921 switch ( t ) { 935 switch ( t ) {
922 case ShutdownImpl::ShutdownSystem: 936 case ShutdownImpl::ShutdownSystem:
923 execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); 937 execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 );
924 break; 938 break;
925 case ShutdownImpl::RebootSystem: 939 case ShutdownImpl::RebootSystem:
926 execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); 940 execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 );
927 break; 941 break;
928 case ShutdownImpl::RestartDesktop: 942 case ShutdownImpl::RestartDesktop:
929 restart(); 943 restart();
930 break; 944 break;
931 case ShutdownImpl::TerminateDesktop: 945 case ShutdownImpl::TerminateDesktop:
932 prepareForTermination( FALSE ); 946 prepareForTermination( FALSE );
933 947
934 // This is a workaround for a Qt bug 948 // This is a workaround for a Qt bug
935 // clipboard applet has to stop its poll timer, or Qt/E 949 // clipboard applet has to stop its poll timer, or Qt/E
936 // will hang on quit() right before it emits aboutToQuit() 950 // will hang on quit() right before it emits aboutToQuit()
937 emit aboutToQuit ( ); 951 emit aboutToQuit ( );
938 952
939 quit(); 953 quit();
940 break; 954 break;
941 } 955 }
942} 956}
943 957
944void DesktopApplication::restart() 958void DesktopApplication::restart()
945{ 959{
946 prepareForTermination( TRUE ); 960 prepareForTermination( TRUE );
947 961
948#ifdef Q_WS_QWS 962#ifdef Q_WS_QWS
949 963
950 for ( int fd = 3; fd < 100; fd++ ) 964 for ( int fd = 3; fd < 100; fd++ )
951 close( fd ); 965 close( fd );
952#if defined(QT_DEMO_SINGLE_FLOPPY) 966#if defined(QT_DEMO_SINGLE_FLOPPY)
953 967
954 execl( "/sbin/init", "qpe", 0 ); 968 execl( "/sbin/init", "qpe", 0 );
955#elif defined(QT_QWS_CASSIOPEIA) 969#elif defined(QT_QWS_CASSIOPEIA)
956 970
957 execl( "/bin/sh", "sh", 0 ); 971 execl( "/bin/sh", "sh", 0 );
958#else 972#else
959 973
960 execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); 974 execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 );
961#endif 975#endif
962 976
963 exit( 1 ); 977 exit( 1 );
964#endif 978#endif
965} 979}
966 980
967void Desktop::startTransferServer() 981void Desktop::startTransferServer()
968{ 982{
969 // start qcop bridge server 983 // start qcop bridge server
970 qcopBridge = new QCopBridge( 4243 ); 984 qcopBridge = new QCopBridge( 4243 );
971 if ( !qcopBridge->ok() ) { 985 if ( !qcopBridge->ok() ) {
972 delete qcopBridge; 986 delete qcopBridge;
973 qcopBridge = 0; 987 qcopBridge = 0;
974 } 988 }
975 // start transfer server 989 // start transfer server
976 transferServer = new TransferServer( 4242 ); 990 transferServer = new TransferServer( 4242 );
977 if ( !transferServer->ok() ) { 991 if ( !transferServer->ok() ) {
978 delete transferServer; 992 delete transferServer;
979 transferServer = 0; 993 transferServer = 0;
980 } 994 }
981 if ( !transferServer || !qcopBridge ) 995 if ( !transferServer || !qcopBridge )
982 startTimer( 2000 ); 996 startTimer( 2000 );
983} 997}
984 998
985void Desktop::timerEvent( QTimerEvent *e ) 999void Desktop::timerEvent( QTimerEvent *e )
986{ 1000{
987 killTimer( e->timerId() ); 1001 killTimer( e->timerId() );
988 startTransferServer(); 1002 startTransferServer();
989} 1003}
990 1004
991void Desktop::terminateServers() 1005void Desktop::terminateServers()
992{ 1006{
993 delete transferServer; 1007 delete transferServer;
994 delete qcopBridge; 1008 delete qcopBridge;
995 transferServer = 0; 1009 transferServer = 0;
996 qcopBridge = 0; 1010 qcopBridge = 0;
997} 1011}
998 1012
999void Desktop::rereadVolumes() 1013void Desktop::rereadVolumes()
1000{ 1014{
1001 Config cfg( "qpe" ); 1015 Config cfg( "qpe" );
1002 cfg.setGroup( "Volume" ); 1016 cfg.setGroup( "Volume" );
1003 touchclick = cfg.readBoolEntry( "TouchSound" ); 1017 touchclick = cfg.readBoolEntry( "TouchSound" );
1004 keyclick = cfg.readBoolEntry( "KeySound" ); 1018 keyclick = cfg.readBoolEntry( "KeySound" );
1005 alarmsound = cfg.readBoolEntry( "AlarmSound" ); 1019 alarmsound = cfg.readBoolEntry( "AlarmSound" );
1006} 1020}
1007 1021
1008void Desktop::keyClick() 1022void Desktop::keyClick()
1009{ 1023{
1010 if ( keyclick ) 1024 if ( keyclick )
1011 ODevice::inst ( ) -> keySound ( ); 1025 ODevice::inst ( ) -> keySound ( );
1012} 1026}
1013 1027
1014void Desktop::screenClick() 1028void Desktop::screenClick()
1015{ 1029{
1016 if ( touchclick ) 1030 if ( touchclick )
1017 ODevice::inst ( ) -> touchSound ( ); 1031 ODevice::inst ( ) -> touchSound ( );
1018} 1032}
1019 1033
1020void Desktop::soundAlarm() 1034void Desktop::soundAlarm()
1021{ 1035{
1022 if ( qpedesktop-> alarmsound ) 1036 if ( qpedesktop-> alarmsound )
1023 ODevice::inst ( ) -> alarmSound ( ); 1037 ODevice::inst ( ) -> alarmSound ( );
1024} 1038}
1025 1039