Martin A has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks.

I am writing a Gtk2-perl based mp3 player which utilizes a Gtk2::SimpleList for its playlist. The Gtk2::SimpleList (for those who don't know) is a module that simplify the use of TreeView's in Gtk2. It work by giving you a tied array as your only interface the data (in the TreeView).
I also use the "drag and drop reorder" feature of the Gtk2 TreeView which enables the user to just drag and drop the items in the list to reorder / sort there playlist. This is all nice and all but it give me a problem, The program have way of knowing when the playlist is being reordered (To my knowledge there is no Gtk2 signal for this). So when the player wants the next song in the playlist is does not know that the current song have changed place. (Hope you understand, I am having a hard time explaining this)

example:

Playlist looks like this:
0: song 1
1: song 2
3: song 4
4: song 5

a. the player plays "song 4" (currentitem = 3)
b. the user reorder the list so that "song 4" is the first entry.
c. when the player wants the next song it does (currentitem +1) = (3 +1)
but this is wrong since the currently playing song is now in the top of the list.

I can only figure out two ways of solving this, and none of them seems very good:

1. the currentitem points to the item it self and not the position in the list. Then when the next song is requested it searches through the playlist finding the item and then get the next in the list.

2. Use some tie / perl magic to notify the program when the list is reordered ( don't know is this would work, just an idea)

Martin A -- Just Another Perl Hooker
"We did not inherit the earth from our parents. We are borrowing it from our children." -- Unknown.

Replies are listed 'Best First'.
Re: Gtk2 problems (again :)
by Aristotle (Chancellor) on Jan 12, 2004 at 12:37 UTC
Re: Gtk2 problems (again :)
by Aristotle (Chancellor) on Jan 11, 2004 at 19:57 UTC
    I just had a quick look and didn't discover anything off hand. You should generally assume that to get useful answers, you need to ask on the Gtk2-Perl mailinglist.

    Makeshifts last the longest.

Re: Gtk2 problems (again :)
by CountZero (Bishop) on Jan 11, 2004 at 21:30 UTC
    There is something I don't get: if currentitem points to the item itself and not to the position in the list, you cannot do a currentitem + 1 as the value of currentitem has nothing to do with the position.

    The canonical way of doing what you want, is indeed going through the ordered list until you find the item and then going one item further to find the next. As you will not have lists with scores of thousands of items, the overhead seems small.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Gtk2 problems (again :)
by Pardus (Pilgrim) on Jan 12, 2004 at 03:21 UTC
    I just took a look at the tie magic used by SimpleList and the problem is that it isn't updated by the widget (which could of course be monitored by subclassing SimpleList) but simply queries the widget for each lookup you do in the list. Thus option 2 is impossible due to the implementation of SimpleList.

    So you need to go for option 1, which is also easier and simpler to implement anyway.

    --
    Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
    >>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<