2 #ArchLinux Daemon Manager Gui! by Harvie 2oo9
10 print "You are not root! Trying GKSU...\n";
15 my $aldm = '/usr/sbin/aldm';
19 my $builder = Gtk2
::Builder
->new();
20 $builder->add_from_file('/usr/share/aldm-gui/aldm.ui');
23 foreach my $widget qw(window1 aboutdialog1 treeview1 liststore1 label2)
25 $widgets{$widget}=$builder->get_object($widget);
28 $builder->connect_signals( undef );
31 #create columns in treeview
32 my $column = Gtk2
::TreeViewColumn
->new_with_attributes('Daemon', Gtk2
::CellRendererText
->new, text
=> 0);
33 $widgets{'treeview1'}->append_column($column);
35 $column = Gtk2
::TreeViewColumn
->new_with_attributes('?', Gtk2
::CellRendererText
->new, text
=> 1);
36 $widgets{'treeview1'}->append_column($column);
38 $column = Gtk2
::TreeViewColumn
->new_with_attributes('Running', Gtk2
::CellRendererText
->new, text
=> 2);
39 $widgets{'treeview1'}->append_column($column);
41 $column = Gtk2
::TreeViewColumn
->new_with_attributes('WhatIs', Gtk2
::CellRendererText
->new, text
=> 3);
42 $widgets{'treeview1'}->append_column($column);
46 $widgets{'window1'}->show();
52 sub on_window1_destroy
57 sub on_imagemenuitem10_activate
59 $widgets{'aboutdialog1'}->show();
62 sub on_aboutdialog1_close
64 $widgets{'aboutdialog1'}->hide();
70 #$widgets{'liststore1'}->clear();
73 open(my $daemon_list, "$aldm list|");
74 while(<$daemon_list>) {
75 no warnings
'uninitialized';
76 $_ =~ s/^\s+|\s+$//g; #trim
77 open(my $whatis, "'$aldm' whatis '$_'|"); my $w = <$whatis>; close($whatis); $w =~ s/^\s+|\s+$//g; #trim
78 (my $run, $w) = split(/ /,$w,2);
80 #my $iter = $widgets{'liststore1'}->append();
81 #$widgets{'liststore1'}->set($iter, 0 => "$_", 1=> "$run", 2 => "$w");
84 $state =~ s/[a-zA-Z0-9 \-]*//g;
88 if(!defined($iterators{$serv})) {
89 $iterators{$serv} = $widgets{'liststore1'}->append();
91 $widgets{'liststore1'}->set($iterators{$serv}, 0 => "$serv", 1=> "$state", 2=> "$run", 3 => "$w");
96 sub get_selected_daemon
98 my $path = $widgets{'treeview1'}->get_selection->get_selected_rows;
99 my $model = $widgets{'treeview1'}->get_model;
100 my $iter = $model->get_iter($path);
101 my $str = $model->get ($iter, 0);
107 $_[0] =~ s/^\s+|\s+$//g; #trim
108 $widgets{'label2'}->set_text($_[0]);
113 open(my $pipe, "$_[0]|");
114 while(<$pipe>) { status
($_); }
118 sub on_button_start_clicked
{ s_system
"$aldm start ".get_selected_daemon
(); refresh_view
(); }
119 sub on_button_stop_clicked
{ s_system
"$aldm stop ".get_selected_daemon
(); refresh_view
(); }
120 sub on_button_restart_clicked
{ s_system
"$aldm restart ".get_selected_daemon
(); refresh_view
(); }
122 sub on_button_enable_fg_clicked
{
123 my $d = get_selected_daemon
();
124 system "$aldm enable-fg ".$d;
126 status
($d." enabled on init!");
129 sub on_button_enable_bg_clicked
{
130 my $d = get_selected_daemon
();
131 system "$aldm enable-bg ".$d;
133 status
($d." enabled on init background!");
136 sub on_button_disable_clicked
{
137 my $d = get_selected_daemon
();
138 system "$aldm disable ".$d;
140 status
($d." disabled!");