package Display::Plugins::MPD;
use Clutter;
-use Audio::MPD;
use POSIX qw/strftime/;
use base ('Display::Plugin');
+use POE qw{ Component::Client::MPD };
sub new {
my $proto = shift;
my $self = $class->SUPER::new(@_);
- $self->{'mpd'} = Audio::MPD->new();
$self->{'file'} = '';
$self->{'active'} = 0;
}
sub display {
- my $self = shift;
+ my ($self, $msg, $answer) = @_[OBJECT, ARG0, ARG1];
- my $current = $self->{'mpd'}->current();
+warn "Got a response from MPD\n";
+ my $current = $answer->current();
if ($self->{'file'} ne $current->file()) {
my @lines = ();
$self->{'active'} = time() + 30;
}
- Glib::Timeout->add_seconds(30, $self->can('hide_display'), $self);
+ $self->{'KERNEL'}->delay( hide_display, 30 );
}
- return 1;
+ $self->{'KERNEL'}->delay_add( mpd, 5, current );
}
sub hide_display {
return 0;
}
+sub error {
+ my ($kernel, $msg, $errstr) = @_[KERNEL, ARG0, ARG1];
+
+ warn "MPD: Error $errstr\n";
+
+ $kernel->delay_add( mpd, 5, current );
+}
+
sub init {
my $self = shift;
+ $self->{'kernel'}->state('mpd_result', $self, 'display');
+ $self->{'kernel'}->state('mpd_error', $self, 'error');
+ $self->{'kernel'}->state('mpd_hide_display', $self, 'hide_display');
+ POE::Component::Client::MPD->new( {
+ alias => 'mpd',
+ status_msgs_to => 'mpd_status_msgs',
+ } );
+
$self->{'status'} = Clutter::Label->new('Sans 20', "Song\nAlbum");
$self->{'status'}->set_color(Clutter::Color->parse('White'));
$self->{'bg'} = Clutter::Rectangle->new(Clutter::Color->parse('Black'));
$self->{'bg'}->set_width($self->{'stage'}->get_width() - 40);
$self->{'bg'}->set_opacity(100);
+}
- Glib::Timeout->add_seconds(5, $self->can('display'), $self);
+sub mpd_status_msgs {
+ my ($kernel, $arg) = @_[KERNEL, ARG0];
+
+ if ($arg eq 'mpd_connected') {
+ $self->{'kernel'}->post( 'mpd', 'current' );
+ } else {
+ warn "Failed to connected to MPD. What now?\n";
+ }
}
1;