Bug 238912

Summary: [PATCH] Copy to collection progress bar is not updated in some cases when working with iPod nano 2G and Creative Zen
Product: [Applications] amarok Reporter: Hakan Bayindir <hakan>
Component: Collections/Media DevicesAssignee: Amarok Developers <amarok-bugs-dist>
Severity: normal CC: aumuell, axel.rasmussen1, balustre, bart.cerneels, jihaire, johann.gruendl, manu.wagner, pastas4, rdieter, teuf, trlanzi, volalto86
Priority: NOR    
Version: 2.4-GIT   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In: 2.4.2
Sentry Crash Report:
Attachments: Debug log while copying one track to MTP device (Creative ZEN)
Increases debug output from StatusBar.
Debug log while copying one and two tracks, after applying increased debug patch
Patch that fixes the finalization of copy process to media devices

Description Hakan Bayindir 2010-05-26 19:01:13 UTC
Version:  (using KDE 4.4.3) 
OS:                Linux

The progress bar that tracks the completion of the tasks on the bottom right corner is not updated in two cases:
a- When copying an artist (with all sub albums) to the iPod (but not to UMS devices such as USB sticks)
b- When deleting songs from an iPod.

I'm reporting two cases in single ticket since I think they are connected to each other code-wise.

Reproducible: Always

Steps to Reproduce:
For case a:
1- Open Amarok
2- Connect and mount your iPod, Amarok will auto-mount it.
3- Select an artist from your local collection, right click it, select copy to collection, select your iPod.

Actual Results:  
- Progress bar stuck at 0%
- Text "Transferring tracks to device" appears when copying actually completes (checked transfer state with iostat).
- Copying is actually done
- Canceling after copying finished has no adverse effects.

Expected Results:  
- Progress bar shall show actual transfer percent and disappear when copying finishes.
- Text "Transferring tracks to device" shall appear when copying actually starts and shall vanish when copying completes.

Packages: Debian experimental
OS: Linux (i686) release 2.6.32-3-686-bigmem
Compiler: cc
Comment 1 Hakan Bayindir 2010-05-26 19:06:51 UTC
uh oh, forgot details for case b, which also perfectly reproducible.

---8<---Case B--------
Steps to Reproduce:
For case b:
1- Open Amarok
2- Connect and mount your iPod, Amarok will auto-mount it.
3- Select an artist/album/track from your iPod collection, right click it, select delete tracks.

Actual Results:  
- Progress bar stuck at 0%
- Text "Removing tracks from device" appears and stays forever.
- Deleting is actually done
- Canceling after deleting finished has no adverse effects.

Expected Results:  
- Progress bar shall show actual operation completion percent and disappear when deleting finishes.
- Text "Removing tracks from device" shall appear when copying actually
starts and shall vanish when deleting completes.

---8<---Case B---------
Comment 2 Axel Rasmussen 2010-08-28 00:20:04 UTC
I can confirm that I have this same bug. It happens in both cases as described.

Some information about my system:
***** Amarok 2.3.1 (-r2, Gentoo patches)
***** KDE 4.4.5

- Latest GIT copy of libgpod as of a few days ago.
- gcc (Gentoo 4.4.3-r2 p1.2) 4.4.3
- x86_64 Architecture, Gentoo Kernel 2.6.34-r1
- Sixth-generation iPod Classic (160 GB)

I can provide any other information/testing that is needed if I've left anything out.
Comment 3 Myriam Schweingruber 2010-08-28 08:58:17 UTC
Confirmed by comment #2
Comment 4 frederic dinh 2010-10-26 21:54:21 UTC
In my case, the progress bar is not updated whenever i copy something (a track / an album / an artist) on my ipod
Comment 5 Timothy Lanzi 2011-01-05 02:08:22 UTC
Amarok 2.4-GIT, kubuntu 10.10 , iPod 2g nano – CASE A – When copying artist to iPod, progress bar does not display live status (bug still present). CASE B – When deleting artist from iPod, Amarok crashes (see bug 260275). (CASE C - When copying album to iPod, progress bar **does** show status properly.)
Comment 6 Myriam Schweingruber 2011-01-05 11:15:02 UTC
Thanks for testing, changing version.
Comment 7 Tommaso Falchi Delitala 2011-02-06 14:30:38 UTC
Version:           2.4.0 (KDE 4.6.0) 
OS:                  Linux x64

I do confirm this behaviour. When copying music to my Creative Zen (MTP device) the transfer process seems not to be correctly finalized. This means that:

