]> git.etc.gen.nz Git - picture-display.git/commitdiff
Allow the directory to specified in the config file.
authorAndrew Ruthven <puck@catalyst.net.nz>
Sat, 21 Feb 2009 07:33:52 +0000 (20:33 +1300)
committerAndrew Ruthven <puck@dirk.wgtn.cat-it.co.nz>
Sat, 21 Feb 2009 07:33:52 +0000 (20:33 +1300)
lib/Display/Plugins/Photo/Directory.pm

index 93a5134991f2b4b336e7e6c9ef94ba27b0285e2c..f72760bd23eda392e7f74b20d0a283add2ef72db 100644 (file)
@@ -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";
   }
 }