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