- Status bar is is not updated (i.e. it's stuck to 0% when one track is copied and to 80-90% when multiple tracks are copied)
- Amarok refuses to start a new transfer job since the previous one is marked as still in progress

In fact tracks are correctly transferred to the device. 
The problem seems to lie in how Amarok handles the finalization of the transfer job.
Comment 8 balustre 2011-02-16 19:16:38 UTC
Same bug here with my Creative Zen (MTP device) on Fedora 14. Progress bar starts from 0% to 89% (0, 10,20...) then stops there until i unmount the device. I cannot start another transfer neither.

Are there some tests i can run to help finding the problem ?
Comment 9 johann.gruendl 2011-04-08 00:47:07 UTC
Similar or same behaviour here. I'm using Amarok 2.4.0 under KDE 4.6.1 on an up-to-date Archlinux installation. When copying files to my Samsung YP-S3 (MTP-device) through Amarok the progress bar gets stuck somewhere around 90 % most of the time (had 90 %, 97 %, 99 %, when copying tracks it even stopped at 45 %). I copied Artists, Albums and Multiple Tracks.
Comment 10 Tommaso Falchi Delitala 2011-05-17 12:19:24 UTC
Created attachment 60076 [details]
Debug log while copying one track to MTP device (Creative ZEN)
Comment 11 Tommaso Falchi Delitala 2011-05-17 12:23:56 UTC
I attach the debug output while copying one single track to my Creative Zen

The track is transferred correctly and looking at the debug log the operation
seems to be finalized properly, but nevertheless the transfer bar is stuck to

Similar behavior when synching N multiple tracks: bar updated for N-1 tracks
and stuck after copying the Nth.

This bug really affects the (already poor) usability of amarok as a mp3 device
manager...I would suggest to raise its priority.
Comment 12 Tommaso Falchi Delitala 2011-05-23 11:26:34 UTC
Same issue with my sister's Samsung YP-T10.

This problem seems to be a general flaw of Amarok's MTP file transfer implementation, since it shows up with different MTP devices. 

I suggest to update the bug's title to:
"Copy to collection progress bar is not updated when working with MTP devices"
Comment 13 Axel Rasmussen 2011-05-24 03:52:11 UTC
Actually, this bug seems to be fixed in the current git sources, although it is still present in Amarok 2.4.0 (KDE 4.6.2).

I only have an iPod to test with, not an MTP device, but I would be /very/ surprised if this bug was in a device-specific portion of the code.

Anyone willing to grab the latest git sources and verify?
Comment 14 Tommaso Falchi Delitala 2011-05-24 12:58:00 UTC
Just tried the latest GIT. The problem persists.

Amarok 2.4-git (May 24th), KDE 4.6.3
Arch Linux 64bit, libMTP 1.0.6, libGphoto2
Comment 15 Axel Rasmussen 2011-05-24 22:48:32 UTC
Created attachment 60286 [details]
Increases debug output from StatusBar.
Comment 16 Axel Rasmussen 2011-05-24 22:52:03 UTC
Can you apply the patch I just attached to your copy of the git tree, and give me the resulting debug log from when you try to copy a track/album/whatever?

I still cannot reproduce this bug in the current git sources; the progress update is handled by MediaDeviceHandler::slotFinalizeTrackCopy(), which is device-independent -- the same code gets used for MTP devices, iPods, and USB mass storage.

I am curious as to whether or not StatusBar::incrementProgress() is getting called in your case, since it seems to work as expected when I try it.
Comment 17 Tommaso Falchi Delitala 2011-05-25 16:07:40 UTC
Created attachment 60320 [details]
Debug log while copying one and two tracks, after applying increased debug patch

Debug log in two cases:
1) Copying one single track: bar hangs at 0%
2) Copying two tracks: bar hangs at 50%

I can't see anything wrong in the log file.
Comment 18 Tommaso Falchi Delitala 2011-06-16 01:07:01 UTC
I had a look at the source code and I may have found something wrong.

There is a MediaDeviceHandler::slotCopyTrackJobsDone() which finishes the progress bar and notifies amarok that the copy process is complete. 
It also seems never to be used anywhere in the code. There is no method calling it nor any signal connected to it.

Could this be the problem? 

MediaDeviceHandler::slotFinalizeTrackCopy() takes care of finalizing the copy of every single track, but the copy job itself never get finalized properly.
Comment 19 Tommaso Falchi Delitala 2011-06-16 02:23:40 UTC
Adding a direct call to slotCopyTrackJobsDone() does the trick. The transfer job is properly finalized!

This is my quick and dirty experiment:

void MediaDeviceHandler::enqueueNextCopyThread()
//Added part--------------
    debug() << "No more tracks to copy...done";
    slotCopyTrackJobsDone((ThreadWeaver::Job*) NULL);

I don't think this is the way this method it's meant to be used and I'm not sure MediaDeviceHandler::enqueueNextCopyThread() is the right place to start the process finalization, though.
Comment 20 Tommaso Falchi Delitala 2011-06-17 02:21:17 UTC
Created attachment 61065 [details]
Patch that fixes the finalization of copy process to media devices

I'm attaching a patch that fixes the problem. 

The patch gets rid of the unused slot MediaDeviceHandler::slotCopyTrackJobsDone() and incorporates into MediaDeviceHandler::slotCopyTrackJobsDone() the proper steps for the copy process to be finalized correctly, in case no tracks are left to be transferred.
Comment 21 Myriam Schweingruber 2011-06-17 11:28:13 UTC
Tommaso, thank youfor the patch. Please submit it to http://reviewboard.kde.org. You might need to get an identity first at http://identity.kde.org
Comment 22 Bart Cerneels 2011-06-19 08:29:52 UTC
Git commit 7e48852a1763e4ac3a1089c5891b84515438e34b by Bart Cerneels.
Committed on 19/06/2011 at 08:26.
Pushed by shanachie into branch 'master'.

Fix finalization of track copy process.

... to media device collections.

Patch by Tommaso Falchi Delitala.


M  +2    -0    ChangeLog     
M  +9    -14   src/core-impl/collections/mediadevicecollection/handler/MediaDeviceHandler.cpp     
M  +0    -1    src/core-impl/collections/mediadevicecollection/handler/MediaDeviceHandler.h     

Comment 23 Sven Krohlas 2011-06-26 16:00:52 UTC
*** Bug 276536 has been marked as a duplicate of this bug. ***