Bug 73642 - Sorting on fields ETA, Last Seen and Age not correct
Summary: Sorting on fields ETA, Last Seen and Age not correct
Status: RESOLVED FIXED
Alias: None
Product: kmldonkey
Classification: Applications
Component: general (show other bugs)
Version: 0.9.1
Platform: Gentoo Packages Linux
: NOR minor
Target Milestone: ---
Assignee: Petter Stokke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-27 22:30 UTC by Henk de Leeuw
Modified: 2004-02-07 18:49 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henk de Leeuw 2004-01-27 22:30:51 UTC
Version:           0.9.1 (using KDE KDE 3.2.0)
Installed from:    Gentoo Packages
OS:          Linux

Sorting on the fields ETA, Last Seen and Age happens alphabetically instead of numerically. This renders the results of sorting useless.
I created a small patch that solves this:

--- infolist.old.cpp    2004-01-27 20:22:27.000000000 +0100
+++ infolist.cpp        2004-01-27 21:54:13.760975192 +0100
@@ -321,16 +328,22 @@
     FileInfo* it = KMLDonkey::App->donkey->findDownloadFileNo(fileno);
     if (!it) return 0.0;
     switch (col) {
-    case 1:
+    case 1:    // Priority
        return (double)it->filePriority();
-    case 4:
+    case 3:    // Speed
+       return it->fileSpeed();
+    case 4:    // Size
        return (double)it->fileSize();
-    case 5:
+    case 5:    // Downloaded
        return (double)it->fileDownloaded();
-    case 6:
+    case 6:    // %
        return it->fileSize() ? ((double)it->fileDownloaded() * 100.0) / (double)it->fileSize() : 0.0;
-    case 3:
-       return it->fileSpeed();
+    case 7:    // ETA
+       return it->fileSpeed() ? ((double)(it->fileSize() - it->fileDownloaded()) / it->fileSpeed()) : 1e9;
+    case 11:   // Last seen
+       return (double)it->fileLastSeen();
+    case 12:   // Age
+       return (double)((time_t)it->fileAge() & 0x7FFFFFFF);
     default:
        return 0.0;
     }
@@ -339,11 +352,14 @@
 bool DownloadFile::isNumeric(int col) const
 {
     switch (col) {
-    case 1:
-    case 3:
-    case 4:
-    case 5:
-    case 6:
+    case 1:    // Priority
+    case 3:    // Speed
+    case 4:    // Size
+    case 5:    // Downloaded
+    case 6:    // %
+    case 7:    // ETA
+    case 11:   // Last seen
+    case 12:   // Age
        return true;
     default:
        return false;
Comment 1 Petter Stokke 2004-02-07 18:45:31 UTC
This is mostly fixed in CVS. I'll follow up with a commit that fixes the rest.
Comment 2 Petter Stokke 2004-02-07 18:47:23 UTC
Subject: kdeextragear-2/kmldonkey/kmldonkey

CVS commit by pstokke: 

Sort the ETA field numerically.

CCMAIL: 73642-done@bugs.kde.org


  M +11 -2     infolist.cpp   1.20


--- kdeextragear-2/kmldonkey/kmldonkey/infolist.cpp  #1.19:1.20
@@ -284,4 +284,10 @@ QString humanReadableTime(time_t t, bool
 }
 
+double calculateETANumeric(FileInfo* fi)
+{
+    if (!fi->fileSpeed() || fi->fileSize() <= fi->fileDownloaded()) return 0;
+    return (double)(fi->fileSize() - fi->fileDownloaded()) / fi->fileSpeed();
+}
+
 QString calculateETA(FileInfo* fi)
 {
@@ -398,4 +404,6 @@ double DownloadFile::numeric( int col ) 
     case 6:
         return it->fileSize() ? ((double)it->fileDownloaded() * 100.0) / (double)it->fileSize() : 0.0;
+    case 7:
+        return calculateETANumeric(it);
     case 3:
         return it->fileSpeed();
@@ -403,7 +411,7 @@ double DownloadFile::numeric( int col ) 
         return (double)it->fileSources().size();
     case 11:
-        return (time_t)it->fileLastSeen();
+        return (double)((time_t)it->fileLastSeen());
     case 12:
-        return it->fileAge();
+        return (double)(time(0) - (time_t)it->fileAge());
     default:
         return 0.0;
@@ -419,4 +427,5 @@ bool DownloadFile::isNumeric(int col) co
     case 5:
     case 6:
+    case 7:
     case 9:
     case 11:


Comment 3 Petter Stokke 2004-02-07 18:49:10 UTC
It was a minor bug, really, not a wishlist item. :)