From: Andrew Ruthven Date: Sat, 21 Feb 2009 07:33:52 +0000 (+1300) Subject: Allow the directory to specified in the config file. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c52b258b86be4c98f00dd9e0dc686139d955c9de;p=picture-display.git Allow the directory to specified in the config file. --- diff --git a/lib/Display/Plugins/Photo/Directory.pm b/lib/Display/Plugins/Photo/Directory.pm index 93a5134..f72760b 100644 --- a/lib/Display/Plugins/Photo/Directory.pm +++ b/lib/Display/Plugins/Photo/Directory.pm @@ -5,7 +5,7 @@ use Clutter; use POE::Session; use FindBin qw/$Bin/; -my $directory = "$Bin/test_images"; +my $default_directory = "$Bin/test_images"; sub new { my $proto = shift; @@ -13,6 +13,9 @@ sub new { my $self = $class->SUPER::new(@_); + $self->{'directory'} = + $self->{'config'}{'_config'}{'plugins'}{'Directory'}{'Directory'} || $default_directory; + bless ($self, $class); $self->{'kernel'}->yield('find_photo'); return $self; @@ -21,13 +24,13 @@ sub new { sub find_photo { my $self = shift; - if (opendir(DIR, $directory)) { + if (opendir(DIR, $self->{'directory'})) { my @files = readdir(DIR); closedir DIR; - $self->{'kernel'}->yield('display_photo', join("/", $directory, $files[rand @files])); + $self->{'kernel'}->yield('display_photo', join("/", $self->{'directory'}, $files[rand @files])); } else { - warn "Failed to open $directory for reading: $!\n"; + warn "Failed to open $self->{'directory'} for reading: $!\n"; } }