summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp5
-rw-r--r--noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp4
-rw-r--r--noncore/settings/sysinfo/benchmarkinfo.cpp2
3 files changed, 9 insertions, 2 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index 554efd3..3f1077c 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,360 +1,363 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can 5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License. 9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       : 10     ._= =}       :
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that 12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details. 17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .: 18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU 19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file; 20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the 21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc., 22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, 23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. 24 Boston, MA 02111-1307, USA.
25 25
26*/ 26*/
27 27
28#include "loginapplication.h" 28#include "loginapplication.h"
29#include "loginwindowimpl.h" 29#include "loginwindowimpl.h"
30#include "calibrate.h" 30#include "calibrate.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/odevice.h> 33#include <opie2/odevice.h>
34#include <qpe/qpestyle.h> 34#include <qpe/qpestyle.h>
35#include <qpe/power.h> 35#include <qpe/power.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37 37
38/* QT */ 38/* QT */
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#include <qmessagebox.h> 40#include <qmessagebox.h>
41#include <qlabel.h> 41#include <qlabel.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qfile.h> 43#include <qfile.h>
44 44
45/* STD */ 45/* STD */
46#include <sys/types.h> 46#include <sys/types.h>
47#include <time.h> 47#include <time.h>
48#include <sys/time.h> 48#include <sys/time.h>
49#include <sys/resource.h> 49#include <sys/resource.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <syslog.h> 51#include <syslog.h>
52#include <sys/wait.h> 52#include <sys/wait.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <signal.h> 55#include <signal.h>
56#include <getopt.h> 56#include <getopt.h>
57#include <string.h> 57#include <string.h>
58 58
59using namespace Opie::Core; 59using namespace Opie::Core;
60 60
61int login_main ( int argc, char **argv, pid_t ppid ); 61int login_main ( int argc, char **argv, pid_t ppid );
62void sigterm ( int sig ); 62void sigterm ( int sig );
63void sigint ( int sig ); 63void sigint ( int sig );
64void exit_closelog ( ); 64void exit_closelog ( );
65 65
66int main ( int argc, char **argv ) 66int main ( int argc, char **argv )
67{ 67{
68 int userExited = 0; 68 int userExited = 0;
69 pid_t ppid = ::getpid ( ); 69 pid_t ppid = ::getpid ( );
70 70
71 if ( ::geteuid ( ) != 0 ) { 71 if ( ::geteuid ( ) != 0 ) {
72 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] ); 72 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] );
73 return 1; 73 return 1;
74 } 74 }
75 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and 75 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and
76 ::setuid ( 0 ); // messes up things like config files 76 ::setuid ( 0 ); // messes up things like config files
77 77
78 //struct rlimit rl; 78 //struct rlimit rl;
79 //::getrlimit ( RLIMIT_NOFILE, &rl ); 79 //::getrlimit ( RLIMIT_NOFILE, &rl );
80 80
81 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 81 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
82 // ::close ( i ); 82 // ::close ( i );
83 83
84 ::setpgid ( 0, 0 ); 84 ::setpgid ( 0, 0 );
85 ::setsid ( ); 85 ::setsid ( );
86 86
87 ::signal ( SIGTERM, sigterm ); 87 ::signal ( SIGTERM, sigterm );
88 ::signal ( SIGINT, sigterm ); 88 ::signal ( SIGINT, sigterm );
89 89
90 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 90 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
91 ::atexit ( exit_closelog ); 91 ::atexit ( exit_closelog );
92 92
93 const char* autolog = 0; 93 const char* autolog = 0;
94 Config c( "opie-login" ); 94 Config c( "opie-login" );
95 c.setGroup( "autologin" ); 95 c.setGroup( "autologin" );
96 QString entry = c.readEntry( "user", "" ); 96 QString entry = c.readEntry( "user", "" );
97 if ( !entry.isEmpty() ) autolog = ::strdup( (const char*) entry ); 97 if ( !entry.isEmpty() ) autolog = ::strdup( (const char*) entry );
98 98
99 while ( true ) { 99 while ( true ) {
100 pid_t child = ::fork ( ); 100 pid_t child = ::fork ( );
101 101
102 if ( child < 0 ) { 102 if ( child < 0 ) {
103 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 103 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
104 break; 104 break;
105 } 105 }
106 else if ( child > 0 ) { 106 else if ( child > 0 ) {
107 int status = 0; 107 int status = 0;
108 time_t started = ::time ( 0 ); 108 time_t started = ::time ( 0 );
109 109
110 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 110 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
111 111
112 LoginApplication::logout ( ); 112 LoginApplication::logout ( );
113 113
114 if (( ::time ( 0 ) - started ) < 3 ) { 114 if (( ::time ( 0 ) - started ) < 3 ) {
115 if ( autolog ) { 115 if ( autolog ) {
116 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); 116 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
117 autolog = 0; 117 autolog = 0;
118 } 118 }
119 else { 119 else {
120 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); 120 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
121 break; 121 break;
122 } 122 }
123 } 123 }
124 int killedbysig = 0; 124 int killedbysig = 0;
125 userExited=0; 125 userExited=0;
126 if (WIFEXITED(status)!=0 ) { 126 if (WIFEXITED(status)!=0 ) {
127 if (WEXITSTATUS(status)==137) { 127 if (WEXITSTATUS(status)==137) {
128 userExited=1; 128 userExited=1;
129 } 129 }
130 } 130 }
131 131
132 if ( WIFSIGNALED( status )) { 132 if ( WIFSIGNALED( status )) {
133 switch ( WTERMSIG( status )) { 133 switch ( WTERMSIG( status )) {
134 case SIGTERM: 134 case SIGTERM:
135 case SIGINT : 135 case SIGINT :
136 case SIGKILL: 136 case SIGKILL:
137 break; 137 break;
138 138
139 default : 139 default :
140 killedbysig = WTERMSIG( status ); 140 killedbysig = WTERMSIG( status );
141 break; 141 break;
142 } 142 }
143 } 143 }
144 if ( killedbysig ) { // qpe was killed by an uncaught signal 144 if ( killedbysig ) { // qpe was killed by an uncaught signal
145 qApp = 0; 145 qApp = 0;
146 146
147 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); 147 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig );
148 148
149 QWSServer::setDesktopBackground ( QImage ( )); 149 QWSServer::setDesktopBackground ( QImage ( ));
150 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); 150 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
151 app-> setFont ( QFont ( "Helvetica", 10 )); 151 app-> setFont ( QFont ( "Helvetica", 10 ));
152 app-> setStyle ( new QPEStyle ( )); 152 app-> setStyle ( new QPEStyle ( ));
153 153
154 // const char *sig = ::strsignal ( killedbysig ); 154#ifndef __UCLIBC__
155 const char *sig = ::sys_siglist[killedbysig]; 155 const char *sig = ::sys_siglist[killedbysig];
156#else
157 const char *sig = ::strsignal ( killedbysig );
158#endif
156 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); 159 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool );
157 l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); 160 l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig ));
158 l-> setAlignment ( Qt::AlignCenter ); 161 l-> setAlignment ( Qt::AlignCenter );
159 l-> move ( 0, 0 ); 162 l-> move ( 0, 0 );
160 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 163 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
161 l-> show ( ); 164 l-> show ( );
162 QTimer::singleShot ( 3000, app, SLOT( quit())); 165 QTimer::singleShot ( 3000, app, SLOT( quit()));
163 app-> exec ( ); 166 app-> exec ( );
164 delete app; 167 delete app;
165 qApp = 0; 168 qApp = 0;
166 } 169 }
167 } 170 }
168 else { 171 else {
169 if ( !autolog ) { 172 if ( !autolog ) {
170 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf"; 173 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf";
171 Config cfg ( confFile, Config::File ); 174 Config cfg ( confFile, Config::File );
172 cfg. setGroup ( "General" ); 175 cfg. setGroup ( "General" );
173 QString user = cfg. readEntry ( "AutoLogin" ); 176 QString user = cfg. readEntry ( "AutoLogin" );
174 177
175 if ( !user. isEmpty ( )) 178 if ( !user. isEmpty ( ))
176 autolog = ::strdup ( user. latin1 ( )); 179 autolog = ::strdup ( user. latin1 ( ));
177 } 180 }
178 181
179 if ( autolog && !userExited ) { 182 if ( autolog && !userExited ) {
180 183
181 QWSServer::setDesktopBackground( QImage() ); 184 QWSServer::setDesktopBackground( QImage() );
182 ODevice::inst()->setDisplayStatus( true ); 185 ODevice::inst()->setDisplayStatus( true );
183 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 186 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
184 LoginApplication::setLoginAs( autolog ); 187 LoginApplication::setLoginAs( autolog );
185 188
186 189
187 if ( LoginApplication::changeIdentity ( )) 190 if ( LoginApplication::changeIdentity ( ))
188 ::exit ( LoginApplication::login ( )); 191 ::exit ( LoginApplication::login ( ));
189 else 192 else
190 ::exit ( 0 ); 193 ::exit ( 0 );
191 } 194 }
192 else { 195 else {
193 ::exit ( login_main ( argc, argv, ppid )); 196 ::exit ( login_main ( argc, argv, ppid ));
194 } 197 }
195 } 198 }
196 } 199 }
197 return 0; 200 return 0;
198} 201}
199 202
200void sigterm ( int /*sig*/ ) 203void sigterm ( int /*sig*/ )
201{ 204{
202 ::exit ( 0 ); 205 ::exit ( 0 );
203} 206}
204 207
205 208
206void exit_closelog ( ) 209void exit_closelog ( )
207{ 210{
208 ::closelog ( ); 211 ::closelog ( );
209} 212}
210 213
211 214
212class LoginScreenSaver : public QWSScreenSaver 215class LoginScreenSaver : public QWSScreenSaver
213{ 216{
214public: 217public:
215 LoginScreenSaver ( ) 218 LoginScreenSaver ( )
216 { 219 {
217 m_lcd_status = true; 220 m_lcd_status = true;
218 221
219 m_backlight_bright = -1; 222 m_backlight_bright = -1;
220 m_backlight_forcedoff = false; 223 m_backlight_forcedoff = false;
221 224
222 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 225 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
223 ODevice::inst ( )-> setDisplayStatus ( true ); 226 ODevice::inst ( )-> setDisplayStatus ( true );
224 } 227 }
225 void restore() 228 void restore()
226 { 229 {
227 if ( !m_lcd_status ) // We must have turned it off 230 if ( !m_lcd_status ) // We must have turned it off
228 ODevice::inst ( ) -> setDisplayStatus ( true ); 231 ODevice::inst ( ) -> setDisplayStatus ( true );
229 232
230 setBacklight ( -3 ); 233 setBacklight ( -3 );
231 } 234 }
232 bool save( int level ) 235 bool save( int level )
233 { 236 {
234 switch ( level ) { 237 switch ( level ) {
235 case 0: 238 case 0:
236 if ( backlight() > 1 ) 239 if ( backlight() > 1 )
237 setBacklight( 1 ); // lowest non-off 240 setBacklight( 1 ); // lowest non-off
238 return true; 241 return true;
239 break; 242 break;
240 case 1: 243 case 1:
241 setBacklight( 0 ); // off 244 setBacklight( 0 ); // off
242 return true; 245 return true;
243 break; 246 break;
244 case 2: 247 case 2:
245 // We're going to suspend the whole machine 248 // We're going to suspend the whole machine
246 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 249 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
247 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 250 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
248 return true; 251 return true;
249 } 252 }
250 break; 253 break;
251 } 254 }
252 return false; 255 return false;
253 } 256 }
254 257
255private: 258private:
256public: 259public:
257 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) 260 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
258 { 261 {
259 int v [4]; 262 int v [4];
260 263
261 v [ 0 ] = QMAX( 1000 * i1, 100 ); 264 v [ 0 ] = QMAX( 1000 * i1, 100 );
262 v [ 1 ] = QMAX( 1000 * i2, 100 ); 265 v [ 1 ] = QMAX( 1000 * i2, 100 );
263 v [ 2 ] = QMAX( 1000 * i3, 100 ); 266 v [ 2 ] = QMAX( 1000 * i3, 100 );
264 v [ 3 ] = 0; 267 v [ 3 ] = 0;
265 268
266 if ( !i1 && !i2 && !i3 ) 269 if ( !i1 && !i2 && !i3 )
267 QWSServer::setScreenSaverInterval ( 0 ); 270 QWSServer::setScreenSaverInterval ( 0 );
268 else 271 else
269 QWSServer::setScreenSaverIntervals ( v ); 272 QWSServer::setScreenSaverIntervals ( v );
270 } 273 }
271 274
272 int backlight ( ) 275 int backlight ( )
273 { 276 {
274 if ( m_backlight_bright == -1 ) 277 if ( m_backlight_bright == -1 )
275 m_backlight_bright = 255; 278 m_backlight_bright = 255;
276 279
277 return m_backlight_bright; 280 return m_backlight_bright;
278 } 281 }
279 282
280 void setBacklight ( int bright ) 283 void setBacklight ( int bright )
281 { 284 {
282 if ( bright == -3 ) { 285 if ( bright == -3 ) {
283 // Forced on 286 // Forced on
284 m_backlight_forcedoff = false; 287 m_backlight_forcedoff = false;
285 bright = -1; 288 bright = -1;
286 } 289 }
287 if ( m_backlight_forcedoff && bright != -2 ) 290 if ( m_backlight_forcedoff && bright != -2 )
288 return ; 291 return ;
289 if ( bright == -2 ) { 292 if ( bright == -2 ) {
290 // Toggle between off and on 293 // Toggle between off and on
291 bright = m_backlight_bright ? 0 : -1; 294 bright = m_backlight_bright ? 0 : -1;
292 m_backlight_forcedoff = !bright; 295 m_backlight_forcedoff = !bright;
293 } 296 }
294 297
295 m_backlight_bright = bright; 298 m_backlight_bright = bright;
296 299
297 bright = backlight ( ); 300 bright = backlight ( );
298 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 301 ODevice::inst ( ) -> setDisplayBrightness ( bright );
299 302
300 m_backlight_bright = bright; 303 m_backlight_bright = bright;
301 } 304 }
302 305
303private: 306private:
304 bool m_lcd_status; 307 bool m_lcd_status;
305 308
306 int m_backlight_bright; 309 int m_backlight_bright;
307 bool m_backlight_forcedoff; 310 bool m_backlight_forcedoff;
308}; 311};
309 312
310 313
311int login_main ( int argc, char **argv, pid_t ppid ) 314int login_main ( int argc, char **argv, pid_t ppid )
312{ 315{
313 QWSServer::setDesktopBackground( QImage() ); 316 QWSServer::setDesktopBackground( QImage() );
314 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 317 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
315 318
316 app-> setFont ( QFont ( "Helvetica", 10 )); 319 app-> setFont ( QFont ( "Helvetica", 10 ));
317 app-> setStyle ( new QPEStyle ( )); 320 app-> setStyle ( new QPEStyle ( ));
318 321
319 if ( QWSServer::mouseHandler() && 322 if ( QWSServer::mouseHandler() &&
320 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 323 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
321 if ( !QFile::exists ( "/etc/pointercal" )) { 324 if ( !QFile::exists ( "/etc/pointercal" )) {
322 // Make sure calibration widget starts on top. 325 // Make sure calibration widget starts on top.
323 Calibrate *cal = new Calibrate; 326 Calibrate *cal = new Calibrate;
324 cal-> exec ( ); 327 cal-> exec ( );
325 delete cal; 328 delete cal;
326 } 329 }
327 } 330 }
328 331
329 LoginScreenSaver *saver = new LoginScreenSaver; 332 LoginScreenSaver *saver = new LoginScreenSaver;
330 333
331 saver-> setIntervals ( ); 334 saver-> setIntervals ( );
332 QWSServer::setScreenSaver ( saver ); 335 QWSServer::setScreenSaver ( saver );
333 saver-> restore ( ); 336 saver-> restore ( );
334 337
335 338
336 LoginWindowImpl *lw = new LoginWindowImpl ( ); 339 LoginWindowImpl *lw = new LoginWindowImpl ( );
337 app-> setMainWidget ( lw ); 340 app-> setMainWidget ( lw );
338 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 341 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
339 lw-> show ( ); 342 lw-> show ( );
340 343
341 int rc = app-> exec ( ); 344 int rc = app-> exec ( );
342 345
343 if ( app-> loginAs ( )) { 346 if ( app-> loginAs ( )) {
344 if ( app-> changeIdentity ( )) { 347 if ( app-> changeIdentity ( )) {
345 app-> login ( ); 348 app-> login ( );
346 349
347 // if login succeeds, it never comes back 350 // if login succeeds, it never comes back
348 351
349 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); 352 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." ));
350 rc = 1; 353 rc = 1;
351 } 354 }
352 else { 355 else {
353 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); 356 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" ));
354 rc = 2; 357 rc = 2;
355 } 358 }
356 359
357 } 360 }
358 return rc; 361 return rc;
359} 362}
360 363
diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp
index 09605bd..ff06551 100644
--- a/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp
+++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp
@@ -1,386 +1,390 @@
1#include "ProcessInvoker.h" 1#include "ProcessInvoker.h"
2 2
3#ifndef PIPE_BUF // uClibc or similar
4#include <linux/limits.h>
5#endif
6
3static ProcessInvoker* g_this; 7static ProcessInvoker* g_this;
4/* ------------------------------------------------------------------------ */ 8/* ------------------------------------------------------------------------ */
5 /* static functions */ 9 /* static functions */
6/* ------------------------------------------------------------------------ */ 10/* ------------------------------------------------------------------------ */
7 11
8static Sigfunc* setSignalHandler(int signo, Sigfunc* handler) 12static Sigfunc* setSignalHandler(int signo, Sigfunc* handler)
9{ 13{
10 struct sigaction act,oact; 14 struct sigaction act,oact;
11 15
12 act.sa_handler = handler; 16 act.sa_handler = handler;
13 ::sigemptyset(&act.sa_mask); 17 ::sigemptyset(&act.sa_mask);
14 act.sa_flags = 0; 18 act.sa_flags = 0;
15 #ifdefSA_RESTART 19 #ifdefSA_RESTART
16 act.sa_flags |= SA_RESTART; 20 act.sa_flags |= SA_RESTART;
17#endif 21#endif
18 if(::sigaction(signo, &act, &oact) < 0){ 22 if(::sigaction(signo, &act, &oact) < 0){
19 return(NULL); 23 return(NULL);
20 } 24 }
21 return(oact.sa_handler); 25 return(oact.sa_handler);
22} 26}
23 27
24static void childHandler(int /*signo*/) 28static void childHandler(int /*signo*/)
25{ 29{
26 pid_t pid; 30 pid_t pid;
27 int status; 31 int status;
28 while((pid = ::waitpid(-1, &status, WNOHANG)) > 0){ 32 while((pid = ::waitpid(-1, &status, WNOHANG)) > 0){
29 if(pid == g_this->m_child){ 33 if(pid == g_this->m_child){
30 g_this->notifyFinish(status); 34 g_this->notifyFinish(status);
31 } 35 }
32 } 36 }
33} 37}
34 38
35/* ------------------------------------------------------------------------ */ 39/* ------------------------------------------------------------------------ */
36 /* ProcessInvoker Class : parent process */ 40 /* ProcessInvoker Class : parent process */
37/* ------------------------------------------------------------------------ */ 41/* ------------------------------------------------------------------------ */
38ProcessInvoker::ProcessInvoker() 42ProcessInvoker::ProcessInvoker()
39{ 43{
40 g_this = this; 44 g_this = this;
41 m_isRunning = false; 45 m_isRunning = false;
42 m_child = 0; 46 m_child = 0;
43 m_defChildHandler = SIG_DFL; 47 m_defChildHandler = SIG_DFL;
44 m_pTimer = new QTimer(this); 48 m_pTimer = new QTimer(this);
45 m_stdfd[0] = m_stdfd[1] = -1; 49 m_stdfd[0] = m_stdfd[1] = -1;
46 m_errfd[0] = m_errfd[1] = -1; 50 m_errfd[0] = m_errfd[1] = -1;
47 connect(m_pTimer, SIGNAL(timeout()), 51 connect(m_pTimer, SIGNAL(timeout()),
48 this, SLOT(readOutputs())); 52 this, SLOT(readOutputs()));
49} 53}
50 54
51ProcessInvoker::~ProcessInvoker() 55ProcessInvoker::~ProcessInvoker()
52{ 56{
53 qDebug("ProcessInvoker::~ProcessInvoker()"); 57 qDebug("ProcessInvoker::~ProcessInvoker()");
54} 58}
55 59
56bool ProcessInvoker::openPipe() 60bool ProcessInvoker::openPipe()
57{ 61{
58 if(m_stdfd[0] >= 0) closePipe(m_stdfd, 0); 62 if(m_stdfd[0] >= 0) closePipe(m_stdfd, 0);
59 if(m_stdfd[1] >= 0) closePipe(m_stdfd, 1); 63 if(m_stdfd[1] >= 0) closePipe(m_stdfd, 1);
60 if(::pipe(m_stdfd) < 0){ 64 if(::pipe(m_stdfd) < 0){
61 return(false); 65 return(false);
62 } 66 }
63 if(m_errfd[0] >= 0) closePipe(m_errfd, 0); 67 if(m_errfd[0] >= 0) closePipe(m_errfd, 0);
64 if(m_errfd[1] >= 0) closePipe(m_errfd, 1); 68 if(m_errfd[1] >= 0) closePipe(m_errfd, 1);
65 if(::pipe(m_errfd) < 0){ 69 if(::pipe(m_errfd) < 0){
66 closePipe(m_stdfd); 70 closePipe(m_stdfd);
67 return(false); 71 return(false);
68 } 72 }
69 m_maxfdp1 = m_stdfd[0]; 73 m_maxfdp1 = m_stdfd[0];
70 if(m_errfd[0] > m_maxfdp1){ 74 if(m_errfd[0] > m_maxfdp1){
71 m_maxfdp1 = m_errfd[0]; 75 m_maxfdp1 = m_errfd[0];
72 } 76 }
73 m_maxfdp1++; 77 m_maxfdp1++;
74 return(true); 78 return(true);
75} 79}
76 80
77void ProcessInvoker::closePipe(int fd[], int n) 81void ProcessInvoker::closePipe(int fd[], int n)
78{ 82{
79 if(fd == NULL){ 83 if(fd == NULL){
80 closePipe(m_stdfd, n); 84 closePipe(m_stdfd, n);
81 closePipe(m_errfd, n); 85 closePipe(m_errfd, n);
82 } else { 86 } else {
83 if(n != 1 && fd[0] >= 0){ 87 if(n != 1 && fd[0] >= 0){
84 ::close(fd[0]); 88 ::close(fd[0]);
85 fd[0] = -1; 89 fd[0] = -1;
86 } 90 }
87 if(n != 0 && fd[1] >= 0){ 91 if(n != 0 && fd[1] >= 0){
88 ::close(fd[1]); 92 ::close(fd[1]);
89 fd[1] = -1; 93 fd[1] = -1;
90 } 94 }
91 } 95 }
92} 96}
93 97
94void ProcessInvoker::setRunning(int pid) 98void ProcessInvoker::setRunning(int pid)
95{ 99{
96 m_child = pid; 100 m_child = pid;
97 m_isRunning = true; 101 m_isRunning = true;
98} 102}
99 103
100bool ProcessInvoker::run(const QString& args) 104bool ProcessInvoker::run(const QString& args)
101{ 105{
102 //setArguments(KHUtil::parseArgs(args)); 106 //setArguments(KHUtil::parseArgs(args));
103 setArguments(StringParser::split(' ', args)); 107 setArguments(StringParser::split(' ', args));
104 return(run()); 108 return(run());
105} 109}
106 110
107bool ProcessInvoker::run() 111bool ProcessInvoker::run()
108{ 112{
109 if(m_isRunning){ 113 if(m_isRunning){
110 return(false); 114 return(false);
111 } 115 }
112 m_isRunning = true; 116 m_isRunning = true;
113 if(m_arguments.isEmpty()){ 117 if(m_arguments.isEmpty()){
114 m_isRunning = false; 118 m_isRunning = false;
115 return(false); 119 return(false);
116 } 120 }
117 if(m_arguments[0][0] != '/'){ 121 if(m_arguments[0][0] != '/'){
118 m_isRunning = false; 122 m_isRunning = false;
119 return(false); 123 return(false);
120 } 124 }
121 125
122 for(QStringList::Iterator it=m_arguments.begin(); 126 for(QStringList::Iterator it=m_arguments.begin();
123 it!=m_arguments.end(); ++it){ 127 it!=m_arguments.end(); ++it){
124 qDebug("arguments[%s]", (*it).ascii()); 128 qDebug("arguments[%s]", (*it).ascii());
125 } 129 }
126 130
127 /* open pipe */ 131 /* open pipe */
128 if(openPipe() == false){ 132 if(openPipe() == false){
129 m_isRunning = false; 133 m_isRunning = false;
130 return(false); 134 return(false);
131 } 135 }
132 136
133 /* signal handler reset */ 137 /* signal handler reset */
134 m_defChildHandler = setSignalHandler(SIGCHLD, SIG_DFL); 138 m_defChildHandler = setSignalHandler(SIGCHLD, SIG_DFL);
135 139
136 m_child = ::fork(); 140 m_child = ::fork();
137 if(m_child < 0){ 141 if(m_child < 0){
138 /* fork error */ 142 /* fork error */
139 closePipe(); 143 closePipe();
140 setSignalHandler(SIGCHLD, m_defChildHandler); 144 setSignalHandler(SIGCHLD, m_defChildHandler);
141 m_isRunning = false; 145 m_isRunning = false;
142 return(false); 146 return(false);
143 } else if(m_child == 0){ 147 } else if(m_child == 0){
144 /* child process */ 148 /* child process */
145 qDebug("child process[%d]", ::getpid()); 149 qDebug("child process[%d]", ::getpid());
146 m_child = ::getpid(); 150 m_child = ::getpid();
147 //setSignalHandler(SIGCHLD, SIG_DFL); 151 //setSignalHandler(SIGCHLD, SIG_DFL);
148 workerProc(); 152 workerProc();
149 /* no return */ 153 /* no return */
150 } 154 }
151 /* close pipe(write) */ 155 /* close pipe(write) */
152 closePipe(NULL, 1); 156 closePipe(NULL, 1);
153#if 0 157#if 0
154 m_pTimer = new QTimer(this); 158 m_pTimer = new QTimer(this);
155 connect(m_pTimer, SIGNAL(timeout()), 159 connect(m_pTimer, SIGNAL(timeout()),
156 this, SLOT(readOutputs())); 160 this, SLOT(readOutputs()));
157#endif 161#endif
158 m_pTimer->start(500); 162 m_pTimer->start(500);
159 { 163 {
160 emit start(m_child, m_arguments); 164 emit start(m_child, m_arguments);
161 QCopEnvelope e(SC_CHANNEL, "start(int,QStringList)"); 165 QCopEnvelope e(SC_CHANNEL, "start(int,QStringList)");
162 e << m_child << m_arguments; 166 e << m_child << m_arguments;
163 if(m_isNotify){ 167 if(m_isNotify){
164 int idx = m_arguments[0].findRev('/'); 168 int idx = m_arguments[0].findRev('/');
165 notifyStatus(m_arguments[0].mid(idx+1), m_child); 169 notifyStatus(m_arguments[0].mid(idx+1), m_child);
166 } 170 }
167 } 171 }
168 int status; 172 int status;
169 if(::waitpid(-1, &status, WNOHANG) > 0){ 173 if(::waitpid(-1, &status, WNOHANG) > 0){
170 qDebug("finish"); 174 qDebug("finish");
171 notifyFinish(status); 175 notifyFinish(status);
172 } else { 176 } else {
173 /* signal handler set */ 177 /* signal handler set */
174 setSignalHandler(SIGCHLD, childHandler); 178 setSignalHandler(SIGCHLD, childHandler);
175 } 179 }
176 return(true); 180 return(true);
177} 181}
178 182
179void ProcessInvoker::terminate() 183void ProcessInvoker::terminate()
180{ 184{
181 if(m_isRunning && m_child > 0){ 185 if(m_isRunning && m_child > 0){
182 terminate(m_child); 186 terminate(m_child);
183 } 187 }
184} 188}
185 189
186void ProcessInvoker::terminate(pid_t pid) 190void ProcessInvoker::terminate(pid_t pid)
187{ 191{
188 ::kill(pid, SIGTERM); 192 ::kill(pid, SIGTERM);
189} 193}
190 194
191void ProcessInvoker::kill() 195void ProcessInvoker::kill()
192{ 196{
193 if(m_isRunning && m_child > 0){ 197 if(m_isRunning && m_child > 0){
194 kill(m_child); 198 kill(m_child);
195 } 199 }
196} 200}
197 201
198void ProcessInvoker::kill(pid_t pid) 202void ProcessInvoker::kill(pid_t pid)
199{ 203{
200 ::kill(pid, SIGKILL); 204 ::kill(pid, SIGKILL);
201} 205}
202 206
203#if 0 207#if 0
204const QStringList ProcessInvoker::parseArgs(const QString& arguments) 208const QStringList ProcessInvoker::parseArgs(const QString& arguments)
205{ 209{
206 QString str; 210 QString str;
207 QStringList args; 211 QStringList args;
208 char quote = 0; 212 char quote = 0;
209 char c; 213 char c;
210 for(unsigned int i=0; i<arguments.length(); i++){ 214 for(unsigned int i=0; i<arguments.length(); i++){
211 c = arguments[i]; 215 c = arguments[i];
212 switch(c){ 216 switch(c){
213 case '\"': 217 case '\"':
214 if(quote == 0){ 218 if(quote == 0){
215 quote = c; 219 quote = c;
216 } else if(quote == '\"'){ 220 } else if(quote == '\"'){
217 if(str.length() > 0){ 221 if(str.length() > 0){
218 args.append(str); 222 args.append(str);
219 } 223 }
220 str = ""; 224 str = "";
221 quote = 0; 225 quote = 0;
222 } else { 226 } else {
223 str += c; 227 str += c;
224 } 228 }
225 break; 229 break;
226 case '\'': 230 case '\'':
227 if(quote == 0){ 231 if(quote == 0){
228 quote = c; 232 quote = c;
229 } else if(quote == '\''){ 233 } else if(quote == '\''){
230 if(str.length() > 0){ 234 if(str.length() > 0){
231 args.append(str); 235 args.append(str);
232 } 236 }
233 str = ""; 237 str = "";
234 quote = 0; 238 quote = 0;
235 } else { 239 } else {
236 str += c; 240 str += c;
237 } 241 }
238 break; 242 break;
239 case ' ': 243 case ' ':
240 if(quote == 0){ 244 if(quote == 0){
241 if(str.length() > 0){ 245 if(str.length() > 0){
242 args.append(str); 246 args.append(str);
243 str = ""; 247 str = "";
244 } 248 }
245 } else { 249 } else {
246 str += c; 250 str += c;
247 } 251 }
248 break; 252 break;
249 default: 253 default:
250 str += c; 254 str += c;
251 break; 255 break;
252 } 256 }
253 } 257 }
254 if(str.length() > 0){ 258 if(str.length() > 0){
255 args.append(str); 259 args.append(str);
256 } 260 }
257 return(args); 261 return(args);
258} 262}
259#endif 263#endif
260 264
261void ProcessInvoker::readOutputs() 265void ProcessInvoker::readOutputs()
262{ 266{
263 struct timeval tmval; 267 struct timeval tmval;
264 tmval.tv_sec = 0; 268 tmval.tv_sec = 0;
265 tmval.tv_usec = 0; 269 tmval.tv_usec = 0;
266 fd_set rset; 270 fd_set rset;
267 271
268 QByteArray stdBuf, errBuf, resBuf; 272 QByteArray stdBuf, errBuf, resBuf;
269 QDataStream stdStream(stdBuf, IO_WriteOnly); 273 QDataStream stdStream(stdBuf, IO_WriteOnly);
270 QDataStream errStream(errBuf, IO_WriteOnly); 274 QDataStream errStream(errBuf, IO_WriteOnly);
271 275
272 int iRet; 276 int iRet;
273 bool running; 277 bool running;
274 char buf[PIPE_BUF+1]; 278 char buf[PIPE_BUF+1];
275 while(true){ 279 while(true){
276 running = false; 280 running = false;
277 FD_ZERO(&rset); 281 FD_ZERO(&rset);
278 if(m_stdfd[0] >= 0){ 282 if(m_stdfd[0] >= 0){
279 FD_SET(m_stdfd[0], &rset); 283 FD_SET(m_stdfd[0], &rset);
280 running = true; 284 running = true;
281 } 285 }
282 if(m_errfd[0] >= 0){ 286 if(m_errfd[0] >= 0){
283 FD_SET(m_errfd[0], &rset); 287 FD_SET(m_errfd[0], &rset);
284 running = true; 288 running = true;
285 } 289 }
286 if(running == false){ 290 if(running == false){
287 m_pTimer->stop(); 291 m_pTimer->stop();
288 //delete m_pTimer; 292 //delete m_pTimer;
289 break; 293 break;
290 } 294 }
291 295
292 if((iRet = ::select(m_maxfdp1, &rset, NULL, NULL, &tmval)) <= 0){ 296 if((iRet = ::select(m_maxfdp1, &rset, NULL, NULL, &tmval)) <= 0){
293 qDebug("select[%d]", iRet); 297 qDebug("select[%d]", iRet);
294 break; 298 break;
295 } 299 }
296 300
297 if(m_stdfd[0] >= 0 && FD_ISSET(m_stdfd[0], &rset)){ 301 if(m_stdfd[0] >= 0 && FD_ISSET(m_stdfd[0], &rset)){
298 int n = ::read(m_stdfd[0], buf, PIPE_BUF); 302 int n = ::read(m_stdfd[0], buf, PIPE_BUF);
299 if(n > 0){ 303 if(n > 0){
300 stdStream.writeRawBytes(buf, n); 304 stdStream.writeRawBytes(buf, n);
301 } else { 305 } else {
302 qDebug("stdout close"); 306 qDebug("stdout close");
303 closePipe(m_stdfd, 0); 307 closePipe(m_stdfd, 0);
304 } 308 }
305 } 309 }
306 if(m_errfd[0] >= 0 && FD_ISSET(m_errfd[0], &rset)){ 310 if(m_errfd[0] >= 0 && FD_ISSET(m_errfd[0], &rset)){
307 int n = ::read(m_errfd[0], buf, PIPE_BUF); 311 int n = ::read(m_errfd[0], buf, PIPE_BUF);
308 if(n > 0){ 312 if(n > 0){
309 errStream.writeRawBytes(buf, n); 313 errStream.writeRawBytes(buf, n);
310 } else { 314 } else {
311 qDebug("stderr close"); 315 qDebug("stderr close");
312 closePipe(m_errfd, 0); 316 closePipe(m_errfd, 0);
313 } 317 }
314 } 318 }
315 } 319 }
316 320
317 if(stdBuf.size() > 0){ 321 if(stdBuf.size() > 0){
318 QCopEnvelope e(SC_CHANNEL, "stdout(int,QByteArray)"); 322 QCopEnvelope e(SC_CHANNEL, "stdout(int,QByteArray)");
319 e << m_child << stdBuf; 323 e << m_child << stdBuf;
320 } 324 }
321 if(errBuf.size() > 0){ 325 if(errBuf.size() > 0){
322 QCopEnvelope e(SC_CHANNEL, "stderr(int,QByteArray)"); 326 QCopEnvelope e(SC_CHANNEL, "stderr(int,QByteArray)");
323 e << m_child << errBuf; 327 e << m_child << errBuf;
324 } 328 }
325 if(running == false){ 329 if(running == false){
326 QCopEnvelope e(SC_CHANNEL, "close(int)"); 330 QCopEnvelope e(SC_CHANNEL, "close(int)");
327 e << m_child; 331 e << m_child;
328 } 332 }
329} 333}
330 334
331#if 0 335#if 0
332void ProcessInvoker::waitFinish() 336void ProcessInvoker::waitFinish()
333{ 337{
334 int status; 338 int status;
335 if(::waitpid(m_child, &status, 0) > 0){ 339 if(::waitpid(m_child, &status, 0) > 0){
336 notifyFinish(status); 340 notifyFinish(status);
337 } else { 341 } else {
338 notifyFinish(0, false); 342 notifyFinish(0, false);
339 } 343 }
340} 344}
341#endif 345#endif
342 346
343void ProcessInvoker::notifyFinish(int status, bool success) 347void ProcessInvoker::notifyFinish(int status, bool success)
344{ 348{
345 bool stopped = false; 349 bool stopped = false;
346 QString result; 350 QString result;
347 int code; 351 int code;
348 if(success){ 352 if(success){
349 if(WIFEXITED(status)){ 353 if(WIFEXITED(status)){
350 code = WEXITSTATUS(status); 354 code = WEXITSTATUS(status);
351 if(code == 127){ 355 if(code == 127){
352 result = "error"; 356 result = "error";
353 } else { 357 } else {
354 result = "exit"; 358 result = "exit";
355 } 359 }
356 } else if(WIFSIGNALED(status)){ 360 } else if(WIFSIGNALED(status)){
357 result = "terminated"; 361 result = "terminated";
358 code = WTERMSIG(status); 362 code = WTERMSIG(status);
359 } else if(WIFSTOPPED(status)){ 363 } else if(WIFSTOPPED(status)){
360 result = "stopped"; 364 result = "stopped";
361 code = WSTOPSIG(status); 365 code = WSTOPSIG(status);
362 stopped = true; 366 stopped = true;
363 } else { 367 } else {
364 /* ¤³¤ì¤Ï̵¤¤¤Ï¤º? */ 368 /* ¤³¤ì¤Ï̵¤¤¤Ï¤º? */
365 result = "error"; 369 result = "error";
366 code = -2; 370 code = -2;
367 qWarning("ProcessInvoker: unknown status"); 371 qWarning("ProcessInvoker: unknown status");
368 } 372 }
369 } else { 373 } else {
370 result = "error"; 374 result = "error";
371 code = -1; 375 code = -1;
372 qWarning("ProcessInvoker: wait error"); 376 qWarning("ProcessInvoker: wait error");
373 } 377 }
374 emit finish(result, code); 378 emit finish(result, code);
375 QCopEnvelope e(SC_CHANNEL, "finish(int,QString,int)"); 379 QCopEnvelope e(SC_CHANNEL, "finish(int,QString,int)");
376 e << m_child << result << code; 380 e << m_child << result << code;
377 if(m_isNotify){ 381 if(m_isNotify){
378 notifyStatus(result, code); 382 notifyStatus(result, code);
379 setNotify(false); 383 setNotify(false);
380 } 384 }
381 if(stopped == false){ 385 if(stopped == false){
382 setSignalHandler(SIGCHLD, m_defChildHandler); 386 setSignalHandler(SIGCHLD, m_defChildHandler);
383 m_isRunning = false; 387 m_isRunning = false;
384 } 388 }
385} 389}
386 390
diff --git a/noncore/settings/sysinfo/benchmarkinfo.cpp b/noncore/settings/sysinfo/benchmarkinfo.cpp
index ac6e1fa..8de9aa1 100644
--- a/noncore/settings/sysinfo/benchmarkinfo.cpp
+++ b/noncore/settings/sysinfo/benchmarkinfo.cpp
@@ -1,406 +1,406 @@
1/********************************************************************** 1/**********************************************************************
2** BenchmarkInfo 2** BenchmarkInfo
3** 3**
4** A benchmark widget for Qt/Embedded 4** A benchmark widget for Qt/Embedded
5** 5**
6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de> 6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de>
7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp> 7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp>
8** 8**
9** This file may be distributed and/or modified under the terms of the 9** This file may be distributed and/or modified under the terms of the
10** GNU General Public License version 2 as published by the Free Software 10** GNU General Public License version 2 as published by the Free Software
11** Foundation and appearing in the file LICENSE.GPL included in the 11** Foundation and appearing in the file LICENSE.GPL included in the
12** packaging of this file. 12** packaging of this file.
13** 13**
14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16** 16**
17**********************************************************************/ 17**********************************************************************/
18 18
19#include "benchmarkinfo.h" 19#include "benchmarkinfo.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/odebug.h> 22#include <opie2/odebug.h>
23#include <opie2/ostorageinfo.h> 23#include <opie2/ostorageinfo.h>
24#include <opie2/olistview.h> 24#include <opie2/olistview.h>
25#include <opie2/oresource.h> 25#include <opie2/oresource.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/qcopenvelope_qws.h> 27#include <qpe/qcopenvelope_qws.h>
28#include <qpe/qpedecoration_qws.h> 28#include <qpe/qpedecoration_qws.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31using namespace Opie::Ui; 31using namespace Opie::Ui;
32 32
33/* QT */ 33/* QT */
34#include <qclipboard.h> 34#include <qclipboard.h>
35#include <qcolor.h> 35#include <qcolor.h>
36#include <qcombobox.h> 36#include <qcombobox.h>
37#include <qdirectpainter_qws.h> 37#include <qdirectpainter_qws.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qfiledialog.h> 40#include <qfiledialog.h>
41#include <qlabel.h> 41#include <qlabel.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qpainter.h> 43#include <qpainter.h>
44#include <qpushbutton.h> 44#include <qpushbutton.h>
45#include <qtimer.h> 45#include <qtimer.h>
46#include <qwhatsthis.h> 46#include <qwhatsthis.h>
47 47
48/* STD */ 48/* STD */
49#include <time.h> 49#include <time.h>
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <math.h> 52#include <math.h>
53#if defined (__GNUC__) && (__GNUC__ < 3) 53#if (defined (__GNUC__) && (__GNUC__ < 3)) || defined(__UCLIBC__)
54#define round qRound 54#define round qRound
55#endif 55#endif
56 56
57extern "C" 57extern "C"
58{ 58{
59 void BenchFFT( void ); 59 void BenchFFT( void );
60 double dhry_main( int ); 60 double dhry_main( int );
61} 61}
62 62
63#define DHRYSTONE_RUNS 20000000 63#define DHRYSTONE_RUNS 20000000
64#define TEST_DURATION 3 64#define TEST_DURATION 3
65 65
66//=========================================================================== 66//===========================================================================
67 67
68class BenchmarkPaintWidget : public QWidget 68class BenchmarkPaintWidget : public QWidget
69{ 69{
70 public: 70 public:
71 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) 71 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever )
72 { 72 {
73 resize( QApplication::desktop()->size() ); 73 resize( QApplication::desktop()->size() );
74 show(); 74 show();
75 p.begin( this ); 75 p.begin( this );
76 }; 76 };
77 77
78 ~BenchmarkPaintWidget() 78 ~BenchmarkPaintWidget()
79 { 79 {
80 p.end(); 80 p.end();
81 hide(); 81 hide();
82 }; 82 };
83 83
84 QPainter p; 84 QPainter p;
85}; 85};
86 86
87//=========================================================================== 87//===========================================================================
88 88
89BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) 89BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags )
90 : QWidget( parent, name, wFlags ) 90 : QWidget( parent, name, wFlags )
91{ 91{
92 92
93 setMinimumSize( 200, 150 ); 93 setMinimumSize( 200, 150 );
94 94
95 QVBoxLayout* vb = new QVBoxLayout( this ); 95 QVBoxLayout* vb = new QVBoxLayout( this );
96 vb->setSpacing( 4 ); 96 vb->setSpacing( 4 );
97 vb->setMargin( 4 ); 97 vb->setMargin( 4 );
98 98
99 tests = new OListView( this ); 99 tests = new OListView( this );
100 QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests " 100 QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests "
101 "have been performed, and comparison values for one selected device. " 101 "have been performed, and comparison values for one selected device. "
102 "Use the checkboxes to define which tests you want to perform." ) ); 102 "Use the checkboxes to define which tests you want to perform." ) );
103 tests->setMargin( 0 ); 103 tests->setMargin( 0 );
104 tests->addColumn( tr( "Tests" ) ); 104 tests->addColumn( tr( "Tests" ) );
105 tests->addColumn( tr( "Results" ) ); 105 tests->addColumn( tr( "Results" ) );
106 tests->addColumn( tr( "Comparison" ) ); 106 tests->addColumn( tr( "Comparison" ) );
107 tests->setShowSortIndicator( true ); 107 tests->setShowSortIndicator( true );
108 108
109 test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox ); 109 test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox );
110 test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox ); 110 test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox );
111 test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox ); 111 test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox );
112 test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox ); 112 test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox );
113 test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox ); 113 test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox );
114#ifndef QT_QWS_RAMSES 114#ifndef QT_QWS_RAMSES
115 test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox ); 115 test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox );
116 test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox ); 116 test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox );
117#endif 117#endif
118 test_alu->setText( 1, "n/a" ); 118 test_alu->setText( 1, "n/a" );
119 test_fpu->setText( 1, "n/a" ); 119 test_fpu->setText( 1, "n/a" );
120 test_txt->setText( 1, "n/a" ); 120 test_txt->setText( 1, "n/a" );
121 test_gfx->setText( 1, "n/a" ); 121 test_gfx->setText( 1, "n/a" );
122 test_ram->setText( 1, "n/a" ); 122 test_ram->setText( 1, "n/a" );
123#ifndef QT_QWS_RAMSES 123#ifndef QT_QWS_RAMSES
124 test_sd->setText( 1, "n/a" ); 124 test_sd->setText( 1, "n/a" );
125 test_cf->setText( 1, "n/a" ); 125 test_cf->setText( 1, "n/a" );
126#endif 126#endif
127 test_alu->setText( 2, "n/a" ); 127 test_alu->setText( 2, "n/a" );
128 test_fpu->setText( 2, "n/a" ); 128 test_fpu->setText( 2, "n/a" );
129 test_txt->setText( 2, "n/a" ); 129 test_txt->setText( 2, "n/a" );
130 test_gfx->setText( 2, "n/a" ); 130 test_gfx->setText( 2, "n/a" );
131 test_ram->setText( 2, "n/a" ); 131 test_ram->setText( 2, "n/a" );
132#ifndef QT_QWS_RAMSES 132#ifndef QT_QWS_RAMSES
133 test_sd->setText( 2, "n/a" ); 133 test_sd->setText( 2, "n/a" );
134 test_cf->setText( 2, "n/a" ); 134 test_cf->setText( 2, "n/a" );
135#endif 135#endif
136 136
137 startButton = new QPushButton( tr( "&Start Tests!" ), this ); 137 startButton = new QPushButton( tr( "&Start Tests!" ), this );
138 QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) ); 138 QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) );
139 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); 139 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) );
140 vb->addWidget( tests, 2 ); 140 vb->addWidget( tests, 2 );
141 141
142 QHBoxLayout* hb = new QHBoxLayout( vb ); 142 QHBoxLayout* hb = new QHBoxLayout( vb );
143 hb->addWidget( startButton, 2 ); 143 hb->addWidget( startButton, 2 );
144 144
145 QFile f( QPEApplication::qpeDir() + "share/sysinfo/results" ); 145 QFile f( QPEApplication::qpeDir() + "share/sysinfo/results" );
146 if ( f.open( IO_ReadOnly ) ) 146 if ( f.open( IO_ReadOnly ) )
147 { 147 {
148 machineCombo = new QComboBox( this ); 148 machineCombo = new QComboBox( this );
149 QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) ); 149 QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) );
150 150
151 QTextStream ts( &f ); 151 QTextStream ts( &f );
152 while( !ts.eof() ) 152 while( !ts.eof() )
153 { 153 {
154 QString machline = ts.readLine(); 154 QString machline = ts.readLine();
155 odebug << "sysinfo: parsing benchmark results for '" << machline << "'" << oendl; 155 odebug << "sysinfo: parsing benchmark results for '" << machline << "'" << oendl;
156 QString resline = ts.readLine(); 156 QString resline = ts.readLine();
157 machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) ); 157 machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) );
158 machineCombo->insertItem( machline ); 158 machineCombo->insertItem( machline );
159 } 159 }
160 hb->addWidget( machineCombo, 2 ); 160 hb->addWidget( machineCombo, 2 );
161 connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) ); 161 connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) );
162 } 162 }
163} 163}
164 164
165 165
166BenchmarkInfo::~BenchmarkInfo() 166BenchmarkInfo::~BenchmarkInfo()
167{} 167{}
168 168
169 169
170void BenchmarkInfo::machineActivated( int index ) 170void BenchmarkInfo::machineActivated( int index )
171{ 171{
172 QStringList* results = machines[ machineCombo->text( index ) ]; 172 QStringList* results = machines[ machineCombo->text( index ) ];
173 if ( !results ) 173 if ( !results )
174 { 174 {
175 odebug << "sysinfo: no results available." << oendl; 175 odebug << "sysinfo: no results available." << oendl;
176 return; 176 return;
177 } 177 }
178 QStringList::Iterator it = results->begin(); 178 QStringList::Iterator it = results->begin();
179 test_alu->setText( 2, *(it++) ); 179 test_alu->setText( 2, *(it++) );
180 test_fpu->setText( 2, *(it++) ); 180 test_fpu->setText( 2, *(it++) );
181 test_txt->setText( 2, *(it++) ); 181 test_txt->setText( 2, *(it++) );
182 test_gfx->setText( 2, *(it++) ); 182 test_gfx->setText( 2, *(it++) );
183 test_ram->setText( 2, *(it++) ); 183 test_ram->setText( 2, *(it++) );
184#ifndef QT_QWS_RAMSES 184#ifndef QT_QWS_RAMSES
185 test_sd->setText( 2, *(it++) ); 185 test_sd->setText( 2, *(it++) );
186 test_cf->setText( 2, *(it++) ); 186 test_cf->setText( 2, *(it++) );
187#endif 187#endif
188} 188}
189 189
190 190
191void BenchmarkInfo::run() 191void BenchmarkInfo::run()
192{ 192{
193 startButton->setText( "> Don't touch! <" ); 193 startButton->setText( "> Don't touch! <" );
194 qApp->processEvents(); 194 qApp->processEvents();
195 QTime t; 195 QTime t;
196 196
197 if ( test_alu->isOn() ) 197 if ( test_alu->isOn() )
198 { 198 {
199 int d = round( dhry_main( DHRYSTONE_RUNS ) ); 199 int d = round( dhry_main( DHRYSTONE_RUNS ) );
200 test_alu->setText( 1, QString().sprintf( "%d dhrys", d ) ); 200 test_alu->setText( 1, QString().sprintf( "%d dhrys", d ) );
201 test_alu->setOn( false ); 201 test_alu->setOn( false );
202 } 202 }
203 203
204 if ( test_fpu->isOn() ) 204 if ( test_fpu->isOn() )
205 { 205 {
206 t.start(); 206 t.start();
207 BenchFFT(); 207 BenchFFT();
208 test_fpu->setText( 1, QString().sprintf( "%.2f secs", t.elapsed() / 1000.0 ) );; 208 test_fpu->setText( 1, QString().sprintf( "%.2f secs", t.elapsed() / 1000.0 ) );;
209 test_fpu->setOn( false ); 209 test_fpu->setOn( false );
210 } 210 }
211 211
212 if ( test_txt->isOn() ) 212 if ( test_txt->isOn() )
213 { 213 {
214 int value = textRendering( TEST_DURATION ); 214 int value = textRendering( TEST_DURATION );
215 test_txt->setText( 1, QString().sprintf( "%d chars/sec", value / TEST_DURATION ) ); 215 test_txt->setText( 1, QString().sprintf( "%d chars/sec", value / TEST_DURATION ) );
216 test_txt->setOn( false ); 216 test_txt->setOn( false );
217 } 217 }
218 218
219 if ( test_gfx->isOn() ) 219 if ( test_gfx->isOn() )
220 { 220 {
221 int value = gfxRendering( TEST_DURATION ); 221 int value = gfxRendering( TEST_DURATION );
222 test_gfx->setText( 1, QString().sprintf( "%.2f gops/sec", value / 4.0 / TEST_DURATION ) ); // 4 tests 222 test_gfx->setText( 1, QString().sprintf( "%.2f gops/sec", value / 4.0 / TEST_DURATION ) ); // 4 tests
223 test_gfx->setOn( false ); 223 test_gfx->setOn( false );
224 } 224 }
225 225
226 if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA 226 if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA
227 { 227 {
228 performFileTest( "/tmp/benchmarkFile.dat", test_ram ); 228 performFileTest( "/tmp/benchmarkFile.dat", test_ram );
229 } 229 }
230 230
231#ifndef QT_QWS_RAMSES 231#ifndef QT_QWS_RAMSES
232 if ( test_cf->isOn() ) 232 if ( test_cf->isOn() )
233 { 233 {
234 OStorageInfo storage; 234 OStorageInfo storage;
235 performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf ); 235 performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf );
236 } 236 }
237 237
238 if ( test_sd->isOn() ) 238 if ( test_sd->isOn() )
239 { 239 {
240 OStorageInfo storage; 240 OStorageInfo storage;
241 performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd ); 241 performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd );
242 } 242 }
243#endif 243#endif
244 244
245 startButton->setText( tr( "&Start Tests!" ) ); 245 startButton->setText( tr( "&Start Tests!" ) );
246} 246}
247 247
248 248
249int BenchmarkInfo::textRendering( int seconds ) 249int BenchmarkInfo::textRendering( int seconds )
250{ 250{
251 QTime t; 251 QTime t;
252 t.start(); 252 t.start();
253 int stop = t.elapsed() + seconds * 1000; 253 int stop = t.elapsed() + seconds * 1000;
254 254
255 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; 255 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
256 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; 256 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
257 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; 257 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
258 const QString text( "Opie Benchmark Test" ); 258 const QString text( "Opie Benchmark Test" );
259 259
260 int w = QApplication::desktop()->width(); 260 int w = QApplication::desktop()->width();
261 int h = QApplication::desktop()->height(); 261 int h = QApplication::desktop()->height();
262 262
263 srand( time( NULL ) ); 263 srand( time( NULL ) );
264 264
265 BenchmarkPaintWidget bpw; 265 BenchmarkPaintWidget bpw;
266 266
267 int loops = 0; 267 int loops = 0;
268 268
269 while ( t.elapsed() < stop ) 269 while ( t.elapsed() < stop )
270 { 270 {
271 int k = rand() % 9; 271 int k = rand() % 9;
272 int s = rand() % 100; 272 int s = rand() % 100;
273 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 273 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
274 bpw.p.setFont( QFont( "Vera", s ) ); 274 bpw.p.setFont( QFont( "Vera", s ) );
275 bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); 275 bpw.p.drawText( rand() % w, rand() % h, text, text.length() );
276 ++loops; 276 ++loops;
277 } 277 }
278 278
279 return loops * text.length(); 279 return loops * text.length();
280} 280}
281 281
282int BenchmarkInfo::gfxRendering( int seconds ) 282int BenchmarkInfo::gfxRendering( int seconds )
283{ 283{
284 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; 284 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
285 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; 285 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
286 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; 286 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
287 287
288 int w = QApplication::desktop()->width(); 288 int w = QApplication::desktop()->width();
289 int h = QApplication::desktop()->height(); 289 int h = QApplication::desktop()->height();
290 290
291 srand( time( NULL ) ); 291 srand( time( NULL ) );
292 292
293 BenchmarkPaintWidget bpw; 293 BenchmarkPaintWidget bpw;
294 294
295 QTime t; 295 QTime t;
296 t.start(); 296 t.start();
297 int stop = t.elapsed() + seconds*1000; 297 int stop = t.elapsed() + seconds*1000;
298 int loops = 0; 298 int loops = 0;
299 299
300 while ( t.elapsed() < stop ) 300 while ( t.elapsed() < stop )
301 { 301 {
302 int k = rand() % 9; 302 int k = rand() % 9;
303 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 303 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
304 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); 304 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h );
305 ++loops; 305 ++loops;
306 } 306 }
307 307
308 t.restart(); 308 t.restart();
309 stop = t.elapsed() + seconds*1000; 309 stop = t.elapsed() + seconds*1000;
310 310
311 while ( t.elapsed() < stop ) 311 while ( t.elapsed() < stop )
312 { 312 {
313 int k = rand() % 9; 313 int k = rand() % 9;
314 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 314 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
315 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); 315 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 );
316 ++loops; 316 ++loops;
317 } 317 }
318 318
319 QBrush br1; 319 QBrush br1;
320 br1.setStyle( SolidPattern ); 320 br1.setStyle( SolidPattern );
321 t.restart(); 321 t.restart();
322 stop = t.elapsed() + seconds*1000; 322 stop = t.elapsed() + seconds*1000;
323 323
324 while ( t.elapsed() < stop ) 324 while ( t.elapsed() < stop )
325 { 325 {
326 int k = rand() % 9; 326 int k = rand() % 9;
327 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 327 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
328 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); 328 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 );
329 ++loops; 329 ++loops;
330 } 330 }
331 331
332 QPixmap p = Opie::Core::OResource::loadPixmap( "sysinfo/pattern" ); 332 QPixmap p = Opie::Core::OResource::loadPixmap( "sysinfo/pattern" );
333 t.restart(); 333 t.restart();
334 stop = t.elapsed() + seconds*1000; 334 stop = t.elapsed() + seconds*1000;
335 335
336 while ( t.elapsed() < stop ) 336 while ( t.elapsed() < stop )
337 { 337 {
338 bpw.p.drawPixmap( rand()%w, rand()%h, p ); 338 bpw.p.drawPixmap( rand()%w, rand()%h, p );
339 ++loops; 339 ++loops;
340 } 340 }
341 341
342 return loops; 342 return loops;
343 343
344} 344}
345 345
346const unsigned int FILE_TEST_COUNT = 8000; 346const unsigned int FILE_TEST_COUNT = 8000;
347const unsigned int FILE_TEST_BLOCKSIZE = 1024; 347const unsigned int FILE_TEST_BLOCKSIZE = 1024;
348 348
349void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item ) 349void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item )
350{ 350{
351 QString filename = fname == "/benchmarkFile.dat" ? QString( "/tmp/bla" ) : fname; 351 QString filename = fname == "/benchmarkFile.dat" ? QString( "/tmp/bla" ) : fname;
352 odebug << "performing file test on " << filename << oendl; 352 odebug << "performing file test on " << filename << oendl;
353 353
354 QString writeCommand = QString( "dd if=/dev/zero of=%1 count=%2 bs=%3 && sync" ).arg( filename ) 354 QString writeCommand = QString( "dd if=/dev/zero of=%1 count=%2 bs=%3 && sync" ).arg( filename )
355 .arg( FILE_TEST_COUNT ) 355 .arg( FILE_TEST_COUNT )
356 .arg( FILE_TEST_BLOCKSIZE ); 356 .arg( FILE_TEST_BLOCKSIZE );
357 QString readCommand = QString( "dd if=%1 of=/dev/null count=%2 bs=%3").arg( filename ) 357 QString readCommand = QString( "dd if=%1 of=/dev/null count=%2 bs=%3").arg( filename )
358 .arg( FILE_TEST_COUNT ) 358 .arg( FILE_TEST_COUNT )
359 .arg( FILE_TEST_BLOCKSIZE ); 359 .arg( FILE_TEST_BLOCKSIZE );
360 ::system( "sync" ); 360 ::system( "sync" );
361 odebug << "performing file test on " << filename << oendl; 361 odebug << "performing file test on " << filename << oendl;
362 362
363 int write = 0; 363 int write = 0;
364 int read = 0; 364 int read = 0;
365 365
366 QTime time; 366 QTime time;
367 time.start(); 367 time.start();
368 if ( ::system( writeCommand ) == 0 ) 368 if ( ::system( writeCommand ) == 0 )
369 { 369 {
370 write = time.elapsed(); 370 write = time.elapsed();
371 } 371 }
372 else 372 else
373 { 373 {
374 item->setText( 1, tr( "error" ) ); 374 item->setText( 1, tr( "error" ) );
375 return; 375 return;
376 } 376 }
377 377
378 time.restart(); 378 time.restart();
379 if ( ::system( readCommand ) == 0 ) 379 if ( ::system( readCommand ) == 0 )
380 { 380 {
381 read = time.elapsed(); 381 read = time.elapsed();
382 } 382 }
383 else 383 else
384 { 384 {
385 item->setText( 1, tr( "error" ) ); 385 item->setText( 1, tr( "error" ) );
386 return; 386 return;
387 } 387 }
388 388
389 QFile::remove( filename ); 389 QFile::remove( filename );
390 double readSpeed = FILE_TEST_COUNT / ( read / 1000.0 ); 390 double readSpeed = FILE_TEST_COUNT / ( read / 1000.0 );
391 QString readUnit = "kB/s"; 391 QString readUnit = "kB/s";
392 if ( readSpeed > 1024 ) 392 if ( readSpeed > 1024 )
393 { 393 {
394 readSpeed /= 1024.0; 394 readSpeed /= 1024.0;
395 readUnit = "MB/s"; 395 readUnit = "MB/s";
396 } 396 }
397 double writeSpeed = FILE_TEST_COUNT / ( write / 1000.0 ); 397 double writeSpeed = FILE_TEST_COUNT / ( write / 1000.0 );
398 QString writeUnit = "kb/s"; 398 QString writeUnit = "kb/s";
399 if ( writeSpeed > 1024 ) 399 if ( writeSpeed > 1024 )
400 { 400 {
401 writeSpeed /= 1024.0; 401 writeSpeed /= 1024.0;
402 writeUnit = "MB/s"; 402 writeUnit = "MB/s";
403 } 403 }
404 item->setText( 1, QString().sprintf( "%.2f %s; %.2f %s", readSpeed, readUnit.latin1(), writeSpeed, writeUnit.latin1() ) ); 404 item->setText( 1, QString().sprintf( "%.2f %s; %.2f %s", readSpeed, readUnit.latin1(), writeSpeed, writeUnit.latin1() ) );
405 item->setOn( false ); 405 item->setOn( false );
406} 406}