diff options
-rw-r--r-- | gurpmi | 49 | ||||
-rw-r--r-- | gurpmi.pm | 34 | ||||
-rwxr-xr-x | gurpmi2 | 51 |
3 files changed, 55 insertions, 79 deletions
@@ -10,42 +10,13 @@ BEGIN { #- set up a safe path and environment delete @ENV{qw(ENV BASH_ENV IFS CDPATH)}; } -#- This is needed because text printed by Gtk2 will always be encoded -#- in UTF-8; we first check if LC_ALL is defined, because if it is, -#- changing only LC_COLLATE will have no effect. -use POSIX qw(setlocale LC_ALL LC_COLLATE); -use locale; -BEGIN { - my $collation_locale = $ENV{LC_ALL}; - if ($collation_locale) { - $collation_locale =~ /UTF-8/ or setlocale(LC_ALL, "$collation_locale.UTF-8"); - } else { - $collation_locale = setlocale(LC_COLLATE); - $collation_locale =~ /UTF-8/ or setlocale(LC_COLLATE, "$collation_locale.UTF-8"); - } -} - -use urpm; +use gurpmi; use urpm::msg qw(N); use Gtk2; -use MDK::Common qw(partition); - -sub usage () { - print STDERR <<USAGE; -gurpmi version $urpm::VERSION -Usage : - gurpmi <rpm> [ <rpm>... ] -USAGE - exit 0; -} - -#- fatal gurpmi initialisation error (*not* fatal urpmi errors) -sub fatal { print STDERR "$_[0]\n"; exit 1 } +use MDK::Common::Func qw(partition); sub quit () { Gtk2->main_quit } -sub but ($) { " $_[0] " } - #- globals my (@all_rpms, $srpms, $rpms); my ($mainw, $mainbox); @@ -79,12 +50,12 @@ sub new_label { #- Parse command line foreach (@ARGV) { if (/^-/) { - /^--?[hv?]/ and usage; - fatal N("Unknown option %s", $_); + /^--?[hv?]/ and gurpmi::usage(); + gurpmi::fatal N("Unknown option %s", $_); } push @all_rpms, $_; } -@all_rpms or fatal N("No packages specified"); +@all_rpms or gurpmi::fatal N("No packages specified"); #- Now, the graphical stuff. @@ -130,13 +101,13 @@ Proceed?", join "\n", @all_rpms) } { #- buttons - my $inst_button = Gtk2::Button->new(but N("_Install")); - my $save_button = @all_rpms == 1 ? Gtk2::Button->new(but N("_Save")) : undef; - my $ccel_button = Gtk2::Button->new(but N("_Cancel")); + my $inst_button = Gtk2::Button->new(gurpmi::but N("_Install")); + my $save_button = @all_rpms == 1 ? Gtk2::Button->new(gurpmi::but N("_Save")) : undef; + my $ccel_button = Gtk2::Button->new(gurpmi::but N("_Cancel")); $inst_button->signal_connect(clicked => sub { #- performs installation. - quit; + quit(); #- we need to switch to root if we're not already (via consolehelper) #- yes. hardcoded paths. safe. exec $> ? '/usr/bin/gurpmi2' : '/usr/sbin/gurpmi2', @ARGV; @@ -149,7 +120,7 @@ Proceed?", join "\n", @all_rpms) $file_dialog->hide_fileop_buttons; $file_dialog->ok_button->signal_connect(clicked => sub { my $location = $file_dialog->get_filename; - quit; + quit(); $location and exec '/bin/mv', '-f', $rpms->[0], $location; }); $file_dialog->cancel_button->signal_connect(clicked => \&quit); diff --git a/gurpmi.pm b/gurpmi.pm new file mode 100644 index 00000000..404282c5 --- /dev/null +++ b/gurpmi.pm @@ -0,0 +1,34 @@ +package gurpmi; + +#- This is needed because text printed by Gtk2 will always be encoded +#- in UTF-8; we first check if LC_ALL is defined, because if it is, +#- changing only LC_COLLATE will have no effect. +use POSIX qw(setlocale LC_ALL LC_COLLATE); +use locale; +BEGIN { + my $collation_locale = $ENV{LC_ALL}; + if ($collation_locale) { + $collation_locale =~ /UTF-8/ or setlocale(LC_ALL, "$collation_locale.UTF-8"); + } else { + $collation_locale = setlocale(LC_COLLATE); + $collation_locale =~ /UTF-8/ or setlocale(LC_COLLATE, "$collation_locale.UTF-8"); + } +} + +use urpm; + +sub usage () { + print STDERR <<USAGE; +gurpmi version $urpm::VERSION +Usage : + gurpmi <rpm> [ <rpm>... ] +USAGE + exit 0; +} + +#- fatal gurpmi initialisation error (*not* fatal urpmi errors) +sub fatal { print STDERR "$_[0]\n"; exit 1 } + +sub but ($) { " $_[0] " } + +1; @@ -10,41 +10,12 @@ BEGIN { #- set up a safe path and environment delete @ENV{qw(ENV BASH_ENV IFS CDPATH)}; } -#- This is needed because text printed by Gtk2 will always be encoded -#- in UTF-8; we first check if LC_ALL is defined, because if it is, -#- changing only LC_COLLATE will have no effect. -use POSIX qw(setlocale LC_ALL LC_COLLATE); -use locale; -BEGIN { - my $collation_locale = $ENV{LC_ALL}; - if ($collation_locale) { - $collation_locale =~ /UTF-8/ or setlocale(LC_ALL, "$collation_locale.UTF-8"); - } else { - $collation_locale = setlocale(LC_COLLATE); - $collation_locale =~ /UTF-8/ or setlocale(LC_COLLATE, "$collation_locale.UTF-8"); - } -} - -use urpm; +use gurpmi; use urpm::msg qw(N); use Gtk2; -sub usage () { - print STDERR <<USAGE; -gurpmi2 version $urpm::VERSION -Usage : - gurpmi2 <rpm> [ <rpm>... ] -USAGE - exit 0; -} - -#- fatal gurpmi initialisation error (*not* fatal urpmi errors) -sub fatal { print STDERR "$_[0]\n"; exit 1 } - sub quit () { Gtk2->main_quit } -sub but ($) { " $_[0] " } - #- GUI globals my ($mainw, $mainbox); @@ -102,14 +73,14 @@ sub wait_label { my (@all_rpms); foreach (@ARGV) { if (/^-/) { - /^--?[hv?]/ and usage(); - fatal N("Unknown option %s", $_); + /^--?[hv?]/ and gurpmi::usage(); + gurpmi::fatal N("Unknown option %s", $_); } push @all_rpms, $_; } -@all_rpms or fatal N("No packages specified"); +@all_rpms or gurpmi::fatal N("No packages specified"); -$> and fatal N("Must be root"); +$> and gurpmi::fatal N("Must be root"); #- Now, the graphical stuff. @@ -149,7 +120,7 @@ $mainw->show_all; Gtk2->main; #- Creates and configure an urpm object for this application to use. -sub configure_urpm () { +sub configure_urpm { my $urpm = new urpm; $urpm->{fatal} = sub { Gtk2::MessageDialog->new($mainw, [qw(modal destroy-with-parent)], 'error', 'ok', $_[1])->run; @@ -187,8 +158,8 @@ sub ask_choice { $label->set_alignment(0.5, 0.5); $vbox->pack_start($label, 1, 1, 0); $vbox->pack_start($_, 1, 1, 0) foreach @radios; - my $cancel_button = Gtk2::Button->new(but N("_Cancel")); - my $choice_button = Gtk2::Button->new(but N("_Ok")); + my $cancel_button = Gtk2::Button->new(gurpmi::but N("_Cancel")); + my $choice_button = Gtk2::Button->new(gurpmi::but N("_Ok")); $cancel_button->signal_connect(clicked => \&quit); $choice_button->signal_connect(clicked => sub { my $n = 0; @@ -204,8 +175,8 @@ sub ask_continue { my ($msg, $nextclosure) = @_; my $vbox = Gtk2::VBox->new(0, 5); $vbox->pack_start(new_label($msg), 1, 1, 0); - my $continue_button = Gtk2::Button->new(but N("_Ok")); - my $quit_button = Gtk2::Button->new(but N("_Abort")); + my $continue_button = Gtk2::Button->new(gurpmi::but N("_Ok")); + my $quit_button = Gtk2::Button->new(gurpmi::but N("_Abort")); $quit_button->signal_connect(clicked => \&quit); $continue_button->signal_connect(clicked => sub { goto &$nextclosure }); add_button_box($vbox, $quit_button, $continue_button); @@ -355,7 +326,7 @@ sub do_install_3 () { $vbox = Gtk2::VBox->new(0, 5); $progress_label = Gtk2::Label->new('-'); $vbox->pack_start($progress_label, 1, 1, 0); - my $quit_button = Gtk2::Button->new(but N("_Done")); + my $quit_button = Gtk2::Button->new(gurpmi::but N("_Done")); $quit_button->signal_connect(clicked => \&quit); add_button_box($vbox, $quit_button); change_mainw($vbox); |