diff options
author | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2005-01-24 15:05:03 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2005-01-24 15:05:03 +0000 |
commit | 27f824577805d11bd50f5fcdefa4343c5b32b028 (patch) | |
tree | 32078da7a01b92b46df238e55bc9475f23d34435 | |
parent | e9bca51a4155e9afe46ee816560609a530893e24 (diff) | |
download | urpmi-27f824577805d11bd50f5fcdefa4343c5b32b028.tar urpmi-27f824577805d11bd50f5fcdefa4343c5b32b028.tar.gz urpmi-27f824577805d11bd50f5fcdefa4343c5b32b028.tar.bz2 urpmi-27f824577805d11bd50f5fcdefa4343c5b32b028.tar.xz urpmi-27f824577805d11bd50f5fcdefa4343c5b32b028.zip |
More refactorisation
-rw-r--r-- | gurpmi | 38 | ||||
-rw-r--r-- | gurpmi.pm | 31 | ||||
-rwxr-xr-x | gurpmi2 | 46 |
3 files changed, 46 insertions, 69 deletions
@@ -15,47 +15,21 @@ use urpm::msg qw(N); use Gtk2; use MDK::Common::Func qw(partition); -sub quit () { Gtk2->main_quit } - #- globals my (@all_rpms, $srpms, $rpms); my ($mainw, $mainbox); #- Gtk2 helper functions -sub add_button_box { - my ($vbox, @buttons) = @_; - my $hbox = Gtk2::HButtonBox->new; - $vbox->pack_start($hbox, 0, 0, 0); - $hbox->set_layout('edge'); - $_->set_alignment(0.5, 0.5), $hbox->add($_) foreach @buttons; -} - -sub new_label { - my ($msg) = @_; - my $label = Gtk2::Label->new($msg); - $label->set_line_wrap(1); - $label->set_alignment(0.5, 0.5); - if (($msg =~ tr/\n/\n/) > 5) { - my $sw = Gtk2::ScrolledWindow->new; - $sw->set_policy('never', 'automatic'); - $sw->add_with_viewport($label); - $sw->set_size_request(-1,200); - return $sw; - } else { - return $label; - } -} - #- Parse command line foreach (@ARGV) { if (/^-/) { - /^--?[hv?]/ and gurpmi::usage(); - gurpmi::fatal N("Unknown option %s", $_); + /^--?[hv?]/ and usage(); + fatal(N("Unknown option %s", $_)); } push @all_rpms, $_; } -@all_rpms or gurpmi::fatal N("No packages specified"); +@all_rpms or fatal(N("No packages specified")); #- Now, the graphical stuff. @@ -101,9 +75,9 @@ Proceed?", join "\n", @all_rpms) } { #- buttons - 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")); + 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"))); $inst_button->signal_connect(clicked => sub { #- performs installation. @@ -16,6 +16,11 @@ BEGIN { } use urpm; +use strict; + +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(usage fatal but quit add_button_box new_label); sub usage () { print STDERR <<USAGE; @@ -31,4 +36,30 @@ sub fatal { print STDERR "$_[0]\n"; exit 1 } sub but ($) { " $_[0] " } +sub quit () { Gtk2->main_quit } + +sub add_button_box { + my ($vbox, @buttons) = @_; + my $hbox = Gtk2::HButtonBox->new; + $vbox->pack_start($hbox, 0, 0, 0); + $hbox->set_layout('edge'); + $_->set_alignment(0.5, 0.5), $hbox->add($_) foreach @buttons; +} + +sub new_label { + my ($msg) = @_; + my $label = Gtk2::Label->new($msg); + $label->set_line_wrap(1); + $label->set_alignment(0.5, 0.5); + if (($msg =~ tr/\n/\n/) > 5) { + my $sw = Gtk2::ScrolledWindow->new; + $sw->set_policy('never', 'automatic'); + $sw->add_with_viewport($label); + $sw->set_size_request(-1,200); + return $sw; + } else { + return $label; + } +} + 1; @@ -14,13 +14,9 @@ use gurpmi; use urpm::msg qw(N); use Gtk2; -sub quit () { Gtk2->main_quit } - #- GUI globals my ($mainw, $mainbox); -#- Gtk2 helper functions - #- Replaces the contents of the main window with the specified box #- (avoids popup multiplication) sub change_mainw { @@ -30,35 +26,11 @@ sub change_mainw { $mainw->show_all; } -sub add_button_box { - my ($vbox, @buttons) = @_; - my $hbox = Gtk2::HButtonBox->new; - $vbox->pack_start($hbox, 0, 0, 0); - $hbox->set_layout('edge'); - $_->set_alignment(0.5, 0.5), $hbox->add($_) foreach @buttons; -} - sub sync () { $mainw->show; Gtk2->main_iteration while Gtk2->events_pending; } -sub new_label { - my ($msg) = @_; - my $label = Gtk2::Label->new($msg); - $label->set_line_wrap(1); - $label->set_alignment(0.5, 0.5); - if (($msg =~ tr/\n/\n/) > 5) { - my $sw = Gtk2::ScrolledWindow->new; - $sw->set_policy('never', 'automatic'); - $sw->add_with_viewport($label); - $sw->set_size_request(-1,200); - return $sw; - } else { - return $label; - } -} - #- sets the window to a please-wait message sub wait_label { my $wait_vbox = Gtk2::VBox->new(0, 5); @@ -73,14 +45,14 @@ sub wait_label { my (@all_rpms); foreach (@ARGV) { if (/^-/) { - /^--?[hv?]/ and gurpmi::usage(); - gurpmi::fatal N("Unknown option %s", $_); + /^--?[hv?]/ and usage(); + fatal(N("Unknown option %s", $_)); } push @all_rpms, $_; } -@all_rpms or gurpmi::fatal N("No packages specified"); +@all_rpms or fatal(N("No packages specified")); -$> and gurpmi::fatal N("Must be root"); +$> and fatal(N("Must be root")); #- Now, the graphical stuff. @@ -158,8 +130,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(gurpmi::but N("_Cancel")); - my $choice_button = Gtk2::Button->new(gurpmi::but N("_Ok")); + my $cancel_button = Gtk2::Button->new(but(N("_Cancel"))); + my $choice_button = Gtk2::Button->new(but(N("_Ok"))); $cancel_button->signal_connect(clicked => \&quit); $choice_button->signal_connect(clicked => sub { my $n = 0; @@ -175,8 +147,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(gurpmi::but N("_Ok")); - my $quit_button = Gtk2::Button->new(gurpmi::but N("_Abort")); + my $continue_button = Gtk2::Button->new(but(N("_Ok"))); + my $quit_button = Gtk2::Button->new(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); @@ -326,7 +298,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(gurpmi::but N("_Done")); + my $quit_button = Gtk2::Button->new(but(N("_Done"))); $quit_button->signal_connect(clicked => \&quit); add_button_box($vbox, $quit_button); change_mainw($vbox); |