summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp58
-rw-r--r--core/launcher/main.cpp42
-rw-r--r--libopie/odevice.cpp62
-rw-r--r--libopie/odevice.h4
4 files changed, 135 insertions, 31 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index f90da1a..7f24259 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -1,796 +1,806 @@
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 41
42#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 42#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
43#include <qpe/custom.h> 43#include <qpe/custom.h>
44#endif 44#endif
45 45
46#include <opie/odevice.h> 46#include <opie/odevice.h>
47 47
48#include <qgfx_qws.h> 48#include <qgfx_qws.h>
49#include <qmainwindow.h> 49#include <qmainwindow.h>
50#include <qmessagebox.h> 50#include <qmessagebox.h>
51#include <qtimer.h> 51#include <qtimer.h>
52#include <qwindowsystem_qws.h> 52#include <qwindowsystem_qws.h>
53 53
54#include <qvaluelist.h> 54#include <qvaluelist.h>
55 55
56#include <stdlib.h> 56#include <stdlib.h>
57#include <unistd.h> 57#include <unistd.h>
58 58
59class QCopKeyRegister 59class QCopKeyRegister
60{ 60{
61public: 61public:
62 QCopKeyRegister() : keyCode(0) { } 62 QCopKeyRegister() : keyCode(0) { }
63 QCopKeyRegister(int k, const QString &c, const QString &m) 63 QCopKeyRegister(int k, const QString &c, const QString &m)
64 : keyCode(k), channel(c), message(m) { } 64 : keyCode(k), channel(c), message(m) { }
65 65
66 int getKeyCode() const { return keyCode; } 66 int getKeyCode() const { return keyCode; }
67 QString getChannel() const { return channel; } 67 QString getChannel() const { return channel; }
68 QString getMessage() const { return message; } 68 QString getMessage() const { return message; }
69 69
70private: 70private:
71 int keyCode; 71 int keyCode;
72 QString channel, message; 72 QString channel, message;
73}; 73};
74 74
75typedef QValueList<QCopKeyRegister> KeyRegisterList; 75typedef QValueList<QCopKeyRegister> KeyRegisterList;
76KeyRegisterList keyRegisterList; 76KeyRegisterList keyRegisterList;
77 77
78static Desktop* qpedesktop = 0; 78static Desktop* qpedesktop = 0;
79static int loggedin=0; 79static int loggedin=0;
80static void login(bool at_poweron) 80static void login(bool at_poweron)
81{ 81{
82 if ( !loggedin ) { 82 if ( !loggedin ) {
83 Global::terminateBuiltin("calibrate"); 83 Global::terminateBuiltin("calibrate");
84 Password::authenticate(at_poweron); 84 Password::authenticate(at_poweron);
85 loggedin=1; 85 loggedin=1;
86 QCopEnvelope e( "QPE/Desktop", "unlocked()" ); 86 QCopEnvelope e( "QPE/Desktop", "unlocked()" );
87 } 87 }
88} 88}
89 89
90bool Desktop::screenLocked() 90bool Desktop::screenLocked()
91{ 91{
92 return loggedin == 0; 92 return loggedin == 0;
93} 93}
94 94
95/* 95/*
96 Priority is number of alerts that are needed to pop up 96 Priority is number of alerts that are needed to pop up
97 alert. 97 alert.
98 */ 98 */
99class DesktopPowerAlerter : public QMessageBox 99class DesktopPowerAlerter : public QMessageBox
100{ 100{
101public: 101public:
102 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 102 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
103 : QMessageBox( tr("Battery Status"), "Low Battery", 103 : QMessageBox( tr("Battery Status"), "Low Battery",
104 QMessageBox::Critical, 104 QMessageBox::Critical,
105 QMessageBox::Ok | QMessageBox::Default, 105 QMessageBox::Ok | QMessageBox::Default,
106 QMessageBox::NoButton, QMessageBox::NoButton, 106 QMessageBox::NoButton, QMessageBox::NoButton,
107 parent, name, FALSE ) 107 parent, name, FALSE )
108 { 108 {
109 currentPriority = INT_MAX; 109 currentPriority = INT_MAX;
110 alertCount = 0; 110 alertCount = 0;
111 } 111 }
112 112
113 void alert( const QString &text, int priority ); 113 void alert( const QString &text, int priority );
114 void hideEvent( QHideEvent * ); 114 void hideEvent( QHideEvent * );
115private: 115private:
116 int currentPriority; 116 int currentPriority;
117 int alertCount; 117 int alertCount;
118}; 118};
119 119
120void DesktopPowerAlerter::alert( const QString &text, int priority ) 120void DesktopPowerAlerter::alert( const QString &text, int priority )
121{ 121{
122 alertCount++; 122 alertCount++;
123 if ( alertCount < priority ) 123 if ( alertCount < priority )
124 return; 124 return;
125 if ( priority > currentPriority ) 125 if ( priority > currentPriority )
126 return; 126 return;
127 currentPriority = priority; 127 currentPriority = priority;
128 setText( text ); 128 setText( text );
129 show(); 129 show();
130} 130}
131 131
132 132
133void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 133void DesktopPowerAlerter::hideEvent( QHideEvent *e )
134{ 134{
135 QMessageBox::hideEvent( e ); 135 QMessageBox::hideEvent( e );
136 alertCount = 0; 136 alertCount = 0;
137 currentPriority = INT_MAX; 137 currentPriority = INT_MAX;
138} 138}
139 139
140 140
141 141
142DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) 142DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
143 : QPEApplication( argc, argv, appType ) 143 : QPEApplication( argc, argv, appType )
144{ 144{
145 145
146 QTimer *t = new QTimer( this ); 146 QTimer *t = new QTimer( this );
147 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); 147 connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) );
148 t->start( 10000 ); 148 t->start( 10000 );
149 ps = new PowerStatus; 149 ps = new PowerStatus;
150 pa = new DesktopPowerAlerter( 0 ); 150 pa = new DesktopPowerAlerter( 0 );
151 151
152 channel = new QCopChannel( "QPE/Desktop", this ); 152 channel = new QCopChannel( "QPE/Desktop", this );
153 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 153 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
154 this, SLOT(receive(const QCString&, const QByteArray&)) ); 154 this, SLOT(receive(const QCString&, const QByteArray&)) );
155} 155}
156 156
157 157
158DesktopApplication::~DesktopApplication() 158DesktopApplication::~DesktopApplication()
159{ 159{
160 delete ps; 160 delete ps;
161 delete pa; 161 delete pa;
162} 162}
163 163
164void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) 164void DesktopApplication::receive( const QCString &msg, const QByteArray &data )
165{ 165{
166 QDataStream stream( data, IO_ReadOnly ); 166 QDataStream stream( data, IO_ReadOnly );
167 if (msg == "keyRegister(int key, QString channel, QString message)") 167 if (msg == "keyRegister(int key, QString channel, QString message)")
168 { 168 {
169 int k; 169 int k;
170 QString c, m; 170 QString c, m;
171 stream >> k; 171 stream >> k;
172 stream >> c; 172 stream >> c;
173 stream >> m; 173 stream >> m;
174 174
175 qWarning("KeyRegisterReceived: %i, %s, %s", k, (const char*)c, (const char *)m ); 175 qWarning("KeyRegisterReceived: %i, %s, %s", k, (const char*)c, (const char *)m );
176 keyRegisterList.append(QCopKeyRegister(k,c,m)); 176 keyRegisterList.append(QCopKeyRegister(k,c,m));
177 } 177 }
178 else if (msg == "suspend()"){ 178 else if (msg == "suspend()"){
179 emit power(); 179 emit power();
180 } 180 }
181 181
182} 182}
183 183
184enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; 184enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown;
185 185
186#ifdef Q_WS_QWS 186#ifdef Q_WS_QWS
187bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 187bool DesktopApplication::qwsEventFilter( QWSEvent *e )
188{ 188{
189 qpedesktop->checkMemory(); 189 qpedesktop->checkMemory();
190 190
191 if ( e->type == QWSEvent::Key ) { 191 if ( e->type == QWSEvent::Key ) {
192 QWSKeyEvent *ke = (QWSKeyEvent *)e; 192 QWSKeyEvent *ke = (QWSKeyEvent *)e;
193 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 193 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
194 return TRUE; 194 return TRUE;
195 bool press = ke->simpleData.is_press; 195 bool press = ke->simpleData.is_press;
196 bool autoRepeat= ke->simpleData.is_auto_repeat; 196 bool autoRepeat= ke->simpleData.is_auto_repeat;
197 197
198 /* 198 /*
199 app that registers key/message to be sent back to the app, when it doesn't have focus, 199 app that registers key/message to be sent back to the app, when it doesn't have focus,
200 when user presses key, unless keyboard has been requested from app. 200 when user presses key, unless keyboard has been requested from app.
201 will not send multiple repeats if user holds key 201 will not send multiple repeats if user holds key
202 i.e. one shot 202 i.e. one shot
203 203
204 */ 204 */
205 if (!keyRegisterList.isEmpty()) { 205 if (!keyRegisterList.isEmpty()) {
206 KeyRegisterList::Iterator it; 206 KeyRegisterList::Iterator it;
207 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { 207 for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
208 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() && press) { 208 if ((*it).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() && press) {
209 if(press) qDebug("press"); else qDebug("release"); 209 if(press) qDebug("press"); else qDebug("release");
210 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); 210 QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8());
211 } 211 }
212 } 212 }
213 } 213 }
214 214
215 if ( !keyboardGrabbed() ) { 215 if ( !keyboardGrabbed() ) {
216 if ( ke->simpleData.keycode == Key_F9 ) { 216 if ( ke->simpleData.keycode == Key_F9 ) {
217 if ( press ) emit datebook(); 217 if ( press ) emit datebook();
218 return TRUE; 218 return TRUE;
219 } 219 }
220 if ( ke->simpleData.keycode == Key_F10 ) { 220 if ( ke->simpleData.keycode == Key_F10 ) {
221 if ( !press && cardSendTimer ) { 221 if ( !press && cardSendTimer ) {
222 emit contacts(); 222 emit contacts();
223 delete cardSendTimer; 223 delete cardSendTimer;
224 } else if ( press ) { 224 } else if ( press ) {
225 cardSendTimer = new QTimer(); 225 cardSendTimer = new QTimer();
226 cardSendTimer->start( 2000, TRUE ); 226 cardSendTimer->start( 2000, TRUE );
227 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 227 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
228 } 228 }
229 return TRUE; 229 return TRUE;
230 } 230 }
231 /* menu key now opens application menu/toolbar 231 /* menu key now opens application menu/toolbar
232 if ( ke->simpleData.keycode == Key_F11 ) { 232 if ( ke->simpleData.keycode == Key_F11 ) {
233 if ( press ) emit menu(); 233 if ( press ) emit menu();
234 return TRUE; 234 return TRUE;
235 } 235 }
236 */ 236 */
237 if ( ke->simpleData.keycode == Key_F12 ) { 237 if ( ke->simpleData.keycode == Key_F12 ) {
238 while( activePopupWidget() ) 238 while( activePopupWidget() )
239 activePopupWidget()->close(); 239 activePopupWidget()->close();
240 if ( press ) emit launch(); 240 if ( press ) emit launch();
241 return TRUE; 241 return TRUE;
242 } 242 }
243 if ( ke->simpleData.keycode == Key_F13 ) { 243 if ( ke->simpleData.keycode == Key_F13 ) {
244 if ( press ) emit email(); 244 if ( press ) emit email();
245 return TRUE; 245 return TRUE;
246 } 246 }
247 } 247 }
248 248
249 if ( ke->simpleData.keycode == Key_F34 ) { 249 if ( ke->simpleData.keycode == Key_F34 ) {
250 if ( press ) emit power(); 250 if ( press ) emit power();
251 return TRUE; 251 return TRUE;
252 } 252 }
253// This was used for the iPAQ PowerButton 253// This was used for the iPAQ PowerButton
254// See main.cpp for new KeyboardFilter 254// See main.cpp for new KeyboardFilter
255// 255//
256// if ( ke->simpleData.keycode == Key_SysReq ) { 256// if ( ke->simpleData.keycode == Key_SysReq ) {
257// if ( press ) emit power(); 257// if ( press ) emit power();
258// return TRUE; 258// return TRUE;
259// } 259// }
260 if ( ke->simpleData.keycode == Key_F35 ) { 260 if ( ke->simpleData.keycode == Key_F35 ) {
261 if ( press ) emit backlight(); 261 if ( press ) emit backlight();
262 return TRUE; 262 return TRUE;
263 } 263 }
264 if ( ke->simpleData.keycode == Key_F32 ) { 264 if ( ke->simpleData.keycode == Key_F32 ) {
265 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 265 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
266 return TRUE; 266 return TRUE;
267 } 267 }
268 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 268 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
269 if ( press ) emit symbol(); 269 if ( press ) emit symbol();
270 return TRUE; 270 return TRUE;
271 } 271 }
272 if ( ke->simpleData.keycode == Key_NumLock ) { 272 if ( ke->simpleData.keycode == Key_NumLock ) {
273 if ( press ) emit numLockStateToggle(); 273 if ( press ) emit numLockStateToggle();
274 } 274 }
275 if ( ke->simpleData.keycode == Key_CapsLock ) { 275 if ( ke->simpleData.keycode == Key_CapsLock ) {
276 if ( press ) emit capsLockStateToggle(); 276 if ( press ) emit capsLockStateToggle();
277 } 277 }
278 if (( press && !autoRepeat ) || ( !press && autoRepeat )) 278 if (( press && !autoRepeat ) || ( !press && autoRepeat ))
279 qpedesktop->keyClick(); 279 qpedesktop->keyClick();
280 } else { 280 } else {
281 if ( e->type == QWSEvent::Mouse ) { 281 if ( e->type == QWSEvent::Mouse ) {
282 QWSMouseEvent *me = (QWSMouseEvent *)e; 282 QWSMouseEvent *me = (QWSMouseEvent *)e;
283 static bool up = TRUE; 283 static bool up = TRUE;
284 if ( me->simpleData.state&LeftButton ) { 284 if ( me->simpleData.state&LeftButton ) {
285 if ( up ) { 285 if ( up ) {
286 up = FALSE; 286 up = FALSE;
287 qpedesktop->screenClick(); 287 qpedesktop->screenClick();
288 } 288 }
289 } else { 289 } else {
290 up = TRUE; 290 up = TRUE;
291 } 291 }
292 } 292 }
293 } 293 }
294 294
295 return QPEApplication::qwsEventFilter( e ); 295 return QPEApplication::qwsEventFilter( e );
296} 296}
297#endif 297#endif
298 298
299void DesktopApplication::psTimeout() 299void DesktopApplication::psTimeout()
300{ 300{
301 qpedesktop->checkMemory(); // in case no events are being generated 301 qpedesktop->checkMemory(); // in case no events are being generated
302 302
303 *ps = PowerStatusManager::readStatus(); 303 *ps = PowerStatusManager::readStatus();
304 304
305 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) { 305 if ( (ps->batteryStatus() == PowerStatus::VeryLow ) ) {
306 pa->alert( tr( "Battery is running very low." ), 6 ); 306 pa->alert( tr( "Battery is running very low." ), 6 );
307 } 307 }
308 308
309 if ( ps->batteryStatus() == PowerStatus::Critical ) { 309 if ( ps->batteryStatus() == PowerStatus::Critical ) {
310 pa->alert( tr( "Battery level is critical!\n" 310 pa->alert( tr( "Battery level is critical!\n"
311 "Keep power off until power restored!" ), 1 ); 311 "Keep power off until power restored!" ), 1 );
312 } 312 }
313 313
314 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 314 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
315 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 315 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
316 } 316 }
317} 317}
318 318
319 319
320void DesktopApplication::sendCard() 320void DesktopApplication::sendCard()
321{ 321{
322 delete cardSendTimer; 322 delete cardSendTimer;
323 cardSendTimer = 0; 323 cardSendTimer = 0;
324 QString card = getenv("HOME"); 324 QString card = getenv("HOME");
325 card += "/Applications/addressbook/businesscard.vcf"; 325 card += "/Applications/addressbook/businesscard.vcf";
326 326
327 if ( QFile::exists( card ) ) { 327 if ( QFile::exists( card ) ) {
328 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); 328 QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
329 QString mimetype = "text/x-vCard"; 329 QString mimetype = "text/x-vCard";
330 e << tr("business card") << card << mimetype; 330 e << tr("business card") << card << mimetype;
331 } 331 }
332} 332}
333 333
334#if defined(QPE_HAVE_MEMALERTER) 334#if defined(QPE_HAVE_MEMALERTER)
335QPE_MEMALERTER_IMPL 335QPE_MEMALERTER_IMPL
336#endif 336#endif
337 337
338//=========================================================================== 338//===========================================================================
339 339
340Desktop::Desktop() : 340Desktop::Desktop() :
341 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 341 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
342 qcopBridge( 0 ), 342 qcopBridge( 0 ),
343 transferServer( 0 ), 343 transferServer( 0 ),
344 packageSlave( 0 ) 344 packageSlave( 0 )
345{ 345{
346 qpedesktop = this; 346 qpedesktop = this;
347 347
348// bg = new Info( this ); 348// bg = new Info( this );
349 tb = new TaskBar; 349 tb = new TaskBar;
350 350
351 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 351 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
352 352
353 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait())); 353 connect(launcher, SIGNAL(busy()), tb, SLOT(startWait()));
354 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&))); 354 connect(launcher, SIGNAL(notBusy(const QString&)), tb, SLOT(stopWait(const QString&)));
355 355
356 int displayw = qApp->desktop()->width(); 356 int displayw = qApp->desktop()->width();
357 int displayh = qApp->desktop()->height(); 357 int displayh = qApp->desktop()->height();
358 358
359 359
360 QSize sz = tb->sizeHint(); 360 QSize sz = tb->sizeHint();
361 361
362 setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 362 setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
363 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 363 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
364 364
365 tb->show(); 365 tb->show();
366 launcher->showMaximized(); 366 launcher->showMaximized();
367 launcher->show(); 367 launcher->show();
368 launcher->raise(); 368 launcher->raise();
369#if defined(QPE_HAVE_MEMALERTER) 369#if defined(QPE_HAVE_MEMALERTER)
370 initMemalerter(); 370 initMemalerter();
371#endif 371#endif
372 // start services 372 // start services
373 startTransferServer(); 373 startTransferServer();
374 (void) new IrServer( this ); 374 (void) new IrServer( this );
375 rereadVolumes(); 375 rereadVolumes();
376 376
377 packageSlave = new PackageSlave( this ); 377 packageSlave = new PackageSlave( this );
378 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes())); 378 connect(qApp, SIGNAL(volumeChanged(bool)), this, SLOT(rereadVolumes()));
379 379
380 qApp->installEventFilter( this ); 380 qApp->installEventFilter( this );
381} 381}
382 382
383void Desktop::show() 383void Desktop::show()
384{ 384{
385 login(TRUE); 385 login(TRUE);
386 QWidget::show(); 386 QWidget::show();
387} 387}
388 388
389Desktop::~Desktop() 389Desktop::~Desktop()
390{ 390{
391 delete launcher; 391 delete launcher;
392 delete tb; 392 delete tb;
393 delete qcopBridge; 393 delete qcopBridge;
394 delete transferServer; 394 delete transferServer;
395} 395}
396 396
397bool Desktop::recoverMemory() 397bool Desktop::recoverMemory()
398{ 398{
399 return tb->recoverMemory(); 399 return tb->recoverMemory();
400} 400}
401 401
402void Desktop::checkMemory() 402void Desktop::checkMemory()
403{ 403{
404#if defined(QPE_HAVE_MEMALERTER) 404#if defined(QPE_HAVE_MEMALERTER)
405 static bool ignoreNormal=FALSE; 405 static bool ignoreNormal=FALSE;
406 static bool existingMessage=FALSE; 406 static bool existingMessage=FALSE;
407 407
408 if(existingMessage) 408 if(existingMessage)
409 return; // don't show a second message while still on first 409 return; // don't show a second message while still on first
410 410
411 existingMessage = TRUE; 411 existingMessage = TRUE;
412 switch ( memstate ) { 412 switch ( memstate ) {
413 case Unknown: 413 case Unknown:
414 break; 414 break;
415 case Low: 415 case Low:
416 memstate = Unknown; 416 memstate = Unknown;
417 if ( recoverMemory() ) 417 if ( recoverMemory() )
418 ignoreNormal = TRUE; 418 ignoreNormal = TRUE;
419 else 419 else
420 QMessageBox::warning( 0 , "Memory Status", 420 QMessageBox::warning( 0 , "Memory Status",
421 "The memory smacks of shortage. \n" 421 "The memory smacks of shortage. \n"
422 "Please save data. " ); 422 "Please save data. " );
423 break; 423 break;
424 case Normal: 424 case Normal:
425 memstate = Unknown; 425 memstate = Unknown;
426 if ( ignoreNormal ) 426 if ( ignoreNormal )
427 ignoreNormal = FALSE; 427 ignoreNormal = FALSE;
428 else 428 else
429 QMessageBox::information ( 0 , "Memory Status", 429 QMessageBox::information ( 0 , "Memory Status",
430 "There is enough memory again." ); 430 "There is enough memory again." );
431 break; 431 break;
432 case VeryLow: 432 case VeryLow:
433 memstate = Unknown; 433 memstate = Unknown;
434 QMessageBox::critical( 0 , "Memory Status", 434 QMessageBox::critical( 0 , "Memory Status",
435 "The memory is very low. \n" 435 "The memory is very low. \n"
436 "Please end this application \n" 436 "Please end this application \n"
437 "immediately." ); 437 "immediately." );
438 recoverMemory(); 438 recoverMemory();
439 } 439 }
440 existingMessage = FALSE; 440 existingMessage = FALSE;
441#endif 441#endif
442} 442}
443 443
444static bool isVisibleWindow(int wid) 444static bool isVisibleWindow(int wid)
445{ 445{
446 const QList<QWSWindow> &list = qwsServer->clientWindows(); 446 const QList<QWSWindow> &list = qwsServer->clientWindows();
447 QWSWindow* w; 447 QWSWindow* w;
448 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 448 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
449 if ( w->winId() == wid ) 449 if ( w->winId() == wid )
450 return !w->isFullyObscured(); 450 return !w->isFullyObscured();
451 } 451 }
452 return FALSE; 452 return FALSE;
453} 453}
454 454
455static bool hasVisibleWindow(const QString& clientname) 455static bool hasVisibleWindow(const QString& clientname)
456{ 456{
457 const QList<QWSWindow> &list = qwsServer->clientWindows(); 457 const QList<QWSWindow> &list = qwsServer->clientWindows();
458 QWSWindow* w; 458 QWSWindow* w;
459 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 459 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
460 if ( w->client()->identity() == clientname && !w->isFullyObscured() ) 460 if ( w->client()->identity() == clientname && !w->isFullyObscured() )
461 return TRUE; 461 return TRUE;
462 } 462 }
463 return FALSE; 463 return FALSE;
464} 464}
465 465
466void Desktop::raiseLauncher() 466void Desktop::raiseLauncher()
467{ 467{
468 Config cfg("qpe"); //F12 'Home' 468 Config cfg("qpe"); //F12 'Home'
469 cfg.setGroup("AppsKey"); 469 cfg.setGroup("AppsKey");
470 QString tempItem; 470 QString tempItem;
471 tempItem = cfg.readEntry("Middle","Home"); 471 tempItem = cfg.readEntry("Middle","Home");
472 if(tempItem == "Home" || tempItem.isEmpty()) { 472 if(tempItem == "Home" || tempItem.isEmpty()) {
473 if ( isVisibleWindow(launcher->winId()) ) 473 if ( isVisibleWindow(launcher->winId()) )
474 launcher->nextView(); 474 launcher->nextView();
475 else 475 else
476 launcher->raise(); 476 launcher->raise();
477 } else { 477 } else {
478 QCopEnvelope e("QPE/System","execute(QString)"); 478 QCopEnvelope e("QPE/System","execute(QString)");
479 e << tempItem; 479 e << tempItem;
480 } 480 }
481} 481}
482 482
483void Desktop::executeOrModify(const QString& appLnkFile) 483void Desktop::executeOrModify(const QString& appLnkFile)
484{ 484{
485 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile); 485 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile);
486 if ( lnk.isValid() ) { 486 if ( lnk.isValid() ) {
487 QCString app = lnk.exec().utf8(); 487 QCString app = lnk.exec().utf8();
488 Global::terminateBuiltin("calibrate"); 488 Global::terminateBuiltin("calibrate");
489 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) { 489 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) {
490 MRUList::addTask(&lnk); 490 MRUList::addTask(&lnk);
491 if ( hasVisibleWindow(app) ) 491 if ( hasVisibleWindow(app) )
492 QCopChannel::send("QPE/Application/" + app, "nextView()"); 492 QCopChannel::send("QPE/Application/" + app, "nextView()");
493 else 493 else
494 QCopChannel::send("QPE/Application/" + app, "raise()"); 494 QCopChannel::send("QPE/Application/" + app, "raise()");
495 } else { 495 } else {
496 lnk.execute(); 496 lnk.execute();
497 } 497 }
498 } 498 }
499} 499}
500 500
501void Desktop::raiseDatebook() 501void Desktop::raiseDatebook()
502{ 502{
503 Config cfg("qpe"); //F9 'Activity' 503 Config cfg("qpe"); //F9 'Activity'
504 cfg.setGroup("AppsKey"); 504 cfg.setGroup("AppsKey");
505 QString tempItem; 505 QString tempItem;
506 tempItem = cfg.readEntry("LeftEnd","Calender"); 506 tempItem = cfg.readEntry("LeftEnd","Calender");
507 if(tempItem == "Calender" || tempItem.isEmpty()) executeOrModify("Applications/datebook.desktop"); 507 if(tempItem == "Calender" || tempItem.isEmpty()) executeOrModify("Applications/datebook.desktop");
508 else { 508 else {
509 QCopEnvelope e("QPE/System","execute(QString)"); 509 QCopEnvelope e("QPE/System","execute(QString)");
510 e << tempItem; 510 e << tempItem;
511 } 511 }
512} 512}
513 513
514void Desktop::raiseContacts() 514void Desktop::raiseContacts()
515{ 515{
516 Config cfg("qpe"); //F10, 'Contacts' 516 Config cfg("qpe"); //F10, 'Contacts'
517 cfg.setGroup("AppsKey"); 517 cfg.setGroup("AppsKey");
518 QString tempItem; 518 QString tempItem;
519 tempItem = cfg.readEntry("Left2nd","Address Book"); 519 tempItem = cfg.readEntry("Left2nd","Address Book");
520 if(tempItem == "Address Book" || tempItem.isEmpty()) executeOrModify("Applications/addressbook.desktop"); 520 if(tempItem == "Address Book" || tempItem.isEmpty()) executeOrModify("Applications/addressbook.desktop");
521 else { 521 else {
522 QCopEnvelope e("QPE/System","execute(QString)"); 522 QCopEnvelope e("QPE/System","execute(QString)");
523 e << tempItem; 523 e << tempItem;
524 } 524 }
525} 525}
526 526
527void Desktop::raiseMenu() 527void Desktop::raiseMenu()
528{ 528{
529 Config cfg("qpe"); //F11, 'Menu' 529 Config cfg("qpe"); //F11, 'Menu'
530 cfg.setGroup("AppsKey"); 530 cfg.setGroup("AppsKey");
531 QString tempItem; 531 QString tempItem;
532 tempItem = cfg.readEntry("Right2nd","Popup Menu"); 532 tempItem = cfg.readEntry("Right2nd","Popup Menu");
533 if(tempItem == "Popup Menu" || tempItem.isEmpty()) { 533 if(tempItem == "Popup Menu" || tempItem.isEmpty()) {
534 Global::terminateBuiltin("calibrate"); 534 Global::terminateBuiltin("calibrate");
535 tb->startMenu()->launch(); 535 tb->startMenu()->launch();
536 } else { 536 } else {
537 QCopEnvelope e("QPE/System","execute(QString)"); 537 QCopEnvelope e("QPE/System","execute(QString)");
538 e << tempItem; 538 e << tempItem;
539 } 539 }
540} 540}
541 541
542void Desktop::raiseEmail() 542void Desktop::raiseEmail()
543{ 543{
544 Config cfg("qpe"); //F13, 'Mail' 544 Config cfg("qpe"); //F13, 'Mail'
545 cfg.setGroup("AppsKey"); 545 cfg.setGroup("AppsKey");
546 QString tempItem; 546 QString tempItem;
547 tempItem = cfg.readEntry("RightEnd","Mail"); 547 tempItem = cfg.readEntry("RightEnd","Mail");
548 if(tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty()) executeOrModify("Applications/qtmail.desktop"); 548 if(tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty()) executeOrModify("Applications/qtmail.desktop");
549 else { 549 else {
550 QCopEnvelope e("QPE/System","execute(QString)"); 550 QCopEnvelope e("QPE/System","execute(QString)");
551 e << tempItem; 551 e << tempItem;
552 } 552 }
553} 553}
554 554
555// autoStarts apps on resume and start 555// autoStarts apps on resume and start
556void Desktop::execAutoStart() { 556void Desktop::execAutoStart() {
557 QString appName; 557 QString appName;
558 int delay; 558 int delay;
559 QDateTime now = QDateTime::currentDateTime(); 559 QDateTime now = QDateTime::currentDateTime();
560 Config cfg( "autostart" ); 560 Config cfg( "autostart" );
561 cfg.setGroup( "AutoStart" ); 561 cfg.setGroup( "AutoStart" );
562 appName = cfg.readEntry("Apps", ""); 562 appName = cfg.readEntry("Apps", "");
563 delay = (cfg.readEntry("Delay", "0" )).toInt(); 563 delay = (cfg.readEntry("Delay", "0" )).toInt();
564 // If the time between suspend and resume was longer then the 564 // If the time between suspend and resume was longer then the
565 // value saved as delay, start the app 565 // value saved as delay, start the app
566 if ( suspendTime.secsTo(now) >= (delay*60) ) { 566 if ( suspendTime.secsTo(now) >= (delay*60) ) {
567 QCopEnvelope e("QPE/System", "execute(QString)"); 567 QCopEnvelope e("QPE/System", "execute(QString)");
568 e << QString(appName); 568 e << QString(appName);
569 } //else { 569 } //else {
570 //} 570 //}
571} 571}
572 572
573#if defined(QPE_HAVE_TOGGLELIGHT) 573#if defined(QPE_HAVE_TOGGLELIGHT)
574#include <qpe/config.h> 574#include <qpe/config.h>
575 575
576#include <sys/ioctl.h> 576#include <sys/ioctl.h>
577#include <sys/types.h> 577#include <sys/types.h>
578#include <fcntl.h> 578#include <fcntl.h>
579#include <unistd.h> 579#include <unistd.h>
580#include <errno.h> 580#include <errno.h>
581#include <linux/ioctl.h> 581#include <linux/ioctl.h>
582#include <time.h> 582#include <time.h>
583#endif 583#endif
584 584
585static bool blanked=FALSE; 585static bool blanked=FALSE;
586 586
587static void blankScreen() 587static void blankScreen()
588{ 588{
589 if ( !qt_screen ) return; 589 if ( !qt_screen ) return;
590 /* Should use a big black window instead. 590 /* Should use a big black window instead.
591 QGfx* g = qt_screen->screenGfx(); 591 QGfx* g = qt_screen->screenGfx();
592 g->fillRect(0,0,qt_screen->width(),qt_screen->height()); 592 g->fillRect(0,0,qt_screen->width(),qt_screen->height());
593 delete g; 593 delete g;
594 */ 594 */
595 blanked = TRUE; 595 blanked = TRUE;
596} 596}
597 597
598static void darkScreen() 598static void darkScreen()
599{ 599{
600 extern void qpe_setBacklight(int); 600 extern void qpe_setBacklight(int);
601 qpe_setBacklight(0); // force off 601 qpe_setBacklight(0); // force off
602} 602}
603 603
604 604
605void Desktop::togglePower() 605void Desktop::togglePower()
606{ 606{
607 bool wasloggedin = loggedin; 607 static bool excllock = false;
608 loggedin=0; 608
609 suspendTime = QDateTime::currentDateTime(); 609 if ( excllock )
610 darkScreen(); 610 return;
611 if ( wasloggedin ) 611
612 blankScreen(); 612 excllock = true;
613 613
614 system("apm --suspend"); 614 bool wasloggedin = loggedin;
615 615 loggedin=0;
616 616 suspendTime = QDateTime::currentDateTime();
617 617 darkScreen();
618 QWSServer::screenSaverActivate( FALSE ); 618 if ( wasloggedin )
619 { 619 blankScreen();
620 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep 620
621 QCopEnvelope e("QPE/System", "setBacklight(int)"); 621 ODevice::inst ( )-> suspend ( );
622 e << -3; // Force on 622
623 } 623 QWSServer::screenSaverActivate( FALSE );
624 if ( wasloggedin ) { 624
625 login(TRUE); 625 {
626 } 626 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep
627 sleep(1); 627 QCopEnvelope e("QPE/System", "setBacklight(int)");
628 execAutoStart(); 628 e << -3; // Force on
629 //qcopBridge->closeOpenConnections(); 629 }
630 //qDebug("called togglePower()!!!!!!"); 630
631 if ( wasloggedin )
632 login(TRUE);
633
634 execAutoStart();
635 //qcopBridge->closeOpenConnections();
636 //qDebug("called togglePower()!!!!!!");
637
638 qApp-> processEvents ( );
639
640 excllock = false;
631} 641}
632 642
633void Desktop::toggleLight() 643void Desktop::toggleLight()
634{ 644{
635 QCopEnvelope e("QPE/System", "setBacklight(int)"); 645 QCopEnvelope e("QPE/System", "setBacklight(int)");
636 e << -2; // toggle 646 e << -2; // toggle
637} 647}
638 648
639void Desktop::toggleSymbolInput() 649void Desktop::toggleSymbolInput()
640{ 650{
641 tb->toggleSymbolInput(); 651 tb->toggleSymbolInput();
642} 652}
643 653
644void Desktop::toggleNumLockState() 654void Desktop::toggleNumLockState()
645{ 655{
646 tb->toggleNumLockState(); 656 tb->toggleNumLockState();
647} 657}
648 658
649void Desktop::toggleCapsLockState() 659void Desktop::toggleCapsLockState()
650{ 660{
651 tb->toggleCapsLockState(); 661 tb->toggleCapsLockState();
652} 662}
653 663
654void Desktop::styleChange( QStyle &s ) 664void Desktop::styleChange( QStyle &s )
655{ 665{
656 QWidget::styleChange( s ); 666 QWidget::styleChange( s );
657 int displayw = qApp->desktop()->width(); 667 int displayw = qApp->desktop()->width();
658 int displayh = qApp->desktop()->height(); 668 int displayh = qApp->desktop()->height();
659 669
660 QSize sz = tb->sizeHint(); 670 QSize sz = tb->sizeHint();
661 671
662 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 672 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
663} 673}
664 674
665void DesktopApplication::shutdown() 675void DesktopApplication::shutdown()
666{ 676{
667 if ( type() != GuiServer ) 677 if ( type() != GuiServer )
668 return; 678 return;
669 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 679 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
670 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 680 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
671 this, SLOT(shutdown(ShutdownImpl::Type)) ); 681 this, SLOT(shutdown(ShutdownImpl::Type)) );
672 sd->showMaximized(); 682 sd->showMaximized();
673} 683}
674 684
675void DesktopApplication::shutdown( ShutdownImpl::Type t ) 685void DesktopApplication::shutdown( ShutdownImpl::Type t )
676{ 686{
677 switch ( t ) { 687 switch ( t ) {
678 case ShutdownImpl::ShutdownSystem: 688 case ShutdownImpl::ShutdownSystem:
679 execlp("shutdown", "shutdown", "-h", "now", (void*)0); 689 execlp("shutdown", "shutdown", "-h", "now", (void*)0);
680 break; 690 break;
681 case ShutdownImpl::RebootSystem: 691 case ShutdownImpl::RebootSystem:
682 execlp("shutdown", "shutdown", "-r", "now", (void*)0); 692 execlp("shutdown", "shutdown", "-r", "now", (void*)0);
683 break; 693 break;
684 case ShutdownImpl::RestartDesktop: 694 case ShutdownImpl::RestartDesktop:
685 restart(); 695 restart();
686 break; 696 break;
687 case ShutdownImpl::TerminateDesktop: 697 case ShutdownImpl::TerminateDesktop:
688 prepareForTermination(FALSE); 698 prepareForTermination(FALSE);
689 699
690 // This is a workaround for a Qt bug 700 // This is a workaround for a Qt bug
691 // clipboard applet has to stop its poll timer, or Qt/E 701 // clipboard applet has to stop its poll timer, or Qt/E
692 // will hang on quit() right before it emits aboutToQuit() 702 // will hang on quit() right before it emits aboutToQuit()
693 emit aboutToQuit ( ); 703 emit aboutToQuit ( );
694 704
695 quit(); 705 quit();
696 break; 706 break;
697 } 707 }
698} 708}
699 709
700void DesktopApplication::restart() 710void DesktopApplication::restart()
701{ 711{
702 prepareForTermination(TRUE); 712 prepareForTermination(TRUE);
703 713
704#ifdef Q_WS_QWS 714#ifdef Q_WS_QWS
705 for ( int fd = 3; fd < 100; fd++ ) 715 for ( int fd = 3; fd < 100; fd++ )
706 close( fd ); 716 close( fd );
707#if defined(QT_DEMO_SINGLE_FLOPPY) 717#if defined(QT_DEMO_SINGLE_FLOPPY)
708 execl( "/sbin/init", "qpe", 0 ); 718 execl( "/sbin/init", "qpe", 0 );
709#elif defined(QT_QWS_CASSIOPEIA) 719#elif defined(QT_QWS_CASSIOPEIA)
710 execl( "/bin/sh", "sh", 0 ); 720 execl( "/bin/sh", "sh", 0 );
711#else 721#else
712 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 ); 722 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 );
713#endif 723#endif
714 exit(1); 724 exit(1);
715#endif 725#endif
716} 726}
717 727
718void Desktop::startTransferServer() 728void Desktop::startTransferServer()
719{ 729{
720 // start qcop bridge server 730 // start qcop bridge server
721 qcopBridge = new QCopBridge( 4243 ); 731 qcopBridge = new QCopBridge( 4243 );
722 if ( !qcopBridge->ok() ) { 732 if ( !qcopBridge->ok() ) {
723 delete qcopBridge; 733 delete qcopBridge;
724 qcopBridge = 0; 734 qcopBridge = 0;
725 } 735 }
726 // start transfer server 736 // start transfer server
727 transferServer = new TransferServer( 4242 ); 737 transferServer = new TransferServer( 4242 );
728 if ( !transferServer->ok() ) { 738 if ( !transferServer->ok() ) {
729 delete transferServer; 739 delete transferServer;
730 transferServer = 0; 740 transferServer = 0;
731 } 741 }
732 if ( !transferServer || !qcopBridge ) 742 if ( !transferServer || !qcopBridge )
733 startTimer( 2000 ); 743 startTimer( 2000 );
734} 744}
735 745
736void Desktop::timerEvent( QTimerEvent *e ) 746void Desktop::timerEvent( QTimerEvent *e )
737{ 747{
738 killTimer( e->timerId() ); 748 killTimer( e->timerId() );
739 startTransferServer(); 749 startTransferServer();
740} 750}
741 751
742void Desktop::terminateServers() 752void Desktop::terminateServers()
743{ 753{
744 delete transferServer; 754 delete transferServer;
745 delete qcopBridge; 755 delete qcopBridge;
746 transferServer = 0; 756 transferServer = 0;
747 qcopBridge = 0; 757 qcopBridge = 0;
748} 758}
749 759
750void Desktop::rereadVolumes() 760void Desktop::rereadVolumes()
751{ 761{
752 Config cfg("qpe"); 762 Config cfg("qpe");
753 cfg.setGroup("Volume"); 763 cfg.setGroup("Volume");
754 touchclick = cfg.readBoolEntry("TouchSound"); 764 touchclick = cfg.readBoolEntry("TouchSound");
755 keyclick = cfg.readBoolEntry("KeySound"); 765 keyclick = cfg.readBoolEntry("KeySound");
756 alarmsound = cfg.readBoolEntry("AlarmSound"); 766 alarmsound = cfg.readBoolEntry("AlarmSound");
757// Config cfg("Sound"); 767// Config cfg("Sound");
758// cfg.setGroup("System"); 768// cfg.setGroup("System");
759// touchclick = cfg.readBoolEntry("Touch"); 769// touchclick = cfg.readBoolEntry("Touch");
760// keyclick = cfg.readBoolEntry("Key"); 770// keyclick = cfg.readBoolEntry("Key");
761} 771}
762 772
763void Desktop::keyClick() 773void Desktop::keyClick()
764{ 774{
765 if ( keyclick ) 775 if ( keyclick )
766 ODevice::inst ( )-> keySound ( ); 776 ODevice::inst ( )-> keySound ( );
767} 777}
768 778
769void Desktop::screenClick() 779void Desktop::screenClick()
770{ 780{
771 if ( touchclick ) 781 if ( touchclick )
772 ODevice::inst ( )-> touchSound ( ); 782 ODevice::inst ( )-> touchSound ( );
773} 783}
774 784
775void Desktop::soundAlarm() 785void Desktop::soundAlarm()
776{ 786{
777 if ( qpedesktop-> alarmsound ) 787 if ( qpedesktop-> alarmsound )
778 ODevice::inst ( )-> alarmSound ( ); 788 ODevice::inst ( )-> alarmSound ( );
779} 789}
780 790
781bool Desktop::eventFilter( QObject *, QEvent *ev ) 791bool Desktop::eventFilter( QObject *, QEvent *ev )
782{ 792{
783 if ( ev-> type ( ) == QEvent::KeyPress ) { 793 if ( ev-> type ( ) == QEvent::KeyPress ) {
784 QKeyEvent *ke = (QKeyEvent *) ev; 794 QKeyEvent *ke = (QKeyEvent *) ev;
785 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key 795 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key
786 QWidget *active = qApp-> activeWindow ( ); 796 QWidget *active = qApp-> activeWindow ( );
787 797
788 if ( active && active-> isPopup ( )) 798 if ( active && active-> isPopup ( ))
789 active->close(); 799 active->close();
790 800
791 raiseMenu ( ); 801 raiseMenu ( );
792 return true; 802 return true;
793 } 803 }
794 } 804 }
795 return false; 805 return false;
796} 806}
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index a19da14..1e741d5 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,354 +1,384 @@
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 "taskbar.h" 22#include "taskbar.h"
23#include "stabmon.h" 23#include "stabmon.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/network.h> 26#include <qpe/network.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
29#include <qpe/custom.h> 29#include <qpe/custom.h>
30#endif 30#endif
31 31
32#include <opie/odevice.h> 32#include <opie/odevice.h>
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qwindowsystem_qws.h> 35#include <qwindowsystem_qws.h>
36#include <qpe/qcopenvelope_qws.h> 36#include <qpe/qcopenvelope_qws.h>
37#include <qpe/alarmserver.h> 37#include <qpe/alarmserver.h>
38 38
39#include <stdlib.h> 39#include <stdlib.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <signal.h> 41#include <signal.h>
42#include <unistd.h> 42#include <unistd.h>
43 43
44#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 44#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
45#include "../calibrate/calibrate.h" 45#include "../calibrate/calibrate.h"
46#endif 46#endif
47 47
48#ifdef QT_QWS_CASSIOPEIA 48#ifdef QT_QWS_CASSIOPEIA
49static void ignoreMessage( QtMsgType, const char * ) 49static void ignoreMessage( QtMsgType, const char * )
50{ 50{
51} 51}
52#include <sys/mount.h> 52#include <sys/mount.h>
53#include <sys/types.h> 53#include <sys/types.h>
54#include <sys/stat.h> 54#include <sys/stat.h>
55#include <sys/time.h> 55#include <sys/time.h>
56#include <fcntl.h> 56#include <fcntl.h>
57#include <qdatetime.h> 57#include <qdatetime.h>
58 58
59void initCassiopeia() 59void initCassiopeia()
60{ 60{
61 // MIPSEL-specific init - make sure /proc exists for shm 61 // MIPSEL-specific init - make sure /proc exists for shm
62/* 62/*
63 if ( mount("/dev/ram0", "/", "ext2", MS_REMOUNT | MS_MGC_VAL, 0 ) ) { 63 if ( mount("/dev/ram0", "/", "ext2", MS_REMOUNT | MS_MGC_VAL, 0 ) ) {
64 perror("Remounting - / read/write"); 64 perror("Remounting - / read/write");
65 } 65 }
66*/ 66*/
67 if ( mount("none", "/tmp", "ramfs", 0, 0 ) ) { 67 if ( mount("none", "/tmp", "ramfs", 0, 0 ) ) {
68 perror("mounting ramfs /tmp"); 68 perror("mounting ramfs /tmp");
69 } else { 69 } else {
70 fprintf( stderr, "mounted /tmp\n" ); 70 fprintf( stderr, "mounted /tmp\n" );
71 } 71 }
72 if ( mount("none", "/home", "ramfs", 0, 0 ) ) { 72 if ( mount("none", "/home", "ramfs", 0, 0 ) ) {
73 perror("mounting ramfs /home"); 73 perror("mounting ramfs /home");
74 } else { 74 } else {
75 fprintf( stderr, "mounted /home\n" ); 75 fprintf( stderr, "mounted /home\n" );
76 } 76 }
77 if ( mount("none","/proc","proc",0,0) ) { 77 if ( mount("none","/proc","proc",0,0) ) {
78 perror("Mounting - /proc"); 78 perror("Mounting - /proc");
79 } else { 79 } else {
80 fprintf( stderr, "mounted /proc\n" ); 80 fprintf( stderr, "mounted /proc\n" );
81 } 81 }
82 if ( mount("none","/mnt","shm",0,0) ) { 82 if ( mount("none","/mnt","shm",0,0) ) {
83 perror("Mounting - shm"); 83 perror("Mounting - shm");
84 } 84 }
85 setenv( "QTDIR", "/", 1 ); 85 setenv( "QTDIR", "/", 1 );
86 setenv( "OPIEDIR", "/", 1 ); 86 setenv( "OPIEDIR", "/", 1 );
87 setenv( "HOME", "/home", 1 ); 87 setenv( "HOME", "/home", 1 );
88 mkdir( "/home/Documents", 0755 ); 88 mkdir( "/home/Documents", 0755 );
89 89
90 // set a reasonable starting date 90 // set a reasonable starting date
91 QDateTime dt( QDate( 2001, 3, 15 ) ); 91 QDateTime dt( QDate( 2001, 3, 15 ) );
92 QDateTime now = QDateTime::currentDateTime(); 92 QDateTime now = QDateTime::currentDateTime();
93 int change = now.secsTo( dt ); 93 int change = now.secsTo( dt );
94 94
95 time_t t = ::time(0); 95 time_t t = ::time(0);
96 t += change; 96 t += change;
97 stime(&t); 97 stime(&t);
98 98
99 qInstallMsgHandler(ignoreMessage); 99 qInstallMsgHandler(ignoreMessage);
100} 100}
101#endif 101#endif
102 102
103#ifdef QPE_OWNAPM 103#ifdef QPE_OWNAPM
104#include <sys/ioctl.h> 104#include <sys/ioctl.h>
105#include <sys/types.h> 105#include <sys/types.h>
106#include <fcntl.h> 106#include <fcntl.h>
107#include <unistd.h> 107#include <unistd.h>
108#include <errno.h> 108#include <errno.h>
109#include <linux/ioctl.h> 109#include <linux/ioctl.h>
110#include <qpe/global.h> 110#include <qpe/global.h>
111 111
112static void disableAPM() 112static void disableAPM()
113{ 113{
114 114
115 int fd, cur_val, ret; 115 int fd, cur_val, ret;
116 char *device = "/dev/apm_bios"; 116 char *device = "/dev/apm_bios";
117 117
118 fd = open (device, O_WRONLY); 118 fd = open (device, O_WRONLY);
119 119
120 if (fd == -1) { 120 if (fd == -1) {
121 perror(device); 121 perror(device);
122 return; 122 return;
123 } 123 }
124 124
125 cur_val = ioctl(fd, APM_IOCGEVTSRC, 0); 125 cur_val = ioctl(fd, APM_IOCGEVTSRC, 0);
126 if (cur_val == -1) { 126 if (cur_val == -1) {
127 perror("ioctl"); 127 perror("ioctl");
128 exit(errno); 128 exit(errno);
129 } 129 }
130 130
131 ret = ioctl(fd, APM_IOCSEVTSRC, cur_val & ~APM_EVT_POWER_BUTTON); 131 ret = ioctl(fd, APM_IOCSEVTSRC, cur_val & ~APM_EVT_POWER_BUTTON);
132 if (ret == -1) { 132 if (ret == -1) {
133 perror("ioctl"); 133 perror("ioctl");
134 return; 134 return;
135 } 135 }
136 close(fd); 136 close(fd);
137} 137}
138 138
139static void initAPM() 139static void initAPM()
140{ 140{
141 // So that we have to do it ourself, but better. 141 // So that we have to do it ourself, but better.
142 disableAPM(); 142 disableAPM();
143} 143}
144#endif 144#endif
145 145
146#ifdef QT_DEMO_SINGLE_FLOPPY 146#ifdef QT_DEMO_SINGLE_FLOPPY
147#include <sys/mount.h> 147#include <sys/mount.h>
148 148
149void initFloppy() 149void initFloppy()
150{ 150{
151 mount("none","/proc","proc",0,0); 151 mount("none","/proc","proc",0,0);
152 setenv( "QTDIR", "/", 0 ); 152 setenv( "QTDIR", "/", 0 );
153 setenv( "HOME", "/root", 0 ); 153 setenv( "HOME", "/root", 0 );
154 setenv( "QWS_SIZE", "240x320", 0 ); 154 setenv( "QWS_SIZE", "240x320", 0 );
155} 155}
156#endif 156#endif
157 157
158 158
159void initEnvironment() 159void initEnvironment()
160{ 160{
161 Config config("locale"); 161 Config config("locale");
162 config.setGroup( "Location" ); 162 config.setGroup( "Location" );
163 QString tz = config.readEntry( "Timezone", getenv("TZ") ); 163 QString tz = config.readEntry( "Timezone", getenv("TZ") );
164 164
165 // if not timezone set, pick New York 165 // if not timezone set, pick New York
166 if (tz.isNull()) 166 if (tz.isNull())
167 tz = "America/New_York"; 167 tz = "America/New_York";
168 168
169 setenv( "TZ", tz, 1 ); 169 setenv( "TZ", tz, 1 );
170 config.writeEntry( "Timezone", tz); 170 config.writeEntry( "Timezone", tz);
171 171
172 config.setGroup( "Language" ); 172 config.setGroup( "Language" );
173 QString lang = config.readEntry( "Language", getenv("LANG") ); 173 QString lang = config.readEntry( "Language", getenv("LANG") );
174 if ( !lang.isNull() ) 174 if ( !lang.isNull() )
175 setenv( "LANG", lang, 1 ); 175 setenv( "LANG", lang, 1 );
176} 176}
177 177
178static void initBacklight() 178static void initBacklight()
179{ 179{
180 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 180 QCopEnvelope e("QPE/System", "setBacklight(int)" );
181 e << -3; // Forced on 181 e << -3; // Forced on
182} 182}
183 183
184 184
185class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter 185class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter
186{ 186{
187public: 187public:
188 ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" ) 188 ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" )
189 { 189 {
190 bool doinst = false; 190 bool doinst = false;
191 191
192 m_model = ODevice::inst ( )-> model ( ); 192 m_model = ODevice::inst ( )-> model ( );
193 m_power_timer = 0; 193 m_power_timer = 0;
194 194
195 switch ( m_model ) { 195 switch ( m_model ) {
196 case OMODEL_iPAQ_H31xx: 196 case OMODEL_iPAQ_H31xx:
197 case OMODEL_iPAQ_H36xx: 197 case OMODEL_iPAQ_H36xx:
198 case OMODEL_iPAQ_H37xx: 198 case OMODEL_iPAQ_H37xx:
199 case OMODEL_iPAQ_H38xx: doinst = true; 199 case OMODEL_iPAQ_H38xx: doinst = true;
200 break; 200 break;
201 default : break; 201 default : break;
202 } 202 }
203 if ( doinst ) 203 if ( doinst )
204 QWSServer::setKeyboardFilter ( this ); 204 QWSServer::setKeyboardFilter ( this );
205 } 205 }
206 206
207 virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 207 virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
208 { 208 {
209 bool kill = false; 209 bool kill = false;
210 210
211 // Rotate cursor keys 180° 211 // Rotate cursor keys 180°
212 switch ( m_model ) { 212 switch ( m_model ) {
213 case OMODEL_iPAQ_H31xx: 213 case OMODEL_iPAQ_H31xx:
214 case OMODEL_iPAQ_H38xx: { 214 case OMODEL_iPAQ_H38xx: {
215 int newkeycode = keycode; 215 int newkeycode = keycode;
216 216
217 switch ( keycode ) { 217 switch ( keycode ) {
218 case Key_Left : newkeycode = Key_Right; break; 218 case Key_Left : newkeycode = Key_Right; break;
219 case Key_Right: newkeycode = Key_Left; break; 219 case Key_Right: newkeycode = Key_Left; break;
220 case Key_Up : newkeycode = Key_Down; break; 220 case Key_Up : newkeycode = Key_Down; break;
221 case Key_Down : newkeycode = Key_Up; break; 221 case Key_Down : newkeycode = Key_Up; break;
222 } 222 }
223 if ( newkeycode != keycode ) { 223 if ( newkeycode != keycode ) {
224 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 224 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
225 kill = true; 225 kill = true;
226 } 226 }
227 break; 227 break;
228 } 228 }
229 default: break; 229 default: break;
230 } 230 }
231 231
232 // map Power Button short/long press to F34/F35 232 // map Power Button short/long press to F34/F35
233 switch ( m_model ) { 233 switch ( m_model ) {
234 case OMODEL_iPAQ_H31xx: 234 case OMODEL_iPAQ_H31xx:
235 case OMODEL_iPAQ_H36xx: 235 case OMODEL_iPAQ_H36xx:
236 case OMODEL_iPAQ_H37xx: 236 case OMODEL_iPAQ_H37xx:
237 case OMODEL_iPAQ_H38xx: { 237 case OMODEL_iPAQ_H38xx: {
238 if ( keycode == Key_SysReq ) { 238 if ( keycode == Key_SysReq ) {
239 if ( isPress ) { 239 if ( isPress ) {
240 m_power_timer = startTimer ( 500 ); 240 m_power_timer = startTimer ( 500 );
241 } 241 }
242 else if ( m_power_timer ) { 242 else if ( m_power_timer ) {
243 killTimer ( m_power_timer ); 243 killTimer ( m_power_timer );
244 m_power_timer = 0; 244 m_power_timer = 0;
245 QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false ); 245 QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false );
246 QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false ); 246 QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false );
247 } 247 }
248 kill = true; 248 kill = true;
249 } 249 }
250 break; 250 break;
251 } 251 }
252 default: break; 252 default: break;
253 } 253 }
254 return kill; 254 return kill;
255 } 255 }
256 256
257 virtual void timerEvent ( QTimerEvent * ) 257 virtual void timerEvent ( QTimerEvent * )
258 { 258 {
259 killTimer ( m_power_timer ); 259 killTimer ( m_power_timer );
260 m_power_timer = 0; 260 m_power_timer = 0;
261 QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false ); 261 QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false );
262 QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false ); 262 QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false );
263 } 263 }
264 264
265private: 265private:
266 OModel m_model; 266 OModel m_model;
267 int m_power_timer; 267 int m_power_timer;
268}; 268};
269 269
270 270
271 271
272int initApplication( int argc, char ** argv ) 272int initApplication( int argc, char ** argv )
273{ 273{
274#ifdef QT_QWS_CASSIOPEIA 274#ifdef QT_QWS_CASSIOPEIA
275 initCassiopeia(); 275 initCassiopeia();
276#endif 276#endif
277 277
278#ifdef QPE_OWNAPM 278#ifdef QPE_OWNAPM
279 initAPM(); 279 initAPM();
280#endif 280#endif
281 281
282#ifdef QT_DEMO_SINGLE_FLOPPY 282#ifdef QT_DEMO_SINGLE_FLOPPY
283 initFloppy(); 283 initFloppy();
284#endif 284#endif
285 285
286 initEnvironment(); 286 initEnvironment();
287 287
288#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX) 288#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
289 setenv( "QWS_SIZE", "240x320", 0 ); 289 setenv( "QWS_SIZE", "240x320", 0 );
290#endif 290#endif
291 291
292 //Don't flicker at startup: 292 //Don't flicker at startup:
293 QWSServer::setDesktopBackground( QImage() ); 293 QWSServer::setDesktopBackground( QImage() );
294 DesktopApplication a( argc, argv, QApplication::GuiServer ); 294 DesktopApplication a( argc, argv, QApplication::GuiServer );
295 295
296 (void) new ModelKeyFilter ( ); 296 (void) new ModelKeyFilter ( );
297 297
298 initBacklight(); 298 initBacklight();
299 299
300 AlarmServer::initialize(); 300 AlarmServer::initialize();
301 301
302 Desktop *d = new Desktop(); 302 Desktop *d = new Desktop();
303 303
304 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) ); 304 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) );
305 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) ); 305 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) );
306 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) ); 306 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) );
307 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) ); 307 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) );
308 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) ); 308 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) );
309 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) ); 309 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) );
310 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) ); 310 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) );
311 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) ); 311 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) );
312 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) ); 312 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) );
313 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) ); 313 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) );
314 314
315 (void)new SysFileMonitor(d); 315 (void)new SysFileMonitor(d);
316 Network::createServer(d); 316 Network::createServer(d);
317 317
318#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 318#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
319 if ( !QFile::exists( "/etc/pointercal" ) ) { 319 if ( !QFile::exists( "/etc/pointercal" ) ) {
320 // Make sure calibration widget starts on top. 320 // Make sure calibration widget starts on top.
321 Calibrate *cal = new Calibrate; 321 Calibrate *cal = new Calibrate;
322 cal->exec(); 322 cal->exec();
323 delete cal; 323 delete cal;
324 } 324 }
325#endif 325#endif
326 326
327 d->show(); 327 d->show();
328 328
329 int rv = a.exec(); 329 int rv = a.exec();
330 330
331 delete d; 331 delete d;
332 332
333 return rv; 333 return rv;
334} 334}
335 335
336static const char *pidfile_path = "/var/run/opie.pid";
337
338void create_pidfile ( )
339{
340 FILE *f;
341
342 if (( f = ::fopen ( pidfile_path, "w" ))) {
343 ::fprintf ( f, "%d", getpid ( ));
344 ::fclose ( f );
345 }
346}
347
348void remove_pidfile ( )
349{
350 ::unlink ( pidfile_path );
351}
352
353void handle_sigterm ( int sig )
354{
355 if ( qApp )
356 qApp-> quit ( );
357}
358
336int main( int argc, char ** argv ) 359int main( int argc, char ** argv )
337{ 360{
338#ifndef SINGLE_APP 361#ifndef SINGLE_APP
339 signal( SIGCHLD, SIG_IGN ); 362 ::signal( SIGCHLD, SIG_IGN );
363
364 ::signal ( SIGTERM, handle_sigterm );
365
366 ::setsid ( );
367 ::setpgid ( 0, 0 );
368
369 ::atexit ( remove_pidfile );
370 create_pidfile ( );
340#endif 371#endif
341 372
342 int retVal = initApplication( argc, argv ); 373 int retVal = initApplication ( argc, argv );
343 374
344#ifndef SINGLE_APP 375#ifndef SINGLE_APP
345 // Kill them. Kill them all. 376 // Kill them. Kill them all.
346 setpgid( getpid(), getppid() ); 377 ::kill ( 0, SIGTERM );
347 killpg( getpid(), SIGTERM ); 378 ::sleep( 1 );
348 sleep( 1 ); 379 ::kill ( 0, SIGKILL );
349 killpg( getpid(), SIGKILL );
350#endif 380#endif
351 381
352 return retVal; 382 return retVal;
353} 383}
354 384
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index bc8014a..057c344 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,514 +1,576 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) 2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <stdlib.h>
21
20#include <qfile.h> 22#include <qfile.h>
21#include <qtextstream.h> 23#include <qtextstream.h>
22#include <qpe/sound.h> 24#include <qpe/sound.h>
23#include <qpe/resource.h> 25#include <qpe/resource.h>
24 26
25 27
26#include "odevice.h" 28#include "odevice.h"
27 29
28 30
29class ODeviceData { 31class ODeviceData {
30public: 32public:
31 QString m_vendorstr; 33 QString m_vendorstr;
32 OVendor m_vendor; 34 OVendor m_vendor;
33 35
34 QString m_modelstr; 36 QString m_modelstr;
35 OModel m_model; 37 OModel m_model;
36 38
37 QString m_systemstr; 39 QString m_systemstr;
38 OSystem m_system; 40 OSystem m_system;
39 41
40 QString m_sysverstr; 42 QString m_sysverstr;
41 43
42 OLedState m_leds [4]; // just for convenience ... 44 OLedState m_leds [4]; // just for convenience ...
43}; 45};
44 46
45class ODeviceIPAQ : public ODevice { 47class ODeviceIPAQ : public ODevice {
46protected: 48protected:
47 virtual void init ( ); 49 virtual void init ( );
48 50
49public: 51public:
52 virtual bool suspend ( );
53
50 virtual void alarmSound ( ); 54 virtual void alarmSound ( );
51 55
52 virtual uint hasLeds ( ) const; 56 virtual uint hasLeds ( ) const;
53 virtual OLedState led ( uint which ) const; 57 virtual OLedState led ( uint which ) const;
54 virtual bool setLed ( uint which, OLedState st ); 58 virtual bool setLed ( uint which, OLedState st );
59
60private:
61 static void tstp_sighandler ( int );
55}; 62};
56 63
57class ODeviceZaurus : public ODevice { 64class ODeviceZaurus : public ODevice {
58protected: 65protected:
59 virtual void init ( ); 66 virtual void init ( );
60 67
61 public: 68 public:
62 virtual void alarmSound ( ); 69 virtual void alarmSound ( );
63 virtual void keySound ( ); 70 virtual void keySound ( );
64 virtual void touchSound ( ); 71 virtual void touchSound ( );
65 72
66 virtual uint hasLeds ( ) const; 73 virtual uint hasLeds ( ) const;
67 virtual OLedState led ( uint which ) const; 74 virtual OLedState led ( uint which ) const;
68 virtual bool setLed ( uint which, OLedState st ); 75 virtual bool setLed ( uint which, OLedState st );
69 76
70protected: 77protected:
71 virtual void buzzer ( int snd ); 78 virtual void buzzer ( int snd );
72}; 79};
73 80
74 81
75 82
76 83
77ODevice *ODevice::inst ( ) 84ODevice *ODevice::inst ( )
78{ 85{
79 static ODevice *dev = 0; 86 static ODevice *dev = 0;
80 87
81 if ( !dev ) { 88 if ( !dev ) {
82 if ( QFile::exists ( "/proc/hal/model" )) 89 if ( QFile::exists ( "/proc/hal/model" ))
83 dev = new ODeviceIPAQ ( ); 90 dev = new ODeviceIPAQ ( );
84 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 91 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
85 dev = new ODeviceZaurus ( ); 92 dev = new ODeviceZaurus ( );
86 else 93 else
87 dev = new ODevice ( ); 94 dev = new ODevice ( );
88 95
89 dev-> init ( ); 96 dev-> init ( );
90 } 97 }
91 return dev; 98 return dev;
92} 99}
93 100
94ODevice::ODevice ( ) 101ODevice::ODevice ( )
95{ 102{
96 d = new ODeviceData; 103 d = new ODeviceData;
97 104
98 d-> m_modelstr = "Unknown"; 105 d-> m_modelstr = "Unknown";
99 d-> m_model = OMODEL_Unknown; 106 d-> m_model = OMODEL_Unknown;
100 d-> m_vendorstr = "Unkown"; 107 d-> m_vendorstr = "Unkown";
101 d-> m_vendor = OVENDOR_Unknown; 108 d-> m_vendor = OVENDOR_Unknown;
102 d-> m_systemstr = "Unkown"; 109 d-> m_systemstr = "Unkown";
103 d-> m_system = OSYSTEM_Unknown; 110 d-> m_system = OSYSTEM_Unknown;
104 d-> m_sysverstr = "0.0"; 111 d-> m_sysverstr = "0.0";
105} 112}
106 113
107void ODevice::init ( ) 114void ODevice::init ( )
108{ 115{
109} 116}
110 117
111ODevice::~ODevice ( ) 118ODevice::~ODevice ( )
112{ 119{
113 delete d; 120 delete d;
114} 121}
115 122
123bool ODevice::suspend ( )
124{
125 int rc = ::system ( "apm --suspend" );
126
127 if (( rc == 127 ) || ( rc == -1 ))
128 return false;
129 else
130 return true;
131}
132
116QString ODevice::vendorString ( ) 133QString ODevice::vendorString ( )
117{ 134{
118 return d-> m_vendorstr; 135 return d-> m_vendorstr;
119} 136}
120 137
121OVendor ODevice::vendor ( ) 138OVendor ODevice::vendor ( )
122{ 139{
123 return d-> m_vendor; 140 return d-> m_vendor;
124} 141}
125 142
126QString ODevice::modelString ( ) 143QString ODevice::modelString ( )
127{ 144{
128 return d-> m_modelstr; 145 return d-> m_modelstr;
129} 146}
130 147
131OModel ODevice::model ( ) 148OModel ODevice::model ( )
132{ 149{
133 return d-> m_model; 150 return d-> m_model;
134} 151}
135 152
136QString ODevice::systemString ( ) 153QString ODevice::systemString ( )
137{ 154{
138 return d-> m_systemstr; 155 return d-> m_systemstr;
139} 156}
140 157
141OSystem ODevice::system ( ) 158OSystem ODevice::system ( )
142{ 159{
143 return d-> m_system; 160 return d-> m_system;
144} 161}
145 162
146QString ODevice::systemVersionString ( ) 163QString ODevice::systemVersionString ( )
147{ 164{
148 return d-> m_sysverstr; 165 return d-> m_sysverstr;
149} 166}
150 167
151void ODevice::alarmSound ( ) 168void ODevice::alarmSound ( )
152{ 169{
153#ifndef QT_QWS_EBX 170#ifndef QT_QWS_EBX
154#ifndef QT_NO_SOUND 171#ifndef QT_NO_SOUND
155 static Sound snd ( "alarm" ); 172 static Sound snd ( "alarm" );
156 173
157 if ( snd. isFinished ( )) 174 if ( snd. isFinished ( ))
158 snd. play ( ); 175 snd. play ( );
159#endif 176#endif
160#endif 177#endif
161} 178}
162 179
163void ODevice::keySound ( ) 180void ODevice::keySound ( )
164{ 181{
165#ifndef QT_QWS_EBX 182#ifndef QT_QWS_EBX
166#ifndef QT_NO_SOUND 183#ifndef QT_NO_SOUND
167 static Sound snd ( "keysound" ); 184 static Sound snd ( "keysound" );
168 185
169 if ( snd. isFinished ( )) 186 if ( snd. isFinished ( ))
170 snd. play ( ); 187 snd. play ( );
171#endif 188#endif
172#endif 189#endif
173} 190}
174 191
175void ODevice::touchSound ( ) 192void ODevice::touchSound ( )
176{ 193{
177 194
178#ifndef QT_QWS_EBX 195#ifndef QT_QWS_EBX
179#ifndef QT_NO_SOUND 196#ifndef QT_NO_SOUND
180 static Sound snd ( "touchsound" ); 197 static Sound snd ( "touchsound" );
181//qDebug("touchSound"); 198//qDebug("touchSound");
182 if ( snd. isFinished ( )) { 199 if ( snd. isFinished ( )) {
183 snd. play ( ); 200 snd. play ( );
184 // qDebug("sound should play"); 201 // qDebug("sound should play");
185 } 202 }
186#endif 203#endif
187#endif 204#endif
188} 205}
189 206
190uint ODevice::hasLeds ( ) const 207uint ODevice::hasLeds ( ) const
191{ 208{
192 return 0; 209 return 0;
193} 210}
194 211
195OLedState ODevice::led ( uint /*which*/ ) const 212OLedState ODevice::led ( uint /*which*/ ) const
196{ 213{
197 return OLED_Off; 214 return OLED_Off;
198} 215}
199 216
200bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) 217bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ )
201{ 218{
202 return false; 219 return false;
203} 220}
204 221
205 222
206 223
207 224
208//#if defined( QT_QWS_IPAQ ) // IPAQ 225//#if defined( QT_QWS_IPAQ ) // IPAQ
209 226
210 227
211void ODeviceIPAQ::init ( ) 228void ODeviceIPAQ::init ( )
212{ 229{
213 d-> m_vendorstr = "HP"; 230 d-> m_vendorstr = "HP";
214 d-> m_vendor = OVENDOR_HP; 231 d-> m_vendor = OVENDOR_HP;
215 232
216 QFile f ( "/proc/hal/model" ); 233 QFile f ( "/proc/hal/model" );
217 234
218 if ( f. open ( IO_ReadOnly )) { 235 if ( f. open ( IO_ReadOnly )) {
219 QTextStream ts ( &f ); 236 QTextStream ts ( &f );
220 237
221 d-> m_modelstr = "H" + ts. readLine ( ); 238 d-> m_modelstr = "H" + ts. readLine ( );
222 239
223 if ( d-> m_modelstr == "H3100" ) 240 if ( d-> m_modelstr == "H3100" )
224 d-> m_model = OMODEL_iPAQ_H31xx; 241 d-> m_model = OMODEL_iPAQ_H31xx;
225 else if ( d-> m_modelstr == "H3600" ) 242 else if ( d-> m_modelstr == "H3600" )
226 d-> m_model = OMODEL_iPAQ_H36xx; 243 d-> m_model = OMODEL_iPAQ_H36xx;
227 else if ( d-> m_modelstr == "H3700" ) 244 else if ( d-> m_modelstr == "H3700" )
228 d-> m_model = OMODEL_iPAQ_H37xx; 245 d-> m_model = OMODEL_iPAQ_H37xx;
229 else if ( d-> m_modelstr == "H3800" ) 246 else if ( d-> m_modelstr == "H3800" )
230 d-> m_model = OMODEL_iPAQ_H38xx; 247 d-> m_model = OMODEL_iPAQ_H38xx;
231 else 248 else
232 d-> m_model = OMODEL_Unknown; 249 d-> m_model = OMODEL_Unknown;
233 250
234 f. close ( ); 251 f. close ( );
235 } 252 }
236 253
237 f. setName ( "/etc/familiar-version" ); 254 f. setName ( "/etc/familiar-version" );
238 if ( f. open ( IO_ReadOnly )) { 255 if ( f. open ( IO_ReadOnly )) {
239 d-> m_systemstr = "Familiar"; 256 d-> m_systemstr = "Familiar";
240 d-> m_system = OSYSTEM_Familiar; 257 d-> m_system = OSYSTEM_Familiar;
241 258
242 QTextStream ts ( &f ); 259 QTextStream ts ( &f );
243 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 260 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
244 261
245 f. close ( ); 262 f. close ( );
246 } 263 }
247 264
248 d-> m_leds [0] = OLED_Off; 265 d-> m_leds [0] = OLED_Off;
249} 266}
250 267
251#include <unistd.h> 268#include <unistd.h>
252#include <fcntl.h> 269#include <fcntl.h>
253#include <sys/ioctl.h> 270#include <sys/ioctl.h>
271#include <signal.h>
272#include <sys/time.h>
254#include <linux/soundcard.h> 273#include <linux/soundcard.h>
255#include <qapplication.h> 274#include <qapplication.h>
256#include <qpe/config.h> 275#include <qpe/config.h>
257 276
258//#include <linux/h3600_ts.h> // including kernel headers is evil ... 277//#include <linux/h3600_ts.h> // including kernel headers is evil ...
259 278
260typedef struct h3600_ts_led { 279typedef struct h3600_ts_led {
261 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 280 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
262 unsigned char TotalTime; /* Units of 5 seconds */ 281 unsigned char TotalTime; /* Units of 5 seconds */
263 unsigned char OnTime; /* units of 100m/s */ 282 unsigned char OnTime; /* units of 100m/s */
264 unsigned char OffTime; /* units of 100m/s */ 283 unsigned char OffTime; /* units of 100m/s */
265} LED_IN; 284} LED_IN;
266 285
267 286
268// #define IOC_H3600_TS_MAGIC 'f' 287// #define IOC_H3600_TS_MAGIC 'f'
269// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) 288// #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led)
270#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( 289#define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :(
271 290
272 291
292//#include <linux/apm_bios.h>
293
294//#define APM_IOC_SUSPEND _IO('A',2)
295
296#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 ))
297
298
299void ODeviceIPAQ::tstp_sighandler ( int )
300{
301}
302
303
304bool ODeviceIPAQ::suspend ( )
305{
306 int fd;
307 bool res = false;
308
309 if (( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) {
310 struct timeval tvs, tvn;
311
312 ::signal ( SIGTSTP, tstp_sighandler );
313 ::gettimeofday ( &tvs, 0 );
314
315 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 );
316 ::close ( fd );
317
318 if ( res ) {
319 ::kill ( -::getpid ( ), SIGTSTP );
320
321 do {
322 ::usleep ( 200 * 1000 );
323 ::gettimeofday ( &tvn, 0 );
324 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
325
326 ::kill ( -::getpid ( ), SIGCONT );
327 }
328
329 ::signal ( SIGTSTP, SIG_DFL );
330 }
331 return res;
332}
333
334
273void ODeviceIPAQ::alarmSound ( ) 335void ODeviceIPAQ::alarmSound ( )
274{ 336{
275#if defined( QT_QWS_IPAQ ) // IPAQ 337#if defined( QT_QWS_IPAQ ) // IPAQ
276#ifndef QT_NO_SOUND 338#ifndef QT_NO_SOUND
277 static Sound snd ( "alarm" ); 339 static Sound snd ( "alarm" );
278 int fd; 340 int fd;
279 int vol; 341 int vol;
280 bool vol_reset = false; 342 bool vol_reset = false;
281 343
282 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || 344 if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) ||
283 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { 345 (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) {
284 346
285 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 347 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
286 Config cfg ( "qpe" ); 348 Config cfg ( "qpe" );
287 cfg. setGroup ( "Volume" ); 349 cfg. setGroup ( "Volume" );
288 350
289 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 351 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
290 if ( volalarm < 0 ) 352 if ( volalarm < 0 )
291 volalarm = 0; 353 volalarm = 0;
292 else if ( volalarm > 100 ) 354 else if ( volalarm > 100 )
293 volalarm = 100; 355 volalarm = 100;
294 volalarm |= ( volalarm << 8 ); 356 volalarm |= ( volalarm << 8 );
295 357
296 if (( volalarm & 0xff ) > ( vol & 0xff )) { 358 if (( volalarm & 0xff ) > ( vol & 0xff )) {
297 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 359 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
298 vol_reset = true; 360 vol_reset = true;
299 } 361 }
300 } 362 }
301 } 363 }
302 364
303 snd. play ( ); 365 snd. play ( );
304 while ( !snd. isFinished ( )) 366 while ( !snd. isFinished ( ))
305 qApp-> processEvents ( ); 367 qApp-> processEvents ( );
306 368
307 if ( fd >= 0 ) { 369 if ( fd >= 0 ) {
308 if ( vol_reset ) 370 if ( vol_reset )
309 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 371 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
310 ::close ( fd ); 372 ::close ( fd );
311 } 373 }
312#endif 374#endif
313#endif 375#endif
314} 376}
315 377
316uint ODeviceIPAQ::hasLeds ( ) const 378uint ODeviceIPAQ::hasLeds ( ) const
317{ 379{
318 return 1; 380 return 1;
319} 381}
320 382
321OLedState ODeviceIPAQ::led ( uint which ) const 383OLedState ODeviceIPAQ::led ( uint which ) const
322{ 384{
323 if ( which == 0 ) 385 if ( which == 0 )
324 return d-> m_leds [0]; 386 return d-> m_leds [0];
325 else 387 else
326 return OLED_Off; 388 return OLED_Off;
327} 389}
328 390
329bool ODeviceIPAQ::setLed ( uint which, OLedState st ) 391bool ODeviceIPAQ::setLed ( uint which, OLedState st )
330{ 392{
331 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK ); 393 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK );
332 394
333 if ( which == 0 ) { 395 if ( which == 0 ) {
334 if ( fd >= 0 ) { 396 if ( fd >= 0 ) {
335 struct h3600_ts_led leds; 397 struct h3600_ts_led leds;
336 ::memset ( &leds, 0, sizeof( leds )); 398 ::memset ( &leds, 0, sizeof( leds ));
337 leds. TotalTime = 0; 399 leds. TotalTime = 0;
338 leds. OnTime = 0; 400 leds. OnTime = 0;
339 leds. OffTime = 1; 401 leds. OffTime = 1;
340 leds. OffOnBlink = 2; 402 leds. OffOnBlink = 2;
341 403
342 switch ( st ) { 404 switch ( st ) {
343 case OLED_Off : leds. OffOnBlink = 0; break; 405 case OLED_Off : leds. OffOnBlink = 0; break;
344 case OLED_On : leds. OffOnBlink = 1; break; 406 case OLED_On : leds. OffOnBlink = 1; break;
345 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 407 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
346 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 408 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
347 } 409 }
348 410
349 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 411 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
350 d-> m_leds [0] = st; 412 d-> m_leds [0] = st;
351 return true; 413 return true;
352 } 414 }
353 } 415 }
354 } 416 }
355 return false; 417 return false;
356} 418}
357 419
358 420
359//#endif 421//#endif
360 422
361 423
362 424
363 425
364 426
365//#if defined( QT_QWS_EBX ) // Zaurus 427//#if defined( QT_QWS_EBX ) // Zaurus
366 428
367void ODeviceZaurus::init ( ) 429void ODeviceZaurus::init ( )
368{ 430{
369 d-> m_modelstr = "Zaurus SL5000"; 431 d-> m_modelstr = "Zaurus SL5000";
370 d-> m_model = OMODEL_Zaurus_SL5000; 432 d-> m_model = OMODEL_Zaurus_SL5000;
371 d-> m_vendorstr = "Sharp"; 433 d-> m_vendorstr = "Sharp";
372 d-> m_vendor = OVENDOR_Sharp; 434 d-> m_vendor = OVENDOR_Sharp;
373 435
374 QFile f ( "/proc/filesystems" ); 436 QFile f ( "/proc/filesystems" );
375 437
376 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 438 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
377 d-> m_systemstr = "OpenZaurus"; 439 d-> m_systemstr = "OpenZaurus";
378 d-> m_system = OSYSTEM_OpenZaurus; 440 d-> m_system = OSYSTEM_OpenZaurus;
379 441
380 f. close ( ); 442 f. close ( );
381 } 443 }
382 else { 444 else {
383 d-> m_systemstr = "Zaurus"; 445 d-> m_systemstr = "Zaurus";
384 d-> m_system = OSYSTEM_Zaurus; 446 d-> m_system = OSYSTEM_Zaurus;
385 } 447 }
386 448
387 d-> m_leds [0] = OLED_Off; 449 d-> m_leds [0] = OLED_Off;
388} 450}
389 451
390#include <unistd.h> 452#include <unistd.h>
391#include <fcntl.h> 453#include <fcntl.h>
392#include <sys/ioctl.h> 454#include <sys/ioctl.h>
393 455
394//#include <asm/sharp_char.h> // including kernel headers is evil ... 456//#include <asm/sharp_char.h> // including kernel headers is evil ...
395 457
396#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 458#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
397 459
398 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 460 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
399#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 461#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
400 462
401#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 463#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
402#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 464#define SHARP_BUZ_KEYSOUND 2 /* key sound */
403#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 465#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
404 466
405/* --- for SHARP_BUZZER device --- */ 467/* --- for SHARP_BUZZER device --- */
406 468
407 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 469 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
408//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 470//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
409 471
410#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 472#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
411#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 473#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
412#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 474#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
413#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 475#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
414#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 476#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
415 477
416//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 478//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
417//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 479//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
418 480
419//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 481//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
420//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 482//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
421//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 483//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
422//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 484//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
423//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 485//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
424//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 486//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
425//#define SHARP_PDA_APPSTART 9 /* application start */ 487//#define SHARP_PDA_APPSTART 9 /* application start */
426//#define SHARP_PDA_APPQUIT 10 /* application ends */ 488//#define SHARP_PDA_APPQUIT 10 /* application ends */
427 489
428//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 490//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
429//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 491//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
430//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 492//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
431//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 493//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
432// 494//
433 495
434 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 496 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
435#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 497#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
436 498
437typedef struct sharp_led_status { 499typedef struct sharp_led_status {
438 int which; /* select which LED status is wanted. */ 500 int which; /* select which LED status is wanted. */
439 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 501 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
440} sharp_led_status; 502} sharp_led_status;
441 503
442#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 504#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
443 505
444#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 506#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
445#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 507#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
446#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 508#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
447 509
448 510
449 511
450void ODeviceZaurus::buzzer ( int sound ) 512void ODeviceZaurus::buzzer ( int sound )
451{ 513{
452 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); 514 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
453 515
454 if ( fd >= 0 ) 516 if ( fd >= 0 )
455 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 517 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
456} 518}
457 519
458 520
459void ODeviceZaurus::alarmSound ( ) 521void ODeviceZaurus::alarmSound ( )
460{ 522{
461 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 523 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
462} 524}
463 525
464void ODeviceZaurus::touchSound ( ) 526void ODeviceZaurus::touchSound ( )
465{ 527{
466 buzzer ( SHARP_BUZ_TOUCHSOUND ); 528 buzzer ( SHARP_BUZ_TOUCHSOUND );
467} 529}
468 530
469void ODeviceZaurus::keySound ( ) 531void ODeviceZaurus::keySound ( )
470{ 532{
471 buzzer ( SHARP_BUZ_KEYSOUND ); 533 buzzer ( SHARP_BUZ_KEYSOUND );
472} 534}
473 535
474 536
475uint ODeviceZaurus::hasLeds ( ) const 537uint ODeviceZaurus::hasLeds ( ) const
476{ 538{
477 return 1; 539 return 1;
478} 540}
479 541
480OLedState ODeviceZaurus::led ( uint which ) const 542OLedState ODeviceZaurus::led ( uint which ) const
481{ 543{
482 if ( which == 0 ) 544 if ( which == 0 )
483 return d-> m_leds [0]; 545 return d-> m_leds [0];
484 else 546 else
485 return OLED_Off; 547 return OLED_Off;
486} 548}
487 549
488bool ODeviceZaurus::setLed ( uint which, OLedState st ) 550bool ODeviceZaurus::setLed ( uint which, OLedState st )
489{ 551{
490 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 552 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
491 553
492 if ( which == 0 ) { 554 if ( which == 0 ) {
493 if ( fd >= 0 ) { 555 if ( fd >= 0 ) {
494 struct sharp_led_status leds; 556 struct sharp_led_status leds;
495 ::memset ( &leds, 0, sizeof( leds )); 557 ::memset ( &leds, 0, sizeof( leds ));
496 leds. which = SHARP_LED_MAIL_EXISTS; 558 leds. which = SHARP_LED_MAIL_EXISTS;
497 559
498 switch ( st ) { 560 switch ( st ) {
499 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 561 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
500 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 562 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
501 case OLED_BlinkSlow: 563 case OLED_BlinkSlow:
502 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 564 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
503 } 565 }
504 566
505 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) { 567 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) {
506 d-> m_leds [0] = st; 568 d-> m_leds [0] = st;
507 return true; 569 return true;
508 } 570 }
509 } 571 }
510 } 572 }
511 return false; 573 return false;
512} 574}
513 575
514//#endif 576//#endif
diff --git a/libopie/odevice.h b/libopie/odevice.h
index b54e576..eeae357 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -1,108 +1,110 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) 2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#ifndef _LIBOPIE_ODEVICE_H_ 20#ifndef _LIBOPIE_ODEVICE_H_
21#define _LIBOPIE_ODEVICE_H_ 21#define _LIBOPIE_ODEVICE_H_
22 22
23#include <qstring.h> 23#include <qstring.h>
24 24
25 25
26class ODeviceData; 26class ODeviceData;
27 27
28enum OModel { 28enum OModel {
29 OMODEL_Unknown, 29 OMODEL_Unknown,
30 30
31 OMODEL_iPAQ_H31xx, 31 OMODEL_iPAQ_H31xx,
32 OMODEL_iPAQ_H36xx, 32 OMODEL_iPAQ_H36xx,
33 OMODEL_iPAQ_H37xx, 33 OMODEL_iPAQ_H37xx,
34 OMODEL_iPAQ_H38xx, 34 OMODEL_iPAQ_H38xx,
35 35
36 OMODEL_Zaurus_SL5000 36 OMODEL_Zaurus_SL5000
37}; 37};
38 38
39 enum OVendor { 39 enum OVendor {
40 OVENDOR_Unknown, 40 OVENDOR_Unknown,
41 41
42 OVENDOR_HP, 42 OVENDOR_HP,
43 OVENDOR_Sharp 43 OVENDOR_Sharp
44 }; 44 };
45 45
46enum OSystem { 46enum OSystem {
47 OSYSTEM_Unknown, 47 OSYSTEM_Unknown,
48 48
49 OSYSTEM_Familiar, 49 OSYSTEM_Familiar,
50 OSYSTEM_Zaurus, 50 OSYSTEM_Zaurus,
51 OSYSTEM_OpenZaurus 51 OSYSTEM_OpenZaurus
52}; 52};
53 53
54enum OLedState { 54enum OLedState {
55 OLED_Off, 55 OLED_Off,
56 OLED_On, 56 OLED_On,
57 OLED_BlinkSlow, 57 OLED_BlinkSlow,
58 OLED_BlinkFast 58 OLED_BlinkFast
59}; 59};
60 60
61 61
62class ODevice 62class ODevice
63{ 63{
64public: 64public:
65 65
66public: 66public:
67 static ODevice *inst ( ); 67 static ODevice *inst ( );
68 68
69 // system
70 virtual bool suspend ( );
69 71
70// information 72// information
71 73
72 QString modelString ( ); 74 QString modelString ( );
73 OModel model ( ); 75 OModel model ( );
74 76
75 QString vendorString ( ); 77 QString vendorString ( );
76 OVendor vendor ( ); 78 OVendor vendor ( );
77 79
78 QString systemString ( ); 80 QString systemString ( );
79 OSystem system ( ); 81 OSystem system ( );
80 82
81 QString systemVersionString ( ); 83 QString systemVersionString ( );
82 84
83// input / output 85// input / output
84 86
85 virtual void alarmSound ( ); 87 virtual void alarmSound ( );
86 virtual void keySound ( ); 88 virtual void keySound ( );
87 virtual void touchSound ( ); 89 virtual void touchSound ( );
88 90
89 virtual uint hasLeds ( ) const; 91 virtual uint hasLeds ( ) const;
90 virtual OLedState led ( uint which ) const; 92 virtual OLedState led ( uint which ) const;
91 virtual bool setLed ( uint which, OLedState st ); 93 virtual bool setLed ( uint which, OLedState st );
92 94
93 virtual ~ODevice ( ); 95 virtual ~ODevice ( );
94 96
95protected: 97protected:
96 ODevice ( ); 98 ODevice ( );
97 virtual void init ( ); 99 virtual void init ( );
98 100
99 ODeviceData *d; 101 ODeviceData *d;
100 102
101private: 103private:
102 ODevice ( const ODevice & ); 104 ODevice ( const ODevice & );
103 105
104}; 106};
105 107
106#endif 108#endif
107 109
108 110