From: Andrew Ruthven Date: Sat, 27 Sep 2008 08:58:31 +0000 (+1200) Subject: Create a new base object for the photo classes which contains common code. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74d3ae7812b4fd44dcbacd53a9ef8e23b231fc15;p=picture-display.git Create a new base object for the photo classes which contains common code. Now the Directory plugin has nice fade out and in features! --- diff --git a/lib/Display/Plugins/Directory.pm b/lib/Display/Plugins/Directory.pm deleted file mode 100644 index ea98e73..0000000 --- a/lib/Display/Plugins/Directory.pm +++ /dev/null @@ -1,93 +0,0 @@ -package Display::Plugins::Directory; - -use base ('Display::Plugin'); -use Clutter; -use POE; -use FindBin qw/$Bin/; - -my $directory = "$Bin/test_images"; - -sub new { - my $proto = shift; - my $class = ref($proto) || $proto; - - my $self = $class->SUPER::new(@_); - - $self->{'last_file'} = ''; - - bless ($self, $class); - $self->init(); - return $self; -} - -sub display { - my ($self, $kernel) = @_[OBJECT, KERNEL]; - my $file; - - # Keep on looking until we find a file that exists. - do { - $file = $self->find_photo(); - - return - unless defined $file; - } until -f $file && $file ne $self->{'last_file'}; - - $self->{'new'}->set_from_file($file); - - if ($self->{'last_file'} eq '') { - fade_in($self->{'new'}); -# } else { -#warn "Fade out old\n"; -# my $old_effect = Clutter::EffectTemplate->new_for_duration(1000, 'main::smoothstep_dec' ); -# my $old = Clutter::Effect->fade($old_effect, $self->{'old'}, 0, $self->can('fade_in'), $self->{'new'}); -# $old->start(); - } - -# my $temp = $self->{'old'}; -# $self->{'old'} = $self->{'new'}; -# $self->{'new'} = $temp; - $self->{'last_file'} = $file; - - $self->{'kernel'}->delay(directory_display, 30); -} - -sub fade_in { - my $new_pic = shift; - - my $new_effect = Clutter::EffectTemplate->new_for_duration(1000, 'main::smoothstep_inc'); - my $new = Clutter::Effect->fade($new_effect, $new_pic, 255); - $new->start(); -} - -sub find_photo { - my $self = shift; - - if (opendir(DIR, $directory)) { - my @files = readdir(DIR); - closedir DIR; - - return join("/", $directory, $files[rand @files]); - } else { - warn "Failed to open $directory for reading: $!\n"; - } -} - -sub init { - my $self = shift; - - $self->{'kernel'}->state('directory_display', $self, 'display'); - - for my $age ('new', 'old') { - $self->{$age} = Clutter::Texture->new(); - $self->{$age}->set_size($self->{'stage'}->get_size()); - $self->{$age}->set('keep-aspect-ratio' => 1); - $self->{$age}->set('sync-size' => 1); - $self->{$age}->set_opacity(0); - - $self->{'stage'}->add($self->{$age}); - } - - $self->{'kernel'}->yield('directory_display'); -} - -1; diff --git a/lib/Display/Plugins/FSpot.pm b/lib/Display/Plugins/Photo.pm similarity index 70% rename from lib/Display/Plugins/FSpot.pm rename to lib/Display/Plugins/Photo.pm index 8664785..e4947be 100644 --- a/lib/Display/Plugins/FSpot.pm +++ b/lib/Display/Plugins/Photo.pm @@ -1,12 +1,10 @@ -package Display::Plugins::FSpot; +package Display::Plugins::Photo; use base ('Display::Plugin'); use Clutter; -use POE; -use POE::Component::EasyDBI; +use POE::Session; use strict; -my $default_f_spot_db = "$ENV{HOME}/.gnome2/f-spot/photos.db"; my $delay = 10; sub new { @@ -18,22 +16,36 @@ sub new { $self->{'last_file'} = ''; bless ($self, $class); - $self->init_delay($delay, 'fspot_display'); - $self->init(); + + $self->{'kernel'}->state('display_photo', $self); + + if ($self->can('find_photo')) { + $self->{'kernel'}->state('find_photo', $self); + $self->init_delay($delay, 'find_photo'); + } + + for my $age ('new', 'old') { + $self->{$age} = Clutter::Texture->new(); + $self->{$age}->set('request_mode' => 'width-for-height'); + $self->{$age}->set('keep-aspect-ratio' => 1); + $self->{$age}->set('sync-size' => 1); + $self->{$age}->set_opacity(0); + + $self->{'stage'}->add($self->{$age}); + } + return $self; } sub display_photo { - my ($self, $kernel, $args) = @_[OBJECT, KERNEL, ARG0]; - my $file = $args->{'result'}; - $file =~ s|^file://||; + my ($self, $kernel, $file) = @_[OBJECT, KERNEL, ARG0]; # Keep on looking until we find a file that exists. if (! -f $file || $file eq $self->{'last_file'}) { - $kernel->yield('fspot_display'); + $kernel->yield('find_photo'); return; } - + #warn "Loading $file\n"; $self->{'new'}->set_opacity(0); $self->{'new'}->set_size(-1, -1); @@ -100,50 +112,4 @@ sub fade_out { # $timeline->start(); } - -sub display { - my $self = shift; - - $self->{'kernel'}->post('FSpotDB', - single => { sql => $self->{'sql'}, event => 'fspot_display_photo' } - ); -} - -sub init { - my $self = shift; - - $self->{'kernel'}->state('fspot_display', $self, 'display'); - $self->{'kernel'}->state('fspot_display_photo', $self, 'display_photo'); - - POE::Component::EasyDBI->spawn( - alias => 'FSpotDB', - dsn => "dbi:SQLite:dbname=" . ($self->{'config'}{'_config'}{'plugins'}{'DB'} || $default_f_spot_db), - username => '', - password => '', - ); - - $self->{'sql'} = " -SELECT uri -FROM photos, photo_tags, tags - WHERE photos.id = photo_tags.photo_id - AND photo_tags.tag_id = tags.id - AND tags.name = 'Brooke' -ORDER BY random() -LIMIT 1 -"; - - for my $age ('new', 'old') { - $self->{$age} = Clutter::Texture->new(); - $self->{$age}->set('request_mode' => 'width-for-height'); - $self->{$age}->set('keep-aspect-ratio' => 1); - $self->{$age}->set('sync-size' => 1); - $self->{$age}->set_opacity(0); - - $self->{'stage'}->add($self->{$age}); - } - -warn "Going to yield\n"; - $self->{'kernel'}->yield('fspot_display'); -} - 1; diff --git a/lib/Display/Plugins/Photo/Directory.pm b/lib/Display/Plugins/Photo/Directory.pm new file mode 100644 index 0000000..2bdba07 --- /dev/null +++ b/lib/Display/Plugins/Photo/Directory.pm @@ -0,0 +1,36 @@ +package Display::Plugins::Photo::Directory; + +use base ('Display::Plugins::Photo'); +use Clutter; +use POE::Session; +use FindBin qw/$Bin/; + +my $directory = "$Bin/test_images"; + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + + my $self = $class->SUPER::new(@_); + + bless ($self, $class); + $self->{'kernel'}->yield('find_photo'); + return $self; +} + +sub find_photo { + my $self = shift; + print "Trying to find a photo\n"; + + if (opendir(DIR, $directory)) { + my @files = readdir(DIR); + closedir DIR; + +print "Trying a file.\n"; + $self->{'kernel'}->yield('display_photo', join("/", $directory, $files[rand @files])); + } else { + warn "Failed to open $directory for reading: $!\n"; + } +} + +1; diff --git a/lib/Display/Plugins/Photo/FSpot.pm b/lib/Display/Plugins/Photo/FSpot.pm new file mode 100644 index 0000000..4a56671 --- /dev/null +++ b/lib/Display/Plugins/Photo/FSpot.pm @@ -0,0 +1,63 @@ +package Display::Plugins::Photo::FSpot; + +use base ('Display::Plugins::Photo'); +use Clutter; +use POE; +use POE::Component::EasyDBI; +use strict; + +my $default_f_spot_db = "$ENV{HOME}/.gnome2/f-spot/photos.db"; +my $delay = 10; + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + + my $self = $class->SUPER::new(@_); + + bless ($self, $class); + $self->init(); + return $self; +} + +sub find_photo { + my $self = shift; + + $self->{'kernel'}->post('FSpotDB', + single => { sql => $self->{'sql'}, event => 'find_photo_result' } + ); +} + +sub find_photo_result { + my ($self, $kernel, $args) = @_[OBJECT, KERNEL, ARG0]; + my $file = $args->{'result'}; + $file =~ s|^file://||; + + $kernel->yield('display_photo', $file); +} + +sub init { + my $self = shift; + + POE::Component::EasyDBI->spawn( + alias => 'FSpotDB', + dsn => "dbi:SQLite:dbname=" . ($self->{'config'}{'_config'}{'plugins'}{'DB'} || $default_f_spot_db), + username => '', + password => '', + ); + + $self->{'sql'} = " +SELECT uri +FROM photos, photo_tags, tags + WHERE photos.id = photo_tags.photo_id + AND photo_tags.tag_id = tags.id + AND tags.name = 'Brooke' +ORDER BY random() +LIMIT 1 +"; + + $self->{'kernel'}->state('find_photo_result', $self); + $self->{'kernel'}->yield('find_photo'); +} + +1;