--- /dev/null
+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;