# Album Plugin:	dir_thumbs/file
# For info:	'album -plugin_info dir_thumbs/file'
# For usage:	'album -plugin_usage dir_thumbs/file'
use strict;

my $DESC = <<DESC;
This will use the file "dirthumb.jpg" as the directory thumbnail
in the parent album.
DESC


##Hook: dir_image
##  Args: ($opt,$data, 'dir_image',  $child)
##  Description: Picks the image for a directory thumbnail
##  Returns: thumb path, full path to image, local path to image, image filename
##    Thumb path:  Where the tn/ directory and the thumbnail gets created
##    = (local path from the current working directory)
##    Full path to image:  Path to full size image from current working directory
##    Local path:  Thumbnail path, but from the current album directory.
##    Image filename:  Just the image part of the filename.
##
##    The thumbnail path and the path used in the full path to the image
##    don't have to be the same, but they probably will be.
##
##    Example:  (album/dir/, dir/, album/dir/image.gif, image.gif)


sub start_plugin {
    my ($opt) = @_;

    album::hook($opt, 'dir_thumb', \&dirthumb);
    return {
        author => 'Joey Richards',
        href => 'http://www.borkbork.org/~bigjoe',
        version => '0.1',
        description => 'Specify an image for the directory thumbnail.'
        };
}

sub dirthumb {
    my ($opt, $data, $s, $child) = @_;

    my $dir = $data->{paths}{dir};
    my $child_path = "$dir/$child";

    if (-e "$child_path/dirthumb.jpg") {
        return ($child_path, $child, "$child_path/dirthumb.jpg", "dirthumb.jpg");
    } else {
        return undef;
    }
}
