summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-19 16:35:56 (UTC)
committer llornkcor <llornkcor>2002-05-19 16:35:56 (UTC)
commit602ff2a6f588584bf47afa6faae08ce60b49047f (patch) (unidiff)
treec319da92b22a1a81be1e52f5bf2fe855d646cae3
parent7b05e648c1f7c29dee80d5731aacaab1a1b01b05 (diff)
downloadopie-602ff2a6f588584bf47afa6faae08ce60b49047f.zip
opie-602ff2a6f588584bf47afa6faae08ce60b49047f.tar.gz
opie-602ff2a6f588584bf47afa6faae08ce60b49047f.tar.bz2
don't send keyRegister QCop message if autoRepeated, and fixed spelling error
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index d5c16b3..85ba160 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -1,712 +1,712 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#include "desktop.h"
22#include "info.h" 22#include "info.h"
23#include "launcher.h" 23#include "launcher.h"
24#include "mrulist.h" 24#include "mrulist.h"
25#include "qcopbridge.h" 25#include "qcopbridge.h"
26#include "shutdownimpl.h" 26#include "shutdownimpl.h"
27#include "startmenu.h" 27#include "startmenu.h"
28#include "taskbar.h" 28#include "taskbar.h"
29#include "transferserver.h" 29#include "transferserver.h"
30#include "irserver.h" 30#include "irserver.h"
31#include "packageslave.h" 31#include "packageslave.h"
32 32
33#include <qpe/applnk.h> 33#include <qpe/applnk.h>
34#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
35#include <qpe/password.h> 35#include <qpe/password.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/power.h> 37#include <qpe/power.h>
38#include <qpe/timeconversion.h> 38#include <qpe/timeconversion.h>
39#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
40#include <qpe/global.h> 40#include <qpe/global.h>
41#ifdef QT_QWS_CUSTOM 41#ifdef QT_QWS_CUSTOM
42#include "qpe/custom.h" 42#include "qpe/custom.h"
43#endif 43#endif
44 44
45#include <qgfx_qws.h> 45#include <qgfx_qws.h>
46#include <qmainwindow.h> 46#include <qmainwindow.h>
47#include <qmessagebox.h> 47#include <qmessagebox.h>
48#include <qtimer.h> 48#include <qtimer.h>
49#include <qwindowsystem_qws.h> 49#include <qwindowsystem_qws.h>
50 50
51#include <qvaluelist.h> 51#include <qvaluelist.h>
52 52
53#include <stdlib.h> 53#include <stdlib.h>
54#include <unistd.h> 54#include <unistd.h>
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 appType ) 139DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
140 : QPEApplication( argc, argv, appType ) 140 : QPEApplication( argc, argv, appType )
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 else if (msg == "suspend()"){ 176 else if (msg == "suspend()"){
177 emit power(); 177 emit power();
178 } 178 }
179 179
180} 180}
181 181
182enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; 182enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
183 183
184#ifdef Q_WS_QWS 184#ifdef Q_WS_QWS
185bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 185bool DesktopApplication::qwsEventFilter( QWSEvent *e )
186{ 186{
187 qpedesktop->checkMemory(); 187 qpedesktop->checkMemory();
188 188
189 if ( e->type == QWSEvent::Key ) { 189 if ( e->type == QWSEvent::Key ) {
190 QWSKeyEvent *ke = (QWSKeyEvent *)e; 190 QWSKeyEvent *ke = (QWSKeyEvent *)e;
191 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 191 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
192 return TRUE; 192 return TRUE;
193 bool press = ke->simpleData.is_press; 193 bool press = ke->simpleData.is_press;
194 194 bool autoRepeat = ke ->simpleData.is_auto_repeat;
195 if (!keyRegisterList.isEmpty()) 195 if (!keyRegisterList.isEmpty())
196 { 196 {
197 KeyRegisterList::Iterator it; 197 KeyRegisterList::Iterator it;
198 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) 198 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it )
199 { 199 {
200 if ((*it).getKeyCode() == ke->simpleData.keycode) 200 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat)
201 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); 201 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
202 } 202 }
203 } 203 }
204 204
205 if ( !keyboardGrabbed() ) { 205 if ( !keyboardGrabbed() ) {
206 if ( ke->simpleData.keycode == Key_F9 ) { 206 if ( ke->simpleData.keycode == Key_F9 ) {
207 if ( press ) emit datebook(); 207 if ( press ) emit datebook();
208 return TRUE; 208 return TRUE;
209 } 209 }
210 if ( ke->simpleData.keycode == Key_F10 ) { 210 if ( ke->simpleData.keycode == Key_F10 ) {
211 if ( !press && cardSendTimer ) { 211 if ( !press && cardSendTimer ) {
212 emit contacts(); 212 emit contacts();
213 delete cardSendTimer; 213 delete cardSendTimer;
214 } else if ( press ) { 214 } else if ( press ) {
215 cardSendTimer = new QTimer(); 215 cardSendTimer = new QTimer();
216 cardSendTimer->start( 2000, TRUE ); 216 cardSendTimer->start( 2000, TRUE );
217 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 217 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
218 } 218 }
219 return TRUE; 219 return TRUE;
220 } 220 }
221 /* menu key now opens application menu/toolbar 221 /* menu key now opens application menu/toolbar
222 if ( ke->simpleData.keycode == Key_F11 ) { 222 if ( ke->simpleData.keycode == Key_F11 ) {
223 if ( press ) emit menu(); 223 if ( press ) emit menu();
224 return TRUE; 224 return TRUE;
225 } 225 }
226 */ 226 */
227 if ( ke->simpleData.keycode == Key_F12 ) { 227 if ( ke->simpleData.keycode == Key_F12 ) {
228 while( activePopupWidget() ) 228 while( activePopupWidget() )
229 activePopupWidget()->close(); 229 activePopupWidget()->close();
230 if ( press ) emit launch(); 230 if ( press ) emit launch();
231 return TRUE; 231 return TRUE;
232 } 232 }
233 if ( ke->simpleData.keycode == Key_F13 ) { 233 if ( ke->simpleData.keycode == Key_F13 ) {
234 if ( press ) emit email(); 234 if ( press ) emit email();
235 return TRUE; 235 return TRUE;
236 } 236 }
237 } 237 }
238 238
239 if ( ke->simpleData.keycode == Key_F34 ) { 239 if ( ke->simpleData.keycode == Key_F34 ) {
240 if ( press ) emit power(); 240 if ( press ) emit power();
241 return TRUE; 241 return TRUE;
242 } 242 }
243 if ( ke->simpleData.keycode == Key_SysReq ) { 243 if ( ke->simpleData.keycode == Key_SysReq ) {
244 if ( press ) emit power(); 244 if ( press ) emit power();
245 return TRUE; 245 return TRUE;
246 } 246 }
247 if ( ke->simpleData.keycode == Key_F35 ) { 247 if ( ke->simpleData.keycode == Key_F35 ) {
248 if ( press ) emit backlight(); 248 if ( press ) emit backlight();
249 return TRUE; 249 return TRUE;
250 } 250 }
251 if ( ke->simpleData.keycode == Key_F32 ) { 251 if ( ke->simpleData.keycode == Key_F32 ) {
252 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 252 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
253 return TRUE; 253 return TRUE;
254 } 254 }
255 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 255 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
256 if ( press ) emit symbol(); 256 if ( press ) emit symbol();
257 return TRUE; 257 return TRUE;
258 } 258 }
259 if ( ke->simpleData.keycode == Key_NumLock ) { 259 if ( ke->simpleData.keycode == Key_NumLock ) {
260 if ( press ) emit numLockStateToggle(); 260 if ( press ) emit numLockStateToggle();
261 } 261 }
262 if ( ke->simpleData.keycode == Key_CapsLock ) { 262 if ( ke->simpleData.keycode == Key_CapsLock ) {
263 if ( press ) emit capsLockStateToggle(); 263 if ( press ) emit capsLockStateToggle();
264 } 264 }
265 if ( press ) 265 if ( press )
266 qpedesktop->keyClick(); 266 qpedesktop->keyClick();
267 } else { 267 } else {
268 if ( e->type == QWSEvent::Mouse ) { 268 if ( e->type == QWSEvent::Mouse ) {
269 QWSMouseEvent *me = (QWSMouseEvent *)e; 269 QWSMouseEvent *me = (QWSMouseEvent *)e;
270 static bool up = TRUE; 270 static bool up = TRUE;
271 if ( me->simpleData.state&LeftButton ) { 271 if ( me->simpleData.state&LeftButton ) {
272 if ( up ) { 272 if ( up ) {
273 up = FALSE; 273 up = FALSE;
274 qpedesktop->screenClick(); 274 qpedesktop->screenClick();
275 } 275 }
276 } else { 276 } else {
277 up = TRUE; 277 up = TRUE;
278 } 278 }
279 } 279 }
280 } 280 }
281 281
282 return QPEApplication::qwsEventFilter( e ); 282 return QPEApplication::qwsEventFilter( e );
283} 283}
284#endif 284#endif
285 285
286void DesktopApplication::psTimeout() 286void DesktopApplication::psTimeout()
287{ 287{
288 qpedesktop->checkMemory(); // in case no events are being generated 288 qpedesktop->checkMemory(); // in case no events are being generated
289 289
290 *ps = PowerStatusManager::readStatus(); 290 *ps = PowerStatusManager::readStatus();
291 291
292 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) { 292 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) {
293 pa->alert( tr( "Battery is running very low." ), 6 ); 293 pa->alert( tr( "Battery is running very low." ), 6 );
294 } 294 }
295 295
296 if ( ps->batteryStatus() == PowerStatus::Critical ) { 296 if ( ps->batteryStatus() == PowerStatus::Critical ) {
297 pa->alert( tr( "Battery level is critical!\n" 297 pa->alert( tr( "Battery level is critical!\n"
298 "Keep power off until power restored!" ), 1 ); 298 "Keep power off until power restored!" ), 1 );
299 } 299 }
300 300
301 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 301 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
302 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 302 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
303 } 303 }
304} 304}
305 305
306 306
307void DesktopApplication::sendCard() 307void DesktopApplication::sendCard()
308{ 308{
309 delete cardSendTimer; 309 delete cardSendTimer;
310 cardSendTimer = 0; 310 cardSendTimer = 0;
311 QString card = getenv("HOME"); 311 QString card = getenv("HOME");
312 card += "/Applications/addressbook/businesscard.vcf"; 312 card += "/Applications/addressbook/businesscard.vcf";
313 313
314 if ( QFile::exists( card ) ) { 314 if ( QFile::exists( card ) ) {
315 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 315 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
316 QString mimetype = "text/x-vCard"; 316 QString mimetype = "text/x-vCard";
317 e << tr("business card") << card << mimetype; 317 e << tr("business card") << card << mimetype;
318 } 318 }
319} 319}
320 320
321#if defined(QPE_HAVE_MEMALERTER) 321#if defined(QPE_HAVE_MEMALERTER)
322QPE_MEMALERTER_IMPL 322QPE_MEMALERTER_IMPL
323#endif 323#endif
324 324
325#if defined(CUSTOM_SOUND_IMPL) 325#if defined(CUSTOM_SOUND_IMPL)
326CUSTOM_SOUND_IMPL 326CUSTOM_SOUND_IMPL
327#endif 327#endif
328 328
329//=========================================================================== 329//===========================================================================
330 330
331Desktop::Desktop() : 331Desktop::Desktop() :
332 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 332 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
333 qcopBridge( 0 ), 333 qcopBridge( 0 ),
334 transferServer( 0 ), 334 transferServer( 0 ),
335 packageSlave( 0 ) 335 packageSlave( 0 )
336{ 336{
337#ifdef CUSTOM_SOUND_INIT 337#ifdef CUSTOM_SOUND_INIT
338 CUSTOM_SOUND_INIT; 338 CUSTOM_SOUND_INIT;
339#endif 339#endif
340 340
341 qpedesktop = this; 341 qpedesktop = this;
342 342
343// bg = new Info( this ); 343// bg = new Info( this );
344 tb = new TaskBar; 344 tb = new TaskBar;
345 345
346 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 346 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
347 347
348 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait())); 348 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait()));
349 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&))); 349 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&)));
350 350
351 int displayw = qApp->desktop()->width(); 351 int displayw = qApp->desktop()->width();
352 int displayh = qApp->desktop()->height(); 352 int displayh = qApp->desktop()->height();
353 353
354 354
355 QSize sz = tb->sizeHint(); 355 QSize sz = tb->sizeHint();
356 356
357 setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 357 setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
358 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 358 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
359 359
360 tb->show(); 360 tb->show();
361 launcher->showMaximized(); 361 launcher->showMaximized();
362 launcher->show(); 362 launcher->show();
363 launcher->raise(); 363 launcher->raise();
364#if defined(QPE_HAVE_MEMALERTER) 364#if defined(QPE_HAVE_MEMALERTER)
365 initMemalerter(); 365 initMemalerter();
366#endif 366#endif
367 // start services 367 // start services
368 startTransferServer(); 368 startTransferServer();
369 (void) new IrServer( this ); 369 (void) new IrServer( this );
370 rereadVolumes(); 370 rereadVolumes();
371 371
372 packageSlave = new PackageSlave( this ); 372 packageSlave = new PackageSlave( this );
373 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes())); 373 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes()));
374 374
375 qApp->installEventFilter( this ); 375 qApp->installEventFilter( this );
376} 376}
377 377
378void Desktop::show() 378void Desktop::show()
379{ 379{
380 login(TRUE); 380 login(TRUE);
381 QWidget::show(); 381 QWidget::show();
382} 382}
383 383
384Desktop::~Desktop() 384Desktop::~Desktop()
385{ 385{
386 delete launcher; 386 delete launcher;
387 delete tb; 387 delete tb;
388 delete qcopBridge; 388 delete qcopBridge;
389 delete transferServer; 389 delete transferServer;
390} 390}
391 391
392bool Desktop::recoverMemory() 392bool Desktop::recoverMemory()
393{ 393{
394 return tb->recoverMemory(); 394 return tb->recoverMemory();
395} 395}
396 396
397void Desktop::checkMemory() 397void Desktop::checkMemory()
398{ 398{
399#if defined(QPE_HAVE_MEMALERTER) 399#if defined(QPE_HAVE_MEMALERTER)
400 static bool ignoreNormal=FALSE; 400 static bool ignoreNormal=FALSE;
401 static bool existingMessage=FALSE; 401 static bool existingMessage=FALSE;
402 402
403 if(existingMessage) 403 if(existingMessage)
404 return; // don't show a second message while still on first 404 return; // don't show a second message while still on first
405 405
406 existingMessage = TRUE; 406 existingMessage = TRUE;
407 switch ( memstate ) { 407 switch ( memstate ) {
408 case Unknown: 408 case Unknown:
409 break; 409 break;
410 case Low: 410 case Low:
411 memstate = Unknown; 411 memstate = Unknown;
412 if ( recoverMemory() ) 412 if ( recoverMemory() )
413 ignoreNormal = TRUE; 413 ignoreNormal = TRUE;
414 else 414 else
415 QMessageBox::warning( 0 , "Memory Status", 415 QMessageBox::warning( 0 , "Memory Status",
416 "The memory smacks of shortage. \n" 416 "The memory smacks of shortage. \n"
417 "Please save data. " ); 417 "Please save data. " );
418 break; 418 break;
419 case Normal: 419 case Normal:
420 memstate = Unknown; 420 memstate = Unknown;
421 if ( ignoreNormal ) 421 if ( ignoreNormal )
422 ignoreNormal = FALSE; 422 ignoreNormal = FALSE;
423 else 423 else
424 QMessageBox::information ( 0 , "Memory Status", 424 QMessageBox::information ( 0 , "Memory Status",
425 "There is enough memory again." ); 425 "There is enough memory again." );
426 break; 426 break;
427 case VeryLow: 427 case VeryLow:
428 memstate = Unknown; 428 memstate = Unknown;
429 QMessageBox::critical( 0 , "Memory Status", 429 QMessageBox::critical( 0 , "Memory Status",
430 "The memory is very low. \n" 430 "The memory is very low. \n"
431 "Please end this application \n" 431 "Please end this application \n"
432 "immediately." ); 432 "immediately." );
433 recoverMemory(); 433 recoverMemory();
434 } 434 }
435 existingMessage = FALSE; 435 existingMessage = FALSE;
436#endif 436#endif
437} 437}
438 438
439static bool isVisibleWindow(int wid) 439static bool isVisibleWindow(int wid)
440{ 440{
441 const QList<QWSWindow> &list = qwsServer->clientWindows(); 441 const QList<QWSWindow> &list = qwsServer->clientWindows();
442 QWSWindow* w; 442 QWSWindow* w;
443 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 443 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
444 if ( w->winId() == wid ) 444 if ( w->winId() == wid )
445 return !w->isFullyObscured(); 445 return !w->isFullyObscured();
446 } 446 }
447 return FALSE; 447 return FALSE;
448} 448}
449 449
450static bool hasVisibleWindow(const QString& clientname) 450static bool hasVisibleWindow(const QString& clientname)
451{ 451{
452 const QList<QWSWindow> &list = qwsServer->clientWindows(); 452 const QList<QWSWindow> &list = qwsServer->clientWindows();
453 QWSWindow* w; 453 QWSWindow* w;
454 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 454 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
455 if ( w->client()->identity() == clientname && !w->isFullyObscured() ) 455 if ( w->client()->identity() == clientname && !w->isFullyObscured() )
456 return TRUE; 456 return TRUE;
457 } 457 }
458 return FALSE; 458 return FALSE;
459} 459}
460 460
461void Desktop::raiseLauncher() 461void Desktop::raiseLauncher()
462{ 462{
463 Config cfg("qpe"); //F12 'Home' 463 Config cfg("qpe"); //F12 'Home'
464 cfg.setGroup("AppsKey"); 464 cfg.setGroup("AppsKey");
465 QString tempItem; 465 QString tempItem;
466 tempItem = cfg.readEntry("Middle","Home"); 466 tempItem = cfg.readEntry("Middle","Home");
467 if(tempItem == "Home" || tempItem.isEmpty()) { 467 if(tempItem == "Home" || tempItem.isEmpty()) {
468 if ( isVisibleWindow(launcher->winId()) ) 468 if ( isVisibleWindow(launcher->winId()) )
469 launcher->nextView(); 469 launcher->nextView();
470 else 470 else
471 launcher->raise(); 471 launcher->raise();
472 } else { 472 } else {
473 QCopEnvelope e("QPE/System","execute(QString)"); 473 QCopEnvelope e("QPE/System","execute(QString)");
474 e << tempItem; 474 e << tempItem;
475 } 475 }
476} 476}
477 477
478void Desktop::executeOrModify(const QString& appLnkFile) 478void Desktop::executeOrModify(const QString& appLnkFile)
479{ 479{
480 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile); 480 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile);
481 if ( lnk.isValid() ) { 481 if ( lnk.isValid() ) {
482 QCString app = lnk.exec().utf8(); 482 QCString app = lnk.exec().utf8();
483 Global::terminateBuiltin("calibrate"); 483 Global::terminateBuiltin("calibrate");
484 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) { 484 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) {
485 MRUList::addTask(&lnk); 485 MRUList::addTask(&lnk);
486 if ( hasVisibleWindow(app) ) 486 if ( hasVisibleWindow(app) )
487 QCopChannel::send("QPE/Application/" + app, "nextView()"); 487 QCopChannel::send("QPE/Application/" + app, "nextView()");
488 else 488 else
489 QCopChannel::send("QPE/Application/" + app, "raise()"); 489 QCopChannel::send("QPE/Application/" + app, "raise()");
490 } else { 490 } else {
491 lnk.execute(); 491 lnk.execute();
492 } 492 }
493 } 493 }
494} 494}
495 495
496void Desktop::raiseDatebook() 496void Desktop::raiseDatebook()
497{ 497{
498 Config cfg("qpe"); //F9 'Activity' 498 Config cfg("qpe"); //F9 'Activity'
499 cfg.setGroup("AppsKey"); 499 cfg.setGroup("AppsKey");
500 QString tempItem; 500 QString tempItem;
501 tempItem = cfg.readEntry("LeftEnd","Calender"); 501 tempItem = cfg.readEntry("LeftEnd","Calender");
502 if(tempItem == "Calender" || tempItem.isEmpty()) executeOrModify("Applications/datebook.desktop"); 502 if(tempItem == "Calender" || tempItem.isEmpty()) executeOrModify("Applications/datebook.desktop");
503 else { 503 else {
504 QCopEnvelope e("QPE/System","execute(QString)"); 504 QCopEnvelope e("QPE/System","execute(QString)");
505 e << tempItem; 505 e << tempItem;
506 } 506 }
507} 507}
508 508
509void Desktop::raiseContacts() 509void Desktop::raiseContacts()
510{ 510{
511 Config cfg("qpe"); //F10, 'Contacts' 511 Config cfg("qpe"); //F10, 'Contacts'
512 cfg.setGroup("AppsKey"); 512 cfg.setGroup("AppsKey");
513 QString tempItem; 513 QString tempItem;
514 tempItem = cfg.readEntry("Left2nd","Address Book"); 514 tempItem = cfg.readEntry("Left2nd","Address Book");
515 if(tempItem == "Address Book" || tempItem.isEmpty()) executeOrModify("Applications/addressbook.desktop"); 515 if(tempItem == "Address Book" || tempItem.isEmpty()) executeOrModify("Applications/addressbook.desktop");
516 else { 516 else {
517 QCopEnvelope e("QPE/System","execute(QString)"); 517 QCopEnvelope e("QPE/System","execute(QString)");
518 e << tempItem; 518 e << tempItem;
519 } 519 }
520} 520}
521 521
522void Desktop::raiseMenu() 522void Desktop::raiseMenu()
523{ 523{
524 Config cfg("qpe"); //F11, 'Menu' 524 Config cfg("qpe"); //F11, 'Menu'
525 cfg.setGroup("AppsKey"); 525 cfg.setGroup("AppsKey");
526 QString tempItem; 526 QString tempItem;
527 tempItem = cfg.readEntry("Right2nd","Popup Menu"); 527 tempItem = cfg.readEntry("Right2nd","Popup Menu");
528 if(tempItem == "Popup Menu" || tempItem.isEmpty()) { 528 if(tempItem == "Popup Menu" || tempItem.isEmpty()) {
529 Global::terminateBuiltin("calibrate"); 529 Global::terminateBuiltin("calibrate");
530 tb->startMenu()->launch(); 530 tb->startMenu()->launch();
531 } else { 531 } else {
532 QCopEnvelope e("QPE/System","execute(QString)"); 532 QCopEnvelope e("QPE/System","execute(QString)");
533 e << tempItem; 533 e << tempItem;
534 } 534 }
535} 535}
536 536
537void Desktop::raiseEmail() 537void Desktop::raiseEmail()
538{ 538{
539 Config cfg("qpe"); //F13, 'Mail' 539 Config cfg("qpe"); //F13, 'Mail'
540 cfg.setGroup("AppsKey"); 540 cfg.setGroup("AppsKey");
541 QString tempItem; 541 QString tempItem;
542 tempItem = cfg.readEntry("RightEnd","Mail"); 542 tempItem = cfg.readEntry("RightEnd","Mail");
543 if(tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty()) executeOrModify("Applications/qtmail.desktop"); 543 if(tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty()) executeOrModify("Applications/qtmail.desktop");
544 else { 544 else {
545 QCopEnvelope e("QPE/System","execute(QString)"); 545 QCopEnvelope e("QPE/System","execute(QString)");
546 e << tempItem; 546 e << tempItem;
547 } 547 }
548} 548}
549 549
550// autoStarts apps on resume and start 550// autoStarts apps on resume and start
551void Desktop::execAutoStart() { 551void Desktop::execAutoStart() {
552 QString appName; 552 QString appName;
553 int delay; 553 int delay;
554 QDateTime now = QDateTime::currentDateTime(); 554 QDateTime now = QDateTime::currentDateTime();
555 Config cfg( "autostart" ); 555 Config cfg( "autostart" );
556 cfg.setGroup( "AutoStart" ); 556 cfg.setGroup( "AutoStart" );
557 appName = cfg.readEntry("Apps", ""); 557 appName = cfg.readEntry("Apps", "");
558 delay = (cfg.readEntry("Delay", "0" )).toInt(); 558 delay = (cfg.readEntry("Delay", "0" )).toInt();
559 // If the time between suspend and resume was longer then the 559 // If the time between suspend and resume was longer then the
560 // value saved as delay, start the app 560 // value saved as delay, start the app
561 if ( suspendTime.secsTo(now) >= (delay*60) ) { 561 if ( suspendTime.secsTo(now) >= (delay*60) ) {
562 QCopEnvelope e("QPE/System", "execute(QString)"); 562 QCopEnvelope e("QPE/System", "execute(QString)");
563 e << QString(appName); 563 e << QString(appName);
564 } else { 564 } else {
565 } 565 }
566} 566}
567 567
568#if defined(QPE_HAVE_TOGGLELIGHT) 568#if defined(QPE_HAVE_TOGGLELIGHT)
569#include <qpe/config.h> 569#include <qpe/config.h>
570 570
571#include <sys/ioctl.h> 571#include <sys/ioctl.h>
572#include <sys/types.h> 572#include <sys/types.h>
573#include <fcntl.h> 573#include <fcntl.h>
574#include <unistd.h> 574#include <unistd.h>
575#include <errno.h> 575#include <errno.h>
576#include <linux/ioctl.h> 576#include <linux/ioctl.h>
577#include <time.h> 577#include <time.h>
578#endif 578#endif
579 579
580static bool blanked=FALSE; 580static bool blanked=FALSE;
581 581
582static void blankScreen() 582static void blankScreen()
583{ 583{
584 if ( !qt_screen ) return; 584 if ( !qt_screen ) return;
585 /* Should use a big black window instead. 585 /* Should use a big black window instead.
586 QGfx* g = qt_screen->screenGfx(); 586 QGfx* g = qt_screen->screenGfx();
587 g->fillRect(0,0,qt_screen->width(),qt_screen->height()); 587 g->fillRect(0,0,qt_screen->width(),qt_screen->height());
588 delete g; 588 delete g;
589 */ 589 */
590 blanked = TRUE; 590 blanked = TRUE;
591} 591}
592 592
593static void darkScreen() 593static void darkScreen()
594{ 594{
595 extern void qpe_setBacklight(int); 595 extern void qpe_setBacklight(int);
596 qpe_setBacklight(0); // force off 596 qpe_setBacklight(0); // force off
597} 597}
598 598
599 599
600void Desktop::togglePower() 600void Desktop::togglePower()
601{ 601{
602 bool wasloggedin = loggedin; 602 bool wasloggedin = loggedin;
603 loggedin=0; 603 loggedin=0;
604 suspendTime = QDateTime::currentDateTime(); 604 suspendTime = QDateTime::currentDateTime();
605 darkScreen(); 605 darkScreen();
606 if ( wasloggedin ) 606 if ( wasloggedin )
607 blankScreen(); 607 blankScreen();
608 608
609 system("apm --suspend"); 609 system("apm --suspend");
610 610
611 611
612 612
613 QWSServer::screenSaverActivate( FALSE ); 613 QWSServer::screenSaverActivate( FALSE );
614 { 614 {
615 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep 615 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep
616 QCopEnvelope e("QPE/System", "setBacklight(int)"); 616 QCopEnvelope e("QPE/System", "setBacklight(int)");
617 e << -3; // Force on 617 e << -3; // Force on
618 } 618 }
619 if ( wasloggedin ) { 619 if ( wasloggedin ) {
620 login(TRUE); 620 login(TRUE);
621 } 621 }
622 sleep(1); 622 sleep(1);
623 execAutoStart(); 623 execAutoStart();
624 //qcopBridge->closeOpenConnections(); 624 //qcopBridge->closeOpenConnections();
625 //qDebug("called togglePower()!!!!!!"); 625 //qDebug("called togglePower()!!!!!!");
626} 626}
627 627
628void Desktop::toggleLight() 628void Desktop::toggleLight()
629{ 629{
630 QCopEnvelope e("QPE/System", "setBacklight(int)"); 630 QCopEnvelope e("QPE/System", "setBacklight(int)");
631 e << -2; // toggle 631 e << -2; // toggle
632} 632}
633 633
634void Desktop::toggleSymbolInput() 634void Desktop::toggleSymbolInput()
635{ 635{
636 tb->toggleSymbolInput(); 636 tb->toggleSymbolInput();
637} 637}
638 638
639void Desktop::toggleNumLockState() 639void Desktop::toggleNumLockState()
640{ 640{
641 tb->toggleNumLockState(); 641 tb->toggleNumLockState();
642} 642}
643 643
644void Desktop::toggleCapsLockState() 644void Desktop::toggleCapsLockState()
645{ 645{
646 tb->toggleCapsLockState(); 646 tb->toggleCapsLockState();
647} 647}
648 648
649void Desktop::styleChange( QStyle &s ) 649void Desktop::styleChange( QStyle &s )
650{ 650{
651 QWidget::styleChange( s ); 651 QWidget::styleChange( s );
652 int displayw = qApp->desktop()->width(); 652 int displayw = qApp->desktop()->width();
653 int displayh = qApp->desktop()->height(); 653 int displayh = qApp->desktop()->height();
654 654
655 QSize sz = tb->sizeHint(); 655 QSize sz = tb->sizeHint();
656 656
657 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 657 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
658} 658}
659 659
660void DesktopApplication::shutdown() 660void DesktopApplication::shutdown()
661{ 661{
662 if ( type() != GuiServer ) 662 if ( type() != GuiServer )
663 return; 663 return;
664 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 664 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
665 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 665 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
666 this, SLOT(shutdown(ShutdownImpl::Type)) ); 666 this, SLOT(shutdown(ShutdownImpl::Type)) );
667 sd->showMaximized(); 667 sd->showMaximized();
668} 668}
669 669
670void DesktopApplication::shutdown( ShutdownImpl::Type t ) 670void DesktopApplication::shutdown( ShutdownImpl::Type t )
671{ 671{
672 switch ( t ) { 672 switch ( t ) {
673 case ShutdownImpl::ShutdownSystem: 673 case ShutdownImpl::ShutdownSystem:
674 execlp("shutdown", "shutdown", "-h", "now", (void*)0); 674 execlp("shutdown", "shutdown", "-h", "now", (void*)0);
675 break; 675 break;
676 case ShutdownImpl::RebootSystem: 676 case ShutdownImpl::RebootSystem:
677 execlp("shutdown", "shutdown", "-r", "now", (void*)0); 677 execlp("shutdown", "shutdown", "-r", "now", (void*)0);
678 break; 678 break;
679 case ShutdownImpl::RestartDesktop: 679 case ShutdownImpl::RestartDesktop:
680 restart(); 680 restart();
681 break; 681 break;
682 case ShutdownImpl::TerminateDesktop: 682 case ShutdownImpl::TerminateDesktop:
683 prepareForTermination(FALSE); 683 prepareForTermination(FALSE);
684 quit(); 684 quit();
685 break; 685 break;
686 } 686 }
687} 687}
688 688
689void DesktopApplication::restart() 689void DesktopApplication::restart()
690{ 690{
691 prepareForTermination(TRUE); 691 prepareForTermination(TRUE);
692 692
693#ifdef Q_WS_QWS 693#ifdef Q_WS_QWS
694 for ( int fd = 3; fd < 100; fd++ ) 694 for ( int fd = 3; fd < 100; fd++ )
695 close( fd ); 695 close( fd );
696#if defined(QT_DEMO_SINGLE_FLOPPY) 696#if defined(QT_DEMO_SINGLE_FLOPPY)
697 execl( "/sbin/init", "qpe", 0 ); 697 execl( "/sbin/init", "qpe", 0 );
698#elif defined(QT_QWS_CASSIOPEIA) 698#elif defined(QT_QWS_CASSIOPEIA)
699 execl( "/bin/sh", "sh", 0 ); 699 execl( "/bin/sh", "sh", 0 );
700#else 700#else
701 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 ); 701 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 );
702#endif 702#endif
703 exit(1); 703 exit(1);
704#endif 704#endif
705} 705}
706 706
707void Desktop::startTransferServer() 707void Desktop::startTransferServer()
708{ 708{
709 // start qcop bridge server 709 // start qcop bridge server
710 qcopBridge = new QCopBridge( 4243 ); 710 qcopBridge = new QCopBridge( 4243 );
711 if ( !qcopBridge->ok() ) { 711 if ( !qcopBridge->ok() ) {
712 delete qcopBridge; 712 delete qcopBridge;