package Display::Plugins::FSpot;
-use Clutter;
use base ('Display::Plugin');
+use Clutter;
+use POE;
+use POE::Component::EasyDBI;
my $f_spot_db = "/home/andrew/.gnome2/f-spot/photos.db";
return $self;
}
-sub display {
- my $self = shift;
- my $file;
+sub display_photo {
+ my ($self, $kernel, $args) = @_[OBJECT, KERNEL, ARG0];
+ my $file = $args->{'result'};
+ $file =~ s|^file://||;
# Keep on looking until we find a file that exists.
- do {
- $file = $self->find_photo();
- } until (-f $file && $file ne $self->{'last_file'});
+ if (! -f $file || $file eq $self->{'last_file'}) {
+ $kernel->post('fspot_display');
+ return;
+ }
$self->{'new'}->set_from_file($file);
$new->start();
}
-sub find_photo {
+sub display {
my $self = shift;
-
- my $uri;
- $self->{'sth'}->bind_columns(\$uri);
- my $rc = $self->{'sth'}->execute()
- || die "Failed to execute statement: $DBI::errstr\n";
-
- $self->{'sth'}->fetch;
-
- $self->{'sth'}->finish()
- || die "Failed to finish statement: $DBI::errstr\n";;
- $uri =~ s|^file://||;
-
- return $uri;
+ $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');
- $self->{'dbh'} = DBI->connect("dbi:SQLite:dbname=$f_spot_db","","")
- || die "Failed to connect to $f_spot_db: $DBI::errstr\n";
+ POE::Component::EasyDBI->spawn(
+ alias => 'FSpotDB',
+ dsn => "dbi:SQLite:dbname=$f_spot_db",
+ username => '',
+ password => '',
+ );
- my $sql = "
+ $self->{'sql'} = "
SELECT uri
FROM photos, photo_tags, tags
WHERE photos.id = photo_tags.photo_id
LIMIT 1
";
- $self->{'sth'} = $self->{'dbh'}->prepare($sql)
- || die "Failed to prepare statement: $DBI::errstr\n";
-
for my $age ('new', 'old') {
$self->{$age} = Clutter::Texture->new();
$self->{$age}->set_size($self->{'stage'}->get_size());