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