Create a new base object for the photo classes which contains common code.
[picture-display.git] / 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 (file)
@@ -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;