#!/usr/bin/perl
### 
# X11-HALT/REBOOT fuer OpenBSD (c) 2005 by I.S.
# ---
# Voraussetzung:
# 1.) cd /usr/ports/x11/p5-Gtk && make install 
# 2.) sudo ist eingerichtet ...
###

use warnings;

use Gtk;
use strict;

init Gtk;
set_locale Gtk;

my $false = 0;
my $true = 1;

my $window;
my $vbox;
my $hbox;
my $button;
my $check1;
my $check2;
my $action = "/sbin/halt";

$window = new Gtk::Window( "toplevel" );
$window->set_usize( 200, 150 );
$window->set_title( " S Y S T E M " );
$window->signal_connect( "delete_event", sub { Gtk->exit( 0 ); } );
$window->border_width( 20 );
$window->set_position( "center" ); 

$vbox = new Gtk::VBox( $false, 0 );
$window->add( $vbox );
$vbox->show();

$hbox = new Gtk::HBox( $false, 0 );
$vbox->add( $hbox );
$hbox->show();

$check1 = new Gtk::RadioButton( "HALT" );
$check1->signal_connect( "clicked", \&entry_clicked_halt );
$hbox->add( $check1 );
$check1->show();

$check2 = new Gtk::RadioButton( "REBOOT", $check1 );
$check2->signal_connect( "clicked", \&entry_clicked_reboot );
$hbox->add( $check2 );
$check2->show();

$button = new Gtk::Button( " Y E S " );
$button->signal_connect( "clicked", \&do_it );
$vbox->pack_start( $button, $true, $true, 0 );
$button->can_default( $true );
$button->grab_default();
$button->show();

$window->show();

main Gtk;
exit( 0 );

sub entry_clicked_halt{
    $action = "/sbin/halt";
  }

sub entry_clicked_reboot{
    $action = "/sbin/reboot";
  }
  
sub do_it{
    #print "===> $action\n";
    system("sudo $action &");
    exit( 0 );
  }

###EOF###
