summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gurpmi38
-rw-r--r--gurpmi.pm31
-rwxr-xr-xgurpmi246
3 files changed, 46 insertions, 69 deletions
diff --git a/gurpmi b/gurpmi
index a3a910d9..0dcabcbb 100644
--- a/gurpmi
+++ b/gurpmi
@@ -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.
diff --git a/gurpmi.pm b/gurpmi.pm
index 404282c5..410602f6 100644
--- a/gurpmi.pm
+++ b/gurpmi.pm
@@ -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;
diff --git a/gurpmi2 b/gurpmi2
index 800a4d64..4c0375f2 100755
--- a/gurpmi2
+++ b/gurpmi2
@@ -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);