The Notifications object now handles displaying multiple notifications.
[picture-display.git] / lib / Display / Plugins / MPD.pm
index ca46ff2..13d92df 100644 (file)
@@ -1,24 +1,36 @@
 package Display::Plugins::MPD;
 
 use Clutter;
+use Carp;
 use Audio::MPD;
 use POSIX qw/strftime/;
 use POE::Session;
-use base ('Display::Plugin');
+use base ('Display::Plugins');
+use FindBin qw/$Bin/;
 use strict;
 
+my $delay = 5;
+
 sub new {
   my $proto = shift;
   my $class = ref($proto) || $proto;
 
   my $self = $class->SUPER::new(@_);
+  bless ($self, $class);
+
+  eval {
+    $self->{'mpd'} = Audio::MPD->new();
+  };
+  if ($@) {
+    carp "Failed to connect to MPD: $@";
+  } else {
+    $self->init_delay($delay, 'mpd_display');
+    $self->init();
+  }
 
-  $self->{'mpd'} = Audio::MPD->new();
   $self->{'file'} = '';
   $self->{'active'} = 0;
 
-  bless ($self, $class);
-  $self->init();
   return $self;
 }
 
@@ -33,14 +45,12 @@ sub display {
     push @lines, $current->album()  if defined $current->album();
     push @lines, $current->artist() if defined $current->artist();
 
-    $self->{'status'}->set_text(join("\n", @lines));
-
     $self->{'file'} = $current->file();
 
-    $kernel->yield('notifications_add', $self->{'status'});
+    $kernel->post('display', 'notifications_add', join("\n", @lines), $self->{'logo'});
   }
 
-  $kernel->delay('mpd_display', 5);
+  $self->delay();
 }
 
 sub init {
@@ -48,11 +58,9 @@ sub init {
 
   $self->{'kernel'}->state('mpd_display', $self, 'display');
 
-  $self->{'status'} = Clutter::Label->new('Sans 20', "Song\nAlbum");
-  $self->{'status'}->set_color(Clutter::Color->parse('White'));
-  $self->{'status'}->set_ellipsize('end');
+  $self->{'logo'} = "$Bin/share/MPD.png";
 
-  $self->{'kernel'}->delay('mpd_display', 5);
+  $self->{'kernel'}->yield('mpd_display');
 }
 
 1;