From 4de35184d51665ae5743e76472a1d717199690c2 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 21 Feb 2009 20:39:39 +1300 Subject: [PATCH] Show images alternating between two directories. --- .../Plugins/Photo/AlternatingDirectories.pm | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/Display/Plugins/Photo/AlternatingDirectories.pm diff --git a/lib/Display/Plugins/Photo/AlternatingDirectories.pm b/lib/Display/Plugins/Photo/AlternatingDirectories.pm new file mode 100644 index 0000000..0c5c7c1 --- /dev/null +++ b/lib/Display/Plugins/Photo/AlternatingDirectories.pm @@ -0,0 +1,57 @@ +package Display::Plugins::Photo::AlternatingDirectories; + +use base ('Display::Plugins::Photo'); +use Clutter; +use POE::Session; +use FindBin qw/$Bin/; + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + + my $self = $class->SUPER::new(@_); + + $self->{'current_directory'} = -1; + + bless ($self, $class); + $self->{'kernel'}->yield('find_photo'); + return $self; +} + +sub find_photo { + my $self = shift; + + $self->{'current directory'} = + ($self->{'current directory'} + 1) % @{ $self->{'config'}{'_config'}{'plugins'}{'AlternatingDirectories'}{'Directories'} }; + +#pr#int join(", ", @{ $self->{'config'}{'_config'}{'plugins'}{'AlternatingDirectories'}{'Directories'} }) . "\n"; +#print "dir: $self->{'current directory'}\n"; + + my $directory = $self->{'config'}{'_config'}{'plugins'}{'AlternatingDirectories'}{'Directories'}[$self->{'current directory'}]; + + $self->{'directory state'}{$directory} ||= ''; + + if (opendir(DIR, $directory)) { + my @files = sort readdir(DIR); + closedir DIR; + + my $photo = $files[0]; + for my $file (@files) { +#print "$file cmp $self->{'directory state'}{$directory} = " . ($file cmp $self->{'directory state'}{$directory}) . "\n"; + if ($file cmp $self->{'directory state'}{$directory} > 1) { + next unless $file =~ /(jpg|png|gif)$/; + $photo = $file; + last; + } + } + + $self->{'directory state'}{$directory} = $photo; + +#print "photo: $directory/$photo\n"; + $self->{'kernel'}->yield('display_photo', join("/", $directory, $photo)); + } else { + warn "Failed to open $directory for reading: $!\n"; + } +} + +1; -- 2.30.2