From cb5c7ea44a31b39adec99e7602c10ad7fd8aa152 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Fri, 4 Jul 2014 00:55:33 +0200 Subject: Added update media (TODO fix index to update them really) --- lib/AdminPanel/Rpmdragora/edit_urpm_sources.pm | 3 + lib/AdminPanel/rpmdragora.pm | 198 +++++++++++++++++-------- 2 files changed, 137 insertions(+), 64 deletions(-) (limited to 'lib') diff --git a/lib/AdminPanel/Rpmdragora/edit_urpm_sources.pm b/lib/AdminPanel/Rpmdragora/edit_urpm_sources.pm index 21e4b29..c3d835a 100644 --- a/lib/AdminPanel/Rpmdragora/edit_urpm_sources.pm +++ b/lib/AdminPanel/Rpmdragora/edit_urpm_sources.pm @@ -1276,6 +1276,9 @@ sub mainwindow() { } ); } + elsif ($menuLabel eq $fileMenu{ update }->label()) { + update_callback(); + } } elsif ($eventType == $yui::YEvent::WidgetEvent) { # widget selected diff --git a/lib/AdminPanel/rpmdragora.pm b/lib/AdminPanel/rpmdragora.pm index 058c53c..a31b5b5 100644 --- a/lib/AdminPanel/rpmdragora.pm +++ b/lib/AdminPanel/rpmdragora.pm @@ -703,7 +703,6 @@ sub show_urpm_progress { $pb->setValue(0); $label->setValue(N("Starting download of `%s'...", $file)); } elsif ($mode eq 'progress') { - $DB::single = 1; if (defined $total && defined $eta) { $pb->setValue($percent); $label->setValue(N("Download of `%s'\ntime to go:%s, speed:%s", $file, $eta, $speed)); @@ -715,6 +714,139 @@ sub show_urpm_progress { } } + +sub update_sources_interactive { + my ($urpm, %options) = @_; + + my $appTitle = yui::YUI::app()->applicationTitle(); + + ## set new title to get it in dialog + yui::YUI::app()->setApplicationTitle(N("Update media")); + + my $retVal = 0; + my $mageiaPlugin = "mga"; + my $factory = yui::YUI::widgetFactory; + my $mgaFactory = yui::YExternalWidgets::externalWidgetFactory($mageiaPlugin); + $mgaFactory = yui::YMGAWidgetFactory::getYMGAWidgetFactory($mgaFactory); + + my $dialog = $factory->createPopupDialog(); + my $minSize = $factory->createMinSize( $dialog, 60, 15 ); + my $vbox = $factory->createVBox($minSize); + + my $yTableHeader = new yui::YTableHeader(); + $yTableHeader->addColumn("", $yui::YAlignBegin); + $yTableHeader->addColumn(N("Media"), $yui::YAlignBegin); + + my $mediaTable = $mgaFactory->createCBTable($vbox, $yTableHeader, $yui::YCBTableCheckBoxOnFirstColumn); + my @media = grep { ! $_->{ignore} } @{$urpm->{media}}; + unless (@media) { + interactive_msg(N("Warning"), N("No active medium found. You must enable some media to be able to update them.")); + return 0; + } + + my $itemCollection = new yui::YItemCollection; + foreach (@media) { + my $item = new yui::YCBTableItem($_->{name}); + $item->setLabel($_->{name}); + $itemCollection->push($item); + $item->DISOWN(); + + } + $mediaTable->addItems($itemCollection); + + + # dialog buttons + $factory->createVSpacing($vbox, 1.0); + ## Window push buttons + my $hbox = $factory->createHBox( $vbox ); + + my $cancelButton = $factory->createPushButton($hbox, N("Cancel") ); + my $selectButton = $factory->createPushButton($hbox, N("Select all") ); + my $updateButton = $factory->createPushButton($hbox, N("Update") ); + + while(1) { + my $event = $dialog->waitForEvent(); + my $eventType = $event->eventType(); + + #event type checking + if ($eventType == $yui::YEvent::CancelEvent) { + last; + } + elsif ($eventType == $yui::YEvent::WidgetEvent) { + # widget selected + my $widget = $event->widget(); + my $wEvent = yui::toYWidgetEvent($event); + + if ($widget == $cancelButton) { + last; + } + elsif ($widget == $selectButton) { + yui::YUI::app()->busyCursor(); + yui::YUI::ui()->blockEvents(); + $dialog->startMultipleChanges(); + for (my $it = $mediaTable->itemsBegin(); $it != $mediaTable->itemsEnd(); ) { + my $item = $mediaTable->YItemIteratorToYItem($it); + if ($item) { + $mediaTable->checkItem($item, 1); + # NOTE for some reasons it is never == $mediaTable->itemsEnd() + if ($item->index() == $mediaTable->itemsCount()-1) { + last; + } + } + $it = $mediaTable->nextItem($it); + } + $dialog->recalcLayout(); + $dialog->doneMultipleChanges(); + yui::YUI::ui()->unblockEvents(); + yui::YUI::app()->normalCursor(); + + } + elsif ($widget == $updateButton) { +# @media = map_index { if_($_->get_active, $buttonmedia[$::i]{name}) } @buttons; +# +# my @media_index; +# for (my $it = $mediaTable->itemsBegin(); $it != $mediaTable->itemsEnd(); ) { +# my $item = $mediaTable->YItemIteratorToYItem($it); +# $item = $mediaTable->toCBYTableItem($item); +# if ($item) { +# if ($item->checked() && $media[$item->index()]{name}) { +# push @media_index, $item->index(); +# } +# # NOTE for some reasons it is never == $mediaTable->itemsEnd() +# if ($item->index() == $mediaTable->itemsCount()-1) { +# last; +# } +# } +# $it = $mediaTable->nextItem($it); +# } +# +# $retVal = update_sources_noninteractive($urpm, \@media_index, %options); + last; + } + } + } + + $dialog->destroy(); + + #restore old application title + yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle; + + return $retVal; +} + +sub update_sources_noninteractive { + my ($urpm, $media, %options) = @_; + + urpm::media::select_media($urpm, @$media); + update_sources_check( + $urpm, + {}, + N_("Unable to update medium; it will be automatically disabled.\n\nErrors:\n%s"), + @$media, + ); + return 1; +} + sub mirrors { my ($urpm, $want_base_distro) = @_; my $cachedir = $urpm->{cachedir} || '/root'; @@ -872,71 +1004,9 @@ by Mageia Official Updates.")), %options -sub update_sources_interactive { - my ($urpm, %options) = @_; - my $w = ugtk2->new(N("Update media"), grab => 1, center => 1, %options); - $w->{rwindow}->set_position($options{transient} ? 'center_on_parent' : 'center_always'); - my @buttons; - my @media = grep { ! $_->{ignore} } @{$urpm->{media}}; - unless (@media) { - interactive_msg(N("Warning"), N("No active medium found. You must enable some media to be able to update them.")); - return 0; - } - gtkadd( - $w->{window}, - gtkpack_( - 0, Gtk2::VBox->new(0,5), - 0, Gtk2::Label->new(N("Select the media you wish to update:")), - 1, gtknew('ScrolledWindow', height => 300, child => - # FIXME: using a listview would be just better: - gtknew('VBox', spacing => 5, children_tight => [ - @buttons = map { - Gtk2::CheckButton->new_with_label($_->{name}); - } @media - ]) - ), - 0, Gtk2::HSeparator->new, - 0, gtkpack( - create_hbox(), - gtksignal_connect( - Gtk2::Button->new(N("Cancel")), - clicked => sub { $w->{retval} = 0; Gtk2->main_quit }, - ), - gtksignal_connect( - Gtk2::Button->new(N("Select all")), - clicked => sub { $_->set_active(1) foreach @buttons }, - ), - gtksignal_connect( - Gtk2::Button->new(N("Update")), - clicked => sub { - $w->{retval} = any { $_->get_active } @buttons; - # list of media listed in the checkbox panel - my @buttonmedia = grep { !$_->{ignore} } @{$urpm->{media}}; - @media = map_index { if_($_->get_active, $buttonmedia[$::i]{name}) } @buttons; - Gtk2->main_quit; - }, - ), - ) - ) - ); - if ($w->main) { - return update_sources_noninteractive($urpm, \@media, %options); - } - return 0; -} -sub update_sources_noninteractive { - my ($urpm, $media, %options) = @_; - urpm::media::select_media($urpm, @$media); - update_sources_check( - $urpm, - {}, - N_("Unable to update medium; it will be automatically disabled.\n\nErrors:\n%s"), - @$media, - ); - return 1; -} + #- Check whether the default update media (added by installation) -- cgit v1.2.1