package PACMethod;
##################################################################
# This file is part of PAC( Perl Auto Connector)
#
# Copyright (C) 2010 David Torrejon Vaquerizas
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
###################################################################
$|++;
###################################################################
# Import Modules
# Standard
use strict;
use warnings;
use FindBin qw ( $RealBin $Bin $Script );
#use Data::Dumper;
# GTK2
use Gtk2 '-init';
# END: Import Modules
###################################################################
###################################################################
# Define GLOBAL CLASS variables
our $CONTAINER = Gtk2::VBox -> new( 0, 0 );
my %METHODS;
foreach my $file ( <$RealBin/lib/method/PACMethod_*.pm> )
{
next unless $file =~ /.*PACMethod_(.+).pm$/go;
my $method = $1;
eval
{
require $file;
no strict 'refs';
$METHODS{ $method } = "PACMethod_$method" -> new( $CONTAINER );
use strict 'refs';
};
die $@ if $@;
}
# END: Define GLOBAL CLASS variables
###################################################################
###################################################################
# START: Public class methods
sub new
{
my $class = shift;
my $self = {};
$self -> {container} = $CONTAINER;
$self -> {_METHOD} = undef;
$self -> {_CFG} = undef;
bless( $self, $class );
return $self;
}
sub change
{
my $self = shift;
my $method = shift;
my $cfg = shift;
$$self{_METHOD} = $method;
$$self{_METHOD} =~ s/-/_/go;
defined $cfg and $$self{_CFG} = $cfg;
$$self{container} -> foreach( sub { $_[0] -> destroy(); } );
$METHODS{$$self{_METHOD}} -> _buildGUI;
$METHODS{$$self{_METHOD}} -> update( $$self{_CFG}{'options'} );
return 1;
}
sub update
{
my $self = shift;
my $cfg = shift;
$$self{_CFG} = $cfg;
$$self{_METHOD} = $$cfg{'method'};
$$self{_METHOD} =~ s/-/_/go;
$METHODS{$$self{_METHOD}} -> update( $$self{_CFG}{'options'} );
return 1;
}
sub get_cfg
{
my $self = shift;
return $METHODS{$$self{_METHOD}} -> get_cfg;
}
# END: Public class methods
###################################################################
# END: Private functions definitions
###################################################################
1;