iPodDB::Playlist - listing of playlists in a database


iPodDB documentation Contained in the iPodDB distribution.

Index


Code Index:

NAME

Top

iPodDB::Playlist - listing of playlists in a database

SYNOPSIS

Top

    my $playlists = iPodDB::Playlist->new( $frame, $songlist );
    $playlists->populate( @playlists );

DESCRIPTION

Top

This module provides a listing of the playlists in an iPod database. Clicking on a different playlist will populate the songlist it is attached to.

PROPERTIES

Top

songlist

An iPodDB::Playlist object (listing of songs in a given playlist)

METHODS

Top

new( $frame, $songlist )

This creates the list widget and makes the link to the songlist widget.

populate( @playlists )

This will populate listing and expand the tree.

select_root( )

This will select the first item in the list.

EVENTS

Top

on_item_click( )

This event will re-populate the songlist obect with the songs from the selected playlist.

AUTHOR

Top

* Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


iPodDB documentation Contained in the iPodDB distribution.
package iPodDB::Playlist;

use base qw( Wx::TreeCtrl Class::Accessor );
use Wx::Event qw( EVT_TREE_SEL_CHANGED );

use strict;
use warnings;

our $VERSION = '0.03';

__PACKAGE__->mk_accessors( qw( songlist ) );

sub new {
    my $class  = shift;
    my $parent = shift;
    my $self   = $class->SUPER::new( $parent, -1 );

    bless $self, $class;

    $self->songlist( shift );

    $self->EVT_TREE_SEL_CHANGED( $self, \&on_item_click );

    return $self;
}

sub populate {
    my $self      = shift;
    my @playlists = @_;

    $self->DeleteAllItems;

    my $id;
    my $first = 1;
    for my $playlist ( @playlists ) {
        if( $first ) {
            $first--;
            $id = $self->AddRoot( $playlist->name, -1, -1, Wx::TreeItemData->new( $playlist ) );
            next;
        }
        $self->AppendItem( $id, $playlist->name, -1, -1, Wx::TreeItemData->new( $playlist ) ) 
    }
    $self->Expand( $id ) if defined $id;
}

sub select_root {
    my $self = shift;
    $self->SelectItem( $self->GetRootItem );
}

sub on_item_click {
    my $self     = shift;
    my $event    = shift;

    # for some reason this event gets called twice initially
    return unless $event->GetOldItem or not $self->songlist->songs;

    my $database = $self->GetGrandParent->database;
    my $playlist = $self->GetPlData( $event->GetItem );
    my @songs;

    # Mac::iPod::DB::Playlist will throw an error for smartlists
    eval { $playlist->songs; };

    unless( $@ ) {
        push @songs, $database->song( $_ ) for $playlist->songs;
    }

    $self->songlist->populate( @songs );
    $self->songlist->on_select;
}

1;