Get notification expiring working.
[picture-display.git] / lib / Display / Plugins / MPD.pm
1 package Display::Plugins::MPD;
2
3 use Clutter;
4 use Audio::MPD;
5 use POSIX qw/strftime/;
6 use POE::Session;
7 use base ('Display::Plugin');
8 use strict;
9
10 sub new {
11   my $proto = shift;
12   my $class = ref($proto) || $proto;
13
14   my $self = $class->SUPER::new(@_);
15
16   $self->{'mpd'} = Audio::MPD->new();
17   $self->{'file'} = '';
18   $self->{'active'} = 0;
19
20   bless ($self, $class);
21   $self->init();
22   return $self;
23 }
24
25 sub display {
26   my ($self, $kernel) = @_[OBJECT, KERNEL];
27
28   my $current = $self->{'mpd'}->current();
29
30   if (defined $current && $self->{'file'} ne $current->file()) {
31     my @lines = ();
32     push @lines, $current->title()  if defined $current->title();
33     push @lines, $current->album()  if defined $current->album();
34     push @lines, $current->artist() if defined $current->artist();
35
36     $self->{'status'}->set_text(join("\n", @lines));
37
38     $self->{'file'} = $current->file();
39
40     $kernel->yield('notifications_add', $self->{'status'});
41   }
42
43   $kernel->delay('mpd_display', 5);
44 }
45
46 sub init {
47   my $self = shift;
48
49   $self->{'kernel'}->state('mpd_display', $self, 'display');
50
51   $self->{'status'} = Clutter::Label->new('Sans 20', "Song\nAlbum");
52   $self->{'status'}->set_color(Clutter::Color->parse('White'));
53   $self->{'status'}->set_ellipsize('end');
54
55   $self->{'kernel'}->delay('mpd_display', 5);
56 }
57
58 1;