+++ /dev/null
-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;
-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 {
$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);
# $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;
--- /dev/null
+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;
--- /dev/null
+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;