[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [Patch] SlaveBase progress...
From:       Craig Drummond <craig () kde ! org>
Date:       2005-05-19 21:11:51
Message-ID: 200505192211.51419.craig () kde ! org
[Download RAW message or body]

I've noticed, and so have others (http://bugs.kde.org/show_bug.cgi?id=96108), 
that the progress data shown in the UI server's progress dialog is 
inconsistent with the real progress.

Looking at kio/slavebase.cpp, I discovered that SlaveBase::processedSize() 
only emits if it has been greater than 100ms since the last update.   However, 
when copying from file:/ to fonts:/ (or event to file:/) the frequency of 
calling processedSize is quicker than 100ms, so most (all?) updates are not 
emitted. 

For example, if I have a font of 99k,   I call SlaveBase::totalSize() with this 
value, and then read 32k chunks of date. For each chunk read I call 
SlaveBase::processedSize(). As reading from a file is very fast, only the 1st 
call to SlaveBase::processedSize() ever emits a signal. This causes the 
progress bar to only be updated with the 1st 32k chunk of each file - with 
the results being similar to the bug report mentioned above.

The attached patch "fixes" this by forcing an update if 
processedSize==totalSize. Is this OK to commit? Or is there a better 
solution?

Craig.

["slavebase.cpp.patch" (text/x-diff)]

--- 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;
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic