updated on Tue Jan 10 12:02:00 UTC 2012
[aur-mirror.git] / aldm / aldm-gui
blobbf4ed6bd2f706f7c6baf7bfe9f31048bcc4ad28e
1 #!/usr/bin/env perl
2 #ArchLinux Daemon Manager Gui! by Harvie 2oo9
3 use strict;
4 use warnings;
5 use utf8;
6 use Gtk2 qw(-init);
8 if($< > 0) {
9 #run as root
10 print "You are not root! Trying GKSU...\n";
11 system("gksu ".$0);
12 exit;
15 my $aldm = '/usr/sbin/aldm';
17 my %iterators = {};
19 my $builder = Gtk2::Builder->new();
20 $builder->add_from_file('/usr/share/aldm-gui/aldm.ui');
22 my %widgets;
23 foreach my $widget qw(window1 aboutdialog1 treeview1 liststore1 label2)
25 $widgets{$widget}=$builder->get_object($widget);
28 $builder->connect_signals( undef );
29 $builder = 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);
44 refresh_view();
46 $widgets{'window1'}->show();
49 Gtk2->main();
50 exit;
52 sub on_window1_destroy
54 Gtk2->main_quit();
57 sub on_imagemenuitem10_activate
59 $widgets{'aboutdialog1'}->show();
62 sub on_aboutdialog1_close
64 $widgets{'aboutdialog1'}->hide();
67 sub refresh_view
69 #clear
70 #$widgets{'liststore1'}->clear();
72 #list daemons
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");
83 my $state = $_;
84 $state =~ s/[a-zA-Z0-9 \-]*//g;
86 my $serv = $_;
87 $serv =~ s/^(!|@)//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");
93 close($daemon_list);
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);
102 return $str;
105 sub status
107 $_[0] =~ s/^\s+|\s+$//g; #trim
108 $widgets{'label2'}->set_text($_[0]);
111 sub s_system
113 open(my $pipe, "$_[0]|");
114 while(<$pipe>) { status($_); }
115 close($pipe);
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;
125 refresh_view();
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;
132 refresh_view();
133 status($d." enabled on init background!");
136 sub on_button_disable_clicked {
137 my $d = get_selected_daemon();
138 system "$aldm disable ".$d;
139 refresh_view();
140 status($d." disabled!");