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