Bug 134333 - Negative duration for Last.fm track
Summary: Negative duration for Last.fm track
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: general (show other bugs)
Version: 1.4.3
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-19 15:33 UTC by Bram Schoenmakers
Modified: 2006-11-29 00:06 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Update playlist lenghs when playlistitem changes (3.87 KB, patch)
2006-11-25 00:34 UTC, Modestas Vainius
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bram Schoenmakers 2006-09-19 15:33:19 UTC
Version:           1.4.3 (using KDE KDE 3.5.4)
Installed from:    Gentoo Packages
Compiler:          gcc 4.1.1 
OS:                Linux

While playing Last.fm neighbour radio, the track length in the status bar is displayed wrong:

1 track (-10:4294967254)

I think it should display the current track's length instead.
Comment 1 Modestas Vainius 2006-11-25 00:34:50 UTC
Created attachment 18695 [details]
Update playlist lenghs when playlistitem changes

Properly compute total playlist length if there are tracks with dynamic lengths
(e.g. last.fm streams) in the playlist.

The patch is against amarok 1.4.4
Comment 2 Martin Aumueller 2006-11-29 00:06:57 UTC
SVN commit 608931 by aumuell:

correctly update total playlist play time when removing last.fm streams
- thanks to Modestas Vainius <geromanas@mailas.com> for the patch!
BUG: 134333


 M  +2 -0      ChangeLog  
 M  +68 -28    src/playlistitem.cpp  
 M  +5 -0      src/playlistitem.h  


--- trunk/extragear/multimedia/amarok/ChangeLog #608930:608931
@@ -39,6 +39,8 @@
     * Amarok now saves playlists with relative paths by default.
 
   BUGFIXES:
+    * Correctly update total playlist play time when removing last.fm
+      streams. Patch by Modestas Vainius <geromanas@mailas.com>. (BR 134333)
     * File organization jobs could not be canceled. Patch by Wenli Liu
       <wenlil@xandros.com>. (BR 136527)
     * Sending filenames to MTP media devices as UTF-8 caused problems, use
--- trunk/extragear/multimedia/amarok/src/playlistitem.cpp #608930:608931
@@ -71,19 +71,8 @@
 
     refAlbum();
 
-    listView()->m_totalCount++;
-    listView()->m_totalLength += length();
-    if( isSelected() )
-    {
-        listView()->m_selCount++;
-        listView()->m_selLength += length();
-    }
-    if( isVisible() )
-    {
-        listView()->m_visCount++;
-        listView()->m_visLength += length();
-        incrementTotals();
-    }
+    incrementCounts();
+    incrementLengths();
 
     filter( listView()->m_filter );
 
@@ -96,19 +85,8 @@
     if( isEmpty() ) //constructed with the generic constructor, for PlaylistLoader's marker item
         return;
 
-    listView()->m_totalCount--;
-    listView()->m_totalLength -= length();
-    if( isSelected() )
-    {
-        listView()->m_selCount--;
-        listView()->m_selLength -= length();
-    }
-    if( isVisible() )
-    {
-        listView()->m_visCount--;
-        listView()->m_visLength -= length();
-        decrementTotals();
-    }
+    decrementCounts();
+    decrementLengths();
 
     derefAlbum();
 
@@ -160,13 +138,16 @@
 
 void PlaylistItem::aboutToChange( const QValueList<int> &columns )
 {
-    bool totals = false, ref = false;
+    bool totals = false, ref = false, length = false;
     for( int i = 0, n = columns.count(); i < n; ++i )
         switch( columns[i] )
         {
+	    case Length: length = true; break;
             case Artist: case Album: ref = true; //note, no breaks
             case Track: case Rating: case Score: case LastPlayed: totals = true;
         }
+    if ( length )
+        decrementLengths();
     if( totals )
         decrementTotals();
     if( ref )
@@ -176,11 +157,16 @@
 void PlaylistItem::reactToChanges( const QValueList<int> &columns )
 {
     MetaBundle::reactToChanges(columns);
-    bool totals = false, ref = false;
+    bool totals = false, ref = false, length = false;
     for( int i = 0, n = columns.count(); i < n; ++i )
       {
         if( columns[i] == Mood )
           moodbar().reset();
+	if ( !length && columns[i] == Length ) {
+	    length = true;
+	    incrementLengths();
+	    listView()->countChanged();
+	}
         switch( columns[i] )
         {
             case Artist: case Album: ref = true; //note, no breaks
@@ -1069,6 +1055,60 @@
     }
 }
 
+void PlaylistItem::incrementCounts()
+{
+    listView()->m_totalCount++;
+    if( isSelected() )
+    {
+        listView()->m_selCount++;
+    }
+    if( isVisible() )
+    {
+        listView()->m_visCount++;
+        incrementTotals();
+    }
+}
+
+void PlaylistItem::decrementCounts()
+{
+    listView()->m_totalCount--;
+    if( isSelected() )
+    {
+        listView()->m_selCount--;
+    }
+    if( isVisible() )
+    {
+        listView()->m_visCount--;
+        decrementTotals();
+    }
+}
+
+void PlaylistItem::incrementLengths()
+{
+    listView()->m_totalLength += length();
+    if( isSelected() )
+    {
+        listView()->m_selLength += length();
+    }
+    if( isVisible() )
+    {
+        listView()->m_visLength += length();
+    }
+}
+
+void PlaylistItem::decrementLengths()
+{
+    listView()->m_totalLength -= length();
+    if( isSelected() )
+    {
+        listView()->m_selLength -= length();
+    }
+    if( isVisible() )
+    {
+        listView()->m_visLength -= length();
+    }
+}
+
 QPixmap *PlaylistItem::s_star = 0;
 QPixmap *PlaylistItem::s_grayedStar = 0;
 QPixmap *PlaylistItem::s_smallStar = 0;
--- trunk/extragear/multimedia/amarok/src/playlistitem.h #608930:608931
@@ -149,6 +149,11 @@
         void decrementTotals();
         void incrementTotals();
 
+        void incrementCounts();
+        void decrementCounts();
+        void incrementLengths();
+        void decrementLengths();
+
         int totalIncrementAmount() const;
 
         PlaylistAlbum *m_album;