From kde-core-devel Thu May 19 21:11:51 2005 From: Craig Drummond Date: Thu, 19 May 2005 21:11:51 +0000 To: kde-core-devel Subject: [Patch] SlaveBase progress... Message-Id: <200505192211.51419.craig () kde ! org> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=111653689824379 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_XEQjCJElKiujwKO" --Boundary-00=_XEQjCJElKiujwKO Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I've noticed, and so have others (http://bugs.kde.org/show_bug.cgi?id=3D961= 08),=20 that the progress data shown in the UI server's progress dialog is=20 inconsistent with the real progress. Looking at kio/slavebase.cpp, I discovered that SlaveBase::processedSize()= =20 only emits if it has been greater than 100ms since the last update. =C2=A0H= owever,=20 when copying from file:/ to fonts:/ (or event to file:/) the frequency of=20 calling processedSize is quicker than 100ms, so most (all?) updates are not= =20 emitted.=20 =46or example, if I have a font of 99k, =C2=A0I call SlaveBase::totalSize()= with this=20 value, and then read 32k chunks of date. For each chunk read I call=20 SlaveBase::processedSize(). As reading from a file is very fast, only the 1= st=20 call to SlaveBase::processedSize() ever emits a signal. This causes the=20 progress bar to only be updated with the 1st 32k chunk of each file - with= =20 the results being similar to the bug report mentioned above. The attached patch "fixes" this by forcing an update if=20 processedSize=3D=3DtotalSize. Is this OK to commit? Or is there a better=20 solution? Craig. --Boundary-00=_XEQjCJElKiujwKO Content-Type: text/x-diff; charset="utf-8"; name="slavebase.cpp.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="slavebase.cpp.patch" --- slavebase.cpp.orig 2005-05-19 21:16:24.000000000 +0100 +++ slavebase.cpp 2005-05-19 21:32:21.000000000 +0100 @@ -486,27 +486,36 @@ void SlaveBase::processedSize( KIO::filesize_t _bytes ) { + bool emitSignal=false; struct timeval tv; - if ( gettimeofday( &tv, 0L ) == 0 ) { - time_t msecdiff = 2000; - if (d->last_tv.tv_sec) { - // Compute difference, in ms - msecdiff = 1000 * ( tv.tv_sec - d->last_tv.tv_sec ); - time_t usecdiff = tv.tv_usec - d->last_tv.tv_usec; - if ( usecdiff < 0 ) { - msecdiff--; - msecdiff += 1000; - } - msecdiff += usecdiff / 1000; - } - if ( msecdiff >= 100 ) { // emit size 10 times a second - KIO_DATA << KIO_FILESIZE_T(_bytes); - slaveWriteError = false; - m_pConnection->send( INF_PROCESSED_SIZE, data ); + int gettimeofday_res=gettimeofday( &tv, 0L ); + + if( _bytes == d->totalSize ) + emitSignal=true; + else if ( gettimeofday_res == 0 ) { + time_t msecdiff = 2000; + if (d->last_tv.tv_sec) { + // Compute difference, in ms + msecdiff = 1000 * ( tv.tv_sec - d->last_tv.tv_sec ); + time_t usecdiff = tv.tv_usec - d->last_tv.tv_usec; + if ( usecdiff < 0 ) { + msecdiff--; + msecdiff += 1000; + } + msecdiff += usecdiff / 1000; + } + emitSignal=msecdiff >= 100; // emit size 10 times a second + } + + if( emitSignal ) { + KIO_DATA << KIO_FILESIZE_T(_bytes); + slaveWriteError = false; + m_pConnection->send( INF_PROCESSED_SIZE, data ); if (slaveWriteError) exit(); - d->last_tv.tv_sec = tv.tv_sec; - d->last_tv.tv_usec = tv.tv_usec; - } + if ( gettimeofday_res == 0 ) { + d->last_tv.tv_sec = tv.tv_sec; + d->last_tv.tv_usec = tv.tv_usec; + } } // d->processed_size = _bytes; } --Boundary-00=_XEQjCJElKiujwKO--