###########################################################################
#
# PharosVideoPlugin - an VideoPlugin that can also do pharos related tasks.
#
# A component of the Greenstone digital library software
# from the New Zealand Digital Library Project at the 
# University of Waikato, New Zealand.
#
# Copyright (C) 2008 New Zealand Digital Library Project
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###########################################################################
package PharosVideoPlugin;

use VideoPlugin;
use PharosImageIndexer;

use strict;
no strict 'refs'; # allow filehandles to be variables and viceversa

use gsprintf 'gsprintf';

BEGIN {
    @PharosVideoPlugin::ISA = ('VideoPlugin', 'PharosImageIndexer');
}

my $arguments = [
		 ];

my $options = { 'name' => "PharosVideoPlugin",
		'desc' => "{PharosVideoPlugin.desc}",
		'abstract' => "no",
		'inherits' => "yes",
		'args' => $arguments };

sub new {
    my ($class) = shift (@_);
    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
    push(@$pluginlist, $class);

    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
    push(@{$hashArgOptLists->{"OptList"}},$options);

    new PharosImageIndexer($pluginlist, $inputargs, $hashArgOptLists);
    my $self = new VideoPlugin($pluginlist, $inputargs, $hashArgOptLists);


    return bless $self, $class;

}

# needs to be called after BasePlugin init, so that outhandle is set up.
sub init {
    my $self = shift(@_);
    my ($verbosity, $outhandle, $failhandle) = @_;

    $self->SUPER::init(@_);
    $self->PharosImageIndexer::init();

}

sub remove_all {
    my $self = shift (@_);
    my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
    
    $self->SUPER::remove_all(@_);
    $self->PharosImageIndexer::remove_all(@_);
   
}

sub remove_one {
    my $self = shift (@_);
    my ($file, $oids, $archivedir) = @_;
    return undef if (!$self->can_process_this_file($file));
    
    $self->PharosImageIndexer::remove_one(@_);
    return $self->SUPER::remove_one(@_);
        
}


sub post_process_doc_obj {
    my $self = shift (@_);
    # options??
    my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;

    my $topsection = $doc_obj->get_top_section();

    my $assoc_files = $doc_obj->get_assoc_files();


    my $docid = $doc_obj->get_OID();

    foreach my $ar (@$assoc_files) {
	my ($real_filename,$afile,$mimetype,$section) = @$ar;
	if ($afile =~ m/^keyframe/) {

	    my $secid = $docid;
	    if ($section ne "") {
		$secid .= ".$section";
	    }

	    $self->pharos_index_image($real_filename, $doc_obj, $secid);
	}
    }
}



1;	
