From 7ed2c026ec660f95945545fd39a6f78b5a8f96c9 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Wed, 7 Jan 2015 18:43:12 +0100 Subject: changed gurpmi to Moose and managed all the calls --- lib/AdminPanel/Rpmdragora/gurpm.pm | 372 +++++++++++++++++++++++++------------ lib/AdminPanel/Rpmdragora/pkg.pm | 25 ++- lib/AdminPanel/rpmdragora.pm | 5 +- 3 files changed, 276 insertions(+), 126 deletions(-) (limited to 'lib/AdminPanel') diff --git a/lib/AdminPanel/Rpmdragora/gurpm.pm b/lib/AdminPanel/Rpmdragora/gurpm.pm index 9c0ea43..d1a24df 100644 --- a/lib/AdminPanel/Rpmdragora/gurpm.pm +++ b/lib/AdminPanel/Rpmdragora/gurpm.pm @@ -1,152 +1,294 @@ # vim: set et ts=4 sw=4: package AdminPanel::Rpmdragora::gurpm; -#***************************************************************************** -# -# Copyright (c) 2002 Guillaume Cottenceau -# Copyright (c) 2002-2007 Thierry Vignaud -# Copyright (c) 2003, 2004, 2005 MandrakeSoft SA -# Copyright (c) 2005-2007 Mandriva SA -# Copyright (c) 2013 Matteo Pasotti -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2, as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -#***************************************************************************** -# -# $Id: gurpm.pm 255450 2009-04-03 16:00:16Z tv $ -use strict; +#============================================================= -*-perl-*- -use yui; +=head1 NAME + + AdminPanel::Rpmdragora::gurpm - Module that shows the urpmi + progress status + +=head1 SYNOPSIS + + my %option = (title => "Urpmi action ivoked", text => "Please wait", ); + my $gurpmi = AdminPanel::Rpmdragora::gurpm->new(%option); + $gurpmi->progress(45); + + #add to an existing dialog + %option = (title => "Urpmi action ivoked", text => "Please wait", main_dialog => $dialog, parent => $parent_container); + $gurpmi = AdminPanel::Rpmdragora::gurpm->new(%option); + $gurpmi->progress(20); + +=head1 DESCRIPTION + + This class is used to show the progress of an urpmi operation on + its progress bar. It can be istantiated as a popup dialog or used + to add label and progress bar into a YLayoutBox container. + +=head1 SUPPORT + + You can find documentation for this module with the perldoc command: + + perldoc AdminPanel::Rpmdragora::gurpm + +=head1 AUTHOR + + Angelo Naselli + +=head1 COPYRIGHT and LICENSE + + Copyright (c) 2002 Guillaume Cottenceau + Copyright (c) 2002-2007 Thierry Vignaud + Copyright (c) 2003, 2004, 2005 MandrakeSoft SA + Copyright (c) 2005-2007 Mandriva SA + Copyright (c) 2013 Matteo Pasotti + Copyright (C) 2015, Angelo Naselli + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2, as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +=cut + + +use Moose; +use Carp; use Time::HiRes; + +use yui; use feature 'state'; -sub new { - my ($class, $title, $initializing, %options) = @_; - my $self = { - my $label = 0, - my $factory = 0, - my $mainw = 0, - my $vbox = 0, - my $progressbar = 0, - my $cancel = 0 - }; - bless $self, 'AdminPanel::Rpmdragora::gurpm'; - #my $mainw = bless(ugtk2->new($title, %options, default_width => 600, width => 600), $self); - $self->{factory} = yui::YUI::widgetFactory; - $self->{mainw} = $self->{factory}->createPopupDialog(); - - $self->{mainw}->startMultipleChanges(); - - #$::main_window = $self->{mainw}; - $self->{vbox} = $self->{factory}->createVBox($self->{mainw}); - #OLD $mainw->{label} = gtknew('Label', text => $initializing, alignment => [ 0.5, 0 ]); - $self->{label} = $self->{factory}->createLabel($self->{vbox}, $initializing); - $self->{label}->setStretchable( $yui::YD_HORIZ, 1 ); - # size label's heigh to 2 lines in order to prevent dummy vertical resizing: - #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)); - - #OLD $mainw->{progressbar} = gtknew('ProgressBar'); - $self->{progressbar} = $self->{factory}->createProgressBar($self->{vbox}, ""); - #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->{real_window}->show_all; - #select(undef, undef, undef, 0.1); #- hackish :-( - #$mainw->SUPER::sync; - $self->{mainw}->pollEvent(); - $self->flush(); - $self; +has 'title' => ( + is => 'rw', + isa => 'Str', +); + +has 'text' => ( + is => 'rw', + isa => 'Str', +); + +has 'main_dialog' => ( + is => 'rw', + isa => 'yui::YDialog', +); + +has 'parent' => ( + is => 'rw', + isa => 'yui::YReplacePoint', +); + +has 'label_widget' => ( + is => 'rw', + isa => 'yui::YLabel', + init_arg => undef, +); + +has 'progressbar' => ( + is => 'rw', + isa => 'yui::YProgressBar', + init_arg => undef, +); + +#============================================================= + +=head2 BUILD + +=head3 DESCRIPTION + + The BUILD method is called after a Moose object is created, + in this methods Services loads all the service information. + +=cut + +#============================================================= +sub BUILD { + my $self = shift; + + my $factory = yui::YUI::widgetFactory; + my $vbox; +$DB::single = 1; + + if (! $self->main_dialog) { + if ($self->parent) { + carp "WARNING: parent parameter is skipped without main_dialog set\n" ; + $self->parent(undef); + } + $self->main_dialog($factory->createPopupDialog()); + $vbox = $factory->createVBox($self->main_dialog); + } + else { + die "parent parameter is mandatory with main_dialog" if !$self->parent; + $self->main_dialog->startMultipleChanges(); + $self->parent->deleteChildren(); + $vbox = $factory->createVBox($self->parent); + $factory->createVSpacing($vbox, 0.5); + } + + $self->label_widget( $factory->createLabel($vbox, $self->text) ); + $self->label_widget->setStretchable( $yui::YD_HORIZ, 1 ); + $self->progressbar( $factory->createProgressBar($vbox, "") ); + + if ($self->parent) { + $factory->createVSpacing($vbox, 0.5); + $self->parent->showChild(); + $self->main_dialog->recalcLayout(); + $self->main_dialog->doneMultipleChanges(); + } + + $self->main_dialog->pollEvent(); + $self->flush(); } + +#============================================================= + +=head2 flush + +=head3 DESCRIPTION + + Polls a dialog event to refresh the dialog + +=cut + +#============================================================= sub flush { my ($self) = @_; - $self->{mainw}->recalcLayout(); - $self->{mainw}->doneMultipleChanges(); - $self->{mainw}->waitForEvent(10); + $self->main_dialog->startMultipleChanges(); + $self->main_dialog->recalcLayout(); + $self->main_dialog->doneMultipleChanges(); - $self->{mainw}->pollEvent(); + if ($self->main_dialog->isTopmostDialog()) { + $self->main_dialog->waitForEvent(10); + $self->main_dialog->pollEvent(); + } + else { + carp "This dialog is not a top most dialog\n"; + } yui::YUI::app()->redrawScreen(); } +#============================================================= + +=head2 label + +=head3 INPUT + + $text: text to be shown on label + +=head3 DESCRIPTION + + Sets the label text + +=cut + +#============================================================= sub label { - my ($self, $label) = @_; + my ($self, $text) = @_; + + $self->main_dialog->startMultipleChanges(); + $self->label_widget->setValue($text) if $text; + $self->main_dialog->doneMultipleChanges(); - $self->{mainw}->startMultipleChanges(); - $self->{label}->setValue($label) if $label; - #select(undef, undef, undef, 0.1); #- hackish :-( $self->flush(); } +#============================================================= + +=head2 progress + +=head3 INPUT + + $value: integer value in the range 0..100 + +=head3 DESCRIPTION + + Sets the progress bar percentage value + +=cut + +#============================================================= sub progress { my ($self, $value) = @_; - state $time; - $time = 0 if(!defined($time)); + state $time = 0; + $value = 0 if !defined($value) || $value < 0; $value = 100 if 100 < $value; - $self->{progressbar}->setValue($value); + + $self->progressbar->setValue($value); return if Time::HiRes::clock_gettime() - $time < 0.333; $time = Time::HiRes::clock_gettime(); - $self->{mainw}->startMultipleChanges(); + $self->flush(); } -sub DESTROY { - my ($self) = @_; - #mygtk2::may_destroy($self); - $self and $self->{mainw}->destroy; - #$self = undef; - $self->{cancel} = undef; #- in case we'll do another one later -} +#============================================================= -sub validate_cancel { - my ($self, $cancel_msg, $cancel_cb) = @_; - $self->{mainw}->startMultipleChanges(); - if (!$self->{cancel}) { - $self->{cancel} = $self->{factory}->createIconButton($self->{vbox},"",$cancel_msg); - #gtkpack__( - #$self->{vbox}, - #$self->{hbox_cancel} = gtkpack__( - #gtknew('HButtonBox'), - #$self->{cancel} = gtknew('Button', text => $cancel_msg, clicked => \&$cancel_cb), - #), - #); - } - #$self->{cancel}->set_sensitive(1); - #$self->{cancel}->show; - $self->flush(); -} +=head2 DEMOLISH -sub invalidate_cancel { - my ($self) = @_; - $self->{cancel} and $self->{cancel}->setEnabled(0); -} +=head3 INPUT -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): - #$self->shrink_topwindow; + $val: boolean value indicating whether or not this method + was called as part of the global destruction process + (when the Perl interpreter exits) + +=head3 DESCRIPTION + + Moose provides a hook for object destruction with the + DEMOLISH method as it does for construtor with BUILD + +=cut + +#============================================================= +sub DEMOLISH { + my ($self, $val) = @_; + + $self->main_dialog->destroy if !$self->parent; } +# sub validate_cancel { +# my ($self, $cancel_msg, $cancel_cb) = @_; +# $self->{main_dialog}->startMultipleChanges(); +# if (!$self->{cancel}) { +# $self->{cancel} = $self->{factory}->createIconButton($self->{vbox},"",$cancel_msg); +# #gtkpack__( +# #$self->{vbox}, +# #$self->{hbox_cancel} = gtkpack__( +# #gtknew('HButtonBox'), +# #$self->{cancel} = gtknew('Button', text => $cancel_msg, clicked => \&$cancel_cb), +# #), +# #); +# } +# #$self->{cancel}->set_sensitive(1); +# #$self->{cancel}->show; +# $self->flush(); +# } +# +# sub invalidate_cancel { +# my ($self) = @_; +# $self->{cancel} and $self->{cancel}->setEnabled(0); +# } +# +# 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): +# #$self->shrink_topwindow; +# } + 1; diff --git a/lib/AdminPanel/Rpmdragora/pkg.pm b/lib/AdminPanel/Rpmdragora/pkg.pm index 96e5b54..f849518 100644 --- a/lib/AdminPanel/Rpmdragora/pkg.pm +++ b/lib/AdminPanel/Rpmdragora/pkg.pm @@ -141,9 +141,9 @@ sub extract_header { $bar_id = statusbar_msg($loc->N("Getting '%s' from XML meta-data...", $xml_info), 0); my $_gurpm_clean_guard = MDK::Common::Func::before_leaving { undef $gurpm }; if (my $xml_info_file = eval { urpm::media::any_xml_info($urpm, $medium, $xml_info, undef, sub { - $gurpm ||= AdminPanel::Rpmdragora::gurpm->new($loc->N("Please wait"), - '', # FIXME: add a real string after cooker - transient => $::main_window); + $gurpm ||= AdminPanel::Rpmdragora::gurpm->new( + text => $loc->N("Please wait"), + ); download_callback($gurpm, @_) or goto header_non_available; }) }) { @@ -213,7 +213,7 @@ sub download_callback { if ($mode eq 'start') { $gurpm->label($loc->N("Downloading package `%s'...", urpm::util::basename($file))); - $gurpm->validate_cancel(but($loc->N("Cancel")), sub { $canceled = 1 }); +# $gurpm->validate_cancel(but($loc->N("Cancel")), sub { $canceled = 1 }); } elsif ($mode eq 'progress') { $gurpm->label( join("\n", @@ -228,7 +228,7 @@ sub download_callback { $gurpm->progress(ceil($percent)); } elsif ($mode eq 'end') { $gurpm->progress(100); - $gurpm->invalidate_cancel; +# $gurpm->invalidate_cancel; } !$canceled; } @@ -457,7 +457,9 @@ sub get_pkgs { myexit (-1) if (warn_about_media($w, %options) == -1); - my $gurpm = AdminPanel::Rpmdragora::gurpm->new(1 ? $loc->N("Please wait") : $loc->N("Package installation..."), $loc->N("Initializing..."), transient => $::main_window); + my $gurpm = AdminPanel::Rpmdragora::gurpm->new( + text => $loc->N("Please wait"), + ); my $_gurpm_clean_guard = MDK::Common::Func::before_leaving { undef $gurpm }; my $urpm = open_urpmi_db(update => $probe_only_for_updates && !is_it_a_devel_distro()); @@ -815,7 +817,10 @@ 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; - $gurpm = AdminPanel::Rpmdragora::gurpm->new($loc->N("Please wait"), $loc->N("Initializing..."), transient => $::main_window); + $gurpm = AdminPanel::Rpmdragora::gurpm->new( + text => $loc->N("Please wait"), + title => $loc->N("Initializing..."), + ); # my $_gurpm_clean_guard = MDK::Common::Func::before_leaving { undef $gurpm }; my $something_installed; @@ -925,7 +930,7 @@ sub perform_installation { #- (partially) duplicated from /usr/sbin/urpmi :-( }, post_download => sub { $canceled and goto return_with_exit_code; - $gurpm->invalidate_cancel_forever; +# $gurpm->invalidate_cancel_forever; }, need_restart => sub { my ($need_restart_formatted) = @_; @@ -1025,7 +1030,9 @@ sub perform_removal { my ($urpm, $pkgs) = @_; my @toremove = map { MDK::Common::Func::if_($pkgs->{$_}{selected}, $pkgs->{$_}{urpm_name}) } keys %$pkgs; return if !@toremove; - my $gurpm = AdminPanel::Rpmdragora::gurpm->new(1 ? $loc->N("Please wait") : $loc->N("Please wait, removing packages..."), $loc->N("Initializing..."), transient => $::main_window); + my $gurpm = AdminPanel::Rpmdragora::gurpm->new( + text => $loc->N("Please wait") + ); my $_gurpm_clean_guard = MDK::Common::Func::before_leaving { undef $gurpm }; my $may_be_orphans = 1; diff --git a/lib/AdminPanel/rpmdragora.pm b/lib/AdminPanel/rpmdragora.pm index 09c62d8..fd6f5e0 100644 --- a/lib/AdminPanel/rpmdragora.pm +++ b/lib/AdminPanel/rpmdragora.pm @@ -1091,8 +1091,9 @@ sub mirrors { dir => $cachedir, callback => sub { $gurpm ||= - AdminPanel::Rpmdragora::gurpm->new($loc->N("Please wait"), - transient => $::main_window); + AdminPanel::Rpmdragora::gurpm->new( + text => $loc->N("Please wait"), + ); $canceled ||= !AdminPanel::Rpmdragora::pkg::download_callback($gurpm, @_); $gurpm->flush(); -- cgit v1.2.1