# CPUTemp.pm
# A PerlPanel applet which displays the PU temperature
# using mbmon.
# This requires a working installation of xmbmon.
# You can get it at http://freshmeat.net/projects/xmbmon
#
# I can't guarantee that this works for you, but it does for me.
# if it doesn't work the most prpably is that the shellcommand
# which filters the CPU temperature out of the whole output 
# has to be customized. This should be no problem.
#
# This is published under the Terms of the GNU Puplic License
# Copyright (c) 2004 Harm Reck <reck.harm@web.de>





# declare our package:
  package PerlPanel::Applet::CPUTemp; 
  use strict;

# constructor:
  sub new {
      my $self                = {};
      $self->{package}        = shift;
      bless($self, $self->{package});
      return $self;
  }

# build the widget:
  sub configure {
      my $self = shift;
      $self->{config} = PerlPanel::get_config('CPUTemp');
      $self->{widget} = Gtk2::Label->new();
      PerlPanel::tips->set_tip($self->{widget}, _('CPU Temperature'));
      $self->update;
      Glib::Timeout->add( 1000, sub { $self->update });
      return 1;
  }

# update function:
  sub update {
      my $self = shift;
      system ("mbmon -c 1 | cut -d = -f 2| cut -d , -f 2 | head -n 2 | tail -n 1 > /tmp/cputemp");

      open (TEMP, "< /tmp/cputemp");
      chomp (my $data = <TEMP>);
      close(TEMP);
      $self->{widget}->set_text(sprintf('%i°',$data));
      system("rm /tmp/cputemp");
      return 1;
  }
  


# return the widget;
  sub widget {
      return $_[0]->{widget};
  }

# return the expand (1 or 0) for packing:
  sub expand {
      return 0;
  }

# return the fill (1 or 0) for packing:
  sub fill {
      return 0;
  }

# return 'start' or 'end':
  sub end {
      return 'start';
     }

sub get_default_config {
    
    return { interval => 1000 }
}

1;
