diff options
-rw-r--r-- | Rpmdrake/gurpm.pm | 81 | ||||
-rw-r--r-- | Rpmdrake/pkg.pm | 69 |
2 files changed, 77 insertions, 73 deletions
diff --git a/Rpmdrake/gurpm.pm b/Rpmdrake/gurpm.pm index d29dea8c..4ddc9d28 100644 --- a/Rpmdrake/gurpm.pm +++ b/Rpmdrake/gurpm.pm @@ -27,77 +27,82 @@ use strict; use lib qw(/usr/lib/libDrakX); use mygtk2 qw(gtknew); #- do not import anything else, especially gtkadd() which conflicts with ugtk2 one use ugtk2 qw(:all); +use base qw(ugtk2); -our ($mainw, $label, $progressbar, $vbox, $cancel, $hbox_cancel); - -my $previous_main_window; - -sub init { - my ($title, $initializing, %options) = @_; - $mainw = ugtk2->new($title, %options, default_width => 600, width => 600); - $previous_main_window = $::main_window; +sub new { + my ($self, $title, $initializing, %options) = @_; + my $mainw = bless(ugtk2->new($title, %options, default_width => 600, width => 600), $self); + $mainw->{previous_main_window} = $::main_window; $::main_window = $mainw->{real_window}; - $label = gtknew('Label', text => $initializing, alignment => [ 0.5, 0 ]); + $mainw->{label} = gtknew('Label', text => $initializing, alignment => [ 0.5, 0 ]); # size label's heigh to 2 lines in order to prevent dummy vertical resizing: - my $context = $label->get_layout->get_context; - my $metrics = $context->get_metrics($label->style->font_desc, $context->get_language); - $label->set_size_request(-1, 2 * Gtk2::Pango->PANGO_PIXELS($metrics->get_ascent + $metrics->get_descent)); + my $context = $mainw->{label}->get_layout->get_context; + my $metrics = $context->get_metrics($mainw->{label}->style->font_desc, $context->get_language); + $mainw->{label}->set_size_request(-1, 2 * Gtk2::Pango->PANGO_PIXELS($metrics->get_ascent + $metrics->get_descent)); - $progressbar = gtknew('ProgressBar'); - gtkadd($mainw->{window}, $vbox = gtknew('VBox', spacing => 5, border_width => 6, children_tight => [ $label, $progressbar ])); + $mainw->{progressbar} = gtknew('ProgressBar'); + gtkadd($mainw->{window}, $mainw->{vbox} = gtknew('VBox', spacing => 5, border_width => 6, children_tight => [ + $mainw->{label}, + $mainw->{progressbar} + ])); $mainw->{rwindow}->set_position('center-on-parent'); - $mainw->sync; + $mainw->SUPER::sync; + $mainw; } sub label { - $label->set($_[0]); + my ($self, $label) = @_; + $self->{label}->set($label); select(undef, undef, undef, 0.1); #- hackish :-( - $mainw->flush; + $self->flush; } sub progress { - my ($fraction) = @_; + my ($self, $fraction) = @_; $fraction = 0 if $fraction < 0; $fraction = 1 if 1 < $fraction; - $progressbar->set_fraction($fraction); - $mainw->flush; + $self->{progressbar}->set_fraction($fraction); + $self->flush; } -sub end() { - $mainw and $mainw->destroy; - $mainw = undef; - $cancel = undef; #- in case we'll do another one later - $::main_window = $previous_main_window; +sub DESTROY { + my ($self) = @_; + $::main_window = $self->{previous_main_window}; + $self and $self->destroy; + $self = undef; + $self->{cancel} = undef; #- in case we'll do another one later } sub validate_cancel { - my ($cancel_msg, $cancel_cb) = @_; - if (!$cancel) { + my ($self, $cancel_msg, $cancel_cb) = @_; + if (!$self->{cancel}) { gtkpack__( - $vbox, - $hbox_cancel = gtkpack__( + $self->{vbox}, + $self->{hbox_cancel} = gtkpack__( gtknew('HButtonBox'), - $cancel = gtknew('Button', text => $cancel_msg, clicked => \&$cancel_cb), + $self->{cancel} = gtknew('Button', text => $cancel_msg, clicked => \&$cancel_cb), ), ); } - $cancel->set_sensitive(1); - $cancel->show; + $self->{cancel}->set_sensitive(1); + $self->{cancel}->show; } -sub invalidate_cancel() { - $cancel and $cancel->set_sensitive(0); +sub invalidate_cancel { + my ($self) = @_; + $self->{cancel} and $self->{cancel}->set_sensitive(0); } -sub invalidate_cancel_forever() { - $hbox_cancel or return; - $hbox_cancel->destroy; +sub invalidate_cancel_forever { + my ($self) = @_; + $self->{hbox_cancel} or return; + $self->{hbox_cancel}->destroy; # FIXME: temporary workaround that prevents # Gtk2::Label::set_text() set_text_internal() -> queue_resize() -> # size_allocate() call chain to mess up when ->shrink_topwindow() # has been called (#32613): - #$mainw->shrink_topwindow; + #$self->shrink_topwindow; } 1; diff --git a/Rpmdrake/pkg.pm b/Rpmdrake/pkg.pm index 83e77900..58e5ed51 100644 --- a/Rpmdrake/pkg.pm +++ b/Rpmdrake/pkg.pm @@ -230,9 +230,9 @@ sub get_pkgs { my ($opts) = @_; my $w = $::main_window; - Rpmdrake::gurpm::init(1 ? N("Please wait") : N("Package installation..."), N("Initializing..."), transient => $::main_window); + my $gurpm = Rpmdrake::gurpm->new(1 ? N("Please wait") : N("Package installation..."), N("Initializing..."), transient => $::main_window); my $_gurpm_clean_guard = before_leaving { Rpmdrake::gurpm::end() }; - my $_flush_guard = Gtk2::GUI_Update_Guard->new; + #my $_flush_guard = Gtk2::GUI_Update_Guard->new; warn_about_media($w, $opts); @@ -243,8 +243,8 @@ sub get_pkgs { # update media list in case warn_about_media() added some: @update_medias = get_update_medias($urpm); - Rpmdrake::gurpm::label(N("Reading updates description")); - Rpmdrake::gurpm::progress(0.05); + $gurpm->label(N("Reading updates description")); + $gurpm->progress(0.05); #- parse the description file my $update_descr = urpm::get_updates_description($urpm, @update_medias); @@ -255,8 +255,8 @@ sub get_pkgs { my $level = 0.05; my $total = @{$urpm->{depslist}}; - Rpmdrake::gurpm::label(N("Please wait, listing base packages...")); - Rpmdrake::gurpm::progress($level); + $gurpm->label(N("Please wait, listing base packages...")); + $gurpm->progress($level); my ($count, $prev_stage, $new_stage, $limit); @@ -267,7 +267,7 @@ sub get_pkgs { $new_stage = $level+($limit-$level)*$count/$total; if ($prev_stage + 0.01 < $new_stage) { $prev_stage = $new_stage; - Rpmdrake::gurpm::progress($new_stage); + $gurpm->progress($new_stage); } }; @@ -292,8 +292,8 @@ sub get_pkgs { $base{$_} = \$n; } } - Rpmdrake::gurpm::label(N("Please wait, finding installed packages...")); - Rpmdrake::gurpm::progress($level = 0.33); + $gurpm->label(N("Please wait, finding installed packages...")); + $gurpm->progress($level = 0.33); $reset_update->(0.66); my (@installed_pkgs, %all_pkgs); if (!$probe_only_for_updates) { @@ -325,8 +325,8 @@ sub get_pkgs { $urpm->{state} = {}; my (@installable_pkgs, @updates); - Rpmdrake::gurpm::label(N("Please wait, finding available packages...")); - Rpmdrake::gurpm::progress($level = 0.66); + $gurpm->label(N("Please wait, finding available packages...")); + $gurpm->progress($level = 0.66); check_update_media_version($urpm, @update_medias); @@ -354,7 +354,7 @@ sub get_pkgs { $urpm->{depslist}[$_]->set_flag_installed foreach keys %$requested; #- pretend it's installed } $urpm->{rpmdrake_state} = $state; #- Don't forget it - Rpmdrake::gurpm::progress($level = 0.7); + $gurpm->progress($level = 0.7); my @search_medias = grep { $_->{searchmedia} } @{$urpm->{media}}; @@ -486,10 +486,11 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( my @error_msgs; my $statusbar_msg_id; + my $gurpm; local $urpm->{fatal} = sub { my $fatal_msg = $_[1]; printf STDERR "Fatal: %s\n", $fatal_msg; - Rpmdrake::gurpm::end(); + undef $gurpm; interactive_msg(N("Installation failed"), N("There was a problem during the installation:\n\n%s", $fatal_msg)); goto return_with_exit_code; @@ -553,8 +554,7 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( # select packages to uninstall for !update mode: perform_removal($urpm, { map { $_ => $pkgs->{$_} } @to_remove }) if !$probe_only_for_updates; - Rpmdrake::gurpm::init(1 ? N("Please wait") : N("Package installation..."), N("Initializing..."), transient => $::main_window); - my $_guard = before_leaving { Rpmdrake::gurpm::end() }; + $gurpm = Rpmdrake::gurpm->new(1 ? N("Please wait") : N("Package installation..."), N("Initializing..."), transient => $::main_window); my $canceled; my $something_installed; @@ -566,14 +566,14 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( my $pkg = defined $id ? $urpm->{depslist}[$id] : undef; if ($subtype eq 'start') { if ($type eq 'trans') { - Rpmdrake::gurpm::label(1 ? N("Preparing packages installation...") : N("Preparing package installation transaction...")); + $gurpm->label(1 ? N("Preparing packages installation...") : N("Preparing package installation transaction...")); } elsif (defined $pkg) { $something_installed = 1; - Rpmdrake::gurpm::label(N("Installing package `%s' (%s/%s)...", $pkg->name, ++$transaction_progress_nb, scalar(@{$transaction->{upgrade}})) + $gurpm->label(N("Installing package `%s' (%s/%s)...", $pkg->name, ++$transaction_progress_nb, scalar(@{$transaction->{upgrade}})) . "\n" . N("Total: %s/%s", ++$progress_nb, $install_count)); } } elsif ($subtype eq 'progress') { - Rpmdrake::gurpm::progress($total ? $amount/$total : 1); + $gurpm->progress($total ? $amount/$total : 1); } }; @@ -582,7 +582,7 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( completed => sub { # explicitly destroy the progress window when it's over; we may # have sg to display before returning (errors, rpmnew/rpmsave, ...): - Rpmdrake::gurpm::end(); + undef $gurpm; undef $lock; undef $rpm_lock; @@ -592,7 +592,7 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( ask_yes_or_no => sub { # handle 'allow-force' and 'allow-nodeps' options: my ($title, $msg) = @_; - local $::main_window = $Rpmdrake::gurpm::mainw->{real_window}; + local $::main_window = $$gurpm->mainw->{real_window}; interactive_msg($title, $msg, yesno => 1, scroll => 1, ) or goto return_with_exit_code; }, @@ -603,10 +603,10 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( trans_log => sub { my ($mode, $file, $percent, $total, $eta, $speed) = @_; if ($mode eq 'start') { - Rpmdrake::gurpm::label(N("Downloading package `%s'...", basename($file))); - Rpmdrake::gurpm::validate_cancel(but(N("Cancel")), sub { $canceled = 1 }); + $gurpm->label(N("Downloading package `%s'...", basename($file))); + $gurpm->validate_cancel(but(N("Cancel")), sub { $canceled = 1 }); } elsif ($mode eq 'progress') { - Rpmdrake::gurpm::label( + $gurpm->label( join("\n", N("Downloading package `%s'...", basename($file)), (defined $total && defined $eta ? @@ -615,10 +615,10 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( ) =~ /^\s*(.*)/ ), ); - Rpmdrake::gurpm::progress($percent/100); + $gurpm->progress($percent/100); } elsif ($mode eq 'end') { - Rpmdrake::gurpm::progress(1); - Rpmdrake::gurpm::invalidate_cancel(); + $gurpm->progress(1); + $gurpm->invalidate_cancel(); } $canceled and goto return_with_exit_code; @@ -649,18 +649,18 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( yesno => 1, text => { no => N("Cancel"), yes => N("Ok") }, ); }, - pre_check_sig => sub { Rpmdrake::gurpm::label(N("Verifying package signatures...")) }, - check_sig => sub { Rpmdrake::gurpm::progress(++$progress/$total) }, + pre_check_sig => sub { $gurpm->label(N("Verifying package signatures...")) }, + check_sig => sub { $gurpm->progress(++$progress/$total) }, bad_signature => sub { my ($msg, $msg2) = @_; - local $::main_window = $Rpmdrake::gurpm::mainw->{real_window}; + local $::main_window = $$gurpm->mainw->{real_window}; interactive_msg( N("Warning"), "$msg\n$msg2", yesno => 1, if_(10 < $msg =~ tr/\n/\n/, scroll => 1), ) or goto return_with_exit_code; }, post_download => sub { $canceled and goto return_with_exit_code; - Rpmdrake::gurpm::invalidate_cancel_forever(); + $gurpm->invalidate_cancel_forever(); }, missing_files_summary => sub { my ($error_sources) = @_; @@ -723,8 +723,7 @@ sub perform_removal { my ($urpm, $pkgs) = @_; my @toremove = map { if_($pkgs->{$_}{selected}, $pkgs->{$_}{urpm_name}) } keys %$pkgs; return if !@toremove; - Rpmdrake::gurpm::init(1 ? N("Please wait") : N("Please wait, removing packages..."), N("Initializing..."), transient => $::main_window); - my $_a = before_leaving { Rpmdrake::gurpm::end() }; + my $gurpm = Rpmdrake::gurpm::new(1 ? N("Please wait") : N("Please wait, removing packages..."), N("Initializing..."), transient => $::main_window); my $progress = -1; local $urpm->{log} = sub { @@ -732,8 +731,8 @@ sub perform_removal { print $str; $progress++; return if $progress <= 0; # skip first "creating transaction..." message - Rpmdrake::gurpm::label($str); # display "removing package %s" - Rpmdrake::gurpm::progress(min(0.99, scalar($progress/@toremove))); + $gurpm->label($str); # display "removing package %s" + $gurpm->progress(min(0.99, scalar($progress/@toremove))); gtkflush(); }; @@ -745,7 +744,7 @@ sub perform_removal { @results = $::rpmdrake_options{parallel} ? urpm::parallel::remove($urpm, \@toremove) : urpm::install::install($urpm, \@toremove, {}, {}, - callback_report_uninst => sub { Rpmdrake::gurpm::label($_[0]) }, + callback_report_uninst => sub { $gurpm->label($_[0]) }, ); open_rpm_db('force_sync'); }, |