author | groucho <groucho> | 2003-03-22 09:21:03 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-03-22 09:21:03 (UTC) |
commit | f462ccd5ad11da7bddfa627d4773e3b02f18e2b8 (patch) (unidiff) | |
tree | ba1250690fe416d01802059117107391fecb0d88 | |
parent | 32458f9d70e8b13a7e8ff46c06af17860c218f23 (diff) | |
download | opie-f462ccd5ad11da7bddfa627d4773e3b02f18e2b8.zip opie-f462ccd5ad11da7bddfa627d4773e3b02f18e2b8.tar.gz opie-f462ccd5ad11da7bddfa627d4773e3b02f18e2b8.tar.bz2 |
Bug fix- Key presess are now routed up to the QPEApplication event queue if ignore is defined for a certain key
-rw-r--r-- | core/launcher/desktop.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index fbcce7c..86527f6 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -1,858 +1,861 @@ | |||
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 <syslog.h> | 21 | #include <syslog.h> |
22 | 22 | ||
23 | #include "desktop.h" | 23 | #include "desktop.h" |
24 | #include "info.h" | 24 | #include "info.h" |
25 | #include "launcher.h" | 25 | #include "launcher.h" |
26 | #include "qcopbridge.h" | 26 | #include "qcopbridge.h" |
27 | #include "shutdownimpl.h" | 27 | #include "shutdownimpl.h" |
28 | #include "startmenu.h" | 28 | #include "startmenu.h" |
29 | #include "taskbar.h" | 29 | #include "taskbar.h" |
30 | #include "transferserver.h" | 30 | #include "transferserver.h" |
31 | #include "irserver.h" | 31 | #include "irserver.h" |
32 | #include "packageslave.h" | 32 | #include "packageslave.h" |
33 | #include "screensaver.h" | 33 | #include "screensaver.h" |
34 | 34 | ||
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | #include <qpe/mimetype.h> | 36 | #include <qpe/mimetype.h> |
37 | #include <qpe/password.h> | 37 | #include <qpe/password.h> |
38 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
39 | #include <qpe/power.h> | 39 | #include <qpe/power.h> |
40 | #include <qpe/timeconversion.h> | 40 | #include <qpe/timeconversion.h> |
41 | #include <qpe/qcopenvelope_qws.h> | 41 | #include <qpe/qcopenvelope_qws.h> |
42 | #include <qpe/network.h> | 42 | #include <qpe/network.h> |
43 | #include <qpe/global.h> | 43 | #include <qpe/global.h> |
44 | 44 | ||
45 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) | 45 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) |
46 | #include <qpe/custom.h> | 46 | #include <qpe/custom.h> |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #include <opie/odevice.h> | 49 | #include <opie/odevice.h> |
50 | 50 | ||
51 | #include <qgfx_qws.h> | 51 | #include <qgfx_qws.h> |
52 | #include <qmainwindow.h> | 52 | #include <qmainwindow.h> |
53 | #include <qmessagebox.h> | 53 | #include <qmessagebox.h> |
54 | #include <qtimer.h> | 54 | #include <qtimer.h> |
55 | #include <qwindowsystem_qws.h> | 55 | #include <qwindowsystem_qws.h> |
56 | 56 | ||
57 | #include <qvaluelist.h> | 57 | #include <qvaluelist.h> |
58 | 58 | ||
59 | #include <stdlib.h> | 59 | #include <stdlib.h> |
60 | #include <unistd.h> | 60 | #include <unistd.h> |
61 | #include <fcntl.h> | 61 | #include <fcntl.h> |
62 | 62 | ||
63 | 63 | ||
64 | using namespace Opie; | 64 | using namespace Opie; |
65 | 65 | ||
66 | class QCopKeyRegister | 66 | class QCopKeyRegister |
67 | { | 67 | { |
68 | public: | 68 | public: |
69 | QCopKeyRegister() : keyCode( 0 ) | 69 | QCopKeyRegister() : keyCode( 0 ) |
70 | { } | 70 | { } |
71 | QCopKeyRegister( int k, const QCString &c, const QCString &m ) | 71 | QCopKeyRegister( int k, const QCString &c, const QCString &m ) |
72 | : keyCode( k ), channel( c ), message( m ) | 72 | : keyCode( k ), channel( c ), message( m ) |
73 | { } | 73 | { } |
74 | 74 | ||
75 | int getKeyCode() const | 75 | int getKeyCode() const |
76 | { | 76 | { |
77 | return keyCode; | 77 | return keyCode; |
78 | } | 78 | } |
79 | QCString getChannel() const | 79 | QCString getChannel() const |
80 | { | 80 | { |
81 | return channel; | 81 | return channel; |
82 | } | 82 | } |
83 | QCString getMessage() const | 83 | QCString getMessage() const |
84 | { | 84 | { |
85 | return message; | 85 | return message; |
86 | } | 86 | } |
87 | 87 | ||
88 | private: | 88 | private: |
89 | int keyCode; | 89 | int keyCode; |
90 | QCString channel, message; | 90 | QCString channel, message; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | typedef QValueList<QCopKeyRegister> KeyRegisterList; | 93 | typedef QValueList<QCopKeyRegister> KeyRegisterList; |
94 | KeyRegisterList keyRegisterList; | 94 | KeyRegisterList keyRegisterList; |
95 | 95 | ||
96 | static Desktop* qpedesktop = 0; | 96 | static Desktop* qpedesktop = 0; |
97 | static int loggedin = 0; | 97 | static int loggedin = 0; |
98 | static void login( bool at_poweron ) | 98 | static void login( bool at_poweron ) |
99 | { | 99 | { |
100 | if ( !loggedin ) { | 100 | if ( !loggedin ) { |
101 | Global::terminateBuiltin( "calibrate" ); | 101 | Global::terminateBuiltin( "calibrate" ); |
102 | Password::authenticate( at_poweron ); | 102 | Password::authenticate( at_poweron ); |
103 | loggedin = 1; | 103 | loggedin = 1; |
104 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 104 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | bool Desktop::screenLocked() | 108 | bool Desktop::screenLocked() |
109 | { | 109 | { |
110 | return loggedin == 0; | 110 | return loggedin == 0; |
111 | } | 111 | } |
112 | 112 | ||
113 | /* | 113 | /* |
114 | Priority is number of alerts that are needed to pop up | 114 | Priority is number of alerts that are needed to pop up |
115 | alert. | 115 | alert. |
116 | */ | 116 | */ |
117 | class DesktopPowerAlerter : public QMessageBox | 117 | class DesktopPowerAlerter : public QMessageBox |
118 | { | 118 | { |
119 | public: | 119 | public: |
120 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 120 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
121 | : QMessageBox( tr( "Battery Status" ), "Low Battery", | 121 | : QMessageBox( tr( "Battery Status" ), "Low Battery", |
122 | QMessageBox::Critical, | 122 | QMessageBox::Critical, |
123 | QMessageBox::Ok | QMessageBox::Default, | 123 | QMessageBox::Ok | QMessageBox::Default, |
124 | QMessageBox::NoButton, QMessageBox::NoButton, | 124 | QMessageBox::NoButton, QMessageBox::NoButton, |
125 | parent, name, FALSE ) | 125 | parent, name, FALSE ) |
126 | { | 126 | { |
127 | currentPriority = INT_MAX; | 127 | currentPriority = INT_MAX; |
128 | alertCount = 0; | 128 | alertCount = 0; |
129 | } | 129 | } |
130 | 130 | ||
131 | void alert( const QString &text, int priority ); | 131 | void alert( const QString &text, int priority ); |
132 | void hideEvent( QHideEvent * ); | 132 | void hideEvent( QHideEvent * ); |
133 | private: | 133 | private: |
134 | int currentPriority; | 134 | int currentPriority; |
135 | int alertCount; | 135 | int alertCount; |
136 | }; | 136 | }; |
137 | 137 | ||
138 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 138 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
139 | { | 139 | { |
140 | alertCount++; | 140 | alertCount++; |
141 | if ( alertCount < priority ) | 141 | if ( alertCount < priority ) |
142 | return ; | 142 | return ; |
143 | if ( priority > currentPriority ) | 143 | if ( priority > currentPriority ) |
144 | return ; | 144 | return ; |
145 | currentPriority = priority; | 145 | currentPriority = priority; |
146 | setText( text ); | 146 | setText( text ); |
147 | show(); | 147 | show(); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 151 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
152 | { | 152 | { |
153 | QMessageBox::hideEvent( e ); | 153 | QMessageBox::hideEvent( e ); |
154 | alertCount = 0; | 154 | alertCount = 0; |
155 | currentPriority = INT_MAX; | 155 | currentPriority = INT_MAX; |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | void DesktopApplication::switchLCD ( bool on ) | 159 | void DesktopApplication::switchLCD ( bool on ) |
160 | { | 160 | { |
161 | if ( qApp ) { | 161 | if ( qApp ) { |
162 | DesktopApplication *dapp = (DesktopApplication *) qApp; | 162 | DesktopApplication *dapp = (DesktopApplication *) qApp; |
163 | 163 | ||
164 | if ( dapp-> m_screensaver ) { | 164 | if ( dapp-> m_screensaver ) { |
165 | if ( on ) { | 165 | if ( on ) { |
166 | dapp-> m_screensaver-> setDisplayState ( true ); | 166 | dapp-> m_screensaver-> setDisplayState ( true ); |
167 | dapp-> m_screensaver-> setBacklight ( -3 ); | 167 | dapp-> m_screensaver-> setBacklight ( -3 ); |
168 | } | 168 | } |
169 | else { | 169 | else { |
170 | dapp-> m_screensaver-> setDisplayState ( false ); | 170 | dapp-> m_screensaver-> setDisplayState ( false ); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | 177 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) |
178 | : QPEApplication( argc, argv, appType ) | 178 | : QPEApplication( argc, argv, appType ) |
179 | { | 179 | { |
180 | m_ps = new PowerStatus; | 180 | m_ps = new PowerStatus; |
181 | m_ps_last = new PowerStatus; | 181 | m_ps_last = new PowerStatus; |
182 | pa = new DesktopPowerAlerter( 0 ); | 182 | pa = new DesktopPowerAlerter( 0 ); |
183 | 183 | ||
184 | m_apm_timer = new QTimer ( this ); | 184 | m_apm_timer = new QTimer ( this ); |
185 | connect ( m_apm_timer, SIGNAL( timeout ( )), this, SLOT( apmTimeout ( ))); | 185 | connect ( m_apm_timer, SIGNAL( timeout ( )), this, SLOT( apmTimeout ( ))); |
186 | reloadPowerWarnSettings ( ); | 186 | reloadPowerWarnSettings ( ); |
187 | 187 | ||
188 | m_last_button = 0; | 188 | m_last_button = 0; |
189 | m_button_timer = new QTimer ( ); | 189 | m_button_timer = new QTimer ( ); |
190 | connect ( m_button_timer, SIGNAL( timeout ( )), this, SLOT( sendHeldAction ( ))); | 190 | connect ( m_button_timer, SIGNAL( timeout ( )), this, SLOT( sendHeldAction ( ))); |
191 | 191 | ||
192 | channel = new QCopChannel( "QPE/System", this ); | 192 | channel = new QCopChannel( "QPE/System", this ); |
193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
194 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 194 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); |
195 | 195 | ||
196 | channel = new QCopChannel( "QPE/Launcher", this ); | 196 | channel = new QCopChannel( "QPE/Launcher", this ); |
197 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 197 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
198 | this, SLOT( launcherMessage( const QCString&, const QByteArray& ) ) ); | 198 | this, SLOT( launcherMessage( const QCString&, const QByteArray& ) ) ); |
199 | 199 | ||
200 | m_screensaver = new OpieScreenSaver ( ); | 200 | m_screensaver = new OpieScreenSaver ( ); |
201 | m_screensaver-> setInterval ( -1 ); | 201 | m_screensaver-> setInterval ( -1 ); |
202 | QWSServer::setScreenSaver( m_screensaver ); | 202 | QWSServer::setScreenSaver( m_screensaver ); |
203 | 203 | ||
204 | rereadVolumes(); | 204 | rereadVolumes(); |
205 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); | 205 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); |
206 | 206 | ||
207 | apmTimeout ( ); | 207 | apmTimeout ( ); |
208 | 208 | ||
209 | grabKeyboard ( ); | 209 | grabKeyboard ( ); |
210 | } | 210 | } |
211 | 211 | ||
212 | 212 | ||
213 | DesktopApplication::~DesktopApplication() | 213 | DesktopApplication::~DesktopApplication() |
214 | { | 214 | { |
215 | ungrabKeyboard ( ); | 215 | ungrabKeyboard ( ); |
216 | 216 | ||
217 | delete m_ps; | 217 | delete m_ps; |
218 | delete m_ps_last; | 218 | delete m_ps_last; |
219 | delete pa; | 219 | delete pa; |
220 | } | 220 | } |
221 | 221 | ||
222 | void DesktopApplication::apmTimeout() | 222 | void DesktopApplication::apmTimeout() |
223 | { | 223 | { |
224 | qpedesktop-> checkMemory ( ); // in case no events are being generated | 224 | qpedesktop-> checkMemory ( ); // in case no events are being generated |
225 | 225 | ||
226 | *m_ps_last = *m_ps; | 226 | *m_ps_last = *m_ps; |
227 | *m_ps = PowerStatusManager::readStatus(); | 227 | *m_ps = PowerStatusManager::readStatus(); |
228 | 228 | ||
229 | if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) | 229 | if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) |
230 | m_screensaver-> powerStatusChanged ( *m_ps ); | 230 | m_screensaver-> powerStatusChanged ( *m_ps ); |
231 | 231 | ||
232 | if ( m_ps-> acStatus ( ) != PowerStatus::Online ) { | 232 | if ( m_ps-> acStatus ( ) != PowerStatus::Online ) { |
233 | int bat = m_ps-> batteryPercentRemaining ( ); | 233 | int bat = m_ps-> batteryPercentRemaining ( ); |
234 | 234 | ||
235 | if ( bat < m_ps_last-> batteryPercentRemaining ( )) { | 235 | if ( bat < m_ps_last-> batteryPercentRemaining ( )) { |
236 | if ( bat <= m_powerCritical ) | 236 | if ( bat <= m_powerCritical ) |
237 | pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); | 237 | pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); |
238 | else if ( bat <= m_powerVeryLow ) | 238 | else if ( bat <= m_powerVeryLow ) |
239 | pa->alert( tr( "Battery is running very low." ), 2 ); | 239 | pa->alert( tr( "Battery is running very low." ), 2 ); |
240 | } | 240 | } |
241 | if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) | 241 | if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) |
242 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); | 242 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) | 247 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) |
248 | { | 248 | { |
249 | QDataStream stream ( data, IO_ReadOnly ); | 249 | QDataStream stream ( data, IO_ReadOnly ); |
250 | 250 | ||
251 | if ( msg == "setScreenSaverInterval(int)" ) { | 251 | if ( msg == "setScreenSaverInterval(int)" ) { |
252 | int time; | 252 | int time; |
253 | stream >> time; | 253 | stream >> time; |
254 | m_screensaver-> setInterval( time ); | 254 | m_screensaver-> setInterval( time ); |
255 | } | 255 | } |
256 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 256 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
257 | int t1, t2, t3; | 257 | int t1, t2, t3; |
258 | stream >> t1 >> t2 >> t3; | 258 | stream >> t1 >> t2 >> t3; |
259 | m_screensaver-> setIntervals( t1, t2, t3 ); | 259 | m_screensaver-> setIntervals( t1, t2, t3 ); |
260 | } | 260 | } |
261 | else if ( msg == "setBacklight(int)" ) { | 261 | else if ( msg == "setBacklight(int)" ) { |
262 | int bright; | 262 | int bright; |
263 | stream >> bright; | 263 | stream >> bright; |
264 | m_screensaver-> setBacklight( bright ); | 264 | m_screensaver-> setBacklight( bright ); |
265 | } | 265 | } |
266 | else if ( msg == "setScreenSaverMode(int)" ) { | 266 | else if ( msg == "setScreenSaverMode(int)" ) { |
267 | int mode; | 267 | int mode; |
268 | stream >> mode; | 268 | stream >> mode; |
269 | m_screensaver-> setMode ( mode ); | 269 | m_screensaver-> setMode ( mode ); |
270 | } | 270 | } |
271 | else if ( msg == "reloadPowerWarnSettings()" ) { | 271 | else if ( msg == "reloadPowerWarnSettings()" ) { |
272 | reloadPowerWarnSettings(); | 272 | reloadPowerWarnSettings(); |
273 | } | 273 | } |
274 | else if ( msg == "setDisplayState(int)" ) { | 274 | else if ( msg == "setDisplayState(int)" ) { |
275 | int state; | 275 | int state; |
276 | stream >> state; | 276 | stream >> state; |
277 | m_screensaver-> setDisplayState ( state != 0 ); | 277 | m_screensaver-> setDisplayState ( state != 0 ); |
278 | } | 278 | } |
279 | else if ( msg == "suspend()" ) { | 279 | else if ( msg == "suspend()" ) { |
280 | emit power(); | 280 | emit power(); |
281 | } | 281 | } |
282 | else if ( msg == "sendBusinessCard()" ) { | 282 | else if ( msg == "sendBusinessCard()" ) { |
283 | QString card = ::getenv ( "HOME" ); | 283 | QString card = ::getenv ( "HOME" ); |
284 | card += "/Applications/addressbook/businesscard.vcf"; | 284 | card += "/Applications/addressbook/businesscard.vcf"; |
285 | 285 | ||
286 | if ( QFile::exists( card ) ) { | 286 | if ( QFile::exists( card ) ) { |
287 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); | 287 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); |
288 | QString mimetype = "text/x-vCard"; | 288 | QString mimetype = "text/x-vCard"; |
289 | e << tr( "business card" ) << card << mimetype; | 289 | e << tr( "business card" ) << card << mimetype; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | } | 292 | } |
293 | 293 | ||
294 | void DesktopApplication::reloadPowerWarnSettings ( ) | 294 | void DesktopApplication::reloadPowerWarnSettings ( ) |
295 | { | 295 | { |
296 | Config cfg ( "apm" ); | 296 | Config cfg ( "apm" ); |
297 | cfg. setGroup ( "Warnings" ); | 297 | cfg. setGroup ( "Warnings" ); |
298 | 298 | ||
299 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); | 299 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); |
300 | 300 | ||
301 | m_apm_timer-> stop ( ); | 301 | m_apm_timer-> stop ( ); |
302 | if ( iv ) | 302 | if ( iv ) |
303 | m_apm_timer-> start ( iv ); | 303 | m_apm_timer-> start ( iv ); |
304 | 304 | ||
305 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); | 305 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); |
306 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); | 306 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; | 310 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; |
311 | 311 | ||
312 | 312 | ||
313 | void DesktopApplication::launcherMessage( const QCString & msg, const QByteArray & data ) | 313 | void DesktopApplication::launcherMessage( const QCString & msg, const QByteArray & data ) |
314 | { | 314 | { |
315 | QDataStream stream ( data, IO_ReadOnly ); | 315 | QDataStream stream ( data, IO_ReadOnly ); |
316 | 316 | ||
317 | if ( msg == "deviceButton(int,int,int)" ) { | 317 | if ( msg == "deviceButton(int,int,int)" ) { |
318 | int keycode, press, autoRepeat; | 318 | int keycode, press, autoRepeat; |
319 | stream >> keycode >> press >> autoRepeat; | 319 | stream >> keycode >> press >> autoRepeat; |
320 | 320 | ||
321 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( keycode ); | 321 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( keycode ); |
322 | 322 | ||
323 | if ( db ) | 323 | if ( db ) |
324 | checkButtonAction ( db, keycode, press, autoRepeat ); | 324 | checkButtonAction ( db, keycode, press, autoRepeat ); |
325 | } | 325 | } |
326 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { | 326 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { |
327 | int k; | 327 | int k; |
328 | QCString c, m; | 328 | QCString c, m; |
329 | stream >> k >> c >> m; | 329 | stream >> k >> c >> m; |
330 | 330 | ||
331 | keyRegisterList.append ( QCopKeyRegister ( k, c, m )); | 331 | keyRegisterList.append ( QCopKeyRegister ( k, c, m )); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | void DesktopApplication::sendHeldAction ( ) | 335 | void DesktopApplication::sendHeldAction ( ) |
336 | { | 336 | { |
337 | if ( m_last_button ) { | 337 | if ( m_last_button ) { |
338 | m_last_button-> heldAction ( ). send ( ); | 338 | m_last_button-> heldAction ( ). send ( ); |
339 | m_last_button = 0; | 339 | m_last_button = 0; |
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
343 | 343 | ||
344 | 344 | ||
345 | bool DesktopApplication::checkButtonAction ( const ODeviceButton *db, int /*keycode*/, bool press, bool autoRepeat ) | 345 | bool DesktopApplication::checkButtonAction ( const ODeviceButton *db, int /*keycode*/, bool press, bool autoRepeat ) |
346 | { | 346 | { |
347 | if ( db ) { | 347 | if ( db ) { |
348 | if ( !press && !autoRepeat && m_button_timer-> isActive ( )) { | 348 | if ( !press && !autoRepeat && m_button_timer-> isActive ( )) { |
349 | m_button_timer-> stop ( ); | 349 | m_button_timer-> stop ( ); |
350 | 350 | ||
351 | if (!db-> pressedAction ( ). channel ( ) .isEmpty()) | 351 | if (!db-> pressedAction ( ). channel ( ) .isEmpty()) |
352 | { | 352 | { |
353 | |||
353 | if ( db-> pressedAction ( ). channel ( )!="ignore") { | 354 | if ( db-> pressedAction ( ). channel ( )!="ignore") { |
355 | |||
354 | db-> pressedAction ( ). send ( ); | 356 | db-> pressedAction ( ). send ( ); |
355 | } | 357 | } |
356 | else return false; | 358 | else |
359 | return false; | ||
357 | } | 360 | } |
358 | } | 361 | } |
359 | else if ( press && !autoRepeat ) { | 362 | else if ( press && !autoRepeat ) { |
360 | m_button_timer-> stop ( ); | 363 | m_button_timer-> stop ( ); |
361 | if (!db-> pressedAction ( ). channel ( ) .isEmpty()) | 364 | if (!db-> pressedAction ( ). channel ( ) .isEmpty()) |
362 | { | 365 | { |
363 | 366 | ||
364 | if ( db-> heldAction ( ). channel ( )!="ignore") { | 367 | if ( db-> heldAction ( ). channel ( )!="ignore") { |
365 | m_last_button = db; | 368 | m_last_button = db; |
366 | m_button_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true ); | 369 | m_button_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true ); |
367 | } | 370 | } |
368 | else return false; | 371 | else return false; |
369 | } | 372 | } |
370 | } | 373 | } |
371 | } | 374 | } |
372 | return true; | 375 | return true; |
373 | } | 376 | } |
374 | 377 | ||
375 | bool DesktopApplication::eventFilter ( QObject *o, QEvent *e ) | 378 | bool DesktopApplication::eventFilter ( QObject *o, QEvent *e ) |
376 | { | 379 | { |
380 | |||
377 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { | 381 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { |
378 | QKeyEvent *ke = (QKeyEvent *) e; | 382 | QKeyEvent *ke = (QKeyEvent *) e; |
379 | 383 | ||
380 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); | 384 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); |
381 | 385 | ||
382 | if ( db ) { | 386 | if ( db ) { |
383 | return checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( )); | 387 | if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) |
388 | return true; //checkButtonAction retrune false if events should be routed through | ||
384 | } | 389 | } |
385 | } | 390 | } |
386 | return QPEApplication::eventFilter ( o, e ); | 391 | return QPEApplication::eventFilter ( o, e ); |
387 | } | 392 | } |
388 | 393 | ||
389 | #ifdef Q_WS_QWS | 394 | #ifdef Q_WS_QWS |
390 | 395 | ||
391 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | 396 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) |
392 | { | 397 | { |
393 | qpedesktop->checkMemory(); | 398 | qpedesktop->checkMemory(); |
394 | 399 | ||
395 | if ( e->type == QWSEvent::Key ) { | 400 | if ( e->type == QWSEvent::Key ) { |
396 | QWSKeyEvent * ke = (QWSKeyEvent *) e; | 401 | QWSKeyEvent * ke = (QWSKeyEvent *) e; |
397 | ushort keycode = ke-> simpleData. keycode; | 402 | ushort keycode = ke-> simpleData. keycode; |
398 | 403 | ||
399 | if ( !loggedin && keycode != Key_F34 ) | 404 | if ( !loggedin && keycode != Key_F34 ) |
400 | return true; | 405 | return true; |
401 | 406 | ||
402 | bool press = ke-> simpleData. is_press; | 407 | bool press = ke-> simpleData. is_press; |
403 | bool autoRepeat = ke-> simpleData. is_auto_repeat; | 408 | bool autoRepeat = ke-> simpleData. is_auto_repeat; |
404 | 409 | ||
405 | if ( !keyboardGrabbed ( )) { | 410 | if ( !keyboardGrabbed ( )) { |
406 | // app that registers key/message to be sent back to the app, when it doesn't have focus, | 411 | // app that registers key/message to be sent back to the app, when it doesn't have focus, |
407 | // when user presses key, unless keyboard has been requested from app. | 412 | // when user presses key, unless keyboard has been requested from app. |
408 | // will not send multiple repeats if user holds key | 413 | // will not send multiple repeats if user holds key |
409 | // i.e. one shot | 414 | // i.e. one shot |
410 | 415 | ||
411 | if ( keycode != 0 && press && !autoRepeat ) { | 416 | if ( keycode != 0 && press && !autoRepeat ) { |
412 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | 417 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { |
413 | if (( *it ). getKeyCode ( ) == keycode ) { | 418 | if (( *it ). getKeyCode ( ) == keycode ) { |
414 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); | 419 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); |
415 | return true; | 420 | return true; |
416 | } | 421 | } |
417 | } | 422 | } |
418 | } | 423 | } |
419 | } | 424 | } |
420 | 425 | ||
421 | if ( keycode == HardKey_Suspend ) { | 426 | if ( keycode == HardKey_Suspend ) { |
422 | if ( press ) | 427 | if ( press ) |
423 | emit power ( ); | 428 | emit power ( ); |
424 | return true; | 429 | return true; |
425 | } | 430 | } |
426 | else if ( keycode == HardKey_Backlight ) { | 431 | else if ( keycode == HardKey_Backlight ) { |
427 | if ( press ) | 432 | if ( press ) |
428 | emit backlight ( ); | 433 | emit backlight ( ); |
429 | return true; | 434 | return true; |
430 | } | 435 | } |
431 | else if ( keycode == Key_F32 ) { | 436 | else if ( keycode == Key_F32 ) { |
432 | if ( press ) | 437 | if ( press ) |
433 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 438 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
434 | return true; | 439 | return true; |
435 | } | 440 | } |
436 | else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM | 441 | else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM |
437 | if ( press ) | 442 | if ( press ) |
438 | emit symbol ( ); | 443 | emit symbol ( ); |
439 | return true; | 444 | return true; |
440 | } | 445 | } |
441 | else if ( keycode == Key_NumLock ) { | 446 | else if ( keycode == Key_NumLock ) { |
442 | if ( press ) | 447 | if ( press ) |
443 | emit numLockStateToggle ( ); | 448 | emit numLockStateToggle ( ); |
444 | } | 449 | } |
445 | else if ( keycode == Key_CapsLock ) { | 450 | else if ( keycode == Key_CapsLock ) { |
446 | if ( press ) | 451 | if ( press ) |
447 | emit capsLockStateToggle(); | 452 | emit capsLockStateToggle(); |
448 | } | 453 | } |
449 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { | 454 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { |
450 | if ( m_keyclick_sound ) | 455 | if ( m_keyclick_sound ) |
451 | ODevice::inst ( )-> keySound ( ); | 456 | ODevice::inst ( )-> keySound ( ); |
452 | } | 457 | } |
453 | } | 458 | } |
454 | else if ( e-> type == QWSEvent::Mouse ) { | 459 | else if ( e-> type == QWSEvent::Mouse ) { |
455 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; | 460 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; |
456 | static bool up = true; | 461 | static bool up = true; |
457 | 462 | ||
458 | if ( me-> simpleData. state & LeftButton ) { | 463 | if ( me-> simpleData. state & LeftButton ) { |
459 | if ( up ) { | 464 | if ( up ) { |
460 | up = false; | 465 | up = false; |
461 | if ( m_screentap_sound ) | 466 | if ( m_screentap_sound ) |
462 | ODevice::inst ( ) -> touchSound ( ); | 467 | ODevice::inst ( ) -> touchSound ( ); |
463 | } | 468 | } |
464 | } | 469 | } |
465 | else { | 470 | else { |
466 | up = true; | 471 | up = true; |
467 | } | 472 | } |
468 | } | 473 | } |
469 | 474 | ||
470 | return QPEApplication::qwsEventFilter ( e ); | 475 | return QPEApplication::qwsEventFilter ( e ); |
471 | } | 476 | } |
472 | #endif | 477 | #endif |
473 | 478 | ||
474 | 479 | ||
475 | 480 | ||
476 | #if defined(QPE_HAVE_MEMALERTER) | 481 | #if defined(QPE_HAVE_MEMALERTER) |
477 | QPE_MEMALERTER_IMPL | 482 | QPE_MEMALERTER_IMPL |
478 | #endif | 483 | #endif |
479 | 484 | ||
480 | //=========================================================================== | 485 | //=========================================================================== |
481 | 486 | ||
482 | Desktop::Desktop() : | 487 | Desktop::Desktop() : |
483 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | 488 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), |
484 | qcopBridge( 0 ), | 489 | qcopBridge( 0 ), |
485 | transferServer( 0 ), | 490 | transferServer( 0 ), |
486 | packageSlave( 0 ) | 491 | packageSlave( 0 ) |
487 | { | 492 | { |
488 | qpedesktop = this; | 493 | qpedesktop = this; |
489 | 494 | ||
490 | // bg = new Info( this ); | 495 | // bg = new Info( this ); |
491 | tb = new TaskBar; | 496 | tb = new TaskBar; |
492 | 497 | ||
493 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); | 498 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); |
494 | 499 | ||
495 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); | 500 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); |
496 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); | 501 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); |
497 | 502 | ||
498 | int displayw = qApp->desktop() ->width(); | 503 | int displayw = qApp->desktop() ->width(); |
499 | int displayh = qApp->desktop() ->height(); | 504 | int displayh = qApp->desktop() ->height(); |
500 | 505 | ||
501 | 506 | ||
502 | QSize sz = tb->sizeHint(); | 507 | QSize sz = tb->sizeHint(); |
503 | 508 | ||
504 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 509 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
505 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 510 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
506 | 511 | ||
507 | tb->show(); | 512 | tb->show(); |
508 | launcher->showMaximized(); | 513 | launcher->showMaximized(); |
509 | launcher->show(); | 514 | launcher->show(); |
510 | launcher->raise(); | 515 | launcher->raise(); |
511 | #if defined(QPE_HAVE_MEMALERTER) | 516 | #if defined(QPE_HAVE_MEMALERTER) |
512 | 517 | ||
513 | initMemalerter(); | 518 | initMemalerter(); |
514 | #endif | 519 | #endif |
515 | // start services | 520 | // start services |
516 | startTransferServer(); | 521 | startTransferServer(); |
517 | ( void ) new IrServer( this ); | 522 | ( void ) new IrServer( this ); |
518 | 523 | ||
519 | packageSlave = new PackageSlave( this ); | 524 | packageSlave = new PackageSlave( this ); |
520 | 525 | ||
521 | qApp->installEventFilter( this ); | 526 | qApp->installEventFilter( this ); |
522 | 527 | ||
523 | qApp-> setMainWidget ( launcher ); | 528 | qApp-> setMainWidget ( launcher ); |
524 | } | 529 | } |
525 | 530 | ||
526 | void Desktop::show() | 531 | void Desktop::show() |
527 | { | 532 | { |
528 | login( TRUE ); | 533 | login( TRUE ); |
529 | QWidget::show(); | 534 | QWidget::show(); |
530 | } | 535 | } |
531 | 536 | ||
532 | Desktop::~Desktop() | 537 | Desktop::~Desktop() |
533 | { | 538 | { |
534 | delete launcher; | 539 | delete launcher; |
535 | delete tb; | 540 | delete tb; |
536 | delete qcopBridge; | 541 | delete qcopBridge; |
537 | delete transferServer; | 542 | delete transferServer; |
538 | } | 543 | } |
539 | 544 | ||
540 | bool Desktop::recoverMemory() | 545 | bool Desktop::recoverMemory() |
541 | { | 546 | { |
542 | return tb->recoverMemory(); | 547 | return tb->recoverMemory(); |
543 | } | 548 | } |
544 | 549 | ||
545 | void Desktop::checkMemory() | 550 | void Desktop::checkMemory() |
546 | { | 551 | { |
547 | #if defined(QPE_HAVE_MEMALERTER) | 552 | #if defined(QPE_HAVE_MEMALERTER) |
548 | static bool ignoreNormal = FALSE; | 553 | static bool ignoreNormal = FALSE; |
549 | static bool existingMessage = FALSE; | 554 | static bool existingMessage = FALSE; |
550 | 555 | ||
551 | if ( existingMessage ) | 556 | if ( existingMessage ) |
552 | return ; // don't show a second message while still on first | 557 | return ; // don't show a second message while still on first |
553 | 558 | ||
554 | existingMessage = TRUE; | 559 | existingMessage = TRUE; |
555 | switch ( memstate ) { | 560 | switch ( memstate ) { |
556 | case Unknown: | 561 | case Unknown: |
557 | break; | 562 | break; |
558 | case Low: | 563 | case Low: |
559 | memstate = Unknown; | 564 | memstate = Unknown; |
560 | if ( recoverMemory() ) | 565 | if ( recoverMemory() ) |
561 | ignoreNormal = TRUE; | 566 | ignoreNormal = TRUE; |
562 | else | 567 | else |
563 | QMessageBox::warning( 0 , "Memory Status", | 568 | QMessageBox::warning( 0 , "Memory Status", |
564 | "The memory smacks of shortage. \n" | 569 | "The memory smacks of shortage. \n" |
565 | "Please save data. " ); | 570 | "Please save data. " ); |
566 | break; | 571 | break; |
567 | case Normal: | 572 | case Normal: |
568 | memstate = Unknown; | 573 | memstate = Unknown; |
569 | if ( ignoreNormal ) | 574 | if ( ignoreNormal ) |
570 | ignoreNormal = FALSE; | 575 | ignoreNormal = FALSE; |
571 | // else | 576 | // else |
572 | // QMessageBox::information ( 0 , "Memory Status", | 577 | // QMessageBox::information ( 0 , "Memory Status", |
573 | // "There is enough memory again." ); | 578 | // "There is enough memory again." ); |
574 | break; | 579 | break; |
575 | case VeryLow: | 580 | case VeryLow: |
576 | memstate = Unknown; | 581 | memstate = Unknown; |
577 | QMessageBox::critical( 0 , "Memory Status", | 582 | QMessageBox::critical( 0 , "Memory Status", |
578 | "The memory is very low. \n" | 583 | "The memory is very low. \n" |
579 | "Please end this application \n" | 584 | "Please end this application \n" |
580 | "immediately." ); | 585 | "immediately." ); |
581 | recoverMemory(); | 586 | recoverMemory(); |
582 | } | 587 | } |
583 | existingMessage = FALSE; | 588 | existingMessage = FALSE; |
584 | #endif | 589 | #endif |
585 | } | 590 | } |
586 | 591 | ||
587 | static bool isVisibleWindow( int wid ) | 592 | static bool isVisibleWindow( int wid ) |
588 | { | 593 | { |
589 | #ifdef QWS | 594 | #ifdef QWS |
590 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 595 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
591 | QWSWindow* w; | 596 | QWSWindow* w; |
592 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 597 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
593 | if ( w->winId() == wid ) | 598 | if ( w->winId() == wid ) |
594 | return !w->isFullyObscured(); | 599 | return !w->isFullyObscured(); |
595 | } | 600 | } |
596 | #endif | 601 | #endif |
597 | return FALSE; | 602 | return FALSE; |
598 | } | 603 | } |
599 | 604 | ||
600 | static bool hasVisibleWindow( const QString& clientname ) | 605 | static bool hasVisibleWindow( const QString& clientname ) |
601 | { | 606 | { |
602 | #ifdef QWS | 607 | #ifdef QWS |
603 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 608 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
604 | QWSWindow* w; | 609 | QWSWindow* w; |
605 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 610 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
606 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) | 611 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) |
607 | return TRUE; | 612 | return TRUE; |
608 | } | 613 | } |
609 | #endif | 614 | #endif |
610 | return FALSE; | 615 | return FALSE; |
611 | } | 616 | } |
612 | 617 | ||
613 | 618 | ||
614 | void Desktop::executeOrModify( const QString& appLnkFile ) | 619 | void Desktop::executeOrModify( const QString& appLnkFile ) |
615 | { | 620 | { |
616 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); | 621 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); |
617 | if ( lnk.isValid() ) { | 622 | if ( lnk.isValid() ) { |
618 | QCString app = lnk.exec().utf8(); | 623 | QCString app = lnk.exec().utf8(); |
619 | Global::terminateBuiltin( "calibrate" ); | 624 | Global::terminateBuiltin( "calibrate" ); |
620 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { | 625 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { |
621 | // MRUList::addTask( &lnk ); | 626 | // MRUList::addTask( &lnk ); |
622 | if ( hasVisibleWindow( app ) ) | 627 | if ( hasVisibleWindow( app ) ) |
623 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); | 628 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); |
624 | else | 629 | else |
625 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); | 630 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); |
626 | } | 631 | } |
627 | else { | 632 | else { |
628 | lnk.execute(); | 633 | lnk.execute(); |
629 | } | 634 | } |
630 | } | 635 | } |
631 | } | 636 | } |
632 | 637 | ||
633 | // autoStarts apps on resume and start | 638 | // autoStarts apps on resume and start |
634 | void Desktop::execAutoStart() | 639 | void Desktop::execAutoStart() |
635 | { | 640 | { |
636 | QString appName; | 641 | QString appName; |
637 | int delay; | 642 | int delay; |
638 | QDateTime now = QDateTime::currentDateTime(); | 643 | QDateTime now = QDateTime::currentDateTime(); |
639 | Config cfg( "autostart" ); | 644 | Config cfg( "autostart" ); |
640 | cfg.setGroup( "AutoStart" ); | 645 | cfg.setGroup( "AutoStart" ); |
641 | appName = cfg.readEntry( "Apps", "" ); | 646 | appName = cfg.readEntry( "Apps", "" ); |
642 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); | 647 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); |
643 | // If the time between suspend and resume was longer then the | 648 | // If the time between suspend and resume was longer then the |
644 | // value saved as delay, start the app | 649 | // value saved as delay, start the app |
645 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | 650 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { |
646 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 651 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
647 | e << QString( appName ); | 652 | e << QString( appName ); |
648 | } | 653 | } |
649 | } | 654 | } |
650 | 655 | ||
651 | #if defined(QPE_HAVE_TOGGLELIGHT) | 656 | #if defined(QPE_HAVE_TOGGLELIGHT) |
652 | #include <qpe/config.h> | 657 | #include <qpe/config.h> |
653 | 658 | ||
654 | #include <sys/ioctl.h> | 659 | #include <sys/ioctl.h> |
655 | #include <sys/types.h> | 660 | #include <sys/types.h> |
656 | #include <fcntl.h> | 661 | #include <fcntl.h> |
657 | #include <unistd.h> | 662 | #include <unistd.h> |
658 | #include <errno.h> | 663 | #include <errno.h> |
659 | #include <linux/ioctl.h> | 664 | #include <linux/ioctl.h> |
660 | #include <time.h> | 665 | #include <time.h> |
661 | #endif | 666 | #endif |
662 | 667 | ||
663 | 668 | ||
664 | void Desktop::togglePower() | 669 | void Desktop::togglePower() |
665 | { | 670 | { |
666 | static bool excllock = false; | 671 | static bool excllock = false; |
667 | 672 | ||
668 | qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); | ||
669 | |||
670 | if ( excllock ) | 673 | if ( excllock ) |
671 | return ; | 674 | return ; |
672 | 675 | ||
673 | excllock = true; | 676 | excllock = true; |
674 | 677 | ||
675 | bool wasloggedin = loggedin; | 678 | bool wasloggedin = loggedin; |
676 | loggedin = 0; | 679 | loggedin = 0; |
677 | suspendTime = QDateTime::currentDateTime(); | 680 | suspendTime = QDateTime::currentDateTime(); |
678 | 681 | ||
679 | #ifdef QWS | 682 | #ifdef QWS |
680 | 683 | ||
681 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { | 684 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { |
682 | // Should use a big black window instead. | 685 | // Should use a big black window instead. |
683 | // But this would not show up fast enough | 686 | // But this would not show up fast enough |
684 | QGfx *g = qt_screen-> screenGfx ( ); | 687 | QGfx *g = qt_screen-> screenGfx ( ); |
685 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | 688 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); |
686 | delete g; | 689 | delete g; |
687 | } | 690 | } |
688 | #endif | 691 | #endif |
689 | 692 | ||
690 | ODevice::inst ( )-> suspend ( ); | 693 | ODevice::inst ( )-> suspend ( ); |
691 | 694 | ||
692 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call | 695 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call |
693 | QWSServer::screenSaverActivate ( false ); | 696 | QWSServer::screenSaverActivate ( false ); |
694 | 697 | ||
695 | { | 698 | { |
696 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | 699 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep |
697 | } | 700 | } |
698 | 701 | ||
699 | if ( wasloggedin ) | 702 | if ( wasloggedin ) |
700 | login ( true ); | 703 | login ( true ); |
701 | 704 | ||
702 | execAutoStart(); | 705 | execAutoStart(); |
703 | //qcopBridge->closeOpenConnections(); | 706 | //qcopBridge->closeOpenConnections(); |
704 | 707 | ||
705 | excllock = false; | 708 | excllock = false; |
706 | } | 709 | } |
707 | 710 | ||
708 | void Desktop::toggleLight() | 711 | void Desktop::toggleLight() |
709 | { | 712 | { |
710 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); | 713 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); |
711 | e << -2; // toggle | 714 | e << -2; // toggle |
712 | } | 715 | } |
713 | 716 | ||
714 | void Desktop::toggleSymbolInput() | 717 | void Desktop::toggleSymbolInput() |
715 | { | 718 | { |
716 | tb->toggleSymbolInput(); | 719 | tb->toggleSymbolInput(); |
717 | } | 720 | } |
718 | 721 | ||
719 | void Desktop::toggleNumLockState() | 722 | void Desktop::toggleNumLockState() |
720 | { | 723 | { |
721 | tb->toggleNumLockState(); | 724 | tb->toggleNumLockState(); |
722 | } | 725 | } |
723 | 726 | ||
724 | void Desktop::toggleCapsLockState() | 727 | void Desktop::toggleCapsLockState() |
725 | { | 728 | { |
726 | tb->toggleCapsLockState(); | 729 | tb->toggleCapsLockState(); |
727 | } | 730 | } |
728 | 731 | ||
729 | void Desktop::styleChange( QStyle &s ) | 732 | void Desktop::styleChange( QStyle &s ) |
730 | { | 733 | { |
731 | QWidget::styleChange( s ); | 734 | QWidget::styleChange( s ); |
732 | int displayw = qApp->desktop() ->width(); | 735 | int displayw = qApp->desktop() ->width(); |
733 | int displayh = qApp->desktop() ->height(); | 736 | int displayh = qApp->desktop() ->height(); |
734 | 737 | ||
735 | QSize sz = tb->sizeHint(); | 738 | QSize sz = tb->sizeHint(); |
736 | 739 | ||
737 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 740 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
738 | } | 741 | } |
739 | 742 | ||
740 | void DesktopApplication::shutdown() | 743 | void DesktopApplication::shutdown() |
741 | { | 744 | { |
742 | if ( type() != GuiServer ) | 745 | if ( type() != GuiServer ) |
743 | return ; | 746 | return ; |
744 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | 747 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); |
745 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), | 748 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), |
746 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); | 749 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); |
747 | sd->showMaximized(); | 750 | sd->showMaximized(); |
748 | } | 751 | } |
749 | 752 | ||
750 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) | 753 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) |
751 | { | 754 | { |
752 | char *opt = 0; | 755 | char *opt = 0; |
753 | 756 | ||
754 | switch ( t ) { | 757 | switch ( t ) { |
755 | case ShutdownImpl::ShutdownSystem: | 758 | case ShutdownImpl::ShutdownSystem: |
756 | opt = "-h"; | 759 | opt = "-h"; |
757 | // fall through | 760 | // fall through |
758 | case ShutdownImpl::RebootSystem: | 761 | case ShutdownImpl::RebootSystem: |
759 | if ( opt == 0 ) | 762 | if ( opt == 0 ) |
760 | opt = "-r"; | 763 | opt = "-r"; |
761 | 764 | ||
762 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) | 765 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) |
763 | perror("shutdown"); | 766 | perror("shutdown"); |
764 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); | 767 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); |
765 | 768 | ||
766 | break; | 769 | break; |
767 | case ShutdownImpl::RestartDesktop: | 770 | case ShutdownImpl::RestartDesktop: |
768 | restart(); | 771 | restart(); |
769 | break; | 772 | break; |
770 | case ShutdownImpl::TerminateDesktop: | 773 | case ShutdownImpl::TerminateDesktop: |
771 | prepareForTermination( FALSE ); | 774 | prepareForTermination( FALSE ); |
772 | 775 | ||
773 | // This is a workaround for a Qt bug | 776 | // This is a workaround for a Qt bug |
774 | // clipboard applet has to stop its poll timer, or Qt/E | 777 | // clipboard applet has to stop its poll timer, or Qt/E |
775 | // will hang on quit() right before it emits aboutToQuit() | 778 | // will hang on quit() right before it emits aboutToQuit() |
776 | emit aboutToQuit ( ); | 779 | emit aboutToQuit ( ); |
777 | 780 | ||
778 | quit(); | 781 | quit(); |
779 | break; | 782 | break; |
780 | } | 783 | } |
781 | } | 784 | } |
782 | 785 | ||
783 | void DesktopApplication::restart() | 786 | void DesktopApplication::restart() |
784 | { | 787 | { |
785 | prepareForTermination( TRUE ); | 788 | prepareForTermination( TRUE ); |
786 | 789 | ||
787 | #ifdef Q_WS_QWS | 790 | #ifdef Q_WS_QWS |
788 | 791 | ||
789 | for ( int fd = 3; fd < 100; fd++ ) | 792 | for ( int fd = 3; fd < 100; fd++ ) |
790 | close( fd ); | 793 | close( fd ); |
791 | #if defined(QT_DEMO_SINGLE_FLOPPY) | 794 | #if defined(QT_DEMO_SINGLE_FLOPPY) |
792 | 795 | ||
793 | execl( "/sbin/init", "qpe", 0 ); | 796 | execl( "/sbin/init", "qpe", 0 ); |
794 | #elif defined(QT_QWS_CASSIOPEIA) | 797 | #elif defined(QT_QWS_CASSIOPEIA) |
795 | 798 | ||
796 | execl( "/bin/sh", "sh", 0 ); | 799 | execl( "/bin/sh", "sh", 0 ); |
797 | #else | 800 | #else |
798 | 801 | ||
799 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); | 802 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); |
800 | #endif | 803 | #endif |
801 | 804 | ||
802 | exit( 1 ); | 805 | exit( 1 ); |
803 | #endif | 806 | #endif |
804 | } | 807 | } |
805 | 808 | ||
806 | void Desktop::startTransferServer() | 809 | void Desktop::startTransferServer() |
807 | { | 810 | { |
808 | // start qcop bridge server | 811 | // start qcop bridge server |
809 | qcopBridge = new QCopBridge( 4243 ); | 812 | qcopBridge = new QCopBridge( 4243 ); |
810 | if ( !qcopBridge->ok() ) { | 813 | if ( !qcopBridge->ok() ) { |
811 | delete qcopBridge; | 814 | delete qcopBridge; |
812 | qcopBridge = 0; | 815 | qcopBridge = 0; |
813 | } | 816 | } |
814 | // start transfer server | 817 | // start transfer server |
815 | transferServer = new TransferServer( 4242 ); | 818 | transferServer = new TransferServer( 4242 ); |
816 | if ( !transferServer->ok() ) { | 819 | if ( !transferServer->ok() ) { |
817 | delete transferServer; | 820 | delete transferServer; |
818 | transferServer = 0; | 821 | transferServer = 0; |
819 | } | 822 | } |
820 | if ( !transferServer || !qcopBridge ) | 823 | if ( !transferServer || !qcopBridge ) |
821 | startTimer( 2000 ); | 824 | startTimer( 2000 ); |
822 | } | 825 | } |
823 | 826 | ||
824 | void Desktop::timerEvent( QTimerEvent *e ) | 827 | void Desktop::timerEvent( QTimerEvent *e ) |
825 | { | 828 | { |
826 | killTimer( e->timerId() ); | 829 | killTimer( e->timerId() ); |
827 | startTransferServer(); | 830 | startTransferServer(); |
828 | } | 831 | } |
829 | 832 | ||
830 | void Desktop::terminateServers() | 833 | void Desktop::terminateServers() |
831 | { | 834 | { |
832 | delete transferServer; | 835 | delete transferServer; |
833 | delete qcopBridge; | 836 | delete qcopBridge; |
834 | transferServer = 0; | 837 | transferServer = 0; |
835 | qcopBridge = 0; | 838 | qcopBridge = 0; |
836 | } | 839 | } |
837 | 840 | ||
838 | void DesktopApplication::rereadVolumes() | 841 | void DesktopApplication::rereadVolumes() |
839 | { | 842 | { |
840 | Config cfg( "qpe" ); | 843 | Config cfg( "qpe" ); |
841 | cfg. setGroup ( "Volume" ); | 844 | cfg. setGroup ( "Volume" ); |
842 | 845 | ||
843 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); | 846 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); |
844 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); | 847 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); |
845 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); | 848 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); |
846 | } | 849 | } |
847 | 850 | ||
848 | void DesktopApplication::soundAlarm() | 851 | void DesktopApplication::soundAlarm() |
849 | { | 852 | { |
850 | if ( me ( )-> m_alarm_sound ) | 853 | if ( me ( )-> m_alarm_sound ) |
851 | ODevice::inst ( )-> alarmSound ( ); | 854 | ODevice::inst ( )-> alarmSound ( ); |
852 | } | 855 | } |
853 | 856 | ||
854 | DesktopApplication *DesktopApplication::me ( ) | 857 | DesktopApplication *DesktopApplication::me ( ) |
855 | { | 858 | { |
856 | return (DesktopApplication *) qApp; | 859 | return (DesktopApplication *) qApp; |
857 | } | 860 | } |
858 | 861 | ||