Add logo support to notifications.
[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 FindBin qw/$Bin/;
9 use strict;
10
11 my $delay = 5;
12
13 sub new {
14   my $proto = shift;
15   my $class = ref($proto) || $proto;
16
17   my $self = $class->SUPER::new(@_);
18
19   $self->{'mpd'} = Audio::MPD->new();
20   $self->{'file'} = '';
21   $self->{'active'} = 0;
22
23   bless ($self, $class);
24   $self->init_delay($delay, 'mpd_display');
25   $self->init();
26   return $self;
27 }
28
29 sub display {
30   my ($self, $kernel) = @_[OBJECT, KERNEL];
31
32   my $current = $self->{'mpd'}->current();
33
34   if (defined $current && $self->{'file'} ne $current->file()) {
35     my @lines = ();
36     push @lines, $current->title()  if defined $current->title();
37     push @lines, $current->album()  if defined $current->album();
38     push @lines, $current->artist() if defined $current->artist();
39
40     $self->{'status'}->set_text(join("\n", @lines));
41
42     $self->{'file'} = $current->file();
43
44     $kernel->yield('notifications_add', $self->{'status'}, $self->{'logo'});
45   }
46
47   $self->delay();
48 }
49
50 sub init {
51   my $self = shift;
52
53   $self->{'kernel'}->state('mpd_display', $self, 'display');
54
55   $self->{'status'} = Clutter::Label->new('Sans 20', "Song\nAlbum");
56   $self->{'status'}->set_color(Clutter::Color->parse('White'));
57   $self->{'status'}->set_ellipsize('end');
58
59   $self->{'logo'} = Clutter::Texture->new("$Bin/share/MPD.png");
60
61   $self->{'kernel'}->yield('mpd_display');
62 }
63
64 1;