-rw-r--r-- | core/launcher/serverapp.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp index 6fe0479..0e92040 100644 --- a/core/launcher/serverapp.cpp +++ b/core/launcher/serverapp.cpp | |||
@@ -1,863 +1,863 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the 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 "serverapp.h" | 21 | #include "serverapp.h" |
22 | #include "screensaver.h" | 22 | #include "screensaver.h" |
23 | 23 | ||
24 | /* OPIE */ | 24 | /* OPIE */ |
25 | #include <opie2/odebug.h> | 25 | #include <opie2/odebug.h> |
26 | #include <opie2/odevice.h> | 26 | #include <opie2/odevice.h> |
27 | #include <opie2/multiauthpassword.h> | 27 | #include <opie2/multiauthpassword.h> |
28 | 28 | ||
29 | #include <qtopia/config.h> | 29 | #include <qtopia/config.h> |
30 | #include <qtopia/power.h> | 30 | #include <qtopia/power.h> |
31 | 31 | ||
32 | #ifdef Q_WS_QWS | 32 | #ifdef Q_WS_QWS |
33 | #include <qtopia/qcopenvelope_qws.h> | 33 | #include <qtopia/qcopenvelope_qws.h> |
34 | #endif | 34 | #endif |
35 | #include <qtopia/global.h> | 35 | #include <qtopia/global.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #ifdef Q_WS_QWS | 39 | #ifdef Q_WS_QWS |
40 | #include <qgfx_qws.h> | 40 | #include <qgfx_qws.h> |
41 | #endif | 41 | #endif |
42 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qpainter.h> | 44 | #include <qpainter.h> |
45 | #include <qfile.h> | 45 | #include <qfile.h> |
46 | #include <qpixmapcache.h> | 46 | #include <qpixmapcache.h> |
47 | 47 | ||
48 | /* STD */ | 48 | /* STD */ |
49 | #ifdef Q_OS_WIN32 | 49 | #ifdef Q_OS_WIN32 |
50 | #include <io.h> | 50 | #include <io.h> |
51 | #include <process.h> | 51 | #include <process.h> |
52 | #else | 52 | #else |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #endif | 54 | #endif |
55 | #include <stdlib.h> | 55 | #include <stdlib.h> |
56 | 56 | ||
57 | static ServerApplication *serverApp = 0; | 57 | static ServerApplication *serverApp = 0; |
58 | static int loggedin=0; | 58 | static int loggedin=0; |
59 | 59 | ||
60 | QCopKeyRegister::QCopKeyRegister() | 60 | QCopKeyRegister::QCopKeyRegister() |
61 | : m_keyCode( 0 ) | 61 | : m_keyCode( 0 ) |
62 | { | 62 | { |
63 | 63 | ||
64 | } | 64 | } |
65 | 65 | ||
66 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) | 66 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) |
67 | :m_keyCode( k ), m_channel( c ), m_message( m ) | 67 | :m_keyCode( k ), m_channel( c ), m_message( m ) |
68 | { | 68 | { |
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | int QCopKeyRegister::keyCode() const | 72 | int QCopKeyRegister::keyCode() const |
73 | { | 73 | { |
74 | return m_keyCode; | 74 | return m_keyCode; |
75 | } | 75 | } |
76 | 76 | ||
77 | QCString QCopKeyRegister::channel() const | 77 | QCString QCopKeyRegister::channel() const |
78 | { | 78 | { |
79 | return m_channel; | 79 | return m_channel; |
80 | } | 80 | } |
81 | 81 | ||
82 | QCString QCopKeyRegister::message() const | 82 | QCString QCopKeyRegister::message() const |
83 | { | 83 | { |
84 | return m_message; | 84 | return m_message; |
85 | } | 85 | } |
86 | 86 | ||
87 | bool QCopKeyRegister::send() | 87 | bool QCopKeyRegister::send() |
88 | { | 88 | { |
89 | if (m_channel.isNull() ) | 89 | if (m_channel.isNull() ) |
90 | return false; | 90 | return false; |
91 | 91 | ||
92 | QCopEnvelope e( m_channel, m_message ); | 92 | QCopEnvelope e( m_channel, m_message ); |
93 | 93 | ||
94 | return true; | 94 | return true; |
95 | } | 95 | } |
96 | 96 | ||
97 | //--------------------------------------------------------------------------- | 97 | //--------------------------------------------------------------------------- |
98 | 98 | ||
99 | /* | 99 | /* |
100 | Priority is number of alerts that are needed to pop up | 100 | Priority is number of alerts that are needed to pop up |
101 | alert. | 101 | alert. |
102 | */ | 102 | */ |
103 | class DesktopPowerAlerter : public QMessageBox | 103 | class DesktopPowerAlerter : public QMessageBox |
104 | { | 104 | { |
105 | Q_OBJECT | 105 | Q_OBJECT |
106 | public: | 106 | public: |
107 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 107 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
108 | : QMessageBox( tr("Battery Status"), tr("Low Battery"), | 108 | : QMessageBox( tr("Battery Status"), tr("Low Battery"), |
109 | QMessageBox::Critical, | 109 | QMessageBox::Critical, |
110 | QMessageBox::Ok | QMessageBox::Default, | 110 | QMessageBox::Ok | QMessageBox::Default, |
111 | QMessageBox::NoButton, QMessageBox::NoButton, | 111 | QMessageBox::NoButton, QMessageBox::NoButton, |
112 | parent, name, FALSE ) | 112 | parent, name, FALSE ) |
113 | { | 113 | { |
114 | currentPriority = INT_MAX; | 114 | currentPriority = INT_MAX; |
115 | alertCount = 0; | 115 | alertCount = 0; |
116 | } | 116 | } |
117 | 117 | ||
118 | void alert( const QString &text, int priority ); | 118 | void alert( const QString &text, int priority ); |
119 | void hideEvent( QHideEvent * ); | 119 | void hideEvent( QHideEvent * ); |
120 | private: | 120 | private: |
121 | int currentPriority; | 121 | int currentPriority; |
122 | int alertCount; | 122 | int alertCount; |
123 | }; | 123 | }; |
124 | 124 | ||
125 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 125 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
126 | { | 126 | { |
127 | alertCount++; | 127 | alertCount++; |
128 | if ( alertCount < priority ) | 128 | if ( alertCount < priority ) |
129 | return; | 129 | return; |
130 | if ( priority > currentPriority ) | 130 | if ( priority > currentPriority ) |
131 | return; | 131 | return; |
132 | currentPriority = priority; | 132 | currentPriority = priority; |
133 | setText( text ); | 133 | setText( text ); |
134 | show(); | 134 | show(); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 138 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
139 | { | 139 | { |
140 | QMessageBox::hideEvent( e ); | 140 | QMessageBox::hideEvent( e ); |
141 | alertCount = 0; | 141 | alertCount = 0; |
142 | currentPriority = INT_MAX; | 142 | currentPriority = INT_MAX; |
143 | } | 143 | } |
144 | 144 | ||
145 | //--------------------------------------------------------------------------- | 145 | //--------------------------------------------------------------------------- |
146 | 146 | ||
147 | KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0),firedHeldButton(0) | 147 | KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0),firedHeldButton(0) |
148 | { | 148 | { |
149 | /* We don't do this cause it would interfere with ODevice */ | 149 | /* We don't do this cause it would interfere with ODevice */ |
150 | #if 0 | 150 | #if 0 |
151 | qwsServer->setKeyboardFilter(this); | 151 | qwsServer->setKeyboardFilter(this); |
152 | #endif | 152 | #endif |
153 | } | 153 | } |
154 | 154 | ||
155 | void KeyFilter::timerEvent(QTimerEvent* e) | 155 | void KeyFilter::timerEvent(QTimerEvent* e) |
156 | { | 156 | { |
157 | if ( e->timerId() == held_tid ) { | 157 | if ( e->timerId() == held_tid ) { |
158 | killTimer(held_tid); | 158 | killTimer(held_tid); |
159 | // button held | 159 | // button held |
160 | if ( heldButton ) { | 160 | if ( heldButton ) { |
161 | emit activate(heldButton, TRUE); | 161 | emit activate(heldButton, TRUE); |
162 | firedHeldButton = heldButton; | 162 | firedHeldButton = heldButton; |
163 | heldButton = 0; | 163 | heldButton = 0; |
164 | } | 164 | } |
165 | held_tid = 0; | 165 | held_tid = 0; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | void KeyFilter::registerKey( const QCopKeyRegister& key ) | 169 | void KeyFilter::registerKey( const QCopKeyRegister& key ) |
170 | { | 170 | { |
171 | 171 | ||
172 | m_keys.insert( key.keyCode(), key ); | 172 | m_keys.insert( key.keyCode(), key ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) | 175 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) |
176 | { | 176 | { |
177 | m_keys.remove( key.keyCode() ); | 177 | m_keys.remove( key.keyCode() ); |
178 | } | 178 | } |
179 | 179 | ||
180 | bool KeyFilter::keyRegistered( int key ) | 180 | bool KeyFilter::keyRegistered( int key ) |
181 | { | 181 | { |
182 | /* | 182 | /* |
183 | * Check if we've a key registered | 183 | * Check if we've a key registered |
184 | */ | 184 | */ |
185 | if ( !m_keys[key].send()) | 185 | if ( !m_keys[key].send()) |
186 | return false; | 186 | return false; |
187 | else | 187 | else |
188 | return true; | 188 | return true; |
189 | } | 189 | } |
190 | 190 | ||
191 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) | 191 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) |
192 | { | 192 | { |
193 | if ( !loggedin | 193 | if ( !loggedin |
194 | // Permitted keys | 194 | // Permitted keys |
195 | && keycode != Key_F34 // power | 195 | && keycode != Key_F34 // power |
196 | && keycode != Key_F30 // select | 196 | && keycode != Key_F30 // select |
197 | && keycode != Key_Enter | 197 | && keycode != Key_Enter |
198 | && keycode != Key_Return | 198 | && keycode != Key_Return |
199 | && keycode != Key_Space | 199 | && keycode != Key_Space |
200 | && keycode != Key_Left | 200 | && keycode != Key_Left |
201 | && keycode != Key_Right | 201 | && keycode != Key_Right |
202 | && keycode != Key_Up | 202 | && keycode != Key_Up |
203 | && keycode != Key_Down ) | 203 | && keycode != Key_Down ) |
204 | return TRUE; | 204 | return TRUE; |
205 | 205 | ||
206 | // odebug << " KeyFilter::checkButtonAction("<<db<<","<<keycode<<","<<press<<","<<autoRepeat<<")"<<oendl; | 206 | // odebug << " KeyFilter::checkButtonAction("<<db<<","<<keycode<<","<<press<<","<<autoRepeat<<")"<<oendl; |
207 | /* check if it was registered */ | 207 | /* check if it was registered */ |
208 | if (!db ) { | 208 | if (!db ) { |
209 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) | 209 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) |
210 | return true; | 210 | return true; |
211 | } else { | 211 | } else { |
212 | // First check to see if DeviceButtonManager knows something about this button: | 212 | // First check to see if DeviceButtonManager knows something about this button: |
213 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); | 213 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); |
214 | if (button && !autoRepeat) { | 214 | if (button && !autoRepeat) { |
215 | if (firedHeldButton) { | 215 | if (firedHeldButton) { |
216 | if (held_tid) { | 216 | if (held_tid) { |
217 | killTimer(held_tid); | 217 | killTimer(held_tid); |
218 | held_tid = 0; | 218 | held_tid = 0; |
219 | } | 219 | } |
220 | if (!press && button == firedHeldButton) { | 220 | if (!press && button == firedHeldButton) { |
221 | firedHeldButton = 0; | 221 | firedHeldButton = 0; |
222 | return TRUE; | 222 | return TRUE; |
223 | } | 223 | } |
224 | } else if ( held_tid && heldButton != button) { | 224 | } else if ( held_tid && heldButton != button) { |
225 | killTimer(held_tid); | 225 | killTimer(held_tid); |
226 | held_tid = 0; | 226 | held_tid = 0; |
227 | } | 227 | } |
228 | if ( button->heldAction().isNull() ) { | 228 | if ( button->heldAction().isNull() ) { |
229 | if ( press ) | 229 | if ( press ) |
230 | emit activate(button, FALSE); | 230 | emit activate(button, FALSE); |
231 | } else if ( press ) { | 231 | } else if ( press ) { |
232 | if (heldButton != button) { | 232 | if (heldButton != button) { |
233 | heldButton = button; | 233 | heldButton = button; |
234 | held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); | 234 | held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); |
235 | } | 235 | } |
236 | } else if ( heldButton ) { | 236 | } else if ( heldButton ) { |
237 | heldButton = 0; | 237 | heldButton = 0; |
238 | emit activate(button, FALSE); | 238 | emit activate(button, FALSE); |
239 | } | 239 | } |
240 | QWSServer::screenSaverActivate(FALSE); | 240 | QWSServer::screenSaverActivate(FALSE); |
241 | return TRUE; | 241 | return TRUE; |
242 | } | 242 | } |
243 | return false; | 243 | return false; |
244 | } | 244 | } |
245 | if ( keycode == HardKey_Suspend ) { | 245 | if ( keycode == HardKey_Suspend ) { |
246 | if ( press ) emit power(); | 246 | if ( press ) emit power(); |
247 | return TRUE; | 247 | return TRUE; |
248 | } | 248 | } |
249 | if ( keycode == HardKey_Backlight ) { | 249 | if ( keycode == HardKey_Backlight ) { |
250 | if ( press ) emit backlight(); | 250 | if ( press ) emit backlight(); |
251 | return TRUE; | 251 | return TRUE; |
252 | } | 252 | } |
253 | if ( keycode == Key_F32 ) { | 253 | if ( keycode == Key_F32 ) { |
254 | #ifndef QT_NO_COP | 254 | #ifndef QT_NO_COP |
255 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 255 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
256 | #endif | 256 | #endif |
257 | return TRUE; | 257 | return TRUE; |
258 | } | 258 | } |
259 | if ( keycode == Key_F31 ) { | 259 | if ( keycode == Key_F31 ) { |
260 | if ( press ) emit symbol(); | 260 | if ( press ) emit symbol(); |
261 | QWSServer::screenSaverActivate(FALSE); | 261 | QWSServer::screenSaverActivate(FALSE); |
262 | return TRUE; | 262 | return TRUE; |
263 | } | 263 | } |
264 | 264 | ||
265 | if ( keycode == Key_NumLock ) | 265 | if ( keycode == Key_NumLock ) |
266 | if ( press ) emit numLockStateToggle(); | 266 | if ( press ) emit numLockStateToggle(); |
267 | 267 | ||
268 | if ( keycode == Key_CapsLock ) | 268 | if ( keycode == Key_CapsLock ) |
269 | if ( press ) emit capsLockStateToggle(); | 269 | if ( press ) emit capsLockStateToggle(); |
270 | 270 | ||
271 | if ( serverApp ) | 271 | if ( serverApp ) |
272 | serverApp->keyClick(keycode,press,autoRepeat); | 272 | serverApp->keyClick(keycode,press,autoRepeat); |
273 | 273 | ||
274 | return FALSE; | 274 | return FALSE; |
275 | } | 275 | } |
276 | 276 | ||
277 | enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; | 277 | enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; |
278 | 278 | ||
279 | #if defined(QPE_HAVE_MEMALERTER) | 279 | #if defined(QPE_HAVE_MEMALERTER) |
280 | QPE_MEMALERTER_IMPL | 280 | QPE_MEMALERTER_IMPL |
281 | #endif | 281 | #endif |
282 | 282 | ||
283 | 283 | ||
284 | 284 | ||
285 | //--------------------------------------------------------------------------- | 285 | //--------------------------------------------------------------------------- |
286 | 286 | ||
287 | bool ServerApplication::doRestart = FALSE; | 287 | bool ServerApplication::doRestart = FALSE; |
288 | bool ServerApplication::allowRestart = TRUE; | 288 | bool ServerApplication::allowRestart = TRUE; |
289 | bool ServerApplication::ms_is_starting = TRUE; | 289 | bool ServerApplication::ms_is_starting = TRUE; |
290 | 290 | ||
291 | void ServerApplication::switchLCD( bool on ) | 291 | void ServerApplication::switchLCD( bool on ) |
292 | { | 292 | { |
293 | if ( !qApp ) | 293 | if ( !qApp ) |
294 | return; | 294 | return; |
295 | 295 | ||
296 | ServerApplication *dapp = ServerApplication::me() ; | 296 | ServerApplication *dapp = ServerApplication::me() ; |
297 | 297 | ||
298 | if ( !dapp-> m_screensaver ) | 298 | if ( !dapp-> m_screensaver ) |
299 | return; | 299 | return; |
300 | 300 | ||
301 | if ( on ) { | 301 | if ( on ) { |
302 | dapp-> m_screensaver-> setDisplayState ( true ); | 302 | dapp-> m_screensaver-> setDisplayState ( true ); |
303 | dapp-> m_screensaver-> setBacklight ( -3 ); | 303 | dapp-> m_screensaver-> setBacklight ( -3 ); |
304 | } else | 304 | } else |
305 | dapp-> m_screensaver-> setDisplayState ( false ); | 305 | dapp-> m_screensaver-> setDisplayState ( false ); |
306 | 306 | ||
307 | 307 | ||
308 | } | 308 | } |
309 | 309 | ||
310 | ServerApplication::ServerApplication( int& argc, char **argv, Type t ) | 310 | ServerApplication::ServerApplication( int& argc, char **argv, Type t ) |
311 | : Opie::Core::OApplication( argc, argv, t ) | 311 | : Opie::Core::OApplication( argc, argv, t ) |
312 | { | 312 | { |
313 | ms_is_starting = true; | 313 | ms_is_starting = true; |
314 | 314 | ||
315 | // We know we'll have lots of cached pixmaps due to App/DocLnks | 315 | // We know we'll have lots of cached pixmaps due to App/DocLnks |
316 | QPixmapCache::setCacheLimit(512); | 316 | QPixmapCache::setCacheLimit(512); |
317 | 317 | ||
318 | m_ps = new PowerStatus; | 318 | m_ps = new PowerStatus; |
319 | m_ps_last = new PowerStatus; | 319 | m_ps_last = new PowerStatus; |
320 | pa = new DesktopPowerAlerter( 0 ); | 320 | pa = new DesktopPowerAlerter( 0 ); |
321 | 321 | ||
322 | m_apm_timer = new QTimer( this ); | 322 | m_apm_timer = new QTimer( this ); |
323 | connect(m_apm_timer, SIGNAL( timeout() ), | 323 | connect(m_apm_timer, SIGNAL( timeout() ), |
324 | this, SLOT( apmTimeout() ) ); | 324 | this, SLOT( apmTimeout() ) ); |
325 | 325 | ||
326 | reloadPowerWarnSettings(); | 326 | reloadPowerWarnSettings(); |
327 | 327 | ||
328 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 328 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
329 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 329 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), |
330 | this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); | 330 | this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); |
331 | 331 | ||
332 | channel = new QCopChannel("QPE/Launcher", this ); | 332 | channel = new QCopChannel("QPE/Launcher", this ); |
333 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 333 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), |
334 | this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); | 334 | this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); |
335 | 335 | ||
336 | m_screensaver = new OpieScreenSaver(); | 336 | m_screensaver = new OpieScreenSaver(); |
337 | m_screensaver->setInterval( -1 ); | 337 | m_screensaver->setInterval( -1 ); |
338 | QWSServer::setScreenSaver( m_screensaver ); | 338 | QWSServer::setScreenSaver( m_screensaver ); |
339 | 339 | ||
340 | connect( qApp, SIGNAL( volumeChanged(bool) ), | 340 | connect( qApp, SIGNAL( volumeChanged(bool) ), |
341 | this, SLOT( rereadVolumes() ) ); | 341 | this, SLOT( rereadVolumes() ) ); |
342 | 342 | ||
343 | 343 | ||
344 | /* ### PluginLoader libqtopia SafeMode */ | 344 | /* ### PluginLoader libqtopia SafeMode */ |
345 | #if 0 | 345 | #if 0 |
346 | if ( PluginLoader::inSafeMode() ) | 346 | if ( PluginLoader::inSafeMode() ) |
347 | QTimer::singleShot(500, this, SLOT(showSafeMode()) ); | 347 | QTimer::singleShot(500, this, SLOT(showSafeMode()) ); |
348 | QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); | 348 | QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); |
349 | #endif | 349 | #endif |
350 | 350 | ||
351 | kf = new KeyFilter(this); | 351 | kf = new KeyFilter(this); |
352 | 352 | ||
353 | connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); | 353 | connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); |
354 | connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); | 354 | connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); |
355 | connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); | 355 | connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); |
356 | connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); | 356 | connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); |
357 | connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); | 357 | connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); |
358 | connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); | 358 | connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); |
359 | connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), | 359 | connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), |
360 | this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); | 360 | this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); |
361 | 361 | ||
362 | 362 | ||
363 | connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); | 363 | connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); |
364 | 364 | ||
365 | connect( this, SIGNAL(power() ), | 365 | connect( this, SIGNAL(power() ), |
366 | SLOT(togglePower() ) ); | 366 | SLOT(togglePower() ) ); |
367 | 367 | ||
368 | rereadVolumes(); | 368 | rereadVolumes(); |
369 | 369 | ||
370 | serverApp = this; | 370 | serverApp = this; |
371 | 371 | ||
372 | apmTimeout(); | 372 | apmTimeout(); |
373 | grabKeyboard(); | 373 | grabKeyboard(); |
374 | 374 | ||
375 | /* make sure the event filter is installed */ /* std::limits<short>::max() when you've stdc++ */ | 375 | /* make sure the event filter is installed */ /* std::limits<short>::max() when you've stdc++ */ |
376 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( SHRT_MAX ); | 376 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( SHRT_MAX ); |
377 | Q_CONST_UNUSED( but ) | 377 | Q_CONST_UNUSED( but ) |
378 | } | 378 | } |
379 | 379 | ||
380 | 380 | ||
381 | ServerApplication::~ServerApplication() | 381 | ServerApplication::~ServerApplication() |
382 | { | 382 | { |
383 | ungrabKeyboard(); | 383 | ungrabKeyboard(); |
384 | 384 | ||
385 | delete pa; | 385 | delete pa; |
386 | delete m_ps; | 386 | delete m_ps; |
387 | delete m_ps_last; | 387 | delete m_ps_last; |
388 | } | 388 | } |
389 | 389 | ||
390 | void ServerApplication::apmTimeout() | 390 | void ServerApplication::apmTimeout() |
391 | { | 391 | { |
392 | serverApp-> checkMemory( ); // in case no events are generated | 392 | serverApp-> checkMemory( ); // in case no events are generated |
393 | *m_ps_last = *m_ps; | 393 | *m_ps_last = *m_ps; |
394 | *m_ps = PowerStatusManager::readStatus(); | 394 | *m_ps = PowerStatusManager::readStatus(); |
395 | 395 | ||
396 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) | 396 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) |
397 | m_screensaver-> powerStatusChanged( *m_ps ); | 397 | m_screensaver-> powerStatusChanged( *m_ps ); |
398 | 398 | ||
399 | if ( m_ps->acStatus() == PowerStatus::Online ) { | 399 | if ( m_ps->acStatus() == PowerStatus::Online ) { |
400 | return; | 400 | return; |
401 | } | 401 | } |
402 | 402 | ||
403 | int bat = m_ps-> batteryPercentRemaining(); | 403 | int bat = m_ps-> batteryPercentRemaining(); |
404 | 404 | ||
405 | if ( bat < m_ps_last-> batteryPercentRemaining() ) { | 405 | if ( bat < m_ps_last-> batteryPercentRemaining() ) { |
406 | if ( bat <= m_powerCritical ) { | 406 | if ( bat <= m_powerCritical ) { |
407 | QMessageBox battlow( | 407 | QMessageBox battlow( |
408 | tr("WARNING"), | 408 | tr("WARNING"), |
409 | tr("<p>The battery level is critical!" | 409 | tr("<p>The battery level is critical!" |
410 | "<p>Keep power off until AC is restored"), | 410 | "<p>Keep power off until AC is restored"), |
411 | QMessageBox::Warning, | 411 | QMessageBox::Warning, |
412 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 412 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
413 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 413 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
414 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 414 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
415 | battlow.exec(); | 415 | battlow.exec(); |
416 | } else if ( bat <= m_powerVeryLow ) | 416 | } else if ( bat <= m_powerVeryLow ) |
417 | pa->alert( tr( "The battery is running very low. "), 2 ); | 417 | pa->alert( tr( "The battery is running very low. "), 2 ); |
418 | } | 418 | } |
419 | 419 | ||
420 | if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { | 420 | if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { |
421 | QMessageBox battlow( | 421 | QMessageBox battlow( |
422 | tr("WARNING"), | 422 | tr("WARNING"), |
423 | tr("<p>The Back-up battery is very low" | 423 | tr("<p>The Back-up battery is very low" |
424 | "<p>Please charge the back-up battery"), | 424 | "<p>Please charge the back-up battery"), |
425 | QMessageBox::Warning, | 425 | QMessageBox::Warning, |
426 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 426 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
427 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 427 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
428 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 428 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
429 | battlow.exec(); | 429 | battlow.exec(); |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | void ServerApplication::systemMessage( const QCString& msg, | 433 | void ServerApplication::systemMessage( const QCString& msg, |
434 | const QByteArray& data ) | 434 | const QByteArray& data ) |
435 | { | 435 | { |
436 | QDataStream stream ( data, IO_ReadOnly ); | 436 | QDataStream stream ( data, IO_ReadOnly ); |
437 | 437 | ||
438 | if ( msg == "setScreenSaverInterval(int)" ) { | 438 | if ( msg == "setScreenSaverInterval(int)" ) { |
439 | int time; | 439 | int time; |
440 | stream >> time; | 440 | stream >> time; |
441 | m_screensaver-> setInterval( time ); | 441 | m_screensaver-> setInterval( time ); |
442 | } | 442 | } |
443 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 443 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
444 | int t1, t2, t3; | 444 | int t1, t2, t3; |
445 | stream >> t1 >> t2 >> t3; | 445 | stream >> t1 >> t2 >> t3; |
446 | m_screensaver-> setIntervals( t1, t2, t3 ); | 446 | m_screensaver-> setIntervals( t1, t2, t3 ); |
447 | } | 447 | } |
448 | else if ( msg == "setBacklight(int)" ) { | 448 | else if ( msg == "setBacklight(int)" ) { |
449 | int bright; | 449 | int bright; |
450 | stream >> bright; | 450 | stream >> bright; |
451 | m_screensaver-> setBacklight( bright ); | 451 | m_screensaver-> setBacklight( bright ); |
452 | } | 452 | } |
453 | else if ( msg == "setScreenSaverMode(int)" ) { | 453 | else if ( msg == "setScreenSaverMode(int)" ) { |
454 | int mode; | 454 | int mode; |
455 | stream >> mode; | 455 | stream >> mode; |
456 | m_screensaver-> setMode ( mode ); | 456 | m_screensaver-> setMode ( mode ); |
457 | } | 457 | } |
458 | else if ( msg == "reloadPowerWarnSettings()" ) { | 458 | else if ( msg == "reloadPowerWarnSettings()" ) { |
459 | reloadPowerWarnSettings(); | 459 | reloadPowerWarnSettings(); |
460 | } | 460 | } |
461 | else if ( msg == "setDisplayState(int)" ) { | 461 | else if ( msg == "setDisplayState(int)" ) { |
462 | int state; | 462 | int state; |
463 | stream >> state; | 463 | stream >> state; |
464 | m_screensaver-> setDisplayState ( state != 0 ); | 464 | m_screensaver-> setDisplayState ( state != 0 ); |
465 | } | 465 | } |
466 | else if ( msg == "suspend()" ) { | 466 | else if ( msg == "suspend()" ) { |
467 | emit power(); | 467 | emit power(); |
468 | } | 468 | } |
469 | else if ( msg == "sendBusinessCard()" ) { | 469 | else if ( msg == "sendBusinessCard()" ) { |
470 | QString card = ::getenv ( "HOME" ); | 470 | QString card = ::getenv ( "HOME" ); |
471 | card += "/Applications/addressbook/businesscard.vcf"; | 471 | card += "/Applications/addressbook/businesscard.vcf"; |
472 | 472 | ||
473 | if ( QFile::exists( card ) ) { | 473 | if ( QFile::exists( card ) ) { |
474 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); | 474 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); |
475 | QString mimetype = "text/x-vCard"; | 475 | QString mimetype = "text/x-vCard"; |
476 | e << tr( "business card" ) << card << mimetype; | 476 | e << tr( "business card" ) << card << mimetype; |
477 | } | 477 | } |
478 | } | 478 | } |
479 | } | 479 | } |
480 | 480 | ||
481 | void ServerApplication::reloadPowerWarnSettings ( ) | 481 | void ServerApplication::reloadPowerWarnSettings ( ) |
482 | { | 482 | { |
483 | Config cfg ( "apm" ); | 483 | Config cfg ( "apm" ); |
484 | cfg. setGroup ( "Warnings" ); | 484 | cfg. setGroup ( "Warnings" ); |
485 | 485 | ||
486 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); | 486 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); |
487 | 487 | ||
488 | m_apm_timer-> stop ( ); | 488 | m_apm_timer-> stop ( ); |
489 | if ( iv ) | 489 | if ( iv ) |
490 | m_apm_timer-> start ( iv ); | 490 | m_apm_timer-> start ( iv ); |
491 | 491 | ||
492 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); | 492 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); |
493 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); | 493 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); |
494 | } | 494 | } |
495 | 495 | ||
496 | void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) | 496 | void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) |
497 | { | 497 | { |
498 | QDataStream stream ( data, IO_ReadOnly ); | 498 | QDataStream stream ( data, IO_ReadOnly ); |
499 | 499 | ||
500 | if ( msg == "deviceButton(int,int,int)" ) { | 500 | if ( msg == "deviceButton(int,int,int)" ) { |
501 | int keycode, press, autoRepeat; | 501 | int keycode, press, autoRepeat; |
502 | stream >> keycode >> press >> autoRepeat; | 502 | stream >> keycode >> press >> autoRepeat; |
503 | 503 | ||
504 | kf->checkButtonAction ( true, keycode, press, autoRepeat ); | 504 | kf->checkButtonAction ( true, keycode, press, autoRepeat ); |
505 | } | 505 | } |
506 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { | 506 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { |
507 | int k; | 507 | int k; |
508 | QCString c, m; | 508 | QCString c, m; |
509 | stream >> k >> c >> m; | 509 | stream >> k >> c >> m; |
510 | 510 | ||
511 | kf -> registerKey( QCopKeyRegister(k, c, m) ); | 511 | kf -> registerKey( QCopKeyRegister(k, c, m) ); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | 515 | ||
516 | bool ServerApplication::screenLocked() | 516 | bool ServerApplication::screenLocked() |
517 | { | 517 | { |
518 | return loggedin == 0; | 518 | return loggedin == 0; |
519 | } | 519 | } |
520 | 520 | ||
521 | void ServerApplication::login(bool at_poweron) | 521 | void ServerApplication::login(bool at_poweron) |
522 | { | 522 | { |
523 | if ( !loggedin ) { | 523 | if ( !loggedin ) { |
524 | Global::terminateBuiltin("calibrate"); // No tr | 524 | Global::terminateBuiltin("calibrate"); // No tr |
525 | int lockMode = at_poweron ? Opie::Security::IfPowerOn : Opie::Security::IfResume; | 525 | int lockMode = at_poweron ? Opie::Security::IfPowerOn : Opie::Security::IfResume; |
526 | Opie::Security::MultiauthPassword::authenticate(lockMode); | 526 | Opie::Security::MultiauthPassword::authenticate(lockMode); |
527 | loggedin=1; | 527 | loggedin=1; |
528 | #ifndef QT_NO_COP | 528 | #ifndef QT_NO_COP |
529 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 529 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
530 | #endif | 530 | #endif |
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | #if defined(QPE_HAVE_TOGGLELIGHT) | 534 | #if defined(QPE_HAVE_TOGGLELIGHT) |
535 | #include <qtopia/config.h> | 535 | #include <qtopia/config.h> |
536 | 536 | ||
537 | #include <sys/ioctl.h> | 537 | #include <sys/ioctl.h> |
538 | #include <sys/types.h> | 538 | #include <sys/types.h> |
539 | #include <fcntl.h> | 539 | #include <fcntl.h> |
540 | #include <unistd.h> | 540 | #include <unistd.h> |
541 | #include <errno.h> | 541 | #include <errno.h> |
542 | #include <linux/ioctl.h> | 542 | #include <linux/ioctl.h> |
543 | #include <time.h> | 543 | #include <time.h> |
544 | #endif | 544 | #endif |
545 | 545 | ||
546 | namespace { | 546 | namespace { |
547 | void execAutoStart(const QDateTime& suspendTime ) { | 547 | void execAutoStart(const QDateTime& suspendTime ) { |
548 | QString appName; | 548 | QString appName; |
549 | int delay; | 549 | int delay; |
550 | QDateTime now = QDateTime::currentDateTime(); | 550 | QDateTime now = QDateTime::currentDateTime(); |
551 | 551 | ||
552 | Config cfg( "autostart" ); | 552 | Config cfg( "autostart" ); |
553 | cfg.setGroup( "AutoStart" ); | 553 | cfg.setGroup( "AutoStart" ); |
554 | appName = cfg.readEntry( "Apps", "" ); | 554 | appName = cfg.readEntry( "Apps", "" ); |
555 | delay = cfg.readNumEntry( "Delay", 0 ); | 555 | delay = cfg.readNumEntry( "Delay", 0 ); |
556 | 556 | ||
557 | // If the time between suspend and resume was longer then the | 557 | // If the time between suspend and resume was longer then the |
558 | // value saved as delay, start the app | 558 | // value saved as delay, start the app |
559 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | 559 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { |
560 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 560 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
561 | e << QString( appName ); | 561 | e << QString( appName ); |
562 | } | 562 | } |
563 | } | 563 | } |
564 | } | 564 | } |
565 | 565 | ||
566 | 566 | ||
567 | void ServerApplication::togglePower() | 567 | void ServerApplication::togglePower() |
568 | { | 568 | { |
569 | static bool excllock = false; | 569 | static bool excllock = false; |
570 | 570 | ||
571 | if ( excllock ) | 571 | if ( excllock ) |
572 | return ; | 572 | return ; |
573 | 573 | ||
574 | excllock = true; | 574 | excllock = true; |
575 | 575 | ||
576 | bool wasloggedin = loggedin; | 576 | bool wasloggedin = loggedin; |
577 | loggedin = 0; | 577 | loggedin = 0; |
578 | m_suspendTime = QDateTime::currentDateTime(); | 578 | m_suspendTime = QDateTime::currentDateTime(); |
579 | 579 | ||
580 | #ifdef QWS | 580 | #ifdef QWS |
581 | if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) { | 581 | if ( Opie::Security::MultiauthPassword::needToAuthenticate ( false ) && qt_screen ) { |
582 | // Should use a big black window instead. | 582 | // Should use a big black window instead. |
583 | // But this would not show up fast enough | 583 | // But this would not show up fast enough |
584 | QGfx *g = qt_screen-> screenGfx ( ); | 584 | QGfx *g = qt_screen-> screenGfx ( ); |
585 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | 585 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); |
586 | delete g; | 586 | delete g; |
587 | } | 587 | } |
588 | #endif | 588 | #endif |
589 | 589 | ||
590 | ODevice::inst ( )-> suspend ( ); | 590 | ODevice::inst ( )-> suspend ( ); |
591 | 591 | ||
592 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call | 592 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call |
593 | QWSServer::screenSaverActivate ( false ); | 593 | QWSServer::screenSaverActivate ( false ); |
594 | 594 | ||
595 | { | 595 | { |
596 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | 596 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep |
597 | } | 597 | } |
598 | 598 | ||
599 | if ( wasloggedin ) | 599 | if ( wasloggedin ) |
600 | login ( true ); | 600 | login ( false ); |
601 | 601 | ||
602 | execAutoStart(m_suspendTime); | 602 | execAutoStart(m_suspendTime); |
603 | //qcopBridge->closeOpenConnections(); | 603 | //qcopBridge->closeOpenConnections(); |
604 | 604 | ||
605 | excllock = false; | 605 | excllock = false; |
606 | } | 606 | } |
607 | 607 | ||
608 | void ServerApplication::toggleLight() | 608 | void ServerApplication::toggleLight() |
609 | { | 609 | { |
610 | #ifndef QT_NO_COP | 610 | #ifndef QT_NO_COP |
611 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 611 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
612 | e << -2; // toggle | 612 | e << -2; // toggle |
613 | #endif | 613 | #endif |
614 | } | 614 | } |
615 | 615 | ||
616 | 616 | ||
617 | /* | 617 | /* |
618 | * We still listen to key events but handle them in | 618 | * We still listen to key events but handle them in |
619 | * a special class | 619 | * a special class |
620 | */ | 620 | */ |
621 | 621 | ||
622 | bool ServerApplication::eventFilter( QObject *o, QEvent *e) { | 622 | bool ServerApplication::eventFilter( QObject *o, QEvent *e) { |
623 | if ( e->type() != QEvent::KeyPress && | 623 | if ( e->type() != QEvent::KeyPress && |
624 | e->type() != QEvent::KeyRelease ) | 624 | e->type() != QEvent::KeyRelease ) |
625 | return QPEApplication::eventFilter( o, e ); | 625 | return QPEApplication::eventFilter( o, e ); |
626 | 626 | ||
627 | QKeyEvent *ke = static_cast<QKeyEvent*>( e ); | 627 | QKeyEvent *ke = static_cast<QKeyEvent*>( e ); |
628 | if ( kf->checkButtonAction( true, ke->key(), | 628 | if ( kf->checkButtonAction( true, ke->key(), |
629 | e->type() == QEvent::KeyPress, | 629 | e->type() == QEvent::KeyPress, |
630 | ke-> isAutoRepeat() )) | 630 | ke-> isAutoRepeat() )) |
631 | return true; | 631 | return true; |
632 | 632 | ||
633 | return QPEApplication::eventFilter( o, e ); | 633 | return QPEApplication::eventFilter( o, e ); |
634 | 634 | ||
635 | } | 635 | } |
636 | 636 | ||
637 | #ifdef Q_WS_QWS | 637 | #ifdef Q_WS_QWS |
638 | bool ServerApplication::qwsEventFilter( QWSEvent *e ) | 638 | bool ServerApplication::qwsEventFilter( QWSEvent *e ) |
639 | { | 639 | { |
640 | checkMemory(); | 640 | checkMemory(); |
641 | 641 | ||
642 | if ( e->type == QWSEvent::Mouse ) { | 642 | if ( e->type == QWSEvent::Mouse ) { |
643 | QWSMouseEvent *me = (QWSMouseEvent *)e; | 643 | QWSMouseEvent *me = (QWSMouseEvent *)e; |
644 | static bool up = TRUE; | 644 | static bool up = TRUE; |
645 | if ( me->simpleData.state&LeftButton ) { | 645 | if ( me->simpleData.state&LeftButton ) { |
646 | if ( up ) { | 646 | if ( up ) { |
647 | up = FALSE; | 647 | up = FALSE; |
648 | screenClick(TRUE); | 648 | screenClick(TRUE); |
649 | } | 649 | } |
650 | } else if ( !up ) { | 650 | } else if ( !up ) { |
651 | up = TRUE; | 651 | up = TRUE; |
652 | screenClick(FALSE); | 652 | screenClick(FALSE); |
653 | } | 653 | } |
654 | } else | 654 | } else |
655 | if ( e->type == QWSEvent::Key ) { | 655 | if ( e->type == QWSEvent::Key ) { |
656 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); | 656 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); |
657 | if ( kf->checkButtonAction( false, | 657 | if ( kf->checkButtonAction( false, |
658 | ke-> simpleData.keycode, | 658 | ke-> simpleData.keycode, |
659 | ke-> simpleData.is_press, | 659 | ke-> simpleData.is_press, |
660 | ke-> simpleData.is_auto_repeat ) ) | 660 | ke-> simpleData.is_auto_repeat ) ) |
661 | return true; | 661 | return true; |
662 | } | 662 | } |
663 | 663 | ||
664 | return QPEApplication::qwsEventFilter( e ); | 664 | return QPEApplication::qwsEventFilter( e ); |
665 | } | 665 | } |
666 | #endif | 666 | #endif |
667 | 667 | ||
668 | 668 | ||
669 | /* ### FIXME libqtopia Plugin Safe Mode */ | 669 | /* ### FIXME libqtopia Plugin Safe Mode */ |
670 | 670 | ||
671 | void ServerApplication::showSafeMode() | 671 | void ServerApplication::showSafeMode() |
672 | { | 672 | { |
673 | #if 0 | 673 | #if 0 |
674 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " | 674 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " |
675 | "and the system is now in Safe Mode. " | 675 | "and the system is now in Safe Mode. " |
676 | "Plugins are not loaded in Safe Mode. " | 676 | "Plugins are not loaded in Safe Mode. " |
677 | "You can use the Plugin Manager to " | 677 | "You can use the Plugin Manager to " |
678 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) | 678 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) |
679 | { | 679 | { |
680 | Global::execute( "pluginmanager" ); | 680 | Global::execute( "pluginmanager" ); |
681 | } | 681 | } |
682 | #endif | 682 | #endif |
683 | } | 683 | } |
684 | 684 | ||
685 | void ServerApplication::clearSafeMode() | 685 | void ServerApplication::clearSafeMode() |
686 | { | 686 | { |
687 | #if 0 | 687 | #if 0 |
688 | // If we've been running OK for a while then we won't bother going into | 688 | // If we've been running OK for a while then we won't bother going into |
689 | // safe mode immediately on the next crash. | 689 | // safe mode immediately on the next crash. |
690 | Config cfg( "PluginLoader" ); | 690 | Config cfg( "PluginLoader" ); |
691 | cfg.setGroup( "Global" ); | 691 | cfg.setGroup( "Global" ); |
692 | QString mode = cfg.readEntry( "Mode", "Normal" ); | 692 | QString mode = cfg.readEntry( "Mode", "Normal" ); |
693 | if ( mode == "MaybeSafe" ) { | 693 | if ( mode == "MaybeSafe" ) { |
694 | cfg.writeEntry( "Mode", "Normal" ); | 694 | cfg.writeEntry( "Mode", "Normal" ); |
695 | } | 695 | } |
696 | #endif | 696 | #endif |
697 | } | 697 | } |
698 | 698 | ||
699 | 699 | ||
700 | void ServerApplication::shutdown() | 700 | void ServerApplication::shutdown() |
701 | { | 701 | { |
702 | if ( type() != GuiServer ) | 702 | if ( type() != GuiServer ) |
703 | return; | 703 | return; |
704 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | 704 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); |
705 | connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), | 705 | connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), |
706 | this, SLOT(shutdown(ShutdownImpl::Type)) ); | 706 | this, SLOT(shutdown(ShutdownImpl::Type)) ); |
707 | QPEApplication::showWidget( sd ); | 707 | QPEApplication::showWidget( sd ); |
708 | } | 708 | } |
709 | 709 | ||
710 | void ServerApplication::shutdown( ShutdownImpl::Type t ) | 710 | void ServerApplication::shutdown( ShutdownImpl::Type t ) |
711 | { | 711 | { |
712 | char *opt = 0; | 712 | char *opt = 0; |
713 | 713 | ||
714 | switch ( t ) { | 714 | switch ( t ) { |
715 | case ShutdownImpl::ShutdownSystem: | 715 | case ShutdownImpl::ShutdownSystem: |
716 | opt = "-h"; | 716 | opt = "-h"; |
717 | // fall through | 717 | // fall through |
718 | case ShutdownImpl::RebootSystem: | 718 | case ShutdownImpl::RebootSystem: |
719 | if ( opt == 0 ) | 719 | if ( opt == 0 ) |
720 | opt = "-r"; | 720 | opt = "-r"; |
721 | 721 | ||
722 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) | 722 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) |
723 | perror("shutdown"); | 723 | perror("shutdown"); |
724 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); | 724 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); |
725 | 725 | ||
726 | break; | 726 | break; |
727 | case ShutdownImpl::RestartDesktop: | 727 | case ShutdownImpl::RestartDesktop: |
728 | restart(); | 728 | restart(); |
729 | break; | 729 | break; |
730 | case ShutdownImpl::TerminateDesktop: | 730 | case ShutdownImpl::TerminateDesktop: |
731 | prepareForTermination( FALSE ); | 731 | prepareForTermination( FALSE ); |
732 | 732 | ||
733 | // This is a workaround for a Qt bug | 733 | // This is a workaround for a Qt bug |
734 | // clipboard applet has to stop its poll timer, or Qt/E | 734 | // clipboard applet has to stop its poll timer, or Qt/E |
735 | // will hang on quit() right before it emits aboutToQuit() | 735 | // will hang on quit() right before it emits aboutToQuit() |
736 | emit aboutToQuit ( ); | 736 | emit aboutToQuit ( ); |
737 | 737 | ||
738 | quit(); | 738 | quit(); |
739 | break; | 739 | break; |
740 | } | 740 | } |
741 | } | 741 | } |
742 | 742 | ||
743 | void ServerApplication::restart() | 743 | void ServerApplication::restart() |
744 | { | 744 | { |
745 | if ( allowRestart ) { | 745 | if ( allowRestart ) { |
746 | 746 | ||
747 | /* | 747 | /* |
748 | * Applets and restart is a problem. Some applets delete | 748 | * Applets and restart is a problem. Some applets delete |
749 | * their widgets even if ownership gets transfered to the | 749 | * their widgets even if ownership gets transfered to the |
750 | * parent (Systray ) but deleting the applet may be unsafe | 750 | * parent (Systray ) but deleting the applet may be unsafe |
751 | * as well ( double deletion ). Some have topLevel widgets | 751 | * as well ( double deletion ). Some have topLevel widgets |
752 | * and when we dlclose and then delete the widget we will | 752 | * and when we dlclose and then delete the widget we will |
753 | * crash and an crash during restart is not nice | 753 | * crash and an crash during restart is not nice |
754 | */ | 754 | */ |
755 | #ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED | 755 | #ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED |
756 | /* same as above */ | 756 | /* same as above */ |
757 | emit aboutToQuit(); | 757 | emit aboutToQuit(); |
758 | prepareForTermination(TRUE); | 758 | prepareForTermination(TRUE); |
759 | doRestart = TRUE; | 759 | doRestart = TRUE; |
760 | quit(); | 760 | quit(); |
761 | #else | 761 | #else |
762 | prepareForTermination( true ); | 762 | prepareForTermination( true ); |
763 | for ( int fd = 3; fd < 100; fd++ ) | 763 | for ( int fd = 3; fd < 100; fd++ ) |
764 | close( fd ); | 764 | close( fd ); |
765 | execl( ( qpeDir() + "/bin/qpe" ).local8Bit(), "qpe", NULL ); | 765 | execl( ( qpeDir() + "/bin/qpe" ).local8Bit(), "qpe", NULL ); |
766 | exit( 1 ); | 766 | exit( 1 ); |
767 | #endif | 767 | #endif |
768 | } | 768 | } |
769 | } | 769 | } |
770 | 770 | ||
771 | void ServerApplication::rereadVolumes() | 771 | void ServerApplication::rereadVolumes() |
772 | { | 772 | { |
773 | Config cfg( "qpe" ); | 773 | Config cfg( "qpe" ); |
774 | cfg. setGroup ( "Volume" ); | 774 | cfg. setGroup ( "Volume" ); |
775 | 775 | ||
776 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); | 776 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); |
777 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); | 777 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); |
778 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); | 778 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); |
779 | } | 779 | } |
780 | 780 | ||
781 | 781 | ||
782 | void ServerApplication::checkMemory() | 782 | void ServerApplication::checkMemory() |
783 | { | 783 | { |
784 | #if defined(QPE_HAVE_MEMALERTER) | 784 | #if defined(QPE_HAVE_MEMALERTER) |
785 | static bool ignoreNormal=TRUE; | 785 | static bool ignoreNormal=TRUE; |
786 | static bool existingMessage=FALSE; | 786 | static bool existingMessage=FALSE; |
787 | 787 | ||
788 | if(existingMessage) | 788 | if(existingMessage) |
789 | return; // don't show a second message while still on first | 789 | return; // don't show a second message while still on first |
790 | 790 | ||
791 | existingMessage = TRUE; | 791 | existingMessage = TRUE; |
792 | switch ( memstate ) { | 792 | switch ( memstate ) { |
793 | case MemUnknown: | 793 | case MemUnknown: |
794 | break; | 794 | break; |
795 | case MemLow: | 795 | case MemLow: |
796 | memstate = MemUnknown; | 796 | memstate = MemUnknown; |
797 | if ( !recoverMemory() ) { | 797 | if ( !recoverMemory() ) { |
798 | QMessageBox::warning( 0 , tr("Memory Status"), | 798 | QMessageBox::warning( 0 , tr("Memory Status"), |
799 | tr("Memory Low\nPlease save data.") ); | 799 | tr("Memory Low\nPlease save data.") ); |
800 | ignoreNormal = FALSE; | 800 | ignoreNormal = FALSE; |
801 | } | 801 | } |
802 | break; | 802 | break; |
803 | case MemNormal: | 803 | case MemNormal: |
804 | memstate = MemUnknown; | 804 | memstate = MemUnknown; |
805 | if ( !ignoreNormal ) { | 805 | if ( !ignoreNormal ) { |
806 | ignoreNormal = TRUE; | 806 | ignoreNormal = TRUE; |
807 | QMessageBox::information ( 0 , tr("Memory Status"), | 807 | QMessageBox::information ( 0 , tr("Memory Status"), |
808 | "Memory OK" ); | 808 | "Memory OK" ); |
809 | } | 809 | } |
810 | break; | 810 | break; |
811 | case MemVeryLow: | 811 | case MemVeryLow: |
812 | memstate = MemUnknown; | 812 | memstate = MemUnknown; |
813 | QMessageBox::critical( 0 , tr("Memory Status"), | 813 | QMessageBox::critical( 0 , tr("Memory Status"), |
814 | tr("Critical Memory Shortage\n" | 814 | tr("Critical Memory Shortage\n" |
815 | "Please end this application\n" | 815 | "Please end this application\n" |
816 | "immediately.") ); | 816 | "immediately.") ); |
817 | recoverMemory(); | 817 | recoverMemory(); |
818 | } | 818 | } |
819 | existingMessage = FALSE; | 819 | existingMessage = FALSE; |
820 | #endif | 820 | #endif |
821 | } | 821 | } |
822 | 822 | ||
823 | bool ServerApplication::recoverMemory() | 823 | bool ServerApplication::recoverMemory() |
824 | { | 824 | { |
825 | return FALSE; | 825 | return FALSE; |
826 | } | 826 | } |
827 | 827 | ||
828 | void ServerApplication::keyClick(int , bool press, bool ) | 828 | void ServerApplication::keyClick(int , bool press, bool ) |
829 | { | 829 | { |
830 | if ( press && m_keyclick_sound ) | 830 | if ( press && m_keyclick_sound ) |
831 | ODevice::inst() -> playKeySound(); | 831 | ODevice::inst() -> playKeySound(); |
832 | 832 | ||
833 | } | 833 | } |
834 | 834 | ||
835 | void ServerApplication::screenClick(bool press) | 835 | void ServerApplication::screenClick(bool press) |
836 | { | 836 | { |
837 | if ( press && m_screentap_sound ) | 837 | if ( press && m_screentap_sound ) |
838 | ODevice::inst() -> playTouchSound(); | 838 | ODevice::inst() -> playTouchSound(); |
839 | } | 839 | } |
840 | 840 | ||
841 | void ServerApplication::soundAlarm() { | 841 | void ServerApplication::soundAlarm() { |
842 | if ( me ()->m_alarm_sound ) | 842 | if ( me ()->m_alarm_sound ) |
843 | ODevice::inst()->playAlarmSound(); | 843 | ODevice::inst()->playAlarmSound(); |
844 | } | 844 | } |
845 | 845 | ||
846 | ServerApplication *ServerApplication::me ( ) | 846 | ServerApplication *ServerApplication::me ( ) |
847 | { | 847 | { |
848 | return static_cast<ServerApplication*>( qApp ); | 848 | return static_cast<ServerApplication*>( qApp ); |
849 | } | 849 | } |
850 | 850 | ||
851 | bool ServerApplication::isStarting() | 851 | bool ServerApplication::isStarting() |
852 | { | 852 | { |
853 | return ms_is_starting; | 853 | return ms_is_starting; |
854 | } | 854 | } |
855 | 855 | ||
856 | int ServerApplication::exec() | 856 | int ServerApplication::exec() |
857 | { | 857 | { |
858 | ms_is_starting = true; | 858 | ms_is_starting = true; |
859 | odebug << "Serverapp - exec" << oendl; | 859 | odebug << "Serverapp - exec" << oendl; |
860 | return QPEApplication::exec(); | 860 | return QPEApplication::exec(); |
861 | } | 861 | } |
862 | 862 | ||
863 | #include "serverapp.moc" | 863 | #include "serverapp.moc" |