summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakups
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/standalone/drakups')
-rwxr-xr-xperl-install/standalone/drakups102
1 files changed, 50 insertions, 52 deletions
diff --git a/perl-install/standalone/drakups b/perl-install/standalone/drakups
index ee6aeedb1..427216069 100755
--- a/perl-install/standalone/drakups
+++ b/perl-install/standalone/drakups
@@ -6,7 +6,7 @@ use standalone;
use common;
use mouse;
use detect_devices;
-use ugtk2 qw(:create :dialogs :helpers :wrappers);
+use ugtk3 qw(:create :dialogs :helpers :wrappers);
use interactive;
use Libconf qw(:functions);
use Libconf::Glueconf::NUT::Ups_conf;
@@ -38,16 +38,16 @@ sub writeconf() {
}
sub read_nut_config() {
- $struct = Libconf::Glueconf::NUT::Ups_conf->new($files{devices})
+ $struct = Libconf::Glueconf::NUT::Ups_conf->new({ filename => $files{devices} });
}
sub readDriversList() {
my (%ups, @ups);
local $_;
- foreach (cat_(first(glob("/usr/share/doc/nut-*/docs/driver.list")))) {
+ foreach (cat_(first(glob("/usr/share/doc/nut/docs/driver.list")))) {
/^#/ and next;
if (my ($vendor, $model, $extra, $driver) = /^"(.*)"\s+"(.*)"\s+"(.*)"\s+"(.*)"/) {
- $ups{$vendor}{$model} = {
+ $ups{$vendor}{$model . $extra} = {
driver => $driver,
extra => $extra,
};
@@ -63,10 +63,7 @@ sub add_device_wizard {
my ($in, $config) = @_;
my ($ups_models, $model_list) = readDriversList();
- use wizards;
- my ($ups, $vendor, $model, $name, $driver, $port, @new_devices);
- my $w = wizards->new;
- my $wiz;
+ my ($ups, $vendor, $model, $extra, $name, $driver, $port, @new_devices, $opts);
my %methods = (
# network => N("Connected through the network"), # need SNMP probe
# serial => N("Connected through a serial port"),
@@ -75,7 +72,8 @@ sub add_device_wizard {
manual => N("Manual configuration"),
);
my $method = $methods{auto};
- $wiz = {
+ require wizards;
+ my $wiz = wizards->new({
#defaultimage => "logdrake.png", # FIXME
name => N("Add an UPS device"),
pages => {
@@ -118,7 +116,7 @@ Do you want to autodetect UPS devices connected to this machine or to manually s
name => sub {
if (@new_devices) {
N("Congratulations") . "\n\n" .
- N("The wizard successfully added the following UPS devices:") . join("\n\n-", @new_devices)
+ N("The wizard successfully added the following UPS devices:") . join("\n\n-", @new_devices);
} else {
N("No new UPS devices was found");
}
@@ -129,9 +127,9 @@ Do you want to autodetect UPS devices connected to this machine or to manually s
data => [ { label => N("Manufacturer / Model:"), val => \$ups, list => $model_list,
type => 'combo', sort => 1, separator => '|' }, ],
post => sub {
- ($vendor, $model) = ($1, $2) if $ups =~ /(.*)\|(.*) \(/;
- ($name, $driver, $port) = ("myups", $ups_models->{$vendor}{$model}{driver}, "");
- ($driver) = split(/\s+/, $driver);
+ ($vendor, $model, $extra) = ($1, $2, $3) if $ups =~ /(.*)\|(.*) \((.*)\)$/;
+ ($name, $driver, $port) = ("myups", $ups_models->{$vendor}{$model . $extra}{driver}, "");
+ ($driver, $opts) = split(/\s+/, $driver);
"driver";
},
},
@@ -144,12 +142,15 @@ Please fill in its name, its driver and its port.", $model, $vendor);
[
{ label => N("Name:"), val => \$name, help => N("The name of your ups") },
{ label => N("Driver:"), val => \$driver, help => N("The driver that manages your ups") },
- { label => N("Port:"), val => \$port, format => \&mouse::serial_port2text, type => "combo",
- list => [ &mouse::serial_ports() ], not_edit => 0,
+ { label => N("Port:"), val => \$port, format => \&detect_devices::serialPort2text, type => "combo",
+ list => [ &detect_devices::serialPorts() ], not_edit => 0,
help => N("The port on which is connected your ups") },
];
},
- next => "end",
+ post => sub {
+ $port = '/dev/' . $port if $port !~ m!/dev/!;
+ return 'end';
+ },
},
end => {
name => sub {
@@ -161,11 +162,12 @@ Please fill in its name, its driver and its port.", $model, $vendor);
next => 0
},
},
- };
- $w->process($wiz, $in);
+ });
+ $wiz->process($in);
$config->{$name}{driver} = $driver;
$config->{$name}{port} = $port;
+ $config->{$name}{$1} = $2 if $opts =~ /\b(.*)=(.*)\b/;
# refresh the GUI when needed:
$models{ups}->append_set(1 => $name, 2 => $driver, 3 => $port) if $models{ups};
@@ -192,27 +194,27 @@ sub load_access_conf() {
# misc gui data
sub edit_row {
- my ($model, $iter) = @_;
+ my ($model, $o_iter) = @_;
# create new item if needed (that is when adding a new one) at end of list
- $iter ||= $model->append;
- my $dialog = Gtk2::Dialog->new;
- $dialog->set_transient_for($w->{rwindow}) unless $::isEmbedded;
+ my $iter = $o_iter || $model->append;
+ my $dialog = Gtk3::Dialog->new;
+ $dialog->set_transient_for($w->{real_window});
$dialog->set_modal(1);
- gtkpack_($dialog->vbox,
+ gtkpack_($dialog->get_child,
#map {
#}
);
- gtkadd($dialog->action_area,
- gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub {
+ gtkadd($dialog->get_action_area,
+ gtksignal_connect(Gtk3::Button->new(N("Ok")), clicked => sub {
# create new item if needed (that is when adding a new one) at end of list
$iter ||= $model->append;
# $model->set($iter, 1 => $file->get_text); # FILL ME
$dialog->destroy;
# $modified++;
}),
- gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $dialog->destroy }),
+ gtksignal_connect(Gtk3::Button->new(N("Cancel")), clicked => sub { $dialog->destroy }),
);
$dialog->show_all;
@@ -234,8 +236,8 @@ sub edit_callback {
sub del_callback {
my ($model, $list) = @_;
- my (undef, $iter) = $list->get_selection->get_selected;
- my $removed_idx = $list->get($iter, 0); # 1st column is index
+ #my (undef, $iter) = $list->get_selection->get_selected;
+ #my $removed_idx = $model->get($iter, 0); # 1st column is index
#@rules = grep { $_->{index} ne $removed_idx } @rules;
#$tree->remove($iter);
#sensitive_buttons(0);
@@ -273,7 +275,7 @@ my @pages = (
remove => sub {},
},
load => sub {
- $users = Libconf::Glueconf::NUT::Ups_conf->new($files{users});
+ $users = Libconf::Glueconf::NUT::Ups_conf->new({ filename => $files{users} });
map { [ $_ ] } keys %$users;
},
id => "users",
@@ -311,9 +313,11 @@ my @pages = (
#$in = 'interactive'->vnew('su'); # require_root_capability();
$in = 'interactive'->vnew;
-$ugtk2::wm_icon = "drakups";
+$ugtk3::wm_icon = "drakups";
-$in->do_pkgs->ensure_is_installed('nut-server', '/etc/rc.d/init.d/upsd') if !$::testing;
+if (!$::testing) {
+ $in->do_pkgs->ensure_is_installed('nut-server', '/usr/sbin/upsd') or $in->exit(1);
+}
if (member('--wizard', @ARGV)) {
read_nut_config();
@@ -322,9 +326,9 @@ if (member('--wizard', @ARGV)) {
$in->exit($@ ? 1 : 0);
}
-$w = ugtk2->new(N("DrakUPS"));
+$w = ugtk3->new(N("UPS Management"));
if (!$::isEmbedded) {
- $::main_window = $w->{rwindow};
+ mygtk3::register_main_window($w->{real_window});
$w->{window}->set_size_request(500, 550);
$w->{rwindow}->set_title(N("DrakUPS"));
}
@@ -334,10 +338,10 @@ if (!$::isEmbedded) {
my $_msg = N("Welcome to the UPS configuration tools");
-$w->{window}->add(gtkpack_(Gtk2::VBox->new,
- if_(!$::isEmbedded, 0, Gtk2::Banner->new('drakups', N("DrakUPS"))),
- 1, my $nb = Gtk2::Notebook->new,
- 0, create_okcancel(my $oc =
+$w->{window}->add(gtkpack_(Gtk3::VBox->new,
+ if_(!$::isEmbedded, 0, Gtk3::Banner->new('drakups', N("DrakUPS"))),
+ 1, my $nb = Gtk3::Notebook->new,
+ 0, create_okcancel(
{
ok_clicked => sub {
#$_->{save}->() foreach @pages;
@@ -353,42 +357,36 @@ $w->{window}->add(gtkpack_(Gtk2::VBox->new,
#------------------------------------------------------------------
# build the notebook
-my %labels = (
- add => N("Add"),
- edit => N("Edit"),
- remove => N("Remove"),
- );
-
foreach my $i (@pages) {
- my $model = $models{$i->{id}} = Gtk2::ListStore->new("Glib::Int", ("Glib::String") x listlength(@{$i->{columns}}));
+ my $model = $models{$i->{id}} = Gtk3::ListStore->new("Glib::Int", ("Glib::String") x listlength(@{$i->{columns}}));
my (%buttons, $list);
$indexes{$i->{name}} = 0;
my $idx = \$indexes{$i->{name}};
my $getindex = sub { $$idx++ };
- $nb->append_page(gtkpack_(Gtk2::VBox->new,
- 1, create_scrolled_window($list = Gtk2::TreeView->new_with_model($model),
+ $nb->append_page(gtkpack_(Gtk3::VBox->new,
+ 1, create_scrolled_window($list = Gtk3::TreeView->new_with_model($model),
[ 'automatic', 'automatic' ]),
- 0, gtkpack(Gtk2::HButtonBox->new,
+ 0, gtkpack(Gtk3::HButtonBox->new,
(map {
my ($id, $label, $sub) = @$_;
- gtksignal_connect($buttons{$id} = Gtk2::Button->new($label), clicked => sub {
+ gtksignal_connect($buttons{$id} = Gtk3::Button->new($label), clicked => sub {
$sub->($model, $list, $getindex);
- })
+ });
} ([ 'add', N("Add"), $i->{callbacks}{add} || \&add_callback ],
[ 'edit', N("Edit"), \&edit_callback ],
[ 'remove', N("Remove"), \&del_callback ],
)
)
#(map {
- # gtksignal_connect(Gtk2::Button->new($_), clicked => $i->{callbacks}{$_}),
+ # gtksignal_connect(Gtk3::Button->new($_), clicked => $i->{callbacks}{$_}),
#} keys %{$i->{callbacks}})
),
),
- Gtk2::Label->new($i->{name}),
+ Gtk3::Label->new($i->{name}),
);
#$i->{list} = $list;
each_index {
- $list->append_column(Gtk2::TreeViewColumn->new_with_attributes($_, Gtk2::CellRendererText->new, 'text' => $::i + 1));
+ $list->append_column(Gtk3::TreeViewColumn->new_with_attributes($_, Gtk3::CellRendererText->new, 'text' => $::i + 1));
} @{$i->{columns}};
my @u = $i->{load}->();
foreach my $line (@u) {