Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 142 lines (112 sloc) 3.32 KB
#!/usr/bin/env perl
#ArchLinux Daemon Manager Gui! by Harvie 2oo9
use strict;
use warnings;
use utf8;
use Gtk2 qw(-init);
if($< > 0) {
#run as root
print "You are not root! Trying GKSU...\n";
system("gksu ".$0);
exit;
}
my $aldm = '/usr/sbin/aldm';
my %iterators = {};
my $builder = Gtk2::Builder->new();
$builder->add_from_file('/usr/share/aldm-gui/aldm.ui');
my %widgets;
foreach my $widget qw(window1 aboutdialog1 treeview1 liststore1 label2)
{
$widgets{$widget}=$builder->get_object($widget);
}
$builder->connect_signals( undef );
$builder = undef;
#create columns in treeview
my $column = Gtk2::TreeViewColumn->new_with_attributes('Daemon', Gtk2::CellRendererText->new, text => 0);
$widgets{'treeview1'}->append_column($column);
$column = Gtk2::TreeViewColumn->new_with_attributes('?', Gtk2::CellRendererText->new, text => 1);
$widgets{'treeview1'}->append_column($column);
$column = Gtk2::TreeViewColumn->new_with_attributes('Running', Gtk2::CellRendererText->new, text => 2);
$widgets{'treeview1'}->append_column($column);
$column = Gtk2::TreeViewColumn->new_with_attributes('WhatIs', Gtk2::CellRendererText->new, text => 3);
$widgets{'treeview1'}->append_column($column);
refresh_view();
$widgets{'window1'}->show();
Gtk2->main();
exit;
sub on_window1_destroy
{
Gtk2->main_quit();
}
sub on_imagemenuitem10_activate
{
$widgets{'aboutdialog1'}->show();
}
sub on_aboutdialog1_close
{
$widgets{'aboutdialog1'}->hide();
}
sub refresh_view
{
#clear
#$widgets{'liststore1'}->clear();
#list daemons
open(my $daemon_list, "$aldm list|");
while(<$daemon_list>) {
no warnings 'uninitialized';
$_ =~ s/^\s+|\s+$//g; #trim
open(my $whatis, "'$aldm' whatis '$_'|"); my $w = <$whatis>; close($whatis); $w =~ s/^\s+|\s+$//g; #trim
(my $run, $w) = split(/ /,$w,2);
#my $iter = $widgets{'liststore1'}->append();
#$widgets{'liststore1'}->set($iter, 0 => "$_", 1=> "$run", 2 => "$w");
my $state = $_;
$state =~ s/[a-zA-Z0-9 \-]*//g;
my $serv = $_;
$serv =~ s/^(!|@)//g;
if(!defined($iterators{$serv})) {
$iterators{$serv} = $widgets{'liststore1'}->append();
}
$widgets{'liststore1'}->set($iterators{$serv}, 0 => "$serv", 1=> "$state", 2=> "$run", 3 => "$w");
}
close($daemon_list);
}
sub get_selected_daemon
{
my $path = $widgets{'treeview1'}->get_selection->get_selected_rows;
my $model = $widgets{'treeview1'}->get_model;
my $iter = $model->get_iter($path);
my $str = $model->get ($iter, 0);
return $str;
}
sub status
{
$_[0] =~ s/^\s+|\s+$//g; #trim
$widgets{'label2'}->set_text($_[0]);
}
sub s_system
{
open(my $pipe, "$_[0]|");
while(<$pipe>) { status($_); }
close($pipe);
}
sub on_button_start_clicked { s_system "$aldm start ".get_selected_daemon(); refresh_view(); }
sub on_button_stop_clicked { s_system "$aldm stop ".get_selected_daemon(); refresh_view(); }
sub on_button_restart_clicked { s_system "$aldm restart ".get_selected_daemon(); refresh_view(); }
sub on_button_enable_fg_clicked {
my $d = get_selected_daemon();
system "$aldm enable-fg ".$d;
refresh_view();
status($d." enabled on init!");
}
sub on_button_enable_bg_clicked {
my $d = get_selected_daemon();
system "$aldm enable-bg ".$d;
refresh_view();
status($d." enabled on init background!");
}
sub on_button_disable_clicked {
my $d = get_selected_daemon();
system "$aldm disable ".$d;
refresh_view();
status($d." disabled!");
}
Something went wrong with that request. Please try again.