author | sandman <sandman> | 2002-10-29 15:44:30 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-29 15:44:30 (UTC) |
commit | 6224d462ef211b3b4cffa42d4a7f261caa92834b (patch) (unidiff) | |
tree | 7cb1ccbd7a3cf7c0340cc2283cd7b5040636fd4d | |
parent | f47abe11e3e0281fab06e2b4b9d23a2e35960a2c (diff) | |
download | opie-6224d462ef211b3b4cffa42d4a7f261caa92834b.zip opie-6224d462ef211b3b4cffa42d4a7f261caa92834b.tar.gz opie-6224d462ef211b3b4cffa42d4a7f261caa92834b.tar.bz2 |
- use sane default values for screensaver timeouts
- fixed the "Battery low warning" when plugging the device into AC
-rw-r--r-- | core/launcher/desktop.cpp | 20 | ||||
-rw-r--r-- | core/launcher/screensaver.cpp | 14 |
2 files changed, 17 insertions, 17 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index bc43475..f2e00d8 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -1,620 +1,620 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "desktop.h" | 21 | #include "desktop.h" |
22 | #include "info.h" | 22 | #include "info.h" |
23 | #include "launcher.h" | 23 | #include "launcher.h" |
24 | #include "qcopbridge.h" | 24 | #include "qcopbridge.h" |
25 | #include "shutdownimpl.h" | 25 | #include "shutdownimpl.h" |
26 | #include "startmenu.h" | 26 | #include "startmenu.h" |
27 | #include "taskbar.h" | 27 | #include "taskbar.h" |
28 | #include "transferserver.h" | 28 | #include "transferserver.h" |
29 | #include "irserver.h" | 29 | #include "irserver.h" |
30 | #include "packageslave.h" | 30 | #include "packageslave.h" |
31 | #include "screensaver.h" | 31 | #include "screensaver.h" |
32 | 32 | ||
33 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/password.h> | 35 | #include <qpe/password.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/power.h> | 37 | #include <qpe/power.h> |
38 | #include <qpe/timeconversion.h> | 38 | #include <qpe/timeconversion.h> |
39 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
40 | #include <qpe/network.h> | 40 | #include <qpe/network.h> |
41 | #include <qpe/global.h> | 41 | #include <qpe/global.h> |
42 | 42 | ||
43 | #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) | 43 | #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) |
44 | #include <qpe/custom.h> | 44 | #include <qpe/custom.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #include <opie/odevice.h> | 47 | #include <opie/odevice.h> |
48 | 48 | ||
49 | #include <qgfx_qws.h> | 49 | #include <qgfx_qws.h> |
50 | #include <qmainwindow.h> | 50 | #include <qmainwindow.h> |
51 | #include <qmessagebox.h> | 51 | #include <qmessagebox.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qwindowsystem_qws.h> | 53 | #include <qwindowsystem_qws.h> |
54 | 54 | ||
55 | #include <qvaluelist.h> | 55 | #include <qvaluelist.h> |
56 | 56 | ||
57 | #include <stdlib.h> | 57 | #include <stdlib.h> |
58 | #include <unistd.h> | 58 | #include <unistd.h> |
59 | #include <fcntl.h> | 59 | #include <fcntl.h> |
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | 62 | ||
63 | class QCopKeyRegister | 63 | class QCopKeyRegister |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | QCopKeyRegister() : keyCode( 0 ) | 66 | QCopKeyRegister() : keyCode( 0 ) |
67 | { } | 67 | { } |
68 | QCopKeyRegister( int k, const QString &c, const QString &m ) | 68 | QCopKeyRegister( int k, const QString &c, const QString &m ) |
69 | : keyCode( k ), channel( c ), message( m ) | 69 | : keyCode( k ), channel( c ), message( m ) |
70 | { } | 70 | { } |
71 | 71 | ||
72 | int getKeyCode() const | 72 | int getKeyCode() const |
73 | { | 73 | { |
74 | return keyCode; | 74 | return keyCode; |
75 | } | 75 | } |
76 | QString getChannel() const | 76 | QString getChannel() const |
77 | { | 77 | { |
78 | return channel; | 78 | return channel; |
79 | } | 79 | } |
80 | QString getMessage() const | 80 | QString getMessage() const |
81 | { | 81 | { |
82 | return message; | 82 | return message; |
83 | } | 83 | } |
84 | 84 | ||
85 | private: | 85 | private: |
86 | int keyCode; | 86 | int keyCode; |
87 | QString channel, message; | 87 | QString channel, message; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | typedef QValueList<QCopKeyRegister> KeyRegisterList; | 90 | typedef QValueList<QCopKeyRegister> KeyRegisterList; |
91 | KeyRegisterList keyRegisterList; | 91 | KeyRegisterList keyRegisterList; |
92 | 92 | ||
93 | static Desktop* qpedesktop = 0; | 93 | static Desktop* qpedesktop = 0; |
94 | static int loggedin = 0; | 94 | static int loggedin = 0; |
95 | static void login( bool at_poweron ) | 95 | static void login( bool at_poweron ) |
96 | { | 96 | { |
97 | if ( !loggedin ) { | 97 | if ( !loggedin ) { |
98 | Global::terminateBuiltin( "calibrate" ); | 98 | Global::terminateBuiltin( "calibrate" ); |
99 | Password::authenticate( at_poweron ); | 99 | Password::authenticate( at_poweron ); |
100 | loggedin = 1; | 100 | loggedin = 1; |
101 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 101 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | bool Desktop::screenLocked() | 105 | bool Desktop::screenLocked() |
106 | { | 106 | { |
107 | return loggedin == 0; | 107 | return loggedin == 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | /* | 110 | /* |
111 | Priority is number of alerts that are needed to pop up | 111 | Priority is number of alerts that are needed to pop up |
112 | alert. | 112 | alert. |
113 | */ | 113 | */ |
114 | class DesktopPowerAlerter : public QMessageBox | 114 | class DesktopPowerAlerter : public QMessageBox |
115 | { | 115 | { |
116 | public: | 116 | public: |
117 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 117 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
118 | : QMessageBox( tr( "Battery Status" ), "Low Battery", | 118 | : QMessageBox( tr( "Battery Status" ), "Low Battery", |
119 | QMessageBox::Critical, | 119 | QMessageBox::Critical, |
120 | QMessageBox::Ok | QMessageBox::Default, | 120 | QMessageBox::Ok | QMessageBox::Default, |
121 | QMessageBox::NoButton, QMessageBox::NoButton, | 121 | QMessageBox::NoButton, QMessageBox::NoButton, |
122 | parent, name, FALSE ) | 122 | parent, name, FALSE ) |
123 | { | 123 | { |
124 | currentPriority = INT_MAX; | 124 | currentPriority = INT_MAX; |
125 | alertCount = 0; | 125 | alertCount = 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | void alert( const QString &text, int priority ); | 128 | void alert( const QString &text, int priority ); |
129 | void hideEvent( QHideEvent * ); | 129 | void hideEvent( QHideEvent * ); |
130 | private: | 130 | private: |
131 | int currentPriority; | 131 | int currentPriority; |
132 | int alertCount; | 132 | int alertCount; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
136 | { | 136 | { |
137 | alertCount++; | 137 | alertCount++; |
138 | if ( alertCount < priority ) | 138 | if ( alertCount < priority ) |
139 | return ; | 139 | return ; |
140 | if ( priority > currentPriority ) | 140 | if ( priority > currentPriority ) |
141 | return ; | 141 | return ; |
142 | currentPriority = priority; | 142 | currentPriority = priority; |
143 | setText( text ); | 143 | setText( text ); |
144 | show(); | 144 | show(); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
149 | { | 149 | { |
150 | QMessageBox::hideEvent( e ); | 150 | QMessageBox::hideEvent( e ); |
151 | alertCount = 0; | 151 | alertCount = 0; |
152 | currentPriority = INT_MAX; | 152 | currentPriority = INT_MAX; |
153 | } | 153 | } |
154 | 154 | ||
155 | 155 | ||
156 | void DesktopApplication::switchLCD ( bool on ) | 156 | void DesktopApplication::switchLCD ( bool on ) |
157 | { | 157 | { |
158 | if ( qApp ) { | 158 | if ( qApp ) { |
159 | DesktopApplication *dapp = (DesktopApplication *) qApp; | 159 | DesktopApplication *dapp = (DesktopApplication *) qApp; |
160 | 160 | ||
161 | if ( dapp-> m_screensaver ) { | 161 | if ( dapp-> m_screensaver ) { |
162 | if ( on ) { | 162 | if ( on ) { |
163 | dapp-> m_screensaver-> setDisplayState ( true ); | 163 | dapp-> m_screensaver-> setDisplayState ( true ); |
164 | dapp-> m_screensaver-> setBacklight ( -3 ); | 164 | dapp-> m_screensaver-> setBacklight ( -3 ); |
165 | } | 165 | } |
166 | else { | 166 | else { |
167 | dapp-> m_screensaver-> setDisplayState ( false ); | 167 | dapp-> m_screensaver-> setDisplayState ( false ); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | 174 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) |
175 | : QPEApplication( argc, argv, appType ) | 175 | : QPEApplication( argc, argv, appType ) |
176 | { | 176 | { |
177 | 177 | ||
178 | Config cfg( "apm" ); | 178 | Config cfg( "apm" ); |
179 | cfg.setGroup( "Warnings" ); | 179 | cfg.setGroup( "Warnings" ); |
180 | //cfg.readNumEntry( "checkinterval", 10000 ) | 180 | //cfg.readNumEntry( "checkinterval", 10000 ) |
181 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); | 181 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); |
182 | m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); | 182 | m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); |
183 | 183 | ||
184 | m_ps = new PowerStatus; | 184 | m_ps = new PowerStatus; |
185 | m_ps_last = new PowerStatus; | 185 | m_ps_last = new PowerStatus; |
186 | pa = new DesktopPowerAlerter( 0 ); | 186 | pa = new DesktopPowerAlerter( 0 ); |
187 | 187 | ||
188 | m_timer = new QTimer( this ); | 188 | m_timer = new QTimer( this ); |
189 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); | 189 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); |
190 | m_timer->start( 5000 ); | 190 | m_timer->start( 5000 ); |
191 | 191 | ||
192 | channel = new QCopChannel( "QPE/Desktop", this ); | 192 | channel = new QCopChannel( "QPE/Desktop", this ); |
193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
194 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); | 194 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); |
195 | 195 | ||
196 | channel = new QCopChannel( "QPE/System", this ); | 196 | channel = new QCopChannel( "QPE/System", this ); |
197 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 197 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
198 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 198 | this, SLOT( systemMessage( 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 | apmTimeout ( ); | 204 | apmTimeout ( ); |
205 | } | 205 | } |
206 | 206 | ||
207 | 207 | ||
208 | DesktopApplication::~DesktopApplication() | 208 | DesktopApplication::~DesktopApplication() |
209 | { | 209 | { |
210 | delete m_ps; | 210 | delete m_ps; |
211 | delete m_ps_last; | 211 | delete m_ps_last; |
212 | delete pa; | 212 | delete pa; |
213 | } | 213 | } |
214 | 214 | ||
215 | void DesktopApplication::apmTimeout() | 215 | void DesktopApplication::apmTimeout() |
216 | { | 216 | { |
217 | qpedesktop->checkMemory(); // in case no events are being generated | 217 | qpedesktop->checkMemory(); // in case no events are being generated |
218 | 218 | ||
219 | *m_ps_last = *m_ps; | 219 | *m_ps_last = *m_ps; |
220 | *m_ps = PowerStatusManager::readStatus(); | 220 | *m_ps = PowerStatusManager::readStatus(); |
221 | 221 | ||
222 | if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) | 222 | if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) |
223 | m_screensaver-> powerStatusChanged ( *m_ps ); | 223 | m_screensaver-> powerStatusChanged ( *m_ps ); |
224 | 224 | ||
225 | int bat = m_ps-> batteryPercentRemaining ( ); | 225 | if ( m_ps-> acStatus ( ) != PowerStatus::Online ) { |
226 | 226 | int bat = m_ps-> batteryPercentRemaining ( ); | |
227 | if ( m_ps_last-> batteryPercentRemaining ( ) != bat ) { | 227 | |
228 | if ( bat <= m_powerCritical ) | 228 | if ( bat < m_ps_last-> batteryPercentRemaining ( )) { |
229 | pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); | 229 | if ( bat <= m_powerCritical ) |
230 | else if ( bat <= m_powerVeryLow ) | 230 | pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); |
231 | pa->alert( tr( "Battery is running very low." ), 2 ); | 231 | else if ( bat <= m_powerVeryLow ) |
232 | 232 | pa->alert( tr( "Battery is running very low." ), 2 ); | |
233 | 233 | } | |
234 | if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) | 234 | if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) |
235 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); | 235 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | 238 | ||
239 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) | 239 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) |
240 | { | 240 | { |
241 | QDataStream stream( data, IO_ReadOnly ); | 241 | QDataStream stream( data, IO_ReadOnly ); |
242 | if ( msg == "keyRegister(int key, QString channel, QString message)" ) { | 242 | if ( msg == "keyRegister(int key, QString channel, QString message)" ) { |
243 | int k; | 243 | int k; |
244 | QString c, m; | 244 | QString c, m; |
245 | stream >> k; | 245 | stream >> k; |
246 | stream >> c; | 246 | stream >> c; |
247 | stream >> m; | 247 | stream >> m; |
248 | 248 | ||
249 | qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); | 249 | qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); |
250 | keyRegisterList.append( QCopKeyRegister( k, c, m ) ); | 250 | keyRegisterList.append( QCopKeyRegister( k, c, m ) ); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) | 255 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) |
256 | { | 256 | { |
257 | QDataStream stream ( data, IO_ReadOnly ); | 257 | QDataStream stream ( data, IO_ReadOnly ); |
258 | 258 | ||
259 | if ( msg == "setScreenSaverInterval(int)" ) { | 259 | if ( msg == "setScreenSaverInterval(int)" ) { |
260 | int time; | 260 | int time; |
261 | stream >> time; | 261 | stream >> time; |
262 | m_screensaver-> setInterval( time ); | 262 | m_screensaver-> setInterval( time ); |
263 | } | 263 | } |
264 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 264 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
265 | int t1, t2, t3; | 265 | int t1, t2, t3; |
266 | stream >> t1 >> t2 >> t3; | 266 | stream >> t1 >> t2 >> t3; |
267 | m_screensaver-> setIntervals( t1, t2, t3 ); | 267 | m_screensaver-> setIntervals( t1, t2, t3 ); |
268 | } | 268 | } |
269 | else if ( msg == "setBacklight(int)" ) { | 269 | else if ( msg == "setBacklight(int)" ) { |
270 | int bright; | 270 | int bright; |
271 | stream >> bright; | 271 | stream >> bright; |
272 | m_screensaver-> setBacklight( bright ); | 272 | m_screensaver-> setBacklight( bright ); |
273 | } | 273 | } |
274 | else if ( msg == "setScreenSaverMode(int)" ) { | 274 | else if ( msg == "setScreenSaverMode(int)" ) { |
275 | int mode; | 275 | int mode; |
276 | stream >> mode; | 276 | stream >> mode; |
277 | m_screensaver-> setMode ( mode ); | 277 | m_screensaver-> setMode ( mode ); |
278 | } | 278 | } |
279 | else if ( msg == "reloadPowerWarnSettings()" ) { | 279 | else if ( msg == "reloadPowerWarnSettings()" ) { |
280 | reloadPowerWarnSettings(); | 280 | reloadPowerWarnSettings(); |
281 | } | 281 | } |
282 | else if ( msg == "setDisplayState(int)" ) { | 282 | else if ( msg == "setDisplayState(int)" ) { |
283 | int state; | 283 | int state; |
284 | stream >> state; | 284 | stream >> state; |
285 | m_screensaver-> setDisplayState ( state != 0 ); | 285 | m_screensaver-> setDisplayState ( state != 0 ); |
286 | } | 286 | } |
287 | else if ( msg == "suspend()" ) { | 287 | else if ( msg == "suspend()" ) { |
288 | emit power(); | 288 | emit power(); |
289 | } | 289 | } |
290 | } | 290 | } |
291 | 291 | ||
292 | void DesktopApplication::reloadPowerWarnSettings() { | 292 | void DesktopApplication::reloadPowerWarnSettings() { |
293 | Config cfg( "apm" ); | 293 | Config cfg( "apm" ); |
294 | cfg.setGroup( "Warnings" ); | 294 | cfg.setGroup( "Warnings" ); |
295 | 295 | ||
296 | // m_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); | 296 | // m_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); |
297 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); | 297 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); |
298 | m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); | 298 | m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); |
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; | 302 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; |
303 | 303 | ||
304 | #ifdef Q_WS_QWS | 304 | #ifdef Q_WS_QWS |
305 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | 305 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) |
306 | { | 306 | { |
307 | qpedesktop->checkMemory(); | 307 | qpedesktop->checkMemory(); |
308 | 308 | ||
309 | if ( e->type == QWSEvent::Key ) { | 309 | if ( e->type == QWSEvent::Key ) { |
310 | QWSKeyEvent * ke = ( QWSKeyEvent * ) e; | 310 | QWSKeyEvent * ke = ( QWSKeyEvent * ) e; |
311 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) | 311 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) |
312 | return TRUE; | 312 | return TRUE; |
313 | bool press = ke->simpleData.is_press; | 313 | bool press = ke->simpleData.is_press; |
314 | bool autoRepeat = ke->simpleData.is_auto_repeat; | 314 | bool autoRepeat = ke->simpleData.is_auto_repeat; |
315 | 315 | ||
316 | /* | 316 | /* |
317 | app that registers key/message to be sent back to the app, when it doesn't have focus, | 317 | app that registers key/message to be sent back to the app, when it doesn't have focus, |
318 | when user presses key, unless keyboard has been requested from app. | 318 | when user presses key, unless keyboard has been requested from app. |
319 | will not send multiple repeats if user holds key | 319 | will not send multiple repeats if user holds key |
320 | i.e. one shot | 320 | i.e. one shot |
321 | */ | 321 | */ |
322 | if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { | 322 | if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { |
323 | // qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); | 323 | // qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); |
324 | KeyRegisterList::Iterator it; | 324 | KeyRegisterList::Iterator it; |
325 | for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | 325 | for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { |
326 | if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { | 326 | if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { |
327 | if ( press ) | 327 | if ( press ) |
328 | qDebug( "press" ); | 328 | qDebug( "press" ); |
329 | else | 329 | else |
330 | qDebug( "release" ); | 330 | qDebug( "release" ); |
331 | QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); | 331 | QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
336 | if ( !keyboardGrabbed() ) { | 336 | if ( !keyboardGrabbed() ) { |
337 | if ( ke->simpleData.keycode == Key_F9 ) { | 337 | if ( ke->simpleData.keycode == Key_F9 ) { |
338 | if ( press ) | 338 | if ( press ) |
339 | emit datebook(); | 339 | emit datebook(); |
340 | return TRUE; | 340 | return TRUE; |
341 | } | 341 | } |
342 | if ( ke->simpleData.keycode == Key_F10 ) { | 342 | if ( ke->simpleData.keycode == Key_F10 ) { |
343 | if ( !press && cardSendTimer ) { | 343 | if ( !press && cardSendTimer ) { |
344 | emit contacts(); | 344 | emit contacts(); |
345 | delete cardSendTimer; | 345 | delete cardSendTimer; |
346 | } | 346 | } |
347 | else if ( press ) { | 347 | else if ( press ) { |
348 | cardSendTimer = new QTimer(); | 348 | cardSendTimer = new QTimer(); |
349 | cardSendTimer->start( 2000, TRUE ); | 349 | cardSendTimer->start( 2000, TRUE ); |
350 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); | 350 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); |
351 | } | 351 | } |
352 | return TRUE; | 352 | return TRUE; |
353 | } | 353 | } |
354 | 354 | ||
355 | // if ( ke->simpleData.keycode == Key_F11 ) { | 355 | // if ( ke->simpleData.keycode == Key_F11 ) { |
356 | // if ( press ) emit menu(); | 356 | // if ( press ) emit menu(); |
357 | // return TRUE; | 357 | // return TRUE; |
358 | // } | 358 | // } |
359 | 359 | ||
360 | if ( ke->simpleData.keycode == Key_F12 ) { | 360 | if ( ke->simpleData.keycode == Key_F12 ) { |
361 | while ( activePopupWidget() ) | 361 | while ( activePopupWidget() ) |
362 | activePopupWidget() ->close(); | 362 | activePopupWidget() ->close(); |
363 | if ( press ) | 363 | if ( press ) |
364 | emit launch(); | 364 | emit launch(); |
365 | return TRUE; | 365 | return TRUE; |
366 | } | 366 | } |
367 | if ( ke->simpleData.keycode == Key_F13 ) { | 367 | if ( ke->simpleData.keycode == Key_F13 ) { |
368 | if ( press ) | 368 | if ( press ) |
369 | emit email(); | 369 | emit email(); |
370 | return TRUE; | 370 | return TRUE; |
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | if ( ke->simpleData.keycode == Key_F34 ) { | 374 | if ( ke->simpleData.keycode == Key_F34 ) { |
375 | if ( press ) | 375 | if ( press ) |
376 | emit power(); | 376 | emit power(); |
377 | return TRUE; | 377 | return TRUE; |
378 | } | 378 | } |
379 | // This was used for the iPAQ PowerButton | 379 | // This was used for the iPAQ PowerButton |
380 | // See main.cpp for new KeyboardFilter | 380 | // See main.cpp for new KeyboardFilter |
381 | // | 381 | // |
382 | // if ( ke->simpleData.keycode == Key_SysReq ) { | 382 | // if ( ke->simpleData.keycode == Key_SysReq ) { |
383 | // if ( press ) emit power(); | 383 | // if ( press ) emit power(); |
384 | // return TRUE; | 384 | // return TRUE; |
385 | // } | 385 | // } |
386 | if ( ke->simpleData.keycode == Key_F35 ) { | 386 | if ( ke->simpleData.keycode == Key_F35 ) { |
387 | if ( press ) | 387 | if ( press ) |
388 | emit backlight(); | 388 | emit backlight(); |
389 | return TRUE; | 389 | return TRUE; |
390 | } | 390 | } |
391 | if ( ke->simpleData.keycode == Key_F32 ) { | 391 | if ( ke->simpleData.keycode == Key_F32 ) { |
392 | if ( press ) | 392 | if ( press ) |
393 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 393 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
394 | return TRUE; | 394 | return TRUE; |
395 | } | 395 | } |
396 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { | 396 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { |
397 | if ( press ) | 397 | if ( press ) |
398 | emit symbol(); | 398 | emit symbol(); |
399 | return TRUE; | 399 | return TRUE; |
400 | } | 400 | } |
401 | if ( ke->simpleData.keycode == Key_NumLock ) { | 401 | if ( ke->simpleData.keycode == Key_NumLock ) { |
402 | if ( press ) | 402 | if ( press ) |
403 | emit numLockStateToggle(); | 403 | emit numLockStateToggle(); |
404 | } | 404 | } |
405 | if ( ke->simpleData.keycode == Key_CapsLock ) { | 405 | if ( ke->simpleData.keycode == Key_CapsLock ) { |
406 | if ( press ) | 406 | if ( press ) |
407 | emit capsLockStateToggle(); | 407 | emit capsLockStateToggle(); |
408 | } | 408 | } |
409 | if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) | 409 | if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) |
410 | qpedesktop->keyClick(); | 410 | qpedesktop->keyClick(); |
411 | } | 411 | } |
412 | else { | 412 | else { |
413 | if ( e->type == QWSEvent::Mouse ) { | 413 | if ( e->type == QWSEvent::Mouse ) { |
414 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; | 414 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; |
415 | static bool up = TRUE; | 415 | static bool up = TRUE; |
416 | if ( me->simpleData.state & LeftButton ) { | 416 | if ( me->simpleData.state & LeftButton ) { |
417 | if ( up ) { | 417 | if ( up ) { |
418 | up = FALSE; | 418 | up = FALSE; |
419 | qpedesktop->screenClick(); | 419 | qpedesktop->screenClick(); |
420 | } | 420 | } |
421 | } | 421 | } |
422 | else { | 422 | else { |
423 | up = TRUE; | 423 | up = TRUE; |
424 | } | 424 | } |
425 | } | 425 | } |
426 | } | 426 | } |
427 | 427 | ||
428 | return QPEApplication::qwsEventFilter( e ); | 428 | return QPEApplication::qwsEventFilter( e ); |
429 | } | 429 | } |
430 | #endif | 430 | #endif |
431 | 431 | ||
432 | 432 | ||
433 | void DesktopApplication::sendCard() | 433 | void DesktopApplication::sendCard() |
434 | { | 434 | { |
435 | delete cardSendTimer; | 435 | delete cardSendTimer; |
436 | cardSendTimer = 0; | 436 | cardSendTimer = 0; |
437 | QString card = getenv( "HOME" ); | 437 | QString card = getenv( "HOME" ); |
438 | card += "/Applications/addressbook/businesscard.vcf"; | 438 | card += "/Applications/addressbook/businesscard.vcf"; |
439 | 439 | ||
440 | if ( QFile::exists( card ) ) { | 440 | if ( QFile::exists( card ) ) { |
441 | QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); | 441 | QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); |
442 | QString mimetype = "text/x-vCard"; | 442 | QString mimetype = "text/x-vCard"; |
443 | e << tr( "business card" ) << card << mimetype; | 443 | e << tr( "business card" ) << card << mimetype; |
444 | } | 444 | } |
445 | } | 445 | } |
446 | 446 | ||
447 | #if defined(QPE_HAVE_MEMALERTER) | 447 | #if defined(QPE_HAVE_MEMALERTER) |
448 | QPE_MEMALERTER_IMPL | 448 | QPE_MEMALERTER_IMPL |
449 | #endif | 449 | #endif |
450 | 450 | ||
451 | //=========================================================================== | 451 | //=========================================================================== |
452 | 452 | ||
453 | Desktop::Desktop() : | 453 | Desktop::Desktop() : |
454 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | 454 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), |
455 | qcopBridge( 0 ), | 455 | qcopBridge( 0 ), |
456 | transferServer( 0 ), | 456 | transferServer( 0 ), |
457 | packageSlave( 0 ) | 457 | packageSlave( 0 ) |
458 | { | 458 | { |
459 | qpedesktop = this; | 459 | qpedesktop = this; |
460 | 460 | ||
461 | // bg = new Info( this ); | 461 | // bg = new Info( this ); |
462 | tb = new TaskBar; | 462 | tb = new TaskBar; |
463 | 463 | ||
464 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); | 464 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); |
465 | 465 | ||
466 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); | 466 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); |
467 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); | 467 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); |
468 | 468 | ||
469 | int displayw = qApp->desktop() ->width(); | 469 | int displayw = qApp->desktop() ->width(); |
470 | int displayh = qApp->desktop() ->height(); | 470 | int displayh = qApp->desktop() ->height(); |
471 | 471 | ||
472 | 472 | ||
473 | QSize sz = tb->sizeHint(); | 473 | QSize sz = tb->sizeHint(); |
474 | 474 | ||
475 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 475 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
476 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 476 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
477 | 477 | ||
478 | tb->show(); | 478 | tb->show(); |
479 | launcher->showMaximized(); | 479 | launcher->showMaximized(); |
480 | launcher->show(); | 480 | launcher->show(); |
481 | launcher->raise(); | 481 | launcher->raise(); |
482 | #if defined(QPE_HAVE_MEMALERTER) | 482 | #if defined(QPE_HAVE_MEMALERTER) |
483 | 483 | ||
484 | initMemalerter(); | 484 | initMemalerter(); |
485 | #endif | 485 | #endif |
486 | // start services | 486 | // start services |
487 | startTransferServer(); | 487 | startTransferServer(); |
488 | ( void ) new IrServer( this ); | 488 | ( void ) new IrServer( this ); |
489 | rereadVolumes(); | 489 | rereadVolumes(); |
490 | 490 | ||
491 | packageSlave = new PackageSlave( this ); | 491 | packageSlave = new PackageSlave( this ); |
492 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); | 492 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); |
493 | 493 | ||
494 | qApp->installEventFilter( this ); | 494 | qApp->installEventFilter( this ); |
495 | 495 | ||
496 | qApp-> setMainWidget ( launcher ); | 496 | qApp-> setMainWidget ( launcher ); |
497 | } | 497 | } |
498 | 498 | ||
499 | void Desktop::show() | 499 | void Desktop::show() |
500 | { | 500 | { |
501 | login( TRUE ); | 501 | login( TRUE ); |
502 | QWidget::show(); | 502 | QWidget::show(); |
503 | } | 503 | } |
504 | 504 | ||
505 | Desktop::~Desktop() | 505 | Desktop::~Desktop() |
506 | { | 506 | { |
507 | delete launcher; | 507 | delete launcher; |
508 | delete tb; | 508 | delete tb; |
509 | delete qcopBridge; | 509 | delete qcopBridge; |
510 | delete transferServer; | 510 | delete transferServer; |
511 | } | 511 | } |
512 | 512 | ||
513 | bool Desktop::recoverMemory() | 513 | bool Desktop::recoverMemory() |
514 | { | 514 | { |
515 | return tb->recoverMemory(); | 515 | return tb->recoverMemory(); |
516 | } | 516 | } |
517 | 517 | ||
518 | void Desktop::checkMemory() | 518 | void Desktop::checkMemory() |
519 | { | 519 | { |
520 | #if defined(QPE_HAVE_MEMALERTER) | 520 | #if defined(QPE_HAVE_MEMALERTER) |
521 | static bool ignoreNormal = FALSE; | 521 | static bool ignoreNormal = FALSE; |
522 | static bool existingMessage = FALSE; | 522 | static bool existingMessage = FALSE; |
523 | 523 | ||
524 | if ( existingMessage ) | 524 | if ( existingMessage ) |
525 | return ; // don't show a second message while still on first | 525 | return ; // don't show a second message while still on first |
526 | 526 | ||
527 | existingMessage = TRUE; | 527 | existingMessage = TRUE; |
528 | switch ( memstate ) { | 528 | switch ( memstate ) { |
529 | case Unknown: | 529 | case Unknown: |
530 | break; | 530 | break; |
531 | case Low: | 531 | case Low: |
532 | memstate = Unknown; | 532 | memstate = Unknown; |
533 | if ( recoverMemory() ) | 533 | if ( recoverMemory() ) |
534 | ignoreNormal = TRUE; | 534 | ignoreNormal = TRUE; |
535 | else | 535 | else |
536 | QMessageBox::warning( 0 , "Memory Status", | 536 | QMessageBox::warning( 0 , "Memory Status", |
537 | "The memory smacks of shortage. \n" | 537 | "The memory smacks of shortage. \n" |
538 | "Please save data. " ); | 538 | "Please save data. " ); |
539 | break; | 539 | break; |
540 | case Normal: | 540 | case Normal: |
541 | memstate = Unknown; | 541 | memstate = Unknown; |
542 | if ( ignoreNormal ) | 542 | if ( ignoreNormal ) |
543 | ignoreNormal = FALSE; | 543 | ignoreNormal = FALSE; |
544 | // else | 544 | // else |
545 | // QMessageBox::information ( 0 , "Memory Status", | 545 | // QMessageBox::information ( 0 , "Memory Status", |
546 | // "There is enough memory again." ); | 546 | // "There is enough memory again." ); |
547 | break; | 547 | break; |
548 | case VeryLow: | 548 | case VeryLow: |
549 | memstate = Unknown; | 549 | memstate = Unknown; |
550 | QMessageBox::critical( 0 , "Memory Status", | 550 | QMessageBox::critical( 0 , "Memory Status", |
551 | "The memory is very low. \n" | 551 | "The memory is very low. \n" |
552 | "Please end this application \n" | 552 | "Please end this application \n" |
553 | "immediately." ); | 553 | "immediately." ); |
554 | recoverMemory(); | 554 | recoverMemory(); |
555 | } | 555 | } |
556 | existingMessage = FALSE; | 556 | existingMessage = FALSE; |
557 | #endif | 557 | #endif |
558 | } | 558 | } |
559 | 559 | ||
560 | static bool isVisibleWindow( int wid ) | 560 | static bool isVisibleWindow( int wid ) |
561 | { | 561 | { |
562 | #ifdef QWS | 562 | #ifdef QWS |
563 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 563 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
564 | QWSWindow* w; | 564 | QWSWindow* w; |
565 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 565 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
566 | if ( w->winId() == wid ) | 566 | if ( w->winId() == wid ) |
567 | return !w->isFullyObscured(); | 567 | return !w->isFullyObscured(); |
568 | } | 568 | } |
569 | #endif | 569 | #endif |
570 | return FALSE; | 570 | return FALSE; |
571 | } | 571 | } |
572 | 572 | ||
573 | static bool hasVisibleWindow( const QString& clientname ) | 573 | static bool hasVisibleWindow( const QString& clientname ) |
574 | { | 574 | { |
575 | #ifdef QWS | 575 | #ifdef QWS |
576 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 576 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
577 | QWSWindow* w; | 577 | QWSWindow* w; |
578 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 578 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
579 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) | 579 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) |
580 | return TRUE; | 580 | return TRUE; |
581 | } | 581 | } |
582 | #endif | 582 | #endif |
583 | return FALSE; | 583 | return FALSE; |
584 | } | 584 | } |
585 | 585 | ||
586 | void Desktop::raiseLauncher() | 586 | void Desktop::raiseLauncher() |
587 | { | 587 | { |
588 | Config cfg( "qpe" ); //F12 'Home' | 588 | Config cfg( "qpe" ); //F12 'Home' |
589 | cfg.setGroup( "AppsKey" ); | 589 | cfg.setGroup( "AppsKey" ); |
590 | QString tempItem; | 590 | QString tempItem; |
591 | tempItem = cfg.readEntry( "Middle", "Home" ); | 591 | tempItem = cfg.readEntry( "Middle", "Home" ); |
592 | if ( tempItem == "Home" || tempItem.isEmpty() ) { | 592 | if ( tempItem == "Home" || tempItem.isEmpty() ) { |
593 | home ( ); | 593 | home ( ); |
594 | } | 594 | } |
595 | else { | 595 | else { |
596 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 596 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
597 | e << tempItem; | 597 | e << tempItem; |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | void Desktop::home ( ) | 601 | void Desktop::home ( ) |
602 | { | 602 | { |
603 | if ( isVisibleWindow( launcher->winId() ) ) | 603 | if ( isVisibleWindow( launcher->winId() ) ) |
604 | launcher->nextView(); | 604 | launcher->nextView(); |
605 | else | 605 | else |
606 | launcher->raise(); | 606 | launcher->raise(); |
607 | } | 607 | } |
608 | 608 | ||
609 | void Desktop::executeOrModify( const QString& appLnkFile ) | 609 | void Desktop::executeOrModify( const QString& appLnkFile ) |
610 | { | 610 | { |
611 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); | 611 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); |
612 | if ( lnk.isValid() ) { | 612 | if ( lnk.isValid() ) { |
613 | QCString app = lnk.exec().utf8(); | 613 | QCString app = lnk.exec().utf8(); |
614 | Global::terminateBuiltin( "calibrate" ); | 614 | Global::terminateBuiltin( "calibrate" ); |
615 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { | 615 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { |
616 | // MRUList::addTask( &lnk ); | 616 | // MRUList::addTask( &lnk ); |
617 | if ( hasVisibleWindow( app ) ) | 617 | if ( hasVisibleWindow( app ) ) |
618 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); | 618 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); |
619 | else | 619 | else |
620 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); | 620 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); |
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 741591e..45da9ed 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -1,270 +1,270 @@ | |||
1 | 1 | ||
2 | #include "screensaver.h" | 2 | #include "screensaver.h" |
3 | 3 | ||
4 | #include <qpe/config.h> | 4 | #include <qpe/config.h> |
5 | #include <qpe/power.h> | 5 | #include <qpe/power.h> |
6 | #include <qpe/network.h> | 6 | #include <qpe/network.h> |
7 | 7 | ||
8 | #include <opie/odevice.h> | 8 | #include <opie/odevice.h> |
9 | 9 | ||
10 | 10 | ||
11 | using namespace Opie; | 11 | using namespace Opie; |
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
15 | OpieScreenSaver::OpieScreenSaver ( ) | 15 | OpieScreenSaver::OpieScreenSaver ( ) |
16 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) | 16 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) |
17 | { | 17 | { |
18 | m_disable_suspend = 100; | 18 | m_disable_suspend = 100; |
19 | m_enable_dim = false; | 19 | m_enable_dim = false; |
20 | m_enable_lightoff = false; | 20 | m_enable_lightoff = false; |
21 | m_enable_suspend = false; | 21 | m_enable_suspend = false; |
22 | m_onlylcdoff = false; | 22 | m_onlylcdoff = false; |
23 | 23 | ||
24 | m_enable_dim_ac = false; | 24 | m_enable_dim_ac = false; |
25 | m_enable_lightoff_ac = false; | 25 | m_enable_lightoff_ac = false; |
26 | m_enable_suspend_ac = false; | 26 | m_enable_suspend_ac = false; |
27 | m_onlylcdoff_ac = false; | 27 | m_onlylcdoff_ac = false; |
28 | 28 | ||
29 | m_use_light_sensor = false; | 29 | m_use_light_sensor = false; |
30 | m_backlight_sensor = -1; | 30 | m_backlight_sensor = -1; |
31 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); | 31 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); |
32 | 32 | ||
33 | m_lcd_status = true; | 33 | m_lcd_status = true; |
34 | 34 | ||
35 | m_backlight_normal = -1; | 35 | m_backlight_normal = -1; |
36 | m_backlight_current = -1; | 36 | m_backlight_current = -1; |
37 | m_backlight_forcedoff = false; | 37 | m_backlight_forcedoff = false; |
38 | 38 | ||
39 | m_on_ac = false; | 39 | m_on_ac = false; |
40 | 40 | ||
41 | m_level = -1; | 41 | m_level = -1; |
42 | 42 | ||
43 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 43 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
44 | ODevice::inst ( )-> setDisplayStatus ( true ); | 44 | ODevice::inst ( )-> setDisplayStatus ( true ); |
45 | setBacklight ( -1 ); | 45 | setBacklight ( -1 ); |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | void OpieScreenSaver::restore() | 49 | void OpieScreenSaver::restore() |
50 | { | 50 | { |
51 | m_level = -1; | 51 | m_level = -1; |
52 | 52 | ||
53 | if ( !m_lcd_status ) { // We must have turned it off | 53 | if ( !m_lcd_status ) { // We must have turned it off |
54 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 54 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
55 | m_lcd_status = true; | 55 | m_lcd_status = true; |
56 | } | 56 | } |
57 | 57 | ||
58 | setBacklightInternal ( -1 ); | 58 | setBacklightInternal ( -1 ); |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | bool OpieScreenSaver::save( int level ) | 62 | bool OpieScreenSaver::save( int level ) |
63 | { | 63 | { |
64 | m_level = level; | 64 | m_level = level; |
65 | 65 | ||
66 | switch ( level ) { | 66 | switch ( level ) { |
67 | case 0: | 67 | case 0: |
68 | if (( m_on_ac && m_enable_dim_ac ) || | 68 | if (( m_on_ac && m_enable_dim_ac ) || |
69 | ( !m_on_ac && m_enable_dim )) { | 69 | ( !m_on_ac && m_enable_dim )) { |
70 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) | 70 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) |
71 | setBacklightInternal ( 1 ); // lowest non-off | 71 | setBacklightInternal ( 1 ); // lowest non-off |
72 | } | 72 | } |
73 | return true; | 73 | return true; |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case 1: | 76 | case 1: |
77 | if (( m_on_ac && m_enable_lightoff_ac ) || | 77 | if (( m_on_ac && m_enable_lightoff_ac ) || |
78 | ( !m_on_ac && m_enable_lightoff )) { | 78 | ( !m_on_ac && m_enable_lightoff )) { |
79 | if ( m_disable_suspend > 1 ) | 79 | if ( m_disable_suspend > 1 ) |
80 | setBacklightInternal ( 0 ); // off | 80 | setBacklightInternal ( 0 ); // off |
81 | } | 81 | } |
82 | return true; | 82 | return true; |
83 | break; | 83 | break; |
84 | 84 | ||
85 | case 2: | 85 | case 2: |
86 | if (( m_on_ac && !m_enable_suspend_ac ) || | 86 | if (( m_on_ac && !m_enable_suspend_ac ) || |
87 | ( !m_on_ac && !m_enable_suspend )) { | 87 | ( !m_on_ac && !m_enable_suspend )) { |
88 | return true; | 88 | return true; |
89 | } | 89 | } |
90 | 90 | ||
91 | if (( m_on_ac && m_onlylcdoff_ac ) || | 91 | if (( m_on_ac && m_onlylcdoff_ac ) || |
92 | ( !m_on_ac && m_onlylcdoff )) { | 92 | ( !m_on_ac && m_onlylcdoff )) { |
93 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 93 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
94 | m_lcd_status = false; | 94 | m_lcd_status = false; |
95 | return true; | 95 | return true; |
96 | } | 96 | } |
97 | 97 | ||
98 | // We're going to suspend the whole machine | 98 | // We're going to suspend the whole machine |
99 | 99 | ||
100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { | 100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { |
101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
102 | return true; | 102 | return true; |
103 | } | 103 | } |
104 | 104 | ||
105 | break; | 105 | break; |
106 | } | 106 | } |
107 | return false; | 107 | return false; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) | 111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) |
112 | { | 112 | { |
113 | Config config ( "apm" ); | 113 | Config config ( "apm" ); |
114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
115 | 115 | ||
116 | int v[ 4 ]; | 116 | int v[ 4 ]; |
117 | if ( i1 < 0 ) | 117 | if ( i1 < 0 ) |
118 | i1 = config. readNumEntry ( "Dim", 30 ); | 118 | i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); |
119 | if ( i2 < 0 ) | 119 | if ( i2 < 0 ) |
120 | i2 = config. readNumEntry ( "LightOff", 20 ); | 120 | i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); |
121 | if ( i3 < 0 ) | 121 | if ( i3 < 0 ) |
122 | i3 = config. readNumEntry ( "Suspend", 60 ); | 122 | i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); |
123 | 123 | ||
124 | if ( m_on_ac ) { | 124 | if ( m_on_ac ) { |
125 | m_enable_dim_ac = ( i1 > 0 ); | 125 | m_enable_dim_ac = ( i1 > 0 ); |
126 | m_enable_lightoff_ac = ( i2 > 0 ); | 126 | m_enable_lightoff_ac = ( i2 > 0 ); |
127 | m_enable_suspend_ac = ( i3 > 0 ); | 127 | m_enable_suspend_ac = ( i3 > 0 ); |
128 | m_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnly", 0 ); | 128 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); |
129 | } | 129 | } |
130 | else { | 130 | else { |
131 | m_enable_dim = ( i1 > 0 ); | 131 | m_enable_dim = ( i1 > 0 ); |
132 | m_enable_lightoff = ( i2 > 0 ); | 132 | m_enable_lightoff = ( i2 > 0 ); |
133 | m_enable_suspend = ( i3 > 0 ); | 133 | m_enable_suspend = ( i3 > 0 ); |
134 | m_onlylcdoff = config.readNumEntry ( "LcdOffOnly", 0 ); | 134 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); |
135 | } | 135 | } |
136 | 136 | ||
137 | qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 137 | qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
138 | 138 | ||
139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); |
142 | v [ 3 ] = 0; | 142 | v [ 3 ] = 0; |
143 | 143 | ||
144 | if ( !i1 && !i2 && !i3 ) | 144 | if ( !i1 && !i2 && !i3 ) |
145 | QWSServer::setScreenSaverInterval( 0 ); | 145 | QWSServer::setScreenSaverInterval( 0 ); |
146 | else | 146 | else |
147 | QWSServer::setScreenSaverIntervals( v ); | 147 | QWSServer::setScreenSaverIntervals( v ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | void OpieScreenSaver::setInterval ( int interval ) | 151 | void OpieScreenSaver::setInterval ( int interval ) |
152 | { | 152 | { |
153 | setIntervals ( -1, -1, interval ); | 153 | setIntervals ( -1, -1, interval ); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | void OpieScreenSaver::setMode ( int mode ) | 157 | void OpieScreenSaver::setMode ( int mode ) |
158 | { | 158 | { |
159 | if ( mode > m_disable_suspend ) | 159 | if ( mode > m_disable_suspend ) |
160 | setInterval ( -1 ); | 160 | setInterval ( -1 ); |
161 | m_disable_suspend = mode; | 161 | m_disable_suspend = mode; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | void OpieScreenSaver::setBacklight ( int bright ) | 165 | void OpieScreenSaver::setBacklight ( int bright ) |
166 | { | 166 | { |
167 | // Read from config | 167 | // Read from config |
168 | Config config ( "apm" ); | 168 | Config config ( "apm" ); |
169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
170 | m_backlight_normal = config. readNumEntry ( "Brightness", 255 ); | 170 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
171 | 171 | ||
172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
173 | 173 | ||
174 | qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 174 | //qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
175 | 175 | ||
176 | killTimers ( ); | 176 | killTimers ( ); |
177 | if ( m_use_light_sensor ) { | 177 | if ( m_use_light_sensor ) { |
178 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); | 178 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); |
179 | 179 | ||
180 | m_sensordata [LS_SensorMin] = 40; | 180 | m_sensordata [LS_SensorMin] = 40; |
181 | m_sensordata [LS_SensorMax] = 215; | 181 | m_sensordata [LS_SensorMax] = 215; |
182 | m_sensordata [LS_LightMin] = 1; | 182 | m_sensordata [LS_LightMin] = 1; |
183 | m_sensordata [LS_LightMax] = 255; | 183 | m_sensordata [LS_LightMax] = 255; |
184 | m_sensordata [LS_Steps] = 12; | 184 | m_sensordata [LS_Steps] = 12; |
185 | m_sensordata [LS_Interval] = 2000; | 185 | m_sensordata [LS_Interval] = 2000; |
186 | 186 | ||
187 | for ( uint i = 0; i < LS_Count; i++ ) { | 187 | for ( uint i = 0; i < LS_Count; i++ ) { |
188 | if ( i < sl. count ( )) | 188 | if ( i < sl. count ( )) |
189 | m_sensordata [i] = sl [i]. toInt ( ); | 189 | m_sensordata [i] = sl [i]. toInt ( ); |
190 | } | 190 | } |
191 | 191 | ||
192 | timerEvent ( 0 ); | 192 | timerEvent ( 0 ); |
193 | startTimer ( m_sensordata [LS_Interval] ); | 193 | startTimer ( m_sensordata [LS_Interval] ); |
194 | } | 194 | } |
195 | 195 | ||
196 | setBacklightInternal ( bright ); | 196 | setBacklightInternal ( bright ); |
197 | } | 197 | } |
198 | 198 | ||
199 | 199 | ||
200 | void OpieScreenSaver::setBacklightInternal ( int bright ) | 200 | void OpieScreenSaver::setBacklightInternal ( int bright ) |
201 | { | 201 | { |
202 | if ( bright == -3 ) { | 202 | if ( bright == -3 ) { |
203 | // Forced on | 203 | // Forced on |
204 | m_backlight_forcedoff = false; | 204 | m_backlight_forcedoff = false; |
205 | bright = -1; | 205 | bright = -1; |
206 | } | 206 | } |
207 | if ( m_backlight_forcedoff && bright != -2 ) | 207 | if ( m_backlight_forcedoff && bright != -2 ) |
208 | return ; | 208 | return ; |
209 | if ( bright == -2 ) { | 209 | if ( bright == -2 ) { |
210 | // Toggle between off and on | 210 | // Toggle between off and on |
211 | bright = m_backlight_current ? 0 : -1; | 211 | bright = m_backlight_current ? 0 : -1; |
212 | m_backlight_forcedoff = !bright; | 212 | m_backlight_forcedoff = !bright; |
213 | } | 213 | } |
214 | if ( bright == -1 ) | 214 | if ( bright == -1 ) |
215 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | 215 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; |
216 | 216 | ||
217 | if ( bright != m_backlight_current ) { | 217 | if ( bright != m_backlight_current ) { |
218 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 218 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
219 | m_backlight_current = bright; | 219 | m_backlight_current = bright; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 224 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
225 | { | 225 | { |
226 | int s = ODevice::inst ( )-> readLightSensor ( ); | 226 | int s = ODevice::inst ( )-> readLightSensor ( ); |
227 | 227 | ||
228 | if ( s < m_sensordata [LS_SensorMin] ) | 228 | if ( s < m_sensordata [LS_SensorMin] ) |
229 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 229 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
230 | else if ( s >= m_sensordata [LS_SensorMax] ) | 230 | else if ( s >= m_sensordata [LS_SensorMax] ) |
231 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 231 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
232 | else { | 232 | else { |
233 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 233 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
234 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 234 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
235 | 235 | ||
236 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; | 236 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; |
237 | 237 | ||
238 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); | 238 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |
239 | } | 239 | } |
240 | if ( !m_backlight_sensor ) | 240 | if ( !m_backlight_sensor ) |
241 | m_backlight_sensor = 1; | 241 | m_backlight_sensor = 1; |
242 | 242 | ||
243 | // qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); | 243 | // qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); |
244 | 244 | ||
245 | if ( m_level <= 0 ) | 245 | if ( m_level <= 0 ) |
246 | setBacklightInternal ( -1 ); | 246 | setBacklightInternal ( -1 ); |
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | void OpieScreenSaver::setDisplayState ( bool on ) | 250 | void OpieScreenSaver::setDisplayState ( bool on ) |
251 | { | 251 | { |
252 | if ( m_lcd_status != on ) { | 252 | if ( m_lcd_status != on ) { |
253 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 253 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
254 | m_lcd_status = on; | 254 | m_lcd_status = on; |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 259 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
260 | { | 260 | { |
261 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 261 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
262 | 262 | ||
263 | if ( newonac != m_on_ac ) { | 263 | if ( newonac != m_on_ac ) { |
264 | m_on_ac = newonac; | 264 | m_on_ac = newonac; |
265 | setInterval ( -1 ); | 265 | setInterval ( -1 ); |
266 | setBacklight ( -1 ); | 266 | setBacklight ( -1 ); |
267 | restore ( ); | 267 | restore ( ); |
268 | } | 268 | } |
269 | } | 269 | } |
270 | 270 | ||