Convert to using POE for the event management.
[picture-display.git] / lib / Display / Plugins / Clock.pm
1 package Display::Plugins::Clock;
2
3 use Clutter;
4 use POSIX qw/strftime/;
5 use base ('Display::Plugin');
6
7 sub new {
8   my $proto = shift;
9   my $class = ref($proto) || $proto;
10
11   my $self = $class->SUPER::new(@_);
12
13   bless ($self, $class);
14   $self->init();
15   return $self;
16 }
17
18 sub display {
19   my $self = shift;
20
21   $self->{'clock'}->set_text(strftime("%H:%M %d/%m/%Y", localtime(time)));
22
23   Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self);
24   $self->{'kernel'}->delay_set(clock_display, 60 - strftime(%s, localtime()));
25 }
26
27 sub init {
28   my $self = shift;
29
30   $self->{'kernel'}->state('clock_display', $self, 'display');
31
32   $self->{'clock'} = Clutter::Label->new('Sans 20', strftime("%H:%M %d/%m/%Y", localtime(time)));
33   $self->{'clock'}->set_anchor_point($self->{'clock'}->get_width(), 1);
34   $self->{'clock'}->set_position($self->{'stage'}->get_width() - 20, 15);
35   $self->{'clock'}->set_color(Clutter::Color->parse('White'));
36
37   $self->{'bg'} = Clutter::Rectangle->new(Clutter::Color->parse('Black'));
38   $self->{'bg'}->set_width($self->{'clock'}->get_width() + 20);
39   $self->{'bg'}->set_height($self->{'clock'}->get_height() + 10);
40   $self->{'bg'}->set_anchor_point($self->{'bg'}->get_width(), 1);
41   $self->{'bg'}->set_position($self->{'stage'}->get_width() - 10, 10);
42   $self->{'bg'}->set_opacity(100);
43
44   $self->{'stage'}->add($self->{'bg'});
45   $self->{'stage'}->add($self->{'clock'});
46
47   $self->{'kernel'}->delay_set(clock_display, 60 - strftime(%s, localtime()));
48 }
49
50 1;