summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index da535d9..680cc06 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -1,727 +1,731 @@
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/qcopenvelope_qws.h> 38#include <qpe/qcopenvelope_qws.h>
39#include <qpe/global.h> 39#include <qpe/global.h>
40#ifdef QT_QWS_CUSTOM 40#ifdef QT_QWS_CUSTOM
41#include "qpe/custom.h" 41#include "qpe/custom.h"
42#endif 42#endif
43 43
44#include <qgfx_qws.h> 44#include <qgfx_qws.h>
45#include <qmainwindow.h> 45#include <qmainwindow.h>
46#include <qmessagebox.h> 46#include <qmessagebox.h>
47#include <qtimer.h> 47#include <qtimer.h>
48#include <qwindowsystem_qws.h> 48#include <qwindowsystem_qws.h>
49 49
50#include <qvaluelist.h> 50#include <qvaluelist.h>
51 51
52#include <stdlib.h> 52#include <stdlib.h>
53#include <unistd.h> 53#include <unistd.h>
54 54
55class QCopKeyRegister 55class QCopKeyRegister
56{ 56{
57public: 57public:
58 QCopKeyRegister() : keyCode(0) { } 58 QCopKeyRegister() : keyCode(0) { }
59 QCopKeyRegister(int k, const QString &c, const QString &m) 59 QCopKeyRegister(int k, const QString &c, const QString &m)
60 : keyCode(k), channel(c), message(m) { } 60 : keyCode(k), channel(c), message(m) { }
61 61
62 int getKeyCode() const { return keyCode; } 62 int getKeyCode() const { return keyCode; }
63 QString getChannel() const { return channel; } 63 QString getChannel() const { return channel; }
64 QString getMessage() const { return message; } 64 QString getMessage() const { return message; }
65 65
66private: 66private:
67 int keyCode; 67 int keyCode;
68 QString channel, message; 68 QString channel, message;
69}; 69};
70 70
71typedef QValueList<QCopKeyRegister> KeyRegisterList; 71typedef QValueList<QCopKeyRegister> KeyRegisterList;
72KeyRegisterList keyRegisterList; 72KeyRegisterList keyRegisterList;
73 73
74static Desktop* qpedesktop = 0; 74static Desktop* qpedesktop = 0;
75static int loggedin=0; 75static int loggedin=0;
76static void login(bool at_poweron) 76static void login(bool at_poweron)
77{ 77{
78 if ( !loggedin ) { 78 if ( !loggedin ) {
79 Global::terminateBuiltin("calibrate"); 79 Global::terminateBuiltin("calibrate");
80 Password::authenticate(at_poweron); 80 Password::authenticate(at_poweron);
81 loggedin=1; 81 loggedin=1;
82 QCopEnvelope e( "QPE/Desktop", "unlocked()" ); 82 QCopEnvelope e( "QPE/Desktop", "unlocked()" );
83 } 83 }
84} 84}
85 85
86bool Desktop::screenLocked() 86bool Desktop::screenLocked()
87{ 87{
88 return loggedin == 0; 88 return loggedin == 0;
89} 89}
90 90
91/* 91/*
92 Priority is number of alerts that are needed to pop up 92 Priority is number of alerts that are needed to pop up
93 alert. 93 alert.
94 */ 94 */
95class DesktopPowerAlerter : public QMessageBox 95class DesktopPowerAlerter : public QMessageBox
96{ 96{
97public: 97public:
98 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 98 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
99 : QMessageBox( tr("Battery Status"), "Low Battery", 99 : QMessageBox( tr("Battery Status"), "Low Battery",
100 QMessageBox::Critical, 100 QMessageBox::Critical,
101 QMessageBox::Ok | QMessageBox::Default, 101 QMessageBox::Ok | QMessageBox::Default,
102 QMessageBox::NoButton, QMessageBox::NoButton, 102 QMessageBox::NoButton, QMessageBox::NoButton,
103 parent, name, FALSE ) 103 parent, name, FALSE )
104 { 104 {
105 currentPriority = INT_MAX; 105 currentPriority = INT_MAX;
106 alertCount = 0; 106 alertCount = 0;
107 } 107 }
108 108
109 void alert( const QString &text, int priority ); 109 void alert( const QString &text, int priority );
110 void hideEvent( QHideEvent * ); 110 void hideEvent( QHideEvent * );
111private: 111private:
112 int currentPriority; 112 int currentPriority;
113 int alertCount; 113 int alertCount;
114}; 114};
115 115
116void DesktopPowerAlerter::alert( const QString &text, int priority ) 116void DesktopPowerAlerter::alert( const QString &text, int priority )
117{ 117{
118 alertCount++; 118 alertCount++;
119 if ( alertCount < priority ) 119 if ( alertCount < priority )
120 return; 120 return;
121 if ( priority > currentPriority ) 121 if ( priority > currentPriority )
122 return; 122 return;
123 currentPriority = priority; 123 currentPriority = priority;
124 setText( text ); 124 setText( text );
125 show(); 125 show();
126} 126}
127 127
128 128
129void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 129void DesktopPowerAlerter::hideEvent( QHideEvent *e )
130{ 130{
131 QMessageBox::hideEvent( e ); 131 QMessageBox::hideEvent( e );
132 alertCount = 0; 132 alertCount = 0;
133 currentPriority = INT_MAX; 133 currentPriority = INT_MAX;
134} 134}
135 135
136 136
137 137
138DesktopApplication::DesktopApplication( int& argc, char **argv, Type t ) 138DesktopApplication::DesktopApplication( int& argc, char **argv, Type t )
139 : QPEApplication( argc, argv, t ) 139 : QPEApplication( argc, argv, t )
140{ 140{
141 141
142 QTimer *t = new QTimer( this ); 142 QTimer *t = new QTimer( this );
143 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); 143 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) );
144 t->start( 10000 ); 144 t->start( 10000 );
145 ps = new PowerStatus; 145 ps = new PowerStatus;
146 pa = new DesktopPowerAlerter( 0 ); 146 pa = new DesktopPowerAlerter( 0 );
147 147
148 channel = new QCopChannel( "QPE/Desktop", this ); 148 channel = new QCopChannel( "QPE/Desktop", this );
149 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 149 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
150 this, SLOT(receive(const QCString&, const QByteArray&)) ); 150 this, SLOT(receive(const QCString&, const QByteArray&)) );
151} 151}
152 152
153 153
154DesktopApplication::~DesktopApplication() 154DesktopApplication::~DesktopApplication()
155{ 155{
156 delete ps; 156 delete ps;
157 delete pa; 157 delete pa;
158} 158}
159 159
160void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) 160void DesktopApplication::receive( const QCString &msg, const QByteArray &data )
161{ 161{
162 QDataStream stream( data, IO_ReadOnly ); 162 QDataStream stream( data, IO_ReadOnly );
163 if (msg == "keyRegister(int key, QString channel, QString message)") 163 if (msg == "keyRegister(int key, QString channel, QString message)")
164 { 164 {
165 int k; 165 int k;
166 QString c, m; 166 QString c, m;
167 167
168 stream >> k; 168 stream >> k;
169 stream >> c; 169 stream >> c;
170 stream >> m; 170 stream >> m;
171 171
172 qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m); 172 qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m);
173 keyRegisterList.append(QCopKeyRegister(k,c,m)); 173 keyRegisterList.append(QCopKeyRegister(k,c,m));
174 } 174 }
175 else if (msg == "suspend()"){ 175 else if (msg == "suspend()"){
176 emit power(); 176 emit power();
177 } 177 }
178 178
179} 179}
180 180
181enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; 181enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
182 182
183#ifdef Q_WS_QWS 183#ifdef Q_WS_QWS
184bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 184bool DesktopApplication::qwsEventFilter( QWSEvent *e )
185{ 185{
186 qpedesktop->checkMemory(); 186 qpedesktop->checkMemory();
187 187
188 if ( e->type == QWSEvent::Key ) { 188 if ( e->type == QWSEvent::Key ) {
189 QWSKeyEvent *ke = (QWSKeyEvent *)e; 189 QWSKeyEvent *ke = (QWSKeyEvent *)e;
190 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 190 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
191 return TRUE; 191 return TRUE;
192 bool press = ke->simpleData.is_press; 192 bool press = ke->simpleData.is_press;
193 193
194 if (!keyRegisterList.isEmpty()) 194 if (!keyRegisterList.isEmpty())
195 { 195 {
196 KeyRegisterList::Iterator it; 196 KeyRegisterList::Iterator it;
197 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) 197 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it )
198 { 198 {
199 if ((*it).getKeyCode() == ke->simpleData.keycode) 199 if ((*it).getKeyCode() == ke->simpleData.keycode)
200 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); 200 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
201 } 201 }
202 } 202 }
203 203
204 if ( !keyboardGrabbed() ) { 204 if ( !keyboardGrabbed() ) {
205 if ( ke->simpleData.keycode == Key_F9 ) { 205 if ( ke->simpleData.keycode == Key_F9 ) {
206 if ( press ) emit datebook(); 206 if ( press ) emit datebook();
207 return TRUE; 207 return TRUE;
208 } 208 }
209 if ( ke->simpleData.keycode == Key_F10 ) { 209 if ( ke->simpleData.keycode == Key_F10 ) {
210 if ( !press && cardSendTimer ) { 210 if ( !press && cardSendTimer ) {
211 emit contacts(); 211 emit contacts();
212 delete cardSendTimer; 212 delete cardSendTimer;
213 } else if ( press ) { 213 } else if ( press ) {
214 cardSendTimer = new QTimer(); 214 cardSendTimer = new QTimer();
215 cardSendTimer->start( 2000, TRUE ); 215 cardSendTimer->start( 2000, TRUE );
216 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 216 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
217 } 217 }
218 return TRUE; 218 return TRUE;
219 } 219 }
220 /* menu key now opens application menu/toolbar 220 /* menu key now opens application menu/toolbar
221 if ( ke->simpleData.keycode == Key_F11 ) { 221 if ( ke->simpleData.keycode == Key_F11 ) {
222 if ( press ) emit menu(); 222 if ( press ) emit menu();
223 return TRUE; 223 return TRUE;
224 } 224 }
225 */ 225 */
226 if ( ke->simpleData.keycode == Key_F12 ) { 226 if ( ke->simpleData.keycode == Key_F12 ) {
227 while( activePopupWidget() ) 227 while( activePopupWidget() )
228 activePopupWidget()->close(); 228 activePopupWidget()->close();
229 if ( press ) emit launch(); 229 if ( press ) emit launch();
230 return TRUE; 230 return TRUE;
231 } 231 }
232 if ( ke->simpleData.keycode == Key_F13 ) { 232 if ( ke->simpleData.keycode == Key_F13 ) {
233 if ( press ) emit email(); 233 if ( press ) emit email();
234 return TRUE; 234 return TRUE;
235 } 235 }
236 } 236 }
237 237
238 if ( ke->simpleData.keycode == Key_F34 ) { 238 if ( ke->simpleData.keycode == Key_F34 ) {
239 if ( press ) emit power(); 239 if ( press ) emit power();
240 return TRUE; 240 return TRUE;
241 } 241 }
242 if ( ke->simpleData.keycode == Key_SysReq ) {
243 if ( press ) emit power();
244 return TRUE;
245 }
242 if ( ke->simpleData.keycode == Key_F35 ) { 246 if ( ke->simpleData.keycode == Key_F35 ) {
243 if ( press ) emit backlight(); 247 if ( press ) emit backlight();
244 return TRUE; 248 return TRUE;
245 } 249 }
246 if ( ke->simpleData.keycode == Key_F32 ) { 250 if ( ke->simpleData.keycode == Key_F32 ) {
247 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 251 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
248 return TRUE; 252 return TRUE;
249 } 253 }
250 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 254 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
251 if ( press ) emit symbol(); 255 if ( press ) emit symbol();
252 return TRUE; 256 return TRUE;
253 } 257 }
254 if ( ke->simpleData.keycode == Key_NumLock ) { 258 if ( ke->simpleData.keycode == Key_NumLock ) {
255 if ( press ) emit numLockStateToggle(); 259 if ( press ) emit numLockStateToggle();
256 } 260 }
257 if ( ke->simpleData.keycode == Key_CapsLock ) { 261 if ( ke->simpleData.keycode == Key_CapsLock ) {
258 if ( press ) emit capsLockStateToggle(); 262 if ( press ) emit capsLockStateToggle();
259 } 263 }
260 if ( press ) 264 if ( press )
261 qpedesktop->keyClick(); 265 qpedesktop->keyClick();
262 } else { 266 } else {
263 if ( e->type == QWSEvent::Mouse ) { 267 if ( e->type == QWSEvent::Mouse ) {
264 QWSMouseEvent *me = (QWSMouseEvent *)e; 268 QWSMouseEvent *me = (QWSMouseEvent *)e;
265 static bool up = TRUE; 269 static bool up = TRUE;
266 if ( me->simpleData.state&LeftButton ) { 270 if ( me->simpleData.state&LeftButton ) {
267 if ( up ) { 271 if ( up ) {
268 up = FALSE; 272 up = FALSE;
269 qpedesktop->screenClick(); 273 qpedesktop->screenClick();
270 } 274 }
271 } else { 275 } else {
272 up = TRUE; 276 up = TRUE;
273 } 277 }
274 } 278 }
275 } 279 }
276 280
277 return QPEApplication::qwsEventFilter( e ); 281 return QPEApplication::qwsEventFilter( e );
278} 282}
279#endif 283#endif
280 284
281void DesktopApplication::psTimeout() 285void DesktopApplication::psTimeout()
282{ 286{
283 qpedesktop->checkMemory(); // in case no events are being generated 287 qpedesktop->checkMemory(); // in case no events are being generated
284 288
285 *ps = PowerStatusManager::readStatus(); 289 *ps = PowerStatusManager::readStatus();
286 290
287 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) { 291 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) {
288 pa->alert( tr( "Battery is running very low." ), 6 ); 292 pa->alert( tr( "Battery is running very low." ), 6 );
289 } 293 }
290 294
291 if ( ps->batteryStatus() == PowerStatus::Critical ) { 295 if ( ps->batteryStatus() == PowerStatus::Critical ) {
292 pa->alert( tr( "Battery level is critical!\n" 296 pa->alert( tr( "Battery level is critical!\n"
293 "Keep power off until power restored!" ), 1 ); 297 "Keep power off until power restored!" ), 1 );
294 } 298 }
295 299
296 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 300 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
297 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 301 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
298 } 302 }
299} 303}
300 304
301 305
302void DesktopApplication::sendCard() 306void DesktopApplication::sendCard()
303{ 307{
304 delete cardSendTimer; 308 delete cardSendTimer;
305 cardSendTimer = 0; 309 cardSendTimer = 0;
306 QString card = getenv("HOME"); 310 QString card = getenv("HOME");
307 card += "/Applications/addressbook/businesscard.vcf"; 311 card += "/Applications/addressbook/businesscard.vcf";
308 312
309 if ( QFile::exists( card ) ) { 313 if ( QFile::exists( card ) ) {
310 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 314 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
311 QString mimetype = "text/x-vCard"; 315 QString mimetype = "text/x-vCard";
312 e << tr("business card") << card << mimetype; 316 e << tr("business card") << card << mimetype;
313 } 317 }
314} 318}
315 319
316#if defined(QPE_HAVE_MEMALERTER) 320#if defined(QPE_HAVE_MEMALERTER)
317QPE_MEMALERTER_IMPL 321QPE_MEMALERTER_IMPL
318#endif 322#endif
319 323
320#if defined(CUSTOM_SOUND_IMPL) 324#if defined(CUSTOM_SOUND_IMPL)
321CUSTOM_SOUND_IMPL 325CUSTOM_SOUND_IMPL
322#endif 326#endif
323 327
324//=========================================================================== 328//===========================================================================
325 329
326Desktop::Desktop() : 330Desktop::Desktop() :
327 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 331 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
328 qcopBridge( 0 ), 332 qcopBridge( 0 ),
329 transferServer( 0 ), 333 transferServer( 0 ),
330 packageSlave( 0 ) 334 packageSlave( 0 )
331{ 335{
332#ifdef CUSTOM_SOUND_INIT 336#ifdef CUSTOM_SOUND_INIT
333 CUSTOM_SOUND_INIT; 337 CUSTOM_SOUND_INIT;
334#endif 338#endif
335 339
336 qpedesktop = this; 340 qpedesktop = this;
337 341
338// bg = new Info( this ); 342// bg = new Info( this );
339 tb = new TaskBar; 343 tb = new TaskBar;
340 344
341 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 345 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
342 346
343 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait())); 347 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait()));
344 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&))); 348 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&)));
345 349
346 int displayw = qApp->desktop()->width(); 350 int displayw = qApp->desktop()->width();
347 int displayh = qApp->desktop()->height(); 351 int displayh = qApp->desktop()->height();
348 352
349 353
350 QSize sz = tb->sizeHint(); 354 QSize sz = tb->sizeHint();
351 355
352 setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 356 setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
353 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 357 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
354 358
355 tb->show(); 359 tb->show();
356 launcher->showMaximized(); 360 launcher->showMaximized();
357 launcher->show(); 361 launcher->show();
358 launcher->raise(); 362 launcher->raise();
359#if defined(QPE_HAVE_MEMALERTER) 363#if defined(QPE_HAVE_MEMALERTER)
360 initMemalerter(); 364 initMemalerter();
361#endif 365#endif
362 // start services 366 // start services
363 startTransferServer(); 367 startTransferServer();
364 (void) new IrServer( this ); 368 (void) new IrServer( this );
365 rereadVolumes(); 369 rereadVolumes();
366 370
367 packageSlave = new PackageSlave( this ); 371 packageSlave = new PackageSlave( this );
368 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes())); 372 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes()));
369 373
370 qApp->installEventFilter( this ); 374 qApp->installEventFilter( this );
371} 375}
372 376
373void Desktop::show() 377void Desktop::show()
374{ 378{
375 login(TRUE); 379 login(TRUE);
376 QWidget::show(); 380 QWidget::show();
377} 381}
378 382
379Desktop::~Desktop() 383Desktop::~Desktop()
380{ 384{
381 delete launcher; 385 delete launcher;
382 delete tb; 386 delete tb;
383 delete qcopBridge; 387 delete qcopBridge;
384 delete transferServer; 388 delete transferServer;
385} 389}
386 390
387bool Desktop::recoverMemory() 391bool Desktop::recoverMemory()
388{ 392{
389 return tb->recoverMemory(); 393 return tb->recoverMemory();
390} 394}
391 395
392void Desktop::checkMemory() 396void Desktop::checkMemory()
393{ 397{
394#if defined(QPE_HAVE_MEMALERTER) 398#if defined(QPE_HAVE_MEMALERTER)
395 static bool ignoreNormal=FALSE; 399 static bool ignoreNormal=FALSE;
396 static bool existingMessage=FALSE; 400 static bool existingMessage=FALSE;
397 401
398 if(existingMessage) 402 if(existingMessage)
399 return; // don't show a second message while still on first 403 return; // don't show a second message while still on first
400 404
401 existingMessage = TRUE; 405 existingMessage = TRUE;
402 switch ( memstate ) { 406 switch ( memstate ) {
403 case Unknown: 407 case Unknown:
404 break; 408 break;
405 case Low: 409 case Low:
406 memstate = Unknown; 410 memstate = Unknown;
407 if ( recoverMemory() ) 411 if ( recoverMemory() )
408 ignoreNormal = TRUE; 412 ignoreNormal = TRUE;
409 else 413 else
410 QMessageBox::warning( 0 , "Memory Status", 414 QMessageBox::warning( 0 , "Memory Status",
411 "The memory smacks of shortage. \n" 415 "The memory smacks of shortage. \n"
412 "Please save data. " ); 416 "Please save data. " );
413 break; 417 break;
414 case Normal: 418 case Normal:
415 memstate = Unknown; 419 memstate = Unknown;
416 if ( ignoreNormal ) 420 if ( ignoreNormal )
417 ignoreNormal = FALSE; 421 ignoreNormal = FALSE;
418 else 422 else
419 QMessageBox::information ( 0 , "Memory Status", 423 QMessageBox::information ( 0 , "Memory Status",
420 "There is enough memory again." ); 424 "There is enough memory again." );
421 break; 425 break;
422 case VeryLow: 426 case VeryLow:
423 memstate = Unknown; 427 memstate = Unknown;
424 QMessageBox::critical( 0 , "Memory Status", 428 QMessageBox::critical( 0 , "Memory Status",
425 "The memory is very low. \n" 429 "The memory is very low. \n"
426 "Please end this application \n" 430 "Please end this application \n"
427 "immediately." ); 431 "immediately." );
428 recoverMemory(); 432 recoverMemory();
429 } 433 }
430 existingMessage = FALSE; 434 existingMessage = FALSE;
431#endif 435#endif
432} 436}
433 437
434static bool isVisibleWindow(int wid) 438static bool isVisibleWindow(int wid)
435{ 439{
436 const QList<QWSWindow> &list = qwsServer->clientWindows(); 440 const QList<QWSWindow> &list = qwsServer->clientWindows();
437 QWSWindow* w; 441 QWSWindow* w;
438 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 442 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
439 if ( w->winId() == wid ) 443 if ( w->winId() == wid )
440 return !w->isFullyObscured(); 444 return !w->isFullyObscured();
441 } 445 }
442 return FALSE; 446 return FALSE;
443} 447}
444 448
445static bool hasVisibleWindow(const QString& clientname) 449static bool hasVisibleWindow(const QString& clientname)
446{ 450{
447 const QList<QWSWindow> &list = qwsServer->clientWindows(); 451 const QList<QWSWindow> &list = qwsServer->clientWindows();
448 QWSWindow* w; 452 QWSWindow* w;
449 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 453 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
450 if ( w->client()->identity() == clientname && !w->isFullyObscured() ) 454 if ( w->client()->identity() == clientname && !w->isFullyObscured() )
451 return TRUE; 455 return TRUE;
452 } 456 }
453 return FALSE; 457 return FALSE;
454} 458}
455 459
456void Desktop::raiseLauncher() 460void Desktop::raiseLauncher()
457{ 461{
458 if ( isVisibleWindow(launcher->winId()) ) 462 if ( isVisibleWindow(launcher->winId()) )
459 launcher->nextView(); 463 launcher->nextView();
460 else 464 else
461 launcher->raise(); 465 launcher->raise();
462} 466}
463 467
464void Desktop::executeOrModify(const QString& appLnkFile) 468void Desktop::executeOrModify(const QString& appLnkFile)
465{ 469{
466 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile); 470 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile);
467 if ( lnk.isValid() ) { 471 if ( lnk.isValid() ) {
468 QCString app = lnk.exec().utf8(); 472 QCString app = lnk.exec().utf8();
469 Global::terminateBuiltin("calibrate"); 473 Global::terminateBuiltin("calibrate");
470 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) { 474 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) {
471 MRUList::addTask(&lnk); 475 MRUList::addTask(&lnk);
472 if ( hasVisibleWindow(app) ) 476 if ( hasVisibleWindow(app) )
473 QCopChannel::send("QPE/Application/" + app, "nextView()"); 477 QCopChannel::send("QPE/Application/" + app, "nextView()");
474 else 478 else
475 QCopChannel::send("QPE/Application/" + app, "raise()"); 479 QCopChannel::send("QPE/Application/" + app, "raise()");
476 } else { 480 } else {
477 lnk.execute(); 481 lnk.execute();
478 } 482 }
479 } 483 }
480} 484}
481 485
482void Desktop::raiseDatebook() 486void Desktop::raiseDatebook()
483{ 487{
484 executeOrModify("Applications/datebook.desktop"); 488 executeOrModify("Applications/datebook.desktop");
485} 489}
486 490
487void Desktop::raiseContacts() 491void Desktop::raiseContacts()
488{ 492{
489 executeOrModify("Applications/addressbook.desktop"); 493 executeOrModify("Applications/addressbook.desktop");
490} 494}
491 495
492void Desktop::raiseMenu() 496void Desktop::raiseMenu()
493{ 497{
494 Global::terminateBuiltin("calibrate"); 498 Global::terminateBuiltin("calibrate");
495 tb->startMenu()->launch(); 499 tb->startMenu()->launch();
496} 500}
497 501
498void Desktop::raiseEmail() 502void Desktop::raiseEmail()
499{ 503{
500 executeOrModify("Applications/qtmail.desktop"); 504 executeOrModify("Applications/qtmail.desktop");
501} 505}
502 506
503// autoStarts apps on resume and start 507// autoStarts apps on resume and start
504void Desktop::execAutoStart() 508void Desktop::execAutoStart()
505{ 509{
506 QString appName; 510 QString appName;
507 Config cfg( "autostart" ); 511 Config cfg( "autostart" );
508 cfg.setGroup( "AutoStart" ); 512 cfg.setGroup( "AutoStart" );
509 appName = cfg.readEntry("Apps", ""); 513 appName = cfg.readEntry("Apps", "");
510 QCopEnvelope e("QPE/System", "execute(QString)"); 514 QCopEnvelope e("QPE/System", "execute(QString)");
511 e << QString(appName); 515 e << QString(appName);
512} 516}
513 517
514#if defined(QPE_HAVE_TOGGLELIGHT) 518#if defined(QPE_HAVE_TOGGLELIGHT)
515#include <qpe/config.h> 519#include <qpe/config.h>
516 520
517#include <sys/ioctl.h> 521#include <sys/ioctl.h>
518#include <sys/types.h> 522#include <sys/types.h>
519#include <fcntl.h> 523#include <fcntl.h>
520#include <unistd.h> 524#include <unistd.h>
521#include <errno.h> 525#include <errno.h>
522#include <linux/ioctl.h> 526#include <linux/ioctl.h>
523#include <time.h> 527#include <time.h>
524#endif 528#endif
525 529
526static bool blanked=FALSE; 530static bool blanked=FALSE;
527 531
528static void blankScreen() 532static void blankScreen()
529{ 533{
530 if ( !qt_screen ) return; 534 if ( !qt_screen ) return;
531 /* Should use a big black window instead. 535 /* Should use a big black window instead.
532 QGfx* g = qt_screen->screenGfx(); 536 QGfx* g = qt_screen->screenGfx();
533 g->fillRect(0,0,qt_screen->width(),qt_screen->height()); 537 g->fillRect(0,0,qt_screen->width(),qt_screen->height());
534 delete g; 538 delete g;
535 */ 539 */
536 blanked = TRUE; 540 blanked = TRUE;
537} 541}
538 542
539static void darkScreen() 543static void darkScreen()
540{ 544{
541 extern void qpe_setBacklight(int); 545 extern void qpe_setBacklight(int);
542 qpe_setBacklight(0); // force off 546 qpe_setBacklight(0); // force off
543} 547}
544 548
545 549
546void Desktop::togglePower() 550void Desktop::togglePower()
547{ 551{
548 bool wasloggedin = loggedin; 552 bool wasloggedin = loggedin;
549 loggedin=0; 553 loggedin=0;
550 darkScreen(); 554 darkScreen();
551 if ( wasloggedin ) 555 if ( wasloggedin )
552 blankScreen(); 556 blankScreen();
553 557
554 system("apm --suspend"); 558 system("apm --suspend");
555 execAutoStart(); 559
556 QWSServer::screenSaverActivate( FALSE ); 560 QWSServer::screenSaverActivate( FALSE );
557 { 561 {
558 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep 562 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep
559 QCopEnvelope e("QPE/System", "setBacklight(int)"); 563 QCopEnvelope e("QPE/System", "setBacklight(int)");
560 e << -3; // Force on 564 e << -3; // Force on
561 } 565 }
562 if ( wasloggedin ) { 566 if ( wasloggedin ) {
563 login(TRUE); 567 login(TRUE);
564 } 568 }
565 569 execAutoStart();
566 //qcopBridge->closeOpenConnections(); 570 //qcopBridge->closeOpenConnections();
567 //qDebug("called togglePower()!!!!!!"); 571 //qDebug("called togglePower()!!!!!!");
568} 572}
569 573
570void Desktop::toggleLight() 574void Desktop::toggleLight()
571{ 575{
572 QCopEnvelope e("QPE/System", "setBacklight(int)"); 576 QCopEnvelope e("QPE/System", "setBacklight(int)");
573 e << -2; // toggle 577 e << -2; // toggle
574} 578}
575 579
576void Desktop::toggleSymbolInput() 580void Desktop::toggleSymbolInput()
577{ 581{
578 tb->toggleSymbolInput(); 582 tb->toggleSymbolInput();
579} 583}
580 584
581void Desktop::toggleNumLockState() 585void Desktop::toggleNumLockState()
582{ 586{
583 tb->toggleNumLockState(); 587 tb->toggleNumLockState();
584} 588}
585 589
586void Desktop::toggleCapsLockState() 590void Desktop::toggleCapsLockState()
587{ 591{
588 tb->toggleCapsLockState(); 592 tb->toggleCapsLockState();
589} 593}
590 594
591void Desktop::styleChange( QStyle &s ) 595void Desktop::styleChange( QStyle &s )
592{ 596{
593 QWidget::styleChange( s ); 597 QWidget::styleChange( s );
594 int displayw = qApp->desktop()->width(); 598 int displayw = qApp->desktop()->width();
595 int displayh = qApp->desktop()->height(); 599 int displayh = qApp->desktop()->height();
596 600
597 QSize sz = tb->sizeHint(); 601 QSize sz = tb->sizeHint();
598 602
599 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 603 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
600} 604}
601 605
602void DesktopApplication::shutdown() 606void DesktopApplication::shutdown()
603{ 607{
604 if ( type() != GuiServer ) 608 if ( type() != GuiServer )
605 return; 609 return;
606 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 610 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
607 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 611 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
608 this, SLOT(shutdown(ShutdownImpl::Type)) ); 612 this, SLOT(shutdown(ShutdownImpl::Type)) );
609 sd->showMaximized(); 613 sd->showMaximized();
610} 614}
611 615
612void DesktopApplication::shutdown( ShutdownImpl::Type t ) 616void DesktopApplication::shutdown( ShutdownImpl::Type t )
613{ 617{
614 switch ( t ) { 618 switch ( t ) {
615 case ShutdownImpl::ShutdownSystem: 619 case ShutdownImpl::ShutdownSystem:
616 execlp("shutdown", "shutdown", "-h", "now", (void*)0); 620 execlp("shutdown", "shutdown", "-h", "now", (void*)0);
617 break; 621 break;
618 case ShutdownImpl::RebootSystem: 622 case ShutdownImpl::RebootSystem:
619 execlp("shutdown", "shutdown", "-r", "now", (void*)0); 623 execlp("shutdown", "shutdown", "-r", "now", (void*)0);
620 break; 624 break;
621 case ShutdownImpl::RestartDesktop: 625 case ShutdownImpl::RestartDesktop:
622 restart(); 626 restart();
623 break; 627 break;
624 case ShutdownImpl::TerminateDesktop: 628 case ShutdownImpl::TerminateDesktop:
625 prepareForTermination(FALSE); 629 prepareForTermination(FALSE);
626 quit(); 630 quit();
627 break; 631 break;
628 } 632 }
629} 633}
630 634
631void DesktopApplication::restart() 635void DesktopApplication::restart()
632{ 636{
633 prepareForTermination(TRUE); 637 prepareForTermination(TRUE);
634 638
635#ifdef Q_WS_QWS 639#ifdef Q_WS_QWS
636 for ( int fd = 3; fd < 100; fd++ ) 640 for ( int fd = 3; fd < 100; fd++ )
637 close( fd ); 641 close( fd );
638#if defined(QT_DEMO_SINGLE_FLOPPY) 642#if defined(QT_DEMO_SINGLE_FLOPPY)
639 execl( "/sbin/init", "qpe", 0 ); 643 execl( "/sbin/init", "qpe", 0 );
640#elif defined(QT_QWS_CASSIOPEIA) 644#elif defined(QT_QWS_CASSIOPEIA)
641 execl( "/bin/sh", "sh", 0 ); 645 execl( "/bin/sh", "sh", 0 );
642#else 646#else
643 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 ); 647 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 );
644#endif 648#endif
645 exit(1); 649 exit(1);
646#endif 650#endif
647} 651}
648 652
649void Desktop::startTransferServer() 653void Desktop::startTransferServer()
650{ 654{
651 // start qcop bridge server 655 // start qcop bridge server
652 qcopBridge = new QCopBridge( 4243 ); 656 qcopBridge = new QCopBridge( 4243 );
653 if ( !qcopBridge->ok() ) { 657 if ( !qcopBridge->ok() ) {
654 delete qcopBridge; 658 delete qcopBridge;
655 qcopBridge = 0; 659 qcopBridge = 0;
656 } 660 }
657 // start transfer server 661 // start transfer server
658 transferServer = new TransferServer( 4242 ); 662 transferServer = new TransferServer( 4242 );
659 if ( !transferServer->ok() ) { 663 if ( !transferServer->ok() ) {
660 delete transferServer; 664 delete transferServer;
661 transferServer = 0; 665 transferServer = 0;
662 } 666 }
663 if ( !transferServer || !qcopBridge ) 667 if ( !transferServer || !qcopBridge )
664 startTimer( 2000 ); 668 startTimer( 2000 );
665} 669}
666 670
667void Desktop::timerEvent( QTimerEvent *e ) 671void Desktop::timerEvent( QTimerEvent *e )
668{ 672{
669 killTimer( e->timerId() ); 673 killTimer( e->timerId() );
670 startTransferServer(); 674 startTransferServer();
671} 675}
672 676
673void Desktop::terminateServers() 677void Desktop::terminateServers()
674{ 678{
675 delete transferServer; 679 delete transferServer;
676 delete qcopBridge; 680 delete qcopBridge;
677 transferServer = 0; 681 transferServer = 0;
678 qcopBridge = 0; 682 qcopBridge = 0;
679} 683}
680 684
681void Desktop::rereadVolumes() 685void Desktop::rereadVolumes()
682{ 686{
683 Config cfg("Sound"); 687 Config cfg("Sound");
684 cfg.setGroup("System"); 688 cfg.setGroup("System");
685 touchclick = cfg.readBoolEntry("Touch"); 689 touchclick = cfg.readBoolEntry("Touch");
686 keyclick = cfg.readBoolEntry("Key"); 690 keyclick = cfg.readBoolEntry("Key");
687} 691}
688 692
689void Desktop::keyClick() 693void Desktop::keyClick()
690{ 694{
691#ifdef CUSTOM_SOUND_KEYCLICK 695#ifdef CUSTOM_SOUND_KEYCLICK
692 if ( keyclick ) 696 if ( keyclick )
693 CUSTOM_SOUND_KEYCLICK; 697 CUSTOM_SOUND_KEYCLICK;
694#endif 698#endif
695} 699}
696 700
697void Desktop::screenClick() 701void Desktop::screenClick()
698{ 702{
699#ifdef CUSTOM_SOUND_TOUCH 703#ifdef CUSTOM_SOUND_TOUCH
700 if ( touchclick ) 704 if ( touchclick )
701 CUSTOM_SOUND_TOUCH; 705 CUSTOM_SOUND_TOUCH;
702#endif 706#endif
703} 707}
704 708
705void Desktop::soundAlarm() 709void Desktop::soundAlarm()
706{ 710{
707#ifdef CUSTOM_SOUND_ALARM 711#ifdef CUSTOM_SOUND_ALARM
708 CUSTOM_SOUND_ALARM; 712 CUSTOM_SOUND_ALARM;
709#endif 713#endif
710} 714}
711 715
712bool Desktop::eventFilter( QObject *w, QEvent *ev ) 716bool Desktop::eventFilter( QObject *w, QEvent *ev )
713{ 717{
714 if ( ev->type() == QEvent::KeyPress ) { 718 if ( ev->type() == QEvent::KeyPress ) {
715 QKeyEvent *ke = (QKeyEvent *)ev; 719 QKeyEvent *ke = (QKeyEvent *)ev;
716 if ( ke->key() == Qt::Key_F11 ) { // menu key 720 if ( ke->key() == Qt::Key_F11 ) { // menu key
717 QWidget *active = qApp->activeWindow(); 721 QWidget *active = qApp->activeWindow();
718 if ( active && active->isPopup() ) { 722 if ( active && active->isPopup() ) {
719 active->close(); 723 active->close();
720 } 724 }
721 raiseMenu(); 725 raiseMenu();
722 return TRUE; 726 return TRUE;
723 } 727 }
724 } 728 }
725 return FALSE; 729 return FALSE;
726} 730}
727 731