Bug 130667 - collection browser sorts numerical columns incorrectly
Summary: collection browser sorts numerical columns incorrectly
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR minor
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
: 132646 132948 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-12 03:44 UTC by Aaron VonderHaar
Modified: 2006-08-25 10:12 UTC (History)
3 users (show)

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 Aaron VonderHaar 2006-07-12 03:44:34 UTC
Version:            (using KDE KDE 3.5.2)
Installed from:    Compiled From Sources
Compiler:          gcc (GCC) 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9) 
OS:                Linux

In the collection browser, in flat view if you display a column that includes a numerical value (such as Length or Score), and then sort on that column, the table is sorted by the string value instead of by the numerical value (10:30 comes before 5:00).

The culprit is the CollectionItem::compare() function.  It should be modified to have additional logic similar to PlaylistItem::compare().
Comment 1 Stefan Borggraefe 2006-07-12 13:32:55 UTC
Confirming with Amarok 1.4.1 final.
Comment 2 Alexandre Oliveira 2006-08-21 17:26:54 UTC
*** Bug 132646 has been marked as a duplicate of this bug. ***
Comment 3 Martin Aumueller 2006-08-22 04:17:40 UTC
SVN commit 575764 by aumuell:

numeric sort for numeric columns in flat collection view
BUG: 130667


 M  +1 -0      ChangeLog  
 M  +38 -9     src/collectionbrowser.cpp  


--- trunk/extragear/multimedia/amarok/ChangeLog #575763:575764
@@ -10,6 +10,7 @@
   CHANGES:
 
   BUGFIXES:
+    * Sort numeric columns in flat collection numerically. (BR 130667)
 
 VERSION 1.4.2:
   FEATURES:
--- trunk/extragear/multimedia/amarok/src/collectionbrowser.cpp #575763:575764
@@ -3781,9 +3781,9 @@
                     w += correct;
                     correct = 0;
                     setColumnWidth( c, w );
-                    if( m_viewMode == modeFlatView )
-                        m_flatColumnWidths.push_back( w );
                 }
+                if( m_viewMode == modeFlatView )
+                    m_flatColumnWidths.push_back( w );
             }
         }
 
@@ -3806,7 +3806,6 @@
         setColumnWidth( 0, width - col1width );
     }
 
-
     // Needed for correct redraw of bubble help
     triggerUpdate();
 }
@@ -3911,13 +3910,43 @@
     // Sampler is the first one in iPod view
     CollectionView* view = static_cast<CollectionView*>( listView() );
     if( view->viewMode() == CollectionView::modeIpodView )
-      {
-	if ( m_isSampler )
-	  return -1;
-	if ( dynamic_cast<CollectionItem*>( i ) && static_cast<CollectionItem*>( i )->m_isSampler )
-	  return 1;
-      }
+    {
+        if ( m_isSampler )
+            return -1;
+        if ( dynamic_cast<CollectionItem*>( i ) && static_cast<CollectionItem*>( i )->m_isSampler )
+            return 1;
+    }
+    else if( view->viewMode() == CollectionView::modeFlatView )
+    {
+        ia = ib = 0;
+        // correctly treat numeric values
+        switch( col )
+        {
+            case CollectionView::Track:
+            case CollectionView::DiscNumber:
+            case CollectionView::Bitrate:
+            case CollectionView::Score:
+            case CollectionView::Rating:
+            case CollectionView::Playcount:
+            case CollectionView::BPM:
+                ia = a.toInt();
+                ib = b.toInt();
+                break;
+            case CollectionView::Length:
+                ia = a.section( ':', 0, 0 ).toInt() * 60 + a.section( ':', 1, 1 ).toInt();
+                ib = b.section( ':', 0, 0 ).toInt() * 60 + b.section( ':', 1, 1 ).toInt();
+                break;
+        }
 
+        if( ia || ib )
+        {
+            if( ia < ib )
+                return 1;
+            if( ia > ib )
+                return -1;
+            return 0;
+        }
+    }
 
     // Unknown is always the first one unless we're doing iPod view, but if the two items to be compared are Unknown,
     // then compare the normal way
Comment 4 Martin Aumueller 2006-08-25 10:12:08 UTC
*** Bug 132948 has been marked as a duplicate of this bug. ***